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