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