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