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