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