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