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