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