guix system: Factorize boot parameter parsing.
[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
3618@item --expression=@var{expr}
3619@itemx -e @var{expr}
ac5de156 3620Build the package or derivation @var{expr} evaluates to.
c78bd12b 3621
5401dd75 3622For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
3623guile-1.8)}, which unambiguously designates this specific variant of
3624version 1.8 of Guile.
3625
56b82106
LC
3626Alternately, @var{expr} may be a G-expression, in which case it is used
3627as a build program passed to @code{gexp->derivation}
3628(@pxref{G-Expressions}).
3629
3630Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
3631(@pxref{The Store Monad}). The procedure must return a derivation as a
3632monadic value, which is then passed through @code{run-with-store}.
3633
c78bd12b
LC
3634@item --source
3635@itemx -S
3636Build the packages' source derivations, rather than the packages
3637themselves.
3638
e49951eb 3639For instance, @code{guix build -S gcc} returns something like
834129e0 3640@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 3641
f9cc8971
LC
3642The returned source tarball is the result of applying any patches and
3643code snippets specified in the package's @code{origin} (@pxref{Defining
3644Packages}).
3645
2cdfe13d
EB
3646@item --sources
3647Fetch and return the source of @var{package-or-derivation} and all their
3648dependencies, recursively. This is a handy way to obtain a local copy
3649of all the source code needed to build @var{packages}, allowing you to
3650eventually build them even without network access. It is an extension
3651of the @code{--source} option and can accept one of the following
3652optional argument values:
3653
3654@table @code
3655@item package
3656This value causes the @code{--sources} option to behave in the same way
3657as the @code{--source} option.
3658
3659@item all
3660Build all packages' source derivations, including any source that might
3661be listed as @code{inputs}. This is the default value.
3662
3663@example
3664$ guix build --sources tzdata
3665The following derivations will be built:
3666 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
3667 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3668@end example
3669
3670@item transitive
3671Build all packages' source derivations, as well as all source
3672derivations for packages' transitive inputs. This can be used e.g. to
3673prefetch package source for later offline building.
3674
3675@example
3676$ guix build --sources=transitive tzdata
3677The following derivations will be built:
3678 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
3679 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
3680 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
3681 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
3682 /gnu/store/@dots{}-make-4.1.tar.xz.drv
3683 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
3684@dots{}
3685@end example
3686
3687@end table
3688
c78bd12b
LC
3689@item --system=@var{system}
3690@itemx -s @var{system}
3691Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
3692the host's system type.
3693
3694An example use of this is on Linux-based systems, which can emulate
3695different personalities. For instance, passing
3696@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
3697to build packages in a complete 32-bit environment.
3698
e55ec43d
LC
3699@item --target=@var{triplet}
3700@cindex cross-compilation
3701Cross-build for @var{triplet}, which must be a valid GNU triplet, such
3702as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
3703configuration triplets,, configure, GNU Configure and Build System}).
3704
7f3673f2
LC
3705@item --with-source=@var{source}
3706Use @var{source} as the source of the corresponding package.
3707@var{source} must be a file name or a URL, as for @command{guix
3708download} (@pxref{Invoking guix download}).
3709
3710The ``corresponding package'' is taken to be one specified on the
3711command line whose name matches the base of @var{source}---e.g., if
3712@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
3713package is @code{guile}. Likewise, the version string is inferred from
3714@var{source}; in the previous example, it's @code{2.0.10}.
3715
3716This option allows users to try out versions of packages other than the
3717one provided by the distribution. The example below downloads
3718@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
3719the @code{ed} package:
3720
3721@example
3722guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
3723@end example
3724
3725As a developer, @code{--with-source} makes it easy to test release
3726candidates:
3727
3728@example
3729guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
3730@end example
3731
a43b55f1
LC
3732@dots{} or to build from a checkout in a pristine environment:
3733
3734@example
3735$ git clone git://git.sv.gnu.org/guix.git
3736$ guix build guix --with-source=./guix
3737@end example
3738
05962f29
LC
3739@item --no-grafts
3740Do not ``graft'' packages. In practice, this means that package updates
3741available as grafts are not applied. @xref{Security Updates}, for more
3742information on grafts.
7f3673f2 3743
c78bd12b
LC
3744@item --derivations
3745@itemx -d
3746Return the derivation paths, not the output paths, of the given
3747packages.
3748
70ee5642
LC
3749@item --root=@var{file}
3750@itemx -r @var{file}
3751Make @var{file} a symlink to the result, and register it as a garbage
3752collector root.
3753
3754@item --log-file
3f208ad7 3755Return the build log file names or URLs for the given
70ee5642
LC
3756@var{package-or-derivation}s, or raise an error if build logs are
3757missing.
3758
3759This works regardless of how packages or derivations are specified. For
3760instance, the following invocations are equivalent:
3761
3762@example
3763guix build --log-file `guix build -d guile`
3764guix build --log-file `guix build guile`
3765guix build --log-file guile
3766guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
3767@end example
3768
3f208ad7
LC
3769If a log is unavailable locally, and unless @code{--no-substitutes} is
3770passed, the command looks for a corresponding log on one of the
3771substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 3772
3f208ad7
LC
3773So for instance, let's say you want to see the build log of GDB on MIPS
3774but you're actually on an @code{x86_64} machine:
3775
3776@example
3777$ guix build --log-file gdb -s mips64el-linux
3778http://hydra.gnu.org/log/@dots{}-gdb-7.10
3779@end example
3780
3781You can freely access a huge library of build logs!
70ee5642
LC
3782@end table
3783
3784@cindex common build options
3785In addition, a number of options that control the build process are
3786common to @command{guix build} and other commands that can spawn builds,
3787such as @command{guix package} or @command{guix archive}. These are the
3788following:
3789
3790@table @code
3791
300868ba
LC
3792@item --load-path=@var{directory}
3793@itemx -L @var{directory}
3794Add @var{directory} to the front of the package module search path
3795(@pxref{Package Modules}).
3796
3797This allows users to define their own packages and make them visible to
3798the command-line tools.
3799
c78bd12b
LC
3800@item --keep-failed
3801@itemx -K
3802Keep the build tree of failed builds. Thus, if a build fail, its build
3803tree is kept under @file{/tmp}, in a directory whose name is shown at
3804the end of the build log. This is useful when debugging build issues.
3805
3806@item --dry-run
3807@itemx -n
3808Do not build the derivations.
3809
56b1f4b7
LC
3810@item --fallback
3811When substituting a pre-built binary fails, fall back to building
3812packages locally.
3813
f8a8e0fe
LC
3814@item --substitute-urls=@var{urls}
3815@anchor{client-substitute-urls}
3816Consider @var{urls} the whitespace-separated list of substitute source
3817URLs, overriding the default list of URLs of @command{guix-daemon}
3818(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3819
3820This means that substitutes may be downloaded from @var{urls}, provided
3821they are signed by a key authorized by the system administrator
3822(@pxref{Substitutes}).
3823
c78bd12b 3824@item --no-substitutes
b5385b52 3825Do not use substitutes for build products. That is, always build things
c4202d60
LC
3826locally instead of allowing downloads of pre-built binaries
3827(@pxref{Substitutes}).
c78bd12b 3828
425b0bfc 3829@item --no-build-hook
4ec2e92d
LC
3830Do not attempt to offload builds @i{via} the daemon's ``build hook''
3831(@pxref{Daemon Offload Setup}). That is, always build things locally
3832instead of offloading builds to remote machines.
425b0bfc 3833
969e678e
LC
3834@item --max-silent-time=@var{seconds}
3835When the build or substitution process remains silent for more than
3836@var{seconds}, terminate it and report a build failure.
3837
002622b6
LC
3838@item --timeout=@var{seconds}
3839Likewise, when the build or substitution process lasts for more than
3840@var{seconds}, terminate it and report a build failure.
3841
3842By default there is no timeout. This behavior can be restored with
3843@code{--timeout=0}.
3844
07ab4bf1
LC
3845@item --verbosity=@var{level}
3846Use the given verbosity level. @var{level} must be an integer between 0
3847and 5; higher means more verbose output. Setting a level of 4 or more
3848may be helpful when debugging setup issues with the build daemon.
3849
70ee5642
LC
3850@item --cores=@var{n}
3851@itemx -c @var{n}
3852Allow the use of up to @var{n} CPU cores for the build. The special
3853value @code{0} means to use as many CPU cores as available.
bf421152 3854
f6526eb3
LC
3855@item --max-jobs=@var{n}
3856@itemx -M @var{n}
3857Allow at most @var{n} build jobs in parallel. @xref{Invoking
3858guix-daemon, @code{--max-jobs}}, for details about this option and the
3859equivalent @command{guix-daemon} option.
3860
c78bd12b
LC
3861@end table
3862
e49951eb 3863Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
3864the @code{package-derivation} procedure of the @code{(guix packages)}
3865module, and to the @code{build-derivations} procedure of the @code{(guix
01d8ac64 3866derivations)} module.
c78bd12b 3867
16eb115e
DP
3868In addition to options explicitly passed on the command line,
3869@command{guix build} and other @command{guix} commands that support
3870building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
3871
3872@defvr {Environment Variable} GUIX_BUILD_OPTIONS
3873Users can define this variable to a list of command line options that
3874will automatically be used by @command{guix build} and other
3875@command{guix} commands that can perform builds, as in the example
3876below:
3877
3878@example
3879$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
3880@end example
3881
847391fe
DP
3882These options are parsed independently, and the result is appended to
3883the parsed command-line options.
16eb115e
DP
3884@end defvr
3885
3886
39bee8a2
LC
3887@node Invoking guix edit
3888@section Invoking @command{guix edit}
3889
3890@cindex package definition, editing
3891So many packages, so many source files! The @command{guix edit} command
3892facilitates the life of packagers by pointing their editor at the source
3893file containing the definition of the specified packages. For instance:
3894
3895@example
3896guix edit gcc-4.8 vim
3897@end example
3898
3899@noindent
3900launches the program specified in the @code{EDITOR} environment variable
3901to edit the recipe of GCC@tie{}4.8.4 and that of Vim.
3902
3903If you are using Emacs, note that the Emacs user interface provides
6248e326
AK
3904similar functionality in the ``package info'' and ``package list''
3905buffers created by @kbd{M-x guix-search-by-name} and similar commands
3906(@pxref{Emacs Commands}).
39bee8a2
LC
3907
3908
210cc920
LC
3909@node Invoking guix download
3910@section Invoking @command{guix download}
3911
3912When writing a package definition, developers typically need to download
3913the package's source tarball, compute its SHA256 hash, and write that
3914hash in the package definition (@pxref{Defining Packages}). The
3915@command{guix download} tool helps with this task: it downloads a file
3916from the given URI, adds it to the store, and prints both its file name
3917in the store and its SHA256 hash.
3918
3919The fact that the downloaded file is added to the store saves bandwidth:
3920when the developer eventually tries to build the newly defined package
3921with @command{guix build}, the source tarball will not have to be
3922downloaded again because it is already in the store. It is also a
3923convenient way to temporarily stash files, which may be deleted
3924eventually (@pxref{Invoking guix gc}).
3925
3926The @command{guix download} command supports the same URIs as used in
3927package definitions. In particular, it supports @code{mirror://} URIs.
3928@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
3929Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
3930they are not available, an error is raised. @xref{Guile Preparations,
3931how to install the GnuTLS bindings for Guile,, gnutls-guile,
3932GnuTLS-Guile}, for more information.
210cc920
LC
3933
3934The following option is available:
3935
3936@table @code
3937@item --format=@var{fmt}
3938@itemx -f @var{fmt}
3939Write the hash in the format specified by @var{fmt}. For more
081145cf 3940information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
3941@end table
3942
6c365eca
NK
3943@node Invoking guix hash
3944@section Invoking @command{guix hash}
3945
210cc920 3946The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
3947It is primarily a convenience tool for anyone contributing to the
3948distribution: it computes the cryptographic hash of a file, which can be
3949used in the definition of a package (@pxref{Defining Packages}).
3950
3951The general syntax is:
3952
3953@example
3954guix hash @var{option} @var{file}
3955@end example
3956
3957@command{guix hash} has the following option:
3958
3959@table @code
3960
3961@item --format=@var{fmt}
3962@itemx -f @var{fmt}
210cc920 3963Write the hash in the format specified by @var{fmt}.
6c365eca
NK
3964
3965Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
3966(@code{hex} and @code{hexadecimal} can be used as well).
3967
3968If the @option{--format} option is not specified, @command{guix hash}
3969will output the hash in @code{nix-base32}. This representation is used
3970in the definitions of packages.
3971
3140f2df
LC
3972@item --recursive
3973@itemx -r
3974Compute the hash on @var{file} recursively.
3975
3976In this case, the hash is computed on an archive containing @var{file},
3977including its children if it is a directory. Some of @var{file}'s
3978meta-data is part of the archive; for instance, when @var{file} is a
3979regular file, the hash is different depending on whether @var{file} is
3980executable or not. Meta-data such as time stamps has no impact on the
3981hash (@pxref{Invoking guix archive}).
3982@c FIXME: Replace xref above with xref to an ``Archive'' section when
3983@c it exists.
3984
6c365eca
NK
3985@end table
3986
2f7d2d91
LC
3987@node Invoking guix import
3988@section Invoking @command{guix import}
3989
3990@cindex importing packages
3991@cindex package import
3992@cindex package conversion
3993The @command{guix import} command is useful for people willing to add a
3994package to the distribution but who'd rather do as little work as
3995possible to get there---a legitimate demand. The command knows of a few
3996repositories from which it can ``import'' package meta-data. The result
3997is a package definition, or a template thereof, in the format we know
3998(@pxref{Defining Packages}).
3999
4000The general syntax is:
4001
4002@example
4003guix import @var{importer} @var{options}@dots{}
4004@end example
4005
4006@var{importer} specifies the source from which to import package
4007meta-data, and @var{options} specifies a package identifier and other
4008options specific to @var{importer}. Currently, the available
4009``importers'' are:
4010
4011@table @code
4012@item gnu
4013Import meta-data for the given GNU package. This provides a template
4014for the latest version of that GNU package, including the hash of its
4015source tarball, and its canonical synopsis and description.
4016
4017Additional information such as the package's dependencies and its
4018license needs to be figured out manually.
4019
4020For example, the following command returns a package definition for
4021GNU@tie{}Hello:
4022
4023@example
4024guix import gnu hello
4025@end example
4026
4027Specific command-line options are:
4028
4029@table @code
4030@item --key-download=@var{policy}
4031As for @code{guix refresh}, specify the policy to handle missing OpenPGP
4032keys when verifying the package's signature. @xref{Invoking guix
4033refresh, @code{--key-download}}.
4034@end table
4035
4036@item pypi
4037@cindex pypi
4038Import meta-data from the @uref{https://pypi.python.org/, Python Package
4039Index}@footnote{This functionality requires Guile-JSON to be installed.
4040@xref{Requirements}.}. Information is taken from the JSON-formatted
4041description available at @code{pypi.python.org} and usually includes all
4042the relevant information, including package dependencies.
4043
4044The command below imports meta-data for the @code{itsdangerous} Python
4045package:
4046
4047@example
4048guix import pypi itsdangerous
4049@end example
4050
3aae8145
DT
4051@item gem
4052@cindex gem
4053Import meta-data from @uref{https://rubygems.org/,
4054RubyGems}@footnote{This functionality requires Guile-JSON to be
4055installed. @xref{Requirements}.}. Information is taken from the
4056JSON-formatted description available at @code{rubygems.org} and includes
4057most relevant information, including runtime dependencies. There are
4058some caveats, however. The meta-data doesn't distinguish between
4059synopses and descriptions, so the same string is used for both fields.
4060Additionally, the details of non-Ruby dependencies required to build
4061native extensions is unavailable and left as an exercise to the
4062packager.
4063
4064The command below imports meta-data for the @code{rails} Ruby package:
4065
4066@example
4067guix import gem rails
4068@end example
4069
d45dc6da
EB
4070@item cpan
4071@cindex CPAN
4072Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}.
4073Information is taken from the JSON-formatted meta-data provided through
4074@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4075relevant information, such as module dependencies. License information
4076should be checked closely. If Perl is available in the store, then the
4077@code{corelist} utility will be used to filter core modules out of the
4078list of dependencies.
d45dc6da
EB
4079
4080The command command below imports meta-data for the @code{Acme::Boolean}
4081Perl module:
4082
4083@example
4084guix import cpan Acme::Boolean
4085@end example
4086
e1248602
RW
4087@item cran
4088@cindex CRAN
4089Import meta-data from @uref{http://cran.r-project.org/, CRAN}, the
4090central repository for the @uref{http://r-project.org, GNU@tie{}R
4091statistical and graphical environment}.
4092
4093Information is extracted from the HTML package description.
4094
4095The command command below imports meta-data for the @code{Cairo}
4096R package:
4097
4098@example
4099guix import cran Cairo
4100@end example
4101
2f7d2d91
LC
4102@item nix
4103Import meta-data from a local copy of the source of the
4104@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4105relies on the @command{nix-instantiate} command of
4106@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4107typically written in a mixture of Nix-language and Bash code. This
4108command only imports the high-level package structure that is written in
4109the Nix language. It normally includes all the basic fields of a
4110package definition.
4111
4112When importing a GNU package, the synopsis and descriptions are replaced
4113by their canonical upstream variant.
4114
4115As an example, the command below imports the package definition of
4116LibreOffice (more precisely, it imports the definition of the package
4117bound to the @code{libreoffice} top-level attribute):
4118
4119@example
4120guix import nix ~/path/to/nixpkgs libreoffice
4121@end example
863af4e1
FB
4122
4123@item hackage
4124@cindex hackage
4125Import meta-data from Haskell community's central package archive
4126@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4127Cabal files and includes all the relevant information, including package
4128dependencies.
4129
4130Specific command-line options are:
4131
4132@table @code
a4154748
FB
4133@item --stdin
4134@itemx -s
4135Read a Cabal file from the standard input.
863af4e1
FB
4136@item --no-test-dependencies
4137@itemx -t
a4154748
FB
4138Do not include dependencies required by the test suites only.
4139@item --cabal-environment=@var{alist}
4140@itemx -e @var{alist}
4141@var{alist} is a Scheme alist defining the environment in which the
4142Cabal conditionals are evaluated. The accepted keys are: @code{os},
4143@code{arch}, @code{impl} and a string representing the name of a flag.
4144The value associated with a flag has to be either the symbol
4145@code{true} or @code{false}. The value associated with other keys
4146has to conform to the Cabal file format definition. The default value
4147associated with the keys @code{os}, @code{arch} and @code{impl} is
4148@samp{linux}, @samp{x86_64} and @samp{ghc} respectively.
863af4e1
FB
4149@end table
4150
4151The command below imports meta-data for the latest version of the
a4154748
FB
4152@code{HTTP} Haskell package without including test dependencies and
4153specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4154
4155@example
a4154748 4156guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4157@end example
4158
4159A specific package version may optionally be specified by following the
4160package name by a hyphen and a version number as in the following example:
4161
4162@example
4163guix import hackage mtl-2.1.3.1
4164@end example
7f74a931
FB
4165
4166@item elpa
4167@cindex elpa
4168Import meta-data from an Emacs Lisp Package Archive (ELPA) package
4169repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4170
4171Specific command-line options are:
4172
4173@table @code
4174@item --archive=@var{repo}
4175@itemx -a @var{repo}
4176@var{repo} identifies the archive repository from which to retrieve the
4177information. Currently the supported repositories and their identifiers
4178are:
4179@itemize -
4180@item
840bd1d3 4181@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4182identifier. This is the default.
4183
4184@item
840bd1d3 4185@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4186@code{melpa-stable} identifier.
4187
4188@item
840bd1d3 4189@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4190identifier.
4191@end itemize
4192@end table
2f7d2d91
LC
4193@end table
4194
4195The structure of the @command{guix import} code is modular. It would be
4196useful to have more importers for other package formats, and your help
4197is welcome here (@pxref{Contributing}).
4198
37166310
LC
4199@node Invoking guix refresh
4200@section Invoking @command{guix refresh}
4201
4202The primary audience of the @command{guix refresh} command is developers
4203of the GNU software distribution. By default, it reports any packages
4204provided by the distribution that are outdated compared to the latest
4205upstream version, like this:
4206
4207@example
4208$ guix refresh
4209gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4210gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4211@end example
4212
4213It does so by browsing each package's FTP directory and determining the
bcb571cb
LC
4214highest version number of the source tarballs therein. The command
4215knows how to update specific types of packages: GNU packages, ELPA
4216packages, etc.---see the documentation for @option{--type} below. The
4217are many packages, though, for which it lacks a method to determine
4218whether a new upstream release is available. However, the mechanism is
4219extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4220
4221When passed @code{--update}, it modifies distribution source files to
4222update the version numbers and source tarball hashes of those packages'
4223recipes (@pxref{Defining Packages}). This is achieved by downloading
4224each package's latest source tarball and its associated OpenPGP
4225signature, authenticating the downloaded tarball against its signature
4226using @command{gpg}, and finally computing its hash. When the public
4227key used to sign the tarball is missing from the user's keyring, an
4228attempt is made to automatically retrieve it from a public key server;
4229when it's successful, the key is added to the user's keyring; otherwise,
4230@command{guix refresh} reports an error.
4231
4232The following options are supported:
4233
4234@table @code
4235
4236@item --update
4237@itemx -u
38e16b49
LC
4238Update distribution source files (package recipes) in place. This is
4239usually run from a checkout of the Guix source tree (@pxref{Running
4240Guix Before It Is Installed}):
4241
4242@example
4243$ ./pre-inst-env guix refresh -s non-core
4244@end example
4245
081145cf 4246@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4247
4248@item --select=[@var{subset}]
4249@itemx -s @var{subset}
4250Select all the packages in @var{subset}, one of @code{core} or
4251@code{non-core}.
4252
4253The @code{core} subset refers to all the packages at the core of the
4254distribution---i.e., packages that are used to build ``everything
4255else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4256changing one of these packages in the distribution entails a rebuild of
4257all the others. Thus, such updates are an inconvenience to users in
4258terms of build time or bandwidth used to achieve the upgrade.
4259
4260The @code{non-core} subset refers to the remaining packages. It is
4261typically useful in cases where an update of the core packages would be
4262inconvenient.
4263
bcb571cb
LC
4264@item --type=@var{updater}
4265@itemx -t @var{updater}
4266Select only packages handled by @var{updater}. Currently, @var{updater}
4267may be one of:
4268
4269@table @code
4270@item gnu
4271the updater for GNU packages;
4272@item elpa
d882c235
LC
4273the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4274@item cran
4275the updater fro @uref{http://cran.r-project.org/, CRAN} packages.
bcb571cb
LC
4276@end table
4277
4278For instance, the following commands only checks for updates of Emacs
d882c235 4279packages hosted at @code{elpa.gnu.org} and updates of CRAN packages:
bcb571cb
LC
4280
4281@example
d882c235
LC
4282$ guix refresh -t elpa -t cran
4283gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4284gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4285@end example
4286
37166310
LC
4287@end table
4288
4289In addition, @command{guix refresh} can be passed one or more package
4290names, as in this example:
4291
4292@example
38e16b49 4293$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4294@end example
4295
4296@noindent
4297The command above specifically updates the @code{emacs} and
4298@code{idutils} packages. The @code{--select} option would have no
4299effect in this case.
4300
7d193ec3
EB
4301When considering whether to upgrade a package, it is sometimes
4302convenient to know which packages would be affected by the upgrade and
4303should be checked for compatibility. For this the following option may
4304be used when passing @command{guix refresh} one or more package names:
4305
4306@table @code
4307
4308@item --list-dependent
4309@itemx -l
4310List top-level dependent packages that would need to be rebuilt as a
4311result of upgrading one or more packages.
4312
4313@end table
4314
4315Be aware that the @code{--list-dependent} option only
4316@emph{approximates} the rebuilds that would be required as a result of
4317an upgrade. More rebuilds might be required under some circumstances.
4318
4319@example
7779ab61
LC
4320$ guix refresh --list-dependent flex
4321Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4322hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4323@end example
4324
4325The command above lists a set of packages that could be built to check
4326for compatibility with an upgraded @code{flex} package.
4327
f9230085
LC
4328The following options can be used to customize GnuPG operation:
4329
4330@table @code
4331
f9230085
LC
4332@item --gpg=@var{command}
4333Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4334for in @code{$PATH}.
4335
2bc53ba9
LC
4336@item --key-download=@var{policy}
4337Handle missing OpenPGP keys according to @var{policy}, which may be one
4338of:
4339
4340@table @code
4341@item always
4342Always download missing OpenPGP keys from the key server, and add them
4343to the user's GnuPG keyring.
4344
4345@item never
4346Never try to download missing OpenPGP keys. Instead just bail out.
4347
4348@item interactive
4349When a package signed with an unknown OpenPGP key is encountered, ask
4350the user whether to download it or not. This is the default behavior.
4351@end table
4352
4353@item --key-server=@var{host}
4354Use @var{host} as the OpenPGP key server when importing a public key.
4355
f9230085
LC
4356@end table
4357
b4f5e0e8
CR
4358@node Invoking guix lint
4359@section Invoking @command{guix lint}
4360The @command{guix lint} is meant to help package developers avoid common
873c4085
LC
4361errors and use a consistent style. It runs a number of checks on a
4362given set of packages in order to find common mistakes in their
4363definitions. Available @dfn{checkers} include (see
4364@code{--list-checkers} for a complete list):
4365
4366@table @code
4367@item synopsis
4368@itemx description
4369Validate certain typographical and stylistic rules about package
4370descriptions and synopses.
4371
4372@item inputs-should-be-native
4373Identify inputs that should most likely be native inputs.
4374
4375@item source
4376@itemx home-page
50f5c46d 4377@itemx source-file-name
873c4085 4378Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d
EB
4379invalid. Check that the source file name is meaningful, e.g. is not
4380just a version number or ``git-checkout'', and should not have a
4381@code{file-name} declared (@pxref{origin Reference}).
40a7d4e5
LC
4382
4383@item formatting
4384Warn about obvious source code formatting issues: trailing white space,
4385use of tabulations, etc.
873c4085 4386@end table
b4f5e0e8
CR
4387
4388The general syntax is:
4389
4390@example
4391guix lint @var{options} @var{package}@dots{}
4392@end example
4393
4394If no package is given on the command line, then all packages are checked.
4395The @var{options} may be zero or more of the following:
4396
4397@table @code
4398
dd7c013d
CR
4399@item --checkers
4400@itemx -c
4401Only enable the checkers specified in a comma-separated list using the
4402names returned by @code{--list-checkers}.
4403
b4f5e0e8
CR
4404@item --list-checkers
4405@itemx -l
4406List and describe all the available checkers that will be run on packages
4407and exit.
4408
4409@end table
37166310 4410
fcc58db6
LC
4411@node Invoking guix size
4412@section Invoking @command{guix size}
4413
4414The @command{guix size} command helps package developers profile the
4415disk usage of packages. It is easy to overlook the impact of an
4416additional dependency added to a package, or the impact of using a
4417single output for a package that could easily be split (@pxref{Packages
4418with Multiple Outputs}). These are the typical issues that
4419@command{guix size} can highlight.
4420
4421The command can be passed a package specification such as @code{gcc-4.8}
4422or @code{guile:debug}, or a file name in the store. Consider this
4423example:
4424
4425@example
4426$ guix size coreutils
4427store item total self
4428/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4429/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4430/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4431/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4432/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4433/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4434@end example
4435
4436@cindex closure
4437The store items listed here constitute the @dfn{transitive closure} of
4438Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4439would be returned by:
4440
4441@example
4442$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4443@end example
4444
4445Here the output shows 3 columns next to store items. The first column,
4446labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4447the store item---that is, its own size plus the size of all its
4448dependencies. The next column, labeled ``self'', shows the size of the
4449item itself. The last column shows the ratio of the item's size to the
4450space occupied by all the items listed here.
4451
4452In this example, we see that the closure of Coreutils weighs in at
445370@tie{}MiB, half of which is taken by libc. (That libc represents a
4454large fraction of the closure is not a problem @i{per se} because it is
4455always available on the system anyway.)
4456
4457When the package passed to @command{guix size} is available in the
4458store, @command{guix size} queries the daemon to determine its
4459dependencies, and measures its size in the store, similar to @command{du
4460-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4461Coreutils}).
4462
4463When the given package is @emph{not} in the store, @command{guix size}
4464reports information based on information about the available substitutes
4465(@pxref{Substitutes}). This allows it to profile disk usage of store
4466items that are not even on disk, only available remotely.
4467
a8f996c6 4468The available options are:
fcc58db6
LC
4469
4470@table @option
4471
d490d06e
LC
4472@item --substitute-urls=@var{urls}
4473Use substitute information from @var{urls}.
4474@xref{client-substitute-urls, the same option for @code{guix build}}.
4475
a8f996c6
LC
4476@item --map-file=@var{file}
4477Write to @var{file} a graphical map of disk usage as a PNG file.
4478
4479For the example above, the map looks like this:
4480
4481@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4482produced by @command{guix size}}
4483
4484This option requires that
4485@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4486installed and visible in Guile's module search path. When that is not
4487the case, @command{guix size} fails as it tries to load it.
4488
fcc58db6
LC
4489@item --system=@var{system}
4490@itemx -s @var{system}
4491Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4492
4493@end table
4494
88856916
LC
4495@node Invoking guix graph
4496@section Invoking @command{guix graph}
4497
4498@cindex DAG
4499Packages and their dependencies form a @dfn{graph}, specifically a
4500directed acyclic graph (DAG). It can quickly become difficult to have a
4501mental model of the package DAG, so the @command{guix graph} command is
4502here to provide a visual representation of the DAG. @command{guix
4503graph} emits a DAG representation in the input format of
4504@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
4505directly to Graphviz's @command{dot} command, for instance. The general
4506syntax is:
4507
4508@example
4509guix graph @var{options} @var{package}@dots{}
4510@end example
4511
4512For example, the following command generates a PDF file representing the
4513package DAG for the GNU@tie{}Core Utilities, showing its build-time
4514dependencies:
4515
4516@example
4517guix graph coreutils | dot -Tpdf > dag.pdf
4518@end example
4519
4520The output looks like this:
4521
4522@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4523
4524Nice little graph, no?
4525
4526But there's more than one graph! The one above is concise: it's the
4527graph of package objects, omitting implicit inputs such as GCC, libc,
4528grep, etc. It's often useful to have such a concise graph, but
4529sometimes you want to see more details. @command{guix graph} supports
4530several types of graphs, allowing you to choose the level of details:
4531
4532@table @code
4533@item package
4534This is the default type, the one we used above. It shows the DAG of
4535package objects, excluding implicit dependencies. It is concise, but
4536filters out many details.
4537
4538@item bag-emerged
4539This is the package DAG, @emph{including} implicit inputs.
4540
4541For instance, the following command:
4542
4543@example
4544guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4545@end example
4546
4547... yields this bigger graph:
4548
4549@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4550
4551At the bottom of the graph, we see all the implicit inputs of
4552@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4553
4554Now, note that the dependencies of those implicit inputs---that is, the
4555@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4556here, for conciseness.
4557
4558@item bag
4559Similar to @code{bag-emerged}, but this time including all the bootstrap
4560dependencies.
4561
4562@item derivations
4563This is the most detailed representation: It shows the DAG of
4564derivations (@pxref{Derivations}) and plain store items. Compared to
4565the above representation, many additional nodes are visible, including
4566builds scripts, patches, Guile modules, etc.
4567
4568@end table
4569
4570All the above types correspond to @emph{build-time dependencies}. The
4571following graph type represents the @emph{run-time dependencies}:
4572
4573@table @code
4574@item references
4575This is the graph of @dfn{references} of a package output, as returned
4576by @command{guix gc --references} (@pxref{Invoking guix gc}).
4577
4578If the given package output is not available in the store, @command{guix
4579graph} attempts to obtain dependency information from substitutes.
4580@end table
4581
4582The available options are the following:
4583
4584@table @option
4585@item --type=@var{type}
4586@itemx -t @var{type}
4587Produce a graph output of @var{type}, where @var{type} must be one of
4588the values listed above.
4589
4590@item --list-types
4591List the supported graph types.
4c8f997a
LC
4592
4593@item --expression=@var{expr}
4594@itemx -e @var{expr}
4595Consider the package @var{expr} evaluates to.
4596
4597This is useful to precisely refer to a package, as in this example:
4598
4599@example
4600guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
4601@end example
88856916
LC
4602@end table
4603
4604
372c4bbc
DT
4605@node Invoking guix environment
4606@section Invoking @command{guix environment}
4607
f5fd4fd2 4608@cindex reproducible build environments
fe36d84e 4609@cindex development environments
372c4bbc
DT
4610The purpose of @command{guix environment} is to assist hackers in
4611creating reproducible development environments without polluting their
4612package profile. The @command{guix environment} tool takes one or more
4613packages, builds all of the necessary inputs, and creates a shell
4614environment to use them.
4615
4616The general syntax is:
4617
4618@example
4619guix environment @var{options} @var{package}@dots{}
4620@end example
4621
fe36d84e
LC
4622The following example spawns a new shell set up for the development of
4623GNU@tie{}Guile:
372c4bbc
DT
4624
4625@example
4626guix environment guile
4627@end example
4628
4629If the specified packages are not built yet, @command{guix environment}
4630automatically builds them. The new shell's environment is an augmented
4631version of the environment that @command{guix environment} was run in.
4632It contains the necessary search paths for building the given package
4633added to the existing environment variables. To create a ``pure''
4634environment in which the original environment variables have been unset,
50500f7c
LC
4635use the @code{--pure} option@footnote{Users sometimes wrongfully augment
4636environment variables such as @code{PATH} in their @file{~/.bashrc}
4637file. As a consequence, when @code{guix environment} launches it, Bash
4638may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
4639environment variables. It is an error to define such environment
4640variables in @file{.bashrc}; instead, they should be defined in
4641@file{.bash_profile}, which is sourced only by log-in shells.
4642@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
4643details on Bash start-up files.}.
372c4bbc 4644
28de8d25
LC
4645@vindex GUIX_ENVIRONMENT
4646@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
4647variable in the shell it spaws. This allows users to, say, define a
4648specific prompt for development environments in their @file{.bashrc}
4649(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
4650
4651@example
4652if [ -n "$GUIX_ENVIRONMENT" ]
4653then
4654 export PS1="\u@@\h \w [dev]\$ "
4655fi
4656@end example
4657
372c4bbc
DT
4658Additionally, more than one package may be specified, in which case the
4659union of the inputs for the given packages are used. For example, the
4660command below spawns a shell where all of the dependencies of both Guile
4661and Emacs are available:
4662
4663@example
4664guix environment guile emacs
4665@end example
4666
1de2fe95
DT
4667Sometimes an interactive shell session is not desired. An arbitrary
4668command may be invoked by placing the @code{--} token to separate the
4669command from the rest of the arguments:
372c4bbc
DT
4670
4671@example
1de2fe95 4672guix environment guile -- make -j4
372c4bbc
DT
4673@end example
4674
fe36d84e
LC
4675In other situations, it is more convenient to specify the list of
4676packages needed in the environment. For example, the following command
4677runs @command{python} from an environment containing Python@tie{}2.7 and
4678NumPy:
4679
4680@example
1de2fe95 4681guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
4682@end example
4683
f535dcbe
DT
4684Sometimes it is desirable to isolate the environment as much as
4685possible, for maximal purity and reproducibility. In particular, when
4686using Guix on a host distro that is not GuixSD, it is desirable to
4687prevent access to @file{/usr/bin} and other system-wide resources from
4688the development environment. For example, the following command spawns
4689a Guile REPL in a ``container'' where only the store and the current
4690working directory are mounted:
4691
4692@example
4693guix environment --ad-hoc --container guile -- guile
4694@end example
4695
fe36d84e 4696The available options are summarized below.
372c4bbc
DT
4697
4698@table @code
4699@item --expression=@var{expr}
4700@itemx -e @var{expr}
4701Create an environment for the package that @var{expr} evaluates to.
4702
fe36d84e
LC
4703For example, running:
4704
4705@example
4706guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
4707@end example
4708
4709starts a shell with the environment for this specific variant of the
4710PETSc package.
4711
372c4bbc
DT
4712@item --load=@var{file}
4713@itemx -l @var{file}
4714Create an environment for the package that the code within @var{file}
4715evaluates to.
4716
fe36d84e
LC
4717As an example, @var{file} might contain a definition like this
4718(@pxref{Defining Packages}):
4719
4720@example
4721@verbatiminclude environment-gdb.scm
4722@end example
4723
a54bd6d7
DT
4724@item --ad-hoc
4725Include all specified packages in the resulting environment, as if an
4726@i{ad hoc} package were defined with them as inputs. This option is
4727useful for quickly creating an environment without having to write a
4728package expression to contain the desired inputs.
4729
4730For instance, the command:
4731
4732@example
1de2fe95 4733guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
4734@end example
4735
4736runs @command{guile} in an environment where Guile and Guile-SDL are
4737available.
4738
417c39f1
LC
4739Note that this example implicitly asks for the default output of
4740@code{guile} and @code{guile-sdl} but it is possible to ask for a
4741specific output---e.g., @code{glib:bin} asks for the @code{bin} output
4742of @code{glib} (@pxref{Packages with Multiple Outputs}).
4743
372c4bbc
DT
4744@item --pure
4745Unset existing environment variables when building the new environment.
4746This has the effect of creating an environment in which search paths
4747only contain package inputs.
4748
4749@item --search-paths
4750Display the environment variable definitions that make up the
4751environment.
ce367ef3
LC
4752
4753@item --system=@var{system}
4754@itemx -s @var{system}
4755Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
4756
4757@item --container
4758@itemx -C
4759@cindex container
4760Run @var{command} within an isolated container. The current working
4761directory outside the container is mapped to @file{/env} inside the
4762container. Additionally, the spawned process runs as the current user
4763outside the container, but has root privileges in the context of the
4764container.
4765
4766@item --network
4767@itemx -N
4768For containers, share the network namespace with the host system.
4769Containers created without this flag only have access to the loopback
4770device.
4771
4772@item --expose=@var{source}[=@var{target}]
4773For containers, expose the file system @var{source} from the host system
4774as the read-only file system @var{target} within the container. If
4775@var{target} is not specified, @var{source} is used as the target mount
4776point in the container.
4777
4778The example below spawns a Guile REPL in a container in which the user's
4779home directory is accessible read-only via the @file{/exchange}
4780directory:
4781
4782@example
4783guix environment --container --expose=$HOME=/exchange guile -- guile
4784@end example
4785
4786@item --share
4787For containers, share the file system @var{source} from the host system
4788as the writable file system @var{target} within the container. If
4789@var{target} is not specified, @var{source} is used as the target mount
4790point in the container.
4791
4792The example below spawns a Guile REPL in a container in which the user's
4793home directory is accessible for both reading and writing via the
4794@file{/exchange} directory:
4795
4796@example
4797guix environment --container --share=$HOME=/exchange guile -- guile
4798@end example
372c4bbc
DT
4799@end table
4800
4801It also supports all of the common build options that @command{guix
4802build} supports (@pxref{Invoking guix build, common build options}).
4803
aff8ce7c
DT
4804@node Invoking guix publish
4805@section Invoking @command{guix publish}
4806
4807The purpose of @command{guix publish} is to enable users to easily share
8ce229fc
LC
4808their store with others, which can then use it as a substitute server
4809(@pxref{Substitutes}).
4810
4811When @command{guix publish} runs, it spawns an HTTP server which allows
4812anyone with network access to obtain substitutes from it. This means
4813that any machine running Guix can also act as if it were a build farm,
4814since the HTTP interface is compatible with Hydra, the software behind
4815the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
4816
4817For security, each substitute is signed, allowing recipients to check
4818their authenticity and integrity (@pxref{Substitutes}). Because
4819@command{guix publish} uses the system's signing key, which is only
5463fe51
LC
4820readable by the system administrator, it must be started as root; the
4821@code{--user} option makes it drop root privileges early on.
aff8ce7c
DT
4822
4823The general syntax is:
4824
4825@example
4826guix publish @var{options}@dots{}
4827@end example
4828
4829Running @command{guix publish} without any additional arguments will
4830spawn an HTTP server on port 8080:
4831
4832@example
4833guix publish
4834@end example
4835
4836Once a publishing server has been authorized (@pxref{Invoking guix
4837archive}), the daemon may download substitutes from it:
4838
4839@example
4840guix-daemon --substitute-urls=http://example.org:8080
4841@end example
4842
4843The following options are available:
4844
4845@table @code
4846@item --port=@var{port}
4847@itemx -p @var{port}
4848Listen for HTTP requests on @var{port}.
4849
9e2292ef
LC
4850@item --listen=@var{host}
4851Listen on the network interface for @var{host}. The default is to
4852accept connections from any interface.
4853
5463fe51
LC
4854@item --user=@var{user}
4855@itemx -u @var{user}
4856Change privileges to @var{user} as soon as possible---i.e., once the
4857server socket is open and the signing key has been read.
4858
aff8ce7c
DT
4859@item --repl[=@var{port}]
4860@itemx -r [@var{port}]
4861Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
4862Reference Manual}) on @var{port} (37146 by default). This is used
4863primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
4864@end table
4865
d23c20f1
LC
4866
4867@node Invoking guix challenge
4868@section Invoking @command{guix challenge}
4869
4870@cindex reproducible builds
4871@cindex verifiable builds
4872
4873Do the binaries provided by this server really correspond to the source
4874code it claims to build? Is this package's build process deterministic?
4875These are the questions the @command{guix challenge} command attempts to
4876answer.
4877
4878The former is obviously an important question: Before using a substitute
4879server (@pxref{Substitutes}), you'd rather @emph{verify} that it
4880provides the right binaries, and thus @emph{challenge} it. The latter
4881is what enables the former: If package builds are deterministic, then
4882independent builds of the package should yield the exact same result,
4883bit for bit; if a server provides a binary different from the one
4884obtained locally, it may be either corrupt or malicious.
4885
4886We know that the hash that shows up in @file{/gnu/store} file names is
4887the hash of all the inputs of the process that built the file or
4888directory---compilers, libraries, build scripts,
4889etc. (@pxref{Introduction}). Assuming deterministic build processes,
4890one store file name should map to exactly one build output.
4891@command{guix challenge} checks whether there is, indeed, a single
4892mapping by comparing the build outputs of several independent builds of
4893any given store item.
4894
4895The command's output looks like this:
4896
4897@smallexample
4898$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
4899updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
4900updating list of substitutes from 'http://guix.example.org'... 100.0%
4901/gnu/store/@dots{}-openssl-1.0.2d contents differ:
4902 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
4903 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
4904 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
4905/gnu/store/@dots{}-git-2.5.0 contents differ:
4906 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
4907 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
4908 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
4909/gnu/store/@dots{}-pius-2.1.1 contents differ:
4910 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
4911 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
4912 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
4913@end smallexample
4914
4915@noindent
4916In this example, @command{guix challenge} first scans the store to
4917determine the set of locally-built derivations---as opposed to store
4918items that were downloaded from a substitute server---and then queries
4919all the substitute servers. It then reports those store items for which
4920the servers obtained a result different from the local build.
4921
4922@cindex non-determinism, in package builds
4923As an example, @code{guix.example.org} always gets a different answer.
4924Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
4925case of Git. This might indicate that the build process of Git is
4926non-deterministic, meaning that its output varies as a function of
4927various things that Guix does not fully control, in spite of building
4928packages in isolated environments (@pxref{Features}). Most common
4929sources of non-determinism include the addition of timestamps in build
4930results, the inclusion of random numbers, and directory listings sorted
4931by inode number. See @uref{http://reproducible.debian.net/howto/}, for
4932more information.
4933
4934To find out what's wrong with this Git binary, we can do something along
4935these lines (@pxref{Invoking guix archive}):
4936
4937@example
4938$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
4939 | guix archive -x /tmp/git
4940$ diff -ur /gnu/store/@dots{}-git.2.5.0 /tmp/git
4941@end example
4942
4943This command shows the difference between the files resulting from the
4944local build, and the files resulting from the build on
4945@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
4946diffutils, Comparing and Merging Files}). The @command{diff} command
4947works great for text files. When binary files differ, a better option
4948is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
4949visualize differences for all kinds of files.
4950
4951Once you've done that work, you can tell whether the differences are due
4952to a non-deterministic build process or to a malicious server. We try
4953hard to remove sources of non-determinism in packages to make it easier
4954to verify substitutes, but of course, this is a process, one that
4955involves not just Guix but a large part of the free software community.
4956In the meantime, @command{guix challenge} is one tool to help address
4957the problem.
4958
4959If you are writing packages for Guix, you are encouraged to check
4960whether @code{hydra.gnu.org} and other substitute servers obtain the
4961same build result as you did with:
4962
4963@example
4964$ guix challenge @var{package}
4965@end example
4966
4967@noindent
4968... where @var{package} is a package specification such as
4969@code{guile-2.0} or @code{glibc:debug}.
4970
4971The general syntax is:
4972
4973@example
4974guix challenge @var{options} [@var{packages}@dots{}]
4975@end example
4976
4977The one option that matters is:
4978
4979@table @code
4980
4981@item --substitute-urls=@var{urls}
4982Consider @var{urls} the whitespace-separated list of substitute source
4983URLs to compare to.
4984
4985@end table
4986
4987
a1ba8475
LC
4988@c *********************************************************************
4989@node GNU Distribution
4990@chapter GNU Distribution
4991
3ca2731c 4992@cindex Guix System Distribution
4705641f 4993@cindex GuixSD
3ca2731c
LC
4994Guix comes with a distribution of the GNU system consisting entirely of
4995free software@footnote{The term ``free'' here refers to the
a1ba8475 4996@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 4997users of that software}.}. The
35ed9306
LC
4998distribution can be installed on its own (@pxref{System Installation}),
4999but it is also possible to install Guix as a package manager on top of
5000an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5001between the two, we refer to the standalone distribution as the Guix
4705641f 5002System Distribution, or GuixSD.
35ed9306
LC
5003
5004The distribution provides core GNU packages such as GNU libc, GCC, and
5005Binutils, as well as many GNU and non-GNU applications. The complete
5006list of available packages can be browsed
093ae1be 5007@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5008running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5009
5010@example
e49951eb 5011guix package --list-available
a1ba8475
LC
5012@end example
5013
35ed9306 5014Our goal has been to provide a practical 100% free software distribution of
401c53c4
LC
5015Linux-based and other variants of GNU, with a focus on the promotion and
5016tight integration of GNU components, and an emphasis on programs and
5017tools that help users exert that freedom.
5018
3ca2731c 5019Packages are currently available on the following platforms:
c320011d
LC
5020
5021@table @code
5022
5023@item x86_64-linux
5024Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5025
5026@item i686-linux
5027Intel 32-bit architecture (IA32), Linux-Libre kernel;
5028
aa1e1947 5029@item armhf-linux
aa725117 5030ARMv7-A architecture with hard float, Thumb-2 and NEON,
aa1e1947
MW
5031using the EABI hard-float ABI, and Linux-Libre kernel.
5032
c320011d
LC
5033@item mips64el-linux
5034little-endian 64-bit MIPS processors, specifically the Loongson series,
5035n32 application binary interface (ABI), and Linux-Libre kernel.
5036
5037@end table
5038
4705641f 5039GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5040
c320011d
LC
5041@noindent
5042For information on porting to other architectures or kernels,
5043@xref{Porting}.
5044
401c53c4 5045@menu
5af6de3e 5046* System Installation:: Installing the whole operating system.
35ed9306 5047* System Configuration:: Configuring the operating system.
91ef73d4 5048* Installing Debugging Files:: Feeding the debugger.
05962f29 5049* Security Updates:: Deploying security fixes quickly.
401c53c4 5050* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5051* Packaging Guidelines:: Growing the distribution.
401c53c4 5052* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5053* Porting:: Targeting another platform or kernel.
401c53c4
LC
5054@end menu
5055
5056Building this distribution is a cooperative effort, and you are invited
081145cf 5057to join! @xref{Contributing}, for information about how you can help.
401c53c4 5058
5af6de3e
LC
5059@node System Installation
5060@section System Installation
5061
3ca2731c
LC
5062@cindex Guix System Distribution
5063This section explains how to install the Guix System Distribution
5064on a machine. The Guix package manager can
35ed9306
LC
5065also be installed on top of a running GNU/Linux system,
5066@pxref{Installation}.
5af6de3e
LC
5067
5068@ifinfo
5069@c This paragraph is for people reading this from tty2 of the
5070@c installation image.
5071You're reading this documentation with an Info reader. For details on
5072how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 5073link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
5074@kbd{l} afterwards to come back here.
5075@end ifinfo
5076
8aaaae38
LC
5077@subsection Limitations
5078
4705641f 5079As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5080not production-ready. It may contain bugs and lack important
8aaaae38
LC
5081features. Thus, if you are looking for a stable production system that
5082respects your freedom as a computer user, a good solution at this point
5083is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
5084more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5085to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5086also keep using your distribution and try out the package manager on top
5087of it (@pxref{Installation}).
5088
5089Before you proceed with the installation, be aware of the following
5090noteworthy limitations applicable to version @value{VERSION}:
5091
5092@itemize
5093@item
5094The installation process does not include a graphical user interface and
5095requires familiarity with GNU/Linux (see the following subsections to
5096get a feel of what that means.)
5097
5098@item
093ae1be
LC
5099The system does not yet provide full GNOME and KDE desktops. Xfce and
5100Enlightenment are available though, if graphical desktop environments
5101are your thing, as well as a number of X11 window managers.
8aaaae38
LC
5102
5103@item
dbcb0ab1 5104Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5105
5106@item
5107Few system services are currently supported out-of-the-box
5108(@pxref{Services}).
5109
5110@item
093ae1be 5111More than 2,000 packages are available, but you may
8aaaae38
LC
5112occasionally find that a useful package is missing.
5113@end itemize
5114
5115You've been warned. But more than a disclaimer, this is an invitation
5116to report issues (and success stories!), and join us in improving it.
5117@xref{Contributing}, for more info.
5af6de3e
LC
5118
5119@subsection USB Stick Installation
5120
5121An installation image for USB sticks can be downloaded from
4705641f 5122@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5123where @var{system} is one of:
5124
5125@table @code
5126@item x86_64-linux
5127for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5128
5129@item i686-linux
5130for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5131@end table
5132
5133This image contains a single partition with the tools necessary for an
5134installation. It is meant to be copied @emph{as is} to a large-enough
5135USB stick.
5136
5137To copy the image to a USB stick, follow these steps:
5138
5139@enumerate
5140@item
5141Decompress the image using the @command{xz} command:
5142
5143@example
4705641f 5144xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5145@end example
5146
5147@item
5148Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
5149its device name. Assuming that USB stick is known as @file{/dev/sdX},
5150copy the image with:
5151
5152@example
4705641f 5153dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5154@end example
5155
5156Access to @file{/dev/sdX} usually requires root privileges.
5157@end enumerate
5158
5159Once this is done, you should be able to reboot the system and boot from
5160the USB stick. The latter usually requires you to get in the BIOS' boot
5161menu, where you can choose to boot from the USB stick.
5162
5163@subsection Preparing for Installation
5164
5165Once you have successfully booted the image on the USB stick, you should
5166end up with a root prompt. Several console TTYs are configured and can
5167be used to run commands as root. TTY2 shows this documentation,
5168browsable using the Info reader commands (@pxref{Help,,, info, Info: An
5169Introduction}).
5170
5171To install the system, you would:
5172
5173@enumerate
5174
5175@item
152dd61c
LC
5176Configure the network, by running @command{ifconfig eno1 up && dhclient
5177eno1} (to get an automatically assigned IP address from the wired
5178network interface controller@footnote{
95c559c1
LC
5179@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
5180The name @code{eno1} is for the first on-board Ethernet controller. The
5181interface name for an Ethernet controller that is in the first slot of
5182the first PCI bus, for instance, would be @code{enp1s0}. Use
5183@command{ifconfig -a} to list all the available network interfaces.}),
5184or using the @command{ifconfig} command.
5af6de3e
LC
5185
5186The system automatically loads drivers for your network interface
5187controllers.
5188
5189Setting up network access is almost always a requirement because the
5190image does not contain all the software and tools that may be needed.
5191
5192@item
5193Unless this has already been done, you must partition and format the
5194target partitions.
5195
7ab44369
LC
5196Preferably, assign partitions a label so that you can easily and
5197reliably refer to them in @code{file-system} declarations (@pxref{File
5198Systems}). This is typically done using the @code{-L} option of
5199@command{mkfs.ext4} and related commands.
5200
5af6de3e 5201The installation image includes Parted (@pxref{Overview,,, parted, GNU
b419c7f5
LC
5202Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk
5203encryption, and e2fsprogs, the suite of tools to manipulate
5204ext2/ext3/ext4 file systems.
5af6de3e 5205
83a17b62
LC
5206@item
5207Once that is done, mount the target root partition under @file{/mnt}.
5208
5209@item
5210Lastly, run @code{deco start cow-store /mnt}.
5211
5212This will make @file{/gnu/store} copy-on-write, such that packages added
5213to it during the installation phase will be written to the target disk
5214rather than kept in memory.
5215
5af6de3e
LC
5216@end enumerate
5217
5af6de3e
LC
5218
5219@subsection Proceeding with the Installation
5220
5221With the target partitions ready, you now have to edit a file and
5222provide the declaration of the operating system to be installed. To
5223that end, the installation system comes with two text editors: GNU nano
5224(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5225It is better to store that file on the target root file system, say, as
5226@file{/mnt/etc/config.scm}.
5227
dd51caac
LC
5228@xref{Using the Configuration System}, for examples of operating system
5229configurations. These examples are available under
5230@file{/etc/configuration} in the installation image, so you can copy
5231them and use them as a starting point for your own configuration.
5af6de3e 5232
dd51caac
LC
5233Once you are done preparing the configuration file, the new system must
5234be initialized (remember that the target root file system is mounted
5235under @file{/mnt}):
5af6de3e
LC
5236
5237@example
5238guix system init /mnt/etc/config.scm /mnt
5239@end example
5240
5241@noindent
5242This will copy all the necessary files, and install GRUB on
5243@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 5244more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
5245downloads or builds of missing packages, which can take some time.
5246
1bd4e6db
LC
5247Once that command has completed---and hopefully succeeded!---you can run
5248@command{reboot} and boot into the new system. The @code{root} password
5249in the new system is initially empty; other users' passwords need to be
5250initialized by running the @command{passwd} command as @code{root},
5251unless your configuration specifies otherwise
5252(@pxref{user-account-password, user account passwords}).
5253
5254Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
5255@file{guix-devel@@gnu.org} to share your experience---good or not so
5256good.
5257
5258@subsection Building the Installation Image
5259
5260The installation image described above was built using the @command{guix
5261system} command, specifically:
5262
5263@example
8a225c66 5264guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
5265@end example
5266
5267@xref{Invoking guix system}, for more information. See
5268@file{gnu/system/install.scm} in the source tree for more information
5269about the installation image.
5270
cf4a9129
LC
5271@node System Configuration
5272@section System Configuration
b208a005 5273
cf4a9129 5274@cindex system configuration
3ca2731c 5275The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
5276mechanism. By that we mean that all aspects of the global system
5277configuration---such as the available system services, timezone and
5278locale settings, user accounts---are declared in a single place. Such
5279a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 5280
cf4a9129
LC
5281One of the advantages of putting all the system configuration under the
5282control of Guix is that it supports transactional system upgrades, and
5283makes it possible to roll-back to a previous system instantiation,
5284should something go wrong with the new one (@pxref{Features}). Another
5285one is that it makes it easy to replicate the exact same configuration
5286across different machines, or at different points in time, without
5287having to resort to additional administration tools layered on top of
5288the system's own tools.
5289@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 5290
cf4a9129
LC
5291This section describes this mechanism. First we focus on the system
5292administrator's viewpoint---explaining how the system is configured and
5293instantiated. Then we show how this mechanism can be extended, for
5294instance to support new system services.
91ef73d4 5295
cf4a9129
LC
5296@menu
5297* Using the Configuration System:: Customizing your GNU system.
7313a52e 5298* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 5299* File Systems:: Configuring file system mounts.
510f9d86 5300* Mapped Devices:: Block device extra processing.
cf4a9129 5301* User Accounts:: Specifying user accounts.
598e19dc 5302* Locales:: Language and cultural convention settings.
cf4a9129 5303* Services:: Specifying system services.
0ae8c15a 5304* Setuid Programs:: Programs running with root privileges.
efb5e833 5305* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 5306* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 5307* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 5308* GRUB Configuration:: Configuring the boot loader.
cf4a9129
LC
5309* Invoking guix system:: Instantiating a system configuration.
5310* Defining Services:: Adding new service definitions.
5311@end menu
91ef73d4 5312
cf4a9129
LC
5313@node Using the Configuration System
5314@subsection Using the Configuration System
64d76fa6 5315
cf4a9129
LC
5316The operating system is configured by providing an
5317@code{operating-system} declaration in a file that can then be passed to
5318the @command{guix system} command (@pxref{Invoking guix system}). A
5319simple setup, with the default system services, the default Linux-Libre
5320kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 5321
cf4a9129
LC
5322@findex operating-system
5323@lisp
dd51caac 5324@include os-config-bare-bones.texi
cf4a9129 5325@end lisp
401c53c4 5326
cf4a9129
LC
5327This example should be self-describing. Some of the fields defined
5328above, such as @code{host-name} and @code{bootloader}, are mandatory.
5329Others, such as @code{packages} and @code{services}, can be omitted, in
5330which case they get a default value.
e7f34eb0 5331
cf4a9129
LC
5332@vindex %base-packages
5333The @code{packages} field lists
5334packages that will be globally visible on the system, for all user
5335accounts---i.e., in every user's @code{PATH} environment variable---in
5336addition to the per-user profiles (@pxref{Invoking guix package}). The
5337@var{%base-packages} variable provides all the tools one would expect
5338for basic user and administrator tasks---including the GNU Core
5339Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
5340editor, @command{find}, @command{grep}, etc. The example above adds
5341Emacs to those, taken from the @code{(gnu packages emacs)} module
5342(@pxref{Package Modules}).
e7f34eb0 5343
cf4a9129
LC
5344@vindex %base-services
5345The @code{services} field lists @dfn{system services} to be made
5346available when the system starts (@pxref{Services}).
5347The @code{operating-system} declaration above specifies that, in
5348addition to the basic services, we want the @command{lshd} secure shell
5349daemon listening on port 2222, and allowing remote @code{root} logins
5350(@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
5351@code{lsh-service} arranges so that @code{lshd} is started with the
5352right command-line options, possibly with supporting configuration files
7313a52e
LC
5353generated as needed (@pxref{Defining Services}). @xref{operating-system
5354Reference}, for details about the available @code{operating-system}
5355fields.
a1ba8475 5356
dd51caac
LC
5357The configuration for a typical ``desktop'' usage, with the X11 display
5358server, a desktop environment, network management, an SSH server, and
5359more, would look like this:
5360
5361@lisp
5362@include os-config-desktop.texi
5363@end lisp
5364
5365@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
5366@var{%desktop-services}. @xref{X.509 Certificates}, for background
5367information about the @code{nss-certs} package that is used here.
dd51caac 5368
cf4a9129
LC
5369Assuming the above snippet is stored in the @file{my-system-config.scm}
5370file, the @command{guix system reconfigure my-system-config.scm} command
5371instantiates that configuration, and makes it the default GRUB boot
5372entry (@pxref{Invoking guix system}). The normal way to change the
5373system's configuration is by updating this file and re-running the
5374@command{guix system} command.
b81e1947 5375
cf4a9129
LC
5376At the Scheme level, the bulk of an @code{operating-system} declaration
5377is instantiated with the following monadic procedure (@pxref{The Store
5378Monad}):
b81e1947 5379
cf4a9129
LC
5380@deffn {Monadic Procedure} operating-system-derivation os
5381Return a derivation that builds @var{os}, an @code{operating-system}
5382object (@pxref{Derivations}).
b81e1947 5383
cf4a9129
LC
5384The output of the derivation is a single directory that refers to all
5385the packages, configuration files, and other supporting files needed to
5386instantiate @var{os}.
5387@end deffn
b81e1947 5388
7313a52e
LC
5389@node operating-system Reference
5390@subsection @code{operating-system} Reference
5391
5392This section summarizes all the options available in
5393@code{operating-system} declarations (@pxref{Using the Configuration
5394System}).
5395
5396@deftp {Data Type} operating-system
5397This is the data type representing an operating system configuration.
5398By that, we mean all the global system configuration, not per-user
5399configuration (@pxref{Using the Configuration System}).
5400
5401@table @asis
5402@item @code{kernel} (default: @var{linux-libre})
fbb25e56 5403The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
5404only the Linux-libre kernel is supported. In the future, it will be
5405possible to use the GNU@tie{}Hurd.}.
5406
ee2a6304
LC
5407@item @code{kernel-arguments} (default: @code{'()})
5408List of strings or gexps representing additional arguments to pass on
5409the kernel's command-line---e.g., @code{("console=ttyS0")}.
5410
7313a52e 5411@item @code{bootloader}
88faf933 5412The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
5413
5414@item @code{initrd} (default: @code{base-initrd})
5415A two-argument monadic procedure that returns an initial RAM disk for
5416the Linux kernel. @xref{Initial RAM Disk}.
5417
f34c56be
LC
5418@item @code{firmware} (default: @var{%base-firmware})
5419@cindex firmware
5420List of firmware packages loadable by the operating system kernel.
5421
5422The default includes firmware needed for Atheros-based WiFi devices
5423(Linux-libre module @code{ath9k}.)
5424
7313a52e
LC
5425@item @code{host-name}
5426The host name.
5427
5428@item @code{hosts-file}
5429@cindex hosts file
24e02c28 5430A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 5431@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 5432Reference Manual}). The default is a file with entries for
7313a52e
LC
5433@code{localhost} and @var{host-name}.
5434
5435@item @code{mapped-devices} (default: @code{'()})
5436A list of mapped devices. @xref{Mapped Devices}.
5437
5438@item @code{file-systems}
5439A list of file systems. @xref{File Systems}.
5440
5441@item @code{swap-devices} (default: @code{'()})
5442@cindex swap devices
5443A list of strings identifying devices to be used for ``swap space''
5444(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
5445For example, @code{'("/dev/sda3")}.
5446
bf87f38a 5447@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
5448@itemx @code{groups} (default: @var{%base-groups})
5449List of user accounts and groups. @xref{User Accounts}.
5450
5451@item @code{skeletons} (default: @code{(default-skeletons)})
5452A monadic list of pairs of target file name and files. These are the
5453files that will be used as skeletons as new accounts are created.
5454
5455For instance, a valid value may look like this:
5456
5457@example
5458(mlet %store-monad ((bashrc (text-file "bashrc" "\
5459 export PATH=$HOME/.guix-profile/bin")))
5460 (return `((".bashrc" ,bashrc))))
5461@end example
5462
5463@item @code{issue} (default: @var{%default-issue})
5464A string denoting the contents of the @file{/etc/issue} file, which is
5465what displayed when users log in on a text console.
5466
5467@item @code{packages} (default: @var{%base-packages})
5468The set of packages installed in the global profile, which is accessible
5469at @file{/run/current-system/profile}.
5470
5471The default set includes core utilities, but it is good practice to
5472install non-core utilities in user profiles (@pxref{Invoking guix
5473package}).
5474
5475@item @code{timezone}
5476A timezone identifying string---e.g., @code{"Europe/Paris"}.
5477
598e19dc
LC
5478@item @code{locale} (default: @code{"en_US.utf8"})
5479The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
5480Library Reference Manual}). @xref{Locales}, for more information.
5481
5482@item @code{locale-definitions} (default: @var{%default-locale-definitions})
5483The list of locale definitions to be compiled and that may be used at
5484run time. @xref{Locales}.
7313a52e 5485
996ed739
LC
5486@item @code{name-service-switch} (default: @var{%default-nss})
5487Configuration of libc's name service switch (NSS)---a
5488@code{<name-service-switch>} object. @xref{Name Service Switch}, for
5489details.
5490
7313a52e
LC
5491@item @code{services} (default: @var{%base-services})
5492A list of monadic values denoting system services. @xref{Services}.
5493
5494@item @code{pam-services} (default: @code{(base-pam-services)})
5495@cindex PAM
5496@cindex pluggable authentication modules
5497Linux @dfn{pluggable authentication module} (PAM) services.
5498@c FIXME: Add xref to PAM services section.
5499
5500@item @code{setuid-programs} (default: @var{%setuid-programs})
5501List of string-valued G-expressions denoting setuid programs.
5502@xref{Setuid Programs}.
5503
f5a9ffa0
AK
5504@item @code{sudoers-file} (default: @var{%sudoers-specification})
5505@cindex sudoers file
84765839
LC
5506The contents of the @file{/etc/sudoers} file as a file-like object
5507(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
5508
5509This file specifies which users can use the @command{sudo} command, what
5510they are allowed to do, and what privileges they may gain. The default
5511is that only @code{root} and members of the @code{wheel} group may use
5512@code{sudo}.
5513
5514@end table
5515@end deftp
5516
cf4a9129
LC
5517@node File Systems
5518@subsection File Systems
b81e1947 5519
cf4a9129
LC
5520The list of file systems to be mounted is specified in the
5521@code{file-systems} field of the operating system's declaration
5522(@pxref{Using the Configuration System}). Each file system is declared
5523using the @code{file-system} form, like this:
b81e1947
LC
5524
5525@example
cf4a9129
LC
5526(file-system
5527 (mount-point "/home")
5528 (device "/dev/sda3")
5529 (type "ext4"))
b81e1947
LC
5530@end example
5531
cf4a9129
LC
5532As usual, some of the fields are mandatory---those shown in the example
5533above---while others can be omitted. These are described below.
b81e1947 5534
cf4a9129
LC
5535@deftp {Data Type} file-system
5536Objects of this type represent file systems to be mounted. They
5537contain the following members:
5ff3c4b8 5538
cf4a9129
LC
5539@table @asis
5540@item @code{type}
5541This is a string specifying the type of the file system---e.g.,
5542@code{"ext4"}.
5ff3c4b8 5543
cf4a9129
LC
5544@item @code{mount-point}
5545This designates the place where the file system is to be mounted.
b81e1947 5546
cf4a9129
LC
5547@item @code{device}
5548This names the ``source'' of the file system. By default it is the name
5549of a node under @file{/dev}, but its meaning depends on the @code{title}
5550field described below.
401c53c4 5551
cf4a9129
LC
5552@item @code{title} (default: @code{'device})
5553This is a symbol that specifies how the @code{device} field is to be
5554interpreted.
401c53c4 5555
cf4a9129
LC
5556When it is the symbol @code{device}, then the @code{device} field is
5557interpreted as a file name; when it is @code{label}, then @code{device}
5558is interpreted as a partition label name; when it is @code{uuid},
5559@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 5560
661a1d79
LC
5561UUIDs may be converted from their string representation (as shown by the
5562@command{tune2fs -l} command) using the @code{uuid} form, like this:
5563
5564@example
5565(file-system
5566 (mount-point "/home")
5567 (type "ext4")
5568 (title 'uuid)
5569 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
5570@end example
5571
cf4a9129 5572The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
5573partitions without having to hard-code their actual device
5574name@footnote{Note that, while it is tempting to use
5575@file{/dev/disk/by-uuid} and similar device names to achieve the same
5576result, this is not recommended: These special device nodes are created
5577by the udev daemon and may be unavailable at the time the device is
5578mounted.}.
da7cabd4 5579
5f86a66e
LC
5580However, when a file system's source is a mapped device (@pxref{Mapped
5581Devices}), its @code{device} field @emph{must} refer to the mapped
5582device name---e.g., @file{/dev/mapper/root-partition}---and consequently
5583@code{title} must be set to @code{'device}. This is required so that
5584the system knows that mounting the file system depends on having the
5585corresponding device mapping established.
5586
cf4a9129
LC
5587@item @code{flags} (default: @code{'()})
5588This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
5589include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
5590access to special files), @code{no-suid} (ignore setuid and setgid
5591bits), and @code{no-exec} (disallow program execution.)
da7cabd4 5592
cf4a9129
LC
5593@item @code{options} (default: @code{#f})
5594This is either @code{#f}, or a string denoting mount options.
da7cabd4 5595
cf4a9129
LC
5596@item @code{needed-for-boot?} (default: @code{#f})
5597This Boolean value indicates whether the file system is needed when
5598booting. If that is true, then the file system is mounted when the
5599initial RAM disk (initrd) is loaded. This is always the case, for
5600instance, for the root file system.
da7cabd4 5601
cf4a9129
LC
5602@item @code{check?} (default: @code{#t})
5603This Boolean indicates whether the file system needs to be checked for
5604errors before being mounted.
f9cc8971 5605
4e469051
LC
5606@item @code{create-mount-point?} (default: @code{#f})
5607When true, the mount point is created if it does not exist yet.
5608
e51710d1
LC
5609@item @code{dependencies} (default: @code{'()})
5610This is a list of @code{<file-system>} objects representing file systems
5611that must be mounted before (and unmounted after) this one.
5612
5613As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
5614a dependency of @file{/sys/fs/cgroup/cpu} and
5615@file{/sys/fs/cgroup/memory}.
5616
cf4a9129
LC
5617@end table
5618@end deftp
da7cabd4 5619
a69576ea
LC
5620The @code{(gnu system file-systems)} exports the following useful
5621variables.
5622
5623@defvr {Scheme Variable} %base-file-systems
5624These are essential file systems that are required on normal systems,
cc0e575a 5625such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
5626below.) Operating system declarations should always contain at least
5627these.
a69576ea
LC
5628@end defvr
5629
7f239fd3
LC
5630@defvr {Scheme Variable} %pseudo-terminal-file-system
5631This is the file system to be mounted as @file{/dev/pts}. It supports
5632@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
5633functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
5634Manual}). Pseudo-terminals are used by terminal emulators such as
5635@command{xterm}.
5636@end defvr
5637
db17ae5c
LC
5638@defvr {Scheme Variable} %shared-memory-file-system
5639This file system is mounted as @file{/dev/shm} and is used to support
5640memory sharing across processes (@pxref{Memory-mapped I/O,
5641@code{shm_open},, libc, The GNU C Library Reference Manual}).
5642@end defvr
5643
3392ce5d
LC
5644@defvr {Scheme Variable} %immutable-store
5645This file system performs a read-only ``bind mount'' of
5646@file{/gnu/store}, making it read-only for all the users including
5647@code{root}. This prevents against accidental modification by software
5648running as @code{root} or by system administrators.
5649
5650The daemon itself is still able to write to the store: it remounts it
5651read-write in its own ``name space.''
5652@end defvr
5653
a69576ea
LC
5654@defvr {Scheme Variable} %binary-format-file-system
5655The @code{binfmt_misc} file system, which allows handling of arbitrary
5656executable file types to be delegated to user space. This requires the
5657@code{binfmt.ko} kernel module to be loaded.
5658@end defvr
5659
5660@defvr {Scheme Variable} %fuse-control-file-system
5661The @code{fusectl} file system, which allows unprivileged users to mount
5662and unmount user-space FUSE file systems. This requires the
5663@code{fuse.ko} kernel module to be loaded.
5664@end defvr
5665
510f9d86
LC
5666@node Mapped Devices
5667@subsection Mapped Devices
5668
5669@cindex device mapping
5670@cindex mapped devices
5671The Linux kernel has a notion of @dfn{device mapping}: a block device,
5672such as a hard disk partition, can be @dfn{mapped} into another device,
5673with additional processing over the data that flows through
5674it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
5675concept of a ``mapped device'' and that of a file system: both boil down
5676to @emph{translating} input/output operations made on a file to
5677operations on its backing store. Thus, the Hurd implements mapped
5678devices, like file systems, using the generic @dfn{translator} mechanism
5679(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
5680typical example is encryption device mapping: all writes to the mapped
5681device are encrypted, and all reads are deciphered, transparently.
5682
5683Mapped devices are declared using the @code{mapped-device} form:
5684
5685@example
5686(mapped-device
5687 (source "/dev/sda3")
5688 (target "home")
5689 (type luks-device-mapping))
5690@end example
5691
5692@noindent
5693@cindex disk encryption
5694@cindex LUKS
5695This example specifies a mapping from @file{/dev/sda3} to
5696@file{/dev/mapper/home} using LUKS---the
5697@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
5698standard mechanism for disk encryption. The @file{/dev/mapper/home}
5699device can then be used as the @code{device} of a @code{file-system}
5700declaration (@pxref{File Systems}). The @code{mapped-device} form is
5701detailed below.
5702
5703@deftp {Data Type} mapped-device
5704Objects of this type represent device mappings that will be made when
5705the system boots up.
5706
9cb426b8
LC
5707@table @code
5708@item source
510f9d86
LC
5709This string specifies the name of the block device to be mapped, such as
5710@code{"/dev/sda3"}.
5711
9cb426b8 5712@item target
510f9d86
LC
5713This string specifies the name of the mapping to be established. For
5714example, specifying @code{"my-partition"} will lead to the creation of
5715the @code{"/dev/mapper/my-partition"} device.
5716
9cb426b8 5717@item type
510f9d86
LC
5718This must be a @code{mapped-device-kind} object, which specifies how
5719@var{source} is mapped to @var{target}.
5720@end table
5721@end deftp
5722
5723@defvr {Scheme Variable} luks-device-mapping
5724This defines LUKS block device encryption using the @command{cryptsetup}
5725command, from the same-named package. This relies on the
5726@code{dm-crypt} Linux kernel module.
5727@end defvr
5728
cf4a9129
LC
5729@node User Accounts
5730@subsection User Accounts
ee85f3db 5731
9bea87a5
LC
5732User accounts and groups are entirely managed through the
5733@code{operating-system} declaration. They are specified with the
5734@code{user-account} and @code{user-group} forms:
ee85f3db 5735
cf4a9129
LC
5736@example
5737(user-account
5738 (name "alice")
5739 (group "users")
24e752c0
LC
5740 (supplementary-groups '("wheel" ;allow use of sudo, etc.
5741 "audio" ;sound card
5742 "video" ;video devices such as webcams
5743 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
5744 (comment "Bob's sister")
5745 (home-directory "/home/alice"))
5746@end example
25083588 5747
9bea87a5
LC
5748When booting or upon completion of @command{guix system reconfigure},
5749the system ensures that only the user accounts and groups specified in
5750the @code{operating-system} declaration exist, and with the specified
5751properties. Thus, account or group creations or modifications made by
5752directly invoking commands such as @command{useradd} are lost upon
5753reconfiguration or reboot. This ensures that the system remains exactly
5754as declared.
5755
cf4a9129
LC
5756@deftp {Data Type} user-account
5757Objects of this type represent user accounts. The following members may
5758be specified:
ee85f3db 5759
cf4a9129
LC
5760@table @asis
5761@item @code{name}
5762The name of the user account.
ee85f3db 5763
cf4a9129
LC
5764@item @code{group}
5765This is the name (a string) or identifier (a number) of the user group
5766this account belongs to.
ee85f3db 5767
cf4a9129
LC
5768@item @code{supplementary-groups} (default: @code{'()})
5769Optionally, this can be defined as a list of group names that this
5770account belongs to.
ee85f3db 5771
cf4a9129
LC
5772@item @code{uid} (default: @code{#f})
5773This is the user ID for this account (a number), or @code{#f}. In the
5774latter case, a number is automatically chosen by the system when the
5775account is created.
ee85f3db 5776
cf4a9129
LC
5777@item @code{comment} (default: @code{""})
5778A comment about the account, such as the account's owner full name.
c8c871d1 5779
cf4a9129
LC
5780@item @code{home-directory}
5781This is the name of the home directory for the account.
ee85f3db 5782
cf4a9129
LC
5783@item @code{shell} (default: Bash)
5784This is a G-expression denoting the file name of a program to be used as
5785the shell (@pxref{G-Expressions}).
ee85f3db 5786
cf4a9129
LC
5787@item @code{system?} (default: @code{#f})
5788This Boolean value indicates whether the account is a ``system''
5789account. System accounts are sometimes treated specially; for instance,
5790graphical login managers do not list them.
ee85f3db 5791
1bd4e6db 5792@anchor{user-account-password}
cf4a9129 5793@item @code{password} (default: @code{#f})
eb59595c
LC
5794You would normally leave this field to @code{#f}, initialize user
5795passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
5796users change it with @command{passwd}. Passwords set with
5797@command{passwd} are of course preserved across reboot and
5798reconfiguration.
eb59595c
LC
5799
5800If you @emph{do} want to have a preset password for an account, then
5801this field must contain the encrypted password, as a string.
5d1f1177
LC
5802@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
5803on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 5804Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 5805
cf4a9129
LC
5806@end table
5807@end deftp
ee85f3db 5808
cf4a9129 5809User group declarations are even simpler:
ee85f3db 5810
cf4a9129
LC
5811@example
5812(user-group (name "students"))
5813@end example
ee85f3db 5814
cf4a9129
LC
5815@deftp {Data Type} user-group
5816This type is for, well, user groups. There are just a few fields:
af8a56b8 5817
cf4a9129
LC
5818@table @asis
5819@item @code{name}
5820The group's name.
ee85f3db 5821
cf4a9129
LC
5822@item @code{id} (default: @code{#f})
5823The group identifier (a number). If @code{#f}, a new number is
5824automatically allocated when the group is created.
ee85f3db 5825
c8fa3426
LC
5826@item @code{system?} (default: @code{#f})
5827This Boolean value indicates whether the group is a ``system'' group.
5828System groups have low numerical IDs.
5829
cf4a9129
LC
5830@item @code{password} (default: @code{#f})
5831What, user groups can have a password? Well, apparently yes. Unless
5832@code{#f}, this field specifies the group's password.
ee85f3db 5833
cf4a9129
LC
5834@end table
5835@end deftp
401c53c4 5836
cf4a9129
LC
5837For convenience, a variable lists all the basic user groups one may
5838expect:
401c53c4 5839
cf4a9129
LC
5840@defvr {Scheme Variable} %base-groups
5841This is the list of basic user groups that users and/or packages expect
5842to be present on the system. This includes groups such as ``root'',
5843``wheel'', and ``users'', as well as groups used to control access to
5844specific devices such as ``audio'', ``disk'', and ``cdrom''.
5845@end defvr
401c53c4 5846
bf87f38a
LC
5847@defvr {Scheme Variable} %base-user-accounts
5848This is the list of basic system accounts that programs may expect to
5849find on a GNU/Linux system, such as the ``nobody'' account.
5850
5851Note that the ``root'' account is not included here. It is a
5852special-case and is automatically added whether or not it is specified.
5853@end defvr
5854
598e19dc
LC
5855@node Locales
5856@subsection Locales
5857
5858@cindex locale
5859A @dfn{locale} defines cultural conventions for a particular language
5860and region of the world (@pxref{Locales,,, libc, The GNU C Library
5861Reference Manual}). Each locale has a name that typically has the form
b2636518 5862@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
5863@code{fr_LU.utf8} designates the locale for the French language, with
5864cultural conventions from Luxembourg, and using the UTF-8 encoding.
5865
5866@cindex locale definition
5867Usually, you will want to specify the default locale for the machine
5868using the @code{locale} field of the @code{operating-system} declaration
5869(@pxref{operating-system Reference, @code{locale}}).
5870
5871That locale must be among the @dfn{locale definitions} that are known to
5872the system---and these are specified in the @code{locale-definitions}
5873slot of @code{operating-system}. The default value includes locale
5874definition for some widely used locales, but not for all the available
5875locales, in order to save space.
5876
5877If the locale specified in the @code{locale} field is not among the
5878definitions listed in @code{locale-definitions}, @command{guix system}
5879raises an error. In that case, you should add the locale definition to
5880the @code{locale-definitions} field. For instance, to add the North
5881Frisian locale for Germany, the value of that field may be:
5882
5883@example
5884(cons (locale-definition
5885 (name "fy_DE.utf8") (source "fy_DE"))
5886 %default-locale-definitions)
5887@end example
5888
5889Likewise, to save space, one might want @code{locale-definitions} to
5890list only the locales that are actually used, as in:
5891
5892@example
5893(list (locale-definition
5894 (name "ja_JP.eucjp") (source "ja_JP")
5895 (charset "EUC-JP")))
5896@end example
5897
5c3c1427
LC
5898@vindex LOCPATH
5899The compiled locale definitions are available at
46bd6edd
LC
5900@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
5901version, which is the default location where the GNU@tie{}libc provided
5902by Guix looks for locale data. This can be overridden using the
5903@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
5904@code{LOCPATH} and locale packages}).
5905
598e19dc
LC
5906The @code{locale-definition} form is provided by the @code{(gnu system
5907locale)} module. Details are given below.
5908
5909@deftp {Data Type} locale-definition
5910This is the data type of a locale definition.
5911
5912@table @asis
5913
5914@item @code{name}
5915The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
5916Reference Manual}, for more information on locale names.
5917
5918@item @code{source}
5919The name of the source for that locale. This is typically the
5920@code{@var{language}_@var{territory}} part of the locale name.
5921
5922@item @code{charset} (default: @code{"UTF-8"})
5923The ``character set'' or ``code set'' for that locale,
5924@uref{http://www.iana.org/assignments/character-sets, as defined by
5925IANA}.
5926
5927@end table
5928@end deftp
5929
5930@defvr {Scheme Variable} %default-locale-definitions
b2636518
LC
5931An arbitrary list of commonly used UTF-8 locales, used as the default
5932value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 5933declarations.
b2636518
LC
5934
5935@cindex locale name
5936@cindex normalized codeset in locale names
5937These locale definitions use the @dfn{normalized codeset} for the part
5938that follows the dot in the name (@pxref{Using gettextized software,
5939normalized codeset,, libc, The GNU C Library Reference Manual}). So for
5940instance it has @code{uk_UA.utf8} but @emph{not}, say,
5941@code{uk_UA.UTF-8}.
598e19dc 5942@end defvr
401c53c4 5943
cf4a9129
LC
5944@node Services
5945@subsection Services
401c53c4 5946
cf4a9129
LC
5947@cindex system services
5948An important part of preparing an @code{operating-system} declaration is
5949listing @dfn{system services} and their configuration (@pxref{Using the
5950Configuration System}). System services are typically daemons launched
5951when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
5952configuring network access.
5953
5954Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU
5955dmd Manual}). On a running system, the @command{deco} command allows
5956you to list the available services, show their status, start and stop
5957them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd
5958Manual}). For example:
5959
5960@example
5961# deco status dmd
5962@end example
5963
5964The above command, run as @code{root}, lists the currently defined
5965services. The @command{deco doc} command shows a synopsis of the given
5966service:
5967
5968@example
5969# deco doc nscd
5970Run libc's name service cache daemon (nscd).
5971@end example
5972
5973The @command{start}, @command{stop}, and @command{restart} sub-commands
5974have the effect you would expect. For instance, the commands below stop
5975the nscd service and restart the Xorg display server:
5976
5977@example
5978# deco stop nscd
5979Service nscd has been stopped.
5980# deco restart xorg-server
5981Service xorg-server has been stopped.
5982Service xorg-server has been started.
5983@end example
401c53c4 5984
cf4a9129 5985The following sections document the available services, starting with
d8b94dbd
LC
5986the core services, that may be used in an @code{operating-system}
5987declaration.
401c53c4 5988
cf4a9129
LC
5989@menu
5990* Base Services:: Essential system services.
5991* Networking Services:: Network setup, SSH daemon, etc.
5992* X Window:: Graphical display.
fe1a39d3 5993* Desktop Services:: D-Bus and desktop services.
105369a4 5994* Database Services:: SQL databases.
58724c48 5995* Web Services:: Web servers.
aa4ed923 5996* Various Services:: Other services.
cf4a9129 5997@end menu
401c53c4 5998
cf4a9129
LC
5999@node Base Services
6000@subsubsection Base Services
a1ba8475 6001
cf4a9129
LC
6002The @code{(gnu services base)} module provides definitions for the basic
6003services that one expects from the system. The services exported by
6004this module are listed below.
401c53c4 6005
cf4a9129
LC
6006@defvr {Scheme Variable} %base-services
6007This variable contains a list of basic services@footnote{Technically,
6008this is a list of monadic services. @xref{The Store Monad}.} one would
6009expect from the system: a login service (mingetty) on each tty, syslogd,
6010libc's name service cache daemon (nscd), the udev device manager, and
6011more.
401c53c4 6012
cf4a9129
LC
6013This is the default value of the @code{services} field of
6014@code{operating-system} declarations. Usually, when customizing a
6015system, you will want to append services to @var{%base-services}, like
6016this:
401c53c4 6017
cf4a9129 6018@example
fa1e31b8 6019(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
6020@end example
6021@end defvr
401c53c4 6022
be1c2c54 6023@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
6024Return a service that sets the host name to @var{name}.
6025@end deffn
401c53c4 6026
66e4f01c
LC
6027@deffn {Scheme Procedure} mingetty-service @var{config}
6028Return a service to run mingetty according to @var{config}, a
6029@code{<mingetty-configuration>} object, which specifies the tty to run, among
6030other things.
cf4a9129 6031@end deffn
401c53c4 6032
66e4f01c
LC
6033@deftp {Data Type} mingetty-configuration
6034This is the data type representing the configuration of Mingetty, which
6035implements console log-in.
6036
6037@table @asis
6038
6039@item @code{tty}
6040The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6041
6042@item @code{motd}
6043A file-like object containing the ``message of the day''.
6044
6045@item @code{auto-login} (default: @code{#f})
6046When true, this field must be a string denoting the user name under
6047which the the system automatically logs in. When it is @code{#f}, a
6048user name and password must be entered to log in.
6049
6050@item @code{login-program} (default: @code{#f})
6051This must be either @code{#f}, in which case the default log-in program
6052is used (@command{login} from the Shadow tool suite), or a gexp denoting
6053the name of the log-in program.
6054
6055@item @code{login-pause?} (default: @code{#f})
6056When set to @code{#t} in conjunction with @var{auto-login}, the user
6057will have to press a key before the log-in shell is launched.
6058
6059@item @code{mingetty} (default: @var{mingetty})
6060The Mingetty package to use.
6061
6062@end table
6063@end deftp
6064
6454b333
LC
6065@cindex name service cache daemon
6066@cindex nscd
be1c2c54 6067@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 6068 [#:name-services '()]
b893f1ae
LC
6069Return a service that runs libc's name service cache daemon (nscd) with the
6070given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6071Service Switch}, for an example.
cf4a9129 6072@end deffn
401c53c4 6073
6454b333
LC
6074@defvr {Scheme Variable} %nscd-default-configuration
6075This is the default @code{<nscd-configuration>} value (see below) used
6076by @code{nscd-service}. This uses the caches defined by
6077@var{%nscd-default-caches}; see below.
6078@end defvr
6079
6080@deftp {Data Type} nscd-configuration
6081This is the type representing the name service cache daemon (nscd)
6082configuration.
6083
6084@table @asis
6085
b893f1ae
LC
6086@item @code{name-services} (default: @code{'()})
6087List of packages denoting @dfn{name services} that must be visible to
6088the nscd---e.g., @code{(list @var{nss-mdns})}.
6089
6090@item @code{glibc} (default: @var{glibc})
6091Package object denoting the GNU C Library providing the @command{nscd}
6092command.
6093
6454b333
LC
6094@item @code{log-file} (default: @code{"/var/log/nscd.log"})
6095Name of nscd's log file. This is where debugging output goes when
6096@code{debug-level} is strictly positive.
6097
6098@item @code{debug-level} (default: @code{0})
6099Integer denoting the debugging levels. Higher numbers mean more
6100debugging output is logged.
6101
6102@item @code{caches} (default: @var{%nscd-default-caches})
6103List of @code{<nscd-cache>} objects denoting things to be cached; see
6104below.
6105
6106@end table
6107@end deftp
6108
6109@deftp {Data Type} nscd-cache
6110Data type representing a cache database of nscd and its parameters.
6111
6112@table @asis
6113
6114@item @code{database}
6115This is a symbol representing the name of the database to be cached.
6116Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6117@code{services}, which designate the corresponding NSS database
6118(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6119
6120@item @code{positive-time-to-live}
6121@itemx @code{negative-time-to-live} (default: @code{20})
6122A number representing the number of seconds during which a positive or
6123negative lookup result remains in cache.
6124
6125@item @code{check-files?} (default: @code{#t})
6126Whether to check for updates of the files corresponding to
6127@var{database}.
6128
6129For instance, when @var{database} is @code{hosts}, setting this flag
6130instructs nscd to check for updates in @file{/etc/hosts} and to take
6131them into account.
6132
6133@item @code{persistent?} (default: @code{#t})
6134Whether the cache should be stored persistently on disk.
6135
6136@item @code{shared?} (default: @code{#t})
6137Whether the cache should be shared among users.
6138
6139@item @code{max-database-size} (default: 32@tie{}MiB)
6140Maximum size in bytes of the database cache.
6141
6142@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6143@c settings, so leave them out.
6144
6145@end table
6146@end deftp
6147
6148@defvr {Scheme Variable} %nscd-default-caches
6149List of @code{<nscd-cache>} objects used by default by
6150@code{nscd-configuration} (see above.)
6151
6152It enables persistent and aggressive caching of service and host name
6153lookups. The latter provides better host name lookup performance,
6154resilience in the face of unreliable name servers, and also better
6155privacy---often the result of host name lookups is in local cache, so
6156external name servers do not even need to be queried.
6157@end defvr
6158
6159
be1c2c54 6160@deffn {Scheme Procedure} syslog-service [#:config-file #f]
1bb76f75
AK
6161Return a service that runs @code{syslogd}. If configuration file name
6162@var{config-file} is not specified, use some reasonable default
cf4a9129
LC
6163settings.
6164@end deffn
401c53c4 6165
0adfe95a
LC
6166@anchor{guix-configuration-type}
6167@deftp {Data Type} guix-configuration
6168This data type represents the configuration of the Guix build daemon.
6169@xref{Invoking guix-daemon}, for more information.
6170
6171@table @asis
6172@item @code{guix} (default: @var{guix})
6173The Guix package to use.
401c53c4 6174
0adfe95a
LC
6175@item @code{build-group} (default: @code{"guixbuild"})
6176Name of the group for build user accounts.
401c53c4 6177
0adfe95a
LC
6178@item @code{build-accounts} (default: @code{10})
6179Number of build user accounts to create.
401c53c4 6180
0adfe95a
LC
6181@item @code{authorize-key?} (default: @code{#t})
6182Whether to authorize the substitute key for @code{hydra.gnu.org}
6183(@pxref{Substitutes}).
6184
6185@item @code{use-substitutes?} (default: @code{#t})
6186Whether to use substitutes.
6187
6188@item @code{extra-options} (default: @code{'()})
6189List of extra command-line options for @command{guix-daemon}.
6190
6191@item @code{lsof} (default: @var{lsof})
6192@itemx @code{lsh} (default: @var{lsh})
6193The lsof and lsh packages to use.
6194
6195@end table
6196@end deftp
6197
6198@deffn {Scheme Procedure} guix-service @var{config}
6199Return a service that runs the Guix build daemon according to
6200@var{config}.
cf4a9129 6201@end deffn
a1ba8475 6202
be1c2c54 6203@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
6204Run @var{udev}, which populates the @file{/dev} directory dynamically.
6205@end deffn
401c53c4 6206
be1c2c54 6207@deffn {Scheme Procedure} console-keymap-service @var{file}
5eca9459
AK
6208Return a service to load console keymap from @var{file} using
6209@command{loadkeys} command.
6210@end deffn
6211
a69576ea 6212
cf4a9129
LC
6213@node Networking Services
6214@subsubsection Networking Services
401c53c4 6215
fa1e31b8 6216The @code{(gnu services networking)} module provides services to configure
cf4a9129 6217the network interface.
a1ba8475 6218
a023cca8 6219@cindex DHCP, networking service
be1c2c54 6220@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
6221Return a service that runs @var{dhcp}, a Dynamic Host Configuration
6222Protocol (DHCP) client, on all the non-loopback network interfaces.
6223@end deffn
6224
be1c2c54 6225@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
6226 [#:gateway #f] [#:name-services @code{'()}]
6227Return a service that starts @var{interface} with address @var{ip}. If
6228@var{gateway} is true, it must be a string specifying the default network
6229gateway.
6230@end deffn
8b315a6d 6231
b7d0c494 6232@cindex wicd
be1c2c54 6233@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
b7d0c494
MW
6234Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a
6235network manager that aims to simplify wired and wireless networking.
6236@end deffn
6237
be1c2c54 6238@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
6239 [#:name-service @var{%ntp-servers}]
6240Return a service that runs the daemon from @var{ntp}, the
6241@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
6242keep the system clock synchronized with that of @var{servers}.
6243@end deffn
6244
6245@defvr {Scheme Variable} %ntp-servers
6246List of host names used as the default NTP servers.
6247@end defvr
6248
be1c2c54 6249@deffn {Scheme Procedure} tor-service [#:tor tor]
cf4a9129 6250Return a service to run the @uref{https://torproject.org,Tor} daemon.
8b315a6d 6251
cf4a9129
LC
6252The daemon runs with the default settings (in particular the default exit
6253policy) as the @code{tor} unprivileged user.
6254@end deffn
8b315a6d 6255
be1c2c54 6256@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
6257 [#:interface "127.0.0.1"] [#:port 6667] @
6258 [#:extra-settings ""]
6259Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
6260acts as a gateway between IRC and chat networks.
6261
6262The daemon will listen to the interface corresponding to the IP address
6263specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
6264local clients can connect, whereas @code{0.0.0.0} means that connections can
6265come from any networking interface.
6266
6267In addition, @var{extra-settings} specifies a string to append to the
6268configuration file.
6269@end deffn
6270
f4391bec 6271Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 6272
be1c2c54 6273@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 6274 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
6275 [#:allow-empty-passwords? #f] [#:root-login? #f] @
6276 [#:syslog-output? #t] [#:x11-forwarding? #t] @
6277 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 6278 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
6279Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
6280@var{host-key} must designate a file containing the host key, and readable
6281only by root.
72e25e35 6282
5833bf33
DP
6283When @var{daemonic?} is true, @command{lshd} will detach from the
6284controlling terminal and log its output to syslogd, unless one sets
6285@var{syslog-output?} to false. Obviously, it also makes lsh-service
6286depend on existence of syslogd service. When @var{pid-file?} is true,
6287@command{lshd} writes its PID to the file called @var{pid-file}.
6288
cf4a9129
LC
6289When @var{initialize?} is true, automatically create the seed and host key
6290upon service activation if they do not exist yet. This may take long and
6291require interaction.
8b315a6d 6292
20dd519c
LC
6293When @var{initialize?} is false, it is up to the user to initialize the
6294randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
6295a key pair with the private key stored in file @var{host-key} (@pxref{lshd
6296basics,,, lsh, LSH Manual}).
6297
cf4a9129
LC
6298When @var{interfaces} is empty, lshd listens for connections on all the
6299network interfaces; otherwise, @var{interfaces} must be a list of host names
6300or addresses.
9bf3c1a7 6301
20dd519c
LC
6302@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
6303passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 6304root.
4af2447e 6305
cf4a9129
LC
6306The other options should be self-descriptive.
6307@end deffn
4af2447e 6308
fa0c1d61
LC
6309@defvr {Scheme Variable} %facebook-host-aliases
6310This variable contains a string for use in @file{/etc/hosts}
6311(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
6312line contains a entry that maps a known server name of the Facebook
6313on-line service---e.g., @code{www.facebook.com}---to the local
6314host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
6315
6316This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
6317@code{operating-system} declaration (@pxref{operating-system Reference,
6318@file{/etc/hosts}}):
fa0c1d61
LC
6319
6320@example
6321(use-modules (gnu) (guix))
6322
6323(operating-system
6324 (host-name "mymachine")
6325 ;; ...
6326 (hosts-file
6327 ;; Create a /etc/hosts file with aliases for "localhost"
6328 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
6329 (plain-file "hosts"
6330 (string-append (local-host-aliases host-name)
6331 %facebook-host-aliases))))
fa0c1d61
LC
6332@end example
6333
6334This mechanism can prevent programs running locally, such as Web
6335browsers, from accessing Facebook.
6336@end defvr
6337
965a7332
LC
6338The @code{(gnu services avahi)} provides the following definition.
6339
be1c2c54 6340@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
6341 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
6342 [#:ipv6? #t] [#:wide-area? #f] @
6343 [#:domains-to-browse '()]
6344Return a service that runs @command{avahi-daemon}, a system-wide
6345mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
6346"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
6347extends the name service cache daemon (nscd) so that it can resolve
6348@code{.local} host names using
6349@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}.
965a7332
LC
6350
6351If @var{host-name} is different from @code{#f}, use that as the host name to
6352publish for this machine; otherwise, use the machine's actual host name.
6353
6354When @var{publish?} is true, publishing of host names and services is allowed;
6355in particular, avahi-daemon will publish the machine's host name and IP
6356address via mDNS on the local network.
6357
6358When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
6359
6360Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
6361sockets.
6362@end deffn
6363
6364
cf4a9129
LC
6365@node X Window
6366@subsubsection X Window
68ad877c 6367
cf4a9129
LC
6368Support for the X Window graphical display system---specifically
6369Xorg---is provided by the @code{(gnu services xorg)} module. Note that
6370there is no @code{xorg-service} procedure. Instead, the X server is
6371started by the @dfn{login manager}, currently SLiM.
4af2447e 6372
be1c2c54 6373@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
6374 [#:auto-login? #f] [#:default-user ""] [#:startx] @
6375 [#:theme @var{%default-slim-theme}] @
4bd43bbe 6376 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
6377Return a service that spawns the SLiM graphical login manager, which in
6378turn starts the X display server with @var{startx}, a command as returned by
6379@code{xorg-start-command}.
4af2447e 6380
04e4e6ab
LC
6381@cindex X session
6382
6383SLiM automatically looks for session types described by the @file{.desktop}
6384files in @file{/run/current-system/profile/share/xsessions} and allows users
6385to choose a session from the log-in screen using @kbd{F1}. Packages such as
6386@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
6387adding them to the system-wide set of packages automatically makes them
6388available at the log-in screen.
6389
6390In addition, @file{~/.xsession} files are honored. When available,
6391@file{~/.xsession} must be an executable that starts a window manager
6392and/or other X clients.
6393
cf4a9129
LC
6394When @var{allow-empty-passwords?} is true, allow logins with an empty
6395password. When @var{auto-login?} is true, log in automatically as
6396@var{default-user}.
0ecc3bf3
LC
6397
6398If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
6399@var{theme} must be a gexp denoting the name of a directory containing the
6400theme to use. In that case, @var{theme-name} specifies the name of the
6401theme.
cf4a9129 6402@end deffn
4af2447e 6403
0ecc3bf3
LC
6404@defvr {Scheme Variable} %default-theme
6405@defvrx {Scheme Variable} %default-theme-name
6406The G-Expression denoting the default SLiM theme and its name.
6407@end defvr
6408
be1c2c54 6409@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 6410 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 6411Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
6412from @var{xorg-server}. @var{configuration-file} is the server configuration
6413file or a derivation that builds it; when omitted, the result of
6414@code{xorg-configuration-file} is used.
6415
6416Usually the X server is started by a login manager.
6417@end deffn
6418
be1c2c54 6419@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 6420 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
6421Return a configuration file for the Xorg server containing search paths for
6422all the common drivers.
f703413e
LC
6423
6424@var{drivers} must be either the empty list, in which case Xorg chooses a
6425graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 6426this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
6427
6428Likewise, when @var{resolutions} is the empty list, Xorg chooses an
6429appropriate screen resolution; otherwise, it must be a list of
6430resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
6431
6432Last, @var{extra-config} is a list of strings or objects appended to the
6433@code{text-file*} argument list. It is used to pass extra text to be added
6434verbatim to the configuration file.
f703413e 6435@end deffn
4af2447e 6436
fe1a39d3
LC
6437@node Desktop Services
6438@subsubsection Desktop Services
aa4ed923 6439
fe1a39d3
LC
6440The @code{(gnu services desktop)} module provides services that are
6441usually useful in the context of a ``desktop'' setup---that is, on a
6442machine running a graphical display server, possibly with graphical user
6443interfaces, etc.
aa4ed923 6444
4467be21
LC
6445To simplify things, the module defines a variable containing the set of
6446services that users typically expect on a machine with a graphical
6447environment and networking:
6448
6449@defvr {Scheme Variable} %desktop-services
6450This is a list of services that builds upon @var{%base-services} and
6451adds or adjust services for a typical ``desktop'' setup.
6452
6453In particular, it adds a graphical login manager (@pxref{X Window,
6454@code{slim-service}}), a network management tool (@pxref{Networking
6455Services, @code{wicd-service}}), energy and color management services,
4650a77e 6456the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
6457the GeoClue location service, an NTP client (@pxref{Networking
6458Services}), the Avahi daemon, and has the name service switch service
6459configured to be able to use @code{nss-mdns} (@pxref{Name Service
6460Switch, mDNS}).
4467be21
LC
6461@end defvr
6462
6463The @var{%desktop-services} variable can be used as the @code{services}
6464field of an @code{operating-system} declaration (@pxref{operating-system
6465Reference, @code{services}}).
6466
0adfe95a
LC
6467The actual service definitions provided by @code{(gnu services dbus)}
6468and @code{(gnu services desktop)} are described below.
4467be21 6469
0adfe95a 6470@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
6471Return a service that runs the ``system bus'', using @var{dbus}, with
6472support for @var{services}.
aa4ed923 6473
fe1a39d3
LC
6474@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
6475facility. Its system bus is used to allow system services to communicate
6476and be notified of system-wide events.
aa4ed923 6477
fe1a39d3
LC
6478@var{services} must be a list of packages that provide an
6479@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
6480and policy files. For example, to allow avahi-daemon to use the system bus,
6481@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
6482@end deffn
6483
0adfe95a 6484@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
6485Return a service that runs the @code{elogind} login and
6486seat management daemon. @uref{https://github.com/andywingo/elogind,
6487Elogind} exposes a D-Bus interface that can be used to know which users
6488are logged in, know what kind of sessions they have open, suspend the
6489system, inhibit system suspend, reboot the system, and other tasks.
6490
6491Elogind handles most system-level power events for a computer, for
6492example suspending the system when a lid is closed, or shutting it down
6493when the power button is pressed.
6494
6495The @var{config} keyword argument specifies the configuration for
6496elogind, and should be the result of a @code{(elogind-configuration
6497(@var{parameter} @var{value})...)} invocation. Available parameters and
6498their default values are:
6499
6500@table @code
6501@item kill-user-processes?
6502@code{#f}
6503@item kill-only-users
6504@code{()}
6505@item kill-exclude-users
6506@code{("root")}
6507@item inhibit-delay-max-seconds
6508@code{5}
6509@item handle-power-key
6510@code{poweroff}
6511@item handle-suspend-key
6512@code{suspend}
6513@item handle-hibernate-key
6514@code{hibernate}
6515@item handle-lid-switch
6516@code{suspend}
6517@item handle-lid-switch-docked
6518@code{ignore}
6519@item power-key-ignore-inhibited?
6520@code{#f}
6521@item suspend-key-ignore-inhibited?
6522@code{#f}
6523@item hibernate-key-ignore-inhibited?
6524@code{#f}
6525@item lid-switch-ignore-inhibited?
6526@code{#t}
6527@item holdoff-timeout-seconds
6528@code{30}
6529@item idle-action
6530@code{ignore}
6531@item idle-action-seconds
6532@code{(* 30 60)}
6533@item runtime-directory-size-percent
6534@code{10}
6535@item runtime-directory-size
6536@code{#f}
6537@item remove-ipc?
6538@code{#t}
6539@item suspend-state
6540@code{("mem" "standby" "freeze")}
6541@item suspend-mode
6542@code{()}
6543@item hibernate-state
6544@code{("disk")}
6545@item hibernate-mode
6546@code{("platform" "shutdown")}
6547@item hybrid-sleep-state
6548@code{("disk")}
6549@item hybrid-sleep-mode
6550@code{("suspend" "platform" "shutdown")}
6551@end table
6552@end deffn
6553
be1c2c54 6554@deffn {Scheme Procedure} polkit-service @
4650a77e
AW
6555 [#:polkit @var{polkit}]
6556Return a service that runs the Polkit privilege manager.
6557@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit} allows
6558system administrators to grant access to privileged operations in a
6559structured way. For example, polkit rules can allow a logged-in user
6560whose session is active to shut down the machine, if there are no other
6561users active.
6562@end deffn
6563
be1c2c54 6564@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
6565 [#:watts-up-pro? #f] @
6566 [#:poll-batteries? #t] @
6567 [#:ignore-lid? #f] @
6568 [#:use-percentage-for-policy? #f] @
6569 [#:percentage-low 10] @
6570 [#:percentage-critical 3] @
6571 [#:percentage-action 2] @
6572 [#:time-low 1200] @
6573 [#:time-critical 300] @
6574 [#:time-action 120] @
6575 [#:critical-power-action 'hybrid-sleep]
6576Return a service that runs @uref{http://upower.freedesktop.org/,
6577@command{upowerd}}, a system-wide monitor for power consumption and battery
6578levels, with the given configuration settings. It implements the
6579@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
6580GNOME.
6581@end deffn
6582
be1c2c54 6583@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
6584Return a service that runs @command{colord}, a system service with a D-Bus
6585interface to manage the color profiles of input and output devices such as
6586screens and scanners. It is notably used by the GNOME Color Manager graphical
6587tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
6588site} for more information.
6589@end deffn
6590
cee32ee4
AW
6591@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
6592Return an configuration allowing an application to access GeoClue
6593location data. @var{name} is the Desktop ID of the application, without
6594the @code{.desktop} part. If @var{allowed?} is true, the application
6595will have access to location information by default. The boolean
6596@var{system?} value indicates that an application is a system component
6597or not. Finally @var{users} is a list of UIDs of all users for which
6598this application is allowed location info access. An empty users list
6599means that all users are allowed.
6600@end deffn
6601
6602@defvr {Scheme Variable} %standard-geoclue-applications
6603The standard list of well-known GeoClue application configurations,
6604granting authority to GNOME's date-and-time utility to ask for the
6605current location in order to set the time zone, and allowing the Firefox
6606(IceCat) and Epiphany web browsers to request location information.
6607Firefox and Epiphany both query the user before allowing a web page to
6608know the user's location.
6609@end defvr
6610
be1c2c54 6611@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
6612 [#:whitelist '()] @
6613 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
6614 [#:submit-data? #f]
6615 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
6616 [#:submission-nick "geoclue"] @
6617 [#:applications %standard-geoclue-applications]
6618Return a service that runs the GeoClue location service. This service
6619provides a D-Bus interface to allow applications to request access to a
6620user's physical location, and optionally to add information to online
6621location databases. See
6622@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
6623web site} for more information.
6624@end deffn
6625
105369a4
DT
6626@node Database Services
6627@subsubsection Database Services
6628
6629The @code{(gnu services databases)} module provides the following service.
6630
be1c2c54 6631@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
6632 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
6633Return a service that runs @var{postgresql}, the PostgreSQL database
6634server.
6635
6636The PostgreSQL daemon loads its runtime configuration from
6637@var{config-file} and stores the database cluster in
6638@var{data-directory}.
6639@end deffn
fe1a39d3 6640
58724c48
DT
6641@node Web Services
6642@subsubsection Web Services
6643
6644The @code{(gnu services web)} module provides the following service:
6645
be1c2c54 6646@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
6647 [#:log-directory ``/var/log/nginx''] @
6648 [#:run-directory ``/var/run/nginx''] @
6649 [#:config-file]
6650
6651Return a service that runs @var{nginx}, the nginx web server.
6652
6653The nginx daemon loads its runtime configuration from @var{config-file}.
6654Log files are written to @var{log-directory} and temporary runtime data
6655files are written to @var{run-directory}. For proper operation, these
6656arguments should match what is in @var{config-file} to ensure that the
6657directories are created when the service is activated.
6658
6659@end deffn
6660
fe1a39d3
LC
6661@node Various Services
6662@subsubsection Various Services
6663
6664The @code{(gnu services lirc)} module provides the following service.
6665
be1c2c54 6666@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
6667 [#:device #f] [#:driver #f] [#:config-file #f] @
6668 [#:extra-options '()]
6669Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
6670decodes infrared signals from remote controls.
6671
6672Optionally, @var{device}, @var{driver} and @var{config-file}
6673(configuration file name) may be specified. See @command{lircd} manual
6674for details.
6675
6676Finally, @var{extra-options} is a list of additional command-line options
6677passed to @command{lircd}.
6678@end deffn
6679
6680
0ae8c15a
LC
6681@node Setuid Programs
6682@subsection Setuid Programs
6683
6684@cindex setuid programs
6685Some programs need to run with ``root'' privileges, even when they are
6686launched by unprivileged users. A notorious example is the
4d40227c
LC
6687@command{passwd} program, which users can run to change their
6688password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
6689@file{/etc/shadow} files---something normally restricted to root, for
6690obvious security reasons. To address that, these executables are
6691@dfn{setuid-root}, meaning that they always run with root privileges
6692(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
6693for more info about the setuid mechanisms.)
6694
6695The store itself @emph{cannot} contain setuid programs: that would be a
6696security issue since any user on the system can write derivations that
6697populate the store (@pxref{The Store}). Thus, a different mechanism is
6698used: instead of changing the setuid bit directly on files that are in
6699the store, we let the system administrator @emph{declare} which programs
6700should be setuid root.
6701
6702The @code{setuid-programs} field of an @code{operating-system}
6703declaration contains a list of G-expressions denoting the names of
6704programs to be setuid-root (@pxref{Using the Configuration System}).
6705For instance, the @command{passwd} program, which is part of the Shadow
6706package, can be designated by this G-expression (@pxref{G-Expressions}):
6707
6708@example
6709#~(string-append #$shadow "/bin/passwd")
6710@end example
6711
6712A default set of setuid programs is defined by the
6713@code{%setuid-programs} variable of the @code{(gnu system)} module.
6714
6715@defvr {Scheme Variable} %setuid-programs
6716A list of G-expressions denoting common programs that are setuid-root.
6717
6718The list includes commands such as @command{passwd}, @command{ping},
6719@command{su}, and @command{sudo}.
6720@end defvr
6721
6722Under the hood, the actual setuid programs are created in the
6723@file{/run/setuid-programs} directory at system activation time. The
6724files in this directory refer to the ``real'' binaries, which are in the
6725store.
6726
efb5e833
LC
6727@node X.509 Certificates
6728@subsection X.509 Certificates
6729
6730@cindex HTTPS, certificates
6731@cindex X.509 certificates
6732@cindex TLS
6733Web servers available over HTTPS (that is, HTTP over the transport-layer
6734security mechanism, TLS) send client programs an @dfn{X.509 certificate}
6735that the client can then use to @emph{authenticate} the server. To do
6736that, clients verify that the server's certificate is signed by a
6737so-called @dfn{certificate authority} (CA). But to verify the CA's
6738signature, clients must have first acquired the CA's certificate.
6739
6740Web browsers such as GNU@tie{}IceCat include their own set of CA
6741certificates, such that they are able to verify CA signatures
6742out-of-the-box.
6743
6744However, most other programs that can talk HTTPS---@command{wget},
6745@command{git}, @command{w3m}, etc.---need to be told where CA
6746certificates can be found.
6747
6748@cindex @code{nss-certs}
6749In GuixSD, this is done by adding a package that provides certificates
6750to the @code{packages} field of the @code{operating-system} declaration
6751(@pxref{operating-system Reference}). GuixSD includes one such package,
6752@code{nss-certs}, which is a set of CA certificates provided as part of
6753Mozilla's Network Security Services.
6754
6755Note that it is @emph{not} part of @var{%base-packages}, so you need to
6756explicitly add it. The @file{/etc/ssl/certs} directory, which is where
6757most applications and libraries look for certificates by default, points
6758to the certificates installed globally.
6759
6760Unprivileged users can also install their own certificate package in
6761their profile. A number of environment variables need to be defined so
6762that applications and libraries know where to find them. Namely, the
6763OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
6764variables. Some applications add their own environment variables; for
6765instance, the Git version control system honors the certificate bundle
6766pointed to by the @code{GIT_SSL_CAINFO} environment variable.
6767
6768
996ed739
LC
6769@node Name Service Switch
6770@subsection Name Service Switch
6771
6772@cindex name service switch
6773@cindex NSS
6774The @code{(gnu system nss)} module provides bindings to the
6775configuration file of libc's @dfn{name service switch} or @dfn{NSS}
6776(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
6777Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
6778extended with new ``name'' lookup methods for system databases, which
6779includes host names, service names, user accounts, and more (@pxref{Name
6780Service Switch, System Databases and Name Service Switch,, libc, The GNU
6781C Library Reference Manual}).
6782
6783The NSS configuration specifies, for each system database, which lookup
6784method is to be used, and how the various methods are chained
6785together---for instance, under which circumstances NSS should try the
6786next method in the list. The NSS configuration is given in the
6787@code{name-service-switch} field of @code{operating-system} declarations
6788(@pxref{operating-system Reference, @code{name-service-switch}}).
6789
4c9050c6
LC
6790@cindex nss-mdns
6791@cindex .local, host name lookup
996ed739 6792As an example, the declaration below configures the NSS to use the
4c9050c6
LC
6793@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
6794back-end}, which supports host name lookups over multicast DNS (mDNS)
6795for host names ending in @code{.local}:
996ed739
LC
6796
6797@example
6798(name-service-switch
6799 (hosts (list %files ;first, check /etc/hosts
6800
6801 ;; If the above did not succeed, try
6802 ;; with 'mdns_minimal'.
6803 (name-service
6804 (name "mdns_minimal")
6805
6806 ;; 'mdns_minimal' is authoritative for
6807 ;; '.local'. When it returns "not found",
6808 ;; no need to try the next methods.
6809 (reaction (lookup-specification
6810 (not-found => return))))
6811
6812 ;; Then fall back to DNS.
6813 (name-service
6814 (name "dns"))
6815
6816 ;; Finally, try with the "full" 'mdns'.
6817 (name-service
6818 (name "mdns")))))
6819@end example
6820
15137a29
LC
6821Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
6822contains this configuration, so you won't have to type it if all you
6823want is to have @code{.local} host lookup working.
6824
4c9050c6
LC
6825Note that, in this case, in addition to setting the
6826@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
6827you also need to use @code{avahi-service} (@pxref{Networking Services,
6828@code{avahi-service}}), or @var{%desktop-services}, which includes it
6829(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
6830to the name service cache daemon (@pxref{Base Services,
6831@code{nscd-service}}).
15137a29
LC
6832
6833For convenience, the following variables provide typical NSS
6834configurations.
6835
6836@defvr {Scheme Variable} %default-nss
6837This is the default name service switch configuration, a
6838@code{name-service-switch} object.
6839@end defvr
6840
6841@defvr {Scheme Variable} %mdns-host-lookup-nss
6842This is the name service switch configuration with support for host name
6843lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
6844@end defvr
4c9050c6 6845
996ed739
LC
6846The reference for name service switch configuration is given below. It
6847is a direct mapping of the C library's configuration file format, so
6848please refer to the C library manual for more information (@pxref{NSS
6849Configuration File,,, libc, The GNU C Library Reference Manual}).
6850Compared to libc's NSS configuration file format, it has the advantage
6851not only of adding this warm parenthetic feel that we like, but also
6852static checks: you'll know about syntax errors and typos as soon as you
6853run @command{guix system}.
6854
996ed739
LC
6855@deftp {Data Type} name-service-switch
6856
6857This is the data type representation the configuration of libc's name
6858service switch (NSS). Each field below represents one of the supported
6859system databases.
6860
6861@table @code
6862@item aliases
6863@itemx ethers
6864@itemx group
6865@itemx gshadow
6866@itemx hosts
6867@itemx initgroups
6868@itemx netgroup
6869@itemx networks
6870@itemx password
6871@itemx public-key
6872@itemx rpc
6873@itemx services
6874@itemx shadow
6875The system databases handled by the NSS. Each of these fields must be a
6876list of @code{<name-service>} objects (see below.)
6877@end table
6878@end deftp
6879
6880@deftp {Data Type} name-service
6881
6882This is the data type representing an actual name service and the
6883associated lookup action.
6884
6885@table @code
6886@item name
6887A string denoting the name service (@pxref{Services in the NSS
6888configuration,,, libc, The GNU C Library Reference Manual}).
6889
4aee6e60
LC
6890Note that name services listed here must be visible to nscd. This is
6891achieved by passing the @code{#:name-services} argument to
6892@code{nscd-service} the list of packages providing the needed name
6893services (@pxref{Base Services, @code{nscd-service}}).
6894
996ed739
LC
6895@item reaction
6896An action specified using the @code{lookup-specification} macro
6897(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
6898Reference Manual}). For example:
6899
6900@example
6901(lookup-specification (unavailable => continue)
6902 (success => return))
6903@end example
6904@end table
6905@end deftp
0ae8c15a 6906
fd1b1fa2
LC
6907@node Initial RAM Disk
6908@subsection Initial RAM Disk
6909
6910@cindex initial RAM disk (initrd)
6911@cindex initrd (initial RAM disk)
6912For bootstrapping purposes, the Linux-Libre kernel is passed an
6913@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
6914root file system, as well as an initialization script. The latter is
6915responsible for mounting the real root file system, and for loading any
6916kernel modules that may be needed to achieve that.
6917
6918The @code{initrd} field of an @code{operating-system} declaration allows
6919you to specify which initrd you would like to use. The @code{(gnu
6920system linux-initrd)} module provides two ways to build an initrd: the
6921high-level @code{base-initrd} procedure, and the low-level
6922@code{expression->initrd} procedure.
6923
6924The @code{base-initrd} procedure is intended to cover most common uses.
6925For example, if you want to add a bunch of kernel modules to be loaded
6926at boot time, you can define the @code{initrd} field of the operating
6927system declaration like this:
6928
6929@example
52ac153e 6930(initrd (lambda (file-systems . rest)
027981d6
LC
6931 ;; Create a standard initrd that has modules "foo.ko"
6932 ;; and "bar.ko", as well as their dependencies, in
6933 ;; addition to the modules available by default.
52ac153e 6934 (apply base-initrd file-systems
027981d6 6935 #:extra-modules '("foo" "bar")
52ac153e 6936 rest)))
fd1b1fa2
LC
6937@end example
6938
52ac153e
LC
6939The @code{base-initrd} procedure also handles common use cases that
6940involves using the system as a QEMU guest, or as a ``live'' system whose
6941root file system is volatile.
fd1b1fa2
LC
6942
6943@deffn {Monadic Procedure} base-initrd @var{file-systems} @
6944 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
52ac153e 6945 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
6946Return a monadic derivation that builds a generic initrd. @var{file-systems} is
6947a list of file-systems to be mounted by the initrd, possibly in addition to
6948the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
6949@var{mapped-devices} is a list of device mappings to realize before
6950@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
6951
6952When @var{qemu-networking?} is true, set up networking with the standard QEMU
6953parameters. When @var{virtio?} is true, load additional modules so the initrd can
6954be used as a QEMU guest with para-virtualized I/O drivers.
6955
6956When @var{volatile-root?} is true, the root file system is writable but any changes
6957to it are lost.
6958
6959The initrd is automatically populated with all the kernel modules necessary
6960for @var{file-systems} and for the given options. However, additional kernel
6961modules can be listed in @var{extra-modules}. They will be added to the initrd, and
6962loaded at boot time in the order in which they appear.
6963@end deffn
6964
6965Needless to say, the initrds we produce and use embed a
6966statically-linked Guile, and the initialization program is a Guile
6967program. That gives a lot of flexibility. The
6968@code{expression->initrd} procedure builds such an initrd, given the
6969program to run in that initrd.
6970
6971@deffn {Monadic Procedure} expression->initrd @var{exp} @
6972 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 6973 [#:modules '()]
fd1b1fa2
LC
6974Return a derivation that builds a Linux initrd (a gzipped cpio archive)
6975containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
6976upon booting. All the derivations referenced by @var{exp} are
6977automatically copied to the initrd.
fd1b1fa2 6978
42d10464
LC
6979@var{modules} is a list of Guile module names to be embedded in the
6980initrd.
fd1b1fa2
LC
6981@end deffn
6982
88faf933
LC
6983@node GRUB Configuration
6984@subsection GRUB Configuration
6985
6986@cindex GRUB
6987@cindex boot loader
6988
6989The operating system uses GNU@tie{}GRUB as its boot loader
6990(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
6991configured using @code{grub-configuration} declarations. This data type
6992is exported by the @code{(gnu system grub)} module, and described below.
6993
6994@deftp {Data Type} grub-configuration
6995The type of a GRUB configuration declaration.
6996
6997@table @asis
6998
6999@item @code{device}
7000This is a string denoting the boot device. It must be a device name
7001understood by the @command{grub-install} command, such as
7002@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
7003GNU GRUB Manual}).
7004
7005@item @code{menu-entries} (default: @code{()})
7006A possibly empty list of @code{menu-entry} objects (see below), denoting
7007entries to appear in the GRUB boot menu, in addition to the current
7008system entry and the entry pointing to previous system generations.
7009
7010@item @code{default-entry} (default: @code{0})
7011The index of the default boot menu entry. Index 0 is for the current
7012system's entry.
7013
7014@item @code{timeout} (default: @code{5})
7015The number of seconds to wait for keyboard input before booting. Set to
70160 to boot immediately, and to -1 to wait indefinitely.
7017
7018@item @code{theme} (default: @var{%default-theme})
7019The @code{grub-theme} object describing the theme to use.
7020@end table
7021
7022@end deftp
7023
7024Should you want to list additional boot menu entries @i{via} the
7025@code{menu-entries} field above, you will need to create them with the
7026@code{menu-entry} form:
7027
7028@deftp {Data Type} menu-entry
7029The type of an entry in the GRUB boot menu.
7030
7031@table @asis
7032
7033@item @code{label}
35ed9306 7034The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
7035
7036@item @code{linux}
7037The Linux kernel to boot.
7038
7039@item @code{linux-arguments} (default: @code{()})
7040The list of extra Linux kernel command-line arguments---e.g.,
7041@code{("console=ttyS0")}.
7042
7043@item @code{initrd}
7044A G-Expression or string denoting the file name of the initial RAM disk
7045to use (@pxref{G-Expressions}).
7046
7047@end table
7048@end deftp
7049
7050@c FIXME: Write documentation once it's stable.
7051Themes are created using the @code{grub-theme} form, which is not
7052documented yet.
7053
7054@defvr {Scheme Variable} %default-theme
7055This is the default GRUB theme used by the operating system, with a
7056fancy background image displaying the GNU and Guix logos.
7057@end defvr
7058
7059
cf4a9129
LC
7060@node Invoking guix system
7061@subsection Invoking @code{guix system}
0918e64a 7062
cf4a9129
LC
7063Once you have written an operating system declaration, as seen in the
7064previous section, it can be @dfn{instantiated} using the @command{guix
7065system} command. The synopsis is:
4af2447e 7066
cf4a9129
LC
7067@example
7068guix system @var{options}@dots{} @var{action} @var{file}
7069@end example
4af2447e 7070
cf4a9129
LC
7071@var{file} must be the name of a file containing an
7072@code{operating-system} declaration. @var{action} specifies how the
7073operating system is instantiate. Currently the following values are
7074supported:
4af2447e 7075
cf4a9129
LC
7076@table @code
7077@item reconfigure
7078Build the operating system described in @var{file}, activate it, and
7079switch to it@footnote{This action is usable only on systems already
7080running GNU.}.
4af2447e 7081
cf4a9129
LC
7082This effects all the configuration specified in @var{file}: user
7083accounts, system services, global package list, setuid programs, etc.
4af2447e 7084
cf4a9129
LC
7085It also adds a GRUB menu entry for the new OS configuration, and moves
7086entries for older configurations to a submenu---unless
7087@option{--no-grub} is passed.
4af2447e 7088
bf2479c7
LC
7089@c The paragraph below refers to the problem discussed at
7090@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
7091It is highly recommended to run @command{guix pull} once before you run
7092@command{guix system reconfigure} for the first time (@pxref{Invoking
7093guix pull}). Failing to do that you would see an older version of Guix
7094once @command{reconfigure} has completed.
7095
cf4a9129
LC
7096@item build
7097Build the operating system's derivation, which includes all the
7098configuration files and programs needed to boot and run the system.
7099This action does not actually install anything.
113daf62 7100
cf4a9129
LC
7101@item init
7102Populate the given directory with all the files necessary to run the
7103operating system specified in @var{file}. This is useful for first-time
4705641f 7104installations of GuixSD. For instance:
113daf62
LC
7105
7106@example
cf4a9129 7107guix system init my-os-config.scm /mnt
113daf62
LC
7108@end example
7109
cf4a9129
LC
7110copies to @file{/mnt} all the store items required by the configuration
7111specified in @file{my-os-config.scm}. This includes configuration
7112files, packages, and so on. It also creates other essential files
7113needed for the system to operate correctly---e.g., the @file{/etc},
7114@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 7115
cf4a9129
LC
7116This command also installs GRUB on the device specified in
7117@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 7118
cf4a9129
LC
7119@item vm
7120@cindex virtual machine
0276f697 7121@cindex VM
f535dcbe 7122@anchor{guix system vm}
cf4a9129
LC
7123Build a virtual machine that contain the operating system declared in
7124@var{file}, and return a script to run that virtual machine (VM).
810568b3 7125Arguments given to the script are passed as is to QEMU.
113daf62 7126
cf4a9129 7127The VM shares its store with the host system.
113daf62 7128
0276f697
LC
7129Additional file systems can be shared between the host and the VM using
7130the @code{--share} and @code{--expose} command-line options: the former
7131specifies a directory to be shared with write access, while the latter
7132provides read-only access to the shared directory.
7133
7134The example below creates a VM in which the user's home directory is
7135accessible read-only, and where the @file{/exchange} directory is a
7136read-write mapping of the host's @file{$HOME/tmp}:
7137
7138@example
7139guix system vm my-config.scm \
7140 --expose=$HOME --share=$HOME/tmp=/exchange
7141@end example
7142
6aa260af
LC
7143On GNU/Linux, the default is to boot directly to the kernel; this has
7144the advantage of requiring only a very tiny root disk image since the
7145host's store can then be mounted.
7146
7147The @code{--full-boot} option forces a complete boot sequence, starting
7148with the bootloader. This requires more disk space since a root image
7149containing at least the kernel, initrd, and bootloader data files must
7150be created. The @code{--image-size} option can be used to specify the
7151image's size.
ab11f0be 7152
cf4a9129
LC
7153@item vm-image
7154@itemx disk-image
7155Return a virtual machine or disk image of the operating system declared
7156in @var{file} that stands alone. Use the @option{--image-size} option
7157to specify the size of the image.
113daf62 7158
cf4a9129
LC
7159When using @code{vm-image}, the returned image is in qcow2 format, which
7160the QEMU emulator can efficiently use.
113daf62 7161
cf4a9129
LC
7162When using @code{disk-image}, a raw disk image is produced; it can be
7163copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
7164the device corresponding to a USB stick, one can copy the image on it
7165using the following command:
113daf62 7166
cf4a9129
LC
7167@example
7168# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
7169@end example
113daf62 7170
cf4a9129 7171@end table
113daf62 7172
cf4a9129
LC
7173@var{options} can contain any of the common build options provided by
7174@command{guix build} (@pxref{Invoking guix build}). In addition,
7175@var{options} can contain one of the following:
113daf62 7176
cf4a9129
LC
7177@table @option
7178@item --system=@var{system}
7179@itemx -s @var{system}
7180Attempt to build for @var{system} instead of the host's system type.
7181This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 7182
f3f427c2
LC
7183@item --derivation
7184@itemx -d
7185Return the derivation file name of the given operating system without
7186building anything.
7187
cf4a9129
LC
7188@item --image-size=@var{size}
7189For the @code{vm-image} and @code{disk-image} actions, create an image
7190of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
7191include a unit as a suffix (@pxref{Block size, size specifications,,
7192coreutils, GNU Coreutils}).
db030303
LC
7193
7194@item --on-error=@var{strategy}
7195Apply @var{strategy} when an error occurs when reading @var{file}.
7196@var{strategy} may be one of the following:
7197
7198@table @code
7199@item nothing-special
7200Report the error concisely and exit. This is the default strategy.
7201
7202@item backtrace
7203Likewise, but also display a backtrace.
7204
7205@item debug
7206Report the error and enter Guile's debugger. From there, you can run
7207commands such as @code{,bt} to get a backtrace, @code{,locals} to
7208display local variable values, and more generally inspect the program's
7209state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
7210a list of available debugging commands.
7211@end table
113daf62 7212@end table
113daf62 7213
cf4a9129
LC
7214Note that all the actions above, except @code{build} and @code{init},
7215rely on KVM support in the Linux-Libre kernel. Specifically, the
7216machine should have hardware virtualization support, the corresponding
7217KVM kernel module should be loaded, and the @file{/dev/kvm} device node
7218must exist and be readable and writable by the user and by the daemon's
7219build users.
8451a568 7220
d6c3267a
LC
7221The @command{guix system} command has even more to offer! The following
7222sub-commands allow you to visualize how your system services relate to
7223each other:
7224
7225@anchor{system-extension-graph}
7226@table @code
7227
7228@item extension-graph
7229Emit in Dot/Graphviz format to standard output the @dfn{service
7230extension graph} of the operating system defined in @var{file}
7231(@pxref{Service Composition}, for more information on service
7232extensions.)
7233
7234The command:
7235
7236@example
7237$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
7238@end example
7239
7240produces a PDF file showing the extension relations among services.
7241
6f305ea5
LC
7242@anchor{system-dmd-graph}
7243@item dmd-graph
7244Emit in Dot/Graphviz format to standard output the @dfn{dependency
7245graph} of dmd services of the operating system defined in @var{file}.
7246@xref{dmd Services}, for more information and for an example graph.
7247
d6c3267a
LC
7248@end table
7249
7250
cf4a9129
LC
7251@node Defining Services
7252@subsection Defining Services
8451a568 7253
eb524192 7254The previous sections show the available services and how one can combine
0adfe95a
LC
7255them in an @code{operating-system} declaration. But how do we define
7256them in the first place? And what is a service anyway?
8451a568 7257
0adfe95a
LC
7258@menu
7259* Service Composition:: The model for composing services.
7260* Service Types and Services:: Types and services.
7261* Service Reference:: API reference.
7262* dmd Services:: A particular type of service.
7263@end menu
7264
7265@node Service Composition
7266@subsubsection Service Composition
7267
7268@cindex services
7269@cindex daemons
7270Here we define a @dfn{service} as, broadly, something that extends the
7271operating system's functionality. Often a service is a process---a
7272@dfn{daemon}---started when the system boots: a secure shell server, a
7273Web server, the Guix build daemon, etc. Sometimes a service is a daemon
7274whose execution can be triggered by another daemon---e.g., an FTP server
7275started by @command{inetd} or a D-Bus service activated by
7276@command{dbus-daemon}. Occasionally, a service does not map to a
7277daemon. For instance, the ``account'' service collects user accounts
7278and makes sure they exist when the system runs; the ``udev'' service
7279collects device management rules and makes them available to the eudev
7280daemon; the @file{/etc} service populates the system's @file{/etc}
7281directory.
7282
d6c3267a 7283@cindex service extensions
0adfe95a
LC
7284GuixSD services are connected by @dfn{extensions}. For instance, the
7285secure shell service @emph{extends} dmd---GuixSD's initialization system,
7286running as PID@tie{}1---by giving it the command lines to start and stop
7287the secure shell daemon (@pxref{Networking Services,
7288@code{lsh-service}}); the UPower service extends the D-Bus service by
7289passing it its @file{.service} specification, and extends the udev
7290service by passing it device management rules (@pxref{Desktop Services,
7291@code{upower-service}}); the Guix daemon service extends dmd by passing
7292it the command lines to start and stop the daemon, and extends the
7293account service by passing it a list of required build user accounts
7294(@pxref{Base Services}).
7295
7296All in all, services and their ``extends'' relations form a directed
7297acyclic graph (DAG). If we represent services as boxes and extensions
7298as arrows, a typical system might provide something like this:
7299
7300@image{images/service-graph,,5in,Typical service extension graph.}
7301
7302At the bottom, we see the @dfn{boot service}, which produces the boot
7303script that is executed at boot time from the initial RAM disk.
d6c3267a
LC
7304@xref{system-extension-graph, the @command{guix system extension-graph}
7305command}, for information on how to generate this representation for a
7306particular operating system definition.
0adfe95a
LC
7307
7308@cindex service types
7309Technically, developers can define @dfn{service types} to express these
7310relations. There can be any number of services of a given type on the
7311system---for instance, a system running two instances of the GNU secure
7312shell server (lsh) has two instances of @var{lsh-service-type}, with
7313different parameters.
7314
7315The following section describes the programming interface for service
7316types and services.
7317
7318@node Service Types and Services
7319@subsubsection Service Types and Services
7320
7321A @dfn{service type} is a node in the DAG described above. Let us start
7322with a simple example, the service type for the Guix build daemon
7323(@pxref{Invoking guix-daemon}):
7324
7325@example
7326(define guix-service-type
7327 (service-type
7328 (name 'guix)
7329 (extensions
7330 (list (service-extension dmd-root-service-type guix-dmd-service)
7331 (service-extension account-service-type guix-accounts)
7332 (service-extension activation-service-type guix-activation)))))
7333@end example
8451a568 7334
cf4a9129 7335@noindent
0adfe95a
LC
7336It defines a two things:
7337
7338@enumerate
7339@item
7340A name, whose sole purpose is to make inspection and debugging easier.
7341
7342@item
7343A list of @dfn{service extensions}, where each extension designates the
7344target service type and a procedure that, given the service's
7345parameters, returns a list of object to extend the service of that type.
7346
7347Every service type has at least one service extension. The only
7348exception is the @dfn{boot service type}, which is the ultimate service.
7349@end enumerate
7350
7351In this example, @var{guix-service-type} extends three services:
7352
7353@table @var
7354@item dmd-root-service-type
7355The @var{guix-dmd-service} procedure defines how the dmd service is
7356extended. Namely, it returns a @code{<dmd-service>} object that defines
7357how @command{guix-daemon} is started and stopped (@pxref{dmd Services}).
7358
7359@item account-service-type
7360This extension for this service is computed by @var{guix-accounts},
7361which returns a list of @code{user-group} and @code{user-account}
7362objects representing the build user accounts (@pxref{Invoking
7363guix-daemon}).
7364
7365@item activation-service-type
7366Here @var{guix-activation} is a procedure that returns a gexp, which is
7367a code snippet to run at ``activation time''---e.g., when the service is
7368booted.
7369@end table
7370
7371A service of this type is instantiated like this:
7372
7373@example
7374(service guix-service-type
7375 (guix-configuration
7376 (build-accounts 5)
7377 (use-substitutes? #f)))
7378@end example
7379
7380The second argument to the @code{service} form is a value representing
7381the parameters of this specific service instance.
7382@xref{guix-configuration-type, @code{guix-configuration}}, for
7383information about the @code{guix-configuration} data type.
7384
7385@var{guix-service-type} is quite simple because it extends other
7386services but is not extensible itself.
7387
7388@c @subsubsubsection Extensible Service Types
7389
7390The service type for an @emph{extensible} service looks like this:
7391
7392@example
7393(define udev-service-type
7394 (service-type (name 'udev)
7395 (extensions
7396 (list (service-extension dmd-root-service-type
7397 udev-dmd-service)))
7398
7399 (compose concatenate) ;concatenate the list of rules
7400 (extend (lambda (config rules)
7401 (match config
7402 (($ <udev-configuration> udev initial-rules)
7403 (udev-configuration
7404 (udev udev) ;the udev package to use
7405 (rules (append initial-rules rules)))))))))
7406@end example
7407
7408This is the service type for the
7409@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
7410management daemon}. Compared to the previous example, in addition to an
7411extension of @var{dmd-root-service-type}, we see two new fields:
7412
7413@table @code
7414@item compose
7415This is the procedure to @dfn{compose} the list of extensions to
7416services of this type.
7417
7418Services can extend the udev service by passing it lists of rules; we
7419compose those extensions simply by concatenating them.
7420
7421@item extend
7422This procedure defines how the service's value is @dfn{extended} with
7423the composition of the extensions.
7424
7425Udev extensions are composed into a list of rules, but the udev service
7426value is itself a @code{<udev-configuration>} record. So here, we
7427extend that record by appending the list of rules is contains to the
7428list of contributed rules.
7429@end table
7430
7431There can be only one instance of an extensible service type such as
7432@var{udev-service-type}. If there were more, the
7433@code{service-extension} specifications would be ambiguous.
7434
7435Still here? The next section provides a reference of the programming
7436interface for services.
7437
7438@node Service Reference
7439@subsubsection Service Reference
7440
7441We have seen an overview of service types (@pxref{Service Types and
7442Services}). This section provides a reference on how to manipulate
7443services and service types. This interface is provided by the
7444@code{(gnu services)} module.
7445
7446@deffn {Scheme Procedure} service @var{type} @var{value}
7447Return a new service of @var{type}, a @code{<service-type>} object (see
7448below.) @var{value} can be any object; it represents the parameters of
7449this particular service instance.
7450@end deffn
7451
7452@deffn {Scheme Procedure} service? @var{obj}
7453Return true if @var{obj} is a service.
7454@end deffn
8451a568 7455
0adfe95a
LC
7456@deffn {Scheme Procedure} service-kind @var{service}
7457Return the type of @var{service}---i.e., a @code{<service-type>} object.
7458@end deffn
7459
7460@deffn {Scheme Procedure} service-parameters @var{service}
7461Return the value associated with @var{service}. It represents its
7462parameters.
7463@end deffn
7464
7465Here is an example of how a service is created and manipulated:
7466
7467@example
7468(define s
7469 (service nginx-service-type
7470 (nginx-configuration
7471 (nginx nginx)
7472 (log-directory log-directory)
7473 (run-directory run-directory)
7474 (file config-file))))
7475
7476(service? s)
7477@result{} #t
7478
7479(eq? (service-kind s) nginx-service-type)
7480@result{} #t
7481@end example
7482
7483@deftp {Data Type} service-type
7484@cindex service type
7485This is the representation of a @dfn{service type} (@pxref{Service Types
7486and Services}).
7487
7488@table @asis
7489@item @code{name}
7490This is a symbol, used only to simplify inspection and debugging.
7491
7492@item @code{extensions}
7493A non-empty list of @code{<service-extension>} objects (see below.)
7494
7495@item @code{compose} (default: @code{#f})
7496If this is @code{#f}, then the service type denotes services that cannot
7497be extended---i.e., services that do not receive ``values'' from other
7498services.
7499
7500Otherwise, it must be a one-argument procedure. The procedure is called
7501by @code{fold-services} and is passed a list of values collected from
7502extensions. It must return a value that is a valid parameter value for
7503the service instance.
7504
7505@item @code{extend} (default: @code{#f})
7506If this is @code{#f}, services of this type cannot be extended.
7507
7508Otherwise, it must be a two-argument procedure: @code{fold-services}
7509calls it, passing it the service's initial value as the first argument
7510and the result of applying @code{compose} to the extension values as the
7511second argument.
7512@end table
7513
7514@xref{Service Types and Services}, for examples.
7515@end deftp
7516
7517@deffn {Scheme Procedure} service-extension @var{target-type} @
7518 @var{compute}
7519Return a new extension for services of type @var{target-type}.
7520@var{compute} must be a one-argument procedure: @code{fold-services}
7521calls it, passing it the value associated with the service that provides
7522the extension; it must return a valid value for the target service.
7523@end deffn
7524
7525@deffn {Scheme Procedure} service-extension? @var{obj}
7526Return true if @var{obj} is a service extension.
7527@end deffn
7528
7529At the core of the service abstraction lies the @code{fold-services}
7530procedure, which is responsible for ``compiling'' a list of services
7531down to a single boot script. In essence, it propagates service
7532extensions down the service graph, updating each node parameters on the
7533way, until it reaches the root node.
7534
7535@deffn {Scheme Procedure} fold-services @var{services} @
7536 [#:target-type @var{boot-service-type}]
7537Fold @var{services} by propagating their extensions down to the root of
7538type @var{target-type}; return the root service adjusted accordingly.
7539@end deffn
7540
7541Lastly, the @code{(gnu services)} module also defines several essential
7542service types, some of which are listed below.
7543
7544@defvr {Scheme Variable} boot-service-type
7545The type of the ``boot service'', which is the root of the service
7546graph.
7547@end defvr
7548
7549@defvr {Scheme Variable} etc-service-type
7550The type of the @file{/etc} service. This service can be extended by
7551passing it name/file tuples such as:
7552
7553@example
7554(list `("issue" ,(plain-file "issue" "Welcome!\n")))
7555@end example
7556
7557In this example, the effect would be to add an @file{/etc/issue} file
7558pointing to the given file.
7559@end defvr
7560
7561@defvr {Scheme Variable} setuid-program-service-type
7562Type for the ``setuid-program service''. This service collects lists of
7563executable file names, passed as gexps, and adds them to the set of
7564setuid-root programs on the system (@pxref{Setuid Programs}).
7565@end defvr
7566
7567
7568@node dmd Services
7569@subsubsection dmd Services
7570
7571@cindex PID 1
7572@cindex init system
7573The @code{(gnu services dmd)} provides a way to define services managed
7574by GNU@tie{}dmd, which is GuixSD initialization system---the first
7575process that is started when the system boots, aka. PID@tie{}1
6f305ea5
LC
7576(@pxref{Introduction,,, dmd, GNU dmd Manual}).
7577
7578Services in dmd can depend on each other. For instance, the SSH daemon
7579may need to be started after the syslog daemon has been started, which
7580in turn can only happen once all the file systems have been mounted.
7581The simple operating system defined earlier (@pxref{Using the
7582Configuration System}) results in a service graph like this:
7583
7584@image{images/dmd-graph,,5in,Typical dmd service graph.}
7585
7586You can actually generate such a graph for any operating system
7587definition using the @command{guix system dmd-graph} command
7588(@pxref{system-dmd-graph, @command{guix system dmd-graph}}).
7589
7590The @var{%dmd-root-service} is a service object representing PID@tie{}1,
7591of type @var{dmd-root-service-type}; it can be extended by passing it
7592lists of @code{<dmd-service>} objects.
0adfe95a
LC
7593
7594@deftp {Data Type} dmd-service
7595The data type representing a service managed by dmd.
7596
7597@table @asis
7598@item @code{provision}
7599This is a list of symbols denoting what the service provides.
7600
7601These are the names that may be passed to @command{deco start},
7602@command{deco status}, and similar commands (@pxref{Invoking deco,,,
7603dmd, GNU dmd Manual}). @xref{Slots of services, the @code{provides}
7604slot,, dmd, GNU dmd Manual}, for details.
7605
7606@item @code{requirements} (default: @code{'()})
7607List of symbols denoting the dmd services this one depends on.
7608
7609@item @code{respawn?} (default: @code{#t})
7610Whether to restart the service when it stops, for instance when the
7611underlying process dies.
7612
7613@item @code{start}
7614@itemx @code{stop} (default: @code{#~(const #f)})
cf4a9129
LC
7615The @code{start} and @code{stop} fields refer to dmd's facilities to
7616start and stop processes (@pxref{Service De- and Constructors,,, dmd,
0adfe95a
LC
7617GNU dmd Manual}). They are given as G-expressions that get expanded in
7618the dmd configuration file (@pxref{G-Expressions}).
7619
7620@item @code{documentation}
7621A documentation string, as shown when running:
7622
7623@example
7624deco doc @var{service-name}
7625@end example
7626
7627where @var{service-name} is one of the symbols in @var{provision}
7628(@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
7629@end table
7630@end deftp
7631
7632@defvr {Scheme Variable} dmd-root-service-type
7633The service type for the dmd ``root service''---i.e., PID@tie{}1.
7634
7635This is the service type that extensions target when they want to create
7636dmd services (@pxref{Service Types and Services}, for an example). Each
7637extension must pass a list of @code{<dmd-service>}.
7638@end defvr
7639
7640@defvr {Scheme Variable} %dmd-root-service
7641This service represents PID@tie{}1.
7642@end defvr
8451a568 7643
8451a568 7644
cf4a9129
LC
7645@node Installing Debugging Files
7646@section Installing Debugging Files
8451a568 7647
cf4a9129
LC
7648@cindex debugging files
7649Program binaries, as produced by the GCC compilers for instance, are
7650typically written in the ELF format, with a section containing
7651@dfn{debugging information}. Debugging information is what allows the
7652debugger, GDB, to map binary code to source code; it is required to
7653debug a compiled program in good conditions.
8451a568 7654
cf4a9129
LC
7655The problem with debugging information is that is takes up a fair amount
7656of disk space. For example, debugging information for the GNU C Library
7657weighs in at more than 60 MiB. Thus, as a user, keeping all the
7658debugging info of all the installed programs is usually not an option.
7659Yet, space savings should not come at the cost of an impediment to
7660debugging---especially in the GNU system, which should make it easier
7661for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 7662
cf4a9129
LC
7663Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
7664mechanism that allows users to get the best of both worlds: debugging
7665information can be stripped from the binaries and stored in separate
7666files. GDB is then able to load debugging information from those files,
7667when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
7668with GDB}).
8451a568 7669
cf4a9129
LC
7670The GNU distribution takes advantage of this by storing debugging
7671information in the @code{lib/debug} sub-directory of a separate package
7672output unimaginatively called @code{debug} (@pxref{Packages with
7673Multiple Outputs}). Users can choose to install the @code{debug} output
7674of a package when they need it. For instance, the following command
7675installs the debugging information for the GNU C Library and for GNU
7676Guile:
8451a568
LC
7677
7678@example
cf4a9129 7679guix package -i glibc:debug guile:debug
8451a568
LC
7680@end example
7681
cf4a9129
LC
7682GDB must then be told to look for debug files in the user's profile, by
7683setting the @code{debug-file-directory} variable (consider setting it
7684from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
7685GDB}):
8451a568 7686
cf4a9129
LC
7687@example
7688(gdb) set debug-file-directory ~/.guix-profile/lib/debug
7689@end example
8451a568 7690
cf4a9129
LC
7691From there on, GDB will pick up debugging information from the
7692@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 7693
cf4a9129
LC
7694In addition, you will most likely want GDB to be able to show the source
7695code being debugged. To do that, you will have to unpack the source
7696code of the package of interest (obtained with @code{guix build
7697--source}, @pxref{Invoking guix build}), and to point GDB to that source
7698directory using the @code{directory} command (@pxref{Source Path,
7699@code{directory},, gdb, Debugging with GDB}).
8451a568 7700
cf4a9129
LC
7701@c XXX: keep me up-to-date
7702The @code{debug} output mechanism in Guix is implemented by the
7703@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
7704opt-in---debugging information is available only for those packages
7705whose definition explicitly declares a @code{debug} output. This may be
7706changed to opt-out in the future, if our build farm servers can handle
7707the load. To check whether a package has a @code{debug} output, use
7708@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 7709
8451a568 7710
05962f29
LC
7711@node Security Updates
7712@section Security Updates
7713
843858b8
LC
7714@quotation Note
7715As of version @value{VERSION}, the feature described in this section is
7716experimental.
7717@end quotation
05962f29
LC
7718
7719@cindex security updates
7720Occasionally, important security vulnerabilities are discovered in core
7721software packages and must be patched. Guix follows a functional
7722package management discipline (@pxref{Introduction}), which implies
7723that, when a package is changed, @emph{every package that depends on it}
7724must be rebuilt. This can significantly slow down the deployment of
7725fixes in core packages such as libc or Bash, since basically the whole
7726distribution would need to be rebuilt. Using pre-built binaries helps
7727(@pxref{Substitutes}), but deployment may still take more time than
7728desired.
7729
7730@cindex grafts
7731To address that, Guix implements @dfn{grafts}, a mechanism that allows
7732for fast deployment of critical updates without the costs associated
7733with a whole-distribution rebuild. The idea is to rebuild only the
7734package that needs to be patched, and then to ``graft'' it onto packages
7735explicitly installed by the user and that were previously referring to
7736the original package. The cost of grafting is typically very low, and
7737order of magnitudes lower than a full rebuild of the dependency chain.
7738
7739@cindex replacements of packages, for grafts
7740For instance, suppose a security update needs to be applied to Bash.
7741Guix developers will provide a package definition for the ``fixed''
7742Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
7743Packages}). Then, the original package definition is augmented with a
7744@code{replacement} field pointing to the package containing the bug fix:
7745
7746@example
7747(define bash
7748 (package
7749 (name "bash")
7750 ;; @dots{}
7751 (replacement bash-fixed)))
7752@end example
7753
7754From there on, any package depending directly or indirectly on Bash that
7755is installed will automatically be ``rewritten'' to refer to
7756@var{bash-fixed} instead of @var{bash}. This grafting process takes
7757time proportional to the size of the package, but expect less than a
7758minute for an ``average'' package on a recent machine.
7759
7760Currently, the graft and the package it replaces (@var{bash-fixed} and
7761@var{bash} in the example above) must have the exact same @code{name}
7762and @code{version} fields. This restriction mostly comes from the fact
7763that grafting works by patching files, including binary files, directly.
7764Other restrictions may apply: for instance, when adding a graft to a
7765package providing a shared library, the original shared library and its
7766replacement must have the same @code{SONAME} and be binary-compatible.
7767
7768
cf4a9129
LC
7769@node Package Modules
7770@section Package Modules
8451a568 7771
cf4a9129
LC
7772From a programming viewpoint, the package definitions of the
7773GNU distribution are provided by Guile modules in the @code{(gnu packages
7774@dots{})} name space@footnote{Note that packages under the @code{(gnu
7775packages @dots{})} module name space are not necessarily ``GNU
7776packages''. This module naming scheme follows the usual Guile module
7777naming convention: @code{gnu} means that these modules are distributed
7778as part of the GNU system, and @code{packages} identifies modules that
7779define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
7780Reference Manual}). For instance, the @code{(gnu packages emacs)}
7781module exports a variable named @code{emacs}, which is bound to a
7782@code{<package>} object (@pxref{Defining Packages}).
113daf62 7783
300868ba 7784The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
7785automatically scanned for packages by the command-line tools. For
7786instance, when running @code{guix package -i emacs}, all the @code{(gnu
7787packages @dots{})} modules are scanned until one that exports a package
7788object whose name is @code{emacs} is found. This package search
7789facility is implemented in the @code{(gnu packages)} module.
113daf62 7790
300868ba 7791@cindex customization, of packages
8689901f 7792@cindex package module search path
cf4a9129 7793Users can store package definitions in modules with different
60142854 7794names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
7795name and module name must match. For instance, the @code{(my-packages
7796emacs)} module must be stored in a @file{my-packages/emacs.scm} file
7797relative to the load path specified with @option{--load-path} or
7798@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
7799guile, GNU Guile Reference Manual}, for details.}. These package definitions
300868ba
LC
7800will not be visible by default. Thus, users can invoke commands such as
7801@command{guix package} and @command{guix build} have to be used with the
c95ded7e
LC
7802@code{-e} option so that they know where to find the package. Better
7803yet, they can use the
300868ba 7804@code{-L} option of these commands to make those modules visible
8689901f
LC
7805(@pxref{Invoking guix build, @code{--load-path}}), or define the
7806@code{GUIX_PACKAGE_PATH} environment variable. This environment
7807variable makes it easy to extend or customize the distribution and is
7808honored by all the user interfaces.
7809
7810@defvr {Environment Variable} GUIX_PACKAGE_PATH
7811This is a colon-separated list of directories to search for package
7812modules. Directories listed in this variable take precedence over the
7813distribution's own modules.
7814@end defvr
ef5dd60a 7815
cf4a9129
LC
7816The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
7817each package is built based solely on other packages in the
7818distribution. The root of this dependency graph is a small set of
7819@dfn{bootstrap binaries}, provided by the @code{(gnu packages
7820bootstrap)} module. For more information on bootstrapping,
081145cf 7821@pxref{Bootstrapping}.
ef5dd60a 7822
cf4a9129
LC
7823@node Packaging Guidelines
7824@section Packaging Guidelines
ef5dd60a 7825
cf4a9129
LC
7826The GNU distribution is nascent and may well lack some of your favorite
7827packages. This section describes how you can help make the distribution
7828grow. @xref{Contributing}, for additional information on how you can
7829help.
ef5dd60a 7830
cf4a9129
LC
7831Free software packages are usually distributed in the form of
7832@dfn{source code tarballs}---typically @file{tar.gz} files that contain
7833all the source files. Adding a package to the distribution means
7834essentially two things: adding a @dfn{recipe} that describes how to
7835build the package, including a list of other packages required to build
7836it, and adding @dfn{package meta-data} along with that recipe, such as a
7837description and licensing information.
ef5dd60a 7838
cf4a9129
LC
7839In Guix all this information is embodied in @dfn{package definitions}.
7840Package definitions provide a high-level view of the package. They are
7841written using the syntax of the Scheme programming language; in fact,
7842for each package we define a variable bound to the package definition,
7843and export that variable from a module (@pxref{Package Modules}).
7844However, in-depth Scheme knowledge is @emph{not} a prerequisite for
7845creating packages. For more information on package definitions,
081145cf 7846@pxref{Defining Packages}.
ef5dd60a 7847
cf4a9129
LC
7848Once a package definition is in place, stored in a file in the Guix
7849source tree, it can be tested using the @command{guix build} command
7850(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
7851called @code{gnew}, you may run this command from the Guix build tree
7852(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
7853
7854@example
cf4a9129 7855./pre-inst-env guix build gnew --keep-failed
ef5dd60a 7856@end example
ef5dd60a 7857
cf4a9129
LC
7858Using @code{--keep-failed} makes it easier to debug build failures since
7859it provides access to the failed build tree. Another useful
7860command-line option when debugging is @code{--log-file}, to access the
7861build log.
ef5dd60a 7862
cf4a9129
LC
7863If the package is unknown to the @command{guix} command, it may be that
7864the source file contains a syntax error, or lacks a @code{define-public}
7865clause to export the package variable. To figure it out, you may load
7866the module from Guile to get more information about the actual error:
ef5dd60a 7867
cf4a9129
LC
7868@example
7869./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
7870@end example
ef5dd60a 7871
cf4a9129
LC
7872Once your package builds correctly, please send us a patch
7873(@pxref{Contributing}). Well, if you need help, we will be happy to
7874help you too. Once the patch is committed in the Guix repository, the
7875new package automatically gets built on the supported platforms by
2b1cee21 7876@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 7877system}.
ef5dd60a 7878
cf4a9129
LC
7879@cindex substituter
7880Users can obtain the new package definition simply by running
7881@command{guix pull} (@pxref{Invoking guix pull}). When
7882@code{hydra.gnu.org} is done building the package, installing the
7883package automatically downloads binaries from there
7884(@pxref{Substitutes}). The only place where human intervention is
7885needed is to review and apply the patch.
ef5dd60a 7886
ef5dd60a 7887
cf4a9129 7888@menu
ec0339cd
LC
7889* Software Freedom:: What may go into the distribution.
7890* Package Naming:: What's in a name?
7891* Version Numbers:: When the name is not enough.
cbd02397 7892* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
7893* Python Modules:: Taming the snake.
7894* Perl Modules:: Little pearls.
7895* Fonts:: Fond of fonts.
cf4a9129 7896@end menu
ef5dd60a 7897
cf4a9129
LC
7898@node Software Freedom
7899@subsection Software Freedom
ef5dd60a 7900
cf4a9129 7901@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 7902
cf4a9129
LC
7903The GNU operating system has been developed so that users can have
7904freedom in their computing. GNU is @dfn{free software}, meaning that
7905users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
7906essential freedoms}: to run the program, to study and change the program
7907in source code form, to redistribute exact copies, and to distribute
7908modified versions. Packages found in the GNU distribution provide only
7909software that conveys these four freedoms.
c11a6eb1 7910
cf4a9129
LC
7911In addition, the GNU distribution follow the
7912@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
7913software distribution guidelines}. Among other things, these guidelines
7914reject non-free firmware, recommendations of non-free software, and
7915discuss ways to deal with trademarks and patents.
ef5dd60a 7916
cf4a9129
LC
7917Some packages contain a small and optional subset that violates the
7918above guidelines, for instance because this subset is itself non-free
7919code. When that happens, the offending items are removed with
7920appropriate patches or code snippets in the package definition's
7921@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
7922build --source} returns the ``freed'' source rather than the unmodified
7923upstream source.
ef5dd60a 7924
ef5dd60a 7925
cf4a9129
LC
7926@node Package Naming
7927@subsection Package Naming
ef5dd60a 7928
cf4a9129
LC
7929A package has actually two names associated with it:
7930First, there is the name of the @emph{Scheme variable}, the one following
7931@code{define-public}. By this name, the package can be made known in the
7932Scheme code, for instance as input to another package. Second, there is
7933the string in the @code{name} field of a package definition. This name
7934is used by package management commands such as
7935@command{guix package} and @command{guix build}.
ef5dd60a 7936
cf4a9129
LC
7937Both are usually the same and correspond to the lowercase conversion of
7938the project name chosen upstream, with underscores replaced with
7939hyphens. For instance, GNUnet is available as @code{gnunet}, and
7940SDL_net as @code{sdl-net}.
927097ef 7941
cf4a9129 7942We do not add @code{lib} prefixes for library packages, unless these are
081145cf 7943already part of the official project name. But @pxref{Python
cf4a9129
LC
7944Modules} and @ref{Perl Modules} for special rules concerning modules for
7945the Python and Perl languages.
927097ef 7946
1b366ee4 7947Font package names are handled differently, @pxref{Fonts}.
7fec52b7 7948
ef5dd60a 7949
cf4a9129
LC
7950@node Version Numbers
7951@subsection Version Numbers
ef5dd60a 7952
cf4a9129
LC
7953We usually package only the latest version of a given free software
7954project. But sometimes, for instance for incompatible library versions,
7955two (or more) versions of the same package are needed. These require
7956different Scheme variable names. We use the name as defined
7957in @ref{Package Naming}
7958for the most recent version; previous versions use the same name, suffixed
7959by @code{-} and the smallest prefix of the version number that may
7960distinguish the two versions.
ef5dd60a 7961
cf4a9129
LC
7962The name inside the package definition is the same for all versions of a
7963package and does not contain any version number.
ef5dd60a 7964
cf4a9129 7965For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 7966
cf4a9129
LC
7967@example
7968(define-public gtk+
7969 (package
17d8e33f
ML
7970 (name "gtk+")
7971 (version "3.9.12")
7972 ...))
cf4a9129
LC
7973(define-public gtk+-2
7974 (package
17d8e33f
ML
7975 (name "gtk+")
7976 (version "2.24.20")
7977 ...))
cf4a9129
LC
7978@end example
7979If we also wanted GTK+ 3.8.2, this would be packaged as
7980@example
7981(define-public gtk+-3.8
7982 (package
17d8e33f
ML
7983 (name "gtk+")
7984 (version "3.8.2")
7985 ...))
cf4a9129 7986@end example
ef5dd60a 7987
cbd02397
LC
7988@node Synopses and Descriptions
7989@subsection Synopses and Descriptions
7990
7991As we have seen before, each package in GNU@tie{}Guix includes a
7992synopsis and a description (@pxref{Defining Packages}). Synopses and
7993descriptions are important: They are what @command{guix package
7994--search} searches, and a crucial piece of information to help users
7995determine whether a given package suits their needs. Consequently,
7996packagers should pay attention to what goes into them.
7997
7998Synopses must start with a capital letter and must not end with a
7999period. They must not start with ``a'' or ``the'', which usually does
8000not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
8001tool that frobs files''. The synopsis should say what the package
8002is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
8003used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
8004matching a pattern''.
8005
8006Keep in mind that the synopsis must be meaningful for a very wide
8007audience. For example, ``Manipulate alignments in the SAM format''
8008might make sense for a seasoned bioinformatics researcher, but might be
8009fairly unhelpful or even misleading to a non-specialized audience. It
8010is a good idea to come up with a synopsis that gives an idea of the
8011application domain of the package. In this example, this might give
8012something like ``Manipulate nucleotide sequence alignments'', which
8013hopefully gives the user a better idea of whether this is what they are
8014looking for.
8015
8016@cindex Texinfo markup, in package descriptions
8017Descriptions should take between five and ten lines. Use full
8018sentences, and avoid using acronyms without first introducing them.
8019Descriptions can include Texinfo markup, which is useful to introduce
8020ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
8021hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
8022should be careful when using some characters for example @samp{@@} and
8023curly braces which are the basic special characters in Texinfo
8024(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
8025such as @command{guix package --show} take care of rendering it
8026appropriately.
cbd02397
LC
8027
8028Synopses and descriptions are translated by volunteers
8029@uref{http://translationproject.org/domain/guix-packages.html, at the
8030Translation Project} so that as many users as possible can read them in
8031their native language. User interfaces search them and display them in
8032the language specified by the current locale.
8033
8034Translation is a lot of work so, as a packager, please pay even more
8035attention to your synopses and descriptions as every change may entail
ba7d6c76 8036additional work for translators. In order to help them, it is possible
36743e71 8037to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
8038special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
8039Gettext}):
8040
8041@example
8042;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
8043(description "ARandR is designed to provide a simple visual front end
8044for the X11 resize-and-rotate (RandR) extension. @dots{}")
8045@end example
cbd02397 8046
ef5dd60a 8047
cf4a9129
LC
8048@node Python Modules
8049@subsection Python Modules
ef5dd60a 8050
cf4a9129
LC
8051We currently package Python 2 and Python 3, under the Scheme variable names
8052@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
8053To avoid confusion and naming clashes with other programming languages, it
8054seems desirable that the name of a package for a Python module contains
8055the word @code{python}.
ef5dd60a 8056
cf4a9129
LC
8057Some modules are compatible with only one version of Python, others with both.
8058If the package Foo compiles only with Python 3, we name it
8059@code{python-foo}; if it compiles only with Python 2, we name it
8060@code{python2-foo}. If it is compatible with both versions, we create two
8061packages with the corresponding names.
ef5dd60a 8062
cf4a9129
LC
8063If a project already contains the word @code{python}, we drop this;
8064for instance, the module python-dateutil is packaged under the names
8065@code{python-dateutil} and @code{python2-dateutil}.
113daf62 8066
523e4896 8067
cf4a9129
LC
8068@node Perl Modules
8069@subsection Perl Modules
523e4896 8070
cf4a9129
LC
8071Perl programs standing for themselves are named as any other package,
8072using the lowercase upstream name.
8073For Perl packages containing a single class, we use the lowercase class name,
8074replace all occurrences of @code{::} by dashes and prepend the prefix
8075@code{perl-}.
8076So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
8077Modules containing several classes keep their lowercase upstream name and
8078are also prepended by @code{perl-}. Such modules tend to have the word
8079@code{perl} somewhere in their name, which gets dropped in favor of the
8080prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 8081
523e4896 8082
7fec52b7
AE
8083@node Fonts
8084@subsection Fonts
8085
8086For fonts that are in general not installed by a user for typesetting
8087purposes, or that are distributed as part of a larger software package,
8088we rely on the general packaging rules for software; for instance, this
8089applies to the fonts delivered as part of the X.Org system or fonts that
8090are part of TeX Live.
8091
8092To make it easier for a user to search for fonts, names for other packages
8093containing only fonts are constructed as follows, independently of the
8094upstream package name.
8095
8096The name of a package containing only one font family starts with
8097@code{font-}; it is followed by the foundry name and a dash @code{-}
8098if the foundry is known, and the font family name, in which spaces are
8099replaced by dashes (and as usual, all upper case letters are transformed
8100to lower case).
8101For example, the Gentium font family by SIL is packaged under the name
8102@code{font-sil-gentium}.
8103
8104For a package containing several font families, the name of the collection
8105is used in the place of the font family name.
8106For instance, the Liberation fonts consist of three families,
8107Liberation Sans, Liberation Serif and Liberation Mono.
8108These could be packaged separately under the names
8109@code{font-liberation-sans} and so on; but as they are distributed together
8110under a common name, we prefer to package them together as
8111@code{font-liberation}.
8112
8113In the case where several formats of the same font family or font collection
8114are packaged separately, a short form of the format, prepended by a dash,
8115is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 8116@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
8117fonts.
8118
8119
b25937e3 8120
cf4a9129
LC
8121@node Bootstrapping
8122@section Bootstrapping
b25937e3 8123
cf4a9129 8124@c Adapted from the ELS 2013 paper.
b25937e3 8125
cf4a9129 8126@cindex bootstrapping
7889394e 8127
cf4a9129
LC
8128Bootstrapping in our context refers to how the distribution gets built
8129``from nothing''. Remember that the build environment of a derivation
8130contains nothing but its declared inputs (@pxref{Introduction}). So
8131there's an obvious chicken-and-egg problem: how does the first package
8132get built? How does the first compiler get compiled? Note that this is
8133a question of interest only to the curious hacker, not to the regular
8134user, so you can shamelessly skip this section if you consider yourself
8135a ``regular user''.
72b9d60d 8136
cf4a9129
LC
8137@cindex bootstrap binaries
8138The GNU system is primarily made of C code, with libc at its core. The
8139GNU build system itself assumes the availability of a Bourne shell and
8140command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
8141`grep'. Furthermore, build programs---programs that run
8142@code{./configure}, @code{make}, etc.---are written in Guile Scheme
8143(@pxref{Derivations}). Consequently, to be able to build anything at
8144all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
8145Binutils, libc, and the other packages mentioned above---the
8146@dfn{bootstrap binaries}.
72b9d60d 8147
cf4a9129
LC
8148These bootstrap binaries are ``taken for granted'', though we can also
8149re-create them if needed (more on that later).
72b9d60d 8150
cf4a9129 8151@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 8152
cf4a9129
LC
8153@c As of Emacs 24.3, Info-mode displays the image, but since it's a
8154@c large image, it's hard to scroll. Oh well.
8155@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 8156
cf4a9129
LC
8157The figure above shows the very beginning of the dependency graph of the
8158distribution, corresponding to the package definitions of the @code{(gnu
8159packages bootstrap)} module. At this level of detail, things are
8160slightly complex. First, Guile itself consists of an ELF executable,
8161along with many source and compiled Scheme files that are dynamically
8162loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
8163tarball shown in this graph. This tarball is part of Guix's ``source''
8164distribution, and gets inserted into the store with @code{add-to-store}
8165(@pxref{The Store}).
2e7b5cea 8166
cf4a9129
LC
8167But how do we write a derivation that unpacks this tarball and adds it
8168to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
8169derivation---the first one that gets built---uses @code{bash} as its
8170builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
8171@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
8172@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
8173the Guix source distribution, whose sole purpose is to allow the Guile
8174tarball to be unpacked.
fb729425 8175
cf4a9129
LC
8176Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
8177Guile that can be used to run subsequent build programs. Its first task
8178is to download tarballs containing the other pre-built binaries---this
8179is what the @code{.tar.xz.drv} derivations do. Guix modules such as
8180@code{ftp-client.scm} are used for this purpose. The
8181@code{module-import.drv} derivations import those modules in a directory
8182in the store, using the original layout. The
8183@code{module-import-compiled.drv} derivations compile those modules, and
8184write them in an output directory with the right layout. This
8185corresponds to the @code{#:modules} argument of
8186@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 8187
cf4a9129
LC
8188Finally, the various tarballs are unpacked by the
8189derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
8190etc., at which point we have a working C tool chain.
fb729425 8191
fb729425 8192
cf4a9129 8193@unnumberedsubsec Building the Build Tools
523e4896 8194
cf4a9129
LC
8195@c TODO: Add a package-level dependency graph generated from (gnu
8196@c packages base).
df2ce343 8197
cf4a9129
LC
8198Bootstrapping is complete when we have a full tool chain that does not
8199depend on the pre-built bootstrap tools discussed above. This
8200no-dependency requirement is verified by checking whether the files of
8201the final tool chain contain references to the @file{/gnu/store}
8202directories of the bootstrap inputs. The process that leads to this
8203``final'' tool chain is described by the package definitions found in
1f6f57df 8204the @code{(gnu packages commencement)} module.
df2ce343 8205
cf4a9129
LC
8206@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
8207The first tool that gets built with the bootstrap binaries is
8208GNU Make, which is a prerequisite for all the following packages.
8209From there Findutils and Diffutils get built.
523e4896 8210
cf4a9129
LC
8211Then come the first-stage Binutils and GCC, built as pseudo cross
8212tools---i.e., with @code{--target} equal to @code{--host}. They are
8213used to build libc. Thanks to this cross-build trick, this libc is
8214guaranteed not to hold any reference to the initial tool chain.
4af2447e 8215
cf4a9129
LC
8216From there the final Binutils and GCC are built. GCC uses @code{ld}
8217from the final Binutils, and links programs against the just-built libc.
8218This tool chain is used to build the other packages used by Guix and by
8219the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 8220
cf4a9129
LC
8221And voilà! At this point we have the complete set of build tools that
8222the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
8223variable of the @code{(gnu packages commencement)} module, and are
8224implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 8225(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 8226
4af2447e 8227
cf4a9129 8228@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 8229
cf4a9129
LC
8230Because the final tool chain does not depend on the bootstrap binaries,
8231those rarely need to be updated. Nevertheless, it is useful to have an
8232automated way to produce them, should an update occur, and this is what
8233the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 8234
cf4a9129
LC
8235The following command builds the tarballs containing the bootstrap
8236binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
8237of Coreutils and other basic command-line tools):
4b2615e1 8238
cf4a9129
LC
8239@example
8240guix build bootstrap-tarballs
8241@end example
8242
8243The generated tarballs are those that should be referred to in the
8244@code{(gnu packages bootstrap)} module mentioned at the beginning of
8245this section.
8246
8247Still here? Then perhaps by now you've started to wonder: when do we
8248reach a fixed point? That is an interesting question! The answer is
8249unknown, but if you would like to investigate further (and have
8250significant computational and storage resources to do so), then let us
8251know.
8252
8253@node Porting
8254@section Porting to a New Platform
8255
8256As discussed above, the GNU distribution is self-contained, and
8257self-containment is achieved by relying on pre-built ``bootstrap
8258binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
8259operating system kernel, CPU architecture, and application binary
8260interface (ABI). Thus, to port the distribution to a platform that is
8261not yet supported, one must build those bootstrap binaries, and update
8262the @code{(gnu packages bootstrap)} module to use them on that platform.
8263
8264Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
8265When everything goes well, and assuming the GNU tool chain supports the
8266target platform, this can be as simple as running a command like this
8267one:
8268
8269@example
8270guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
8271@end example
8272
1c0c417d
LC
8273For this to work, the @code{glibc-dynamic-linker} procedure in
8274@code{(gnu packages bootstrap)} must be augmented to return the right
8275file name for libc's dynamic linker on that platform; likewise,
8276@code{system->linux-architecture} in @code{(gnu packages linux)} must be
8277taught about the new platform.
8278
cf4a9129 8279Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
8280to be updated to refer to these binaries on the target platform. That
8281is, the hashes and URLs of the bootstrap tarballs for the new platform
8282must be added alongside those of the currently supported platforms. The
8283bootstrap Guile tarball is treated specially: it is expected to be
8284available locally, and @file{gnu-system.am} has rules do download it for
8285the supported architectures; a rule for the new platform must be added
8286as well.
cf4a9129
LC
8287
8288In practice, there may be some complications. First, it may be that the
8289extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
8290above) is not recognized by all the GNU tools. Typically, glibc
8291recognizes some of these, whereas GCC uses an extra @code{--with-abi}
8292configure flag (see @code{gcc.scm} for examples of how to handle this).
8293Second, some of the required packages could fail to build for that
8294platform. Lastly, the generated binaries could be broken for some
8295reason.
4af2447e 8296
9bf3c1a7 8297@c *********************************************************************
8c01b9d0 8298@include contributing.texi
c78bd12b 8299
568717fd
LC
8300@c *********************************************************************
8301@node Acknowledgments
8302@chapter Acknowledgments
8303
8304Guix is based on the Nix package manager, which was designed and
4c7ac9aa
LC
8305implemented by Eelco Dolstra, with contributions from other people (see
8306the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
8307management, and promoted unprecedented features, such as transactional
8308package upgrades and rollbacks, per-user profiles, and referentially
8309transparent build processes. Without this work, Guix would not exist.
8310
8311The Nix-based software distributions, Nixpkgs and NixOS, have also been
8312an inspiration for Guix.
8313
4c7ac9aa
LC
8314GNU@tie{}Guix itself is a collective work with contributions from a
8315number of people. See the @file{AUTHORS} file in Guix for more
8316information on these fine people. The @file{THANKS} file lists people
8317who have helped by reporting bugs, taking care of the infrastructure,
8318providing artwork and themes, making suggestions, and more---thank you!
8319
8320
568717fd
LC
8321@c *********************************************************************
8322@node GNU Free Documentation License
8323@appendix GNU Free Documentation License
8324
8325@include fdl-1.3.texi
8326
8327@c *********************************************************************
8328@node Concept Index
8329@unnumbered Concept Index
8330@printindex cp
8331
a85b83d2
LC
8332@node Programming Index
8333@unnumbered Programming Index
8334@syncodeindex tp fn
8335@syncodeindex vr fn
568717fd
LC
8336@printindex fn
8337
8338@bye
8339
8340@c Local Variables:
8341@c ispell-local-dictionary: "american";
8342@c End: