refresh: Add '--expression'.
[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 Ludovic Courtès@*
14 Copyright @copyright{} 2013, 2014 Andreas Enge@*
15 Copyright @copyright{} 2013 Nikita Karetnikov@*
16 Copyright @copyright{} 2015 Mathieu Lirzin@*
17 Copyright @copyright{} 2014 Pierre-Antoine Rault@*
18 Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer
19
20 Permission is granted to copy, distribute and/or modify this document
21 under the terms of the GNU Free Documentation License, Version 1.3 or
22 any later version published by the Free Software Foundation; with no
23 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
24 copy of the license is included in the section entitled ``GNU Free
25 Documentation License''.
26 @end copying
27
28 @dircategory Package management
29 @direntry
30 * guix: (guix). Guix, the functional package manager.
31 * guix package: (guix)Invoking guix package
32 Managing packages with Guix.
33 * guix build: (guix)Invoking guix build
34 Building packages with Guix.
35 * guix system: (guix)Invoking guix system
36 Managing the operating system configuration.
37 @end direntry
38
39 @dircategory Software development
40 @direntry
41 * guix environment: (guix)Invoking guix environment
42 Building development environments with Guix.
43 @end direntry
44
45 @titlepage
46 @title GNU Guix Reference Manual
47 @subtitle Using the GNU Guix Functional Package Manager
48 @author The GNU Guix Developers
49
50 @page
51 @vskip 0pt plus 1filll
52 Edition @value{EDITION} @*
53 @value{UPDATED} @*
54
55 @insertcopying
56 @end titlepage
57
58 @contents
59
60 @c *********************************************************************
61 @node Top
62 @top GNU Guix
63
64 This document describes GNU Guix version @value{VERSION}, a functional
65 package management tool written for the GNU system.
66
67 @menu
68 * Introduction:: What is Guix about?
69 * Installation:: Installing Guix.
70 * Package Management:: Package installation, upgrade, etc.
71 * Emacs Interface:: Using Guix from Emacs.
72 * Programming Interface:: Using Guix in Scheme.
73 * Utilities:: Package management commands.
74 * GNU Distribution:: Software for your friendly GNU system.
75 * Contributing:: Your help needed!
76
77 * Acknowledgments:: Thanks!
78 * GNU Free Documentation License:: The license of this manual.
79 * Concept Index:: Concepts.
80 * Programming Index:: Data types, functions, and variables.
81
82 @detailmenu
83 --- The Detailed Node Listing ---
84
85 Installation
86
87 * Binary Installation:: Getting Guix running in no time!
88 * Requirements:: Software needed to build and run Guix.
89 * Running the Test Suite:: Testing Guix.
90 * Setting Up the Daemon:: Preparing the build daemon's environment.
91 * Invoking guix-daemon:: Running the build daemon.
92 * Application Setup:: Application-specific setup.
93
94 Setting Up the Daemon
95
96 * Build Environment Setup:: Preparing the isolated build environment.
97 * Daemon Offload Setup:: Offloading builds to remote machines.
98
99 Package Management
100
101 * Features:: How Guix will make your life brighter.
102 * Invoking guix package:: Package installation, removal, etc.
103 * Substitutes:: Downloading pre-built binaries.
104 * Packages with Multiple Outputs:: Single source package, multiple outputs.
105 * Invoking guix gc:: Running the garbage collector.
106 * Invoking guix pull:: Fetching the latest Guix and distribution.
107 * Invoking guix archive:: Exporting and importing store files.
108
109 Emacs Interface
110
111 * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
112 * Package Management: Emacs Package Management. Managing packages and generations.
113 * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
114 * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
115 * Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
116 * Completions: Emacs Completions. Completing @command{guix} shell command.
117 * Development: Emacs Development. Tools for Guix developers.
118
119 Programming Interface
120
121 * Defining Packages:: Defining new packages.
122 * Build Systems:: Specifying how packages are built.
123 * The Store:: Manipulating the package store.
124 * Derivations:: Low-level interface to package derivations.
125 * The Store Monad:: Purely functional interface to the store.
126 * G-Expressions:: Manipulating build expressions.
127
128 Defining Packages
129
130 * package Reference:: The package data type.
131 * origin Reference:: The origin data type.
132
133 Utilities
134
135 * Invoking guix build:: Building packages from the command line.
136 * Invoking guix edit:: Editing package definitions.
137 * Invoking guix download:: Downloading a file and printing its hash.
138 * Invoking guix hash:: Computing the cryptographic hash of a file.
139 * Invoking guix import:: Importing package definitions.
140 * Invoking guix refresh:: Updating package definitions.
141 * Invoking guix lint:: Finding errors in package definitions.
142 * Invoking guix size:: Profiling disk usage.
143 * Invoking guix graph:: Visualizing the graph of packages.
144 * Invoking guix environment:: Setting up development environments.
145 * Invoking guix publish:: Sharing substitutes.
146 * Invoking guix challenge:: Challenging substitute servers.
147 * Invoking guix container:: Process isolation.
148
149 GNU Distribution
150
151 * System Installation:: Installing the whole operating system.
152 * System Configuration:: Configuring the operating system.
153 * Installing Debugging Files:: Feeding the debugger.
154 * Security Updates:: Deploying security fixes quickly.
155 * Package Modules:: Packages from the programmer's viewpoint.
156 * Packaging Guidelines:: Growing the distribution.
157 * Bootstrapping:: GNU/Linux built from scratch.
158 * Porting:: Targeting another platform or kernel.
159
160 System Configuration
161
162 * Using the Configuration System:: Customizing your GNU system.
163 * operating-system Reference:: Detail of operating-system declarations.
164 * File Systems:: Configuring file system mounts.
165 * Mapped Devices:: Block device extra processing.
166 * User Accounts:: Specifying user accounts.
167 * Locales:: Language and cultural convention settings.
168 * Services:: Specifying system services.
169 * Setuid Programs:: Programs running with root privileges.
170 * X.509 Certificates:: Authenticating HTTPS servers.
171 * Name Service Switch:: Configuring libc's name service switch.
172 * Initial RAM Disk:: Linux-Libre bootstrapping.
173 * GRUB Configuration:: Configuring the boot loader.
174 * Invoking guix system:: Instantiating a system configuration.
175 * Defining Services:: Adding new service definitions.
176
177 Services
178
179 * Base Services:: Essential system services.
180 * Networking Services:: Network setup, SSH daemon, etc.
181 * X Window:: Graphical display.
182 * Desktop Services:: D-Bus and desktop services.
183 * Database Services:: SQL databases.
184 * Web Services:: Web servers.
185 * Various Services:: Other services.
186
187 Defining Services
188
189 * Service Composition:: The model for composing services.
190 * Service Types and Services:: Types and services.
191 * Service Reference:: API reference.
192 * dmd Services:: A particular type of service.
193
194 Packaging Guidelines
195
196 * Software Freedom:: What may go into the distribution.
197 * Package Naming:: What's in a name?
198 * Version Numbers:: When the name is not enough.
199 * Synopses and Descriptions:: Helping users find the right package.
200 * Python Modules:: Taming the snake.
201 * Perl Modules:: Little pearls.
202 * Fonts:: Fond of fonts.
203
204 Contributing
205
206 * Building from Git:: The latest and greatest.
207 * Running Guix Before It Is Installed:: Hacker tricks.
208 * The Perfect Setup:: The right tools.
209 * Coding Style:: Hygiene of the contributor.
210 * Submitting Patches:: Share your work.
211
212 Coding Style
213
214 * Programming Paradigm:: How to compose your elements.
215 * Modules:: Where to store your code?
216 * Data Types and Pattern Matching:: Implementing data structures.
217 * Formatting Code:: Writing conventions.
218
219 @end detailmenu
220 @end menu
221
222 @c *********************************************************************
223 @node Introduction
224 @chapter Introduction
225
226 GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
227 using the international phonetic alphabet (IPA).} is a functional
228 package management tool for the GNU system. Package management consists
229 of all activities that relate to building packages from sources,
230 honoring their build-time and run-time dependencies,
231 installing packages in user environments, upgrading installed packages
232 to new versions or rolling back to a previous set, removing unused
233 software packages, etc.
234
235 @cindex functional package management
236 The term @dfn{functional} refers to a specific package management
237 discipline pioneered by Nix (@pxref{Acknowledgments}).
238 In Guix, the package build and installation process is seen
239 as a function, in the mathematical sense. That function takes inputs,
240 such as build scripts, a compiler, and libraries, and
241 returns an installed package. As a pure function, its result depends
242 solely on its inputs---for instance, it cannot refer to software or
243 scripts that were not explicitly passed as inputs. A build function
244 always produces the same result when passed a given set of inputs. It
245 cannot alter the system's environment in
246 any way; for instance, it cannot create, modify, or delete files outside
247 of its build and installation directories. This is achieved by running
248 build processes in isolated environments (or @dfn{containers}), where only their
249 explicit inputs are visible.
250
251 @cindex store
252 The result of package build functions is @dfn{cached} in the file
253 system, in a special directory called @dfn{the store} (@pxref{The
254 Store}). Each package is installed in a directory of its own, in the
255 store---by default under @file{/gnu/store}. The directory name contains
256 a hash of all the inputs used to build that package; thus, changing an
257 input yields a different directory name.
258
259 This approach is the foundation of Guix's salient features: support for
260 transactional package upgrade and rollback, per-user installation, and
261 garbage collection of packages (@pxref{Features}).
262
263 Guix has a command-line interface, which allows users to build, install,
264 upgrade, and remove packages, as well as a Scheme programming interface.
265
266 @cindex Guix System Distribution
267 @cindex GuixSD
268 Last but not least, Guix is used to build a distribution of the GNU
269 system, with many GNU and non-GNU free software packages. The Guix
270 System Distribution, or GNU@tie{}GuixSD, takes advantage of the core
271 properties of Guix at the system level. With GuixSD, users
272 @emph{declare} all aspects of the operating system configuration, and
273 Guix takes care of instantiating that configuration in a reproducible,
274 stateless fashion. @xref{GNU Distribution}.
275
276 @c *********************************************************************
277 @node Installation
278 @chapter Installation
279
280 GNU Guix is available for download from its website at
281 @url{http://www.gnu.org/software/guix/}. This section describes the
282 software requirements of Guix, as well as how to install it and get
283 ready to use it.
284
285 Note that this section is concerned with the installation of the package
286 manager, which can be done on top of a running GNU/Linux system. If,
287 instead, you want to install the complete GNU operating system,
288 @pxref{System Installation}.
289
290 @menu
291 * Binary Installation:: Getting Guix running in no time!
292 * Requirements:: Software needed to build and run Guix.
293 * Running the Test Suite:: Testing Guix.
294 * Setting Up the Daemon:: Preparing the build daemon's environment.
295 * Invoking guix-daemon:: Running the build daemon.
296 * Application Setup:: Application-specific setup.
297 @end menu
298
299 @node Binary Installation
300 @section Binary Installation
301
302 This section describes how to install Guix on an arbitrary system from a
303 self-contained tarball providing binaries for Guix and for all its
304 dependencies. This is often quicker than installing from source, which
305 is described in the next sections. The only requirement is to have
306 GNU@tie{}tar and Xz.
307
308 Installing goes along these lines:
309
310 @enumerate
311 @item
312 Download the binary tarball from
313 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz}@footnote{As
314 usual, make sure to download the associated @file{.sig} file and to
315 verify the authenticity of the tarball against it!}, where @var{system}
316 is @code{x86_64-linux} for an @code{x86_64} machine already running the
317 kernel Linux, and so on.
318
319 @item
320 As @code{root}, run:
321
322 @example
323 # cd /tmp
324 # tar --warning=no-timestamp -xf \
325 guix-binary-@value{VERSION}.@var{system}.tar.xz
326 # mv var/guix /var/ && mv gnu /
327 @end example
328
329 This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
330 The latter contains a ready-to-use profile for @code{root} (see next
331 step.)
332
333 Do @emph{not} unpack the tarball on a working Guix system since that
334 would overwrite its own essential files.
335
336 The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
337 not emit warnings about ``implausibly old time stamps'' (such
338 warnings were triggered by GNU@tie{}tar 1.26 and older; recent
339 versions are fine.)
340 They stem from the fact that all the
341 files in the archive have their modification time set to zero (which
342 means January 1st, 1970.) This is done on purpose to make sure the
343 archive content is independent of its creation time, thus making it
344 reproducible.
345
346 @item
347 Make @code{root}'s profile available under @file{~/.guix-profile}:
348
349 @example
350 # ln -sf /var/guix/profiles/per-user/root/guix-profile \
351 ~root/.guix-profile
352 @end example
353
354 @item
355 Create the group and user accounts for build users as explained below
356 (@pxref{Build Environment Setup}).
357
358 @item
359 Run the daemon:
360
361 @example
362 # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
363 @end example
364
365 On hosts using the systemd init system, drop
366 @file{~root/.guix-profile/lib/systemd/system/guix-daemon.service} in
367 @file{/etc/systemd/system}.
368
369 @item
370 Make the @command{guix} command available to other users on the machine,
371 for instance with:
372
373 @example
374 # mkdir -p /usr/local/bin
375 # cd /usr/local/bin
376 # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
377 @end example
378
379 @item
380 To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}),
381 authorize them:
382
383 @example
384 # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
385 @end example
386 @end enumerate
387
388 And that's it! For additional tips and tricks, @pxref{Application
389 Setup}.
390
391 The @code{guix} package must remain available in @code{root}'s
392 profile, or it would become subject to garbage collection---in which
393 case you would find yourself badly handicapped by the lack of the
394 @command{guix} command.
395
396 The tarball in question can be (re)produced and verified simply by
397 running the following command in the Guix source tree:
398
399 @example
400 make guix-binary.@var{system}.tar.xz
401 @end example
402
403
404 @node Requirements
405 @section Requirements
406
407 This section lists requirements when building Guix from source. The
408 build procedure for Guix is the same as for other GNU software, and is
409 not covered here. Please see the files @file{README} and @file{INSTALL}
410 in the Guix source tree for additional details.
411
412 GNU Guix depends on the following packages:
413
414 @itemize
415 @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
416 @item @url{http://gnupg.org/, GNU libgcrypt};
417 @item @url{http://www.gnu.org/software/make/, GNU Make}.
418 @end itemize
419
420 The following dependencies are optional:
421
422 @itemize
423 @item
424 Installing
425 @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
426 allow you to use the @command{guix import pypi} command (@pxref{Invoking
427 guix import}). It is of
428 interest primarily for developers and not for casual users.
429 @item
430 Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
431 allow you to access @code{https} URLs with the @command{guix download}
432 command (@pxref{Invoking guix download}), the @command{guix import pypi}
433 command, and the @command{guix import cpan} command. This is primarily
434 of interest to developers. @xref{Guile Preparations, how to install the
435 GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
436 @end itemize
437
438 Unless @code{--disable-daemon} was passed to @command{configure}, the
439 following packages are also needed:
440
441 @itemize
442 @item @url{http://sqlite.org, SQLite 3};
443 @item @url{http://www.bzip.org, libbz2};
444 @item @url{http://gcc.gnu.org, GCC's g++}, with support for the
445 C++11 standard.
446 @end itemize
447
448 When a working installation of @url{http://nixos.org/nix/, the Nix package
449 manager} is available, you
450 can instead configure Guix with @code{--disable-daemon}. In that case,
451 Nix replaces the three dependencies above.
452
453 Guix is compatible with Nix, so it is possible to share the same store
454 between both. To do so, you must pass @command{configure} not only the
455 same @code{--with-store-dir} value, but also the same
456 @code{--localstatedir} value. The latter is essential because it
457 specifies where the database that stores metadata about the store is
458 located, among other things. The default values for Nix are
459 @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
460 Note that @code{--disable-daemon} is not required if
461 your goal is to share the store with Nix.
462
463 @node Running the Test Suite
464 @section Running the Test Suite
465
466 After a successful @command{configure} and @code{make} run, it is a good
467 idea to run the test suite. It can help catch issues with the setup or
468 environment, or bugs in Guix itself---and really, reporting test
469 failures is a good way to help improve the software. To run the test
470 suite, type:
471
472 @example
473 make check
474 @end example
475
476 Test cases can run in parallel: you can use the @code{-j} option of
477 GNU@tie{}make to speed things up. The first run may take a few minutes
478 on a recent machine; subsequent runs will be faster because the store
479 that is created for test purposes will already have various things in
480 cache.
481
482 Upon failure, please email @email{bug-guix@@gnu.org} and attach the
483 @file{test-suite.log} file. When @file{tests/@var{something}.scm}
484 fails, please also attach the @file{@var{something}.log} file available
485 in the top-level build directory. Please specify the Guix version being
486 used as well as version numbers of the dependencies
487 (@pxref{Requirements}) in your message.
488
489 @node Setting Up the Daemon
490 @section Setting Up the Daemon
491
492 @cindex daemon
493 Operations such as building a package or running the garbage collector
494 are all performed by a specialized process, the @dfn{build daemon}, on
495 behalf of clients. Only the daemon may access the store and its
496 associated database. Thus, any operation that manipulates the store
497 goes through the daemon. For instance, command-line tools such as
498 @command{guix package} and @command{guix build} communicate with the
499 daemon (@i{via} remote procedure calls) to instruct it what to do.
500
501 The following sections explain how to prepare the build daemon's
502 environment. Also @ref{Substitutes}, for information on how to allow
503 the daemon to download pre-built binaries.
504
505 @menu
506 * Build Environment Setup:: Preparing the isolated build environment.
507 * Daemon Offload Setup:: Offloading builds to remote machines.
508 @end menu
509
510 @node Build Environment Setup
511 @subsection Build Environment Setup
512
513 In a standard multi-user setup, Guix and its daemon---the
514 @command{guix-daemon} program---are installed by the system
515 administrator; @file{/gnu/store} is owned by @code{root} and
516 @command{guix-daemon} runs as @code{root}. Unprivileged users may use
517 Guix tools to build packages or otherwise access the store, and the
518 daemon will do it on their behalf, ensuring that the store is kept in a
519 consistent state, and allowing built packages to be shared among users.
520
521 @cindex build users
522 When @command{guix-daemon} runs as @code{root}, you may not want package
523 build processes themselves to run as @code{root} too, for obvious
524 security reasons. To avoid that, a special pool of @dfn{build users}
525 should be created for use by build processes started by the daemon.
526 These build users need not have a shell and a home directory: they will
527 just be used when the daemon drops @code{root} privileges in build
528 processes. Having several such users allows the daemon to launch
529 distinct build processes under separate UIDs, which guarantees that they
530 do not interfere with each other---an essential feature since builds are
531 regarded as pure functions (@pxref{Introduction}).
532
533 On a GNU/Linux system, a build user pool may be created like this (using
534 Bash syntax and the @code{shadow} commands):
535
536 @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
537 @c for why `-G' is needed.
538 @example
539 # groupadd --system guixbuild
540 # for i in `seq -w 1 10`;
541 do
542 useradd -g guixbuild -G guixbuild \
543 -d /var/empty -s `which nologin` \
544 -c "Guix build user $i" --system \
545 guixbuilder$i;
546 done
547 @end example
548
549 @noindent
550 The number of build users determines how many build jobs may run in
551 parallel, as specified by the @option{--max-jobs} option
552 (@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
553 @code{guix-daemon} program may then be run as @code{root} with the
554 following command@footnote{If your machine uses the systemd init system,
555 dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
556 file in @file{/etc/systemd/system} will ensure that
557 @command{guix-daemon} is automatically started.}:
558
559 @example
560 # guix-daemon --build-users-group=guixbuild
561 @end example
562
563 @cindex chroot
564 @noindent
565 This way, the daemon starts build processes in a chroot, under one of
566 the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
567 environment contains nothing but:
568
569 @c Keep this list in sync with libstore/build.cc! -----------------------
570 @itemize
571 @item
572 a minimal @code{/dev} directory, created mostly independently from the
573 host @code{/dev}@footnote{``Mostly'', because while the set of files
574 that appear in the chroot's @code{/dev} is fixed, most of these files
575 can only be created if the host has them.};
576
577 @item
578 the @code{/proc} directory; it only shows the container's processes
579 since a separate PID name space is used;
580
581 @item
582 @file{/etc/passwd} with an entry for the current user and an entry for
583 user @file{nobody};
584
585 @item
586 @file{/etc/group} with an entry for the user's group;
587
588 @item
589 @file{/etc/hosts} with an entry that maps @code{localhost} to
590 @code{127.0.0.1};
591
592 @item
593 a writable @file{/tmp} directory.
594 @end itemize
595
596 If you are installing Guix as an unprivileged user, it is still possible
597 to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
598 However, build processes will not be isolated from one another, and not
599 from the rest of the system. Thus, build processes may interfere with
600 each other, and may access programs, libraries, and other files
601 available on the system---making it much harder to view them as
602 @emph{pure} functions.
603
604
605 @node Daemon Offload Setup
606 @subsection Using the Offload Facility
607
608 @cindex offloading
609 @cindex build hook
610 When desired, the build daemon can @dfn{offload}
611 derivation builds to other machines
612 running Guix, using the @code{offload} @dfn{build hook}. When that
613 feature is enabled, a list of user-specified build machines is read from
614 @file{/etc/guix/machines.scm}; anytime a build is requested, for
615 instance via @code{guix build}, the daemon attempts to offload it to one
616 of the machines that satisfies the derivation's constraints, in
617 particular its system type---e.g., @file{x86_64-linux}. Missing
618 prerequisites for the build are copied over SSH to the target machine,
619 which then proceeds with the build; upon success the output(s) of the
620 build are copied back to the initial machine.
621
622 The @file{/etc/guix/machines.scm} file typically looks like this:
623
624 @example
625 (list (build-machine
626 (name "eightysix.example.org")
627 (system "x86_64-linux")
628 (user "bob")
629 (speed 2.)) ; incredibly fast!
630
631 (build-machine
632 (name "meeps.example.org")
633 (system "mips64el-linux")
634 (user "alice")
635 (private-key
636 (string-append (getenv "HOME")
637 "/.lsh/identity-for-guix"))))
638 @end example
639
640 @noindent
641 In the example above we specify a list of two build machines, one for
642 the @code{x86_64} architecture and one for the @code{mips64el}
643 architecture.
644
645 In fact, this file is---not surprisingly!---a Scheme file that is
646 evaluated when the @code{offload} hook is started. Its return value
647 must be a list of @code{build-machine} objects. While this example
648 shows a fixed list of build machines, one could imagine, say, using
649 DNS-SD to return a list of potential build machines discovered in the
650 local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
651 Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
652 detailed below.
653
654 @deftp {Data Type} build-machine
655 This data type represents build machines the daemon may offload builds
656 to. The important fields are:
657
658 @table @code
659
660 @item name
661 The remote machine's host name.
662
663 @item system
664 The remote machine's system type---e.g., @code{"x86_64-linux"}.
665
666 @item user
667 The user account to use when connecting to the remote machine over SSH.
668 Note that the SSH key pair must @emph{not} be passphrase-protected, to
669 allow non-interactive logins.
670
671 @end table
672
673 A number of optional fields may be specified:
674
675 @table @code
676
677 @item port
678 Port number of the machine's SSH server (default: 22).
679
680 @item private-key
681 The SSH private key file to use when connecting to the machine.
682
683 Currently offloading uses GNU@tie{}lsh as its SSH client
684 (@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
685 be an lsh key file. This may change in the future, though.
686
687 @item parallel-builds
688 The number of builds that may run in parallel on the machine (1 by
689 default.)
690
691 @item speed
692 A ``relative speed factor''. The offload scheduler will tend to prefer
693 machines with a higher speed factor.
694
695 @item features
696 A list of strings denoting specific features supported by the machine.
697 An example is @code{"kvm"} for machines that have the KVM Linux modules
698 and corresponding hardware support. Derivations can request features by
699 name, and they will be scheduled on matching build machines.
700
701 @end table
702 @end deftp
703
704 The @code{guix} command must be in the search path on the build
705 machines, since offloading works by invoking the @code{guix archive} and
706 @code{guix build} commands. In addition, the Guix modules must be in
707 @code{$GUILE_LOAD_PATH} on the build machine---you can check whether
708 this is the case by running:
709
710 @example
711 lsh build-machine guile -c '(use-modules (guix config))'
712 @end example
713
714 There's one last thing to do once @file{machines.scm} is in place. As
715 explained above, when offloading, files are transferred back and forth
716 between the machine stores. For this to work, you first need to
717 generate a key pair on each machine to allow the daemon to export signed
718 archives of files from the store (@pxref{Invoking guix archive}):
719
720 @example
721 # guix archive --generate-key
722 @end example
723
724 @noindent
725 Each build machine must authorize the key of the master machine so that
726 it accepts store items it receives from the master:
727
728 @example
729 # guix archive --authorize < master-public-key.txt
730 @end example
731
732 @noindent
733 Likewise, the master machine must authorize the key of each build machine.
734
735 All the fuss with keys is here to express pairwise mutual trust
736 relations between the master and the build machines. Concretely, when
737 the master receives files from a build machine (and @i{vice versa}), its
738 build daemon can make sure they are genuine, have not been tampered
739 with, and that they are signed by an authorized key.
740
741
742 @node Invoking guix-daemon
743 @section Invoking @command{guix-daemon}
744
745 The @command{guix-daemon} program implements all the functionality to
746 access the store. This includes launching build processes, running the
747 garbage collector, querying the availability of a build result, etc. It
748 is normally run as @code{root} like this:
749
750 @example
751 # guix-daemon --build-users-group=guixbuild
752 @end example
753
754 @noindent
755 For details on how to set it up, @pxref{Setting Up the Daemon}.
756
757 @cindex chroot
758 @cindex container, build environment
759 @cindex build environment
760 @cindex reproducible builds
761 By default, @command{guix-daemon} launches build processes under
762 different UIDs, taken from the build group specified with
763 @code{--build-users-group}. In addition, each build process is run in a
764 chroot environment that only contains the subset of the store that the
765 build process depends on, as specified by its derivation
766 (@pxref{Programming Interface, derivation}), plus a set of specific
767 system directories. By default, the latter contains @file{/dev} and
768 @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
769 @dfn{container}: in addition to having its own file system tree, it has
770 a separate mount name space, its own PID name space, network name space,
771 etc. This helps achieve reproducible builds (@pxref{Features}).
772
773 When the daemon performs a build on behalf of the user, it creates a
774 build directory under @file{/tmp} or under the directory specified by
775 its @code{TMPDIR} environment variable; this directory is shared with
776 the container for the duration of the build. Be aware that using a
777 directory other than @file{/tmp} can affect build results---for example,
778 with a longer directory name, a build process that uses Unix-domain
779 sockets might hit the name length limitation for @code{sun_path}, which
780 it would otherwise not hit.
781
782 The build directory is automatically deleted upon completion, unless the
783 build failed and the client specified @option{--keep-failed}
784 (@pxref{Invoking guix build, @option{--keep-failed}}).
785
786 The following command-line options are supported:
787
788 @table @code
789 @item --build-users-group=@var{group}
790 Take users from @var{group} to run build processes (@pxref{Setting Up
791 the Daemon, build users}).
792
793 @item --no-substitutes
794 @cindex substitutes
795 Do not use substitutes for build products. That is, always build things
796 locally instead of allowing downloads of pre-built binaries
797 (@pxref{Substitutes}).
798
799 By default substitutes are used, unless the client---such as the
800 @command{guix package} command---is explicitly invoked with
801 @code{--no-substitutes}.
802
803 When the daemon runs with @code{--no-substitutes}, clients can still
804 explicitly enable substitution @i{via} the @code{set-build-options}
805 remote procedure call (@pxref{The Store}).
806
807 @item --substitute-urls=@var{urls}
808 @anchor{daemon-substitute-urls}
809 Consider @var{urls} the default whitespace-separated list of substitute
810 source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
811 is used.
812
813 This means that substitutes may be downloaded from @var{urls}, as long
814 as they are signed by a trusted signature (@pxref{Substitutes}).
815
816 @cindex build hook
817 @item --no-build-hook
818 Do not use the @dfn{build hook}.
819
820 The build hook is a helper program that the daemon can start and to
821 which it submits build requests. This mechanism is used to offload
822 builds to other machines (@pxref{Daemon Offload Setup}).
823
824 @item --cache-failures
825 Cache build failures. By default, only successful builds are cached.
826
827 When this option is used, @command{guix gc --list-failures} can be used
828 to query the set of store items marked as failed; @command{guix gc
829 --clear-failures} removes store items from the set of cached failures.
830 @xref{Invoking guix gc}.
831
832 @item --cores=@var{n}
833 @itemx -c @var{n}
834 Use @var{n} CPU cores to build each derivation; @code{0} means as many
835 as available.
836
837 The default value is @code{0}, but it may be overridden by clients, such
838 as the @code{--cores} option of @command{guix build} (@pxref{Invoking
839 guix build}).
840
841 The effect is to define the @code{NIX_BUILD_CORES} environment variable
842 in the build process, which can then use it to exploit internal
843 parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
844
845 @item --max-jobs=@var{n}
846 @itemx -M @var{n}
847 Allow at most @var{n} build jobs in parallel. The default value is
848 @code{1}. Setting it to @code{0} means that no builds will be performed
849 locally; instead, the daemon will offload builds (@pxref{Daemon Offload
850 Setup}), or simply fail.
851
852 @item --debug
853 Produce debugging output.
854
855 This is useful to debug daemon start-up issues, but then it may be
856 overridden by clients, for example the @code{--verbosity} option of
857 @command{guix build} (@pxref{Invoking guix build}).
858
859 @item --chroot-directory=@var{dir}
860 Add @var{dir} to the build chroot.
861
862 Doing this may change the result of build processes---for instance if
863 they use optional dependencies found in @var{dir} when it is available,
864 and not otherwise. For that reason, it is not recommended to do so.
865 Instead, make sure that each derivation declares all the inputs that it
866 needs.
867
868 @item --disable-chroot
869 Disable chroot builds.
870
871 Using this option is not recommended since, again, it would allow build
872 processes to gain access to undeclared dependencies. It is necessary,
873 though, when @command{guix-daemon} is running under an unprivileged user
874 account.
875
876 @item --disable-log-compression
877 Disable compression of the build logs.
878
879 Unless @code{--lose-logs} is used, all the build logs are kept in the
880 @var{localstatedir}. To save space, the daemon automatically compresses
881 them with bzip2 by default. This option disables that.
882
883 @item --disable-deduplication
884 @cindex deduplication
885 Disable automatic file ``deduplication'' in the store.
886
887 By default, files added to the store are automatically ``deduplicated'':
888 if a newly added file is identical to another one found in the store,
889 the daemon makes the new file a hard link to the other file. This can
890 noticeably reduce disk usage, at the expense of slightly increased
891 input/output load at the end of a build process. This option disables
892 this optimization.
893
894 @item --gc-keep-outputs[=yes|no]
895 Tell whether the garbage collector (GC) must keep outputs of live
896 derivations.
897
898 When set to ``yes'', the GC will keep the outputs of any live derivation
899 available in the store---the @code{.drv} files. The default is ``no'',
900 meaning that derivation outputs are kept only if they are GC roots.
901
902 @item --gc-keep-derivations[=yes|no]
903 Tell whether the garbage collector (GC) must keep derivations
904 corresponding to live outputs.
905
906 When set to ``yes'', as is the case by default, the GC keeps
907 derivations---i.e., @code{.drv} files---as long as at least one of their
908 outputs is live. This allows users to keep track of the origins of
909 items in their store. Setting it to ``no'' saves a bit of disk space.
910
911 Note that when both @code{--gc-keep-derivations} and
912 @code{--gc-keep-outputs} are used, the effect is to keep all the build
913 prerequisites (the sources, compiler, libraries, and other build-time
914 tools) of live objects in the store, regardless of whether these
915 prerequisites are live. This is convenient for developers since it
916 saves rebuilds or downloads.
917
918 @item --impersonate-linux-2.6
919 On Linux-based systems, impersonate Linux 2.6. This means that the
920 kernel's @code{uname} system call will report 2.6 as the release number.
921
922 This might be helpful to build programs that (usually wrongfully) depend
923 on the kernel version number.
924
925 @item --lose-logs
926 Do not keep build logs. By default they are kept under
927 @code{@var{localstatedir}/guix/log}.
928
929 @item --system=@var{system}
930 Assume @var{system} as the current system type. By default it is the
931 architecture/kernel pair found at configure time, such as
932 @code{x86_64-linux}.
933
934 @item --listen=@var{socket}
935 Listen for connections on @var{socket}, the file name of a Unix-domain
936 socket. The default socket is
937 @file{@var{localstatedir}/daemon-socket/socket}. This option is only
938 useful in exceptional circumstances, such as if you need to run several
939 daemons on the same machine.
940 @end table
941
942
943 @node Application Setup
944 @section Application Setup
945
946 When using Guix on top of GNU/Linux distribution other than GuixSD---a
947 so-called @dfn{foreign distro}---a few additional steps are needed to
948 get everything in place. Here are some of them.
949
950 @subsection Locales
951
952 @anchor{locales-and-locpath}
953 @cindex locales, when not on GuixSD
954 @vindex LOCPATH
955 @vindex GUIX_LOCPATH
956 Packages installed @i{via} Guix will not use the host system's locale
957 data. Instead, you must first install one of the locale packages
958 available with Guix and then define the @code{GUIX_LOCPATH} environment
959 variable:
960
961 @example
962 $ guix package -i glibc-locales
963 $ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
964 @end example
965
966 Note that the @code{glibc-locales} package contains data for all the
967 locales supported by the GNU@tie{}libc and weighs in at around
968 110@tie{}MiB. Alternately, the @code{glibc-utf8-locales} is smaller but
969 limited to a few UTF-8 locales.
970
971 The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
972 (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
973 Manual}). There are two important differences though:
974
975 @enumerate
976 @item
977 @code{GUIX_LOCPATH} is honored only by Guix's libc, and not by the libc
978 provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
979 to make sure the the foreign distro's programs will not end up loading
980 incompatible locale data.
981
982 @item
983 libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
984 @code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
985 should your Guix profile contain a mixture of programs linked against
986 different libc version, each libc version will only try to load locale
987 data in the right format.
988 @end enumerate
989
990 This is important because the locale data format used by different libc
991 versions may be incompatible.
992
993 @subsection X11 Fonts
994
995 The majority of graphical applications use Fontconfig to locate and
996 load fonts and perform X11-client-side rendering. Guix's
997 @code{fontconfig} package looks for fonts in @file{$HOME/.guix-profile}
998 by default. Thus, to allow graphical applications installed with Guix
999 to display fonts, you will have to install fonts with Guix as well.
1000 Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
1001 @code{font-gnu-freefont-ttf}.
1002
1003 To display text written in Chinese languages, Japanese, or Korean in
1004 graphical applications, consider installing
1005 @code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1006 has multiple outputs, one per language family (@pxref{Packages with
1007 Multiple Outputs}). For instance, the following command installs fonts
1008 for Chinese languages:
1009
1010 @example
1011 guix package -i font-adobe-source-han-sans:cn
1012 @end example
1013
1014 @c TODO What else?
1015
1016 @c *********************************************************************
1017 @node Package Management
1018 @chapter Package Management
1019
1020 The purpose of GNU Guix is to allow users to easily install, upgrade, and
1021 remove software packages, without having to know about their build
1022 procedure or dependencies. Guix also goes beyond this obvious set of
1023 features.
1024
1025 This chapter describes the main features of Guix, as well as the package
1026 management tools it provides. Two user interfaces are provided for
1027 routine package management tasks: A command-line interface described below
1028 (@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1029 interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
1030
1031 @menu
1032 * Features:: How Guix will make your life brighter.
1033 * Invoking guix package:: Package installation, removal, etc.
1034 * Substitutes:: Downloading pre-built binaries.
1035 * Packages with Multiple Outputs:: Single source package, multiple outputs.
1036 * Invoking guix gc:: Running the garbage collector.
1037 * Invoking guix pull:: Fetching the latest Guix and distribution.
1038 * Invoking guix archive:: Exporting and importing store files.
1039 @end menu
1040
1041 @node Features
1042 @section Features
1043
1044 When using Guix, each package ends up in the @dfn{package store}, in its
1045 own directory---something that resembles
1046 @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1047 (note that Guix comes with an Emacs extension to shorten those file
1048 names, @pxref{Emacs Prettify}.)
1049
1050 Instead of referring to these directories, users have their own
1051 @dfn{profile}, which points to the packages that they actually want to
1052 use. These profiles are stored within each user's home directory, at
1053 @code{$HOME/.guix-profile}.
1054
1055 For example, @code{alice} installs GCC 4.7.2. As a result,
1056 @file{/home/alice/.guix-profile/bin/gcc} points to
1057 @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
1058 @code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1059 simply continues to point to
1060 @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
1061 coexist on the same system without any interference.
1062
1063 The @command{guix package} command is the central tool to manage
1064 packages (@pxref{Invoking guix package}). It operates on those per-user
1065 profiles, and can be used @emph{with normal user privileges}.
1066
1067 The command provides the obvious install, remove, and upgrade
1068 operations. Each invocation is actually a @emph{transaction}: either
1069 the specified operation succeeds, or nothing happens. Thus, if the
1070 @command{guix package} process is terminated during the transaction,
1071 or if a power outage occurs during the transaction, then the user's
1072 profile remains in its previous state, and remains usable.
1073
1074 In addition, any package transaction may be @emph{rolled back}. So, if,
1075 for example, an upgrade installs a new version of a package that turns
1076 out to have a serious bug, users may roll back to the previous instance
1077 of their profile, which was known to work well. Similarly, the global
1078 system configuration is subject to transactional upgrades and roll-back
1079 (@pxref{Using the Configuration System}).
1080
1081 All those packages in the package store may be @emph{garbage-collected}.
1082 Guix can determine which packages are still referenced by the user
1083 profiles, and remove those that are provably no longer referenced
1084 (@pxref{Invoking guix gc}). Users may also explicitly remove old
1085 generations of their profile so that the packages they refer to can be
1086 collected.
1087
1088 @cindex reproducibility
1089 @cindex reproducible builds
1090 Finally, Guix takes a @dfn{purely functional} approach to package
1091 management, as described in the introduction (@pxref{Introduction}).
1092 Each @file{/gnu/store} package directory name contains a hash of all the
1093 inputs that were used to build that package---compiler, libraries, build
1094 scripts, etc. This direct correspondence allows users to make sure a
1095 given package installation matches the current state of their
1096 distribution. It also helps maximize @dfn{build reproducibility}:
1097 thanks to the isolated build environments that are used, a given build
1098 is likely to yield bit-identical files when performed on different
1099 machines (@pxref{Invoking guix-daemon, container}).
1100
1101 @cindex substitutes
1102 This foundation allows Guix to support @dfn{transparent binary/source
1103 deployment}. When a pre-built binary for a @file{/gnu/store} item is
1104 available from an external source---a @dfn{substitute}, Guix just
1105 downloads it and unpacks it;
1106 otherwise, it builds the package from source, locally
1107 (@pxref{Substitutes}).
1108
1109 Control over the build environment is a feature that is also useful for
1110 developers. The @command{guix environment} command allows developers of
1111 a package to quickly set up the right development environment for their
1112 package, without having to manually install the package's dependencies
1113 in their profile (@pxref{Invoking guix environment}).
1114
1115 @node Invoking guix package
1116 @section Invoking @command{guix package}
1117
1118 The @command{guix package} command is the tool that allows users to
1119 install, upgrade, and remove packages, as well as rolling back to
1120 previous configurations. It operates only on the user's own profile,
1121 and works with normal user privileges (@pxref{Features}). Its syntax
1122 is:
1123
1124 @example
1125 guix package @var{options}
1126 @end example
1127
1128 Primarily, @var{options} specifies the operations to be performed during
1129 the transaction. Upon completion, a new profile is created, but
1130 previous @dfn{generations} of the profile remain available, should the user
1131 want to roll back.
1132
1133 For example, to remove @code{lua} and install @code{guile} and
1134 @code{guile-cairo} in a single transaction:
1135
1136 @example
1137 guix package -r lua -i guile guile-cairo
1138 @end example
1139
1140 @command{guix package} also supports a @dfn{declarative approach}
1141 whereby the user specifies the exact set of packages to be available and
1142 passes it @i{via} the @option{--manifest} option
1143 (@pxref{profile-manifest, @option{--manifest}}).
1144
1145 For each user, a symlink to the user's default profile is automatically
1146 created in @file{$HOME/.guix-profile}. This symlink always points to the
1147 current generation of the user's default profile. Thus, users can add
1148 @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1149 variable, and so on.
1150 @cindex search paths
1151 If you are not using the Guix System Distribution, consider adding the
1152 following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1153 Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1154 shells get all the right environment variable definitions:
1155
1156 @example
1157 GUIX_PROFILE="$HOME/.guix-profile" \
1158 source "$HOME/.guix-profile/etc/profile"
1159 @end example
1160
1161 In a multi-user setup, user profiles are stored in a place registered as
1162 a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1163 to (@pxref{Invoking guix gc}). That directory is normally
1164 @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1165 @var{localstatedir} is the value passed to @code{configure} as
1166 @code{--localstatedir}, and @var{user} is the user name. The
1167 @file{per-user} directory is created when @command{guix-daemon} is
1168 started, and the @var{user} sub-directory is created by @command{guix
1169 package}.
1170
1171 The @var{options} can be among the following:
1172
1173 @table @code
1174
1175 @item --install=@var{package} @dots{}
1176 @itemx -i @var{package} @dots{}
1177 Install the specified @var{package}s.
1178
1179 Each @var{package} may specify either a simple package name, such as
1180 @code{guile}, or a package name followed by a hyphen and version number,
1181 such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter
1182 case, the newest version prefixed by @code{1.8} is selected.)
1183
1184 If no version number is specified, the
1185 newest available version will be selected. In addition, @var{package}
1186 may contain a colon, followed by the name of one of the outputs of the
1187 package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
1188 (@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1189 name (and optionally version) are searched for among the GNU
1190 distribution modules (@pxref{Package Modules}).
1191
1192 @cindex propagated inputs
1193 Sometimes packages have @dfn{propagated inputs}: these are dependencies
1194 that automatically get installed along with the required package
1195 (@pxref{package-propagated-inputs, @code{propagated-inputs} in
1196 @code{package} objects}, for information about propagated inputs in
1197 package definitions).
1198
1199 @anchor{package-cmd-propagated-inputs}
1200 An example is the GNU MPC library: its C header files refer to those of
1201 the GNU MPFR library, which in turn refer to those of the GMP library.
1202 Thus, when installing MPC, the MPFR and GMP libraries also get installed
1203 in the profile; removing MPC also removes MPFR and GMP---unless they had
1204 also been explicitly installed independently.
1205
1206 Besides, packages sometimes rely on the definition of environment
1207 variables for their search paths (see explanation of
1208 @code{--search-paths} below). Any missing or possibly incorrect
1209 environment variable definitions are reported here.
1210
1211 @c XXX: keep me up-to-date
1212 Finally, when installing a GNU package, the tool reports the
1213 availability of a newer upstream version. In the future, it may provide
1214 the option of installing directly from the upstream version, even if
1215 that version is not yet in the distribution.
1216
1217 @item --install-from-expression=@var{exp}
1218 @itemx -e @var{exp}
1219 Install the package @var{exp} evaluates to.
1220
1221 @var{exp} must be a Scheme expression that evaluates to a
1222 @code{<package>} object. This option is notably useful to disambiguate
1223 between same-named variants of a package, with expressions such as
1224 @code{(@@ (gnu packages base) guile-final)}.
1225
1226 Note that this option installs the first output of the specified
1227 package, which may be insufficient when needing a specific output of a
1228 multiple-output package.
1229
1230 @item --install-from-file=@var{file}
1231 @itemx -f @var{file}
1232 Install the package that the code within @var{file} evaluates to.
1233
1234 As an example, @var{file} might contain a definition like this
1235 (@pxref{Defining Packages}):
1236
1237 @example
1238 @verbatiminclude package-hello.scm
1239 @end example
1240
1241 Developers may find it useful to include such a @file{package.scm} file
1242 in the root of their project's source tree that can be used to test
1243 development snapshots and create reproducible development environments
1244 (@pxref{Invoking guix environment}).
1245
1246 @item --remove=@var{package} @dots{}
1247 @itemx -r @var{package} @dots{}
1248 Remove the specified @var{package}s.
1249
1250 As for @code{--install}, each @var{package} may specify a version number
1251 and/or output name in addition to the package name. For instance,
1252 @code{-r glibc:debug} would remove the @code{debug} output of
1253 @code{glibc}.
1254
1255 @item --upgrade[=@var{regexp} @dots{}]
1256 @itemx -u [@var{regexp} @dots{}]
1257 Upgrade all the installed packages. If one or more @var{regexp}s are
1258 specified, upgrade only installed packages whose name matches a
1259 @var{regexp}. Also see the @code{--do-not-upgrade} option below.
1260
1261 Note that this upgrades package to the latest version of packages found
1262 in the distribution currently installed. To update your distribution,
1263 you should regularly run @command{guix pull} (@pxref{Invoking guix
1264 pull}).
1265
1266 @item --do-not-upgrade[=@var{regexp} @dots{}]
1267 When used together with the @code{--upgrade} option, do @emph{not}
1268 upgrade any packages whose name matches a @var{regexp}. For example, to
1269 upgrade all packages in the current profile except those containing the
1270 substring ``emacs'':
1271
1272 @example
1273 $ guix package --upgrade . --do-not-upgrade emacs
1274 @end example
1275
1276 @item @anchor{profile-manifest}--manifest=@var{file}
1277 @itemx -m @var{file}
1278 @cindex profile declaration
1279 @cindex profile manifest
1280 Create a new generation of the profile from the manifest object
1281 returned by the Scheme code in @var{file}.
1282
1283 This allows you to @emph{declare} the profile's contents rather than
1284 constructing it through a sequence of @code{--install} and similar
1285 commands. The advantage is that @var{file} can be put under version
1286 control, copied to different machines to reproduce the same profile, and
1287 so on.
1288
1289 @c FIXME: Add reference to (guix profile) documentation when available.
1290 @var{file} must return a @dfn{manifest} object, which is roughly a list
1291 of packages:
1292
1293 @findex packages->manifest
1294 @example
1295 (use-package-modules guile emacs)
1296
1297 (packages->manifest
1298 (list emacs
1299 guile-2.0
1300 ;; Use a specific package output.
1301 (list guile-2.0 "debug")))
1302 @end example
1303
1304 @item --roll-back
1305 Roll back to the previous @dfn{generation} of the profile---i.e., undo
1306 the last transaction.
1307
1308 When combined with options such as @code{--install}, roll back occurs
1309 before any other actions.
1310
1311 When rolling back from the first generation that actually contains
1312 installed packages, the profile is made to point to the @dfn{zeroth
1313 generation}, which contains no files apart from its own meta-data.
1314
1315 Installing, removing, or upgrading packages from a generation that has
1316 been rolled back to overwrites previous future generations. Thus, the
1317 history of a profile's generations is always linear.
1318
1319 @item --switch-generation=@var{pattern}
1320 @itemx -S @var{pattern}
1321 Switch to a particular generation defined by @var{pattern}.
1322
1323 @var{pattern} may be either a generation number or a number prefixed
1324 with ``+'' or ``-''. The latter means: move forward/backward by a
1325 specified number of generations. For example, if you want to return to
1326 the latest generation after @code{--roll-back}, use
1327 @code{--switch-generation=+1}.
1328
1329 The difference between @code{--roll-back} and
1330 @code{--switch-generation=-1} is that @code{--switch-generation} will
1331 not make a zeroth generation, so if a specified generation does not
1332 exist, the current generation will not be changed.
1333
1334 @item --search-paths[=@var{kind}]
1335 @cindex search paths
1336 Report environment variable definitions, in Bash syntax, that may be
1337 needed in order to use the set of installed packages. These environment
1338 variables are used to specify @dfn{search paths} for files used by some
1339 of the installed packages.
1340
1341 For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1342 environment variables to be defined so it can look for headers and
1343 libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1344 Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1345 library are installed in the profile, then @code{--search-paths} will
1346 suggest setting these variables to @code{@var{profile}/include} and
1347 @code{@var{profile}/lib}, respectively.
1348
1349 The typical use case is to define these environment variables in the
1350 shell:
1351
1352 @example
1353 $ eval `guix package --search-paths`
1354 @end example
1355
1356 @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1357 meaning that the returned environment variable definitions will either
1358 be exact settings, or prefixes or suffixes of the current value of these
1359 variables. When omitted, @var{kind} defaults to @code{exact}.
1360
1361 This option can also be used to compute the @emph{combined} search paths
1362 of several profiles. Consider this example:
1363
1364 @example
1365 $ guix package -p foo -i guile
1366 $ guix package -p bar -i guile-json
1367 $ guix package -p foo -p bar --search-paths
1368 @end example
1369
1370 The last command above reports about the @code{GUILE_LOAD_PATH}
1371 variable, even though, taken individually, neither @file{foo} nor
1372 @file{bar} would lead to that recommendation.
1373
1374
1375 @item --profile=@var{profile}
1376 @itemx -p @var{profile}
1377 Use @var{profile} instead of the user's default profile.
1378
1379 @item --verbose
1380 Produce verbose output. In particular, emit the environment's build log
1381 on the standard error port.
1382
1383 @item --bootstrap
1384 Use the bootstrap Guile to build the profile. This option is only
1385 useful to distribution developers.
1386
1387 @end table
1388
1389 In addition to these actions @command{guix package} supports the
1390 following options to query the current state of a profile, or the
1391 availability of packages:
1392
1393 @table @option
1394
1395 @item --search=@var{regexp}
1396 @itemx -s @var{regexp}
1397 List the available packages whose name, synopsis, or description matches
1398 @var{regexp}. Print all the meta-data of matching packages in
1399 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1400 GNU recutils manual}).
1401
1402 This allows specific fields to be extracted using the @command{recsel}
1403 command, for instance:
1404
1405 @example
1406 $ guix package -s malloc | recsel -p name,version
1407 name: glibc
1408 version: 2.17
1409
1410 name: libgc
1411 version: 7.2alpha6
1412 @end example
1413
1414 Similarly, to show the name of all the packages available under the
1415 terms of the GNU@tie{}LGPL version 3:
1416
1417 @example
1418 $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1419 name: elfutils
1420
1421 name: gmp
1422 @dots{}
1423 @end example
1424
1425 @item --show=@var{package}
1426 Show details about @var{package}, taken from the list of available packages, in
1427 @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1428 recutils manual}).
1429
1430 @example
1431 $ guix package --show=python | recsel -p name,version
1432 name: python
1433 version: 2.7.6
1434
1435 name: python
1436 version: 3.3.5
1437 @end example
1438
1439 You may also specify the full name of a package to only get details about a
1440 specific version of it:
1441 @example
1442 $ guix package --show=python-3.3.5 | recsel -p name,version
1443 name: python
1444 version: 3.3.5
1445 @end example
1446
1447
1448
1449 @item --list-installed[=@var{regexp}]
1450 @itemx -I [@var{regexp}]
1451 List the currently installed packages in the specified profile, with the
1452 most recently installed packages shown last. When @var{regexp} is
1453 specified, list only installed packages whose name matches @var{regexp}.
1454
1455 For each installed package, print the following items, separated by
1456 tabs: the package name, its version string, the part of the package that
1457 is installed (for instance, @code{out} for the default output,
1458 @code{include} for its headers, etc.), and the path of this package in
1459 the store.
1460
1461 @item --list-available[=@var{regexp}]
1462 @itemx -A [@var{regexp}]
1463 List packages currently available in the distribution for this system
1464 (@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1465 installed packages whose name matches @var{regexp}.
1466
1467 For each package, print the following items separated by tabs: its name,
1468 its version string, the parts of the package (@pxref{Packages with
1469 Multiple Outputs}), and the source location of its definition.
1470
1471 @item --list-generations[=@var{pattern}]
1472 @itemx -l [@var{pattern}]
1473 Return a list of generations along with their creation dates; for each
1474 generation, show the installed packages, with the most recently
1475 installed packages shown last. Note that the zeroth generation is never
1476 shown.
1477
1478 For each installed package, print the following items, separated by
1479 tabs: the name of a package, its version string, the part of the package
1480 that is installed (@pxref{Packages with Multiple Outputs}), and the
1481 location of this package in the store.
1482
1483 When @var{pattern} is used, the command returns only matching
1484 generations. Valid patterns include:
1485
1486 @itemize
1487 @item @emph{Integers and comma-separated integers}. Both patterns denote
1488 generation numbers. For instance, @code{--list-generations=1} returns
1489 the first one.
1490
1491 And @code{--list-generations=1,8,2} outputs three generations in the
1492 specified order. Neither spaces nor trailing commas are allowed.
1493
1494 @item @emph{Ranges}. @code{--list-generations=2..9} prints the
1495 specified generations and everything in between. Note that the start of
1496 a range must be lesser than its end.
1497
1498 It is also possible to omit the endpoint. For example,
1499 @code{--list-generations=2..}, returns all generations starting from the
1500 second one.
1501
1502 @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1503 or months by passing an integer along with the first letter of the
1504 duration. For example, @code{--list-generations=20d} lists generations
1505 that are up to 20 days old.
1506 @end itemize
1507
1508 @item --delete-generations[=@var{pattern}]
1509 @itemx -d [@var{pattern}]
1510 When @var{pattern} is omitted, delete all generations except the current
1511 one.
1512
1513 This command accepts the same patterns as @option{--list-generations}.
1514 When @var{pattern} is specified, delete the matching generations. When
1515 @var{pattern} specifies a duration, generations @emph{older} than the
1516 specified duration match. For instance, @code{--delete-generations=1m}
1517 deletes generations that are more than one month old.
1518
1519 If the current generation matches, it is @emph{not} deleted. Also, the
1520 zeroth generation is never deleted.
1521
1522 Note that deleting generations prevents roll-back to them.
1523 Consequently, this command must be used with care.
1524
1525 @end table
1526
1527 Finally, since @command{guix package} may actually start build
1528 processes, it supports all the common build options that @command{guix
1529 build} supports (@pxref{Invoking guix build, common build options}).
1530
1531 @node Substitutes
1532 @section Substitutes
1533
1534 @cindex substitutes
1535 @cindex pre-built binaries
1536 Guix supports transparent source/binary deployment, which means that it
1537 can either build things locally, or download pre-built items from a
1538 server. We call these pre-built items @dfn{substitutes}---they are
1539 substitutes for local build results. In many cases, downloading a
1540 substitute is much faster than building things locally.
1541
1542 Substitutes can be anything resulting from a derivation build
1543 (@pxref{Derivations}). Of course, in the common case, they are
1544 pre-built package binaries, but source tarballs, for instance, which
1545 also result from derivation builds, can be available as substitutes.
1546
1547 The @code{hydra.gnu.org} server is a front-end to a build farm that
1548 builds packages from the GNU distribution continuously for some
1549 architectures, and makes them available as substitutes. This is the
1550 default source of substitutes; it can be overridden by passing the
1551 @option{--substitute-urls} option either to @command{guix-daemon}
1552 (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1553 or to client tools such as @command{guix package}
1554 (@pxref{client-substitute-urls,, client @option{--substitute-urls}
1555 option}).
1556
1557 @cindex security
1558 @cindex digital signatures
1559 To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1560 must add its public key to the access control list (ACL) of archive
1561 imports, using the @command{guix archive} command (@pxref{Invoking guix
1562 archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1563 be compromised and to serve genuine substitutes.
1564
1565 This public key is installed along with Guix, in
1566 @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1567 the installation prefix of Guix. If you installed Guix from source,
1568 make sure you checked the GPG signature of
1569 @file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1570 Then, you can run something like this:
1571
1572 @example
1573 # guix archive --authorize < hydra.gnu.org.pub
1574 @end example
1575
1576 Once this is in place, the output of a command like @code{guix build}
1577 should change from something like:
1578
1579 @example
1580 $ guix build emacs --dry-run
1581 The following derivations would be built:
1582 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1583 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1584 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1585 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1586 @dots{}
1587 @end example
1588
1589 @noindent
1590 to something like:
1591
1592 @example
1593 $ guix build emacs --dry-run
1594 The following files would be downloaded:
1595 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1596 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1597 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1598 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1599 @dots{}
1600 @end example
1601
1602 @noindent
1603 This indicates that substitutes from @code{hydra.gnu.org} are usable and
1604 will be downloaded, when possible, for future builds.
1605
1606 Guix ignores substitutes that are not signed, or that are not signed by
1607 one of the keys listed in the ACL. It also detects and raises an error
1608 when attempting to use a substitute that has been tampered with.
1609
1610 The substitute mechanism can be disabled globally by running
1611 @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1612 guix-daemon}). It can also be disabled temporarily by passing the
1613 @code{--no-substitutes} option to @command{guix package}, @command{guix
1614 build}, and other command-line tools.
1615
1616
1617 Today, each individual's control over their own computing is at the
1618 mercy of institutions, corporations, and groups with enough power and
1619 determination to subvert the computing infrastructure and exploit its
1620 weaknesses. While using @code{hydra.gnu.org} substitutes can be
1621 convenient, we encourage users to also build on their own, or even run
1622 their own build farm, such that @code{hydra.gnu.org} is less of an
1623 interesting target. One way to help is by publishing the software you
1624 build using @command{guix publish} so that others have one more choice
1625 of server to download substitutes from (@pxref{Invoking guix publish}).
1626
1627 Guix has the foundations to maximize build reproducibility
1628 (@pxref{Features}). In most cases, independent builds of a given
1629 package or derivation should yield bit-identical results. Thus, through
1630 a diverse set of independent package builds, we can strengthen the
1631 integrity of our systems. The @command{guix challenge} command aims to
1632 help users assess substitute servers, and to assist developers in
1633 finding out about non-deterministic package builds (@pxref{Invoking guix
1634 challenge}).
1635
1636 In the future, we want Guix to have support to publish and retrieve
1637 binaries to/from other users, in a peer-to-peer fashion. If you would
1638 like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1639
1640
1641 @node Packages with Multiple Outputs
1642 @section Packages with Multiple Outputs
1643
1644 @cindex multiple-output packages
1645 @cindex package outputs
1646
1647 Often, packages defined in Guix have a single @dfn{output}---i.e., the
1648 source package leads exactly one directory in the store. When running
1649 @command{guix package -i glibc}, one installs the default output of the
1650 GNU libc package; the default output is called @code{out}, but its name
1651 can be omitted as shown in this command. In this particular case, the
1652 default output of @code{glibc} contains all the C header files, shared
1653 libraries, static libraries, Info documentation, and other supporting
1654 files.
1655
1656 Sometimes it is more appropriate to separate the various types of files
1657 produced from a single source package into separate outputs. For
1658 instance, the GLib C library (used by GTK+ and related packages)
1659 installs more than 20 MiB of reference documentation as HTML pages.
1660 To save space for users who do not need it, the documentation goes to a
1661 separate output, called @code{doc}. To install the main GLib output,
1662 which contains everything but the documentation, one would run:
1663
1664 @example
1665 guix package -i glib
1666 @end example
1667
1668 The command to install its documentation is:
1669
1670 @example
1671 guix package -i glib:doc
1672 @end example
1673
1674 Some packages install programs with different ``dependency footprints''.
1675 For instance, the WordNet package install both command-line tools and
1676 graphical user interfaces (GUIs). The former depend solely on the C
1677 library, whereas the latter depend on Tcl/Tk and the underlying X
1678 libraries. In this case, we leave the command-line tools in the default
1679 output, whereas the GUIs are in a separate output. This allows users
1680 who do not need the GUIs to save space. The @command{guix size} command
1681 can help find out about such situations (@pxref{Invoking guix size}).
1682 @command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
1683
1684 There are several such multiple-output packages in the GNU distribution.
1685 Other conventional output names include @code{lib} for libraries and
1686 possibly header files, @code{bin} for stand-alone programs, and
1687 @code{debug} for debugging information (@pxref{Installing Debugging
1688 Files}). The outputs of a packages are listed in the third column of
1689 the output of @command{guix package --list-available} (@pxref{Invoking
1690 guix package}).
1691
1692
1693 @node Invoking guix gc
1694 @section Invoking @command{guix gc}
1695
1696 @cindex garbage collector
1697 Packages that are installed but not used may be @dfn{garbage-collected}.
1698 The @command{guix gc} command allows users to explicitly run the garbage
1699 collector to reclaim space from the @file{/gnu/store} directory. It is
1700 the @emph{only} way to remove files from @file{/gnu/store}---removing
1701 files or directories manually may break it beyond repair!
1702
1703 The garbage collector has a set of known @dfn{roots}: any file under
1704 @file{/gnu/store} reachable from a root is considered @dfn{live} and
1705 cannot be deleted; any other file is considered @dfn{dead} and may be
1706 deleted. The set of garbage collector roots includes default user
1707 profiles, and may be augmented with @command{guix build --root}, for
1708 example (@pxref{Invoking guix build}).
1709
1710 Prior to running @code{guix gc --collect-garbage} to make space, it is
1711 often useful to remove old generations from user profiles; that way, old
1712 package builds referenced by those generations can be reclaimed. This
1713 is achieved by running @code{guix package --delete-generations}
1714 (@pxref{Invoking guix package}).
1715
1716 The @command{guix gc} command has three modes of operation: it can be
1717 used to garbage-collect any dead files (the default), to delete specific
1718 files (the @code{--delete} option), to print garbage-collector
1719 information, or for more advanced queries. The garbage collection
1720 options are as follows:
1721
1722 @table @code
1723 @item --collect-garbage[=@var{min}]
1724 @itemx -C [@var{min}]
1725 Collect garbage---i.e., unreachable @file{/gnu/store} files and
1726 sub-directories. This is the default operation when no option is
1727 specified.
1728
1729 When @var{min} is given, stop once @var{min} bytes have been collected.
1730 @var{min} may be a number of bytes, or it may include a unit as a
1731 suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1732 (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
1733
1734 When @var{min} is omitted, collect all the garbage.
1735
1736 @item --delete
1737 @itemx -d
1738 Attempt to delete all the store files and directories specified as
1739 arguments. This fails if some of the files are not in the store, or if
1740 they are still live.
1741
1742 @item --list-failures
1743 List store items corresponding to cached build failures.
1744
1745 This prints nothing unless the daemon was started with
1746 @option{--cache-failures} (@pxref{Invoking guix-daemon,
1747 @option{--cache-failures}}).
1748
1749 @item --clear-failures
1750 Remove the specified store items from the failed-build cache.
1751
1752 Again, this option only makes sense when the daemon is started with
1753 @option{--cache-failures}. Otherwise, it does nothing.
1754
1755 @item --list-dead
1756 Show the list of dead files and directories still present in the
1757 store---i.e., files and directories no longer reachable from any root.
1758
1759 @item --list-live
1760 Show the list of live store files and directories.
1761
1762 @end table
1763
1764 In addition, the references among existing store files can be queried:
1765
1766 @table @code
1767
1768 @item --references
1769 @itemx --referrers
1770 List the references (respectively, the referrers) of store files given
1771 as arguments.
1772
1773 @item --requisites
1774 @itemx -R
1775 @cindex closure
1776 List the requisites of the store files passed as arguments. Requisites
1777 include the store files themselves, their references, and the references
1778 of these, recursively. In other words, the returned list is the
1779 @dfn{transitive closure} of the store files.
1780
1781 @xref{Invoking guix size}, for a tool to profile the size of an
1782 element's closure. @xref{Invoking guix graph}, for a tool to visualize
1783 the graph of references.
1784
1785 @end table
1786
1787 Lastly, the following options allow you to check the integrity of the
1788 store and to control disk usage.
1789
1790 @table @option
1791
1792 @item --verify[=@var{options}]
1793 @cindex integrity, of the store
1794 @cindex integrity checking
1795 Verify the integrity of the store.
1796
1797 By default, make sure that all the store items marked as valid in the
1798 daemon's database actually exist in @file{/gnu/store}.
1799
1800 When provided, @var{options} must a comma-separated list containing one
1801 or more of @code{contents} and @code{repair}.
1802
1803 When passing @option{--verify=contents}, the daemon will compute the
1804 content hash of each store item and compare it against its hash in the
1805 database. Hash mismatches are reported as data corruptions. Because it
1806 traverses @emph{all the files in the store}, this command can take a
1807 long time, especially on systems with a slow disk drive.
1808
1809 @cindex repairing the store
1810 Using @option{--verify=repair} or @option{--verify=contents,repair}
1811 causes the daemon to try to repair corrupt store items by fetching
1812 substitutes for them (@pxref{Substitutes}). Because repairing is not
1813 atomic, and thus potentially dangerous, it is available only to the
1814 system administrator.
1815
1816 @item --optimize
1817 @cindex deduplication
1818 Optimize the store by hard-linking identical files---this is
1819 @dfn{deduplication}.
1820
1821 The daemon performs deduplication after each successful build or archive
1822 import, unless it was started with @code{--disable-deduplication}
1823 (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
1824 this option is primarily useful when the daemon was running with
1825 @code{--disable-deduplication}.
1826
1827 @end table
1828
1829 @node Invoking guix pull
1830 @section Invoking @command{guix pull}
1831
1832 Packages are installed or upgraded to the latest version available in
1833 the distribution currently available on your local machine. To update
1834 that distribution, along with the Guix tools, you must run @command{guix
1835 pull}: the command downloads the latest Guix source code and package
1836 descriptions, and deploys it.
1837
1838 On completion, @command{guix package} will use packages and package
1839 versions from this just-retrieved copy of Guix. Not only that, but all
1840 the Guix commands and Scheme modules will also be taken from that latest
1841 version. New @command{guix} sub-commands added by the update also
1842 become available@footnote{Under the hood, @command{guix pull} updates
1843 the @file{~/.config/guix/latest} symbolic link to point to the latest
1844 Guix, and the @command{guix} command loads code from there.}.
1845
1846 The @command{guix pull} command is usually invoked with no arguments,
1847 but it supports the following options:
1848
1849 @table @code
1850 @item --verbose
1851 Produce verbose output, writing build logs to the standard error output.
1852
1853 @item --url=@var{url}
1854 Download the source tarball of Guix from @var{url}.
1855
1856 By default, the tarball is taken from its canonical address at
1857 @code{gnu.org}, for the stable branch of Guix.
1858
1859 @item --bootstrap
1860 Use the bootstrap Guile to build the latest Guix. This option is only
1861 useful to Guix developers.
1862 @end table
1863
1864
1865 @node Invoking guix archive
1866 @section Invoking @command{guix archive}
1867
1868 The @command{guix archive} command allows users to @dfn{export} files
1869 from the store into a single archive, and to later @dfn{import} them.
1870 In particular, it allows store files to be transferred from one machine
1871 to another machine's store. For example, to transfer the @code{emacs}
1872 package to a machine connected over SSH, one would run:
1873
1874 @example
1875 guix archive --export -r emacs | ssh the-machine guix archive --import
1876 @end example
1877
1878 @noindent
1879 Similarly, a complete user profile may be transferred from one machine
1880 to another like this:
1881
1882 @example
1883 guix archive --export -r $(readlink -f ~/.guix-profile) | \
1884 ssh the-machine guix-archive --import
1885 @end example
1886
1887 @noindent
1888 However, note that, in both examples, all of @code{emacs} and the
1889 profile as well as all of their dependencies are transferred (due to
1890 @code{-r}), regardless of what is already available in the target
1891 machine's store. The @code{--missing} option can help figure out which
1892 items are missing from the target's store.
1893
1894 Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
1895 comparable in spirit to `tar', but with a few noteworthy differences
1896 that make it more appropriate for our purposes. First, rather than
1897 recording all Unix meta-data for each file, the Nar format only mentions
1898 the file type (regular, directory, or symbolic link); Unix permissions
1899 and owner/group are dismissed. Second, the order in which directory
1900 entries are stored always follows the order of file names according to
1901 the C locale collation order. This makes archive production fully
1902 deterministic.
1903
1904 When exporting, the daemon digitally signs the contents of the archive,
1905 and that digital signature is appended. When importing, the daemon
1906 verifies the signature and rejects the import in case of an invalid
1907 signature or if the signing key is not authorized.
1908 @c FIXME: Add xref to daemon doc about signatures.
1909
1910 The main options are:
1911
1912 @table @code
1913 @item --export
1914 Export the specified store files or packages (see below.) Write the
1915 resulting archive to the standard output.
1916
1917 Dependencies are @emph{not} included in the output, unless
1918 @code{--recursive} is passed.
1919
1920 @item -r
1921 @itemx --recursive
1922 When combined with @code{--export}, this instructs @command{guix
1923 archive} to include dependencies of the given items in the archive.
1924 Thus, the resulting archive is self-contained: it contains the closure
1925 of the exported store items.
1926
1927 @item --import
1928 Read an archive from the standard input, and import the files listed
1929 therein into the store. Abort if the archive has an invalid digital
1930 signature, or if it is signed by a public key not among the authorized
1931 keys (see @code{--authorize} below.)
1932
1933 @item --missing
1934 Read a list of store file names from the standard input, one per line,
1935 and write on the standard output the subset of these files missing from
1936 the store.
1937
1938 @item --generate-key[=@var{parameters}]
1939 @cindex signing, archives
1940 Generate a new key pair for the daemons. This is a prerequisite before
1941 archives can be exported with @code{--export}. Note that this operation
1942 usually takes time, because it needs to gather enough entropy to
1943 generate the key pair.
1944
1945 The generated key pair is typically stored under @file{/etc/guix}, in
1946 @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
1947 key, which must be kept secret.) When @var{parameters} is omitted,
1948 an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
1949 versions before 1.6.0, it is a 4096-bit RSA key.
1950 Alternately, @var{parameters} can specify
1951 @code{genkey} parameters suitable for Libgcrypt (@pxref{General
1952 public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
1953 Libgcrypt Reference Manual}).
1954
1955 @item --authorize
1956 @cindex authorizing, archives
1957 Authorize imports signed by the public key passed on standard input.
1958 The public key must be in ``s-expression advanced format''---i.e., the
1959 same format as the @file{signing-key.pub} file.
1960
1961 The list of authorized keys is kept in the human-editable file
1962 @file{/etc/guix/acl}. The file contains
1963 @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
1964 s-expressions''} and is structured as an access-control list in the
1965 @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
1966 (SPKI)}.
1967
1968 @item --extract=@var{directory}
1969 @itemx -x @var{directory}
1970 Read a single-item archive as served by substitute servers
1971 (@pxref{Substitutes}) and extract it to @var{directory}. This is a
1972 low-level operation needed in only very narrow use cases; see below.
1973
1974 For example, the following command extracts the substitute for Emacs
1975 served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
1976
1977 @example
1978 $ wget -O - \
1979 http://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
1980 | bunzip2 | guix archive -x /tmp/emacs
1981 @end example
1982
1983 Single-item archives are different from multiple-item archives produced
1984 by @command{guix archive --export}; they contain a single store item,
1985 and they do @emph{not} embed a signature. Thus this operation does
1986 @emph{no} signature verification and its output should be considered
1987 unsafe.
1988
1989 The primary purpose of this operation is to facilitate inspection of
1990 archive contents coming from possibly untrusted substitute servers.
1991
1992 @end table
1993
1994 To export store files as an archive to the standard output, run:
1995
1996 @example
1997 guix archive --export @var{options} @var{specifications}...
1998 @end example
1999
2000 @var{specifications} may be either store file names or package
2001 specifications, as for @command{guix package} (@pxref{Invoking guix
2002 package}). For instance, the following command creates an archive
2003 containing the @code{gui} output of the @code{git} package and the main
2004 output of @code{emacs}:
2005
2006 @example
2007 guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2008 @end example
2009
2010 If the specified packages are not built yet, @command{guix archive}
2011 automatically builds them. The build process may be controlled with the
2012 same options that can be passed to the @command{guix build} command
2013 (@pxref{Invoking guix build, common build options}).
2014
2015 @c *********************************************************************
2016 @include emacs.texi
2017
2018 @c *********************************************************************
2019 @node Programming Interface
2020 @chapter Programming Interface
2021
2022 GNU Guix provides several Scheme programming interfaces (APIs) to
2023 define, build, and query packages. The first interface allows users to
2024 write high-level package definitions. These definitions refer to
2025 familiar packaging concepts, such as the name and version of a package,
2026 its build system, and its dependencies. These definitions can then be
2027 turned into concrete build actions.
2028
2029 Build actions are performed by the Guix daemon, on behalf of users. In a
2030 standard setup, the daemon has write access to the store---the
2031 @file{/gnu/store} directory---whereas users do not. The recommended
2032 setup also has the daemon perform builds in chroots, under a specific
2033 build users, to minimize interference with the rest of the system.
2034
2035 @cindex derivation
2036 Lower-level APIs are available to interact with the daemon and the
2037 store. To instruct the daemon to perform a build action, users actually
2038 provide it with a @dfn{derivation}. A derivation is a low-level
2039 representation of the build actions to be taken, and the environment in
2040 which they should occur---derivations are to package definitions what
2041 assembly is to C programs. The term ``derivation'' comes from the fact
2042 that build results @emph{derive} from them.
2043
2044 This chapter describes all these APIs in turn, starting from high-level
2045 package definitions.
2046
2047 @menu
2048 * Defining Packages:: Defining new packages.
2049 * Build Systems:: Specifying how packages are built.
2050 * The Store:: Manipulating the package store.
2051 * Derivations:: Low-level interface to package derivations.
2052 * The Store Monad:: Purely functional interface to the store.
2053 * G-Expressions:: Manipulating build expressions.
2054 @end menu
2055
2056 @node Defining Packages
2057 @section Defining Packages
2058
2059 The high-level interface to package definitions is implemented in the
2060 @code{(guix packages)} and @code{(guix build-system)} modules. As an
2061 example, the package definition, or @dfn{recipe}, for the GNU Hello
2062 package looks like this:
2063
2064 @example
2065 (define-module (gnu packages hello)
2066 #:use-module (guix packages)
2067 #:use-module (guix download)
2068 #:use-module (guix build-system gnu)
2069 #:use-module (guix licenses)
2070 #:use-module (gnu packages gawk))
2071
2072 (define-public hello
2073 (package
2074 (name "hello")
2075 (version "2.10")
2076 (source (origin
2077 (method url-fetch)
2078 (uri (string-append "mirror://gnu/hello/hello-" version
2079 ".tar.gz"))
2080 (sha256
2081 (base32
2082 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
2083 (build-system gnu-build-system)
2084 (arguments `(#:configure-flags '("--enable-silent-rules")))
2085 (inputs `(("gawk" ,gawk)))
2086 (synopsis "Hello, GNU world: An example GNU package")
2087 (description "Guess what GNU Hello prints!")
2088 (home-page "http://www.gnu.org/software/hello/")
2089 (license gpl3+)))
2090 @end example
2091
2092 @noindent
2093 Without being a Scheme expert, the reader may have guessed the meaning
2094 of the various fields here. This expression binds variable @code{hello}
2095 to a @code{<package>} object, which is essentially a record
2096 (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2097 This package object can be inspected using procedures found in the
2098 @code{(guix packages)} module; for instance, @code{(package-name hello)}
2099 returns---surprise!---@code{"hello"}.
2100
2101 With luck, you may be able to import part or all of the definition of
2102 the package you are interested in from another repository, using the
2103 @code{guix import} command (@pxref{Invoking guix import}).
2104
2105 In the example above, @var{hello} is defined into a module of its own,
2106 @code{(gnu packages hello)}. Technically, this is not strictly
2107 necessary, but it is convenient to do so: all the packages defined in
2108 modules under @code{(gnu packages @dots{})} are automatically known to
2109 the command-line tools (@pxref{Package Modules}).
2110
2111 There are a few points worth noting in the above package definition:
2112
2113 @itemize
2114 @item
2115 The @code{source} field of the package is an @code{<origin>} object
2116 (@pxref{origin Reference}, for the complete reference).
2117 Here, the @code{url-fetch} method from @code{(guix download)} is used,
2118 meaning that the source is a file to be downloaded over FTP or HTTP.
2119
2120 The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2121 the GNU mirrors defined in @code{(guix download)}.
2122
2123 The @code{sha256} field specifies the expected SHA256 hash of the file
2124 being downloaded. It is mandatory, and allows Guix to check the
2125 integrity of the file. The @code{(base32 @dots{})} form introduces the
2126 base32 representation of the hash. You can obtain this information with
2127 @code{guix download} (@pxref{Invoking guix download}) and @code{guix
2128 hash} (@pxref{Invoking guix hash}).
2129
2130 @cindex patches
2131 When needed, the @code{origin} form can also have a @code{patches} field
2132 listing patches to be applied, and a @code{snippet} field giving a
2133 Scheme expression to modify the source code.
2134
2135 @item
2136 @cindex GNU Build System
2137 The @code{build-system} field specifies the procedure to build the
2138 package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2139 represents the familiar GNU Build System, where packages may be
2140 configured, built, and installed with the usual @code{./configure &&
2141 make && make check && make install} command sequence.
2142
2143 @item
2144 The @code{arguments} field specifies options for the build system
2145 (@pxref{Build Systems}). Here it is interpreted by
2146 @var{gnu-build-system} as a request run @file{configure} with the
2147 @code{--enable-silent-rules} flag.
2148
2149 @item
2150 The @code{inputs} field specifies inputs to the build process---i.e.,
2151 build-time or run-time dependencies of the package. Here, we define an
2152 input called @code{"gawk"} whose value is that of the @var{gawk}
2153 variable; @var{gawk} is itself bound to a @code{<package>} object.
2154
2155 Note that GCC, Coreutils, Bash, and other essential tools do not need to
2156 be specified as inputs here. Instead, @var{gnu-build-system} takes care
2157 of ensuring that they are present (@pxref{Build Systems}).
2158
2159 However, any other dependencies need to be specified in the
2160 @code{inputs} field. Any dependency not specified here will simply be
2161 unavailable to the build process, possibly leading to a build failure.
2162 @end itemize
2163
2164 @xref{package Reference}, for a full description of possible fields.
2165
2166 Once a package definition is in place, the
2167 package may actually be built using the @code{guix build} command-line
2168 tool (@pxref{Invoking guix build}). You can easily jump back to the
2169 package definition using the @command{guix edit} command
2170 (@pxref{Invoking guix edit}).
2171 @xref{Packaging Guidelines}, for
2172 more information on how to test package definitions, and
2173 @ref{Invoking guix lint}, for information on how to check a definition
2174 for style conformance.
2175
2176 Eventually, updating the package definition to a new upstream version
2177 can be partly automated by the @command{guix refresh} command
2178 (@pxref{Invoking guix refresh}).
2179
2180 Behind the scenes, a derivation corresponding to the @code{<package>}
2181 object is first computed by the @code{package-derivation} procedure.
2182 That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
2183 The build actions it prescribes may then be realized by using the
2184 @code{build-derivations} procedure (@pxref{The Store}).
2185
2186 @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
2187 Return the @code{<derivation>} object of @var{package} for @var{system}
2188 (@pxref{Derivations}).
2189
2190 @var{package} must be a valid @code{<package>} object, and @var{system}
2191 must be a string denoting the target system type---e.g.,
2192 @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2193 must be a connection to the daemon, which operates on the store
2194 (@pxref{The Store}).
2195 @end deffn
2196
2197 @noindent
2198 @cindex cross-compilation
2199 Similarly, it is possible to compute a derivation that cross-builds a
2200 package for some other system:
2201
2202 @deffn {Scheme Procedure} package-cross-derivation @var{store} @
2203 @var{package} @var{target} [@var{system}]
2204 Return the @code{<derivation>} object of @var{package} cross-built from
2205 @var{system} to @var{target}.
2206
2207 @var{target} must be a valid GNU triplet denoting the target hardware
2208 and operating system, such as @code{"mips64el-linux-gnu"}
2209 (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2210 Configure and Build System}).
2211 @end deffn
2212
2213 @menu
2214 * package Reference :: The package data type.
2215 * origin Reference:: The origin data type.
2216 @end menu
2217
2218
2219 @node package Reference
2220 @subsection @code{package} Reference
2221
2222 This section summarizes all the options available in @code{package}
2223 declarations (@pxref{Defining Packages}).
2224
2225 @deftp {Data Type} package
2226 This is the data type representing a package recipe.
2227
2228 @table @asis
2229 @item @code{name}
2230 The name of the package, as a string.
2231
2232 @item @code{version}
2233 The version of the package, as a string.
2234
2235 @item @code{source}
2236 An origin object telling how the source code for the package should be
2237 acquired (@pxref{origin Reference}).
2238
2239 @item @code{build-system}
2240 The build system that should be used to build the package (@pxref{Build
2241 Systems}).
2242
2243 @item @code{arguments} (default: @code{'()})
2244 The arguments that should be passed to the build system. This is a
2245 list, typically containing sequential keyword-value pairs.
2246
2247 @item @code{inputs} (default: @code{'()})
2248 Package or derivation inputs to the build. This is a list of lists,
2249 where each list has the name of the input (a string) as its first
2250 element, a package or derivation object as its second element, and
2251 optionally the name of the output of the package or derivation that
2252 should be used, which defaults to @code{"out"}.
2253
2254 @item @anchor{package-propagated-inputs}@code{propagated-inputs} (default: @code{'()})
2255 @cindex propagated inputs
2256 This field is like @code{inputs}, but the specified packages will be
2257 force-installed alongside the package they belong to
2258 (@pxref{package-cmd-propagated-inputs, @command{guix package}}, for
2259 information on how @command{guix package} deals with propagated inputs.)
2260
2261 For example this is necessary when a library needs headers of another
2262 library to compile, or needs another shared library to be linked
2263 alongside itself when a program wants to link to it.
2264
2265 @item @code{native-inputs} (default: @code{'()})
2266 This field is like @code{inputs}, but in case of a cross-compilation it
2267 will be ensured that packages for the architecture of the build machine
2268 are present, such that executables from them can be used during the
2269 build.
2270
2271 This is typically where you would list tools needed at build time but
2272 not at run time, such as Autoconf, Automake, pkg-config, Gettext, or
2273 Bison. @command{guix lint} can report likely mistakes in this area
2274 (@pxref{Invoking guix lint}).
2275
2276 @item @code{self-native-input?} (default: @code{#f})
2277 This is a Boolean field telling whether the package should use itself as
2278 a native input when cross-compiling.
2279
2280 @item @code{outputs} (default: @code{'("out")})
2281 The list of output names of the package. @xref{Packages with Multiple
2282 Outputs}, for typical uses of additional outputs.
2283
2284 @item @code{native-search-paths} (default: @code{'()})
2285 @itemx @code{search-paths} (default: @code{'()})
2286 A list of @code{search-path-specification} objects describing
2287 search-path environment variables honored by the package.
2288
2289 @item @code{replacement} (default: @code{#f})
2290 This must either @code{#f} or a package object that will be used as a
2291 @dfn{replacement} for this package. @xref{Security Updates, grafts},
2292 for details.
2293
2294 @item @code{synopsis}
2295 A one-line description of the package.
2296
2297 @item @code{description}
2298 A more elaborate description of the package.
2299
2300 @item @code{license}
2301 The license of the package; a value from @code{(guix licenses)}.
2302
2303 @item @code{home-page}
2304 The URL to the home-page of the package, as a string.
2305
2306 @item @code{supported-systems} (default: @var{%supported-systems})
2307 The list of systems supported by the package, as strings of the form
2308 @code{architecture-kernel}, for example @code{"x86_64-linux"}.
2309
2310 @item @code{maintainers} (default: @code{'()})
2311 The list of maintainers of the package, as @code{maintainer} objects.
2312
2313 @item @code{location} (default: source location of the @code{package} form)
2314 The source location of the package. It's useful to override this when
2315 inheriting from another package, in which case this field is not
2316 automatically corrected.
2317 @end table
2318 @end deftp
2319
2320
2321 @node origin Reference
2322 @subsection @code{origin} Reference
2323
2324 This section summarizes all the options available in @code{origin}
2325 declarations (@pxref{Defining Packages}).
2326
2327 @deftp {Data Type} origin
2328 This is the data type representing a source code origin.
2329
2330 @table @asis
2331 @item @code{uri}
2332 An object containing the URI of the source. The object type depends on
2333 the @code{method} (see below). For example, when using the
2334 @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2335 values are: a URL represented as a string, or a list thereof.
2336
2337 @item @code{method}
2338 A procedure that will handle the URI.
2339
2340 Examples include:
2341
2342 @table @asis
2343 @item @var{url-fetch} from @code{(guix download)}
2344 download a file the HTTP, HTTPS, or FTP URL specified in the
2345 @code{uri} field;
2346
2347 @item @var{git-fetch} from @code{(guix git-download)}
2348 clone the Git version control repository, and check out the revision
2349 specified in the @code{uri} field as a @code{git-reference} object; a
2350 @code{git-reference} looks like this:
2351
2352 @example
2353 (git-reference
2354 (url "git://git.debian.org/git/pkg-shadow/shadow")
2355 (commit "v4.1.5.1"))
2356 @end example
2357 @end table
2358
2359 @item @code{sha256}
2360 A bytevector containing the SHA-256 hash of the source. Typically the
2361 @code{base32} form is used here to generate the bytevector from a
2362 base-32 string.
2363
2364 @item @code{file-name} (default: @code{#f})
2365 The file name under which the source code should be saved. When this is
2366 @code{#f}, a sensible default value will be used in most cases. In case
2367 the source is fetched from a URL, the file name from the URL will be
2368 used. For version control checkouts, it's recommended to provide the
2369 file name explicitly because the default is not very descriptive.
2370
2371 @item @code{patches} (default: @code{'()})
2372 A list of file names containing patches to be applied to the source.
2373
2374 @item @code{snippet} (default: @code{#f})
2375 A quoted piece of code that will be run in the source directory to make
2376 any modifications, which is sometimes more convenient than a patch.
2377
2378 @item @code{patch-flags} (default: @code{'("-p1")})
2379 A list of command-line flags that should be passed to the @code{patch}
2380 command.
2381
2382 @item @code{patch-inputs} (default: @code{#f})
2383 Input packages or derivations to the patching process. When this is
2384 @code{#f}, the usual set of inputs necessary for patching are provided,
2385 such as GNU@tie{}Patch.
2386
2387 @item @code{modules} (default: @code{'()})
2388 A list of Guile modules that should be loaded during the patching
2389 process and while running the code in the @code{snippet} field.
2390
2391 @item @code{imported-modules} (default: @code{'()})
2392 The list of Guile modules to import in the patch derivation, for use by
2393 the @code{snippet}.
2394
2395 @item @code{patch-guile} (default: @code{#f})
2396 The Guile package that should be used in the patching process. When
2397 this is @code{#f}, a sensible default is used.
2398 @end table
2399 @end deftp
2400
2401
2402 @node Build Systems
2403 @section Build Systems
2404
2405 @cindex build system
2406 Each package definition specifies a @dfn{build system} and arguments for
2407 that build system (@pxref{Defining Packages}). This @code{build-system}
2408 field represents the build procedure of the package, as well implicit
2409 dependencies of that build procedure.
2410
2411 Build systems are @code{<build-system>} objects. The interface to
2412 create and manipulate them is provided by the @code{(guix build-system)}
2413 module, and actual build systems are exported by specific modules.
2414
2415 @cindex bag (low-level package representation)
2416 Under the hood, build systems first compile package objects to
2417 @dfn{bags}. A @dfn{bag} is like a package, but with less
2418 ornamentation---in other words, a bag is a lower-level representation of
2419 a package, which includes all the inputs of that package, including some
2420 that were implicitly added by the build system. This intermediate
2421 representation is then compiled to a derivation (@pxref{Derivations}).
2422
2423 Build systems accept an optional list of @dfn{arguments}. In package
2424 definitions, these are passed @i{via} the @code{arguments} field
2425 (@pxref{Defining Packages}). They are typically keyword arguments
2426 (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2427 Guile Reference Manual}). The value of these arguments is usually
2428 evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2429 by the daemon (@pxref{Derivations}).
2430
2431 The main build system is @var{gnu-build-system}, which implements the
2432 standard build procedure for GNU packages and many other packages. It
2433 is provided by the @code{(guix build-system gnu)} module.
2434
2435 @defvr {Scheme Variable} gnu-build-system
2436 @var{gnu-build-system} represents the GNU Build System, and variants
2437 thereof (@pxref{Configuration, configuration and makefile conventions,,
2438 standards, GNU Coding Standards}).
2439
2440 @cindex build phases
2441 In a nutshell, packages using it configured, built, and installed with
2442 the usual @code{./configure && make && make check && make install}
2443 command sequence. In practice, a few additional steps are often needed.
2444 All these steps are split up in separate @dfn{phases},
2445 notably@footnote{Please see the @code{(guix build gnu-build-system)}
2446 modules for more details about the build phases.}:
2447
2448 @table @code
2449 @item unpack
2450 Unpack the source tarball, and change the current directory to the
2451 extracted source tree. If the source is actually a directory, copy it
2452 to the build tree, and enter that directory.
2453
2454 @item patch-source-shebangs
2455 Patch shebangs encountered in source files so they refer to the right
2456 store file names. For instance, this changes @code{#!/bin/sh} to
2457 @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2458
2459 @item configure
2460 Run the @file{configure} script with a number of default options, such
2461 as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2462 by the @code{#:configure-flags} argument.
2463
2464 @item build
2465 Run @code{make} with the list of flags specified with
2466 @code{#:make-flags}. If the @code{#:parallel-builds?} argument is true
2467 (the default), build with @code{make -j}.
2468
2469 @item check
2470 Run @code{make check}, or some other target specified with
2471 @code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2472 @code{#:parallel-tests?} argument is true (the default), run @code{make
2473 check -j}.
2474
2475 @item install
2476 Run @code{make install} with the flags listed in @code{#:make-flags}.
2477
2478 @item patch-shebangs
2479 Patch shebangs on the installed executable files.
2480
2481 @item strip
2482 Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2483 is false), copying them to the @code{debug} output when available
2484 (@pxref{Installing Debugging Files}).
2485 @end table
2486
2487 @vindex %standard-phases
2488 The build-side module @code{(guix build gnu-build-system)} defines
2489 @var{%standard-phases} as the default list of build phases.
2490 @var{%standard-phases} is a list of symbol/procedure pairs, where the
2491 procedure implements the actual phase.
2492
2493 The list of phases used for a particular package can be changed with the
2494 @code{#:phases} parameter. For instance, passing:
2495
2496 @example
2497 #:phases (alist-delete 'configure %standard-phases)
2498 @end example
2499
2500 means that all the phases described above will be used, except the
2501 @code{configure} phase.
2502
2503 In addition, this build system ensures that the ``standard'' environment
2504 for GNU packages is available. This includes tools such as GCC, libc,
2505 Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
2506 build-system gnu)} module for a complete list.) We call these the
2507 @dfn{implicit inputs} of a package, because package definitions don't
2508 have to mention them.
2509 @end defvr
2510
2511 Other @code{<build-system>} objects are defined to support other
2512 conventions and tools used by free software packages. They inherit most
2513 of @var{gnu-build-system}, and differ mainly in the set of inputs
2514 implicitly added to the build process, and in the list of phases
2515 executed. Some of these build systems are listed below.
2516
2517 @defvr {Scheme Variable} cmake-build-system
2518 This variable is exported by @code{(guix build-system cmake)}. It
2519 implements the build procedure for packages using the
2520 @url{http://www.cmake.org, CMake build tool}.
2521
2522 It automatically adds the @code{cmake} package to the set of inputs.
2523 Which package is used can be specified with the @code{#:cmake}
2524 parameter.
2525
2526 The @code{#:configure-flags} parameter is taken as a list of flags
2527 passed to the @command{cmake} command. The @code{#:build-type}
2528 parameter specifies in abstract terms the flags passed to the compiler;
2529 it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2530 debugging information''), which roughly means that code is compiled with
2531 @code{-O2 -g}, as is the case for Autoconf-based packages by default.
2532 @end defvr
2533
2534 @defvr {Scheme Variable} glib-or-gtk-build-system
2535 This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2536 is intended for use with packages making use of GLib or GTK+.
2537
2538 This build system adds the following two phases to the ones defined by
2539 @var{gnu-build-system}:
2540
2541 @table @code
2542 @item glib-or-gtk-wrap
2543 The phase @code{glib-or-gtk-wrap} ensures that programs found under
2544 @file{bin/} are able to find GLib's ``schemas'' and
2545 @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2546 modules}. This is achieved by wrapping the programs in launch scripts
2547 that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2548 environment variables.
2549
2550 It is possible to exclude specific package outputs from that wrapping
2551 process by listing their names in the
2552 @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2553 when an output is known not to contain any GLib or GTK+ binaries, and
2554 where wrapping would gratuitously add a dependency of that output on
2555 GLib and GTK+.
2556
2557 @item glib-or-gtk-compile-schemas
2558 The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's
2559 @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
2560 GSettings schemas} are compiled. Compilation is performed by the
2561 @command{glib-compile-schemas} program. It is provided by the package
2562 @code{glib:bin} which is automatically imported by the build system.
2563 The @code{glib} package providing @command{glib-compile-schemas} can be
2564 specified with the @code{#:glib} parameter.
2565 @end table
2566
2567 Both phases are executed after the @code{install} phase.
2568 @end defvr
2569
2570 @defvr {Scheme Variable} python-build-system
2571 This variable is exported by @code{(guix build-system python)}. It
2572 implements the more or less standard build procedure used by Python
2573 packages, which consists in running @code{python setup.py build} and
2574 then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2575
2576 For packages that install stand-alone Python programs under @code{bin/},
2577 it takes care of wrapping these programs so their @code{PYTHONPATH}
2578 environment variable points to all the Python libraries they depend on.
2579
2580 Which Python package is used can be specified with the @code{#:python}
2581 parameter.
2582 @end defvr
2583
2584 @defvr {Scheme Variable} perl-build-system
2585 This variable is exported by @code{(guix build-system perl)}. It
2586 implements the standard build procedure for Perl packages, which either
2587 consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2588 followed by @code{Build} and @code{Build install}; or in running
2589 @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2590 @code{make} and @code{make install}; depending on which of
2591 @code{Build.PL} or @code{Makefile.PL} is present in the package
2592 distribution. Preference is given to the former if both @code{Build.PL}
2593 and @code{Makefile.PL} exist in the package distribution. This
2594 preference can be reversed by specifying @code{#t} for the
2595 @code{#:make-maker?} parameter.
2596
2597 The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2598 passes flags specified by the @code{#:make-maker-flags} or
2599 @code{#:module-build-flags} parameter, respectively.
2600
2601 Which Perl package is used can be specified with @code{#:perl}.
2602 @end defvr
2603
2604 @defvr {Scheme Variable} r-build-system
2605 This variable is exported by @code{(guix build-system r)}. It
2606 implements the build procedure used by @uref{http://r-project.org, R}
2607 packages, which essentially is little more than running @code{R CMD
2608 INSTALL --library=/gnu/store/@dots{}} in an environment where
2609 @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2610 are run after installation using the R function
2611 @code{tools::testInstalledPackage}.
2612 @end defvr
2613
2614 @defvr {Scheme Variable} ruby-build-system
2615 This variable is exported by @code{(guix build-system ruby)}. It
2616 implements the RubyGems build procedure used by Ruby packages, which
2617 involves running @code{gem build} followed by @code{gem install}.
2618
2619 The @code{source} field of a package that uses this build system
2620 typically references a gem archive, since this is the format that Ruby
2621 developers use when releasing their software. The build system unpacks
2622 the gem archive, potentially patches the source, runs the test suite,
2623 repackages the gem, and installs it. Additionally, directories and
2624 tarballs may be referenced to allow building unreleased gems from Git or
2625 a traditional source release tarball.
2626
2627 Which Ruby package is used can be specified with the @code{#:ruby}
2628 parameter. A list of additional flags to be passed to the @command{gem}
2629 command can be specified with the @code{#:gem-flags} parameter.
2630 @end defvr
2631
2632 @defvr {Scheme Variable} waf-build-system
2633 This variable is exported by @code{(guix build-system waf)}. It
2634 implements a build procedure around the @code{waf} script. The common
2635 phases---@code{configure}, @code{build}, and @code{install}---are
2636 implemented by passing their names as arguments to the @code{waf}
2637 script.
2638
2639 The @code{waf} script is executed by the Python interpreter. Which
2640 Python package is used to run the script can be specified with the
2641 @code{#:python} parameter.
2642 @end defvr
2643
2644 @defvr {Scheme Variable} haskell-build-system
2645 This variable is exported by @code{(guix build-system haskell)}. It
2646 implements the Cabal build procedure used by Haskell packages, which
2647 involves running @code{runhaskell Setup.hs configure
2648 --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2649 Instead of installing the package by running @code{runhaskell Setup.hs
2650 install}, to avoid trying to register libraries in the read-only
2651 compiler store directory, the build system uses @code{runhaskell
2652 Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2653 addition, the build system generates the package documentation by
2654 running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2655 is passed. Optional Haddock parameters can be passed with the help of
2656 the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2657 not found, the build system looks for @code{Setup.lhs} instead.
2658
2659 Which Haskell compiler is used can be specified with the @code{#:haskell}
2660 parameter which defaults to @code{ghc}.
2661 @end defvr
2662
2663 @defvr {Scheme Variable} emacs-build-system
2664 This variable is exported by @code{(guix build-system emacs)}. It
2665 implements an installation procedure similar to the one of Emacs' own
2666 packaging system (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
2667
2668 It first creates the @code{@var{package}-autoloads.el} file, then it
2669 byte compiles all Emacs Lisp files. Differently from the Emacs
2670 packaging system, the Info documentation files are moved to the standard
2671 documentation directory and the @file{dir} file is deleted. Each
2672 package is installed in its own directory under
2673 @file{share/emacs/site-lisp/guix.d}.
2674 @end defvr
2675
2676 Lastly, for packages that do not need anything as sophisticated, a
2677 ``trivial'' build system is provided. It is trivial in the sense that
2678 it provides basically no support: it does not pull any implicit inputs,
2679 and does not have a notion of build phases.
2680
2681 @defvr {Scheme Variable} trivial-build-system
2682 This variable is exported by @code{(guix build-system trivial)}.
2683
2684 This build system requires a @code{#:builder} argument. This argument
2685 must be a Scheme expression that builds the package's output(s)---as
2686 with @code{build-expression->derivation} (@pxref{Derivations,
2687 @code{build-expression->derivation}}).
2688 @end defvr
2689
2690 @node The Store
2691 @section The Store
2692
2693 @cindex store
2694 @cindex store paths
2695
2696 Conceptually, the @dfn{store} is where derivations that have been
2697 successfully built are stored---by default, under @file{/gnu/store}.
2698 Sub-directories in the store are referred to as @dfn{store paths}. The
2699 store has an associated database that contains information such as the
2700 store paths referred to by each store path, and the list of @emph{valid}
2701 store paths---paths that result from a successful build.
2702
2703 The store is always accessed by the daemon on behalf of its clients
2704 (@pxref{Invoking guix-daemon}). To manipulate the store, clients
2705 connect to the daemon over a Unix-domain socket, send it requests, and
2706 read the result---these are remote procedure calls, or RPCs.
2707
2708 The @code{(guix store)} module provides procedures to connect to the
2709 daemon, and to perform RPCs. These are described below.
2710
2711 @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2712 Connect to the daemon over the Unix-domain socket at @var{file}. When
2713 @var{reserve-space?} is true, instruct it to reserve a little bit of
2714 extra space on the file system so that the garbage collector can still
2715 operate, should the disk become full. Return a server object.
2716
2717 @var{file} defaults to @var{%default-socket-path}, which is the normal
2718 location given the options that were passed to @command{configure}.
2719 @end deffn
2720
2721 @deffn {Scheme Procedure} close-connection @var{server}
2722 Close the connection to @var{server}.
2723 @end deffn
2724
2725 @defvr {Scheme Variable} current-build-output-port
2726 This variable is bound to a SRFI-39 parameter, which refers to the port
2727 where build and error logs sent by the daemon should be written.
2728 @end defvr
2729
2730 Procedures that make RPCs all take a server object as their first
2731 argument.
2732
2733 @deffn {Scheme Procedure} valid-path? @var{server} @var{path}
2734 Return @code{#t} when @var{path} is a valid store path.
2735 @end deffn
2736
2737 @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
2738 Add @var{text} under file @var{name} in the store, and return its store
2739 path. @var{references} is the list of store paths referred to by the
2740 resulting store path.
2741 @end deffn
2742
2743 @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
2744 Build @var{derivations} (a list of @code{<derivation>} objects or
2745 derivation paths), and return when the worker is done building them.
2746 Return @code{#t} on success.
2747 @end deffn
2748
2749 Note that the @code{(guix monads)} module provides a monad as well as
2750 monadic versions of the above procedures, with the goal of making it
2751 more convenient to work with code that accesses the store (@pxref{The
2752 Store Monad}).
2753
2754 @c FIXME
2755 @i{This section is currently incomplete.}
2756
2757 @node Derivations
2758 @section Derivations
2759
2760 @cindex derivations
2761 Low-level build actions and the environment in which they are performed
2762 are represented by @dfn{derivations}. A derivation contain the
2763 following pieces of information:
2764
2765 @itemize
2766 @item
2767 The outputs of the derivation---derivations produce at least one file or
2768 directory in the store, but may produce more.
2769
2770 @item
2771 The inputs of the derivations, which may be other derivations or plain
2772 files in the store (patches, build scripts, etc.)
2773
2774 @item
2775 The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2776
2777 @item
2778 The file name of a build script in the store, along with the arguments
2779 to be passed.
2780
2781 @item
2782 A list of environment variables to be defined.
2783
2784 @end itemize
2785
2786 @cindex derivation path
2787 Derivations allow clients of the daemon to communicate build actions to
2788 the store. They exist in two forms: as an in-memory representation,
2789 both on the client- and daemon-side, and as files in the store whose
2790 name end in @code{.drv}---these files are referred to as @dfn{derivation
2791 paths}. Derivations paths can be passed to the @code{build-derivations}
2792 procedure to perform the build actions they prescribe (@pxref{The
2793 Store}).
2794
2795 The @code{(guix derivations)} module provides a representation of
2796 derivations as Scheme objects, along with procedures to create and
2797 otherwise manipulate derivations. The lowest-level primitive to create
2798 a derivation is the @code{derivation} procedure:
2799
2800 @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2801 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2802 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
2803 [#:system (%current-system)] [#:references-graphs #f] @
2804 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
2805 [#:substitutable? #t]
2806 Build a derivation with the given arguments, and return the resulting
2807 @code{<derivation>} object.
2808
2809 When @var{hash} and @var{hash-algo} are given, a
2810 @dfn{fixed-output derivation} is created---i.e., one whose result is
2811 known in advance, such as a file download. If, in addition,
2812 @var{recursive?} is true, then that fixed output may be an executable
2813 file or a directory and @var{hash} must be the hash of an archive
2814 containing this output.
2815
2816 When @var{references-graphs} is true, it must be a list of file
2817 name/store path pairs. In that case, the reference graph of each store
2818 path is exported in the build environment in the corresponding file, in
2819 a simple text format.
2820
2821 When @var{allowed-references} is true, it must be a list of store items
2822 or outputs that the derivation's output may refer to.
2823
2824 When @var{leaked-env-vars} is true, it must be a list of strings
2825 denoting environment variables that are allowed to ``leak'' from the
2826 daemon's environment to the build environment. This is only applicable
2827 to fixed-output derivations---i.e., when @var{hash} is true. The main
2828 use is to allow variables such as @code{http_proxy} to be passed to
2829 derivations that download files.
2830
2831 When @var{local-build?} is true, declare that the derivation is not a
2832 good candidate for offloading and should rather be built locally
2833 (@pxref{Daemon Offload Setup}). This is the case for small derivations
2834 where the costs of data transfers would outweigh the benefits.
2835
2836 When @var{substitutable?} is false, declare that substitutes of the
2837 derivation's output should not be used (@pxref{Substitutes}). This is
2838 useful, for instance, when building packages that capture details of the
2839 host CPU instruction set.
2840 @end deffn
2841
2842 @noindent
2843 Here's an example with a shell script as its builder, assuming
2844 @var{store} is an open connection to the daemon, and @var{bash} points
2845 to a Bash executable in the store:
2846
2847 @lisp
2848 (use-modules (guix utils)
2849 (guix store)
2850 (guix derivations))
2851
2852 (let ((builder ; add the Bash script to the store
2853 (add-text-to-store store "my-builder.sh"
2854 "echo hello world > $out\n" '())))
2855 (derivation store "foo"
2856 bash `("-e" ,builder)
2857 #:inputs `((,bash) (,builder))
2858 #:env-vars '(("HOME" . "/homeless"))))
2859 @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
2860 @end lisp
2861
2862 As can be guessed, this primitive is cumbersome to use directly. A
2863 better approach is to write build scripts in Scheme, of course! The
2864 best course of action for that is to write the build code as a
2865 ``G-expression'', and to pass it to @code{gexp->derivation}. For more
2866 information, @pxref{G-Expressions}.
2867
2868 Once upon a time, @code{gexp->derivation} did not exist and constructing
2869 derivations with build code written in Scheme was achieved with
2870 @code{build-expression->derivation}, documented below. This procedure
2871 is now deprecated in favor of the much nicer @code{gexp->derivation}.
2872
2873 @deffn {Scheme Procedure} build-expression->derivation @var{store} @
2874 @var{name} @var{exp} @
2875 [#:system (%current-system)] [#:inputs '()] @
2876 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2877 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
2878 [#:references-graphs #f] [#:allowed-references #f] @
2879 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
2880 Return a derivation that executes Scheme expression @var{exp} as a
2881 builder for derivation @var{name}. @var{inputs} must be a list of
2882 @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
2883 @code{"out"} is assumed. @var{modules} is a list of names of Guile
2884 modules from the current search path to be copied in the store,
2885 compiled, and made available in the load path during the execution of
2886 @var{exp}---e.g., @code{((guix build utils) (guix build
2887 gnu-build-system))}.
2888
2889 @var{exp} is evaluated in an environment where @code{%outputs} is bound
2890 to a list of output/path pairs, and where @code{%build-inputs} is bound
2891 to a list of string/output-path pairs made from @var{inputs}.
2892 Optionally, @var{env-vars} is a list of string pairs specifying the name
2893 and value of environment variables visible to the builder. The builder
2894 terminates by passing the result of @var{exp} to @code{exit}; thus, when
2895 @var{exp} returns @code{#f}, the build is considered to have failed.
2896
2897 @var{exp} is built using @var{guile-for-build} (a derivation). When
2898 @var{guile-for-build} is omitted or is @code{#f}, the value of the
2899 @code{%guile-for-build} fluid is used instead.
2900
2901 See the @code{derivation} procedure for the meaning of
2902 @var{references-graphs}, @var{allowed-references}, @var{local-build?},
2903 and @var{substitutable?}.
2904 @end deffn
2905
2906 @noindent
2907 Here's an example of a single-output derivation that creates a directory
2908 containing one file:
2909
2910 @lisp
2911 (let ((builder '(let ((out (assoc-ref %outputs "out")))
2912 (mkdir out) ; create /gnu/store/@dots{}-goo
2913 (call-with-output-file (string-append out "/test")
2914 (lambda (p)
2915 (display '(hello guix) p))))))
2916 (build-expression->derivation store "goo" builder))
2917
2918 @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
2919 @end lisp
2920
2921
2922 @node The Store Monad
2923 @section The Store Monad
2924
2925 @cindex monad
2926
2927 The procedures that operate on the store described in the previous
2928 sections all take an open connection to the build daemon as their first
2929 argument. Although the underlying model is functional, they either have
2930 side effects or depend on the current state of the store.
2931
2932 The former is inconvenient: the connection to the build daemon has to be
2933 carried around in all those functions, making it impossible to compose
2934 functions that do not take that parameter with functions that do. The
2935 latter can be problematic: since store operations have side effects
2936 and/or depend on external state, they have to be properly sequenced.
2937
2938 @cindex monadic values
2939 @cindex monadic functions
2940 This is where the @code{(guix monads)} module comes in. This module
2941 provides a framework for working with @dfn{monads}, and a particularly
2942 useful monad for our uses, the @dfn{store monad}. Monads are a
2943 construct that allows two things: associating ``context'' with values
2944 (in our case, the context is the store), and building sequences of
2945 computations (here computations include accesses to the store.) Values
2946 in a monad---values that carry this additional context---are called
2947 @dfn{monadic values}; procedures that return such values are called
2948 @dfn{monadic procedures}.
2949
2950 Consider this ``normal'' procedure:
2951
2952 @example
2953 (define (sh-symlink store)
2954 ;; Return a derivation that symlinks the 'bash' executable.
2955 (let* ((drv (package-derivation store bash))
2956 (out (derivation->output-path drv))
2957 (sh (string-append out "/bin/bash")))
2958 (build-expression->derivation store "sh"
2959 `(symlink ,sh %output))))
2960 @end example
2961
2962 Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
2963 as a monadic function:
2964
2965 @example
2966 (define (sh-symlink)
2967 ;; Same, but return a monadic value.
2968 (mlet %store-monad ((drv (package->derivation bash)))
2969 (gexp->derivation "sh"
2970 #~(symlink (string-append #$drv "/bin/bash")
2971 #$output))))
2972 @end example
2973
2974 There several things to note in the second version: the @code{store}
2975 parameter is now implicit and is ``threaded'' in the calls to the
2976 @code{package->derivation} and @code{gexp->derivation} monadic
2977 procedures, and the monadic value returned by @code{package->derivation}
2978 is @dfn{bound} using @code{mlet} instead of plain @code{let}.
2979
2980 As it turns out, the call to @code{package->derivation} can even be
2981 omitted since it will take place implicitly, as we will see later
2982 (@pxref{G-Expressions}):
2983
2984 @example
2985 (define (sh-symlink)
2986 (gexp->derivation "sh"
2987 #~(symlink (string-append #$bash "/bin/bash")
2988 #$output)))
2989 @end example
2990
2991 @c See
2992 @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
2993 @c for the funny quote.
2994 Calling the monadic @code{sh-symlink} has no effect. As someone once
2995 said, ``you exit a monad like you exit a building on fire: by running''.
2996 So, to exit the monad and get the desired effect, one must use
2997 @code{run-with-store}:
2998
2999 @example
3000 (run-with-store (open-connection) (sh-symlink))
3001 @result{} /gnu/store/...-sh-symlink
3002 @end example
3003
3004 Note that the @code{(guix monad-repl)} module extends Guile's REPL with
3005 new ``meta-commands'' to make it easier to deal with monadic procedures:
3006 @code{run-in-store}, and @code{enter-store-monad}. The former, is used
3007 to ``run'' a single monadic value through the store:
3008
3009 @example
3010 scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3011 $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3012 @end example
3013
3014 The latter enters a recursive REPL, where all the return values are
3015 automatically run through the store:
3016
3017 @example
3018 scheme@@(guile-user)> ,enter-store-monad
3019 store-monad@@(guile-user) [1]> (package->derivation hello)
3020 $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3021 store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3022 $3 = "/gnu/store/@dots{}-foo"
3023 store-monad@@(guile-user) [1]> ,q
3024 scheme@@(guile-user)>
3025 @end example
3026
3027 @noindent
3028 Note that non-monadic values cannot be returned in the
3029 @code{store-monad} REPL.
3030
3031 The main syntactic forms to deal with monads in general are provided by
3032 the @code{(guix monads)} module and are described below.
3033
3034 @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3035 Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3036 in @var{monad}.
3037 @end deffn
3038
3039 @deffn {Scheme Syntax} return @var{val}
3040 Return a monadic value that encapsulates @var{val}.
3041 @end deffn
3042
3043 @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
3044 @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
3045 procedures @var{mproc}@dots{}@footnote{This operation is commonly
3046 referred to as ``bind'', but that name denotes an unrelated procedure in
3047 Guile. Thus we use this somewhat cryptic symbol inherited from the
3048 Haskell language.}. There can be one @var{mproc} or several of them, as
3049 in this example:
3050
3051 @example
3052 (run-with-state
3053 (with-monad %state-monad
3054 (>>= (return 1)
3055 (lambda (x) (return (+ 1 x)))
3056 (lambda (x) (return (* 2 x)))))
3057 'some-state)
3058
3059 @result{} 4
3060 @result{} some-state
3061 @end example
3062 @end deffn
3063
3064 @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3065 @var{body} ...
3066 @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3067 @var{body} ...
3068 Bind the variables @var{var} to the monadic values @var{mval} in
3069 @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3070 ``normal'' value @var{val}, as per @code{let}.
3071
3072 @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3073 (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3074 @end deffn
3075
3076 @deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3077 Bind @var{mexp} and the following monadic expressions in sequence,
3078 returning the result of the last expression.
3079
3080 This is akin to @code{mlet}, except that the return values of the
3081 monadic expressions are ignored. In that sense, it is analogous to
3082 @code{begin}, but applied to monadic expressions.
3083 @end deffn
3084
3085 @cindex state monad
3086 The @code{(guix monads)} module provides the @dfn{state monad}, which
3087 allows an additional value---the state---to be @emph{threaded} through
3088 monadic procedure calls.
3089
3090 @defvr {Scheme Variable} %state-monad
3091 The state monad. Procedures in the state monad can access and change
3092 the state that is threaded.
3093
3094 Consider the example below. The @code{square} procedure returns a value
3095 in the state monad. It returns the square of its argument, but also
3096 increments the current state value:
3097
3098 @example
3099 (define (square x)
3100 (mlet %state-monad ((count (current-state)))
3101 (mbegin %state-monad
3102 (set-current-state (+ 1 count))
3103 (return (* x x)))))
3104
3105 (run-with-state (sequence %state-monad (map square (iota 3))) 0)
3106 @result{} (0 1 4)
3107 @result{} 3
3108 @end example
3109
3110 When ``run'' through @var{%state-monad}, we obtain that additional state
3111 value, which is the number of @code{square} calls.
3112 @end defvr
3113
3114 @deffn {Monadic Procedure} current-state
3115 Return the current state as a monadic value.
3116 @end deffn
3117
3118 @deffn {Monadic Procedure} set-current-state @var{value}
3119 Set the current state to @var{value} and return the previous state as a
3120 monadic value.
3121 @end deffn
3122
3123 @deffn {Monadic Procedure} state-push @var{value}
3124 Push @var{value} to the current state, which is assumed to be a list,
3125 and return the previous state as a monadic value.
3126 @end deffn
3127
3128 @deffn {Monadic Procedure} state-pop
3129 Pop a value from the current state and return it as a monadic value.
3130 The state is assumed to be a list.
3131 @end deffn
3132
3133 @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3134 Run monadic value @var{mval} starting with @var{state} as the initial
3135 state. Return two values: the resulting value, and the resulting state.
3136 @end deffn
3137
3138 The main interface to the store monad, provided by the @code{(guix
3139 store)} module, is as follows.
3140
3141 @defvr {Scheme Variable} %store-monad
3142 The store monad---an alias for @var{%state-monad}.
3143
3144 Values in the store monad encapsulate accesses to the store. When its
3145 effect is needed, a value of the store monad must be ``evaluated'' by
3146 passing it to the @code{run-with-store} procedure (see below.)
3147 @end defvr
3148
3149 @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3150 Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3151 open store connection.
3152 @end deffn
3153
3154 @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
3155 Return as a monadic value the absolute file name in the store of the file
3156 containing @var{text}, a string. @var{references} is a list of store items that the
3157 resulting text file refers to; it defaults to the empty list.
3158 @end deffn
3159
3160 @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3161 [#:recursive? #t]
3162 Return the name of @var{file} once interned in the store. Use
3163 @var{name} as its store name, or the basename of @var{file} if
3164 @var{name} is omitted.
3165
3166 When @var{recursive?} is true, the contents of @var{file} are added
3167 recursively; if @var{file} designates a flat file and @var{recursive?}
3168 is true, its contents are added, and its permission bits are kept.
3169
3170 The example below adds a file to the store, under two different names:
3171
3172 @example
3173 (run-with-store (open-connection)
3174 (mlet %store-monad ((a (interned-file "README"))
3175 (b (interned-file "README" "LEGU-MIN")))
3176 (return (list a b))))
3177
3178 @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3179 @end example
3180
3181 @end deffn
3182
3183 The @code{(guix packages)} module exports the following package-related
3184 monadic procedures:
3185
3186 @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
3187 [#:system (%current-system)] [#:target #f] @
3188 [#:output "out"] Return as a monadic
3189 value in the absolute file name of @var{file} within the @var{output}
3190 directory of @var{package}. When @var{file} is omitted, return the name
3191 of the @var{output} directory of @var{package}. When @var{target} is
3192 true, use it as a cross-compilation target triplet.
3193 @end deffn
3194
3195 @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
3196 @deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3197 @var{target} [@var{system}]
3198 Monadic version of @code{package-derivation} and
3199 @code{package-cross-derivation} (@pxref{Defining Packages}).
3200 @end deffn
3201
3202
3203 @node G-Expressions
3204 @section G-Expressions
3205
3206 @cindex G-expression
3207 @cindex build code quoting
3208 So we have ``derivations'', which represent a sequence of build actions
3209 to be performed to produce an item in the store (@pxref{Derivations}).
3210 Those build actions are performed when asking the daemon to actually
3211 build the derivations; they are run by the daemon in a container
3212 (@pxref{Invoking guix-daemon}).
3213
3214 @cindex strata of code
3215 It should come as no surprise that we like to write those build actions
3216 in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3217 code@footnote{The term @dfn{stratum} in this context was coined by
3218 Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3219 Kiselyov, who has written insightful
3220 @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3221 on this topic}, refers to this kind of code generation as
3222 @dfn{staging}.}: the ``host code''---code that defines packages, talks
3223 to the daemon, etc.---and the ``build code''---code that actually
3224 performs build actions, such as making directories, invoking
3225 @command{make}, etc.
3226
3227 To describe a derivation and its build actions, one typically needs to
3228 embed build code inside host code. It boils down to manipulating build
3229 code as data, and Scheme's homoiconicity---code has a direct
3230 representation as data---comes in handy for that. But we need more than
3231 Scheme's normal @code{quasiquote} mechanism to construct build
3232 expressions.
3233
3234 The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3235 S-expressions adapted to build expressions. G-expressions, or
3236 @dfn{gexps}, consist essentially in three syntactic forms: @code{gexp},
3237 @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
3238 @code{#$}, and @code{#$@@}), which are comparable respectively to
3239 @code{quasiquote}, @code{unquote}, and @code{unquote-splicing}
3240 (@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile
3241 Reference Manual}). However, there are major differences:
3242
3243 @itemize
3244 @item
3245 Gexps are meant to be written to a file and run or manipulated by other
3246 processes.
3247
3248 @item
3249 When a high-level object such as a package or derivation is unquoted
3250 inside a gexp, the result is as if its output file name had been
3251 introduced.
3252
3253 @item
3254 Gexps carry information about the packages or derivations they refer to,
3255 and these dependencies are automatically added as inputs to the build
3256 processes that use them.
3257 @end itemize
3258
3259 @cindex lowering, of high-level objects in gexps
3260 This mechanism is not limited to package and derivation
3261 objects: @dfn{compilers} able to ``lower'' other high-level objects to
3262 derivations or files in the store can be defined,
3263 such that these objects can also be inserted
3264 into gexps. For example, a useful type of high-level object that can be
3265 inserted in a gexp is ``file-like objects'', which make it easy to
3266 add files to the store and refer to them in
3267 derivations and such (see @code{local-file} and @code{plain-file}
3268 below.)
3269
3270 To illustrate the idea, here is an example of a gexp:
3271
3272 @example
3273 (define build-exp
3274 #~(begin
3275 (mkdir #$output)
3276 (chdir #$output)
3277 (symlink (string-append #$coreutils "/bin/ls")
3278 "list-files")))
3279 @end example
3280
3281 This gexp can be passed to @code{gexp->derivation}; we obtain a
3282 derivation that builds a directory containing exactly one symlink to
3283 @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3284
3285 @example
3286 (gexp->derivation "the-thing" build-exp)
3287 @end example
3288
3289 As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
3290 substituted to the reference to the @var{coreutils} package in the
3291 actual build code, and @var{coreutils} is automatically made an input to
3292 the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
3293 output)}) is replaced by a string containing the derivation's output
3294 directory name.
3295
3296 @cindex cross compilation
3297 In a cross-compilation context, it is useful to distinguish between
3298 references to the @emph{native} build of a package---that can run on the
3299 host---versus references to cross builds of a package. To that end, the
3300 @code{#+} plays the same role as @code{#$}, but is a reference to a
3301 native package build:
3302
3303 @example
3304 (gexp->derivation "vi"
3305 #~(begin
3306 (mkdir #$output)
3307 (system* (string-append #+coreutils "/bin/ln")
3308 "-s"
3309 (string-append #$emacs "/bin/emacs")
3310 (string-append #$output "/bin/vi")))
3311 #:target "mips64el-linux")
3312 @end example
3313
3314 @noindent
3315 In the example above, the native build of @var{coreutils} is used, so
3316 that @command{ln} can actually run on the host; but then the
3317 cross-compiled build of @var{emacs} is referenced.
3318
3319 The syntactic form to construct gexps is summarized below.
3320
3321 @deffn {Scheme Syntax} #~@var{exp}
3322 @deffnx {Scheme Syntax} (gexp @var{exp})
3323 Return a G-expression containing @var{exp}. @var{exp} may contain one
3324 or more of the following forms:
3325
3326 @table @code
3327 @item #$@var{obj}
3328 @itemx (ungexp @var{obj})
3329 Introduce a reference to @var{obj}. @var{obj} may have one of the
3330 supported types, for example a package or a
3331 derivation, in which case the @code{ungexp} form is replaced by its
3332 output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3333
3334 If @var{obj} is a list, it is traversed and references to supported
3335 objects are substituted similarly.
3336
3337 If @var{obj} is another gexp, its contents are inserted and its
3338 dependencies are added to those of the containing gexp.
3339
3340 If @var{obj} is another kind of object, it is inserted as is.
3341
3342 @item #$@var{obj}:@var{output}
3343 @itemx (ungexp @var{obj} @var{output})
3344 This is like the form above, but referring explicitly to the
3345 @var{output} of @var{obj}---this is useful when @var{obj} produces
3346 multiple outputs (@pxref{Packages with Multiple Outputs}).
3347
3348 @item #+@var{obj}
3349 @itemx #+@var{obj}:output
3350 @itemx (ungexp-native @var{obj})
3351 @itemx (ungexp-native @var{obj} @var{output})
3352 Same as @code{ungexp}, but produces a reference to the @emph{native}
3353 build of @var{obj} when used in a cross compilation context.
3354
3355 @item #$output[:@var{output}]
3356 @itemx (ungexp output [@var{output}])
3357 Insert a reference to derivation output @var{output}, or to the main
3358 output when @var{output} is omitted.
3359
3360 This only makes sense for gexps passed to @code{gexp->derivation}.
3361
3362 @item #$@@@var{lst}
3363 @itemx (ungexp-splicing @var{lst})
3364 Like the above, but splices the contents of @var{lst} inside the
3365 containing list.
3366
3367 @item #+@@@var{lst}
3368 @itemx (ungexp-native-splicing @var{lst})
3369 Like the above, but refers to native builds of the objects listed in
3370 @var{lst}.
3371
3372 @end table
3373
3374 G-expressions created by @code{gexp} or @code{#~} are run-time objects
3375 of the @code{gexp?} type (see below.)
3376 @end deffn
3377
3378 @deffn {Scheme Procedure} gexp? @var{obj}
3379 Return @code{#t} if @var{obj} is a G-expression.
3380 @end deffn
3381
3382 G-expressions are meant to be written to disk, either as code building
3383 some derivation, or as plain files in the store. The monadic procedures
3384 below allow you to do that (@pxref{The Store Monad}, for more
3385 information about monads.)
3386
3387 @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
3388 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
3389 [#:hash #f] [#:hash-algo #f] @
3390 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3391 [#:module-path @var{%load-path}] @
3392 [#:references-graphs #f] [#:allowed-references #f] @
3393 [#:leaked-env-vars #f] @
3394 [#:script-name (string-append @var{name} "-builder")] @
3395 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3396 Return a derivation @var{name} that runs @var{exp} (a gexp) with
3397 @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3398 stored in a file called @var{script-name}. When @var{target} is true,
3399 it is used as the cross-compilation target triplet for packages referred
3400 to by @var{exp}.
3401
3402 Make @var{modules} available in the evaluation context of @var{exp};
3403 @var{modules} is a list of names of Guile modules searched in
3404 @var{module-path} to be copied in the store, compiled, and made available in
3405 the load path during the execution of @var{exp}---e.g., @code{((guix
3406 build utils) (guix build gnu-build-system))}.
3407
3408 @var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3409 applicable.
3410
3411 When @var{references-graphs} is true, it must be a list of tuples of one of the
3412 following forms:
3413
3414 @example
3415 (@var{file-name} @var{package})
3416 (@var{file-name} @var{package} @var{output})
3417 (@var{file-name} @var{derivation})
3418 (@var{file-name} @var{derivation} @var{output})
3419 (@var{file-name} @var{store-item})
3420 @end example
3421
3422 The right-hand-side of each element of @var{references-graphs} is automatically made
3423 an input of the build process of @var{exp}. In the build environment, each
3424 @var{file-name} contains the reference graph of the corresponding item, in a simple
3425 text format.
3426
3427 @var{allowed-references} must be either @code{#f} or a list of output names and packages.
3428 In the latter case, the list denotes store items that the result is allowed to
3429 refer to. Any reference to another store item will lead to a build error.
3430
3431 The other arguments are as for @code{derivation} (@pxref{Derivations}).
3432 @end deffn
3433
3434 @cindex file-like objects
3435 The @code{local-file}, @code{plain-file}, @code{computed-file},
3436 @code{program-file}, and @code{scheme-file} procedures below return
3437 @dfn{file-like objects}. That is, when unquoted in a G-expression,
3438 these objects lead to a file in the store. Consider this G-expression:
3439
3440 @example
3441 #~(system* (string-append #$glibc "/sbin/nscd") "-f"
3442 #$(local-file "/tmp/my-nscd.conf"))
3443 @end example
3444
3445 The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3446 to the store. Once expanded, for instance @i{via}
3447 @code{gexp->derivation}, the G-expression refers to that copy under
3448 @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3449 does not have any effect on what the G-expression does.
3450 @code{plain-file} can be used similarly; it differs in that the file
3451 content is directly passed as a string.
3452
3453 @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3454 [#:recursive? #t]
3455 Return an object representing local file @var{file} to add to the store; this
3456 object can be used in a gexp. @var{file} will be added to the store under @var{name}--by
3457 default the base name of @var{file}.
3458
3459 When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3460 designates a flat file and @var{recursive?} is true, its contents are added, and its
3461 permission bits are kept.
3462
3463 This is the declarative counterpart of the @code{interned-file} monadic
3464 procedure (@pxref{The Store Monad, @code{interned-file}}).
3465 @end deffn
3466
3467 @deffn {Scheme Procedure} plain-file @var{name} @var{content}
3468 Return an object representing a text file called @var{name} with the given
3469 @var{content} (a string) to be added to the store.
3470
3471 This is the declarative counterpart of @code{text-file}.
3472 @end deffn
3473
3474 @deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3475 [#:modules '()] [#:options '(#:local-build? #t)]
3476 Return an object representing the store item @var{name}, a file or
3477 directory computed by @var{gexp}. @var{modules} specifies the set of
3478 modules visible in the execution context of @var{gexp}. @var{options}
3479 is a list of additional arguments to pass to @code{gexp->derivation}.
3480
3481 This is the declarative counterpart of @code{gexp->derivation}.
3482 @end deffn
3483
3484 @deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3485 Return an executable script @var{name} that runs @var{exp} using
3486 @var{guile} with @var{modules} in its search path.
3487
3488 The example below builds a script that simply invokes the @command{ls}
3489 command:
3490
3491 @example
3492 (use-modules (guix gexp) (gnu packages base))
3493
3494 (gexp->script "list-files"
3495 #~(execl (string-append #$coreutils "/bin/ls")
3496 "ls"))
3497 @end example
3498
3499 When ``running'' it through the store (@pxref{The Store Monad,
3500 @code{run-with-store}}), we obtain a derivation that produces an
3501 executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3502
3503 @example
3504 #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3505 !#
3506 (execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3507 "ls")
3508 @end example
3509 @end deffn
3510
3511 @deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3512 [#:modules '()] [#:guile #f]
3513 Return an object representing the executable store item @var{name} that
3514 runs @var{gexp}. @var{guile} is the Guile package used to execute that
3515 script, and @var{modules} is the list of modules visible to that script.
3516
3517 This is the declarative counterpart of @code{gexp->script}.
3518 @end deffn
3519
3520 @deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3521 Return a derivation that builds a file @var{name} containing @var{exp}.
3522
3523 The resulting file holds references to all the dependencies of @var{exp}
3524 or a subset thereof.
3525 @end deffn
3526
3527 @deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3528 Return an object representing the Scheme file @var{name} that contains
3529 @var{exp}.
3530
3531 This is the declarative counterpart of @code{gexp->file}.
3532 @end deffn
3533
3534 @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3535 Return as a monadic value a derivation that builds a text file
3536 containing all of @var{text}. @var{text} may list, in addition to
3537 strings, objects of any type that can be used in a gexp: packages,
3538 derivations, local file objects, etc. The resulting store file holds
3539 references to all these.
3540
3541 This variant should be preferred over @code{text-file} anytime the file
3542 to create will reference items from the store. This is typically the
3543 case when building a configuration file that embeds store file names,
3544 like this:
3545
3546 @example
3547 (define (profile.sh)
3548 ;; Return the name of a shell script in the store that
3549 ;; initializes the 'PATH' environment variable.
3550 (text-file* "profile.sh"
3551 "export PATH=" coreutils "/bin:"
3552 grep "/bin:" sed "/bin\n"))
3553 @end example
3554
3555 In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3556 will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3557 preventing them from being garbage-collected during its lifetime.
3558 @end deffn
3559
3560 @deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3561 Return an object representing store file @var{name} containing
3562 @var{text}. @var{text} is a sequence of strings and file-like objects,
3563 as in:
3564
3565 @example
3566 (mixed-text-file "profile"
3567 "export PATH=" coreutils "/bin:" grep "/bin")
3568 @end example
3569
3570 This is the declarative counterpart of @code{text-file*}.
3571 @end deffn
3572
3573 Of course, in addition to gexps embedded in ``host'' code, there are
3574 also modules containing build tools. To make it clear that they are
3575 meant to be used in the build stratum, these modules are kept in the
3576 @code{(guix build @dots{})} name space.
3577
3578 @cindex lowering, of high-level objects in gexps
3579 Internally, high-level objects are @dfn{lowered}, using their compiler,
3580 to either derivations or store items. For instance, lowering a package
3581 yields a derivation, and lowering a @code{plain-file} yields a store
3582 item. This is achieved using the @code{lower-object} monadic procedure.
3583
3584 @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3585 [#:target #f]
3586 Return as a value in @var{%store-monad} the derivation or store item
3587 corresponding to @var{obj} for @var{system}, cross-compiling for
3588 @var{target} if @var{target} is true. @var{obj} must be an object that
3589 has an associated gexp compiler, such as a @code{<package>}.
3590 @end deffn
3591
3592
3593 @c *********************************************************************
3594 @node Utilities
3595 @chapter Utilities
3596
3597 This section describes tools primarily targeted at developers and users
3598 who write new package definitions. They complement the Scheme
3599 programming interface of Guix in a convenient way.
3600
3601 @menu
3602 * Invoking guix build:: Building packages from the command line.
3603 * Invoking guix edit:: Editing package definitions.
3604 * Invoking guix download:: Downloading a file and printing its hash.
3605 * Invoking guix hash:: Computing the cryptographic hash of a file.
3606 * Invoking guix import:: Importing package definitions.
3607 * Invoking guix refresh:: Updating package definitions.
3608 * Invoking guix lint:: Finding errors in package definitions.
3609 * Invoking guix size:: Profiling disk usage.
3610 * Invoking guix graph:: Visualizing the graph of packages.
3611 * Invoking guix environment:: Setting up development environments.
3612 * Invoking guix publish:: Sharing substitutes.
3613 * Invoking guix challenge:: Challenging substitute servers.
3614 * Invoking guix container:: Process isolation.
3615 @end menu
3616
3617 @node Invoking guix build
3618 @section Invoking @command{guix build}
3619
3620 The @command{guix build} command builds packages or derivations and
3621 their dependencies, and prints the resulting store paths. Note that it
3622 does not modify the user's profile---this is the job of the
3623 @command{guix package} command (@pxref{Invoking guix package}). Thus,
3624 it is mainly useful for distribution developers.
3625
3626 The general syntax is:
3627
3628 @example
3629 guix build @var{options} @var{package-or-derivation}@dots{}
3630 @end example
3631
3632 @var{package-or-derivation} may be either the name of a package found in
3633 the software distribution such as @code{coreutils} or
3634 @code{coreutils-8.20}, or a derivation such as
3635 @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
3636 package with the corresponding name (and optionally version) is searched
3637 for among the GNU distribution modules (@pxref{Package Modules}).
3638
3639 Alternatively, the @code{--expression} option may be used to specify a
3640 Scheme expression that evaluates to a package; this is useful when
3641 disambiguation among several same-named packages or package variants is
3642 needed.
3643
3644 The @var{options} may be zero or more of the following:
3645
3646 @table @code
3647
3648 @item --file=@var{file}
3649 @itemx -f @var{file}
3650
3651 Build the package or derivation that the code within @var{file}
3652 evaluates to.
3653
3654 As an example, @var{file} might contain a package definition like this
3655 (@pxref{Defining Packages}):
3656
3657 @example
3658 @verbatiminclude package-hello.scm
3659 @end example
3660
3661 @item --expression=@var{expr}
3662 @itemx -e @var{expr}
3663 Build the package or derivation @var{expr} evaluates to.
3664
3665 For example, @var{expr} may be @code{(@@ (gnu packages guile)
3666 guile-1.8)}, which unambiguously designates this specific variant of
3667 version 1.8 of Guile.
3668
3669 Alternately, @var{expr} may be a G-expression, in which case it is used
3670 as a build program passed to @code{gexp->derivation}
3671 (@pxref{G-Expressions}).
3672
3673 Lastly, @var{expr} may refer to a zero-argument monadic procedure
3674 (@pxref{The Store Monad}). The procedure must return a derivation as a
3675 monadic value, which is then passed through @code{run-with-store}.
3676
3677 @item --source
3678 @itemx -S
3679 Build the packages' source derivations, rather than the packages
3680 themselves.
3681
3682 For instance, @code{guix build -S gcc} returns something like
3683 @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
3684
3685 The returned source tarball is the result of applying any patches and
3686 code snippets specified in the package's @code{origin} (@pxref{Defining
3687 Packages}).
3688
3689 @item --sources
3690 Fetch and return the source of @var{package-or-derivation} and all their
3691 dependencies, recursively. This is a handy way to obtain a local copy
3692 of all the source code needed to build @var{packages}, allowing you to
3693 eventually build them even without network access. It is an extension
3694 of the @code{--source} option and can accept one of the following
3695 optional argument values:
3696
3697 @table @code
3698 @item package
3699 This value causes the @code{--sources} option to behave in the same way
3700 as the @code{--source} option.
3701
3702 @item all
3703 Build all packages' source derivations, including any source that might
3704 be listed as @code{inputs}. This is the default value.
3705
3706 @example
3707 $ guix build --sources tzdata
3708 The following derivations will be built:
3709 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
3710 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3711 @end example
3712
3713 @item transitive
3714 Build all packages' source derivations, as well as all source
3715 derivations for packages' transitive inputs. This can be used e.g. to
3716 prefetch package source for later offline building.
3717
3718 @example
3719 $ guix build --sources=transitive tzdata
3720 The following derivations will be built:
3721 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3722 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
3723 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
3724 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
3725 /gnu/store/@dots{}-make-4.1.tar.xz.drv
3726 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
3727 @dots{}
3728 @end example
3729
3730 @end table
3731
3732 @item --system=@var{system}
3733 @itemx -s @var{system}
3734 Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
3735 the host's system type.
3736
3737 An example use of this is on Linux-based systems, which can emulate
3738 different personalities. For instance, passing
3739 @code{--system=i686-linux} on an @code{x86_64-linux} system allows users
3740 to build packages in a complete 32-bit environment.
3741
3742 @item --target=@var{triplet}
3743 @cindex cross-compilation
3744 Cross-build for @var{triplet}, which must be a valid GNU triplet, such
3745 as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
3746 configuration triplets,, configure, GNU Configure and Build System}).
3747
3748 @item --with-source=@var{source}
3749 Use @var{source} as the source of the corresponding package.
3750 @var{source} must be a file name or a URL, as for @command{guix
3751 download} (@pxref{Invoking guix download}).
3752
3753 The ``corresponding package'' is taken to be one specified on the
3754 command line whose name matches the base of @var{source}---e.g., if
3755 @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
3756 package is @code{guile}. Likewise, the version string is inferred from
3757 @var{source}; in the previous example, it's @code{2.0.10}.
3758
3759 This option allows users to try out versions of packages other than the
3760 one provided by the distribution. The example below downloads
3761 @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
3762 the @code{ed} package:
3763
3764 @example
3765 guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
3766 @end example
3767
3768 As a developer, @code{--with-source} makes it easy to test release
3769 candidates:
3770
3771 @example
3772 guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
3773 @end example
3774
3775 @dots{} or to build from a checkout in a pristine environment:
3776
3777 @example
3778 $ git clone git://git.sv.gnu.org/guix.git
3779 $ guix build guix --with-source=./guix
3780 @end example
3781
3782 @item --no-grafts
3783 Do not ``graft'' packages. In practice, this means that package updates
3784 available as grafts are not applied. @xref{Security Updates}, for more
3785 information on grafts.
3786
3787 @item --derivations
3788 @itemx -d
3789 Return the derivation paths, not the output paths, of the given
3790 packages.
3791
3792 @item --root=@var{file}
3793 @itemx -r @var{file}
3794 Make @var{file} a symlink to the result, and register it as a garbage
3795 collector root.
3796
3797 @item --log-file
3798 Return the build log file names or URLs for the given
3799 @var{package-or-derivation}s, or raise an error if build logs are
3800 missing.
3801
3802 This works regardless of how packages or derivations are specified. For
3803 instance, the following invocations are equivalent:
3804
3805 @example
3806 guix build --log-file `guix build -d guile`
3807 guix build --log-file `guix build guile`
3808 guix build --log-file guile
3809 guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
3810 @end example
3811
3812 If a log is unavailable locally, and unless @code{--no-substitutes} is
3813 passed, the command looks for a corresponding log on one of the
3814 substitute servers (as specified with @code{--substitute-urls}.)
3815
3816 So for instance, let's say you want to see the build log of GDB on MIPS
3817 but you're actually on an @code{x86_64} machine:
3818
3819 @example
3820 $ guix build --log-file gdb -s mips64el-linux
3821 http://hydra.gnu.org/log/@dots{}-gdb-7.10
3822 @end example
3823
3824 You can freely access a huge library of build logs!
3825 @end table
3826
3827 @cindex common build options
3828 In addition, a number of options that control the build process are
3829 common to @command{guix build} and other commands that can spawn builds,
3830 such as @command{guix package} or @command{guix archive}. These are the
3831 following:
3832
3833 @table @code
3834
3835 @item --load-path=@var{directory}
3836 @itemx -L @var{directory}
3837 Add @var{directory} to the front of the package module search path
3838 (@pxref{Package Modules}).
3839
3840 This allows users to define their own packages and make them visible to
3841 the command-line tools.
3842
3843 @item --keep-failed
3844 @itemx -K
3845 Keep the build tree of failed builds. Thus, if a build fail, its build
3846 tree is kept under @file{/tmp}, in a directory whose name is shown at
3847 the end of the build log. This is useful when debugging build issues.
3848
3849 @item --dry-run
3850 @itemx -n
3851 Do not build the derivations.
3852
3853 @item --fallback
3854 When substituting a pre-built binary fails, fall back to building
3855 packages locally.
3856
3857 @item --substitute-urls=@var{urls}
3858 @anchor{client-substitute-urls}
3859 Consider @var{urls} the whitespace-separated list of substitute source
3860 URLs, overriding the default list of URLs of @command{guix-daemon}
3861 (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3862
3863 This means that substitutes may be downloaded from @var{urls}, provided
3864 they are signed by a key authorized by the system administrator
3865 (@pxref{Substitutes}).
3866
3867 @item --no-substitutes
3868 Do not use substitutes for build products. That is, always build things
3869 locally instead of allowing downloads of pre-built binaries
3870 (@pxref{Substitutes}).
3871
3872 @item --no-build-hook
3873 Do not attempt to offload builds @i{via} the daemon's ``build hook''
3874 (@pxref{Daemon Offload Setup}). That is, always build things locally
3875 instead of offloading builds to remote machines.
3876
3877 @item --max-silent-time=@var{seconds}
3878 When the build or substitution process remains silent for more than
3879 @var{seconds}, terminate it and report a build failure.
3880
3881 @item --timeout=@var{seconds}
3882 Likewise, when the build or substitution process lasts for more than
3883 @var{seconds}, terminate it and report a build failure.
3884
3885 By default there is no timeout. This behavior can be restored with
3886 @code{--timeout=0}.
3887
3888 @item --verbosity=@var{level}
3889 Use the given verbosity level. @var{level} must be an integer between 0
3890 and 5; higher means more verbose output. Setting a level of 4 or more
3891 may be helpful when debugging setup issues with the build daemon.
3892
3893 @item --cores=@var{n}
3894 @itemx -c @var{n}
3895 Allow the use of up to @var{n} CPU cores for the build. The special
3896 value @code{0} means to use as many CPU cores as available.
3897
3898 @item --max-jobs=@var{n}
3899 @itemx -M @var{n}
3900 Allow at most @var{n} build jobs in parallel. @xref{Invoking
3901 guix-daemon, @code{--max-jobs}}, for details about this option and the
3902 equivalent @command{guix-daemon} option.
3903
3904 @end table
3905
3906 Behind the scenes, @command{guix build} is essentially an interface to
3907 the @code{package-derivation} procedure of the @code{(guix packages)}
3908 module, and to the @code{build-derivations} procedure of the @code{(guix
3909 derivations)} module.
3910
3911 In addition to options explicitly passed on the command line,
3912 @command{guix build} and other @command{guix} commands that support
3913 building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
3914
3915 @defvr {Environment Variable} GUIX_BUILD_OPTIONS
3916 Users can define this variable to a list of command line options that
3917 will automatically be used by @command{guix build} and other
3918 @command{guix} commands that can perform builds, as in the example
3919 below:
3920
3921 @example
3922 $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
3923 @end example
3924
3925 These options are parsed independently, and the result is appended to
3926 the parsed command-line options.
3927 @end defvr
3928
3929
3930 @node Invoking guix edit
3931 @section Invoking @command{guix edit}
3932
3933 @cindex package definition, editing
3934 So many packages, so many source files! The @command{guix edit} command
3935 facilitates the life of packagers by pointing their editor at the source
3936 file containing the definition of the specified packages. For instance:
3937
3938 @example
3939 guix edit gcc-4.8 vim
3940 @end example
3941
3942 @noindent
3943 launches the program specified in the @code{VISUAL} or in the
3944 @code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
3945 and that of Vim.
3946
3947 If you are using Emacs, note that the Emacs user interface provides
3948 similar functionality in the ``package info'' and ``package list''
3949 buffers created by @kbd{M-x guix-search-by-name} and similar commands
3950 (@pxref{Emacs Commands}).
3951
3952
3953 @node Invoking guix download
3954 @section Invoking @command{guix download}
3955
3956 When writing a package definition, developers typically need to download
3957 the package's source tarball, compute its SHA256 hash, and write that
3958 hash in the package definition (@pxref{Defining Packages}). The
3959 @command{guix download} tool helps with this task: it downloads a file
3960 from the given URI, adds it to the store, and prints both its file name
3961 in the store and its SHA256 hash.
3962
3963 The fact that the downloaded file is added to the store saves bandwidth:
3964 when the developer eventually tries to build the newly defined package
3965 with @command{guix build}, the source tarball will not have to be
3966 downloaded again because it is already in the store. It is also a
3967 convenient way to temporarily stash files, which may be deleted
3968 eventually (@pxref{Invoking guix gc}).
3969
3970 The @command{guix download} command supports the same URIs as used in
3971 package definitions. In particular, it supports @code{mirror://} URIs.
3972 @code{https} URIs (HTTP over TLS) are supported @emph{provided} the
3973 Guile bindings for GnuTLS are available in the user's environment; when
3974 they are not available, an error is raised. @xref{Guile Preparations,
3975 how to install the GnuTLS bindings for Guile,, gnutls-guile,
3976 GnuTLS-Guile}, for more information.
3977
3978 The following option is available:
3979
3980 @table @code
3981 @item --format=@var{fmt}
3982 @itemx -f @var{fmt}
3983 Write the hash in the format specified by @var{fmt}. For more
3984 information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
3985 @end table
3986
3987 @node Invoking guix hash
3988 @section Invoking @command{guix hash}
3989
3990 The @command{guix hash} command computes the SHA256 hash of a file.
3991 It is primarily a convenience tool for anyone contributing to the
3992 distribution: it computes the cryptographic hash of a file, which can be
3993 used in the definition of a package (@pxref{Defining Packages}).
3994
3995 The general syntax is:
3996
3997 @example
3998 guix hash @var{option} @var{file}
3999 @end example
4000
4001 @command{guix hash} has the following option:
4002
4003 @table @code
4004
4005 @item --format=@var{fmt}
4006 @itemx -f @var{fmt}
4007 Write the hash in the format specified by @var{fmt}.
4008
4009 Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4010 (@code{hex} and @code{hexadecimal} can be used as well).
4011
4012 If the @option{--format} option is not specified, @command{guix hash}
4013 will output the hash in @code{nix-base32}. This representation is used
4014 in the definitions of packages.
4015
4016 @item --recursive
4017 @itemx -r
4018 Compute the hash on @var{file} recursively.
4019
4020 In this case, the hash is computed on an archive containing @var{file},
4021 including its children if it is a directory. Some of @var{file}'s
4022 meta-data is part of the archive; for instance, when @var{file} is a
4023 regular file, the hash is different depending on whether @var{file} is
4024 executable or not. Meta-data such as time stamps has no impact on the
4025 hash (@pxref{Invoking guix archive}).
4026 @c FIXME: Replace xref above with xref to an ``Archive'' section when
4027 @c it exists.
4028
4029 @end table
4030
4031 @node Invoking guix import
4032 @section Invoking @command{guix import}
4033
4034 @cindex importing packages
4035 @cindex package import
4036 @cindex package conversion
4037 The @command{guix import} command is useful for people willing to add a
4038 package to the distribution but who'd rather do as little work as
4039 possible to get there---a legitimate demand. The command knows of a few
4040 repositories from which it can ``import'' package meta-data. The result
4041 is a package definition, or a template thereof, in the format we know
4042 (@pxref{Defining Packages}).
4043
4044 The general syntax is:
4045
4046 @example
4047 guix import @var{importer} @var{options}@dots{}
4048 @end example
4049
4050 @var{importer} specifies the source from which to import package
4051 meta-data, and @var{options} specifies a package identifier and other
4052 options specific to @var{importer}. Currently, the available
4053 ``importers'' are:
4054
4055 @table @code
4056 @item gnu
4057 Import meta-data for the given GNU package. This provides a template
4058 for the latest version of that GNU package, including the hash of its
4059 source tarball, and its canonical synopsis and description.
4060
4061 Additional information such as the package's dependencies and its
4062 license needs to be figured out manually.
4063
4064 For example, the following command returns a package definition for
4065 GNU@tie{}Hello:
4066
4067 @example
4068 guix import gnu hello
4069 @end example
4070
4071 Specific command-line options are:
4072
4073 @table @code
4074 @item --key-download=@var{policy}
4075 As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4076 keys when verifying the package's signature. @xref{Invoking guix
4077 refresh, @code{--key-download}}.
4078 @end table
4079
4080 @item pypi
4081 @cindex pypi
4082 Import meta-data from the @uref{https://pypi.python.org/, Python Package
4083 Index}@footnote{This functionality requires Guile-JSON to be installed.
4084 @xref{Requirements}.}. Information is taken from the JSON-formatted
4085 description available at @code{pypi.python.org} and usually includes all
4086 the relevant information, including package dependencies.
4087
4088 The command below imports meta-data for the @code{itsdangerous} Python
4089 package:
4090
4091 @example
4092 guix import pypi itsdangerous
4093 @end example
4094
4095 @item gem
4096 @cindex gem
4097 Import meta-data from @uref{https://rubygems.org/,
4098 RubyGems}@footnote{This functionality requires Guile-JSON to be
4099 installed. @xref{Requirements}.}. Information is taken from the
4100 JSON-formatted description available at @code{rubygems.org} and includes
4101 most relevant information, including runtime dependencies. There are
4102 some caveats, however. The meta-data doesn't distinguish between
4103 synopses and descriptions, so the same string is used for both fields.
4104 Additionally, the details of non-Ruby dependencies required to build
4105 native extensions is unavailable and left as an exercise to the
4106 packager.
4107
4108 The command below imports meta-data for the @code{rails} Ruby package:
4109
4110 @example
4111 guix import gem rails
4112 @end example
4113
4114 @item cpan
4115 @cindex CPAN
4116 Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}.
4117 Information is taken from the JSON-formatted meta-data provided through
4118 @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
4119 relevant information, such as module dependencies. License information
4120 should be checked closely. If Perl is available in the store, then the
4121 @code{corelist} utility will be used to filter core modules out of the
4122 list of dependencies.
4123
4124 The command command below imports meta-data for the @code{Acme::Boolean}
4125 Perl module:
4126
4127 @example
4128 guix import cpan Acme::Boolean
4129 @end example
4130
4131 @item cran
4132 @cindex CRAN
4133 Import meta-data from @uref{http://cran.r-project.org/, CRAN}, the
4134 central repository for the @uref{http://r-project.org, GNU@tie{}R
4135 statistical and graphical environment}.
4136
4137 Information is extracted from the HTML package description.
4138
4139 The command command below imports meta-data for the @code{Cairo}
4140 R package:
4141
4142 @example
4143 guix import cran Cairo
4144 @end example
4145
4146 @item nix
4147 Import meta-data from a local copy of the source of the
4148 @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4149 relies on the @command{nix-instantiate} command of
4150 @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4151 typically written in a mixture of Nix-language and Bash code. This
4152 command only imports the high-level package structure that is written in
4153 the Nix language. It normally includes all the basic fields of a
4154 package definition.
4155
4156 When importing a GNU package, the synopsis and descriptions are replaced
4157 by their canonical upstream variant.
4158
4159 As an example, the command below imports the package definition of
4160 LibreOffice (more precisely, it imports the definition of the package
4161 bound to the @code{libreoffice} top-level attribute):
4162
4163 @example
4164 guix import nix ~/path/to/nixpkgs libreoffice
4165 @end example
4166
4167 @item hackage
4168 @cindex hackage
4169 Import meta-data from Haskell community's central package archive
4170 @uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4171 Cabal files and includes all the relevant information, including package
4172 dependencies.
4173
4174 Specific command-line options are:
4175
4176 @table @code
4177 @item --stdin
4178 @itemx -s
4179 Read a Cabal file from the standard input.
4180 @item --no-test-dependencies
4181 @itemx -t
4182 Do not include dependencies required by the test suites only.
4183 @item --cabal-environment=@var{alist}
4184 @itemx -e @var{alist}
4185 @var{alist} is a Scheme alist defining the environment in which the
4186 Cabal conditionals are evaluated. The accepted keys are: @code{os},
4187 @code{arch}, @code{impl} and a string representing the name of a flag.
4188 The value associated with a flag has to be either the symbol
4189 @code{true} or @code{false}. The value associated with other keys
4190 has to conform to the Cabal file format definition. The default value
4191 associated with the keys @code{os}, @code{arch} and @code{impl} is
4192 @samp{linux}, @samp{x86_64} and @samp{ghc} respectively.
4193 @end table
4194
4195 The command below imports meta-data for the latest version of the
4196 @code{HTTP} Haskell package without including test dependencies and
4197 specifying the value of the flag @samp{network-uri} as @code{false}:
4198
4199 @example
4200 guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
4201 @end example
4202
4203 A specific package version may optionally be specified by following the
4204 package name by a hyphen and a version number as in the following example:
4205
4206 @example
4207 guix import hackage mtl-2.1.3.1
4208 @end example
4209
4210 @item elpa
4211 @cindex elpa
4212 Import meta-data from an Emacs Lisp Package Archive (ELPA) package
4213 repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4214
4215 Specific command-line options are:
4216
4217 @table @code
4218 @item --archive=@var{repo}
4219 @itemx -a @var{repo}
4220 @var{repo} identifies the archive repository from which to retrieve the
4221 information. Currently the supported repositories and their identifiers
4222 are:
4223 @itemize -
4224 @item
4225 @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
4226 identifier. This is the default.
4227
4228 @item
4229 @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
4230 @code{melpa-stable} identifier.
4231
4232 @item
4233 @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
4234 identifier.
4235 @end itemize
4236 @end table
4237 @end table
4238
4239 The structure of the @command{guix import} code is modular. It would be
4240 useful to have more importers for other package formats, and your help
4241 is welcome here (@pxref{Contributing}).
4242
4243 @node Invoking guix refresh
4244 @section Invoking @command{guix refresh}
4245
4246 The primary audience of the @command{guix refresh} command is developers
4247 of the GNU software distribution. By default, it reports any packages
4248 provided by the distribution that are outdated compared to the latest
4249 upstream version, like this:
4250
4251 @example
4252 $ guix refresh
4253 gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4254 gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4255 @end example
4256
4257 It does so by browsing each package's FTP directory and determining the
4258 highest version number of the source tarballs therein. The command
4259 knows how to update specific types of packages: GNU packages, ELPA
4260 packages, etc.---see the documentation for @option{--type} below. The
4261 are many packages, though, for which it lacks a method to determine
4262 whether a new upstream release is available. However, the mechanism is
4263 extensible, so feel free to get in touch with us to add a new method!
4264
4265 When passed @code{--update}, it modifies distribution source files to
4266 update the version numbers and source tarball hashes of those packages'
4267 recipes (@pxref{Defining Packages}). This is achieved by downloading
4268 each package's latest source tarball and its associated OpenPGP
4269 signature, authenticating the downloaded tarball against its signature
4270 using @command{gpg}, and finally computing its hash. When the public
4271 key used to sign the tarball is missing from the user's keyring, an
4272 attempt is made to automatically retrieve it from a public key server;
4273 when it's successful, the key is added to the user's keyring; otherwise,
4274 @command{guix refresh} reports an error.
4275
4276 The following options are supported:
4277
4278 @table @code
4279
4280 @item --expression=@var{expr}
4281 @itemx -e @var{expr}
4282 Consider the package @var{expr} evaluates to.
4283
4284 This is useful to precisely refer to a package, as in this example:
4285
4286 @example
4287 guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4288 @end example
4289
4290 This command lists the dependents of the ``final'' libc (essentially all
4291 the packages.)
4292
4293 @item --update
4294 @itemx -u
4295 Update distribution source files (package recipes) in place. This is
4296 usually run from a checkout of the Guix source tree (@pxref{Running
4297 Guix Before It Is Installed}):
4298
4299 @example
4300 $ ./pre-inst-env guix refresh -s non-core
4301 @end example
4302
4303 @xref{Defining Packages}, for more information on package definitions.
4304
4305 @item --select=[@var{subset}]
4306 @itemx -s @var{subset}
4307 Select all the packages in @var{subset}, one of @code{core} or
4308 @code{non-core}.
4309
4310 The @code{core} subset refers to all the packages at the core of the
4311 distribution---i.e., packages that are used to build ``everything
4312 else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4313 changing one of these packages in the distribution entails a rebuild of
4314 all the others. Thus, such updates are an inconvenience to users in
4315 terms of build time or bandwidth used to achieve the upgrade.
4316
4317 The @code{non-core} subset refers to the remaining packages. It is
4318 typically useful in cases where an update of the core packages would be
4319 inconvenient.
4320
4321 @item --type=@var{updater}
4322 @itemx -t @var{updater}
4323 Select only packages handled by @var{updater} (may be a comma-separated
4324 list of updaters). Currently, @var{updater} may be one of:
4325
4326 @table @code
4327 @item gnu
4328 the updater for GNU packages;
4329 @item elpa
4330 the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4331 @item cran
4332 the updater for @uref{http://cran.r-project.org/, CRAN} packages;
4333 @item pypi
4334 the updater for @uref{https://pypi.python.org, PyPI} packages.
4335 @end table
4336
4337 For instance, the following commands only checks for updates of Emacs
4338 packages hosted at @code{elpa.gnu.org} and updates of CRAN packages:
4339
4340 @example
4341 $ guix refresh --type=elpa,cran
4342 gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
4343 gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4344 @end example
4345
4346 @end table
4347
4348 In addition, @command{guix refresh} can be passed one or more package
4349 names, as in this example:
4350
4351 @example
4352 $ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
4353 @end example
4354
4355 @noindent
4356 The command above specifically updates the @code{emacs} and
4357 @code{idutils} packages. The @code{--select} option would have no
4358 effect in this case.
4359
4360 When considering whether to upgrade a package, it is sometimes
4361 convenient to know which packages would be affected by the upgrade and
4362 should be checked for compatibility. For this the following option may
4363 be used when passing @command{guix refresh} one or more package names:
4364
4365 @table @code
4366
4367 @item --list-updaters
4368 @itemx -L
4369 List available updaters and exit (see @option{--type} above.)
4370
4371 @item --list-dependent
4372 @itemx -l
4373 List top-level dependent packages that would need to be rebuilt as a
4374 result of upgrading one or more packages.
4375
4376 @end table
4377
4378 Be aware that the @code{--list-dependent} option only
4379 @emph{approximates} the rebuilds that would be required as a result of
4380 an upgrade. More rebuilds might be required under some circumstances.
4381
4382 @example
4383 $ guix refresh --list-dependent flex
4384 Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4385 hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
4386 @end example
4387
4388 The command above lists a set of packages that could be built to check
4389 for compatibility with an upgraded @code{flex} package.
4390
4391 The following options can be used to customize GnuPG operation:
4392
4393 @table @code
4394
4395 @item --gpg=@var{command}
4396 Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4397 for in @code{$PATH}.
4398
4399 @item --key-download=@var{policy}
4400 Handle missing OpenPGP keys according to @var{policy}, which may be one
4401 of:
4402
4403 @table @code
4404 @item always
4405 Always download missing OpenPGP keys from the key server, and add them
4406 to the user's GnuPG keyring.
4407
4408 @item never
4409 Never try to download missing OpenPGP keys. Instead just bail out.
4410
4411 @item interactive
4412 When a package signed with an unknown OpenPGP key is encountered, ask
4413 the user whether to download it or not. This is the default behavior.
4414 @end table
4415
4416 @item --key-server=@var{host}
4417 Use @var{host} as the OpenPGP key server when importing a public key.
4418
4419 @end table
4420
4421 @node Invoking guix lint
4422 @section Invoking @command{guix lint}
4423 The @command{guix lint} is meant to help package developers avoid common
4424 errors and use a consistent style. It runs a number of checks on a
4425 given set of packages in order to find common mistakes in their
4426 definitions. Available @dfn{checkers} include (see
4427 @code{--list-checkers} for a complete list):
4428
4429 @table @code
4430 @item synopsis
4431 @itemx description
4432 Validate certain typographical and stylistic rules about package
4433 descriptions and synopses.
4434
4435 @item inputs-should-be-native
4436 Identify inputs that should most likely be native inputs.
4437
4438 @item source
4439 @itemx home-page
4440 @itemx source-file-name
4441 Probe @code{home-page} and @code{source} URLs and report those that are
4442 invalid. Check that the source file name is meaningful, e.g. is not
4443 just a version number or ``git-checkout'', and should not have a
4444 @code{file-name} declared (@pxref{origin Reference}).
4445
4446 @item formatting
4447 Warn about obvious source code formatting issues: trailing white space,
4448 use of tabulations, etc.
4449 @end table
4450
4451 The general syntax is:
4452
4453 @example
4454 guix lint @var{options} @var{package}@dots{}
4455 @end example
4456
4457 If no package is given on the command line, then all packages are checked.
4458 The @var{options} may be zero or more of the following:
4459
4460 @table @code
4461
4462 @item --checkers
4463 @itemx -c
4464 Only enable the checkers specified in a comma-separated list using the
4465 names returned by @code{--list-checkers}.
4466
4467 @item --list-checkers
4468 @itemx -l
4469 List and describe all the available checkers that will be run on packages
4470 and exit.
4471
4472 @end table
4473
4474 @node Invoking guix size
4475 @section Invoking @command{guix size}
4476
4477 The @command{guix size} command helps package developers profile the
4478 disk usage of packages. It is easy to overlook the impact of an
4479 additional dependency added to a package, or the impact of using a
4480 single output for a package that could easily be split (@pxref{Packages
4481 with Multiple Outputs}). These are the typical issues that
4482 @command{guix size} can highlight.
4483
4484 The command can be passed a package specification such as @code{gcc-4.8}
4485 or @code{guile:debug}, or a file name in the store. Consider this
4486 example:
4487
4488 @example
4489 $ guix size coreutils
4490 store item total self
4491 /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4492 /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4493 /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4494 /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4495 /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4496 /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4497 @end example
4498
4499 @cindex closure
4500 The store items listed here constitute the @dfn{transitive closure} of
4501 Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4502 would be returned by:
4503
4504 @example
4505 $ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4506 @end example
4507
4508 Here the output shows 3 columns next to store items. The first column,
4509 labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4510 the store item---that is, its own size plus the size of all its
4511 dependencies. The next column, labeled ``self'', shows the size of the
4512 item itself. The last column shows the ratio of the item's size to the
4513 space occupied by all the items listed here.
4514
4515 In this example, we see that the closure of Coreutils weighs in at
4516 70@tie{}MiB, half of which is taken by libc. (That libc represents a
4517 large fraction of the closure is not a problem @i{per se} because it is
4518 always available on the system anyway.)
4519
4520 When the package passed to @command{guix size} is available in the
4521 store, @command{guix size} queries the daemon to determine its
4522 dependencies, and measures its size in the store, similar to @command{du
4523 -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4524 Coreutils}).
4525
4526 When the given package is @emph{not} in the store, @command{guix size}
4527 reports information based on information about the available substitutes
4528 (@pxref{Substitutes}). This allows it to profile disk usage of store
4529 items that are not even on disk, only available remotely.
4530
4531 The available options are:
4532
4533 @table @option
4534
4535 @item --substitute-urls=@var{urls}
4536 Use substitute information from @var{urls}.
4537 @xref{client-substitute-urls, the same option for @code{guix build}}.
4538
4539 @item --map-file=@var{file}
4540 Write to @var{file} a graphical map of disk usage as a PNG file.
4541
4542 For the example above, the map looks like this:
4543
4544 @image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4545 produced by @command{guix size}}
4546
4547 This option requires that
4548 @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4549 installed and visible in Guile's module search path. When that is not
4550 the case, @command{guix size} fails as it tries to load it.
4551
4552 @item --system=@var{system}
4553 @itemx -s @var{system}
4554 Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4555
4556 @end table
4557
4558 @node Invoking guix graph
4559 @section Invoking @command{guix graph}
4560
4561 @cindex DAG
4562 Packages and their dependencies form a @dfn{graph}, specifically a
4563 directed acyclic graph (DAG). It can quickly become difficult to have a
4564 mental model of the package DAG, so the @command{guix graph} command is
4565 here to provide a visual representation of the DAG. @command{guix
4566 graph} emits a DAG representation in the input format of
4567 @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
4568 directly to Graphviz's @command{dot} command, for instance. The general
4569 syntax is:
4570
4571 @example
4572 guix graph @var{options} @var{package}@dots{}
4573 @end example
4574
4575 For example, the following command generates a PDF file representing the
4576 package DAG for the GNU@tie{}Core Utilities, showing its build-time
4577 dependencies:
4578
4579 @example
4580 guix graph coreutils | dot -Tpdf > dag.pdf
4581 @end example
4582
4583 The output looks like this:
4584
4585 @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4586
4587 Nice little graph, no?
4588
4589 But there's more than one graph! The one above is concise: it's the
4590 graph of package objects, omitting implicit inputs such as GCC, libc,
4591 grep, etc. It's often useful to have such a concise graph, but
4592 sometimes you want to see more details. @command{guix graph} supports
4593 several types of graphs, allowing you to choose the level of details:
4594
4595 @table @code
4596 @item package
4597 This is the default type, the one we used above. It shows the DAG of
4598 package objects, excluding implicit dependencies. It is concise, but
4599 filters out many details.
4600
4601 @item bag-emerged
4602 This is the package DAG, @emph{including} implicit inputs.
4603
4604 For instance, the following command:
4605
4606 @example
4607 guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4608 @end example
4609
4610 ... yields this bigger graph:
4611
4612 @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4613
4614 At the bottom of the graph, we see all the implicit inputs of
4615 @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4616
4617 Now, note that the dependencies of those implicit inputs---that is, the
4618 @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4619 here, for conciseness.
4620
4621 @item bag
4622 Similar to @code{bag-emerged}, but this time including all the bootstrap
4623 dependencies.
4624
4625 @item derivations
4626 This is the most detailed representation: It shows the DAG of
4627 derivations (@pxref{Derivations}) and plain store items. Compared to
4628 the above representation, many additional nodes are visible, including
4629 builds scripts, patches, Guile modules, etc.
4630
4631 @end table
4632
4633 All the above types correspond to @emph{build-time dependencies}. The
4634 following graph type represents the @emph{run-time dependencies}:
4635
4636 @table @code
4637 @item references
4638 This is the graph of @dfn{references} of a package output, as returned
4639 by @command{guix gc --references} (@pxref{Invoking guix gc}).
4640
4641 If the given package output is not available in the store, @command{guix
4642 graph} attempts to obtain dependency information from substitutes.
4643 @end table
4644
4645 The available options are the following:
4646
4647 @table @option
4648 @item --type=@var{type}
4649 @itemx -t @var{type}
4650 Produce a graph output of @var{type}, where @var{type} must be one of
4651 the values listed above.
4652
4653 @item --list-types
4654 List the supported graph types.
4655
4656 @item --expression=@var{expr}
4657 @itemx -e @var{expr}
4658 Consider the package @var{expr} evaluates to.
4659
4660 This is useful to precisely refer to a package, as in this example:
4661
4662 @example
4663 guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
4664 @end example
4665 @end table
4666
4667
4668 @node Invoking guix environment
4669 @section Invoking @command{guix environment}
4670
4671 @cindex reproducible build environments
4672 @cindex development environments
4673 The purpose of @command{guix environment} is to assist hackers in
4674 creating reproducible development environments without polluting their
4675 package profile. The @command{guix environment} tool takes one or more
4676 packages, builds all of the necessary inputs, and creates a shell
4677 environment to use them.
4678
4679 The general syntax is:
4680
4681 @example
4682 guix environment @var{options} @var{package}@dots{}
4683 @end example
4684
4685 The following example spawns a new shell set up for the development of
4686 GNU@tie{}Guile:
4687
4688 @example
4689 guix environment guile
4690 @end example
4691
4692 If the specified packages are not built yet, @command{guix environment}
4693 automatically builds them. The new shell's environment is an augmented
4694 version of the environment that @command{guix environment} was run in.
4695 It contains the necessary search paths for building the given package
4696 added to the existing environment variables. To create a ``pure''
4697 environment in which the original environment variables have been unset,
4698 use the @code{--pure} option@footnote{Users sometimes wrongfully augment
4699 environment variables such as @code{PATH} in their @file{~/.bashrc}
4700 file. As a consequence, when @code{guix environment} launches it, Bash
4701 may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
4702 environment variables. It is an error to define such environment
4703 variables in @file{.bashrc}; instead, they should be defined in
4704 @file{.bash_profile}, which is sourced only by log-in shells.
4705 @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
4706 details on Bash start-up files.}.
4707
4708 @vindex GUIX_ENVIRONMENT
4709 @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
4710 variable in the shell it spaws. This allows users to, say, define a
4711 specific prompt for development environments in their @file{.bashrc}
4712 (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
4713
4714 @example
4715 if [ -n "$GUIX_ENVIRONMENT" ]
4716 then
4717 export PS1="\u@@\h \w [dev]\$ "
4718 fi
4719 @end example
4720
4721 Additionally, more than one package may be specified, in which case the
4722 union of the inputs for the given packages are used. For example, the
4723 command below spawns a shell where all of the dependencies of both Guile
4724 and Emacs are available:
4725
4726 @example
4727 guix environment guile emacs
4728 @end example
4729
4730 Sometimes an interactive shell session is not desired. An arbitrary
4731 command may be invoked by placing the @code{--} token to separate the
4732 command from the rest of the arguments:
4733
4734 @example
4735 guix environment guile -- make -j4
4736 @end example
4737
4738 In other situations, it is more convenient to specify the list of
4739 packages needed in the environment. For example, the following command
4740 runs @command{python} from an environment containing Python@tie{}2.7 and
4741 NumPy:
4742
4743 @example
4744 guix environment --ad-hoc python2-numpy python-2.7 -- python
4745 @end example
4746
4747 Furthermore, one might want the dependencies of a package and also some
4748 additional packages that are not build-time or runtime dependencies, but
4749 are useful when developing nonetheless. Because of this, the
4750 @code{--ad-hoc} flag is positional. Packages appearing before
4751 @code{--ad-hoc} are interpreted as packages whose dependencies will be
4752 added to the environment. Packages appearing after are interpreted as
4753 packages that will be added to the environment directly. For example,
4754 the following command creates a Guix development environment that
4755 additionally includes Git and strace:
4756
4757 @example
4758 guix environment guix --ad-hoc git strace
4759 @end example
4760
4761 Sometimes it is desirable to isolate the environment as much as
4762 possible, for maximal purity and reproducibility. In particular, when
4763 using Guix on a host distro that is not GuixSD, it is desirable to
4764 prevent access to @file{/usr/bin} and other system-wide resources from
4765 the development environment. For example, the following command spawns
4766 a Guile REPL in a ``container'' where only the store and the current
4767 working directory are mounted:
4768
4769 @example
4770 guix environment --ad-hoc --container guile -- guile
4771 @end example
4772
4773 @quotation Note
4774 The @code{--container} option requires Linux-libre 3.19 or newer.
4775 @end quotation
4776
4777 The available options are summarized below.
4778
4779 @table @code
4780 @item --expression=@var{expr}
4781 @itemx -e @var{expr}
4782 Create an environment for the package or list of packages that
4783 @var{expr} evaluates to.
4784
4785 For example, running:
4786
4787 @example
4788 guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
4789 @end example
4790
4791 starts a shell with the environment for this specific variant of the
4792 PETSc package.
4793
4794 Running:
4795
4796 @example
4797 guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
4798 @end example
4799
4800 starts a shell with all the GuixSD base packages available.
4801
4802 @item --load=@var{file}
4803 @itemx -l @var{file}
4804 Create an environment for the package or list of packages that the code
4805 within @var{file} evaluates to.
4806
4807 As an example, @var{file} might contain a definition like this
4808 (@pxref{Defining Packages}):
4809
4810 @example
4811 @verbatiminclude environment-gdb.scm
4812 @end example
4813
4814 @item --ad-hoc
4815 Include all specified packages in the resulting environment, as if an
4816 @i{ad hoc} package were defined with them as inputs. This option is
4817 useful for quickly creating an environment without having to write a
4818 package expression to contain the desired inputs.
4819
4820 For instance, the command:
4821
4822 @example
4823 guix environment --ad-hoc guile guile-sdl -- guile
4824 @end example
4825
4826 runs @command{guile} in an environment where Guile and Guile-SDL are
4827 available.
4828
4829 Note that this example implicitly asks for the default output of
4830 @code{guile} and @code{guile-sdl} but it is possible to ask for a
4831 specific output---e.g., @code{glib:bin} asks for the @code{bin} output
4832 of @code{glib} (@pxref{Packages with Multiple Outputs}).
4833
4834 This option may be composed with the default behavior of @command{guix
4835 environment}. Packages appearing before @code{--ad-hoc} are interpreted
4836 as packages whose dependencies will be added to the environment, the
4837 default behavior. Packages appearing after are interpreted as packages
4838 that will be added to the environment directly.
4839
4840 @item --pure
4841 Unset existing environment variables when building the new environment.
4842 This has the effect of creating an environment in which search paths
4843 only contain package inputs.
4844
4845 @item --search-paths
4846 Display the environment variable definitions that make up the
4847 environment.
4848
4849 @item --system=@var{system}
4850 @itemx -s @var{system}
4851 Attempt to build for @var{system}---e.g., @code{i686-linux}.
4852
4853 @item --container
4854 @itemx -C
4855 @cindex container
4856 Run @var{command} within an isolated container. The current working
4857 directory outside the container is mapped to @file{/env} inside the
4858 container. Additionally, the spawned process runs as the current user
4859 outside the container, but has root privileges in the context of the
4860 container.
4861
4862 @item --network
4863 @itemx -N
4864 For containers, share the network namespace with the host system.
4865 Containers created without this flag only have access to the loopback
4866 device.
4867
4868 @item --expose=@var{source}[=@var{target}]
4869 For containers, expose the file system @var{source} from the host system
4870 as the read-only file system @var{target} within the container. If
4871 @var{target} is not specified, @var{source} is used as the target mount
4872 point in the container.
4873
4874 The example below spawns a Guile REPL in a container in which the user's
4875 home directory is accessible read-only via the @file{/exchange}
4876 directory:
4877
4878 @example
4879 guix environment --container --expose=$HOME=/exchange guile -- guile
4880 @end example
4881
4882 @item --share=@var{source}[=@var{target}]
4883 For containers, share the file system @var{source} from the host system
4884 as the writable file system @var{target} within the container. If
4885 @var{target} is not specified, @var{source} is used as the target mount
4886 point in the container.
4887
4888 The example below spawns a Guile REPL in a container in which the user's
4889 home directory is accessible for both reading and writing via the
4890 @file{/exchange} directory:
4891
4892 @example
4893 guix environment --container --share=$HOME=/exchange guile -- guile
4894 @end example
4895 @end table
4896
4897 It also supports all of the common build options that @command{guix
4898 build} supports (@pxref{Invoking guix build, common build options}).
4899
4900 @node Invoking guix publish
4901 @section Invoking @command{guix publish}
4902
4903 The purpose of @command{guix publish} is to enable users to easily share
4904 their store with others, which can then use it as a substitute server
4905 (@pxref{Substitutes}).
4906
4907 When @command{guix publish} runs, it spawns an HTTP server which allows
4908 anyone with network access to obtain substitutes from it. This means
4909 that any machine running Guix can also act as if it were a build farm,
4910 since the HTTP interface is compatible with Hydra, the software behind
4911 the @code{hydra.gnu.org} build farm.
4912
4913 For security, each substitute is signed, allowing recipients to check
4914 their authenticity and integrity (@pxref{Substitutes}). Because
4915 @command{guix publish} uses the system's signing key, which is only
4916 readable by the system administrator, it must be started as root; the
4917 @code{--user} option makes it drop root privileges early on.
4918
4919 The signing key pair must be generated before @command{guix publish} is
4920 launched, using @command{guix archive --generate-key} (@pxref{Invoking
4921 guix archive}).
4922
4923 The general syntax is:
4924
4925 @example
4926 guix publish @var{options}@dots{}
4927 @end example
4928
4929 Running @command{guix publish} without any additional arguments will
4930 spawn an HTTP server on port 8080:
4931
4932 @example
4933 guix publish
4934 @end example
4935
4936 Once a publishing server has been authorized (@pxref{Invoking guix
4937 archive}), the daemon may download substitutes from it:
4938
4939 @example
4940 guix-daemon --substitute-urls=http://example.org:8080
4941 @end example
4942
4943 The following options are available:
4944
4945 @table @code
4946 @item --port=@var{port}
4947 @itemx -p @var{port}
4948 Listen for HTTP requests on @var{port}.
4949
4950 @item --listen=@var{host}
4951 Listen on the network interface for @var{host}. The default is to
4952 accept connections from any interface.
4953
4954 @item --user=@var{user}
4955 @itemx -u @var{user}
4956 Change privileges to @var{user} as soon as possible---i.e., once the
4957 server socket is open and the signing key has been read.
4958
4959 @item --repl[=@var{port}]
4960 @itemx -r [@var{port}]
4961 Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
4962 Reference Manual}) on @var{port} (37146 by default). This is used
4963 primarily for debugging a running @command{guix publish} server.
4964 @end table
4965
4966 Enabling @command{guix publish} on a GuixSD system is a one-liner: just
4967 add a call to @code{guix-publish-service} in the @code{services} field
4968 of the @code{operating-system} declaration (@pxref{guix-publish-service,
4969 @code{guix-publish-service}}).
4970
4971
4972 @node Invoking guix challenge
4973 @section Invoking @command{guix challenge}
4974
4975 @cindex reproducible builds
4976 @cindex verifiable builds
4977
4978 Do the binaries provided by this server really correspond to the source
4979 code it claims to build? Is this package's build process deterministic?
4980 These are the questions the @command{guix challenge} command attempts to
4981 answer.
4982
4983 The former is obviously an important question: Before using a substitute
4984 server (@pxref{Substitutes}), you'd rather @emph{verify} that it
4985 provides the right binaries, and thus @emph{challenge} it. The latter
4986 is what enables the former: If package builds are deterministic, then
4987 independent builds of the package should yield the exact same result,
4988 bit for bit; if a server provides a binary different from the one
4989 obtained locally, it may be either corrupt or malicious.
4990
4991 We know that the hash that shows up in @file{/gnu/store} file names is
4992 the hash of all the inputs of the process that built the file or
4993 directory---compilers, libraries, build scripts,
4994 etc. (@pxref{Introduction}). Assuming deterministic build processes,
4995 one store file name should map to exactly one build output.
4996 @command{guix challenge} checks whether there is, indeed, a single
4997 mapping by comparing the build outputs of several independent builds of
4998 any given store item.
4999
5000 The command's output looks like this:
5001
5002 @smallexample
5003 $ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5004 updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5005 updating list of substitutes from 'http://guix.example.org'... 100.0%
5006 /gnu/store/@dots{}-openssl-1.0.2d contents differ:
5007 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5008 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5009 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5010 /gnu/store/@dots{}-git-2.5.0 contents differ:
5011 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5012 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5013 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5014 /gnu/store/@dots{}-pius-2.1.1 contents differ:
5015 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5016 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5017 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5018 @end smallexample
5019
5020 @noindent
5021 In this example, @command{guix challenge} first scans the store to
5022 determine the set of locally-built derivations---as opposed to store
5023 items that were downloaded from a substitute server---and then queries
5024 all the substitute servers. It then reports those store items for which
5025 the servers obtained a result different from the local build.
5026
5027 @cindex non-determinism, in package builds
5028 As an example, @code{guix.example.org} always gets a different answer.
5029 Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5030 case of Git. This might indicate that the build process of Git is
5031 non-deterministic, meaning that its output varies as a function of
5032 various things that Guix does not fully control, in spite of building
5033 packages in isolated environments (@pxref{Features}). Most common
5034 sources of non-determinism include the addition of timestamps in build
5035 results, the inclusion of random numbers, and directory listings sorted
5036 by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5037 more information.
5038
5039 To find out what's wrong with this Git binary, we can do something along
5040 these lines (@pxref{Invoking guix archive}):
5041
5042 @example
5043 $ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5044 | guix archive -x /tmp/git
5045 $ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
5046 @end example
5047
5048 This command shows the difference between the files resulting from the
5049 local build, and the files resulting from the build on
5050 @code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5051 diffutils, Comparing and Merging Files}). The @command{diff} command
5052 works great for text files. When binary files differ, a better option
5053 is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5054 visualize differences for all kinds of files.
5055
5056 Once you've done that work, you can tell whether the differences are due
5057 to a non-deterministic build process or to a malicious server. We try
5058 hard to remove sources of non-determinism in packages to make it easier
5059 to verify substitutes, but of course, this is a process, one that
5060 involves not just Guix but a large part of the free software community.
5061 In the meantime, @command{guix challenge} is one tool to help address
5062 the problem.
5063
5064 If you are writing packages for Guix, you are encouraged to check
5065 whether @code{hydra.gnu.org} and other substitute servers obtain the
5066 same build result as you did with:
5067
5068 @example
5069 $ guix challenge @var{package}
5070 @end example
5071
5072 @noindent
5073 ... where @var{package} is a package specification such as
5074 @code{guile-2.0} or @code{glibc:debug}.
5075
5076 The general syntax is:
5077
5078 @example
5079 guix challenge @var{options} [@var{packages}@dots{}]
5080 @end example
5081
5082 The one option that matters is:
5083
5084 @table @code
5085
5086 @item --substitute-urls=@var{urls}
5087 Consider @var{urls} the whitespace-separated list of substitute source
5088 URLs to compare to.
5089
5090 @end table
5091
5092
5093 @node Invoking guix container
5094 @section Invoking @command{guix container}
5095 @cindex container
5096
5097 @quotation Note
5098 As of version @value{VERSION}, this tool is experimental. The interface
5099 is subject to radical change in the future.
5100 @end quotation
5101
5102 The purpose of @command{guix container} is to manipulate processes
5103 running within an isolated environment, commonly known as a
5104 ``container'', typically created by the @command{guix environment}
5105 (@pxref{Invoking guix environment}) and @command{guix system container}
5106 (@pxref{Invoking guix system}) commands.
5107
5108 The general syntax is:
5109
5110 @example
5111 guix container @var{action} @var{options}@dots{}
5112 @end example
5113
5114 @var{action} specifies the operation to perform with a container, and
5115 @var{options} specifies the context-specific arguments for the action.
5116
5117 The following actions are available:
5118
5119 @table @code
5120 @item exec
5121 Execute a command within the context of a running container.
5122
5123 The syntax is:
5124
5125 @example
5126 guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5127 @end example
5128
5129 @var{pid} specifies the process ID of the running container.
5130 @var{program} specifies an executable file name within the container's
5131 root file system. @var{arguments} are the additional options that will
5132 be passed to @var{program}.
5133
5134 The following command launches an interactive login shell inside a
5135 GuixSD container, started by @command{guix system container}, and whose
5136 process ID is 9001:
5137
5138 @example
5139 guix container exec 9001 /run/current-system/profile/bin/bash --login
5140 @end example
5141
5142 Note that the @var{pid} cannot be the parent process of a container. It
5143 must be the container's PID 1 or one of its child processes.
5144
5145 @end table
5146
5147 @c *********************************************************************
5148 @node GNU Distribution
5149 @chapter GNU Distribution
5150
5151 @cindex Guix System Distribution
5152 @cindex GuixSD
5153 Guix comes with a distribution of the GNU system consisting entirely of
5154 free software@footnote{The term ``free'' here refers to the
5155 @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
5156 users of that software}.}. The
5157 distribution can be installed on its own (@pxref{System Installation}),
5158 but it is also possible to install Guix as a package manager on top of
5159 an installed GNU/Linux system (@pxref{Installation}). To distinguish
5160 between the two, we refer to the standalone distribution as the Guix
5161 System Distribution, or GuixSD.
5162
5163 The distribution provides core GNU packages such as GNU libc, GCC, and
5164 Binutils, as well as many GNU and non-GNU applications. The complete
5165 list of available packages can be browsed
5166 @url{http://www.gnu.org/software/guix/packages,on-line} or by
5167 running @command{guix package} (@pxref{Invoking guix package}):
5168
5169 @example
5170 guix package --list-available
5171 @end example
5172
5173 Our goal has been to provide a practical 100% free software distribution of
5174 Linux-based and other variants of GNU, with a focus on the promotion and
5175 tight integration of GNU components, and an emphasis on programs and
5176 tools that help users exert that freedom.
5177
5178 Packages are currently available on the following platforms:
5179
5180 @table @code
5181
5182 @item x86_64-linux
5183 Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5184
5185 @item i686-linux
5186 Intel 32-bit architecture (IA32), Linux-Libre kernel;
5187
5188 @item armhf-linux
5189 ARMv7-A architecture with hard float, Thumb-2 and NEON,
5190 using the EABI hard-float ABI, and Linux-Libre kernel.
5191
5192 @item mips64el-linux
5193 little-endian 64-bit MIPS processors, specifically the Loongson series,
5194 n32 application binary interface (ABI), and Linux-Libre kernel.
5195
5196 @end table
5197
5198 GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
5199
5200 @noindent
5201 For information on porting to other architectures or kernels,
5202 @xref{Porting}.
5203
5204 @menu
5205 * System Installation:: Installing the whole operating system.
5206 * System Configuration:: Configuring the operating system.
5207 * Installing Debugging Files:: Feeding the debugger.
5208 * Security Updates:: Deploying security fixes quickly.
5209 * Package Modules:: Packages from the programmer's viewpoint.
5210 * Packaging Guidelines:: Growing the distribution.
5211 * Bootstrapping:: GNU/Linux built from scratch.
5212 * Porting:: Targeting another platform or kernel.
5213 @end menu
5214
5215 Building this distribution is a cooperative effort, and you are invited
5216 to join! @xref{Contributing}, for information about how you can help.
5217
5218 @node System Installation
5219 @section System Installation
5220
5221 @cindex Guix System Distribution
5222 This section explains how to install the Guix System Distribution
5223 on a machine. The Guix package manager can
5224 also be installed on top of a running GNU/Linux system,
5225 @pxref{Installation}.
5226
5227 @ifinfo
5228 @c This paragraph is for people reading this from tty2 of the
5229 @c installation image.
5230 You're reading this documentation with an Info reader. For details on
5231 how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
5232 link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5233 @kbd{l} afterwards to come back here.
5234 @end ifinfo
5235
5236 @subsection Limitations
5237
5238 As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
5239 not production-ready. It may contain bugs and lack important
5240 features. Thus, if you are looking for a stable production system that
5241 respects your freedom as a computer user, a good solution at this point
5242 is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
5243 more established GNU/Linux distributions}. We hope you can soon switch
5244 to the GuixSD without fear, of course. In the meantime, you can
5245 also keep using your distribution and try out the package manager on top
5246 of it (@pxref{Installation}).
5247
5248 Before you proceed with the installation, be aware of the following
5249 noteworthy limitations applicable to version @value{VERSION}:
5250
5251 @itemize
5252 @item
5253 The installation process does not include a graphical user interface and
5254 requires familiarity with GNU/Linux (see the following subsections to
5255 get a feel of what that means.)
5256
5257 @item
5258 The system does not yet provide full GNOME and KDE desktops. Xfce and
5259 Enlightenment are available though, if graphical desktop environments
5260 are your thing, as well as a number of X11 window managers.
5261
5262 @item
5263 Support for the Logical Volume Manager (LVM) is missing.
5264
5265 @item
5266 Few system services are currently supported out-of-the-box
5267 (@pxref{Services}).
5268
5269 @item
5270 More than 2,000 packages are available, but you may
5271 occasionally find that a useful package is missing.
5272 @end itemize
5273
5274 You've been warned. But more than a disclaimer, this is an invitation
5275 to report issues (and success stories!), and join us in improving it.
5276 @xref{Contributing}, for more info.
5277
5278 @subsection USB Stick Installation
5279
5280 An installation image for USB sticks can be downloaded from
5281 @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5282 where @var{system} is one of:
5283
5284 @table @code
5285 @item x86_64-linux
5286 for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5287
5288 @item i686-linux
5289 for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5290 @end table
5291
5292 This image contains a single partition with the tools necessary for an
5293 installation. It is meant to be copied @emph{as is} to a large-enough
5294 USB stick.
5295
5296 To copy the image to a USB stick, follow these steps:
5297
5298 @enumerate
5299 @item
5300 Decompress the image using the @command{xz} command:
5301
5302 @example
5303 xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5304 @end example
5305
5306 @item
5307 Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
5308 its device name. Assuming that USB stick is known as @file{/dev/sdX},
5309 copy the image with:
5310
5311 @example
5312 dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5313 @end example
5314
5315 Access to @file{/dev/sdX} usually requires root privileges.
5316 @end enumerate
5317
5318 Once this is done, you should be able to reboot the system and boot from
5319 the USB stick. The latter usually requires you to get in the BIOS' boot
5320 menu, where you can choose to boot from the USB stick.
5321
5322 @subsection Preparing for Installation
5323
5324 Once you have successfully booted the image on the USB stick, you should
5325 end up with a root prompt. Several console TTYs are configured and can
5326 be used to run commands as root. TTY2 shows this documentation,
5327 browsable using the Info reader commands (@pxref{Help,,, info, Info: An
5328 Introduction}). The installation system runs the GPM mouse daemon,
5329 which allows you to select text with the left mouse button and to paste
5330 it with the middle button.
5331
5332 To install the system, you would:
5333
5334 @enumerate
5335
5336 @item
5337 Configure the network, by running:
5338
5339 @example
5340 ifconfig eno1 up && dhclient eno1
5341 @end example
5342
5343 to get an automatically assigned IP address from the wired
5344 network interface controller@footnote{
5345 @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
5346 The name @code{eno1} is for the first on-board Ethernet controller. The
5347 interface name for an Ethernet controller that is in the first slot of
5348 the first PCI bus, for instance, would be @code{enp1s0}. Use
5349 @command{ifconfig -a} to list all the available network interfaces.},
5350 or using the @command{ifconfig} command.
5351
5352 The system automatically loads drivers for your network interface
5353 controllers.
5354
5355 Setting up network access is almost always a requirement because the
5356 image does not contain all the software and tools that may be needed.
5357
5358 @item
5359 Unless this has already been done, you must partition, and then format
5360 the target partition.
5361
5362 Preferably, assign partitions a label so that you can easily and
5363 reliably refer to them in @code{file-system} declarations (@pxref{File
5364 Systems}). This is typically done using the @code{-L} option of
5365 @command{mkfs.ext4} and related commands.
5366
5367 @c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5368 @c A typical command sequence may be:
5369 @c
5370 @c @example
5371 @c # fdisk /dev/sdX
5372 @c @dots{} Create partitions etc.@dots{}
5373 @c # cryptsetup luksFormat /dev/sdX1
5374 @c # cryptsetup open --type luks /dev/sdX1 my-partition
5375 @c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5376 @c @end example
5377
5378 The installation image includes Parted (@pxref{Overview,,, parted, GNU
5379 Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk
5380 encryption, and e2fsprogs, the suite of tools to manipulate
5381 ext2/ext3/ext4 file systems.
5382
5383 @item
5384 Once that is done, mount the target root partition under @file{/mnt}.
5385
5386 @item
5387 Lastly, run @code{deco start cow-store /mnt}.
5388
5389 This will make @file{/gnu/store} copy-on-write, such that packages added
5390 to it during the installation phase will be written to the target disk
5391 rather than kept in memory.
5392
5393 @end enumerate
5394
5395
5396 @subsection Proceeding with the Installation
5397
5398 With the target partitions ready, you now have to edit a file and
5399 provide the declaration of the operating system to be installed. To
5400 that end, the installation system comes with two text editors: GNU nano
5401 (@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5402 It is better to store that file on the target root file system, say, as
5403 @file{/mnt/etc/config.scm}.
5404
5405 @xref{Using the Configuration System}, for examples of operating system
5406 configurations. These examples are available under
5407 @file{/etc/configuration} in the installation image, so you can copy
5408 them and use them as a starting point for your own configuration.
5409
5410 Once you are done preparing the configuration file, the new system must
5411 be initialized (remember that the target root file system is mounted
5412 under @file{/mnt}):
5413
5414 @example
5415 guix system init /mnt/etc/config.scm /mnt
5416 @end example
5417
5418 @noindent
5419 This will copy all the necessary files, and install GRUB on
5420 @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
5421 more information, @pxref{Invoking guix system}. This command may trigger
5422 downloads or builds of missing packages, which can take some time.
5423
5424 Once that command has completed---and hopefully succeeded!---you can run
5425 @command{reboot} and boot into the new system. The @code{root} password
5426 in the new system is initially empty; other users' passwords need to be
5427 initialized by running the @command{passwd} command as @code{root},
5428 unless your configuration specifies otherwise
5429 (@pxref{user-account-password, user account passwords}).
5430
5431 Join us on @code{#guix} on the Freenode IRC network or on
5432 @file{guix-devel@@gnu.org} to share your experience---good or not so
5433 good.
5434
5435 @subsection Building the Installation Image
5436
5437 The installation image described above was built using the @command{guix
5438 system} command, specifically:
5439
5440 @example
5441 guix system disk-image --image-size=850MiB gnu/system/install.scm
5442 @end example
5443
5444 @xref{Invoking guix system}, for more information. See
5445 @file{gnu/system/install.scm} in the source tree for more information
5446 about the installation image.
5447
5448 @node System Configuration
5449 @section System Configuration
5450
5451 @cindex system configuration
5452 The Guix System Distribution supports a consistent whole-system configuration
5453 mechanism. By that we mean that all aspects of the global system
5454 configuration---such as the available system services, timezone and
5455 locale settings, user accounts---are declared in a single place. Such
5456 a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
5457
5458 One of the advantages of putting all the system configuration under the
5459 control of Guix is that it supports transactional system upgrades, and
5460 makes it possible to roll-back to a previous system instantiation,
5461 should something go wrong with the new one (@pxref{Features}). Another
5462 one is that it makes it easy to replicate the exact same configuration
5463 across different machines, or at different points in time, without
5464 having to resort to additional administration tools layered on top of
5465 the system's own tools.
5466 @c Yes, we're talking of Puppet, Chef, & co. here. ↑
5467
5468 This section describes this mechanism. First we focus on the system
5469 administrator's viewpoint---explaining how the system is configured and
5470 instantiated. Then we show how this mechanism can be extended, for
5471 instance to support new system services.
5472
5473 @menu
5474 * Using the Configuration System:: Customizing your GNU system.
5475 * operating-system Reference:: Detail of operating-system declarations.
5476 * File Systems:: Configuring file system mounts.
5477 * Mapped Devices:: Block device extra processing.
5478 * User Accounts:: Specifying user accounts.
5479 * Locales:: Language and cultural convention settings.
5480 * Services:: Specifying system services.
5481 * Setuid Programs:: Programs running with root privileges.
5482 * X.509 Certificates:: Authenticating HTTPS servers.
5483 * Name Service Switch:: Configuring libc's name service switch.
5484 * Initial RAM Disk:: Linux-Libre bootstrapping.
5485 * GRUB Configuration:: Configuring the boot loader.
5486 * Invoking guix system:: Instantiating a system configuration.
5487 * Defining Services:: Adding new service definitions.
5488 @end menu
5489
5490 @node Using the Configuration System
5491 @subsection Using the Configuration System
5492
5493 The operating system is configured by providing an
5494 @code{operating-system} declaration in a file that can then be passed to
5495 the @command{guix system} command (@pxref{Invoking guix system}). A
5496 simple setup, with the default system services, the default Linux-Libre
5497 kernel, initial RAM disk, and boot loader looks like this:
5498
5499 @findex operating-system
5500 @lisp
5501 @include os-config-bare-bones.texi
5502 @end lisp
5503
5504 This example should be self-describing. Some of the fields defined
5505 above, such as @code{host-name} and @code{bootloader}, are mandatory.
5506 Others, such as @code{packages} and @code{services}, can be omitted, in
5507 which case they get a default value.
5508
5509 @vindex %base-packages
5510 The @code{packages} field lists
5511 packages that will be globally visible on the system, for all user
5512 accounts---i.e., in every user's @code{PATH} environment variable---in
5513 addition to the per-user profiles (@pxref{Invoking guix package}). The
5514 @var{%base-packages} variable provides all the tools one would expect
5515 for basic user and administrator tasks---including the GNU Core
5516 Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
5517 editor, @command{find}, @command{grep}, etc. The example above adds
5518 tcpdump to those, taken from the @code{(gnu packages admin)} module
5519 (@pxref{Package Modules}).
5520
5521 @vindex %base-services
5522 The @code{services} field lists @dfn{system services} to be made
5523 available when the system starts (@pxref{Services}).
5524 The @code{operating-system} declaration above specifies that, in
5525 addition to the basic services, we want the @command{lshd} secure shell
5526 daemon listening on port 2222 (@pxref{Networking Services,
5527 @code{lsh-service}}). Under the hood,
5528 @code{lsh-service} arranges so that @code{lshd} is started with the
5529 right command-line options, possibly with supporting configuration files
5530 generated as needed (@pxref{Defining Services}).
5531
5532 @cindex customization, of services
5533 @findex modify-services
5534 Occasionally, instead of using the base services as is, you will want to
5535 customize them. For instance, to change the configuration of
5536 @code{guix-daemon} and Mingetty (the console log-in), you may write the
5537 following instead of @var{%base-services}:
5538
5539 @lisp
5540 (modify-services %base-services
5541 (guix-service-type config =>
5542 (guix-configuration
5543 (inherit config)
5544 (use-substitutes? #f)
5545 (extra-options '("--gc-keep-outputs"))))
5546 (mingetty-service-type config =>
5547 (mingetty-configuration
5548 (inherit config)
5549 (motd (plain-file "motd" "Hi there!")))))
5550 @end lisp
5551
5552 @noindent
5553 The effect here is to change the options passed to @command{guix-daemon}
5554 when it is started, as well as the ``message of the day'' that appears
5555 when logging in at the console. @xref{Service Reference,
5556 @code{modify-services}}, for more on that.
5557
5558 The configuration for a typical ``desktop'' usage, with the X11 display
5559 server, a desktop environment, network management, power management, and
5560 more, would look like this:
5561
5562 @lisp
5563 @include os-config-desktop.texi
5564 @end lisp
5565
5566 @xref{Desktop Services}, for the exact list of services provided by
5567 @var{%desktop-services}. @xref{X.509 Certificates}, for background
5568 information about the @code{nss-certs} package that is used here.
5569 @xref{operating-system Reference}, for details about all the available
5570 @code{operating-system} fields.
5571
5572 Assuming the above snippet is stored in the @file{my-system-config.scm}
5573 file, the @command{guix system reconfigure my-system-config.scm} command
5574 instantiates that configuration, and makes it the default GRUB boot
5575 entry (@pxref{Invoking guix system}).
5576
5577 The normal way to change the system's configuration is by updating this
5578 file and re-running @command{guix system reconfigure}. One should never
5579 have to touch files in @command{/etc} or to run commands that modify the
5580 system state such as @command{useradd} or @command{grub-install}. In
5581 fact, you must avoid that since that would not only void your warranty
5582 but also prevent you from rolling back to previous versions of your
5583 system, should you ever need to.
5584
5585 @cindex roll-back, of the operating system
5586 Speaking of roll-back, each time you run @command{guix system
5587 reconfigure}, a new @dfn{generation} of the system is created---without
5588 modifying or deleting previous generations. Old system generations get
5589 an entry in the GRUB boot menu, allowing you to boot them in case
5590 something went wrong with the latest generation. Reassuring, no? The
5591 @command{guix system list-generations} command lists the system
5592 generations available on disk.
5593
5594 At the Scheme level, the bulk of an @code{operating-system} declaration
5595 is instantiated with the following monadic procedure (@pxref{The Store
5596 Monad}):
5597
5598 @deffn {Monadic Procedure} operating-system-derivation os
5599 Return a derivation that builds @var{os}, an @code{operating-system}
5600 object (@pxref{Derivations}).
5601
5602 The output of the derivation is a single directory that refers to all
5603 the packages, configuration files, and other supporting files needed to
5604 instantiate @var{os}.
5605 @end deffn
5606
5607 @node operating-system Reference
5608 @subsection @code{operating-system} Reference
5609
5610 This section summarizes all the options available in
5611 @code{operating-system} declarations (@pxref{Using the Configuration
5612 System}).
5613
5614 @deftp {Data Type} operating-system
5615 This is the data type representing an operating system configuration.
5616 By that, we mean all the global system configuration, not per-user
5617 configuration (@pxref{Using the Configuration System}).
5618
5619 @table @asis
5620 @item @code{kernel} (default: @var{linux-libre})
5621 The package object of the operating system kernel to use@footnote{Currently
5622 only the Linux-libre kernel is supported. In the future, it will be
5623 possible to use the GNU@tie{}Hurd.}.
5624
5625 @item @code{kernel-arguments} (default: @code{'()})
5626 List of strings or gexps representing additional arguments to pass on
5627 the kernel's command-line---e.g., @code{("console=ttyS0")}.
5628
5629 @item @code{bootloader}
5630 The system bootloader configuration object. @xref{GRUB Configuration}.
5631
5632 @item @code{initrd} (default: @code{base-initrd})
5633 A two-argument monadic procedure that returns an initial RAM disk for
5634 the Linux kernel. @xref{Initial RAM Disk}.
5635
5636 @item @code{firmware} (default: @var{%base-firmware})
5637 @cindex firmware
5638 List of firmware packages loadable by the operating system kernel.
5639
5640 The default includes firmware needed for Atheros-based WiFi devices
5641 (Linux-libre module @code{ath9k}.)
5642
5643 @item @code{host-name}
5644 The host name.
5645
5646 @item @code{hosts-file}
5647 @cindex hosts file
5648 A file-like object (@pxref{G-Expressions, file-like objects}) for use as
5649 @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
5650 Reference Manual}). The default is a file with entries for
5651 @code{localhost} and @var{host-name}.
5652
5653 @item @code{mapped-devices} (default: @code{'()})
5654 A list of mapped devices. @xref{Mapped Devices}.
5655
5656 @item @code{file-systems}
5657 A list of file systems. @xref{File Systems}.
5658
5659 @item @code{swap-devices} (default: @code{'()})
5660 @cindex swap devices
5661 A list of strings identifying devices to be used for ``swap space''
5662 (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
5663 For example, @code{'("/dev/sda3")}.
5664
5665 @item @code{users} (default: @code{%base-user-accounts})
5666 @itemx @code{groups} (default: @var{%base-groups})
5667 List of user accounts and groups. @xref{User Accounts}.
5668
5669 @item @code{skeletons} (default: @code{(default-skeletons)})
5670 A monadic list of pairs of target file name and files. These are the
5671 files that will be used as skeletons as new accounts are created.
5672
5673 For instance, a valid value may look like this:
5674
5675 @example
5676 (mlet %store-monad ((bashrc (text-file "bashrc" "\
5677 export PATH=$HOME/.guix-profile/bin")))
5678 (return `((".bashrc" ,bashrc))))
5679 @end example
5680
5681 @item @code{issue} (default: @var{%default-issue})
5682 A string denoting the contents of the @file{/etc/issue} file, which is
5683 what displayed when users log in on a text console.
5684
5685 @item @code{packages} (default: @var{%base-packages})
5686 The set of packages installed in the global profile, which is accessible
5687 at @file{/run/current-system/profile}.
5688
5689 The default set includes core utilities, but it is good practice to
5690 install non-core utilities in user profiles (@pxref{Invoking guix
5691 package}).
5692
5693 @item @code{timezone}
5694 A timezone identifying string---e.g., @code{"Europe/Paris"}.
5695
5696 @item @code{locale} (default: @code{"en_US.utf8"})
5697 The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
5698 Library Reference Manual}). @xref{Locales}, for more information.
5699
5700 @item @code{locale-definitions} (default: @var{%default-locale-definitions})
5701 The list of locale definitions to be compiled and that may be used at
5702 run time. @xref{Locales}.
5703
5704 @item @code{locale-libcs} (default: @code{(list @var{glibc})})
5705 The list of GNU@tie{}libc packages whose locale data and tools are used
5706 to build the locale definitions. @xref{Locales}, for compatibility
5707 considerations that justify this option.
5708
5709 @item @code{name-service-switch} (default: @var{%default-nss})
5710 Configuration of libc's name service switch (NSS)---a
5711 @code{<name-service-switch>} object. @xref{Name Service Switch}, for
5712 details.
5713
5714 @item @code{services} (default: @var{%base-services})
5715 A list of service objects denoting system services. @xref{Services}.
5716
5717 @item @code{pam-services} (default: @code{(base-pam-services)})
5718 @cindex PAM
5719 @cindex pluggable authentication modules
5720 Linux @dfn{pluggable authentication module} (PAM) services.
5721 @c FIXME: Add xref to PAM services section.
5722
5723 @item @code{setuid-programs} (default: @var{%setuid-programs})
5724 List of string-valued G-expressions denoting setuid programs.
5725 @xref{Setuid Programs}.
5726
5727 @item @code{sudoers-file} (default: @var{%sudoers-specification})
5728 @cindex sudoers file
5729 The contents of the @file{/etc/sudoers} file as a file-like object
5730 (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
5731
5732 This file specifies which users can use the @command{sudo} command, what
5733 they are allowed to do, and what privileges they may gain. The default
5734 is that only @code{root} and members of the @code{wheel} group may use
5735 @code{sudo}.
5736
5737 @end table
5738 @end deftp
5739
5740 @node File Systems
5741 @subsection File Systems
5742
5743 The list of file systems to be mounted is specified in the
5744 @code{file-systems} field of the operating system's declaration
5745 (@pxref{Using the Configuration System}). Each file system is declared
5746 using the @code{file-system} form, like this:
5747
5748 @example
5749 (file-system
5750 (mount-point "/home")
5751 (device "/dev/sda3")
5752 (type "ext4"))
5753 @end example
5754
5755 As usual, some of the fields are mandatory---those shown in the example
5756 above---while others can be omitted. These are described below.
5757
5758 @deftp {Data Type} file-system
5759 Objects of this type represent file systems to be mounted. They
5760 contain the following members:
5761
5762 @table @asis
5763 @item @code{type}
5764 This is a string specifying the type of the file system---e.g.,
5765 @code{"ext4"}.
5766
5767 @item @code{mount-point}
5768 This designates the place where the file system is to be mounted.
5769
5770 @item @code{device}
5771 This names the ``source'' of the file system. By default it is the name
5772 of a node under @file{/dev}, but its meaning depends on the @code{title}
5773 field described below.
5774
5775 @item @code{title} (default: @code{'device})
5776 This is a symbol that specifies how the @code{device} field is to be
5777 interpreted.
5778
5779 When it is the symbol @code{device}, then the @code{device} field is
5780 interpreted as a file name; when it is @code{label}, then @code{device}
5781 is interpreted as a partition label name; when it is @code{uuid},
5782 @code{device} is interpreted as a partition unique identifier (UUID).
5783
5784 UUIDs may be converted from their string representation (as shown by the
5785 @command{tune2fs -l} command) using the @code{uuid} form, like this:
5786
5787 @example
5788 (file-system
5789 (mount-point "/home")
5790 (type "ext4")
5791 (title 'uuid)
5792 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
5793 @end example
5794
5795 The @code{label} and @code{uuid} options offer a way to refer to disk
5796 partitions without having to hard-code their actual device
5797 name@footnote{Note that, while it is tempting to use
5798 @file{/dev/disk/by-uuid} and similar device names to achieve the same
5799 result, this is not recommended: These special device nodes are created
5800 by the udev daemon and may be unavailable at the time the device is
5801 mounted.}.
5802
5803 However, when a file system's source is a mapped device (@pxref{Mapped
5804 Devices}), its @code{device} field @emph{must} refer to the mapped
5805 device name---e.g., @file{/dev/mapper/root-partition}---and consequently
5806 @code{title} must be set to @code{'device}. This is required so that
5807 the system knows that mounting the file system depends on having the
5808 corresponding device mapping established.
5809
5810 @item @code{flags} (default: @code{'()})
5811 This is a list of symbols denoting mount flags. Recognized flags
5812 include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
5813 access to special files), @code{no-suid} (ignore setuid and setgid
5814 bits), and @code{no-exec} (disallow program execution.)
5815
5816 @item @code{options} (default: @code{#f})
5817 This is either @code{#f}, or a string denoting mount options.
5818
5819 @item @code{needed-for-boot?} (default: @code{#f})
5820 This Boolean value indicates whether the file system is needed when
5821 booting. If that is true, then the file system is mounted when the
5822 initial RAM disk (initrd) is loaded. This is always the case, for
5823 instance, for the root file system.
5824
5825 @item @code{check?} (default: @code{#t})
5826 This Boolean indicates whether the file system needs to be checked for
5827 errors before being mounted.
5828
5829 @item @code{create-mount-point?} (default: @code{#f})
5830 When true, the mount point is created if it does not exist yet.
5831
5832 @item @code{dependencies} (default: @code{'()})
5833 This is a list of @code{<file-system>} objects representing file systems
5834 that must be mounted before (and unmounted after) this one.
5835
5836 As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
5837 a dependency of @file{/sys/fs/cgroup/cpu} and
5838 @file{/sys/fs/cgroup/memory}.
5839
5840 @end table
5841 @end deftp
5842
5843 The @code{(gnu system file-systems)} exports the following useful
5844 variables.
5845
5846 @defvr {Scheme Variable} %base-file-systems
5847 These are essential file systems that are required on normal systems,
5848 such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
5849 below.) Operating system declarations should always contain at least
5850 these.
5851 @end defvr
5852
5853 @defvr {Scheme Variable} %pseudo-terminal-file-system
5854 This is the file system to be mounted as @file{/dev/pts}. It supports
5855 @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
5856 functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
5857 Manual}). Pseudo-terminals are used by terminal emulators such as
5858 @command{xterm}.
5859 @end defvr
5860
5861 @defvr {Scheme Variable} %shared-memory-file-system
5862 This file system is mounted as @file{/dev/shm} and is used to support
5863 memory sharing across processes (@pxref{Memory-mapped I/O,
5864 @code{shm_open},, libc, The GNU C Library Reference Manual}).
5865 @end defvr
5866
5867 @defvr {Scheme Variable} %immutable-store
5868 This file system performs a read-only ``bind mount'' of
5869 @file{/gnu/store}, making it read-only for all the users including
5870 @code{root}. This prevents against accidental modification by software
5871 running as @code{root} or by system administrators.
5872
5873 The daemon itself is still able to write to the store: it remounts it
5874 read-write in its own ``name space.''
5875 @end defvr
5876
5877 @defvr {Scheme Variable} %binary-format-file-system
5878 The @code{binfmt_misc} file system, which allows handling of arbitrary
5879 executable file types to be delegated to user space. This requires the
5880 @code{binfmt.ko} kernel module to be loaded.
5881 @end defvr
5882
5883 @defvr {Scheme Variable} %fuse-control-file-system
5884 The @code{fusectl} file system, which allows unprivileged users to mount
5885 and unmount user-space FUSE file systems. This requires the
5886 @code{fuse.ko} kernel module to be loaded.
5887 @end defvr
5888
5889 @node Mapped Devices
5890 @subsection Mapped Devices
5891
5892 @cindex device mapping
5893 @cindex mapped devices
5894 The Linux kernel has a notion of @dfn{device mapping}: a block device,
5895 such as a hard disk partition, can be @dfn{mapped} into another device,
5896 with additional processing over the data that flows through
5897 it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
5898 concept of a ``mapped device'' and that of a file system: both boil down
5899 to @emph{translating} input/output operations made on a file to
5900 operations on its backing store. Thus, the Hurd implements mapped
5901 devices, like file systems, using the generic @dfn{translator} mechanism
5902 (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
5903 typical example is encryption device mapping: all writes to the mapped
5904 device are encrypted, and all reads are deciphered, transparently.
5905
5906 Mapped devices are declared using the @code{mapped-device} form:
5907
5908 @example
5909 (mapped-device
5910 (source "/dev/sda3")
5911 (target "home")
5912 (type luks-device-mapping))
5913 @end example
5914
5915 @noindent
5916 @cindex disk encryption
5917 @cindex LUKS
5918 This example specifies a mapping from @file{/dev/sda3} to
5919 @file{/dev/mapper/home} using LUKS---the
5920 @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
5921 standard mechanism for disk encryption. The @file{/dev/mapper/home}
5922 device can then be used as the @code{device} of a @code{file-system}
5923 declaration (@pxref{File Systems}). The @code{mapped-device} form is
5924 detailed below.
5925
5926 @deftp {Data Type} mapped-device
5927 Objects of this type represent device mappings that will be made when
5928 the system boots up.
5929
5930 @table @code
5931 @item source
5932 This string specifies the name of the block device to be mapped, such as
5933 @code{"/dev/sda3"}.
5934
5935 @item target
5936 This string specifies the name of the mapping to be established. For
5937 example, specifying @code{"my-partition"} will lead to the creation of
5938 the @code{"/dev/mapper/my-partition"} device.
5939
5940 @item type
5941 This must be a @code{mapped-device-kind} object, which specifies how
5942 @var{source} is mapped to @var{target}.
5943 @end table
5944 @end deftp
5945
5946 @defvr {Scheme Variable} luks-device-mapping
5947 This defines LUKS block device encryption using the @command{cryptsetup}
5948 command, from the same-named package. This relies on the
5949 @code{dm-crypt} Linux kernel module.
5950 @end defvr
5951
5952 @node User Accounts
5953 @subsection User Accounts
5954
5955 User accounts and groups are entirely managed through the
5956 @code{operating-system} declaration. They are specified with the
5957 @code{user-account} and @code{user-group} forms:
5958
5959 @example
5960 (user-account
5961 (name "alice")
5962 (group "users")
5963 (supplementary-groups '("wheel" ;allow use of sudo, etc.
5964 "audio" ;sound card
5965 "video" ;video devices such as webcams
5966 "cdrom")) ;the good ol' CD-ROM
5967 (comment "Bob's sister")
5968 (home-directory "/home/alice"))
5969 @end example
5970
5971 When booting or upon completion of @command{guix system reconfigure},
5972 the system ensures that only the user accounts and groups specified in
5973 the @code{operating-system} declaration exist, and with the specified
5974 properties. Thus, account or group creations or modifications made by
5975 directly invoking commands such as @command{useradd} are lost upon
5976 reconfiguration or reboot. This ensures that the system remains exactly
5977 as declared.
5978
5979 @deftp {Data Type} user-account
5980 Objects of this type represent user accounts. The following members may
5981 be specified:
5982
5983 @table @asis
5984 @item @code{name}
5985 The name of the user account.
5986
5987 @item @code{group}
5988 This is the name (a string) or identifier (a number) of the user group
5989 this account belongs to.
5990
5991 @item @code{supplementary-groups} (default: @code{'()})
5992 Optionally, this can be defined as a list of group names that this
5993 account belongs to.
5994
5995 @item @code{uid} (default: @code{#f})
5996 This is the user ID for this account (a number), or @code{#f}. In the
5997 latter case, a number is automatically chosen by the system when the
5998 account is created.
5999
6000 @item @code{comment} (default: @code{""})
6001 A comment about the account, such as the account's owner full name.
6002
6003 @item @code{home-directory}
6004 This is the name of the home directory for the account.
6005
6006 @item @code{shell} (default: Bash)
6007 This is a G-expression denoting the file name of a program to be used as
6008 the shell (@pxref{G-Expressions}).
6009
6010 @item @code{system?} (default: @code{#f})
6011 This Boolean value indicates whether the account is a ``system''
6012 account. System accounts are sometimes treated specially; for instance,
6013 graphical login managers do not list them.
6014
6015 @anchor{user-account-password}
6016 @item @code{password} (default: @code{#f})
6017 You would normally leave this field to @code{#f}, initialize user
6018 passwords as @code{root} with the @command{passwd} command, and then let
6019 users change it with @command{passwd}. Passwords set with
6020 @command{passwd} are of course preserved across reboot and
6021 reconfiguration.
6022
6023 If you @emph{do} want to have a preset password for an account, then
6024 this field must contain the encrypted password, as a string.
6025 @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6026 on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
6027 Manual}, for information on Guile's @code{crypt} procedure.
6028
6029 @end table
6030 @end deftp
6031
6032 User group declarations are even simpler:
6033
6034 @example
6035 (user-group (name "students"))
6036 @end example
6037
6038 @deftp {Data Type} user-group
6039 This type is for, well, user groups. There are just a few fields:
6040
6041 @table @asis
6042 @item @code{name}
6043 The group's name.
6044
6045 @item @code{id} (default: @code{#f})
6046 The group identifier (a number). If @code{#f}, a new number is
6047 automatically allocated when the group is created.
6048
6049 @item @code{system?} (default: @code{#f})
6050 This Boolean value indicates whether the group is a ``system'' group.
6051 System groups have low numerical IDs.
6052
6053 @item @code{password} (default: @code{#f})
6054 What, user groups can have a password? Well, apparently yes. Unless
6055 @code{#f}, this field specifies the group's password.
6056
6057 @end table
6058 @end deftp
6059
6060 For convenience, a variable lists all the basic user groups one may
6061 expect:
6062
6063 @defvr {Scheme Variable} %base-groups
6064 This is the list of basic user groups that users and/or packages expect
6065 to be present on the system. This includes groups such as ``root'',
6066 ``wheel'', and ``users'', as well as groups used to control access to
6067 specific devices such as ``audio'', ``disk'', and ``cdrom''.
6068 @end defvr
6069
6070 @defvr {Scheme Variable} %base-user-accounts
6071 This is the list of basic system accounts that programs may expect to
6072 find on a GNU/Linux system, such as the ``nobody'' account.
6073
6074 Note that the ``root'' account is not included here. It is a
6075 special-case and is automatically added whether or not it is specified.
6076 @end defvr
6077
6078 @node Locales
6079 @subsection Locales
6080
6081 @cindex locale
6082 A @dfn{locale} defines cultural conventions for a particular language
6083 and region of the world (@pxref{Locales,,, libc, The GNU C Library
6084 Reference Manual}). Each locale has a name that typically has the form
6085 @code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
6086 @code{fr_LU.utf8} designates the locale for the French language, with
6087 cultural conventions from Luxembourg, and using the UTF-8 encoding.
6088
6089 @cindex locale definition
6090 Usually, you will want to specify the default locale for the machine
6091 using the @code{locale} field of the @code{operating-system} declaration
6092 (@pxref{operating-system Reference, @code{locale}}).
6093
6094 That locale must be among the @dfn{locale definitions} that are known to
6095 the system---and these are specified in the @code{locale-definitions}
6096 slot of @code{operating-system}. The default value includes locale
6097 definition for some widely used locales, but not for all the available
6098 locales, in order to save space.
6099
6100 If the locale specified in the @code{locale} field is not among the
6101 definitions listed in @code{locale-definitions}, @command{guix system}
6102 raises an error. In that case, you should add the locale definition to
6103 the @code{locale-definitions} field. For instance, to add the North
6104 Frisian locale for Germany, the value of that field may be:
6105
6106 @example
6107 (cons (locale-definition
6108 (name "fy_DE.utf8") (source "fy_DE"))
6109 %default-locale-definitions)
6110 @end example
6111
6112 Likewise, to save space, one might want @code{locale-definitions} to
6113 list only the locales that are actually used, as in:
6114
6115 @example
6116 (list (locale-definition
6117 (name "ja_JP.eucjp") (source "ja_JP")
6118 (charset "EUC-JP")))
6119 @end example
6120
6121 @vindex LOCPATH
6122 The compiled locale definitions are available at
6123 @file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6124 version, which is the default location where the GNU@tie{}libc provided
6125 by Guix looks for locale data. This can be overridden using the
6126 @code{LOCPATH} environment variable (@pxref{locales-and-locpath,
6127 @code{LOCPATH} and locale packages}).
6128
6129 The @code{locale-definition} form is provided by the @code{(gnu system
6130 locale)} module. Details are given below.
6131
6132 @deftp {Data Type} locale-definition
6133 This is the data type of a locale definition.
6134
6135 @table @asis
6136
6137 @item @code{name}
6138 The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6139 Reference Manual}, for more information on locale names.
6140
6141 @item @code{source}
6142 The name of the source for that locale. This is typically the
6143 @code{@var{language}_@var{territory}} part of the locale name.
6144
6145 @item @code{charset} (default: @code{"UTF-8"})
6146 The ``character set'' or ``code set'' for that locale,
6147 @uref{http://www.iana.org/assignments/character-sets, as defined by
6148 IANA}.
6149
6150 @end table
6151 @end deftp
6152
6153 @defvr {Scheme Variable} %default-locale-definitions
6154 An arbitrary list of commonly used UTF-8 locales, used as the default
6155 value of the @code{locale-definitions} field of @code{operating-system}
6156 declarations.
6157
6158 @cindex locale name
6159 @cindex normalized codeset in locale names
6160 These locale definitions use the @dfn{normalized codeset} for the part
6161 that follows the dot in the name (@pxref{Using gettextized software,
6162 normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6163 instance it has @code{uk_UA.utf8} but @emph{not}, say,
6164 @code{uk_UA.UTF-8}.
6165 @end defvr
6166
6167 @subsubsection Locale Data Compatibility Considerations
6168
6169 @cindex incompatibility, of locale data
6170 @code{operating-system} declarations provide a @code{locale-libcs} field
6171 to specify the GNU@tie{}libc packages that are used to compile locale
6172 declarations (@pxref{operating-system Reference}). ``Why would I
6173 care?'', you may ask. Well, it turns out that the binary format of
6174 locale data is occasionally incompatible from one libc version to
6175 another.
6176
6177 @c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6178 @c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6179 For instance, a program linked against libc version 2.21 is unable to
6180 read locale data produced with libc 2.22; worse, that program
6181 @emph{aborts} instead of simply ignoring the incompatible locale
6182 data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6183 the incompatible locale data, which is already an improvement.}.
6184 Similarly, a program linked against libc 2.22 can read most, but not
6185 all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6186 data is incompatible); thus calls to @code{setlocale} may fail, but
6187 programs will not abort.
6188
6189 The ``problem'' in GuixSD is that users have a lot of freedom: They can
6190 choose whether and when to upgrade software in their profiles, and might
6191 be using a libc version different from the one the system administrator
6192 used to build the system-wide locale data.
6193
6194 Fortunately, unprivileged users can also install their own locale data
6195 and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6196 @code{GUIX_LOCPATH} and locale packages}).
6197
6198 Still, it is best if the system-wide locale data at
6199 @file{/run/current-system/locale} is built for all the libc versions
6200 actually in use on the system, so that all the programs can access
6201 it---this is especially crucial on a multi-user system. To do that, the
6202 administrator can specify several libc packages in the
6203 @code{locale-libcs} field of @code{operating-system}:
6204
6205 @example
6206 (use-package-modules base)
6207
6208 (operating-system
6209 ;; @dots{}
6210 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6211 @end example
6212
6213 This example would lead to a system containing locale definitions for
6214 both libc 2.21 and the current version of libc in
6215 @file{/run/current-system/locale}.
6216
6217
6218 @node Services
6219 @subsection Services
6220
6221 @cindex system services
6222 An important part of preparing an @code{operating-system} declaration is
6223 listing @dfn{system services} and their configuration (@pxref{Using the
6224 Configuration System}). System services are typically daemons launched
6225 when the system boots, or other actions needed at that time---e.g.,
6226 configuring network access.
6227
6228 Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU
6229 dmd Manual}). On a running system, the @command{deco} command allows
6230 you to list the available services, show their status, start and stop
6231 them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd
6232 Manual}). For example:
6233
6234 @example
6235 # deco status dmd
6236 @end example
6237
6238 The above command, run as @code{root}, lists the currently defined
6239 services. The @command{deco doc} command shows a synopsis of the given
6240 service:
6241
6242 @example
6243 # deco doc nscd
6244 Run libc's name service cache daemon (nscd).
6245 @end example
6246
6247 The @command{start}, @command{stop}, and @command{restart} sub-commands
6248 have the effect you would expect. For instance, the commands below stop
6249 the nscd service and restart the Xorg display server:
6250
6251 @example
6252 # deco stop nscd
6253 Service nscd has been stopped.
6254 # deco restart xorg-server
6255 Service xorg-server has been stopped.
6256 Service xorg-server has been started.
6257 @end example
6258
6259 The following sections document the available services, starting with
6260 the core services, that may be used in an @code{operating-system}
6261 declaration.
6262
6263 @menu
6264 * Base Services:: Essential system services.
6265 * Networking Services:: Network setup, SSH daemon, etc.
6266 * X Window:: Graphical display.
6267 * Desktop Services:: D-Bus and desktop services.
6268 * Database Services:: SQL databases.
6269 * Web Services:: Web servers.
6270 * Various Services:: Other services.
6271 @end menu
6272
6273 @node Base Services
6274 @subsubsection Base Services
6275
6276 The @code{(gnu services base)} module provides definitions for the basic
6277 services that one expects from the system. The services exported by
6278 this module are listed below.
6279
6280 @defvr {Scheme Variable} %base-services
6281 This variable contains a list of basic services@footnote{Technically,
6282 this is a list of monadic services. @xref{The Store Monad}.} one would
6283 expect from the system: a login service (mingetty) on each tty, syslogd,
6284 libc's name service cache daemon (nscd), the udev device manager, and
6285 more.
6286
6287 This is the default value of the @code{services} field of
6288 @code{operating-system} declarations. Usually, when customizing a
6289 system, you will want to append services to @var{%base-services}, like
6290 this:
6291
6292 @example
6293 (cons* (avahi-service) (lsh-service) %base-services)
6294 @end example
6295 @end defvr
6296
6297 @deffn {Scheme Procedure} host-name-service @var{name}
6298 Return a service that sets the host name to @var{name}.
6299 @end deffn
6300
6301 @deffn {Scheme Procedure} mingetty-service @var{config}
6302 Return a service to run mingetty according to @var{config}, a
6303 @code{<mingetty-configuration>} object, which specifies the tty to run, among
6304 other things.
6305 @end deffn
6306
6307 @deftp {Data Type} mingetty-configuration
6308 This is the data type representing the configuration of Mingetty, which
6309 implements console log-in.
6310
6311 @table @asis
6312
6313 @item @code{tty}
6314 The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6315
6316 @item @code{motd}
6317 A file-like object containing the ``message of the day''.
6318
6319 @item @code{auto-login} (default: @code{#f})
6320 When true, this field must be a string denoting the user name under
6321 which the the system automatically logs in. When it is @code{#f}, a
6322 user name and password must be entered to log in.
6323
6324 @item @code{login-program} (default: @code{#f})
6325 This must be either @code{#f}, in which case the default log-in program
6326 is used (@command{login} from the Shadow tool suite), or a gexp denoting
6327 the name of the log-in program.
6328
6329 @item @code{login-pause?} (default: @code{#f})
6330 When set to @code{#t} in conjunction with @var{auto-login}, the user
6331 will have to press a key before the log-in shell is launched.
6332
6333 @item @code{mingetty} (default: @var{mingetty})
6334 The Mingetty package to use.
6335
6336 @end table
6337 @end deftp
6338
6339 @cindex name service cache daemon
6340 @cindex nscd
6341 @deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
6342 [#:name-services '()]
6343 Return a service that runs libc's name service cache daemon (nscd) with the
6344 given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6345 Service Switch}, for an example.
6346 @end deffn
6347
6348 @defvr {Scheme Variable} %nscd-default-configuration
6349 This is the default @code{<nscd-configuration>} value (see below) used
6350 by @code{nscd-service}. This uses the caches defined by
6351 @var{%nscd-default-caches}; see below.
6352 @end defvr
6353
6354 @deftp {Data Type} nscd-configuration
6355 This is the type representing the name service cache daemon (nscd)
6356 configuration.
6357
6358 @table @asis
6359
6360 @item @code{name-services} (default: @code{'()})
6361 List of packages denoting @dfn{name services} that must be visible to
6362 the nscd---e.g., @code{(list @var{nss-mdns})}.
6363
6364 @item @code{glibc} (default: @var{glibc})
6365 Package object denoting the GNU C Library providing the @command{nscd}
6366 command.
6367
6368 @item @code{log-file} (default: @code{"/var/log/nscd.log"})
6369 Name of nscd's log file. This is where debugging output goes when
6370 @code{debug-level} is strictly positive.
6371
6372 @item @code{debug-level} (default: @code{0})
6373 Integer denoting the debugging levels. Higher numbers mean more
6374 debugging output is logged.
6375
6376 @item @code{caches} (default: @var{%nscd-default-caches})
6377 List of @code{<nscd-cache>} objects denoting things to be cached; see
6378 below.
6379
6380 @end table
6381 @end deftp
6382
6383 @deftp {Data Type} nscd-cache
6384 Data type representing a cache database of nscd and its parameters.
6385
6386 @table @asis
6387
6388 @item @code{database}
6389 This is a symbol representing the name of the database to be cached.
6390 Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6391 @code{services}, which designate the corresponding NSS database
6392 (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6393
6394 @item @code{positive-time-to-live}
6395 @itemx @code{negative-time-to-live} (default: @code{20})
6396 A number representing the number of seconds during which a positive or
6397 negative lookup result remains in cache.
6398
6399 @item @code{check-files?} (default: @code{#t})
6400 Whether to check for updates of the files corresponding to
6401 @var{database}.
6402
6403 For instance, when @var{database} is @code{hosts}, setting this flag
6404 instructs nscd to check for updates in @file{/etc/hosts} and to take
6405 them into account.
6406
6407 @item @code{persistent?} (default: @code{#t})
6408 Whether the cache should be stored persistently on disk.
6409
6410 @item @code{shared?} (default: @code{#t})
6411 Whether the cache should be shared among users.
6412
6413 @item @code{max-database-size} (default: 32@tie{}MiB)
6414 Maximum size in bytes of the database cache.
6415
6416 @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6417 @c settings, so leave them out.
6418
6419 @end table
6420 @end deftp
6421
6422 @defvr {Scheme Variable} %nscd-default-caches
6423 List of @code{<nscd-cache>} objects used by default by
6424 @code{nscd-configuration} (see above.)
6425
6426 It enables persistent and aggressive caching of service and host name
6427 lookups. The latter provides better host name lookup performance,
6428 resilience in the face of unreliable name servers, and also better
6429 privacy---often the result of host name lookups is in local cache, so
6430 external name servers do not even need to be queried.
6431 @end defvr
6432
6433
6434 @deffn {Scheme Procedure} syslog-service [#:config-file #f]
6435 Return a service that runs @code{syslogd}. If configuration file name
6436 @var{config-file} is not specified, use some reasonable default
6437 settings.
6438 @end deffn
6439
6440 @anchor{guix-configuration-type}
6441 @deftp {Data Type} guix-configuration
6442 This data type represents the configuration of the Guix build daemon.
6443 @xref{Invoking guix-daemon}, for more information.
6444
6445 @table @asis
6446 @item @code{guix} (default: @var{guix})
6447 The Guix package to use.
6448
6449 @item @code{build-group} (default: @code{"guixbuild"})
6450 Name of the group for build user accounts.
6451
6452 @item @code{build-accounts} (default: @code{10})
6453 Number of build user accounts to create.
6454
6455 @item @code{authorize-key?} (default: @code{#t})
6456 Whether to authorize the substitute key for @code{hydra.gnu.org}
6457 (@pxref{Substitutes}).
6458
6459 @item @code{use-substitutes?} (default: @code{#t})
6460 Whether to use substitutes.
6461
6462 @item @code{substitute-urls} (default: @var{%default-substitute-urls})
6463 The list of URLs where to look for substitutes by default.
6464
6465 @item @code{extra-options} (default: @code{'()})
6466 List of extra command-line options for @command{guix-daemon}.
6467
6468 @item @code{lsof} (default: @var{lsof})
6469 @itemx @code{lsh} (default: @var{lsh})
6470 The lsof and lsh packages to use.
6471
6472 @end table
6473 @end deftp
6474
6475 @deffn {Scheme Procedure} guix-service @var{config}
6476 Return a service that runs the Guix build daemon according to
6477 @var{config}.
6478 @end deffn
6479
6480 @deffn {Scheme Procedure} udev-service [#:udev udev]
6481 Run @var{udev}, which populates the @file{/dev} directory dynamically.
6482 @end deffn
6483
6484 @deffn {Scheme Procedure} console-keymap-service @var{file}
6485 Return a service to load console keymap from @var{file} using
6486 @command{loadkeys} command.
6487 @end deffn
6488
6489 @deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
6490 [#:options]
6491 Run @var{gpm}, the general-purpose mouse daemon, with the given
6492 command-line @var{options}. GPM allows users to use the mouse in the console,
6493 notably to select, copy, and paste text. The default value of @var{options}
6494 uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
6495
6496 This service is not part of @var{%base-services}.
6497 @end deffn
6498
6499 @anchor{guix-publish-service}
6500 @deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
6501 [#:port 80] [#:host "localhost"]
6502 Return a service that runs @command{guix publish} listening on @var{host}
6503 and @var{port} (@pxref{Invoking guix publish}).
6504
6505 This assumes that @file{/etc/guix} already contains a signing key pair as
6506 created by @command{guix archive --generate-key} (@pxref{Invoking guix
6507 archive}). If that is not the case, the service will fail to start.
6508 @end deffn
6509
6510
6511 @node Networking Services
6512 @subsubsection Networking Services
6513
6514 The @code{(gnu services networking)} module provides services to configure
6515 the network interface.
6516
6517 @cindex DHCP, networking service
6518 @deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
6519 Return a service that runs @var{dhcp}, a Dynamic Host Configuration
6520 Protocol (DHCP) client, on all the non-loopback network interfaces.
6521 @end deffn
6522
6523 @deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
6524 [#:gateway #f] [#:name-services @code{'()}]
6525 Return a service that starts @var{interface} with address @var{ip}. If
6526 @var{gateway} is true, it must be a string specifying the default network
6527 gateway.
6528 @end deffn
6529
6530 @cindex wicd
6531 @cindex network management
6532 @deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
6533 Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
6534 management daemon that aims to simplify wired and wireless networking.
6535
6536 This service adds the @var{wicd} package to the global profile, providing
6537 several commands to interact with the daemon and configure networking:
6538 @command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
6539 and @command{wicd-curses} user interfaces.
6540 @end deffn
6541
6542 @deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
6543 [#:name-service @var{%ntp-servers}]
6544 Return a service that runs the daemon from @var{ntp}, the
6545 @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
6546 keep the system clock synchronized with that of @var{servers}.
6547 @end deffn
6548
6549 @defvr {Scheme Variable} %ntp-servers
6550 List of host names used as the default NTP servers.
6551 @end defvr
6552
6553 @deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
6554 Return a service to run the @uref{https://torproject.org, Tor} anonymous
6555 networking daemon.
6556
6557 The daemon runs as the @code{tor} unprivileged user. It is passed
6558 @var{config-file}, a file-like object, with an additional @code{User tor}
6559 line. Run @command{man tor} for information about the configuration file.
6560 @end deffn
6561
6562 @deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
6563 [#:interface "127.0.0.1"] [#:port 6667] @
6564 [#:extra-settings ""]
6565 Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
6566 acts as a gateway between IRC and chat networks.
6567
6568 The daemon will listen to the interface corresponding to the IP address
6569 specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
6570 local clients can connect, whereas @code{0.0.0.0} means that connections can
6571 come from any networking interface.
6572
6573 In addition, @var{extra-settings} specifies a string to append to the
6574 configuration file.
6575 @end deffn
6576
6577 Furthermore, @code{(gnu services ssh)} provides the following service.
6578
6579 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
6580 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
6581 [#:allow-empty-passwords? #f] [#:root-login? #f] @
6582 [#:syslog-output? #t] [#:x11-forwarding? #t] @
6583 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
6584 [#:public-key-authentication? #t] [#:initialize? #t]
6585 Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
6586 @var{host-key} must designate a file containing the host key, and readable
6587 only by root.
6588
6589 When @var{daemonic?} is true, @command{lshd} will detach from the
6590 controlling terminal and log its output to syslogd, unless one sets
6591 @var{syslog-output?} to false. Obviously, it also makes lsh-service
6592 depend on existence of syslogd service. When @var{pid-file?} is true,
6593 @command{lshd} writes its PID to the file called @var{pid-file}.
6594
6595 When @var{initialize?} is true, automatically create the seed and host key
6596 upon service activation if they do not exist yet. This may take long and
6597 require interaction.
6598
6599 When @var{initialize?} is false, it is up to the user to initialize the
6600 randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
6601 a key pair with the private key stored in file @var{host-key} (@pxref{lshd
6602 basics,,, lsh, LSH Manual}).
6603
6604 When @var{interfaces} is empty, lshd listens for connections on all the
6605 network interfaces; otherwise, @var{interfaces} must be a list of host names
6606 or addresses.
6607
6608 @var{allow-empty-passwords?} specifies whether to accept log-ins with empty
6609 passwords, and @var{root-login?} specifies whether to accept log-ins as
6610 root.
6611
6612 The other options should be self-descriptive.
6613 @end deffn
6614
6615 @defvr {Scheme Variable} %facebook-host-aliases
6616 This variable contains a string for use in @file{/etc/hosts}
6617 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
6618 line contains a entry that maps a known server name of the Facebook
6619 on-line service---e.g., @code{www.facebook.com}---to the local
6620 host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
6621
6622 This variable is typically used in the @code{hosts-file} field of an
6623 @code{operating-system} declaration (@pxref{operating-system Reference,
6624 @file{/etc/hosts}}):
6625
6626 @example
6627 (use-modules (gnu) (guix))
6628
6629 (operating-system
6630 (host-name "mymachine")
6631 ;; ...
6632 (hosts-file
6633 ;; Create a /etc/hosts file with aliases for "localhost"
6634 ;; and "mymachine", as well as for Facebook servers.
6635 (plain-file "hosts"
6636 (string-append (local-host-aliases host-name)
6637 %facebook-host-aliases))))
6638 @end example
6639
6640 This mechanism can prevent programs running locally, such as Web
6641 browsers, from accessing Facebook.
6642 @end defvr
6643
6644 The @code{(gnu services avahi)} provides the following definition.
6645
6646 @deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
6647 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
6648 [#:ipv6? #t] [#:wide-area? #f] @
6649 [#:domains-to-browse '()]
6650 Return a service that runs @command{avahi-daemon}, a system-wide
6651 mDNS/DNS-SD responder that allows for service discovery and
6652 "zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
6653 extends the name service cache daemon (nscd) so that it can resolve
6654 @code{.local} host names using
6655 @uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
6656 add the @var{avahi} package to the system profile so that commands such as
6657 @command{avahi-browse} are directly usable.
6658
6659 If @var{host-name} is different from @code{#f}, use that as the host name to
6660 publish for this machine; otherwise, use the machine's actual host name.
6661
6662 When @var{publish?} is true, publishing of host names and services is allowed;
6663 in particular, avahi-daemon will publish the machine's host name and IP
6664 address via mDNS on the local network.
6665
6666 When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
6667
6668 Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
6669 sockets.
6670 @end deffn
6671
6672
6673 @node X Window
6674 @subsubsection X Window
6675
6676 Support for the X Window graphical display system---specifically
6677 Xorg---is provided by the @code{(gnu services xorg)} module. Note that
6678 there is no @code{xorg-service} procedure. Instead, the X server is
6679 started by the @dfn{login manager}, currently SLiM.
6680
6681 @deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
6682 [#:auto-login? #f] [#:default-user ""] [#:startx] @
6683 [#:theme @var{%default-slim-theme}] @
6684 [#:theme-name @var{%default-slim-theme-name}]
6685 Return a service that spawns the SLiM graphical login manager, which in
6686 turn starts the X display server with @var{startx}, a command as returned by
6687 @code{xorg-start-command}.
6688
6689 @cindex X session
6690
6691 SLiM automatically looks for session types described by the @file{.desktop}
6692 files in @file{/run/current-system/profile/share/xsessions} and allows users
6693 to choose a session from the log-in screen using @kbd{F1}. Packages such as
6694 @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
6695 adding them to the system-wide set of packages automatically makes them
6696 available at the log-in screen.
6697
6698 In addition, @file{~/.xsession} files are honored. When available,
6699 @file{~/.xsession} must be an executable that starts a window manager
6700 and/or other X clients.
6701
6702 When @var{allow-empty-passwords?} is true, allow logins with an empty
6703 password. When @var{auto-login?} is true, log in automatically as
6704 @var{default-user}.
6705
6706 If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
6707 @var{theme} must be a gexp denoting the name of a directory containing the
6708 theme to use. In that case, @var{theme-name} specifies the name of the
6709 theme.
6710 @end deffn
6711
6712 @defvr {Scheme Variable} %default-theme
6713 @defvrx {Scheme Variable} %default-theme-name
6714 The G-Expression denoting the default SLiM theme and its name.
6715 @end defvr
6716
6717 @deffn {Scheme Procedure} xorg-start-command [#:guile] @
6718 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
6719 Return a derivation that builds a @var{guile} script to start the X server
6720 from @var{xorg-server}. @var{configuration-file} is the server configuration
6721 file or a derivation that builds it; when omitted, the result of
6722 @code{xorg-configuration-file} is used.
6723
6724 Usually the X server is started by a login manager.
6725 @end deffn
6726
6727 @deffn {Scheme Procedure} xorg-configuration-file @
6728 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
6729 Return a configuration file for the Xorg server containing search paths for
6730 all the common drivers.
6731
6732 @var{drivers} must be either the empty list, in which case Xorg chooses a
6733 graphics driver automatically, or a list of driver names that will be tried in
6734 this order---e.g., @code{(\"modesetting\" \"vesa\")}.
6735
6736 Likewise, when @var{resolutions} is the empty list, Xorg chooses an
6737 appropriate screen resolution; otherwise, it must be a list of
6738 resolutions---e.g., @code{((1024 768) (640 480))}.
6739
6740 Last, @var{extra-config} is a list of strings or objects appended to the
6741 @code{text-file*} argument list. It is used to pass extra text to be added
6742 verbatim to the configuration file.
6743 @end deffn
6744
6745 @deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
6746 Add @var{package}, a package for a screen-locker or screen-saver whose
6747 command is @var{program}, to the set of setuid programs and add a PAM entry
6748 for it. For example:
6749
6750 @lisp
6751 (screen-locker-service xlockmore "xlock")
6752 @end lisp
6753
6754 makes the good ol' XlockMore usable.
6755 @end deffn
6756
6757
6758 @node Desktop Services
6759 @subsubsection Desktop Services
6760
6761 The @code{(gnu services desktop)} module provides services that are
6762 usually useful in the context of a ``desktop'' setup---that is, on a
6763 machine running a graphical display server, possibly with graphical user
6764 interfaces, etc.
6765
6766 To simplify things, the module defines a variable containing the set of
6767 services that users typically expect on a machine with a graphical
6768 environment and networking:
6769
6770 @defvr {Scheme Variable} %desktop-services
6771 This is a list of services that builds upon @var{%base-services} and
6772 adds or adjust services for a typical ``desktop'' setup.
6773
6774 In particular, it adds a graphical login manager (@pxref{X Window,
6775 @code{slim-service}}), screen lockers,
6776 a network management tool (@pxref{Networking
6777 Services, @code{wicd-service}}), energy and color management services,
6778 the @code{elogind} login and seat manager, the Polkit privilege service,
6779 the GeoClue location service, an NTP client (@pxref{Networking
6780 Services}), the Avahi daemon, and has the name service switch service
6781 configured to be able to use @code{nss-mdns} (@pxref{Name Service
6782 Switch, mDNS}).
6783 @end defvr
6784
6785 The @var{%desktop-services} variable can be used as the @code{services}
6786 field of an @code{operating-system} declaration (@pxref{operating-system
6787 Reference, @code{services}}).
6788
6789 The actual service definitions provided by @code{(gnu services dbus)}
6790 and @code{(gnu services desktop)} are described below.
6791
6792 @deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
6793 Return a service that runs the ``system bus'', using @var{dbus}, with
6794 support for @var{services}.
6795
6796 @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
6797 facility. Its system bus is used to allow system services to communicate
6798 and be notified of system-wide events.
6799
6800 @var{services} must be a list of packages that provide an
6801 @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
6802 and policy files. For example, to allow avahi-daemon to use the system bus,
6803 @var{services} must be equal to @code{(list avahi)}.
6804 @end deffn
6805
6806 @deffn {Scheme Procedure} elogind-service [#:config @var{config}]
6807 Return a service that runs the @code{elogind} login and
6808 seat management daemon. @uref{https://github.com/andywingo/elogind,
6809 Elogind} exposes a D-Bus interface that can be used to know which users
6810 are logged in, know what kind of sessions they have open, suspend the
6811 system, inhibit system suspend, reboot the system, and other tasks.
6812
6813 Elogind handles most system-level power events for a computer, for
6814 example suspending the system when a lid is closed, or shutting it down
6815 when the power button is pressed.
6816
6817 The @var{config} keyword argument specifies the configuration for
6818 elogind, and should be the result of a @code{(elogind-configuration
6819 (@var{parameter} @var{value})...)} invocation. Available parameters and
6820 their default values are:
6821
6822 @table @code
6823 @item kill-user-processes?
6824 @code{#f}
6825 @item kill-only-users
6826 @code{()}
6827 @item kill-exclude-users
6828 @code{("root")}
6829 @item inhibit-delay-max-seconds
6830 @code{5}
6831 @item handle-power-key
6832 @code{poweroff}
6833 @item handle-suspend-key
6834 @code{suspend}
6835 @item handle-hibernate-key
6836 @code{hibernate}
6837 @item handle-lid-switch
6838 @code{suspend}
6839 @item handle-lid-switch-docked
6840 @code{ignore}
6841 @item power-key-ignore-inhibited?
6842 @code{#f}
6843 @item suspend-key-ignore-inhibited?
6844 @code{#f}
6845 @item hibernate-key-ignore-inhibited?
6846 @code{#f}
6847 @item lid-switch-ignore-inhibited?
6848 @code{#t}
6849 @item holdoff-timeout-seconds
6850 @code{30}
6851 @item idle-action
6852 @code{ignore}
6853 @item idle-action-seconds
6854 @code{(* 30 60)}
6855 @item runtime-directory-size-percent
6856 @code{10}
6857 @item runtime-directory-size
6858 @code{#f}
6859 @item remove-ipc?
6860 @code{#t}
6861 @item suspend-state
6862 @code{("mem" "standby" "freeze")}
6863 @item suspend-mode
6864 @code{()}
6865 @item hibernate-state
6866 @code{("disk")}
6867 @item hibernate-mode
6868 @code{("platform" "shutdown")}
6869 @item hybrid-sleep-state
6870 @code{("disk")}
6871 @item hybrid-sleep-mode
6872 @code{("suspend" "platform" "shutdown")}
6873 @end table
6874 @end deffn
6875
6876 @deffn {Scheme Procedure} polkit-service @
6877 [#:polkit @var{polkit}]
6878 Return a service that runs the
6879 @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
6880 management service}, which allows system administrators to grant access to
6881 privileged operations in a structured way. By querying the Polkit service, a
6882 privileged system component can know when it should grant additional
6883 capabilities to ordinary users. For example, an ordinary user can be granted
6884 the capability to suspend the system if the user is logged in locally.
6885 @end deffn
6886
6887 @deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
6888 [#:watts-up-pro? #f] @
6889 [#:poll-batteries? #t] @
6890 [#:ignore-lid? #f] @
6891 [#:use-percentage-for-policy? #f] @
6892 [#:percentage-low 10] @
6893 [#:percentage-critical 3] @
6894 [#:percentage-action 2] @
6895 [#:time-low 1200] @
6896 [#:time-critical 300] @
6897 [#:time-action 120] @
6898 [#:critical-power-action 'hybrid-sleep]
6899 Return a service that runs @uref{http://upower.freedesktop.org/,
6900 @command{upowerd}}, a system-wide monitor for power consumption and battery
6901 levels, with the given configuration settings. It implements the
6902 @code{org.freedesktop.UPower} D-Bus interface, and is notably used by
6903 GNOME.
6904 @end deffn
6905
6906 @deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
6907 Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
6908 UDisks}, a @dfn{disk management} daemon that provides user interfaces with
6909 notifications and ways to mount/unmount disks. Programs that talk to UDisks
6910 include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
6911 @end deffn
6912
6913 @deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
6914 Return a service that runs @command{colord}, a system service with a D-Bus
6915 interface to manage the color profiles of input and output devices such as
6916 screens and scanners. It is notably used by the GNOME Color Manager graphical
6917 tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
6918 site} for more information.
6919 @end deffn
6920
6921 @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
6922 Return an configuration allowing an application to access GeoClue
6923 location data. @var{name} is the Desktop ID of the application, without
6924 the @code{.desktop} part. If @var{allowed?} is true, the application
6925 will have access to location information by default. The boolean
6926 @var{system?} value indicates that an application is a system component
6927 or not. Finally @var{users} is a list of UIDs of all users for which
6928 this application is allowed location info access. An empty users list
6929 means that all users are allowed.
6930 @end deffn
6931
6932 @defvr {Scheme Variable} %standard-geoclue-applications
6933 The standard list of well-known GeoClue application configurations,
6934 granting authority to GNOME's date-and-time utility to ask for the
6935 current location in order to set the time zone, and allowing the Firefox
6936 (IceCat) and Epiphany web browsers to request location information.
6937 Firefox and Epiphany both query the user before allowing a web page to
6938 know the user's location.
6939 @end defvr
6940
6941 @deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
6942 [#:whitelist '()] @
6943 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
6944 [#:submit-data? #f]
6945 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
6946 [#:submission-nick "geoclue"] @
6947 [#:applications %standard-geoclue-applications]
6948 Return a service that runs the GeoClue location service. This service
6949 provides a D-Bus interface to allow applications to request access to a
6950 user's physical location, and optionally to add information to online
6951 location databases. See
6952 @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
6953 web site} for more information.
6954 @end deffn
6955
6956 @node Database Services
6957 @subsubsection Database Services
6958
6959 The @code{(gnu services databases)} module provides the following service.
6960
6961 @deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
6962 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
6963 Return a service that runs @var{postgresql}, the PostgreSQL database
6964 server.
6965
6966 The PostgreSQL daemon loads its runtime configuration from
6967 @var{config-file} and stores the database cluster in
6968 @var{data-directory}.
6969 @end deffn
6970
6971 @node Web Services
6972 @subsubsection Web Services
6973
6974 The @code{(gnu services web)} module provides the following service:
6975
6976 @deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
6977 [#:log-directory ``/var/log/nginx''] @
6978 [#:run-directory ``/var/run/nginx''] @
6979 [#:config-file]
6980
6981 Return a service that runs @var{nginx}, the nginx web server.
6982
6983 The nginx daemon loads its runtime configuration from @var{config-file}.
6984 Log files are written to @var{log-directory} and temporary runtime data
6985 files are written to @var{run-directory}. For proper operation, these
6986 arguments should match what is in @var{config-file} to ensure that the
6987 directories are created when the service is activated.
6988
6989 @end deffn
6990
6991 @node Various Services
6992 @subsubsection Various Services
6993
6994 The @code{(gnu services lirc)} module provides the following service.
6995
6996 @deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
6997 [#:device #f] [#:driver #f] [#:config-file #f] @
6998 [#:extra-options '()]
6999 Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
7000 decodes infrared signals from remote controls.
7001
7002 Optionally, @var{device}, @var{driver} and @var{config-file}
7003 (configuration file name) may be specified. See @command{lircd} manual
7004 for details.
7005
7006 Finally, @var{extra-options} is a list of additional command-line options
7007 passed to @command{lircd}.
7008 @end deffn
7009
7010
7011 @node Setuid Programs
7012 @subsection Setuid Programs
7013
7014 @cindex setuid programs
7015 Some programs need to run with ``root'' privileges, even when they are
7016 launched by unprivileged users. A notorious example is the
7017 @command{passwd} program, which users can run to change their
7018 password, and which needs to access the @file{/etc/passwd} and
7019 @file{/etc/shadow} files---something normally restricted to root, for
7020 obvious security reasons. To address that, these executables are
7021 @dfn{setuid-root}, meaning that they always run with root privileges
7022 (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
7023 for more info about the setuid mechanisms.)
7024
7025 The store itself @emph{cannot} contain setuid programs: that would be a
7026 security issue since any user on the system can write derivations that
7027 populate the store (@pxref{The Store}). Thus, a different mechanism is
7028 used: instead of changing the setuid bit directly on files that are in
7029 the store, we let the system administrator @emph{declare} which programs
7030 should be setuid root.
7031
7032 The @code{setuid-programs} field of an @code{operating-system}
7033 declaration contains a list of G-expressions denoting the names of
7034 programs to be setuid-root (@pxref{Using the Configuration System}).
7035 For instance, the @command{passwd} program, which is part of the Shadow
7036 package, can be designated by this G-expression (@pxref{G-Expressions}):
7037
7038 @example
7039 #~(string-append #$shadow "/bin/passwd")
7040 @end example
7041
7042 A default set of setuid programs is defined by the
7043 @code{%setuid-programs} variable of the @code{(gnu system)} module.
7044
7045 @defvr {Scheme Variable} %setuid-programs
7046 A list of G-expressions denoting common programs that are setuid-root.
7047
7048 The list includes commands such as @command{passwd}, @command{ping},
7049 @command{su}, and @command{sudo}.
7050 @end defvr
7051
7052 Under the hood, the actual setuid programs are created in the
7053 @file{/run/setuid-programs} directory at system activation time. The
7054 files in this directory refer to the ``real'' binaries, which are in the
7055 store.
7056
7057 @node X.509 Certificates
7058 @subsection X.509 Certificates
7059
7060 @cindex HTTPS, certificates
7061 @cindex X.509 certificates
7062 @cindex TLS
7063 Web servers available over HTTPS (that is, HTTP over the transport-layer
7064 security mechanism, TLS) send client programs an @dfn{X.509 certificate}
7065 that the client can then use to @emph{authenticate} the server. To do
7066 that, clients verify that the server's certificate is signed by a
7067 so-called @dfn{certificate authority} (CA). But to verify the CA's
7068 signature, clients must have first acquired the CA's certificate.
7069
7070 Web browsers such as GNU@tie{}IceCat include their own set of CA
7071 certificates, such that they are able to verify CA signatures
7072 out-of-the-box.
7073
7074 However, most other programs that can talk HTTPS---@command{wget},
7075 @command{git}, @command{w3m}, etc.---need to be told where CA
7076 certificates can be found.
7077
7078 @cindex @code{nss-certs}
7079 In GuixSD, this is done by adding a package that provides certificates
7080 to the @code{packages} field of the @code{operating-system} declaration
7081 (@pxref{operating-system Reference}). GuixSD includes one such package,
7082 @code{nss-certs}, which is a set of CA certificates provided as part of
7083 Mozilla's Network Security Services.
7084
7085 Note that it is @emph{not} part of @var{%base-packages}, so you need to
7086 explicitly add it. The @file{/etc/ssl/certs} directory, which is where
7087 most applications and libraries look for certificates by default, points
7088 to the certificates installed globally.
7089
7090 Unprivileged users can also install their own certificate package in
7091 their profile. A number of environment variables need to be defined so
7092 that applications and libraries know where to find them. Namely, the
7093 OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
7094 variables. Some applications add their own environment variables; for
7095 instance, the Git version control system honors the certificate bundle
7096 pointed to by the @code{GIT_SSL_CAINFO} environment variable.
7097
7098
7099 @node Name Service Switch
7100 @subsection Name Service Switch
7101
7102 @cindex name service switch
7103 @cindex NSS
7104 The @code{(gnu system nss)} module provides bindings to the
7105 configuration file of libc's @dfn{name service switch} or @dfn{NSS}
7106 (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
7107 Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
7108 extended with new ``name'' lookup methods for system databases, which
7109 includes host names, service names, user accounts, and more (@pxref{Name
7110 Service Switch, System Databases and Name Service Switch,, libc, The GNU
7111 C Library Reference Manual}).
7112
7113 The NSS configuration specifies, for each system database, which lookup
7114 method is to be used, and how the various methods are chained
7115 together---for instance, under which circumstances NSS should try the
7116 next method in the list. The NSS configuration is given in the
7117 @code{name-service-switch} field of @code{operating-system} declarations
7118 (@pxref{operating-system Reference, @code{name-service-switch}}).
7119
7120 @cindex nss-mdns
7121 @cindex .local, host name lookup
7122 As an example, the declaration below configures the NSS to use the
7123 @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
7124 back-end}, which supports host name lookups over multicast DNS (mDNS)
7125 for host names ending in @code{.local}:
7126
7127 @example
7128 (name-service-switch
7129 (hosts (list %files ;first, check /etc/hosts
7130
7131 ;; If the above did not succeed, try
7132 ;; with 'mdns_minimal'.
7133 (name-service
7134 (name "mdns_minimal")
7135
7136 ;; 'mdns_minimal' is authoritative for
7137 ;; '.local'. When it returns "not found",
7138 ;; no need to try the next methods.
7139 (reaction (lookup-specification
7140 (not-found => return))))
7141
7142 ;; Then fall back to DNS.
7143 (name-service
7144 (name "dns"))
7145
7146 ;; Finally, try with the "full" 'mdns'.
7147 (name-service
7148 (name "mdns")))))
7149 @end example
7150
7151 Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
7152 contains this configuration, so you won't have to type it if all you
7153 want is to have @code{.local} host lookup working.
7154
7155 Note that, in this case, in addition to setting the
7156 @code{name-service-switch} of the @code{operating-system} declaration,
7157 you also need to use @code{avahi-service} (@pxref{Networking Services,
7158 @code{avahi-service}}), or @var{%desktop-services}, which includes it
7159 (@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
7160 to the name service cache daemon (@pxref{Base Services,
7161 @code{nscd-service}}).
7162
7163 For convenience, the following variables provide typical NSS
7164 configurations.
7165
7166 @defvr {Scheme Variable} %default-nss
7167 This is the default name service switch configuration, a
7168 @code{name-service-switch} object.
7169 @end defvr
7170
7171 @defvr {Scheme Variable} %mdns-host-lookup-nss
7172 This is the name service switch configuration with support for host name
7173 lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
7174 @end defvr
7175
7176 The reference for name service switch configuration is given below. It
7177 is a direct mapping of the C library's configuration file format, so
7178 please refer to the C library manual for more information (@pxref{NSS
7179 Configuration File,,, libc, The GNU C Library Reference Manual}).
7180 Compared to libc's NSS configuration file format, it has the advantage
7181 not only of adding this warm parenthetic feel that we like, but also
7182 static checks: you'll know about syntax errors and typos as soon as you
7183 run @command{guix system}.
7184
7185 @deftp {Data Type} name-service-switch
7186
7187 This is the data type representation the configuration of libc's name
7188 service switch (NSS). Each field below represents one of the supported
7189 system databases.
7190
7191 @table @code
7192 @item aliases
7193 @itemx ethers
7194 @itemx group
7195 @itemx gshadow
7196 @itemx hosts
7197 @itemx initgroups
7198 @itemx netgroup
7199 @itemx networks
7200 @itemx password
7201 @itemx public-key
7202 @itemx rpc
7203 @itemx services
7204 @itemx shadow
7205 The system databases handled by the NSS. Each of these fields must be a
7206 list of @code{<name-service>} objects (see below.)
7207 @end table
7208 @end deftp
7209
7210 @deftp {Data Type} name-service
7211
7212 This is the data type representing an actual name service and the
7213 associated lookup action.
7214
7215 @table @code
7216 @item name
7217 A string denoting the name service (@pxref{Services in the NSS
7218 configuration,,, libc, The GNU C Library Reference Manual}).
7219
7220 Note that name services listed here must be visible to nscd. This is
7221 achieved by passing the @code{#:name-services} argument to
7222 @code{nscd-service} the list of packages providing the needed name
7223 services (@pxref{Base Services, @code{nscd-service}}).
7224
7225 @item reaction
7226 An action specified using the @code{lookup-specification} macro
7227 (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
7228 Reference Manual}). For example:
7229
7230 @example
7231 (lookup-specification (unavailable => continue)
7232 (success => return))
7233 @end example
7234 @end table
7235 @end deftp
7236
7237 @node Initial RAM Disk
7238 @subsection Initial RAM Disk
7239
7240 @cindex initial RAM disk (initrd)
7241 @cindex initrd (initial RAM disk)
7242 For bootstrapping purposes, the Linux-Libre kernel is passed an
7243 @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
7244 root file system, as well as an initialization script. The latter is
7245 responsible for mounting the real root file system, and for loading any
7246 kernel modules that may be needed to achieve that.
7247
7248 The @code{initrd} field of an @code{operating-system} declaration allows
7249 you to specify which initrd you would like to use. The @code{(gnu
7250 system linux-initrd)} module provides two ways to build an initrd: the
7251 high-level @code{base-initrd} procedure, and the low-level
7252 @code{expression->initrd} procedure.
7253
7254 The @code{base-initrd} procedure is intended to cover most common uses.
7255 For example, if you want to add a bunch of kernel modules to be loaded
7256 at boot time, you can define the @code{initrd} field of the operating
7257 system declaration like this:
7258
7259 @example
7260 (initrd (lambda (file-systems . rest)
7261 ;; Create a standard initrd that has modules "foo.ko"
7262 ;; and "bar.ko", as well as their dependencies, in
7263 ;; addition to the modules available by default.
7264 (apply base-initrd file-systems
7265 #:extra-modules '("foo" "bar")
7266 rest)))
7267 @end example
7268
7269 The @code{base-initrd} procedure also handles common use cases that
7270 involves using the system as a QEMU guest, or as a ``live'' system whose
7271 root file system is volatile.
7272
7273 @deffn {Monadic Procedure} base-initrd @var{file-systems} @
7274 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
7275 [#:extra-modules '()] [#:mapped-devices '()]
7276 Return a monadic derivation that builds a generic initrd. @var{file-systems} is
7277 a list of file-systems to be mounted by the initrd, possibly in addition to
7278 the root file system specified on the kernel command line via @code{--root}.
7279 @var{mapped-devices} is a list of device mappings to realize before
7280 @var{file-systems} are mounted (@pxref{Mapped Devices}).
7281
7282 When @var{qemu-networking?} is true, set up networking with the standard QEMU
7283 parameters. When @var{virtio?} is true, load additional modules so the initrd can
7284 be used as a QEMU guest with para-virtualized I/O drivers.
7285
7286 When @var{volatile-root?} is true, the root file system is writable but any changes
7287 to it are lost.
7288
7289 The initrd is automatically populated with all the kernel modules necessary
7290 for @var{file-systems} and for the given options. However, additional kernel
7291 modules can be listed in @var{extra-modules}. They will be added to the initrd, and
7292 loaded at boot time in the order in which they appear.
7293 @end deffn
7294
7295 Needless to say, the initrds we produce and use embed a
7296 statically-linked Guile, and the initialization program is a Guile
7297 program. That gives a lot of flexibility. The
7298 @code{expression->initrd} procedure builds such an initrd, given the
7299 program to run in that initrd.
7300
7301 @deffn {Monadic Procedure} expression->initrd @var{exp} @
7302 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
7303 [#:modules '()]
7304 Return a derivation that builds a Linux initrd (a gzipped cpio archive)
7305 containing @var{guile} and that evaluates @var{exp}, a G-expression,
7306 upon booting. All the derivations referenced by @var{exp} are
7307 automatically copied to the initrd.
7308
7309 @var{modules} is a list of Guile module names to be embedded in the
7310 initrd.
7311 @end deffn
7312
7313 @node GRUB Configuration
7314 @subsection GRUB Configuration
7315
7316 @cindex GRUB
7317 @cindex boot loader
7318
7319 The operating system uses GNU@tie{}GRUB as its boot loader
7320 (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
7321 configured using @code{grub-configuration} declarations. This data type
7322 is exported by the @code{(gnu system grub)} module, and described below.
7323
7324 @deftp {Data Type} grub-configuration
7325 The type of a GRUB configuration declaration.
7326
7327 @table @asis
7328
7329 @item @code{device}
7330 This is a string denoting the boot device. It must be a device name
7331 understood by the @command{grub-install} command, such as
7332 @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
7333 GNU GRUB Manual}).
7334
7335 @item @code{menu-entries} (default: @code{()})
7336 A possibly empty list of @code{menu-entry} objects (see below), denoting
7337 entries to appear in the GRUB boot menu, in addition to the current
7338 system entry and the entry pointing to previous system generations.
7339
7340 @item @code{default-entry} (default: @code{0})
7341 The index of the default boot menu entry. Index 0 is for the current
7342 system's entry.
7343
7344 @item @code{timeout} (default: @code{5})
7345 The number of seconds to wait for keyboard input before booting. Set to
7346 0 to boot immediately, and to -1 to wait indefinitely.
7347
7348 @item @code{theme} (default: @var{%default-theme})
7349 The @code{grub-theme} object describing the theme to use.
7350 @end table
7351
7352 @end deftp
7353
7354 Should you want to list additional boot menu entries @i{via} the
7355 @code{menu-entries} field above, you will need to create them with the
7356 @code{menu-entry} form:
7357
7358 @deftp {Data Type} menu-entry
7359 The type of an entry in the GRUB boot menu.
7360
7361 @table @asis
7362
7363 @item @code{label}
7364 The label to show in the menu---e.g., @code{"GNU"}.
7365
7366 @item @code{linux}
7367 The Linux kernel to boot.
7368
7369 @item @code{linux-arguments} (default: @code{()})
7370 The list of extra Linux kernel command-line arguments---e.g.,
7371 @code{("console=ttyS0")}.
7372
7373 @item @code{initrd}
7374 A G-Expression or string denoting the file name of the initial RAM disk
7375 to use (@pxref{G-Expressions}).
7376
7377 @end table
7378 @end deftp
7379
7380 @c FIXME: Write documentation once it's stable.
7381 Themes are created using the @code{grub-theme} form, which is not
7382 documented yet.
7383
7384 @defvr {Scheme Variable} %default-theme
7385 This is the default GRUB theme used by the operating system, with a
7386 fancy background image displaying the GNU and Guix logos.
7387 @end defvr
7388
7389
7390 @node Invoking guix system
7391 @subsection Invoking @code{guix system}
7392
7393 Once you have written an operating system declaration, as seen in the
7394 previous section, it can be @dfn{instantiated} using the @command{guix
7395 system} command. The synopsis is:
7396
7397 @example
7398 guix system @var{options}@dots{} @var{action} @var{file}
7399 @end example
7400
7401 @var{file} must be the name of a file containing an
7402 @code{operating-system} declaration. @var{action} specifies how the
7403 operating system is instantiate. Currently the following values are
7404 supported:
7405
7406 @table @code
7407 @item reconfigure
7408 Build the operating system described in @var{file}, activate it, and
7409 switch to it@footnote{This action is usable only on systems already
7410 running GuixSD.}.
7411
7412 This effects all the configuration specified in @var{file}: user
7413 accounts, system services, global package list, setuid programs, etc.
7414
7415 It also adds a GRUB menu entry for the new OS configuration, and moves
7416 entries for older configurations to a submenu---unless
7417 @option{--no-grub} is passed.
7418
7419 @c The paragraph below refers to the problem discussed at
7420 @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
7421 It is highly recommended to run @command{guix pull} once before you run
7422 @command{guix system reconfigure} for the first time (@pxref{Invoking
7423 guix pull}). Failing to do that you would see an older version of Guix
7424 once @command{reconfigure} has completed.
7425
7426 @item build
7427 Build the operating system's derivation, which includes all the
7428 configuration files and programs needed to boot and run the system.
7429 This action does not actually install anything.
7430
7431 @item init
7432 Populate the given directory with all the files necessary to run the
7433 operating system specified in @var{file}. This is useful for first-time
7434 installations of GuixSD. For instance:
7435
7436 @example
7437 guix system init my-os-config.scm /mnt
7438 @end example
7439
7440 copies to @file{/mnt} all the store items required by the configuration
7441 specified in @file{my-os-config.scm}. This includes configuration
7442 files, packages, and so on. It also creates other essential files
7443 needed for the system to operate correctly---e.g., the @file{/etc},
7444 @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
7445
7446 This command also installs GRUB on the device specified in
7447 @file{my-os-config}, unless the @option{--no-grub} option was passed.
7448
7449 @item vm
7450 @cindex virtual machine
7451 @cindex VM
7452 @anchor{guix system vm}
7453 Build a virtual machine that contain the operating system declared in
7454 @var{file}, and return a script to run that virtual machine (VM).
7455 Arguments given to the script are passed as is to QEMU.
7456
7457 The VM shares its store with the host system.
7458
7459 Additional file systems can be shared between the host and the VM using
7460 the @code{--share} and @code{--expose} command-line options: the former
7461 specifies a directory to be shared with write access, while the latter
7462 provides read-only access to the shared directory.
7463
7464 The example below creates a VM in which the user's home directory is
7465 accessible read-only, and where the @file{/exchange} directory is a
7466 read-write mapping of the host's @file{$HOME/tmp}:
7467
7468 @example
7469 guix system vm my-config.scm \
7470 --expose=$HOME --share=$HOME/tmp=/exchange
7471 @end example
7472
7473 On GNU/Linux, the default is to boot directly to the kernel; this has
7474 the advantage of requiring only a very tiny root disk image since the
7475 host's store can then be mounted.
7476
7477 The @code{--full-boot} option forces a complete boot sequence, starting
7478 with the bootloader. This requires more disk space since a root image
7479 containing at least the kernel, initrd, and bootloader data files must
7480 be created. The @code{--image-size} option can be used to specify the
7481 image's size.
7482
7483 @item vm-image
7484 @itemx disk-image
7485 Return a virtual machine or disk image of the operating system declared
7486 in @var{file} that stands alone. Use the @option{--image-size} option
7487 to specify the size of the image.
7488
7489 When using @code{vm-image}, the returned image is in qcow2 format, which
7490 the QEMU emulator can efficiently use.
7491
7492 When using @code{disk-image}, a raw disk image is produced; it can be
7493 copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
7494 the device corresponding to a USB stick, one can copy the image on it
7495 using the following command:
7496
7497 @example
7498 # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
7499 @end example
7500
7501 @item container
7502 Return a script to run the operating system declared in @var{file}
7503 within a container. Containers are a set of lightweight isolation
7504 mechanisms provided by the kernel Linux-libre. Containers are
7505 substantially less resource-demanding than full virtual machines since
7506 the kernel, shared objects, and other resources can be shared with the
7507 host system; this also means they provide thinner isolation.
7508
7509 Currently, the script must be run as root in order to support more than
7510 a single user and group. The container shares its store with the host
7511 system.
7512
7513 As with the @code{vm} action (@pxref{guix system vm}), additional file
7514 systems to be shared between the host and container can be specified
7515 using the @option{--share} and @option{--expose} options:
7516
7517 @example
7518 guix system container my-config.scm \
7519 --expose=$HOME --share=$HOME/tmp=/exchange
7520 @end example
7521
7522 @quotation Note
7523 This option requires Linux-libre 3.19 or newer.
7524 @end quotation
7525
7526 @end table
7527
7528 @var{options} can contain any of the common build options provided by
7529 @command{guix build} (@pxref{Invoking guix build}). In addition,
7530 @var{options} can contain one of the following:
7531
7532 @table @option
7533 @item --system=@var{system}
7534 @itemx -s @var{system}
7535 Attempt to build for @var{system} instead of the host's system type.
7536 This works as per @command{guix build} (@pxref{Invoking guix build}).
7537
7538 @item --derivation
7539 @itemx -d
7540 Return the derivation file name of the given operating system without
7541 building anything.
7542
7543 @item --image-size=@var{size}
7544 For the @code{vm-image} and @code{disk-image} actions, create an image
7545 of the given @var{size}. @var{size} may be a number of bytes, or it may
7546 include a unit as a suffix (@pxref{Block size, size specifications,,
7547 coreutils, GNU Coreutils}).
7548
7549 @item --on-error=@var{strategy}
7550 Apply @var{strategy} when an error occurs when reading @var{file}.
7551 @var{strategy} may be one of the following:
7552
7553 @table @code
7554 @item nothing-special
7555 Report the error concisely and exit. This is the default strategy.
7556
7557 @item backtrace
7558 Likewise, but also display a backtrace.
7559
7560 @item debug
7561 Report the error and enter Guile's debugger. From there, you can run
7562 commands such as @code{,bt} to get a backtrace, @code{,locals} to
7563 display local variable values, and more generally inspect the program's
7564 state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
7565 a list of available debugging commands.
7566 @end table
7567 @end table
7568
7569 Note that all the actions above, except @code{build} and @code{init},
7570 rely on KVM support in the Linux-Libre kernel. Specifically, the
7571 machine should have hardware virtualization support, the corresponding
7572 KVM kernel module should be loaded, and the @file{/dev/kvm} device node
7573 must exist and be readable and writable by the user and by the daemon's
7574 build users.
7575
7576 Once you have built, configured, re-configured, and re-re-configured
7577 your GuixSD installation, you may find it useful to list the operating
7578 system generations available on disk---and that you can choose from the
7579 GRUB boot menu:
7580
7581 @table @code
7582
7583 @item list-generations
7584 List a summary of each generation of the operating system available on
7585 disk, in a human-readable way. This is similar to the
7586 @option{--list-generations} option of @command{guix package}
7587 (@pxref{Invoking guix package}).
7588
7589 Optionally, one can specify a pattern, with the same syntax that is used
7590 in @command{guix package --list-generations}, to restrict the list of
7591 generations displayed. For instance, the following command displays
7592 generations up to 10-day old:
7593
7594 @example
7595 $ guix system list-generations 10d
7596 @end example
7597
7598 @end table
7599
7600 The @command{guix system} command has even more to offer! The following
7601 sub-commands allow you to visualize how your system services relate to
7602 each other:
7603
7604 @anchor{system-extension-graph}
7605 @table @code
7606
7607 @item extension-graph
7608 Emit in Dot/Graphviz format to standard output the @dfn{service
7609 extension graph} of the operating system defined in @var{file}
7610 (@pxref{Service Composition}, for more information on service
7611 extensions.)
7612
7613 The command:
7614
7615 @example
7616 $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
7617 @end example
7618
7619 produces a PDF file showing the extension relations among services.
7620
7621 @anchor{system-dmd-graph}
7622 @item dmd-graph
7623 Emit in Dot/Graphviz format to standard output the @dfn{dependency
7624 graph} of dmd services of the operating system defined in @var{file}.
7625 @xref{dmd Services}, for more information and for an example graph.
7626
7627 @end table
7628
7629
7630 @node Defining Services
7631 @subsection Defining Services
7632
7633 The previous sections show the available services and how one can combine
7634 them in an @code{operating-system} declaration. But how do we define
7635 them in the first place? And what is a service anyway?
7636
7637 @menu
7638 * Service Composition:: The model for composing services.
7639 * Service Types and Services:: Types and services.
7640 * Service Reference:: API reference.
7641 * dmd Services:: A particular type of service.
7642 @end menu
7643
7644 @node Service Composition
7645 @subsubsection Service Composition
7646
7647 @cindex services
7648 @cindex daemons
7649 Here we define a @dfn{service} as, broadly, something that extends the
7650 operating system's functionality. Often a service is a process---a
7651 @dfn{daemon}---started when the system boots: a secure shell server, a
7652 Web server, the Guix build daemon, etc. Sometimes a service is a daemon
7653 whose execution can be triggered by another daemon---e.g., an FTP server
7654 started by @command{inetd} or a D-Bus service activated by
7655 @command{dbus-daemon}. Occasionally, a service does not map to a
7656 daemon. For instance, the ``account'' service collects user accounts
7657 and makes sure they exist when the system runs; the ``udev'' service
7658 collects device management rules and makes them available to the eudev
7659 daemon; the @file{/etc} service populates the system's @file{/etc}
7660 directory.
7661
7662 @cindex service extensions
7663 GuixSD services are connected by @dfn{extensions}. For instance, the
7664 secure shell service @emph{extends} dmd---GuixSD's initialization system,
7665 running as PID@tie{}1---by giving it the command lines to start and stop
7666 the secure shell daemon (@pxref{Networking Services,
7667 @code{lsh-service}}); the UPower service extends the D-Bus service by
7668 passing it its @file{.service} specification, and extends the udev
7669 service by passing it device management rules (@pxref{Desktop Services,
7670 @code{upower-service}}); the Guix daemon service extends dmd by passing
7671 it the command lines to start and stop the daemon, and extends the
7672 account service by passing it a list of required build user accounts
7673 (@pxref{Base Services}).
7674
7675 All in all, services and their ``extends'' relations form a directed
7676 acyclic graph (DAG). If we represent services as boxes and extensions
7677 as arrows, a typical system might provide something like this:
7678
7679 @image{images/service-graph,,5in,Typical service extension graph.}
7680
7681 @cindex system service
7682 At the bottom, we see the @dfn{system service}, which produces the
7683 directory containing everything to run and boot the system, as returned
7684 by the @command{guix system build} command. @xref{Service Reference},
7685 to learn about the other service types shown here.
7686 @xref{system-extension-graph, the @command{guix system extension-graph}
7687 command}, for information on how to generate this representation for a
7688 particular operating system definition.
7689
7690 @cindex service types
7691 Technically, developers can define @dfn{service types} to express these
7692 relations. There can be any number of services of a given type on the
7693 system---for instance, a system running two instances of the GNU secure
7694 shell server (lsh) has two instances of @var{lsh-service-type}, with
7695 different parameters.
7696
7697 The following section describes the programming interface for service
7698 types and services.
7699
7700 @node Service Types and Services
7701 @subsubsection Service Types and Services
7702
7703 A @dfn{service type} is a node in the DAG described above. Let us start
7704 with a simple example, the service type for the Guix build daemon
7705 (@pxref{Invoking guix-daemon}):
7706
7707 @example
7708 (define guix-service-type
7709 (service-type
7710 (name 'guix)
7711 (extensions
7712 (list (service-extension dmd-root-service-type guix-dmd-service)
7713 (service-extension account-service-type guix-accounts)
7714 (service-extension activation-service-type guix-activation)))))
7715 @end example
7716
7717 @noindent
7718 It defines a two things:
7719
7720 @enumerate
7721 @item
7722 A name, whose sole purpose is to make inspection and debugging easier.
7723
7724 @item
7725 A list of @dfn{service extensions}, where each extension designates the
7726 target service type and a procedure that, given the service's
7727 parameters, returns a list of object to extend the service of that type.
7728
7729 Every service type has at least one service extension. The only
7730 exception is the @dfn{boot service type}, which is the ultimate service.
7731 @end enumerate
7732
7733 In this example, @var{guix-service-type} extends three services:
7734
7735 @table @var
7736 @item dmd-root-service-type
7737 The @var{guix-dmd-service} procedure defines how the dmd service is
7738 extended. Namely, it returns a @code{<dmd-service>} object that defines
7739 how @command{guix-daemon} is started and stopped (@pxref{dmd Services}).
7740
7741 @item account-service-type
7742 This extension for this service is computed by @var{guix-accounts},
7743 which returns a list of @code{user-group} and @code{user-account}
7744 objects representing the build user accounts (@pxref{Invoking
7745 guix-daemon}).
7746
7747 @item activation-service-type
7748 Here @var{guix-activation} is a procedure that returns a gexp, which is
7749 a code snippet to run at ``activation time''---e.g., when the service is
7750 booted.
7751 @end table
7752
7753 A service of this type is instantiated like this:
7754
7755 @example
7756 (service guix-service-type
7757 (guix-configuration
7758 (build-accounts 5)
7759 (use-substitutes? #f)))
7760 @end example
7761
7762 The second argument to the @code{service} form is a value representing
7763 the parameters of this specific service instance.
7764 @xref{guix-configuration-type, @code{guix-configuration}}, for
7765 information about the @code{guix-configuration} data type.
7766
7767 @var{guix-service-type} is quite simple because it extends other
7768 services but is not extensible itself.
7769
7770 @c @subsubsubsection Extensible Service Types
7771
7772 The service type for an @emph{extensible} service looks like this:
7773
7774 @example
7775 (define udev-service-type
7776 (service-type (name 'udev)
7777 (extensions
7778 (list (service-extension dmd-root-service-type
7779 udev-dmd-service)))
7780
7781 (compose concatenate) ;concatenate the list of rules
7782 (extend (lambda (config rules)
7783 (match config
7784 (($ <udev-configuration> udev initial-rules)
7785 (udev-configuration
7786 (udev udev) ;the udev package to use
7787 (rules (append initial-rules rules)))))))))
7788 @end example
7789
7790 This is the service type for the
7791 @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
7792 management daemon}. Compared to the previous example, in addition to an
7793 extension of @var{dmd-root-service-type}, we see two new fields:
7794
7795 @table @code
7796 @item compose
7797 This is the procedure to @dfn{compose} the list of extensions to
7798 services of this type.
7799
7800 Services can extend the udev service by passing it lists of rules; we
7801 compose those extensions simply by concatenating them.
7802
7803 @item extend
7804 This procedure defines how the service's value is @dfn{extended} with
7805 the composition of the extensions.
7806
7807 Udev extensions are composed into a list of rules, but the udev service
7808 value is itself a @code{<udev-configuration>} record. So here, we
7809 extend that record by appending the list of rules is contains to the
7810 list of contributed rules.
7811 @end table
7812
7813 There can be only one instance of an extensible service type such as
7814 @var{udev-service-type}. If there were more, the
7815 @code{service-extension} specifications would be ambiguous.
7816
7817 Still here? The next section provides a reference of the programming
7818 interface for services.
7819
7820 @node Service Reference
7821 @subsubsection Service Reference
7822
7823 We have seen an overview of service types (@pxref{Service Types and
7824 Services}). This section provides a reference on how to manipulate
7825 services and service types. This interface is provided by the
7826 @code{(gnu services)} module.
7827
7828 @deffn {Scheme Procedure} service @var{type} @var{value}
7829 Return a new service of @var{type}, a @code{<service-type>} object (see
7830 below.) @var{value} can be any object; it represents the parameters of
7831 this particular service instance.
7832 @end deffn
7833
7834 @deffn {Scheme Procedure} service? @var{obj}
7835 Return true if @var{obj} is a service.
7836 @end deffn
7837
7838 @deffn {Scheme Procedure} service-kind @var{service}
7839 Return the type of @var{service}---i.e., a @code{<service-type>} object.
7840 @end deffn
7841
7842 @deffn {Scheme Procedure} service-parameters @var{service}
7843 Return the value associated with @var{service}. It represents its
7844 parameters.
7845 @end deffn
7846
7847 Here is an example of how a service is created and manipulated:
7848
7849 @example
7850 (define s
7851 (service nginx-service-type
7852 (nginx-configuration
7853 (nginx nginx)
7854 (log-directory log-directory)
7855 (run-directory run-directory)
7856 (file config-file))))
7857
7858 (service? s)
7859 @result{} #t
7860
7861 (eq? (service-kind s) nginx-service-type)
7862 @result{} #t
7863 @end example
7864
7865 The @code{modify-services} form provides a handy way to change the
7866 parameters of some of the services of a list such as
7867 @var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
7868 course, you could always use standard list combinators such as
7869 @code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
7870 guile, GNU Guile Reference Manual}); @code{modify-services} simply
7871 provides a more concise form for this common pattern.
7872
7873 @deffn {Scheme Syntax} modify-services @var{services} @
7874 (@var{type} @var{variable} => @var{body}) @dots{}
7875
7876 Modify the services listed in @var{services} according to the given
7877 clauses. Each clause has the form:
7878
7879 @example
7880 (@var{type} @var{variable} => @var{body})
7881 @end example
7882
7883 where @var{type} is a service type, such as @var{guix-service-type}, and
7884 @var{variable} is an identifier that is bound within @var{body} to the
7885 value of the service of that @var{type}. @xref{Using the Configuration
7886 System}, for an example.
7887
7888 This is a shorthand for:
7889
7890 @example
7891 (map (lambda (service) @dots{}) @var{services})
7892 @end example
7893 @end deffn
7894
7895 Next comes the programming interface for service types. This is
7896 something you want to know when writing new service definitions, but not
7897 necessarily when simply looking for ways to customize your
7898 @code{operating-system} declaration.
7899
7900 @deftp {Data Type} service-type
7901 @cindex service type
7902 This is the representation of a @dfn{service type} (@pxref{Service Types
7903 and Services}).
7904
7905 @table @asis
7906 @item @code{name}
7907 This is a symbol, used only to simplify inspection and debugging.
7908
7909 @item @code{extensions}
7910 A non-empty list of @code{<service-extension>} objects (see below.)
7911
7912 @item @code{compose} (default: @code{#f})
7913 If this is @code{#f}, then the service type denotes services that cannot
7914 be extended---i.e., services that do not receive ``values'' from other
7915 services.
7916
7917 Otherwise, it must be a one-argument procedure. The procedure is called
7918 by @code{fold-services} and is passed a list of values collected from
7919 extensions. It must return a value that is a valid parameter value for
7920 the service instance.
7921
7922 @item @code{extend} (default: @code{#f})
7923 If this is @code{#f}, services of this type cannot be extended.
7924
7925 Otherwise, it must be a two-argument procedure: @code{fold-services}
7926 calls it, passing it the service's initial value as the first argument
7927 and the result of applying @code{compose} to the extension values as the
7928 second argument.
7929 @end table
7930
7931 @xref{Service Types and Services}, for examples.
7932 @end deftp
7933
7934 @deffn {Scheme Procedure} service-extension @var{target-type} @
7935 @var{compute}
7936 Return a new extension for services of type @var{target-type}.
7937 @var{compute} must be a one-argument procedure: @code{fold-services}
7938 calls it, passing it the value associated with the service that provides
7939 the extension; it must return a valid value for the target service.
7940 @end deffn
7941
7942 @deffn {Scheme Procedure} service-extension? @var{obj}
7943 Return true if @var{obj} is a service extension.
7944 @end deffn
7945
7946 At the core of the service abstraction lies the @code{fold-services}
7947 procedure, which is responsible for ``compiling'' a list of services
7948 down to a single directory that contains everything needed to boot and
7949 run the system---the directory shown by the @command{guix system build}
7950 command (@pxref{Invoking guix system}). In essence, it propagates
7951 service extensions down the service graph, updating each node parameters
7952 on the way, until it reaches the root node.
7953
7954 @deffn {Scheme Procedure} fold-services @var{services} @
7955 [#:target-type @var{system-service-type}]
7956 Fold @var{services} by propagating their extensions down to the root of
7957 type @var{target-type}; return the root service adjusted accordingly.
7958 @end deffn
7959
7960 Lastly, the @code{(gnu services)} module also defines several essential
7961 service types, some of which are listed below.
7962
7963 @defvr {Scheme Variable} system-service-type
7964 This is the root of the service graph. It produces the system directory
7965 as returned by the @command{guix system build} command.
7966 @end defvr
7967
7968 @defvr {Scheme Variable} boot-service-type
7969 The type of the ``boot service'', which produces the @dfn{boot script}.
7970 The boot script is what the initial RAM disk runs when booting.
7971 @end defvr
7972
7973 @defvr {Scheme Variable} etc-service-type
7974 The type of the @file{/etc} service. This service can be extended by
7975 passing it name/file tuples such as:
7976
7977 @example
7978 (list `("issue" ,(plain-file "issue" "Welcome!\n")))
7979 @end example
7980
7981 In this example, the effect would be to add an @file{/etc/issue} file
7982 pointing to the given file.
7983 @end defvr
7984
7985 @defvr {Scheme Variable} setuid-program-service-type
7986 Type for the ``setuid-program service''. This service collects lists of
7987 executable file names, passed as gexps, and adds them to the set of
7988 setuid-root programs on the system (@pxref{Setuid Programs}).
7989 @end defvr
7990
7991 @defvr {Scheme Variable} profile-service-type
7992 Type of the service that populates the @dfn{system profile}---i.e., the
7993 programs under @file{/run/current-system/profile}. Other services can
7994 extend it by passing it lists of packages to add to the system profile.
7995 @end defvr
7996
7997
7998 @node dmd Services
7999 @subsubsection dmd Services
8000
8001 @cindex PID 1
8002 @cindex init system
8003 The @code{(gnu services dmd)} provides a way to define services managed
8004 by GNU@tie{}dmd, which is GuixSD initialization system---the first
8005 process that is started when the system boots, aka. PID@tie{}1
8006 (@pxref{Introduction,,, dmd, GNU dmd Manual}).
8007
8008 Services in dmd can depend on each other. For instance, the SSH daemon
8009 may need to be started after the syslog daemon has been started, which
8010 in turn can only happen once all the file systems have been mounted.
8011 The simple operating system defined earlier (@pxref{Using the
8012 Configuration System}) results in a service graph like this:
8013
8014 @image{images/dmd-graph,,5in,Typical dmd service graph.}
8015
8016 You can actually generate such a graph for any operating system
8017 definition using the @command{guix system dmd-graph} command
8018 (@pxref{system-dmd-graph, @command{guix system dmd-graph}}).
8019
8020 The @var{%dmd-root-service} is a service object representing PID@tie{}1,
8021 of type @var{dmd-root-service-type}; it can be extended by passing it
8022 lists of @code{<dmd-service>} objects.
8023
8024 @deftp {Data Type} dmd-service
8025 The data type representing a service managed by dmd.
8026
8027 @table @asis
8028 @item @code{provision}
8029 This is a list of symbols denoting what the service provides.
8030
8031 These are the names that may be passed to @command{deco start},
8032 @command{deco status}, and similar commands (@pxref{Invoking deco,,,
8033 dmd, GNU dmd Manual}). @xref{Slots of services, the @code{provides}
8034 slot,, dmd, GNU dmd Manual}, for details.
8035
8036 @item @code{requirements} (default: @code{'()})
8037 List of symbols denoting the dmd services this one depends on.
8038
8039 @item @code{respawn?} (default: @code{#t})
8040 Whether to restart the service when it stops, for instance when the
8041 underlying process dies.
8042
8043 @item @code{start}
8044 @itemx @code{stop} (default: @code{#~(const #f)})
8045 The @code{start} and @code{stop} fields refer to dmd's facilities to
8046 start and stop processes (@pxref{Service De- and Constructors,,, dmd,
8047 GNU dmd Manual}). They are given as G-expressions that get expanded in
8048 the dmd configuration file (@pxref{G-Expressions}).
8049
8050 @item @code{documentation}
8051 A documentation string, as shown when running:
8052
8053 @example
8054 deco doc @var{service-name}
8055 @end example
8056
8057 where @var{service-name} is one of the symbols in @var{provision}
8058 (@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
8059 @end table
8060 @end deftp
8061
8062 @defvr {Scheme Variable} dmd-root-service-type
8063 The service type for the dmd ``root service''---i.e., PID@tie{}1.
8064
8065 This is the service type that extensions target when they want to create
8066 dmd services (@pxref{Service Types and Services}, for an example). Each
8067 extension must pass a list of @code{<dmd-service>}.
8068 @end defvr
8069
8070 @defvr {Scheme Variable} %dmd-root-service
8071 This service represents PID@tie{}1.
8072 @end defvr
8073
8074
8075 @node Installing Debugging Files
8076 @section Installing Debugging Files
8077
8078 @cindex debugging files
8079 Program binaries, as produced by the GCC compilers for instance, are
8080 typically written in the ELF format, with a section containing
8081 @dfn{debugging information}. Debugging information is what allows the
8082 debugger, GDB, to map binary code to source code; it is required to
8083 debug a compiled program in good conditions.
8084
8085 The problem with debugging information is that is takes up a fair amount
8086 of disk space. For example, debugging information for the GNU C Library
8087 weighs in at more than 60 MiB. Thus, as a user, keeping all the
8088 debugging info of all the installed programs is usually not an option.
8089 Yet, space savings should not come at the cost of an impediment to
8090 debugging---especially in the GNU system, which should make it easier
8091 for users to exert their computing freedom (@pxref{GNU Distribution}).
8092
8093 Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
8094 mechanism that allows users to get the best of both worlds: debugging
8095 information can be stripped from the binaries and stored in separate
8096 files. GDB is then able to load debugging information from those files,
8097 when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
8098 with GDB}).
8099
8100 The GNU distribution takes advantage of this by storing debugging
8101 information in the @code{lib/debug} sub-directory of a separate package
8102 output unimaginatively called @code{debug} (@pxref{Packages with
8103 Multiple Outputs}). Users can choose to install the @code{debug} output
8104 of a package when they need it. For instance, the following command
8105 installs the debugging information for the GNU C Library and for GNU
8106 Guile:
8107
8108 @example
8109 guix package -i glibc:debug guile:debug
8110 @end example
8111
8112 GDB must then be told to look for debug files in the user's profile, by
8113 setting the @code{debug-file-directory} variable (consider setting it
8114 from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
8115 GDB}):
8116
8117 @example
8118 (gdb) set debug-file-directory ~/.guix-profile/lib/debug
8119 @end example
8120
8121 From there on, GDB will pick up debugging information from the
8122 @code{.debug} files under @file{~/.guix-profile/lib/debug}.
8123
8124 In addition, you will most likely want GDB to be able to show the source
8125 code being debugged. To do that, you will have to unpack the source
8126 code of the package of interest (obtained with @code{guix build
8127 --source}, @pxref{Invoking guix build}), and to point GDB to that source
8128 directory using the @code{directory} command (@pxref{Source Path,
8129 @code{directory},, gdb, Debugging with GDB}).
8130
8131 @c XXX: keep me up-to-date
8132 The @code{debug} output mechanism in Guix is implemented by the
8133 @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
8134 opt-in---debugging information is available only for those packages
8135 whose definition explicitly declares a @code{debug} output. This may be
8136 changed to opt-out in the future, if our build farm servers can handle
8137 the load. To check whether a package has a @code{debug} output, use
8138 @command{guix package --list-available} (@pxref{Invoking guix package}).
8139
8140
8141 @node Security Updates
8142 @section Security Updates
8143
8144 @quotation Note
8145 As of version @value{VERSION}, the feature described in this section is
8146 experimental.
8147 @end quotation
8148
8149 @cindex security updates
8150 Occasionally, important security vulnerabilities are discovered in core
8151 software packages and must be patched. Guix follows a functional
8152 package management discipline (@pxref{Introduction}), which implies
8153 that, when a package is changed, @emph{every package that depends on it}
8154 must be rebuilt. This can significantly slow down the deployment of
8155 fixes in core packages such as libc or Bash, since basically the whole
8156 distribution would need to be rebuilt. Using pre-built binaries helps
8157 (@pxref{Substitutes}), but deployment may still take more time than
8158 desired.
8159
8160 @cindex grafts
8161 To address that, Guix implements @dfn{grafts}, a mechanism that allows
8162 for fast deployment of critical updates without the costs associated
8163 with a whole-distribution rebuild. The idea is to rebuild only the
8164 package that needs to be patched, and then to ``graft'' it onto packages
8165 explicitly installed by the user and that were previously referring to
8166 the original package. The cost of grafting is typically very low, and
8167 order of magnitudes lower than a full rebuild of the dependency chain.
8168
8169 @cindex replacements of packages, for grafts
8170 For instance, suppose a security update needs to be applied to Bash.
8171 Guix developers will provide a package definition for the ``fixed''
8172 Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
8173 Packages}). Then, the original package definition is augmented with a
8174 @code{replacement} field pointing to the package containing the bug fix:
8175
8176 @example
8177 (define bash
8178 (package
8179 (name "bash")
8180 ;; @dots{}
8181 (replacement bash-fixed)))
8182 @end example
8183
8184 From there on, any package depending directly or indirectly on Bash that
8185 is installed will automatically be ``rewritten'' to refer to
8186 @var{bash-fixed} instead of @var{bash}. This grafting process takes
8187 time proportional to the size of the package, but expect less than a
8188 minute for an ``average'' package on a recent machine.
8189
8190 Currently, the graft and the package it replaces (@var{bash-fixed} and
8191 @var{bash} in the example above) must have the exact same @code{name}
8192 and @code{version} fields. This restriction mostly comes from the fact
8193 that grafting works by patching files, including binary files, directly.
8194 Other restrictions may apply: for instance, when adding a graft to a
8195 package providing a shared library, the original shared library and its
8196 replacement must have the same @code{SONAME} and be binary-compatible.
8197
8198
8199 @node Package Modules
8200 @section Package Modules
8201
8202 From a programming viewpoint, the package definitions of the
8203 GNU distribution are provided by Guile modules in the @code{(gnu packages
8204 @dots{})} name space@footnote{Note that packages under the @code{(gnu
8205 packages @dots{})} module name space are not necessarily ``GNU
8206 packages''. This module naming scheme follows the usual Guile module
8207 naming convention: @code{gnu} means that these modules are distributed
8208 as part of the GNU system, and @code{packages} identifies modules that
8209 define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
8210 Reference Manual}). For instance, the @code{(gnu packages emacs)}
8211 module exports a variable named @code{emacs}, which is bound to a
8212 @code{<package>} object (@pxref{Defining Packages}).
8213
8214 The @code{(gnu packages @dots{})} module name space is
8215 automatically scanned for packages by the command-line tools. For
8216 instance, when running @code{guix package -i emacs}, all the @code{(gnu
8217 packages @dots{})} modules are scanned until one that exports a package
8218 object whose name is @code{emacs} is found. This package search
8219 facility is implemented in the @code{(gnu packages)} module.
8220
8221 @cindex customization, of packages
8222 @cindex package module search path
8223 Users can store package definitions in modules with different
8224 names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
8225 name and module name must match. For instance, the @code{(my-packages
8226 emacs)} module must be stored in a @file{my-packages/emacs.scm} file
8227 relative to the load path specified with @option{--load-path} or
8228 @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
8229 guile, GNU Guile Reference Manual}, for details.}. These package definitions
8230 will not be visible by default. Thus, users can invoke commands such as
8231 @command{guix package} and @command{guix build} have to be used with the
8232 @code{-e} option so that they know where to find the package. Better
8233 yet, they can use the
8234 @code{-L} option of these commands to make those modules visible
8235 (@pxref{Invoking guix build, @code{--load-path}}), or define the
8236 @code{GUIX_PACKAGE_PATH} environment variable. This environment
8237 variable makes it easy to extend or customize the distribution and is
8238 honored by all the user interfaces.
8239
8240 @defvr {Environment Variable} GUIX_PACKAGE_PATH
8241 This is a colon-separated list of directories to search for package
8242 modules. Directories listed in this variable take precedence over the
8243 distribution's own modules.
8244 @end defvr
8245
8246 The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
8247 each package is built based solely on other packages in the
8248 distribution. The root of this dependency graph is a small set of
8249 @dfn{bootstrap binaries}, provided by the @code{(gnu packages
8250 bootstrap)} module. For more information on bootstrapping,
8251 @pxref{Bootstrapping}.
8252
8253 @node Packaging Guidelines
8254 @section Packaging Guidelines
8255
8256 The GNU distribution is nascent and may well lack some of your favorite
8257 packages. This section describes how you can help make the distribution
8258 grow. @xref{Contributing}, for additional information on how you can
8259 help.
8260
8261 Free software packages are usually distributed in the form of
8262 @dfn{source code tarballs}---typically @file{tar.gz} files that contain
8263 all the source files. Adding a package to the distribution means
8264 essentially two things: adding a @dfn{recipe} that describes how to
8265 build the package, including a list of other packages required to build
8266 it, and adding @dfn{package meta-data} along with that recipe, such as a
8267 description and licensing information.
8268
8269 In Guix all this information is embodied in @dfn{package definitions}.
8270 Package definitions provide a high-level view of the package. They are
8271 written using the syntax of the Scheme programming language; in fact,
8272 for each package we define a variable bound to the package definition,
8273 and export that variable from a module (@pxref{Package Modules}).
8274 However, in-depth Scheme knowledge is @emph{not} a prerequisite for
8275 creating packages. For more information on package definitions,
8276 @pxref{Defining Packages}.
8277
8278 Once a package definition is in place, stored in a file in the Guix
8279 source tree, it can be tested using the @command{guix build} command
8280 (@pxref{Invoking guix build}). For example, assuming the new package is
8281 called @code{gnew}, you may run this command from the Guix build tree
8282 (@pxref{Running Guix Before It Is Installed}):
8283
8284 @example
8285 ./pre-inst-env guix build gnew --keep-failed
8286 @end example
8287
8288 Using @code{--keep-failed} makes it easier to debug build failures since
8289 it provides access to the failed build tree. Another useful
8290 command-line option when debugging is @code{--log-file}, to access the
8291 build log.
8292
8293 If the package is unknown to the @command{guix} command, it may be that
8294 the source file contains a syntax error, or lacks a @code{define-public}
8295 clause to export the package variable. To figure it out, you may load
8296 the module from Guile to get more information about the actual error:
8297
8298 @example
8299 ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
8300 @end example
8301
8302 Once your package builds correctly, please send us a patch
8303 (@pxref{Contributing}). Well, if you need help, we will be happy to
8304 help you too. Once the patch is committed in the Guix repository, the
8305 new package automatically gets built on the supported platforms by
8306 @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
8307 system}.
8308
8309 @cindex substituter
8310 Users can obtain the new package definition simply by running
8311 @command{guix pull} (@pxref{Invoking guix pull}). When
8312 @code{hydra.gnu.org} is done building the package, installing the
8313 package automatically downloads binaries from there
8314 (@pxref{Substitutes}). The only place where human intervention is
8315 needed is to review and apply the patch.
8316
8317
8318 @menu
8319 * Software Freedom:: What may go into the distribution.
8320 * Package Naming:: What's in a name?
8321 * Version Numbers:: When the name is not enough.
8322 * Synopses and Descriptions:: Helping users find the right package.
8323 * Python Modules:: Taming the snake.
8324 * Perl Modules:: Little pearls.
8325 * Fonts:: Fond of fonts.
8326 @end menu
8327
8328 @node Software Freedom
8329 @subsection Software Freedom
8330
8331 @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
8332
8333 The GNU operating system has been developed so that users can have
8334 freedom in their computing. GNU is @dfn{free software}, meaning that
8335 users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
8336 essential freedoms}: to run the program, to study and change the program
8337 in source code form, to redistribute exact copies, and to distribute
8338 modified versions. Packages found in the GNU distribution provide only
8339 software that conveys these four freedoms.
8340
8341 In addition, the GNU distribution follow the
8342 @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
8343 software distribution guidelines}. Among other things, these guidelines
8344 reject non-free firmware, recommendations of non-free software, and
8345 discuss ways to deal with trademarks and patents.
8346
8347 Some packages contain a small and optional subset that violates the
8348 above guidelines, for instance because this subset is itself non-free
8349 code. When that happens, the offending items are removed with
8350 appropriate patches or code snippets in the package definition's
8351 @code{origin} form (@pxref{Defining Packages}). That way, @code{guix
8352 build --source} returns the ``freed'' source rather than the unmodified
8353 upstream source.
8354
8355
8356 @node Package Naming
8357 @subsection Package Naming
8358
8359 A package has actually two names associated with it:
8360 First, there is the name of the @emph{Scheme variable}, the one following
8361 @code{define-public}. By this name, the package can be made known in the
8362 Scheme code, for instance as input to another package. Second, there is
8363 the string in the @code{name} field of a package definition. This name
8364 is used by package management commands such as
8365 @command{guix package} and @command{guix build}.
8366
8367 Both are usually the same and correspond to the lowercase conversion of
8368 the project name chosen upstream, with underscores replaced with
8369 hyphens. For instance, GNUnet is available as @code{gnunet}, and
8370 SDL_net as @code{sdl-net}.
8371
8372 We do not add @code{lib} prefixes for library packages, unless these are
8373 already part of the official project name. But @pxref{Python
8374 Modules} and @ref{Perl Modules} for special rules concerning modules for
8375 the Python and Perl languages.
8376
8377 Font package names are handled differently, @pxref{Fonts}.
8378
8379
8380 @node Version Numbers
8381 @subsection Version Numbers
8382
8383 We usually package only the latest version of a given free software
8384 project. But sometimes, for instance for incompatible library versions,
8385 two (or more) versions of the same package are needed. These require
8386 different Scheme variable names. We use the name as defined
8387 in @ref{Package Naming}
8388 for the most recent version; previous versions use the same name, suffixed
8389 by @code{-} and the smallest prefix of the version number that may
8390 distinguish the two versions.
8391
8392 The name inside the package definition is the same for all versions of a
8393 package and does not contain any version number.
8394
8395 For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
8396
8397 @example
8398 (define-public gtk+
8399 (package
8400 (name "gtk+")
8401 (version "3.9.12")
8402 ...))
8403 (define-public gtk+-2
8404 (package
8405 (name "gtk+")
8406 (version "2.24.20")
8407 ...))
8408 @end example
8409 If we also wanted GTK+ 3.8.2, this would be packaged as
8410 @example
8411 (define-public gtk+-3.8
8412 (package
8413 (name "gtk+")
8414 (version "3.8.2")
8415 ...))
8416 @end example
8417
8418 @node Synopses and Descriptions
8419 @subsection Synopses and Descriptions
8420
8421 As we have seen before, each package in GNU@tie{}Guix includes a
8422 synopsis and a description (@pxref{Defining Packages}). Synopses and
8423 descriptions are important: They are what @command{guix package
8424 --search} searches, and a crucial piece of information to help users
8425 determine whether a given package suits their needs. Consequently,
8426 packagers should pay attention to what goes into them.
8427
8428 Synopses must start with a capital letter and must not end with a
8429 period. They must not start with ``a'' or ``the'', which usually does
8430 not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
8431 tool that frobs files''. The synopsis should say what the package
8432 is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
8433 used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
8434 matching a pattern''.
8435
8436 Keep in mind that the synopsis must be meaningful for a very wide
8437 audience. For example, ``Manipulate alignments in the SAM format''
8438 might make sense for a seasoned bioinformatics researcher, but might be
8439 fairly unhelpful or even misleading to a non-specialized audience. It
8440 is a good idea to come up with a synopsis that gives an idea of the
8441 application domain of the package. In this example, this might give
8442 something like ``Manipulate nucleotide sequence alignments'', which
8443 hopefully gives the user a better idea of whether this is what they are
8444 looking for.
8445
8446 @cindex Texinfo markup, in package descriptions
8447 Descriptions should take between five and ten lines. Use full
8448 sentences, and avoid using acronyms without first introducing them.
8449 Descriptions can include Texinfo markup, which is useful to introduce
8450 ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
8451 hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
8452 should be careful when using some characters for example @samp{@@} and
8453 curly braces which are the basic special characters in Texinfo
8454 (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
8455 such as @command{guix package --show} take care of rendering it
8456 appropriately.
8457
8458 Synopses and descriptions are translated by volunteers
8459 @uref{http://translationproject.org/domain/guix-packages.html, at the
8460 Translation Project} so that as many users as possible can read them in
8461 their native language. User interfaces search them and display them in
8462 the language specified by the current locale.
8463
8464 Translation is a lot of work so, as a packager, please pay even more
8465 attention to your synopses and descriptions as every change may entail
8466 additional work for translators. In order to help them, it is possible
8467 to make recommendations or instructions visible to them by inserting
8468 special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
8469 Gettext}):
8470
8471 @example
8472 ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
8473 (description "ARandR is designed to provide a simple visual front end
8474 for the X11 resize-and-rotate (RandR) extension. @dots{}")
8475 @end example
8476
8477
8478 @node Python Modules
8479 @subsection Python Modules
8480
8481 We currently package Python 2 and Python 3, under the Scheme variable names
8482 @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
8483 To avoid confusion and naming clashes with other programming languages, it
8484 seems desirable that the name of a package for a Python module contains
8485 the word @code{python}.
8486
8487 Some modules are compatible with only one version of Python, others with both.
8488 If the package Foo compiles only with Python 3, we name it
8489 @code{python-foo}; if it compiles only with Python 2, we name it
8490 @code{python2-foo}. If it is compatible with both versions, we create two
8491 packages with the corresponding names.
8492
8493 If a project already contains the word @code{python}, we drop this;
8494 for instance, the module python-dateutil is packaged under the names
8495 @code{python-dateutil} and @code{python2-dateutil}.
8496
8497
8498 @node Perl Modules
8499 @subsection Perl Modules
8500
8501 Perl programs standing for themselves are named as any other package,
8502 using the lowercase upstream name.
8503 For Perl packages containing a single class, we use the lowercase class name,
8504 replace all occurrences of @code{::} by dashes and prepend the prefix
8505 @code{perl-}.
8506 So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
8507 Modules containing several classes keep their lowercase upstream name and
8508 are also prepended by @code{perl-}. Such modules tend to have the word
8509 @code{perl} somewhere in their name, which gets dropped in favor of the
8510 prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
8511
8512
8513 @node Fonts
8514 @subsection Fonts
8515
8516 For fonts that are in general not installed by a user for typesetting
8517 purposes, or that are distributed as part of a larger software package,
8518 we rely on the general packaging rules for software; for instance, this
8519 applies to the fonts delivered as part of the X.Org system or fonts that
8520 are part of TeX Live.
8521
8522 To make it easier for a user to search for fonts, names for other packages
8523 containing only fonts are constructed as follows, independently of the
8524 upstream package name.
8525
8526 The name of a package containing only one font family starts with
8527 @code{font-}; it is followed by the foundry name and a dash @code{-}
8528 if the foundry is known, and the font family name, in which spaces are
8529 replaced by dashes (and as usual, all upper case letters are transformed
8530 to lower case).
8531 For example, the Gentium font family by SIL is packaged under the name
8532 @code{font-sil-gentium}.
8533
8534 For a package containing several font families, the name of the collection
8535 is used in the place of the font family name.
8536 For instance, the Liberation fonts consist of three families,
8537 Liberation Sans, Liberation Serif and Liberation Mono.
8538 These could be packaged separately under the names
8539 @code{font-liberation-sans} and so on; but as they are distributed together
8540 under a common name, we prefer to package them together as
8541 @code{font-liberation}.
8542
8543 In the case where several formats of the same font family or font collection
8544 are packaged separately, a short form of the format, prepended by a dash,
8545 is added to the package name. We use @code{-ttf} for TrueType fonts,
8546 @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
8547 fonts.
8548
8549
8550
8551 @node Bootstrapping
8552 @section Bootstrapping
8553
8554 @c Adapted from the ELS 2013 paper.
8555
8556 @cindex bootstrapping
8557
8558 Bootstrapping in our context refers to how the distribution gets built
8559 ``from nothing''. Remember that the build environment of a derivation
8560 contains nothing but its declared inputs (@pxref{Introduction}). So
8561 there's an obvious chicken-and-egg problem: how does the first package
8562 get built? How does the first compiler get compiled? Note that this is
8563 a question of interest only to the curious hacker, not to the regular
8564 user, so you can shamelessly skip this section if you consider yourself
8565 a ``regular user''.
8566
8567 @cindex bootstrap binaries
8568 The GNU system is primarily made of C code, with libc at its core. The
8569 GNU build system itself assumes the availability of a Bourne shell and
8570 command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
8571 `grep'. Furthermore, build programs---programs that run
8572 @code{./configure}, @code{make}, etc.---are written in Guile Scheme
8573 (@pxref{Derivations}). Consequently, to be able to build anything at
8574 all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
8575 Binutils, libc, and the other packages mentioned above---the
8576 @dfn{bootstrap binaries}.
8577
8578 These bootstrap binaries are ``taken for granted'', though we can also
8579 re-create them if needed (more on that later).
8580
8581 @unnumberedsubsec Preparing to Use the Bootstrap Binaries
8582
8583 @c As of Emacs 24.3, Info-mode displays the image, but since it's a
8584 @c large image, it's hard to scroll. Oh well.
8585 @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
8586
8587 The figure above shows the very beginning of the dependency graph of the
8588 distribution, corresponding to the package definitions of the @code{(gnu
8589 packages bootstrap)} module. At this level of detail, things are
8590 slightly complex. First, Guile itself consists of an ELF executable,
8591 along with many source and compiled Scheme files that are dynamically
8592 loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
8593 tarball shown in this graph. This tarball is part of Guix's ``source''
8594 distribution, and gets inserted into the store with @code{add-to-store}
8595 (@pxref{The Store}).
8596
8597 But how do we write a derivation that unpacks this tarball and adds it
8598 to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
8599 derivation---the first one that gets built---uses @code{bash} as its
8600 builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
8601 @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
8602 @file{xz}, and @file{mkdir} are statically-linked binaries, also part of
8603 the Guix source distribution, whose sole purpose is to allow the Guile
8604 tarball to be unpacked.
8605
8606 Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
8607 Guile that can be used to run subsequent build programs. Its first task
8608 is to download tarballs containing the other pre-built binaries---this
8609 is what the @code{.tar.xz.drv} derivations do. Guix modules such as
8610 @code{ftp-client.scm} are used for this purpose. The
8611 @code{module-import.drv} derivations import those modules in a directory
8612 in the store, using the original layout. The
8613 @code{module-import-compiled.drv} derivations compile those modules, and
8614 write them in an output directory with the right layout. This
8615 corresponds to the @code{#:modules} argument of
8616 @code{build-expression->derivation} (@pxref{Derivations}).
8617
8618 Finally, the various tarballs are unpacked by the
8619 derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
8620 etc., at which point we have a working C tool chain.
8621
8622
8623 @unnumberedsubsec Building the Build Tools
8624
8625 @c TODO: Add a package-level dependency graph generated from (gnu
8626 @c packages base).
8627
8628 Bootstrapping is complete when we have a full tool chain that does not
8629 depend on the pre-built bootstrap tools discussed above. This
8630 no-dependency requirement is verified by checking whether the files of
8631 the final tool chain contain references to the @file{/gnu/store}
8632 directories of the bootstrap inputs. The process that leads to this
8633 ``final'' tool chain is described by the package definitions found in
8634 the @code{(gnu packages commencement)} module.
8635
8636 @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
8637 The first tool that gets built with the bootstrap binaries is
8638 GNU Make, which is a prerequisite for all the following packages.
8639 From there Findutils and Diffutils get built.
8640
8641 Then come the first-stage Binutils and GCC, built as pseudo cross
8642 tools---i.e., with @code{--target} equal to @code{--host}. They are
8643 used to build libc. Thanks to this cross-build trick, this libc is
8644 guaranteed not to hold any reference to the initial tool chain.
8645
8646 From there the final Binutils and GCC are built. GCC uses @code{ld}
8647 from the final Binutils, and links programs against the just-built libc.
8648 This tool chain is used to build the other packages used by Guix and by
8649 the GNU Build System: Guile, Bash, Coreutils, etc.
8650
8651 And voilà! At this point we have the complete set of build tools that
8652 the GNU Build System expects. These are in the @code{%final-inputs}
8653 variable of the @code{(gnu packages commencement)} module, and are
8654 implicitly used by any package that uses @code{gnu-build-system}
8655 (@pxref{Build Systems, @code{gnu-build-system}}).
8656
8657
8658 @unnumberedsubsec Building the Bootstrap Binaries
8659
8660 Because the final tool chain does not depend on the bootstrap binaries,
8661 those rarely need to be updated. Nevertheless, it is useful to have an
8662 automated way to produce them, should an update occur, and this is what
8663 the @code{(gnu packages make-bootstrap)} module provides.
8664
8665 The following command builds the tarballs containing the bootstrap
8666 binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
8667 of Coreutils and other basic command-line tools):
8668
8669 @example
8670 guix build bootstrap-tarballs
8671 @end example
8672
8673 The generated tarballs are those that should be referred to in the
8674 @code{(gnu packages bootstrap)} module mentioned at the beginning of
8675 this section.
8676
8677 Still here? Then perhaps by now you've started to wonder: when do we
8678 reach a fixed point? That is an interesting question! The answer is
8679 unknown, but if you would like to investigate further (and have
8680 significant computational and storage resources to do so), then let us
8681 know.
8682
8683 @node Porting
8684 @section Porting to a New Platform
8685
8686 As discussed above, the GNU distribution is self-contained, and
8687 self-containment is achieved by relying on pre-built ``bootstrap
8688 binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
8689 operating system kernel, CPU architecture, and application binary
8690 interface (ABI). Thus, to port the distribution to a platform that is
8691 not yet supported, one must build those bootstrap binaries, and update
8692 the @code{(gnu packages bootstrap)} module to use them on that platform.
8693
8694 Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
8695 When everything goes well, and assuming the GNU tool chain supports the
8696 target platform, this can be as simple as running a command like this
8697 one:
8698
8699 @example
8700 guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
8701 @end example
8702
8703 For this to work, the @code{glibc-dynamic-linker} procedure in
8704 @code{(gnu packages bootstrap)} must be augmented to return the right
8705 file name for libc's dynamic linker on that platform; likewise,
8706 @code{system->linux-architecture} in @code{(gnu packages linux)} must be
8707 taught about the new platform.
8708
8709 Once these are built, the @code{(gnu packages bootstrap)} module needs
8710 to be updated to refer to these binaries on the target platform. That
8711 is, the hashes and URLs of the bootstrap tarballs for the new platform
8712 must be added alongside those of the currently supported platforms. The
8713 bootstrap Guile tarball is treated specially: it is expected to be
8714 available locally, and @file{gnu-system.am} has rules do download it for
8715 the supported architectures; a rule for the new platform must be added
8716 as well.
8717
8718 In practice, there may be some complications. First, it may be that the
8719 extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
8720 above) is not recognized by all the GNU tools. Typically, glibc
8721 recognizes some of these, whereas GCC uses an extra @code{--with-abi}
8722 configure flag (see @code{gcc.scm} for examples of how to handle this).
8723 Second, some of the required packages could fail to build for that
8724 platform. Lastly, the generated binaries could be broken for some
8725 reason.
8726
8727 @c *********************************************************************
8728 @include contributing.texi
8729
8730 @c *********************************************************************
8731 @node Acknowledgments
8732 @chapter Acknowledgments
8733
8734 Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
8735 which was designed and
8736 implemented by Eelco Dolstra, with contributions from other people (see
8737 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
8738 management, and promoted unprecedented features, such as transactional
8739 package upgrades and rollbacks, per-user profiles, and referentially
8740 transparent build processes. Without this work, Guix would not exist.
8741
8742 The Nix-based software distributions, Nixpkgs and NixOS, have also been
8743 an inspiration for Guix.
8744
8745 GNU@tie{}Guix itself is a collective work with contributions from a
8746 number of people. See the @file{AUTHORS} file in Guix for more
8747 information on these fine people. The @file{THANKS} file lists people
8748 who have helped by reporting bugs, taking care of the infrastructure,
8749 providing artwork and themes, making suggestions, and more---thank you!
8750
8751
8752 @c *********************************************************************
8753 @node GNU Free Documentation License
8754 @appendix GNU Free Documentation License
8755
8756 @include fdl-1.3.texi
8757
8758 @c *********************************************************************
8759 @node Concept Index
8760 @unnumbered Concept Index
8761 @printindex cp
8762
8763 @node Programming Index
8764 @unnumbered Programming Index
8765 @syncodeindex tp fn
8766 @syncodeindex vr fn
8767 @printindex fn
8768
8769 @bye
8770
8771 @c Local Variables:
8772 @c ispell-local-dictionary: "american";
8773 @c End: