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