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