services: Add 'mcron-service'.
[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{} 2016 Ben Woodcroft@*
21 Copyright @copyright{} 2016 Chris Marusich@*
22 Copyright @copyright{} 2016 Efraim Flashner
23
24 Permission is granted to copy, distribute and/or modify this document
25 under the terms of the GNU Free Documentation License, Version 1.3 or
26 any later version published by the Free Software Foundation; with no
27 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
28 copy of the license is included in the section entitled ``GNU Free
29 Documentation License''.
30 @end copying
31
32 @dircategory System administration
33 @direntry
34 * Guix: (guix). Manage installed software and system configuration.
35 * guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
36 * guix build: (guix)Invoking guix build. Building packages.
37 * guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
38 * guix pull: (guix)Invoking guix pull. Update the list of available packages.
39 * guix system: (guix)Invoking guix system. Manage the operating system configuration.
40 @end direntry
41
42 @dircategory Software development
43 @direntry
44 * guix environment: (guix)Invoking guix environment. Building development environments with Guix.
45 @end direntry
46
47 @dircategory Emacs
48 @direntry
49 * Guix user interface: (guix)Emacs Interface. Package management from the comfort of Emacs.
50 @end direntry
51
52
53 @titlepage
54 @title GNU Guix Reference Manual
55 @subtitle Using the GNU Guix Functional Package Manager
56 @author The GNU Guix Developers
57
58 @page
59 @vskip 0pt plus 1filll
60 Edition @value{EDITION} @*
61 @value{UPDATED} @*
62
63 @insertcopying
64 @end titlepage
65
66 @contents
67
68 @c *********************************************************************
69 @node Top
70 @top GNU Guix
71
72 This document describes GNU Guix version @value{VERSION}, a functional
73 package management tool written for the GNU system.
74
75 @menu
76 * Introduction:: What is Guix about?
77 * Installation:: Installing Guix.
78 * Package Management:: Package installation, upgrade, etc.
79 * Emacs Interface:: Using Guix from Emacs.
80 * Programming Interface:: Using Guix in Scheme.
81 * Utilities:: Package management commands.
82 * GNU Distribution:: Software for your friendly GNU system.
83 * Contributing:: Your help needed!
84
85 * Acknowledgments:: Thanks!
86 * GNU Free Documentation License:: The license of this manual.
87 * Concept Index:: Concepts.
88 * Programming Index:: Data types, functions, and variables.
89
90 @detailmenu
91 --- The Detailed Node Listing ---
92
93 Installation
94
95 * Binary Installation:: Getting Guix running in no time!
96 * Requirements:: Software needed to build and run Guix.
97 * Running the Test Suite:: Testing Guix.
98 * Setting Up the Daemon:: Preparing the build daemon's environment.
99 * Invoking guix-daemon:: Running the build daemon.
100 * Application Setup:: Application-specific setup.
101
102 Setting Up the Daemon
103
104 * Build Environment Setup:: Preparing the isolated build environment.
105 * Daemon Offload Setup:: Offloading builds to remote machines.
106
107 Package Management
108
109 * Features:: How Guix will make your life brighter.
110 * Invoking guix package:: Package installation, removal, etc.
111 * Substitutes:: Downloading pre-built binaries.
112 * Packages with Multiple Outputs:: Single source package, multiple outputs.
113 * Invoking guix gc:: Running the garbage collector.
114 * Invoking guix pull:: Fetching the latest Guix and distribution.
115 * Invoking guix archive:: Exporting and importing store files.
116
117 Emacs Interface
118
119 * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
120 * Package Management: Emacs Package Management. Managing packages and generations.
121 * Licenses: Emacs Licenses. Interface for licenses of Guix packages.
122 * Package Source Locations: Emacs Package Locations. Interface for package location files.
123 * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
124 * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
125 * Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
126 * Completions: Emacs Completions. Completing @command{guix} shell command.
127 * Development: Emacs Development. Tools for Guix developers.
128 * Hydra: Emacs Hydra. Interface for Guix build farm.
129
130 Programming Interface
131
132 * Defining Packages:: Defining new packages.
133 * Build Systems:: Specifying how packages are built.
134 * The Store:: Manipulating the package store.
135 * Derivations:: Low-level interface to package derivations.
136 * The Store Monad:: Purely functional interface to the store.
137 * G-Expressions:: Manipulating build expressions.
138
139 Defining Packages
140
141 * package Reference:: The package data type.
142 * origin Reference:: The origin data type.
143
144 Utilities
145
146 * Invoking guix build:: Building packages from the command line.
147 * Invoking guix edit:: Editing package definitions.
148 * Invoking guix download:: Downloading a file and printing its hash.
149 * Invoking guix hash:: Computing the cryptographic hash of a file.
150 * Invoking guix import:: Importing package definitions.
151 * Invoking guix refresh:: Updating package definitions.
152 * Invoking guix lint:: Finding errors in package definitions.
153 * Invoking guix size:: Profiling disk usage.
154 * Invoking guix graph:: Visualizing the graph of packages.
155 * Invoking guix environment:: Setting up development environments.
156 * Invoking guix publish:: Sharing substitutes.
157 * Invoking guix challenge:: Challenging substitute servers.
158 * Invoking guix container:: Process isolation.
159
160 Invoking @command{guix build}
161
162 * Common Build Options:: Build options for most commands.
163 * Package Transformation Options:: Creating variants of packages.
164 * Additional Build Options:: Options specific to 'guix build'.
165
166 GNU Distribution
167
168 * System Installation:: Installing the whole operating system.
169 * System Configuration:: Configuring the operating system.
170 * Installing Debugging Files:: Feeding the debugger.
171 * Security Updates:: Deploying security fixes quickly.
172 * Package Modules:: Packages from the programmer's viewpoint.
173 * Packaging Guidelines:: Growing the distribution.
174 * Bootstrapping:: GNU/Linux built from scratch.
175 * Porting:: Targeting another platform or kernel.
176
177 System Installation
178
179 * Limitations:: What you can expect.
180 * Hardware Considerations:: Supported hardware.
181 * USB Stick Installation:: Preparing the installation medium.
182 * Preparing for Installation:: Networking, partitioning, etc.
183 * Proceeding with the Installation:: The real thing.
184 * Building the Installation Image:: How this comes to be.
185
186 System Configuration
187
188 * Using the Configuration System:: Customizing your GNU system.
189 * operating-system Reference:: Detail of operating-system declarations.
190 * File Systems:: Configuring file system mounts.
191 * Mapped Devices:: Block device extra processing.
192 * User Accounts:: Specifying user accounts.
193 * Locales:: Language and cultural convention settings.
194 * Services:: Specifying system services.
195 * Setuid Programs:: Programs running with root privileges.
196 * X.509 Certificates:: Authenticating HTTPS servers.
197 * Name Service Switch:: Configuring libc's name service switch.
198 * Initial RAM Disk:: Linux-Libre bootstrapping.
199 * GRUB Configuration:: Configuring the boot loader.
200 * Invoking guix system:: Instantiating a system configuration.
201 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
202 * Defining Services:: Adding new service definitions.
203
204 Services
205
206 * Base Services:: Essential system services.
207 * Scheduled Job Execution:: The mcron service.
208 * Networking Services:: Network setup, SSH daemon, etc.
209 * X Window:: Graphical display.
210 * Desktop Services:: D-Bus and desktop services.
211 * Database Services:: SQL databases.
212 * Mail Services:: IMAP, POP3, SMTP, and all that.
213 * Web Services:: Web servers.
214 * Various Services:: Other services.
215
216 Defining Services
217
218 * Service Composition:: The model for composing services.
219 * Service Types and Services:: Types and services.
220 * Service Reference:: API reference.
221 * Shepherd Services:: A particular type of service.
222
223 Packaging Guidelines
224
225 * Software Freedom:: What may go into the distribution.
226 * Package Naming:: What's in a name?
227 * Version Numbers:: When the name is not enough.
228 * Synopses and Descriptions:: Helping users find the right package.
229 * Python Modules:: Taming the snake.
230 * Perl Modules:: Little pearls.
231 * Java Packages:: Coffee break.
232 * Fonts:: Fond of fonts.
233
234 Contributing
235
236 * Building from Git:: The latest and greatest.
237 * Running Guix Before It Is Installed:: Hacker tricks.
238 * The Perfect Setup:: The right tools.
239 * Coding Style:: Hygiene of the contributor.
240 * Submitting Patches:: Share your work.
241
242 Coding Style
243
244 * Programming Paradigm:: How to compose your elements.
245 * Modules:: Where to store your code?
246 * Data Types and Pattern Matching:: Implementing data structures.
247 * Formatting Code:: Writing conventions.
248
249 @end detailmenu
250 @end menu
251
252 @c *********************************************************************
253 @node Introduction
254 @chapter Introduction
255
256 @cindex purpose
257 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
258 using the international phonetic alphabet (IPA).} is a package
259 management tool for the GNU system. Guix makes it easy for unprivileged
260 users to install, upgrade, or remove packages, to roll back to a
261 previous package set, to build packages from source, and generally
262 assists with the creation and maintenance of software environments.
263
264 @cindex user interfaces
265 Guix provides a command-line package management interface
266 (@pxref{Invoking guix package}), a set of command-line utilities
267 (@pxref{Utilities}), a visual user interface in Emacs (@pxref{Emacs
268 Interface}), as well as Scheme programming interfaces
269 (@pxref{Programming Interface}).
270 @cindex build daemon
271 Its @dfn{build daemon} is responsible for building packages on behalf of
272 users (@pxref{Setting Up the Daemon}) and for downloading pre-built
273 binaries from authorized sources (@pxref{Substitutes}).
274
275 @cindex extensibility of the distribution
276 @cindex customization of packages
277 Guix includes package definitions for many GNU and non-GNU packages, all
278 of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
279 user's computing freedom}. It is @emph{extensible}: users can write
280 their own package definitions (@pxref{Defining Packages}) and make them
281 available as independent package modules (@pxref{Package Modules}). It
282 is also @emph{customizable}: users can @emph{derive} specialized package
283 definitions from existing ones, including from the command line
284 (@pxref{Package Transformation Options}).
285
286 @cindex Guix System Distribution
287 @cindex GuixSD
288 You can install GNU@tie{}Guix on top of an existing GNU/Linux system
289 where it complements the available tools without interference
290 (@pxref{Installation}), or you can use it as part of the standalone
291 @dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
292 With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
293 system configuration and Guix takes care of instantiating the
294 configuration in a transactional, reproducible, and stateless fashion
295 (@pxref{System Configuration}).
296
297 @cindex functional package management
298 Under the hood, Guix implements the @dfn{functional package management}
299 discipline pioneered by Nix (@pxref{Acknowledgments}).
300 In Guix, the package build and installation process is seen
301 as a @emph{function}, in the mathematical sense. That function takes inputs,
302 such as build scripts, a compiler, and libraries, and
303 returns an installed package. As a pure function, its result depends
304 solely on its inputs---for instance, it cannot refer to software or
305 scripts that were not explicitly passed as inputs. A build function
306 always produces the same result when passed a given set of inputs. It
307 cannot alter the environment of the running system in
308 any way; for instance, it cannot create, modify, or delete files outside
309 of its build and installation directories. This is achieved by running
310 build processes in isolated environments (or @dfn{containers}), where only their
311 explicit inputs are visible.
312
313 @cindex store
314 The result of package build functions is @dfn{cached} in the file
315 system, in a special directory called @dfn{the store} (@pxref{The
316 Store}). Each package is installed in a directory of its own in the
317 store---by default under @file{/gnu/store}. The directory name contains
318 a hash of all the inputs used to build that package; thus, changing an
319 input yields a different directory name.
320
321 This approach is the foundation for the salient features of Guix: support
322 for transactional package upgrade and rollback, per-user installation, and
323 garbage collection of packages (@pxref{Features}).
324
325
326 @c *********************************************************************
327 @node Installation
328 @chapter Installation
329
330 GNU Guix is available for download from its website at
331 @url{http://www.gnu.org/software/guix/}. This section describes the
332 software requirements of Guix, as well as how to install it and get
333 ready to use it.
334
335 Note that this section is concerned with the installation of the package
336 manager, which can be done on top of a running GNU/Linux system. If,
337 instead, you want to install the complete GNU operating system,
338 @pxref{System Installation}.
339
340 @cindex foreign distro
341 When installed on a running GNU/Linux system---thereafter called a
342 @dfn{foreign distro}---GNU@tie{}Guix complements the available tools
343 without interference. Its data lives exclusively in two directories,
344 usually @file{/gnu/store} and @file{/var/guix}; other files on your
345 system, such as @file{/etc}, are left untouched.
346
347 @menu
348 * Binary Installation:: Getting Guix running in no time!
349 * Requirements:: Software needed to build and run Guix.
350 * Running the Test Suite:: Testing Guix.
351 * Setting Up the Daemon:: Preparing the build daemon's environment.
352 * Invoking guix-daemon:: Running the build daemon.
353 * Application Setup:: Application-specific setup.
354 @end menu
355
356 @node Binary Installation
357 @section Binary Installation
358
359 This section describes how to install Guix on an arbitrary system from a
360 self-contained tarball providing binaries for Guix and for all its
361 dependencies. This is often quicker than installing from source, which
362 is described in the next sections. The only requirement is to have
363 GNU@tie{}tar and Xz.
364
365 Installing goes along these lines:
366
367 @enumerate
368 @item
369 Download the binary tarball from
370 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
371 where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
372 already running the kernel Linux, and so on.
373
374 Make sure to download the associated @file{.sig} file and to verify the
375 authenticity of the tarball against it, along these lines:
376
377 @example
378 $ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
379 $ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
380 @end example
381
382 If that command fails because you do not have the required public key,
383 then run this command to import it:
384
385 @example
386 $ gpg --keyserver pgp.mit.edu --recv-keys 090B11993D9AEBB5
387 @end example
388
389 @noindent
390 and rerun the @code{gpg --verify} command.
391
392 @item
393 As @code{root}, run:
394
395 @example
396 # cd /tmp
397 # tar --warning=no-timestamp -xf \
398 guix-binary-@value{VERSION}.@var{system}.tar.xz
399 # mv var/guix /var/ && mv gnu /
400 @end example
401
402 This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
403 The latter contains a ready-to-use profile for @code{root} (see next
404 step.)
405
406 Do @emph{not} unpack the tarball on a working Guix system since that
407 would overwrite its own essential files.
408
409 The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
410 not emit warnings about ``implausibly old time stamps'' (such
411 warnings were triggered by GNU@tie{}tar 1.26 and older; recent
412 versions are fine.)
413 They stem from the fact that all the
414 files in the archive have their modification time set to zero (which
415 means January 1st, 1970.) This is done on purpose to make sure the
416 archive content is independent of its creation time, thus making it
417 reproducible.
418
419 @item
420 Make @code{root}'s profile available under @file{~/.guix-profile}:
421
422 @example
423 # ln -sf /var/guix/profiles/per-user/root/guix-profile \
424 ~root/.guix-profile
425 @end example
426
427 @item
428 Create the group and user accounts for build users as explained below
429 (@pxref{Build Environment Setup}).
430
431 @item
432 Run the daemon, and set it to automatically start on boot.
433
434 If your host distro uses the systemd init system, this can be achieved
435 with these commands:
436
437 @example
438 # cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
439 /etc/systemd/system/
440 # systemctl start guix-daemon && systemctl enable guix-daemon
441 @end example
442
443 If your host distro uses the Upstart init system:
444
445 @example
446 # cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
447 # start guix-daemon
448 @end example
449
450 Otherwise, you can still start the daemon manually with:
451
452 @example
453 # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
454 @end example
455
456 @item
457 Make the @command{guix} command available to other users on the machine,
458 for instance with:
459
460 @example
461 # mkdir -p /usr/local/bin
462 # cd /usr/local/bin
463 # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
464 @end example
465
466 It is also a good idea to make the Info version of this manual available
467 there:
468
469 @example
470 # mkdir -p /usr/local/share/info
471 # cd /usr/local/share/info
472 # for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
473 do ln -s $i ; done
474 @end example
475
476 That way, assuming @file{/usr/local/share/info} is in the search path,
477 running @command{info guix} will open this manual (@pxref{Other Info
478 Directories,,, texinfo, GNU Texinfo}, for more details on changing the
479 Info search path.)
480
481 @item
482 To use substitutes from @code{hydra.gnu.org} or one of its mirrors
483 (@pxref{Substitutes}), authorize them:
484
485 @example
486 # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
487 @end example
488 @end enumerate
489
490 This completes root-level install of Guix. Each user will need to
491 perform additional steps to make their Guix envionment ready for use,
492 @pxref{Application Setup}.
493
494 You can confirm that Guix is working by installing a sample package into
495 the root profile:
496
497 @example
498 # guix package -i hello
499 @end example
500
501 The @code{guix} package must remain available in @code{root}'s profile,
502 or it would become subject to garbage collection---in which case you
503 would find yourself badly handicapped by the lack of the @command{guix}
504 command. In other words, do not remove @code{guix} by running
505 @code{guix package -r guix}.
506
507 The binary installation tarball can be (re)produced and verified simply
508 by running the following command in the Guix source tree:
509
510 @example
511 make guix-binary.@var{system}.tar.xz
512 @end example
513
514
515 @node Requirements
516 @section Requirements
517
518 This section lists requirements when building Guix from source. The
519 build procedure for Guix is the same as for other GNU software, and is
520 not covered here. Please see the files @file{README} and @file{INSTALL}
521 in the Guix source tree for additional details.
522
523 GNU Guix depends on the following packages:
524
525 @itemize
526 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
527 @item @url{http://gnupg.org/, GNU libgcrypt};
528 @item @url{http://www.gnu.org/software/make/, GNU Make}.
529 @end itemize
530
531 The following dependencies are optional:
532
533 @itemize
534 @item
535 Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
536 access @code{https} URLs for substitutes, which is highly recommended
537 (@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
538 @command{guix download} command (@pxref{Invoking guix download}), the
539 @command{guix import pypi} command, and the @command{guix import cpan}
540 command. @xref{Guile Preparations, how to install the GnuTLS bindings
541 for Guile,, gnutls-guile, GnuTLS-Guile}.
542
543 @item
544 Installing
545 @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
546 allow you to use the @command{guix import pypi} command (@pxref{Invoking
547 guix import}). It is of
548 interest primarily for developers and not for casual users.
549 @end itemize
550
551 Unless @code{--disable-daemon} was passed to @command{configure}, the
552 following packages are also needed:
553
554 @itemize
555 @item @url{http://sqlite.org, SQLite 3};
556 @item @url{http://www.bzip.org, libbz2};
557 @item @url{http://gcc.gnu.org, GCC's g++}, with support for the
558 C++11 standard.
559 @end itemize
560
561 When configuring Guix on a system that already has a Guix installation,
562 be sure to specify the same state directory as the existing installation
563 using the @code{--localstatedir} option of the @command{configure}
564 script (@pxref{Directory Variables, @code{localstatedir},, standards,
565 GNU Coding Standards}). The @command{configure} script protects against
566 unintended misconfiguration of @var{localstatedir} so you do not
567 inadvertently corrupt your store (@pxref{The Store}).
568
569 When a working installation of @url{http://nixos.org/nix/, the Nix package
570 manager} is available, you
571 can instead configure Guix with @code{--disable-daemon}. In that case,
572 Nix replaces the three dependencies above.
573
574 Guix is compatible with Nix, so it is possible to share the same store
575 between both. To do so, you must pass @command{configure} not only the
576 same @code{--with-store-dir} value, but also the same
577 @code{--localstatedir} value. The latter is essential because it
578 specifies where the database that stores metadata about the store is
579 located, among other things. The default values for Nix are
580 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
581 Note that @code{--disable-daemon} is not required if
582 your goal is to share the store with Nix.
583
584 @node Running the Test Suite
585 @section Running the Test Suite
586
587 After a successful @command{configure} and @code{make} run, it is a good
588 idea to run the test suite. It can help catch issues with the setup or
589 environment, or bugs in Guix itself---and really, reporting test
590 failures is a good way to help improve the software. To run the test
591 suite, type:
592
593 @example
594 make check
595 @end example
596
597 Test cases can run in parallel: you can use the @code{-j} option of
598 GNU@tie{}make to speed things up. The first run may take a few minutes
599 on a recent machine; subsequent runs will be faster because the store
600 that is created for test purposes will already have various things in
601 cache.
602
603 It is also possible to run a subset of the tests by defining the
604 @code{TESTS} makefile variable as in this example:
605
606 @example
607 make check TESTS="tests/store.scm tests/cpio.scm"
608 @end example
609
610 By default, tests results are displayed at a file level. In order to
611 see the details of every individual test cases, it is possible to define
612 the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
613
614 @example
615 make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
616 @end example
617
618 Upon failure, please email @email{bug-guix@@gnu.org} and attach the
619 @file{test-suite.log} file. Please specify the Guix version being used
620 as well as version numbers of the dependencies (@pxref{Requirements}) in
621 your message.
622
623 @node Setting Up the Daemon
624 @section Setting Up the Daemon
625
626 @cindex daemon
627 Operations such as building a package or running the garbage collector
628 are all performed by a specialized process, the @dfn{build daemon}, on
629 behalf of clients. Only the daemon may access the store and its
630 associated database. Thus, any operation that manipulates the store
631 goes through the daemon. For instance, command-line tools such as
632 @command{guix package} and @command{guix build} communicate with the
633 daemon (@i{via} remote procedure calls) to instruct it what to do.
634
635 The following sections explain how to prepare the build daemon's
636 environment. See also @ref{Substitutes}, for information on how to allow
637 the daemon to download pre-built binaries.
638
639 @menu
640 * Build Environment Setup:: Preparing the isolated build environment.
641 * Daemon Offload Setup:: Offloading builds to remote machines.
642 @end menu
643
644 @node Build Environment Setup
645 @subsection Build Environment Setup
646
647 In a standard multi-user setup, Guix and its daemon---the
648 @command{guix-daemon} program---are installed by the system
649 administrator; @file{/gnu/store} is owned by @code{root} and
650 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
651 Guix tools to build packages or otherwise access the store, and the
652 daemon will do it on their behalf, ensuring that the store is kept in a
653 consistent state, and allowing built packages to be shared among users.
654
655 @cindex build users
656 When @command{guix-daemon} runs as @code{root}, you may not want package
657 build processes themselves to run as @code{root} too, for obvious
658 security reasons. To avoid that, a special pool of @dfn{build users}
659 should be created for use by build processes started by the daemon.
660 These build users need not have a shell and a home directory: they will
661 just be used when the daemon drops @code{root} privileges in build
662 processes. Having several such users allows the daemon to launch
663 distinct build processes under separate UIDs, which guarantees that they
664 do not interfere with each other---an essential feature since builds are
665 regarded as pure functions (@pxref{Introduction}).
666
667 On a GNU/Linux system, a build user pool may be created like this (using
668 Bash syntax and the @code{shadow} commands):
669
670 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
671 @c for why `-G' is needed.
672 @example
673 # groupadd --system guixbuild
674 # for i in `seq -w 1 10`;
675 do
676 useradd -g guixbuild -G guixbuild \
677 -d /var/empty -s `which nologin` \
678 -c "Guix build user $i" --system \
679 guixbuilder$i;
680 done
681 @end example
682
683 @noindent
684 The number of build users determines how many build jobs may run in
685 parallel, as specified by the @option{--max-jobs} option
686 (@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
687 @code{guix-daemon} program may then be run as @code{root} with the
688 following command@footnote{If your machine uses the systemd init system,
689 dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
690 file in @file{/etc/systemd/system} will ensure that
691 @command{guix-daemon} is automatically started. Similarly, if your
692 machine uses the Upstart init system, drop the
693 @file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
694 file in @file{/etc/init}.}:
695
696 @example
697 # guix-daemon --build-users-group=guixbuild
698 @end example
699
700 @cindex chroot
701 @noindent
702 This way, the daemon starts build processes in a chroot, under one of
703 the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
704 environment contains nothing but:
705
706 @c Keep this list in sync with libstore/build.cc! -----------------------
707 @itemize
708 @item
709 a minimal @code{/dev} directory, created mostly independently from the
710 host @code{/dev}@footnote{``Mostly'', because while the set of files
711 that appear in the chroot's @code{/dev} is fixed, most of these files
712 can only be created if the host has them.};
713
714 @item
715 the @code{/proc} directory; it only shows the processes of the container
716 since a separate PID name space is used;
717
718 @item
719 @file{/etc/passwd} with an entry for the current user and an entry for
720 user @file{nobody};
721
722 @item
723 @file{/etc/group} with an entry for the user's group;
724
725 @item
726 @file{/etc/hosts} with an entry that maps @code{localhost} to
727 @code{127.0.0.1};
728
729 @item
730 a writable @file{/tmp} directory.
731 @end itemize
732
733 You can influence the directory where the daemon stores build trees
734 @i{via} the @code{TMPDIR} environment variable. However, the build tree
735 within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
736 where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
737 This way, the value of @code{TMPDIR} does not leak inside build
738 environments, which avoids discrepancies in cases where build processes
739 capture the name of their build tree.
740
741 @vindex http_proxy
742 The daemon also honors the @code{http_proxy} environment variable for
743 HTTP downloads it performs, be it for fixed-output derivations
744 (@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
745
746 If you are installing Guix as an unprivileged user, it is still possible
747 to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
748 However, build processes will not be isolated from one another, and not
749 from the rest of the system. Thus, build processes may interfere with
750 each other, and may access programs, libraries, and other files
751 available on the system---making it much harder to view them as
752 @emph{pure} functions.
753
754
755 @node Daemon Offload Setup
756 @subsection Using the Offload Facility
757
758 @cindex offloading
759 @cindex build hook
760 When desired, the build daemon can @dfn{offload}
761 derivation builds to other machines
762 running Guix, using the @code{offload} @dfn{build hook}. When that
763 feature is enabled, a list of user-specified build machines is read from
764 @file{/etc/guix/machines.scm}; every time a build is requested, for
765 instance via @code{guix build}, the daemon attempts to offload it to one
766 of the machines that satisfy the constraints of the derivation, in
767 particular its system type---e.g., @file{x86_64-linux}. Missing
768 prerequisites for the build are copied over SSH to the target machine,
769 which then proceeds with the build; upon success the output(s) of the
770 build are copied back to the initial machine.
771
772 The @file{/etc/guix/machines.scm} file typically looks like this:
773
774 @example
775 (list (build-machine
776 (name "eightysix.example.org")
777 (system "x86_64-linux")
778 (user "bob")
779 (speed 2.)) ; incredibly fast!
780
781 (build-machine
782 (name "meeps.example.org")
783 (system "mips64el-linux")
784 (user "alice")
785 (private-key
786 (string-append (getenv "HOME")
787 "/.lsh/identity-for-guix"))))
788 @end example
789
790 @noindent
791 In the example above we specify a list of two build machines, one for
792 the @code{x86_64} architecture and one for the @code{mips64el}
793 architecture.
794
795 In fact, this file is---not surprisingly!---a Scheme file that is
796 evaluated when the @code{offload} hook is started. Its return value
797 must be a list of @code{build-machine} objects. While this example
798 shows a fixed list of build machines, one could imagine, say, using
799 DNS-SD to return a list of potential build machines discovered in the
800 local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
801 Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
802 detailed below.
803
804 @deftp {Data Type} build-machine
805 This data type represents build machines to which the daemon may offload
806 builds. The important fields are:
807
808 @table @code
809
810 @item name
811 The host name of the remote machine.
812
813 @item system
814 The system type of the remote machine---e.g., @code{"x86_64-linux"}.
815
816 @item user
817 The user account to use when connecting to the remote machine over SSH.
818 Note that the SSH key pair must @emph{not} be passphrase-protected, to
819 allow non-interactive logins.
820
821 @end table
822
823 A number of optional fields may be specified:
824
825 @table @code
826
827 @item port
828 Port number of SSH server on the machine (default: 22).
829
830 @item private-key
831 The SSH private key file to use when connecting to the machine.
832
833 Currently offloading uses GNU@tie{}lsh as its SSH client
834 (@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
835 be an lsh key file. This may change in the future, though.
836
837 @item parallel-builds
838 The number of builds that may run in parallel on the machine (1 by
839 default.)
840
841 @item speed
842 A ``relative speed factor''. The offload scheduler will tend to prefer
843 machines with a higher speed factor.
844
845 @item features
846 A list of strings denoting specific features supported by the machine.
847 An example is @code{"kvm"} for machines that have the KVM Linux modules
848 and corresponding hardware support. Derivations can request features by
849 name, and they will be scheduled on matching build machines.
850
851 @end table
852 @end deftp
853
854 The @code{guix} command must be in the search path on the build
855 machines, since offloading works by invoking the @code{guix archive} and
856 @code{guix build} commands. In addition, the Guix modules must be in
857 @code{$GUILE_LOAD_PATH} on the build machine---you can check whether
858 this is the case by running:
859
860 @example
861 lsh build-machine guile -c "'(use-modules (guix config))'"
862 @end example
863
864 There is one last thing to do once @file{machines.scm} is in place. As
865 explained above, when offloading, files are transferred back and forth
866 between the machine stores. For this to work, you first need to
867 generate a key pair on each machine to allow the daemon to export signed
868 archives of files from the store (@pxref{Invoking guix archive}):
869
870 @example
871 # guix archive --generate-key
872 @end example
873
874 @noindent
875 Each build machine must authorize the key of the master machine so that
876 it accepts store items it receives from the master:
877
878 @example
879 # guix archive --authorize < master-public-key.txt
880 @end example
881
882 @noindent
883 Likewise, the master machine must authorize the key of each build machine.
884
885 All the fuss with keys is here to express pairwise mutual trust
886 relations between the master and the build machines. Concretely, when
887 the master receives files from a build machine (and @i{vice versa}), its
888 build daemon can make sure they are genuine, have not been tampered
889 with, and that they are signed by an authorized key.
890
891
892 @node Invoking guix-daemon
893 @section Invoking @command{guix-daemon}
894
895 The @command{guix-daemon} program implements all the functionality to
896 access the store. This includes launching build processes, running the
897 garbage collector, querying the availability of a build result, etc. It
898 is normally run as @code{root} like this:
899
900 @example
901 # guix-daemon --build-users-group=guixbuild
902 @end example
903
904 @noindent
905 For details on how to set it up, @pxref{Setting Up the Daemon}.
906
907 @cindex chroot
908 @cindex container, build environment
909 @cindex build environment
910 @cindex reproducible builds
911 By default, @command{guix-daemon} launches build processes under
912 different UIDs, taken from the build group specified with
913 @code{--build-users-group}. In addition, each build process is run in a
914 chroot environment that only contains the subset of the store that the
915 build process depends on, as specified by its derivation
916 (@pxref{Programming Interface, derivation}), plus a set of specific
917 system directories. By default, the latter contains @file{/dev} and
918 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
919 @dfn{container}: in addition to having its own file system tree, it has
920 a separate mount name space, its own PID name space, network name space,
921 etc. This helps achieve reproducible builds (@pxref{Features}).
922
923 When the daemon performs a build on behalf of the user, it creates a
924 build directory under @file{/tmp} or under the directory specified by
925 its @code{TMPDIR} environment variable; this directory is shared with
926 the container for the duration of the build. Be aware that using a
927 directory other than @file{/tmp} can affect build results---for example,
928 with a longer directory name, a build process that uses Unix-domain
929 sockets might hit the name length limitation for @code{sun_path}, which
930 it would otherwise not hit.
931
932 The build directory is automatically deleted upon completion, unless the
933 build failed and the client specified @option{--keep-failed}
934 (@pxref{Invoking guix build, @option{--keep-failed}}).
935
936 The following command-line options are supported:
937
938 @table @code
939 @item --build-users-group=@var{group}
940 Take users from @var{group} to run build processes (@pxref{Setting Up
941 the Daemon, build users}).
942
943 @item --no-substitutes
944 @cindex substitutes
945 Do not use substitutes for build products. That is, always build things
946 locally instead of allowing downloads of pre-built binaries
947 (@pxref{Substitutes}).
948
949 By default substitutes are used, unless the client---such as the
950 @command{guix package} command---is explicitly invoked with
951 @code{--no-substitutes}.
952
953 When the daemon runs with @code{--no-substitutes}, clients can still
954 explicitly enable substitution @i{via} the @code{set-build-options}
955 remote procedure call (@pxref{The Store}).
956
957 @item --substitute-urls=@var{urls}
958 @anchor{daemon-substitute-urls}
959 Consider @var{urls} the default whitespace-separated list of substitute
960 source URLs. When this option is omitted,
961 @indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
962 (@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
963
964 This means that substitutes may be downloaded from @var{urls}, as long
965 as they are signed by a trusted signature (@pxref{Substitutes}).
966
967 @cindex build hook
968 @item --no-build-hook
969 Do not use the @dfn{build hook}.
970
971 The build hook is a helper program that the daemon can start and to
972 which it submits build requests. This mechanism is used to offload
973 builds to other machines (@pxref{Daemon Offload Setup}).
974
975 @item --cache-failures
976 Cache build failures. By default, only successful builds are cached.
977
978 When this option is used, @command{guix gc --list-failures} can be used
979 to query the set of store items marked as failed; @command{guix gc
980 --clear-failures} removes store items from the set of cached failures.
981 @xref{Invoking guix gc}.
982
983 @item --cores=@var{n}
984 @itemx -c @var{n}
985 Use @var{n} CPU cores to build each derivation; @code{0} means as many
986 as available.
987
988 The default value is @code{0}, but it may be overridden by clients, such
989 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
990 guix build}).
991
992 The effect is to define the @code{NIX_BUILD_CORES} environment variable
993 in the build process, which can then use it to exploit internal
994 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
995
996 @item --max-jobs=@var{n}
997 @itemx -M @var{n}
998 Allow at most @var{n} build jobs in parallel. The default value is
999 @code{1}. Setting it to @code{0} means that no builds will be performed
1000 locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1001 Setup}), or simply fail.
1002
1003 @item --rounds=@var{N}
1004 Build each derivation @var{n} times in a row, and raise an error if
1005 consecutive build results are not bit-for-bit identical. Note that this
1006 setting can be overridden by clients such as @command{guix build}
1007 (@pxref{Invoking guix build}).
1008
1009 When used in conjunction with @option{--keep-failed}, the differing
1010 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1011 This makes it easy to look for differences between the two results.
1012
1013 @item --debug
1014 Produce debugging output.
1015
1016 This is useful to debug daemon start-up issues, but then it may be
1017 overridden by clients, for example the @code{--verbosity} option of
1018 @command{guix build} (@pxref{Invoking guix build}).
1019
1020 @item --chroot-directory=@var{dir}
1021 Add @var{dir} to the build chroot.
1022
1023 Doing this may change the result of build processes---for instance if
1024 they use optional dependencies found in @var{dir} when it is available,
1025 and not otherwise. For that reason, it is not recommended to do so.
1026 Instead, make sure that each derivation declares all the inputs that it
1027 needs.
1028
1029 @item --disable-chroot
1030 Disable chroot builds.
1031
1032 Using this option is not recommended since, again, it would allow build
1033 processes to gain access to undeclared dependencies. It is necessary,
1034 though, when @command{guix-daemon} is running under an unprivileged user
1035 account.
1036
1037 @item --disable-log-compression
1038 Disable compression of the build logs.
1039
1040 Unless @code{--lose-logs} is used, all the build logs are kept in the
1041 @var{localstatedir}. To save space, the daemon automatically compresses
1042 them with bzip2 by default. This option disables that.
1043
1044 @item --disable-deduplication
1045 @cindex deduplication
1046 Disable automatic file ``deduplication'' in the store.
1047
1048 By default, files added to the store are automatically ``deduplicated'':
1049 if a newly added file is identical to another one found in the store,
1050 the daemon makes the new file a hard link to the other file. This can
1051 noticeably reduce disk usage, at the expense of slightly increased
1052 input/output load at the end of a build process. This option disables
1053 this optimization.
1054
1055 @item --gc-keep-outputs[=yes|no]
1056 Tell whether the garbage collector (GC) must keep outputs of live
1057 derivations.
1058
1059 When set to ``yes'', the GC will keep the outputs of any live derivation
1060 available in the store---the @code{.drv} files. The default is ``no'',
1061 meaning that derivation outputs are kept only if they are GC roots.
1062
1063 @item --gc-keep-derivations[=yes|no]
1064 Tell whether the garbage collector (GC) must keep derivations
1065 corresponding to live outputs.
1066
1067 When set to ``yes'', as is the case by default, the GC keeps
1068 derivations---i.e., @code{.drv} files---as long as at least one of their
1069 outputs is live. This allows users to keep track of the origins of
1070 items in their store. Setting it to ``no'' saves a bit of disk space.
1071
1072 Note that when both @code{--gc-keep-derivations} and
1073 @code{--gc-keep-outputs} are used, the effect is to keep all the build
1074 prerequisites (the sources, compiler, libraries, and other build-time
1075 tools) of live objects in the store, regardless of whether these
1076 prerequisites are live. This is convenient for developers since it
1077 saves rebuilds or downloads.
1078
1079 @item --impersonate-linux-2.6
1080 On Linux-based systems, impersonate Linux 2.6. This means that the
1081 kernel's @code{uname} system call will report 2.6 as the release number.
1082
1083 This might be helpful to build programs that (usually wrongfully) depend
1084 on the kernel version number.
1085
1086 @item --lose-logs
1087 Do not keep build logs. By default they are kept under
1088 @code{@var{localstatedir}/guix/log}.
1089
1090 @item --system=@var{system}
1091 Assume @var{system} as the current system type. By default it is the
1092 architecture/kernel pair found at configure time, such as
1093 @code{x86_64-linux}.
1094
1095 @item --listen=@var{socket}
1096 Listen for connections on @var{socket}, the file name of a Unix-domain
1097 socket. The default socket is
1098 @file{@var{localstatedir}/daemon-socket/socket}. This option is only
1099 useful in exceptional circumstances, such as if you need to run several
1100 daemons on the same machine.
1101 @end table
1102
1103
1104 @node Application Setup
1105 @section Application Setup
1106
1107 @cindex foreign distro
1108 When using Guix on top of GNU/Linux distribution other than GuixSD---a
1109 so-called @dfn{foreign distro}---a few additional steps are needed to
1110 get everything in place. Here are some of them.
1111
1112 @subsection Locales
1113
1114 @anchor{locales-and-locpath}
1115 @cindex locales, when not on GuixSD
1116 @vindex LOCPATH
1117 @vindex GUIX_LOCPATH
1118 Packages installed @i{via} Guix will not use the locale data of the
1119 host system. Instead, you must first install one of the locale packages
1120 available with Guix and then define the @code{GUIX_LOCPATH} environment
1121 variable:
1122
1123 @example
1124 $ guix package -i glibc-locales
1125 $ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
1126 @end example
1127
1128 Note that the @code{glibc-locales} package contains data for all the
1129 locales supported by the GNU@tie{}libc and weighs in at around
1130 110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
1131 limited to a few UTF-8 locales.
1132
1133 The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1134 (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1135 Manual}). There are two important differences though:
1136
1137 @enumerate
1138 @item
1139 @code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
1140 provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
1141 to make sure the programs of the foreign distro will not end up loading
1142 incompatible locale data.
1143
1144 @item
1145 libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1146 @code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1147 should your Guix profile contain a mixture of programs linked against
1148 different libc version, each libc version will only try to load locale
1149 data in the right format.
1150 @end enumerate
1151
1152 This is important because the locale data format used by different libc
1153 versions may be incompatible.
1154
1155 @subsection X11 Fonts
1156
1157 The majority of graphical applications use Fontconfig to locate and
1158 load fonts and perform X11-client-side rendering. The @code{fontconfig}
1159 package in Guix looks for fonts in @file{$HOME/.guix-profile}
1160 by default. Thus, to allow graphical applications installed with Guix
1161 to display fonts, you have to install fonts with Guix as well.
1162 Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
1163 @code{font-gnu-freefont-ttf}.
1164
1165 To display text written in Chinese languages, Japanese, or Korean in
1166 graphical applications, consider installing
1167 @code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1168 has multiple outputs, one per language family (@pxref{Packages with
1169 Multiple Outputs}). For instance, the following command installs fonts
1170 for Chinese languages:
1171
1172 @example
1173 guix package -i font-adobe-source-han-sans:cn
1174 @end example
1175
1176 @subsection X.509 Certificates
1177
1178 The @code{nss-certs} package provides X.509 certificates, which allow
1179 programs to authenticate Web servers accessed over HTTPS.
1180
1181 When using Guix on a foreign distro, you can install this package and
1182 define the relevant environment variables so that packages know where to
1183 look for certificates. @pxref{X.509 Certificates}, for detailed
1184 information.
1185
1186 @subsection Emacs Packages
1187
1188 When you install Emacs packages with Guix, the elisp files may be placed
1189 either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1190 sub-directories of
1191 @file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1192 directory exists because potentially there may exist thousands of Emacs
1193 packages and storing all their files in a single directory may be not
1194 reliable (because of name conflicts). So we think using a separate
1195 directory for each package is a good idea. It is very similar to how
1196 the Emacs package system organizes the file structure (@pxref{Package
1197 Files,,, emacs, The GNU Emacs Manual}).
1198
1199 By default, Emacs (installed with Guix) ``knows'' where these packages
1200 are placed, so you do not need to perform any configuration. If, for
1201 some reason, you want to avoid auto-loading Emacs packages installed
1202 with Guix, you can do so by running Emacs with @code{--no-site-file}
1203 option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1204
1205 @c TODO What else?
1206
1207 @c *********************************************************************
1208 @node Package Management
1209 @chapter Package Management
1210
1211 The purpose of GNU Guix is to allow users to easily install, upgrade, and
1212 remove software packages, without having to know about their build
1213 procedures or dependencies. Guix also goes beyond this obvious set of
1214 features.
1215
1216 This chapter describes the main features of Guix, as well as the package
1217 management tools it provides. Two user interfaces are provided for
1218 routine package management tasks: A command-line interface described below
1219 (@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1220 interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
1221
1222 @menu
1223 * Features:: How Guix will make your life brighter.
1224 * Invoking guix package:: Package installation, removal, etc.
1225 * Substitutes:: Downloading pre-built binaries.
1226 * Packages with Multiple Outputs:: Single source package, multiple outputs.
1227 * Invoking guix gc:: Running the garbage collector.
1228 * Invoking guix pull:: Fetching the latest Guix and distribution.
1229 * Invoking guix archive:: Exporting and importing store files.
1230 @end menu
1231
1232 @node Features
1233 @section Features
1234
1235 When using Guix, each package ends up in the @dfn{package store}, in its
1236 own directory---something that resembles
1237 @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1238 (note that Guix comes with an Emacs extension to shorten those file
1239 names, @pxref{Emacs Prettify}.)
1240
1241 Instead of referring to these directories, users have their own
1242 @dfn{profile}, which points to the packages that they actually want to
1243 use. These profiles are stored within each user's home directory, at
1244 @code{$HOME/.guix-profile}.
1245
1246 For example, @code{alice} installs GCC 4.7.2. As a result,
1247 @file{/home/alice/.guix-profile/bin/gcc} points to
1248 @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
1249 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1250 simply continues to point to
1251 @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
1252 coexist on the same system without any interference.
1253
1254 The @command{guix package} command is the central tool to manage
1255 packages (@pxref{Invoking guix package}). It operates on the per-user
1256 profiles, and can be used @emph{with normal user privileges}.
1257
1258 The command provides the obvious install, remove, and upgrade
1259 operations. Each invocation is actually a @emph{transaction}: either
1260 the specified operation succeeds, or nothing happens. Thus, if the
1261 @command{guix package} process is terminated during the transaction,
1262 or if a power outage occurs during the transaction, then the user's
1263 profile remains in its previous state, and remains usable.
1264
1265 In addition, any package transaction may be @emph{rolled back}. So, if,
1266 for example, an upgrade installs a new version of a package that turns
1267 out to have a serious bug, users may roll back to the previous instance
1268 of their profile, which was known to work well. Similarly, the global
1269 system configuration on GuixSD is subject to
1270 transactional upgrades and roll-back
1271 (@pxref{Using the Configuration System}).
1272
1273 All packages in the package store may be @emph{garbage-collected}.
1274 Guix can determine which packages are still referenced by user
1275 profiles, and remove those that are provably no longer referenced
1276 (@pxref{Invoking guix gc}). Users may also explicitly remove old
1277 generations of their profile so that the packages they refer to can be
1278 collected.
1279
1280 @cindex reproducibility
1281 @cindex reproducible builds
1282 Finally, Guix takes a @dfn{purely functional} approach to package
1283 management, as described in the introduction (@pxref{Introduction}).
1284 Each @file{/gnu/store} package directory name contains a hash of all the
1285 inputs that were used to build that package---compiler, libraries, build
1286 scripts, etc. This direct correspondence allows users to make sure a
1287 given package installation matches the current state of their
1288 distribution. It also helps maximize @dfn{build reproducibility}:
1289 thanks to the isolated build environments that are used, a given build
1290 is likely to yield bit-identical files when performed on different
1291 machines (@pxref{Invoking guix-daemon, container}).
1292
1293 @cindex substitutes
1294 This foundation allows Guix to support @dfn{transparent binary/source
1295 deployment}. When a pre-built binary for a @file{/gnu/store} item is
1296 available from an external source---a @dfn{substitute}, Guix just
1297 downloads it and unpacks it;
1298 otherwise, it builds the package from source, locally
1299 (@pxref{Substitutes}). Because build results are usually bit-for-bit
1300 reproducible, users do not have to trust servers that provide
1301 substitutes: they can force a local build and @emph{challenge} providers
1302 (@pxref{Invoking guix challenge}).
1303
1304 Control over the build environment is a feature that is also useful for
1305 developers. The @command{guix environment} command allows developers of
1306 a package to quickly set up the right development environment for their
1307 package, without having to manually install the dependencies of the
1308 package into their profile (@pxref{Invoking guix environment}).
1309
1310 @node Invoking guix package
1311 @section Invoking @command{guix package}
1312
1313 The @command{guix package} command is the tool that allows users to
1314 install, upgrade, and remove packages, as well as rolling back to
1315 previous configurations. It operates only on the user's own profile,
1316 and works with normal user privileges (@pxref{Features}). Its syntax
1317 is:
1318
1319 @example
1320 guix package @var{options}
1321 @end example
1322
1323 Primarily, @var{options} specifies the operations to be performed during
1324 the transaction. Upon completion, a new profile is created, but
1325 previous @dfn{generations} of the profile remain available, should the user
1326 want to roll back.
1327
1328 For example, to remove @code{lua} and install @code{guile} and
1329 @code{guile-cairo} in a single transaction:
1330
1331 @example
1332 guix package -r lua -i guile guile-cairo
1333 @end example
1334
1335 @command{guix package} also supports a @dfn{declarative approach}
1336 whereby the user specifies the exact set of packages to be available and
1337 passes it @i{via} the @option{--manifest} option
1338 (@pxref{profile-manifest, @option{--manifest}}).
1339
1340 For each user, a symlink to the user's default profile is automatically
1341 created in @file{$HOME/.guix-profile}. This symlink always points to the
1342 current generation of the user's default profile. Thus, users can add
1343 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1344 variable, and so on.
1345 @cindex search paths
1346 If you are not using the Guix System Distribution, consider adding the
1347 following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1348 Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1349 shells get all the right environment variable definitions:
1350
1351 @example
1352 GUIX_PROFILE="$HOME/.guix-profile" \
1353 source "$HOME/.guix-profile/etc/profile"
1354 @end example
1355
1356 In a multi-user setup, user profiles are stored in a place registered as
1357 a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1358 to (@pxref{Invoking guix gc}). That directory is normally
1359 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1360 @var{localstatedir} is the value passed to @code{configure} as
1361 @code{--localstatedir}, and @var{user} is the user name. The
1362 @file{per-user} directory is created when @command{guix-daemon} is
1363 started, and the @var{user} sub-directory is created by @command{guix
1364 package}.
1365
1366 The @var{options} can be among the following:
1367
1368 @table @code
1369
1370 @item --install=@var{package} @dots{}
1371 @itemx -i @var{package} @dots{}
1372 Install the specified @var{package}s.
1373
1374 Each @var{package} may specify either a simple package name, such as
1375 @code{guile}, or a package name followed by an at-sign and version number,
1376 such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
1377 case, the newest version prefixed by @code{1.8} is selected.)
1378
1379 If no version number is specified, the
1380 newest available version will be selected. In addition, @var{package}
1381 may contain a colon, followed by the name of one of the outputs of the
1382 package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
1383 (@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1384 name (and optionally version) are searched for among the GNU
1385 distribution modules (@pxref{Package Modules}).
1386
1387 @cindex propagated inputs
1388 Sometimes packages have @dfn{propagated inputs}: these are dependencies
1389 that automatically get installed along with the required package
1390 (@pxref{package-propagated-inputs, @code{propagated-inputs} in
1391 @code{package} objects}, for information about propagated inputs in
1392 package definitions).
1393
1394 @anchor{package-cmd-propagated-inputs}
1395 An example is the GNU MPC library: its C header files refer to those of
1396 the GNU MPFR library, which in turn refer to those of the GMP library.
1397 Thus, when installing MPC, the MPFR and GMP libraries also get installed
1398 in the profile; removing MPC also removes MPFR and GMP---unless they had
1399 also been explicitly installed by the user.
1400
1401 Besides, packages sometimes rely on the definition of environment
1402 variables for their search paths (see explanation of
1403 @code{--search-paths} below). Any missing or possibly incorrect
1404 environment variable definitions are reported here.
1405
1406 @item --install-from-expression=@var{exp}
1407 @itemx -e @var{exp}
1408 Install the package @var{exp} evaluates to.
1409
1410 @var{exp} must be a Scheme expression that evaluates to a
1411 @code{<package>} object. This option is notably useful to disambiguate
1412 between same-named variants of a package, with expressions such as
1413 @code{(@@ (gnu packages base) guile-final)}.
1414
1415 Note that this option installs the first output of the specified
1416 package, which may be insufficient when needing a specific output of a
1417 multiple-output package.
1418
1419 @item --install-from-file=@var{file}
1420 @itemx -f @var{file}
1421 Install the package that the code within @var{file} evaluates to.
1422
1423 As an example, @var{file} might contain a definition like this
1424 (@pxref{Defining Packages}):
1425
1426 @example
1427 @verbatiminclude package-hello.scm
1428 @end example
1429
1430 Developers may find it useful to include such a @file{guix.scm} file
1431 in the root of their project source tree that can be used to test
1432 development snapshots and create reproducible development environments
1433 (@pxref{Invoking guix environment}).
1434
1435 @item --remove=@var{package} @dots{}
1436 @itemx -r @var{package} @dots{}
1437 Remove the specified @var{package}s.
1438
1439 As for @code{--install}, each @var{package} may specify a version number
1440 and/or output name in addition to the package name. For instance,
1441 @code{-r glibc:debug} would remove the @code{debug} output of
1442 @code{glibc}.
1443
1444 @item --upgrade[=@var{regexp} @dots{}]
1445 @itemx -u [@var{regexp} @dots{}]
1446 Upgrade all the installed packages. If one or more @var{regexp}s are
1447 specified, upgrade only installed packages whose name matches a
1448 @var{regexp}. Also see the @code{--do-not-upgrade} option below.
1449
1450 Note that this upgrades package to the latest version of packages found
1451 in the distribution currently installed. To update your distribution,
1452 you should regularly run @command{guix pull} (@pxref{Invoking guix
1453 pull}).
1454
1455 @item --do-not-upgrade[=@var{regexp} @dots{}]
1456 When used together with the @code{--upgrade} option, do @emph{not}
1457 upgrade any packages whose name matches a @var{regexp}. For example, to
1458 upgrade all packages in the current profile except those containing the
1459 substring ``emacs'':
1460
1461 @example
1462 $ guix package --upgrade . --do-not-upgrade emacs
1463 @end example
1464
1465 @item @anchor{profile-manifest}--manifest=@var{file}
1466 @itemx -m @var{file}
1467 @cindex profile declaration
1468 @cindex profile manifest
1469 Create a new generation of the profile from the manifest object
1470 returned by the Scheme code in @var{file}.
1471
1472 This allows you to @emph{declare} the profile's contents rather than
1473 constructing it through a sequence of @code{--install} and similar
1474 commands. The advantage is that @var{file} can be put under version
1475 control, copied to different machines to reproduce the same profile, and
1476 so on.
1477
1478 @c FIXME: Add reference to (guix profile) documentation when available.
1479 @var{file} must return a @dfn{manifest} object, which is roughly a list
1480 of packages:
1481
1482 @findex packages->manifest
1483 @example
1484 (use-package-modules guile emacs)
1485
1486 (packages->manifest
1487 (list emacs
1488 guile-2.0
1489 ;; Use a specific package output.
1490 (list guile-2.0 "debug")))
1491 @end example
1492
1493 @item --roll-back
1494 Roll back to the previous @dfn{generation} of the profile---i.e., undo
1495 the last transaction.
1496
1497 When combined with options such as @code{--install}, roll back occurs
1498 before any other actions.
1499
1500 When rolling back from the first generation that actually contains
1501 installed packages, the profile is made to point to the @dfn{zeroth
1502 generation}, which contains no files apart from its own metadata.
1503
1504 After having rolled back, installing, removing, or upgrading packages
1505 overwrites previous future generations. Thus, the history of the
1506 generations in a profile is always linear.
1507
1508 @item --switch-generation=@var{pattern}
1509 @itemx -S @var{pattern}
1510 Switch to a particular generation defined by @var{pattern}.
1511
1512 @var{pattern} may be either a generation number or a number prefixed
1513 with ``+'' or ``-''. The latter means: move forward/backward by a
1514 specified number of generations. For example, if you want to return to
1515 the latest generation after @code{--roll-back}, use
1516 @code{--switch-generation=+1}.
1517
1518 The difference between @code{--roll-back} and
1519 @code{--switch-generation=-1} is that @code{--switch-generation} will
1520 not make a zeroth generation, so if a specified generation does not
1521 exist, the current generation will not be changed.
1522
1523 @item --search-paths[=@var{kind}]
1524 @cindex search paths
1525 Report environment variable definitions, in Bash syntax, that may be
1526 needed in order to use the set of installed packages. These environment
1527 variables are used to specify @dfn{search paths} for files used by some
1528 of the installed packages.
1529
1530 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1531 environment variables to be defined so it can look for headers and
1532 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1533 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1534 library are installed in the profile, then @code{--search-paths} will
1535 suggest setting these variables to @code{@var{profile}/include} and
1536 @code{@var{profile}/lib}, respectively.
1537
1538 The typical use case is to define these environment variables in the
1539 shell:
1540
1541 @example
1542 $ eval `guix package --search-paths`
1543 @end example
1544
1545 @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1546 meaning that the returned environment variable definitions will either
1547 be exact settings, or prefixes or suffixes of the current value of these
1548 variables. When omitted, @var{kind} defaults to @code{exact}.
1549
1550 This option can also be used to compute the @emph{combined} search paths
1551 of several profiles. Consider this example:
1552
1553 @example
1554 $ guix package -p foo -i guile
1555 $ guix package -p bar -i guile-json
1556 $ guix package -p foo -p bar --search-paths
1557 @end example
1558
1559 The last command above reports about the @code{GUILE_LOAD_PATH}
1560 variable, even though, taken individually, neither @file{foo} nor
1561 @file{bar} would lead to that recommendation.
1562
1563
1564 @item --profile=@var{profile}
1565 @itemx -p @var{profile}
1566 Use @var{profile} instead of the user's default profile.
1567
1568 @item --verbose
1569 Produce verbose output. In particular, emit the build log of the
1570 environment on the standard error port.
1571
1572 @item --bootstrap
1573 Use the bootstrap Guile to build the profile. This option is only
1574 useful to distribution developers.
1575
1576 @end table
1577
1578 In addition to these actions, @command{guix package} supports the
1579 following options to query the current state of a profile, or the
1580 availability of packages:
1581
1582 @table @option
1583
1584 @item --search=@var{regexp}
1585 @itemx -s @var{regexp}
1586 @cindex searching for packages
1587 List the available packages whose name, synopsis, or description matches
1588 @var{regexp}. Print all the metadata of matching packages in
1589 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1590 GNU recutils manual}).
1591
1592 This allows specific fields to be extracted using the @command{recsel}
1593 command, for instance:
1594
1595 @example
1596 $ guix package -s malloc | recsel -p name,version
1597 name: glibc
1598 version: 2.17
1599
1600 name: libgc
1601 version: 7.2alpha6
1602 @end example
1603
1604 Similarly, to show the name of all the packages available under the
1605 terms of the GNU@tie{}LGPL version 3:
1606
1607 @example
1608 $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1609 name: elfutils
1610
1611 name: gmp
1612 @dots{}
1613 @end example
1614
1615 It is also possible to refine search results using several @code{-s}
1616 flags. For example, the following command returns a list of board
1617 games:
1618
1619 @example
1620 $ guix package -s '\<board\>' -s game | recsel -p name
1621 name: gnubg
1622 @dots{}
1623 @end example
1624
1625 If we were to omit @code{-s game}, we would also get software packages
1626 that deal with printed circuit boards; removing the angle brackets
1627 around @code{board} would further add packages that have to do with
1628 keyboards.
1629
1630 And now for a more elaborate example. The following command searches
1631 for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1632 libraries, and prints the name and synopsis of the matching packages:
1633
1634 @example
1635 $ guix package -s crypto -s library | \
1636 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1637 @end example
1638
1639 @noindent
1640 @xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1641 information on @dfn{selection expressions} for @code{recsel -e}.
1642
1643 @item --show=@var{package}
1644 Show details about @var{package}, taken from the list of available packages, in
1645 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1646 recutils manual}).
1647
1648 @example
1649 $ guix package --show=python | recsel -p name,version
1650 name: python
1651 version: 2.7.6
1652
1653 name: python
1654 version: 3.3.5
1655 @end example
1656
1657 You may also specify the full name of a package to only get details about a
1658 specific version of it:
1659 @example
1660 $ guix package --show=python-3.3.5 | recsel -p name,version
1661 name: python
1662 version: 3.3.5
1663 @end example
1664
1665
1666
1667 @item --list-installed[=@var{regexp}]
1668 @itemx -I [@var{regexp}]
1669 List the currently installed packages in the specified profile, with the
1670 most recently installed packages shown last. When @var{regexp} is
1671 specified, list only installed packages whose name matches @var{regexp}.
1672
1673 For each installed package, print the following items, separated by
1674 tabs: the package name, its version string, the part of the package that
1675 is installed (for instance, @code{out} for the default output,
1676 @code{include} for its headers, etc.), and the path of this package in
1677 the store.
1678
1679 @item --list-available[=@var{regexp}]
1680 @itemx -A [@var{regexp}]
1681 List packages currently available in the distribution for this system
1682 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1683 installed packages whose name matches @var{regexp}.
1684
1685 For each package, print the following items separated by tabs: its name,
1686 its version string, the parts of the package (@pxref{Packages with
1687 Multiple Outputs}), and the source location of its definition.
1688
1689 @item --list-generations[=@var{pattern}]
1690 @itemx -l [@var{pattern}]
1691 Return a list of generations along with their creation dates; for each
1692 generation, show the installed packages, with the most recently
1693 installed packages shown last. Note that the zeroth generation is never
1694 shown.
1695
1696 For each installed package, print the following items, separated by
1697 tabs: the name of a package, its version string, the part of the package
1698 that is installed (@pxref{Packages with Multiple Outputs}), and the
1699 location of this package in the store.
1700
1701 When @var{pattern} is used, the command returns only matching
1702 generations. Valid patterns include:
1703
1704 @itemize
1705 @item @emph{Integers and comma-separated integers}. Both patterns denote
1706 generation numbers. For instance, @code{--list-generations=1} returns
1707 the first one.
1708
1709 And @code{--list-generations=1,8,2} outputs three generations in the
1710 specified order. Neither spaces nor trailing commas are allowed.
1711
1712 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
1713 specified generations and everything in between. Note that the start of
1714 a range must be smaller than its end.
1715
1716 It is also possible to omit the endpoint. For example,
1717 @code{--list-generations=2..}, returns all generations starting from the
1718 second one.
1719
1720 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1721 or months by passing an integer along with the first letter of the
1722 duration. For example, @code{--list-generations=20d} lists generations
1723 that are up to 20 days old.
1724 @end itemize
1725
1726 @item --delete-generations[=@var{pattern}]
1727 @itemx -d [@var{pattern}]
1728 When @var{pattern} is omitted, delete all generations except the current
1729 one.
1730
1731 This command accepts the same patterns as @option{--list-generations}.
1732 When @var{pattern} is specified, delete the matching generations. When
1733 @var{pattern} specifies a duration, generations @emph{older} than the
1734 specified duration match. For instance, @code{--delete-generations=1m}
1735 deletes generations that are more than one month old.
1736
1737 If the current generation matches, it is @emph{not} deleted. Also, the
1738 zeroth generation is never deleted.
1739
1740 Note that deleting generations prevents rolling back to them.
1741 Consequently, this command must be used with care.
1742
1743 @end table
1744
1745 Finally, since @command{guix package} may actually start build
1746 processes, it supports all the common build options (@pxref{Common Build
1747 Options}). It also supports package transformation options, such as
1748 @option{--with-source} (@pxref{Package Transformation Options}).
1749 However, note that package transformations are lost when upgrading; to
1750 preserve transformations across upgrades, you should define your own
1751 package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1752 (@pxref{Defining Packages}).
1753
1754
1755 @node Substitutes
1756 @section Substitutes
1757
1758 @cindex substitutes
1759 @cindex pre-built binaries
1760 Guix supports transparent source/binary deployment, which means that it
1761 can either build things locally, or download pre-built items from a
1762 server. We call these pre-built items @dfn{substitutes}---they are
1763 substitutes for local build results. In many cases, downloading a
1764 substitute is much faster than building things locally.
1765
1766 Substitutes can be anything resulting from a derivation build
1767 (@pxref{Derivations}). Of course, in the common case, they are
1768 pre-built package binaries, but source tarballs, for instance, which
1769 also result from derivation builds, can be available as substitutes.
1770
1771 The @code{hydra.gnu.org} server is a front-end to a build farm that
1772 builds packages from the GNU distribution continuously for some
1773 architectures, and makes them available as substitutes (@pxref{Emacs
1774 Hydra}, for information on how to query the continuous integration
1775 server). This is the
1776 default source of substitutes; it can be overridden by passing the
1777 @option{--substitute-urls} option either to @command{guix-daemon}
1778 (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1779 or to client tools such as @command{guix package}
1780 (@pxref{client-substitute-urls,, client @option{--substitute-urls}
1781 option}).
1782
1783 Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1784 the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
1785 HTTPS is recommended because communications are encrypted; conversely,
1786 using HTTP makes all communications visible to an eavesdropper, who
1787 could use the information gathered to determine, for instance, whether
1788 your system has unpatched security vulnerabilities.
1789
1790 @cindex security
1791 @cindex digital signatures
1792 To allow Guix to download substitutes from @code{hydra.gnu.org} or a
1793 mirror thereof, you
1794 must add its public key to the access control list (ACL) of archive
1795 imports, using the @command{guix archive} command (@pxref{Invoking guix
1796 archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1797 be compromised and to serve genuine substitutes.
1798
1799 This public key is installed along with Guix, in
1800 @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1801 the installation prefix of Guix. If you installed Guix from source,
1802 make sure you checked the GPG signature of
1803 @file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1804 Then, you can run something like this:
1805
1806 @example
1807 # guix archive --authorize < hydra.gnu.org.pub
1808 @end example
1809
1810 Once this is in place, the output of a command like @code{guix build}
1811 should change from something like:
1812
1813 @example
1814 $ guix build emacs --dry-run
1815 The following derivations would be built:
1816 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1817 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1818 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1819 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1820 @dots{}
1821 @end example
1822
1823 @noindent
1824 to something like:
1825
1826 @example
1827 $ guix build emacs --dry-run
1828 The following files would be downloaded:
1829 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1830 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1831 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1832 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1833 @dots{}
1834 @end example
1835
1836 @noindent
1837 This indicates that substitutes from @code{hydra.gnu.org} are usable and
1838 will be downloaded, when possible, for future builds.
1839
1840 Guix ignores substitutes that are not signed, or that are not signed by
1841 one of the keys listed in the ACL. It also detects and raises an error
1842 when attempting to use a substitute that has been tampered with.
1843
1844 @vindex http_proxy
1845 Substitutes are downloaded over HTTP or HTTPS.
1846 The @code{http_proxy} environment
1847 variable can be set in the environment of @command{guix-daemon} and is
1848 honored for downloads of substitutes. Note that the value of
1849 @code{http_proxy} in the environment where @command{guix build},
1850 @command{guix package}, and other client commands are run has
1851 @emph{absolutely no effect}.
1852
1853 When using HTTPS, the server's X.509 certificate is @emph{not} validated
1854 (in other words, the server is not authenticated), contrary to what
1855 HTTPS clients such as Web browsers usually do. This is because Guix
1856 authenticates substitute information itself, as explained above, which
1857 is what we care about (whereas X.509 certificates are about
1858 authenticating bindings between domain names and public keys.)
1859
1860 The substitute mechanism can be disabled globally by running
1861 @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1862 guix-daemon}). It can also be disabled temporarily by passing the
1863 @code{--no-substitutes} option to @command{guix package}, @command{guix
1864 build}, and other command-line tools.
1865
1866
1867 @unnumberedsubsec On Trusting Binaries
1868
1869 Today, each individual's control over their own computing is at the
1870 mercy of institutions, corporations, and groups with enough power and
1871 determination to subvert the computing infrastructure and exploit its
1872 weaknesses. While using @code{hydra.gnu.org} substitutes can be
1873 convenient, we encourage users to also build on their own, or even run
1874 their own build farm, such that @code{hydra.gnu.org} is less of an
1875 interesting target. One way to help is by publishing the software you
1876 build using @command{guix publish} so that others have one more choice
1877 of server to download substitutes from (@pxref{Invoking guix publish}).
1878
1879 Guix has the foundations to maximize build reproducibility
1880 (@pxref{Features}). In most cases, independent builds of a given
1881 package or derivation should yield bit-identical results. Thus, through
1882 a diverse set of independent package builds, we can strengthen the
1883 integrity of our systems. The @command{guix challenge} command aims to
1884 help users assess substitute servers, and to assist developers in
1885 finding out about non-deterministic package builds (@pxref{Invoking guix
1886 challenge}). Similarly, the @option{--check} option of @command{guix
1887 build} allows users to check whether previously-installed substitutes
1888 are genuine by rebuilding them locally (@pxref{build-check,
1889 @command{guix build --check}}).
1890
1891 In the future, we want Guix to have support to publish and retrieve
1892 binaries to/from other users, in a peer-to-peer fashion. If you would
1893 like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1894
1895
1896 @node Packages with Multiple Outputs
1897 @section Packages with Multiple Outputs
1898
1899 @cindex multiple-output packages
1900 @cindex package outputs
1901
1902 Often, packages defined in Guix have a single @dfn{output}---i.e., the
1903 source package leads to exactly one directory in the store. When running
1904 @command{guix package -i glibc}, one installs the default output of the
1905 GNU libc package; the default output is called @code{out}, but its name
1906 can be omitted as shown in this command. In this particular case, the
1907 default output of @code{glibc} contains all the C header files, shared
1908 libraries, static libraries, Info documentation, and other supporting
1909 files.
1910
1911 Sometimes it is more appropriate to separate the various types of files
1912 produced from a single source package into separate outputs. For
1913 instance, the GLib C library (used by GTK+ and related packages)
1914 installs more than 20 MiB of reference documentation as HTML pages.
1915 To save space for users who do not need it, the documentation goes to a
1916 separate output, called @code{doc}. To install the main GLib output,
1917 which contains everything but the documentation, one would run:
1918
1919 @example
1920 guix package -i glib
1921 @end example
1922
1923 The command to install its documentation is:
1924
1925 @example
1926 guix package -i glib:doc
1927 @end example
1928
1929 Some packages install programs with different ``dependency footprints''.
1930 For instance, the WordNet package installs both command-line tools and
1931 graphical user interfaces (GUIs). The former depend solely on the C
1932 library, whereas the latter depend on Tcl/Tk and the underlying X
1933 libraries. In this case, we leave the command-line tools in the default
1934 output, whereas the GUIs are in a separate output. This allows users
1935 who do not need the GUIs to save space. The @command{guix size} command
1936 can help find out about such situations (@pxref{Invoking guix size}).
1937 @command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
1938
1939 There are several such multiple-output packages in the GNU distribution.
1940 Other conventional output names include @code{lib} for libraries and
1941 possibly header files, @code{bin} for stand-alone programs, and
1942 @code{debug} for debugging information (@pxref{Installing Debugging
1943 Files}). The outputs of a packages are listed in the third column of
1944 the output of @command{guix package --list-available} (@pxref{Invoking
1945 guix package}).
1946
1947
1948 @node Invoking guix gc
1949 @section Invoking @command{guix gc}
1950
1951 @cindex garbage collector
1952 Packages that are installed, but not used, may be @dfn{garbage-collected}.
1953 The @command{guix gc} command allows users to explicitly run the garbage
1954 collector to reclaim space from the @file{/gnu/store} directory. It is
1955 the @emph{only} way to remove files from @file{/gnu/store}---removing
1956 files or directories manually may break it beyond repair!
1957
1958 The garbage collector has a set of known @dfn{roots}: any file under
1959 @file{/gnu/store} reachable from a root is considered @dfn{live} and
1960 cannot be deleted; any other file is considered @dfn{dead} and may be
1961 deleted. The set of garbage collector roots includes default user
1962 profiles, and may be augmented with @command{guix build --root}, for
1963 example (@pxref{Invoking guix build}).
1964
1965 Prior to running @code{guix gc --collect-garbage} to make space, it is
1966 often useful to remove old generations from user profiles; that way, old
1967 package builds referenced by those generations can be reclaimed. This
1968 is achieved by running @code{guix package --delete-generations}
1969 (@pxref{Invoking guix package}).
1970
1971 The @command{guix gc} command has three modes of operation: it can be
1972 used to garbage-collect any dead files (the default), to delete specific
1973 files (the @code{--delete} option), to print garbage-collector
1974 information, or for more advanced queries. The garbage collection
1975 options are as follows:
1976
1977 @table @code
1978 @item --collect-garbage[=@var{min}]
1979 @itemx -C [@var{min}]
1980 Collect garbage---i.e., unreachable @file{/gnu/store} files and
1981 sub-directories. This is the default operation when no option is
1982 specified.
1983
1984 When @var{min} is given, stop once @var{min} bytes have been collected.
1985 @var{min} may be a number of bytes, or it may include a unit as a
1986 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1987 (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
1988
1989 When @var{min} is omitted, collect all the garbage.
1990
1991 @item --free-space=@var{free}
1992 @itemx -F @var{free}
1993 Collect garbage until @var{free} space is available under
1994 @file{/gnu/store}, if possible; @var{free} denotes storage space, such
1995 as @code{500MiB}, as described above.
1996
1997 When @var{free} or more is already available in @file{/gnu/store}, do
1998 nothing and exit immediately.
1999
2000 @item --delete
2001 @itemx -d
2002 Attempt to delete all the store files and directories specified as
2003 arguments. This fails if some of the files are not in the store, or if
2004 they are still live.
2005
2006 @item --list-failures
2007 List store items corresponding to cached build failures.
2008
2009 This prints nothing unless the daemon was started with
2010 @option{--cache-failures} (@pxref{Invoking guix-daemon,
2011 @option{--cache-failures}}).
2012
2013 @item --clear-failures
2014 Remove the specified store items from the failed-build cache.
2015
2016 Again, this option only makes sense when the daemon is started with
2017 @option{--cache-failures}. Otherwise, it does nothing.
2018
2019 @item --list-dead
2020 Show the list of dead files and directories still present in the
2021 store---i.e., files and directories no longer reachable from any root.
2022
2023 @item --list-live
2024 Show the list of live store files and directories.
2025
2026 @end table
2027
2028 In addition, the references among existing store files can be queried:
2029
2030 @table @code
2031
2032 @item --references
2033 @itemx --referrers
2034 List the references (respectively, the referrers) of store files given
2035 as arguments.
2036
2037 @item --requisites
2038 @itemx -R
2039 @cindex closure
2040 List the requisites of the store files passed as arguments. Requisites
2041 include the store files themselves, their references, and the references
2042 of these, recursively. In other words, the returned list is the
2043 @dfn{transitive closure} of the store files.
2044
2045 @xref{Invoking guix size}, for a tool to profile the size of the closure
2046 of an element. @xref{Invoking guix graph}, for a tool to visualize
2047 the graph of references.
2048
2049 @end table
2050
2051 Lastly, the following options allow you to check the integrity of the
2052 store and to control disk usage.
2053
2054 @table @option
2055
2056 @item --verify[=@var{options}]
2057 @cindex integrity, of the store
2058 @cindex integrity checking
2059 Verify the integrity of the store.
2060
2061 By default, make sure that all the store items marked as valid in the
2062 database of the daemon actually exist in @file{/gnu/store}.
2063
2064 When provided, @var{options} must be a comma-separated list containing one
2065 or more of @code{contents} and @code{repair}.
2066
2067 When passing @option{--verify=contents}, the daemon computse the
2068 content hash of each store item and compares it against its hash in the
2069 database. Hash mismatches are reported as data corruptions. Because it
2070 traverses @emph{all the files in the store}, this command can take a
2071 long time, especially on systems with a slow disk drive.
2072
2073 @cindex repairing the store
2074 Using @option{--verify=repair} or @option{--verify=contents,repair}
2075 causes the daemon to try to repair corrupt store items by fetching
2076 substitutes for them (@pxref{Substitutes}). Because repairing is not
2077 atomic, and thus potentially dangerous, it is available only to the
2078 system administrator.
2079
2080 @item --optimize
2081 @cindex deduplication
2082 Optimize the store by hard-linking identical files---this is
2083 @dfn{deduplication}.
2084
2085 The daemon performs deduplication after each successful build or archive
2086 import, unless it was started with @code{--disable-deduplication}
2087 (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2088 this option is primarily useful when the daemon was running with
2089 @code{--disable-deduplication}.
2090
2091 @end table
2092
2093 @node Invoking guix pull
2094 @section Invoking @command{guix pull}
2095
2096 Packages are installed or upgraded to the latest version available in
2097 the distribution currently available on your local machine. To update
2098 that distribution, along with the Guix tools, you must run @command{guix
2099 pull}: the command downloads the latest Guix source code and package
2100 descriptions, and deploys it.
2101
2102 On completion, @command{guix package} will use packages and package
2103 versions from this just-retrieved copy of Guix. Not only that, but all
2104 the Guix commands and Scheme modules will also be taken from that latest
2105 version. New @command{guix} sub-commands added by the update also
2106 become available.
2107
2108 Any user can update their Guix copy using @command{guix pull}, and the
2109 effect is limited to the user who run @command{guix pull}. For
2110 instance, when user @code{root} runs @command{guix pull}, this has no
2111 effect on the version of Guix that user @code{alice} sees, and vice
2112 versa@footnote{Under the hood, @command{guix pull} updates the
2113 @file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2114 and the @command{guix} command loads code from there.}.
2115
2116 The @command{guix pull} command is usually invoked with no arguments,
2117 but it supports the following options:
2118
2119 @table @code
2120 @item --verbose
2121 Produce verbose output, writing build logs to the standard error output.
2122
2123 @item --url=@var{url}
2124 Download the source tarball of Guix from @var{url}.
2125
2126 By default, the tarball is taken from its canonical address at
2127 @code{gnu.org}, for the stable branch of Guix.
2128
2129 @item --bootstrap
2130 Use the bootstrap Guile to build the latest Guix. This option is only
2131 useful to Guix developers.
2132 @end table
2133
2134
2135 @node Invoking guix archive
2136 @section Invoking @command{guix archive}
2137
2138 The @command{guix archive} command allows users to @dfn{export} files
2139 from the store into a single archive, and to later @dfn{import} them.
2140 In particular, it allows store files to be transferred from one machine
2141 to the store on another machine.
2142
2143 To export store files as an archive to standard output, run:
2144
2145 @example
2146 guix archive --export @var{options} @var{specifications}...
2147 @end example
2148
2149 @var{specifications} may be either store file names or package
2150 specifications, as for @command{guix package} (@pxref{Invoking guix
2151 package}). For instance, the following command creates an archive
2152 containing the @code{gui} output of the @code{git} package and the main
2153 output of @code{emacs}:
2154
2155 @example
2156 guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2157 @end example
2158
2159 If the specified packages are not built yet, @command{guix archive}
2160 automatically builds them. The build process may be controlled with the
2161 common build options (@pxref{Common Build Options}).
2162
2163 To transfer the @code{emacs} package to a machine connected over SSH,
2164 one would run:
2165
2166 @example
2167 guix archive --export -r emacs | ssh the-machine guix archive --import
2168 @end example
2169
2170 @noindent
2171 Similarly, a complete user profile may be transferred from one machine
2172 to another like this:
2173
2174 @example
2175 guix archive --export -r $(readlink -f ~/.guix-profile) | \
2176 ssh the-machine guix-archive --import
2177 @end example
2178
2179 @noindent
2180 However, note that, in both examples, all of @code{emacs} and the
2181 profile as well as all of their dependencies are transferred (due to
2182 @code{-r}), regardless of what is already available in the store on the
2183 target machine. The @code{--missing} option can help figure out which
2184 items are missing from the target store.
2185
2186 Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
2187 comparable in spirit to `tar', but with a few noteworthy differences
2188 that make it more appropriate for our purposes. First, rather than
2189 recording all Unix metadata for each file, the Nar format only mentions
2190 the file type (regular, directory, or symbolic link); Unix permissions
2191 and owner/group are dismissed. Second, the order in which directory
2192 entries are stored always follows the order of file names according to
2193 the C locale collation order. This makes archive production fully
2194 deterministic.
2195
2196 When exporting, the daemon digitally signs the contents of the archive,
2197 and that digital signature is appended. When importing, the daemon
2198 verifies the signature and rejects the import in case of an invalid
2199 signature or if the signing key is not authorized.
2200 @c FIXME: Add xref to daemon doc about signatures.
2201
2202 The main options are:
2203
2204 @table @code
2205 @item --export
2206 Export the specified store files or packages (see below.) Write the
2207 resulting archive to the standard output.
2208
2209 Dependencies are @emph{not} included in the output, unless
2210 @code{--recursive} is passed.
2211
2212 @item -r
2213 @itemx --recursive
2214 When combined with @code{--export}, this instructs @command{guix
2215 archive} to include dependencies of the given items in the archive.
2216 Thus, the resulting archive is self-contained: it contains the closure
2217 of the exported store items.
2218
2219 @item --import
2220 Read an archive from the standard input, and import the files listed
2221 therein into the store. Abort if the archive has an invalid digital
2222 signature, or if it is signed by a public key not among the authorized
2223 keys (see @code{--authorize} below.)
2224
2225 @item --missing
2226 Read a list of store file names from the standard input, one per line,
2227 and write on the standard output the subset of these files missing from
2228 the store.
2229
2230 @item --generate-key[=@var{parameters}]
2231 @cindex signing, archives
2232 Generate a new key pair for the daemon. This is a prerequisite before
2233 archives can be exported with @code{--export}. Note that this operation
2234 usually takes time, because it needs to gather enough entropy to
2235 generate the key pair.
2236
2237 The generated key pair is typically stored under @file{/etc/guix}, in
2238 @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
2239 key, which must be kept secret.) When @var{parameters} is omitted,
2240 an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2241 versions before 1.6.0, it is a 4096-bit RSA key.
2242 Alternatively, @var{parameters} can specify
2243 @code{genkey} parameters suitable for Libgcrypt (@pxref{General
2244 public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2245 Libgcrypt Reference Manual}).
2246
2247 @item --authorize
2248 @cindex authorizing, archives
2249 Authorize imports signed by the public key passed on standard input.
2250 The public key must be in ``s-expression advanced format''---i.e., the
2251 same format as the @file{signing-key.pub} file.
2252
2253 The list of authorized keys is kept in the human-editable file
2254 @file{/etc/guix/acl}. The file contains
2255 @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2256 s-expressions''} and is structured as an access-control list in the
2257 @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2258 (SPKI)}.
2259
2260 @item --extract=@var{directory}
2261 @itemx -x @var{directory}
2262 Read a single-item archive as served by substitute servers
2263 (@pxref{Substitutes}) and extract it to @var{directory}. This is a
2264 low-level operation needed in only very narrow use cases; see below.
2265
2266 For example, the following command extracts the substitute for Emacs
2267 served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2268
2269 @example
2270 $ wget -O - \
2271 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2272 | bunzip2 | guix archive -x /tmp/emacs
2273 @end example
2274
2275 Single-item archives are different from multiple-item archives produced
2276 by @command{guix archive --export}; they contain a single store item,
2277 and they do @emph{not} embed a signature. Thus this operation does
2278 @emph{no} signature verification and its output should be considered
2279 unsafe.
2280
2281 The primary purpose of this operation is to facilitate inspection of
2282 archive contents coming from possibly untrusted substitute servers.
2283
2284 @end table
2285
2286 @c *********************************************************************
2287 @include emacs.texi
2288
2289 @c *********************************************************************
2290 @node Programming Interface
2291 @chapter Programming Interface
2292
2293 GNU Guix provides several Scheme programming interfaces (APIs) to
2294 define, build, and query packages. The first interface allows users to
2295 write high-level package definitions. These definitions refer to
2296 familiar packaging concepts, such as the name and version of a package,
2297 its build system, and its dependencies. These definitions can then be
2298 turned into concrete build actions.
2299
2300 Build actions are performed by the Guix daemon, on behalf of users. In a
2301 standard setup, the daemon has write access to the store---the
2302 @file{/gnu/store} directory---whereas users do not. The recommended
2303 setup also has the daemon perform builds in chroots, under a specific
2304 build users, to minimize interference with the rest of the system.
2305
2306 @cindex derivation
2307 Lower-level APIs are available to interact with the daemon and the
2308 store. To instruct the daemon to perform a build action, users actually
2309 provide it with a @dfn{derivation}. A derivation is a low-level
2310 representation of the build actions to be taken, and the environment in
2311 which they should occur---derivations are to package definitions what
2312 assembly is to C programs. The term ``derivation'' comes from the fact
2313 that build results @emph{derive} from them.
2314
2315 This chapter describes all these APIs in turn, starting from high-level
2316 package definitions.
2317
2318 @menu
2319 * Defining Packages:: Defining new packages.
2320 * Build Systems:: Specifying how packages are built.
2321 * The Store:: Manipulating the package store.
2322 * Derivations:: Low-level interface to package derivations.
2323 * The Store Monad:: Purely functional interface to the store.
2324 * G-Expressions:: Manipulating build expressions.
2325 @end menu
2326
2327 @node Defining Packages
2328 @section Defining Packages
2329
2330 The high-level interface to package definitions is implemented in the
2331 @code{(guix packages)} and @code{(guix build-system)} modules. As an
2332 example, the package definition, or @dfn{recipe}, for the GNU Hello
2333 package looks like this:
2334
2335 @example
2336 (define-module (gnu packages hello)
2337 #:use-module (guix packages)
2338 #:use-module (guix download)
2339 #:use-module (guix build-system gnu)
2340 #:use-module (guix licenses)
2341 #:use-module (gnu packages gawk))
2342
2343 (define-public hello
2344 (package
2345 (name "hello")
2346 (version "2.10")
2347 (source (origin
2348 (method url-fetch)
2349 (uri (string-append "mirror://gnu/hello/hello-" version
2350 ".tar.gz"))
2351 (sha256
2352 (base32
2353 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
2354 (build-system gnu-build-system)
2355 (arguments `(#:configure-flags '("--enable-silent-rules")))
2356 (inputs `(("gawk" ,gawk)))
2357 (synopsis "Hello, GNU world: An example GNU package")
2358 (description "Guess what GNU Hello prints!")
2359 (home-page "http://www.gnu.org/software/hello/")
2360 (license gpl3+)))
2361 @end example
2362
2363 @noindent
2364 Without being a Scheme expert, the reader may have guessed the meaning
2365 of the various fields here. This expression binds the variable
2366 @code{hello} to a @code{<package>} object, which is essentially a record
2367 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2368 This package object can be inspected using procedures found in the
2369 @code{(guix packages)} module; for instance, @code{(package-name hello)}
2370 returns---surprise!---@code{"hello"}.
2371
2372 With luck, you may be able to import part or all of the definition of
2373 the package you are interested in from another repository, using the
2374 @code{guix import} command (@pxref{Invoking guix import}).
2375
2376 In the example above, @var{hello} is defined in a module of its own,
2377 @code{(gnu packages hello)}. Technically, this is not strictly
2378 necessary, but it is convenient to do so: all the packages defined in
2379 modules under @code{(gnu packages @dots{})} are automatically known to
2380 the command-line tools (@pxref{Package Modules}).
2381
2382 There are a few points worth noting in the above package definition:
2383
2384 @itemize
2385 @item
2386 The @code{source} field of the package is an @code{<origin>} object
2387 (@pxref{origin Reference}, for the complete reference).
2388 Here, the @code{url-fetch} method from @code{(guix download)} is used,
2389 meaning that the source is a file to be downloaded over FTP or HTTP.
2390
2391 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2392 the GNU mirrors defined in @code{(guix download)}.
2393
2394 The @code{sha256} field specifies the expected SHA256 hash of the file
2395 being downloaded. It is mandatory, and allows Guix to check the
2396 integrity of the file. The @code{(base32 @dots{})} form introduces the
2397 base32 representation of the hash. You can obtain this information with
2398 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
2399 hash} (@pxref{Invoking guix hash}).
2400
2401 @cindex patches
2402 When needed, the @code{origin} form can also have a @code{patches} field
2403 listing patches to be applied, and a @code{snippet} field giving a
2404 Scheme expression to modify the source code.
2405
2406 @item
2407 @cindex GNU Build System
2408 The @code{build-system} field specifies the procedure to build the
2409 package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2410 represents the familiar GNU Build System, where packages may be
2411 configured, built, and installed with the usual @code{./configure &&
2412 make && make check && make install} command sequence.
2413
2414 @item
2415 The @code{arguments} field specifies options for the build system
2416 (@pxref{Build Systems}). Here it is interpreted by
2417 @var{gnu-build-system} as a request run @file{configure} with the
2418 @code{--enable-silent-rules} flag.
2419
2420 @item
2421 The @code{inputs} field specifies inputs to the build process---i.e.,
2422 build-time or run-time dependencies of the package. Here, we define an
2423 input called @code{"gawk"} whose value is that of the @var{gawk}
2424 variable; @var{gawk} is itself bound to a @code{<package>} object.
2425
2426 Note that GCC, Coreutils, Bash, and other essential tools do not need to
2427 be specified as inputs here. Instead, @var{gnu-build-system} takes care
2428 of ensuring that they are present (@pxref{Build Systems}).
2429
2430 However, any other dependencies need to be specified in the
2431 @code{inputs} field. Any dependency not specified here will simply be
2432 unavailable to the build process, possibly leading to a build failure.
2433 @end itemize
2434
2435 @xref{package Reference}, for a full description of possible fields.
2436
2437 Once a package definition is in place, the
2438 package may actually be built using the @code{guix build} command-line
2439 tool (@pxref{Invoking guix build}). You can easily jump back to the
2440 package definition using the @command{guix edit} command
2441 (@pxref{Invoking guix edit}).
2442 @xref{Packaging Guidelines}, for
2443 more information on how to test package definitions, and
2444 @ref{Invoking guix lint}, for information on how to check a definition
2445 for style conformance.
2446
2447 Finally, updating the package definition to a new upstream version
2448 can be partly automated by the @command{guix refresh} command
2449 (@pxref{Invoking guix refresh}).
2450
2451 Behind the scenes, a derivation corresponding to the @code{<package>}
2452 object is first computed by the @code{package-derivation} procedure.
2453 That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
2454 The build actions it prescribes may then be realized by using the
2455 @code{build-derivations} procedure (@pxref{The Store}).
2456
2457 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
2458 Return the @code{<derivation>} object of @var{package} for @var{system}
2459 (@pxref{Derivations}).
2460
2461 @var{package} must be a valid @code{<package>} object, and @var{system}
2462 must be a string denoting the target system type---e.g.,
2463 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2464 must be a connection to the daemon, which operates on the store
2465 (@pxref{The Store}).
2466 @end deffn
2467
2468 @noindent
2469 @cindex cross-compilation
2470 Similarly, it is possible to compute a derivation that cross-builds a
2471 package for some other system:
2472
2473 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
2474 @var{package} @var{target} [@var{system}]
2475 Return the @code{<derivation>} object of @var{package} cross-built from
2476 @var{system} to @var{target}.
2477
2478 @var{target} must be a valid GNU triplet denoting the target hardware
2479 and operating system, such as @code{"mips64el-linux-gnu"}
2480 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2481 Configure and Build System}).
2482 @end deffn
2483
2484 @menu
2485 * package Reference :: The package data type.
2486 * origin Reference:: The origin data type.
2487 @end menu
2488
2489
2490 @node package Reference
2491 @subsection @code{package} Reference
2492
2493 This section summarizes all the options available in @code{package}
2494 declarations (@pxref{Defining Packages}).
2495
2496 @deftp {Data Type} package
2497 This is the data type representing a package recipe.
2498
2499 @table @asis
2500 @item @code{name}
2501 The name of the package, as a string.
2502
2503 @item @code{version}
2504 The version of the package, as a string.
2505
2506 @item @code{source}
2507 An object telling how the source code for the package should be
2508 acquired. Most of the time, this is an @code{origin} object, which
2509 denotes a file fetched from the Internet (@pxref{origin Reference}). It
2510 can also be any other ``file-like'' object such as a @code{local-file},
2511 which denotes a file from the local file system (@pxref{G-Expressions,
2512 @code{local-file}}).
2513
2514 @item @code{build-system}
2515 The build system that should be used to build the package (@pxref{Build
2516 Systems}).
2517
2518 @item @code{arguments} (default: @code{'()})
2519 The arguments that should be passed to the build system. This is a
2520 list, typically containing sequential keyword-value pairs.
2521
2522 @item @code{inputs} (default: @code{'()})
2523 @itemx @code{native-inputs} (default: @code{'()})
2524 @itemx @code{propagated-inputs} (default: @code{'()})
2525 @cindex inputs, of packages
2526 These fields list dependencies of the package. Each one is a list of
2527 tuples, where each tuple has a label for the input (a string) as its
2528 first element, a package, origin, or derivation as its second element,
2529 and optionally the name of the output thereof that should be used, which
2530 defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
2531 more on package outputs). For example, the list below specifies three
2532 inputs:
2533
2534 @example
2535 `(("libffi" ,libffi)
2536 ("libunistring" ,libunistring)
2537 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2538 @end example
2539
2540 @cindex cross compilation, package dependencies
2541 The distinction between @code{native-inputs} and @code{inputs} is
2542 necessary when considering cross-compilation. When cross-compiling,
2543 dependencies listed in @code{inputs} are built for the @emph{target}
2544 architecture; conversely, dependencies listed in @code{native-inputs}
2545 are built for the architecture of the @emph{build} machine.
2546
2547 @code{native-inputs} is typically used to list tools needed at
2548 build time, but not at run time, such as Autoconf, Automake, pkg-config,
2549 Gettext, or Bison. @command{guix lint} can report likely mistakes in
2550 this area (@pxref{Invoking guix lint}).
2551
2552 @anchor{package-propagated-inputs}
2553 Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
2554 specified packages will be automatically installed alongside the package
2555 they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
2556 package}}, for information on how @command{guix package} deals with
2557 propagated inputs.)
2558
2559 For example this is necessary when a C/C++ library needs headers of
2560 another library to compile, or when a pkg-config file refers to another
2561 one @i{via} its @code{Requires} field.
2562
2563 Another example where @code{propagated-inputs} is useful is for languages
2564 that lack a facility to record the run-time search path akin to the
2565 @code{RUNPATH} of ELF files; this includes Guile, Python, Perl, GHC, and
2566 more. To ensure that libraries written in those languages can find
2567 library code they depend on at run time, run-time dependencies must be
2568 listed in @code{propagated-inputs} rather than @code{inputs}.
2569
2570 @item @code{self-native-input?} (default: @code{#f})
2571 This is a Boolean field telling whether the package should use itself as
2572 a native input when cross-compiling.
2573
2574 @item @code{outputs} (default: @code{'("out")})
2575 The list of output names of the package. @xref{Packages with Multiple
2576 Outputs}, for typical uses of additional outputs.
2577
2578 @item @code{native-search-paths} (default: @code{'()})
2579 @itemx @code{search-paths} (default: @code{'()})
2580 A list of @code{search-path-specification} objects describing
2581 search-path environment variables honored by the package.
2582
2583 @item @code{replacement} (default: @code{#f})
2584 This must be either @code{#f} or a package object that will be used as a
2585 @dfn{replacement} for this package. @xref{Security Updates, grafts},
2586 for details.
2587
2588 @item @code{synopsis}
2589 A one-line description of the package.
2590
2591 @item @code{description}
2592 A more elaborate description of the package.
2593
2594 @item @code{license}
2595 The license of the package; a value from @code{(guix licenses)},
2596 or a list of such values.
2597
2598 @item @code{home-page}
2599 The URL to the home-page of the package, as a string.
2600
2601 @item @code{supported-systems} (default: @var{%supported-systems})
2602 The list of systems supported by the package, as strings of the form
2603 @code{architecture-kernel}, for example @code{"x86_64-linux"}.
2604
2605 @item @code{maintainers} (default: @code{'()})
2606 The list of maintainers of the package, as @code{maintainer} objects.
2607
2608 @item @code{location} (default: source location of the @code{package} form)
2609 The source location of the package. It is useful to override this when
2610 inheriting from another package, in which case this field is not
2611 automatically corrected.
2612 @end table
2613 @end deftp
2614
2615
2616 @node origin Reference
2617 @subsection @code{origin} Reference
2618
2619 This section summarizes all the options available in @code{origin}
2620 declarations (@pxref{Defining Packages}).
2621
2622 @deftp {Data Type} origin
2623 This is the data type representing a source code origin.
2624
2625 @table @asis
2626 @item @code{uri}
2627 An object containing the URI of the source. The object type depends on
2628 the @code{method} (see below). For example, when using the
2629 @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2630 values are: a URL represented as a string, or a list thereof.
2631
2632 @item @code{method}
2633 A procedure that handles the URI.
2634
2635 Examples include:
2636
2637 @table @asis
2638 @item @var{url-fetch} from @code{(guix download)}
2639 download a file from the HTTP, HTTPS, or FTP URL specified in the
2640 @code{uri} field;
2641
2642 @item @var{git-fetch} from @code{(guix git-download)}
2643 clone the Git version control repository, and check out the revision
2644 specified in the @code{uri} field as a @code{git-reference} object; a
2645 @code{git-reference} looks like this:
2646
2647 @example
2648 (git-reference
2649 (url "git://git.debian.org/git/pkg-shadow/shadow")
2650 (commit "v4.1.5.1"))
2651 @end example
2652 @end table
2653
2654 @item @code{sha256}
2655 A bytevector containing the SHA-256 hash of the source. Typically the
2656 @code{base32} form is used here to generate the bytevector from a
2657 base-32 string.
2658
2659 @item @code{file-name} (default: @code{#f})
2660 The file name under which the source code should be saved. When this is
2661 @code{#f}, a sensible default value will be used in most cases. In case
2662 the source is fetched from a URL, the file name from the URL will be
2663 used. For version control checkouts, it is recommended to provide the
2664 file name explicitly because the default is not very descriptive.
2665
2666 @item @code{patches} (default: @code{'()})
2667 A list of file names containing patches to be applied to the source.
2668
2669 @item @code{snippet} (default: @code{#f})
2670 A quoted piece of code that will be run in the source directory to make
2671 any modifications, which is sometimes more convenient than a patch.
2672
2673 @item @code{patch-flags} (default: @code{'("-p1")})
2674 A list of command-line flags that should be passed to the @code{patch}
2675 command.
2676
2677 @item @code{patch-inputs} (default: @code{#f})
2678 Input packages or derivations to the patching process. When this is
2679 @code{#f}, the usual set of inputs necessary for patching are provided,
2680 such as GNU@tie{}Patch.
2681
2682 @item @code{modules} (default: @code{'()})
2683 A list of Guile modules that should be loaded during the patching
2684 process and while running the code in the @code{snippet} field.
2685
2686 @item @code{imported-modules} (default: @code{'()})
2687 The list of Guile modules to import in the patch derivation, for use by
2688 the @code{snippet}.
2689
2690 @item @code{patch-guile} (default: @code{#f})
2691 The Guile package that should be used in the patching process. When
2692 this is @code{#f}, a sensible default is used.
2693 @end table
2694 @end deftp
2695
2696
2697 @node Build Systems
2698 @section Build Systems
2699
2700 @cindex build system
2701 Each package definition specifies a @dfn{build system} and arguments for
2702 that build system (@pxref{Defining Packages}). This @code{build-system}
2703 field represents the build procedure of the package, as well as implicit
2704 dependencies of that build procedure.
2705
2706 Build systems are @code{<build-system>} objects. The interface to
2707 create and manipulate them is provided by the @code{(guix build-system)}
2708 module, and actual build systems are exported by specific modules.
2709
2710 @cindex bag (low-level package representation)
2711 Under the hood, build systems first compile package objects to
2712 @dfn{bags}. A @dfn{bag} is like a package, but with less
2713 ornamentation---in other words, a bag is a lower-level representation of
2714 a package, which includes all the inputs of that package, including some
2715 that were implicitly added by the build system. This intermediate
2716 representation is then compiled to a derivation (@pxref{Derivations}).
2717
2718 Build systems accept an optional list of @dfn{arguments}. In package
2719 definitions, these are passed @i{via} the @code{arguments} field
2720 (@pxref{Defining Packages}). They are typically keyword arguments
2721 (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2722 Guile Reference Manual}). The value of these arguments is usually
2723 evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2724 by the daemon (@pxref{Derivations}).
2725
2726 The main build system is @var{gnu-build-system}, which implements the
2727 standard build procedure for GNU and many other packages. It
2728 is provided by the @code{(guix build-system gnu)} module.
2729
2730 @defvr {Scheme Variable} gnu-build-system
2731 @var{gnu-build-system} represents the GNU Build System, and variants
2732 thereof (@pxref{Configuration, configuration and makefile conventions,,
2733 standards, GNU Coding Standards}).
2734
2735 @cindex build phases
2736 In a nutshell, packages using it are configured, built, and installed with
2737 the usual @code{./configure && make && make check && make install}
2738 command sequence. In practice, a few additional steps are often needed.
2739 All these steps are split up in separate @dfn{phases},
2740 notably@footnote{Please see the @code{(guix build gnu-build-system)}
2741 modules for more details about the build phases.}:
2742
2743 @table @code
2744 @item unpack
2745 Unpack the source tarball, and change the current directory to the
2746 extracted source tree. If the source is actually a directory, copy it
2747 to the build tree, and enter that directory.
2748
2749 @item patch-source-shebangs
2750 Patch shebangs encountered in source files so they refer to the right
2751 store file names. For instance, this changes @code{#!/bin/sh} to
2752 @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2753
2754 @item configure
2755 Run the @file{configure} script with a number of default options, such
2756 as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2757 by the @code{#:configure-flags} argument.
2758
2759 @item build
2760 Run @code{make} with the list of flags specified with
2761 @code{#:make-flags}. If the @code{#:parallel-build?} argument is true
2762 (the default), build with @code{make -j}.
2763
2764 @item check
2765 Run @code{make check}, or some other target specified with
2766 @code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2767 @code{#:parallel-tests?} argument is true (the default), run @code{make
2768 check -j}.
2769
2770 @item install
2771 Run @code{make install} with the flags listed in @code{#:make-flags}.
2772
2773 @item patch-shebangs
2774 Patch shebangs on the installed executable files.
2775
2776 @item strip
2777 Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2778 is false), copying them to the @code{debug} output when available
2779 (@pxref{Installing Debugging Files}).
2780 @end table
2781
2782 @vindex %standard-phases
2783 The build-side module @code{(guix build gnu-build-system)} defines
2784 @var{%standard-phases} as the default list of build phases.
2785 @var{%standard-phases} is a list of symbol/procedure pairs, where the
2786 procedure implements the actual phase.
2787
2788 The list of phases used for a particular package can be changed with the
2789 @code{#:phases} parameter. For instance, passing:
2790
2791 @example
2792 #:phases (modify-phases %standard-phases (delete 'configure))
2793 @end example
2794
2795 means that all the phases described above will be used, except the
2796 @code{configure} phase.
2797
2798 In addition, this build system ensures that the ``standard'' environment
2799 for GNU packages is available. This includes tools such as GCC, libc,
2800 Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2801 build-system gnu)} module for a complete list). We call these the
2802 @dfn{implicit inputs} of a package, because package definitions do not
2803 have to mention them.
2804 @end defvr
2805
2806 Other @code{<build-system>} objects are defined to support other
2807 conventions and tools used by free software packages. They inherit most
2808 of @var{gnu-build-system}, and differ mainly in the set of inputs
2809 implicitly added to the build process, and in the list of phases
2810 executed. Some of these build systems are listed below.
2811
2812 @defvr {Scheme Variable} ant-build-system
2813 This variable is exported by @code{(guix build-system ant)}. It
2814 implements the build procedure for Java packages that can be built with
2815 @url{http://ant.apache.org/, Ant build tool}.
2816
2817 It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
2818 provided by the @code{icedtea} package to the set of inputs. Different
2819 packages can be specified with the @code{#:ant} and @code{#:jdk}
2820 parameters, respectively.
2821
2822 When the original package does not provide a suitable Ant build file,
2823 the parameter @code{#:jar-name} can be used to generate a minimal Ant
2824 build file @file{build.xml} with tasks to build the specified jar
2825 archive.
2826
2827 The parameter @code{#:build-target} can be used to specify the Ant task
2828 that should be run during the @code{build} phase. By default the
2829 ``jar'' task will be run.
2830
2831 @end defvr
2832
2833 @defvr {Scheme Variable} cmake-build-system
2834 This variable is exported by @code{(guix build-system cmake)}. It
2835 implements the build procedure for packages using the
2836 @url{http://www.cmake.org, CMake build tool}.
2837
2838 It automatically adds the @code{cmake} package to the set of inputs.
2839 Which package is used can be specified with the @code{#:cmake}
2840 parameter.
2841
2842 The @code{#:configure-flags} parameter is taken as a list of flags
2843 passed to the @command{cmake} command. The @code{#:build-type}
2844 parameter specifies in abstract terms the flags passed to the compiler;
2845 it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2846 debugging information''), which roughly means that code is compiled with
2847 @code{-O2 -g}, as is the case for Autoconf-based packages by default.
2848 @end defvr
2849
2850 @defvr {Scheme Variable} glib-or-gtk-build-system
2851 This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2852 is intended for use with packages making use of GLib or GTK+.
2853
2854 This build system adds the following two phases to the ones defined by
2855 @var{gnu-build-system}:
2856
2857 @table @code
2858 @item glib-or-gtk-wrap
2859 The phase @code{glib-or-gtk-wrap} ensures that programs in
2860 @file{bin/} are able to find GLib ``schemas'' and
2861 @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2862 modules}. This is achieved by wrapping the programs in launch scripts
2863 that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2864 environment variables.
2865
2866 It is possible to exclude specific package outputs from that wrapping
2867 process by listing their names in the
2868 @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2869 when an output is known not to contain any GLib or GTK+ binaries, and
2870 where wrapping would gratuitously add a dependency of that output on
2871 GLib and GTK+.
2872
2873 @item glib-or-gtk-compile-schemas
2874 The phase @code{glib-or-gtk-compile-schemas} makes sure that all
2875 @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2876 GSettings schemas} of GLib are compiled. Compilation is performed by the
2877 @command{glib-compile-schemas} program. It is provided by the package
2878 @code{glib:bin} which is automatically imported by the build system.
2879 The @code{glib} package providing @command{glib-compile-schemas} can be
2880 specified with the @code{#:glib} parameter.
2881 @end table
2882
2883 Both phases are executed after the @code{install} phase.
2884 @end defvr
2885
2886 @defvr {Scheme Variable} python-build-system
2887 This variable is exported by @code{(guix build-system python)}. It
2888 implements the more or less standard build procedure used by Python
2889 packages, which consists in running @code{python setup.py build} and
2890 then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2891
2892 For packages that install stand-alone Python programs under @code{bin/},
2893 it takes care of wrapping these programs so that their @code{PYTHONPATH}
2894 environment variable points to all the Python libraries they depend on.
2895
2896 Which Python package is used to perform the build can be specified with
2897 the @code{#:python} parameter. This is a useful way to force a package
2898 to be built for a specific version of the Python interpreter, which
2899 might be necessary if the package is only compatible with a single
2900 interpreter version.
2901 @end defvr
2902
2903 @defvr {Scheme Variable} perl-build-system
2904 This variable is exported by @code{(guix build-system perl)}. It
2905 implements the standard build procedure for Perl packages, which either
2906 consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2907 followed by @code{Build} and @code{Build install}; or in running
2908 @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2909 @code{make} and @code{make install}, depending on which of
2910 @code{Build.PL} or @code{Makefile.PL} is present in the package
2911 distribution. Preference is given to the former if both @code{Build.PL}
2912 and @code{Makefile.PL} exist in the package distribution. This
2913 preference can be reversed by specifying @code{#t} for the
2914 @code{#:make-maker?} parameter.
2915
2916 The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2917 passes flags specified by the @code{#:make-maker-flags} or
2918 @code{#:module-build-flags} parameter, respectively.
2919
2920 Which Perl package is used can be specified with @code{#:perl}.
2921 @end defvr
2922
2923 @defvr {Scheme Variable} r-build-system
2924 This variable is exported by @code{(guix build-system r)}. It
2925 implements the build procedure used by @uref{http://r-project.org, R}
2926 packages, which essentially is little more than running @code{R CMD
2927 INSTALL --library=/gnu/store/@dots{}} in an environment where
2928 @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2929 are run after installation using the R function
2930 @code{tools::testInstalledPackage}.
2931 @end defvr
2932
2933 @defvr {Scheme Variable} ruby-build-system
2934 This variable is exported by @code{(guix build-system ruby)}. It
2935 implements the RubyGems build procedure used by Ruby packages, which
2936 involves running @code{gem build} followed by @code{gem install}.
2937
2938 The @code{source} field of a package that uses this build system
2939 typically references a gem archive, since this is the format that Ruby
2940 developers use when releasing their software. The build system unpacks
2941 the gem archive, potentially patches the source, runs the test suite,
2942 repackages the gem, and installs it. Additionally, directories and
2943 tarballs may be referenced to allow building unreleased gems from Git or
2944 a traditional source release tarball.
2945
2946 Which Ruby package is used can be specified with the @code{#:ruby}
2947 parameter. A list of additional flags to be passed to the @command{gem}
2948 command can be specified with the @code{#:gem-flags} parameter.
2949 @end defvr
2950
2951 @defvr {Scheme Variable} waf-build-system
2952 This variable is exported by @code{(guix build-system waf)}. It
2953 implements a build procedure around the @code{waf} script. The common
2954 phases---@code{configure}, @code{build}, and @code{install}---are
2955 implemented by passing their names as arguments to the @code{waf}
2956 script.
2957
2958 The @code{waf} script is executed by the Python interpreter. Which
2959 Python package is used to run the script can be specified with the
2960 @code{#:python} parameter.
2961 @end defvr
2962
2963 @defvr {Scheme Variable} haskell-build-system
2964 This variable is exported by @code{(guix build-system haskell)}. It
2965 implements the Cabal build procedure used by Haskell packages, which
2966 involves running @code{runhaskell Setup.hs configure
2967 --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2968 Instead of installing the package by running @code{runhaskell Setup.hs
2969 install}, to avoid trying to register libraries in the read-only
2970 compiler store directory, the build system uses @code{runhaskell
2971 Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2972 addition, the build system generates the package documentation by
2973 running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2974 is passed. Optional Haddock parameters can be passed with the help of
2975 the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2976 not found, the build system looks for @code{Setup.lhs} instead.
2977
2978 Which Haskell compiler is used can be specified with the @code{#:haskell}
2979 parameter which defaults to @code{ghc}.
2980 @end defvr
2981
2982 @defvr {Scheme Variable} emacs-build-system
2983 This variable is exported by @code{(guix build-system emacs)}. It
2984 implements an installation procedure similar to the packaging system
2985 of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
2986
2987 It first creates the @code{@var{package}-autoloads.el} file, then it
2988 byte compiles all Emacs Lisp files. Differently from the Emacs
2989 packaging system, the Info documentation files are moved to the standard
2990 documentation directory and the @file{dir} file is deleted. Each
2991 package is installed in its own directory under
2992 @file{share/emacs/site-lisp/guix.d}.
2993 @end defvr
2994
2995 Lastly, for packages that do not need anything as sophisticated, a
2996 ``trivial'' build system is provided. It is trivial in the sense that
2997 it provides basically no support: it does not pull any implicit inputs,
2998 and does not have a notion of build phases.
2999
3000 @defvr {Scheme Variable} trivial-build-system
3001 This variable is exported by @code{(guix build-system trivial)}.
3002
3003 This build system requires a @code{#:builder} argument. This argument
3004 must be a Scheme expression that builds the package output(s)---as
3005 with @code{build-expression->derivation} (@pxref{Derivations,
3006 @code{build-expression->derivation}}).
3007 @end defvr
3008
3009 @node The Store
3010 @section The Store
3011
3012 @cindex store
3013 @cindex store items
3014 @cindex store paths
3015
3016 Conceptually, the @dfn{store} is the place where derivations that have
3017 been built successfully are stored---by default, @file{/gnu/store}.
3018 Sub-directories in the store are referred to as @dfn{store items} or
3019 sometimes @dfn{store paths}. The store has an associated database that
3020 contains information such as the store paths referred to by each store
3021 path, and the list of @emph{valid} store items---results of successful
3022 builds. This database resides in @file{@var{localstatedir}/guix/db},
3023 where @var{localstatedir} is the state directory specified @i{via}
3024 @option{--localstatedir} at configure time, usually @file{/var}.
3025
3026 The store is @emph{always} accessed by the daemon on behalf of its clients
3027 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
3028 connect to the daemon over a Unix-domain socket, send requests to it,
3029 and read the result---these are remote procedure calls, or RPCs.
3030
3031 @quotation Note
3032 Users must @emph{never} modify files under @file{/gnu/store} directly.
3033 This would lead to inconsistencies and break the immutability
3034 assumptions of Guix's functional model (@pxref{Introduction}).
3035
3036 @xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3037 how to check the integrity of the store and attempt recovery from
3038 accidental modifications.
3039 @end quotation
3040
3041 The @code{(guix store)} module provides procedures to connect to the
3042 daemon, and to perform RPCs. These are described below.
3043
3044 @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3045 Connect to the daemon over the Unix-domain socket at @var{file}. When
3046 @var{reserve-space?} is true, instruct it to reserve a little bit of
3047 extra space on the file system so that the garbage collector can still
3048 operate should the disk become full. Return a server object.
3049
3050 @var{file} defaults to @var{%default-socket-path}, which is the normal
3051 location given the options that were passed to @command{configure}.
3052 @end deffn
3053
3054 @deffn {Scheme Procedure} close-connection @var{server}
3055 Close the connection to @var{server}.
3056 @end deffn
3057
3058 @defvr {Scheme Variable} current-build-output-port
3059 This variable is bound to a SRFI-39 parameter, which refers to the port
3060 where build and error logs sent by the daemon should be written.
3061 @end defvr
3062
3063 Procedures that make RPCs all take a server object as their first
3064 argument.
3065
3066 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
3067 @cindex invalid store items
3068 Return @code{#t} when @var{path} designates a valid store item and
3069 @code{#f} otherwise (an invalid item may exist on disk but still be
3070 invalid, for instance because it is the result of an aborted or failed
3071 build.)
3072
3073 A @code{&nix-protocol-error} condition is raised if @var{path} is not
3074 prefixed by the store directory (@file{/gnu/store}).
3075 @end deffn
3076
3077 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
3078 Add @var{text} under file @var{name} in the store, and return its store
3079 path. @var{references} is the list of store paths referred to by the
3080 resulting store path.
3081 @end deffn
3082
3083 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
3084 Build @var{derivations} (a list of @code{<derivation>} objects or
3085 derivation paths), and return when the worker is done building them.
3086 Return @code{#t} on success.
3087 @end deffn
3088
3089 Note that the @code{(guix monads)} module provides a monad as well as
3090 monadic versions of the above procedures, with the goal of making it
3091 more convenient to work with code that accesses the store (@pxref{The
3092 Store Monad}).
3093
3094 @c FIXME
3095 @i{This section is currently incomplete.}
3096
3097 @node Derivations
3098 @section Derivations
3099
3100 @cindex derivations
3101 Low-level build actions and the environment in which they are performed
3102 are represented by @dfn{derivations}. A derivation contains the
3103 following pieces of information:
3104
3105 @itemize
3106 @item
3107 The outputs of the derivation---derivations produce at least one file or
3108 directory in the store, but may produce more.
3109
3110 @item
3111 The inputs of the derivations, which may be other derivations or plain
3112 files in the store (patches, build scripts, etc.)
3113
3114 @item
3115 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3116
3117 @item
3118 The file name of a build script in the store, along with the arguments
3119 to be passed.
3120
3121 @item
3122 A list of environment variables to be defined.
3123
3124 @end itemize
3125
3126 @cindex derivation path
3127 Derivations allow clients of the daemon to communicate build actions to
3128 the store. They exist in two forms: as an in-memory representation,
3129 both on the client- and daemon-side, and as files in the store whose
3130 name end in @code{.drv}---these files are referred to as @dfn{derivation
3131 paths}. Derivations paths can be passed to the @code{build-derivations}
3132 procedure to perform the build actions they prescribe (@pxref{The
3133 Store}).
3134
3135 The @code{(guix derivations)} module provides a representation of
3136 derivations as Scheme objects, along with procedures to create and
3137 otherwise manipulate derivations. The lowest-level primitive to create
3138 a derivation is the @code{derivation} procedure:
3139
3140 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3141 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3142 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
3143 [#:system (%current-system)] [#:references-graphs #f] @
3144 [#:allowed-references #f] [#:disallowed-references #f] @
3145 [#:leaked-env-vars #f] [#:local-build? #f] @
3146 [#:substitutable? #t]
3147 Build a derivation with the given arguments, and return the resulting
3148 @code{<derivation>} object.
3149
3150 When @var{hash} and @var{hash-algo} are given, a
3151 @dfn{fixed-output derivation} is created---i.e., one whose result is
3152 known in advance, such as a file download. If, in addition,
3153 @var{recursive?} is true, then that fixed output may be an executable
3154 file or a directory and @var{hash} must be the hash of an archive
3155 containing this output.
3156
3157 When @var{references-graphs} is true, it must be a list of file
3158 name/store path pairs. In that case, the reference graph of each store
3159 path is exported in the build environment in the corresponding file, in
3160 a simple text format.
3161
3162 When @var{allowed-references} is true, it must be a list of store items
3163 or outputs that the derivation's output may refer to. Likewise,
3164 @var{disallowed-references}, if true, must be a list of things the
3165 outputs may @emph{not} refer to.
3166
3167 When @var{leaked-env-vars} is true, it must be a list of strings
3168 denoting environment variables that are allowed to ``leak'' from the
3169 daemon's environment to the build environment. This is only applicable
3170 to fixed-output derivations---i.e., when @var{hash} is true. The main
3171 use is to allow variables such as @code{http_proxy} to be passed to
3172 derivations that download files.
3173
3174 When @var{local-build?} is true, declare that the derivation is not a
3175 good candidate for offloading and should rather be built locally
3176 (@pxref{Daemon Offload Setup}). This is the case for small derivations
3177 where the costs of data transfers would outweigh the benefits.
3178
3179 When @var{substitutable?} is false, declare that substitutes of the
3180 derivation's output should not be used (@pxref{Substitutes}). This is
3181 useful, for instance, when building packages that capture details of the
3182 host CPU instruction set.
3183 @end deffn
3184
3185 @noindent
3186 Here's an example with a shell script as its builder, assuming
3187 @var{store} is an open connection to the daemon, and @var{bash} points
3188 to a Bash executable in the store:
3189
3190 @lisp
3191 (use-modules (guix utils)
3192 (guix store)
3193 (guix derivations))
3194
3195 (let ((builder ; add the Bash script to the store
3196 (add-text-to-store store "my-builder.sh"
3197 "echo hello world > $out\n" '())))
3198 (derivation store "foo"
3199 bash `("-e" ,builder)
3200 #:inputs `((,bash) (,builder))
3201 #:env-vars '(("HOME" . "/homeless"))))
3202 @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
3203 @end lisp
3204
3205 As can be guessed, this primitive is cumbersome to use directly. A
3206 better approach is to write build scripts in Scheme, of course! The
3207 best course of action for that is to write the build code as a
3208 ``G-expression'', and to pass it to @code{gexp->derivation}. For more
3209 information, @pxref{G-Expressions}.
3210
3211 Once upon a time, @code{gexp->derivation} did not exist and constructing
3212 derivations with build code written in Scheme was achieved with
3213 @code{build-expression->derivation}, documented below. This procedure
3214 is now deprecated in favor of the much nicer @code{gexp->derivation}.
3215
3216 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
3217 @var{name} @var{exp} @
3218 [#:system (%current-system)] [#:inputs '()] @
3219 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3220 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3221 [#:references-graphs #f] [#:allowed-references #f] @
3222 [#:disallowed-references #f] @
3223 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3224 Return a derivation that executes Scheme expression @var{exp} as a
3225 builder for derivation @var{name}. @var{inputs} must be a list of
3226 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3227 @code{"out"} is assumed. @var{modules} is a list of names of Guile
3228 modules from the current search path to be copied in the store,
3229 compiled, and made available in the load path during the execution of
3230 @var{exp}---e.g., @code{((guix build utils) (guix build
3231 gnu-build-system))}.
3232
3233 @var{exp} is evaluated in an environment where @code{%outputs} is bound
3234 to a list of output/path pairs, and where @code{%build-inputs} is bound
3235 to a list of string/output-path pairs made from @var{inputs}.
3236 Optionally, @var{env-vars} is a list of string pairs specifying the name
3237 and value of environment variables visible to the builder. The builder
3238 terminates by passing the result of @var{exp} to @code{exit}; thus, when
3239 @var{exp} returns @code{#f}, the build is considered to have failed.
3240
3241 @var{exp} is built using @var{guile-for-build} (a derivation). When
3242 @var{guile-for-build} is omitted or is @code{#f}, the value of the
3243 @code{%guile-for-build} fluid is used instead.
3244
3245 See the @code{derivation} procedure for the meaning of
3246 @var{references-graphs}, @var{allowed-references},
3247 @var{disallowed-references}, @var{local-build?}, and
3248 @var{substitutable?}.
3249 @end deffn
3250
3251 @noindent
3252 Here's an example of a single-output derivation that creates a directory
3253 containing one file:
3254
3255 @lisp
3256 (let ((builder '(let ((out (assoc-ref %outputs "out")))
3257 (mkdir out) ; create /gnu/store/@dots{}-goo
3258 (call-with-output-file (string-append out "/test")
3259 (lambda (p)
3260 (display '(hello guix) p))))))
3261 (build-expression->derivation store "goo" builder))
3262
3263 @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3264 @end lisp
3265
3266
3267 @node The Store Monad
3268 @section The Store Monad
3269
3270 @cindex monad
3271
3272 The procedures that operate on the store described in the previous
3273 sections all take an open connection to the build daemon as their first
3274 argument. Although the underlying model is functional, they either have
3275 side effects or depend on the current state of the store.
3276
3277 The former is inconvenient: the connection to the build daemon has to be
3278 carried around in all those functions, making it impossible to compose
3279 functions that do not take that parameter with functions that do. The
3280 latter can be problematic: since store operations have side effects
3281 and/or depend on external state, they have to be properly sequenced.
3282
3283 @cindex monadic values
3284 @cindex monadic functions
3285 This is where the @code{(guix monads)} module comes in. This module
3286 provides a framework for working with @dfn{monads}, and a particularly
3287 useful monad for our uses, the @dfn{store monad}. Monads are a
3288 construct that allows two things: associating ``context'' with values
3289 (in our case, the context is the store), and building sequences of
3290 computations (here computations include accesses to the store). Values
3291 in a monad---values that carry this additional context---are called
3292 @dfn{monadic values}; procedures that return such values are called
3293 @dfn{monadic procedures}.
3294
3295 Consider this ``normal'' procedure:
3296
3297 @example
3298 (define (sh-symlink store)
3299 ;; Return a derivation that symlinks the 'bash' executable.
3300 (let* ((drv (package-derivation store bash))
3301 (out (derivation->output-path drv))
3302 (sh (string-append out "/bin/bash")))
3303 (build-expression->derivation store "sh"
3304 `(symlink ,sh %output))))
3305 @end example
3306
3307 Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3308 as a monadic function:
3309
3310 @example
3311 (define (sh-symlink)
3312 ;; Same, but return a monadic value.
3313 (mlet %store-monad ((drv (package->derivation bash)))
3314 (gexp->derivation "sh"
3315 #~(symlink (string-append #$drv "/bin/bash")
3316 #$output))))
3317 @end example
3318
3319 There are several things to note in the second version: the @code{store}
3320 parameter is now implicit and is ``threaded'' in the calls to the
3321 @code{package->derivation} and @code{gexp->derivation} monadic
3322 procedures, and the monadic value returned by @code{package->derivation}
3323 is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3324
3325 As it turns out, the call to @code{package->derivation} can even be
3326 omitted since it will take place implicitly, as we will see later
3327 (@pxref{G-Expressions}):
3328
3329 @example
3330 (define (sh-symlink)
3331 (gexp->derivation "sh"
3332 #~(symlink (string-append #$bash "/bin/bash")
3333 #$output)))
3334 @end example
3335
3336 @c See
3337 @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3338 @c for the funny quote.
3339 Calling the monadic @code{sh-symlink} has no effect. As someone once
3340 said, ``you exit a monad like you exit a building on fire: by running''.
3341 So, to exit the monad and get the desired effect, one must use
3342 @code{run-with-store}:
3343
3344 @example
3345 (run-with-store (open-connection) (sh-symlink))
3346 @result{} /gnu/store/...-sh-symlink
3347 @end example
3348
3349 Note that the @code{(guix monad-repl)} module extends the Guile REPL with
3350 new ``meta-commands'' to make it easier to deal with monadic procedures:
3351 @code{run-in-store}, and @code{enter-store-monad}. The former is used
3352 to ``run'' a single monadic value through the store:
3353
3354 @example
3355 scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3356 $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3357 @end example
3358
3359 The latter enters a recursive REPL, where all the return values are
3360 automatically run through the store:
3361
3362 @example
3363 scheme@@(guile-user)> ,enter-store-monad
3364 store-monad@@(guile-user) [1]> (package->derivation hello)
3365 $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3366 store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3367 $3 = "/gnu/store/@dots{}-foo"
3368 store-monad@@(guile-user) [1]> ,q
3369 scheme@@(guile-user)>
3370 @end example
3371
3372 @noindent
3373 Note that non-monadic values cannot be returned in the
3374 @code{store-monad} REPL.
3375
3376 The main syntactic forms to deal with monads in general are provided by
3377 the @code{(guix monads)} module and are described below.
3378
3379 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3380 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3381 in @var{monad}.
3382 @end deffn
3383
3384 @deffn {Scheme Syntax} return @var{val}
3385 Return a monadic value that encapsulates @var{val}.
3386 @end deffn
3387
3388 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
3389 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
3390 procedures @var{mproc}@dots{}@footnote{This operation is commonly
3391 referred to as ``bind'', but that name denotes an unrelated procedure in
3392 Guile. Thus we use this somewhat cryptic symbol inherited from the
3393 Haskell language.}. There can be one @var{mproc} or several of them, as
3394 in this example:
3395
3396 @example
3397 (run-with-state
3398 (with-monad %state-monad
3399 (>>= (return 1)
3400 (lambda (x) (return (+ 1 x)))
3401 (lambda (x) (return (* 2 x)))))
3402 'some-state)
3403
3404 @result{} 4
3405 @result{} some-state
3406 @end example
3407 @end deffn
3408
3409 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3410 @var{body} ...
3411 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3412 @var{body} ...
3413 Bind the variables @var{var} to the monadic values @var{mval} in
3414 @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3415 ``normal'' value @var{val}, as per @code{let}.
3416
3417 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3418 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3419 @end deffn
3420
3421 @deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3422 Bind @var{mexp} and the following monadic expressions in sequence,
3423 returning the result of the last expression.
3424
3425 This is akin to @code{mlet}, except that the return values of the
3426 monadic expressions are ignored. In that sense, it is analogous to
3427 @code{begin}, but applied to monadic expressions.
3428 @end deffn
3429
3430 @cindex state monad
3431 The @code{(guix monads)} module provides the @dfn{state monad}, which
3432 allows an additional value---the state---to be @emph{threaded} through
3433 monadic procedure calls.
3434
3435 @defvr {Scheme Variable} %state-monad
3436 The state monad. Procedures in the state monad can access and change
3437 the state that is threaded.
3438
3439 Consider the example below. The @code{square} procedure returns a value
3440 in the state monad. It returns the square of its argument, but also
3441 increments the current state value:
3442
3443 @example
3444 (define (square x)
3445 (mlet %state-monad ((count (current-state)))
3446 (mbegin %state-monad
3447 (set-current-state (+ 1 count))
3448 (return (* x x)))))
3449
3450 (run-with-state (sequence %state-monad (map square (iota 3))) 0)
3451 @result{} (0 1 4)
3452 @result{} 3
3453 @end example
3454
3455 When ``run'' through @var{%state-monad}, we obtain that additional state
3456 value, which is the number of @code{square} calls.
3457 @end defvr
3458
3459 @deffn {Monadic Procedure} current-state
3460 Return the current state as a monadic value.
3461 @end deffn
3462
3463 @deffn {Monadic Procedure} set-current-state @var{value}
3464 Set the current state to @var{value} and return the previous state as a
3465 monadic value.
3466 @end deffn
3467
3468 @deffn {Monadic Procedure} state-push @var{value}
3469 Push @var{value} to the current state, which is assumed to be a list,
3470 and return the previous state as a monadic value.
3471 @end deffn
3472
3473 @deffn {Monadic Procedure} state-pop
3474 Pop a value from the current state and return it as a monadic value.
3475 The state is assumed to be a list.
3476 @end deffn
3477
3478 @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3479 Run monadic value @var{mval} starting with @var{state} as the initial
3480 state. Return two values: the resulting value, and the resulting state.
3481 @end deffn
3482
3483 The main interface to the store monad, provided by the @code{(guix
3484 store)} module, is as follows.
3485
3486 @defvr {Scheme Variable} %store-monad
3487 The store monad---an alias for @var{%state-monad}.
3488
3489 Values in the store monad encapsulate accesses to the store. When its
3490 effect is needed, a value of the store monad must be ``evaluated'' by
3491 passing it to the @code{run-with-store} procedure (see below.)
3492 @end defvr
3493
3494 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3495 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3496 open store connection.
3497 @end deffn
3498
3499 @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
3500 Return as a monadic value the absolute file name in the store of the file
3501 containing @var{text}, a string. @var{references} is a list of store items that the
3502 resulting text file refers to; it defaults to the empty list.
3503 @end deffn
3504
3505 @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3506 [#:recursive? #t] [#:select? (const #t)]
3507 Return the name of @var{file} once interned in the store. Use
3508 @var{name} as its store name, or the basename of @var{file} if
3509 @var{name} is omitted.
3510
3511 When @var{recursive?} is true, the contents of @var{file} are added
3512 recursively; if @var{file} designates a flat file and @var{recursive?}
3513 is true, its contents are added, and its permission bits are kept.
3514
3515 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3516 @var{stat})} for each directory entry, where @var{file} is the entry's
3517 absolute file name and @var{stat} is the result of @code{lstat}; exclude
3518 entries for which @var{select?} does not return true.
3519
3520 The example below adds a file to the store, under two different names:
3521
3522 @example
3523 (run-with-store (open-connection)
3524 (mlet %store-monad ((a (interned-file "README"))
3525 (b (interned-file "README" "LEGU-MIN")))
3526 (return (list a b))))
3527
3528 @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3529 @end example
3530
3531 @end deffn
3532
3533 The @code{(guix packages)} module exports the following package-related
3534 monadic procedures:
3535
3536 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
3537 [#:system (%current-system)] [#:target #f] @
3538 [#:output "out"]
3539 Return as a monadic
3540 value in the absolute file name of @var{file} within the @var{output}
3541 directory of @var{package}. When @var{file} is omitted, return the name
3542 of the @var{output} directory of @var{package}. When @var{target} is
3543 true, use it as a cross-compilation target triplet.
3544 @end deffn
3545
3546 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
3547 @deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3548 @var{target} [@var{system}]
3549 Monadic version of @code{package-derivation} and
3550 @code{package-cross-derivation} (@pxref{Defining Packages}).
3551 @end deffn
3552
3553
3554 @node G-Expressions
3555 @section G-Expressions
3556
3557 @cindex G-expression
3558 @cindex build code quoting
3559 So we have ``derivations'', which represent a sequence of build actions
3560 to be performed to produce an item in the store (@pxref{Derivations}).
3561 These build actions are performed when asking the daemon to actually
3562 build the derivations; they are run by the daemon in a container
3563 (@pxref{Invoking guix-daemon}).
3564
3565 @cindex strata of code
3566 It should come as no surprise that we like to write these build actions
3567 in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3568 code@footnote{The term @dfn{stratum} in this context was coined by
3569 Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3570 Kiselyov, who has written insightful
3571 @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3572 on this topic}, refers to this kind of code generation as
3573 @dfn{staging}.}: the ``host code''---code that defines packages, talks
3574 to the daemon, etc.---and the ``build code''---code that actually
3575 performs build actions, such as making directories, invoking
3576 @command{make}, etc.
3577
3578 To describe a derivation and its build actions, one typically needs to
3579 embed build code inside host code. It boils down to manipulating build
3580 code as data, and the homoiconicity of Scheme---code has a direct
3581 representation as data---comes in handy for that. But we need more than
3582 the normal @code{quasiquote} mechanism in Scheme to construct build
3583 expressions.
3584
3585 The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3586 S-expressions adapted to build expressions. G-expressions, or
3587 @dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
3588 @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3589 @code{#$}, and @code{#$@@}), which are comparable to
3590 @code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
3591 respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
3592 GNU Guile Reference Manual}). However, there are major differences:
3593
3594 @itemize
3595 @item
3596 Gexps are meant to be written to a file and run or manipulated by other
3597 processes.
3598
3599 @item
3600 When a high-level object such as a package or derivation is unquoted
3601 inside a gexp, the result is as if its output file name had been
3602 introduced.
3603
3604 @item
3605 Gexps carry information about the packages or derivations they refer to,
3606 and these dependencies are automatically added as inputs to the build
3607 processes that use them.
3608 @end itemize
3609
3610 @cindex lowering, of high-level objects in gexps
3611 This mechanism is not limited to package and derivation
3612 objects: @dfn{compilers} able to ``lower'' other high-level objects to
3613 derivations or files in the store can be defined,
3614 such that these objects can also be inserted
3615 into gexps. For example, a useful type of high-level objects that can be
3616 inserted in a gexp is ``file-like objects'', which make it easy to
3617 add files to the store and to refer to them in
3618 derivations and such (see @code{local-file} and @code{plain-file}
3619 below.)
3620
3621 To illustrate the idea, here is an example of a gexp:
3622
3623 @example
3624 (define build-exp
3625 #~(begin
3626 (mkdir #$output)
3627 (chdir #$output)
3628 (symlink (string-append #$coreutils "/bin/ls")
3629 "list-files")))
3630 @end example
3631
3632 This gexp can be passed to @code{gexp->derivation}; we obtain a
3633 derivation that builds a directory containing exactly one symlink to
3634 @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3635
3636 @example
3637 (gexp->derivation "the-thing" build-exp)
3638 @end example
3639
3640 As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
3641 substituted to the reference to the @var{coreutils} package in the
3642 actual build code, and @var{coreutils} is automatically made an input to
3643 the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3644 output)}) is replaced by a string containing the directory name of the
3645 output of the derivation.
3646
3647 @cindex cross compilation
3648 In a cross-compilation context, it is useful to distinguish between
3649 references to the @emph{native} build of a package---that can run on the
3650 host---versus references to cross builds of a package. To that end, the
3651 @code{#+} plays the same role as @code{#$}, but is a reference to a
3652 native package build:
3653
3654 @example
3655 (gexp->derivation "vi"
3656 #~(begin
3657 (mkdir #$output)
3658 (system* (string-append #+coreutils "/bin/ln")
3659 "-s"
3660 (string-append #$emacs "/bin/emacs")
3661 (string-append #$output "/bin/vi")))
3662 #:target "mips64el-linux")
3663 @end example
3664
3665 @noindent
3666 In the example above, the native build of @var{coreutils} is used, so
3667 that @command{ln} can actually run on the host; but then the
3668 cross-compiled build of @var{emacs} is referenced.
3669
3670 The syntactic form to construct gexps is summarized below.
3671
3672 @deffn {Scheme Syntax} #~@var{exp}
3673 @deffnx {Scheme Syntax} (gexp @var{exp})
3674 Return a G-expression containing @var{exp}. @var{exp} may contain one
3675 or more of the following forms:
3676
3677 @table @code
3678 @item #$@var{obj}
3679 @itemx (ungexp @var{obj})
3680 Introduce a reference to @var{obj}. @var{obj} may have one of the
3681 supported types, for example a package or a
3682 derivation, in which case the @code{ungexp} form is replaced by its
3683 output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3684
3685 If @var{obj} is a list, it is traversed and references to supported
3686 objects are substituted similarly.
3687
3688 If @var{obj} is another gexp, its contents are inserted and its
3689 dependencies are added to those of the containing gexp.
3690
3691 If @var{obj} is another kind of object, it is inserted as is.
3692
3693 @item #$@var{obj}:@var{output}
3694 @itemx (ungexp @var{obj} @var{output})
3695 This is like the form above, but referring explicitly to the
3696 @var{output} of @var{obj}---this is useful when @var{obj} produces
3697 multiple outputs (@pxref{Packages with Multiple Outputs}).
3698
3699 @item #+@var{obj}
3700 @itemx #+@var{obj}:output
3701 @itemx (ungexp-native @var{obj})
3702 @itemx (ungexp-native @var{obj} @var{output})
3703 Same as @code{ungexp}, but produces a reference to the @emph{native}
3704 build of @var{obj} when used in a cross compilation context.
3705
3706 @item #$output[:@var{output}]
3707 @itemx (ungexp output [@var{output}])
3708 Insert a reference to derivation output @var{output}, or to the main
3709 output when @var{output} is omitted.
3710
3711 This only makes sense for gexps passed to @code{gexp->derivation}.
3712
3713 @item #$@@@var{lst}
3714 @itemx (ungexp-splicing @var{lst})
3715 Like the above, but splices the contents of @var{lst} inside the
3716 containing list.
3717
3718 @item #+@@@var{lst}
3719 @itemx (ungexp-native-splicing @var{lst})
3720 Like the above, but refers to native builds of the objects listed in
3721 @var{lst}.
3722
3723 @end table
3724
3725 G-expressions created by @code{gexp} or @code{#~} are run-time objects
3726 of the @code{gexp?} type (see below.)
3727 @end deffn
3728
3729 @deffn {Scheme Procedure} gexp? @var{obj}
3730 Return @code{#t} if @var{obj} is a G-expression.
3731 @end deffn
3732
3733 G-expressions are meant to be written to disk, either as code building
3734 some derivation, or as plain files in the store. The monadic procedures
3735 below allow you to do that (@pxref{The Store Monad}, for more
3736 information about monads.)
3737
3738 @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
3739 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
3740 [#:hash #f] [#:hash-algo #f] @
3741 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3742 [#:module-path @var{%load-path}] @
3743 [#:references-graphs #f] [#:allowed-references #f] @
3744 [#:disallowed-references #f] @
3745 [#:leaked-env-vars #f] @
3746 [#:script-name (string-append @var{name} "-builder")] @
3747 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3748 Return a derivation @var{name} that runs @var{exp} (a gexp) with
3749 @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3750 stored in a file called @var{script-name}. When @var{target} is true,
3751 it is used as the cross-compilation target triplet for packages referred
3752 to by @var{exp}.
3753
3754 Make @var{modules} available in the evaluation context of @var{exp};
3755 @var{modules} is a list of names of Guile modules searched in
3756 @var{module-path} to be copied in the store, compiled, and made available in
3757 the load path during the execution of @var{exp}---e.g., @code{((guix
3758 build utils) (guix build gnu-build-system))}.
3759
3760 @var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3761 applicable.
3762
3763 When @var{references-graphs} is true, it must be a list of tuples of one of the
3764 following forms:
3765
3766 @example
3767 (@var{file-name} @var{package})
3768 (@var{file-name} @var{package} @var{output})
3769 (@var{file-name} @var{derivation})
3770 (@var{file-name} @var{derivation} @var{output})
3771 (@var{file-name} @var{store-item})
3772 @end example
3773
3774 The right-hand-side of each element of @var{references-graphs} is automatically made
3775 an input of the build process of @var{exp}. In the build environment, each
3776 @var{file-name} contains the reference graph of the corresponding item, in a simple
3777 text format.
3778
3779 @var{allowed-references} must be either @code{#f} or a list of output names and packages.
3780 In the latter case, the list denotes store items that the result is allowed to
3781 refer to. Any reference to another store item will lead to a build error.
3782 Similarly for @var{disallowed-references}, which can list items that must not be
3783 referenced by the outputs.
3784
3785 The other arguments are as for @code{derivation} (@pxref{Derivations}).
3786 @end deffn
3787
3788 @cindex file-like objects
3789 The @code{local-file}, @code{plain-file}, @code{computed-file},
3790 @code{program-file}, and @code{scheme-file} procedures below return
3791 @dfn{file-like objects}. That is, when unquoted in a G-expression,
3792 these objects lead to a file in the store. Consider this G-expression:
3793
3794 @example
3795 #~(system* (string-append #$glibc "/sbin/nscd") "-f"
3796 #$(local-file "/tmp/my-nscd.conf"))
3797 @end example
3798
3799 The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3800 to the store. Once expanded, for instance @i{via}
3801 @code{gexp->derivation}, the G-expression refers to that copy under
3802 @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3803 does not have any effect on what the G-expression does.
3804 @code{plain-file} can be used similarly; it differs in that the file
3805 content is directly passed as a string.
3806
3807 @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3808 [#:recursive? #f] [#:select? (const #t)]
3809 Return an object representing local file @var{file} to add to the store; this
3810 object can be used in a gexp. If @var{file} is a relative file name, it is looked
3811 up relative to the source file where this form appears. @var{file} will be added to
3812 the store under @var{name}--by default the base name of @var{file}.
3813
3814 When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3815 designates a flat file and @var{recursive?} is true, its contents are added, and its
3816 permission bits are kept.
3817
3818 When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3819 @var{stat})} for each directory entry, where @var{file} is the entry's
3820 absolute file name and @var{stat} is the result of @code{lstat}; exclude
3821 entries for which @var{select?} does not return true.
3822
3823 This is the declarative counterpart of the @code{interned-file} monadic
3824 procedure (@pxref{The Store Monad, @code{interned-file}}).
3825 @end deffn
3826
3827 @deffn {Scheme Procedure} plain-file @var{name} @var{content}
3828 Return an object representing a text file called @var{name} with the given
3829 @var{content} (a string) to be added to the store.
3830
3831 This is the declarative counterpart of @code{text-file}.
3832 @end deffn
3833
3834 @deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3835 [#:modules '()] [#:options '(#:local-build? #t)]
3836 Return an object representing the store item @var{name}, a file or
3837 directory computed by @var{gexp}. @var{modules} specifies the set of
3838 modules visible in the execution context of @var{gexp}. @var{options}
3839 is a list of additional arguments to pass to @code{gexp->derivation}.
3840
3841 This is the declarative counterpart of @code{gexp->derivation}.
3842 @end deffn
3843
3844 @deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3845 Return an executable script @var{name} that runs @var{exp} using
3846 @var{guile} with @var{modules} in its search path.
3847
3848 The example below builds a script that simply invokes the @command{ls}
3849 command:
3850
3851 @example
3852 (use-modules (guix gexp) (gnu packages base))
3853
3854 (gexp->script "list-files"
3855 #~(execl (string-append #$coreutils "/bin/ls")
3856 "ls"))
3857 @end example
3858
3859 When ``running'' it through the store (@pxref{The Store Monad,
3860 @code{run-with-store}}), we obtain a derivation that produces an
3861 executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3862
3863 @example
3864 #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3865 !#
3866 (execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3867 "ls")
3868 @end example
3869 @end deffn
3870
3871 @deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3872 [#:modules '()] [#:guile #f]
3873 Return an object representing the executable store item @var{name} that
3874 runs @var{gexp}. @var{guile} is the Guile package used to execute that
3875 script, and @var{modules} is the list of modules visible to that script.
3876
3877 This is the declarative counterpart of @code{gexp->script}.
3878 @end deffn
3879
3880 @deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3881 Return a derivation that builds a file @var{name} containing @var{exp}.
3882
3883 The resulting file holds references to all the dependencies of @var{exp}
3884 or a subset thereof.
3885 @end deffn
3886
3887 @deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3888 Return an object representing the Scheme file @var{name} that contains
3889 @var{exp}.
3890
3891 This is the declarative counterpart of @code{gexp->file}.
3892 @end deffn
3893
3894 @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3895 Return as a monadic value a derivation that builds a text file
3896 containing all of @var{text}. @var{text} may list, in addition to
3897 strings, objects of any type that can be used in a gexp: packages,
3898 derivations, local file objects, etc. The resulting store file holds
3899 references to all these.
3900
3901 This variant should be preferred over @code{text-file} anytime the file
3902 to create will reference items from the store. This is typically the
3903 case when building a configuration file that embeds store file names,
3904 like this:
3905
3906 @example
3907 (define (profile.sh)
3908 ;; Return the name of a shell script in the store that
3909 ;; initializes the 'PATH' environment variable.
3910 (text-file* "profile.sh"
3911 "export PATH=" coreutils "/bin:"
3912 grep "/bin:" sed "/bin\n"))
3913 @end example
3914
3915 In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3916 will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
3917 preventing them from being garbage-collected during its lifetime.
3918 @end deffn
3919
3920 @deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3921 Return an object representing store file @var{name} containing
3922 @var{text}. @var{text} is a sequence of strings and file-like objects,
3923 as in:
3924
3925 @example
3926 (mixed-text-file "profile"
3927 "export PATH=" coreutils "/bin:" grep "/bin")
3928 @end example
3929
3930 This is the declarative counterpart of @code{text-file*}.
3931 @end deffn
3932
3933 Of course, in addition to gexps embedded in ``host'' code, there are
3934 also modules containing build tools. To make it clear that they are
3935 meant to be used in the build stratum, these modules are kept in the
3936 @code{(guix build @dots{})} name space.
3937
3938 @cindex lowering, of high-level objects in gexps
3939 Internally, high-level objects are @dfn{lowered}, using their compiler,
3940 to either derivations or store items. For instance, lowering a package
3941 yields a derivation, and lowering a @code{plain-file} yields a store
3942 item. This is achieved using the @code{lower-object} monadic procedure.
3943
3944 @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3945 [#:target #f]
3946 Return as a value in @var{%store-monad} the derivation or store item
3947 corresponding to @var{obj} for @var{system}, cross-compiling for
3948 @var{target} if @var{target} is true. @var{obj} must be an object that
3949 has an associated gexp compiler, such as a @code{<package>}.
3950 @end deffn
3951
3952
3953 @c *********************************************************************
3954 @node Utilities
3955 @chapter Utilities
3956
3957 This section describes Guix command-line utilities. Some of them are
3958 primarily targeted at developers and users who write new package
3959 definitions, while others are more generally useful. They complement
3960 the Scheme programming interface of Guix in a convenient way.
3961
3962 @menu
3963 * Invoking guix build:: Building packages from the command line.
3964 * Invoking guix edit:: Editing package definitions.
3965 * Invoking guix download:: Downloading a file and printing its hash.
3966 * Invoking guix hash:: Computing the cryptographic hash of a file.
3967 * Invoking guix import:: Importing package definitions.
3968 * Invoking guix refresh:: Updating package definitions.
3969 * Invoking guix lint:: Finding errors in package definitions.
3970 * Invoking guix size:: Profiling disk usage.
3971 * Invoking guix graph:: Visualizing the graph of packages.
3972 * Invoking guix environment:: Setting up development environments.
3973 * Invoking guix publish:: Sharing substitutes.
3974 * Invoking guix challenge:: Challenging substitute servers.
3975 * Invoking guix container:: Process isolation.
3976 @end menu
3977
3978 @node Invoking guix build
3979 @section Invoking @command{guix build}
3980
3981 The @command{guix build} command builds packages or derivations and
3982 their dependencies, and prints the resulting store paths. Note that it
3983 does not modify the user's profile---this is the job of the
3984 @command{guix package} command (@pxref{Invoking guix package}). Thus,
3985 it is mainly useful for distribution developers.
3986
3987 The general syntax is:
3988
3989 @example
3990 guix build @var{options} @var{package-or-derivation}@dots{}
3991 @end example
3992
3993 As an example, the following command builds the latest versions of Emacs
3994 and of Guile, displays their build logs, and finally displays the
3995 resulting directories:
3996
3997 @example
3998 guix build emacs guile
3999 @end example
4000
4001 Similarly, the following command builds all the available packages:
4002
4003 @example
4004 guix build --quiet --keep-going \
4005 `guix package -A | cut -f1,2 --output-delimiter=@@`
4006 @end example
4007
4008 @var{package-or-derivation} may be either the name of a package found in
4009 the software distribution such as @code{coreutils} or
4010 @code{coreutils-8.20}, or a derivation such as
4011 @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
4012 package with the corresponding name (and optionally version) is searched
4013 for among the GNU distribution modules (@pxref{Package Modules}).
4014
4015 Alternatively, the @code{--expression} option may be used to specify a
4016 Scheme expression that evaluates to a package; this is useful when
4017 disambiguating among several same-named packages or package variants is
4018 needed.
4019
4020 There may be zero or more @var{options}. The available options are
4021 described in the subsections below.
4022
4023 @menu
4024 * Common Build Options:: Build options for most commands.
4025 * Package Transformation Options:: Creating variants of packages.
4026 * Additional Build Options:: Options specific to 'guix build'.
4027 @end menu
4028
4029 @node Common Build Options
4030 @subsection Common Build Options
4031
4032 A number of options that control the build process are common to
4033 @command{guix build} and other commands that can spawn builds, such as
4034 @command{guix package} or @command{guix archive}. These are the
4035 following:
4036
4037 @table @code
4038
4039 @item --load-path=@var{directory}
4040 @itemx -L @var{directory}
4041 Add @var{directory} to the front of the package module search path
4042 (@pxref{Package Modules}).
4043
4044 This allows users to define their own packages and make them visible to
4045 the command-line tools.
4046
4047 @item --keep-failed
4048 @itemx -K
4049 Keep the build tree of failed builds. Thus, if a build fails, its build
4050 tree is kept under @file{/tmp}, in a directory whose name is shown at
4051 the end of the build log. This is useful when debugging build issues.
4052
4053 @item --keep-going
4054 @itemx -k
4055 Keep going when some of the derivations fail to build; return only once
4056 all the builds have either completed or failed.
4057
4058 The default behavior is to stop as soon as one of the specified
4059 derivations has failed.
4060
4061 @item --dry-run
4062 @itemx -n
4063 Do not build the derivations.
4064
4065 @item --fallback
4066 When substituting a pre-built binary fails, fall back to building
4067 packages locally.
4068
4069 @item --substitute-urls=@var{urls}
4070 @anchor{client-substitute-urls}
4071 Consider @var{urls} the whitespace-separated list of substitute source
4072 URLs, overriding the default list of URLs of @command{guix-daemon}
4073 (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4074
4075 This means that substitutes may be downloaded from @var{urls}, provided
4076 they are signed by a key authorized by the system administrator
4077 (@pxref{Substitutes}).
4078
4079 When @var{urls} is the empty string, substitutes are effectively
4080 disabled.
4081
4082 @item --no-substitutes
4083 Do not use substitutes for build products. That is, always build things
4084 locally instead of allowing downloads of pre-built binaries
4085 (@pxref{Substitutes}).
4086
4087 @item --no-grafts
4088 Do not ``graft'' packages. In practice, this means that package updates
4089 available as grafts are not applied. @xref{Security Updates}, for more
4090 information on grafts.
4091
4092 @item --rounds=@var{n}
4093 Build each derivation @var{n} times in a row, and raise an error if
4094 consecutive build results are not bit-for-bit identical.
4095
4096 This is a useful way to detect non-deterministic builds processes.
4097 Non-deterministic build processes are a problem because they make it
4098 practically impossible for users to @emph{verify} whether third-party
4099 binaries are genuine. @xref{Invoking guix challenge}, for more.
4100
4101 Note that, currently, the differing build results are not kept around,
4102 so you will have to manually investigate in case of an error---e.g., by
4103 stashing one of the build results with @code{guix archive --export}
4104 (@pxref{Invoking guix archive}), then rebuilding, and finally comparing
4105 the two results.
4106
4107 @item --no-build-hook
4108 Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
4109 (@pxref{Daemon Offload Setup}). That is, always build things locally
4110 instead of offloading builds to remote machines.
4111
4112 @item --max-silent-time=@var{seconds}
4113 When the build or substitution process remains silent for more than
4114 @var{seconds}, terminate it and report a build failure.
4115
4116 @item --timeout=@var{seconds}
4117 Likewise, when the build or substitution process lasts for more than
4118 @var{seconds}, terminate it and report a build failure.
4119
4120 By default there is no timeout. This behavior can be restored with
4121 @code{--timeout=0}.
4122
4123 @item --verbosity=@var{level}
4124 Use the given verbosity level. @var{level} must be an integer between 0
4125 and 5; higher means more verbose output. Setting a level of 4 or more
4126 may be helpful when debugging setup issues with the build daemon.
4127
4128 @item --cores=@var{n}
4129 @itemx -c @var{n}
4130 Allow the use of up to @var{n} CPU cores for the build. The special
4131 value @code{0} means to use as many CPU cores as available.
4132
4133 @item --max-jobs=@var{n}
4134 @itemx -M @var{n}
4135 Allow at most @var{n} build jobs in parallel. @xref{Invoking
4136 guix-daemon, @code{--max-jobs}}, for details about this option and the
4137 equivalent @command{guix-daemon} option.
4138
4139 @end table
4140
4141 Behind the scenes, @command{guix build} is essentially an interface to
4142 the @code{package-derivation} procedure of the @code{(guix packages)}
4143 module, and to the @code{build-derivations} procedure of the @code{(guix
4144 derivations)} module.
4145
4146 In addition to options explicitly passed on the command line,
4147 @command{guix build} and other @command{guix} commands that support
4148 building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4149
4150 @defvr {Environment Variable} GUIX_BUILD_OPTIONS
4151 Users can define this variable to a list of command line options that
4152 will automatically be used by @command{guix build} and other
4153 @command{guix} commands that can perform builds, as in the example
4154 below:
4155
4156 @example
4157 $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4158 @end example
4159
4160 These options are parsed independently, and the result is appended to
4161 the parsed command-line options.
4162 @end defvr
4163
4164
4165 @node Package Transformation Options
4166 @subsection Package Transformation Options
4167
4168 @cindex package variants
4169 Another set of command-line options supported by @command{guix build}
4170 and also @command{guix package} are @dfn{package transformation
4171 options}. These are options that make it possible to define @dfn{package
4172 variants}---for instance, packages built from different source code.
4173 This is a convenient way to create customized packages on the fly
4174 without having to type in the definitions of package variants
4175 (@pxref{Defining Packages}).
4176
4177 @table @code
4178
4179 @item --with-source=@var{source}
4180 Use @var{source} as the source of the corresponding package.
4181 @var{source} must be a file name or a URL, as for @command{guix
4182 download} (@pxref{Invoking guix download}).
4183
4184 The ``corresponding package'' is taken to be the one specified on the
4185 command line the name of which matches the base of @var{source}---e.g.,
4186 if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
4187 package is @code{guile}. Likewise, the version string is inferred from
4188 @var{source}; in the previous example, it is @code{2.0.10}.
4189
4190 This option allows users to try out versions of packages other than the
4191 one provided by the distribution. The example below downloads
4192 @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4193 the @code{ed} package:
4194
4195 @example
4196 guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4197 @end example
4198
4199 As a developer, @code{--with-source} makes it easy to test release
4200 candidates:
4201
4202 @example
4203 guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4204 @end example
4205
4206 @dots{} or to build from a checkout in a pristine environment:
4207
4208 @example
4209 $ git clone git://git.sv.gnu.org/guix.git
4210 $ guix build guix --with-source=./guix
4211 @end example
4212
4213 @item --with-input=@var{package}=@var{replacement}
4214 Replace dependency on @var{package} by a dependency on
4215 @var{replacement}. @var{package} must be a package name, and
4216 @var{replacement} must be a package specification such as @code{guile}
4217 or @code{guile@@1.8}.
4218
4219 For instance, the following command builds Guix, but replaces its
4220 dependency on the current stable version of Guile with a dependency on
4221 the development version of Guile, @code{guile-next}:
4222
4223 @example
4224 guix build --with-input=guile=guile-next guix
4225 @end example
4226
4227 This is a recursive, deep replacement. So in this example, both
4228 @code{guix} and its dependency @code{guile-json} (which also depends on
4229 @code{guile}) get rebuilt against @code{guile-next}.
4230
4231 However, implicit inputs are left unchanged.
4232 @end table
4233
4234 @node Additional Build Options
4235 @subsection Additional Build Options
4236
4237 The command-line options presented below are specific to @command{guix
4238 build}.
4239
4240 @table @code
4241
4242 @item --quiet
4243 @itemx -q
4244 Build quietly, without displaying the build log. Upon completion, the
4245 build log is kept in @file{/var} (or similar) and can always be
4246 retrieved using the @option{--log-file} option.
4247
4248 @item --file=@var{file}
4249 @itemx -f @var{file}
4250
4251 Build the package or derivation that the code within @var{file}
4252 evaluates to.
4253
4254 As an example, @var{file} might contain a package definition like this
4255 (@pxref{Defining Packages}):
4256
4257 @example
4258 @verbatiminclude package-hello.scm
4259 @end example
4260
4261 @item --expression=@var{expr}
4262 @itemx -e @var{expr}
4263 Build the package or derivation @var{expr} evaluates to.
4264
4265 For example, @var{expr} may be @code{(@@ (gnu packages guile)
4266 guile-1.8)}, which unambiguously designates this specific variant of
4267 version 1.8 of Guile.
4268
4269 Alternatively, @var{expr} may be a G-expression, in which case it is used
4270 as a build program passed to @code{gexp->derivation}
4271 (@pxref{G-Expressions}).
4272
4273 Lastly, @var{expr} may refer to a zero-argument monadic procedure
4274 (@pxref{The Store Monad}). The procedure must return a derivation as a
4275 monadic value, which is then passed through @code{run-with-store}.
4276
4277 @item --source
4278 @itemx -S
4279 Build the source derivations of the packages, rather than the packages
4280 themselves.
4281
4282 For instance, @code{guix build -S gcc} returns something like
4283 @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4284 source tarball.
4285
4286 The returned source tarball is the result of applying any patches and
4287 code snippets specified in the package @code{origin} (@pxref{Defining
4288 Packages}).
4289
4290 @item --sources
4291 Fetch and return the source of @var{package-or-derivation} and all their
4292 dependencies, recursively. This is a handy way to obtain a local copy
4293 of all the source code needed to build @var{packages}, allowing you to
4294 eventually build them even without network access. It is an extension
4295 of the @code{--source} option and can accept one of the following
4296 optional argument values:
4297
4298 @table @code
4299 @item package
4300 This value causes the @code{--sources} option to behave in the same way
4301 as the @code{--source} option.
4302
4303 @item all
4304 Build the source derivations of all packages, including any source that
4305 might be listed as @code{inputs}. This is the default value.
4306
4307 @example
4308 $ guix build --sources tzdata
4309 The following derivations will be built:
4310 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4311 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4312 @end example
4313
4314 @item transitive
4315 Build the source derivations of all packages, as well of all transitive
4316 inputs to the packages. This can be used e.g. to
4317 prefetch package source for later offline building.
4318
4319 @example
4320 $ guix build --sources=transitive tzdata
4321 The following derivations will be built:
4322 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4323 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4324 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4325 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4326 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4327 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4328 @dots{}
4329 @end example
4330
4331 @end table
4332
4333 @item --system=@var{system}
4334 @itemx -s @var{system}
4335 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
4336 the system type of the build host.
4337
4338 An example use of this is on Linux-based systems, which can emulate
4339 different personalities. For instance, passing
4340 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4341 to build packages in a complete 32-bit environment.
4342
4343 @item --target=@var{triplet}
4344 @cindex cross-compilation
4345 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4346 as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4347 configuration triplets,, configure, GNU Configure and Build System}).
4348
4349 @anchor{build-check}
4350 @item --check
4351 @cindex determinism, checking
4352 @cindex reproducibility, checking
4353 Rebuild @var{package-or-derivation}, which are already available in the
4354 store, and raise an error if the build results are not bit-for-bit
4355 identical.
4356
4357 This mechanism allows you to check whether previously installed
4358 substitutes are genuine (@pxref{Substitutes}), or whether the build result
4359 of a package is deterministic. @xref{Invoking guix challenge}, for more
4360 background information and tools.
4361
4362 When used in conjunction with @option{--keep-failed}, the differing
4363 output is kept in the store, under @file{/gnu/store/@dots{}-check}.
4364 This makes it easy to look for differences between the two results.
4365
4366 @item --derivations
4367 @itemx -d
4368 Return the derivation paths, not the output paths, of the given
4369 packages.
4370
4371 @item --root=@var{file}
4372 @itemx -r @var{file}
4373 Make @var{file} a symlink to the result, and register it as a garbage
4374 collector root.
4375
4376 @item --log-file
4377 Return the build log file names or URLs for the given
4378 @var{package-or-derivation}, or raise an error if build logs are
4379 missing.
4380
4381 This works regardless of how packages or derivations are specified. For
4382 instance, the following invocations are equivalent:
4383
4384 @example
4385 guix build --log-file `guix build -d guile`
4386 guix build --log-file `guix build guile`
4387 guix build --log-file guile
4388 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4389 @end example
4390
4391 If a log is unavailable locally, and unless @code{--no-substitutes} is
4392 passed, the command looks for a corresponding log on one of the
4393 substitute servers (as specified with @code{--substitute-urls}.)
4394
4395 So for instance, imagine you want to see the build log of GDB on MIPS,
4396 but you are actually on an @code{x86_64} machine:
4397
4398 @example
4399 $ guix build --log-file gdb -s mips64el-linux
4400 https://hydra.gnu.org/log/@dots{}-gdb-7.10
4401 @end example
4402
4403 You can freely access a huge library of build logs!
4404 @end table
4405
4406
4407 @node Invoking guix edit
4408 @section Invoking @command{guix edit}
4409
4410 @cindex package definition, editing
4411 So many packages, so many source files! The @command{guix edit} command
4412 facilitates the life of packagers by pointing their editor at the source
4413 file containing the definition of the specified packages. For instance:
4414
4415 @example
4416 guix edit gcc@@4.9 vim
4417 @end example
4418
4419 @noindent
4420 launches the program specified in the @code{VISUAL} or in the
4421 @code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.9.3
4422 and that of Vim.
4423
4424 If you are using Emacs, note that the Emacs user interface provides the
4425 @kbd{M-x guix-edit} command and a similar functionality in the ``package
4426 info'' and ``package list'' buffers created by the @kbd{M-x
4427 guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
4428
4429
4430 @node Invoking guix download
4431 @section Invoking @command{guix download}
4432
4433 When writing a package definition, developers typically need to download
4434 a source tarball, compute its SHA256 hash, and write that
4435 hash in the package definition (@pxref{Defining Packages}). The
4436 @command{guix download} tool helps with this task: it downloads a file
4437 from the given URI, adds it to the store, and prints both its file name
4438 in the store and its SHA256 hash.
4439
4440 The fact that the downloaded file is added to the store saves bandwidth:
4441 when the developer eventually tries to build the newly defined package
4442 with @command{guix build}, the source tarball will not have to be
4443 downloaded again because it is already in the store. It is also a
4444 convenient way to temporarily stash files, which may be deleted
4445 eventually (@pxref{Invoking guix gc}).
4446
4447 The @command{guix download} command supports the same URIs as used in
4448 package definitions. In particular, it supports @code{mirror://} URIs.
4449 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4450 Guile bindings for GnuTLS are available in the user's environment; when
4451 they are not available, an error is raised. @xref{Guile Preparations,
4452 how to install the GnuTLS bindings for Guile,, gnutls-guile,
4453 GnuTLS-Guile}, for more information.
4454
4455 The following option is available:
4456
4457 @table @code
4458 @item --format=@var{fmt}
4459 @itemx -f @var{fmt}
4460 Write the hash in the format specified by @var{fmt}. For more
4461 information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
4462 @end table
4463
4464 @node Invoking guix hash
4465 @section Invoking @command{guix hash}
4466
4467 The @command{guix hash} command computes the SHA256 hash of a file.
4468 It is primarily a convenience tool for anyone contributing to the
4469 distribution: it computes the cryptographic hash of a file, which can be
4470 used in the definition of a package (@pxref{Defining Packages}).
4471
4472 The general syntax is:
4473
4474 @example
4475 guix hash @var{option} @var{file}
4476 @end example
4477
4478 @command{guix hash} has the following option:
4479
4480 @table @code
4481
4482 @item --format=@var{fmt}
4483 @itemx -f @var{fmt}
4484 Write the hash in the format specified by @var{fmt}.
4485
4486 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4487 (@code{hex} and @code{hexadecimal} can be used as well).
4488
4489 If the @option{--format} option is not specified, @command{guix hash}
4490 will output the hash in @code{nix-base32}. This representation is used
4491 in the definitions of packages.
4492
4493 @item --recursive
4494 @itemx -r
4495 Compute the hash on @var{file} recursively.
4496
4497 In this case, the hash is computed on an archive containing @var{file},
4498 including its children if it is a directory. Some of the metadata of
4499 @var{file} is part of the archive; for instance, when @var{file} is a
4500 regular file, the hash is different depending on whether @var{file} is
4501 executable or not. Metadata such as time stamps has no impact on the
4502 hash (@pxref{Invoking guix archive}).
4503 @c FIXME: Replace xref above with xref to an ``Archive'' section when
4504 @c it exists.
4505
4506 @end table
4507
4508 @node Invoking guix import
4509 @section Invoking @command{guix import}
4510
4511 @cindex importing packages
4512 @cindex package import
4513 @cindex package conversion
4514 The @command{guix import} command is useful for people who would like to
4515 add a package to the distribution with as little work as
4516 possible---a legitimate demand. The command knows of a few
4517 repositories from which it can ``import'' package metadata. The result
4518 is a package definition, or a template thereof, in the format we know
4519 (@pxref{Defining Packages}).
4520
4521 The general syntax is:
4522
4523 @example
4524 guix import @var{importer} @var{options}@dots{}
4525 @end example
4526
4527 @var{importer} specifies the source from which to import package
4528 metadata, and @var{options} specifies a package identifier and other
4529 options specific to @var{importer}. Currently, the available
4530 ``importers'' are:
4531
4532 @table @code
4533 @item gnu
4534 Import metadata for the given GNU package. This provides a template
4535 for the latest version of that GNU package, including the hash of its
4536 source tarball, and its canonical synopsis and description.
4537
4538 Additional information such as the package dependencies and its
4539 license needs to be figured out manually.
4540
4541 For example, the following command returns a package definition for
4542 GNU@tie{}Hello:
4543
4544 @example
4545 guix import gnu hello
4546 @end example
4547
4548 Specific command-line options are:
4549
4550 @table @code
4551 @item --key-download=@var{policy}
4552 As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4553 keys when verifying the package signature. @xref{Invoking guix
4554 refresh, @code{--key-download}}.
4555 @end table
4556
4557 @item pypi
4558 @cindex pypi
4559 Import metadata from the @uref{https://pypi.python.org/, Python Package
4560 Index}@footnote{This functionality requires Guile-JSON to be installed.
4561 @xref{Requirements}.}. Information is taken from the JSON-formatted
4562 description available at @code{pypi.python.org} and usually includes all
4563 the relevant information, including package dependencies. For maximum
4564 efficiency, it is recommended to install the @command{unzip} utility, so
4565 that the importer can unzip Python wheels and gather data from them.
4566
4567 The command below imports metadata for the @code{itsdangerous} Python
4568 package:
4569
4570 @example
4571 guix import pypi itsdangerous
4572 @end example
4573
4574 @item gem
4575 @cindex gem
4576 Import metadata from @uref{https://rubygems.org/,
4577 RubyGems}@footnote{This functionality requires Guile-JSON to be
4578 installed. @xref{Requirements}.}. Information is taken from the
4579 JSON-formatted description available at @code{rubygems.org} and includes
4580 most relevant information, including runtime dependencies. There are
4581 some caveats, however. The metadata doesn't distinguish between
4582 synopses and descriptions, so the same string is used for both fields.
4583 Additionally, the details of non-Ruby dependencies required to build
4584 native extensions is unavailable and left as an exercise to the
4585 packager.
4586
4587 The command below imports metadata for the @code{rails} Ruby package:
4588
4589 @example
4590 guix import gem rails
4591 @end example
4592
4593 @item cpan
4594 @cindex CPAN
4595 Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4596 functionality requires Guile-JSON to be installed.
4597 @xref{Requirements}.}.
4598 Information is taken from the JSON-formatted metadata provided through
4599 @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
4600 relevant information, such as module dependencies. License information
4601 should be checked closely. If Perl is available in the store, then the
4602 @code{corelist} utility will be used to filter core modules out of the
4603 list of dependencies.
4604
4605 The command command below imports metadata for the @code{Acme::Boolean}
4606 Perl module:
4607
4608 @example
4609 guix import cpan Acme::Boolean
4610 @end example
4611
4612 @item cran
4613 @cindex CRAN
4614 @cindex Bioconductor
4615 Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
4616 central repository for the @uref{http://r-project.org, GNU@tie{}R
4617 statistical and graphical environment}.
4618
4619 Information is extracted from the @code{DESCRIPTION} file of the package.
4620
4621 The command command below imports metadata for the @code{Cairo}
4622 R package:
4623
4624 @example
4625 guix import cran Cairo
4626 @end example
4627
4628 When @code{--archive=bioconductor} is added, metadata is imported from
4629 @uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4630 packages for for the analysis and comprehension of high-throughput
4631 genomic data in bioinformatics.
4632
4633 Information is extracted from the @code{DESCRIPTION} file of a package
4634 published on the web interface of the Bioconductor SVN repository.
4635
4636 The command below imports metadata for the @code{GenomicRanges}
4637 R package:
4638
4639 @example
4640 guix import cran --archive=bioconductor GenomicRanges
4641 @end example
4642
4643 @item nix
4644 Import metadata from a local copy of the source of the
4645 @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4646 relies on the @command{nix-instantiate} command of
4647 @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4648 typically written in a mixture of Nix-language and Bash code. This
4649 command only imports the high-level package structure that is written in
4650 the Nix language. It normally includes all the basic fields of a
4651 package definition.
4652
4653 When importing a GNU package, the synopsis and descriptions are replaced
4654 by their canonical upstream variant.
4655
4656 Usually, you will first need to do:
4657
4658 @example
4659 export NIX_REMOTE=daemon
4660 @end example
4661
4662 @noindent
4663 so that @command{nix-instantiate} does not try to open the Nix database.
4664
4665 As an example, the command below imports the package definition of
4666 LibreOffice (more precisely, it imports the definition of the package
4667 bound to the @code{libreoffice} top-level attribute):
4668
4669 @example
4670 guix import nix ~/path/to/nixpkgs libreoffice
4671 @end example
4672
4673 @item hackage
4674 @cindex hackage
4675 Import metadata from the Haskell community's central package archive
4676 @uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4677 Cabal files and includes all the relevant information, including package
4678 dependencies.
4679
4680 Specific command-line options are:
4681
4682 @table @code
4683 @item --stdin
4684 @itemx -s
4685 Read a Cabal file from standard input.
4686 @item --no-test-dependencies
4687 @itemx -t
4688 Do not include dependencies required only by the test suites.
4689 @item --cabal-environment=@var{alist}
4690 @itemx -e @var{alist}
4691 @var{alist} is a Scheme alist defining the environment in which the
4692 Cabal conditionals are evaluated. The accepted keys are: @code{os},
4693 @code{arch}, @code{impl} and a string representing the name of a flag.
4694 The value associated with a flag has to be either the symbol
4695 @code{true} or @code{false}. The value associated with other keys
4696 has to conform to the Cabal file format definition. The default value
4697 associated with the keys @code{os}, @code{arch} and @code{impl} is
4698 @samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
4699 @end table
4700
4701 The command below imports metadata for the latest version of the
4702 @code{HTTP} Haskell package without including test dependencies and
4703 specifying the value of the flag @samp{network-uri} as @code{false}:
4704
4705 @example
4706 guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
4707 @end example
4708
4709 A specific package version may optionally be specified by following the
4710 package name by an at-sign and a version number as in the following example:
4711
4712 @example
4713 guix import hackage mtl@@2.1.3.1
4714 @end example
4715
4716 @item elpa
4717 @cindex elpa
4718 Import metadata from an Emacs Lisp Package Archive (ELPA) package
4719 repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4720
4721 Specific command-line options are:
4722
4723 @table @code
4724 @item --archive=@var{repo}
4725 @itemx -a @var{repo}
4726 @var{repo} identifies the archive repository from which to retrieve the
4727 information. Currently the supported repositories and their identifiers
4728 are:
4729 @itemize -
4730 @item
4731 @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
4732 identifier. This is the default.
4733
4734 @item
4735 @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
4736 @code{melpa-stable} identifier.
4737
4738 @item
4739 @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
4740 identifier.
4741 @end itemize
4742 @end table
4743 @end table
4744
4745 The structure of the @command{guix import} code is modular. It would be
4746 useful to have more importers for other package formats, and your help
4747 is welcome here (@pxref{Contributing}).
4748
4749 @node Invoking guix refresh
4750 @section Invoking @command{guix refresh}
4751
4752 The primary audience of the @command{guix refresh} command is developers
4753 of the GNU software distribution. By default, it reports any packages
4754 provided by the distribution that are outdated compared to the latest
4755 upstream version, like this:
4756
4757 @example
4758 $ guix refresh
4759 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4760 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4761 @end example
4762
4763 It does so by browsing the FTP directory of each package and determining
4764 the highest version number of the source tarballs therein. The command
4765 knows how to update specific types of packages: GNU packages, ELPA
4766 packages, etc.---see the documentation for @option{--type} below. The
4767 are many packages, though, for which it lacks a method to determine
4768 whether a new upstream release is available. However, the mechanism is
4769 extensible, so feel free to get in touch with us to add a new method!
4770
4771 When passed @code{--update}, it modifies distribution source files to
4772 update the version numbers and source tarball hashes of those package
4773 recipes (@pxref{Defining Packages}). This is achieved by downloading
4774 each package's latest source tarball and its associated OpenPGP
4775 signature, authenticating the downloaded tarball against its signature
4776 using @command{gpg}, and finally computing its hash. When the public
4777 key used to sign the tarball is missing from the user's keyring, an
4778 attempt is made to automatically retrieve it from a public key server;
4779 when this is successful, the key is added to the user's keyring; otherwise,
4780 @command{guix refresh} reports an error.
4781
4782 The following options are supported:
4783
4784 @table @code
4785
4786 @item --expression=@var{expr}
4787 @itemx -e @var{expr}
4788 Consider the package @var{expr} evaluates to.
4789
4790 This is useful to precisely refer to a package, as in this example:
4791
4792 @example
4793 guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4794 @end example
4795
4796 This command lists the dependents of the ``final'' libc (essentially all
4797 the packages.)
4798
4799 @item --update
4800 @itemx -u
4801 Update distribution source files (package recipes) in place. This is
4802 usually run from a checkout of the Guix source tree (@pxref{Running
4803 Guix Before It Is Installed}):
4804
4805 @example
4806 $ ./pre-inst-env guix refresh -s non-core
4807 @end example
4808
4809 @xref{Defining Packages}, for more information on package definitions.
4810
4811 @item --select=[@var{subset}]
4812 @itemx -s @var{subset}
4813 Select all the packages in @var{subset}, one of @code{core} or
4814 @code{non-core}.
4815
4816 The @code{core} subset refers to all the packages at the core of the
4817 distribution---i.e., packages that are used to build ``everything
4818 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4819 changing one of these packages in the distribution entails a rebuild of
4820 all the others. Thus, such updates are an inconvenience to users in
4821 terms of build time or bandwidth used to achieve the upgrade.
4822
4823 The @code{non-core} subset refers to the remaining packages. It is
4824 typically useful in cases where an update of the core packages would be
4825 inconvenient.
4826
4827 @item --type=@var{updater}
4828 @itemx -t @var{updater}
4829 Select only packages handled by @var{updater} (may be a comma-separated
4830 list of updaters). Currently, @var{updater} may be one of:
4831
4832 @table @code
4833 @item gnu
4834 the updater for GNU packages;
4835 @item gnome
4836 the updater for GNOME packages;
4837 @item xorg
4838 the updater for X.org packages;
4839 @item elpa
4840 the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4841 @item cran
4842 the updater for @uref{http://cran.r-project.org/, CRAN} packages;
4843 @item bioconductor
4844 the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
4845 @item pypi
4846 the updater for @uref{https://pypi.python.org, PyPI} packages.
4847 @item gem
4848 the updater for @uref{https://rubygems.org, RubyGems} packages.
4849 @item github
4850 the updater for @uref{https://github.com, GitHub} packages.
4851 @item hackage
4852 the updater for @uref{https://hackage.haskell.org, Hackage} packages.
4853 @end table
4854
4855 For instance, the following command only checks for updates of Emacs
4856 packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
4857
4858 @example
4859 $ guix refresh --type=elpa,cran
4860 gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
4861 gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4862 @end example
4863
4864 @end table
4865
4866 In addition, @command{guix refresh} can be passed one or more package
4867 names, as in this example:
4868
4869 @example
4870 $ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
4871 @end example
4872
4873 @noindent
4874 The command above specifically updates the @code{emacs} and
4875 @code{idutils} packages. The @code{--select} option would have no
4876 effect in this case.
4877
4878 When considering whether to upgrade a package, it is sometimes
4879 convenient to know which packages would be affected by the upgrade and
4880 should be checked for compatibility. For this the following option may
4881 be used when passing @command{guix refresh} one or more package names:
4882
4883 @table @code
4884
4885 @item --list-updaters
4886 @itemx -L
4887 List available updaters and exit (see @option{--type} above.)
4888
4889 @item --list-dependent
4890 @itemx -l
4891 List top-level dependent packages that would need to be rebuilt as a
4892 result of upgrading one or more packages.
4893
4894 @end table
4895
4896 Be aware that the @code{--list-dependent} option only
4897 @emph{approximates} the rebuilds that would be required as a result of
4898 an upgrade. More rebuilds might be required under some circumstances.
4899
4900 @example
4901 $ guix refresh --list-dependent flex
4902 Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4903 hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
4904 @end example
4905
4906 The command above lists a set of packages that could be built to check
4907 for compatibility with an upgraded @code{flex} package.
4908
4909 The following options can be used to customize GnuPG operation:
4910
4911 @table @code
4912
4913 @item --gpg=@var{command}
4914 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4915 for in @code{$PATH}.
4916
4917 @item --key-download=@var{policy}
4918 Handle missing OpenPGP keys according to @var{policy}, which may be one
4919 of:
4920
4921 @table @code
4922 @item always
4923 Always download missing OpenPGP keys from the key server, and add them
4924 to the user's GnuPG keyring.
4925
4926 @item never
4927 Never try to download missing OpenPGP keys. Instead just bail out.
4928
4929 @item interactive
4930 When a package signed with an unknown OpenPGP key is encountered, ask
4931 the user whether to download it or not. This is the default behavior.
4932 @end table
4933
4934 @item --key-server=@var{host}
4935 Use @var{host} as the OpenPGP key server when importing a public key.
4936
4937 @end table
4938
4939 The @code{github} updater uses the
4940 @uref{https://developer.github.com/v3/, GitHub API} to query for new
4941 releases. When used repeatedly e.g. when refreshing all packages,
4942 GitHub will eventually refuse to answer any further API requests. By
4943 default 60 API requests per hour are allowed, and a full refresh on all
4944 GitHub packages in Guix requires more than this. Authentication with
4945 GitHub through the use of an API token alleviates these limits. To use
4946 an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
4947 token procured from @uref{https://github.com/settings/tokens} or
4948 otherwise.
4949
4950
4951 @node Invoking guix lint
4952 @section Invoking @command{guix lint}
4953 The @command{guix lint} command is meant to help package developers avoid
4954 common errors and use a consistent style. It runs a number of checks on
4955 a given set of packages in order to find common mistakes in their
4956 definitions. Available @dfn{checkers} include (see
4957 @code{--list-checkers} for a complete list):
4958
4959 @table @code
4960 @item synopsis
4961 @itemx description
4962 Validate certain typographical and stylistic rules about package
4963 descriptions and synopses.
4964
4965 @item inputs-should-be-native
4966 Identify inputs that should most likely be native inputs.
4967
4968 @item source
4969 @itemx home-page
4970 @itemx source-file-name
4971 Probe @code{home-page} and @code{source} URLs and report those that are
4972 invalid. Check that the source file name is meaningful, e.g. is not
4973 just a version number or ``git-checkout'', without a declared
4974 @code{file-name} (@pxref{origin Reference}).
4975
4976 @item cve
4977 @cindex security vulnerabilities
4978 @cindex CVE, Common Vulnerabilities and Exposures
4979 Report known vulnerabilities found in the Common Vulnerabilities and
4980 Exposures (CVE) databases of the current and past year
4981 @uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4982 NIST}.
4983
4984 To view information about a particular vulnerability, visit pages such as:
4985
4986 @itemize
4987 @item
4988 @indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
4989 @item
4990 @indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
4991 @end itemize
4992
4993 @noindent
4994 where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
4995 @code{CVE-2015-7554}.
4996
4997 Package developers can specify in package recipes the
4998 @uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
4999 name and version of the package when they differ from the name that Guix
5000 uses, as in this example:
5001
5002 @example
5003 (package
5004 (name "grub")
5005 ;; @dots{}
5006 ;; CPE calls this package "grub2".
5007 (properties '((cpe-name . "grub2"))))
5008 @end example
5009
5010 @item formatting
5011 Warn about obvious source code formatting issues: trailing white space,
5012 use of tabulations, etc.
5013 @end table
5014
5015 The general syntax is:
5016
5017 @example
5018 guix lint @var{options} @var{package}@dots{}
5019 @end example
5020
5021 If no package is given on the command line, then all packages are checked.
5022 The @var{options} may be zero or more of the following:
5023
5024 @table @code
5025 @item --list-checkers
5026 @itemx -l
5027 List and describe all the available checkers that will be run on packages
5028 and exit.
5029
5030 @item --checkers
5031 @itemx -c
5032 Only enable the checkers specified in a comma-separated list using the
5033 names returned by @code{--list-checkers}.
5034
5035 @end table
5036
5037 @node Invoking guix size
5038 @section Invoking @command{guix size}
5039
5040 The @command{guix size} command helps package developers profile the
5041 disk usage of packages. It is easy to overlook the impact of an
5042 additional dependency added to a package, or the impact of using a
5043 single output for a package that could easily be split (@pxref{Packages
5044 with Multiple Outputs}). Such are the typical issues that
5045 @command{guix size} can highlight.
5046
5047 The command can be passed a package specification such as @code{gcc-4.8}
5048 or @code{guile:debug}, or a file name in the store. Consider this
5049 example:
5050
5051 @example
5052 $ guix size coreutils
5053 store item total self
5054 /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
5055 /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
5056 /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
5057 /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
5058 /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
5059 /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
5060 @end example
5061
5062 @cindex closure
5063 The store items listed here constitute the @dfn{transitive closure} of
5064 Coreutils---i.e., Coreutils and all its dependencies, recursively---as
5065 would be returned by:
5066
5067 @example
5068 $ guix gc -R /gnu/store/@dots{}-coreutils-8.23
5069 @end example
5070
5071 Here the output shows three columns next to store items. The first column,
5072 labeled ``total'', shows the size in mebibytes (MiB) of the closure of
5073 the store item---that is, its own size plus the size of all its
5074 dependencies. The next column, labeled ``self'', shows the size of the
5075 item itself. The last column shows the ratio of the size of the item
5076 itself to the space occupied by all the items listed here.
5077
5078 In this example, we see that the closure of Coreutils weighs in at
5079 70@tie{}MiB, half of which is taken by libc. (That libc represents a
5080 large fraction of the closure is not a problem @i{per se} because it is
5081 always available on the system anyway.)
5082
5083 When the package passed to @command{guix size} is available in the
5084 store, @command{guix size} queries the daemon to determine its
5085 dependencies, and measures its size in the store, similar to @command{du
5086 -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5087 Coreutils}).
5088
5089 When the given package is @emph{not} in the store, @command{guix size}
5090 reports information based on the available substitutes
5091 (@pxref{Substitutes}). This makes it possible it to profile disk usage of
5092 store items that are not even on disk, only available remotely.
5093
5094 You can also specify several package names:
5095
5096 @example
5097 $ guix size coreutils grep sed bash
5098 store item total self
5099 /gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
5100 /gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
5101 /gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
5102 /gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
5103 @dots{}
5104 total: 102.3 MiB
5105 @end example
5106
5107 @noindent
5108 In this example we see that the combination of the four packages takes
5109 102.3@tie{}MiB in total, which is much less than the sum of each closure
5110 since they have a lot of dependencies in common.
5111
5112 The available options are:
5113
5114 @table @option
5115
5116 @item --substitute-urls=@var{urls}
5117 Use substitute information from @var{urls}.
5118 @xref{client-substitute-urls, the same option for @code{guix build}}.
5119
5120 @item --map-file=@var{file}
5121 Write a graphical map of disk usage in PNG format to @var{file}.
5122
5123 For the example above, the map looks like this:
5124
5125 @image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5126 produced by @command{guix size}}
5127
5128 This option requires that
5129 @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5130 installed and visible in Guile's module search path. When that is not
5131 the case, @command{guix size} fails as it tries to load it.
5132
5133 @item --system=@var{system}
5134 @itemx -s @var{system}
5135 Consider packages for @var{system}---e.g., @code{x86_64-linux}.
5136
5137 @end table
5138
5139 @node Invoking guix graph
5140 @section Invoking @command{guix graph}
5141
5142 @cindex DAG
5143 Packages and their dependencies form a @dfn{graph}, specifically a
5144 directed acyclic graph (DAG). It can quickly become difficult to have a
5145 mental model of the package DAG, so the @command{guix graph} command
5146 provides a visual representation of the DAG. @command{guix graph}
5147 emits a DAG representation in the input format of
5148 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
5149 directly to the @command{dot} command of Graphviz. The general
5150 syntax is:
5151
5152 @example
5153 guix graph @var{options} @var{package}@dots{}
5154 @end example
5155
5156 For example, the following command generates a PDF file representing the
5157 package DAG for the GNU@tie{}Core Utilities, showing its build-time
5158 dependencies:
5159
5160 @example
5161 guix graph coreutils | dot -Tpdf > dag.pdf
5162 @end example
5163
5164 The output looks like this:
5165
5166 @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
5167
5168 Nice little graph, no?
5169
5170 But there is more than one graph! The one above is concise: it is the
5171 graph of package objects, omitting implicit inputs such as GCC, libc,
5172 grep, etc. It is often useful to have such a concise graph, but
5173 sometimes one may want to see more details. @command{guix graph} supports
5174 several types of graphs, allowing you to choose the level of detail:
5175
5176 @table @code
5177 @item package
5178 This is the default type used in the example above. It shows the DAG of
5179 package objects, excluding implicit dependencies. It is concise, but
5180 filters out many details.
5181
5182 @item bag-emerged
5183 This is the package DAG, @emph{including} implicit inputs.
5184
5185 For instance, the following command:
5186
5187 @example
5188 guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5189 @end example
5190
5191 ... yields this bigger graph:
5192
5193 @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5194
5195 At the bottom of the graph, we see all the implicit inputs of
5196 @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5197
5198 Now, note that the dependencies of these implicit inputs---that is, the
5199 @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5200 here, for conciseness.
5201
5202 @item bag
5203 Similar to @code{bag-emerged}, but this time including all the bootstrap
5204 dependencies.
5205
5206 @item bag-with-origins
5207 Similar to @code{bag}, but also showing origins and their dependencies.
5208
5209 @item derivations
5210 This is the most detailed representation: It shows the DAG of
5211 derivations (@pxref{Derivations}) and plain store items. Compared to
5212 the above representation, many additional nodes are visible, including
5213 build scripts, patches, Guile modules, etc.
5214
5215 For this type of graph, it is also possible to pass a @file{.drv} file
5216 name instead of a package name, as in:
5217
5218 @example
5219 guix graph -t derivation `guix system build -d my-config.scm`
5220 @end example
5221 @end table
5222
5223 All the types above correspond to @emph{build-time dependencies}. The
5224 following graph type represents the @emph{run-time dependencies}:
5225
5226 @table @code
5227 @item references
5228 This is the graph of @dfn{references} of a package output, as returned
5229 by @command{guix gc --references} (@pxref{Invoking guix gc}).
5230
5231 If the given package output is not available in the store, @command{guix
5232 graph} attempts to obtain dependency information from substitutes.
5233
5234 Here you can also pass a store file name instead of a package name. For
5235 example, the command below produces the reference graph of your profile
5236 (which can be big!):
5237
5238 @example
5239 guix graph -t references `readlink -f ~/.guix-profile`
5240 @end example
5241 @end table
5242
5243 The available options are the following:
5244
5245 @table @option
5246 @item --type=@var{type}
5247 @itemx -t @var{type}
5248 Produce a graph output of @var{type}, where @var{type} must be one of
5249 the values listed above.
5250
5251 @item --list-types
5252 List the supported graph types.
5253
5254 @item --expression=@var{expr}
5255 @itemx -e @var{expr}
5256 Consider the package @var{expr} evaluates to.
5257
5258 This is useful to precisely refer to a package, as in this example:
5259
5260 @example
5261 guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5262 @end example
5263 @end table
5264
5265
5266 @node Invoking guix environment
5267 @section Invoking @command{guix environment}
5268
5269 @cindex reproducible build environments
5270 @cindex development environments
5271 The purpose of @command{guix environment} is to assist hackers in
5272 creating reproducible development environments without polluting their
5273 package profile. The @command{guix environment} tool takes one or more
5274 packages, builds all of their inputs, and creates a shell
5275 environment to use them.
5276
5277 The general syntax is:
5278
5279 @example
5280 guix environment @var{options} @var{package}@dots{}
5281 @end example
5282
5283 The following example spawns a new shell set up for the development of
5284 GNU@tie{}Guile:
5285
5286 @example
5287 guix environment guile
5288 @end example
5289
5290 If the needed dependencies are not built yet, @command{guix environment}
5291 automatically builds them. The environment of the new shell is an augmented
5292 version of the environment that @command{guix environment} was run in.
5293 It contains the necessary search paths for building the given package
5294 added to the existing environment variables. To create a ``pure''
5295 environment, in which the original environment variables have been unset,
5296 use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5297 environment variables such as @code{PATH} in their @file{~/.bashrc}
5298 file. As a consequence, when @code{guix environment} launches it, Bash
5299 may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5300 environment variables. It is an error to define such environment
5301 variables in @file{.bashrc}; instead, they should be defined in
5302 @file{.bash_profile}, which is sourced only by log-in shells.
5303 @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5304 details on Bash start-up files.}.
5305
5306 @vindex GUIX_ENVIRONMENT
5307 @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
5308 variable in the shell it spawns. This allows users to, say, define a
5309 specific prompt for development environments in their @file{.bashrc}
5310 (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5311
5312 @example
5313 if [ -n "$GUIX_ENVIRONMENT" ]
5314 then
5315 export PS1="\u@@\h \w [dev]\$ "
5316 fi
5317 @end example
5318
5319 Additionally, more than one package may be specified, in which case the
5320 union of the inputs for the given packages are used. For example, the
5321 command below spawns a shell where all of the dependencies of both Guile
5322 and Emacs are available:
5323
5324 @example
5325 guix environment guile emacs
5326 @end example
5327
5328 Sometimes an interactive shell session is not desired. An arbitrary
5329 command may be invoked by placing the @code{--} token to separate the
5330 command from the rest of the arguments:
5331
5332 @example
5333 guix environment guile -- make -j4
5334 @end example
5335
5336 In other situations, it is more convenient to specify the list of
5337 packages needed in the environment. For example, the following command
5338 runs @command{python} from an environment containing Python@tie{}2.7 and
5339 NumPy:
5340
5341 @example
5342 guix environment --ad-hoc python2-numpy python-2.7 -- python
5343 @end example
5344
5345 Furthermore, one might want the dependencies of a package and also some
5346 additional packages that are not build-time or runtime dependencies, but
5347 are useful when developing nonetheless. Because of this, the
5348 @code{--ad-hoc} flag is positional. Packages appearing before
5349 @code{--ad-hoc} are interpreted as packages whose dependencies will be
5350 added to the environment. Packages appearing after are interpreted as
5351 packages that will be added to the environment directly. For example,
5352 the following command creates a Guix development environment that
5353 additionally includes Git and strace:
5354
5355 @example
5356 guix environment guix --ad-hoc git strace
5357 @end example
5358
5359 Sometimes it is desirable to isolate the environment as much as
5360 possible, for maximal purity and reproducibility. In particular, when
5361 using Guix on a host distro that is not GuixSD, it is desirable to
5362 prevent access to @file{/usr/bin} and other system-wide resources from
5363 the development environment. For example, the following command spawns
5364 a Guile REPL in a ``container'' where only the store and the current
5365 working directory are mounted:
5366
5367 @example
5368 guix environment --ad-hoc --container guile -- guile
5369 @end example
5370
5371 @quotation Note
5372 The @code{--container} option requires Linux-libre 3.19 or newer.
5373 @end quotation
5374
5375 The available options are summarized below.
5376
5377 @table @code
5378 @item --expression=@var{expr}
5379 @itemx -e @var{expr}
5380 Create an environment for the package or list of packages that
5381 @var{expr} evaluates to.
5382
5383 For example, running:
5384
5385 @example
5386 guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5387 @end example
5388
5389 starts a shell with the environment for this specific variant of the
5390 PETSc package.
5391
5392 Running:
5393
5394 @example
5395 guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
5396 @end example
5397
5398 starts a shell with all the GuixSD base packages available.
5399
5400 The above commands only the use default output of the given packages.
5401 To select other outputs, two element tuples can be specified:
5402
5403 @example
5404 guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5405 @end example
5406
5407 @item --load=@var{file}
5408 @itemx -l @var{file}
5409 Create an environment for the package or list of packages that the code
5410 within @var{file} evaluates to.
5411
5412 As an example, @var{file} might contain a definition like this
5413 (@pxref{Defining Packages}):
5414
5415 @example
5416 @verbatiminclude environment-gdb.scm
5417 @end example
5418
5419 @item --ad-hoc
5420 Include all specified packages in the resulting environment, as if an
5421 @i{ad hoc} package were defined with them as inputs. This option is
5422 useful for quickly creating an environment without having to write a
5423 package expression to contain the desired inputs.
5424
5425 For instance, the command:
5426
5427 @example
5428 guix environment --ad-hoc guile guile-sdl -- guile
5429 @end example
5430
5431 runs @command{guile} in an environment where Guile and Guile-SDL are
5432 available.
5433
5434 Note that this example implicitly asks for the default output of
5435 @code{guile} and @code{guile-sdl}, but it is possible to ask for a
5436 specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5437 of @code{glib} (@pxref{Packages with Multiple Outputs}).
5438
5439 This option may be composed with the default behavior of @command{guix
5440 environment}. Packages appearing before @code{--ad-hoc} are interpreted
5441 as packages whose dependencies will be added to the environment, the
5442 default behavior. Packages appearing after are interpreted as packages
5443 that will be added to the environment directly.
5444
5445 @item --pure
5446 Unset existing environment variables when building the new environment.
5447 This has the effect of creating an environment in which search paths
5448 only contain package inputs.
5449
5450 @item --search-paths
5451 Display the environment variable definitions that make up the
5452 environment.
5453
5454 @item --system=@var{system}
5455 @itemx -s @var{system}
5456 Attempt to build for @var{system}---e.g., @code{i686-linux}.
5457
5458 @item --container
5459 @itemx -C
5460 @cindex container
5461 Run @var{command} within an isolated container. The current working
5462 directory outside the container is mapped inside the container.
5463 Additionally, a dummy home directory is created that matches the current
5464 user's home directory, and @file{/etc/passwd} is configured accordingly.
5465 The spawned process runs as the current user outside the container, but
5466 has root privileges in the context of the container.
5467
5468 @item --network
5469 @itemx -N
5470 For containers, share the network namespace with the host system.
5471 Containers created without this flag only have access to the loopback
5472 device.
5473
5474 @item --expose=@var{source}[=@var{target}]
5475 For containers, expose the file system @var{source} from the host system
5476 as the read-only file system @var{target} within the container. If
5477 @var{target} is not specified, @var{source} is used as the target mount
5478 point in the container.
5479
5480 The example below spawns a Guile REPL in a container in which the user's
5481 home directory is accessible read-only via the @file{/exchange}
5482 directory:
5483
5484 @example
5485 guix environment --container --expose=$HOME=/exchange guile -- guile
5486 @end example
5487
5488 @item --share=@var{source}[=@var{target}]
5489 For containers, share the file system @var{source} from the host system
5490 as the writable file system @var{target} within the container. If
5491 @var{target} is not specified, @var{source} is used as the target mount
5492 point in the container.
5493
5494 The example below spawns a Guile REPL in a container in which the user's
5495 home directory is accessible for both reading and writing via the
5496 @file{/exchange} directory:
5497
5498 @example
5499 guix environment --container --share=$HOME=/exchange guile -- guile
5500 @end example
5501 @end table
5502
5503 It also supports all of the common build options that @command{guix
5504 build} supports (@pxref{Common Build Options}).
5505
5506 @node Invoking guix publish
5507 @section Invoking @command{guix publish}
5508
5509 The purpose of @command{guix publish} is to enable users to easily share
5510 their store with others, who can then use it as a substitute server
5511 (@pxref{Substitutes}).
5512
5513 When @command{guix publish} runs, it spawns an HTTP server which allows
5514 anyone with network access to obtain substitutes from it. This means
5515 that any machine running Guix can also act as if it were a build farm,
5516 since the HTTP interface is compatible with Hydra, the software behind
5517 the @code{hydra.gnu.org} build farm.
5518
5519 For security, each substitute is signed, allowing recipients to check
5520 their authenticity and integrity (@pxref{Substitutes}). Because
5521 @command{guix publish} uses the signing key of the system, which is only
5522 readable by the system administrator, it must be started as root; the
5523 @code{--user} option makes it drop root privileges early on.
5524
5525 The signing key pair must be generated before @command{guix publish} is
5526 launched, using @command{guix archive --generate-key} (@pxref{Invoking
5527 guix archive}).
5528
5529 The general syntax is:
5530
5531 @example
5532 guix publish @var{options}@dots{}
5533 @end example
5534
5535 Running @command{guix publish} without any additional arguments will
5536 spawn an HTTP server on port 8080:
5537
5538 @example
5539 guix publish
5540 @end example
5541
5542 Once a publishing server has been authorized (@pxref{Invoking guix
5543 archive}), the daemon may download substitutes from it:
5544
5545 @example
5546 guix-daemon --substitute-urls=http://example.org:8080
5547 @end example
5548
5549 The following options are available:
5550
5551 @table @code
5552 @item --port=@var{port}
5553 @itemx -p @var{port}
5554 Listen for HTTP requests on @var{port}.
5555
5556 @item --listen=@var{host}
5557 Listen on the network interface for @var{host}. The default is to
5558 accept connections from any interface.
5559
5560 @item --user=@var{user}
5561 @itemx -u @var{user}
5562 Change privileges to @var{user} as soon as possible---i.e., once the
5563 server socket is open and the signing key has been read.
5564
5565 @item --ttl=@var{ttl}
5566 Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
5567 (TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
5568 days, @code{1m} means 1 month, and so on.
5569
5570 This allows the user's Guix to keep substitute information in cache for
5571 @var{ttl}. However, note that @code{guix publish} does not itself
5572 guarantee that the store items it provides will indeed remain available
5573 for as long as @var{ttl}.
5574
5575 @item --repl[=@var{port}]
5576 @itemx -r [@var{port}]
5577 Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
5578 Reference Manual}) on @var{port} (37146 by default). This is used
5579 primarily for debugging a running @command{guix publish} server.
5580 @end table
5581
5582 Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5583 add a call to @code{guix-publish-service} in the @code{services} field
5584 of the @code{operating-system} declaration (@pxref{guix-publish-service,
5585 @code{guix-publish-service}}).
5586
5587
5588 @node Invoking guix challenge
5589 @section Invoking @command{guix challenge}
5590
5591 @cindex reproducible builds
5592 @cindex verifiable builds
5593
5594 Do the binaries provided by this server really correspond to the source
5595 code it claims to build? Is a package build process deterministic?
5596 These are the questions the @command{guix challenge} command attempts to
5597 answer.
5598
5599 The former is obviously an important question: Before using a substitute
5600 server (@pxref{Substitutes}), one had better @emph{verify} that it
5601 provides the right binaries, and thus @emph{challenge} it. The latter
5602 is what enables the former: If package builds are deterministic, then
5603 independent builds of the package should yield the exact same result,
5604 bit for bit; if a server provides a binary different from the one
5605 obtained locally, it may be either corrupt or malicious.
5606
5607 We know that the hash that shows up in @file{/gnu/store} file names is
5608 the hash of all the inputs of the process that built the file or
5609 directory---compilers, libraries, build scripts,
5610 etc. (@pxref{Introduction}). Assuming deterministic build processes,
5611 one store file name should map to exactly one build output.
5612 @command{guix challenge} checks whether there is, indeed, a single
5613 mapping by comparing the build outputs of several independent builds of
5614 any given store item.
5615
5616 The command output looks like this:
5617
5618 @smallexample
5619 $ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
5620 updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
5621 updating list of substitutes from 'https://guix.example.org'... 100.0%
5622 /gnu/store/@dots{}-openssl-1.0.2d contents differ:
5623 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5624 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5625 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5626 /gnu/store/@dots{}-git-2.5.0 contents differ:
5627 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5628 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5629 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5630 /gnu/store/@dots{}-pius-2.1.1 contents differ:
5631 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5632 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5633 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5634 @end smallexample
5635
5636 @noindent
5637 In this example, @command{guix challenge} first scans the store to
5638 determine the set of locally-built derivations---as opposed to store
5639 items that were downloaded from a substitute server---and then queries
5640 all the substitute servers. It then reports those store items for which
5641 the servers obtained a result different from the local build.
5642
5643 @cindex non-determinism, in package builds
5644 As an example, @code{guix.example.org} always gets a different answer.
5645 Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5646 case of Git. This might indicate that the build process of Git is
5647 non-deterministic, meaning that its output varies as a function of
5648 various things that Guix does not fully control, in spite of building
5649 packages in isolated environments (@pxref{Features}). Most common
5650 sources of non-determinism include the addition of timestamps in build
5651 results, the inclusion of random numbers, and directory listings sorted
5652 by inode number. See @uref{https://reproducible-builds.org/docs/}, for
5653 more information.
5654
5655 To find out what is wrong with this Git binary, we can do something along
5656 these lines (@pxref{Invoking guix archive}):
5657
5658 @example
5659 $ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5660 | guix archive -x /tmp/git
5661 $ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
5662 @end example
5663
5664 This command shows the difference between the files resulting from the
5665 local build, and the files resulting from the build on
5666 @code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5667 diffutils, Comparing and Merging Files}). The @command{diff} command
5668 works great for text files. When binary files differ, a better option
5669 is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
5670 visualize differences for all kinds of files.
5671
5672 Once you have done that work, you can tell whether the differences are due
5673 to a non-deterministic build process or to a malicious server. We try
5674 hard to remove sources of non-determinism in packages to make it easier
5675 to verify substitutes, but of course, this is a process that
5676 involves not just Guix, but a large part of the free software community.
5677 In the meantime, @command{guix challenge} is one tool to help address
5678 the problem.
5679
5680 If you are writing packages for Guix, you are encouraged to check
5681 whether @code{hydra.gnu.org} and other substitute servers obtain the
5682 same build result as you did with:
5683
5684 @example
5685 $ guix challenge @var{package}
5686 @end example
5687
5688 @noindent
5689 where @var{package} is a package specification such as
5690 @code{guile@@2.0} or @code{glibc:debug}.
5691
5692 The general syntax is:
5693
5694 @example
5695 guix challenge @var{options} [@var{packages}@dots{}]
5696 @end example
5697
5698 When a difference is found between the hash of a locally-built item and
5699 that of a server-provided substitute, or among substitutes provided by
5700 different servers, the command displays it as in the example above and
5701 its exit code is 2 (other non-zero exit codes denote other kinds of
5702 errors.)
5703
5704 The one option that matters is:
5705
5706 @table @code
5707
5708 @item --substitute-urls=@var{urls}
5709 Consider @var{urls} the whitespace-separated list of substitute source
5710 URLs to compare to.
5711
5712 @end table
5713
5714
5715 @node Invoking guix container
5716 @section Invoking @command{guix container}
5717 @cindex container
5718
5719 @quotation Note
5720 As of version @value{VERSION}, this tool is experimental. The interface
5721 is subject to radical change in the future.
5722 @end quotation
5723
5724 The purpose of @command{guix container} is to manipulate processes
5725 running within an isolated environment, commonly known as a
5726 ``container'', typically created by the @command{guix environment}
5727 (@pxref{Invoking guix environment}) and @command{guix system container}
5728 (@pxref{Invoking guix system}) commands.
5729
5730 The general syntax is:
5731
5732 @example
5733 guix container @var{action} @var{options}@dots{}
5734 @end example
5735
5736 @var{action} specifies the operation to perform with a container, and
5737 @var{options} specifies the context-specific arguments for the action.
5738
5739 The following actions are available:
5740
5741 @table @code
5742 @item exec
5743 Execute a command within the context of a running container.
5744
5745 The syntax is:
5746
5747 @example
5748 guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5749 @end example
5750
5751 @var{pid} specifies the process ID of the running container.
5752 @var{program} specifies an executable file name within the root file
5753 system of the container. @var{arguments} are the additional options that
5754 will be passed to @var{program}.
5755
5756 The following command launches an interactive login shell inside a
5757 GuixSD container, started by @command{guix system container}, and whose
5758 process ID is 9001:
5759
5760 @example
5761 guix container exec 9001 /run/current-system/profile/bin/bash --login
5762 @end example
5763
5764 Note that the @var{pid} cannot be the parent process of a container. It
5765 must be PID 1 of the container or one of its child processes.
5766
5767 @end table
5768
5769 @c *********************************************************************
5770 @node GNU Distribution
5771 @chapter GNU Distribution
5772
5773 @cindex Guix System Distribution
5774 @cindex GuixSD
5775 Guix comes with a distribution of the GNU system consisting entirely of
5776 free software@footnote{The term ``free'' here refers to the
5777 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
5778 users of that software}.}. The
5779 distribution can be installed on its own (@pxref{System Installation}),
5780 but it is also possible to install Guix as a package manager on top of
5781 an installed GNU/Linux system (@pxref{Installation}). To distinguish
5782 between the two, we refer to the standalone distribution as the Guix
5783 System Distribution, or GuixSD.
5784
5785 The distribution provides core GNU packages such as GNU libc, GCC, and
5786 Binutils, as well as many GNU and non-GNU applications. The complete
5787 list of available packages can be browsed
5788 @url{http://www.gnu.org/software/guix/packages,on-line} or by
5789 running @command{guix package} (@pxref{Invoking guix package}):
5790
5791 @example
5792 guix package --list-available
5793 @end example
5794
5795 Our goal is to provide a practical 100% free software distribution of
5796 Linux-based and other variants of GNU, with a focus on the promotion and
5797 tight integration of GNU components, and an emphasis on programs and
5798 tools that help users exert that freedom.
5799
5800 Packages are currently available on the following platforms:
5801
5802 @table @code
5803
5804 @item x86_64-linux
5805 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5806
5807 @item i686-linux
5808 Intel 32-bit architecture (IA32), Linux-Libre kernel;
5809
5810 @item armhf-linux
5811 ARMv7-A architecture with hard float, Thumb-2 and NEON,
5812 using the EABI hard-float application binary interface (ABI),
5813 and Linux-Libre kernel.
5814
5815 @item mips64el-linux
5816 little-endian 64-bit MIPS processors, specifically the Loongson series,
5817 n32 ABI, and Linux-Libre kernel.
5818
5819 @end table
5820
5821 GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
5822
5823 @noindent
5824 For information on porting to other architectures or kernels,
5825 @pxref{Porting}.
5826
5827 @menu
5828 * System Installation:: Installing the whole operating system.
5829 * System Configuration:: Configuring the operating system.
5830 * Installing Debugging Files:: Feeding the debugger.
5831 * Security Updates:: Deploying security fixes quickly.
5832 * Package Modules:: Packages from the programmer's viewpoint.
5833 * Packaging Guidelines:: Growing the distribution.
5834 * Bootstrapping:: GNU/Linux built from scratch.
5835 * Porting:: Targeting another platform or kernel.
5836 @end menu
5837
5838 Building this distribution is a cooperative effort, and you are invited
5839 to join! @xref{Contributing}, for information about how you can help.
5840
5841 @node System Installation
5842 @section System Installation
5843
5844 @cindex Guix System Distribution
5845 This section explains how to install the Guix System Distribution
5846 on a machine. The Guix package manager can
5847 also be installed on top of a running GNU/Linux system,
5848 @pxref{Installation}.
5849
5850 @ifinfo
5851 @quotation Note
5852 @c This paragraph is for people reading this from tty2 of the
5853 @c installation image.
5854 You are reading this documentation with an Info reader. For details on
5855 how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
5856 link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
5857 Info}. Hit @kbd{l} afterwards to come back here.
5858
5859 Alternately, run @command{info info} in another tty to keep the manual
5860 available.
5861 @end quotation
5862 @end ifinfo
5863
5864 @menu
5865 * Limitations:: What you can expect.
5866 * Hardware Considerations:: Supported hardware.
5867 * USB Stick Installation:: Preparing the installation medium.
5868 * Preparing for Installation:: Networking, partitioning, etc.
5869 * Proceeding with the Installation:: The real thing.
5870 * Building the Installation Image:: How this comes to be.
5871 @end menu
5872
5873 @node Limitations
5874 @subsection Limitations
5875
5876 As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
5877 not production-ready. It may contain bugs and lack important
5878 features. Thus, if you are looking for a stable production system that
5879 respects your freedom as a computer user, a good solution at this point
5880 is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
5881 the more established GNU/Linux distributions}. We hope you can soon switch
5882 to the GuixSD without fear, of course. In the meantime, you can
5883 also keep using your distribution and try out the package manager on top
5884 of it (@pxref{Installation}).
5885
5886 Before you proceed with the installation, be aware of the following
5887 noteworthy limitations applicable to version @value{VERSION}:
5888
5889 @itemize
5890 @item
5891 The installation process does not include a graphical user interface and
5892 requires familiarity with GNU/Linux (see the following subsections to
5893 get a feel of what that means.)
5894
5895 @item
5896 Support for the Logical Volume Manager (LVM) is missing.
5897
5898 @item
5899 Few system services are currently supported out-of-the-box
5900 (@pxref{Services}).
5901
5902 @item
5903 More than 3,200 packages are available, but you may
5904 occasionally find that a useful package is missing.
5905
5906 @item
5907 GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
5908 as well as a number of X11 window managers. However, some graphical
5909 applications may be missing, as well as KDE.
5910 @end itemize
5911
5912 You have been warned! But more than a disclaimer, this is an invitation
5913 to report issues (and success stories!), and to join us in improving it.
5914 @xref{Contributing}, for more info.
5915
5916
5917 @node Hardware Considerations
5918 @subsection Hardware Considerations
5919
5920 @cindex hardware support on GuixSD
5921 GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
5922 builds around the kernel Linux-libre, which means that only hardware for
5923 which free software drivers and firmware exist is supported. Nowadays,
5924 a wide range of off-the-shelf hardware is supported on
5925 GNU/Linux-libre---from keyboards to graphics cards to scanners and
5926 Ethernet controllers. Unfortunately, there are still areas where
5927 hardware vendors deny users control over their own computing, and such
5928 hardware is not supported on GuixSD.
5929
5930 @cindex WiFi, hardware support
5931 One of the main areas where free drivers or firmware are lacking is WiFi
5932 devices. WiFi devices known to work include those using Atheros chips
5933 (AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
5934 driver, and for which free firmware exists and is available
5935 out-of-the-box on GuixSD, as part of @var{%base-firmware}
5936 (@pxref{operating-system Reference, @code{firmware}}).
5937
5938 @cindex RYF, Respects Your Freedom
5939 The @uref{https://www.fsf.org/, Free Software Foundation} runs
5940 @uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
5941 certification program for hardware products that respect your freedom
5942 and your privacy and ensure that you have control over your device. We
5943 encourage you to check the list of RYF-certified devices.
5944
5945 Another useful resource is the @uref{https://www.h-node.org/, H-Node}
5946 web site. It contains a catalog of hardware devices with information
5947 about their support in GNU/Linux.
5948
5949
5950 @node USB Stick Installation
5951 @subsection USB Stick Installation
5952
5953 An installation image for USB sticks can be downloaded from
5954 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5955 where @var{system} is one of:
5956
5957 @table @code
5958 @item x86_64-linux
5959 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5960
5961 @item i686-linux
5962 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5963 @end table
5964
5965 This image contains a single partition with the tools necessary for an
5966 installation. It is meant to be copied @emph{as is} to a large-enough
5967 USB stick.
5968
5969 To copy the image to a USB stick, follow these steps:
5970
5971 @enumerate
5972 @item
5973 Decompress the image using the @command{xz} command:
5974
5975 @example
5976 xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5977 @end example
5978
5979 @item
5980 Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
5981 its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5982 copy the image with:
5983
5984 @example
5985 dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5986 @end example
5987
5988 Access to @file{/dev/sdX} usually requires root privileges.
5989 @end enumerate
5990
5991 Once this is done, you should be able to reboot the system and boot from
5992 the USB stick. The latter usually requires you to get in the BIOS' boot
5993 menu, where you can choose to boot from the USB stick.
5994
5995 @node Preparing for Installation
5996 @subsection Preparing for Installation
5997
5998 Once you have successfully booted the image on the USB stick, you should
5999 end up with a root prompt. Several console TTYs are configured and can
6000 be used to run commands as root. TTY2 shows this documentation,
6001 browsable using the Info reader commands (@pxref{Top,,, info-stnd,
6002 Stand-alone GNU Info}). The installation system runs the GPM mouse
6003 daemon, which allows you to select text with the left mouse button and
6004 to paste it with the middle button.
6005
6006 @quotation Note
6007 Installation requires access to the Internet so that any missing
6008 dependencies of your system configuration can be downloaded. See the
6009 ``Networking'' section below.
6010 @end quotation
6011
6012 The installation system includes many common tools needed for this task.
6013 But it is also a full-blown GuixSD system, which means that you can
6014 install additional packages, should you need it, using @command{guix
6015 package} (@pxref{Invoking guix package}).
6016
6017 @subsubsection Keyboard Layout
6018
6019 @cindex keyboard layout
6020 The installation image uses the US qwerty keyboard layout. If you want
6021 to change it, you can use the @command{loadkeys} command. For example,
6022 the following command selects the Dvorak keyboard layout:
6023
6024 @example
6025 loadkeys dvorak
6026 @end example
6027
6028 See the files under @file{/run/current-system/profile/share/keymaps} for
6029 a list of available keyboard layouts. Run @command{man loadkeys} for
6030 more information.
6031
6032 @subsubsection Networking
6033
6034 Run the following command see what your network interfaces are called:
6035
6036 @example
6037 ifconfig -a
6038 @end example
6039
6040 @noindent
6041 @dots{} or, using the GNU/Linux-specific @command{ip} command:
6042
6043 @example
6044 ip a
6045 @end example
6046
6047 @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
6048 Wired interfaces have a name starting with @samp{e}; for example, the
6049 interface corresponding to the first on-board Ethernet controller is
6050 called @samp{eno1}. Wireless interfaces have a name starting with
6051 @samp{w}, like @samp{w1p2s0}.
6052
6053 @table @asis
6054 @item Wired connection
6055 To configure a wired network run the following command, substituting
6056 @var{interface} with the name of the wired interface you want to use.
6057
6058 @example
6059 ifconfig @var{interface} up
6060 @end example
6061
6062 @item Wireless connection
6063 To configure wireless networking, you can create a configuration file
6064 for the @command{wpa_supplicant} configuration tool (its location is not
6065 important) using one of the available text editors such as
6066 @command{zile}:
6067
6068 @example
6069 zile wpa_supplicant.conf
6070 @end example
6071
6072 As an example, the following stanza can go to this file and will work
6073 for many wireless networks, provided you give the actual SSID and
6074 passphrase for the network you are connecting to:
6075
6076 @example
6077 network=@{
6078 ssid="@var{my-ssid}"
6079 key_mgmt=WPA-PSK
6080 psk="the network's secret passphrase"
6081 @}
6082 @end example
6083
6084 Start the wireless service and run it in the background with the
6085 following command (substitute @var{interface} with the name of the
6086 network interface you want to use):
6087
6088 @example
6089 wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
6090 @end example
6091
6092 Run @command{man wpa_supplicant} for more information.
6093 @end table
6094
6095 At this point, you need to acquire an IP address. On a network where IP
6096 addresses are automatically assigned @i{via} DHCP, you can run:
6097
6098 @example
6099 dhclient -v @var{interface}
6100 @end example
6101
6102 Try to ping a server to see if networking is up and running:
6103
6104 @example
6105 ping -c 3 gnu.org
6106 @end example
6107
6108 Setting up network access is almost always a requirement because the
6109 image does not contain all the software and tools that may be needed.
6110
6111 @subsubsection Disk Partitioning
6112
6113 Unless this has already been done, the next step is to partition, and
6114 then format the target partition(s).
6115
6116 The installation image includes several partitioning tools, including
6117 Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
6118 @command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
6119 the partition layout you want:
6120
6121 @example
6122 cfdisk
6123 @end example
6124
6125 Once you are done partitioning the target hard disk drive, you have to
6126 create a file system on the relevant partition(s)@footnote{Currently
6127 GuixSD pretty much assumes an ext4 file system. In particular, code
6128 that reads partition UUIDs and labels only works with ext4. This will
6129 be fixed in the future.}.
6130
6131 Preferably, assign partitions a label so that you can easily and
6132 reliably refer to them in @code{file-system} declarations (@pxref{File
6133 Systems}). This is typically done using the @code{-L} option of
6134 @command{mkfs.ext4} and related commands. So, assuming the target root
6135 partition lives at @file{/dev/sda1}, a file system with the label
6136 @code{my-root} can be created with:
6137
6138 @example
6139 mkfs.ext4 -L my-root /dev/sda1
6140 @end example
6141
6142 @c FIXME: Uncomment this once GRUB fully supports encrypted roots.
6143 @c A typical command sequence may be:
6144 @c
6145 @c @example
6146 @c # fdisk /dev/sdX
6147 @c @dots{} Create partitions etc.@dots{}
6148 @c # cryptsetup luksFormat /dev/sdX1
6149 @c # cryptsetup open --type luks /dev/sdX1 my-partition
6150 @c # mkfs.ext4 -L my-root /dev/mapper/my-partition
6151 @c @end example
6152
6153 In addition to e2fsprogs, the suite of tools to manipulate
6154 ext2/ext3/ext4 file systems, the installation image includes
6155 Cryptsetup/LUKS for disk encryption.
6156
6157 Once that is done, mount the target root partition under @file{/mnt}
6158 with a command like (again, assuming @file{/dev/sda1} is the root
6159 partition):
6160
6161 @example
6162 mount /dev/sda1 /mnt
6163 @end example
6164
6165 Finally, if you plan to use one or more swap partitions (@pxref{Memory
6166 Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
6167 sure to initialize them with @command{mkswap}. Assuming you have one
6168 swap partition on @file{/dev/sda2}, you would run:
6169
6170 @example
6171 mkswap /dev/sda2
6172 @end example
6173
6174 @node Proceeding with the Installation
6175 @subsection Proceeding with the Installation
6176
6177 With the target partitions ready and the target root mounted on
6178 @file{/mnt}, we're ready to go. First, run:
6179
6180 @example
6181 herd start cow-store /mnt
6182 @end example
6183
6184 This makes @file{/gnu/store} copy-on-write, such that packages added to it
6185 during the installation phase are written to the target disk on @file{/mnt}
6186 rather than kept in memory. This is necessary because the first phase of
6187 the @command{guix system init} command (see below) entails downloads or
6188 builds to @file{/gnu/store} which, initially, is an in-memory file system.
6189
6190 Next, you have to edit a file and
6191 provide the declaration of the operating system to be installed. To
6192 that end, the installation system comes with two text editors: GNU nano
6193 (@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
6194 We strongly recommend storing that file on the target root file system, say,
6195 as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
6196 configuration file once you have rebooted into the newly-installed system.
6197
6198 @xref{Using the Configuration System}, for an overview of the
6199 configuration file. The example configurations discussed in that
6200 section are available under @file{/etc/configuration} in the
6201 installation image. Thus, to get started with a system configuration
6202 providing a graphical display server (a ``desktop'' system), you can run
6203 something along these lines:
6204
6205 @example
6206 # mkdir /mnt/etc
6207 # cp /etc/configuration/desktop.scm /mnt/etc/config.scm
6208 # zile /mnt/etc/config.scm
6209 @end example
6210
6211 You should pay attention to what your configuration file contains, and
6212 in particular:
6213
6214 @itemize
6215 @item
6216 Make sure the @code{grub-configuration} form refers to the device you
6217 want to install GRUB on.
6218
6219 @item
6220 Be sure that your partition labels match the value of their respective
6221 @code{device} fields in your @code{file-system} configuration, assuming
6222 your @code{file-system} configuration sets the value of @code{title} to
6223 @code{'label}.
6224 @end itemize
6225
6226 Once you are done preparing the configuration file, the new system must
6227 be initialized (remember that the target root file system is mounted
6228 under @file{/mnt}):
6229
6230 @example
6231 guix system init /mnt/etc/config.scm /mnt
6232 @end example
6233
6234 @noindent
6235 This copies all the necessary files and installs GRUB on
6236 @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6237 more information, @pxref{Invoking guix system}. This command may trigger
6238 downloads or builds of missing packages, which can take some time.
6239
6240 Once that command has completed---and hopefully succeeded!---you can run
6241 @command{reboot} and boot into the new system. The @code{root} password
6242 in the new system is initially empty; other users' passwords need to be
6243 initialized by running the @command{passwd} command as @code{root},
6244 unless your configuration specifies otherwise
6245 (@pxref{user-account-password, user account passwords}).
6246
6247 Join us on @code{#guix} on the Freenode IRC network or on
6248 @file{guix-devel@@gnu.org} to share your experience---good or not so
6249 good.
6250
6251 @node Building the Installation Image
6252 @subsection Building the Installation Image
6253
6254 The installation image described above was built using the @command{guix
6255 system} command, specifically:
6256
6257 @c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
6258 @example
6259 guix system disk-image --image-size=1G gnu/system/install.scm
6260 @end example
6261
6262 Have a look at @file{gnu/system/install.scm} in the source tree,
6263 and see also @ref{Invoking guix system} for more information
6264 about the installation image.
6265
6266 @node System Configuration
6267 @section System Configuration
6268
6269 @cindex system configuration
6270 The Guix System Distribution supports a consistent whole-system configuration
6271 mechanism. By that we mean that all aspects of the global system
6272 configuration---such as the available system services, timezone and
6273 locale settings, user accounts---are declared in a single place. Such
6274 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
6275
6276 One of the advantages of putting all the system configuration under the
6277 control of Guix is that it supports transactional system upgrades, and
6278 makes it possible to roll back to a previous system instantiation,
6279 should something go wrong with the new one (@pxref{Features}). Another
6280 advantage is that it makes it easy to replicate the exact same configuration
6281 across different machines, or at different points in time, without
6282 having to resort to additional administration tools layered on top of
6283 the own tools of the system.
6284 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
6285
6286 This section describes this mechanism. First we focus on the system
6287 administrator's viewpoint---explaining how the system is configured and
6288 instantiated. Then we show how this mechanism can be extended, for
6289 instance to support new system services.
6290
6291 @menu
6292 * Using the Configuration System:: Customizing your GNU system.
6293 * operating-system Reference:: Detail of operating-system declarations.
6294 * File Systems:: Configuring file system mounts.
6295 * Mapped Devices:: Block device extra processing.
6296 * User Accounts:: Specifying user accounts.
6297 * Locales:: Language and cultural convention settings.
6298 * Services:: Specifying system services.
6299 * Setuid Programs:: Programs running with root privileges.
6300 * X.509 Certificates:: Authenticating HTTPS servers.
6301 * Name Service Switch:: Configuring libc's name service switch.
6302 * Initial RAM Disk:: Linux-Libre bootstrapping.
6303 * GRUB Configuration:: Configuring the boot loader.
6304 * Invoking guix system:: Instantiating a system configuration.
6305 * Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
6306 * Defining Services:: Adding new service definitions.
6307 @end menu
6308
6309 @node Using the Configuration System
6310 @subsection Using the Configuration System
6311
6312 The operating system is configured by providing an
6313 @code{operating-system} declaration in a file that can then be passed to
6314 the @command{guix system} command (@pxref{Invoking guix system}). A
6315 simple setup, with the default system services, the default Linux-Libre
6316 kernel, initial RAM disk, and boot loader looks like this:
6317
6318 @findex operating-system
6319 @lisp
6320 @include os-config-bare-bones.texi
6321 @end lisp
6322
6323 This example should be self-describing. Some of the fields defined
6324 above, such as @code{host-name} and @code{bootloader}, are mandatory.
6325 Others, such as @code{packages} and @code{services}, can be omitted, in
6326 which case they get a default value.
6327
6328 Below we discuss the effect of some of the most important fields
6329 (@pxref{operating-system Reference}, for details about all the available
6330 fields), and how to @dfn{instantiate} the operating system using
6331 @command{guix system}.
6332
6333 @unnumberedsubsubsec Globally-Visible Packages
6334
6335 @vindex %base-packages
6336 The @code{packages} field lists packages that will be globally visible
6337 on the system, for all user accounts---i.e., in every user's @code{PATH}
6338 environment variable---in addition to the per-user profiles
6339 (@pxref{Invoking guix package}). The @var{%base-packages} variable
6340 provides all the tools one would expect for basic user and administrator
6341 tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6342 the GNU Zile lightweight text editor, @command{find}, @command{grep},
6343 etc. The example above adds tcpdump to those, taken from the @code{(gnu
6344 packages admin)} module (@pxref{Package Modules}).
6345
6346 @findex specification->package
6347 Referring to packages by variable name, like @var{tcpdump} above, has
6348 the advantage of being unambiguous; it also allows typos and such to be
6349 diagnosed right away as ``unbound variables''. The downside is that one
6350 needs to know which module defines which package, and to augment the
6351 @code{use-package-modules} line accordingly. To avoid that, one can use
6352 the @code{specification->package} procedure of the @code{(gnu packages)}
6353 module, which returns the best package for a given name or name and
6354 version:
6355
6356 @lisp
6357 (use-modules (gnu packages))
6358
6359 (operating-system
6360 ;; ...
6361 (packages (append (map specification->package
6362 '("tcpdump" "htop" "gnupg@@2.0"))
6363 %base-packages)))
6364 @end lisp
6365
6366 @unnumberedsubsubsec System Services
6367
6368 @vindex %base-services
6369 The @code{services} field lists @dfn{system services} to be made
6370 available when the system starts (@pxref{Services}).
6371 The @code{operating-system} declaration above specifies that, in
6372 addition to the basic services, we want the @command{lshd} secure shell
6373 daemon listening on port 2222 (@pxref{Networking Services,
6374 @code{lsh-service}}). Under the hood,
6375 @code{lsh-service} arranges so that @code{lshd} is started with the
6376 right command-line options, possibly with supporting configuration files
6377 generated as needed (@pxref{Defining Services}).
6378
6379 @cindex customization, of services
6380 @findex modify-services
6381 Occasionally, instead of using the base services as is, you will want to
6382 customize them. To do this, use @code{modify-services} (@pxref{Service
6383 Reference, @code{modify-services}}) to modify the list.
6384
6385 For example, suppose you want to modify @code{guix-daemon} and Mingetty
6386 (the console log-in) in the @var{%base-services} list (@pxref{Base
6387 Services, @code{%base-services}}). To do that, you can write the
6388 following in your operating system declaration:
6389
6390 @lisp
6391 (define %my-services
6392 ;; My very own list of services.
6393 (modify-services %base-services
6394 (guix-service-type config =>
6395 (guix-configuration
6396 (inherit config)
6397 (use-substitutes? #f)
6398 (extra-options '("--gc-keep-derivations"))))
6399 (mingetty-service-type config =>
6400 (mingetty-configuration
6401 (inherit config)
6402 (motd (plain-file "motd" "Howdy!"))))))
6403
6404 (operating-system
6405 ;; @dots{}
6406 (services %my-services))
6407 @end lisp
6408
6409 This changes the configuration---i.e., the service parameters---of the
6410 @code{guix-service-type} instance, and that of all the
6411 @code{mingetty-service-type} instances in the @var{%base-services} list.
6412 Observe how this is accomplished: first, we arrange for the original
6413 configuration to be bound to the identifier @code{config} in the
6414 @var{body}, and then we write the @var{body} so that it evaluates to the
6415 desired configuration. In particular, notice how we use @code{inherit}
6416 to create a new configuration which has the same values as the old
6417 configuration, but with a few modifications.
6418
6419 The configuration for a typical ``desktop'' usage, with the X11 display
6420 server, GNOME and Xfce (users can choose which of these desktop
6421 environments to use at the log-in screen by pressing @kbd{F1}), network
6422 management, power management, and more, would look like this:
6423
6424 @lisp
6425 @include os-config-desktop.texi
6426 @end lisp
6427
6428 A graphical environment with a choice of lightweight window managers
6429 instead of full-blown desktop environments would look like this:
6430
6431 @lisp
6432 @include os-config-lightweight-desktop.texi
6433 @end lisp
6434
6435 @xref{Desktop Services}, for the exact list of services provided by
6436 @var{%desktop-services}. @xref{X.509 Certificates}, for background
6437 information about the @code{nss-certs} package that is used here.
6438
6439 Again, @var{%desktop-services} is just a list of service objects. If
6440 you want to remove services from there, you can do so using the
6441 procedures for list filtering (@pxref{SRFI-1 Filtering and
6442 Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6443 following expression returns a list that contains all the services in
6444 @var{%desktop-services} minus the Avahi service:
6445
6446 @example
6447 (remove (lambda (service)
6448 (eq? (service-kind service) avahi-service-type))
6449 %desktop-services)
6450 @end example
6451
6452 @unnumberedsubsubsec Instantiating the System
6453
6454 Assuming the @code{operating-system} declaration
6455 is stored in the @file{my-system-config.scm}
6456 file, the @command{guix system reconfigure my-system-config.scm} command
6457 instantiates that configuration, and makes it the default GRUB boot
6458 entry (@pxref{Invoking guix system}).
6459
6460 The normal way to change the system configuration is by updating this
6461 file and re-running @command{guix system reconfigure}. One should never
6462 have to touch files in @command{/etc} or to run commands that modify the
6463 system state such as @command{useradd} or @command{grub-install}. In
6464 fact, you must avoid that since that would not only void your warranty
6465 but also prevent you from rolling back to previous versions of your
6466 system, should you ever need to.
6467
6468 @cindex roll-back, of the operating system
6469 Speaking of roll-back, each time you run @command{guix system
6470 reconfigure}, a new @dfn{generation} of the system is created---without
6471 modifying or deleting previous generations. Old system generations get
6472 an entry in the GRUB boot menu, allowing you to boot them in case
6473 something went wrong with the latest generation. Reassuring, no? The
6474 @command{guix system list-generations} command lists the system
6475 generations available on disk.
6476
6477 @unnumberedsubsubsec The Programming Interface
6478
6479 At the Scheme level, the bulk of an @code{operating-system} declaration
6480 is instantiated with the following monadic procedure (@pxref{The Store
6481 Monad}):
6482
6483 @deffn {Monadic Procedure} operating-system-derivation os
6484 Return a derivation that builds @var{os}, an @code{operating-system}
6485 object (@pxref{Derivations}).
6486
6487 The output of the derivation is a single directory that refers to all
6488 the packages, configuration files, and other supporting files needed to
6489 instantiate @var{os}.
6490 @end deffn
6491
6492 This procedure is provided by the @code{(gnu system)} module. Along
6493 with @code{(gnu services)} (@pxref{Services}), this module contains the
6494 guts of GuixSD. Make sure to visit it!
6495
6496
6497 @node operating-system Reference
6498 @subsection @code{operating-system} Reference
6499
6500 This section summarizes all the options available in
6501 @code{operating-system} declarations (@pxref{Using the Configuration
6502 System}).
6503
6504 @deftp {Data Type} operating-system
6505 This is the data type representing an operating system configuration.
6506 By that, we mean all the global system configuration, not per-user
6507 configuration (@pxref{Using the Configuration System}).
6508
6509 @table @asis
6510 @item @code{kernel} (default: @var{linux-libre})
6511 The package object of the operating system kernel to use@footnote{Currently
6512 only the Linux-libre kernel is supported. In the future, it will be
6513 possible to use the GNU@tie{}Hurd.}.
6514
6515 @item @code{kernel-arguments} (default: @code{'()})
6516 List of strings or gexps representing additional arguments to pass on
6517 the command-line of the kernel---e.g., @code{("console=ttyS0")}.
6518
6519 @item @code{bootloader}
6520 The system bootloader configuration object. @xref{GRUB Configuration}.
6521
6522 @item @code{initrd} (default: @code{base-initrd})
6523 A two-argument monadic procedure that returns an initial RAM disk for
6524 the Linux kernel. @xref{Initial RAM Disk}.
6525
6526 @item @code{firmware} (default: @var{%base-firmware})
6527 @cindex firmware
6528 List of firmware packages loadable by the operating system kernel.
6529
6530 The default includes firmware needed for Atheros-based WiFi devices
6531 (Linux-libre module @code{ath9k}). @xref{Hardware Considerations}, for
6532 more info on supported hardware.
6533
6534 @item @code{host-name}
6535 The host name.
6536
6537 @item @code{hosts-file}
6538 @cindex hosts file
6539 A file-like object (@pxref{G-Expressions, file-like objects}) for use as
6540 @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
6541 Reference Manual}). The default is a file with entries for
6542 @code{localhost} and @var{host-name}.
6543
6544 @item @code{mapped-devices} (default: @code{'()})
6545 A list of mapped devices. @xref{Mapped Devices}.
6546
6547 @item @code{file-systems}
6548 A list of file systems. @xref{File Systems}.
6549
6550 @item @code{swap-devices} (default: @code{'()})
6551 @cindex swap devices
6552 A list of strings identifying devices to be used for ``swap space''
6553 (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6554 For example, @code{'("/dev/sda3")}.
6555
6556 @item @code{users} (default: @code{%base-user-accounts})
6557 @itemx @code{groups} (default: @var{%base-groups})
6558 List of user accounts and groups. @xref{User Accounts}.
6559
6560 @item @code{skeletons} (default: @code{(default-skeletons)})
6561 A list target file name/file-like object tuples (@pxref{G-Expressions,
6562 file-like objects}). These are the skeleton files that will be added to
6563 the home directory of newly-created user accounts.
6564
6565 For instance, a valid value may look like this:
6566
6567 @example
6568 `((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
6569 (".guile" ,(plain-file "guile"
6570 "(use-modules (ice-9 readline))
6571 (activate-readline)")))
6572 @end example
6573
6574 @item @code{issue} (default: @var{%default-issue})
6575 A string denoting the contents of the @file{/etc/issue} file, which is
6576 displayed when users log in on a text console.
6577
6578 @item @code{packages} (default: @var{%base-packages})
6579 The set of packages installed in the global profile, which is accessible
6580 at @file{/run/current-system/profile}.
6581
6582 The default set includes core utilities and it is good practice to
6583 install non-core utilities in user profiles (@pxref{Invoking guix
6584 package}).
6585
6586 @item @code{timezone}
6587 A timezone identifying string---e.g., @code{"Europe/Paris"}.
6588
6589 You can run the @command{tzselect} command to find out which timezone
6590 string corresponds to your region. Choosing an invalid timezone name
6591 causes @command{guix system} to fail.
6592
6593 @item @code{locale} (default: @code{"en_US.utf8"})
6594 The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
6595 Library Reference Manual}). @xref{Locales}, for more information.
6596
6597 @item @code{locale-definitions} (default: @var{%default-locale-definitions})
6598 The list of locale definitions to be compiled and that may be used at
6599 run time. @xref{Locales}.
6600
6601 @item @code{locale-libcs} (default: @code{(list @var{glibc})})
6602 The list of GNU@tie{}libc packages whose locale data and tools are used
6603 to build the locale definitions. @xref{Locales}, for compatibility
6604 considerations that justify this option.
6605
6606 @item @code{name-service-switch} (default: @var{%default-nss})
6607 Configuration of the libc name service switch (NSS)---a
6608 @code{<name-service-switch>} object. @xref{Name Service Switch}, for
6609 details.
6610
6611 @item @code{services} (default: @var{%base-services})
6612 A list of service objects denoting system services. @xref{Services}.
6613
6614 @item @code{pam-services} (default: @code{(base-pam-services)})
6615 @cindex PAM
6616 @cindex pluggable authentication modules
6617 Linux @dfn{pluggable authentication module} (PAM) services.
6618 @c FIXME: Add xref to PAM services section.
6619
6620 @item @code{setuid-programs} (default: @var{%setuid-programs})
6621 List of string-valued G-expressions denoting setuid programs.
6622 @xref{Setuid Programs}.
6623
6624 @item @code{sudoers-file} (default: @var{%sudoers-specification})
6625 @cindex sudoers file
6626 The contents of the @file{/etc/sudoers} file as a file-like object
6627 (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
6628
6629 This file specifies which users can use the @command{sudo} command, what
6630 they are allowed to do, and what privileges they may gain. The default
6631 is that only @code{root} and members of the @code{wheel} group may use
6632 @code{sudo}.
6633
6634 @end table
6635 @end deftp
6636
6637 @node File Systems
6638 @subsection File Systems
6639
6640 The list of file systems to be mounted is specified in the
6641 @code{file-systems} field of the operating system declaration
6642 (@pxref{Using the Configuration System}). Each file system is declared
6643 using the @code{file-system} form, like this:
6644
6645 @example
6646 (file-system
6647 (mount-point "/home")
6648 (device "/dev/sda3")
6649 (type "ext4"))
6650 @end example
6651
6652 As usual, some of the fields are mandatory---those shown in the example
6653 above---while others can be omitted. These are described below.
6654
6655 @deftp {Data Type} file-system
6656 Objects of this type represent file systems to be mounted. They
6657 contain the following members:
6658
6659 @table @asis
6660 @item @code{type}
6661 This is a string specifying the type of the file system---e.g.,
6662 @code{"ext4"}.
6663
6664 @item @code{mount-point}
6665 This designates the place where the file system is to be mounted.
6666
6667 @item @code{device}
6668 This names the ``source'' of the file system. By default it is the name
6669 of a node under @file{/dev}, but its meaning depends on the @code{title}
6670 field described below.
6671
6672 @item @code{title} (default: @code{'device})
6673 This is a symbol that specifies how the @code{device} field is to be
6674 interpreted.
6675
6676 When it is the symbol @code{device}, then the @code{device} field is
6677 interpreted as a file name; when it is @code{label}, then @code{device}
6678 is interpreted as a partition label name; when it is @code{uuid},
6679 @code{device} is interpreted as a partition unique identifier (UUID).
6680
6681 UUIDs may be converted from their string representation (as shown by the
6682 @command{tune2fs -l} command) using the @code{uuid} form@footnote{The
6683 @code{uuid} form expects 16-byte UUIDs as defined in
6684 @uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
6685 form of UUID used by the ext2 family of file systems and others, but it
6686 is different from ``UUIDs'' found in FAT file systems, for instance.},
6687 like this:
6688
6689 @example
6690 (file-system
6691 (mount-point "/home")
6692 (type "ext4")
6693 (title 'uuid)
6694 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6695 @end example
6696
6697 The @code{label} and @code{uuid} options offer a way to refer to disk
6698 partitions without having to hard-code their actual device
6699 name@footnote{Note that, while it is tempting to use
6700 @file{/dev/disk/by-uuid} and similar device names to achieve the same
6701 result, this is not recommended: These special device nodes are created
6702 by the udev daemon and may be unavailable at the time the device is
6703 mounted.}.
6704
6705 However, when the source of a file system is a mapped device (@pxref{Mapped
6706 Devices}), its @code{device} field @emph{must} refer to the mapped
6707 device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6708 @code{title} must be set to @code{'device}. This is required so that
6709 the system knows that mounting the file system depends on having the
6710 corresponding device mapping established.
6711
6712 @item @code{flags} (default: @code{'()})
6713 This is a list of symbols denoting mount flags. Recognized flags
6714 include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6715 access to special files), @code{no-suid} (ignore setuid and setgid
6716 bits), and @code{no-exec} (disallow program execution.)
6717
6718 @item @code{options} (default: @code{#f})
6719 This is either @code{#f}, or a string denoting mount options.
6720
6721 @item @code{mount?} (default: @code{#t})
6722 This value indicates whether to automatically mount the file system when
6723 the system is brought up. When set to @code{#f}, the file system gets
6724 an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6725 is not automatically mounted.
6726
6727 @item @code{needed-for-boot?} (default: @code{#f})
6728 This Boolean value indicates whether the file system is needed when
6729 booting. If that is true, then the file system is mounted when the
6730 initial RAM disk (initrd) is loaded. This is always the case, for
6731 instance, for the root file system.
6732
6733 @item @code{check?} (default: @code{#t})
6734 This Boolean indicates whether the file system needs to be checked for
6735 errors before being mounted.
6736
6737 @item @code{create-mount-point?} (default: @code{#f})
6738 When true, the mount point is created if it does not exist yet.
6739
6740 @item @code{dependencies} (default: @code{'()})
6741 This is a list of @code{<file-system>} objects representing file systems
6742 that must be mounted before (and unmounted after) this one.
6743
6744 As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6745 a dependency of @file{/sys/fs/cgroup/cpu} and
6746 @file{/sys/fs/cgroup/memory}.
6747
6748 @end table
6749 @end deftp
6750
6751 The @code{(gnu system file-systems)} exports the following useful
6752 variables.
6753
6754 @defvr {Scheme Variable} %base-file-systems
6755 These are essential file systems that are required on normal systems,
6756 such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
6757 below.) Operating system declarations should always contain at least
6758 these.
6759 @end defvr
6760
6761 @defvr {Scheme Variable} %pseudo-terminal-file-system
6762 This is the file system to be mounted as @file{/dev/pts}. It supports
6763 @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6764 functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6765 Manual}). Pseudo-terminals are used by terminal emulators such as
6766 @command{xterm}.
6767 @end defvr
6768
6769 @defvr {Scheme Variable} %shared-memory-file-system
6770 This file system is mounted as @file{/dev/shm} and is used to support
6771 memory sharing across processes (@pxref{Memory-mapped I/O,
6772 @code{shm_open},, libc, The GNU C Library Reference Manual}).
6773 @end defvr
6774
6775 @defvr {Scheme Variable} %immutable-store
6776 This file system performs a read-only ``bind mount'' of
6777 @file{/gnu/store}, making it read-only for all the users including
6778 @code{root}. This prevents against accidental modification by software
6779 running as @code{root} or by system administrators.
6780
6781 The daemon itself is still able to write to the store: it remounts it
6782 read-write in its own ``name space.''
6783 @end defvr
6784
6785 @defvr {Scheme Variable} %binary-format-file-system
6786 The @code{binfmt_misc} file system, which allows handling of arbitrary
6787 executable file types to be delegated to user space. This requires the
6788 @code{binfmt.ko} kernel module to be loaded.
6789 @end defvr
6790
6791 @defvr {Scheme Variable} %fuse-control-file-system
6792 The @code{fusectl} file system, which allows unprivileged users to mount
6793 and unmount user-space FUSE file systems. This requires the
6794 @code{fuse.ko} kernel module to be loaded.
6795 @end defvr
6796
6797 @node Mapped Devices
6798 @subsection Mapped Devices
6799
6800 @cindex device mapping
6801 @cindex mapped devices
6802 The Linux kernel has a notion of @dfn{device mapping}: a block device,
6803 such as a hard disk partition, can be @dfn{mapped} into another device,
6804 with additional processing over the data that flows through
6805 it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6806 concept of a ``mapped device'' and that of a file system: both boil down
6807 to @emph{translating} input/output operations made on a file to
6808 operations on its backing store. Thus, the Hurd implements mapped
6809 devices, like file systems, using the generic @dfn{translator} mechanism
6810 (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6811 typical example is encryption device mapping: all writes to the mapped
6812 device are encrypted, and all reads are deciphered, transparently.
6813
6814 Mapped devices are declared using the @code{mapped-device} form:
6815
6816 @example
6817 (mapped-device
6818 (source "/dev/sda3")
6819 (target "home")
6820 (type luks-device-mapping))
6821 @end example
6822
6823 Or, better yet, like this:
6824
6825 @example
6826 (mapped-device
6827 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
6828 (target "home")
6829 (type luks-device-mapping))
6830 @end example
6831
6832 @cindex disk encryption
6833 @cindex LUKS
6834 This example specifies a mapping from @file{/dev/sda3} to
6835 @file{/dev/mapper/home} using LUKS---the
6836 @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6837 standard mechanism for disk encryption. In the second example, the UUID
6838 (unique identifier) is the LUKS UUID returned for the device by a
6839 command like:
6840
6841 @example
6842 cryptsetup luksUUID /dev/sdx9
6843 @end example
6844
6845 The @file{/dev/mapper/home}
6846 device can then be used as the @code{device} of a @code{file-system}
6847 declaration (@pxref{File Systems}). The @code{mapped-device} form is
6848 detailed below.
6849
6850 @deftp {Data Type} mapped-device
6851 Objects of this type represent device mappings that will be made when
6852 the system boots up.
6853
6854 @table @code
6855 @item source
6856 This string specifies the name of the block device to be mapped, such as
6857 @code{"/dev/sda3"}.
6858
6859 @item target
6860 This string specifies the name of the mapping to be established. For
6861 example, specifying @code{"my-partition"} will lead to the creation of
6862 the @code{"/dev/mapper/my-partition"} device.
6863
6864 @item type
6865 This must be a @code{mapped-device-kind} object, which specifies how
6866 @var{source} is mapped to @var{target}.
6867 @end table
6868 @end deftp
6869
6870 @defvr {Scheme Variable} luks-device-mapping
6871 This defines LUKS block device encryption using the @command{cryptsetup}
6872 command from the package with the same name. It relies on the
6873 @code{dm-crypt} Linux kernel module.
6874 @end defvr
6875
6876 @node User Accounts
6877 @subsection User Accounts
6878
6879 User accounts and groups are entirely managed through the
6880 @code{operating-system} declaration. They are specified with the
6881 @code{user-account} and @code{user-group} forms:
6882
6883 @example
6884 (user-account
6885 (name "alice")
6886 (group "users")
6887 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6888 "audio" ;sound card
6889 "video" ;video devices such as webcams
6890 "cdrom")) ;the good ol' CD-ROM
6891 (comment "Bob's sister")
6892 (home-directory "/home/alice"))
6893 @end example
6894
6895 When booting or upon completion of @command{guix system reconfigure},
6896 the system ensures that only the user accounts and groups specified in
6897 the @code{operating-system} declaration exist, and with the specified
6898 properties. Thus, account or group creations or modifications made by
6899 directly invoking commands such as @command{useradd} are lost upon
6900 reconfiguration or reboot. This ensures that the system remains exactly
6901 as declared.
6902
6903 @deftp {Data Type} user-account
6904 Objects of this type represent user accounts. The following members may
6905 be specified:
6906
6907 @table @asis
6908 @item @code{name}
6909 The name of the user account.
6910
6911 @item @code{group}
6912 This is the name (a string) or identifier (a number) of the user group
6913 this account belongs to.
6914
6915 @item @code{supplementary-groups} (default: @code{'()})
6916 Optionally, this can be defined as a list of group names that this
6917 account belongs to.
6918
6919 @item @code{uid} (default: @code{#f})
6920 This is the user ID for this account (a number), or @code{#f}. In the
6921 latter case, a number is automatically chosen by the system when the
6922 account is created.
6923
6924 @item @code{comment} (default: @code{""})
6925 A comment about the account, such as the account owner's full name.
6926
6927 @item @code{home-directory}
6928 This is the name of the home directory for the account.
6929
6930 @item @code{shell} (default: Bash)
6931 This is a G-expression denoting the file name of a program to be used as
6932 the shell (@pxref{G-Expressions}).
6933
6934 @item @code{system?} (default: @code{#f})
6935 This Boolean value indicates whether the account is a ``system''
6936 account. System accounts are sometimes treated specially; for instance,
6937 graphical login managers do not list them.
6938
6939 @anchor{user-account-password}
6940 @item @code{password} (default: @code{#f})
6941 You would normally leave this field to @code{#f}, initialize user
6942 passwords as @code{root} with the @command{passwd} command, and then let
6943 users change it with @command{passwd}. Passwords set with
6944 @command{passwd} are of course preserved across reboot and
6945 reconfiguration.
6946
6947 If you @emph{do} want to have a preset password for an account, then
6948 this field must contain the encrypted password, as a string.
6949 @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6950 on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
6951 Manual}, for information on Guile's @code{crypt} procedure.
6952
6953 @end table
6954 @end deftp
6955
6956 User group declarations are even simpler:
6957
6958 @example
6959 (user-group (name "students"))
6960 @end example
6961
6962 @deftp {Data Type} user-group
6963 This type is for, well, user groups. There are just a few fields:
6964
6965 @table @asis
6966 @item @code{name}
6967 The name of the group.
6968
6969 @item @code{id} (default: @code{#f})
6970 The group identifier (a number). If @code{#f}, a new number is
6971 automatically allocated when the group is created.
6972
6973 @item @code{system?} (default: @code{#f})
6974 This Boolean value indicates whether the group is a ``system'' group.
6975 System groups have low numerical IDs.
6976
6977 @item @code{password} (default: @code{#f})
6978 What, user groups can have a password? Well, apparently yes. Unless
6979 @code{#f}, this field specifies the password of the group.
6980
6981 @end table
6982 @end deftp
6983
6984 For convenience, a variable lists all the basic user groups one may
6985 expect:
6986
6987 @defvr {Scheme Variable} %base-groups
6988 This is the list of basic user groups that users and/or packages expect
6989 to be present on the system. This includes groups such as ``root'',
6990 ``wheel'', and ``users'', as well as groups used to control access to
6991 specific devices such as ``audio'', ``disk'', and ``cdrom''.
6992 @end defvr
6993
6994 @defvr {Scheme Variable} %base-user-accounts
6995 This is the list of basic system accounts that programs may expect to
6996 find on a GNU/Linux system, such as the ``nobody'' account.
6997
6998 Note that the ``root'' account is not included here. It is a
6999 special-case and is automatically added whether or not it is specified.
7000 @end defvr
7001
7002 @node Locales
7003 @subsection Locales
7004
7005 @cindex locale
7006 A @dfn{locale} defines cultural conventions for a particular language
7007 and region of the world (@pxref{Locales,,, libc, The GNU C Library
7008 Reference Manual}). Each locale has a name that typically has the form
7009 @code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
7010 @code{fr_LU.utf8} designates the locale for the French language, with
7011 cultural conventions from Luxembourg, and using the UTF-8 encoding.
7012
7013 @cindex locale definition
7014 Usually, you will want to specify the default locale for the machine
7015 using the @code{locale} field of the @code{operating-system} declaration
7016 (@pxref{operating-system Reference, @code{locale}}).
7017
7018 The selected locale is automatically added to the @dfn{locale
7019 definitions} known to the system if needed, with its codeset inferred
7020 from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
7021 @code{UTF-8} codeset. Additional locale definitions can be specified in
7022 the @code{locale-definitions} slot of @code{operating-system}---this is
7023 useful, for instance, if the codeset could not be inferred from the
7024 locale name. The default set of locale definitions includes some widely
7025 used locales, but not all the available locales, in order to save space.
7026
7027 For instance, to add the North Frisian locale for Germany, the value of
7028 that field may be:
7029
7030 @example
7031 (cons (locale-definition
7032 (name "fy_DE.utf8") (source "fy_DE"))
7033 %default-locale-definitions)
7034 @end example
7035
7036 Likewise, to save space, one might want @code{locale-definitions} to
7037 list only the locales that are actually used, as in:
7038
7039 @example
7040 (list (locale-definition
7041 (name "ja_JP.eucjp") (source "ja_JP")
7042 (charset "EUC-JP")))
7043 @end example
7044
7045 @vindex LOCPATH
7046 The compiled locale definitions are available at
7047 @file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
7048 version, which is the default location where the GNU@tie{}libc provided
7049 by Guix looks for locale data. This can be overridden using the
7050 @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
7051 @code{LOCPATH} and locale packages}).
7052
7053 The @code{locale-definition} form is provided by the @code{(gnu system
7054 locale)} module. Details are given below.
7055
7056 @deftp {Data Type} locale-definition
7057 This is the data type of a locale definition.
7058
7059 @table @asis
7060
7061 @item @code{name}
7062 The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
7063 Reference Manual}, for more information on locale names.
7064
7065 @item @code{source}
7066 The name of the source for that locale. This is typically the
7067 @code{@var{language}_@var{territory}} part of the locale name.
7068
7069 @item @code{charset} (default: @code{"UTF-8"})
7070 The ``character set'' or ``code set'' for that locale,
7071 @uref{http://www.iana.org/assignments/character-sets, as defined by
7072 IANA}.
7073
7074 @end table
7075 @end deftp
7076
7077 @defvr {Scheme Variable} %default-locale-definitions
7078 A list of commonly used UTF-8 locales, used as the default
7079 value of the @code{locale-definitions} field of @code{operating-system}
7080 declarations.
7081
7082 @cindex locale name
7083 @cindex normalized codeset in locale names
7084 These locale definitions use the @dfn{normalized codeset} for the part
7085 that follows the dot in the name (@pxref{Using gettextized software,
7086 normalized codeset,, libc, The GNU C Library Reference Manual}). So for
7087 instance it has @code{uk_UA.utf8} but @emph{not}, say,
7088 @code{uk_UA.UTF-8}.
7089 @end defvr
7090
7091 @subsubsection Locale Data Compatibility Considerations
7092
7093 @cindex incompatibility, of locale data
7094 @code{operating-system} declarations provide a @code{locale-libcs} field
7095 to specify the GNU@tie{}libc packages that are used to compile locale
7096 declarations (@pxref{operating-system Reference}). ``Why would I
7097 care?'', you may ask. Well, it turns out that the binary format of
7098 locale data is occasionally incompatible from one libc version to
7099 another.
7100
7101 @c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
7102 @c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
7103 For instance, a program linked against libc version 2.21 is unable to
7104 read locale data produced with libc 2.22; worse, that program
7105 @emph{aborts} instead of simply ignoring the incompatible locale
7106 data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
7107 the incompatible locale data, which is already an improvement.}.
7108 Similarly, a program linked against libc 2.22 can read most, but not
7109 all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
7110 data is incompatible); thus calls to @code{setlocale} may fail, but
7111 programs will not abort.
7112
7113 The ``problem'' in GuixSD is that users have a lot of freedom: They can
7114 choose whether and when to upgrade software in their profiles, and might
7115 be using a libc version different from the one the system administrator
7116 used to build the system-wide locale data.
7117
7118 Fortunately, unprivileged users can also install their own locale data
7119 and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
7120 @code{GUIX_LOCPATH} and locale packages}).
7121
7122 Still, it is best if the system-wide locale data at
7123 @file{/run/current-system/locale} is built for all the libc versions
7124 actually in use on the system, so that all the programs can access
7125 it---this is especially crucial on a multi-user system. To do that, the
7126 administrator can specify several libc packages in the
7127 @code{locale-libcs} field of @code{operating-system}:
7128
7129 @example
7130 (use-package-modules base)
7131
7132 (operating-system
7133 ;; @dots{}
7134 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
7135 @end example
7136
7137 This example would lead to a system containing locale definitions for
7138 both libc 2.21 and the current version of libc in
7139 @file{/run/current-system/locale}.
7140
7141
7142 @node Services
7143 @subsection Services
7144
7145 @cindex system services
7146 An important part of preparing an @code{operating-system} declaration is
7147 listing @dfn{system services} and their configuration (@pxref{Using the
7148 Configuration System}). System services are typically daemons launched
7149 when the system boots, or other actions needed at that time---e.g.,
7150 configuring network access.
7151
7152 Services are managed by the GNU@tie{}Shepherd (@pxref{Introduction,,,
7153 shepherd, The GNU Shepherd Manual}). On a running system, the
7154 @command{herd} command allows you to list the available services, show
7155 their status, start and stop them, or do other specific operations
7156 (@pxref{Jump Start,,, shepherd, The GNU Shepherd Manual}). For example:
7157
7158 @example
7159 # herd status
7160 @end example
7161
7162 The above command, run as @code{root}, lists the currently defined
7163 services. The @command{herd doc} command shows a synopsis of the given
7164 service:
7165
7166 @example
7167 # herd doc nscd
7168 Run libc's name service cache daemon (nscd).
7169 @end example
7170
7171 The @command{start}, @command{stop}, and @command{restart} sub-commands
7172 have the effect you would expect. For instance, the commands below stop
7173 the nscd service and restart the Xorg display server:
7174
7175 @example
7176 # herd stop nscd
7177 Service nscd has been stopped.
7178 # herd restart xorg-server
7179 Service xorg-server has been stopped.
7180 Service xorg-server has been started.
7181 @end example
7182
7183 The following sections document the available services, starting with
7184 the core services, that may be used in an @code{operating-system}
7185 declaration.
7186
7187 @menu
7188 * Base Services:: Essential system services.
7189 * Scheduled Job Execution:: The mcron service.
7190 * Networking Services:: Network setup, SSH daemon, etc.
7191 * X Window:: Graphical display.
7192 * Desktop Services:: D-Bus and desktop services.
7193 * Database Services:: SQL databases.
7194 * Mail Services:: IMAP, POP3, SMTP, and all that.
7195 * Web Services:: Web servers.
7196 * Various Services:: Other services.
7197 @end menu
7198
7199 @node Base Services
7200 @subsubsection Base Services
7201
7202 The @code{(gnu services base)} module provides definitions for the basic
7203 services that one expects from the system. The services exported by
7204 this module are listed below.
7205
7206 @defvr {Scheme Variable} %base-services
7207 This variable contains a list of basic services (@pxref{Service Types
7208 and Services}, for more information on service objects) one would
7209 expect from the system: a login service (mingetty) on each tty, syslogd,
7210 the libc name service cache daemon (nscd), the udev device manager, and
7211 more.
7212
7213 This is the default value of the @code{services} field of
7214 @code{operating-system} declarations. Usually, when customizing a
7215 system, you will want to append services to @var{%base-services}, like
7216 this:
7217
7218 @example
7219 (cons* (avahi-service) (lsh-service) %base-services)
7220 @end example
7221 @end defvr
7222
7223 @deffn {Scheme Procedure} host-name-service @var{name}
7224 Return a service that sets the host name to @var{name}.
7225 @end deffn
7226
7227 @deffn {Scheme Procedure} mingetty-service @var{config}
7228 Return a service to run mingetty according to @var{config}, a
7229 @code{<mingetty-configuration>} object, which specifies the tty to run, among
7230 other things.
7231 @end deffn
7232
7233 @deftp {Data Type} mingetty-configuration
7234 This is the data type representing the configuration of Mingetty, which
7235 implements console log-in.
7236
7237 @table @asis
7238
7239 @item @code{tty}
7240 The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
7241
7242 @item @code{motd}
7243 A file-like object containing the ``message of the day''.
7244
7245 @item @code{auto-login} (default: @code{#f})
7246 When true, this field must be a string denoting the user name under
7247 which the system automatically logs in. When it is @code{#f}, a
7248 user name and password must be entered to log in.
7249
7250 @item @code{login-program} (default: @code{#f})
7251 This must be either @code{#f}, in which case the default log-in program
7252 is used (@command{login} from the Shadow tool suite), or a gexp denoting
7253 the name of the log-in program.
7254
7255 @item @code{login-pause?} (default: @code{#f})
7256 When set to @code{#t} in conjunction with @var{auto-login}, the user
7257 will have to press a key before the log-in shell is launched.
7258
7259 @item @code{mingetty} (default: @var{mingetty})
7260 The Mingetty package to use.
7261
7262 @end table
7263 @end deftp
7264
7265 @cindex name service cache daemon
7266 @cindex nscd
7267 @deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
7268 [#:name-services '()]
7269 Return a service that runs the libc name service cache daemon (nscd) with the
7270 given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
7271 Service Switch}, for an example.
7272 @end deffn
7273
7274 @defvr {Scheme Variable} %nscd-default-configuration
7275 This is the default @code{<nscd-configuration>} value (see below) used
7276 by @code{nscd-service}. It uses the caches defined by
7277 @var{%nscd-default-caches}; see below.
7278 @end defvr
7279
7280 @deftp {Data Type} nscd-configuration
7281 This is the data type representing the name service cache daemon (nscd)
7282 configuration.
7283
7284 @table @asis
7285
7286 @item @code{name-services} (default: @code{'()})
7287 List of packages denoting @dfn{name services} that must be visible to
7288 the nscd---e.g., @code{(list @var{nss-mdns})}.
7289
7290 @item @code{glibc} (default: @var{glibc})
7291 Package object denoting the GNU C Library providing the @command{nscd}
7292 command.
7293
7294 @item @code{log-file} (default: @code{"/var/log/nscd.log"})
7295 Name of the nscd log file. This is where debugging output goes when
7296 @code{debug-level} is strictly positive.
7297
7298 @item @code{debug-level} (default: @code{0})
7299 Integer denoting the debugging levels. Higher numbers mean that more
7300 debugging output is logged.
7301
7302 @item @code{caches} (default: @var{%nscd-default-caches})
7303 List of @code{<nscd-cache>} objects denoting things to be cached; see
7304 below.
7305
7306 @end table
7307 @end deftp
7308
7309 @deftp {Data Type} nscd-cache
7310 Data type representing a cache database of nscd and its parameters.
7311
7312 @table @asis
7313
7314 @item @code{database}
7315 This is a symbol representing the name of the database to be cached.
7316 Valid values are @code{passwd}, @code{group}, @code{hosts}, and
7317 @code{services}, which designate the corresponding NSS database
7318 (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
7319
7320 @item @code{positive-time-to-live}
7321 @itemx @code{negative-time-to-live} (default: @code{20})
7322 A number representing the number of seconds during which a positive or
7323 negative lookup result remains in cache.
7324
7325 @item @code{check-files?} (default: @code{#t})
7326 Whether to check for updates of the files corresponding to
7327 @var{database}.
7328
7329 For instance, when @var{database} is @code{hosts}, setting this flag
7330 instructs nscd to check for updates in @file{/etc/hosts} and to take
7331 them into account.
7332
7333 @item @code{persistent?} (default: @code{#t})
7334 Whether the cache should be stored persistently on disk.
7335
7336 @item @code{shared?} (default: @code{#t})
7337 Whether the cache should be shared among users.
7338
7339 @item @code{max-database-size} (default: 32@tie{}MiB)
7340 Maximum size in bytes of the database cache.
7341
7342 @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
7343 @c settings, so leave them out.
7344
7345 @end table
7346 @end deftp
7347
7348 @defvr {Scheme Variable} %nscd-default-caches
7349 List of @code{<nscd-cache>} objects used by default by
7350 @code{nscd-configuration} (see above).
7351
7352 It enables persistent and aggressive caching of service and host name
7353 lookups. The latter provides better host name lookup performance,
7354 resilience in the face of unreliable name servers, and also better
7355 privacy---often the result of host name lookups is in local cache, so
7356 external name servers do not even need to be queried.
7357 @end defvr
7358
7359
7360 @deffn {Scheme Procedure} syslog-service @
7361 [#:config-file @var{%default-syslog.conf}]
7362 Return a service that runs @command{syslogd}. If the configuration file
7363 name @var{config-file} is not specified, use some reasonable default
7364 settings.
7365
7366 @xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
7367 information on the configuration file syntax.
7368 @end deffn
7369
7370 @anchor{guix-configuration-type}
7371 @deftp {Data Type} guix-configuration
7372 This data type represents the configuration of the Guix build daemon.
7373 @xref{Invoking guix-daemon}, for more information.
7374
7375 @table @asis
7376 @item @code{guix} (default: @var{guix})
7377 The Guix package to use.
7378
7379 @item @code{build-group} (default: @code{"guixbuild"})
7380 Name of the group for build user accounts.
7381
7382 @item @code{build-accounts} (default: @code{10})
7383 Number of build user accounts to create.
7384
7385 @item @code{authorize-key?} (default: @code{#t})
7386 Whether to authorize the substitute key for @code{hydra.gnu.org}
7387 (@pxref{Substitutes}).
7388
7389 @item @code{use-substitutes?} (default: @code{#t})
7390 Whether to use substitutes.
7391
7392 @item @code{substitute-urls} (default: @var{%default-substitute-urls})
7393 The list of URLs where to look for substitutes by default.
7394
7395 @item @code{extra-options} (default: @code{'()})
7396 List of extra command-line options for @command{guix-daemon}.
7397
7398 @item @code{lsof} (default: @var{lsof})
7399 @itemx @code{lsh} (default: @var{lsh})
7400 The lsof and lsh packages to use.
7401
7402 @end table
7403 @end deftp
7404
7405 @deffn {Scheme Procedure} guix-service @var{config}
7406 Return a service that runs the Guix build daemon according to
7407 @var{config}.
7408 @end deffn
7409
7410 @deffn {Scheme Procedure} udev-service [#:udev udev]
7411 Run @var{udev}, which populates the @file{/dev} directory dynamically.
7412 @end deffn
7413
7414 @deffn {Scheme Procedure} urandom-seed-service @var{#f}
7415 Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
7416 when rebooting.
7417 @end deffn
7418
7419 @defvr {Scheme Variable} %random-seed-file
7420 This is the name of the file where some random bytes are saved by
7421 @var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
7422 It defaults to @file{/var/lib/random-seed}.
7423 @end defvr
7424
7425 @deffn {Scheme Procedure} console-keymap-service @var{files} ...
7426 @cindex keyboard layout
7427 Return a service to load console keymaps from @var{files} using
7428 @command{loadkeys} command. Most likely, you want to load some default
7429 keymap, which can be done like this:
7430
7431 @example
7432 (console-keymap-service "dvorak")
7433 @end example
7434
7435 Or, for example, for a Swedish keyboard, you may need to combine
7436 the following keymaps:
7437 @example
7438 (console-keymap-service "se-lat6" "se-fi-lat6")
7439 @end example
7440
7441 Also you can specify a full file name (or file names) of your keymap(s).
7442 See @code{man loadkeys} for details.
7443
7444 @end deffn
7445
7446 @deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
7447 [#:options]
7448 Run @var{gpm}, the general-purpose mouse daemon, with the given
7449 command-line @var{options}. GPM allows users to use the mouse in the console,
7450 notably to select, copy, and paste text. The default value of @var{options}
7451 uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7452
7453 This service is not part of @var{%base-services}.
7454 @end deffn
7455
7456 @anchor{guix-publish-service}
7457 @deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7458 [#:port 80] [#:host "localhost"]
7459 Return a service that runs @command{guix publish} listening on @var{host}
7460 and @var{port} (@pxref{Invoking guix publish}).
7461
7462 This assumes that @file{/etc/guix} already contains a signing key pair as
7463 created by @command{guix archive --generate-key} (@pxref{Invoking guix
7464 archive}). If that is not the case, the service will fail to start.
7465 @end deffn
7466
7467
7468 @node Scheduled Job Execution
7469 @subsubsection Scheduled Job Execution
7470
7471 @cindex cron
7472 @cindex scheduling jobs
7473 The @code{(gnu services mcron)} module provides an interface to
7474 GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
7475 mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
7476 Unix @command{cron} daemon; the main difference is that it is
7477 implemented in Guile Scheme, which provides a lot of flexibility when
7478 specifying the scheduling of jobs and their actions.
7479
7480 For example, to define an operating system that runs the
7481 @command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
7482 and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily:
7483
7484 @lisp
7485 (use-modules (guix) (gnu) (gnu services mcron))
7486
7487 (define updatedb-job
7488 ;; Run 'updatedb' at 3 AM every day.
7489 #~(job '(next-hour '(3))
7490 "updatedb --prunepaths='/tmp /var/tmp /gnu/store'"))
7491
7492 (define garbage-collector-job
7493 ;; Collect garbage 5 minutes after midnight every day.
7494 #~(job "5 0 * * *" ;Vixie cron syntax
7495 "guix gc -F 1G"))
7496
7497 (operating-system
7498 ;; @dots{}
7499 (services (cons (mcron-service (list garbage-collector-job
7500 updatedb-job))
7501 %base-services)))
7502 @end lisp
7503
7504 @xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
7505 for more information on mcron job specifications. Below is the
7506 reference of the mcron service.
7507
7508 @deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
7509 Return an mcron service running @var{mcron} that schedules @var{jobs}, a
7510 list of gexps denoting mcron job specifications.
7511
7512 This is a shorthand for:
7513 @example
7514 (service mcron-service-type
7515 (mcron-configuration (mcron mcron) (jobs jobs)))
7516 @end example
7517 @end deffn
7518
7519 @defvr {Scheme Variable} mcron-service-type
7520 This is the type of the @code{mcron} service, whose value is an
7521 @code{mcron-configuration} object.
7522
7523 This service type can be the target of a service extension that provides
7524 it additional job specifications (@pxref{Service Composition}). In
7525 other words, it is possible to define services that provide addition
7526 mcron jobs to run.
7527 @end defvr
7528
7529 @deftp {Data Type} mcron-configuration
7530 Data type representing the configuration of mcron.
7531
7532 @table @asis
7533 @item @code{mcron} (default: @var{mcron2})
7534 The mcron package to use.
7535
7536 @item @code{jobs}
7537 This is a list of gexps (@pxref{G-Expressions}), where each gexp
7538 corresponds to an mcron job specification (@pxref{Syntax, mcron job
7539 specifications,, mcron, GNU@tie{}mcron}).
7540 @end table
7541 @end deftp
7542
7543
7544 @node Networking Services
7545 @subsubsection Networking Services
7546
7547 The @code{(gnu services networking)} module provides services to configure
7548 the network interface.
7549
7550 @cindex DHCP, networking service
7551 @deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
7552 Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7553 Protocol (DHCP) client, on all the non-loopback network interfaces.
7554 @end deffn
7555
7556 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
7557 [#:gateway #f] [#:name-services @code{'()}]
7558 Return a service that starts @var{interface} with address @var{ip}. If
7559 @var{gateway} is true, it must be a string specifying the default network
7560 gateway.
7561 @end deffn
7562
7563 @cindex wicd
7564 @cindex network management
7565 @deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
7566 Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7567 management daemon that aims to simplify wired and wireless networking.
7568
7569 This service adds the @var{wicd} package to the global profile, providing
7570 several commands to interact with the daemon and configure networking:
7571 @command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7572 and @command{wicd-curses} user interfaces.
7573 @end deffn
7574
7575 @cindex NetworkManager
7576 @deffn {Scheme Procedure} network-manager-service @
7577 [#:network-manager @var{network-manager}]
7578 Return a service that runs NetworkManager, a network connection manager
7579 attempting to keep network connectivity active when available.
7580 @end deffn
7581
7582 @cindex Connman
7583 @deffn {Scheme Procedure} connman-service @
7584 [#:connman @var{connman}]
7585 Return a service that runs @url{https://01.org/connman,Connman}, a network
7586 connection manager.
7587
7588 This service adds the @var{connman} package to the global profile, providing
7589 several the @command{connmanctl} command to interact with the daemon and
7590 configure networking."
7591 @end deffn
7592
7593 @deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
7594 [#:name-service @var{%ntp-servers}]
7595 Return a service that runs the daemon from @var{ntp}, the
7596 @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7597 keep the system clock synchronized with that of @var{servers}.
7598 @end deffn
7599
7600 @defvr {Scheme Variable} %ntp-servers
7601 List of host names used as the default NTP servers.
7602 @end defvr
7603
7604 @deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7605 Return a service to run the @uref{https://torproject.org, Tor} anonymous
7606 networking daemon.
7607
7608 The daemon runs as the @code{tor} unprivileged user. It is passed
7609 @var{config-file}, a file-like object, with an additional @code{User tor} line
7610 and lines for hidden services added via @code{tor-hidden-service}. Run
7611 @command{man tor} for information about the configuration file.
7612 @end deffn
7613
7614 @cindex hidden service
7615 @deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7616 Define a new Tor @dfn{hidden service} called @var{name} and implementing
7617 @var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7618
7619 @example
7620 '((22 "127.0.0.1:22")
7621 (80 "127.0.0.1:8080"))
7622 @end example
7623
7624 In this example, port 22 of the hidden service is mapped to local port 22, and
7625 port 80 is mapped to local port 8080.
7626
7627 This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7628 the @file{hostname} file contains the @code{.onion} host name for the hidden
7629 service.
7630
7631 See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7632 project's documentation} for more information.
7633 @end deffn
7634
7635 @deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
7636 [#:interface "127.0.0.1"] [#:port 6667] @
7637 [#:extra-settings ""]
7638 Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7639 acts as a gateway between IRC and chat networks.
7640
7641 The daemon will listen to the interface corresponding to the IP address
7642 specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7643 local clients can connect, whereas @code{0.0.0.0} means that connections can
7644 come from any networking interface.
7645
7646 In addition, @var{extra-settings} specifies a string to append to the
7647 configuration file.
7648 @end deffn
7649
7650 Furthermore, @code{(gnu services ssh)} provides the following service.
7651
7652 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
7653 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
7654 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7655 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7656 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
7657 [#:public-key-authentication? #t] [#:initialize? #t]
7658 Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7659 @var{host-key} must designate a file containing the host key, and readable
7660 only by root.
7661
7662 When @var{daemonic?} is true, @command{lshd} will detach from the
7663 controlling terminal and log its output to syslogd, unless one sets
7664 @var{syslog-output?} to false. Obviously, it also makes lsh-service
7665 depend on existence of syslogd service. When @var{pid-file?} is true,
7666 @command{lshd} writes its PID to the file called @var{pid-file}.
7667
7668 When @var{initialize?} is true, automatically create the seed and host key
7669 upon service activation if they do not exist yet. This may take long and
7670 require interaction.
7671
7672 When @var{initialize?} is false, it is up to the user to initialize the
7673 randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7674 a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7675 basics,,, lsh, LSH Manual}).
7676
7677 When @var{interfaces} is empty, lshd listens for connections on all the
7678 network interfaces; otherwise, @var{interfaces} must be a list of host names
7679 or addresses.
7680
7681 @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7682 passwords, and @var{root-login?} specifies whether to accept log-ins as
7683 root.
7684
7685 The other options should be self-descriptive.
7686 @end deffn
7687
7688 @defvr {Scheme Variable} %facebook-host-aliases
7689 This variable contains a string for use in @file{/etc/hosts}
7690 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7691 line contains a entry that maps a known server name of the Facebook
7692 on-line service---e.g., @code{www.facebook.com}---to the local
7693 host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7694
7695 This variable is typically used in the @code{hosts-file} field of an
7696 @code{operating-system} declaration (@pxref{operating-system Reference,
7697 @file{/etc/hosts}}):
7698
7699 @example
7700 (use-modules (gnu) (guix))
7701
7702 (operating-system
7703 (host-name "mymachine")
7704 ;; ...
7705 (hosts-file
7706 ;; Create a /etc/hosts file with aliases for "localhost"
7707 ;; and "mymachine", as well as for Facebook servers.
7708 (plain-file "hosts"
7709 (string-append (local-host-aliases host-name)
7710 %facebook-host-aliases))))
7711 @end example
7712
7713 This mechanism can prevent programs running locally, such as Web
7714 browsers, from accessing Facebook.
7715 @end defvr
7716
7717 The @code{(gnu services avahi)} provides the following definition.
7718
7719 @deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
7720 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7721 [#:ipv6? #t] [#:wide-area? #f] @
7722 [#:domains-to-browse '()]
7723 Return a service that runs @command{avahi-daemon}, a system-wide
7724 mDNS/DNS-SD responder that allows for service discovery and
7725 "zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7726 extends the name service cache daemon (nscd) so that it can resolve
7727 @code{.local} host names using
7728 @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7729 add the @var{avahi} package to the system profile so that commands such as
7730 @command{avahi-browse} are directly usable.
7731
7732 If @var{host-name} is different from @code{#f}, use that as the host name to
7733 publish for this machine; otherwise, use the machine's actual host name.
7734
7735 When @var{publish?} is true, publishing of host names and services is allowed;
7736 in particular, avahi-daemon will publish the machine's host name and IP
7737 address via mDNS on the local network.
7738
7739 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7740
7741 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7742 sockets.
7743 @end deffn
7744
7745
7746 @node X Window
7747 @subsubsection X Window
7748
7749 Support for the X Window graphical display system---specifically
7750 Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7751 there is no @code{xorg-service} procedure. Instead, the X server is
7752 started by the @dfn{login manager}, currently SLiM.
7753
7754 @deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
7755 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7756 [#:theme @var{%default-slim-theme}] @
7757 [#:theme-name @var{%default-slim-theme-name}]
7758 Return a service that spawns the SLiM graphical login manager, which in
7759 turn starts the X display server with @var{startx}, a command as returned by
7760 @code{xorg-start-command}.
7761
7762 @cindex X session
7763
7764 SLiM automatically looks for session types described by the @file{.desktop}
7765 files in @file{/run/current-system/profile/share/xsessions} and allows users
7766 to choose a session from the log-in screen using @kbd{F1}. Packages such as
7767 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
7768 adding them to the system-wide set of packages automatically makes them
7769 available at the log-in screen.
7770
7771 In addition, @file{~/.xsession} files are honored. When available,
7772 @file{~/.xsession} must be an executable that starts a window manager
7773 and/or other X clients.
7774
7775 When @var{allow-empty-passwords?} is true, allow logins with an empty
7776 password. When @var{auto-login?} is true, log in automatically as
7777 @var{default-user}.
7778
7779 If @var{theme} is @code{#f}, use the default log-in theme; otherwise
7780 @var{theme} must be a gexp denoting the name of a directory containing the
7781 theme to use. In that case, @var{theme-name} specifies the name of the
7782 theme.
7783 @end deffn
7784
7785 @defvr {Scheme Variable} %default-theme
7786 @defvrx {Scheme Variable} %default-theme-name
7787 The G-Expression denoting the default SLiM theme and its name.
7788 @end defvr
7789
7790 @deffn {Scheme Procedure} xorg-start-command [#:guile] @
7791 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
7792 Return a derivation that builds a @var{guile} script to start the X server
7793 from @var{xorg-server}. @var{configuration-file} is the server configuration
7794 file or a derivation that builds it; when omitted, the result of
7795 @code{xorg-configuration-file} is used.
7796
7797 Usually the X server is started by a login manager.
7798 @end deffn
7799
7800 @deffn {Scheme Procedure} xorg-configuration-file @
7801 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
7802 Return a configuration file for the Xorg server containing search paths for
7803 all the common drivers.
7804
7805 @var{drivers} must be either the empty list, in which case Xorg chooses a
7806 graphics driver automatically, or a list of driver names that will be tried in
7807 this order---e.g., @code{(\"modesetting\" \"vesa\")}.
7808
7809 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7810 appropriate screen resolution; otherwise, it must be a list of
7811 resolutions---e.g., @code{((1024 768) (640 480))}.
7812
7813 Last, @var{extra-config} is a list of strings or objects appended to the
7814 @code{text-file*} argument list. It is used to pass extra text to be added
7815 verbatim to the configuration file.
7816 @end deffn
7817
7818 @deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7819 Add @var{package}, a package for a screen-locker or screen-saver whose
7820 command is @var{program}, to the set of setuid programs and add a PAM entry
7821 for it. For example:
7822
7823 @lisp
7824 (screen-locker-service xlockmore "xlock")
7825 @end lisp
7826
7827 makes the good ol' XlockMore usable.
7828 @end deffn
7829
7830
7831 @node Desktop Services
7832 @subsubsection Desktop Services
7833
7834 The @code{(gnu services desktop)} module provides services that are
7835 usually useful in the context of a ``desktop'' setup---that is, on a
7836 machine running a graphical display server, possibly with graphical user
7837 interfaces, etc. It also defines services that provide specific desktop
7838 environments like GNOME and XFCE.
7839
7840 To simplify things, the module defines a variable containing the set of
7841 services that users typically expect on a machine with a graphical
7842 environment and networking:
7843
7844 @defvr {Scheme Variable} %desktop-services
7845 This is a list of services that builds upon @var{%base-services} and
7846 adds or adjusts services for a typical ``desktop'' setup.
7847
7848 In particular, it adds a graphical login manager (@pxref{X Window,
7849 @code{slim-service}}), screen lockers,
7850 a network management tool (@pxref{Networking
7851 Services, @code{wicd-service}}), energy and color management services,
7852 the @code{elogind} login and seat manager, the Polkit privilege service,
7853 the GeoClue location service, an NTP client (@pxref{Networking
7854 Services}), the Avahi daemon, and has the name service switch service
7855 configured to be able to use @code{nss-mdns} (@pxref{Name Service
7856 Switch, mDNS}).
7857 @end defvr
7858
7859 The @var{%desktop-services} variable can be used as the @code{services}
7860 field of an @code{operating-system} declaration (@pxref{operating-system
7861 Reference, @code{services}}).
7862
7863 Additionally, the @code{gnome-desktop-service} and
7864 @code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
7865 system. To ``add GNOME'' means that system-level services like the
7866 backlight adjustment helpers and the power management utilities are
7867 added to the system, extending @code{polkit} and @code{dbus}
7868 appropriately, allowing GNOME to operate with elevated privileges on a
7869 limited number of special-purpose system interfaces. Additionally,
7870 adding a service made by @code{gnome-desktop-service} adds the GNOME
7871 metapackage to the system profile. Likewise, adding the XFCE service
7872 not only adds the @code{xfce} metapackage to the system profile, but it
7873 also gives the Thunar file manager the ability to open a ``root-mode''
7874 file management window, if the user authenticates using the
7875 administrator's password via the standard polkit graphical interface.
7876
7877 @deffn {Scheme Procedure} gnome-desktop-service
7878 Return a service that adds the @code{gnome} package to the system
7879 profile, and extends polkit with the actions from
7880 @code{gnome-settings-daemon}.
7881 @end deffn
7882
7883 @deffn {Scheme Procedure} xfce-desktop-service
7884 Return a service that adds the @code{xfce} package to the system profile,
7885 and extends polkit with the abilit for @code{thunar} to manipulate the
7886 file system as root from within a user session, after the user has
7887 authenticated with the administrator's password.
7888 @end deffn
7889
7890 Because the GNOME and XFCE desktop services pull in so many packages,
7891 the default @code{%desktop-services} variable doesn't include either of
7892 them by default. To add GNOME or XFCE, just @code{cons} them onto
7893 @code{%desktop-services} in the @code{services} field of your
7894 @code{operating-system}:
7895
7896 @example
7897 (use-modules (gnu))
7898 (use-service-modules desktop)
7899 (operating-system
7900 ...
7901 ;; cons* adds items to the list given as its last argument.
7902 (services (cons* (gnome-desktop-service)
7903 (xfce-desktop-service)
7904 %desktop-services))
7905 ...)
7906 @end example
7907
7908 These desktop environments will then be available as options in the
7909 graphical login window.
7910
7911 The actual service definitions included in @code{%desktop-services} and
7912 provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
7913 are described below.
7914
7915 @deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
7916 Return a service that runs the ``system bus'', using @var{dbus}, with
7917 support for @var{services}.
7918
7919 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7920 facility. Its system bus is used to allow system services to communicate
7921 and to be notified of system-wide events.
7922
7923 @var{services} must be a list of packages that provide an
7924 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7925 and policy files. For example, to allow avahi-daemon to use the system bus,
7926 @var{services} must be equal to @code{(list avahi)}.
7927 @end deffn
7928
7929 @deffn {Scheme Procedure} elogind-service [#:config @var{config}]
7930 Return a service that runs the @code{elogind} login and
7931 seat management daemon. @uref{https://github.com/andywingo/elogind,
7932 Elogind} exposes a D-Bus interface that can be used to know which users
7933 are logged in, know what kind of sessions they have open, suspend the
7934 system, inhibit system suspend, reboot the system, and other tasks.
7935
7936 Elogind handles most system-level power events for a computer, for
7937 example suspending the system when a lid is closed, or shutting it down
7938 when the power button is pressed.
7939
7940 The @var{config} keyword argument specifies the configuration for
7941 elogind, and should be the result of an @code{(elogind-configuration
7942 (@var{parameter} @var{value})...)} invocation. Available parameters and
7943 their default values are:
7944
7945 @table @code
7946 @item kill-user-processes?
7947 @code{#f}
7948 @item kill-only-users
7949 @code{()}
7950 @item kill-exclude-users
7951 @code{("root")}
7952 @item inhibit-delay-max-seconds
7953 @code{5}
7954 @item handle-power-key
7955 @code{poweroff}
7956 @item handle-suspend-key
7957 @code{suspend}
7958 @item handle-hibernate-key
7959 @code{hibernate}
7960 @item handle-lid-switch
7961 @code{suspend}
7962 @item handle-lid-switch-docked
7963 @code{ignore}
7964 @item power-key-ignore-inhibited?
7965 @code{#f}
7966 @item suspend-key-ignore-inhibited?
7967 @code{#f}
7968 @item hibernate-key-ignore-inhibited?
7969 @code{#f}
7970 @item lid-switch-ignore-inhibited?
7971 @code{#t}
7972 @item holdoff-timeout-seconds
7973 @code{30}
7974 @item idle-action
7975 @code{ignore}
7976 @item idle-action-seconds
7977 @code{(* 30 60)}
7978 @item runtime-directory-size-percent
7979 @code{10}
7980 @item runtime-directory-size
7981 @code{#f}
7982 @item remove-ipc?
7983 @code{#t}
7984 @item suspend-state
7985 @code{("mem" "standby" "freeze")}
7986 @item suspend-mode
7987 @code{()}
7988 @item hibernate-state
7989 @code{("disk")}
7990 @item hibernate-mode
7991 @code{("platform" "shutdown")}
7992 @item hybrid-sleep-state
7993 @code{("disk")}
7994 @item hybrid-sleep-mode
7995 @code{("suspend" "platform" "shutdown")}
7996 @end table
7997 @end deffn
7998
7999 @deffn {Scheme Procedure} polkit-service @
8000 [#:polkit @var{polkit}]
8001 Return a service that runs the
8002 @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
8003 management service}, which allows system administrators to grant access to
8004 privileged operations in a structured way. By querying the Polkit service, a
8005 privileged system component can know when it should grant additional
8006 capabilities to ordinary users. For example, an ordinary user can be granted
8007 the capability to suspend the system if the user is logged in locally.
8008 @end deffn
8009
8010 @deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
8011 [#:watts-up-pro? #f] @
8012 [#:poll-batteries? #t] @
8013 [#:ignore-lid? #f] @
8014 [#:use-percentage-for-policy? #f] @
8015 [#:percentage-low 10] @
8016 [#:percentage-critical 3] @
8017 [#:percentage-action 2] @
8018 [#:time-low 1200] @
8019 [#:time-critical 300] @
8020 [#:time-action 120] @
8021 [#:critical-power-action 'hybrid-sleep]
8022 Return a service that runs @uref{http://upower.freedesktop.org/,
8023 @command{upowerd}}, a system-wide monitor for power consumption and battery
8024 levels, with the given configuration settings. It implements the
8025 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by
8026 GNOME.
8027 @end deffn
8028
8029 @deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
8030 Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
8031 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
8032 notifications and ways to mount/unmount disks. Programs that talk to UDisks
8033 include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
8034 @end deffn
8035
8036 @deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
8037 Return a service that runs @command{colord}, a system service with a D-Bus
8038 interface to manage the color profiles of input and output devices such as
8039 screens and scanners. It is notably used by the GNOME Color Manager graphical
8040 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
8041 site} for more information.
8042 @end deffn
8043
8044 @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
8045 Return a configuration allowing an application to access GeoClue
8046 location data. @var{name} is the Desktop ID of the application, without
8047 the @code{.desktop} part. If @var{allowed?} is true, the application
8048 will have access to location information by default. The boolean
8049 @var{system?} value indicates whether an application is a system component
8050 or not. Finally @var{users} is a list of UIDs of all users for which
8051 this application is allowed location info access. An empty users list
8052 means that all users are allowed.
8053 @end deffn
8054
8055 @defvr {Scheme Variable} %standard-geoclue-applications
8056 The standard list of well-known GeoClue application configurations,
8057 granting authority to the GNOME date-and-time utility to ask for the
8058 current location in order to set the time zone, and allowing the
8059 IceCat and Epiphany web browsers to request location information.
8060 IceCat and Epiphany both query the user before allowing a web page to
8061 know the user's location.
8062 @end defvr
8063
8064 @deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
8065 [#:whitelist '()] @
8066 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
8067 [#:submit-data? #f]
8068 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
8069 [#:submission-nick "geoclue"] @
8070 [#:applications %standard-geoclue-applications]
8071 Return a service that runs the GeoClue location service. This service
8072 provides a D-Bus interface to allow applications to request access to a
8073 user's physical location, and optionally to add information to online
8074 location databases. See
8075 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
8076 web site} for more information.
8077 @end deffn
8078
8079 @deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
8080 Return a service that runs the @command{bluetoothd} daemon, which manages
8081 all the Bluetooth devices and provides a number of D-Bus interfaces.
8082
8083 Users need to be in the @code{lp} group to access the D-Bus service.
8084 @end deffn
8085
8086 @node Database Services
8087 @subsubsection Database Services
8088
8089 The @code{(gnu services databases)} module provides the following services.
8090
8091 @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
8092 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
8093 Return a service that runs @var{postgresql}, the PostgreSQL database
8094 server.
8095
8096 The PostgreSQL daemon loads its runtime configuration from
8097 @var{config-file} and stores the database cluster in
8098 @var{data-directory}.
8099 @end deffn
8100
8101 @deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
8102 Return a service that runs @command{mysqld}, the MySQL or MariaDB
8103 database server.
8104
8105 The optional @var{config} argument specifies the configuration for
8106 @command{mysqld}, which should be a @code{<mysql-configuraiton>} object.
8107 @end deffn
8108
8109 @deftp {Data Type} mysql-configuration
8110 Data type representing the configuration of @var{mysql-service}.
8111
8112 @table @asis
8113 @item @code{mysql} (default: @var{mariadb})
8114 Package object of the MySQL database server, can be either @var{mariadb}
8115 or @var{mysql}.
8116
8117 For MySQL, a temorary root password will be displayed at activation time.
8118 For MariaDB, the root password is empty.
8119 @end table
8120 @end deftp
8121
8122 @node Mail Services
8123 @subsubsection Mail Services
8124
8125 The @code{(gnu services mail)} module provides Guix service definitions
8126 for mail services. Currently the only implemented service is Dovecot,
8127 an IMAP, POP3, and LMTP server.
8128
8129 Guix does not yet have a mail transfer agent (MTA), although for some
8130 lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
8131 is needed to properly integrate a full MTA, such as Postfix. Patches
8132 welcome!
8133
8134 To add an IMAP/POP3 server to a GuixSD system, add a
8135 @code{dovecot-service} to the operating system definition:
8136
8137 @deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
8138 Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
8139 @end deffn
8140
8141 By default, Dovecot does not need much configuration; the default
8142 configuration object created by @code{(dovecot-configuration)} will
8143 suffice if your mail is delivered to @code{~/Maildir}. A self-signed
8144 certificate will be generated for TLS-protected connections, though
8145 Dovecot will also listen on cleartext ports by default. There are a
8146 number of options, though, which mail administrators might need to change,
8147 and as is the case with other services, Guix allows the system
8148 administrator to specify these parameters via a uniform Scheme interface.
8149
8150 For example, to specify that mail is located at @code{maildir~/.mail},
8151 one would instantiate the Dovecot service like this:
8152
8153 @example
8154 (dovecot-service #:config
8155 (dovecot-configuration
8156 (mail-location "maildir:~/.mail")))
8157 @end example
8158
8159 The available configuration parameters follow. Each parameter
8160 definition is preceded by its type; for example, @samp{string-list foo}
8161 indicates that the @code{foo} parameter should be specified as a list of
8162 strings. There is also a way to specify the configuration as a string,
8163 if you have an old @code{dovecot.conf} file that you want to port over
8164 from some other system; see the end for more details.
8165
8166 @c The following documentation was initially generated by
8167 @c (generate-documentation) in (gnu services mail). Manually maintained
8168 @c documentation is better, so we shouldn't hesitate to edit below as
8169 @c needed. However if the change you want to make to this documentation
8170 @c can be done in an automated way, it's probably easier to change
8171 @c (generate-documentation) than to make it below and have to deal with
8172 @c the churn as dovecot updates.
8173
8174 Available @code{dovecot-configuration} fields are:
8175
8176 @deftypevr {@code{dovecot-configuration} parameter} package dovecot
8177 The dovecot package.
8178 @end deftypevr
8179
8180 @deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
8181 A list of IPs or hosts where to listen for connections. @samp{*}
8182 listens on all IPv4 interfaces, @samp{::} listens on all IPv6
8183 interfaces. If you want to specify non-default ports or anything more
8184 complex, customize the address and port fields of the
8185 @samp{inet-listener} of the specific services you are interested in.
8186 @end deftypevr
8187
8188 @deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
8189 List of protocols we want to serve. Available protocols include
8190 @samp{imap}, @samp{pop3}, and @samp{lmtp}.
8191
8192 Available @code{protocol-configuration} fields are:
8193
8194 @deftypevr {@code{protocol-configuration} parameter} string name
8195 The name of the protocol.
8196 @end deftypevr
8197
8198 @deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
8199 UNIX socket path to the master authentication server to find users.
8200 This is used by imap (for shared users) and lda.
8201 It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8202 @end deftypevr
8203
8204 @deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
8205 Space separated list of plugins to load.
8206 @end deftypevr
8207
8208 @deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
8209 Maximum number of IMAP connections allowed for a user from each IP
8210 address. NOTE: The username is compared case-sensitively.
8211 Defaults to @samp{10}.
8212 @end deftypevr
8213
8214 @end deftypevr
8215
8216 @deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
8217 List of services to enable. Available services include @samp{imap},
8218 @samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
8219 @samp{lmtp}.
8220
8221 Available @code{service-configuration} fields are:
8222
8223 @deftypevr {@code{service-configuration} parameter} string kind
8224 The service kind. Valid values include @code{director},
8225 @code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
8226 @code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
8227 @code{tcpwrap}, @code{quota-warning}, or anything else.
8228 @end deftypevr
8229
8230 @deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
8231 Listeners for the service. A listener is either a
8232 @code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
8233 an @code{inet-listener-configuration}.
8234 Defaults to @samp{()}.
8235
8236 Available @code{unix-listener-configuration} fields are:
8237
8238 @deftypevr {@code{unix-listener-configuration} parameter} file-name path
8239 The file name on which to listen.
8240 @end deftypevr
8241
8242 @deftypevr {@code{unix-listener-configuration} parameter} string mode
8243 The access mode for the socket.
8244 Defaults to @samp{"0600"}.
8245 @end deftypevr
8246
8247 @deftypevr {@code{unix-listener-configuration} parameter} string user
8248 The user to own the socket.
8249 Defaults to @samp{""}.
8250 @end deftypevr
8251
8252 @deftypevr {@code{unix-listener-configuration} parameter} string group
8253 The group to own the socket.
8254 Defaults to @samp{""}.
8255 @end deftypevr
8256
8257
8258 Available @code{fifo-listener-configuration} fields are:
8259
8260 @deftypevr {@code{fifo-listener-configuration} parameter} file-name path
8261 The file name on which to listen.
8262 @end deftypevr
8263
8264 @deftypevr {@code{fifo-listener-configuration} parameter} string mode
8265 The access mode for the socket.
8266 Defaults to @samp{"0600"}.
8267 @end deftypevr
8268
8269 @deftypevr {@code{fifo-listener-configuration} parameter} string user
8270 The user to own the socket.
8271 Defaults to @samp{""}.
8272 @end deftypevr
8273
8274 @deftypevr {@code{fifo-listener-configuration} parameter} string group
8275 The group to own the socket.
8276 Defaults to @samp{""}.
8277 @end deftypevr
8278
8279
8280 Available @code{inet-listener-configuration} fields are:
8281
8282 @deftypevr {@code{inet-listener-configuration} parameter} string protocol
8283 The protocol to listen for.
8284 @end deftypevr
8285
8286 @deftypevr {@code{inet-listener-configuration} parameter} string address
8287 The address on which to listen, or empty for all addresses.
8288 Defaults to @samp{""}.
8289 @end deftypevr
8290
8291 @deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
8292 The port on which to listen.
8293 @end deftypevr
8294
8295 @deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
8296 Whether to use SSL for this service; @samp{yes}, @samp{no}, or
8297 @samp{required}.
8298 Defaults to @samp{#t}.
8299 @end deftypevr
8300
8301 @end deftypevr
8302
8303 @deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
8304 Number of connections to handle before starting a new process.
8305 Typically the only useful values are 0 (unlimited) or 1. 1 is more
8306 secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
8307 Defaults to @samp{1}.
8308 @end deftypevr
8309
8310 @deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
8311 Number of processes to always keep waiting for more connections.
8312 Defaults to @samp{0}.
8313 @end deftypevr
8314
8315 @deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
8316 If you set @samp{service-count 0}, you probably need to grow
8317 this.
8318 Defaults to @samp{256000000}.
8319 @end deftypevr
8320
8321 @end deftypevr
8322
8323 @deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
8324 Dict configuration, as created by the @code{dict-configuration}
8325 constructor.
8326
8327 Available @code{dict-configuration} fields are:
8328
8329 @deftypevr {@code{dict-configuration} parameter} free-form-fields entries
8330 A list of key-value pairs that this dict should hold.
8331 Defaults to @samp{()}.
8332 @end deftypevr
8333
8334 @end deftypevr
8335
8336 @deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
8337 A list of passdb configurations, each one created by the
8338 @code{passdb-configuration} constructor.
8339
8340 Available @code{passdb-configuration} fields are:
8341
8342 @deftypevr {@code{passdb-configuration} parameter} string driver
8343 The driver that the passdb should use. Valid values include
8344 @samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
8345 @samp{static}.
8346 Defaults to @samp{"pam"}.
8347 @end deftypevr
8348
8349 @deftypevr {@code{passdb-configuration} parameter} free-form-args args
8350 A list of key-value args to the passdb driver.
8351 Defaults to @samp{()}.
8352 @end deftypevr
8353
8354 @end deftypevr
8355
8356 @deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
8357 List of userdb configurations, each one created by the
8358 @code{userdb-configuration} constructor.
8359
8360 Available @code{userdb-configuration} fields are:
8361
8362 @deftypevr {@code{userdb-configuration} parameter} string driver
8363 The driver that the userdb should use. Valid values include
8364 @samp{passwd} and @samp{static}.
8365 Defaults to @samp{"passwd"}.
8366 @end deftypevr
8367
8368 @deftypevr {@code{userdb-configuration} parameter} free-form-args args
8369 A list of key-value args to the userdb driver.
8370 Defaults to @samp{()}.
8371 @end deftypevr
8372
8373 @deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
8374 Override fields from passwd.
8375 Defaults to @samp{()}.
8376 @end deftypevr
8377
8378 @end deftypevr
8379
8380 @deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
8381 Plug-in configuration, created by the @code{plugin-configuration}
8382 constructor.
8383 @end deftypevr
8384
8385 @deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
8386 List of namespaces. Each item in the list is created by the
8387 @code{namespace-configuration} constructor.
8388
8389 Available @code{namespace-configuration} fields are:
8390
8391 @deftypevr {@code{namespace-configuration} parameter} string name
8392 Name for this namespace.
8393 @end deftypevr
8394
8395 @deftypevr {@code{namespace-configuration} parameter} string type
8396 Namespace type: @samp{private}, @samp{shared} or @samp{public}.
8397 Defaults to @samp{"private"}.
8398 @end deftypevr
8399
8400 @deftypevr {@code{namespace-configuration} parameter} string separator
8401 Hierarchy separator to use. You should use the same separator for
8402 all namespaces or some clients get confused. @samp{/} is usually a good
8403 one. The default however depends on the underlying mail storage
8404 format.
8405 Defaults to @samp{""}.
8406 @end deftypevr
8407
8408 @deftypevr {@code{namespace-configuration} parameter} string prefix
8409 Prefix required to access this namespace. This needs to be
8410 different for all namespaces. For example @samp{Public/}.
8411 Defaults to @samp{""}.
8412 @end deftypevr
8413
8414 @deftypevr {@code{namespace-configuration} parameter} string location
8415 Physical location of the mailbox. This is in the same format as
8416 mail_location, which is also the default for it.
8417 Defaults to @samp{""}.
8418 @end deftypevr
8419
8420 @deftypevr {@code{namespace-configuration} parameter} boolean inbox?
8421 There can be only one INBOX, and this setting defines which
8422 namespace has it.
8423 Defaults to @samp{#f}.
8424 @end deftypevr
8425
8426 @deftypevr {@code{namespace-configuration} parameter} boolean hidden?
8427 If namespace is hidden, it's not advertised to clients via NAMESPACE
8428 extension. You'll most likely also want to set @samp{list? #f}. This is mostly
8429 useful when converting from another server with different namespaces
8430 which you want to deprecate but still keep working. For example you can
8431 create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
8432 and @samp{mail/}.
8433 Defaults to @samp{#f}.
8434 @end deftypevr
8435
8436 @deftypevr {@code{namespace-configuration} parameter} boolean list?
8437 Show the mailboxes under this namespace with the LIST command. This
8438 makes the namespace visible for clients that do not support the NAMESPACE
8439 extension. The special @code{children} value lists child mailboxes, but
8440 hides the namespace prefix.
8441 Defaults to @samp{#t}.
8442 @end deftypevr
8443
8444 @deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
8445 Namespace handles its own subscriptions. If set to @code{#f}, the
8446 parent namespace handles them. The empty prefix should always have this
8447 as @code{#t}).
8448 Defaults to @samp{#t}.
8449 @end deftypevr
8450
8451 @deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
8452 List of predefined mailboxes in this namespace.
8453 Defaults to @samp{()}.
8454
8455 Available @code{mailbox-configuration} fields are:
8456
8457 @deftypevr {@code{mailbox-configuration} parameter} string name
8458 Name for this mailbox.
8459 @end deftypevr
8460
8461 @deftypevr {@code{mailbox-configuration} parameter} string auto
8462 @samp{create} will automatically create this mailbox.
8463 @samp{subscribe} will both create and subscribe to the mailbox.
8464 Defaults to @samp{"no"}.
8465 @end deftypevr
8466
8467 @deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
8468 List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
8469 Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
8470 @code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
8471 Defaults to @samp{()}.
8472 @end deftypevr
8473
8474 @end deftypevr
8475
8476 @end deftypevr
8477
8478 @deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
8479 Base directory where to store runtime data.
8480 Defaults to @samp{"/var/run/dovecot/"}.
8481 @end deftypevr
8482
8483 @deftypevr {@code{dovecot-configuration} parameter} string login-greeting
8484 Greeting message for clients.
8485 Defaults to @samp{"Dovecot ready."}.
8486 @end deftypevr
8487
8488 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
8489 List of trusted network ranges. Connections from these IPs are
8490 allowed to override their IP addresses and ports (for logging and for
8491 authentication checks). @samp{disable-plaintext-auth} is also ignored
8492 for these networks. Typically you would specify your IMAP proxy servers
8493 here.
8494 Defaults to @samp{()}.
8495 @end deftypevr
8496
8497 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
8498 List of login access check sockets (e.g. tcpwrap).
8499 Defaults to @samp{()}.
8500 @end deftypevr
8501
8502 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
8503 Show more verbose process titles (in ps). Currently shows user name
8504 and IP address. Useful for seeing who is actually using the IMAP
8505 processes (e.g. shared mailboxes or if the same uid is used for multiple
8506 accounts).
8507 Defaults to @samp{#f}.
8508 @end deftypevr
8509
8510 @deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
8511 Should all processes be killed when Dovecot master process shuts down.
8512 Setting this to @code{#f} means that Dovecot can be upgraded without
8513 forcing existing client connections to close (although that could also
8514 be a problem if the upgrade is e.g. due to a security fix).
8515 Defaults to @samp{#t}.
8516 @end deftypevr
8517
8518 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
8519 If non-zero, run mail commands via this many connections to doveadm
8520 server, instead of running them directly in the same process.
8521 Defaults to @samp{0}.
8522 @end deftypevr
8523
8524 @deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
8525 UNIX socket or host:port used for connecting to doveadm server.
8526 Defaults to @samp{"doveadm-server"}.
8527 @end deftypevr
8528
8529 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
8530 List of environment variables that are preserved on Dovecot startup
8531 and passed down to all of its child processes. You can also give
8532 key=value pairs to always set specific settings.
8533 @end deftypevr
8534
8535 @deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
8536 Disable LOGIN command and all other plaintext authentications unless
8537 SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
8538 matches the local IP (i.e. you're connecting from the same computer),
8539 the connection is considered secure and plaintext authentication is
8540 allowed. See also ssl=required setting.
8541 Defaults to @samp{#t}.
8542 @end deftypevr
8543
8544 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
8545 Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
8546 Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
8547 for caching to be used.
8548 Defaults to @samp{0}.
8549 @end deftypevr
8550
8551 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
8552 Time to live for cached data. After TTL expires the cached record
8553 is no longer used, *except* if the main database lookup returns internal
8554 failure. We also try to handle password changes automatically: If
8555 user's previous authentication was successful, but this one wasn't, the
8556 cache isn't used. For now this works only with plaintext
8557 authentication.
8558 Defaults to @samp{"1 hour"}.
8559 @end deftypevr
8560
8561 @deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
8562 TTL for negative hits (user not found, password mismatch).
8563 0 disables caching them completely.
8564 Defaults to @samp{"1 hour"}.
8565 @end deftypevr
8566
8567 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
8568 List of realms for SASL authentication mechanisms that need them.
8569 You can leave it empty if you don't want to support multiple realms.
8570 Many clients simply use the first one listed here, so keep the default
8571 realm first.
8572 Defaults to @samp{()}.
8573 @end deftypevr
8574
8575 @deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
8576 Default realm/domain to use if none was specified. This is used for
8577 both SASL realms and appending @@domain to username in plaintext
8578 logins.
8579 Defaults to @samp{""}.
8580 @end deftypevr
8581
8582 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
8583 List of allowed characters in username. If the user-given username
8584 contains a character not listed in here, the login automatically fails.
8585 This is just an extra check to make sure user can't exploit any
8586 potential quote escaping vulnerabilities with SQL/LDAP databases. If
8587 you want to allow all characters, set this value to empty.
8588 Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8589 @end deftypevr
8590
8591 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8592 Username character translations before it's looked up from
8593 databases. The value contains series of from -> to characters. For
8594 example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8595 translated to @samp{@@}.
8596 Defaults to @samp{""}.
8597 @end deftypevr
8598
8599 @deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8600 Username formatting before it's looked up from databases. You can
8601 use the standard variables here, e.g. %Lu would lowercase the username,
8602 %n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8603 change the @samp{@@} into @samp{-AT-}. This translation is done after
8604 @samp{auth-username-translation} changes.
8605 Defaults to @samp{"%Lu"}.
8606 @end deftypevr
8607
8608 @deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8609 If you want to allow master users to log in by specifying the master
8610 username within the normal username string (i.e. not using SASL
8611 mechanism's support for it), you can specify the separator character
8612 here. The format is then <username><separator><master username>.
8613 UW-IMAP uses @samp{*} as the separator, so that could be a good
8614 choice.
8615 Defaults to @samp{""}.
8616 @end deftypevr
8617
8618 @deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8619 Username to use for users logging in with ANONYMOUS SASL
8620 mechanism.
8621 Defaults to @samp{"anonymous"}.
8622 @end deftypevr
8623
8624 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8625 Maximum number of dovecot-auth worker processes. They're used to
8626 execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8627 They're automatically created and destroyed as needed.
8628 Defaults to @samp{30}.
8629 @end deftypevr
8630
8631 @deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8632 Host name to use in GSSAPI principal names. The default is to use
8633 the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8634 allow all keytab entries.
8635 Defaults to @samp{""}.
8636 @end deftypevr
8637
8638 @deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8639 Kerberos keytab to use for the GSSAPI mechanism. Will use the
8640 system default (usually /etc/krb5.keytab) if not specified. You may
8641 need to change the auth service to run as root to be able to read this
8642 file.
8643 Defaults to @samp{""}.
8644 @end deftypevr
8645
8646 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8647 Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8648 and @samp{ntlm-auth} helper.
8649 <doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8650 Defaults to @samp{#f}.
8651 @end deftypevr
8652
8653 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8654 Path for Samba's @samp{ntlm-auth} helper binary.
8655 Defaults to @samp{"/usr/bin/ntlm_auth"}.
8656 @end deftypevr
8657
8658 @deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8659 Time to delay before replying to failed authentications.
8660 Defaults to @samp{"2 secs"}.
8661 @end deftypevr
8662
8663 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8664 Require a valid SSL client certificate or the authentication
8665 fails.
8666 Defaults to @samp{#f}.
8667 @end deftypevr
8668
8669 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8670 Take the username from client's SSL certificate, using
8671 @code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8672 CommonName.
8673 Defaults to @samp{#f}.
8674 @end deftypevr
8675
8676 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8677 List of wanted authentication mechanisms. Supported mechanisms are:
8678 @samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8679 @samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8680 @samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8681 @samp{disable-plaintext-auth} setting.
8682 @end deftypevr
8683
8684 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8685 List of IPs or hostnames to all director servers, including ourself.
8686 Ports can be specified as ip:port. The default port is the same as what
8687 director service's @samp{inet-listener} is using.
8688 Defaults to @samp{()}.
8689 @end deftypevr
8690
8691 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8692 List of IPs or hostnames to all backend mail servers. Ranges are
8693 allowed too, like 10.0.0.10-10.0.0.30.
8694 Defaults to @samp{()}.
8695 @end deftypevr
8696
8697 @deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8698 How long to redirect users to a specific server after it no longer
8699 has any connections.
8700 Defaults to @samp{"15 min"}.
8701 @end deftypevr
8702
8703 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8704 TCP/IP port that accepts doveadm connections (instead of director
8705 connections) If you enable this, you'll also need to add
8706 @samp{inet-listener} for the port.
8707 Defaults to @samp{0}.
8708 @end deftypevr
8709
8710 @deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8711 How the username is translated before being hashed. Useful values
8712 include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8713 are shared within domain.
8714 Defaults to @samp{"%Lu"}.
8715 @end deftypevr
8716
8717 @deftypevr {@code{dovecot-configuration} parameter} string log-path
8718 Log file to use for error messages. @samp{syslog} logs to syslog,
8719 @samp{/dev/stderr} logs to stderr.
8720 Defaults to @samp{"syslog"}.
8721 @end deftypevr
8722
8723 @deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8724 Log file to use for informational messages. Defaults to
8725 @samp{log-path}.
8726 Defaults to @samp{""}.
8727 @end deftypevr
8728
8729 @deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8730 Log file to use for debug messages. Defaults to
8731 @samp{info-log-path}.
8732 Defaults to @samp{""}.
8733 @end deftypevr
8734
8735 @deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8736 Syslog facility to use if you're logging to syslog. Usually if you
8737 don't want to use @samp{mail}, you'll use local0..local7. Also other
8738 standard facilities are supported.
8739 Defaults to @samp{"mail"}.
8740 @end deftypevr
8741
8742 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8743 Log unsuccessful authentication attempts and the reasons why they
8744 failed.
8745 Defaults to @samp{#f}.
8746 @end deftypevr
8747
8748 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8749 In case of password mismatches, log the attempted password. Valid
8750 values are no, plain and sha1. sha1 can be useful for detecting brute
8751 force password attempts vs. user simply trying the same password over
8752 and over again. You can also truncate the value to n chars by appending
8753 ":n" (e.g. sha1:6).
8754 Defaults to @samp{#f}.
8755 @end deftypevr
8756
8757 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8758 Even more verbose logging for debugging purposes. Shows for example
8759 SQL queries.
8760 Defaults to @samp{#f}.
8761 @end deftypevr
8762
8763 @deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
8764 In case of password mismatches, log the passwords and used scheme so
8765 the problem can be debugged. Enabling this also enables
8766 @samp{auth-debug}.
8767 Defaults to @samp{#f}.
8768 @end deftypevr
8769
8770 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
8771 Enable mail process debugging. This can help you figure out why
8772 Dovecot isn't finding your mails.
8773 Defaults to @samp{#f}.
8774 @end deftypevr
8775
8776 @deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
8777 Show protocol level SSL errors.
8778 Defaults to @samp{#f}.
8779 @end deftypevr
8780
8781 @deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
8782 Prefix for each line written to log file. % codes are in
8783 strftime(3) format.
8784 Defaults to @samp{"\"%b %d %H:%M:%S \""}.
8785 @end deftypevr
8786
8787 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
8788 List of elements we want to log. The elements which have a
8789 non-empty variable value are joined together to form a comma-separated
8790 string.
8791 @end deftypevr
8792
8793 @deftypevr {@code{dovecot-configuration} parameter} string login-log-format
8794 Login log format. %s contains @samp{login-log-format-elements}
8795 string, %$ contains the data we want to log.
8796 Defaults to @samp{"%$: %s"}.
8797 @end deftypevr
8798
8799 @deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
8800 Log prefix for mail processes. See doc/wiki/Variables.txt for list
8801 of possible variables you can use.
8802 Defaults to @samp{"\"%s(%u): \""}.
8803 @end deftypevr
8804
8805 @deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
8806 Format to use for logging mail deliveries. You can use variables:
8807 @table @code
8808 @item %$
8809 Delivery status message (e.g. @samp{saved to INBOX})
8810 @item %m
8811 Message-ID
8812 @item %s
8813 Subject
8814 @item %f
8815 From address
8816 @item %p
8817 Physical size
8818 @item %w
8819 Virtual size.
8820 @end table
8821 Defaults to @samp{"msgid=%m: %$"}.
8822 @end deftypevr
8823
8824 @deftypevr {@code{dovecot-configuration} parameter} string mail-location
8825 Location for users' mailboxes. The default is empty, which means
8826 that Dovecot tries to find the mailboxes automatically. This won't work
8827 if the user doesn't yet have any mail, so you should explicitly tell
8828 Dovecot the full location.
8829
8830 If you're using mbox, giving a path to the INBOX
8831 file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
8832 where the other mailboxes are kept. This is called the "root mail
8833 directory", and it must be the first path given in the
8834 @samp{mail-location} setting.
8835
8836 There are a few special variables you can use, eg.:
8837
8838 @table @samp
8839 @item %u
8840 username
8841 @item %n
8842 user part in user@@domain, same as %u if there's no domain
8843 @item %d
8844 domain part in user@@domain, empty if there's no domain
8845 @item %h
8846 home director
8847 @end table
8848
8849 See doc/wiki/Variables.txt for full list. Some examples:
8850 @table @samp
8851 @item maildir:~/Maildir
8852 @item mbox:~/mail:INBOX=/var/mail/%u
8853 @item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
8854 @end table
8855 Defaults to @samp{""}.
8856 @end deftypevr
8857
8858 @deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8859 System user and group used to access mails. If you use multiple,
8860 userdb can override these by returning uid or gid fields. You can use
8861 either numbers or names. <doc/wiki/UserIds.txt>.
8862 Defaults to @samp{""}.
8863 @end deftypevr
8864
8865 @deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8866
8867 Defaults to @samp{""}.
8868 @end deftypevr
8869
8870 @deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8871 Group to enable temporarily for privileged operations. Currently
8872 this is used only with INBOX when either its initial creation or
8873 dotlocking fails. Typically this is set to "mail" to give access to
8874 /var/mail.
8875 Defaults to @samp{""}.
8876 @end deftypevr
8877
8878 @deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8879 Grant access to these supplementary groups for mail processes.
8880 Typically these are used to set up access to shared mailboxes. Note
8881 that it may be dangerous to set these if users can create
8882 symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8883 could allow a user to delete others' mailboxes, or ln -s
8884 /secret/shared/box ~/mail/mybox would allow reading it).
8885 Defaults to @samp{""}.
8886 @end deftypevr
8887
8888 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8889 Allow full filesystem access to clients. There's no access checks
8890 other than what the operating system does for the active UID/GID. It
8891 works with both maildir and mboxes, allowing you to prefix mailboxes
8892 names with e.g. /path/ or ~user/.
8893 Defaults to @samp{#f}.
8894 @end deftypevr
8895
8896 @deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8897 Don't use mmap() at all. This is required if you store indexes to
8898 shared filesystems (NFS or clustered filesystem).
8899 Defaults to @samp{#f}.
8900 @end deftypevr
8901
8902 @deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8903 Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8904 supports @samp{O_EXCL} since version 3, so this should be safe to use
8905 nowadays by default.
8906 Defaults to @samp{#t}.
8907 @end deftypevr
8908
8909 @deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8910 When to use fsync() or fdatasync() calls:
8911 @table @code
8912 @item optimized
8913 Whenever necessary to avoid losing important data
8914 @item always
8915 Useful with e.g. NFS when write()s are delayed
8916 @item never
8917 Never use it (best performance, but crashes can lose data).
8918 @end table
8919 Defaults to @samp{"optimized"}.
8920 @end deftypevr
8921
8922 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8923 Mail storage exists in NFS. Set this to yes to make Dovecot flush
8924 NFS caches whenever needed. If you're using only a single mail server
8925 this isn't needed.
8926 Defaults to @samp{#f}.
8927 @end deftypevr
8928
8929 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8930 Mail index files also exist in NFS. Setting this to yes requires
8931 @samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8932 Defaults to @samp{#f}.
8933 @end deftypevr
8934
8935 @deftypevr {@code{dovecot-configuration} parameter} string lock-method
8936 Locking method for index files. Alternatives are fcntl, flock and
8937 dotlock. Dotlocking uses some tricks which may create more disk I/O
8938 than other locking methods. NFS users: flock doesn't work, remember to
8939 change @samp{mmap-disable}.
8940 Defaults to @samp{"fcntl"}.
8941 @end deftypevr
8942
8943 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8944 Directory in which LDA/LMTP temporarily stores incoming mails >128
8945 kB.
8946 Defaults to @samp{"/tmp"}.
8947 @end deftypevr
8948
8949 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8950 Valid UID range for users. This is mostly to make sure that users can't
8951 log in as daemons or other system users. Note that denying root logins is
8952 hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8953 is set to 0.
8954 Defaults to @samp{500}.
8955 @end deftypevr
8956
8957 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8958
8959 Defaults to @samp{0}.
8960 @end deftypevr
8961
8962 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8963 Valid GID range for users. Users having non-valid GID as primary group ID
8964 aren't allowed to log in. If user belongs to supplementary groups with
8965 non-valid GIDs, those groups are not set.
8966 Defaults to @samp{1}.
8967 @end deftypevr
8968
8969 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8970
8971 Defaults to @samp{0}.
8972 @end deftypevr
8973
8974 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8975 Maximum allowed length for mail keyword name. It's only forced when
8976 trying to create new keywords.
8977 Defaults to @samp{50}.
8978 @end deftypevr
8979
8980 @deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8981 List of directories under which chrooting is allowed for mail
8982 processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8983 too). This setting doesn't affect @samp{login-chroot}
8984 @samp{mail-chroot} or auth chroot settings. If this setting is empty,
8985 "/./" in home dirs are ignored. WARNING: Never add directories here
8986 which local users can modify, that may lead to root exploit. Usually
8987 this should be done only if you don't allow shell access for users.
8988 <doc/wiki/Chrooting.txt>.
8989 Defaults to @samp{()}.
8990 @end deftypevr
8991
8992 @deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8993 Default chroot directory for mail processes. This can be overridden
8994 for specific users in user database by giving /./ in user's home
8995 directory (e.g. /home/./user chroots into /home). Note that usually
8996 there is no real need to do chrooting, Dovecot doesn't allow users to
8997 access files outside their mail directory anyway. If your home
8998 directories are prefixed with the chroot directory, append "/." to
8999 @samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
9000 Defaults to @samp{""}.
9001 @end deftypevr
9002
9003 @deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
9004 UNIX socket path to master authentication server to find users.
9005 This is used by imap (for shared users) and lda.
9006 Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
9007 @end deftypevr
9008
9009 @deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
9010 Directory where to look up mail plugins.
9011 Defaults to @samp{"/usr/lib/dovecot"}.
9012 @end deftypevr
9013
9014 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
9015 List of plugins to load for all services. Plugins specific to IMAP,
9016 LDA, etc. are added to this list in their own .conf files.
9017 Defaults to @samp{()}.
9018 @end deftypevr
9019
9020 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
9021 The minimum number of mails in a mailbox before updates are done to
9022 cache file. This allows optimizing Dovecot's behavior to do less disk
9023 writes at the cost of more disk reads.
9024 Defaults to @samp{0}.
9025 @end deftypevr
9026
9027 @deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
9028 When IDLE command is running, mailbox is checked once in a while to
9029 see if there are any new mails or other changes. This setting defines
9030 the minimum time to wait between those checks. Dovecot can also use
9031 dnotify, inotify and kqueue to find out immediately when changes
9032 occur.
9033 Defaults to @samp{"30 secs"}.
9034 @end deftypevr
9035
9036 @deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
9037 Save mails with CR+LF instead of plain LF. This makes sending those
9038 mails take less CPU, especially with sendfile() syscall with Linux and
9039 FreeBSD. But it also creates a bit more disk I/O which may just make it
9040 slower. Also note that if other software reads the mboxes/maildirs,
9041 they may handle the extra CRs wrong and cause problems.
9042 Defaults to @samp{#f}.
9043 @end deftypevr
9044
9045 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
9046 By default LIST command returns all entries in maildir beginning
9047 with a dot. Enabling this option makes Dovecot return only entries
9048 which are directories. This is done by stat()ing each entry, so it
9049 causes more disk I/O.
9050 (For systems setting struct @samp{dirent->d_type} this check is free
9051 and it's done always regardless of this setting).
9052 Defaults to @samp{#f}.
9053 @end deftypevr
9054
9055 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
9056 When copying a message, do it with hard links whenever possible.
9057 This makes the performance much better, and it's unlikely to have any
9058 side effects.
9059 Defaults to @samp{#t}.
9060 @end deftypevr
9061
9062 @deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
9063 Assume Dovecot is the only MUA accessing Maildir: Scan cur/
9064 directory only when its mtime changes unexpectedly or when we can't find
9065 the mail otherwise.
9066 Defaults to @samp{#f}.
9067 @end deftypevr
9068
9069 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
9070 Which locking methods to use for locking mbox. There are four
9071 available:
9072
9073 @table @code
9074 @item dotlock
9075 Create <mailbox>.lock file. This is the oldest and most NFS-safe
9076 solution. If you want to use /var/mail/ like directory, the users will
9077 need write access to that directory.
9078 @item dotlock-try
9079 Same as dotlock, but if it fails because of permissions or because there
9080 isn't enough disk space, just skip it.
9081 @item fcntl
9082 Use this if possible. Works with NFS too if lockd is used.
9083 @item flock
9084 May not exist in all systems. Doesn't work with NFS.
9085 @item lockf
9086 May not exist in all systems. Doesn't work with NFS.
9087 @end table
9088
9089 You can use multiple locking methods; if you do the order they're declared
9090 in is important to avoid deadlocks if other MTAs/MUAs are using multiple
9091 locking methods as well. Some operating systems don't allow using some of
9092 them simultaneously.
9093 @end deftypevr
9094
9095 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
9096
9097 @end deftypevr
9098
9099 @deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
9100 Maximum time to wait for lock (all of them) before aborting.
9101 Defaults to @samp{"5 mins"}.
9102 @end deftypevr
9103
9104 @deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
9105 If dotlock exists but the mailbox isn't modified in any way,
9106 override the lock file after this much time.
9107 Defaults to @samp{"2 mins"}.
9108 @end deftypevr
9109
9110 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
9111 When mbox changes unexpectedly we have to fully read it to find out
9112 what changed. If the mbox is large this can take a long time. Since
9113 the change is usually just a newly appended mail, it'd be faster to
9114 simply read the new mails. If this setting is enabled, Dovecot does
9115 this but still safely fallbacks to re-reading the whole mbox file
9116 whenever something in mbox isn't how it's expected to be. The only real
9117 downside to this setting is that if some other MUA changes message
9118 flags, Dovecot doesn't notice it immediately. Note that a full sync is
9119 done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
9120 Defaults to @samp{#t}.
9121 @end deftypevr
9122
9123 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
9124 Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
9125 EXAMINE, EXPUNGE or CHECK commands. If this is set,
9126 @samp{mbox-dirty-syncs} is ignored.
9127 Defaults to @samp{#f}.
9128 @end deftypevr
9129
9130 @deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
9131 Delay writing mbox headers until doing a full write sync (EXPUNGE
9132 and CHECK commands and when closing the mailbox). This is especially
9133 useful for POP3 where clients often delete all mails. The downside is
9134 that our changes aren't immediately visible to other MUAs.
9135 Defaults to @samp{#t}.
9136 @end deftypevr
9137
9138 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
9139 If mbox size is smaller than this (e.g. 100k), don't write index
9140 files. If an index file already exists it's still read, just not
9141 updated.
9142 Defaults to @samp{0}.
9143 @end deftypevr
9144
9145 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
9146 Maximum dbox file size until it's rotated.
9147 Defaults to @samp{2000000}.
9148 @end deftypevr
9149
9150 @deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
9151 Maximum dbox file age until it's rotated. Typically in days. Day
9152 begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
9153 disabled.
9154 Defaults to @samp{"1d"}.
9155 @end deftypevr
9156
9157 @deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
9158 When creating new mdbox files, immediately preallocate their size to
9159 @samp{mdbox-rotate-size}. This setting currently works only in Linux
9160 with some filesystems (ext4, xfs).
9161 Defaults to @samp{#f}.
9162 @end deftypevr
9163
9164 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
9165 sdbox and mdbox support saving mail attachments to external files,
9166 which also allows single instance storage for them. Other backends
9167 don't support this for now.
9168
9169 WARNING: This feature hasn't been tested much yet. Use at your own risk.
9170
9171 Directory root where to store mail attachments. Disabled, if empty.
9172 Defaults to @samp{""}.
9173 @end deftypevr
9174
9175 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
9176 Attachments smaller than this aren't saved externally. It's also
9177 possible to write a plugin to disable saving specific attachments
9178 externally.
9179 Defaults to @samp{128000}.
9180 @end deftypevr
9181
9182 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
9183 Filesystem backend to use for saving attachments:
9184 @table @code
9185 @item posix
9186 No SiS done by Dovecot (but this might help FS's own deduplication)
9187 @item sis posix
9188 SiS with immediate byte-by-byte comparison during saving
9189 @item sis-queue posix
9190 SiS with delayed comparison and deduplication.
9191 @end table
9192 Defaults to @samp{"sis posix"}.
9193 @end deftypevr
9194
9195 @deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
9196 Hash format to use in attachment filenames. You can add any text and
9197 variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
9198 @code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
9199 truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
9200 Defaults to @samp{"%@{sha1@}"}.
9201 @end deftypevr
9202
9203 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
9204
9205 Defaults to @samp{100}.
9206 @end deftypevr
9207
9208 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
9209
9210 Defaults to @samp{1000}.
9211 @end deftypevr
9212
9213 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
9214 Default VSZ (virtual memory size) limit for service processes.
9215 This is mainly intended to catch and kill processes that leak memory
9216 before they eat up everything.
9217 Defaults to @samp{256000000}.
9218 @end deftypevr
9219
9220 @deftypevr {@code{dovecot-configuration} parameter} string default-login-user
9221 Login user is internally used by login processes. This is the most
9222 untrusted user in Dovecot system. It shouldn't have access to anything
9223 at all.
9224 Defaults to @samp{"dovenull"}.
9225 @end deftypevr
9226
9227 @deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
9228 Internal user is used by unprivileged processes. It should be
9229 separate from login user, so that login processes can't disturb other
9230 processes.
9231 Defaults to @samp{"dovecot"}.
9232 @end deftypevr
9233
9234 @deftypevr {@code{dovecot-configuration} parameter} string ssl?
9235 SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
9236 Defaults to @samp{"required"}.
9237 @end deftypevr
9238
9239 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
9240 PEM encoded X.509 SSL/TLS certificate (public key).
9241 Defaults to @samp{"</etc/dovecot/default.pem"}.
9242 @end deftypevr
9243
9244 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key
9245 PEM encoded SSL/TLS private key. The key is opened before
9246 dropping root privileges, so keep the key file unreadable by anyone but
9247 root.
9248 Defaults to @samp{"</etc/dovecot/private/default.pem"}.
9249 @end deftypevr
9250
9251 @deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
9252 If key file is password protected, give the password here.
9253 Alternatively give it when starting dovecot with -p parameter. Since
9254 this file is often world-readable, you may want to place this setting
9255 instead to a different.
9256 Defaults to @samp{""}.
9257 @end deftypevr
9258
9259 @deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
9260 PEM encoded trusted certificate authority. Set this only if you
9261 intend to use @samp{ssl-verify-client-cert? #t}. The file should
9262 contain the CA certificate(s) followed by the matching
9263 CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
9264 Defaults to @samp{""}.
9265 @end deftypevr
9266
9267 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
9268 Require that CRL check succeeds for client certificates.
9269 Defaults to @samp{#t}.
9270 @end deftypevr
9271
9272 @deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
9273 Request client to send a certificate. If you also want to require
9274 it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
9275 Defaults to @samp{#f}.
9276 @end deftypevr
9277
9278 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
9279 Which field from certificate to use for username. commonName and
9280 x500UniqueIdentifier are the usual choices. You'll also need to set
9281 @samp{auth-ssl-username-from-cert? #t}.
9282 Defaults to @samp{"commonName"}.
9283 @end deftypevr
9284
9285 @deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
9286 How often to regenerate the SSL parameters file. Generation is
9287 quite CPU intensive operation. The value is in hours, 0 disables
9288 regeneration entirely.
9289 Defaults to @samp{168}.
9290 @end deftypevr
9291
9292 @deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
9293 SSL protocols to use.
9294 Defaults to @samp{"!SSLv2"}.
9295 @end deftypevr
9296
9297 @deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
9298 SSL ciphers to use.
9299 Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
9300 @end deftypevr
9301
9302 @deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
9303 SSL crypto device to use, for valid values run "openssl engine".
9304 Defaults to @samp{""}.
9305 @end deftypevr
9306
9307 @deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
9308 Address to use when sending rejection mails.
9309 Default is postmaster@@<your domain>. %d expands to recipient domain.
9310 Defaults to @samp{""}.
9311 @end deftypevr
9312
9313 @deftypevr {@code{dovecot-configuration} parameter} string hostname
9314 Hostname to use in various parts of sent mails (e.g. in Message-Id)
9315 and in LMTP replies. Default is the system's real hostname@@domain.
9316 Defaults to @samp{""}.
9317 @end deftypevr
9318
9319 @deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
9320 If user is over quota, return with temporary failure instead of
9321 bouncing the mail.
9322 Defaults to @samp{#f}.
9323 @end deftypevr
9324
9325 @deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
9326 Binary to use for sending mails.
9327 Defaults to @samp{"/usr/sbin/sendmail"}.
9328 @end deftypevr
9329
9330 @deftypevr {@code{dovecot-configuration} parameter} string submission-host
9331 If non-empty, send mails via this SMTP host[:port] instead of
9332 sendmail.
9333 Defaults to @samp{""}.
9334 @end deftypevr
9335
9336 @deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
9337 Subject: header to use for rejection mails. You can use the same
9338 variables as for @samp{rejection-reason} below.
9339 Defaults to @samp{"Rejected: %s"}.
9340 @end deftypevr
9341
9342 @deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
9343 Human readable error message for rejection mails. You can use
9344 variables:
9345
9346 @table @code
9347 @item %n
9348 CRLF
9349 @item %r
9350 reason
9351 @item %s
9352 original subject
9353 @item %t
9354 recipient
9355 @end table
9356 Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
9357 @end deftypevr
9358
9359 @deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
9360 Delimiter character between local-part and detail in email
9361 address.
9362 Defaults to @samp{"+"}.
9363 @end deftypevr
9364
9365 @deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
9366 Header where the original recipient address (SMTP's RCPT TO:
9367 address) is taken from if not available elsewhere. With dovecot-lda -a
9368 parameter overrides this. A commonly used header for this is
9369 X-Original-To.
9370 Defaults to @samp{""}.
9371 @end deftypevr
9372
9373 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
9374 Should saving a mail to a nonexistent mailbox automatically create
9375 it?.
9376 Defaults to @samp{#f}.
9377 @end deftypevr
9378
9379 @deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
9380 Should automatically created mailboxes be also automatically
9381 subscribed?.
9382 Defaults to @samp{#f}.
9383 @end deftypevr
9384
9385 @deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
9386 Maximum IMAP command line length. Some clients generate very long
9387 command lines with huge mailboxes, so you may need to raise this if you
9388 get "Too long argument" or "IMAP command line too large" errors
9389 often.
9390 Defaults to @samp{64000}.
9391 @end deftypevr
9392
9393 @deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
9394 IMAP logout format string:
9395 @table @code
9396 @item %i
9397 total number of bytes read from client
9398 @item %o
9399 total number of bytes sent to client.
9400 @end table
9401 Defaults to @samp{"in=%i out=%o"}.
9402 @end deftypevr
9403
9404 @deftypevr {@code{dovecot-configuration} parameter} string imap-capability
9405 Override the IMAP CAPABILITY response. If the value begins with '+',
9406 add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
9407 Defaults to @samp{""}.
9408 @end deftypevr
9409
9410 @deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
9411 How long to wait between "OK Still here" notifications when client
9412 is IDLEing.
9413 Defaults to @samp{"2 mins"}.
9414 @end deftypevr
9415
9416 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
9417 ID field names and values to send to clients. Using * as the value
9418 makes Dovecot use the default value. The following fields have default
9419 values currently: name, version, os, os-version, support-url,
9420 support-email.
9421 Defaults to @samp{""}.
9422 @end deftypevr
9423
9424 @deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
9425 ID fields sent by client to log. * means everything.
9426 Defaults to @samp{""}.
9427 @end deftypevr
9428
9429 @deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
9430 Workarounds for various client bugs:
9431
9432 @table @code
9433 @item delay-newmail
9434 Send EXISTS/RECENT new mail notifications only when replying to NOOP and
9435 CHECK commands. Some clients ignore them otherwise, for example OSX
9436 Mail (<v2.1). Outlook Express breaks more badly though, without this it
9437 may show user "Message no longer in server" errors. Note that OE6
9438 still breaks even with this workaround if synchronization is set to
9439 "Headers Only".
9440
9441 @item tb-extra-mailbox-sep
9442 Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
9443 adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
9444 ignore the extra @samp{/} instead of treating it as invalid mailbox name.
9445
9446 @item tb-lsub-flags
9447 Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
9448 This makes Thunderbird realize they aren't selectable and show them
9449 greyed out, instead of only later giving "not selectable" popup error.
9450 @end table
9451 Defaults to @samp{()}.
9452 @end deftypevr
9453
9454 @deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
9455 Host allowed in URLAUTH URLs sent by client. "*" allows all.
9456 Defaults to @samp{""}.
9457 @end deftypevr
9458
9459
9460 Whew! Lots of configuration options. The nice thing about it though is
9461 that GuixSD has a complete interface to Dovecot's configuration
9462 language. This allows not only a nice way to declare configurations,
9463 but also offers reflective capabilities as well: users can write code to
9464 inspect and transform configurations from within Scheme.
9465
9466 However, it could be that you just want to get a @code{dovecot.conf} up
9467 and running. In that case, you can pass an
9468 @code{opaque-dovecot-configuration} as the @code{#:config} paramter to
9469 @code{dovecot-service}. As its name indicates, an opaque configuration
9470 does not have easy reflective capabilities.
9471
9472 Available @code{opaque-dovecot-configuration} fields are:
9473
9474 @deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
9475 The dovecot package.
9476 @end deftypevr
9477
9478 @deftypevr {@code{opaque-dovecot-configuration} parameter} string string
9479 The contents of the @code{dovecot.conf}, as a string.
9480 @end deftypevr
9481
9482 For example, if your @code{dovecot.conf} is just the empty string, you
9483 could instantiate a dovecot service like this:
9484
9485 @example
9486 (dovecot-service #:config
9487 (opaque-dovecot-configuration
9488 (string "")))
9489 @end example
9490
9491 @node Web Services
9492 @subsubsection Web Services
9493
9494 The @code{(gnu services web)} module provides the following service:
9495
9496 @deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
9497 [#:log-directory ``/var/log/nginx''] @
9498 [#:run-directory ``/var/run/nginx''] @
9499 [#:config-file]
9500
9501 Return a service that runs @var{nginx}, the nginx web server.
9502
9503 The nginx daemon loads its runtime configuration from @var{config-file}.
9504 Log files are written to @var{log-directory} and temporary runtime data
9505 files are written to @var{run-directory}. For proper operation, these
9506 arguments should match what is in @var{config-file} to ensure that the
9507 directories are created when the service is activated.
9508
9509 @end deffn
9510
9511 @node Various Services
9512 @subsubsection Various Services
9513
9514 The @code{(gnu services lirc)} module provides the following service.
9515
9516 @deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
9517 [#:device #f] [#:driver #f] [#:config-file #f] @
9518 [#:extra-options '()]
9519 Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
9520 decodes infrared signals from remote controls.
9521
9522 Optionally, @var{device}, @var{driver} and @var{config-file}
9523 (configuration file name) may be specified. See @command{lircd} manual
9524 for details.
9525
9526 Finally, @var{extra-options} is a list of additional command-line options
9527 passed to @command{lircd}.
9528 @end deffn
9529
9530 @subsubsection Dictionary Services
9531 The @code{(gnu services dict)} module provides the following service:
9532
9533 @deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
9534 Return a service that runs the @command{dicod} daemon, an implementation
9535 of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
9536
9537 The optional @var{config} argument specifies the configuration for
9538 @command{dicod}, which should be a @code{<dicod-configuration>} object, by
9539 default it serves the GNU Collaborative International Dictonary of English.
9540
9541 You can add @command{open localhost} to your @file{~/.dico} file to make
9542 @code{localhost} the default server for @command{dico} client
9543 (@pxref{Initialization File,,, dico, GNU Dico Manual}).
9544 @end deffn
9545
9546 @deftp {Data Type} dicod-configuration
9547 Data type representing the configuration of dicod.
9548
9549 @table @asis
9550 @item @code{dico} (default: @var{dico})
9551 Package object of the GNU Dico dictionary server.
9552
9553 @item @code{interfaces} (default: @var{'("localhost")})
9554 This is the list of IP addresses and ports and possibly socket file
9555 names to listen to (@pxref{Server Settings, @code{listen} directive,,
9556 dico, GNU Dico Manual}).
9557
9558 @item @code{databases} (default: @var{(list %dicod-database:gcide)})
9559 List of @code{<dicod-database>} objects denoting dictionaries to be served.
9560 @end table
9561 @end deftp
9562
9563 @deftp {Data Type} dicod-database
9564 Data type representing a dictionary database.
9565
9566 @table @asis
9567 @item @code{name}
9568 Name of the database, will be used in DICT commands.
9569
9570 @item @code{module}
9571 Name of the dicod module used by this database
9572 (@pxref{Modules,,, dico, GNU Dico Manual}).
9573
9574 @item @code{options}
9575 List of strings or gexps representing the arguments for the module handler
9576 (@pxref{Handlers,,, dico, GNU Dico Manual}).
9577 @end table
9578 @end deftp
9579
9580 @defvr {Scheme Variable} %dicod-database:gcide
9581 A @code{<dicod-database>} object serving the GNU Collaborative International
9582 Dictonary of English using the @code{gcide} package.
9583 @end defvr
9584
9585 @node Setuid Programs
9586 @subsection Setuid Programs
9587
9588 @cindex setuid programs
9589 Some programs need to run with ``root'' privileges, even when they are
9590 launched by unprivileged users. A notorious example is the
9591 @command{passwd} program, which users can run to change their
9592 password, and which needs to access the @file{/etc/passwd} and
9593 @file{/etc/shadow} files---something normally restricted to root, for
9594 obvious security reasons. To address that, these executables are
9595 @dfn{setuid-root}, meaning that they always run with root privileges
9596 (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
9597 for more info about the setuid mechanism.)
9598
9599 The store itself @emph{cannot} contain setuid programs: that would be a
9600 security issue since any user on the system can write derivations that
9601 populate the store (@pxref{The Store}). Thus, a different mechanism is
9602 used: instead of changing the setuid bit directly on files that are in
9603 the store, we let the system administrator @emph{declare} which programs
9604 should be setuid root.
9605
9606 The @code{setuid-programs} field of an @code{operating-system}
9607 declaration contains a list of G-expressions denoting the names of
9608 programs to be setuid-root (@pxref{Using the Configuration System}).
9609 For instance, the @command{passwd} program, which is part of the Shadow
9610 package, can be designated by this G-expression (@pxref{G-Expressions}):
9611
9612 @example
9613 #~(string-append #$shadow "/bin/passwd")
9614 @end example
9615
9616 A default set of setuid programs is defined by the
9617 @code{%setuid-programs} variable of the @code{(gnu system)} module.
9618
9619 @defvr {Scheme Variable} %setuid-programs
9620 A list of G-expressions denoting common programs that are setuid-root.
9621
9622 The list includes commands such as @command{passwd}, @command{ping},
9623 @command{su}, and @command{sudo}.
9624 @end defvr
9625
9626 Under the hood, the actual setuid programs are created in the
9627 @file{/run/setuid-programs} directory at system activation time. The
9628 files in this directory refer to the ``real'' binaries, which are in the
9629 store.
9630
9631 @node X.509 Certificates
9632 @subsection X.509 Certificates
9633
9634 @cindex HTTPS, certificates
9635 @cindex X.509 certificates
9636 @cindex TLS
9637 Web servers available over HTTPS (that is, HTTP over the transport-layer
9638 security mechanism, TLS) send client programs an @dfn{X.509 certificate}
9639 that the client can then use to @emph{authenticate} the server. To do
9640 that, clients verify that the server's certificate is signed by a
9641 so-called @dfn{certificate authority} (CA). But to verify the CA's
9642 signature, clients must have first acquired the CA's certificate.
9643
9644 Web browsers such as GNU@tie{}IceCat include their own set of CA
9645 certificates, such that they are able to verify CA signatures
9646 out-of-the-box.
9647
9648 However, most other programs that can talk HTTPS---@command{wget},
9649 @command{git}, @command{w3m}, etc.---need to be told where CA
9650 certificates can be found.
9651
9652 @cindex @code{nss-certs}
9653 In GuixSD, this is done by adding a package that provides certificates
9654 to the @code{packages} field of the @code{operating-system} declaration
9655 (@pxref{operating-system Reference}). GuixSD includes one such package,
9656 @code{nss-certs}, which is a set of CA certificates provided as part of
9657 Mozilla's Network Security Services.
9658
9659 Note that it is @emph{not} part of @var{%base-packages}, so you need to
9660 explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9661 most applications and libraries look for certificates by default, points
9662 to the certificates installed globally.
9663
9664 Unprivileged users, including users of Guix on a foreign distro,
9665 can also install their own certificate package in
9666 their profile. A number of environment variables need to be defined so
9667 that applications and libraries know where to find them. Namely, the
9668 OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9669 variables. Some applications add their own environment variables; for
9670 instance, the Git version control system honors the certificate bundle
9671 pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
9672 would typically run something like:
9673
9674 @example
9675 $ guix package -i nss-certs
9676 $ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
9677 $ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
9678 $ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
9679 @end example
9680
9681 @node Name Service Switch
9682 @subsection Name Service Switch
9683
9684 @cindex name service switch
9685 @cindex NSS
9686 The @code{(gnu system nss)} module provides bindings to the
9687 configuration file of the libc @dfn{name service switch} or @dfn{NSS}
9688 (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9689 Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9690 extended with new ``name'' lookup methods for system databases, which
9691 includes host names, service names, user accounts, and more (@pxref{Name
9692 Service Switch, System Databases and Name Service Switch,, libc, The GNU
9693 C Library Reference Manual}).
9694
9695 The NSS configuration specifies, for each system database, which lookup
9696 method is to be used, and how the various methods are chained
9697 together---for instance, under which circumstances NSS should try the
9698 next method in the list. The NSS configuration is given in the
9699 @code{name-service-switch} field of @code{operating-system} declarations
9700 (@pxref{operating-system Reference, @code{name-service-switch}}).
9701
9702 @cindex nss-mdns
9703 @cindex .local, host name lookup
9704 As an example, the declaration below configures the NSS to use the
9705 @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9706 back-end}, which supports host name lookups over multicast DNS (mDNS)
9707 for host names ending in @code{.local}:
9708
9709 @example
9710 (name-service-switch
9711 (hosts (list %files ;first, check /etc/hosts
9712
9713 ;; If the above did not succeed, try
9714 ;; with 'mdns_minimal'.
9715 (name-service
9716 (name "mdns_minimal")
9717
9718 ;; 'mdns_minimal' is authoritative for
9719 ;; '.local'. When it returns "not found",
9720 ;; no need to try the next methods.
9721 (reaction (lookup-specification
9722 (not-found => return))))
9723
9724 ;; Then fall back to DNS.
9725 (name-service
9726 (name "dns"))
9727
9728 ;; Finally, try with the "full" 'mdns'.
9729 (name-service
9730 (name "mdns")))))
9731 @end example
9732
9733 Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
9734 contains this configuration, so you will not have to type it if all you
9735 want is to have @code{.local} host lookup working.
9736
9737 Note that, in this case, in addition to setting the
9738 @code{name-service-switch} of the @code{operating-system} declaration,
9739 you also need to use @code{avahi-service} (@pxref{Networking Services,
9740 @code{avahi-service}}), or @var{%desktop-services}, which includes it
9741 (@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9742 to the name service cache daemon (@pxref{Base Services,
9743 @code{nscd-service}}).
9744
9745 For convenience, the following variables provide typical NSS
9746 configurations.
9747
9748 @defvr {Scheme Variable} %default-nss
9749 This is the default name service switch configuration, a
9750 @code{name-service-switch} object.
9751 @end defvr
9752
9753 @defvr {Scheme Variable} %mdns-host-lookup-nss
9754 This is the name service switch configuration with support for host name
9755 lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9756 @end defvr
9757
9758 The reference for name service switch configuration is given below. It
9759 is a direct mapping of the configuration file format of the C library , so
9760 please refer to the C library manual for more information (@pxref{NSS
9761 Configuration File,,, libc, The GNU C Library Reference Manual}).
9762 Compared to the configuration file format of libc NSS, it has the advantage
9763 not only of adding this warm parenthetic feel that we like, but also
9764 static checks: you will know about syntax errors and typos as soon as you
9765 run @command{guix system}.
9766
9767 @deftp {Data Type} name-service-switch
9768
9769 This is the data type representation the configuration of libc's name
9770 service switch (NSS). Each field below represents one of the supported
9771 system databases.
9772
9773 @table @code
9774 @item aliases
9775 @itemx ethers
9776 @itemx group
9777 @itemx gshadow
9778 @itemx hosts
9779 @itemx initgroups
9780 @itemx netgroup
9781 @itemx networks
9782 @itemx password
9783 @itemx public-key
9784 @itemx rpc
9785 @itemx services
9786 @itemx shadow
9787 The system databases handled by the NSS. Each of these fields must be a
9788 list of @code{<name-service>} objects (see below).
9789 @end table
9790 @end deftp
9791
9792 @deftp {Data Type} name-service
9793
9794 This is the data type representing an actual name service and the
9795 associated lookup action.
9796
9797 @table @code
9798 @item name
9799 A string denoting the name service (@pxref{Services in the NSS
9800 configuration,,, libc, The GNU C Library Reference Manual}).
9801
9802 Note that name services listed here must be visible to nscd. This is
9803 achieved by passing the @code{#:name-services} argument to
9804 @code{nscd-service} the list of packages providing the needed name
9805 services (@pxref{Base Services, @code{nscd-service}}).
9806
9807 @item reaction
9808 An action specified using the @code{lookup-specification} macro
9809 (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
9810 Reference Manual}). For example:
9811
9812 @example
9813 (lookup-specification (unavailable => continue)
9814 (success => return))
9815 @end example
9816 @end table
9817 @end deftp
9818
9819 @node Initial RAM Disk
9820 @subsection Initial RAM Disk
9821
9822 @cindex initial RAM disk (initrd)
9823 @cindex initrd (initial RAM disk)
9824 For bootstrapping purposes, the Linux-Libre kernel is passed an
9825 @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
9826 root file system as well as an initialization script. The latter is
9827 responsible for mounting the real root file system, and for loading any
9828 kernel modules that may be needed to achieve that.
9829
9830 The @code{initrd} field of an @code{operating-system} declaration allows
9831 you to specify which initrd you would like to use. The @code{(gnu
9832 system linux-initrd)} module provides two ways to build an initrd: the
9833 high-level @code{base-initrd} procedure, and the low-level
9834 @code{expression->initrd} procedure.
9835
9836 The @code{base-initrd} procedure is intended to cover most common uses.
9837 For example, if you want to add a bunch of kernel modules to be loaded
9838 at boot time, you can define the @code{initrd} field of the operating
9839 system declaration like this:
9840
9841 @example
9842 (initrd (lambda (file-systems . rest)
9843 ;; Create a standard initrd that has modules "foo.ko"
9844 ;; and "bar.ko", as well as their dependencies, in
9845 ;; addition to the modules available by default.
9846 (apply base-initrd file-systems
9847 #:extra-modules '("foo" "bar")
9848 rest)))
9849 @end example
9850
9851 The @code{base-initrd} procedure also handles common use cases that
9852 involves using the system as a QEMU guest, or as a ``live'' system with
9853 volatile root file system.
9854
9855 The initial RAM disk produced by @code{base-initrd} honors several
9856 options passed on the Linux kernel command line (that is, arguments
9857 passed @i{via} the @code{linux} command of GRUB, or the
9858 @code{-append} option) of QEMU, notably:
9859
9860 @table @code
9861 @item --load=@var{boot}
9862 Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
9863 program, once it has mounted the root file system.
9864
9865 GuixSD uses this option to yield control to a boot program that runs the
9866 service activation programs and then spawns the GNU@tie{}Shepherd, the
9867 initialization system.
9868
9869 @item --root=@var{root}
9870 Mount @var{root} as the root file system. @var{root} can be a
9871 device name like @code{/dev/sda1}, a partition label, or a partition
9872 UUID.
9873
9874 @item --system=@var{system}
9875 Have @file{/run/booted-system} and @file{/run/current-system} point to
9876 @var{system}.
9877
9878 @item modprobe.blacklist=@var{modules}@dots{}
9879 @cindex module, black-listing
9880 @cindex black list, of kernel modules
9881 Instruct the initial RAM disk as well as the @command{modprobe} command
9882 (from the kmod package) to refuse to load @var{modules}. @var{modules}
9883 must be a comma-separated list of module names---e.g.,
9884 @code{usbkbd,9pnet}.
9885
9886 @item --repl
9887 Start a read-eval-print loop (REPL) from the initial RAM disk before it
9888 tries to load kernel modules and to mount the root file system. Our
9889 marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
9890 love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
9891 Manual}, for more information on Guile's REPL.
9892
9893 @end table
9894
9895 Now that you know all the features that initial RAM disks produced by
9896 @code{base-initrd} provide, here is how to use it and customize it
9897 further.
9898
9899 @deffn {Monadic Procedure} base-initrd @var{file-systems} @
9900 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
9901 [#:extra-modules '()] [#:mapped-devices '()]
9902 Return a monadic derivation that builds a generic initrd. @var{file-systems} is
9903 a list of file systems to be mounted by the initrd, possibly in addition to
9904 the root file system specified on the kernel command line via @code{--root}.
9905 @var{mapped-devices} is a list of device mappings to realize before
9906 @var{file-systems} are mounted (@pxref{Mapped Devices}).
9907
9908 When @var{qemu-networking?} is true, set up networking with the standard QEMU
9909 parameters. When @var{virtio?} is true, load additional modules so that the
9910 initrd can be used as a QEMU guest with para-virtualized I/O drivers.
9911
9912 When @var{volatile-root?} is true, the root file system is writable but any changes
9913 to it are lost.
9914
9915 The initrd is automatically populated with all the kernel modules necessary
9916 for @var{file-systems} and for the given options. However, additional kernel
9917 modules can be listed in @var{extra-modules}. They will be added to the initrd, and
9918 loaded at boot time in the order in which they appear.
9919 @end deffn
9920
9921 Needless to say, the initrds we produce and use embed a
9922 statically-linked Guile, and the initialization program is a Guile
9923 program. That gives a lot of flexibility. The
9924 @code{expression->initrd} procedure builds such an initrd, given the
9925 program to run in that initrd.
9926
9927 @deffn {Monadic Procedure} expression->initrd @var{exp} @
9928 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
9929 [#:modules '()]
9930 Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9931 containing @var{guile} and that evaluates @var{exp}, a G-expression,
9932 upon booting. All the derivations referenced by @var{exp} are
9933 automatically copied to the initrd.
9934
9935 @var{modules} is a list of Guile module names to be embedded in the
9936 initrd.
9937 @end deffn
9938
9939 @node GRUB Configuration
9940 @subsection GRUB Configuration
9941
9942 @cindex GRUB
9943 @cindex boot loader
9944
9945 The operating system uses GNU@tie{}GRUB as its boot loader
9946 (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
9947 configured using a @code{grub-configuration} declaration. This data type
9948 is exported by the @code{(gnu system grub)} module and described below.
9949
9950 @deftp {Data Type} grub-configuration
9951 The type of a GRUB configuration declaration.
9952
9953 @table @asis
9954
9955 @item @code{device}
9956 This is a string denoting the boot device. It must be a device name
9957 understood by the @command{grub-install} command, such as
9958 @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9959 GNU GRUB Manual}).
9960
9961 @item @code{menu-entries} (default: @code{()})
9962 A possibly empty list of @code{menu-entry} objects (see below), denoting
9963 entries to appear in the GRUB boot menu, in addition to the current
9964 system entry and the entry pointing to previous system generations.
9965
9966 @item @code{default-entry} (default: @code{0})
9967 The index of the default boot menu entry. Index 0 is for the entry of the
9968 current system.
9969
9970 @item @code{timeout} (default: @code{5})
9971 The number of seconds to wait for keyboard input before booting. Set to
9972 0 to boot immediately, and to -1 to wait indefinitely.
9973
9974 @item @code{theme} (default: @var{%default-theme})
9975 The @code{grub-theme} object describing the theme to use.
9976 @end table
9977
9978 @end deftp
9979
9980 Should you want to list additional boot menu entries @i{via} the
9981 @code{menu-entries} field above, you will need to create them with the
9982 @code{menu-entry} form:
9983
9984 @deftp {Data Type} menu-entry
9985 The type of an entry in the GRUB boot menu.
9986
9987 @table @asis
9988
9989 @item @code{label}
9990 The label to show in the menu---e.g., @code{"GNU"}.
9991
9992 @item @code{linux}
9993 The Linux kernel to boot.
9994
9995 @item @code{linux-arguments} (default: @code{()})
9996 The list of extra Linux kernel command-line arguments---e.g.,
9997 @code{("console=ttyS0")}.
9998
9999 @item @code{initrd}
10000 A G-Expression or string denoting the file name of the initial RAM disk
10001 to use (@pxref{G-Expressions}).
10002
10003 @end table
10004 @end deftp
10005
10006 @c FIXME: Write documentation once it's stable.
10007 Themes are created using the @code{grub-theme} form, which is not
10008 documented yet.
10009
10010 @defvr {Scheme Variable} %default-theme
10011 This is the default GRUB theme used by the operating system, with a
10012 fancy background image displaying the GNU and Guix logos.
10013 @end defvr
10014
10015
10016 @node Invoking guix system
10017 @subsection Invoking @code{guix system}
10018
10019 Once you have written an operating system declaration as seen in the
10020 previous section, it can be @dfn{instantiated} using the @command{guix
10021 system} command. The synopsis is:
10022
10023 @example
10024 guix system @var{options}@dots{} @var{action} @var{file}
10025 @end example
10026
10027 @var{file} must be the name of a file containing an
10028 @code{operating-system} declaration. @var{action} specifies how the
10029 operating system is instantiated. Currently the following values are
10030 supported:
10031
10032 @table @code
10033 @item reconfigure
10034 Build the operating system described in @var{file}, activate it, and
10035 switch to it@footnote{This action is usable only on systems already
10036 running GuixSD.}.
10037
10038 This effects all the configuration specified in @var{file}: user
10039 accounts, system services, global package list, setuid programs, etc.
10040 The command starts system services specified in @var{file} that are not
10041 currently running; if a service is currently running, it does not
10042 attempt to upgrade it since this would not be possible without stopping it
10043 first.
10044
10045 It also adds a GRUB menu entry for the new OS configuration, and moves
10046 entries for older configurations to a submenu---unless
10047 @option{--no-grub} is passed.
10048
10049 @quotation Note
10050 @c The paragraph below refers to the problem discussed at
10051 @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
10052 It is highly recommended to run @command{guix pull} once before you run
10053 @command{guix system reconfigure} for the first time (@pxref{Invoking
10054 guix pull}). Failing to do that you would see an older version of Guix
10055 once @command{reconfigure} has completed.
10056 @end quotation
10057
10058 @item build
10059 Build the derivation of the operating system, which includes all the
10060 configuration files and programs needed to boot and run the system.
10061 This action does not actually install anything.
10062
10063 @item init
10064 Populate the given directory with all the files necessary to run the
10065 operating system specified in @var{file}. This is useful for first-time
10066 installations of GuixSD. For instance:
10067
10068 @example
10069 guix system init my-os-config.scm /mnt
10070 @end example
10071
10072 copies to @file{/mnt} all the store items required by the configuration
10073 specified in @file{my-os-config.scm}. This includes configuration
10074 files, packages, and so on. It also creates other essential files
10075 needed for the system to operate correctly---e.g., the @file{/etc},
10076 @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
10077
10078 This command also installs GRUB on the device specified in
10079 @file{my-os-config}, unless the @option{--no-grub} option was passed.
10080
10081 @item vm
10082 @cindex virtual machine
10083 @cindex VM
10084 @anchor{guix system vm}
10085 Build a virtual machine that contains the operating system declared in
10086 @var{file}, and return a script to run that virtual machine (VM).
10087 Arguments given to the script are passed to QEMU.
10088
10089 The VM shares its store with the host system.
10090
10091 Additional file systems can be shared between the host and the VM using
10092 the @code{--share} and @code{--expose} command-line options: the former
10093 specifies a directory to be shared with write access, while the latter
10094 provides read-only access to the shared directory.
10095
10096 The example below creates a VM in which the user's home directory is
10097 accessible read-only, and where the @file{/exchange} directory is a
10098 read-write mapping of @file{$HOME/tmp} on the host:
10099
10100 @example
10101 guix system vm my-config.scm \
10102 --expose=$HOME --share=$HOME/tmp=/exchange
10103 @end example
10104
10105 On GNU/Linux, the default is to boot directly to the kernel; this has
10106 the advantage of requiring only a very tiny root disk image since the
10107 store of the host can then be mounted.
10108
10109 The @code{--full-boot} option forces a complete boot sequence, starting
10110 with the bootloader. This requires more disk space since a root image
10111 containing at least the kernel, initrd, and bootloader data files must
10112 be created. The @code{--image-size} option can be used to specify the
10113 size of the image.
10114
10115 @item vm-image
10116 @itemx disk-image
10117 Return a virtual machine or disk image of the operating system declared
10118 in @var{file} that stands alone. Use the @option{--image-size} option
10119 to specify the size of the image.
10120
10121 When using @code{vm-image}, the returned image is in qcow2 format, which
10122 the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
10123 for more information on how to run the image in a virtual machine.
10124
10125 When using @code{disk-image}, a raw disk image is produced; it can be
10126 copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
10127 the device corresponding to a USB stick, one can copy the image to it
10128 using the following command:
10129
10130 @example
10131 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
10132 @end example
10133
10134 @item container
10135 Return a script to run the operating system declared in @var{file}
10136 within a container. Containers are a set of lightweight isolation
10137 mechanisms provided by the kernel Linux-libre. Containers are
10138 substantially less resource-demanding than full virtual machines since
10139 the kernel, shared objects, and other resources can be shared with the
10140 host system; this also means they provide thinner isolation.
10141
10142 Currently, the script must be run as root in order to support more than
10143 a single user and group. The container shares its store with the host
10144 system.
10145
10146 As with the @code{vm} action (@pxref{guix system vm}), additional file
10147 systems to be shared between the host and container can be specified
10148 using the @option{--share} and @option{--expose} options:
10149
10150 @example
10151 guix system container my-config.scm \
10152 --expose=$HOME --share=$HOME/tmp=/exchange
10153 @end example
10154
10155 @quotation Note
10156 This option requires Linux-libre 3.19 or newer.
10157 @end quotation
10158
10159 @end table
10160
10161 @var{options} can contain any of the common build options (@pxref{Common
10162 Build Options}). In addition, @var{options} can contain one of the
10163 following:
10164
10165 @table @option
10166 @item --system=@var{system}
10167 @itemx -s @var{system}
10168 Attempt to build for @var{system} instead of the host system type.
10169 This works as per @command{guix build} (@pxref{Invoking guix build}).
10170
10171 @item --derivation
10172 @itemx -d
10173 Return the derivation file name of the given operating system without
10174 building anything.
10175
10176 @item --image-size=@var{size}
10177 For the @code{vm-image} and @code{disk-image} actions, create an image
10178 of the given @var{size}. @var{size} may be a number of bytes, or it may
10179 include a unit as a suffix (@pxref{Block size, size specifications,,
10180 coreutils, GNU Coreutils}).
10181
10182 @item --on-error=@var{strategy}
10183 Apply @var{strategy} when an error occurs when reading @var{file}.
10184 @var{strategy} may be one of the following:
10185
10186 @table @code
10187 @item nothing-special
10188 Report the error concisely and exit. This is the default strategy.
10189
10190 @item backtrace
10191 Likewise, but also display a backtrace.
10192
10193 @item debug
10194 Report the error and enter Guile's debugger. From there, you can run
10195 commands such as @code{,bt} to get a backtrace, @code{,locals} to
10196 display local variable values, and more generally inspect the state of the
10197 program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
10198 a list of available debugging commands.
10199 @end table
10200 @end table
10201
10202 Note that all the actions above, except @code{build} and @code{init},
10203 rely on KVM support in the Linux-Libre kernel. Specifically, the
10204 machine should have hardware virtualization support, the corresponding
10205 KVM kernel module should be loaded, and the @file{/dev/kvm} device node
10206 must exist and be readable and writable by the user and by the
10207 build users of the daemon.
10208
10209 Once you have built, configured, re-configured, and re-re-configured
10210 your GuixSD installation, you may find it useful to list the operating
10211 system generations available on disk---and that you can choose from the
10212 GRUB boot menu:
10213
10214 @table @code
10215
10216 @item list-generations
10217 List a summary of each generation of the operating system available on
10218 disk, in a human-readable way. This is similar to the
10219 @option{--list-generations} option of @command{guix package}
10220 (@pxref{Invoking guix package}).
10221
10222 Optionally, one can specify a pattern, with the same syntax that is used
10223 in @command{guix package --list-generations}, to restrict the list of
10224 generations displayed. For instance, the following command displays
10225 generations that are up to 10 days old:
10226
10227 @example
10228 $ guix system list-generations 10d
10229 @end example
10230
10231 @end table
10232
10233 The @command{guix system} command has even more to offer! The following
10234 sub-commands allow you to visualize how your system services relate to
10235 each other:
10236
10237 @anchor{system-extension-graph}
10238 @table @code
10239
10240 @item extension-graph
10241 Emit in Dot/Graphviz format to standard output the @dfn{service
10242 extension graph} of the operating system defined in @var{file}
10243 (@pxref{Service Composition}, for more information on service
10244 extensions.)
10245
10246 The command:
10247
10248 @example
10249 $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
10250 @end example
10251
10252 produces a PDF file showing the extension relations among services.
10253
10254 @anchor{system-shepherd-graph}
10255 @item shepherd-graph
10256 Emit in Dot/Graphviz format to standard output the @dfn{dependency
10257 graph} of shepherd services of the operating system defined in
10258 @var{file}. @xref{Shepherd Services}, for more information and for an
10259 example graph.
10260
10261 @end table
10262
10263 @node Running GuixSD in a VM
10264 @subsection Running GuixSD in a Virtual Machine
10265
10266 One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
10267 virtual machine image using @command{guix system vm-image}
10268 (@pxref{Invoking guix system}). The returned image is in qcow2 format,
10269 which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
10270
10271 To run the image in QEMU, copy it out of the store (@pxref{The Store})
10272 and give yourself permission to write to the copy. When invoking QEMU,
10273 you must choose a system emulator that is suitable for your hardware
10274 platform. Here is a minimal QEMU invocation that will boot the result
10275 of @command{guix system vm-image} on x86_64 hardware:
10276
10277 @example
10278 $ qemu-system-x86_64 \
10279 -net user -net nic,model=virtio \
10280 -enable-kvm -m 256 /tmp/qemu-image
10281 @end example
10282
10283 Here is what each of these options means:
10284
10285 @table @code
10286 @item qemu-system-x86_64
10287 This specifies the hardware platform to emulate. This should match the
10288 host.
10289
10290 @item -net user
10291 Enable the unprivileged user-mode network stack. The guest OS can
10292 access the host but not vice versa. This is the simplest way to get the
10293 guest OS online. If you do not choose a network stack, the boot will
10294 fail.
10295
10296 @item -net nic,model=virtio
10297 You must create a network interface of a given model. If you do not
10298 create a NIC, the boot will fail. Assuming your hardware platform is
10299 x86_64, you can get a list of available NIC models by running
10300 @command{qemu-system-x86_64 -net nic,model=help}.
10301
10302 @item -enable-kvm
10303 If your system has hardware virtualization extensions, enabling the
10304 virtual machine support (KVM) of the Linux kernel will make things run
10305 faster.
10306
10307 @item -m 256
10308 RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
10309 which may be insufficent for some operations.
10310
10311 @item /tmp/qemu-image
10312 The file name of the qcow2 image.
10313 @end table
10314
10315 @node Defining Services
10316 @subsection Defining Services
10317
10318 The previous sections show the available services and how one can combine
10319 them in an @code{operating-system} declaration. But how do we define
10320 them in the first place? And what is a service anyway?
10321
10322 @menu
10323 * Service Composition:: The model for composing services.
10324 * Service Types and Services:: Types and services.
10325 * Service Reference:: API reference.
10326 * Shepherd Services:: A particular type of service.
10327 @end menu
10328
10329 @node Service Composition
10330 @subsubsection Service Composition
10331
10332 @cindex services
10333 @cindex daemons
10334 Here we define a @dfn{service} as, broadly, something that extends the
10335 functionality of the operating system. Often a service is a process---a
10336 @dfn{daemon}---started when the system boots: a secure shell server, a
10337 Web server, the Guix build daemon, etc. Sometimes a service is a daemon
10338 whose execution can be triggered by another daemon---e.g., an FTP server
10339 started by @command{inetd} or a D-Bus service activated by
10340 @command{dbus-daemon}. Occasionally, a service does not map to a
10341 daemon. For instance, the ``account'' service collects user accounts
10342 and makes sure they exist when the system runs; the ``udev'' service
10343 collects device management rules and makes them available to the eudev
10344 daemon; the @file{/etc} service populates the @file{/etc} directory
10345 of the system.
10346
10347 @cindex service extensions
10348 GuixSD services are connected by @dfn{extensions}. For instance, the
10349 secure shell service @emph{extends} the Shepherd---the GuixSD
10350 initialization system, running as PID@tie{}1---by giving it the command
10351 lines to start and stop the secure shell daemon (@pxref{Networking
10352 Services, @code{lsh-service}}); the UPower service extends the D-Bus
10353 service by passing it its @file{.service} specification, and extends the
10354 udev service by passing it device management rules (@pxref{Desktop
10355 Services, @code{upower-service}}); the Guix daemon service extends the
10356 Shepherd by passing it the command lines to start and stop the daemon,
10357 and extends the account service by passing it a list of required build
10358 user accounts (@pxref{Base Services}).
10359
10360 All in all, services and their ``extends'' relations form a directed
10361 acyclic graph (DAG). If we represent services as boxes and extensions
10362 as arrows, a typical system might provide something like this:
10363
10364 @image{images/service-graph,,5in,Typical service extension graph.}
10365
10366 @cindex system service
10367 At the bottom, we see the @dfn{system service}, which produces the
10368 directory containing everything to run and boot the system, as returned
10369 by the @command{guix system build} command. @xref{Service Reference},
10370 to learn about the other service types shown here.
10371 @xref{system-extension-graph, the @command{guix system extension-graph}
10372 command}, for information on how to generate this representation for a
10373 particular operating system definition.
10374
10375 @cindex service types
10376 Technically, developers can define @dfn{service types} to express these
10377 relations. There can be any number of services of a given type on the
10378 system---for instance, a system running two instances of the GNU secure
10379 shell server (lsh) has two instances of @var{lsh-service-type}, with
10380 different parameters.
10381
10382 The following section describes the programming interface for service
10383 types and services.
10384
10385 @node Service Types and Services
10386 @subsubsection Service Types and Services
10387
10388 A @dfn{service type} is a node in the DAG described above. Let us start
10389 with a simple example, the service type for the Guix build daemon
10390 (@pxref{Invoking guix-daemon}):
10391
10392 @example
10393 (define guix-service-type
10394 (service-type
10395 (name 'guix)
10396 (extensions
10397 (list (service-extension shepherd-root-service-type guix-shepherd-service)
10398 (service-extension account-service-type guix-accounts)
10399 (service-extension activation-service-type guix-activation)))))
10400 @end example
10401
10402 @noindent
10403 It defines two things:
10404
10405 @enumerate
10406 @item
10407 A name, whose sole purpose is to make inspection and debugging easier.
10408
10409 @item
10410 A list of @dfn{service extensions}, where each extension designates the
10411 target service type and a procedure that, given the parameters of the
10412 service, returns a list of objects to extend the service of that type.
10413
10414 Every service type has at least one service extension. The only
10415 exception is the @dfn{boot service type}, which is the ultimate service.
10416 @end enumerate
10417
10418 In this example, @var{guix-service-type} extends three services:
10419
10420 @table @var
10421 @item shepherd-root-service-type
10422 The @var{guix-shepherd-service} procedure defines how the Shepherd
10423 service is extended. Namely, it returns a @code{<shepherd-service>}
10424 object that defines how @command{guix-daemon} is started and stopped
10425 (@pxref{Shepherd Services}).
10426
10427 @item account-service-type
10428 This extension for this service is computed by @var{guix-accounts},
10429 which returns a list of @code{user-group} and @code{user-account}
10430 objects representing the build user accounts (@pxref{Invoking
10431 guix-daemon}).
10432
10433 @item activation-service-type
10434 Here @var{guix-activation} is a procedure that returns a gexp, which is
10435 a code snippet to run at ``activation time''---e.g., when the service is
10436 booted.
10437 @end table
10438
10439 A service of this type is instantiated like this:
10440
10441 @example
10442 (service guix-service-type
10443 (guix-configuration
10444 (build-accounts 5)
10445 (use-substitutes? #f)))
10446 @end example
10447
10448 The second argument to the @code{service} form is a value representing
10449 the parameters of this specific service instance.
10450 @xref{guix-configuration-type, @code{guix-configuration}}, for
10451 information about the @code{guix-configuration} data type.
10452
10453 @var{guix-service-type} is quite simple because it extends other
10454 services but is not extensible itself.
10455
10456 @c @subsubsubsection Extensible Service Types
10457
10458 The service type for an @emph{extensible} service looks like this:
10459
10460 @example
10461 (define udev-service-type
10462 (service-type (name 'udev)
10463 (extensions
10464 (list (service-extension shepherd-root-service-type
10465 udev-shepherd-service)))
10466
10467 (compose concatenate) ;concatenate the list of rules
10468 (extend (lambda (config rules)
10469 (match config
10470 (($ <udev-configuration> udev initial-rules)
10471 (udev-configuration
10472 (udev udev) ;the udev package to use
10473 (rules (append initial-rules rules)))))))))
10474 @end example
10475
10476 This is the service type for the
10477 @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
10478 management daemon}. Compared to the previous example, in addition to an
10479 extension of @var{shepherd-root-service-type}, we see two new fields:
10480
10481 @table @code
10482 @item compose
10483 This is the procedure to @dfn{compose} the list of extensions to
10484 services of this type.
10485
10486 Services can extend the udev service by passing it lists of rules; we
10487 compose those extensions simply by concatenating them.
10488
10489 @item extend
10490 This procedure defines how the value of the service is @dfn{extended} with
10491 the composition of the extensions.
10492
10493 Udev extensions are composed into a list of rules, but the udev service
10494 value is itself a @code{<udev-configuration>} record. So here, we
10495 extend that record by appending the list of rules it contains to the
10496 list of contributed rules.
10497 @end table
10498
10499 There can be only one instance of an extensible service type such as
10500 @var{udev-service-type}. If there were more, the
10501 @code{service-extension} specifications would be ambiguous.
10502
10503 Still here? The next section provides a reference of the programming
10504 interface for services.
10505
10506 @node Service Reference
10507 @subsubsection Service Reference
10508
10509 We have seen an overview of service types (@pxref{Service Types and
10510 Services}). This section provides a reference on how to manipulate
10511 services and service types. This interface is provided by the
10512 @code{(gnu services)} module.
10513
10514 @deffn {Scheme Procedure} service @var{type} @var{value}
10515 Return a new service of @var{type}, a @code{<service-type>} object (see
10516 below.) @var{value} can be any object; it represents the parameters of
10517 this particular service instance.
10518 @end deffn
10519
10520 @deffn {Scheme Procedure} service? @var{obj}
10521 Return true if @var{obj} is a service.
10522 @end deffn
10523
10524 @deffn {Scheme Procedure} service-kind @var{service}
10525 Return the type of @var{service}---i.e., a @code{<service-type>} object.
10526 @end deffn
10527
10528 @deffn {Scheme Procedure} service-parameters @var{service}
10529 Return the value associated with @var{service}. It represents its
10530 parameters.
10531 @end deffn
10532
10533 Here is an example of how a service is created and manipulated:
10534
10535 @example
10536 (define s
10537 (service nginx-service-type
10538 (nginx-configuration
10539 (nginx nginx)
10540 (log-directory log-directory)
10541 (run-directory run-directory)
10542 (file config-file))))
10543
10544 (service? s)
10545 @result{} #t
10546
10547 (eq? (service-kind s) nginx-service-type)
10548 @result{} #t
10549 @end example
10550
10551 The @code{modify-services} form provides a handy way to change the
10552 parameters of some of the services of a list such as
10553 @var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
10554 evalutes to a list of services. Of course, you could always use
10555 standard list combinators such as @code{map} and @code{fold} to do that
10556 (@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
10557 @code{modify-services} simply provides a more concise form for this
10558 common pattern.
10559
10560 @deffn {Scheme Syntax} modify-services @var{services} @
10561 (@var{type} @var{variable} => @var{body}) @dots{}
10562
10563 Modify the services listed in @var{services} according to the given
10564 clauses. Each clause has the form:
10565
10566 @example
10567 (@var{type} @var{variable} => @var{body})
10568 @end example
10569
10570 where @var{type} is a service type---e.g.,
10571 @code{guix-service-type}---and @var{variable} is an identifier that is
10572 bound within the @var{body} to the service parameters---e.g., a
10573 @code{guix-configuration} instance---of the original service of that
10574 @var{type}.
10575
10576 The @var{body} should evaluate to the new service parameters, which will
10577 be used to configure the new service. This new service will replace the
10578 original in the resulting list. Because a service's service parameters
10579 are created using @code{define-record-type*}, you can write a succint
10580 @var{body} that evaluates to the new service parameters by using the
10581 @code{inherit} feature that @code{define-record-type*} provides.
10582
10583 @xref{Using the Configuration System}, for example usage.
10584
10585 @end deffn
10586
10587 Next comes the programming interface for service types. This is
10588 something you want to know when writing new service definitions, but not
10589 necessarily when simply looking for ways to customize your
10590 @code{operating-system} declaration.
10591
10592 @deftp {Data Type} service-type
10593 @cindex service type
10594 This is the representation of a @dfn{service type} (@pxref{Service Types
10595 and Services}).
10596
10597 @table @asis
10598 @item @code{name}
10599 This is a symbol, used only to simplify inspection and debugging.
10600
10601 @item @code{extensions}
10602 A non-empty list of @code{<service-extension>} objects (see below).
10603
10604 @item @code{compose} (default: @code{#f})
10605 If this is @code{#f}, then the service type denotes services that cannot
10606 be extended---i.e., services that do not receive ``values'' from other
10607 services.
10608
10609 Otherwise, it must be a one-argument procedure. The procedure is called
10610 by @code{fold-services} and is passed a list of values collected from
10611 extensions. It must return a value that is a valid parameter value for
10612 the service instance.
10613
10614 @item @code{extend} (default: @code{#f})
10615 If this is @code{#f}, services of this type cannot be extended.
10616
10617 Otherwise, it must be a two-argument procedure: @code{fold-services}
10618 calls it, passing it the initial value of the service as the first argument
10619 and the result of applying @code{compose} to the extension values as the
10620 second argument.
10621 @end table
10622
10623 @xref{Service Types and Services}, for examples.
10624 @end deftp
10625
10626 @deffn {Scheme Procedure} service-extension @var{target-type} @
10627 @var{compute}
10628 Return a new extension for services of type @var{target-type}.
10629 @var{compute} must be a one-argument procedure: @code{fold-services}
10630 calls it, passing it the value associated with the service that provides
10631 the extension; it must return a valid value for the target service.
10632 @end deffn
10633
10634 @deffn {Scheme Procedure} service-extension? @var{obj}
10635 Return true if @var{obj} is a service extension.
10636 @end deffn
10637
10638 At the core of the service abstraction lies the @code{fold-services}
10639 procedure, which is responsible for ``compiling'' a list of services
10640 down to a single directory that contains everything needed to boot and
10641 run the system---the directory shown by the @command{guix system build}
10642 command (@pxref{Invoking guix system}). In essence, it propagates
10643 service extensions down the service graph, updating each node parameters
10644 on the way, until it reaches the root node.
10645
10646 @deffn {Scheme Procedure} fold-services @var{services} @
10647 [#:target-type @var{system-service-type}]
10648 Fold @var{services} by propagating their extensions down to the root of
10649 type @var{target-type}; return the root service adjusted accordingly.
10650 @end deffn
10651
10652 Lastly, the @code{(gnu services)} module also defines several essential
10653 service types, some of which are listed below.
10654
10655 @defvr {Scheme Variable} system-service-type
10656 This is the root of the service graph. It produces the system directory
10657 as returned by the @command{guix system build} command.
10658 @end defvr
10659
10660 @defvr {Scheme Variable} boot-service-type
10661 The type of the ``boot service'', which produces the @dfn{boot script}.
10662 The boot script is what the initial RAM disk runs when booting.
10663 @end defvr
10664
10665 @defvr {Scheme Variable} etc-service-type
10666 The type of the @file{/etc} service. This service can be extended by
10667 passing it name/file tuples such as:
10668
10669 @example
10670 (list `("issue" ,(plain-file "issue" "Welcome!\n")))
10671 @end example
10672
10673 In this example, the effect would be to add an @file{/etc/issue} file
10674 pointing to the given file.
10675 @end defvr
10676
10677 @defvr {Scheme Variable} setuid-program-service-type
10678 Type for the ``setuid-program service''. This service collects lists of
10679 executable file names, passed as gexps, and adds them to the set of
10680 setuid-root programs on the system (@pxref{Setuid Programs}).
10681 @end defvr
10682
10683 @defvr {Scheme Variable} profile-service-type
10684 Type of the service that populates the @dfn{system profile}---i.e., the
10685 programs under @file{/run/current-system/profile}. Other services can
10686 extend it by passing it lists of packages to add to the system profile.
10687 @end defvr
10688
10689
10690 @node Shepherd Services
10691 @subsubsection Shepherd Services
10692
10693 @cindex PID 1
10694 @cindex init system
10695 The @code{(gnu services shepherd)} module provides a way to define
10696 services managed by the GNU@tie{}Shepherd, which is the GuixSD
10697 initialization system---the first process that is started when the
10698 system boots, also known as PID@tie{}1
10699 (@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
10700
10701 Services in the Shepherd can depend on each other. For instance, the
10702 SSH daemon may need to be started after the syslog daemon has been
10703 started, which in turn can only happen once all the file systems have
10704 been mounted. The simple operating system defined earlier (@pxref{Using
10705 the Configuration System}) results in a service graph like this:
10706
10707 @image{images/shepherd-graph,,5in,Typical shepherd service graph.}
10708
10709 You can actually generate such a graph for any operating system
10710 definition using the @command{guix system shepherd-graph} command
10711 (@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
10712
10713 The @var{%shepherd-root-service} is a service object representing
10714 PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10715 by passing it lists of @code{<shepherd-service>} objects.
10716
10717 @deftp {Data Type} shepherd-service
10718 The data type representing a service managed by the Shepherd.
10719
10720 @table @asis
10721 @item @code{provision}
10722 This is a list of symbols denoting what the service provides.
10723
10724 These are the names that may be passed to @command{herd start},
10725 @command{herd status}, and similar commands (@pxref{Invoking herd,,,
10726 shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10727 @code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
10728
10729 @item @code{requirements} (default: @code{'()})
10730 List of symbols denoting the Shepherd services this one depends on.
10731
10732 @item @code{respawn?} (default: @code{#t})
10733 Whether to restart the service when it stops, for instance when the
10734 underlying process dies.
10735
10736 @item @code{start}
10737 @itemx @code{stop} (default: @code{#~(const #f)})
10738 The @code{start} and @code{stop} fields refer to the Shepherd's
10739 facilities to start and stop processes (@pxref{Service De- and
10740 Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10741 G-expressions that get expanded in the Shepherd configuration file
10742 (@pxref{G-Expressions}).
10743
10744 @item @code{documentation}
10745 A documentation string, as shown when running:
10746
10747 @example
10748 herd doc @var{service-name}
10749 @end example
10750
10751 where @var{service-name} is one of the symbols in @var{provision}
10752 (@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
10753
10754 @item @code{modules} (default: @var{%default-modules})
10755 This is the list of modules that must be in scope when @code{start} and
10756 @code{stop} are evaluated.
10757
10758 @item @code{imported-modules} (default: @var{%default-imported-modules})
10759 This is the list of modules to import in the execution environment of
10760 the Shepherd.
10761
10762 @end table
10763 @end deftp
10764
10765 @defvr {Scheme Variable} shepherd-root-service-type
10766 The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
10767
10768 This is the service type that extensions target when they want to create
10769 shepherd services (@pxref{Service Types and Services}, for an example).
10770 Each extension must pass a list of @code{<shepherd-service>}.
10771 @end defvr
10772
10773 @defvr {Scheme Variable} %shepherd-root-service
10774 This service represents PID@tie{}1.
10775 @end defvr
10776
10777
10778 @node Installing Debugging Files
10779 @section Installing Debugging Files
10780
10781 @cindex debugging files
10782 Program binaries, as produced by the GCC compilers for instance, are
10783 typically written in the ELF format, with a section containing
10784 @dfn{debugging information}. Debugging information is what allows the
10785 debugger, GDB, to map binary code to source code; it is required to
10786 debug a compiled program in good conditions.
10787
10788 The problem with debugging information is that is takes up a fair amount
10789 of disk space. For example, debugging information for the GNU C Library
10790 weighs in at more than 60 MiB. Thus, as a user, keeping all the
10791 debugging info of all the installed programs is usually not an option.
10792 Yet, space savings should not come at the cost of an impediment to
10793 debugging---especially in the GNU system, which should make it easier
10794 for users to exert their computing freedom (@pxref{GNU Distribution}).
10795
10796 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
10797 mechanism that allows users to get the best of both worlds: debugging
10798 information can be stripped from the binaries and stored in separate
10799 files. GDB is then able to load debugging information from those files,
10800 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
10801 with GDB}).
10802
10803 The GNU distribution takes advantage of this by storing debugging
10804 information in the @code{lib/debug} sub-directory of a separate package
10805 output unimaginatively called @code{debug} (@pxref{Packages with
10806 Multiple Outputs}). Users can choose to install the @code{debug} output
10807 of a package when they need it. For instance, the following command
10808 installs the debugging information for the GNU C Library and for GNU
10809 Guile:
10810
10811 @example
10812 guix package -i glibc:debug guile:debug
10813 @end example
10814
10815 GDB must then be told to look for debug files in the user's profile, by
10816 setting the @code{debug-file-directory} variable (consider setting it
10817 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
10818 GDB}):
10819
10820 @example
10821 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
10822 @end example
10823
10824 From there on, GDB will pick up debugging information from the
10825 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
10826
10827 In addition, you will most likely want GDB to be able to show the source
10828 code being debugged. To do that, you will have to unpack the source
10829 code of the package of interest (obtained with @code{guix build
10830 --source}, @pxref{Invoking guix build}), and to point GDB to that source
10831 directory using the @code{directory} command (@pxref{Source Path,
10832 @code{directory},, gdb, Debugging with GDB}).
10833
10834 @c XXX: keep me up-to-date
10835 The @code{debug} output mechanism in Guix is implemented by the
10836 @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
10837 opt-in---debugging information is available only for the packages
10838 with definitions explicitly declaring a @code{debug} output. This may be
10839 changed to opt-out in the future if our build farm servers can handle
10840 the load. To check whether a package has a @code{debug} output, use
10841 @command{guix package --list-available} (@pxref{Invoking guix package}).
10842
10843
10844 @node Security Updates
10845 @section Security Updates
10846
10847 @cindex security updates
10848 @cindex security vulnerabilities
10849 Occasionally, important security vulnerabilities are discovered in software
10850 packages and must be patched. Guix developers try hard to keep track of
10851 known vulnerabilities and to apply fixes as soon as possible in the
10852 @code{master} branch of Guix (we do not yet provide a ``stable'' branch
10853 containing only security updates.) The @command{guix lint} tool helps
10854 developers find out about vulnerable versions of software packages in the
10855 distribution:
10856
10857 @smallexample
10858 $ guix lint -c cve
10859 gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
10860 gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
10861 gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
10862 @dots{}
10863 @end smallexample
10864
10865 @xref{Invoking guix lint}, for more information.
10866
10867 @quotation Note
10868 As of version @value{VERSION}, the feature described below is considered
10869 ``beta''.
10870 @end quotation
10871
10872 Guix follows a functional
10873 package management discipline (@pxref{Introduction}), which implies
10874 that, when a package is changed, @emph{every package that depends on it}
10875 must be rebuilt. This can significantly slow down the deployment of
10876 fixes in core packages such as libc or Bash, since basically the whole
10877 distribution would need to be rebuilt. Using pre-built binaries helps
10878 (@pxref{Substitutes}), but deployment may still take more time than
10879 desired.
10880
10881 @cindex grafts
10882 To address this, Guix implements @dfn{grafts}, a mechanism that allows
10883 for fast deployment of critical updates without the costs associated
10884 with a whole-distribution rebuild. The idea is to rebuild only the
10885 package that needs to be patched, and then to ``graft'' it onto packages
10886 explicitly installed by the user and that were previously referring to
10887 the original package. The cost of grafting is typically very low, and
10888 order of magnitudes lower than a full rebuild of the dependency chain.
10889
10890 @cindex replacements of packages, for grafts
10891 For instance, suppose a security update needs to be applied to Bash.
10892 Guix developers will provide a package definition for the ``fixed''
10893 Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
10894 Packages}). Then, the original package definition is augmented with a
10895 @code{replacement} field pointing to the package containing the bug fix:
10896
10897 @example
10898 (define bash
10899 (package
10900 (name "bash")
10901 ;; @dots{}
10902 (replacement bash-fixed)))
10903 @end example
10904
10905 From there on, any package depending directly or indirectly on Bash---as
10906 reported by @command{guix gc --requisites} (@pxref{Invoking guix
10907 gc})---that is installed is automatically ``rewritten'' to refer to
10908 @var{bash-fixed} instead of @var{bash}. This grafting process takes
10909 time proportional to the size of the package, usually less than a
10910 minute for an ``average'' package on a recent machine. Grafting is
10911 recursive: when an indirect dependency requires grafting, then grafting
10912 ``propagates'' up to the package that the user is installing.
10913
10914 Currently, the graft and the package it replaces (@var{bash-fixed} and
10915 @var{bash} in the example above) must have the exact same @code{name}
10916 and @code{version} fields. This restriction mostly comes from the fact
10917 that grafting works by patching files, including binary files, directly.
10918 Other restrictions may apply: for instance, when adding a graft to a
10919 package providing a shared library, the original shared library and its
10920 replacement must have the same @code{SONAME} and be binary-compatible.
10921
10922 The @option{--no-grafts} command-line option allows you to forcefully
10923 avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
10924 Thus, the command:
10925
10926 @example
10927 guix build bash --no-grafts
10928 @end example
10929
10930 @noindent
10931 returns the store file name of the original Bash, whereas:
10932
10933 @example
10934 guix build bash
10935 @end example
10936
10937 @noindent
10938 returns the store file name of the ``fixed'', replacement Bash. This
10939 allows you to distinguish between the two variants of Bash.
10940
10941 To verify which Bash your whole profile refers to, you can run
10942 (@pxref{Invoking guix gc}):
10943
10944 @example
10945 guix gc -R `readlink -f ~/.guix-profile` | grep bash
10946 @end example
10947
10948 @noindent
10949 @dots{} and compare the store file names that you get with those above.
10950 Likewise for a complete GuixSD system generation:
10951
10952 @example
10953 guix gc -R `guix system build my-config.scm` | grep bash
10954 @end example
10955
10956 Lastly, to check which Bash running processes are using, you can use the
10957 @command{lsof} command:
10958
10959 @example
10960 lsof | grep /gnu/store/.*bash
10961 @end example
10962
10963
10964 @node Package Modules
10965 @section Package Modules
10966
10967 From a programming viewpoint, the package definitions of the
10968 GNU distribution are provided by Guile modules in the @code{(gnu packages
10969 @dots{})} name space@footnote{Note that packages under the @code{(gnu
10970 packages @dots{})} module name space are not necessarily ``GNU
10971 packages''. This module naming scheme follows the usual Guile module
10972 naming convention: @code{gnu} means that these modules are distributed
10973 as part of the GNU system, and @code{packages} identifies modules that
10974 define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
10975 Reference Manual}). For instance, the @code{(gnu packages emacs)}
10976 module exports a variable named @code{emacs}, which is bound to a
10977 @code{<package>} object (@pxref{Defining Packages}).
10978
10979 The @code{(gnu packages @dots{})} module name space is
10980 automatically scanned for packages by the command-line tools. For
10981 instance, when running @code{guix package -i emacs}, all the @code{(gnu
10982 packages @dots{})} modules are scanned until one that exports a package
10983 object whose name is @code{emacs} is found. This package search
10984 facility is implemented in the @code{(gnu packages)} module.
10985
10986 @cindex customization, of packages
10987 @cindex package module search path
10988 Users can store package definitions in modules with different
10989 names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
10990 name and module name must match. For instance, the @code{(my-packages
10991 emacs)} module must be stored in a @file{my-packages/emacs.scm} file
10992 relative to the load path specified with @option{--load-path} or
10993 @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
10994 guile, GNU Guile Reference Manual}, for details.}. These package definitions
10995 will not be visible by default. Users can invoke commands such as
10996 @command{guix package} and @command{guix build} with the
10997 @code{-e} option so that they know where to find the package. Better
10998 yet, they can use the
10999 @code{-L} option of these commands to make those modules visible
11000 (@pxref{Invoking guix build, @code{--load-path}}), or define the
11001 @code{GUIX_PACKAGE_PATH} environment variable. This environment
11002 variable makes it easy to extend or customize the distribution and is
11003 honored by all the user interfaces.
11004
11005 @defvr {Environment Variable} GUIX_PACKAGE_PATH
11006 This is a colon-separated list of directories to search for additional
11007 package modules. Directories listed in this variable take precedence
11008 over the own modules of the distribution.
11009 @end defvr
11010
11011 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
11012 each package is built based solely on other packages in the
11013 distribution. The root of this dependency graph is a small set of
11014 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
11015 bootstrap)} module. For more information on bootstrapping,
11016 @pxref{Bootstrapping}.
11017
11018 @node Packaging Guidelines
11019 @section Packaging Guidelines
11020
11021 The GNU distribution is nascent and may well lack some of your favorite
11022 packages. This section describes how you can help make the distribution
11023 grow. @xref{Contributing}, for additional information on how you can
11024 help.
11025
11026 Free software packages are usually distributed in the form of
11027 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
11028 all the source files. Adding a package to the distribution means
11029 essentially two things: adding a @dfn{recipe} that describes how to
11030 build the package, including a list of other packages required to build
11031 it, and adding @dfn{package metadata} along with that recipe, such as a
11032 description and licensing information.
11033
11034 In Guix all this information is embodied in @dfn{package definitions}.
11035 Package definitions provide a high-level view of the package. They are
11036 written using the syntax of the Scheme programming language; in fact,
11037 for each package we define a variable bound to the package definition,
11038 and export that variable from a module (@pxref{Package Modules}).
11039 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
11040 creating packages. For more information on package definitions,
11041 @pxref{Defining Packages}.
11042
11043 Once a package definition is in place, stored in a file in the Guix
11044 source tree, it can be tested using the @command{guix build} command
11045 (@pxref{Invoking guix build}). For example, assuming the new package is
11046 called @code{gnew}, you may run this command from the Guix build tree
11047 (@pxref{Running Guix Before It Is Installed}):
11048
11049 @example
11050 ./pre-inst-env guix build gnew --keep-failed
11051 @end example
11052
11053 Using @code{--keep-failed} makes it easier to debug build failures since
11054 it provides access to the failed build tree. Another useful
11055 command-line option when debugging is @code{--log-file}, to access the
11056 build log.
11057
11058 If the package is unknown to the @command{guix} command, it may be that
11059 the source file contains a syntax error, or lacks a @code{define-public}
11060 clause to export the package variable. To figure it out, you may load
11061 the module from Guile to get more information about the actual error:
11062
11063 @example
11064 ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
11065 @end example
11066
11067 Once your package builds correctly, please send us a patch
11068 (@pxref{Contributing}). Well, if you need help, we will be happy to
11069 help you too. Once the patch is committed in the Guix repository, the
11070 new package automatically gets built on the supported platforms by
11071 @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
11072 system}.
11073
11074 @cindex substituter
11075 Users can obtain the new package definition simply by running
11076 @command{guix pull} (@pxref{Invoking guix pull}). When
11077 @code{hydra.gnu.org} is done building the package, installing the
11078 package automatically downloads binaries from there
11079 (@pxref{Substitutes}). The only place where human intervention is
11080 needed is to review and apply the patch.
11081
11082
11083 @menu
11084 * Software Freedom:: What may go into the distribution.
11085 * Package Naming:: What's in a name?
11086 * Version Numbers:: When the name is not enough.
11087 * Synopses and Descriptions:: Helping users find the right package.
11088 * Python Modules:: Taming the snake.
11089 * Perl Modules:: Little pearls.
11090 * Java Packages:: Coffee break.
11091 * Fonts:: Fond of fonts.
11092 @end menu
11093
11094 @node Software Freedom
11095 @subsection Software Freedom
11096
11097 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
11098
11099 The GNU operating system has been developed so that users can have
11100 freedom in their computing. GNU is @dfn{free software}, meaning that
11101 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
11102 essential freedoms}: to run the program, to study and change the program
11103 in source code form, to redistribute exact copies, and to distribute
11104 modified versions. Packages found in the GNU distribution provide only
11105 software that conveys these four freedoms.
11106
11107 In addition, the GNU distribution follow the
11108 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
11109 software distribution guidelines}. Among other things, these guidelines
11110 reject non-free firmware, recommendations of non-free software, and
11111 discuss ways to deal with trademarks and patents.
11112
11113 Some otherwise free upstream package sources contain a small and optional
11114 subset that violates the above guidelines, for instance because this subset
11115 is itself non-free code. When that happens, the offending items are removed
11116 with appropriate patches or code snippets in the @code{origin} form of the
11117 package (@pxref{Defining Packages}). This way, @code{guix
11118 build --source} returns the ``freed'' source rather than the unmodified
11119 upstream source.
11120
11121
11122 @node Package Naming
11123 @subsection Package Naming
11124
11125 A package has actually two names associated with it:
11126 First, there is the name of the @emph{Scheme variable}, the one following
11127 @code{define-public}. By this name, the package can be made known in the
11128 Scheme code, for instance as input to another package. Second, there is
11129 the string in the @code{name} field of a package definition. This name
11130 is used by package management commands such as
11131 @command{guix package} and @command{guix build}.
11132
11133 Both are usually the same and correspond to the lowercase conversion of
11134 the project name chosen upstream, with underscores replaced with
11135 hyphens. For instance, GNUnet is available as @code{gnunet}, and
11136 SDL_net as @code{sdl-net}.
11137
11138 We do not add @code{lib} prefixes for library packages, unless these are
11139 already part of the official project name. But @pxref{Python
11140 Modules} and @ref{Perl Modules} for special rules concerning modules for
11141 the Python and Perl languages.
11142
11143 Font package names are handled differently, @pxref{Fonts}.
11144
11145
11146 @node Version Numbers
11147 @subsection Version Numbers
11148
11149 We usually package only the latest version of a given free software
11150 project. But sometimes, for instance for incompatible library versions,
11151 two (or more) versions of the same package are needed. These require
11152 different Scheme variable names. We use the name as defined
11153 in @ref{Package Naming}
11154 for the most recent version; previous versions use the same name, suffixed
11155 by @code{-} and the smallest prefix of the version number that may
11156 distinguish the two versions.
11157
11158 The name inside the package definition is the same for all versions of a
11159 package and does not contain any version number.
11160
11161 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
11162
11163 @example
11164 (define-public gtk+
11165 (package
11166 (name "gtk+")
11167 (version "3.9.12")
11168 ...))
11169 (define-public gtk+-2
11170 (package
11171 (name "gtk+")
11172 (version "2.24.20")
11173 ...))
11174 @end example
11175 If we also wanted GTK+ 3.8.2, this would be packaged as
11176 @example
11177 (define-public gtk+-3.8
11178 (package
11179 (name "gtk+")
11180 (version "3.8.2")
11181 ...))
11182 @end example
11183
11184 @c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
11185 @c for a discussion of what follows.
11186 @cindex version number, for VCS snapshots
11187 Occasionally, we package snapshots of upstream's version control system
11188 (VCS) instead of formal releases. This should remain exceptional,
11189 because it is up to upstream developers to clarify what the stable
11190 release is. Yet, it is sometimes necessary. So, what should we put in
11191 the @code{version} field?
11192
11193 Clearly, we need to make the commit identifier of the VCS snapshot
11194 visible in the version string, but we also need to make sure that the
11195 version string is monotonically increasing so that @command{guix package
11196 --upgrade} can determine which version is newer. Since commit
11197 identifiers, notably with Git, are not monotonically increasing, we add
11198 a revision number that we increase each time we upgrade to a newer
11199 snapshot. The resulting version string looks like this:
11200
11201 @example
11202 2.0.11-3.cabba9e
11203 ^ ^ ^
11204 | | `-- upstream commit ID
11205 | |
11206 | `--- Guix package revision
11207 |
11208 latest upstream version
11209 @end example
11210
11211 It is a good idea to strip commit identifiers in the @code{version}
11212 field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
11213 aesthetics have a role to play here) as well as problems related to OS
11214 limits such as the maximum shebang length (127 bytes for the Linux
11215 kernel.) It is best to use the full commit identifiers in
11216 @code{origin}s, though, to avoid ambiguities. A typical package
11217 definition may look like this:
11218
11219 @example
11220 (define my-package
11221 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
11222 (package
11223 (version (string-append "0.9-1."
11224 (string-take commit 7)))
11225 (source (origin
11226 (method git-fetch)
11227 (uri (git-reference
11228 (url "git://example.org/my-package.git")
11229 (commit commit)))
11230 (sha256 (base32 "1mbikn@dots{}"))
11231 (file-name (string-append "my-package-" version
11232 "-checkout"))))
11233 ;; @dots{}
11234 )))
11235 @end example
11236
11237 @node Synopses and Descriptions
11238 @subsection Synopses and Descriptions
11239
11240 As we have seen before, each package in GNU@tie{}Guix includes a
11241 synopsis and a description (@pxref{Defining Packages}). Synopses and
11242 descriptions are important: They are what @command{guix package
11243 --search} searches, and a crucial piece of information to help users
11244 determine whether a given package suits their needs. Consequently,
11245 packagers should pay attention to what goes into them.
11246
11247 Synopses must start with a capital letter and must not end with a
11248 period. They must not start with ``a'' or ``the'', which usually does
11249 not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
11250 tool that frobs files''. The synopsis should say what the package
11251 is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
11252 used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
11253 matching a pattern''.
11254
11255 Keep in mind that the synopsis must be meaningful for a very wide
11256 audience. For example, ``Manipulate alignments in the SAM format''
11257 might make sense for a seasoned bioinformatics researcher, but might be
11258 fairly unhelpful or even misleading to a non-specialized audience. It
11259 is a good idea to come up with a synopsis that gives an idea of the
11260 application domain of the package. In this example, this might give
11261 something like ``Manipulate nucleotide sequence alignments'', which
11262 hopefully gives the user a better idea of whether this is what they are
11263 looking for.
11264
11265 Descriptions should take between five and ten lines. Use full
11266 sentences, and avoid using acronyms without first introducing them.
11267 Please avoid marketing phrases such as ``world-leading'',
11268 ``industrial-strength'', and ``next-generation'', and avoid superlatives
11269 like ``the most advanced''---they are not helpful to users looking for a
11270 package and may even sound suspicious. Instead, try to be factual,
11271 mentioning use cases and features.
11272
11273 @cindex Texinfo markup, in package descriptions
11274 Descriptions can include Texinfo markup, which is useful to introduce
11275 ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
11276 hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
11277 should be careful when using some characters for example @samp{@@} and
11278 curly braces which are the basic special characters in Texinfo
11279 (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
11280 such as @command{guix package --show} take care of rendering it
11281 appropriately.
11282
11283 Synopses and descriptions are translated by volunteers
11284 @uref{http://translationproject.org/domain/guix-packages.html, at the
11285 Translation Project} so that as many users as possible can read them in
11286 their native language. User interfaces search them and display them in
11287 the language specified by the current locale.
11288
11289 Translation is a lot of work so, as a packager, please pay even more
11290 attention to your synopses and descriptions as every change may entail
11291 additional work for translators. In order to help them, it is possible
11292 to make recommendations or instructions visible to them by inserting
11293 special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
11294 Gettext}):
11295
11296 @example
11297 ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
11298 (description "ARandR is designed to provide a simple visual front end
11299 for the X11 resize-and-rotate (RandR) extension. @dots{}")
11300 @end example
11301
11302
11303 @node Python Modules
11304 @subsection Python Modules
11305
11306 We currently package Python 2 and Python 3, under the Scheme variable names
11307 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
11308 To avoid confusion and naming clashes with other programming languages, it
11309 seems desirable that the name of a package for a Python module contains
11310 the word @code{python}.
11311
11312 Some modules are compatible with only one version of Python, others with both.
11313 If the package Foo compiles only with Python 3, we name it
11314 @code{python-foo}; if it compiles only with Python 2, we name it
11315 @code{python2-foo}. If it is compatible with both versions, we create two
11316 packages with the corresponding names.
11317
11318 If a project already contains the word @code{python}, we drop this;
11319 for instance, the module python-dateutil is packaged under the names
11320 @code{python-dateutil} and @code{python2-dateutil}. If the project name
11321 starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
11322 described above.
11323
11324
11325 @node Perl Modules
11326 @subsection Perl Modules
11327
11328 Perl programs standing for themselves are named as any other package,
11329 using the lowercase upstream name.
11330 For Perl packages containing a single class, we use the lowercase class name,
11331 replace all occurrences of @code{::} by dashes and prepend the prefix
11332 @code{perl-}.
11333 So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
11334 Modules containing several classes keep their lowercase upstream name and
11335 are also prepended by @code{perl-}. Such modules tend to have the word
11336 @code{perl} somewhere in their name, which gets dropped in favor of the
11337 prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
11338
11339
11340 @node Java Packages
11341 @subsection Java Packages
11342
11343 Java programs standing for themselves are named as any other package,
11344 using the lowercase upstream name.
11345
11346 To avoid confusion and naming clashes with other programming languages,
11347 it is desirable that the name of a package for a Java package is
11348 prefixed with @code{java-}. If a project already contains the word
11349 @code{java}, we drop this; for instance, the package @code{ngsjava} is
11350 packaged under the name @code{java-ngs}.
11351
11352 For Java packages containing a single class or a small class hierarchy,
11353 we use the lowercase class name, replace all occurrences of @code{.} by
11354 dashes and prepend the prefix @code{java-}. So the class
11355 @code{apache.commons.cli} becomes package
11356 @code{java-apache-commons-cli}.
11357
11358
11359 @node Fonts
11360 @subsection Fonts
11361
11362 For fonts that are in general not installed by a user for typesetting
11363 purposes, or that are distributed as part of a larger software package,
11364 we rely on the general packaging rules for software; for instance, this
11365 applies to the fonts delivered as part of the X.Org system or fonts that
11366 are part of TeX Live.
11367
11368 To make it easier for a user to search for fonts, names for other packages
11369 containing only fonts are constructed as follows, independently of the
11370 upstream package name.
11371
11372 The name of a package containing only one font family starts with
11373 @code{font-}; it is followed by the foundry name and a dash @code{-}
11374 if the foundry is known, and the font family name, in which spaces are
11375 replaced by dashes (and as usual, all upper case letters are transformed
11376 to lower case).
11377 For example, the Gentium font family by SIL is packaged under the name
11378 @code{font-sil-gentium}.
11379
11380 For a package containing several font families, the name of the collection
11381 is used in the place of the font family name.
11382 For instance, the Liberation fonts consist of three families,
11383 Liberation Sans, Liberation Serif and Liberation Mono.
11384 These could be packaged separately under the names
11385 @code{font-liberation-sans} and so on; but as they are distributed together
11386 under a common name, we prefer to package them together as
11387 @code{font-liberation}.
11388
11389 In the case where several formats of the same font family or font collection
11390 are packaged separately, a short form of the format, prepended by a dash,
11391 is added to the package name. We use @code{-ttf} for TrueType fonts,
11392 @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
11393 fonts.
11394
11395
11396
11397 @node Bootstrapping
11398 @section Bootstrapping
11399
11400 @c Adapted from the ELS 2013 paper.
11401
11402 @cindex bootstrapping
11403
11404 Bootstrapping in our context refers to how the distribution gets built
11405 ``from nothing''. Remember that the build environment of a derivation
11406 contains nothing but its declared inputs (@pxref{Introduction}). So
11407 there's an obvious chicken-and-egg problem: how does the first package
11408 get built? How does the first compiler get compiled? Note that this is
11409 a question of interest only to the curious hacker, not to the regular
11410 user, so you can shamelessly skip this section if you consider yourself
11411 a ``regular user''.
11412
11413 @cindex bootstrap binaries
11414 The GNU system is primarily made of C code, with libc at its core. The
11415 GNU build system itself assumes the availability of a Bourne shell and
11416 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
11417 `grep'. Furthermore, build programs---programs that run
11418 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
11419 (@pxref{Derivations}). Consequently, to be able to build anything at
11420 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
11421 Binutils, libc, and the other packages mentioned above---the
11422 @dfn{bootstrap binaries}.
11423
11424 These bootstrap binaries are ``taken for granted'', though we can also
11425 re-create them if needed (more on that later).
11426
11427 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
11428
11429 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
11430 @c large image, it's hard to scroll. Oh well.
11431 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
11432
11433 The figure above shows the very beginning of the dependency graph of the
11434 distribution, corresponding to the package definitions of the @code{(gnu
11435 packages bootstrap)} module. A similar figure can be generated with
11436 @command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
11437
11438 @example
11439 guix graph -t derivation \
11440 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
11441 | dot -Tps > t.ps
11442 @end example
11443
11444 At this level of detail, things are
11445 slightly complex. First, Guile itself consists of an ELF executable,
11446 along with many source and compiled Scheme files that are dynamically
11447 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
11448 tarball shown in this graph. This tarball is part of Guix's ``source''
11449 distribution, and gets inserted into the store with @code{add-to-store}
11450 (@pxref{The Store}).
11451
11452 But how do we write a derivation that unpacks this tarball and adds it
11453 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
11454 derivation---the first one that gets built---uses @code{bash} as its
11455 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
11456 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
11457 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
11458 the Guix source distribution, whose sole purpose is to allow the Guile
11459 tarball to be unpacked.
11460
11461 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
11462 Guile that can be used to run subsequent build programs. Its first task
11463 is to download tarballs containing the other pre-built binaries---this
11464 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
11465 @code{ftp-client.scm} are used for this purpose. The
11466 @code{module-import.drv} derivations import those modules in a directory
11467 in the store, using the original layout. The
11468 @code{module-import-compiled.drv} derivations compile those modules, and
11469 write them in an output directory with the right layout. This
11470 corresponds to the @code{#:modules} argument of
11471 @code{build-expression->derivation} (@pxref{Derivations}).
11472
11473 Finally, the various tarballs are unpacked by the
11474 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
11475 etc., at which point we have a working C tool chain.
11476
11477
11478 @unnumberedsubsec Building the Build Tools
11479
11480 Bootstrapping is complete when we have a full tool chain that does not
11481 depend on the pre-built bootstrap tools discussed above. This
11482 no-dependency requirement is verified by checking whether the files of
11483 the final tool chain contain references to the @file{/gnu/store}
11484 directories of the bootstrap inputs. The process that leads to this
11485 ``final'' tool chain is described by the package definitions found in
11486 the @code{(gnu packages commencement)} module.
11487
11488 The @command{guix graph} command allows us to ``zoom out'' compared to
11489 the graph above, by looking at the level of package objects instead of
11490 individual derivations---remember that a package may translate to
11491 several derivations, typically one derivation to download its source,
11492 one to build the Guile modules it needs, and one to actually build the
11493 package from source. The command:
11494
11495 @example
11496 guix graph -t bag \
11497 -e '(@@@@ (gnu packages commencement)
11498 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
11499 @end example
11500
11501 @noindent
11502 produces the dependency graph leading to the ``final'' C
11503 library@footnote{You may notice the @code{glibc-intermediate} label,
11504 suggesting that it is not @emph{quite} final, but as a good
11505 approximation, we will consider it final.}, depicted below.
11506
11507 @image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
11508
11509 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
11510 The first tool that gets built with the bootstrap binaries is
11511 GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
11512 for all the following packages. From there Findutils and Diffutils get
11513 built.
11514
11515 Then come the first-stage Binutils and GCC, built as pseudo cross
11516 tools---i.e., with @code{--target} equal to @code{--host}. They are
11517 used to build libc. Thanks to this cross-build trick, this libc is
11518 guaranteed not to hold any reference to the initial tool chain.
11519
11520 From there the final Binutils and GCC (not shown above) are built.
11521 GCC uses @code{ld}
11522 from the final Binutils, and links programs against the just-built libc.
11523 This tool chain is used to build the other packages used by Guix and by
11524 the GNU Build System: Guile, Bash, Coreutils, etc.
11525
11526 And voilà! At this point we have the complete set of build tools that
11527 the GNU Build System expects. These are in the @code{%final-inputs}
11528 variable of the @code{(gnu packages commencement)} module, and are
11529 implicitly used by any package that uses @code{gnu-build-system}
11530 (@pxref{Build Systems, @code{gnu-build-system}}).
11531
11532
11533 @unnumberedsubsec Building the Bootstrap Binaries
11534
11535 Because the final tool chain does not depend on the bootstrap binaries,
11536 those rarely need to be updated. Nevertheless, it is useful to have an
11537 automated way to produce them, should an update occur, and this is what
11538 the @code{(gnu packages make-bootstrap)} module provides.
11539
11540 The following command builds the tarballs containing the bootstrap
11541 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
11542 of Coreutils and other basic command-line tools):
11543
11544 @example
11545 guix build bootstrap-tarballs
11546 @end example
11547
11548 The generated tarballs are those that should be referred to in the
11549 @code{(gnu packages bootstrap)} module mentioned at the beginning of
11550 this section.
11551
11552 Still here? Then perhaps by now you've started to wonder: when do we
11553 reach a fixed point? That is an interesting question! The answer is
11554 unknown, but if you would like to investigate further (and have
11555 significant computational and storage resources to do so), then let us
11556 know.
11557
11558 @node Porting
11559 @section Porting to a New Platform
11560
11561 As discussed above, the GNU distribution is self-contained, and
11562 self-containment is achieved by relying on pre-built ``bootstrap
11563 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
11564 operating system kernel, CPU architecture, and application binary
11565 interface (ABI). Thus, to port the distribution to a platform that is
11566 not yet supported, one must build those bootstrap binaries, and update
11567 the @code{(gnu packages bootstrap)} module to use them on that platform.
11568
11569 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
11570 When everything goes well, and assuming the GNU tool chain supports the
11571 target platform, this can be as simple as running a command like this
11572 one:
11573
11574 @example
11575 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
11576 @end example
11577
11578 For this to work, the @code{glibc-dynamic-linker} procedure in
11579 @code{(gnu packages bootstrap)} must be augmented to return the right
11580 file name for libc's dynamic linker on that platform; likewise,
11581 @code{system->linux-architecture} in @code{(gnu packages linux)} must be
11582 taught about the new platform.
11583
11584 Once these are built, the @code{(gnu packages bootstrap)} module needs
11585 to be updated to refer to these binaries on the target platform. That
11586 is, the hashes and URLs of the bootstrap tarballs for the new platform
11587 must be added alongside those of the currently supported platforms. The
11588 bootstrap Guile tarball is treated specially: it is expected to be
11589 available locally, and @file{gnu/local.mk} has rules do download it for
11590 the supported architectures; a rule for the new platform must be added
11591 as well.
11592
11593 In practice, there may be some complications. First, it may be that the
11594 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
11595 above) is not recognized by all the GNU tools. Typically, glibc
11596 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
11597 configure flag (see @code{gcc.scm} for examples of how to handle this).
11598 Second, some of the required packages could fail to build for that
11599 platform. Lastly, the generated binaries could be broken for some
11600 reason.
11601
11602 @c *********************************************************************
11603 @include contributing.texi
11604
11605 @c *********************************************************************
11606 @node Acknowledgments
11607 @chapter Acknowledgments
11608
11609 Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
11610 which was designed and
11611 implemented by Eelco Dolstra, with contributions from other people (see
11612 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
11613 management, and promoted unprecedented features, such as transactional
11614 package upgrades and rollbacks, per-user profiles, and referentially
11615 transparent build processes. Without this work, Guix would not exist.
11616
11617 The Nix-based software distributions, Nixpkgs and NixOS, have also been
11618 an inspiration for Guix.
11619
11620 GNU@tie{}Guix itself is a collective work with contributions from a
11621 number of people. See the @file{AUTHORS} file in Guix for more
11622 information on these fine people. The @file{THANKS} file lists people
11623 who have helped by reporting bugs, taking care of the infrastructure,
11624 providing artwork and themes, making suggestions, and more---thank you!
11625
11626
11627 @c *********************************************************************
11628 @node GNU Free Documentation License
11629 @appendix GNU Free Documentation License
11630
11631 @include fdl-1.3.texi
11632
11633 @c *********************************************************************
11634 @node Concept Index
11635 @unnumbered Concept Index
11636 @printindex cp
11637
11638 @node Programming Index
11639 @unnumbered Programming Index
11640 @syncodeindex tp fn
11641 @syncodeindex vr fn
11642 @printindex fn
11643
11644 @bye
11645
11646 @c Local Variables:
11647 @c ispell-local-dictionary: "american";
11648 @c End: