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