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