gnu: Add liblangtag.
[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
db5a9444 13Copyright @copyright{} 2012, 2013, 2014, 2015, 2016 Ludovic Courtès@*
f97c9175 14Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
87eafdbd 15Copyright @copyright{} 2013 Nikita Karetnikov@*
1b846da8 16Copyright @copyright{} 2015, 2016 Mathieu Lirzin@*
8c01b9d0 17Copyright @copyright{} 2014 Pierre-Antoine Rault@*
97d76250
LF
18Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
19Copyright @copyright{} 2015, 2016 Leo Famulari
917a2a58 20Copyright @copyright{} 2016 Ben Woodcroft
7df7a74e
NK
21
22Permission is granted to copy, distribute and/or modify this document
23under the terms of the GNU Free Documentation License, Version 1.3 or
24any later version published by the Free Software Foundation; with no
25Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
26copy of the license is included in the section entitled ``GNU Free
27Documentation License''.
28@end copying
568717fd 29
abd67856 30@dircategory System administration
568717fd 31@direntry
abd67856
LC
32* Guix: (guix). Manage installed software and system configuration.
33* guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
34* guix build: (guix)Invoking guix build. Building packages.
35* guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
36* guix pull: (guix)Invoking guix pull. Update the list of available packages.
37* guix system: (guix)Invoking guix system. Manage the operating system configuration.
568717fd 38@end direntry
568717fd 39
372c4bbc
DT
40@dircategory Software development
41@direntry
abd67856 42* guix environment: (guix)Invoking guix environment. Building development environments with Guix.
372c4bbc
DT
43@end direntry
44
abd67856
LC
45@dircategory Emacs
46@direntry
47* Guix user interface: (guix)Emacs Interface. Package management from the comfort of Emacs.
48@end direntry
49
50
568717fd 51@titlepage
7730d112
LC
52@title GNU Guix Reference Manual
53@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 54@author The GNU Guix Developers
568717fd
LC
55
56@page
57@vskip 0pt plus 1filll
58Edition @value{EDITION} @*
59@value{UPDATED} @*
60
7df7a74e 61@insertcopying
568717fd
LC
62@end titlepage
63
568717fd
LC
64@contents
65
66@c *********************************************************************
67@node Top
f8348b91 68@top GNU Guix
568717fd 69
f8348b91
LC
70This document describes GNU Guix version @value{VERSION}, a functional
71package management tool written for the GNU system.
568717fd
LC
72
73@menu
74* Introduction:: What is Guix about?
bd5e766b 75* Installation:: Installing Guix.
eeaf4427 76* Package Management:: Package installation, upgrade, etc.
c554de89 77* Emacs Interface:: Using Guix from Emacs.
568717fd
LC
78* Programming Interface:: Using Guix in Scheme.
79* Utilities:: Package management commands.
a1ba8475 80* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 81* Contributing:: Your help needed!
568717fd
LC
82
83* Acknowledgments:: Thanks!
84* GNU Free Documentation License:: The license of this manual.
85* Concept Index:: Concepts.
a85b83d2 86* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
87
88@detailmenu
89 --- The Detailed Node Listing ---
90
91Installation
92
1b2b8177 93* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 94* Requirements:: Software needed to build and run Guix.
ec0339cd 95* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
96* Setting Up the Daemon:: Preparing the build daemon's environment.
97* Invoking guix-daemon:: Running the build daemon.
0e2d0213 98* Application Setup:: Application-specific setup.
aaa3eaa9
LC
99
100Setting Up the Daemon
101
102* Build Environment Setup:: Preparing the isolated build environment.
103* Daemon Offload Setup:: Offloading builds to remote machines.
104
105Package Management
106
107* Features:: How Guix will make your life brighter.
108* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
109* Substitutes:: Downloading pre-built binaries.
110* Packages with Multiple Outputs:: Single source package, multiple outputs.
111* Invoking guix gc:: Running the garbage collector.
112* Invoking guix pull:: Fetching the latest Guix and distribution.
113* Invoking guix archive:: Exporting and importing store files.
114
c554de89
AK
115Emacs Interface
116
117* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
118* Package Management: Emacs Package Management. Managing packages and generations.
687c9bc0 119* Licenses: Emacs Licenses. Interface for licenses of Guix packages.
9b0afb0d 120* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
c554de89 121* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
34850cd5 122* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
187f80c6
AK
123* Completions: Emacs Completions. Completing @command{guix} shell command.
124* Development: Emacs Development. Tools for Guix developers.
32950fc8 125* Hydra: Emacs Hydra. Interface for Guix build farm.
c554de89 126
aaa3eaa9
LC
127Programming Interface
128
129* Defining Packages:: Defining new packages.
130* Build Systems:: Specifying how packages are built.
131* The Store:: Manipulating the package store.
132* Derivations:: Low-level interface to package derivations.
133* The Store Monad:: Purely functional interface to the store.
134* G-Expressions:: Manipulating build expressions.
135
92492b23
LC
136Defining Packages
137
138* package Reference:: The package data type.
139* origin Reference:: The origin data type.
140
aaa3eaa9
LC
141Utilities
142
143* Invoking guix build:: Building packages from the command line.
fcc58db6 144* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
145* Invoking guix download:: Downloading a file and printing its hash.
146* Invoking guix hash:: Computing the cryptographic hash of a file.
147* Invoking guix import:: Importing package definitions.
148* Invoking guix refresh:: Updating package definitions.
149* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 150* Invoking guix size:: Profiling disk usage.
88856916 151* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 152* Invoking guix environment:: Setting up development environments.
aff8ce7c 153* Invoking guix publish:: Sharing substitutes.
d23c20f1 154* Invoking guix challenge:: Challenging substitute servers.
32efa254 155* Invoking guix container:: Process isolation.
aaa3eaa9
LC
156
157GNU Distribution
158
159* System Installation:: Installing the whole operating system.
35ed9306 160* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
161* Installing Debugging Files:: Feeding the debugger.
162* Security Updates:: Deploying security fixes quickly.
163* Package Modules:: Packages from the programmer's viewpoint.
164* Packaging Guidelines:: Growing the distribution.
165* Bootstrapping:: GNU/Linux built from scratch.
166* Porting:: Targeting another platform or kernel.
167
168System Configuration
169
170* Using the Configuration System:: Customizing your GNU system.
171* operating-system Reference:: Detail of operating-system declarations.
172* File Systems:: Configuring file system mounts.
173* Mapped Devices:: Block device extra processing.
174* User Accounts:: Specifying user accounts.
598e19dc 175* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
176* Services:: Specifying system services.
177* Setuid Programs:: Programs running with root privileges.
1b2b8177 178* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 179* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
180* Initial RAM Disk:: Linux-Libre bootstrapping.
181* GRUB Configuration:: Configuring the boot loader.
182* Invoking guix system:: Instantiating a system configuration.
97d76250 183* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
aaa3eaa9
LC
184* Defining Services:: Adding new service definitions.
185
186Services
187
188* Base Services:: Essential system services.
189* Networking Services:: Network setup, SSH daemon, etc.
190* X Window:: Graphical display.
1b2b8177
LC
191* Desktop Services:: D-Bus and desktop services.
192* Database Services:: SQL databases.
d8c18af8 193* Mail Services:: IMAP, POP3, SMTP, and all that.
cbd02397 194* Web Services:: Web servers.
aa4ed923 195* Various Services:: Other services.
aaa3eaa9 196
0adfe95a
LC
197Defining Services
198
199* Service Composition:: The model for composing services.
200* Service Types and Services:: Types and services.
201* Service Reference:: API reference.
dd17bc38 202* Shepherd Services:: A particular type of service.
0adfe95a 203
aaa3eaa9
LC
204Packaging Guidelines
205
ec0339cd
LC
206* Software Freedom:: What may go into the distribution.
207* Package Naming:: What's in a name?
208* Version Numbers:: When the name is not enough.
cbd02397 209* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
210* Python Modules:: Taming the snake.
211* Perl Modules:: Little pearls.
212* Fonts:: Fond of fonts.
aaa3eaa9 213
8c01b9d0
ML
214Contributing
215
216* Building from Git:: The latest and greatest.
217* Running Guix Before It Is Installed:: Hacker tricks.
218* The Perfect Setup:: The right tools.
219* Coding Style:: Hygiene of the contributor.
220* Submitting Patches:: Share your work.
221
222Coding Style
223
224* Programming Paradigm:: How to compose your elements.
225* Modules:: Where to store your code?
226* Data Types and Pattern Matching:: Implementing data structures.
227* Formatting Code:: Writing conventions.
228
aaa3eaa9 229@end detailmenu
568717fd
LC
230@end menu
231
232@c *********************************************************************
233@node Introduction
234@chapter Introduction
235
c80e7e55
LC
236GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
237using the international phonetic alphabet (IPA).} is a functional
238package management tool for the GNU system. Package management consists
4bfc4ea3
NK
239of all activities that relate to building packages from sources,
240honoring their build-time and run-time dependencies,
c80e7e55
LC
241installing packages in user environments, upgrading installed packages
242to new versions or rolling back to a previous set, removing unused
243software packages, etc.
568717fd
LC
244
245@cindex functional package management
246The term @dfn{functional} refers to a specific package management
136787cb
LC
247discipline pioneered by Nix (@pxref{Acknowledgments}).
248In Guix, the package build and installation process is seen
4bfc4ea3
NK
249as a function, in the mathematical sense. That function takes inputs,
250such as build scripts, a compiler, and libraries, and
251returns an installed package. As a pure function, its result depends
568717fd
LC
252solely on its inputs---for instance, it cannot refer to software or
253scripts that were not explicitly passed as inputs. A build function
4bfc4ea3 254always produces the same result when passed a given set of inputs. It
f97c9175 255cannot alter the environment of the running system in
568717fd
LC
256any way; for instance, it cannot create, modify, or delete files outside
257of its build and installation directories. This is achieved by running
e900c503 258build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 259explicit inputs are visible.
568717fd 260
e531ac2a 261@cindex store
568717fd 262The result of package build functions is @dfn{cached} in the file
e531ac2a 263system, in a special directory called @dfn{the store} (@pxref{The
f97c9175 264Store}). Each package is installed in a directory of its own in the
834129e0 265store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
266a hash of all the inputs used to build that package; thus, changing an
267input yields a different directory name.
268
f97c9175
AE
269This approach is the foundation for the salient features of Guix: support
270for transactional package upgrade and rollback, per-user installation, and
eeaf4427 271garbage collection of packages (@pxref{Features}).
568717fd 272
4bfc4ea3 273Guix has a command-line interface, which allows users to build, install,
568717fd 274upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 275
3ca2731c 276@cindex Guix System Distribution
4705641f 277@cindex GuixSD
a1ba8475 278Last but not least, Guix is used to build a distribution of the GNU
3ca2731c 279system, with many GNU and non-GNU free software packages. The Guix
4705641f
LC
280System Distribution, or GNU@tie{}GuixSD, takes advantage of the core
281properties of Guix at the system level. With GuixSD, users
3ca2731c
LC
282@emph{declare} all aspects of the operating system configuration, and
283Guix takes care of instantiating that configuration in a reproducible,
284stateless fashion. @xref{GNU Distribution}.
a1ba8475 285
bd5e766b
LC
286@c *********************************************************************
287@node Installation
288@chapter Installation
289
48febeb8
LC
290GNU Guix is available for download from its website at
291@url{http://www.gnu.org/software/guix/}. This section describes the
292software requirements of Guix, as well as how to install it and get
293ready to use it.
bd5e766b 294
5af6de3e
LC
295Note that this section is concerned with the installation of the package
296manager, which can be done on top of a running GNU/Linux system. If,
297instead, you want to install the complete GNU operating system,
6621cdb6 298@pxref{System Installation}.
5af6de3e 299
bd5e766b 300@menu
09722b11 301* Binary Installation:: Getting Guix running in no time!
bd5e766b 302* Requirements:: Software needed to build and run Guix.
ec0339cd 303* Running the Test Suite:: Testing Guix.
bd5e766b
LC
304* Setting Up the Daemon:: Preparing the build daemon's environment.
305* Invoking guix-daemon:: Running the build daemon.
0e2d0213 306* Application Setup:: Application-specific setup.
bd5e766b
LC
307@end menu
308
09722b11
LC
309@node Binary Installation
310@section Binary Installation
311
312This section describes how to install Guix on an arbitrary system from a
313self-contained tarball providing binaries for Guix and for all its
314dependencies. This is often quicker than installing from source, which
315is described in the next sections. The only requirement is to have
316GNU@tie{}tar and Xz.
317
318Installing goes along these lines:
319
320@enumerate
321@item
322Download the binary tarball from
daa8922a
LC
323@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
324where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
325already running the kernel Linux, and so on.
326
327Make sure to download the associated @file{.sig} file and to verify the
328authenticity of the tarball against it, along these lines:
329
330@example
331$ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
332$ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
333@end example
334
f97c9175 335If that command fails because you do not have the required public key,
daa8922a
LC
336then run this command to import it:
337
338@example
339$ gpg --keyserver keys.gnupg.net --recv-keys 3D9AEBB5
340@end example
341
342@noindent
343and rerun the @code{gpg --verify} command.
09722b11
LC
344
345@item
346As @code{root}, run:
347
348@example
5dc42964 349# cd /tmp
254b1c2e
LC
350# tar --warning=no-timestamp -xf \
351 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 352# mv var/guix /var/ && mv gnu /
09722b11
LC
353@end example
354
7acd3439
LC
355This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
356The latter contains a ready-to-use profile for @code{root} (see next
357step.)
09722b11 358
5dc3ce5f
LC
359Do @emph{not} unpack the tarball on a working Guix system since that
360would overwrite its own essential files.
361
254b1c2e 362The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
363not emit warnings about ``implausibly old time stamps'' (such
364warnings were triggered by GNU@tie{}tar 1.26 and older; recent
365versions are fine.)
366They stem from the fact that all the
254b1c2e
LC
367files in the archive have their modification time set to zero (which
368means January 1st, 1970.) This is done on purpose to make sure the
369archive content is independent of its creation time, thus making it
370reproducible.
371
7acd3439
LC
372@item
373Make @code{root}'s profile available under @file{~/.guix-profile}:
374
375@example
376# ln -sf /var/guix/profiles/per-user/root/guix-profile \
377 ~root/.guix-profile
378@end example
379
43c33047
LC
380@item
381Create the group and user accounts for build users as explained below
382(@pxref{Build Environment Setup}).
383
09722b11 384@item
bf98aea9 385Run the daemon, and set it to automatically start on boot.
c8e26887 386
bf98aea9
LC
387If your host distro uses the systemd init system, this can be achieved
388with these commands:
c8e26887
GC
389
390@example
391# cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
392 /etc/systemd/system/
393# systemctl start guix-daemon && systemctl enable guix-daemon
394@end example
395
396If your host distro uses the Upstart init system:
09722b11
LC
397
398@example
c8e26887 399# cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
bf98aea9 400# start guix-daemon
09722b11
LC
401@end example
402
c8e26887
GC
403Otherwise, you can still start the daemon manually with:
404
405@example
406# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
407@end example
d2825c96 408
09722b11
LC
409@item
410Make the @command{guix} command available to other users on the machine,
411for instance with:
412
413@example
414# mkdir -p /usr/local/bin
415# cd /usr/local/bin
d72d05f9 416# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 417@end example
39f8ed14 418
aca738f3
LC
419It is also a good idea to make the Info version of this manual available
420there:
421
422@example
423# mkdir -p /usr/local/share/info
424# cd /usr/local/share/info
425# for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
426 do ln -s $i ; done
427@end example
428
429That way, assuming @file{/usr/local/share/info} is in the search path,
430running @command{info guix} will open this manual (@pxref{Other Info
431Directories,,, texinfo, GNU Texinfo}, for more details on changing the
432Info search path.)
433
39f8ed14
LC
434@item
435To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}),
436authorize them:
437
438@example
7acd3439 439# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 440@end example
09722b11
LC
441@end enumerate
442
bf98aea9 443This completes root-level install of Guix. Each user will need to
c8e26887
GC
444perform additional steps to make their Guix envionment ready for use,
445@pxref{Application Setup}.
09722b11 446
c8e26887
GC
447You can confirm that Guix is working by installing a sample package into
448the root profile:
09722b11
LC
449
450@example
c8e26887 451# guix package -i hello
09722b11
LC
452@end example
453
c8e26887
GC
454The @code{guix} package must remain available in @code{root}'s profile,
455or it would become subject to garbage collection---in which case you
456would find yourself badly handicapped by the lack of the @command{guix}
bf98aea9
LC
457command. In other words, do not remove @code{guix} by running
458@code{guix package -r guix}.
459
460The binary installation tarball can be (re)produced and verified simply
461by running the following command in the Guix source tree:
462
463@example
464make guix-binary.@var{system}.tar.xz
465@end example
c8e26887 466
09722b11 467
bd5e766b
LC
468@node Requirements
469@section Requirements
470
09722b11
LC
471This section lists requirements when building Guix from source. The
472build procedure for Guix is the same as for other GNU software, and is
473not covered here. Please see the files @file{README} and @file{INSTALL}
474in the Guix source tree for additional details.
475
bd5e766b
LC
476GNU Guix depends on the following packages:
477
478@itemize
47c66da0 479@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 480@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 481@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
482@end itemize
483
484The following dependencies are optional:
485
486@itemize
288dca55 487@item
8a96bd4b 488Installing
288dca55 489@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
490allow you to use the @command{guix import pypi} command (@pxref{Invoking
491guix import}). It is of
288dca55 492interest primarily for developers and not for casual users.
8a96bd4b
ID
493@item
494Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
495allow you to access @code{https} URLs with the @command{guix download}
d45dc6da
EB
496command (@pxref{Invoking guix download}), the @command{guix import pypi}
497command, and the @command{guix import cpan} command. This is primarily
498of interest to developers. @xref{Guile Preparations, how to install the
499GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
bd5e766b
LC
500@end itemize
501
502Unless @code{--disable-daemon} was passed to @command{configure}, the
503following packages are also needed:
504
505@itemize
368d08f7
LC
506@item @url{http://sqlite.org, SQLite 3};
507@item @url{http://www.bzip.org, libbz2};
508@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
509C++11 standard.
bd5e766b
LC
510@end itemize
511
4bfc4ea3
NK
512When a working installation of @url{http://nixos.org/nix/, the Nix package
513manager} is available, you
bd5e766b 514can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 515Nix replaces the three dependencies above.
bd5e766b 516
b22a12fd
LC
517Guix is compatible with Nix, so it is possible to share the same store
518between both. To do so, you must pass @command{configure} not only the
519same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
520@code{--localstatedir} value. The latter is essential because it
521specifies where the database that stores metadata about the store is
834129e0 522located, among other things. The default values for Nix are
b22a12fd 523@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
524Note that @code{--disable-daemon} is not required if
525your goal is to share the store with Nix.
b22a12fd 526
ec0339cd
LC
527@node Running the Test Suite
528@section Running the Test Suite
529
530After a successful @command{configure} and @code{make} run, it is a good
531idea to run the test suite. It can help catch issues with the setup or
532environment, or bugs in Guix itself---and really, reporting test
533failures is a good way to help improve the software. To run the test
534suite, type:
535
536@example
537make check
538@end example
539
540Test cases can run in parallel: you can use the @code{-j} option of
541GNU@tie{}make to speed things up. The first run may take a few minutes
542on a recent machine; subsequent runs will be faster because the store
543that is created for test purposes will already have various things in
544cache.
545
a887fd8d
LC
546It is also possible to run a subset of the tests by defining the
547@code{TESTS} makefile variable as in this example:
548
549@example
550make check TESTS="tests/store.scm tests/cpio.scm"
551@end example
552
ec0339cd
LC
553Upon failure, please email @email{bug-guix@@gnu.org} and attach the
554@file{test-suite.log} file. When @file{tests/@var{something}.scm}
555fails, please also attach the @file{@var{something}.log} file available
556in the top-level build directory. Please specify the Guix version being
557used as well as version numbers of the dependencies
558(@pxref{Requirements}) in your message.
559
bd5e766b
LC
560@node Setting Up the Daemon
561@section Setting Up the Daemon
562
563@cindex daemon
564Operations such as building a package or running the garbage collector
49e6291a 565are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
566behalf of clients. Only the daemon may access the store and its
567associated database. Thus, any operation that manipulates the store
568goes through the daemon. For instance, command-line tools such as
e49951eb 569@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
570daemon (@i{via} remote procedure calls) to instruct it what to do.
571
49e6291a 572The following sections explain how to prepare the build daemon's
f97c9175 573environment. See also @ref{Substitutes}, for information on how to allow
225dafde 574the daemon to download pre-built binaries.
49e6291a
LC
575
576@menu
577* Build Environment Setup:: Preparing the isolated build environment.
578* Daemon Offload Setup:: Offloading builds to remote machines.
579@end menu
580
581@node Build Environment Setup
582@subsection Build Environment Setup
583
bd5e766b
LC
584In a standard multi-user setup, Guix and its daemon---the
585@command{guix-daemon} program---are installed by the system
834129e0 586administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
587@command{guix-daemon} runs as @code{root}. Unprivileged users may use
588Guix tools to build packages or otherwise access the store, and the
589daemon will do it on their behalf, ensuring that the store is kept in a
590consistent state, and allowing built packages to be shared among users.
591
592@cindex build users
593When @command{guix-daemon} runs as @code{root}, you may not want package
594build processes themselves to run as @code{root} too, for obvious
595security reasons. To avoid that, a special pool of @dfn{build users}
596should be created for use by build processes started by the daemon.
597These build users need not have a shell and a home directory: they will
598just be used when the daemon drops @code{root} privileges in build
599processes. Having several such users allows the daemon to launch
600distinct build processes under separate UIDs, which guarantees that they
601do not interfere with each other---an essential feature since builds are
602regarded as pure functions (@pxref{Introduction}).
603
604On a GNU/Linux system, a build user pool may be created like this (using
605Bash syntax and the @code{shadow} commands):
606
091196b3
LC
607@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
608@c for why `-G' is needed.
bd5e766b 609@example
cfc149dc
LC
610# groupadd --system guixbuild
611# for i in `seq -w 1 10`;
bd5e766b 612 do
cfc149dc
LC
613 useradd -g guixbuild -G guixbuild \
614 -d /var/empty -s `which nologin` \
615 -c "Guix build user $i" --system \
616 guixbuilder$i;
bd5e766b
LC
617 done
618@end example
619
620@noindent
54eb03ab
LC
621The number of build users determines how many build jobs may run in
622parallel, as specified by the @option{--max-jobs} option
d2825c96
LC
623(@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
624@code{guix-daemon} program may then be run as @code{root} with the
625following command@footnote{If your machine uses the systemd init system,
626dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
627file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
628@command{guix-daemon} is automatically started. Similarly, if your
629machine uses the Upstart init system, drop the
630@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
631file in @file{/etc/init}.}:
bd5e766b
LC
632
633@example
cfc149dc 634# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
635@end example
636
e900c503 637@cindex chroot
b095792f
LC
638@noindent
639This way, the daemon starts build processes in a chroot, under one of
cfc149dc 640the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
641environment contains nothing but:
642
643@c Keep this list in sync with libstore/build.cc! -----------------------
644@itemize
645@item
4743a4da
LC
646a minimal @code{/dev} directory, created mostly independently from the
647host @code{/dev}@footnote{``Mostly'', because while the set of files
648that appear in the chroot's @code{/dev} is fixed, most of these files
649can only be created if the host has them.};
650
651@item
f97c9175 652the @code{/proc} directory; it only shows the processes of the container
4743a4da 653since a separate PID name space is used;
6dc99317
LC
654
655@item
656@file{/etc/passwd} with an entry for the current user and an entry for
657user @file{nobody};
658
659@item
660@file{/etc/group} with an entry for the user's group;
661
662@item
663@file{/etc/hosts} with an entry that maps @code{localhost} to
664@code{127.0.0.1};
665
666@item
667a writable @file{/tmp} directory.
668@end itemize
b095792f 669
cb960102
ED
670You can influence the directory where the daemon stores build trees
671@i{via} the @code{TMPDIR} environment variable. However, the build tree
f97c9175 672within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
673where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
674This way, the value of @code{TMPDIR} does not leak inside build
675environments, which avoids discrepancies in cases where build processes
676capture the name of their build tree.
677
e0c941fe
LC
678@vindex http_proxy
679The daemon also honors the @code{http_proxy} environment variable for
680HTTP downloads it performs, be it for fixed-output derivations
681(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
682
1e2644bb
LC
683If you are installing Guix as an unprivileged user, it is still possible
684to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
685However, build processes will not be isolated from one another, and not
686from the rest of the system. Thus, build processes may interfere with
687each other, and may access programs, libraries, and other files
688available on the system---making it much harder to view them as
689@emph{pure} functions.
bd5e766b 690
49e6291a
LC
691
692@node Daemon Offload Setup
693@subsection Using the Offload Facility
694
695@cindex offloading
4ec2e92d
LC
696@cindex build hook
697When desired, the build daemon can @dfn{offload}
698derivation builds to other machines
49e6291a
LC
699running Guix, using the @code{offload} @dfn{build hook}. When that
700feature is enabled, a list of user-specified build machines is read from
f97c9175 701@file{/etc/guix/machines.scm}; every time a build is requested, for
49e6291a 702instance via @code{guix build}, the daemon attempts to offload it to one
f97c9175 703of the machines that satisfy the constraints of the derivation, in
49e6291a
LC
704particular its system type---e.g., @file{x86_64-linux}. Missing
705prerequisites for the build are copied over SSH to the target machine,
706which then proceeds with the build; upon success the output(s) of the
707build are copied back to the initial machine.
708
4ec2e92d 709The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
710
711@example
712(list (build-machine
713 (name "eightysix.example.org")
714 (system "x86_64-linux")
715 (user "bob")
716 (speed 2.)) ; incredibly fast!
717
718 (build-machine
719 (name "meeps.example.org")
720 (system "mips64el-linux")
721 (user "alice")
722 (private-key
723 (string-append (getenv "HOME")
c4fdfd6f 724 "/.lsh/identity-for-guix"))))
49e6291a
LC
725@end example
726
727@noindent
728In the example above we specify a list of two build machines, one for
729the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
730architecture.
731
732In fact, this file is---not surprisingly!---a Scheme file that is
733evaluated when the @code{offload} hook is started. Its return value
734must be a list of @code{build-machine} objects. While this example
735shows a fixed list of build machines, one could imagine, say, using
736DNS-SD to return a list of potential build machines discovered in the
737local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
738Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
739detailed below.
4ec2e92d 740
c678a4ee 741@deftp {Data Type} build-machine
f97c9175
AE
742This data type represents build machines to which the daemon may offload
743builds. The important fields are:
49e6291a
LC
744
745@table @code
746
747@item name
f97c9175 748The host name of the remote machine.
49e6291a
LC
749
750@item system
f97c9175 751The system type of the remote machine---e.g., @code{"x86_64-linux"}.
49e6291a
LC
752
753@item user
754The user account to use when connecting to the remote machine over SSH.
755Note that the SSH key pair must @emph{not} be passphrase-protected, to
756allow non-interactive logins.
757
758@end table
759
4ec2e92d 760A number of optional fields may be specified:
49e6291a
LC
761
762@table @code
763
cecd72d5 764@item port
f97c9175 765Port number of SSH server on the machine (default: 22).
cecd72d5 766
49e6291a
LC
767@item private-key
768The SSH private key file to use when connecting to the machine.
769
c4fdfd6f
LC
770Currently offloading uses GNU@tie{}lsh as its SSH client
771(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
772be an lsh key file. This may change in the future, though.
773
49e6291a
LC
774@item parallel-builds
775The number of builds that may run in parallel on the machine (1 by
776default.)
777
778@item speed
779A ``relative speed factor''. The offload scheduler will tend to prefer
780machines with a higher speed factor.
781
782@item features
783A list of strings denoting specific features supported by the machine.
784An example is @code{"kvm"} for machines that have the KVM Linux modules
785and corresponding hardware support. Derivations can request features by
786name, and they will be scheduled on matching build machines.
787
788@end table
c678a4ee 789@end deftp
49e6291a
LC
790
791The @code{guix} command must be in the search path on the build
792machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
793@code{guix build} commands. In addition, the Guix modules must be in
794@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
795this is the case by running:
796
797@example
74273b6f 798lsh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 799@end example
49e6291a 800
f97c9175 801There is one last thing to do once @file{machines.scm} is in place. As
49e6291a 802explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
803between the machine stores. For this to work, you first need to
804generate a key pair on each machine to allow the daemon to export signed
805archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
806
807@example
808# guix archive --generate-key
809@end example
810
811@noindent
c4fdfd6f
LC
812Each build machine must authorize the key of the master machine so that
813it accepts store items it receives from the master:
814
815@example
816# guix archive --authorize < master-public-key.txt
817@end example
818
819@noindent
820Likewise, the master machine must authorize the key of each build machine.
821
822All the fuss with keys is here to express pairwise mutual trust
823relations between the master and the build machines. Concretely, when
824the master receives files from a build machine (and @i{vice versa}), its
825build daemon can make sure they are genuine, have not been tampered
826with, and that they are signed by an authorized key.
49e6291a
LC
827
828
bd5e766b
LC
829@node Invoking guix-daemon
830@section Invoking @command{guix-daemon}
831
832The @command{guix-daemon} program implements all the functionality to
833access the store. This includes launching build processes, running the
834garbage collector, querying the availability of a build result, etc. It
835is normally run as @code{root} like this:
836
837@example
cfc149dc 838# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
839@end example
840
841@noindent
081145cf 842For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 843
e900c503
LC
844@cindex chroot
845@cindex container, build environment
846@cindex build environment
847@cindex reproducible builds
bd5e766b
LC
848By default, @command{guix-daemon} launches build processes under
849different UIDs, taken from the build group specified with
850@code{--build-users-group}. In addition, each build process is run in a
851chroot environment that only contains the subset of the store that the
852build process depends on, as specified by its derivation
853(@pxref{Programming Interface, derivation}), plus a set of specific
854system directories. By default, the latter contains @file{/dev} and
e900c503
LC
855@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
856@dfn{container}: in addition to having its own file system tree, it has
857a separate mount name space, its own PID name space, network name space,
858etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 859
cbc538fe
LC
860When the daemon performs a build on behalf of the user, it creates a
861build directory under @file{/tmp} or under the directory specified by
862its @code{TMPDIR} environment variable; this directory is shared with
863the container for the duration of the build. Be aware that using a
864directory other than @file{/tmp} can affect build results---for example,
865with a longer directory name, a build process that uses Unix-domain
866sockets might hit the name length limitation for @code{sun_path}, which
867it would otherwise not hit.
868
869The build directory is automatically deleted upon completion, unless the
870build failed and the client specified @option{--keep-failed}
871(@pxref{Invoking guix build, @option{--keep-failed}}).
872
bd5e766b
LC
873The following command-line options are supported:
874
875@table @code
876@item --build-users-group=@var{group}
877Take users from @var{group} to run build processes (@pxref{Setting Up
878the Daemon, build users}).
879
6858f9d1 880@item --no-substitutes
b5385b52 881@cindex substitutes
6858f9d1 882Do not use substitutes for build products. That is, always build things
c4202d60
LC
883locally instead of allowing downloads of pre-built binaries
884(@pxref{Substitutes}).
6858f9d1 885
b5385b52
LC
886By default substitutes are used, unless the client---such as the
887@command{guix package} command---is explicitly invoked with
888@code{--no-substitutes}.
889
890When the daemon runs with @code{--no-substitutes}, clients can still
891explicitly enable substitution @i{via} the @code{set-build-options}
892remote procedure call (@pxref{The Store}).
893
9176607e 894@item --substitute-urls=@var{urls}
f8a8e0fe 895@anchor{daemon-substitute-urls}
9176607e 896Consider @var{urls} the default whitespace-separated list of substitute
ae806096 897source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
9176607e
LC
898is used.
899
900This means that substitutes may be downloaded from @var{urls}, as long
901as they are signed by a trusted signature (@pxref{Substitutes}).
902
4ec2e92d
LC
903@cindex build hook
904@item --no-build-hook
905Do not use the @dfn{build hook}.
906
907The build hook is a helper program that the daemon can start and to
908which it submits build requests. This mechanism is used to offload
909builds to other machines (@pxref{Daemon Offload Setup}).
910
bd5e766b
LC
911@item --cache-failures
912Cache build failures. By default, only successful builds are cached.
913
30d9aa54
LC
914When this option is used, @command{guix gc --list-failures} can be used
915to query the set of store items marked as failed; @command{guix gc
916--clear-failures} removes store items from the set of cached failures.
917@xref{Invoking guix gc}.
918
bd5e766b
LC
919@item --cores=@var{n}
920@itemx -c @var{n}
921Use @var{n} CPU cores to build each derivation; @code{0} means as many
922as available.
923
6efc160e 924The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
925as the @code{--cores} option of @command{guix build} (@pxref{Invoking
926guix build}).
bd5e766b
LC
927
928The effect is to define the @code{NIX_BUILD_CORES} environment variable
929in the build process, which can then use it to exploit internal
930parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
931
932@item --max-jobs=@var{n}
933@itemx -M @var{n}
934Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
935@code{1}. Setting it to @code{0} means that no builds will be performed
936locally; instead, the daemon will offload builds (@pxref{Daemon Offload
937Setup}), or simply fail.
bd5e766b 938
ecf84b7c
LC
939@item --rounds=@var{N}
940Build each derivation @var{n} times in a row, and raise an error if
941consecutive build results are not bit-for-bit identical. Note that this
942setting can be overridden by clients such as @command{guix build}
943(@pxref{Invoking guix build}).
944
bd5e766b
LC
945@item --debug
946Produce debugging output.
947
948This is useful to debug daemon start-up issues, but then it may be
949overridden by clients, for example the @code{--verbosity} option of
e49951eb 950@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
951
952@item --chroot-directory=@var{dir}
953Add @var{dir} to the build chroot.
954
955Doing this may change the result of build processes---for instance if
956they use optional dependencies found in @var{dir} when it is available,
957and not otherwise. For that reason, it is not recommended to do so.
958Instead, make sure that each derivation declares all the inputs that it
959needs.
960
961@item --disable-chroot
962Disable chroot builds.
963
964Using this option is not recommended since, again, it would allow build
1e2644bb
LC
965processes to gain access to undeclared dependencies. It is necessary,
966though, when @command{guix-daemon} is running under an unprivileged user
967account.
bd5e766b
LC
968
969@item --disable-log-compression
970Disable compression of the build logs.
971
1da983b9
LC
972Unless @code{--lose-logs} is used, all the build logs are kept in the
973@var{localstatedir}. To save space, the daemon automatically compresses
974them with bzip2 by default. This option disables that.
975
ab3893d7
LC
976@item --disable-deduplication
977@cindex deduplication
bd5e766b
LC
978Disable automatic file ``deduplication'' in the store.
979
1da983b9 980By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
981if a newly added file is identical to another one found in the store,
982the daemon makes the new file a hard link to the other file. This can
4988dd40 983noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
984input/output load at the end of a build process. This option disables
985this optimization.
1da983b9 986
6e37066e
LC
987@item --gc-keep-outputs[=yes|no]
988Tell whether the garbage collector (GC) must keep outputs of live
989derivations.
990
991When set to ``yes'', the GC will keep the outputs of any live derivation
992available in the store---the @code{.drv} files. The default is ``no'',
993meaning that derivation outputs are kept only if they are GC roots.
994
995@item --gc-keep-derivations[=yes|no]
996Tell whether the garbage collector (GC) must keep derivations
997corresponding to live outputs.
998
999When set to ``yes'', as is the case by default, the GC keeps
1000derivations---i.e., @code{.drv} files---as long as at least one of their
1001outputs is live. This allows users to keep track of the origins of
1002items in their store. Setting it to ``no'' saves a bit of disk space.
1003
1004Note that when both @code{--gc-keep-derivations} and
1005@code{--gc-keep-outputs} are used, the effect is to keep all the build
1006prerequisites (the sources, compiler, libraries, and other build-time
1007tools) of live objects in the store, regardless of whether these
1008prerequisites are live. This is convenient for developers since it
1009saves rebuilds or downloads.
1010
bd5e766b
LC
1011@item --impersonate-linux-2.6
1012On Linux-based systems, impersonate Linux 2.6. This means that the
1013kernel's @code{uname} system call will report 2.6 as the release number.
1014
1015This might be helpful to build programs that (usually wrongfully) depend
1016on the kernel version number.
1017
1018@item --lose-logs
1019Do not keep build logs. By default they are kept under
ce33631f 1020@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
1021
1022@item --system=@var{system}
1023Assume @var{system} as the current system type. By default it is the
1024architecture/kernel pair found at configure time, such as
1025@code{x86_64-linux}.
b8d2aa26
LC
1026
1027@item --listen=@var{socket}
1028Listen for connections on @var{socket}, the file name of a Unix-domain
1029socket. The default socket is
1030@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1031useful in exceptional circumstances, such as if you need to run several
1032daemons on the same machine.
bd5e766b
LC
1033@end table
1034
1035
0e2d0213
LC
1036@node Application Setup
1037@section Application Setup
1038
85e57214
LC
1039When using Guix on top of GNU/Linux distribution other than GuixSD---a
1040so-called @dfn{foreign distro}---a few additional steps are needed to
1041get everything in place. Here are some of them.
0e2d0213
LC
1042
1043@subsection Locales
1044
5c3c1427 1045@anchor{locales-and-locpath}
0e2d0213 1046@cindex locales, when not on GuixSD
5c3c1427 1047@vindex LOCPATH
85e57214 1048@vindex GUIX_LOCPATH
f97c9175
AE
1049Packages installed @i{via} Guix will not use the locale data of the
1050host system. Instead, you must first install one of the locale packages
85e57214
LC
1051available with Guix and then define the @code{GUIX_LOCPATH} environment
1052variable:
0e2d0213
LC
1053
1054@example
1055$ guix package -i glibc-locales
85e57214 1056$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1057@end example
1058
1059Note that the @code{glibc-locales} package contains data for all the
1060locales supported by the GNU@tie{}libc and weighs in at around
f97c9175 1061110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
0e2d0213
LC
1062limited to a few UTF-8 locales.
1063
85e57214
LC
1064The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1065(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1066Manual}). There are two important differences though:
1067
1068@enumerate
1069@item
f97c9175 1070@code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
85e57214 1071provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f97c9175 1072to make sure the programs of the foreign distro will not end up loading
85e57214
LC
1073incompatible locale data.
1074
1075@item
1076libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1077@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1078should your Guix profile contain a mixture of programs linked against
1079different libc version, each libc version will only try to load locale
1080data in the right format.
1081@end enumerate
1082
1083This is important because the locale data format used by different libc
1084versions may be incompatible.
1085
0e2d0213
LC
1086@subsection X11 Fonts
1087
4988dd40 1088The majority of graphical applications use Fontconfig to locate and
f97c9175
AE
1089load fonts and perform X11-client-side rendering. The @code{fontconfig}
1090package in Guix looks for fonts in @file{$HOME/.guix-profile}
0e2d0213 1091by default. Thus, to allow graphical applications installed with Guix
f97c9175 1092to display fonts, you have to install fonts with Guix as well.
0e2d0213 1093Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1094@code{font-gnu-freefont-ttf}.
0e2d0213 1095
5c36edc8
LC
1096To display text written in Chinese languages, Japanese, or Korean in
1097graphical applications, consider installing
1098@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1099has multiple outputs, one per language family (@pxref{Packages with
1100Multiple Outputs}). For instance, the following command installs fonts
1101for Chinese languages:
1102
1103@example
1104guix package -i font-adobe-source-han-sans:cn
1105@end example
1106
6d97319c
AK
1107@subsection Emacs Packages
1108
1109When you install Emacs packages with Guix, the elisp files may be placed
1110either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1111sub-directories of
1112@file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1113directory exists because potentially there may exist thousands of Emacs
1114packages and storing all their files in a single directory may be not
1115reliable (because of name conflicts). So we think using a separate
1116directory for each package is a good idea. It is very similar to how
1117the Emacs package system organizes the file structure (@pxref{Package
1118Files,,, emacs, The GNU Emacs Manual}).
1119
1120By default, Emacs (installed with Guix) ``knows'' where these packages
f97c9175 1121are placed, so you do not need to perform any configuration. If, for
6d97319c 1122some reason, you want to avoid auto-loading Emacs packages installed
f97c9175 1123with Guix, you can do so by running Emacs with @code{--no-site-file}
6d97319c
AK
1124option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1125
0e2d0213
LC
1126@c TODO What else?
1127
eeaf4427
LC
1128@c *********************************************************************
1129@node Package Management
1130@chapter Package Management
1131
f8348b91 1132The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427 1133remove software packages, without having to know about their build
f97c9175 1134procedures or dependencies. Guix also goes beyond this obvious set of
eeaf4427
LC
1135features.
1136
1137This chapter describes the main features of Guix, as well as the package
c1941588 1138management tools it provides. Two user interfaces are provided for
c554de89
AK
1139routine package management tasks: A command-line interface described below
1140(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1141interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
1142
1143@menu
1144* Features:: How Guix will make your life brighter.
e49951eb 1145* Invoking guix package:: Package installation, removal, etc.
c4202d60 1146* Substitutes:: Downloading pre-built binaries.
760c60d6 1147* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1148* Invoking guix gc:: Running the garbage collector.
f651b477 1149* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1150* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1151@end menu
1152
1153@node Features
1154@section Features
1155
1156When using Guix, each package ends up in the @dfn{package store}, in its
1157own directory---something that resembles
9a130e19
AK
1158@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1159(note that Guix comes with an Emacs extension to shorten those file
081145cf 1160names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1161
1162Instead of referring to these directories, users have their own
1163@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1164use. These profiles are stored within each user's home directory, at
1165@code{$HOME/.guix-profile}.
eeaf4427 1166
821b0015 1167For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1168@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1169@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1170@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1171simply continues to point to
834129e0 1172@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1173coexist on the same system without any interference.
eeaf4427 1174
e49951eb 1175The @command{guix package} command is the central tool to manage
f97c9175 1176packages (@pxref{Invoking guix package}). It operates on the per-user
821b0015 1177profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
1178
1179The command provides the obvious install, remove, and upgrade
1180operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1181the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1182@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1183or if a power outage occurs during the transaction, then the user's
1184profile remains in its previous state, and remains usable.
1185
1186In addition, any package transaction may be @emph{rolled back}. So, if,
1187for example, an upgrade installs a new version of a package that turns
1188out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
1189of their profile, which was known to work well. Similarly, the global
1190system configuration is subject to transactional upgrades and roll-back
1191(@pxref{Using the Configuration System}).
eeaf4427 1192
f97c9175
AE
1193All packages in the package store may be @emph{garbage-collected}.
1194Guix can determine which packages are still referenced by user
fe8ff028 1195profiles, and remove those that are provably no longer referenced
e49951eb 1196(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1197generations of their profile so that the packages they refer to can be
1198collected.
eeaf4427 1199
e900c503
LC
1200@cindex reproducibility
1201@cindex reproducible builds
eeaf4427
LC
1202Finally, Guix takes a @dfn{purely functional} approach to package
1203management, as described in the introduction (@pxref{Introduction}).
834129e0 1204Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1205inputs that were used to build that package---compiler, libraries, build
1206scripts, etc. This direct correspondence allows users to make sure a
1207given package installation matches the current state of their
e900c503
LC
1208distribution. It also helps maximize @dfn{build reproducibility}:
1209thanks to the isolated build environments that are used, a given build
1210is likely to yield bit-identical files when performed on different
1211machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1212
c4202d60 1213@cindex substitutes
eeaf4427 1214This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1215deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1216available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1217downloads it and unpacks it;
1218otherwise, it builds the package from source, locally
1219(@pxref{Substitutes}).
eeaf4427 1220
f5fd4fd2
LC
1221Control over the build environment is a feature that is also useful for
1222developers. The @command{guix environment} command allows developers of
1223a package to quickly set up the right development environment for their
f97c9175
AE
1224package, without having to manually install the dependencies of the
1225package into their profile (@pxref{Invoking guix environment}).
f5fd4fd2 1226
e49951eb
MW
1227@node Invoking guix package
1228@section Invoking @command{guix package}
eeaf4427 1229
e49951eb 1230The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1231install, upgrade, and remove packages, as well as rolling back to
1232previous configurations. It operates only on the user's own profile,
1233and works with normal user privileges (@pxref{Features}). Its syntax
1234is:
1235
1236@example
e49951eb 1237guix package @var{options}
eeaf4427
LC
1238@end example
1239
ba55b1cb 1240Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1241the transaction. Upon completion, a new profile is created, but
99bd74d5 1242previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1243want to roll back.
1244
6447738c
MW
1245For example, to remove @code{lua} and install @code{guile} and
1246@code{guile-cairo} in a single transaction:
1247
1248@example
1249guix package -r lua -i guile guile-cairo
1250@end example
1251
99bd74d5
LC
1252@command{guix package} also supports a @dfn{declarative approach}
1253whereby the user specifies the exact set of packages to be available and
1254passes it @i{via} the @option{--manifest} option
1255(@pxref{profile-manifest, @option{--manifest}}).
1256
b9e5c0a9 1257For each user, a symlink to the user's default profile is automatically
0ec1af59 1258created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1259current generation of the user's default profile. Thus, users can add
1260@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1261variable, and so on.
d664f1b4
LC
1262@cindex search paths
1263If you are not using the Guix System Distribution, consider adding the
1264following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1265Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1266shells get all the right environment variable definitions:
1267
1268@example
1269GUIX_PROFILE="$HOME/.guix-profile" \
1270source "$HOME/.guix-profile/etc/profile"
1271@end example
b9e5c0a9 1272
4379c35b
LC
1273In a multi-user setup, user profiles are stored in a place registered as
1274a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1275to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1276@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1277@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1278@code{--localstatedir}, and @var{user} is the user name. The
1279@file{per-user} directory is created when @command{guix-daemon} is
1280started, and the @var{user} sub-directory is created by @command{guix
1281package}.
0ec1af59
LC
1282
1283The @var{options} can be among the following:
1284
eeaf4427
LC
1285@table @code
1286
6447738c
MW
1287@item --install=@var{package} @dots{}
1288@itemx -i @var{package} @dots{}
1289Install the specified @var{package}s.
eeaf4427 1290
6447738c 1291Each @var{package} may specify either a simple package name, such as
1b846da8
ML
1292@code{guile}, or a package name followed by an at-sign and version number,
1293such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
724311a2
LC
1294case, the newest version prefixed by @code{1.8} is selected.)
1295
1296If no version number is specified, the
dc5669cd
MW
1297newest available version will be selected. In addition, @var{package}
1298may contain a colon, followed by the name of one of the outputs of the
1b846da8 1299package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
e7f34eb0
LC
1300(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1301name (and optionally version) are searched for among the GNU
1302distribution modules (@pxref{Package Modules}).
eeaf4427 1303
461572cc
LC
1304@cindex propagated inputs
1305Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1306that automatically get installed along with the required package
1307(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1308@code{package} objects}, for information about propagated inputs in
1309package definitions).
461572cc 1310
21461f27 1311@anchor{package-cmd-propagated-inputs}
461572cc
LC
1312An example is the GNU MPC library: its C header files refer to those of
1313the GNU MPFR library, which in turn refer to those of the GMP library.
1314Thus, when installing MPC, the MPFR and GMP libraries also get installed
1315in the profile; removing MPC also removes MPFR and GMP---unless they had
f97c9175 1316also been explicitly installed by the user.
461572cc 1317
ba7ea5ce 1318Besides, packages sometimes rely on the definition of environment
5924080d 1319variables for their search paths (see explanation of
ba7ea5ce 1320@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1321environment variable definitions are reported here.
1322
ef010c0f 1323@c XXX: keep me up-to-date
5924080d 1324Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
1325availability of a newer upstream version. In the future, it may provide
1326the option of installing directly from the upstream version, even if
1327that version is not yet in the distribution.
1328
5d4b411f
LC
1329@item --install-from-expression=@var{exp}
1330@itemx -e @var{exp}
1331Install the package @var{exp} evaluates to.
1332
1333@var{exp} must be a Scheme expression that evaluates to a
1334@code{<package>} object. This option is notably useful to disambiguate
1335between same-named variants of a package, with expressions such as
1336@code{(@@ (gnu packages base) guile-final)}.
1337
1338Note that this option installs the first output of the specified
1339package, which may be insufficient when needing a specific output of a
1340multiple-output package.
1341
0d279400
DT
1342@item --install-from-file=@var{file}
1343@itemx -f @var{file}
1344Install the package that the code within @var{file} evaluates to.
1345
1346As an example, @var{file} might contain a definition like this
1347(@pxref{Defining Packages}):
1348
1349@example
1350@verbatiminclude package-hello.scm
1351@end example
1352
1353Developers may find it useful to include such a @file{package.scm} file
f97c9175 1354in the root of their project source tree that can be used to test
0d279400
DT
1355development snapshots and create reproducible development environments
1356(@pxref{Invoking guix environment}).
1357
6447738c
MW
1358@item --remove=@var{package} @dots{}
1359@itemx -r @var{package} @dots{}
1360Remove the specified @var{package}s.
eeaf4427 1361
6447738c 1362As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1363and/or output name in addition to the package name. For instance,
1364@code{-r glibc:debug} would remove the @code{debug} output of
1365@code{glibc}.
1366
6447738c
MW
1367@item --upgrade[=@var{regexp} @dots{}]
1368@itemx -u [@var{regexp} @dots{}]
1369Upgrade all the installed packages. If one or more @var{regexp}s are
1370specified, upgrade only installed packages whose name matches a
d5f01e48 1371@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1372
f651b477
LC
1373Note that this upgrades package to the latest version of packages found
1374in the distribution currently installed. To update your distribution,
1375you should regularly run @command{guix pull} (@pxref{Invoking guix
1376pull}).
1377
d5f01e48
MW
1378@item --do-not-upgrade[=@var{regexp} @dots{}]
1379When used together with the @code{--upgrade} option, do @emph{not}
1380upgrade any packages whose name matches a @var{regexp}. For example, to
1381upgrade all packages in the current profile except those containing the
1382substring ``emacs'':
1383
1384@example
1385$ guix package --upgrade . --do-not-upgrade emacs
1386@end example
1387
99bd74d5 1388@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1389@itemx -m @var{file}
99bd74d5
LC
1390@cindex profile declaration
1391@cindex profile manifest
1392Create a new generation of the profile from the manifest object
1b676447
DT
1393returned by the Scheme code in @var{file}.
1394
99bd74d5
LC
1395This allows you to @emph{declare} the profile's contents rather than
1396constructing it through a sequence of @code{--install} and similar
1397commands. The advantage is that @var{file} can be put under version
1398control, copied to different machines to reproduce the same profile, and
1399so on.
1400
1401@c FIXME: Add reference to (guix profile) documentation when available.
1402@var{file} must return a @dfn{manifest} object, which is roughly a list
1403of packages:
1b676447 1404
99bd74d5 1405@findex packages->manifest
1b676447 1406@example
99bd74d5 1407(use-package-modules guile emacs)
1b676447
DT
1408
1409(packages->manifest
99bd74d5
LC
1410 (list emacs
1411 guile-2.0
1b676447 1412 ;; Use a specific package output.
99bd74d5 1413 (list guile-2.0 "debug")))
1b676447
DT
1414@end example
1415
24e262f0
LC
1416@item --roll-back
1417Roll back to the previous @dfn{generation} of the profile---i.e., undo
1418the last transaction.
1419
1420When combined with options such as @code{--install}, roll back occurs
1421before any other actions.
1422
d9307267 1423When rolling back from the first generation that actually contains
4b2bc804 1424installed packages, the profile is made to point to the @dfn{zeroth
f97c9175 1425generation}, which contains no files apart from its own metadata.
d9307267 1426
f97c9175
AE
1427After having rolled back, installing, removing, or upgrading packages
1428overwrites previous future generations. Thus, the history of the
1429generations in a profile is always linear.
82fe08ed 1430
b3bb82f1
AK
1431@item --switch-generation=@var{pattern}
1432@itemx -S @var{pattern}
1433Switch to a particular generation defined by @var{pattern}.
1434
1435@var{pattern} may be either a generation number or a number prefixed
1436with ``+'' or ``-''. The latter means: move forward/backward by a
1437specified number of generations. For example, if you want to return to
1438the latest generation after @code{--roll-back}, use
1439@code{--switch-generation=+1}.
1440
1441The difference between @code{--roll-back} and
1442@code{--switch-generation=-1} is that @code{--switch-generation} will
1443not make a zeroth generation, so if a specified generation does not
1444exist, the current generation will not be changed.
1445
dbc31ab2 1446@item --search-paths[=@var{kind}]
5924080d
LC
1447@cindex search paths
1448Report environment variable definitions, in Bash syntax, that may be
1449needed in order to use the set of installed packages. These environment
1450variables are used to specify @dfn{search paths} for files used by some
1451of the installed packages.
1452
1453For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1454environment variables to be defined so it can look for headers and
1455libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1456Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1457library are installed in the profile, then @code{--search-paths} will
1458suggest setting these variables to @code{@var{profile}/include} and
1459@code{@var{profile}/lib}, respectively.
1460
dbc31ab2
LC
1461The typical use case is to define these environment variables in the
1462shell:
1463
1464@example
1465$ eval `guix package --search-paths`
1466@end example
1467
1468@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1469meaning that the returned environment variable definitions will either
1470be exact settings, or prefixes or suffixes of the current value of these
1471variables. When omitted, @var{kind} defaults to @code{exact}.
1472
fc2d2339
LC
1473This option can also be used to compute the @emph{combined} search paths
1474of several profiles. Consider this example:
1475
1476@example
1477$ guix package -p foo -i guile
1478$ guix package -p bar -i guile-json
1479$ guix package -p foo -p bar --search-paths
1480@end example
1481
1482The last command above reports about the @code{GUILE_LOAD_PATH}
1483variable, even though, taken individually, neither @file{foo} nor
1484@file{bar} would lead to that recommendation.
1485
1486
eeaf4427
LC
1487@item --profile=@var{profile}
1488@itemx -p @var{profile}
1489Use @var{profile} instead of the user's default profile.
1490
70915c1a 1491@item --verbose
f97c9175
AE
1492Produce verbose output. In particular, emit the build log of the
1493environment on the standard error port.
70915c1a 1494
eeaf4427
LC
1495@item --bootstrap
1496Use the bootstrap Guile to build the profile. This option is only
1497useful to distribution developers.
1498
1499@end table
1500
f97c9175 1501In addition to these actions, @command{guix package} supports the
733b4130
LC
1502following options to query the current state of a profile, or the
1503availability of packages:
eeaf4427 1504
733b4130
LC
1505@table @option
1506
acc08466
NK
1507@item --search=@var{regexp}
1508@itemx -s @var{regexp}
b110869d 1509@cindex searching for packages
5763ad92 1510List the available packages whose name, synopsis, or description matches
f97c9175 1511@var{regexp}. Print all the metadata of matching packages in
299112d3
LC
1512@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1513GNU recutils manual}).
acc08466 1514
299112d3
LC
1515This allows specific fields to be extracted using the @command{recsel}
1516command, for instance:
1517
1518@example
e49951eb 1519$ guix package -s malloc | recsel -p name,version
299112d3
LC
1520name: glibc
1521version: 2.17
1522
1523name: libgc
1524version: 7.2alpha6
1525@end example
acc08466 1526
a12d92f5
LC
1527Similarly, to show the name of all the packages available under the
1528terms of the GNU@tie{}LGPL version 3:
1529
1530@example
1531$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1532name: elfutils
1533
1534name: gmp
1535@dots{}
1536@end example
1537
db5a9444
LC
1538It is also possible to refine search results using several @code{-s}
1539flags. For example, the following command returns a list of board
1540games:
1541
1542@example
1543$ guix package -s '\<board\>' -s game | recsel -p name
1544name: gnubg
1545@dots{}
1546@end example
1547
1548If we were to omit @code{-s game}, we would also get software packages
1549that deal with printed circuit boards; removing the angle brackets
1550around @code{board} would further add packages that have to do with
1551keyboards.
1552
b110869d
LC
1553And now for a more elaborate example. The following command searches
1554for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1555libraries, and prints the name and synopsis of the matching packages:
1556
1557@example
1558$ guix package -s crypto -s library | \
1559 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1560@end example
1561
1562@noindent
1563@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1564information on @dfn{selection expressions} for @code{recsel -e}.
1565
2aa6efb0
CR
1566@item --show=@var{package}
1567Show details about @var{package}, taken from the list of available packages, in
1568@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1569recutils manual}).
1570
1571@example
1572$ guix package --show=python | recsel -p name,version
1573name: python
1574version: 2.7.6
1575
1576name: python
1577version: 3.3.5
1578@end example
1579
1580You may also specify the full name of a package to only get details about a
1581specific version of it:
1582@example
1583$ guix package --show=python-3.3.5 | recsel -p name,version
1584name: python
1585version: 3.3.5
1586@end example
1587
1588
1589
733b4130
LC
1590@item --list-installed[=@var{regexp}]
1591@itemx -I [@var{regexp}]
bd9bde1c
LC
1592List the currently installed packages in the specified profile, with the
1593most recently installed packages shown last. When @var{regexp} is
1594specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1595
1596For each installed package, print the following items, separated by
1597tabs: the package name, its version string, the part of the package that
1598is installed (for instance, @code{out} for the default output,
1599@code{include} for its headers, etc.), and the path of this package in
1600the store.
1601
64fc89b6
LC
1602@item --list-available[=@var{regexp}]
1603@itemx -A [@var{regexp}]
5763ad92 1604List packages currently available in the distribution for this system
a1ba8475
LC
1605(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1606installed packages whose name matches @var{regexp}.
64fc89b6
LC
1607
1608For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1609its version string, the parts of the package (@pxref{Packages with
1610Multiple Outputs}), and the source location of its definition.
64fc89b6 1611
f566d765
LC
1612@item --list-generations[=@var{pattern}]
1613@itemx -l [@var{pattern}]
1614Return a list of generations along with their creation dates; for each
1615generation, show the installed packages, with the most recently
4b2bc804
NK
1616installed packages shown last. Note that the zeroth generation is never
1617shown.
f566d765
LC
1618
1619For each installed package, print the following items, separated by
1620tabs: the name of a package, its version string, the part of the package
1621that is installed (@pxref{Packages with Multiple Outputs}), and the
1622location of this package in the store.
1623
1624When @var{pattern} is used, the command returns only matching
1625generations. Valid patterns include:
1626
1627@itemize
1628@item @emph{Integers and comma-separated integers}. Both patterns denote
1629generation numbers. For instance, @code{--list-generations=1} returns
1630the first one.
1631
1632And @code{--list-generations=1,8,2} outputs three generations in the
1633specified order. Neither spaces nor trailing commas are allowed.
1634
1635@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1636specified generations and everything in between. Note that the start of
f97c9175 1637a range must be smaller than its end.
f566d765
LC
1638
1639It is also possible to omit the endpoint. For example,
1640@code{--list-generations=2..}, returns all generations starting from the
1641second one.
1642
1643@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1644or months by passing an integer along with the first letter of the
d7ddb257
LC
1645duration. For example, @code{--list-generations=20d} lists generations
1646that are up to 20 days old.
f566d765
LC
1647@end itemize
1648
b7884ca3
NK
1649@item --delete-generations[=@var{pattern}]
1650@itemx -d [@var{pattern}]
d7ddb257
LC
1651When @var{pattern} is omitted, delete all generations except the current
1652one.
b7884ca3
NK
1653
1654This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1655When @var{pattern} is specified, delete the matching generations. When
1656@var{pattern} specifies a duration, generations @emph{older} than the
1657specified duration match. For instance, @code{--delete-generations=1m}
1658deletes generations that are more than one month old.
1659
391bdd8f
LC
1660If the current generation matches, it is @emph{not} deleted. Also, the
1661zeroth generation is never deleted.
b7884ca3 1662
f97c9175 1663Note that deleting generations prevents rolling back to them.
1bb9900a
LC
1664Consequently, this command must be used with care.
1665
733b4130 1666@end table
eeaf4427 1667
70ee5642 1668Finally, since @command{guix package} may actually start build
ccd7158d 1669processes, it supports all the common build options (@pxref{Common Build
f97c9175 1670Options}). It also supports package transformation options, such as
b8638f03
LC
1671@option{--with-source} (@pxref{Package Transformation Options}).
1672However, note that package transformations are lost when upgrading; to
f97c9175 1673preserve transformations across upgrades, you should define your own
b8638f03
LC
1674package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1675(@pxref{Defining Packages}).
1676
70ee5642 1677
c4202d60
LC
1678@node Substitutes
1679@section Substitutes
1680
1681@cindex substitutes
1682@cindex pre-built binaries
1683Guix supports transparent source/binary deployment, which means that it
1684can either build things locally, or download pre-built items from a
1685server. We call these pre-built items @dfn{substitutes}---they are
1686substitutes for local build results. In many cases, downloading a
1687substitute is much faster than building things locally.
1688
1689Substitutes can be anything resulting from a derivation build
1690(@pxref{Derivations}). Of course, in the common case, they are
1691pre-built package binaries, but source tarballs, for instance, which
1692also result from derivation builds, can be available as substitutes.
1693
1694The @code{hydra.gnu.org} server is a front-end to a build farm that
1695builds packages from the GNU distribution continuously for some
32950fc8
AK
1696architectures, and makes them available as substitutes (@pxref{Emacs
1697Hydra}, for information on how to query the continuous integration
1698server). This is the
f8a8e0fe
LC
1699default source of substitutes; it can be overridden by passing the
1700@option{--substitute-urls} option either to @command{guix-daemon}
1701(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1702or to client tools such as @command{guix package}
1703(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1704option}).
c4202d60
LC
1705
1706@cindex security
1707@cindex digital signatures
1708To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1709must add its public key to the access control list (ACL) of archive
1710imports, using the @command{guix archive} command (@pxref{Invoking guix
1711archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1712be compromised and to serve genuine substitutes.
1713
1714This public key is installed along with Guix, in
1715@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1716the installation prefix of Guix. If you installed Guix from source,
1717make sure you checked the GPG signature of
1718@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1719Then, you can run something like this:
1720
1721@example
1722# guix archive --authorize < hydra.gnu.org.pub
1723@end example
1724
1725Once this is in place, the output of a command like @code{guix build}
1726should change from something like:
1727
1728@example
1729$ guix build emacs --dry-run
1730The following derivations would be built:
1731 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1732 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1733 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1734 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1735@dots{}
1736@end example
1737
1738@noindent
1739to something like:
1740
1741@example
1742$ guix build emacs --dry-run
1743The following files would be downloaded:
1744 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1745 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1746 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1747 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1748@dots{}
1749@end example
1750
1751@noindent
1752This indicates that substitutes from @code{hydra.gnu.org} are usable and
1753will be downloaded, when possible, for future builds.
1754
1755Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1756one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1757when attempting to use a substitute that has been tampered with.
1758
e0c941fe
LC
1759@vindex http_proxy
1760Substitutes are downloaded over HTTP. The @code{http_proxy} environment
1761variable can be set in the environment of @command{guix-daemon} and is
1762honored for downloads of substitutes. Note that the value of
1763@code{http_proxy} in the environment where @command{guix build},
1764@command{guix package}, and other client commands are run has
1765@emph{absolutely no effect}.
1766
c4202d60
LC
1767The substitute mechanism can be disabled globally by running
1768@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1769guix-daemon}). It can also be disabled temporarily by passing the
1770@code{--no-substitutes} option to @command{guix package}, @command{guix
1771build}, and other command-line tools.
1772
1773
1774Today, each individual's control over their own computing is at the
1775mercy of institutions, corporations, and groups with enough power and
1776determination to subvert the computing infrastructure and exploit its
1777weaknesses. While using @code{hydra.gnu.org} substitutes can be
1778convenient, we encourage users to also build on their own, or even run
1779their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1780interesting target. One way to help is by publishing the software you
1781build using @command{guix publish} so that others have one more choice
1782of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1783
1784Guix has the foundations to maximize build reproducibility
1785(@pxref{Features}). In most cases, independent builds of a given
1786package or derivation should yield bit-identical results. Thus, through
1787a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
1788integrity of our systems. The @command{guix challenge} command aims to
1789help users assess substitute servers, and to assist developers in
1790finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
1791challenge}). Similarly, the @option{--check} option of @command{guix
1792build} allows users to check whether previously-installed substitutes
1793are genuine by rebuilding them locally (@pxref{build-check,
1794@command{guix build --check}}).
c4202d60
LC
1795
1796In the future, we want Guix to have support to publish and retrieve
1797binaries to/from other users, in a peer-to-peer fashion. If you would
1798like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1799
1800
6e721c4d
LC
1801@node Packages with Multiple Outputs
1802@section Packages with Multiple Outputs
1803
1804@cindex multiple-output packages
1805@cindex package outputs
1806
1807Often, packages defined in Guix have a single @dfn{output}---i.e., the
f97c9175 1808source package leads to exactly one directory in the store. When running
6e721c4d
LC
1809@command{guix package -i glibc}, one installs the default output of the
1810GNU libc package; the default output is called @code{out}, but its name
1811can be omitted as shown in this command. In this particular case, the
1812default output of @code{glibc} contains all the C header files, shared
1813libraries, static libraries, Info documentation, and other supporting
1814files.
1815
1816Sometimes it is more appropriate to separate the various types of files
1817produced from a single source package into separate outputs. For
1818instance, the GLib C library (used by GTK+ and related packages)
1819installs more than 20 MiB of reference documentation as HTML pages.
1820To save space for users who do not need it, the documentation goes to a
1821separate output, called @code{doc}. To install the main GLib output,
1822which contains everything but the documentation, one would run:
1823
1824@example
1825guix package -i glib
1826@end example
1827
1828The command to install its documentation is:
1829
1830@example
1831guix package -i glib:doc
1832@end example
1833
1834Some packages install programs with different ``dependency footprints''.
f97c9175 1835For instance, the WordNet package installs both command-line tools and
6e721c4d
LC
1836graphical user interfaces (GUIs). The former depend solely on the C
1837library, whereas the latter depend on Tcl/Tk and the underlying X
1838libraries. In this case, we leave the command-line tools in the default
1839output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
1840who do not need the GUIs to save space. The @command{guix size} command
1841can help find out about such situations (@pxref{Invoking guix size}).
88856916 1842@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
1843
1844There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1845Other conventional output names include @code{lib} for libraries and
1846possibly header files, @code{bin} for stand-alone programs, and
1847@code{debug} for debugging information (@pxref{Installing Debugging
1848Files}). The outputs of a packages are listed in the third column of
1849the output of @command{guix package --list-available} (@pxref{Invoking
1850guix package}).
6e721c4d 1851
eeaf4427 1852
e49951eb
MW
1853@node Invoking guix gc
1854@section Invoking @command{guix gc}
fe8ff028
LC
1855
1856@cindex garbage collector
f97c9175 1857Packages that are installed, but not used, may be @dfn{garbage-collected}.
e49951eb 1858The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1859collector to reclaim space from the @file{/gnu/store} directory. It is
1860the @emph{only} way to remove files from @file{/gnu/store}---removing
1861files or directories manually may break it beyond repair!
fe8ff028
LC
1862
1863The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1864@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1865cannot be deleted; any other file is considered @dfn{dead} and may be
1866deleted. The set of garbage collector roots includes default user
e49951eb
MW
1867profiles, and may be augmented with @command{guix build --root}, for
1868example (@pxref{Invoking guix build}).
fe8ff028 1869
1bb9900a
LC
1870Prior to running @code{guix gc --collect-garbage} to make space, it is
1871often useful to remove old generations from user profiles; that way, old
1872package builds referenced by those generations can be reclaimed. This
1873is achieved by running @code{guix package --delete-generations}
1874(@pxref{Invoking guix package}).
1875
e49951eb 1876The @command{guix gc} command has three modes of operation: it can be
fe8ff028 1877used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
1878files (the @code{--delete} option), to print garbage-collector
1879information, or for more advanced queries. The garbage collection
1880options are as follows:
fe8ff028
LC
1881
1882@table @code
1883@item --collect-garbage[=@var{min}]
1884@itemx -C [@var{min}]
834129e0 1885Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1886sub-directories. This is the default operation when no option is
1887specified.
1888
1889When @var{min} is given, stop once @var{min} bytes have been collected.
1890@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1891suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1892(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1893
1894When @var{min} is omitted, collect all the garbage.
1895
1896@item --delete
1897@itemx -d
1898Attempt to delete all the store files and directories specified as
1899arguments. This fails if some of the files are not in the store, or if
1900they are still live.
1901
30d9aa54
LC
1902@item --list-failures
1903List store items corresponding to cached build failures.
1904
1905This prints nothing unless the daemon was started with
1906@option{--cache-failures} (@pxref{Invoking guix-daemon,
1907@option{--cache-failures}}).
1908
1909@item --clear-failures
1910Remove the specified store items from the failed-build cache.
1911
1912Again, this option only makes sense when the daemon is started with
1913@option{--cache-failures}. Otherwise, it does nothing.
1914
fe8ff028
LC
1915@item --list-dead
1916Show the list of dead files and directories still present in the
1917store---i.e., files and directories no longer reachable from any root.
1918
1919@item --list-live
1920Show the list of live store files and directories.
ba8b732d
LC
1921
1922@end table
1923
1924In addition, the references among existing store files can be queried:
1925
1926@table @code
1927
1928@item --references
1929@itemx --referrers
1930List the references (respectively, the referrers) of store files given
1931as arguments.
1932
8e59fdd5
LC
1933@item --requisites
1934@itemx -R
fcc58db6 1935@cindex closure
8e59fdd5
LC
1936List the requisites of the store files passed as arguments. Requisites
1937include the store files themselves, their references, and the references
1938of these, recursively. In other words, the returned list is the
1939@dfn{transitive closure} of the store files.
1940
f97c9175
AE
1941@xref{Invoking guix size}, for a tool to profile the size of the closure
1942of an element. @xref{Invoking guix graph}, for a tool to visualize
88856916 1943the graph of references.
fcc58db6 1944
fe8ff028
LC
1945@end table
1946
7770aafc
LC
1947Lastly, the following options allow you to check the integrity of the
1948store and to control disk usage.
1949
1950@table @option
1951
1952@item --verify[=@var{options}]
1953@cindex integrity, of the store
1954@cindex integrity checking
1955Verify the integrity of the store.
1956
1957By default, make sure that all the store items marked as valid in the
f97c9175 1958database of the daemon actually exist in @file{/gnu/store}.
7770aafc 1959
f97c9175 1960When provided, @var{options} must be a comma-separated list containing one
7770aafc
LC
1961or more of @code{contents} and @code{repair}.
1962
f97c9175
AE
1963When passing @option{--verify=contents}, the daemon computse the
1964content hash of each store item and compares it against its hash in the
7770aafc
LC
1965database. Hash mismatches are reported as data corruptions. Because it
1966traverses @emph{all the files in the store}, this command can take a
1967long time, especially on systems with a slow disk drive.
1968
1969@cindex repairing the store
1970Using @option{--verify=repair} or @option{--verify=contents,repair}
1971causes the daemon to try to repair corrupt store items by fetching
1972substitutes for them (@pxref{Substitutes}). Because repairing is not
1973atomic, and thus potentially dangerous, it is available only to the
1974system administrator.
1975
1976@item --optimize
1977@cindex deduplication
1978Optimize the store by hard-linking identical files---this is
1979@dfn{deduplication}.
1980
1981The daemon performs deduplication after each successful build or archive
1982import, unless it was started with @code{--disable-deduplication}
1983(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
1984this option is primarily useful when the daemon was running with
1985@code{--disable-deduplication}.
1986
1987@end table
eeaf4427 1988
f651b477
LC
1989@node Invoking guix pull
1990@section Invoking @command{guix pull}
1991
1992Packages are installed or upgraded to the latest version available in
1993the distribution currently available on your local machine. To update
1994that distribution, along with the Guix tools, you must run @command{guix
1995pull}: the command downloads the latest Guix source code and package
1996descriptions, and deploys it.
1997
1998On completion, @command{guix package} will use packages and package
1999versions from this just-retrieved copy of Guix. Not only that, but all
2000the Guix commands and Scheme modules will also be taken from that latest
2001version. New @command{guix} sub-commands added by the update also
cb05108a
LC
2002become available.
2003
2004Any user can update their Guix copy using @command{guix pull}, and the
2005effect is limited to the user who run @command{guix pull}. For
2006instance, when user @code{root} runs @command{guix pull}, this has no
2007effect on the version of Guix that user @code{alice} sees, and vice
2008versa@footnote{Under the hood, @command{guix pull} updates the
2009@file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2010and the @command{guix} command loads code from there.}.
f651b477
LC
2011
2012The @command{guix pull} command is usually invoked with no arguments,
2013but it supports the following options:
2014
2015@table @code
2016@item --verbose
2017Produce verbose output, writing build logs to the standard error output.
2018
ab5d72ad
LC
2019@item --url=@var{url}
2020Download the source tarball of Guix from @var{url}.
2021
2022By default, the tarball is taken from its canonical address at
2023@code{gnu.org}, for the stable branch of Guix.
2024
f651b477
LC
2025@item --bootstrap
2026Use the bootstrap Guile to build the latest Guix. This option is only
2027useful to Guix developers.
2028@end table
2029
760c60d6
LC
2030
2031@node Invoking guix archive
2032@section Invoking @command{guix archive}
2033
2034The @command{guix archive} command allows users to @dfn{export} files
2035from the store into a single archive, and to later @dfn{import} them.
2036In particular, it allows store files to be transferred from one machine
4d4c4816
AE
2037to the store on another machine.
2038
2039To export store files as an archive to standard output, run:
2040
2041@example
2042guix archive --export @var{options} @var{specifications}...
2043@end example
2044
2045@var{specifications} may be either store file names or package
2046specifications, as for @command{guix package} (@pxref{Invoking guix
2047package}). For instance, the following command creates an archive
2048containing the @code{gui} output of the @code{git} package and the main
2049output of @code{emacs}:
2050
2051@example
2052guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2053@end example
2054
2055If the specified packages are not built yet, @command{guix archive}
2056automatically builds them. The build process may be controlled with the
2057common build options (@pxref{Common Build Options}).
2058
2059To transfer the @code{emacs} package to a machine connected over SSH,
2060one would run:
760c60d6
LC
2061
2062@example
56607088 2063guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
2064@end example
2065
87236aed 2066@noindent
56607088
LC
2067Similarly, a complete user profile may be transferred from one machine
2068to another like this:
2069
2070@example
2071guix archive --export -r $(readlink -f ~/.guix-profile) | \
2072 ssh the-machine guix-archive --import
2073@end example
2074
2075@noindent
2076However, note that, in both examples, all of @code{emacs} and the
2077profile as well as all of their dependencies are transferred (due to
f97c9175
AE
2078@code{-r}), regardless of what is already available in the store on the
2079target machine. The @code{--missing} option can help figure out which
2080items are missing from the target store.
87236aed 2081
760c60d6 2082Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
2083comparable in spirit to `tar', but with a few noteworthy differences
2084that make it more appropriate for our purposes. First, rather than
f97c9175 2085recording all Unix metadata for each file, the Nar format only mentions
0dbd88db
LC
2086the file type (regular, directory, or symbolic link); Unix permissions
2087and owner/group are dismissed. Second, the order in which directory
2088entries are stored always follows the order of file names according to
2089the C locale collation order. This makes archive production fully
2090deterministic.
2091
2092When exporting, the daemon digitally signs the contents of the archive,
2093and that digital signature is appended. When importing, the daemon
2094verifies the signature and rejects the import in case of an invalid
2095signature or if the signing key is not authorized.
760c60d6
LC
2096@c FIXME: Add xref to daemon doc about signatures.
2097
2098The main options are:
2099
2100@table @code
2101@item --export
2102Export the specified store files or packages (see below.) Write the
2103resulting archive to the standard output.
2104
56607088
LC
2105Dependencies are @emph{not} included in the output, unless
2106@code{--recursive} is passed.
2107
2108@item -r
2109@itemx --recursive
2110When combined with @code{--export}, this instructs @command{guix
2111archive} to include dependencies of the given items in the archive.
2112Thus, the resulting archive is self-contained: it contains the closure
2113of the exported store items.
2114
760c60d6
LC
2115@item --import
2116Read an archive from the standard input, and import the files listed
2117therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2118signature, or if it is signed by a public key not among the authorized
2119keys (see @code{--authorize} below.)
554f26ec 2120
87236aed
LC
2121@item --missing
2122Read a list of store file names from the standard input, one per line,
2123and write on the standard output the subset of these files missing from
2124the store.
2125
554f26ec 2126@item --generate-key[=@var{parameters}]
f82cc5fd 2127@cindex signing, archives
f97c9175 2128Generate a new key pair for the daemon. This is a prerequisite before
554f26ec
LC
2129archives can be exported with @code{--export}. Note that this operation
2130usually takes time, because it needs to gather enough entropy to
2131generate the key pair.
2132
2133The generated key pair is typically stored under @file{/etc/guix}, in
2134@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2135key, which must be kept secret.) When @var{parameters} is omitted,
2136an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2137versions before 1.6.0, it is a 4096-bit RSA key.
f97c9175 2138Alternatively, @var{parameters} can specify
554f26ec
LC
2139@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2140public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2141Libgcrypt Reference Manual}).
f82cc5fd
LC
2142
2143@item --authorize
2144@cindex authorizing, archives
2145Authorize imports signed by the public key passed on standard input.
2146The public key must be in ``s-expression advanced format''---i.e., the
2147same format as the @file{signing-key.pub} file.
2148
2149The list of authorized keys is kept in the human-editable file
2150@file{/etc/guix/acl}. The file contains
2151@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2152s-expressions''} and is structured as an access-control list in the
2153@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2154(SPKI)}.
c6f8e9dd
LC
2155
2156@item --extract=@var{directory}
2157@itemx -x @var{directory}
2158Read a single-item archive as served by substitute servers
2159(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2160low-level operation needed in only very narrow use cases; see below.
2161
2162For example, the following command extracts the substitute for Emacs
2163served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2164
2165@example
2166$ wget -O - \
2167 http://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2168 | bunzip2 | guix archive -x /tmp/emacs
2169@end example
2170
2171Single-item archives are different from multiple-item archives produced
2172by @command{guix archive --export}; they contain a single store item,
2173and they do @emph{not} embed a signature. Thus this operation does
2174@emph{no} signature verification and its output should be considered
2175unsafe.
2176
2177The primary purpose of this operation is to facilitate inspection of
2178archive contents coming from possibly untrusted substitute servers.
2179
760c60d6
LC
2180@end table
2181
c554de89
AK
2182@c *********************************************************************
2183@include emacs.texi
760c60d6 2184
568717fd
LC
2185@c *********************************************************************
2186@node Programming Interface
2187@chapter Programming Interface
2188
3dc1970d
LC
2189GNU Guix provides several Scheme programming interfaces (APIs) to
2190define, build, and query packages. The first interface allows users to
2191write high-level package definitions. These definitions refer to
2192familiar packaging concepts, such as the name and version of a package,
2193its build system, and its dependencies. These definitions can then be
2194turned into concrete build actions.
2195
ba55b1cb 2196Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2197standard setup, the daemon has write access to the store---the
834129e0 2198@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2199setup also has the daemon perform builds in chroots, under a specific
2200build users, to minimize interference with the rest of the system.
2201
2202@cindex derivation
2203Lower-level APIs are available to interact with the daemon and the
2204store. To instruct the daemon to perform a build action, users actually
2205provide it with a @dfn{derivation}. A derivation is a low-level
2206representation of the build actions to be taken, and the environment in
2207which they should occur---derivations are to package definitions what
49ad317a
LC
2208assembly is to C programs. The term ``derivation'' comes from the fact
2209that build results @emph{derive} from them.
3dc1970d
LC
2210
2211This chapter describes all these APIs in turn, starting from high-level
2212package definitions.
2213
568717fd 2214@menu
b860f382 2215* Defining Packages:: Defining new packages.
7458bd0a 2216* Build Systems:: Specifying how packages are built.
b860f382
LC
2217* The Store:: Manipulating the package store.
2218* Derivations:: Low-level interface to package derivations.
2219* The Store Monad:: Purely functional interface to the store.
21b679f6 2220* G-Expressions:: Manipulating build expressions.
568717fd
LC
2221@end menu
2222
2223@node Defining Packages
2224@section Defining Packages
2225
3dc1970d
LC
2226The high-level interface to package definitions is implemented in the
2227@code{(guix packages)} and @code{(guix build-system)} modules. As an
2228example, the package definition, or @dfn{recipe}, for the GNU Hello
2229package looks like this:
2230
2231@example
e7f34eb0
LC
2232(define-module (gnu packages hello)
2233 #:use-module (guix packages)
2234 #:use-module (guix download)
2235 #:use-module (guix build-system gnu)
a6dcdcac
SB
2236 #:use-module (guix licenses)
2237 #:use-module (gnu packages gawk))
b22a12fd 2238
79f5dd59 2239(define-public hello
3dc1970d
LC
2240 (package
2241 (name "hello")
17d8e33f 2242 (version "2.10")
3dc1970d 2243 (source (origin
17d8e33f
ML
2244 (method url-fetch)
2245 (uri (string-append "mirror://gnu/hello/hello-" version
2246 ".tar.gz"))
2247 (sha256
2248 (base32
2249 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2250 (build-system gnu-build-system)
7458bd0a 2251 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2252 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2253 (synopsis "Hello, GNU world: An example GNU package")
2254 (description "Guess what GNU Hello prints!")
3dc1970d 2255 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2256 (license gpl3+)))
3dc1970d
LC
2257@end example
2258
2259@noindent
2260Without being a Scheme expert, the reader may have guessed the meaning
f97c9175
AE
2261of the various fields here. This expression binds the variable
2262@code{hello} to a @code{<package>} object, which is essentially a record
3dc1970d
LC
2263(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2264This package object can be inspected using procedures found in the
2265@code{(guix packages)} module; for instance, @code{(package-name hello)}
2266returns---surprise!---@code{"hello"}.
2267
2f7d2d91
LC
2268With luck, you may be able to import part or all of the definition of
2269the package you are interested in from another repository, using the
2270@code{guix import} command (@pxref{Invoking guix import}).
2271
f97c9175 2272In the example above, @var{hello} is defined in a module of its own,
e7f34eb0
LC
2273@code{(gnu packages hello)}. Technically, this is not strictly
2274necessary, but it is convenient to do so: all the packages defined in
2275modules under @code{(gnu packages @dots{})} are automatically known to
2276the command-line tools (@pxref{Package Modules}).
2277
3dc1970d
LC
2278There are a few points worth noting in the above package definition:
2279
2280@itemize
2281@item
a2bf4907
LC
2282The @code{source} field of the package is an @code{<origin>} object
2283(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2284Here, the @code{url-fetch} method from @code{(guix download)} is used,
2285meaning that the source is a file to be downloaded over FTP or HTTP.
2286
2287The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2288the GNU mirrors defined in @code{(guix download)}.
2289
2290The @code{sha256} field specifies the expected SHA256 hash of the file
2291being downloaded. It is mandatory, and allows Guix to check the
2292integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2293base32 representation of the hash. You can obtain this information with
210cc920
LC
2294@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2295hash} (@pxref{Invoking guix hash}).
3dc1970d 2296
f9cc8971
LC
2297@cindex patches
2298When needed, the @code{origin} form can also have a @code{patches} field
2299listing patches to be applied, and a @code{snippet} field giving a
2300Scheme expression to modify the source code.
2301
3dc1970d
LC
2302@item
2303@cindex GNU Build System
7458bd0a
LC
2304The @code{build-system} field specifies the procedure to build the
2305package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2306represents the familiar GNU Build System, where packages may be
2307configured, built, and installed with the usual @code{./configure &&
2308make && make check && make install} command sequence.
2309
2310@item
2311The @code{arguments} field specifies options for the build system
2312(@pxref{Build Systems}). Here it is interpreted by
2313@var{gnu-build-system} as a request run @file{configure} with the
2314@code{--enable-silent-rules} flag.
3dc1970d
LC
2315
2316@item
2317The @code{inputs} field specifies inputs to the build process---i.e.,
2318build-time or run-time dependencies of the package. Here, we define an
2319input called @code{"gawk"} whose value is that of the @var{gawk}
2320variable; @var{gawk} is itself bound to a @code{<package>} object.
2321
2322Note that GCC, Coreutils, Bash, and other essential tools do not need to
2323be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2324of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2325
2326However, any other dependencies need to be specified in the
2327@code{inputs} field. Any dependency not specified here will simply be
2328unavailable to the build process, possibly leading to a build failure.
2329@end itemize
2330
87eafdbd
TUBK
2331@xref{package Reference}, for a full description of possible fields.
2332
2f7d2d91 2333Once a package definition is in place, the
e49951eb 2334package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2335tool (@pxref{Invoking guix build}). You can easily jump back to the
2336package definition using the @command{guix edit} command
2337(@pxref{Invoking guix edit}).
2338@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2339more information on how to test package definitions, and
2340@ref{Invoking guix lint}, for information on how to check a definition
2341for style conformance.
2342
f97c9175 2343Finally, updating the package definition to a new upstream version
7458bd0a
LC
2344can be partly automated by the @command{guix refresh} command
2345(@pxref{Invoking guix refresh}).
3dc1970d
LC
2346
2347Behind the scenes, a derivation corresponding to the @code{<package>}
2348object is first computed by the @code{package-derivation} procedure.
834129e0 2349That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2350The build actions it prescribes may then be realized by using the
3dc1970d
LC
2351@code{build-derivations} procedure (@pxref{The Store}).
2352
2353@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2354Return the @code{<derivation>} object of @var{package} for @var{system}
2355(@pxref{Derivations}).
3dc1970d
LC
2356
2357@var{package} must be a valid @code{<package>} object, and @var{system}
2358must be a string denoting the target system type---e.g.,
2359@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2360must be a connection to the daemon, which operates on the store
2361(@pxref{The Store}).
2362@end deffn
568717fd 2363
9c1edabd
LC
2364@noindent
2365@cindex cross-compilation
2366Similarly, it is possible to compute a derivation that cross-builds a
2367package for some other system:
2368
2369@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2370 @var{package} @var{target} [@var{system}]
59688fc4
LC
2371Return the @code{<derivation>} object of @var{package} cross-built from
2372@var{system} to @var{target}.
9c1edabd
LC
2373
2374@var{target} must be a valid GNU triplet denoting the target hardware
2375and operating system, such as @code{"mips64el-linux-gnu"}
2376(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2377Configure and Build System}).
2378@end deffn
2379
87eafdbd
TUBK
2380@menu
2381* package Reference :: The package data type.
2382* origin Reference:: The origin data type.
2383@end menu
2384
2385
2386@node package Reference
2387@subsection @code{package} Reference
2388
2389This section summarizes all the options available in @code{package}
2390declarations (@pxref{Defining Packages}).
2391
2392@deftp {Data Type} package
2393This is the data type representing a package recipe.
2394
2395@table @asis
2396@item @code{name}
2397The name of the package, as a string.
2398
2399@item @code{version}
2400The version of the package, as a string.
2401
2402@item @code{source}
2403An origin object telling how the source code for the package should be
2404acquired (@pxref{origin Reference}).
2405
2406@item @code{build-system}
2407The build system that should be used to build the package (@pxref{Build
2408Systems}).
2409
2410@item @code{arguments} (default: @code{'()})
2411The arguments that should be passed to the build system. This is a
2412list, typically containing sequential keyword-value pairs.
2413
2414@item @code{inputs} (default: @code{'()})
70650c68
LC
2415@itemx @code{native-inputs} (default: @code{'()})
2416@itemx @code{propagated-inputs} (default: @code{'()})
2417@cindex inputs, of packages
2418These fields list dependencies of the package. Each one is a list of
2419tuples, where each tuple has a label for the input (a string) as its
2420first element, a package, origin, or derivation as its second element,
2421and optionally the name of the output thereof that should be used, which
2422defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
f97c9175 2423more on package outputs). For example, the list below specifies three
70650c68 2424inputs:
87eafdbd 2425
70650c68
LC
2426@example
2427`(("libffi" ,libffi)
2428 ("libunistring" ,libunistring)
2429 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2430@end example
2431
2432@cindex cross compilation, package dependencies
2433The distinction between @code{native-inputs} and @code{inputs} is
2434necessary when considering cross-compilation. When cross-compiling,
2435dependencies listed in @code{inputs} are built for the @emph{target}
2436architecture; conversely, dependencies listed in @code{native-inputs}
2437are built for the architecture of the @emph{build} machine.
2438
f97c9175
AE
2439@code{native-inputs} is typically used to list tools needed at
2440build time, but not at run time, such as Autoconf, Automake, pkg-config,
70650c68
LC
2441Gettext, or Bison. @command{guix lint} can report likely mistakes in
2442this area (@pxref{Invoking guix lint}).
2443
2444@anchor{package-propagated-inputs}
2445Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
f97c9175
AE
2446specified packages will be automatically installed alongside the package
2447they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
70650c68
LC
2448package}}, for information on how @command{guix package} deals with
2449propagated inputs.)
21461f27 2450
e0508b6b
LC
2451For example this is necessary when a C/C++ library needs headers of
2452another library to compile, or when a pkg-config file refers to another
2453one @i{via} its @code{Requires} field.
2454
f97c9175
AE
2455Another example where @code{propagated-inputs} is useful is for languages
2456that lack a facility to record the run-time search path akin to the
2457@code{RUNPATH}of ELF files; this includes Guile, Python, Perl, GHC, and
e0508b6b
LC
2458more. To ensure that libraries written in those languages can find
2459library code they depend on at run time, run-time dependencies must be
2460listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2461
87eafdbd
TUBK
2462@item @code{self-native-input?} (default: @code{#f})
2463This is a Boolean field telling whether the package should use itself as
2464a native input when cross-compiling.
2465
2466@item @code{outputs} (default: @code{'("out")})
2467The list of output names of the package. @xref{Packages with Multiple
2468Outputs}, for typical uses of additional outputs.
2469
2470@item @code{native-search-paths} (default: @code{'()})
2471@itemx @code{search-paths} (default: @code{'()})
2472A list of @code{search-path-specification} objects describing
2473search-path environment variables honored by the package.
2474
2475@item @code{replacement} (default: @code{#f})
f97c9175 2476This must be either @code{#f} or a package object that will be used as a
87eafdbd
TUBK
2477@dfn{replacement} for this package. @xref{Security Updates, grafts},
2478for details.
2479
2480@item @code{synopsis}
2481A one-line description of the package.
2482
2483@item @code{description}
2484A more elaborate description of the package.
2485
2486@item @code{license}
f97c9175
AE
2487The license of the package; a value from @code{(guix licenses)},
2488or a list of such values.
87eafdbd
TUBK
2489
2490@item @code{home-page}
2491The URL to the home-page of the package, as a string.
2492
2493@item @code{supported-systems} (default: @var{%supported-systems})
2494The list of systems supported by the package, as strings of the form
2495@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2496
2497@item @code{maintainers} (default: @code{'()})
2498The list of maintainers of the package, as @code{maintainer} objects.
2499
2500@item @code{location} (default: source location of the @code{package} form)
f97c9175 2501The source location of the package. It is useful to override this when
87eafdbd
TUBK
2502inheriting from another package, in which case this field is not
2503automatically corrected.
2504@end table
2505@end deftp
2506
2507
2508@node origin Reference
2509@subsection @code{origin} Reference
2510
2511This section summarizes all the options available in @code{origin}
2512declarations (@pxref{Defining Packages}).
2513
2514@deftp {Data Type} origin
2515This is the data type representing a source code origin.
2516
2517@table @asis
2518@item @code{uri}
2519An object containing the URI of the source. The object type depends on
2520the @code{method} (see below). For example, when using the
2521@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2522values are: a URL represented as a string, or a list thereof.
2523
2524@item @code{method}
f97c9175 2525A procedure that handles the URI.
87eafdbd
TUBK
2526
2527Examples include:
2528
2529@table @asis
2530@item @var{url-fetch} from @code{(guix download)}
f97c9175 2531download a file from the HTTP, HTTPS, or FTP URL specified in the
87eafdbd
TUBK
2532@code{uri} field;
2533
2534@item @var{git-fetch} from @code{(guix git-download)}
2535clone the Git version control repository, and check out the revision
2536specified in the @code{uri} field as a @code{git-reference} object; a
2537@code{git-reference} looks like this:
2538
2539@example
2540(git-reference
2541 (url "git://git.debian.org/git/pkg-shadow/shadow")
2542 (commit "v4.1.5.1"))
2543@end example
2544@end table
2545
2546@item @code{sha256}
2547A bytevector containing the SHA-256 hash of the source. Typically the
2548@code{base32} form is used here to generate the bytevector from a
2549base-32 string.
2550
2551@item @code{file-name} (default: @code{#f})
2552The file name under which the source code should be saved. When this is
2553@code{#f}, a sensible default value will be used in most cases. In case
2554the source is fetched from a URL, the file name from the URL will be
f97c9175 2555used. For version control checkouts, it is recommended to provide the
87eafdbd
TUBK
2556file name explicitly because the default is not very descriptive.
2557
2558@item @code{patches} (default: @code{'()})
2559A list of file names containing patches to be applied to the source.
2560
2561@item @code{snippet} (default: @code{#f})
2562A quoted piece of code that will be run in the source directory to make
2563any modifications, which is sometimes more convenient than a patch.
2564
2565@item @code{patch-flags} (default: @code{'("-p1")})
2566A list of command-line flags that should be passed to the @code{patch}
2567command.
2568
2569@item @code{patch-inputs} (default: @code{#f})
2570Input packages or derivations to the patching process. When this is
2571@code{#f}, the usual set of inputs necessary for patching are provided,
2572such as GNU@tie{}Patch.
2573
2574@item @code{modules} (default: @code{'()})
2575A list of Guile modules that should be loaded during the patching
2576process and while running the code in the @code{snippet} field.
2577
2578@item @code{imported-modules} (default: @code{'()})
2579The list of Guile modules to import in the patch derivation, for use by
2580the @code{snippet}.
2581
2582@item @code{patch-guile} (default: @code{#f})
2583The Guile package that should be used in the patching process. When
2584this is @code{#f}, a sensible default is used.
2585@end table
2586@end deftp
2587
9c1edabd 2588
7458bd0a
LC
2589@node Build Systems
2590@section Build Systems
2591
2592@cindex build system
2593Each package definition specifies a @dfn{build system} and arguments for
2594that build system (@pxref{Defining Packages}). This @code{build-system}
f97c9175 2595field represents the build procedure of the package, as well as implicit
7458bd0a
LC
2596dependencies of that build procedure.
2597
2598Build systems are @code{<build-system>} objects. The interface to
2599create and manipulate them is provided by the @code{(guix build-system)}
2600module, and actual build systems are exported by specific modules.
2601
f5fd4fd2 2602@cindex bag (low-level package representation)
0d5a559f
LC
2603Under the hood, build systems first compile package objects to
2604@dfn{bags}. A @dfn{bag} is like a package, but with less
2605ornamentation---in other words, a bag is a lower-level representation of
2606a package, which includes all the inputs of that package, including some
2607that were implicitly added by the build system. This intermediate
2608representation is then compiled to a derivation (@pxref{Derivations}).
2609
7458bd0a
LC
2610Build systems accept an optional list of @dfn{arguments}. In package
2611definitions, these are passed @i{via} the @code{arguments} field
2612(@pxref{Defining Packages}). They are typically keyword arguments
2613(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2614Guile Reference Manual}). The value of these arguments is usually
2615evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2616by the daemon (@pxref{Derivations}).
2617
2618The main build system is @var{gnu-build-system}, which implements the
f97c9175 2619standard build procedure for GNU and many other packages. It
7458bd0a
LC
2620is provided by the @code{(guix build-system gnu)} module.
2621
2622@defvr {Scheme Variable} gnu-build-system
2623@var{gnu-build-system} represents the GNU Build System, and variants
2624thereof (@pxref{Configuration, configuration and makefile conventions,,
2625standards, GNU Coding Standards}).
2626
2627@cindex build phases
f97c9175 2628In a nutshell, packages using it are configured, built, and installed with
7458bd0a
LC
2629the usual @code{./configure && make && make check && make install}
2630command sequence. In practice, a few additional steps are often needed.
2631All these steps are split up in separate @dfn{phases},
2632notably@footnote{Please see the @code{(guix build gnu-build-system)}
2633modules for more details about the build phases.}:
2634
2635@table @code
2636@item unpack
2637Unpack the source tarball, and change the current directory to the
2638extracted source tree. If the source is actually a directory, copy it
2639to the build tree, and enter that directory.
2640
2641@item patch-source-shebangs
2642Patch shebangs encountered in source files so they refer to the right
2643store file names. For instance, this changes @code{#!/bin/sh} to
2644@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2645
2646@item configure
2647Run the @file{configure} script with a number of default options, such
2648as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2649by the @code{#:configure-flags} argument.
2650
2651@item build
2652Run @code{make} with the list of flags specified with
0917e80e 2653@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
2654(the default), build with @code{make -j}.
2655
2656@item check
2657Run @code{make check}, or some other target specified with
2658@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2659@code{#:parallel-tests?} argument is true (the default), run @code{make
2660check -j}.
2661
2662@item install
2663Run @code{make install} with the flags listed in @code{#:make-flags}.
2664
2665@item patch-shebangs
2666Patch shebangs on the installed executable files.
2667
2668@item strip
2669Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2670is false), copying them to the @code{debug} output when available
2671(@pxref{Installing Debugging Files}).
2672@end table
2673
2674@vindex %standard-phases
2675The build-side module @code{(guix build gnu-build-system)} defines
2676@var{%standard-phases} as the default list of build phases.
2677@var{%standard-phases} is a list of symbol/procedure pairs, where the
2678procedure implements the actual phase.
2679
2680The list of phases used for a particular package can be changed with the
2681@code{#:phases} parameter. For instance, passing:
2682
2683@example
c2c5dc79 2684#:phases (modify-phases %standard-phases (delete 'configure))
7458bd0a
LC
2685@end example
2686
9bf404e9 2687means that all the phases described above will be used, except the
7458bd0a
LC
2688@code{configure} phase.
2689
2690In addition, this build system ensures that the ``standard'' environment
2691for GNU packages is available. This includes tools such as GCC, libc,
2692Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
f97c9175
AE
2693build-system gnu)} module for a complete list). We call these the
2694@dfn{implicit inputs} of a package, because package definitions do not
7458bd0a
LC
2695have to mention them.
2696@end defvr
2697
2698Other @code{<build-system>} objects are defined to support other
2699conventions and tools used by free software packages. They inherit most
2700of @var{gnu-build-system}, and differ mainly in the set of inputs
2701implicitly added to the build process, and in the list of phases
2702executed. Some of these build systems are listed below.
2703
2704@defvr {Scheme Variable} cmake-build-system
2705This variable is exported by @code{(guix build-system cmake)}. It
2706implements the build procedure for packages using the
2707@url{http://www.cmake.org, CMake build tool}.
2708
2709It automatically adds the @code{cmake} package to the set of inputs.
2710Which package is used can be specified with the @code{#:cmake}
2711parameter.
9849cfc1
LC
2712
2713The @code{#:configure-flags} parameter is taken as a list of flags
2714passed to the @command{cmake} command. The @code{#:build-type}
2715parameter specifies in abstract terms the flags passed to the compiler;
2716it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2717debugging information''), which roughly means that code is compiled with
2718@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
2719@end defvr
2720
3afcf52b
FB
2721@defvr {Scheme Variable} glib-or-gtk-build-system
2722This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2723is intended for use with packages making use of GLib or GTK+.
2724
2725This build system adds the following two phases to the ones defined by
2726@var{gnu-build-system}:
2727
2728@table @code
2729@item glib-or-gtk-wrap
f97c9175
AE
2730The phase @code{glib-or-gtk-wrap} ensures that programs in
2731@file{bin/} are able to find GLib ``schemas'' and
3afcf52b
FB
2732@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2733modules}. This is achieved by wrapping the programs in launch scripts
2734that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2735environment variables.
2736
73aa8ddb
LC
2737It is possible to exclude specific package outputs from that wrapping
2738process by listing their names in the
2739@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2740when an output is known not to contain any GLib or GTK+ binaries, and
2741where wrapping would gratuitously add a dependency of that output on
2742GLib and GTK+.
2743
3afcf52b 2744@item glib-or-gtk-compile-schemas
f97c9175 2745The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3afcf52b 2746@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
f97c9175 2747GSettings schemas} of GLib are compiled. Compilation is performed by the
3afcf52b
FB
2748@command{glib-compile-schemas} program. It is provided by the package
2749@code{glib:bin} which is automatically imported by the build system.
2750The @code{glib} package providing @command{glib-compile-schemas} can be
2751specified with the @code{#:glib} parameter.
2752@end table
2753
2754Both phases are executed after the @code{install} phase.
2755@end defvr
2756
7458bd0a
LC
2757@defvr {Scheme Variable} python-build-system
2758This variable is exported by @code{(guix build-system python)}. It
2759implements the more or less standard build procedure used by Python
2760packages, which consists in running @code{python setup.py build} and
2761then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2762
2763For packages that install stand-alone Python programs under @code{bin/},
f97c9175 2764it takes care of wrapping these programs so that their @code{PYTHONPATH}
7458bd0a
LC
2765environment variable points to all the Python libraries they depend on.
2766
2767Which Python package is used can be specified with the @code{#:python}
2768parameter.
2769@end defvr
2770
2771@defvr {Scheme Variable} perl-build-system
2772This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2773implements the standard build procedure for Perl packages, which either
2774consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2775followed by @code{Build} and @code{Build install}; or in running
2776@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
f97c9175 2777@code{make} and @code{make install}, depending on which of
2d2a53fc
EB
2778@code{Build.PL} or @code{Makefile.PL} is present in the package
2779distribution. Preference is given to the former if both @code{Build.PL}
2780and @code{Makefile.PL} exist in the package distribution. This
2781preference can be reversed by specifying @code{#t} for the
2782@code{#:make-maker?} parameter.
2783
2784The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2785passes flags specified by the @code{#:make-maker-flags} or
2786@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2787
2788Which Perl package is used can be specified with @code{#:perl}.
2789@end defvr
2790
f8f3bef6
RW
2791@defvr {Scheme Variable} r-build-system
2792This variable is exported by @code{(guix build-system r)}. It
2793implements the build procedure used by @uref{http://r-project.org, R}
2794packages, which essentially is little more than running @code{R CMD
2795INSTALL --library=/gnu/store/@dots{}} in an environment where
2796@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2797are run after installation using the R function
2798@code{tools::testInstalledPackage}.
2799@end defvr
2800
c08f9818
DT
2801@defvr {Scheme Variable} ruby-build-system
2802This variable is exported by @code{(guix build-system ruby)}. It
2803implements the RubyGems build procedure used by Ruby packages, which
2804involves running @code{gem build} followed by @code{gem install}.
2805
5dc87623
DT
2806The @code{source} field of a package that uses this build system
2807typically references a gem archive, since this is the format that Ruby
2808developers use when releasing their software. The build system unpacks
2809the gem archive, potentially patches the source, runs the test suite,
2810repackages the gem, and installs it. Additionally, directories and
2811tarballs may be referenced to allow building unreleased gems from Git or
2812a traditional source release tarball.
e83c6d00 2813
c08f9818 2814Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
2815parameter. A list of additional flags to be passed to the @command{gem}
2816command can be specified with the @code{#:gem-flags} parameter.
c08f9818 2817@end defvr
7458bd0a 2818
a677c726
RW
2819@defvr {Scheme Variable} waf-build-system
2820This variable is exported by @code{(guix build-system waf)}. It
2821implements a build procedure around the @code{waf} script. The common
2822phases---@code{configure}, @code{build}, and @code{install}---are
2823implemented by passing their names as arguments to the @code{waf}
2824script.
2825
2826The @code{waf} script is executed by the Python interpreter. Which
2827Python package is used to run the script can be specified with the
2828@code{#:python} parameter.
2829@end defvr
2830
14dfdf2e
FB
2831@defvr {Scheme Variable} haskell-build-system
2832This variable is exported by @code{(guix build-system haskell)}. It
2833implements the Cabal build procedure used by Haskell packages, which
2834involves running @code{runhaskell Setup.hs configure
2835--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2836Instead of installing the package by running @code{runhaskell Setup.hs
2837install}, to avoid trying to register libraries in the read-only
2838compiler store directory, the build system uses @code{runhaskell
2839Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2840addition, the build system generates the package documentation by
2841running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2842is passed. Optional Haddock parameters can be passed with the help of
2843the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2844not found, the build system looks for @code{Setup.lhs} instead.
2845
2846Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 2847parameter which defaults to @code{ghc}.
14dfdf2e
FB
2848@end defvr
2849
e9137a53
FB
2850@defvr {Scheme Variable} emacs-build-system
2851This variable is exported by @code{(guix build-system emacs)}. It
f97c9175
AE
2852implements an installation procedure similar to the packaging system
2853of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
e9137a53
FB
2854
2855It first creates the @code{@var{package}-autoloads.el} file, then it
2856byte compiles all Emacs Lisp files. Differently from the Emacs
2857packaging system, the Info documentation files are moved to the standard
2858documentation directory and the @file{dir} file is deleted. Each
2859package is installed in its own directory under
2860@file{share/emacs/site-lisp/guix.d}.
2861@end defvr
2862
7458bd0a
LC
2863Lastly, for packages that do not need anything as sophisticated, a
2864``trivial'' build system is provided. It is trivial in the sense that
2865it provides basically no support: it does not pull any implicit inputs,
2866and does not have a notion of build phases.
2867
2868@defvr {Scheme Variable} trivial-build-system
2869This variable is exported by @code{(guix build-system trivial)}.
2870
2871This build system requires a @code{#:builder} argument. This argument
f97c9175 2872must be a Scheme expression that builds the package output(s)---as
7458bd0a
LC
2873with @code{build-expression->derivation} (@pxref{Derivations,
2874@code{build-expression->derivation}}).
2875@end defvr
2876
568717fd
LC
2877@node The Store
2878@section The Store
2879
e531ac2a
LC
2880@cindex store
2881@cindex store paths
2882
f97c9175
AE
2883Conceptually, the @dfn{store} is the place where derivations that have
2884been built successfully are stored---by default, @file{/gnu/store}.
e531ac2a 2885Sub-directories in the store are referred to as @dfn{store paths}. The
4988dd40 2886store has an associated database that contains information such as the
e531ac2a
LC
2887store paths referred to by each store path, and the list of @emph{valid}
2888store paths---paths that result from a successful build.
2889
2890The store is always accessed by the daemon on behalf of its clients
2891(@pxref{Invoking guix-daemon}). To manipulate the store, clients
f97c9175
AE
2892connect to the daemon over a Unix-domain socket, send requests to it,
2893and read the result---these are remote procedure calls, or RPCs.
e531ac2a
LC
2894
2895The @code{(guix store)} module provides procedures to connect to the
2896daemon, and to perform RPCs. These are described below.
2897
2898@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2899Connect to the daemon over the Unix-domain socket at @var{file}. When
2900@var{reserve-space?} is true, instruct it to reserve a little bit of
2901extra space on the file system so that the garbage collector can still
f97c9175 2902operate should the disk become full. Return a server object.
e531ac2a
LC
2903
2904@var{file} defaults to @var{%default-socket-path}, which is the normal
2905location given the options that were passed to @command{configure}.
2906@end deffn
2907
2908@deffn {Scheme Procedure} close-connection @var{server}
2909Close the connection to @var{server}.
2910@end deffn
2911
2912@defvr {Scheme Variable} current-build-output-port
2913This variable is bound to a SRFI-39 parameter, which refers to the port
2914where build and error logs sent by the daemon should be written.
2915@end defvr
2916
2917Procedures that make RPCs all take a server object as their first
2918argument.
2919
2920@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
06b76acc
LC
2921@cindex invalid store items
2922Return @code{#t} when @var{path} designates a valid store item and
2923@code{#f} otherwise (an invalid item may exist on disk but still be
2924invalid, for instance because it is the result of an aborted or failed
2925build.)
2926
2927A @code{&nix-protocol-error} condition is raised if @var{path} is not
2928prefixed by the store directory (@file{/gnu/store}).
e531ac2a
LC
2929@end deffn
2930
cfbf9160 2931@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
2932Add @var{text} under file @var{name} in the store, and return its store
2933path. @var{references} is the list of store paths referred to by the
2934resulting store path.
2935@end deffn
2936
874e6874 2937@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
2938Build @var{derivations} (a list of @code{<derivation>} objects or
2939derivation paths), and return when the worker is done building them.
2940Return @code{#t} on success.
874e6874
LC
2941@end deffn
2942
b860f382
LC
2943Note that the @code{(guix monads)} module provides a monad as well as
2944monadic versions of the above procedures, with the goal of making it
2945more convenient to work with code that accesses the store (@pxref{The
2946Store Monad}).
2947
e531ac2a
LC
2948@c FIXME
2949@i{This section is currently incomplete.}
568717fd
LC
2950
2951@node Derivations
2952@section Derivations
2953
874e6874
LC
2954@cindex derivations
2955Low-level build actions and the environment in which they are performed
2956are represented by @dfn{derivations}. A derivation contain the
2957following pieces of information:
2958
2959@itemize
2960@item
2961The outputs of the derivation---derivations produce at least one file or
2962directory in the store, but may produce more.
2963
2964@item
2965The inputs of the derivations, which may be other derivations or plain
2966files in the store (patches, build scripts, etc.)
2967
2968@item
2969The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2970
2971@item
2972The file name of a build script in the store, along with the arguments
2973to be passed.
2974
2975@item
2976A list of environment variables to be defined.
2977
2978@end itemize
2979
2980@cindex derivation path
2981Derivations allow clients of the daemon to communicate build actions to
2982the store. They exist in two forms: as an in-memory representation,
2983both on the client- and daemon-side, and as files in the store whose
2984name end in @code{.drv}---these files are referred to as @dfn{derivation
2985paths}. Derivations paths can be passed to the @code{build-derivations}
2986procedure to perform the build actions they prescribe (@pxref{The
2987Store}).
2988
2989The @code{(guix derivations)} module provides a representation of
2990derivations as Scheme objects, along with procedures to create and
2991otherwise manipulate derivations. The lowest-level primitive to create
2992a derivation is the @code{derivation} procedure:
2993
1909431c
LC
2994@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2995 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 2996 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 2997 [#:system (%current-system)] [#:references-graphs #f] @
4a6aeb67
LC
2998 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
2999 [#:substitutable? #t]
59688fc4
LC
3000Build a derivation with the given arguments, and return the resulting
3001@code{<derivation>} object.
874e6874 3002
2096ef47 3003When @var{hash} and @var{hash-algo} are given, a
874e6874 3004@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
3005known in advance, such as a file download. If, in addition,
3006@var{recursive?} is true, then that fixed output may be an executable
3007file or a directory and @var{hash} must be the hash of an archive
3008containing this output.
5b0c9d16 3009
858e9282 3010When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
3011name/store path pairs. In that case, the reference graph of each store
3012path is exported in the build environment in the corresponding file, in
3013a simple text format.
1909431c 3014
b53be755
LC
3015When @var{allowed-references} is true, it must be a list of store items
3016or outputs that the derivation's output may refer to.
3017
c0468155
LC
3018When @var{leaked-env-vars} is true, it must be a list of strings
3019denoting environment variables that are allowed to ``leak'' from the
3020daemon's environment to the build environment. This is only applicable
3021to fixed-output derivations---i.e., when @var{hash} is true. The main
3022use is to allow variables such as @code{http_proxy} to be passed to
3023derivations that download files.
3024
1909431c
LC
3025When @var{local-build?} is true, declare that the derivation is not a
3026good candidate for offloading and should rather be built locally
3027(@pxref{Daemon Offload Setup}). This is the case for small derivations
3028where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
3029
3030When @var{substitutable?} is false, declare that substitutes of the
3031derivation's output should not be used (@pxref{Substitutes}). This is
3032useful, for instance, when building packages that capture details of the
3033host CPU instruction set.
874e6874
LC
3034@end deffn
3035
3036@noindent
3037Here's an example with a shell script as its builder, assuming
3038@var{store} is an open connection to the daemon, and @var{bash} points
3039to a Bash executable in the store:
3040
3041@lisp
3042(use-modules (guix utils)
3043 (guix store)
3044 (guix derivations))
3045
59688fc4
LC
3046(let ((builder ; add the Bash script to the store
3047 (add-text-to-store store "my-builder.sh"
3048 "echo hello world > $out\n" '())))
3049 (derivation store "foo"
3050 bash `("-e" ,builder)
21b679f6 3051 #:inputs `((,bash) (,builder))
59688fc4 3052 #:env-vars '(("HOME" . "/homeless"))))
834129e0 3053@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
3054@end lisp
3055
21b679f6
LC
3056As can be guessed, this primitive is cumbersome to use directly. A
3057better approach is to write build scripts in Scheme, of course! The
3058best course of action for that is to write the build code as a
3059``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 3060information, @pxref{G-Expressions}.
21b679f6 3061
f2fadbc1
AE
3062Once upon a time, @code{gexp->derivation} did not exist and constructing
3063derivations with build code written in Scheme was achieved with
3064@code{build-expression->derivation}, documented below. This procedure
3065is now deprecated in favor of the much nicer @code{gexp->derivation}.
3066
3067@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3068 @var{name} @var{exp} @
3069 [#:system (%current-system)] [#:inputs '()] @
3070 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3071 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3072 [#:references-graphs #f] [#:allowed-references #f] @
3073 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3074Return a derivation that executes Scheme expression @var{exp} as a
3075builder for derivation @var{name}. @var{inputs} must be a list of
3076@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3077@code{"out"} is assumed. @var{modules} is a list of names of Guile
3078modules from the current search path to be copied in the store,
3079compiled, and made available in the load path during the execution of
3080@var{exp}---e.g., @code{((guix build utils) (guix build
3081gnu-build-system))}.
3082
3083@var{exp} is evaluated in an environment where @code{%outputs} is bound
3084to a list of output/path pairs, and where @code{%build-inputs} is bound
3085to a list of string/output-path pairs made from @var{inputs}.
3086Optionally, @var{env-vars} is a list of string pairs specifying the name
3087and value of environment variables visible to the builder. The builder
3088terminates by passing the result of @var{exp} to @code{exit}; thus, when
3089@var{exp} returns @code{#f}, the build is considered to have failed.
3090
3091@var{exp} is built using @var{guile-for-build} (a derivation). When
3092@var{guile-for-build} is omitted or is @code{#f}, the value of the
3093@code{%guile-for-build} fluid is used instead.
3094
3095See the @code{derivation} procedure for the meaning of
3096@var{references-graphs}, @var{allowed-references}, @var{local-build?},
3097and @var{substitutable?}.
3098@end deffn
3099
3100@noindent
3101Here's an example of a single-output derivation that creates a directory
3102containing one file:
3103
3104@lisp
3105(let ((builder '(let ((out (assoc-ref %outputs "out")))
3106 (mkdir out) ; create /gnu/store/@dots{}-goo
3107 (call-with-output-file (string-append out "/test")
3108 (lambda (p)
3109 (display '(hello guix) p))))))
3110 (build-expression->derivation store "goo" builder))
3111
3112@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3113@end lisp
3114
568717fd 3115
b860f382
LC
3116@node The Store Monad
3117@section The Store Monad
3118
3119@cindex monad
3120
3121The procedures that operate on the store described in the previous
3122sections all take an open connection to the build daemon as their first
3123argument. Although the underlying model is functional, they either have
3124side effects or depend on the current state of the store.
3125
3126The former is inconvenient: the connection to the build daemon has to be
3127carried around in all those functions, making it impossible to compose
3128functions that do not take that parameter with functions that do. The
3129latter can be problematic: since store operations have side effects
3130and/or depend on external state, they have to be properly sequenced.
3131
3132@cindex monadic values
3133@cindex monadic functions
3134This is where the @code{(guix monads)} module comes in. This module
3135provides a framework for working with @dfn{monads}, and a particularly
3136useful monad for our uses, the @dfn{store monad}. Monads are a
3137construct that allows two things: associating ``context'' with values
3138(in our case, the context is the store), and building sequences of
561fb6c3 3139computations (here computations include accesses to the store.) Values
b860f382
LC
3140in a monad---values that carry this additional context---are called
3141@dfn{monadic values}; procedures that return such values are called
3142@dfn{monadic procedures}.
3143
3144Consider this ``normal'' procedure:
3145
3146@example
45adbd62
LC
3147(define (sh-symlink store)
3148 ;; Return a derivation that symlinks the 'bash' executable.
3149 (let* ((drv (package-derivation store bash))
3150 (out (derivation->output-path drv))
3151 (sh (string-append out "/bin/bash")))
3152 (build-expression->derivation store "sh"
3153 `(symlink ,sh %output))))
b860f382
LC
3154@end example
3155
c6f30b81
LC
3156Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3157as a monadic function:
b860f382
LC
3158
3159@example
45adbd62 3160(define (sh-symlink)
b860f382 3161 ;; Same, but return a monadic value.
c6f30b81
LC
3162 (mlet %store-monad ((drv (package->derivation bash)))
3163 (gexp->derivation "sh"
3164 #~(symlink (string-append #$drv "/bin/bash")
3165 #$output))))
b860f382
LC
3166@end example
3167
c6f30b81
LC
3168There several things to note in the second version: the @code{store}
3169parameter is now implicit and is ``threaded'' in the calls to the
3170@code{package->derivation} and @code{gexp->derivation} monadic
3171procedures, and the monadic value returned by @code{package->derivation}
3172is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3173
3174As it turns out, the call to @code{package->derivation} can even be
3175omitted since it will take place implicitly, as we will see later
3176(@pxref{G-Expressions}):
3177
3178@example
3179(define (sh-symlink)
3180 (gexp->derivation "sh"
3181 #~(symlink (string-append #$bash "/bin/bash")
3182 #$output)))
3183@end example
b860f382 3184
7ce21611
LC
3185@c See
3186@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3187@c for the funny quote.
3188Calling the monadic @code{sh-symlink} has no effect. As someone once
3189said, ``you exit a monad like you exit a building on fire: by running''.
3190So, to exit the monad and get the desired effect, one must use
3191@code{run-with-store}:
b860f382
LC
3192
3193@example
8e9aa37f
CAW
3194(run-with-store (open-connection) (sh-symlink))
3195@result{} /gnu/store/...-sh-symlink
b860f382
LC
3196@end example
3197
f97c9175 3198Note that the @code{(guix monad-repl)} module extends the Guile REPL with
b9b86078 3199new ``meta-commands'' to make it easier to deal with monadic procedures:
f97c9175 3200@code{run-in-store}, and @code{enter-store-monad}. The former is used
b9b86078
LC
3201to ``run'' a single monadic value through the store:
3202
3203@example
3204scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3205$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3206@end example
3207
3208The latter enters a recursive REPL, where all the return values are
3209automatically run through the store:
3210
3211@example
3212scheme@@(guile-user)> ,enter-store-monad
3213store-monad@@(guile-user) [1]> (package->derivation hello)
3214$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3215store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3216$3 = "/gnu/store/@dots{}-foo"
3217store-monad@@(guile-user) [1]> ,q
3218scheme@@(guile-user)>
3219@end example
3220
3221@noindent
3222Note that non-monadic values cannot be returned in the
3223@code{store-monad} REPL.
3224
e87f0591
LC
3225The main syntactic forms to deal with monads in general are provided by
3226the @code{(guix monads)} module and are described below.
b860f382
LC
3227
3228@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3229Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3230in @var{monad}.
3231@end deffn
3232
3233@deffn {Scheme Syntax} return @var{val}
3234Return a monadic value that encapsulates @var{val}.
3235@end deffn
3236
751630c9 3237@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3238@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3239procedures @var{mproc}@dots{}@footnote{This operation is commonly
3240referred to as ``bind'', but that name denotes an unrelated procedure in
3241Guile. Thus we use this somewhat cryptic symbol inherited from the
3242Haskell language.}. There can be one @var{mproc} or several of them, as
3243in this example:
3244
3245@example
3246(run-with-state
3247 (with-monad %state-monad
3248 (>>= (return 1)
3249 (lambda (x) (return (+ 1 x)))
3250 (lambda (x) (return (* 2 x)))))
3251 'some-state)
3252
3253@result{} 4
3254@result{} some-state
3255@end example
b860f382
LC
3256@end deffn
3257
3258@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3259 @var{body} ...
3260@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3261 @var{body} ...
3262Bind the variables @var{var} to the monadic values @var{mval} in
3263@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3264``normal'' value @var{val}, as per @code{let}.
3265
3266@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3267(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3268@end deffn
3269
405a9d4e
LC
3270@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3271Bind @var{mexp} and the following monadic expressions in sequence,
3272returning the result of the last expression.
3273
3274This is akin to @code{mlet}, except that the return values of the
3275monadic expressions are ignored. In that sense, it is analogous to
3276@code{begin}, but applied to monadic expressions.
3277@end deffn
3278
561fb6c3
LC
3279@cindex state monad
3280The @code{(guix monads)} module provides the @dfn{state monad}, which
3281allows an additional value---the state---to be @emph{threaded} through
3282monadic procedure calls.
3283
3284@defvr {Scheme Variable} %state-monad
3285The state monad. Procedures in the state monad can access and change
3286the state that is threaded.
3287
3288Consider the example below. The @code{square} procedure returns a value
3289in the state monad. It returns the square of its argument, but also
3290increments the current state value:
3291
3292@example
3293(define (square x)
3294 (mlet %state-monad ((count (current-state)))
3295 (mbegin %state-monad
3296 (set-current-state (+ 1 count))
3297 (return (* x x)))))
3298
3299(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3300@result{} (0 1 4)
3301@result{} 3
3302@end example
3303
3304When ``run'' through @var{%state-monad}, we obtain that additional state
3305value, which is the number of @code{square} calls.
3306@end defvr
3307
3308@deffn {Monadic Procedure} current-state
3309Return the current state as a monadic value.
3310@end deffn
3311
3312@deffn {Monadic Procedure} set-current-state @var{value}
3313Set the current state to @var{value} and return the previous state as a
3314monadic value.
3315@end deffn
3316
3317@deffn {Monadic Procedure} state-push @var{value}
3318Push @var{value} to the current state, which is assumed to be a list,
3319and return the previous state as a monadic value.
3320@end deffn
3321
3322@deffn {Monadic Procedure} state-pop
3323Pop a value from the current state and return it as a monadic value.
3324The state is assumed to be a list.
3325@end deffn
3326
3327@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3328Run monadic value @var{mval} starting with @var{state} as the initial
3329state. Return two values: the resulting value, and the resulting state.
3330@end deffn
3331
e87f0591
LC
3332The main interface to the store monad, provided by the @code{(guix
3333store)} module, is as follows.
b860f382
LC
3334
3335@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3336The store monad---an alias for @var{%state-monad}.
3337
3338Values in the store monad encapsulate accesses to the store. When its
3339effect is needed, a value of the store monad must be ``evaluated'' by
3340passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3341@end defvr
3342
3343@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3344Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3345open store connection.
3346@end deffn
3347
ad372953 3348@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3349Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3350containing @var{text}, a string. @var{references} is a list of store items that the
3351resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3352@end deffn
3353
0a90af15
LC
3354@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3355 [#:recursive? #t]
3356Return the name of @var{file} once interned in the store. Use
3357@var{name} as its store name, or the basename of @var{file} if
3358@var{name} is omitted.
3359
3360When @var{recursive?} is true, the contents of @var{file} are added
3361recursively; if @var{file} designates a flat file and @var{recursive?}
3362is true, its contents are added, and its permission bits are kept.
3363
3364The example below adds a file to the store, under two different names:
3365
3366@example
3367(run-with-store (open-connection)
3368 (mlet %store-monad ((a (interned-file "README"))
3369 (b (interned-file "README" "LEGU-MIN")))
3370 (return (list a b))))
3371
3372@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3373@end example
3374
3375@end deffn
3376
e87f0591
LC
3377The @code{(guix packages)} module exports the following package-related
3378monadic procedures:
3379
b860f382 3380@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b 3381 [#:system (%current-system)] [#:target #f] @
f97c9175
AE
3382 [#:output "out"]
3383Return as a monadic
b860f382
LC
3384value in the absolute file name of @var{file} within the @var{output}
3385directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3386of the @var{output} directory of @var{package}. When @var{target} is
3387true, use it as a cross-compilation target triplet.
b860f382
LC
3388@end deffn
3389
b860f382 3390@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3391@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3392 @var{target} [@var{system}]
3393Monadic version of @code{package-derivation} and
3394@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3395@end deffn
3396
3397
21b679f6
LC
3398@node G-Expressions
3399@section G-Expressions
3400
3401@cindex G-expression
3402@cindex build code quoting
3403So we have ``derivations'', which represent a sequence of build actions
3404to be performed to produce an item in the store (@pxref{Derivations}).
f97c9175 3405These build actions are performed when asking the daemon to actually
21b679f6
LC
3406build the derivations; they are run by the daemon in a container
3407(@pxref{Invoking guix-daemon}).
3408
3409@cindex strata of code
f97c9175 3410It should come as no surprise that we like to write these build actions
21b679f6
LC
3411in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3412code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3413Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3414Kiselyov, who has written insightful
3415@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3416on this topic}, refers to this kind of code generation as
3417@dfn{staging}.}: the ``host code''---code that defines packages, talks
3418to the daemon, etc.---and the ``build code''---code that actually
3419performs build actions, such as making directories, invoking
3420@command{make}, etc.
21b679f6
LC
3421
3422To describe a derivation and its build actions, one typically needs to
3423embed build code inside host code. It boils down to manipulating build
f97c9175 3424code as data, and the homoiconicity of Scheme---code has a direct
21b679f6 3425representation as data---comes in handy for that. But we need more than
f97c9175 3426the normal @code{quasiquote} mechanism in Scheme to construct build
21b679f6
LC
3427expressions.
3428
3429The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3430S-expressions adapted to build expressions. G-expressions, or
f97c9175 3431@dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
21b679f6 3432@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
f97c9175
AE
3433@code{#$}, and @code{#$@@}), which are comparable to
3434@code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
3435respectivel (@pxref{Expression Syntax, @code{quasiquote},, guile,
3436GNU Guile Reference Manual}). However, there are major differences:
21b679f6
LC
3437
3438@itemize
3439@item
3440Gexps are meant to be written to a file and run or manipulated by other
3441processes.
3442
3443@item
b39fc6f7
LC
3444When a high-level object such as a package or derivation is unquoted
3445inside a gexp, the result is as if its output file name had been
3446introduced.
ff40e9b7 3447
21b679f6
LC
3448@item
3449Gexps carry information about the packages or derivations they refer to,
3450and these dependencies are automatically added as inputs to the build
3451processes that use them.
3452@end itemize
3453
c2b84676 3454@cindex lowering, of high-level objects in gexps
343eacbe
LC
3455This mechanism is not limited to package and derivation
3456objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3457derivations or files in the store can be defined,
3458such that these objects can also be inserted
f97c9175 3459into gexps. For example, a useful type of high-level objects that can be
343eacbe 3460inserted in a gexp is ``file-like objects'', which make it easy to
f97c9175 3461add files to the store and to refer to them in
558e8b11
LC
3462derivations and such (see @code{local-file} and @code{plain-file}
3463below.)
b39fc6f7 3464
21b679f6
LC
3465To illustrate the idea, here is an example of a gexp:
3466
3467@example
3468(define build-exp
3469 #~(begin
3470 (mkdir #$output)
3471 (chdir #$output)
aff8ce7c 3472 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3473 "list-files")))
3474@end example
3475
3476This gexp can be passed to @code{gexp->derivation}; we obtain a
3477derivation that builds a directory containing exactly one symlink to
3478@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3479
3480@example
3481(gexp->derivation "the-thing" build-exp)
3482@end example
3483
e20fd1bf 3484As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3485substituted to the reference to the @var{coreutils} package in the
3486actual build code, and @var{coreutils} is automatically made an input to
3487the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
f97c9175
AE
3488output)}) is replaced by a string containing the directory name of the
3489output of the derivation.
667b2508
LC
3490
3491@cindex cross compilation
3492In a cross-compilation context, it is useful to distinguish between
3493references to the @emph{native} build of a package---that can run on the
3494host---versus references to cross builds of a package. To that end, the
3495@code{#+} plays the same role as @code{#$}, but is a reference to a
3496native package build:
3497
3498@example
3499(gexp->derivation "vi"
3500 #~(begin
3501 (mkdir #$output)
3502 (system* (string-append #+coreutils "/bin/ln")
3503 "-s"
3504 (string-append #$emacs "/bin/emacs")
3505 (string-append #$output "/bin/vi")))
3506 #:target "mips64el-linux")
3507@end example
3508
3509@noindent
3510In the example above, the native build of @var{coreutils} is used, so
3511that @command{ln} can actually run on the host; but then the
3512cross-compiled build of @var{emacs} is referenced.
3513
3514The syntactic form to construct gexps is summarized below.
21b679f6
LC
3515
3516@deffn {Scheme Syntax} #~@var{exp}
3517@deffnx {Scheme Syntax} (gexp @var{exp})
3518Return a G-expression containing @var{exp}. @var{exp} may contain one
3519or more of the following forms:
3520
3521@table @code
3522@item #$@var{obj}
3523@itemx (ungexp @var{obj})
b39fc6f7
LC
3524Introduce a reference to @var{obj}. @var{obj} may have one of the
3525supported types, for example a package or a
21b679f6
LC
3526derivation, in which case the @code{ungexp} form is replaced by its
3527output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3528
b39fc6f7
LC
3529If @var{obj} is a list, it is traversed and references to supported
3530objects are substituted similarly.
21b679f6
LC
3531
3532If @var{obj} is another gexp, its contents are inserted and its
3533dependencies are added to those of the containing gexp.
3534
3535If @var{obj} is another kind of object, it is inserted as is.
3536
b39fc6f7
LC
3537@item #$@var{obj}:@var{output}
3538@itemx (ungexp @var{obj} @var{output})
21b679f6 3539This is like the form above, but referring explicitly to the
b39fc6f7
LC
3540@var{output} of @var{obj}---this is useful when @var{obj} produces
3541multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3542
667b2508
LC
3543@item #+@var{obj}
3544@itemx #+@var{obj}:output
3545@itemx (ungexp-native @var{obj})
3546@itemx (ungexp-native @var{obj} @var{output})
3547Same as @code{ungexp}, but produces a reference to the @emph{native}
3548build of @var{obj} when used in a cross compilation context.
3549
21b679f6
LC
3550@item #$output[:@var{output}]
3551@itemx (ungexp output [@var{output}])
3552Insert a reference to derivation output @var{output}, or to the main
3553output when @var{output} is omitted.
3554
3555This only makes sense for gexps passed to @code{gexp->derivation}.
3556
3557@item #$@@@var{lst}
3558@itemx (ungexp-splicing @var{lst})
3559Like the above, but splices the contents of @var{lst} inside the
3560containing list.
3561
667b2508
LC
3562@item #+@@@var{lst}
3563@itemx (ungexp-native-splicing @var{lst})
3564Like the above, but refers to native builds of the objects listed in
3565@var{lst}.
3566
21b679f6
LC
3567@end table
3568
3569G-expressions created by @code{gexp} or @code{#~} are run-time objects
3570of the @code{gexp?} type (see below.)
3571@end deffn
3572
3573@deffn {Scheme Procedure} gexp? @var{obj}
3574Return @code{#t} if @var{obj} is a G-expression.
3575@end deffn
3576
3577G-expressions are meant to be written to disk, either as code building
3578some derivation, or as plain files in the store. The monadic procedures
3579below allow you to do that (@pxref{The Store Monad}, for more
3580information about monads.)
3581
3582@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 3583 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
3584 [#:hash #f] [#:hash-algo #f] @
3585 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 3586 [#:module-path @var{%load-path}] @
c8351d9a 3587 [#:references-graphs #f] [#:allowed-references #f] @
c0468155 3588 [#:leaked-env-vars #f] @
0309e1b0 3589 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 3590 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 3591Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
3592@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3593stored in a file called @var{script-name}. When @var{target} is true,
3594it is used as the cross-compilation target triplet for packages referred
3595to by @var{exp}.
21b679f6 3596
ce45eb4c
LC
3597Make @var{modules} available in the evaluation context of @var{exp};
3598@var{modules} is a list of names of Guile modules searched in
3599@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
3600the load path during the execution of @var{exp}---e.g., @code{((guix
3601build utils) (guix build gnu-build-system))}.
3602
ce45eb4c
LC
3603@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3604applicable.
3605
b53833b2
LC
3606When @var{references-graphs} is true, it must be a list of tuples of one of the
3607following forms:
3608
3609@example
3610(@var{file-name} @var{package})
3611(@var{file-name} @var{package} @var{output})
3612(@var{file-name} @var{derivation})
3613(@var{file-name} @var{derivation} @var{output})
3614(@var{file-name} @var{store-item})
3615@end example
3616
3617The right-hand-side of each element of @var{references-graphs} is automatically made
3618an input of the build process of @var{exp}. In the build environment, each
3619@var{file-name} contains the reference graph of the corresponding item, in a simple
3620text format.
3621
c8351d9a
LC
3622@var{allowed-references} must be either @code{#f} or a list of output names and packages.
3623In the latter case, the list denotes store items that the result is allowed to
3624refer to. Any reference to another store item will lead to a build error.
3625
e20fd1bf 3626The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
3627@end deffn
3628
343eacbe 3629@cindex file-like objects
e1c153e0
LC
3630The @code{local-file}, @code{plain-file}, @code{computed-file},
3631@code{program-file}, and @code{scheme-file} procedures below return
3632@dfn{file-like objects}. That is, when unquoted in a G-expression,
3633these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
3634
3635@example
3636#~(system* (string-append #$glibc "/sbin/nscd") "-f"
3637 #$(local-file "/tmp/my-nscd.conf"))
3638@end example
3639
3640The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3641to the store. Once expanded, for instance @i{via}
3642@code{gexp->derivation}, the G-expression refers to that copy under
3643@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3644does not have any effect on what the G-expression does.
3645@code{plain-file} can be used similarly; it differs in that the file
3646content is directly passed as a string.
3647
d9ae938f
LC
3648@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3649 [#:recursive? #t]
3650Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
3651object can be used in a gexp. If @var{file} is a relative file name, it is looked
3652up relative to the source file where this form appears. @var{file} will be added to
3653the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
3654
3655When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3656designates a flat file and @var{recursive?} is true, its contents are added, and its
3657permission bits are kept.
3658
3659This is the declarative counterpart of the @code{interned-file} monadic
3660procedure (@pxref{The Store Monad, @code{interned-file}}).
3661@end deffn
3662
558e8b11
LC
3663@deffn {Scheme Procedure} plain-file @var{name} @var{content}
3664Return an object representing a text file called @var{name} with the given
3665@var{content} (a string) to be added to the store.
3666
3667This is the declarative counterpart of @code{text-file}.
3668@end deffn
3669
91937029
LC
3670@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3671 [#:modules '()] [#:options '(#:local-build? #t)]
3672Return an object representing the store item @var{name}, a file or
3673directory computed by @var{gexp}. @var{modules} specifies the set of
3674modules visible in the execution context of @var{gexp}. @var{options}
3675is a list of additional arguments to pass to @code{gexp->derivation}.
3676
3677This is the declarative counterpart of @code{gexp->derivation}.
3678@end deffn
3679
21b679f6
LC
3680@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3681Return an executable script @var{name} that runs @var{exp} using
3682@var{guile} with @var{modules} in its search path.
3683
3684The example below builds a script that simply invokes the @command{ls}
3685command:
3686
3687@example
3688(use-modules (guix gexp) (gnu packages base))
3689
3690(gexp->script "list-files"
3691 #~(execl (string-append #$coreutils "/bin/ls")
3692 "ls"))
3693@end example
3694
3695When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 3696@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
3697executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3698
3699@example
3700#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3701!#
3702(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3703 "ls")
3704@end example
3705@end deffn
3706
15a01c72
LC
3707@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3708 [#:modules '()] [#:guile #f]
3709Return an object representing the executable store item @var{name} that
3710runs @var{gexp}. @var{guile} is the Guile package used to execute that
3711script, and @var{modules} is the list of modules visible to that script.
3712
3713This is the declarative counterpart of @code{gexp->script}.
3714@end deffn
3715
21b679f6
LC
3716@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3717Return a derivation that builds a file @var{name} containing @var{exp}.
3718
3719The resulting file holds references to all the dependencies of @var{exp}
3720or a subset thereof.
3721@end deffn
1ed19464 3722
e1c153e0
LC
3723@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3724Return an object representing the Scheme file @var{name} that contains
3725@var{exp}.
3726
3727This is the declarative counterpart of @code{gexp->file}.
3728@end deffn
3729
1ed19464
LC
3730@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3731Return as a monadic value a derivation that builds a text file
3732containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
3733strings, objects of any type that can be used in a gexp: packages,
3734derivations, local file objects, etc. The resulting store file holds
3735references to all these.
1ed19464
LC
3736
3737This variant should be preferred over @code{text-file} anytime the file
3738to create will reference items from the store. This is typically the
3739case when building a configuration file that embeds store file names,
3740like this:
3741
3742@example
3743(define (profile.sh)
3744 ;; Return the name of a shell script in the store that
3745 ;; initializes the 'PATH' environment variable.
3746 (text-file* "profile.sh"
3747 "export PATH=" coreutils "/bin:"
3748 grep "/bin:" sed "/bin\n"))
3749@end example
3750
3751In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3752will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3753preventing them from being garbage-collected during its lifetime.
3754@end deffn
21b679f6 3755
b751cde3
LC
3756@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3757Return an object representing store file @var{name} containing
3758@var{text}. @var{text} is a sequence of strings and file-like objects,
3759as in:
3760
3761@example
3762(mixed-text-file "profile"
3763 "export PATH=" coreutils "/bin:" grep "/bin")
3764@end example
3765
3766This is the declarative counterpart of @code{text-file*}.
3767@end deffn
3768
21b679f6
LC
3769Of course, in addition to gexps embedded in ``host'' code, there are
3770also modules containing build tools. To make it clear that they are
3771meant to be used in the build stratum, these modules are kept in the
3772@code{(guix build @dots{})} name space.
3773
c2b84676
LC
3774@cindex lowering, of high-level objects in gexps
3775Internally, high-level objects are @dfn{lowered}, using their compiler,
3776to either derivations or store items. For instance, lowering a package
3777yields a derivation, and lowering a @code{plain-file} yields a store
3778item. This is achieved using the @code{lower-object} monadic procedure.
3779
3780@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3781 [#:target #f]
3782Return as a value in @var{%store-monad} the derivation or store item
3783corresponding to @var{obj} for @var{system}, cross-compiling for
3784@var{target} if @var{target} is true. @var{obj} must be an object that
3785has an associated gexp compiler, such as a @code{<package>}.
3786@end deffn
3787
21b679f6 3788
568717fd
LC
3789@c *********************************************************************
3790@node Utilities
3791@chapter Utilities
3792
210cc920
LC
3793This section describes tools primarily targeted at developers and users
3794who write new package definitions. They complement the Scheme
3795programming interface of Guix in a convenient way.
3796
568717fd 3797@menu
37166310 3798* Invoking guix build:: Building packages from the command line.
39bee8a2 3799* Invoking guix edit:: Editing package definitions.
210cc920 3800* Invoking guix download:: Downloading a file and printing its hash.
37166310 3801* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 3802* Invoking guix import:: Importing package definitions.
37166310 3803* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 3804* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 3805* Invoking guix size:: Profiling disk usage.
88856916 3806* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 3807* Invoking guix environment:: Setting up development environments.
aff8ce7c 3808* Invoking guix publish:: Sharing substitutes.
d23c20f1 3809* Invoking guix challenge:: Challenging substitute servers.
32efa254 3810* Invoking guix container:: Process isolation.
568717fd
LC
3811@end menu
3812
e49951eb
MW
3813@node Invoking guix build
3814@section Invoking @command{guix build}
568717fd 3815
e49951eb 3816The @command{guix build} command builds packages or derivations and
6798a8e4
LC
3817their dependencies, and prints the resulting store paths. Note that it
3818does not modify the user's profile---this is the job of the
e49951eb 3819@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
3820it is mainly useful for distribution developers.
3821
3822The general syntax is:
c78bd12b
LC
3823
3824@example
e49951eb 3825guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
3826@end example
3827
f97c9175 3828As an example, the following command builds the latest versions of Emacs
ccd7158d
LC
3829and of Guile, displays their build logs, and finally displays the
3830resulting directories:
3831
3832@example
3833guix build emacs guile
3834@end example
3835
3836Similarly, the following command builds all the available packages:
3837
3838@example
5284339d 3839guix build --quiet --keep-going \
ccd7158d
LC
3840 `guix package -A | cut -f1,2 --output-delimiter=@@`
3841@end example
3842
c78bd12b 3843@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
3844the software distribution such as @code{coreutils} or
3845@code{coreutils-8.20}, or a derivation such as
834129e0 3846@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
3847package with the corresponding name (and optionally version) is searched
3848for among the GNU distribution modules (@pxref{Package Modules}).
3849
3850Alternatively, the @code{--expression} option may be used to specify a
3851Scheme expression that evaluates to a package; this is useful when
3852disambiguation among several same-named packages or package variants is
3853needed.
c78bd12b 3854
ccd7158d
LC
3855There may be zero or more @var{options}. The available options are
3856described in the subsections below.
3857
3858@menu
3859* Common Build Options:: Build options for most commands.
88ad6ded 3860* Package Transformation Options:: Creating variants of packages.
ccd7158d
LC
3861* Additional Build Options:: Options specific to 'guix build'.
3862@end menu
3863
3864@node Common Build Options
3865@subsection Common Build Options
3866
3867A number of options that control the build process are common to
3868@command{guix build} and other commands that can spawn builds, such as
3869@command{guix package} or @command{guix archive}. These are the
3870following:
3871
3872@table @code
3873
3874@item --load-path=@var{directory}
3875@itemx -L @var{directory}
3876Add @var{directory} to the front of the package module search path
3877(@pxref{Package Modules}).
3878
3879This allows users to define their own packages and make them visible to
3880the command-line tools.
3881
3882@item --keep-failed
3883@itemx -K
3884Keep the build tree of failed builds. Thus, if a build fail, its build
3885tree is kept under @file{/tmp}, in a directory whose name is shown at
3886the end of the build log. This is useful when debugging build issues.
3887
3888@item --keep-going
3889@itemx -k
3890Keep going when some of the derivations fail to build; return only once
3891all the builds have either completed or failed.
3892
3893The default behavior is to stop as soon as one of the specified
3894derivations has failed.
3895
3896@item --dry-run
3897@itemx -n
3898Do not build the derivations.
3899
3900@item --fallback
3901When substituting a pre-built binary fails, fall back to building
3902packages locally.
3903
3904@item --substitute-urls=@var{urls}
3905@anchor{client-substitute-urls}
3906Consider @var{urls} the whitespace-separated list of substitute source
3907URLs, overriding the default list of URLs of @command{guix-daemon}
3908(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3909
3910This means that substitutes may be downloaded from @var{urls}, provided
3911they are signed by a key authorized by the system administrator
3912(@pxref{Substitutes}).
3913
3914@item --no-substitutes
3915Do not use substitutes for build products. That is, always build things
3916locally instead of allowing downloads of pre-built binaries
3917(@pxref{Substitutes}).
3918
7573d30f
LC
3919@item --no-grafts
3920Do not ``graft'' packages. In practice, this means that package updates
3921available as grafts are not applied. @xref{Security Updates}, for more
3922information on grafts.
3923
ccd7158d
LC
3924@item --rounds=@var{n}
3925Build each derivation @var{n} times in a row, and raise an error if
3926consecutive build results are not bit-for-bit identical.
3927
3928This is a useful way to detect non-deterministic builds processes.
3929Non-deterministic build processes are a problem because they make it
3930practically impossible for users to @emph{verify} whether third-party
3931binaries are genuine. @xref{Invoking guix challenge}, for more.
3932
3933Note that, currently, the differing build results are not kept around,
3934so you will have to manually investigate in case of an error---e.g., by
3935stashing one of the build results with @code{guix archive --export},
3936then rebuilding, and finally comparing the two results.
3937
3938@item --no-build-hook
f97c9175 3939Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
ccd7158d
LC
3940(@pxref{Daemon Offload Setup}). That is, always build things locally
3941instead of offloading builds to remote machines.
3942
3943@item --max-silent-time=@var{seconds}
3944When the build or substitution process remains silent for more than
3945@var{seconds}, terminate it and report a build failure.
3946
3947@item --timeout=@var{seconds}
3948Likewise, when the build or substitution process lasts for more than
3949@var{seconds}, terminate it and report a build failure.
3950
3951By default there is no timeout. This behavior can be restored with
3952@code{--timeout=0}.
3953
3954@item --verbosity=@var{level}
3955Use the given verbosity level. @var{level} must be an integer between 0
3956and 5; higher means more verbose output. Setting a level of 4 or more
3957may be helpful when debugging setup issues with the build daemon.
3958
3959@item --cores=@var{n}
3960@itemx -c @var{n}
3961Allow the use of up to @var{n} CPU cores for the build. The special
3962value @code{0} means to use as many CPU cores as available.
3963
3964@item --max-jobs=@var{n}
3965@itemx -M @var{n}
3966Allow at most @var{n} build jobs in parallel. @xref{Invoking
3967guix-daemon, @code{--max-jobs}}, for details about this option and the
3968equivalent @command{guix-daemon} option.
3969
3970@end table
3971
3972Behind the scenes, @command{guix build} is essentially an interface to
3973the @code{package-derivation} procedure of the @code{(guix packages)}
3974module, and to the @code{build-derivations} procedure of the @code{(guix
3975derivations)} module.
3976
3977In addition to options explicitly passed on the command line,
3978@command{guix build} and other @command{guix} commands that support
3979building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
3980
3981@defvr {Environment Variable} GUIX_BUILD_OPTIONS
3982Users can define this variable to a list of command line options that
3983will automatically be used by @command{guix build} and other
3984@command{guix} commands that can perform builds, as in the example
3985below:
3986
3987@example
3988$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
3989@end example
3990
3991These options are parsed independently, and the result is appended to
3992the parsed command-line options.
3993@end defvr
3994
88ad6ded
LC
3995
3996@node Package Transformation Options
3997@subsection Package Transformation Options
3998
3999@cindex package variants
4000Another set of command-line options supported by @command{guix build}
b8638f03 4001and also @command{guix package} are @dfn{package transformation
f97c9175 4002options}. These are options that make it possible to define @dfn{package
b8638f03
LC
4003variants}---for instance, packages built from different source code.
4004This is a convenient way to create customized packages on the fly
4005without having to type in the definitions of package variants
4006(@pxref{Defining Packages}).
88ad6ded
LC
4007
4008@table @code
4009
4010@item --with-source=@var{source}
4011Use @var{source} as the source of the corresponding package.
4012@var{source} must be a file name or a URL, as for @command{guix
4013download} (@pxref{Invoking guix download}).
4014
f97c9175
AE
4015The ``corresponding package'' is taken to be the one specified on the
4016command line the name of which matches the base of @var{source}---e.g.,
4017if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
88ad6ded 4018package is @code{guile}. Likewise, the version string is inferred from
f97c9175 4019@var{source}; in the previous example, it is @code{2.0.10}.
88ad6ded
LC
4020
4021This option allows users to try out versions of packages other than the
4022one provided by the distribution. The example below downloads
4023@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4024the @code{ed} package:
4025
4026@example
4027guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4028@end example
4029
4030As a developer, @code{--with-source} makes it easy to test release
4031candidates:
4032
4033@example
4034guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4035@end example
4036
4037@dots{} or to build from a checkout in a pristine environment:
4038
4039@example
4040$ git clone git://git.sv.gnu.org/guix.git
4041$ guix build guix --with-source=./guix
4042@end example
4043
47c0f92c
LC
4044@item --with-input=@var{package}=@var{replacement}
4045Replace dependency on @var{package} by a dependency on
4046@var{replacement}. @var{package} must be a package name, and
4047@var{replacement} must be a package specification such as @code{guile}
4048or @code{guile@@1.8}.
4049
f97c9175 4050For instance, the following command builds Guix, but replaces its
47c0f92c
LC
4051dependency on the current stable version of Guile with a dependency on
4052the development version of Guile, @code{guile-next}:
4053
4054@example
4055guix build --with-input=guile=guile-next guix
4056@end example
4057
4058This is a recursive, deep replacement. So in this example, both
4059@code{guix} and its dependency @code{guile-json} (which also depends on
4060@code{guile}) get rebuilt against @code{guile-next}.
4061
4062However, implicit inputs are left unchanged.
88ad6ded
LC
4063@end table
4064
ccd7158d
LC
4065@node Additional Build Options
4066@subsection Additional Build Options
4067
4068The command-line options presented below are specific to @command{guix
4069build}.
c78bd12b
LC
4070
4071@table @code
4072
5284339d
LC
4073@item --quiet
4074@itemx -q
4075Build quietly, without displaying the build log. Upon completion, the
4076build log is kept in @file{/var} (or similar) and can always be
4077retrieved using the @option{--log-file} option.
4078
34a1783f
DT
4079@item --file=@var{file}
4080@itemx -f @var{file}
4081
4082Build the package or derivation that the code within @var{file}
4083evaluates to.
4084
4085As an example, @var{file} might contain a package definition like this
4086(@pxref{Defining Packages}):
4087
4088@example
4089@verbatiminclude package-hello.scm
4090@end example
4091
c78bd12b
LC
4092@item --expression=@var{expr}
4093@itemx -e @var{expr}
ac5de156 4094Build the package or derivation @var{expr} evaluates to.
c78bd12b 4095
5401dd75 4096For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
4097guile-1.8)}, which unambiguously designates this specific variant of
4098version 1.8 of Guile.
4099
f97c9175 4100Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
4101as a build program passed to @code{gexp->derivation}
4102(@pxref{G-Expressions}).
4103
4104Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
4105(@pxref{The Store Monad}). The procedure must return a derivation as a
4106monadic value, which is then passed through @code{run-with-store}.
4107
c78bd12b
LC
4108@item --source
4109@itemx -S
f97c9175 4110Build the source derivations of the packages, rather than the packages
c78bd12b
LC
4111themselves.
4112
e49951eb 4113For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
4114@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4115source tarball.
c78bd12b 4116
f9cc8971 4117The returned source tarball is the result of applying any patches and
f97c9175 4118code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
4119Packages}).
4120
2cdfe13d
EB
4121@item --sources
4122Fetch and return the source of @var{package-or-derivation} and all their
4123dependencies, recursively. This is a handy way to obtain a local copy
4124of all the source code needed to build @var{packages}, allowing you to
4125eventually build them even without network access. It is an extension
4126of the @code{--source} option and can accept one of the following
4127optional argument values:
4128
4129@table @code
4130@item package
4131This value causes the @code{--sources} option to behave in the same way
4132as the @code{--source} option.
4133
4134@item all
f97c9175
AE
4135Build the source derivations of all packages, including any source that
4136might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
4137
4138@example
4139$ guix build --sources tzdata
4140The following derivations will be built:
4141 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4142 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4143@end example
4144
4145@item transitive
f97c9175
AE
4146Build the source derivations of all packages, as well of all transitive
4147inputs to the packages. This can be used e.g. to
2cdfe13d
EB
4148prefetch package source for later offline building.
4149
4150@example
4151$ guix build --sources=transitive tzdata
4152The following derivations will be built:
4153 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4154 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4155 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4156 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4157 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4158 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4159@dots{}
4160@end example
4161
4162@end table
4163
c78bd12b
LC
4164@item --system=@var{system}
4165@itemx -s @var{system}
4166Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 4167the system type of the build host.
c78bd12b
LC
4168
4169An example use of this is on Linux-based systems, which can emulate
4170different personalities. For instance, passing
4171@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4172to build packages in a complete 32-bit environment.
4173
e55ec43d
LC
4174@item --target=@var{triplet}
4175@cindex cross-compilation
4176Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4177as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4178configuration triplets,, configure, GNU Configure and Build System}).
4179
a8d65643
LC
4180@anchor{build-check}
4181@item --check
4182@cindex determinism, checking
4183@cindex reproducibility, checking
4184Rebuild @var{package-or-derivation}, which are already available in the
4185store, and raise an error if the build results are not bit-for-bit
4186identical.
4187
f97c9175
AE
4188This mechanism allows you to check whether previously installed
4189substitutes are genuine (@pxref{Substitutes}), or whether the build result
4190of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
4191background information and tools.
4192
c78bd12b
LC
4193@item --derivations
4194@itemx -d
4195Return the derivation paths, not the output paths, of the given
4196packages.
4197
70ee5642
LC
4198@item --root=@var{file}
4199@itemx -r @var{file}
4200Make @var{file} a symlink to the result, and register it as a garbage
4201collector root.
4202
4203@item --log-file
3f208ad7 4204Return the build log file names or URLs for the given
f97c9175 4205@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
4206missing.
4207
4208This works regardless of how packages or derivations are specified. For
4209instance, the following invocations are equivalent:
4210
4211@example
4212guix build --log-file `guix build -d guile`
4213guix build --log-file `guix build guile`
4214guix build --log-file guile
4215guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4216@end example
4217
3f208ad7
LC
4218If a log is unavailable locally, and unless @code{--no-substitutes} is
4219passed, the command looks for a corresponding log on one of the
4220substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 4221
f97c9175
AE
4222So for instance, imagine you want to see the build log of GDB on MIPS,
4223but you are actually on an @code{x86_64} machine:
3f208ad7
LC
4224
4225@example
4226$ guix build --log-file gdb -s mips64el-linux
4227http://hydra.gnu.org/log/@dots{}-gdb-7.10
4228@end example
4229
4230You can freely access a huge library of build logs!
70ee5642
LC
4231@end table
4232
16eb115e 4233
39bee8a2
LC
4234@node Invoking guix edit
4235@section Invoking @command{guix edit}
4236
4237@cindex package definition, editing
4238So many packages, so many source files! The @command{guix edit} command
4239facilitates the life of packagers by pointing their editor at the source
4240file containing the definition of the specified packages. For instance:
4241
4242@example
4243guix edit gcc-4.8 vim
4244@end example
4245
4246@noindent
6237b9fa
LC
4247launches the program specified in the @code{VISUAL} or in the
4248@code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4249and that of Vim.
39bee8a2 4250
f97c9175 4251If you are using Emacs, note that the Emacs user interface provides the
7c1b1ae2 4252@kbd{M-x guix-edit} command and a similar functionality in the ``package
f97c9175 4253info'' and ``package list'' buffers created by the @kbd{M-x
7c1b1ae2 4254guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
39bee8a2
LC
4255
4256
210cc920
LC
4257@node Invoking guix download
4258@section Invoking @command{guix download}
4259
4260When writing a package definition, developers typically need to download
f97c9175 4261a source tarball, compute its SHA256 hash, and write that
210cc920
LC
4262hash in the package definition (@pxref{Defining Packages}). The
4263@command{guix download} tool helps with this task: it downloads a file
4264from the given URI, adds it to the store, and prints both its file name
4265in the store and its SHA256 hash.
4266
4267The fact that the downloaded file is added to the store saves bandwidth:
4268when the developer eventually tries to build the newly defined package
4269with @command{guix build}, the source tarball will not have to be
4270downloaded again because it is already in the store. It is also a
4271convenient way to temporarily stash files, which may be deleted
4272eventually (@pxref{Invoking guix gc}).
4273
4274The @command{guix download} command supports the same URIs as used in
4275package definitions. In particular, it supports @code{mirror://} URIs.
4276@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4277Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4278they are not available, an error is raised. @xref{Guile Preparations,
4279how to install the GnuTLS bindings for Guile,, gnutls-guile,
4280GnuTLS-Guile}, for more information.
210cc920
LC
4281
4282The following option is available:
4283
4284@table @code
4285@item --format=@var{fmt}
4286@itemx -f @var{fmt}
4287Write the hash in the format specified by @var{fmt}. For more
081145cf 4288information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
4289@end table
4290
6c365eca
NK
4291@node Invoking guix hash
4292@section Invoking @command{guix hash}
4293
210cc920 4294The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4295It is primarily a convenience tool for anyone contributing to the
4296distribution: it computes the cryptographic hash of a file, which can be
4297used in the definition of a package (@pxref{Defining Packages}).
4298
4299The general syntax is:
4300
4301@example
4302guix hash @var{option} @var{file}
4303@end example
4304
4305@command{guix hash} has the following option:
4306
4307@table @code
4308
4309@item --format=@var{fmt}
4310@itemx -f @var{fmt}
210cc920 4311Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4312
4313Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4314(@code{hex} and @code{hexadecimal} can be used as well).
4315
4316If the @option{--format} option is not specified, @command{guix hash}
4317will output the hash in @code{nix-base32}. This representation is used
4318in the definitions of packages.
4319
3140f2df
LC
4320@item --recursive
4321@itemx -r
4322Compute the hash on @var{file} recursively.
4323
4324In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
4325including its children if it is a directory. Some of the metadata of
4326@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 4327regular file, the hash is different depending on whether @var{file} is
f97c9175 4328executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
4329hash (@pxref{Invoking guix archive}).
4330@c FIXME: Replace xref above with xref to an ``Archive'' section when
4331@c it exists.
4332
6c365eca
NK
4333@end table
4334
2f7d2d91
LC
4335@node Invoking guix import
4336@section Invoking @command{guix import}
4337
4338@cindex importing packages
4339@cindex package import
4340@cindex package conversion
f97c9175
AE
4341The @command{guix import} command is useful for people who would like to
4342add a package to the distribution with as little work as
4343possible---a legitimate demand. The command knows of a few
4344repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
4345is a package definition, or a template thereof, in the format we know
4346(@pxref{Defining Packages}).
4347
4348The general syntax is:
4349
4350@example
4351guix import @var{importer} @var{options}@dots{}
4352@end example
4353
4354@var{importer} specifies the source from which to import package
f97c9175 4355metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
4356options specific to @var{importer}. Currently, the available
4357``importers'' are:
4358
4359@table @code
4360@item gnu
f97c9175 4361Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
4362for the latest version of that GNU package, including the hash of its
4363source tarball, and its canonical synopsis and description.
4364
f97c9175 4365Additional information such as the package dependencies and its
2f7d2d91
LC
4366license needs to be figured out manually.
4367
4368For example, the following command returns a package definition for
4369GNU@tie{}Hello:
4370
4371@example
4372guix import gnu hello
4373@end example
4374
4375Specific command-line options are:
4376
4377@table @code
4378@item --key-download=@var{policy}
4379As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 4380keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
4381refresh, @code{--key-download}}.
4382@end table
4383
4384@item pypi
4385@cindex pypi
f97c9175 4386Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
4387Index}@footnote{This functionality requires Guile-JSON to be installed.
4388@xref{Requirements}.}. Information is taken from the JSON-formatted
4389description available at @code{pypi.python.org} and usually includes all
4390the relevant information, including package dependencies.
4391
f97c9175 4392The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
4393package:
4394
4395@example
4396guix import pypi itsdangerous
4397@end example
4398
3aae8145
DT
4399@item gem
4400@cindex gem
f97c9175 4401Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
4402RubyGems}@footnote{This functionality requires Guile-JSON to be
4403installed. @xref{Requirements}.}. Information is taken from the
4404JSON-formatted description available at @code{rubygems.org} and includes
4405most relevant information, including runtime dependencies. There are
f97c9175 4406some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
4407synopses and descriptions, so the same string is used for both fields.
4408Additionally, the details of non-Ruby dependencies required to build
4409native extensions is unavailable and left as an exercise to the
4410packager.
4411
f97c9175 4412The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
4413
4414@example
4415guix import gem rails
4416@end example
4417
d45dc6da
EB
4418@item cpan
4419@cindex CPAN
3c192e4e
AE
4420Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4421functionality requires Guile-JSON to be installed.
4422@xref{Requirements}.}.
f97c9175 4423Information is taken from the JSON-formatted metadata provided through
d45dc6da 4424@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4425relevant information, such as module dependencies. License information
4426should be checked closely. If Perl is available in the store, then the
4427@code{corelist} utility will be used to filter core modules out of the
4428list of dependencies.
d45dc6da 4429
f97c9175 4430The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
4431Perl module:
4432
4433@example
4434guix import cpan Acme::Boolean
4435@end example
4436
e1248602
RW
4437@item cran
4438@cindex CRAN
d0bd632f 4439@cindex Bioconductor
f97c9175 4440Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
4441central repository for the @uref{http://r-project.org, GNU@tie{}R
4442statistical and graphical environment}.
4443
f97c9175 4444Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 4445
f97c9175 4446The command command below imports metadata for the @code{Cairo}
e1248602
RW
4447R package:
4448
4449@example
4450guix import cran Cairo
4451@end example
4452
f97c9175 4453When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
4454@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4455packages for for the analysis and comprehension of high-throughput
4456genomic data in bioinformatics.
4457
f97c9175 4458Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
4459published on the web interface of the Bioconductor SVN repository.
4460
f97c9175 4461The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
4462R package:
4463
4464@example
4465guix import cran --archive=bioconductor GenomicRanges
4466@end example
4467
2f7d2d91 4468@item nix
f97c9175 4469Import metadata from a local copy of the source of the
2f7d2d91
LC
4470@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4471relies on the @command{nix-instantiate} command of
4472@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4473typically written in a mixture of Nix-language and Bash code. This
4474command only imports the high-level package structure that is written in
4475the Nix language. It normally includes all the basic fields of a
4476package definition.
4477
4478When importing a GNU package, the synopsis and descriptions are replaced
4479by their canonical upstream variant.
4480
961d0d2d
LC
4481Usually, you will first need to do:
4482
4483@example
4484export NIX_REMOTE=daemon
4485@end example
4486
4487@noindent
4488so that @command{nix-instantiate} does not try to open the Nix database.
4489
2f7d2d91
LC
4490As an example, the command below imports the package definition of
4491LibreOffice (more precisely, it imports the definition of the package
4492bound to the @code{libreoffice} top-level attribute):
4493
4494@example
4495guix import nix ~/path/to/nixpkgs libreoffice
4496@end example
863af4e1
FB
4497
4498@item hackage
4499@cindex hackage
f97c9175 4500Import metadata from the Haskell community's central package archive
863af4e1
FB
4501@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4502Cabal files and includes all the relevant information, including package
4503dependencies.
4504
4505Specific command-line options are:
4506
4507@table @code
a4154748
FB
4508@item --stdin
4509@itemx -s
f97c9175 4510Read a Cabal file from standard input.
863af4e1
FB
4511@item --no-test-dependencies
4512@itemx -t
f97c9175 4513Do not include dependencies required only by the test suites.
a4154748
FB
4514@item --cabal-environment=@var{alist}
4515@itemx -e @var{alist}
4516@var{alist} is a Scheme alist defining the environment in which the
4517Cabal conditionals are evaluated. The accepted keys are: @code{os},
4518@code{arch}, @code{impl} and a string representing the name of a flag.
4519The value associated with a flag has to be either the symbol
4520@code{true} or @code{false}. The value associated with other keys
4521has to conform to the Cabal file format definition. The default value
4522associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 4523@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
4524@end table
4525
f97c9175 4526The command below imports metadata for the latest version of the
a4154748
FB
4527@code{HTTP} Haskell package without including test dependencies and
4528specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4529
4530@example
a4154748 4531guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4532@end example
4533
4534A specific package version may optionally be specified by following the
1b846da8 4535package name by an at-sign and a version number as in the following example:
863af4e1
FB
4536
4537@example
1b846da8 4538guix import hackage mtl@@2.1.3.1
863af4e1 4539@end example
7f74a931
FB
4540
4541@item elpa
4542@cindex elpa
f97c9175 4543Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
4544repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4545
4546Specific command-line options are:
4547
4548@table @code
4549@item --archive=@var{repo}
4550@itemx -a @var{repo}
4551@var{repo} identifies the archive repository from which to retrieve the
4552information. Currently the supported repositories and their identifiers
4553are:
4554@itemize -
4555@item
840bd1d3 4556@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4557identifier. This is the default.
4558
4559@item
840bd1d3 4560@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4561@code{melpa-stable} identifier.
4562
4563@item
840bd1d3 4564@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4565identifier.
4566@end itemize
4567@end table
2f7d2d91
LC
4568@end table
4569
4570The structure of the @command{guix import} code is modular. It would be
4571useful to have more importers for other package formats, and your help
4572is welcome here (@pxref{Contributing}).
4573
37166310
LC
4574@node Invoking guix refresh
4575@section Invoking @command{guix refresh}
4576
4577The primary audience of the @command{guix refresh} command is developers
4578of the GNU software distribution. By default, it reports any packages
4579provided by the distribution that are outdated compared to the latest
4580upstream version, like this:
4581
4582@example
4583$ guix refresh
4584gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4585gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4586@end example
4587
f97c9175
AE
4588It does so by browsing the FTP directory of each package and determining
4589the highest version number of the source tarballs therein. The command
bcb571cb
LC
4590knows how to update specific types of packages: GNU packages, ELPA
4591packages, etc.---see the documentation for @option{--type} below. The
4592are many packages, though, for which it lacks a method to determine
4593whether a new upstream release is available. However, the mechanism is
4594extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4595
4596When passed @code{--update}, it modifies distribution source files to
f97c9175 4597update the version numbers and source tarball hashes of those package
37166310
LC
4598recipes (@pxref{Defining Packages}). This is achieved by downloading
4599each package's latest source tarball and its associated OpenPGP
4600signature, authenticating the downloaded tarball against its signature
4601using @command{gpg}, and finally computing its hash. When the public
4602key used to sign the tarball is missing from the user's keyring, an
4603attempt is made to automatically retrieve it from a public key server;
f97c9175 4604when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
4605@command{guix refresh} reports an error.
4606
4607The following options are supported:
4608
4609@table @code
4610
2d7fc7da
LC
4611@item --expression=@var{expr}
4612@itemx -e @var{expr}
4613Consider the package @var{expr} evaluates to.
4614
4615This is useful to precisely refer to a package, as in this example:
4616
4617@example
4618guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4619@end example
4620
4621This command lists the dependents of the ``final'' libc (essentially all
4622the packages.)
4623
37166310
LC
4624@item --update
4625@itemx -u
38e16b49
LC
4626Update distribution source files (package recipes) in place. This is
4627usually run from a checkout of the Guix source tree (@pxref{Running
4628Guix Before It Is Installed}):
4629
4630@example
4631$ ./pre-inst-env guix refresh -s non-core
4632@end example
4633
081145cf 4634@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4635
4636@item --select=[@var{subset}]
4637@itemx -s @var{subset}
4638Select all the packages in @var{subset}, one of @code{core} or
4639@code{non-core}.
4640
4641The @code{core} subset refers to all the packages at the core of the
4642distribution---i.e., packages that are used to build ``everything
4643else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4644changing one of these packages in the distribution entails a rebuild of
4645all the others. Thus, such updates are an inconvenience to users in
4646terms of build time or bandwidth used to achieve the upgrade.
4647
4648The @code{non-core} subset refers to the remaining packages. It is
4649typically useful in cases where an update of the core packages would be
4650inconvenient.
4651
bcb571cb
LC
4652@item --type=@var{updater}
4653@itemx -t @var{updater}
7191adc5
AK
4654Select only packages handled by @var{updater} (may be a comma-separated
4655list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
4656
4657@table @code
4658@item gnu
4659the updater for GNU packages;
e80c0f85
LC
4660@item gnome
4661the updater for GNOME packages;
62061d6b
AW
4662@item xorg
4663the updater for X.org packages;
bcb571cb 4664@item elpa
d882c235
LC
4665the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4666@item cran
b9d044ef 4667the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
4668@item bioconductor
4669the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
bab020d7 4670@item pypi
b9d044ef 4671the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
4672@item gem
4673the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
4674@item github
4675the updater for @uref{https://github.com, GitHub} packages.
bcb571cb
LC
4676@end table
4677
f97c9175
AE
4678For instance, the following command only checks for updates of Emacs
4679packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
4680
4681@example
7191adc5 4682$ guix refresh --type=elpa,cran
d882c235 4683gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4684gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4685@end example
4686
37166310
LC
4687@end table
4688
4689In addition, @command{guix refresh} can be passed one or more package
4690names, as in this example:
4691
4692@example
38e16b49 4693$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4694@end example
4695
4696@noindent
4697The command above specifically updates the @code{emacs} and
4698@code{idutils} packages. The @code{--select} option would have no
4699effect in this case.
4700
7d193ec3
EB
4701When considering whether to upgrade a package, it is sometimes
4702convenient to know which packages would be affected by the upgrade and
4703should be checked for compatibility. For this the following option may
4704be used when passing @command{guix refresh} one or more package names:
4705
4706@table @code
4707
6ffa706b
AK
4708@item --list-updaters
4709@itemx -L
4710List available updaters and exit (see @option{--type} above.)
4711
7d193ec3
EB
4712@item --list-dependent
4713@itemx -l
4714List top-level dependent packages that would need to be rebuilt as a
4715result of upgrading one or more packages.
4716
4717@end table
4718
4719Be aware that the @code{--list-dependent} option only
4720@emph{approximates} the rebuilds that would be required as a result of
4721an upgrade. More rebuilds might be required under some circumstances.
4722
4723@example
7779ab61
LC
4724$ guix refresh --list-dependent flex
4725Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4726hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4727@end example
4728
4729The command above lists a set of packages that could be built to check
4730for compatibility with an upgraded @code{flex} package.
4731
f9230085
LC
4732The following options can be used to customize GnuPG operation:
4733
4734@table @code
4735
f9230085
LC
4736@item --gpg=@var{command}
4737Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4738for in @code{$PATH}.
4739
2bc53ba9
LC
4740@item --key-download=@var{policy}
4741Handle missing OpenPGP keys according to @var{policy}, which may be one
4742of:
4743
4744@table @code
4745@item always
4746Always download missing OpenPGP keys from the key server, and add them
4747to the user's GnuPG keyring.
4748
4749@item never
4750Never try to download missing OpenPGP keys. Instead just bail out.
4751
4752@item interactive
4753When a package signed with an unknown OpenPGP key is encountered, ask
4754the user whether to download it or not. This is the default behavior.
4755@end table
4756
4757@item --key-server=@var{host}
4758Use @var{host} as the OpenPGP key server when importing a public key.
4759
f9230085
LC
4760@end table
4761
917a2a58
BW
4762The @code{github} updater uses the
4763@uref{https://developer.github.com/v3/, GitHub API} to query for new
4764releases. When used repeatedly e.g. when refreshing all packages,
4765GitHub will eventually refuse to answer any further API requests. By
4766default 60 API requests per hour are allowed, and a full refresh on all
4767GitHub packages in Guix requires more than this. Authentication with
4768GitHub through the use of an API token alleviates these limits. To use
4769an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
4770token procured from @uref{https://github.com/settings/tokens} or
4771otherwise.
4772
4773
b4f5e0e8
CR
4774@node Invoking guix lint
4775@section Invoking @command{guix lint}
f97c9175
AE
4776The @command{guix lint} command is meant to help package developers avoid
4777common errors and use a consistent style. It runs a number of checks on
4778a given set of packages in order to find common mistakes in their
873c4085
LC
4779definitions. Available @dfn{checkers} include (see
4780@code{--list-checkers} for a complete list):
4781
4782@table @code
4783@item synopsis
4784@itemx description
4785Validate certain typographical and stylistic rules about package
4786descriptions and synopses.
4787
4788@item inputs-should-be-native
4789Identify inputs that should most likely be native inputs.
4790
4791@item source
4792@itemx home-page
50f5c46d 4793@itemx source-file-name
873c4085 4794Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d 4795invalid. Check that the source file name is meaningful, e.g. is not
f97c9175
AE
4796just a version number or ``git-checkout'', without a declared
4797@code{file-name} (@pxref{origin Reference}).
40a7d4e5 4798
5432734b
LC
4799@item cve
4800Report known vulnerabilities found in the Common Vulnerabilities and
4801Exposures (CVE) database
4802@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4803NIST}.
4804
40a7d4e5
LC
4805@item formatting
4806Warn about obvious source code formatting issues: trailing white space,
4807use of tabulations, etc.
873c4085 4808@end table
b4f5e0e8
CR
4809
4810The general syntax is:
4811
4812@example
4813guix lint @var{options} @var{package}@dots{}
4814@end example
4815
4816If no package is given on the command line, then all packages are checked.
4817The @var{options} may be zero or more of the following:
4818
4819@table @code
f97c9175
AE
4820@item --list-checkers
4821@itemx -l
4822List and describe all the available checkers that will be run on packages
4823and exit.
b4f5e0e8 4824
dd7c013d
CR
4825@item --checkers
4826@itemx -c
4827Only enable the checkers specified in a comma-separated list using the
4828names returned by @code{--list-checkers}.
4829
b4f5e0e8 4830@end table
37166310 4831
fcc58db6
LC
4832@node Invoking guix size
4833@section Invoking @command{guix size}
4834
4835The @command{guix size} command helps package developers profile the
4836disk usage of packages. It is easy to overlook the impact of an
4837additional dependency added to a package, or the impact of using a
4838single output for a package that could easily be split (@pxref{Packages
f97c9175 4839with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
4840@command{guix size} can highlight.
4841
4842The command can be passed a package specification such as @code{gcc-4.8}
4843or @code{guile:debug}, or a file name in the store. Consider this
4844example:
4845
4846@example
4847$ guix size coreutils
4848store item total self
4849/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4850/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4851/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4852/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4853/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4854/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4855@end example
4856
4857@cindex closure
4858The store items listed here constitute the @dfn{transitive closure} of
4859Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4860would be returned by:
4861
4862@example
4863$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4864@end example
4865
f97c9175 4866Here the output shows three columns next to store items. The first column,
fcc58db6
LC
4867labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4868the store item---that is, its own size plus the size of all its
4869dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
4870item itself. The last column shows the ratio of the size of the item
4871itself to the space occupied by all the items listed here.
fcc58db6
LC
4872
4873In this example, we see that the closure of Coreutils weighs in at
487470@tie{}MiB, half of which is taken by libc. (That libc represents a
4875large fraction of the closure is not a problem @i{per se} because it is
4876always available on the system anyway.)
4877
4878When the package passed to @command{guix size} is available in the
4879store, @command{guix size} queries the daemon to determine its
4880dependencies, and measures its size in the store, similar to @command{du
4881-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4882Coreutils}).
4883
4884When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
4885reports information based on the available substitutes
4886(@pxref{Substitutes}). This makes it possible it to profile disk usage of
4887store items that are not even on disk, only available remotely.
fcc58db6 4888
a8f996c6 4889The available options are:
fcc58db6
LC
4890
4891@table @option
4892
d490d06e
LC
4893@item --substitute-urls=@var{urls}
4894Use substitute information from @var{urls}.
4895@xref{client-substitute-urls, the same option for @code{guix build}}.
4896
a8f996c6 4897@item --map-file=@var{file}
f97c9175 4898Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
4899
4900For the example above, the map looks like this:
4901
4902@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4903produced by @command{guix size}}
4904
4905This option requires that
4906@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4907installed and visible in Guile's module search path. When that is not
4908the case, @command{guix size} fails as it tries to load it.
4909
fcc58db6
LC
4910@item --system=@var{system}
4911@itemx -s @var{system}
4912Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4913
4914@end table
4915
88856916
LC
4916@node Invoking guix graph
4917@section Invoking @command{guix graph}
4918
4919@cindex DAG
4920Packages and their dependencies form a @dfn{graph}, specifically a
4921directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175
AE
4922mental model of the package DAG, so the @command{guix graph} command
4923provides a visual representation of the DAG. @command{guix graph}
4924emits a DAG representation in the input format of
88856916 4925@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
f97c9175 4926directly to the @command{dot} command of Graphviz. The general
88856916
LC
4927syntax is:
4928
4929@example
4930guix graph @var{options} @var{package}@dots{}
4931@end example
4932
4933For example, the following command generates a PDF file representing the
4934package DAG for the GNU@tie{}Core Utilities, showing its build-time
4935dependencies:
4936
4937@example
4938guix graph coreutils | dot -Tpdf > dag.pdf
4939@end example
4940
4941The output looks like this:
4942
4943@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4944
4945Nice little graph, no?
4946
f97c9175 4947But there is more than one graph! The one above is concise: it is the
88856916 4948graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
4949grep, etc. It is often useful to have such a concise graph, but
4950sometimes one may want to see more details. @command{guix graph} supports
4951several types of graphs, allowing you to choose the level of detail:
88856916
LC
4952
4953@table @code
4954@item package
f97c9175 4955This is the default type used in the example above. It shows the DAG of
88856916
LC
4956package objects, excluding implicit dependencies. It is concise, but
4957filters out many details.
4958
4959@item bag-emerged
4960This is the package DAG, @emph{including} implicit inputs.
4961
4962For instance, the following command:
4963
4964@example
4965guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4966@end example
4967
4968... yields this bigger graph:
4969
4970@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4971
4972At the bottom of the graph, we see all the implicit inputs of
4973@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4974
f97c9175 4975Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
4976@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4977here, for conciseness.
4978
4979@item bag
4980Similar to @code{bag-emerged}, but this time including all the bootstrap
4981dependencies.
4982
38b92daa
LC
4983@item bag-with-origins
4984Similar to @code{bag}, but also showing origins and their dependencies.
4985
88856916
LC
4986@item derivations
4987This is the most detailed representation: It shows the DAG of
4988derivations (@pxref{Derivations}) and plain store items. Compared to
4989the above representation, many additional nodes are visible, including
f97c9175 4990build scripts, patches, Guile modules, etc.
88856916
LC
4991
4992@end table
4993
f97c9175 4994All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
4995following graph type represents the @emph{run-time dependencies}:
4996
4997@table @code
4998@item references
4999This is the graph of @dfn{references} of a package output, as returned
5000by @command{guix gc --references} (@pxref{Invoking guix gc}).
5001
5002If the given package output is not available in the store, @command{guix
5003graph} attempts to obtain dependency information from substitutes.
5004@end table
5005
5006The available options are the following:
5007
5008@table @option
5009@item --type=@var{type}
5010@itemx -t @var{type}
5011Produce a graph output of @var{type}, where @var{type} must be one of
5012the values listed above.
5013
5014@item --list-types
5015List the supported graph types.
4c8f997a
LC
5016
5017@item --expression=@var{expr}
5018@itemx -e @var{expr}
5019Consider the package @var{expr} evaluates to.
5020
5021This is useful to precisely refer to a package, as in this example:
5022
5023@example
5024guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5025@end example
88856916
LC
5026@end table
5027
5028
372c4bbc
DT
5029@node Invoking guix environment
5030@section Invoking @command{guix environment}
5031
f5fd4fd2 5032@cindex reproducible build environments
fe36d84e 5033@cindex development environments
372c4bbc
DT
5034The purpose of @command{guix environment} is to assist hackers in
5035creating reproducible development environments without polluting their
5036package profile. The @command{guix environment} tool takes one or more
f97c9175 5037packages, builds all of their inputs, and creates a shell
372c4bbc
DT
5038environment to use them.
5039
5040The general syntax is:
5041
5042@example
5043guix environment @var{options} @var{package}@dots{}
5044@end example
5045
fe36d84e
LC
5046The following example spawns a new shell set up for the development of
5047GNU@tie{}Guile:
372c4bbc
DT
5048
5049@example
5050guix environment guile
5051@end example
5052
f97c9175
AE
5053If the needed dependencies are not built yet, @command{guix environment}
5054automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
5055version of the environment that @command{guix environment} was run in.
5056It contains the necessary search paths for building the given package
5057added to the existing environment variables. To create a ``pure''
f97c9175 5058environment, in which the original environment variables have been unset,
50500f7c
LC
5059use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5060environment variables such as @code{PATH} in their @file{~/.bashrc}
5061file. As a consequence, when @code{guix environment} launches it, Bash
5062may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5063environment variables. It is an error to define such environment
5064variables in @file{.bashrc}; instead, they should be defined in
5065@file{.bash_profile}, which is sourced only by log-in shells.
5066@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5067details on Bash start-up files.}.
372c4bbc 5068
28de8d25
LC
5069@vindex GUIX_ENVIRONMENT
5070@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
f97c9175 5071variable in the shell it spawns. This allows users to, say, define a
28de8d25
LC
5072specific prompt for development environments in their @file{.bashrc}
5073(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5074
5075@example
5076if [ -n "$GUIX_ENVIRONMENT" ]
5077then
5078 export PS1="\u@@\h \w [dev]\$ "
5079fi
5080@end example
5081
372c4bbc
DT
5082Additionally, more than one package may be specified, in which case the
5083union of the inputs for the given packages are used. For example, the
5084command below spawns a shell where all of the dependencies of both Guile
5085and Emacs are available:
5086
5087@example
5088guix environment guile emacs
5089@end example
5090
1de2fe95
DT
5091Sometimes an interactive shell session is not desired. An arbitrary
5092command may be invoked by placing the @code{--} token to separate the
5093command from the rest of the arguments:
372c4bbc
DT
5094
5095@example
1de2fe95 5096guix environment guile -- make -j4
372c4bbc
DT
5097@end example
5098
fe36d84e
LC
5099In other situations, it is more convenient to specify the list of
5100packages needed in the environment. For example, the following command
5101runs @command{python} from an environment containing Python@tie{}2.7 and
5102NumPy:
5103
5104@example
1de2fe95 5105guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
5106@end example
5107
cc90fbbf
DT
5108Furthermore, one might want the dependencies of a package and also some
5109additional packages that are not build-time or runtime dependencies, but
5110are useful when developing nonetheless. Because of this, the
5111@code{--ad-hoc} flag is positional. Packages appearing before
5112@code{--ad-hoc} are interpreted as packages whose dependencies will be
5113added to the environment. Packages appearing after are interpreted as
5114packages that will be added to the environment directly. For example,
5115the following command creates a Guix development environment that
5116additionally includes Git and strace:
5117
5118@example
5119guix environment guix --ad-hoc git strace
5120@end example
5121
f535dcbe
DT
5122Sometimes it is desirable to isolate the environment as much as
5123possible, for maximal purity and reproducibility. In particular, when
5124using Guix on a host distro that is not GuixSD, it is desirable to
5125prevent access to @file{/usr/bin} and other system-wide resources from
5126the development environment. For example, the following command spawns
5127a Guile REPL in a ``container'' where only the store and the current
5128working directory are mounted:
5129
5130@example
5131guix environment --ad-hoc --container guile -- guile
5132@end example
5133
0f252e26 5134@quotation Note
cfd35b4e 5135The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
5136@end quotation
5137
fe36d84e 5138The available options are summarized below.
372c4bbc
DT
5139
5140@table @code
5141@item --expression=@var{expr}
5142@itemx -e @var{expr}
c9c282ce
DT
5143Create an environment for the package or list of packages that
5144@var{expr} evaluates to.
372c4bbc 5145
fe36d84e
LC
5146For example, running:
5147
5148@example
5149guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5150@end example
5151
5152starts a shell with the environment for this specific variant of the
5153PETSc package.
5154
c9c282ce
DT
5155Running:
5156
5157@example
5c2b2f00 5158guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
5159@end example
5160
5161starts a shell with all the GuixSD base packages available.
5162
779aa003
DT
5163The above commands only the use default output of the given packages.
5164To select other outputs, two element tuples can be specified:
5165
5166@example
5167guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5168@end example
5169
372c4bbc
DT
5170@item --load=@var{file}
5171@itemx -l @var{file}
c9c282ce
DT
5172Create an environment for the package or list of packages that the code
5173within @var{file} evaluates to.
372c4bbc 5174
fe36d84e
LC
5175As an example, @var{file} might contain a definition like this
5176(@pxref{Defining Packages}):
5177
5178@example
5179@verbatiminclude environment-gdb.scm
5180@end example
5181
a54bd6d7
DT
5182@item --ad-hoc
5183Include all specified packages in the resulting environment, as if an
5184@i{ad hoc} package were defined with them as inputs. This option is
5185useful for quickly creating an environment without having to write a
5186package expression to contain the desired inputs.
5187
5188For instance, the command:
5189
5190@example
1de2fe95 5191guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
5192@end example
5193
5194runs @command{guile} in an environment where Guile and Guile-SDL are
5195available.
5196
417c39f1 5197Note that this example implicitly asks for the default output of
f97c9175 5198@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
5199specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5200of @code{glib} (@pxref{Packages with Multiple Outputs}).
5201
cc90fbbf
DT
5202This option may be composed with the default behavior of @command{guix
5203environment}. Packages appearing before @code{--ad-hoc} are interpreted
5204as packages whose dependencies will be added to the environment, the
5205default behavior. Packages appearing after are interpreted as packages
5206that will be added to the environment directly.
5207
372c4bbc
DT
5208@item --pure
5209Unset existing environment variables when building the new environment.
5210This has the effect of creating an environment in which search paths
5211only contain package inputs.
5212
5213@item --search-paths
5214Display the environment variable definitions that make up the
5215environment.
ce367ef3
LC
5216
5217@item --system=@var{system}
5218@itemx -s @var{system}
5219Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
5220
5221@item --container
5222@itemx -C
5223@cindex container
5224Run @var{command} within an isolated container. The current working
56b6befb 5225directory outside the container is mapped inside the
f535dcbe
DT
5226container. Additionally, the spawned process runs as the current user
5227outside the container, but has root privileges in the context of the
5228container.
5229
5230@item --network
5231@itemx -N
5232For containers, share the network namespace with the host system.
5233Containers created without this flag only have access to the loopback
5234device.
5235
5236@item --expose=@var{source}[=@var{target}]
5237For containers, expose the file system @var{source} from the host system
5238as the read-only file system @var{target} within the container. If
5239@var{target} is not specified, @var{source} is used as the target mount
5240point in the container.
5241
5242The example below spawns a Guile REPL in a container in which the user's
5243home directory is accessible read-only via the @file{/exchange}
5244directory:
5245
5246@example
5247guix environment --container --expose=$HOME=/exchange guile -- guile
5248@end example
5249
5c2b2f00 5250@item --share=@var{source}[=@var{target}]
f535dcbe
DT
5251For containers, share the file system @var{source} from the host system
5252as the writable file system @var{target} within the container. If
5253@var{target} is not specified, @var{source} is used as the target mount
5254point in the container.
5255
5256The example below spawns a Guile REPL in a container in which the user's
5257home directory is accessible for both reading and writing via the
5258@file{/exchange} directory:
5259
5260@example
5261guix environment --container --share=$HOME=/exchange guile -- guile
5262@end example
372c4bbc
DT
5263@end table
5264
5265It also supports all of the common build options that @command{guix
ccd7158d 5266build} supports (@pxref{Common Build Options}).
372c4bbc 5267
aff8ce7c
DT
5268@node Invoking guix publish
5269@section Invoking @command{guix publish}
5270
5271The purpose of @command{guix publish} is to enable users to easily share
f97c9175 5272their store with others, who can then use it as a substitute server
8ce229fc
LC
5273(@pxref{Substitutes}).
5274
5275When @command{guix publish} runs, it spawns an HTTP server which allows
5276anyone with network access to obtain substitutes from it. This means
5277that any machine running Guix can also act as if it were a build farm,
5278since the HTTP interface is compatible with Hydra, the software behind
5279the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5280
5281For security, each substitute is signed, allowing recipients to check
5282their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 5283@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
5284readable by the system administrator, it must be started as root; the
5285@code{--user} option makes it drop root privileges early on.
aff8ce7c 5286
b18812b6
LC
5287The signing key pair must be generated before @command{guix publish} is
5288launched, using @command{guix archive --generate-key} (@pxref{Invoking
5289guix archive}).
5290
aff8ce7c
DT
5291The general syntax is:
5292
5293@example
5294guix publish @var{options}@dots{}
5295@end example
5296
5297Running @command{guix publish} without any additional arguments will
5298spawn an HTTP server on port 8080:
5299
5300@example
5301guix publish
5302@end example
5303
5304Once a publishing server has been authorized (@pxref{Invoking guix
5305archive}), the daemon may download substitutes from it:
5306
5307@example
5308guix-daemon --substitute-urls=http://example.org:8080
5309@end example
5310
5311The following options are available:
5312
5313@table @code
5314@item --port=@var{port}
5315@itemx -p @var{port}
5316Listen for HTTP requests on @var{port}.
5317
9e2292ef
LC
5318@item --listen=@var{host}
5319Listen on the network interface for @var{host}. The default is to
5320accept connections from any interface.
5321
5463fe51
LC
5322@item --user=@var{user}
5323@itemx -u @var{user}
5324Change privileges to @var{user} as soon as possible---i.e., once the
5325server socket is open and the signing key has been read.
5326
aff8ce7c
DT
5327@item --repl[=@var{port}]
5328@itemx -r [@var{port}]
5329Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
5330Reference Manual}) on @var{port} (37146 by default). This is used
5331primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
5332@end table
5333
1c52181f
LC
5334Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5335add a call to @code{guix-publish-service} in the @code{services} field
5336of the @code{operating-system} declaration (@pxref{guix-publish-service,
5337@code{guix-publish-service}}).
5338
d23c20f1
LC
5339
5340@node Invoking guix challenge
5341@section Invoking @command{guix challenge}
5342
5343@cindex reproducible builds
5344@cindex verifiable builds
5345
5346Do the binaries provided by this server really correspond to the source
f97c9175 5347code it claims to build? Is a package build process deterministic?
d23c20f1
LC
5348These are the questions the @command{guix challenge} command attempts to
5349answer.
5350
5351The former is obviously an important question: Before using a substitute
f97c9175 5352server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
5353provides the right binaries, and thus @emph{challenge} it. The latter
5354is what enables the former: If package builds are deterministic, then
5355independent builds of the package should yield the exact same result,
5356bit for bit; if a server provides a binary different from the one
5357obtained locally, it may be either corrupt or malicious.
5358
5359We know that the hash that shows up in @file{/gnu/store} file names is
5360the hash of all the inputs of the process that built the file or
5361directory---compilers, libraries, build scripts,
5362etc. (@pxref{Introduction}). Assuming deterministic build processes,
5363one store file name should map to exactly one build output.
5364@command{guix challenge} checks whether there is, indeed, a single
5365mapping by comparing the build outputs of several independent builds of
5366any given store item.
5367
f97c9175 5368The command output looks like this:
d23c20f1
LC
5369
5370@smallexample
5371$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5372updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5373updating list of substitutes from 'http://guix.example.org'... 100.0%
5374/gnu/store/@dots{}-openssl-1.0.2d contents differ:
5375 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5376 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5377 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5378/gnu/store/@dots{}-git-2.5.0 contents differ:
5379 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5380 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5381 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5382/gnu/store/@dots{}-pius-2.1.1 contents differ:
5383 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5384 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5385 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5386@end smallexample
5387
5388@noindent
5389In this example, @command{guix challenge} first scans the store to
5390determine the set of locally-built derivations---as opposed to store
5391items that were downloaded from a substitute server---and then queries
5392all the substitute servers. It then reports those store items for which
5393the servers obtained a result different from the local build.
5394
5395@cindex non-determinism, in package builds
5396As an example, @code{guix.example.org} always gets a different answer.
5397Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5398case of Git. This might indicate that the build process of Git is
5399non-deterministic, meaning that its output varies as a function of
5400various things that Guix does not fully control, in spite of building
5401packages in isolated environments (@pxref{Features}). Most common
5402sources of non-determinism include the addition of timestamps in build
5403results, the inclusion of random numbers, and directory listings sorted
5404by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5405more information.
5406
f97c9175 5407To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
5408these lines (@pxref{Invoking guix archive}):
5409
5410@example
5411$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5412 | guix archive -x /tmp/git
043f4698 5413$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
5414@end example
5415
5416This command shows the difference between the files resulting from the
5417local build, and the files resulting from the build on
5418@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5419diffutils, Comparing and Merging Files}). The @command{diff} command
5420works great for text files. When binary files differ, a better option
5421is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5422visualize differences for all kinds of files.
5423
f97c9175 5424Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
5425to a non-deterministic build process or to a malicious server. We try
5426hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
5427to verify substitutes, but of course, this is a process that
5428involves not just Guix, but a large part of the free software community.
d23c20f1
LC
5429In the meantime, @command{guix challenge} is one tool to help address
5430the problem.
5431
5432If you are writing packages for Guix, you are encouraged to check
5433whether @code{hydra.gnu.org} and other substitute servers obtain the
5434same build result as you did with:
5435
5436@example
5437$ guix challenge @var{package}
5438@end example
5439
5440@noindent
f97c9175 5441where @var{package} is a package specification such as
d23c20f1
LC
5442@code{guile-2.0} or @code{glibc:debug}.
5443
5444The general syntax is:
5445
5446@example
5447guix challenge @var{options} [@var{packages}@dots{}]
5448@end example
5449
5450The one option that matters is:
5451
5452@table @code
5453
5454@item --substitute-urls=@var{urls}
5455Consider @var{urls} the whitespace-separated list of substitute source
5456URLs to compare to.
5457
5458@end table
5459
5460
32efa254
DT
5461@node Invoking guix container
5462@section Invoking @command{guix container}
5463@cindex container
5464
5465@quotation Note
5466As of version @value{VERSION}, this tool is experimental. The interface
5467is subject to radical change in the future.
5468@end quotation
5469
5470The purpose of @command{guix container} is to manipulate processes
5471running within an isolated environment, commonly known as a
46c36586 5472``container'', typically created by the @command{guix environment}
32efa254
DT
5473(@pxref{Invoking guix environment}) and @command{guix system container}
5474(@pxref{Invoking guix system}) commands.
5475
5476The general syntax is:
5477
5478@example
5479guix container @var{action} @var{options}@dots{}
5480@end example
5481
5482@var{action} specifies the operation to perform with a container, and
5483@var{options} specifies the context-specific arguments for the action.
5484
5485The following actions are available:
5486
5487@table @code
5488@item exec
5489Execute a command within the context of a running container.
5490
5491The syntax is:
5492
5493@example
5494guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5495@end example
5496
5497@var{pid} specifies the process ID of the running container.
f97c9175
AE
5498@var{program} specifies an executable file name within the root file
5499system of the container. @var{arguments} are the additional options that
5500will be passed to @var{program}.
32efa254
DT
5501
5502The following command launches an interactive login shell inside a
5503GuixSD container, started by @command{guix system container}, and whose
5504process ID is 9001:
5505
5506@example
5507guix container exec 9001 /run/current-system/profile/bin/bash --login
5508@end example
5509
5510Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 5511must be PID 1 of the container or one of its child processes.
32efa254
DT
5512
5513@end table
5514
a1ba8475
LC
5515@c *********************************************************************
5516@node GNU Distribution
5517@chapter GNU Distribution
5518
3ca2731c 5519@cindex Guix System Distribution
4705641f 5520@cindex GuixSD
3ca2731c
LC
5521Guix comes with a distribution of the GNU system consisting entirely of
5522free software@footnote{The term ``free'' here refers to the
a1ba8475 5523@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 5524users of that software}.}. The
35ed9306
LC
5525distribution can be installed on its own (@pxref{System Installation}),
5526but it is also possible to install Guix as a package manager on top of
5527an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5528between the two, we refer to the standalone distribution as the Guix
4705641f 5529System Distribution, or GuixSD.
35ed9306
LC
5530
5531The distribution provides core GNU packages such as GNU libc, GCC, and
5532Binutils, as well as many GNU and non-GNU applications. The complete
5533list of available packages can be browsed
093ae1be 5534@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5535running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5536
5537@example
e49951eb 5538guix package --list-available
a1ba8475
LC
5539@end example
5540
f97c9175 5541Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
5542Linux-based and other variants of GNU, with a focus on the promotion and
5543tight integration of GNU components, and an emphasis on programs and
5544tools that help users exert that freedom.
5545
3ca2731c 5546Packages are currently available on the following platforms:
c320011d
LC
5547
5548@table @code
5549
5550@item x86_64-linux
5551Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5552
5553@item i686-linux
5554Intel 32-bit architecture (IA32), Linux-Libre kernel;
5555
aa1e1947 5556@item armhf-linux
aa725117 5557ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
5558using the EABI hard-float application binary interface (ABI),
5559and Linux-Libre kernel.
aa1e1947 5560
c320011d
LC
5561@item mips64el-linux
5562little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 5563n32 ABI, and Linux-Libre kernel.
c320011d
LC
5564
5565@end table
5566
4705641f 5567GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5568
c320011d
LC
5569@noindent
5570For information on porting to other architectures or kernels,
f97c9175 5571@pxref{Porting}.
c320011d 5572
401c53c4 5573@menu
5af6de3e 5574* System Installation:: Installing the whole operating system.
35ed9306 5575* System Configuration:: Configuring the operating system.
91ef73d4 5576* Installing Debugging Files:: Feeding the debugger.
05962f29 5577* Security Updates:: Deploying security fixes quickly.
401c53c4 5578* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5579* Packaging Guidelines:: Growing the distribution.
401c53c4 5580* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5581* Porting:: Targeting another platform or kernel.
401c53c4
LC
5582@end menu
5583
5584Building this distribution is a cooperative effort, and you are invited
081145cf 5585to join! @xref{Contributing}, for information about how you can help.
401c53c4 5586
5af6de3e
LC
5587@node System Installation
5588@section System Installation
5589
3ca2731c
LC
5590@cindex Guix System Distribution
5591This section explains how to install the Guix System Distribution
5592on a machine. The Guix package manager can
35ed9306
LC
5593also be installed on top of a running GNU/Linux system,
5594@pxref{Installation}.
5af6de3e
LC
5595
5596@ifinfo
5597@c This paragraph is for people reading this from tty2 of the
5598@c installation image.
1068f26b 5599You are reading this documentation with an Info reader. For details on
5af6de3e 5600how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 5601link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
5602@kbd{l} afterwards to come back here.
5603@end ifinfo
5604
dedb8d5e
LC
5605@menu
5606* Limitations:: What you can expect.
5607* USB Stick Installation:: Preparing the installation medium.
5608* Preparing for Installation:: Networking, partitioning, etc.
5609* Proceeding with the Installation:: The real thing.
5610* Building the Installation Image:: How this comes to be.
5611@end menu
5612
5613@node Limitations
8aaaae38
LC
5614@subsection Limitations
5615
4705641f 5616As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5617not production-ready. It may contain bugs and lack important
8aaaae38
LC
5618features. Thus, if you are looking for a stable production system that
5619respects your freedom as a computer user, a good solution at this point
5620is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 5621the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5622to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5623also keep using your distribution and try out the package manager on top
5624of it (@pxref{Installation}).
5625
5626Before you proceed with the installation, be aware of the following
5627noteworthy limitations applicable to version @value{VERSION}:
5628
5629@itemize
5630@item
5631The installation process does not include a graphical user interface and
5632requires familiarity with GNU/Linux (see the following subsections to
5633get a feel of what that means.)
5634
5635@item
093ae1be 5636The system does not yet provide full GNOME and KDE desktops. Xfce and
f97c9175 5637Enlightenment are available, though, if graphical desktop environments
093ae1be 5638are your thing, as well as a number of X11 window managers.
8aaaae38
LC
5639
5640@item
dbcb0ab1 5641Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5642
5643@item
5644Few system services are currently supported out-of-the-box
5645(@pxref{Services}).
5646
5647@item
dedb8d5e 5648More than 3,000 packages are available, but you may
8aaaae38
LC
5649occasionally find that a useful package is missing.
5650@end itemize
5651
f97c9175
AE
5652You have been warned! But more than a disclaimer, this is an invitation
5653to report issues (and success stories!), and to join us in improving it.
8aaaae38 5654@xref{Contributing}, for more info.
5af6de3e 5655
dedb8d5e 5656@node USB Stick Installation
5af6de3e
LC
5657@subsection USB Stick Installation
5658
5659An installation image for USB sticks can be downloaded from
4705641f 5660@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5661where @var{system} is one of:
5662
5663@table @code
5664@item x86_64-linux
5665for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5666
5667@item i686-linux
5668for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5669@end table
5670
5671This image contains a single partition with the tools necessary for an
5672installation. It is meant to be copied @emph{as is} to a large-enough
5673USB stick.
5674
5675To copy the image to a USB stick, follow these steps:
5676
5677@enumerate
5678@item
5679Decompress the image using the @command{xz} command:
5680
5681@example
4705641f 5682xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5683@end example
5684
5685@item
f97c9175
AE
5686Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
5687its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
5688copy the image with:
5689
5690@example
4705641f 5691dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5692@end example
5693
5694Access to @file{/dev/sdX} usually requires root privileges.
5695@end enumerate
5696
5697Once this is done, you should be able to reboot the system and boot from
5698the USB stick. The latter usually requires you to get in the BIOS' boot
5699menu, where you can choose to boot from the USB stick.
5700
dedb8d5e 5701@node Preparing for Installation
5af6de3e
LC
5702@subsection Preparing for Installation
5703
5704Once you have successfully booted the image on the USB stick, you should
5705end up with a root prompt. Several console TTYs are configured and can
5706be used to run commands as root. TTY2 shows this documentation,
5707browsable using the Info reader commands (@pxref{Help,,, info, Info: An
ae7ffa9e
LC
5708Introduction}). The installation system runs the GPM mouse daemon,
5709which allows you to select text with the left mouse button and to paste
5710it with the middle button.
5af6de3e 5711
dedb8d5e 5712@subsubsection Keyboard Layout
5af6de3e 5713
dedb8d5e
LC
5714@cindex keyboard layout
5715The installation image uses the US qwerty keyboard layout. If you want
5716to change it, you can use the @command{loadkeys} command. For example,
5717the following command selects the Dvorak keyboard layout:
5af6de3e 5718
dedb8d5e
LC
5719@example
5720loadkeys dvorak
5721@end example
5722
5723See the files under @file{/run/current-system/profile/share/keymaps} for
5724a list of available keyboard layouts. Run @command{man loadkeys} for
5725more information.
5726
5727@subsubsection Networking
5728
5729Run the following command see what your network interfaces are called:
235cba85
LC
5730
5731@example
dedb8d5e 5732ifconfig -a
235cba85
LC
5733@end example
5734
95c559c1 5735@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
5736Wired interfaces have a name starting with @samp{e}; for example, the
5737interface corresponding to the first on-board Ethernet controller is
5738called @samp{eno1}. Wireless interfaces have a name starting with
5739@samp{w}, like @samp{w1p2s0}.
5740
5741@table @asis
5742@item Wired connection
5743To configure a wired network run the following command, substituting
5744@var{interface} with the name of the wired interface you want to use.
5745
5746@example
5747ifconfig @var{interface} up
5748@end example
5749
5750@item Wireless connection
5751To configure wireless networking, you can create a configuration file
5752for the @command{wpa_supplicant} configuration tool (its location is not
5753important) using one of the available text editors such as
5754@command{zile}:
5755
5756@example
5757zile wpa_supplicant.conf
5758@end example
5759
5760As an example, the following stanza can go to this file and will work
5761for many wireless networks, provided you give the actual SSID and
5762passphrase for the network you are connecting to:
5763
5764@example
5765network=@{
5766 ssid=@var{my-ssid}
5767 key_mgmt=WPA-PSK
5768 psk="the network's secret passphrase"
5769@}
5770@end example
5771
5772Start the wireless service and run it in the background with the
5773following command (substitute @var{interface} with the name of the
5774network interface you want to use):
5775
5776@example
5777wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
5778@end example
5779
5780Run @command{man wpa_supplication} for more information.
5781@end table
5782
5783At this point, you need to acquire an IP address. On a network where IP
5784addresses are automatically assigned @i{via} DHCP, you can run:
5785
5786@example
5787dhclient @var{interface}
5788@end example
5af6de3e 5789
dedb8d5e
LC
5790Try to ping a server to see if networking is up and running:
5791
5792@example
5793ping -c 3 gnu.org
5794@end example
5af6de3e
LC
5795
5796Setting up network access is almost always a requirement because the
5797image does not contain all the software and tools that may be needed.
5798
dedb8d5e
LC
5799@subsubsection Disk Partitioning
5800
5801Unless this has already been done, the next step is to partition, and
5802then format the target partition(s).
5803
5804The installation image includes several partitioning tools, including
5805Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
5806@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
5807the partition layout you want:
5808
5809@example
5810cfdisk
5811@end example
5812
5813Once you are done partitioning the target hard disk drive, you have to
5814create a file system on the relevant partition(s)@footnote{Currently
5815GuixSD pretty much assumes an ext4 file system. In particular, code
5816that reads partition UUIDs and labels only works with ext4. This will
5817be fixed in the future.}.
5af6de3e 5818
7ab44369
LC
5819Preferably, assign partitions a label so that you can easily and
5820reliably refer to them in @code{file-system} declarations (@pxref{File
5821Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
5822@command{mkfs.ext4} and related commands. So, assuming the target root
5823partition lives at @file{/dev/sda1}, a file system with the label
5824@code{my-root} can be created with:
7ab44369 5825
dedb8d5e
LC
5826@example
5827mkfs.ext4 -L my-root /dev/sda1
5828@end example
dd816355 5829
316d65be
LC
5830@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5831@c A typical command sequence may be:
5832@c
5833@c @example
5834@c # fdisk /dev/sdX
5835@c @dots{} Create partitions etc.@dots{}
5836@c # cryptsetup luksFormat /dev/sdX1
5837@c # cryptsetup open --type luks /dev/sdX1 my-partition
5838@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5839@c @end example
6d6e6281 5840
dedb8d5e
LC
5841In addition to e2fsprogs, the suite of tools to manipulate
5842ext2/ext3/ext4 file systems, the installation image includes
5843Cryptsetup/LUKS for disk encryption.
5af6de3e 5844
dedb8d5e
LC
5845Once that is done, mount the target root partition under @file{/mnt}
5846with a command like (again, assuming @file{/dev/sda1} is the root
5847partition):
83a17b62 5848
dedb8d5e
LC
5849@example
5850mount /dev/sda1 /mnt
5851@end example
83a17b62 5852
dedb8d5e
LC
5853@node Proceeding with the Installation
5854@subsection Proceeding with the Installation
83a17b62 5855
dedb8d5e
LC
5856With the target partitions ready and the target root mounted on
5857@file{/mnt}, we're ready to go. First, run:
5af6de3e 5858
dedb8d5e
LC
5859@example
5860herd start cow-store /mnt
5861@end example
5af6de3e 5862
dedb8d5e
LC
5863This makes @file{/gnu/store} copy-on-write, such that packages added to
5864it during the installation phase are written to the target disk rather
5865than kept in memory.
5af6de3e 5866
dedb8d5e 5867Next, you have to edit a file and
5af6de3e
LC
5868provide the declaration of the operating system to be installed. To
5869that end, the installation system comes with two text editors: GNU nano
5870(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5871It is better to store that file on the target root file system, say, as
5872@file{/mnt/etc/config.scm}.
5873
dedb8d5e
LC
5874@xref{Using the Configuration System}, for an overview of the
5875configuration file. The example configurations discussed in that
5876section are available under @file{/etc/configuration} in the
5877installation image. Thus, to get started with a system configuration
5878providing a graphical display server (a ``desktop'' system), you can run
5879something along these lines:
5880
5881@example
5882# mkdir /mnt/etc
5883# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
5884# zile /mnt/etc/config.scm
5885@end example
5886
5887You should pay attention to what your configuration file contains, and
5888in particular:
5889
5890@itemize
5891@item
5892Make sure the @code{grub-configuration} form refers to the device you
5893want to install GRUB on.
5894
5895@item
5896Be sure that your partition labels match the value of their respective
5897@code{device} fields in your @code{file-system} configuration, assuming
5898your @code{file-system} configuration sets the value of @code{title} to
5899@code{'label}.
5900@end itemize
5af6de3e 5901
dd51caac
LC
5902Once you are done preparing the configuration file, the new system must
5903be initialized (remember that the target root file system is mounted
5904under @file{/mnt}):
5af6de3e
LC
5905
5906@example
5907guix system init /mnt/etc/config.scm /mnt
5908@end example
5909
5910@noindent
dedb8d5e 5911This copies all the necessary files and installs GRUB on
5af6de3e 5912@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 5913more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
5914downloads or builds of missing packages, which can take some time.
5915
1bd4e6db
LC
5916Once that command has completed---and hopefully succeeded!---you can run
5917@command{reboot} and boot into the new system. The @code{root} password
5918in the new system is initially empty; other users' passwords need to be
5919initialized by running the @command{passwd} command as @code{root},
5920unless your configuration specifies otherwise
5921(@pxref{user-account-password, user account passwords}).
5922
5923Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
5924@file{guix-devel@@gnu.org} to share your experience---good or not so
5925good.
5926
dedb8d5e 5927@node Building the Installation Image
5af6de3e
LC
5928@subsection Building the Installation Image
5929
5930The installation image described above was built using the @command{guix
5931system} command, specifically:
5932
5933@example
8a225c66 5934guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
5935@end example
5936
1068f26b 5937@xref{Invoking guix system} and
5af6de3e
LC
5938@file{gnu/system/install.scm} in the source tree for more information
5939about the installation image.
5940
cf4a9129
LC
5941@node System Configuration
5942@section System Configuration
b208a005 5943
cf4a9129 5944@cindex system configuration
3ca2731c 5945The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
5946mechanism. By that we mean that all aspects of the global system
5947configuration---such as the available system services, timezone and
5948locale settings, user accounts---are declared in a single place. Such
5949a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 5950
cf4a9129
LC
5951One of the advantages of putting all the system configuration under the
5952control of Guix is that it supports transactional system upgrades, and
1068f26b 5953makes it possible to roll back to a previous system instantiation,
cf4a9129 5954should something go wrong with the new one (@pxref{Features}). Another
1068f26b 5955advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
5956across different machines, or at different points in time, without
5957having to resort to additional administration tools layered on top of
1068f26b 5958the own tools of the system.
cf4a9129 5959@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 5960
cf4a9129
LC
5961This section describes this mechanism. First we focus on the system
5962administrator's viewpoint---explaining how the system is configured and
5963instantiated. Then we show how this mechanism can be extended, for
5964instance to support new system services.
91ef73d4 5965
cf4a9129
LC
5966@menu
5967* Using the Configuration System:: Customizing your GNU system.
7313a52e 5968* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 5969* File Systems:: Configuring file system mounts.
510f9d86 5970* Mapped Devices:: Block device extra processing.
cf4a9129 5971* User Accounts:: Specifying user accounts.
598e19dc 5972* Locales:: Language and cultural convention settings.
cf4a9129 5973* Services:: Specifying system services.
0ae8c15a 5974* Setuid Programs:: Programs running with root privileges.
efb5e833 5975* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 5976* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 5977* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 5978* GRUB Configuration:: Configuring the boot loader.
cf4a9129 5979* Invoking guix system:: Instantiating a system configuration.
97d76250 5980* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
5981* Defining Services:: Adding new service definitions.
5982@end menu
91ef73d4 5983
cf4a9129
LC
5984@node Using the Configuration System
5985@subsection Using the Configuration System
64d76fa6 5986
cf4a9129
LC
5987The operating system is configured by providing an
5988@code{operating-system} declaration in a file that can then be passed to
5989the @command{guix system} command (@pxref{Invoking guix system}). A
5990simple setup, with the default system services, the default Linux-Libre
5991kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 5992
cf4a9129
LC
5993@findex operating-system
5994@lisp
dd51caac 5995@include os-config-bare-bones.texi
cf4a9129 5996@end lisp
401c53c4 5997
cf4a9129
LC
5998This example should be self-describing. Some of the fields defined
5999above, such as @code{host-name} and @code{bootloader}, are mandatory.
6000Others, such as @code{packages} and @code{services}, can be omitted, in
6001which case they get a default value.
e7f34eb0 6002
5d94ac51
LC
6003Below we discuss the effect of some of the most important fields
6004(@pxref{operating-system Reference}, for details about all the available
6005fields), and how to @dfn{instantiate} the operating system using
6006@command{guix system}.
6007
6008@unnumberedsubsubsec Globally-Visible Packages
6009
cf4a9129 6010@vindex %base-packages
5d94ac51
LC
6011The @code{packages} field lists packages that will be globally visible
6012on the system, for all user accounts---i.e., in every user's @code{PATH}
6013environment variable---in addition to the per-user profiles
6014(@pxref{Invoking guix package}). The @var{%base-packages} variable
6015provides all the tools one would expect for basic user and administrator
6016tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6017the GNU Zile lightweight text editor, @command{find}, @command{grep},
6018etc. The example above adds tcpdump to those, taken from the @code{(gnu
6019packages admin)} module (@pxref{Package Modules}).
e7f34eb0 6020
f6c9fb1b
LC
6021@findex specification->package
6022Referring to packages by variable name, like @var{tcpdump} above, has
6023the advantage of being unambiguous; it also allows typos and such to be
6024diagnosed right away as ``unbound variables''. The downside is that one
6025needs to know which module defines which package, and to augment the
6026@code{use-package-modules} line accordingly. To avoid that, one can use
6027the @code{specification->package} procedure of the @code{(gnu packages)}
6028module, which returns the best package for a given name or name and
6029version:
6030
6031@lisp
6032(use-modules (gnu packages))
6033
6034(operating-system
6035 ;; ...
6036 (packages (append (map specification->package
6037 '("tcpdump" "htop" "gnupg-2.0"))
6038 %base-packages)))
6039@end lisp
6040
5d94ac51
LC
6041@unnumberedsubsubsec System Services
6042
cf4a9129
LC
6043@vindex %base-services
6044The @code{services} field lists @dfn{system services} to be made
6045available when the system starts (@pxref{Services}).
6046The @code{operating-system} declaration above specifies that, in
6047addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
6048daemon listening on port 2222 (@pxref{Networking Services,
6049@code{lsh-service}}). Under the hood,
cf4a9129
LC
6050@code{lsh-service} arranges so that @code{lshd} is started with the
6051right command-line options, possibly with supporting configuration files
cd6f6c22
LC
6052generated as needed (@pxref{Defining Services}).
6053
6054@cindex customization, of services
6055@findex modify-services
6056Occasionally, instead of using the base services as is, you will want to
6057customize them. For instance, to change the configuration of
6058@code{guix-daemon} and Mingetty (the console log-in), you may write the
6059following instead of @var{%base-services}:
6060
6061@lisp
6062(modify-services %base-services
6063 (guix-service-type config =>
6064 (guix-configuration
6065 (inherit config)
6066 (use-substitutes? #f)
6067 (extra-options '("--gc-keep-outputs"))))
6068 (mingetty-service-type config =>
6069 (mingetty-configuration
6070 (inherit config)
6071 (motd (plain-file "motd" "Hi there!")))))
6072@end lisp
6073
6074@noindent
6075The effect here is to change the options passed to @command{guix-daemon}
6076when it is started, as well as the ``message of the day'' that appears
6077when logging in at the console. @xref{Service Reference,
6078@code{modify-services}}, for more on that.
a1ba8475 6079
dd51caac 6080The configuration for a typical ``desktop'' usage, with the X11 display
cd6f6c22 6081server, a desktop environment, network management, power management, and
dd51caac
LC
6082more, would look like this:
6083
6084@lisp
6085@include os-config-desktop.texi
6086@end lisp
6087
6088@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
6089@var{%desktop-services}. @xref{X.509 Certificates}, for background
6090information about the @code{nss-certs} package that is used here.
dd51caac 6091
5d94ac51
LC
6092Again, @var{%desktop-services} is just a list of service objects. If
6093you want to remove services from there, you can do so using the
6094procedures for list filtering (@pxref{SRFI-1 Filtering and
6095Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6096following expression returns a list that contains all the services in
6097@var{%desktop-services} minus the Avahi service:
6098
6099@example
6100(remove (lambda (service)
6101 (eq? (service-kind service) avahi-service-type))
6102 %desktop-services)
6103@end example
6104
6105@unnumberedsubsubsec Instantiating the System
6106
6107Assuming the @code{operating-system} declaration
6108is stored in the @file{my-system-config.scm}
cf4a9129
LC
6109file, the @command{guix system reconfigure my-system-config.scm} command
6110instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
6111entry (@pxref{Invoking guix system}).
6112
1068f26b 6113The normal way to change the system configuration is by updating this
65797bff
LC
6114file and re-running @command{guix system reconfigure}. One should never
6115have to touch files in @command{/etc} or to run commands that modify the
6116system state such as @command{useradd} or @command{grub-install}. In
6117fact, you must avoid that since that would not only void your warranty
6118but also prevent you from rolling back to previous versions of your
6119system, should you ever need to.
6120
6121@cindex roll-back, of the operating system
6122Speaking of roll-back, each time you run @command{guix system
6123reconfigure}, a new @dfn{generation} of the system is created---without
6124modifying or deleting previous generations. Old system generations get
6125an entry in the GRUB boot menu, allowing you to boot them in case
6126something went wrong with the latest generation. Reassuring, no? The
6127@command{guix system list-generations} command lists the system
6128generations available on disk.
b81e1947 6129
5d94ac51
LC
6130@unnumberedsubsubsec The Programming Interface
6131
cf4a9129
LC
6132At the Scheme level, the bulk of an @code{operating-system} declaration
6133is instantiated with the following monadic procedure (@pxref{The Store
6134Monad}):
b81e1947 6135
cf4a9129
LC
6136@deffn {Monadic Procedure} operating-system-derivation os
6137Return a derivation that builds @var{os}, an @code{operating-system}
6138object (@pxref{Derivations}).
b81e1947 6139
cf4a9129
LC
6140The output of the derivation is a single directory that refers to all
6141the packages, configuration files, and other supporting files needed to
6142instantiate @var{os}.
6143@end deffn
b81e1947 6144
5d94ac51
LC
6145This procedure is provided by the @code{(gnu system)} module. Along
6146with @code{(gnu services)} (@pxref{Services}), this module contains the
6147guts of GuixSD. Make sure to visit it!
6148
6149
7313a52e
LC
6150@node operating-system Reference
6151@subsection @code{operating-system} Reference
6152
6153This section summarizes all the options available in
6154@code{operating-system} declarations (@pxref{Using the Configuration
6155System}).
6156
6157@deftp {Data Type} operating-system
6158This is the data type representing an operating system configuration.
6159By that, we mean all the global system configuration, not per-user
6160configuration (@pxref{Using the Configuration System}).
6161
6162@table @asis
6163@item @code{kernel} (default: @var{linux-libre})
fbb25e56 6164The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
6165only the Linux-libre kernel is supported. In the future, it will be
6166possible to use the GNU@tie{}Hurd.}.
6167
ee2a6304
LC
6168@item @code{kernel-arguments} (default: @code{'()})
6169List of strings or gexps representing additional arguments to pass on
1068f26b 6170the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 6171
7313a52e 6172@item @code{bootloader}
88faf933 6173The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
6174
6175@item @code{initrd} (default: @code{base-initrd})
6176A two-argument monadic procedure that returns an initial RAM disk for
6177the Linux kernel. @xref{Initial RAM Disk}.
6178
f34c56be
LC
6179@item @code{firmware} (default: @var{%base-firmware})
6180@cindex firmware
6181List of firmware packages loadable by the operating system kernel.
6182
6183The default includes firmware needed for Atheros-based WiFi devices
6184(Linux-libre module @code{ath9k}.)
6185
7313a52e
LC
6186@item @code{host-name}
6187The host name.
6188
6189@item @code{hosts-file}
6190@cindex hosts file
24e02c28 6191A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 6192@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 6193Reference Manual}). The default is a file with entries for
7313a52e
LC
6194@code{localhost} and @var{host-name}.
6195
6196@item @code{mapped-devices} (default: @code{'()})
6197A list of mapped devices. @xref{Mapped Devices}.
6198
6199@item @code{file-systems}
6200A list of file systems. @xref{File Systems}.
6201
6202@item @code{swap-devices} (default: @code{'()})
6203@cindex swap devices
6204A list of strings identifying devices to be used for ``swap space''
6205(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6206For example, @code{'("/dev/sda3")}.
6207
bf87f38a 6208@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
6209@itemx @code{groups} (default: @var{%base-groups})
6210List of user accounts and groups. @xref{User Accounts}.
6211
6212@item @code{skeletons} (default: @code{(default-skeletons)})
6213A monadic list of pairs of target file name and files. These are the
6214files that will be used as skeletons as new accounts are created.
6215
6216For instance, a valid value may look like this:
6217
6218@example
6219(mlet %store-monad ((bashrc (text-file "bashrc" "\
6220 export PATH=$HOME/.guix-profile/bin")))
6221 (return `((".bashrc" ,bashrc))))
6222@end example
6223
6224@item @code{issue} (default: @var{%default-issue})
6225A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 6226displayed when users log in on a text console.
7313a52e
LC
6227
6228@item @code{packages} (default: @var{%base-packages})
6229The set of packages installed in the global profile, which is accessible
6230at @file{/run/current-system/profile}.
6231
1068f26b 6232The default set includes core utilities and it is good practice to
7313a52e
LC
6233install non-core utilities in user profiles (@pxref{Invoking guix
6234package}).
6235
6236@item @code{timezone}
6237A timezone identifying string---e.g., @code{"Europe/Paris"}.
6238
17c20385
LC
6239You can run the @command{tzselect} command to find out which timezone
6240string corresponds to your region. Choosing an invalid timezone name
6241causes @command{guix system} to fail.
6242
598e19dc
LC
6243@item @code{locale} (default: @code{"en_US.utf8"})
6244The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
6245Library Reference Manual}). @xref{Locales}, for more information.
6246
6247@item @code{locale-definitions} (default: @var{%default-locale-definitions})
6248The list of locale definitions to be compiled and that may be used at
6249run time. @xref{Locales}.
7313a52e 6250
34760ae7
LC
6251@item @code{locale-libcs} (default: @code{(list @var{glibc})})
6252The list of GNU@tie{}libc packages whose locale data and tools are used
6253to build the locale definitions. @xref{Locales}, for compatibility
6254considerations that justify this option.
6255
996ed739 6256@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 6257Configuration of the libc name service switch (NSS)---a
996ed739
LC
6258@code{<name-service-switch>} object. @xref{Name Service Switch}, for
6259details.
6260
7313a52e 6261@item @code{services} (default: @var{%base-services})
28d939af 6262A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
6263
6264@item @code{pam-services} (default: @code{(base-pam-services)})
6265@cindex PAM
6266@cindex pluggable authentication modules
6267Linux @dfn{pluggable authentication module} (PAM) services.
6268@c FIXME: Add xref to PAM services section.
6269
6270@item @code{setuid-programs} (default: @var{%setuid-programs})
6271List of string-valued G-expressions denoting setuid programs.
6272@xref{Setuid Programs}.
6273
f5a9ffa0
AK
6274@item @code{sudoers-file} (default: @var{%sudoers-specification})
6275@cindex sudoers file
84765839
LC
6276The contents of the @file{/etc/sudoers} file as a file-like object
6277(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
6278
6279This file specifies which users can use the @command{sudo} command, what
6280they are allowed to do, and what privileges they may gain. The default
6281is that only @code{root} and members of the @code{wheel} group may use
6282@code{sudo}.
6283
6284@end table
6285@end deftp
6286
cf4a9129
LC
6287@node File Systems
6288@subsection File Systems
b81e1947 6289
cf4a9129 6290The list of file systems to be mounted is specified in the
1068f26b 6291@code{file-systems} field of the operating system declaration
cf4a9129
LC
6292(@pxref{Using the Configuration System}). Each file system is declared
6293using the @code{file-system} form, like this:
b81e1947
LC
6294
6295@example
cf4a9129
LC
6296(file-system
6297 (mount-point "/home")
6298 (device "/dev/sda3")
6299 (type "ext4"))
b81e1947
LC
6300@end example
6301
cf4a9129
LC
6302As usual, some of the fields are mandatory---those shown in the example
6303above---while others can be omitted. These are described below.
b81e1947 6304
cf4a9129
LC
6305@deftp {Data Type} file-system
6306Objects of this type represent file systems to be mounted. They
6307contain the following members:
5ff3c4b8 6308
cf4a9129
LC
6309@table @asis
6310@item @code{type}
6311This is a string specifying the type of the file system---e.g.,
6312@code{"ext4"}.
5ff3c4b8 6313
cf4a9129
LC
6314@item @code{mount-point}
6315This designates the place where the file system is to be mounted.
b81e1947 6316
cf4a9129
LC
6317@item @code{device}
6318This names the ``source'' of the file system. By default it is the name
6319of a node under @file{/dev}, but its meaning depends on the @code{title}
6320field described below.
401c53c4 6321
cf4a9129
LC
6322@item @code{title} (default: @code{'device})
6323This is a symbol that specifies how the @code{device} field is to be
6324interpreted.
401c53c4 6325
cf4a9129
LC
6326When it is the symbol @code{device}, then the @code{device} field is
6327interpreted as a file name; when it is @code{label}, then @code{device}
6328is interpreted as a partition label name; when it is @code{uuid},
6329@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 6330
661a1d79 6331UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
6332@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
6333@code{uuid} form expects 16-byte UUIDs as defined in
6334@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
6335form of UUID used by the ext2 family of file systems and others, but it
6336is different from ``UUIDs'' found in FAT file systems, for instance.},
6337like this:
661a1d79
LC
6338
6339@example
6340(file-system
6341 (mount-point "/home")
6342 (type "ext4")
6343 (title 'uuid)
6344 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6345@end example
6346
cf4a9129 6347The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
6348partitions without having to hard-code their actual device
6349name@footnote{Note that, while it is tempting to use
6350@file{/dev/disk/by-uuid} and similar device names to achieve the same
6351result, this is not recommended: These special device nodes are created
6352by the udev daemon and may be unavailable at the time the device is
6353mounted.}.
da7cabd4 6354
1068f26b 6355However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
6356Devices}), its @code{device} field @emph{must} refer to the mapped
6357device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6358@code{title} must be set to @code{'device}. This is required so that
6359the system knows that mounting the file system depends on having the
6360corresponding device mapping established.
6361
cf4a9129
LC
6362@item @code{flags} (default: @code{'()})
6363This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
6364include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6365access to special files), @code{no-suid} (ignore setuid and setgid
6366bits), and @code{no-exec} (disallow program execution.)
da7cabd4 6367
cf4a9129
LC
6368@item @code{options} (default: @code{#f})
6369This is either @code{#f}, or a string denoting mount options.
da7cabd4 6370
be21979d
LC
6371@item @code{mount?} (default: @code{#t})
6372This value indicates whether to automatically mount the file system when
6373the system is brought up. When set to @code{#f}, the file system gets
6374an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6375is not automatically mounted.
6376
cf4a9129
LC
6377@item @code{needed-for-boot?} (default: @code{#f})
6378This Boolean value indicates whether the file system is needed when
6379booting. If that is true, then the file system is mounted when the
6380initial RAM disk (initrd) is loaded. This is always the case, for
6381instance, for the root file system.
da7cabd4 6382
cf4a9129
LC
6383@item @code{check?} (default: @code{#t})
6384This Boolean indicates whether the file system needs to be checked for
6385errors before being mounted.
f9cc8971 6386
4e469051
LC
6387@item @code{create-mount-point?} (default: @code{#f})
6388When true, the mount point is created if it does not exist yet.
6389
e51710d1
LC
6390@item @code{dependencies} (default: @code{'()})
6391This is a list of @code{<file-system>} objects representing file systems
6392that must be mounted before (and unmounted after) this one.
6393
6394As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6395a dependency of @file{/sys/fs/cgroup/cpu} and
6396@file{/sys/fs/cgroup/memory}.
6397
cf4a9129
LC
6398@end table
6399@end deftp
da7cabd4 6400
a69576ea
LC
6401The @code{(gnu system file-systems)} exports the following useful
6402variables.
6403
6404@defvr {Scheme Variable} %base-file-systems
6405These are essential file systems that are required on normal systems,
cc0e575a 6406such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
6407below.) Operating system declarations should always contain at least
6408these.
a69576ea
LC
6409@end defvr
6410
7f239fd3
LC
6411@defvr {Scheme Variable} %pseudo-terminal-file-system
6412This is the file system to be mounted as @file{/dev/pts}. It supports
6413@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6414functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6415Manual}). Pseudo-terminals are used by terminal emulators such as
6416@command{xterm}.
6417@end defvr
6418
db17ae5c
LC
6419@defvr {Scheme Variable} %shared-memory-file-system
6420This file system is mounted as @file{/dev/shm} and is used to support
6421memory sharing across processes (@pxref{Memory-mapped I/O,
6422@code{shm_open},, libc, The GNU C Library Reference Manual}).
6423@end defvr
6424
3392ce5d
LC
6425@defvr {Scheme Variable} %immutable-store
6426This file system performs a read-only ``bind mount'' of
6427@file{/gnu/store}, making it read-only for all the users including
6428@code{root}. This prevents against accidental modification by software
6429running as @code{root} or by system administrators.
6430
6431The daemon itself is still able to write to the store: it remounts it
6432read-write in its own ``name space.''
6433@end defvr
6434
a69576ea
LC
6435@defvr {Scheme Variable} %binary-format-file-system
6436The @code{binfmt_misc} file system, which allows handling of arbitrary
6437executable file types to be delegated to user space. This requires the
6438@code{binfmt.ko} kernel module to be loaded.
6439@end defvr
6440
6441@defvr {Scheme Variable} %fuse-control-file-system
6442The @code{fusectl} file system, which allows unprivileged users to mount
6443and unmount user-space FUSE file systems. This requires the
6444@code{fuse.ko} kernel module to be loaded.
6445@end defvr
6446
510f9d86
LC
6447@node Mapped Devices
6448@subsection Mapped Devices
6449
6450@cindex device mapping
6451@cindex mapped devices
6452The Linux kernel has a notion of @dfn{device mapping}: a block device,
6453such as a hard disk partition, can be @dfn{mapped} into another device,
6454with additional processing over the data that flows through
6455it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6456concept of a ``mapped device'' and that of a file system: both boil down
6457to @emph{translating} input/output operations made on a file to
6458operations on its backing store. Thus, the Hurd implements mapped
6459devices, like file systems, using the generic @dfn{translator} mechanism
6460(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6461typical example is encryption device mapping: all writes to the mapped
6462device are encrypted, and all reads are deciphered, transparently.
6463
6464Mapped devices are declared using the @code{mapped-device} form:
6465
6466@example
6467(mapped-device
6468 (source "/dev/sda3")
6469 (target "home")
6470 (type luks-device-mapping))
6471@end example
6472
6473@noindent
6474@cindex disk encryption
6475@cindex LUKS
6476This example specifies a mapping from @file{/dev/sda3} to
6477@file{/dev/mapper/home} using LUKS---the
6478@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6479standard mechanism for disk encryption. The @file{/dev/mapper/home}
6480device can then be used as the @code{device} of a @code{file-system}
6481declaration (@pxref{File Systems}). The @code{mapped-device} form is
6482detailed below.
6483
6484@deftp {Data Type} mapped-device
6485Objects of this type represent device mappings that will be made when
6486the system boots up.
6487
9cb426b8
LC
6488@table @code
6489@item source
510f9d86
LC
6490This string specifies the name of the block device to be mapped, such as
6491@code{"/dev/sda3"}.
6492
9cb426b8 6493@item target
510f9d86
LC
6494This string specifies the name of the mapping to be established. For
6495example, specifying @code{"my-partition"} will lead to the creation of
6496the @code{"/dev/mapper/my-partition"} device.
6497
9cb426b8 6498@item type
510f9d86
LC
6499This must be a @code{mapped-device-kind} object, which specifies how
6500@var{source} is mapped to @var{target}.
6501@end table
6502@end deftp
6503
6504@defvr {Scheme Variable} luks-device-mapping
6505This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 6506command from the package with the same name. It relies on the
510f9d86
LC
6507@code{dm-crypt} Linux kernel module.
6508@end defvr
6509
cf4a9129
LC
6510@node User Accounts
6511@subsection User Accounts
ee85f3db 6512
9bea87a5
LC
6513User accounts and groups are entirely managed through the
6514@code{operating-system} declaration. They are specified with the
6515@code{user-account} and @code{user-group} forms:
ee85f3db 6516
cf4a9129
LC
6517@example
6518(user-account
6519 (name "alice")
6520 (group "users")
24e752c0
LC
6521 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6522 "audio" ;sound card
6523 "video" ;video devices such as webcams
6524 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
6525 (comment "Bob's sister")
6526 (home-directory "/home/alice"))
6527@end example
25083588 6528
9bea87a5
LC
6529When booting or upon completion of @command{guix system reconfigure},
6530the system ensures that only the user accounts and groups specified in
6531the @code{operating-system} declaration exist, and with the specified
6532properties. Thus, account or group creations or modifications made by
6533directly invoking commands such as @command{useradd} are lost upon
6534reconfiguration or reboot. This ensures that the system remains exactly
6535as declared.
6536
cf4a9129
LC
6537@deftp {Data Type} user-account
6538Objects of this type represent user accounts. The following members may
6539be specified:
ee85f3db 6540
cf4a9129
LC
6541@table @asis
6542@item @code{name}
6543The name of the user account.
ee85f3db 6544
cf4a9129
LC
6545@item @code{group}
6546This is the name (a string) or identifier (a number) of the user group
6547this account belongs to.
ee85f3db 6548
cf4a9129
LC
6549@item @code{supplementary-groups} (default: @code{'()})
6550Optionally, this can be defined as a list of group names that this
6551account belongs to.
ee85f3db 6552
cf4a9129
LC
6553@item @code{uid} (default: @code{#f})
6554This is the user ID for this account (a number), or @code{#f}. In the
6555latter case, a number is automatically chosen by the system when the
6556account is created.
ee85f3db 6557
cf4a9129 6558@item @code{comment} (default: @code{""})
1068f26b 6559A comment about the account, such as the account owner's full name.
c8c871d1 6560
cf4a9129
LC
6561@item @code{home-directory}
6562This is the name of the home directory for the account.
ee85f3db 6563
cf4a9129
LC
6564@item @code{shell} (default: Bash)
6565This is a G-expression denoting the file name of a program to be used as
6566the shell (@pxref{G-Expressions}).
ee85f3db 6567
cf4a9129
LC
6568@item @code{system?} (default: @code{#f})
6569This Boolean value indicates whether the account is a ``system''
6570account. System accounts are sometimes treated specially; for instance,
6571graphical login managers do not list them.
ee85f3db 6572
1bd4e6db 6573@anchor{user-account-password}
cf4a9129 6574@item @code{password} (default: @code{#f})
eb59595c
LC
6575You would normally leave this field to @code{#f}, initialize user
6576passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
6577users change it with @command{passwd}. Passwords set with
6578@command{passwd} are of course preserved across reboot and
6579reconfiguration.
eb59595c
LC
6580
6581If you @emph{do} want to have a preset password for an account, then
6582this field must contain the encrypted password, as a string.
5d1f1177
LC
6583@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6584on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 6585Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 6586
cf4a9129
LC
6587@end table
6588@end deftp
ee85f3db 6589
cf4a9129 6590User group declarations are even simpler:
ee85f3db 6591
cf4a9129
LC
6592@example
6593(user-group (name "students"))
6594@end example
ee85f3db 6595
cf4a9129
LC
6596@deftp {Data Type} user-group
6597This type is for, well, user groups. There are just a few fields:
af8a56b8 6598
cf4a9129
LC
6599@table @asis
6600@item @code{name}
1068f26b 6601The name of the group.
ee85f3db 6602
cf4a9129
LC
6603@item @code{id} (default: @code{#f})
6604The group identifier (a number). If @code{#f}, a new number is
6605automatically allocated when the group is created.
ee85f3db 6606
c8fa3426
LC
6607@item @code{system?} (default: @code{#f})
6608This Boolean value indicates whether the group is a ``system'' group.
6609System groups have low numerical IDs.
6610
cf4a9129
LC
6611@item @code{password} (default: @code{#f})
6612What, user groups can have a password? Well, apparently yes. Unless
1068f26b 6613@code{#f}, this field specifies the password of the group.
ee85f3db 6614
cf4a9129
LC
6615@end table
6616@end deftp
401c53c4 6617
cf4a9129
LC
6618For convenience, a variable lists all the basic user groups one may
6619expect:
401c53c4 6620
cf4a9129
LC
6621@defvr {Scheme Variable} %base-groups
6622This is the list of basic user groups that users and/or packages expect
6623to be present on the system. This includes groups such as ``root'',
6624``wheel'', and ``users'', as well as groups used to control access to
6625specific devices such as ``audio'', ``disk'', and ``cdrom''.
6626@end defvr
401c53c4 6627
bf87f38a
LC
6628@defvr {Scheme Variable} %base-user-accounts
6629This is the list of basic system accounts that programs may expect to
6630find on a GNU/Linux system, such as the ``nobody'' account.
6631
6632Note that the ``root'' account is not included here. It is a
6633special-case and is automatically added whether or not it is specified.
6634@end defvr
6635
598e19dc
LC
6636@node Locales
6637@subsection Locales
6638
6639@cindex locale
6640A @dfn{locale} defines cultural conventions for a particular language
6641and region of the world (@pxref{Locales,,, libc, The GNU C Library
6642Reference Manual}). Each locale has a name that typically has the form
b2636518 6643@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
6644@code{fr_LU.utf8} designates the locale for the French language, with
6645cultural conventions from Luxembourg, and using the UTF-8 encoding.
6646
6647@cindex locale definition
6648Usually, you will want to specify the default locale for the machine
6649using the @code{locale} field of the @code{operating-system} declaration
6650(@pxref{operating-system Reference, @code{locale}}).
6651
f5582b2c
LC
6652The selected locale is automatically added to the @dfn{locale
6653definitions} known to the system if needed, with its codeset inferred
6654from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
6655@code{UTF-8} codeset. Additional locale definitions can be specified in
6656the @code{locale-definitions} slot of @code{operating-system}---this is
6657useful, for instance, if the codeset could not be inferred from the
6658locale name. The default set of locale definitions includes some widely
6659used locales, but not all the available locales, in order to save space.
6660
6661For instance, to add the North Frisian locale for Germany, the value of
6662that field may be:
598e19dc
LC
6663
6664@example
6665(cons (locale-definition
6666 (name "fy_DE.utf8") (source "fy_DE"))
6667 %default-locale-definitions)
6668@end example
6669
6670Likewise, to save space, one might want @code{locale-definitions} to
6671list only the locales that are actually used, as in:
6672
6673@example
6674(list (locale-definition
6675 (name "ja_JP.eucjp") (source "ja_JP")
6676 (charset "EUC-JP")))
6677@end example
6678
5c3c1427
LC
6679@vindex LOCPATH
6680The compiled locale definitions are available at
46bd6edd
LC
6681@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6682version, which is the default location where the GNU@tie{}libc provided
6683by Guix looks for locale data. This can be overridden using the
6684@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
6685@code{LOCPATH} and locale packages}).
6686
598e19dc
LC
6687The @code{locale-definition} form is provided by the @code{(gnu system
6688locale)} module. Details are given below.
6689
6690@deftp {Data Type} locale-definition
6691This is the data type of a locale definition.
6692
6693@table @asis
6694
6695@item @code{name}
6696The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6697Reference Manual}, for more information on locale names.
6698
6699@item @code{source}
6700The name of the source for that locale. This is typically the
6701@code{@var{language}_@var{territory}} part of the locale name.
6702
6703@item @code{charset} (default: @code{"UTF-8"})
6704The ``character set'' or ``code set'' for that locale,
6705@uref{http://www.iana.org/assignments/character-sets, as defined by
6706IANA}.
6707
6708@end table
6709@end deftp
6710
6711@defvr {Scheme Variable} %default-locale-definitions
1068f26b 6712A list of commonly used UTF-8 locales, used as the default
b2636518 6713value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 6714declarations.
b2636518
LC
6715
6716@cindex locale name
6717@cindex normalized codeset in locale names
6718These locale definitions use the @dfn{normalized codeset} for the part
6719that follows the dot in the name (@pxref{Using gettextized software,
6720normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6721instance it has @code{uk_UA.utf8} but @emph{not}, say,
6722@code{uk_UA.UTF-8}.
598e19dc 6723@end defvr
401c53c4 6724
34760ae7
LC
6725@subsubsection Locale Data Compatibility Considerations
6726
6727@cindex incompatibility, of locale data
6728@code{operating-system} declarations provide a @code{locale-libcs} field
6729to specify the GNU@tie{}libc packages that are used to compile locale
6730declarations (@pxref{operating-system Reference}). ``Why would I
6731care?'', you may ask. Well, it turns out that the binary format of
6732locale data is occasionally incompatible from one libc version to
6733another.
6734
6735@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6736@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6737For instance, a program linked against libc version 2.21 is unable to
6738read locale data produced with libc 2.22; worse, that program
6739@emph{aborts} instead of simply ignoring the incompatible locale
6740data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6741the incompatible locale data, which is already an improvement.}.
6742Similarly, a program linked against libc 2.22 can read most, but not
6743all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6744data is incompatible); thus calls to @code{setlocale} may fail, but
6745programs will not abort.
6746
6747The ``problem'' in GuixSD is that users have a lot of freedom: They can
6748choose whether and when to upgrade software in their profiles, and might
6749be using a libc version different from the one the system administrator
6750used to build the system-wide locale data.
6751
6752Fortunately, unprivileged users can also install their own locale data
6753and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6754@code{GUIX_LOCPATH} and locale packages}).
6755
6756Still, it is best if the system-wide locale data at
6757@file{/run/current-system/locale} is built for all the libc versions
6758actually in use on the system, so that all the programs can access
6759it---this is especially crucial on a multi-user system. To do that, the
6760administrator can specify several libc packages in the
6761@code{locale-libcs} field of @code{operating-system}:
6762
6763@example
6764(use-package-modules base)
6765
6766(operating-system
6767 ;; @dots{}
6768 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6769@end example
6770
6771This example would lead to a system containing locale definitions for
6772both libc 2.21 and the current version of libc in
6773@file{/run/current-system/locale}.
6774
6775
cf4a9129
LC
6776@node Services
6777@subsection Services
401c53c4 6778
cf4a9129
LC
6779@cindex system services
6780An important part of preparing an @code{operating-system} declaration is
6781listing @dfn{system services} and their configuration (@pxref{Using the
6782Configuration System}). System services are typically daemons launched
6783when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
6784configuring network access.
6785
dd17bc38
AK
6786Services are managed by the GNU@tie{}Shepherd (@pxref{Introduction,,,
6787shepherd, The GNU Shepherd Manual}). On a running system, the
6788@command{herd} command allows you to list the available services, show
6789their status, start and stop them, or do other specific operations
6790(@pxref{Jump Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
6791
6792@example
dd17bc38 6793# herd status
d8b94dbd
LC
6794@end example
6795
6796The above command, run as @code{root}, lists the currently defined
dd17bc38 6797services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
6798service:
6799
6800@example
dd17bc38 6801# herd doc nscd
d8b94dbd
LC
6802Run libc's name service cache daemon (nscd).
6803@end example
6804
6805The @command{start}, @command{stop}, and @command{restart} sub-commands
6806have the effect you would expect. For instance, the commands below stop
6807the nscd service and restart the Xorg display server:
6808
6809@example
dd17bc38 6810# herd stop nscd
d8b94dbd 6811Service nscd has been stopped.
dd17bc38 6812# herd restart xorg-server
d8b94dbd
LC
6813Service xorg-server has been stopped.
6814Service xorg-server has been started.
6815@end example
401c53c4 6816
cf4a9129 6817The following sections document the available services, starting with
d8b94dbd
LC
6818the core services, that may be used in an @code{operating-system}
6819declaration.
401c53c4 6820
cf4a9129
LC
6821@menu
6822* Base Services:: Essential system services.
6823* Networking Services:: Network setup, SSH daemon, etc.
6824* X Window:: Graphical display.
fe1a39d3 6825* Desktop Services:: D-Bus and desktop services.
105369a4 6826* Database Services:: SQL databases.
d8c18af8 6827* Mail Services:: IMAP, POP3, SMTP, and all that.
58724c48 6828* Web Services:: Web servers.
aa4ed923 6829* Various Services:: Other services.
cf4a9129 6830@end menu
401c53c4 6831
cf4a9129
LC
6832@node Base Services
6833@subsubsection Base Services
a1ba8475 6834
cf4a9129
LC
6835The @code{(gnu services base)} module provides definitions for the basic
6836services that one expects from the system. The services exported by
6837this module are listed below.
401c53c4 6838
cf4a9129 6839@defvr {Scheme Variable} %base-services
31771497
LC
6840This variable contains a list of basic services (@pxref{Service Types
6841and Services}, for more information on service objects) one would
cf4a9129 6842expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 6843the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 6844more.
401c53c4 6845
cf4a9129
LC
6846This is the default value of the @code{services} field of
6847@code{operating-system} declarations. Usually, when customizing a
6848system, you will want to append services to @var{%base-services}, like
6849this:
401c53c4 6850
cf4a9129 6851@example
fa1e31b8 6852(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
6853@end example
6854@end defvr
401c53c4 6855
be1c2c54 6856@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
6857Return a service that sets the host name to @var{name}.
6858@end deffn
401c53c4 6859
66e4f01c
LC
6860@deffn {Scheme Procedure} mingetty-service @var{config}
6861Return a service to run mingetty according to @var{config}, a
6862@code{<mingetty-configuration>} object, which specifies the tty to run, among
6863other things.
cf4a9129 6864@end deffn
401c53c4 6865
66e4f01c
LC
6866@deftp {Data Type} mingetty-configuration
6867This is the data type representing the configuration of Mingetty, which
6868implements console log-in.
6869
6870@table @asis
6871
6872@item @code{tty}
6873The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6874
6875@item @code{motd}
6876A file-like object containing the ``message of the day''.
6877
6878@item @code{auto-login} (default: @code{#f})
6879When true, this field must be a string denoting the user name under
f9b9a033 6880which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
6881user name and password must be entered to log in.
6882
6883@item @code{login-program} (default: @code{#f})
6884This must be either @code{#f}, in which case the default log-in program
6885is used (@command{login} from the Shadow tool suite), or a gexp denoting
6886the name of the log-in program.
6887
6888@item @code{login-pause?} (default: @code{#f})
6889When set to @code{#t} in conjunction with @var{auto-login}, the user
6890will have to press a key before the log-in shell is launched.
6891
6892@item @code{mingetty} (default: @var{mingetty})
6893The Mingetty package to use.
6894
6895@end table
6896@end deftp
6897
6454b333
LC
6898@cindex name service cache daemon
6899@cindex nscd
be1c2c54 6900@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 6901 [#:name-services '()]
1068f26b 6902Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
6903given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6904Service Switch}, for an example.
cf4a9129 6905@end deffn
401c53c4 6906
6454b333
LC
6907@defvr {Scheme Variable} %nscd-default-configuration
6908This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 6909by @code{nscd-service}. It uses the caches defined by
6454b333
LC
6910@var{%nscd-default-caches}; see below.
6911@end defvr
6912
6913@deftp {Data Type} nscd-configuration
1068f26b 6914This is the data type representing the name service cache daemon (nscd)
6454b333
LC
6915configuration.
6916
6917@table @asis
6918
b893f1ae
LC
6919@item @code{name-services} (default: @code{'()})
6920List of packages denoting @dfn{name services} that must be visible to
6921the nscd---e.g., @code{(list @var{nss-mdns})}.
6922
6923@item @code{glibc} (default: @var{glibc})
6924Package object denoting the GNU C Library providing the @command{nscd}
6925command.
6926
6454b333 6927@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 6928Name of the nscd log file. This is where debugging output goes when
6454b333
LC
6929@code{debug-level} is strictly positive.
6930
6931@item @code{debug-level} (default: @code{0})
1068f26b 6932Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
6933debugging output is logged.
6934
6935@item @code{caches} (default: @var{%nscd-default-caches})
6936List of @code{<nscd-cache>} objects denoting things to be cached; see
6937below.
6938
6939@end table
6940@end deftp
6941
6942@deftp {Data Type} nscd-cache
6943Data type representing a cache database of nscd and its parameters.
6944
6945@table @asis
6946
6947@item @code{database}
6948This is a symbol representing the name of the database to be cached.
6949Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6950@code{services}, which designate the corresponding NSS database
6951(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6952
6953@item @code{positive-time-to-live}
6954@itemx @code{negative-time-to-live} (default: @code{20})
6955A number representing the number of seconds during which a positive or
6956negative lookup result remains in cache.
6957
6958@item @code{check-files?} (default: @code{#t})
6959Whether to check for updates of the files corresponding to
6960@var{database}.
6961
6962For instance, when @var{database} is @code{hosts}, setting this flag
6963instructs nscd to check for updates in @file{/etc/hosts} and to take
6964them into account.
6965
6966@item @code{persistent?} (default: @code{#t})
6967Whether the cache should be stored persistently on disk.
6968
6969@item @code{shared?} (default: @code{#t})
6970Whether the cache should be shared among users.
6971
6972@item @code{max-database-size} (default: 32@tie{}MiB)
6973Maximum size in bytes of the database cache.
6974
6975@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6976@c settings, so leave them out.
6977
6978@end table
6979@end deftp
6980
6981@defvr {Scheme Variable} %nscd-default-caches
6982List of @code{<nscd-cache>} objects used by default by
1068f26b 6983@code{nscd-configuration} (see above).
6454b333
LC
6984
6985It enables persistent and aggressive caching of service and host name
6986lookups. The latter provides better host name lookup performance,
6987resilience in the face of unreliable name servers, and also better
6988privacy---often the result of host name lookups is in local cache, so
6989external name servers do not even need to be queried.
6990@end defvr
6991
6992
44abcb28
LC
6993@deffn {Scheme Procedure} syslog-service @
6994 [#:config-file @var{%default-syslog.conf}]
1068f26b 6995Return a service that runs @command{syslogd}. If the configuration file
44abcb28 6996name @var{config-file} is not specified, use some reasonable default
cf4a9129 6997settings.
44abcb28
LC
6998
6999@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
7000information on the configuration file syntax.
cf4a9129 7001@end deffn
401c53c4 7002
0adfe95a
LC
7003@anchor{guix-configuration-type}
7004@deftp {Data Type} guix-configuration
7005This data type represents the configuration of the Guix build daemon.
7006@xref{Invoking guix-daemon}, for more information.
7007
7008@table @asis
7009@item @code{guix} (default: @var{guix})
7010The Guix package to use.
401c53c4 7011
0adfe95a
LC
7012@item @code{build-group} (default: @code{"guixbuild"})
7013Name of the group for build user accounts.
401c53c4 7014
0adfe95a
LC
7015@item @code{build-accounts} (default: @code{10})
7016Number of build user accounts to create.
401c53c4 7017
0adfe95a
LC
7018@item @code{authorize-key?} (default: @code{#t})
7019Whether to authorize the substitute key for @code{hydra.gnu.org}
7020(@pxref{Substitutes}).
7021
7022@item @code{use-substitutes?} (default: @code{#t})
7023Whether to use substitutes.
7024
b0b9f6e0
LC
7025@item @code{substitute-urls} (default: @var{%default-substitute-urls})
7026The list of URLs where to look for substitutes by default.
7027
0adfe95a
LC
7028@item @code{extra-options} (default: @code{'()})
7029List of extra command-line options for @command{guix-daemon}.
7030
7031@item @code{lsof} (default: @var{lsof})
7032@itemx @code{lsh} (default: @var{lsh})
7033The lsof and lsh packages to use.
7034
7035@end table
7036@end deftp
7037
7038@deffn {Scheme Procedure} guix-service @var{config}
7039Return a service that runs the Guix build daemon according to
7040@var{config}.
cf4a9129 7041@end deffn
a1ba8475 7042
be1c2c54 7043@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
7044Run @var{udev}, which populates the @file{/dev} directory dynamically.
7045@end deffn
401c53c4 7046
be1c2c54 7047@deffn {Scheme Procedure} console-keymap-service @var{file}
dedb8d5e 7048@cindex keyboard layout
5eca9459
AK
7049Return a service to load console keymap from @var{file} using
7050@command{loadkeys} command.
7051@end deffn
7052
8664cc88
LC
7053@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
7054 [#:options]
7055Run @var{gpm}, the general-purpose mouse daemon, with the given
7056command-line @var{options}. GPM allows users to use the mouse in the console,
7057notably to select, copy, and paste text. The default value of @var{options}
7058uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7059
7060This service is not part of @var{%base-services}.
7061@end deffn
7062
1c52181f
LC
7063@anchor{guix-publish-service}
7064@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7065 [#:port 80] [#:host "localhost"]
7066Return a service that runs @command{guix publish} listening on @var{host}
7067and @var{port} (@pxref{Invoking guix publish}).
7068
7069This assumes that @file{/etc/guix} already contains a signing key pair as
7070created by @command{guix archive --generate-key} (@pxref{Invoking guix
7071archive}). If that is not the case, the service will fail to start.
7072@end deffn
7073
a69576ea 7074
cf4a9129
LC
7075@node Networking Services
7076@subsubsection Networking Services
401c53c4 7077
fa1e31b8 7078The @code{(gnu services networking)} module provides services to configure
cf4a9129 7079the network interface.
a1ba8475 7080
a023cca8 7081@cindex DHCP, networking service
be1c2c54 7082@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
7083Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7084Protocol (DHCP) client, on all the non-loopback network interfaces.
7085@end deffn
7086
be1c2c54 7087@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
7088 [#:gateway #f] [#:name-services @code{'()}]
7089Return a service that starts @var{interface} with address @var{ip}. If
7090@var{gateway} is true, it must be a string specifying the default network
7091gateway.
7092@end deffn
8b315a6d 7093
b7d0c494 7094@cindex wicd
87f40011 7095@cindex network management
be1c2c54 7096@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
7097Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7098management daemon that aims to simplify wired and wireless networking.
7099
7100This service adds the @var{wicd} package to the global profile, providing
7101several commands to interact with the daemon and configure networking:
7102@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7103and @command{wicd-curses} user interfaces.
b7d0c494
MW
7104@end deffn
7105
c0a9589d
SB
7106@cindex NetworkManager
7107@deffn {Scheme Procedure} network-manager-service @
7108 [#:network-manager @var{network-manager}]
7109Return a service that runs NetworkManager, a network connection manager
1068f26b 7110attempting to keep network connectivity active when available.
c0a9589d
SB
7111@end deffn
7112
be1c2c54 7113@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
7114 [#:name-service @var{%ntp-servers}]
7115Return a service that runs the daemon from @var{ntp}, the
7116@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7117keep the system clock synchronized with that of @var{servers}.
7118@end deffn
7119
7120@defvr {Scheme Variable} %ntp-servers
7121List of host names used as the default NTP servers.
7122@end defvr
7123
375c6108
LC
7124@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7125Return a service to run the @uref{https://torproject.org, Tor} anonymous
7126networking daemon.
8b315a6d 7127
375c6108 7128The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
7129@var{config-file}, a file-like object, with an additional @code{User tor} line
7130and lines for hidden services added via @code{tor-hidden-service}. Run
7131@command{man tor} for information about the configuration file.
7132@end deffn
7133
24a8ef3b 7134@cindex hidden service
6331bde7
LC
7135@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7136Define a new Tor @dfn{hidden service} called @var{name} and implementing
7137@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7138
7139@example
24a8ef3b
LC
7140 '((22 "127.0.0.1:22")
7141 (80 "127.0.0.1:8080"))
6331bde7
LC
7142@end example
7143
7144In this example, port 22 of the hidden service is mapped to local port 22, and
7145port 80 is mapped to local port 8080.
7146
6629099a
LC
7147This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7148the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
7149service.
7150
7151See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7152project's documentation} for more information.
cf4a9129 7153@end deffn
8b315a6d 7154
be1c2c54 7155@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
7156 [#:interface "127.0.0.1"] [#:port 6667] @
7157 [#:extra-settings ""]
7158Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7159acts as a gateway between IRC and chat networks.
7160
7161The daemon will listen to the interface corresponding to the IP address
7162specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7163local clients can connect, whereas @code{0.0.0.0} means that connections can
7164come from any networking interface.
7165
7166In addition, @var{extra-settings} specifies a string to append to the
7167configuration file.
7168@end deffn
7169
f4391bec 7170Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 7171
be1c2c54 7172@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 7173 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
7174 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7175 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7176 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 7177 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
7178Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7179@var{host-key} must designate a file containing the host key, and readable
7180only by root.
72e25e35 7181
5833bf33
DP
7182When @var{daemonic?} is true, @command{lshd} will detach from the
7183controlling terminal and log its output to syslogd, unless one sets
7184@var{syslog-output?} to false. Obviously, it also makes lsh-service
7185depend on existence of syslogd service. When @var{pid-file?} is true,
7186@command{lshd} writes its PID to the file called @var{pid-file}.
7187
cf4a9129
LC
7188When @var{initialize?} is true, automatically create the seed and host key
7189upon service activation if they do not exist yet. This may take long and
7190require interaction.
8b315a6d 7191
20dd519c
LC
7192When @var{initialize?} is false, it is up to the user to initialize the
7193randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7194a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7195basics,,, lsh, LSH Manual}).
7196
cf4a9129
LC
7197When @var{interfaces} is empty, lshd listens for connections on all the
7198network interfaces; otherwise, @var{interfaces} must be a list of host names
7199or addresses.
9bf3c1a7 7200
20dd519c
LC
7201@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7202passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 7203root.
4af2447e 7204
cf4a9129
LC
7205The other options should be self-descriptive.
7206@end deffn
4af2447e 7207
fa0c1d61
LC
7208@defvr {Scheme Variable} %facebook-host-aliases
7209This variable contains a string for use in @file{/etc/hosts}
7210(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7211line contains a entry that maps a known server name of the Facebook
7212on-line service---e.g., @code{www.facebook.com}---to the local
7213host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7214
7215This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
7216@code{operating-system} declaration (@pxref{operating-system Reference,
7217@file{/etc/hosts}}):
fa0c1d61
LC
7218
7219@example
7220(use-modules (gnu) (guix))
7221
7222(operating-system
7223 (host-name "mymachine")
7224 ;; ...
7225 (hosts-file
7226 ;; Create a /etc/hosts file with aliases for "localhost"
7227 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
7228 (plain-file "hosts"
7229 (string-append (local-host-aliases host-name)
7230 %facebook-host-aliases))))
fa0c1d61
LC
7231@end example
7232
7233This mechanism can prevent programs running locally, such as Web
7234browsers, from accessing Facebook.
7235@end defvr
7236
965a7332
LC
7237The @code{(gnu services avahi)} provides the following definition.
7238
be1c2c54 7239@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
7240 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7241 [#:ipv6? #t] [#:wide-area? #f] @
7242 [#:domains-to-browse '()]
7243Return a service that runs @command{avahi-daemon}, a system-wide
7244mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
7245"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7246extends the name service cache daemon (nscd) so that it can resolve
7247@code{.local} host names using
1065bed9
LC
7248@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7249add the @var{avahi} package to the system profile so that commands such as
7250@command{avahi-browse} are directly usable.
965a7332
LC
7251
7252If @var{host-name} is different from @code{#f}, use that as the host name to
7253publish for this machine; otherwise, use the machine's actual host name.
7254
7255When @var{publish?} is true, publishing of host names and services is allowed;
7256in particular, avahi-daemon will publish the machine's host name and IP
7257address via mDNS on the local network.
7258
7259When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7260
7261Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7262sockets.
7263@end deffn
7264
7265
cf4a9129
LC
7266@node X Window
7267@subsubsection X Window
68ad877c 7268
cf4a9129
LC
7269Support for the X Window graphical display system---specifically
7270Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7271there is no @code{xorg-service} procedure. Instead, the X server is
7272started by the @dfn{login manager}, currently SLiM.
4af2447e 7273
be1c2c54 7274@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
7275 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7276 [#:theme @var{%default-slim-theme}] @
4bd43bbe 7277 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
7278Return a service that spawns the SLiM graphical login manager, which in
7279turn starts the X display server with @var{startx}, a command as returned by
7280@code{xorg-start-command}.
4af2447e 7281
04e4e6ab
LC
7282@cindex X session
7283
7284SLiM automatically looks for session types described by the @file{.desktop}
7285files in @file{/run/current-system/profile/share/xsessions} and allows users
7286to choose a session from the log-in screen using @kbd{F1}. Packages such as
7287@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
7288adding them to the system-wide set of packages automatically makes them
7289available at the log-in screen.
7290
7291In addition, @file{~/.xsession} files are honored. When available,
7292@file{~/.xsession} must be an executable that starts a window manager
7293and/or other X clients.
7294
cf4a9129
LC
7295When @var{allow-empty-passwords?} is true, allow logins with an empty
7296password. When @var{auto-login?} is true, log in automatically as
7297@var{default-user}.
0ecc3bf3 7298
1068f26b 7299If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
7300@var{theme} must be a gexp denoting the name of a directory containing the
7301theme to use. In that case, @var{theme-name} specifies the name of the
7302theme.
cf4a9129 7303@end deffn
4af2447e 7304
0ecc3bf3
LC
7305@defvr {Scheme Variable} %default-theme
7306@defvrx {Scheme Variable} %default-theme-name
7307The G-Expression denoting the default SLiM theme and its name.
7308@end defvr
7309
be1c2c54 7310@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 7311 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 7312Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
7313from @var{xorg-server}. @var{configuration-file} is the server configuration
7314file or a derivation that builds it; when omitted, the result of
7315@code{xorg-configuration-file} is used.
7316
7317Usually the X server is started by a login manager.
7318@end deffn
7319
be1c2c54 7320@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 7321 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
7322Return a configuration file for the Xorg server containing search paths for
7323all the common drivers.
f703413e
LC
7324
7325@var{drivers} must be either the empty list, in which case Xorg chooses a
7326graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 7327this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
7328
7329Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7330appropriate screen resolution; otherwise, it must be a list of
7331resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
7332
7333Last, @var{extra-config} is a list of strings or objects appended to the
7334@code{text-file*} argument list. It is used to pass extra text to be added
7335verbatim to the configuration file.
f703413e 7336@end deffn
4af2447e 7337
6726282b
LC
7338@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7339Add @var{package}, a package for a screen-locker or screen-saver whose
7340command is @var{program}, to the set of setuid programs and add a PAM entry
7341for it. For example:
7342
7343@lisp
7344(screen-locker-service xlockmore "xlock")
7345@end lisp
7346
7347makes the good ol' XlockMore usable.
7348@end deffn
7349
7350
fe1a39d3
LC
7351@node Desktop Services
7352@subsubsection Desktop Services
aa4ed923 7353
fe1a39d3
LC
7354The @code{(gnu services desktop)} module provides services that are
7355usually useful in the context of a ``desktop'' setup---that is, on a
7356machine running a graphical display server, possibly with graphical user
7357interfaces, etc.
aa4ed923 7358
4467be21
LC
7359To simplify things, the module defines a variable containing the set of
7360services that users typically expect on a machine with a graphical
7361environment and networking:
7362
7363@defvr {Scheme Variable} %desktop-services
7364This is a list of services that builds upon @var{%base-services} and
1068f26b 7365adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
7366
7367In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
7368@code{slim-service}}), screen lockers,
7369a network management tool (@pxref{Networking
4467be21 7370Services, @code{wicd-service}}), energy and color management services,
4650a77e 7371the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
7372the GeoClue location service, an NTP client (@pxref{Networking
7373Services}), the Avahi daemon, and has the name service switch service
7374configured to be able to use @code{nss-mdns} (@pxref{Name Service
7375Switch, mDNS}).
4467be21
LC
7376@end defvr
7377
7378The @var{%desktop-services} variable can be used as the @code{services}
7379field of an @code{operating-system} declaration (@pxref{operating-system
7380Reference, @code{services}}).
7381
0adfe95a
LC
7382The actual service definitions provided by @code{(gnu services dbus)}
7383and @code{(gnu services desktop)} are described below.
4467be21 7384
0adfe95a 7385@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
7386Return a service that runs the ``system bus'', using @var{dbus}, with
7387support for @var{services}.
aa4ed923 7388
fe1a39d3
LC
7389@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7390facility. Its system bus is used to allow system services to communicate
1068f26b 7391and to be notified of system-wide events.
aa4ed923 7392
fe1a39d3
LC
7393@var{services} must be a list of packages that provide an
7394@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7395and policy files. For example, to allow avahi-daemon to use the system bus,
7396@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
7397@end deffn
7398
0adfe95a 7399@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
7400Return a service that runs the @code{elogind} login and
7401seat management daemon. @uref{https://github.com/andywingo/elogind,
7402Elogind} exposes a D-Bus interface that can be used to know which users
7403are logged in, know what kind of sessions they have open, suspend the
7404system, inhibit system suspend, reboot the system, and other tasks.
7405
7406Elogind handles most system-level power events for a computer, for
7407example suspending the system when a lid is closed, or shutting it down
7408when the power button is pressed.
7409
7410The @var{config} keyword argument specifies the configuration for
1068f26b 7411elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
7412(@var{parameter} @var{value})...)} invocation. Available parameters and
7413their default values are:
7414
7415@table @code
7416@item kill-user-processes?
7417@code{#f}
7418@item kill-only-users
7419@code{()}
7420@item kill-exclude-users
7421@code{("root")}
7422@item inhibit-delay-max-seconds
7423@code{5}
7424@item handle-power-key
7425@code{poweroff}
7426@item handle-suspend-key
7427@code{suspend}
7428@item handle-hibernate-key
7429@code{hibernate}
7430@item handle-lid-switch
7431@code{suspend}
7432@item handle-lid-switch-docked
7433@code{ignore}
7434@item power-key-ignore-inhibited?
7435@code{#f}
7436@item suspend-key-ignore-inhibited?
7437@code{#f}
7438@item hibernate-key-ignore-inhibited?
7439@code{#f}
7440@item lid-switch-ignore-inhibited?
7441@code{#t}
7442@item holdoff-timeout-seconds
7443@code{30}
7444@item idle-action
7445@code{ignore}
7446@item idle-action-seconds
7447@code{(* 30 60)}
7448@item runtime-directory-size-percent
7449@code{10}
7450@item runtime-directory-size
7451@code{#f}
7452@item remove-ipc?
7453@code{#t}
7454@item suspend-state
7455@code{("mem" "standby" "freeze")}
7456@item suspend-mode
7457@code{()}
7458@item hibernate-state
7459@code{("disk")}
7460@item hibernate-mode
7461@code{("platform" "shutdown")}
7462@item hybrid-sleep-state
7463@code{("disk")}
7464@item hybrid-sleep-mode
7465@code{("suspend" "platform" "shutdown")}
7466@end table
7467@end deffn
7468
be1c2c54 7469@deffn {Scheme Procedure} polkit-service @
4650a77e 7470 [#:polkit @var{polkit}]
222e3319
LC
7471Return a service that runs the
7472@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7473management service}, which allows system administrators to grant access to
7474privileged operations in a structured way. By querying the Polkit service, a
7475privileged system component can know when it should grant additional
7476capabilities to ordinary users. For example, an ordinary user can be granted
7477the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7478@end deffn
7479
be1c2c54 7480@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7481 [#:watts-up-pro? #f] @
7482 [#:poll-batteries? #t] @
7483 [#:ignore-lid? #f] @
7484 [#:use-percentage-for-policy? #f] @
7485 [#:percentage-low 10] @
7486 [#:percentage-critical 3] @
7487 [#:percentage-action 2] @
7488 [#:time-low 1200] @
7489 [#:time-critical 300] @
7490 [#:time-action 120] @
7491 [#:critical-power-action 'hybrid-sleep]
7492Return a service that runs @uref{http://upower.freedesktop.org/,
7493@command{upowerd}}, a system-wide monitor for power consumption and battery
7494levels, with the given configuration settings. It implements the
7495@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7496GNOME.
7497@end deffn
7498
2b9e0a94
LC
7499@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7500Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7501UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7502notifications and ways to mount/unmount disks. Programs that talk to UDisks
7503include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7504@end deffn
7505
be1c2c54 7506@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7507Return a service that runs @command{colord}, a system service with a D-Bus
7508interface to manage the color profiles of input and output devices such as
7509screens and scanners. It is notably used by the GNOME Color Manager graphical
7510tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7511site} for more information.
7512@end deffn
7513
cee32ee4 7514@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 7515Return a configuration allowing an application to access GeoClue
cee32ee4
AW
7516location data. @var{name} is the Desktop ID of the application, without
7517the @code{.desktop} part. If @var{allowed?} is true, the application
7518will have access to location information by default. The boolean
1068f26b 7519@var{system?} value indicates whether an application is a system component
cee32ee4
AW
7520or not. Finally @var{users} is a list of UIDs of all users for which
7521this application is allowed location info access. An empty users list
7522means that all users are allowed.
7523@end deffn
7524
7525@defvr {Scheme Variable} %standard-geoclue-applications
7526The standard list of well-known GeoClue application configurations,
1068f26b
AE
7527granting authority to the GNOME date-and-time utility to ask for the
7528current location in order to set the time zone, and allowing the
7529IceCat and Epiphany web browsers to request location information.
7530IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
7531know the user's location.
7532@end defvr
7533
be1c2c54 7534@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7535 [#:whitelist '()] @
7536 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7537 [#:submit-data? #f]
7538 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7539 [#:submission-nick "geoclue"] @
7540 [#:applications %standard-geoclue-applications]
7541Return a service that runs the GeoClue location service. This service
7542provides a D-Bus interface to allow applications to request access to a
7543user's physical location, and optionally to add information to online
7544location databases. See
7545@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7546web site} for more information.
7547@end deffn
7548
105369a4
DT
7549@node Database Services
7550@subsubsection Database Services
7551
7552The @code{(gnu services databases)} module provides the following service.
7553
be1c2c54 7554@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7555 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7556Return a service that runs @var{postgresql}, the PostgreSQL database
7557server.
7558
7559The PostgreSQL daemon loads its runtime configuration from
7560@var{config-file} and stores the database cluster in
7561@var{data-directory}.
7562@end deffn
fe1a39d3 7563
d8c18af8
AW
7564@node Mail Services
7565@subsubsection Mail Services
7566
7567The @code{(gnu services mail)} module provides Guix service definitions
7568for mail services. Currently the only implemented service is Dovecot,
7569an IMAP, POP3, and LMTP server.
7570
7571Guix does not yet have a mail transfer agent (MTA), although for some
7572lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7573is needed to properly integrate a full MTA, such as Postfix. Patches
7574welcome!
7575
7576To add an IMAP/POP3 server to a GuixSD system, add a
7577@code{dovecot-service} to the operating system definition:
7578
7579@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7580Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7581@end deffn
7582
1068f26b 7583By default, Dovecot does not need much configuration; the default
d8c18af8
AW
7584configuration object created by @code{(dovecot-configuration)} will
7585suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7586certificate will be generated for TLS-protected connections, though
7587Dovecot will also listen on cleartext ports by default. There are a
1068f26b 7588number of options, though, which mail administrators might need to change,
d8c18af8
AW
7589and as is the case with other services, Guix allows the system
7590administrator to specify these parameters via a uniform Scheme interface.
7591
7592For example, to specify that mail is located at @code{maildir~/.mail},
7593one would instantiate the Dovecot service like this:
7594
7595@example
7596(dovecot-service #:config
7597 (dovecot-configuration
7598 (mail-location "maildir:~/.mail")))
7599@end example
7600
7601The available configuration parameters follow. Each parameter
7602definition is preceded by its type; for example, @samp{string-list foo}
7603indicates that the @code{foo} parameter should be specified as a list of
7604strings. There is also a way to specify the configuration as a string,
7605if you have an old @code{dovecot.conf} file that you want to port over
7606from some other system; see the end for more details.
7607
7608@c The following documentation was initially generated by
7609@c (generate-documentation) in (gnu services mail). Manually maintained
7610@c documentation is better, so we shouldn't hesitate to edit below as
7611@c needed. However if the change you want to make to this documentation
7612@c can be done in an automated way, it's probably easier to change
7613@c (generate-documentation) than to make it below and have to deal with
7614@c the churn as dovecot updates.
7615
7616Available @code{dovecot-configuration} fields are:
7617
7618@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7619The dovecot package.
7620@end deftypevr
7621
7622@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
7623A list of IPs or hosts where to listen for connections. @samp{*}
7624listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
7625interfaces. If you want to specify non-default ports or anything more
7626complex, customize the address and port fields of the
7627@samp{inet-listener} of the specific services you are interested in.
7628@end deftypevr
7629
7630@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7631List of protocols we want to serve. Available protocols include
7632@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7633
7634Available @code{protocol-configuration} fields are:
7635
7636@deftypevr {@code{protocol-configuration} parameter} string name
7637The name of the protocol.
7638@end deftypevr
7639
7640@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 7641UNIX socket path to the master authentication server to find users.
d8c18af8 7642This is used by imap (for shared users) and lda.
1068f26b 7643It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
7644@end deftypevr
7645
7646@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7647Space separated list of plugins to load.
7648@end deftypevr
7649
7650@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7651Maximum number of IMAP connections allowed for a user from each IP
7652address. NOTE: The username is compared case-sensitively.
7653Defaults to @samp{10}.
7654@end deftypevr
7655
7656@end deftypevr
7657
7658@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7659List of services to enable. Available services include @samp{imap},
7660@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7661@samp{lmtp}.
7662
7663Available @code{service-configuration} fields are:
7664
7665@deftypevr {@code{service-configuration} parameter} string kind
7666The service kind. Valid values include @code{director},
7667@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7668@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7669@code{tcpwrap}, @code{quota-warning}, or anything else.
7670@end deftypevr
7671
7672@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 7673Listeners for the service. A listener is either a
d8c18af8
AW
7674@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7675an @code{inet-listener-configuration}.
7676Defaults to @samp{()}.
7677
7678Available @code{unix-listener-configuration} fields are:
7679
7680@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7681The file name on which to listen.
7682@end deftypevr
7683
7684@deftypevr {@code{unix-listener-configuration} parameter} string mode
7685The access mode for the socket.
7686Defaults to @samp{"0600"}.
7687@end deftypevr
7688
7689@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 7690The user to own the socket.
d8c18af8
AW
7691Defaults to @samp{""}.
7692@end deftypevr
7693
7694@deftypevr {@code{unix-listener-configuration} parameter} string group
7695The group to own the socket.
7696Defaults to @samp{""}.
7697@end deftypevr
7698
7699
7700Available @code{fifo-listener-configuration} fields are:
7701
7702@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7703The file name on which to listen.
7704@end deftypevr
7705
7706@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7707The access mode for the socket.
7708Defaults to @samp{"0600"}.
7709@end deftypevr
7710
7711@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 7712The user to own the socket.
d8c18af8
AW
7713Defaults to @samp{""}.
7714@end deftypevr
7715
7716@deftypevr {@code{fifo-listener-configuration} parameter} string group
7717The group to own the socket.
7718Defaults to @samp{""}.
7719@end deftypevr
7720
7721
7722Available @code{inet-listener-configuration} fields are:
7723
7724@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7725The protocol to listen for.
7726@end deftypevr
7727
7728@deftypevr {@code{inet-listener-configuration} parameter} string address
7729The address on which to listen, or empty for all addresses.
7730Defaults to @samp{""}.
7731@end deftypevr
7732
7733@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7734The port on which to listen.
7735@end deftypevr
7736
7737@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7738Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7739@samp{required}.
7740Defaults to @samp{#t}.
7741@end deftypevr
7742
7743@end deftypevr
7744
7745@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7746Number of connections to handle before starting a new process.
7747Typically the only useful values are 0 (unlimited) or 1. 1 is more
7748secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7749Defaults to @samp{1}.
7750@end deftypevr
7751
7752@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7753Number of processes to always keep waiting for more connections.
7754Defaults to @samp{0}.
7755@end deftypevr
7756
7757@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7758If you set @samp{service-count 0}, you probably need to grow
7759this.
7760Defaults to @samp{256000000}.
7761@end deftypevr
7762
7763@end deftypevr
7764
7765@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7766Dict configuration, as created by the @code{dict-configuration}
7767constructor.
7768
7769Available @code{dict-configuration} fields are:
7770
7771@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7772A list of key-value pairs that this dict should hold.
7773Defaults to @samp{()}.
7774@end deftypevr
7775
7776@end deftypevr
7777
7778@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 7779A list of passdb configurations, each one created by the
d8c18af8
AW
7780@code{passdb-configuration} constructor.
7781
7782Available @code{passdb-configuration} fields are:
7783
7784@deftypevr {@code{passdb-configuration} parameter} string driver
7785The driver that the passdb should use. Valid values include
7786@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7787@samp{static}.
7788Defaults to @samp{"pam"}.
7789@end deftypevr
7790
7791@deftypevr {@code{passdb-configuration} parameter} free-form-args args
7792A list of key-value args to the passdb driver.
7793Defaults to @samp{()}.
7794@end deftypevr
7795
7796@end deftypevr
7797
7798@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7799List of userdb configurations, each one created by the
7800@code{userdb-configuration} constructor.
7801
7802Available @code{userdb-configuration} fields are:
7803
7804@deftypevr {@code{userdb-configuration} parameter} string driver
7805The driver that the userdb should use. Valid values include
7806@samp{passwd} and @samp{static}.
7807Defaults to @samp{"passwd"}.
7808@end deftypevr
7809
7810@deftypevr {@code{userdb-configuration} parameter} free-form-args args
7811A list of key-value args to the userdb driver.
7812Defaults to @samp{()}.
7813@end deftypevr
7814
7815@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7816Override fields from passwd.
7817Defaults to @samp{()}.
7818@end deftypevr
7819
7820@end deftypevr
7821
7822@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7823Plug-in configuration, created by the @code{plugin-configuration}
7824constructor.
7825@end deftypevr
7826
7827@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7828List of namespaces. Each item in the list is created by the
7829@code{namespace-configuration} constructor.
7830
7831Available @code{namespace-configuration} fields are:
7832
7833@deftypevr {@code{namespace-configuration} parameter} string name
7834Name for this namespace.
7835@end deftypevr
7836
7837@deftypevr {@code{namespace-configuration} parameter} string type
7838Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7839Defaults to @samp{"private"}.
7840@end deftypevr
7841
7842@deftypevr {@code{namespace-configuration} parameter} string separator
7843Hierarchy separator to use. You should use the same separator for
7844all namespaces or some clients get confused. @samp{/} is usually a good
7845one. The default however depends on the underlying mail storage
7846format.
7847Defaults to @samp{""}.
7848@end deftypevr
7849
7850@deftypevr {@code{namespace-configuration} parameter} string prefix
7851Prefix required to access this namespace. This needs to be
7852different for all namespaces. For example @samp{Public/}.
7853Defaults to @samp{""}.
7854@end deftypevr
7855
7856@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 7857Physical location of the mailbox. This is in the same format as
d8c18af8
AW
7858mail_location, which is also the default for it.
7859Defaults to @samp{""}.
7860@end deftypevr
7861
7862@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7863There can be only one INBOX, and this setting defines which
7864namespace has it.
7865Defaults to @samp{#f}.
7866@end deftypevr
7867
7868@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7869If namespace is hidden, it's not advertised to clients via NAMESPACE
7870extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7871useful when converting from another server with different namespaces
7872which you want to deprecate but still keep working. For example you can
7873create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7874and @samp{mail/}.
7875Defaults to @samp{#f}.
7876@end deftypevr
7877
7878@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
7879Show the mailboxes under this namespace with the LIST command. This
7880makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
7881extension. The special @code{children} value lists child mailboxes, but
7882hides the namespace prefix.
7883Defaults to @samp{#t}.
7884@end deftypevr
7885
7886@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7887Namespace handles its own subscriptions. If set to @code{#f}, the
7888parent namespace handles them. The empty prefix should always have this
1068f26b 7889as @code{#t}).
d8c18af8
AW
7890Defaults to @samp{#t}.
7891@end deftypevr
7892
7893@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7894List of predefined mailboxes in this namespace.
7895Defaults to @samp{()}.
7896
7897Available @code{mailbox-configuration} fields are:
7898
7899@deftypevr {@code{mailbox-configuration} parameter} string name
7900Name for this mailbox.
7901@end deftypevr
7902
7903@deftypevr {@code{mailbox-configuration} parameter} string auto
7904@samp{create} will automatically create this mailbox.
7905@samp{subscribe} will both create and subscribe to the mailbox.
7906Defaults to @samp{"no"}.
7907@end deftypevr
7908
7909@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7910List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7911Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7912@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7913Defaults to @samp{()}.
7914@end deftypevr
7915
7916@end deftypevr
7917
7918@end deftypevr
7919
7920@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7921Base directory where to store runtime data.
7922Defaults to @samp{"/var/run/dovecot/"}.
7923@end deftypevr
7924
7925@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7926Greeting message for clients.
7927Defaults to @samp{"Dovecot ready."}.
7928@end deftypevr
7929
7930@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7931List of trusted network ranges. Connections from these IPs are
7932allowed to override their IP addresses and ports (for logging and for
7933authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 7934for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
7935here.
7936Defaults to @samp{()}.
7937@end deftypevr
7938
7939@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7940List of login access check sockets (e.g. tcpwrap).
7941Defaults to @samp{()}.
7942@end deftypevr
7943
7944@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7945Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
7946and IP address. Useful for seeing who is actually using the IMAP
7947processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
7948accounts).
7949Defaults to @samp{#f}.
7950@end deftypevr
7951
7952@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
7953Should all processes be killed when Dovecot master process shuts down.
7954Setting this to @code{#f} means that Dovecot can be upgraded without
7955forcing existing client connections to close (although that could also
1068f26b 7956be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
7957Defaults to @samp{#t}.
7958@end deftypevr
7959
7960@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
7961If non-zero, run mail commands via this many connections to doveadm
7962server, instead of running them directly in the same process.
7963Defaults to @samp{0}.
7964@end deftypevr
7965
7966@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
7967UNIX socket or host:port used for connecting to doveadm server.
7968Defaults to @samp{"doveadm-server"}.
7969@end deftypevr
7970
7971@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
7972List of environment variables that are preserved on Dovecot startup
7973and passed down to all of its child processes. You can also give
7974key=value pairs to always set specific settings.
7975@end deftypevr
7976
7977@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
7978Disable LOGIN command and all other plaintext authentications unless
7979SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
7980matches the local IP (i.e. you're connecting from the same computer),
7981the connection is considered secure and plaintext authentication is
7982allowed. See also ssl=required setting.
7983Defaults to @samp{#t}.
7984@end deftypevr
7985
7986@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
7987Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
7988Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
7989for caching to be used.
7990Defaults to @samp{0}.
7991@end deftypevr
7992
7993@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
7994Time to live for cached data. After TTL expires the cached record
7995is no longer used, *except* if the main database lookup returns internal
7996failure. We also try to handle password changes automatically: If
7997user's previous authentication was successful, but this one wasn't, the
7998cache isn't used. For now this works only with plaintext
7999authentication.
8000Defaults to @samp{"1 hour"}.
8001@end deftypevr
8002
8003@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
8004TTL for negative hits (user not found, password mismatch).
80050 disables caching them completely.
8006Defaults to @samp{"1 hour"}.
8007@end deftypevr
8008
8009@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
8010List of realms for SASL authentication mechanisms that need them.
8011You can leave it empty if you don't want to support multiple realms.
8012Many clients simply use the first one listed here, so keep the default
8013realm first.
8014Defaults to @samp{()}.
8015@end deftypevr
8016
8017@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
8018Default realm/domain to use if none was specified. This is used for
8019both SASL realms and appending @@domain to username in plaintext
8020logins.
8021Defaults to @samp{""}.
8022@end deftypevr
8023
8024@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
8025List of allowed characters in username. If the user-given username
8026contains a character not listed in here, the login automatically fails.
8027This is just an extra check to make sure user can't exploit any
8028potential quote escaping vulnerabilities with SQL/LDAP databases. If
8029you want to allow all characters, set this value to empty.
8030Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8031@end deftypevr
8032
8033@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8034Username character translations before it's looked up from
8035databases. The value contains series of from -> to characters. For
8036example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8037translated to @samp{@@}.
8038Defaults to @samp{""}.
8039@end deftypevr
8040
8041@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8042Username formatting before it's looked up from databases. You can
8043use the standard variables here, e.g. %Lu would lowercase the username,
8044%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8045change the @samp{@@} into @samp{-AT-}. This translation is done after
8046@samp{auth-username-translation} changes.
8047Defaults to @samp{"%Lu"}.
8048@end deftypevr
8049
8050@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8051If you want to allow master users to log in by specifying the master
8052username within the normal username string (i.e. not using SASL
8053mechanism's support for it), you can specify the separator character
8054here. The format is then <username><separator><master username>.
8055UW-IMAP uses @samp{*} as the separator, so that could be a good
8056choice.
8057Defaults to @samp{""}.
8058@end deftypevr
8059
8060@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8061Username to use for users logging in with ANONYMOUS SASL
8062mechanism.
8063Defaults to @samp{"anonymous"}.
8064@end deftypevr
8065
8066@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8067Maximum number of dovecot-auth worker processes. They're used to
8068execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8069They're automatically created and destroyed as needed.
8070Defaults to @samp{30}.
8071@end deftypevr
8072
8073@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8074Host name to use in GSSAPI principal names. The default is to use
8075the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8076allow all keytab entries.
8077Defaults to @samp{""}.
8078@end deftypevr
8079
8080@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8081Kerberos keytab to use for the GSSAPI mechanism. Will use the
8082system default (usually /etc/krb5.keytab) if not specified. You may
8083need to change the auth service to run as root to be able to read this
8084file.
8085Defaults to @samp{""}.
8086@end deftypevr
8087
8088@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8089Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8090and @samp{ntlm-auth} helper.
8091<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8092Defaults to @samp{#f}.
8093@end deftypevr
8094
8095@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8096Path for Samba's @samp{ntlm-auth} helper binary.
8097Defaults to @samp{"/usr/bin/ntlm_auth"}.
8098@end deftypevr
8099
8100@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8101Time to delay before replying to failed authentications.
8102Defaults to @samp{"2 secs"}.
8103@end deftypevr
8104
8105@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8106Require a valid SSL client certificate or the authentication
8107fails.
8108Defaults to @samp{#f}.
8109@end deftypevr
8110
8111@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8112Take the username from client's SSL certificate, using
8113@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8114CommonName.
8115Defaults to @samp{#f}.
8116@end deftypevr
8117
8118@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8119List of wanted authentication mechanisms. Supported mechanisms are:
8120@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8121@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8122@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8123@samp{disable-plaintext-auth} setting.
8124@end deftypevr
8125
8126@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8127List of IPs or hostnames to all director servers, including ourself.
8128Ports can be specified as ip:port. The default port is the same as what
8129director service's @samp{inet-listener} is using.
8130Defaults to @samp{()}.
8131@end deftypevr
8132
8133@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8134List of IPs or hostnames to all backend mail servers. Ranges are
8135allowed too, like 10.0.0.10-10.0.0.30.
8136Defaults to @samp{()}.
8137@end deftypevr
8138
8139@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8140How long to redirect users to a specific server after it no longer
8141has any connections.
8142Defaults to @samp{"15 min"}.
8143@end deftypevr
8144
8145@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8146TCP/IP port that accepts doveadm connections (instead of director
8147connections) If you enable this, you'll also need to add
8148@samp{inet-listener} for the port.
8149Defaults to @samp{0}.
8150@end deftypevr
8151
8152@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8153How the username is translated before being hashed. Useful values
8154include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8155are shared within domain.
8156Defaults to @samp{"%Lu"}.
8157@end deftypevr
8158
8159@deftypevr {@code{dovecot-configuration} parameter} string log-path
8160Log file to use for error messages. @samp{syslog} logs to syslog,
8161@samp{/dev/stderr} logs to stderr.
8162Defaults to @samp{"syslog"}.
8163@end deftypevr
8164
8165@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8166Log file to use for informational messages. Defaults to
8167@samp{log-path}.
8168Defaults to @samp{""}.
8169@end deftypevr
8170
8171@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8172Log file to use for debug messages. Defaults to
8173@samp{info-log-path}.
8174Defaults to @samp{""}.
8175@end deftypevr
8176
8177@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8178Syslog facility to use if you're logging to syslog. Usually if you
8179don't want to use @samp{mail}, you'll use local0..local7. Also other
8180standard facilities are supported.
8181Defaults to @samp{"mail"}.
8182@end deftypevr
8183
8184@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8185Log unsuccessful authentication attempts and the reasons why they
8186failed.
8187Defaults to @samp{#f}.
8188@end deftypevr
8189
8190@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8191In case of password mismatches, log the attempted password. Valid
8192values are no, plain and sha1. sha1 can be useful for detecting brute
8193force password attempts vs. user simply trying the same password over
8194and over again. You can also truncate the value to n chars by appending
8195":n" (e.g. sha1:6).
8196Defaults to @samp{#f}.
8197@end deftypevr
8198
8199@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8200Even more verbose logging for debugging purposes. Shows for example
8201SQL queries.
8202Defaults to @samp{#f}.
8203@end deftypevr
8204
8205@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
8206In case of password mismatches, log the passwords and used scheme so
8207the problem can be debugged. Enabling this also enables
8208@samp{auth-debug}.
8209Defaults to @samp{#f}.
8210@end deftypevr
8211
8212@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
8213Enable mail process debugging. This can help you figure out why
8214Dovecot isn't finding your mails.
8215Defaults to @samp{#f}.
8216@end deftypevr
8217
8218@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
8219Show protocol level SSL errors.
8220Defaults to @samp{#f}.
8221@end deftypevr
8222
8223@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
8224Prefix for each line written to log file. % codes are in
8225strftime(3) format.
8226Defaults to @samp{"\"%b %d %H:%M:%S \""}.
8227@end deftypevr
8228
8229@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
8230List of elements we want to log. The elements which have a
8231non-empty variable value are joined together to form a comma-separated
8232string.
8233@end deftypevr
8234
8235@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
8236Login log format. %s contains @samp{login-log-format-elements}
8237string, %$ contains the data we want to log.
8238Defaults to @samp{"%$: %s"}.
8239@end deftypevr
8240
8241@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
8242Log prefix for mail processes. See doc/wiki/Variables.txt for list
8243of possible variables you can use.
8244Defaults to @samp{"\"%s(%u): \""}.
8245@end deftypevr
8246
8247@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
8248Format to use for logging mail deliveries. You can use variables:
8249@table @code
8250@item %$
8251Delivery status message (e.g. @samp{saved to INBOX})
8252@item %m
8253Message-ID
8254@item %s
8255Subject
8256@item %f
8257From address
8258@item %p
8259Physical size
8260@item %w
8261Virtual size.
8262@end table
8263Defaults to @samp{"msgid=%m: %$"}.
8264@end deftypevr
8265
8266@deftypevr {@code{dovecot-configuration} parameter} string mail-location
8267Location for users' mailboxes. The default is empty, which means
8268that Dovecot tries to find the mailboxes automatically. This won't work
8269if the user doesn't yet have any mail, so you should explicitly tell
8270Dovecot the full location.
8271
8272If you're using mbox, giving a path to the INBOX
8273file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
8274where the other mailboxes are kept. This is called the "root mail
8275directory", and it must be the first path given in the
8276@samp{mail-location} setting.
8277
8278There are a few special variables you can use, eg.:
8279
8280@table @samp
8281@item %u
8282username
8283@item %n
8284user part in user@@domain, same as %u if there's no domain
8285@item %d
8286domain part in user@@domain, empty if there's no domain
8287@item %h
8288home director
8289@end table
8290
8291See doc/wiki/Variables.txt for full list. Some examples:
8292@table @samp
8293@item maildir:~/Maildir
8294@item mbox:~/mail:INBOX=/var/mail/%u
8295@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
8296@end table
8297Defaults to @samp{""}.
8298@end deftypevr
8299
8300@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8301System user and group used to access mails. If you use multiple,
8302userdb can override these by returning uid or gid fields. You can use
8303either numbers or names. <doc/wiki/UserIds.txt>.
8304Defaults to @samp{""}.
8305@end deftypevr
8306
8307@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8308
8309Defaults to @samp{""}.
8310@end deftypevr
8311
8312@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8313Group to enable temporarily for privileged operations. Currently
8314this is used only with INBOX when either its initial creation or
8315dotlocking fails. Typically this is set to "mail" to give access to
8316/var/mail.
8317Defaults to @samp{""}.
8318@end deftypevr
8319
8320@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8321Grant access to these supplementary groups for mail processes.
8322Typically these are used to set up access to shared mailboxes. Note
8323that it may be dangerous to set these if users can create
8324symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8325could allow a user to delete others' mailboxes, or ln -s
8326/secret/shared/box ~/mail/mybox would allow reading it).
8327Defaults to @samp{""}.
8328@end deftypevr
8329
8330@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8331Allow full filesystem access to clients. There's no access checks
8332other than what the operating system does for the active UID/GID. It
8333works with both maildir and mboxes, allowing you to prefix mailboxes
8334names with e.g. /path/ or ~user/.
8335Defaults to @samp{#f}.
8336@end deftypevr
8337
8338@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8339Don't use mmap() at all. This is required if you store indexes to
8340shared filesystems (NFS or clustered filesystem).
8341Defaults to @samp{#f}.
8342@end deftypevr
8343
8344@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8345Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8346supports @samp{O_EXCL} since version 3, so this should be safe to use
8347nowadays by default.
8348Defaults to @samp{#t}.
8349@end deftypevr
8350
8351@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8352When to use fsync() or fdatasync() calls:
8353@table @code
8354@item optimized
8355Whenever necessary to avoid losing important data
8356@item always
8357Useful with e.g. NFS when write()s are delayed
8358@item never
8359Never use it (best performance, but crashes can lose data).
8360@end table
8361Defaults to @samp{"optimized"}.
8362@end deftypevr
8363
8364@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8365Mail storage exists in NFS. Set this to yes to make Dovecot flush
8366NFS caches whenever needed. If you're using only a single mail server
8367this isn't needed.
8368Defaults to @samp{#f}.
8369@end deftypevr
8370
8371@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8372Mail index files also exist in NFS. Setting this to yes requires
8373@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8374Defaults to @samp{#f}.
8375@end deftypevr
8376
8377@deftypevr {@code{dovecot-configuration} parameter} string lock-method
8378Locking method for index files. Alternatives are fcntl, flock and
8379dotlock. Dotlocking uses some tricks which may create more disk I/O
8380than other locking methods. NFS users: flock doesn't work, remember to
8381change @samp{mmap-disable}.
8382Defaults to @samp{"fcntl"}.
8383@end deftypevr
8384
8385@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8386Directory in which LDA/LMTP temporarily stores incoming mails >128
8387kB.
8388Defaults to @samp{"/tmp"}.
8389@end deftypevr
8390
8391@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8392Valid UID range for users. This is mostly to make sure that users can't
8393log in as daemons or other system users. Note that denying root logins is
8394hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8395is set to 0.
8396Defaults to @samp{500}.
8397@end deftypevr
8398
8399@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8400
8401Defaults to @samp{0}.
8402@end deftypevr
8403
8404@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8405Valid GID range for users. Users having non-valid GID as primary group ID
8406aren't allowed to log in. If user belongs to supplementary groups with
8407non-valid GIDs, those groups are not set.
8408Defaults to @samp{1}.
8409@end deftypevr
8410
8411@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8412
8413Defaults to @samp{0}.
8414@end deftypevr
8415
8416@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8417Maximum allowed length for mail keyword name. It's only forced when
8418trying to create new keywords.
8419Defaults to @samp{50}.
8420@end deftypevr
8421
8422@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8423List of directories under which chrooting is allowed for mail
8424processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8425too). This setting doesn't affect @samp{login-chroot}
8426@samp{mail-chroot} or auth chroot settings. If this setting is empty,
8427"/./" in home dirs are ignored. WARNING: Never add directories here
8428which local users can modify, that may lead to root exploit. Usually
8429this should be done only if you don't allow shell access for users.
8430<doc/wiki/Chrooting.txt>.
8431Defaults to @samp{()}.
8432@end deftypevr
8433
8434@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8435Default chroot directory for mail processes. This can be overridden
8436for specific users in user database by giving /./ in user's home
8437directory (e.g. /home/./user chroots into /home). Note that usually
8438there is no real need to do chrooting, Dovecot doesn't allow users to
8439access files outside their mail directory anyway. If your home
8440directories are prefixed with the chroot directory, append "/." to
8441@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8442Defaults to @samp{""}.
8443@end deftypevr
8444
8445@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8446UNIX socket path to master authentication server to find users.
8447This is used by imap (for shared users) and lda.
8448Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8449@end deftypevr
8450
8451@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8452Directory where to look up mail plugins.
8453Defaults to @samp{"/usr/lib/dovecot"}.
8454@end deftypevr
8455
8456@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8457List of plugins to load for all services. Plugins specific to IMAP,
8458LDA, etc. are added to this list in their own .conf files.
8459Defaults to @samp{()}.
8460@end deftypevr
8461
8462@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8463The minimum number of mails in a mailbox before updates are done to
8464cache file. This allows optimizing Dovecot's behavior to do less disk
8465writes at the cost of more disk reads.
8466Defaults to @samp{0}.
8467@end deftypevr
8468
8469@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8470When IDLE command is running, mailbox is checked once in a while to
8471see if there are any new mails or other changes. This setting defines
8472the minimum time to wait between those checks. Dovecot can also use
8473dnotify, inotify and kqueue to find out immediately when changes
8474occur.
8475Defaults to @samp{"30 secs"}.
8476@end deftypevr
8477
8478@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8479Save mails with CR+LF instead of plain LF. This makes sending those
8480mails take less CPU, especially with sendfile() syscall with Linux and
8481FreeBSD. But it also creates a bit more disk I/O which may just make it
8482slower. Also note that if other software reads the mboxes/maildirs,
8483they may handle the extra CRs wrong and cause problems.
8484Defaults to @samp{#f}.
8485@end deftypevr
8486
8487@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8488By default LIST command returns all entries in maildir beginning
8489with a dot. Enabling this option makes Dovecot return only entries
8490which are directories. This is done by stat()ing each entry, so it
8491causes more disk I/O.
8492 (For systems setting struct @samp{dirent->d_type} this check is free
8493and it's done always regardless of this setting).
8494Defaults to @samp{#f}.
8495@end deftypevr
8496
8497@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8498When copying a message, do it with hard links whenever possible.
8499This makes the performance much better, and it's unlikely to have any
8500side effects.
8501Defaults to @samp{#t}.
8502@end deftypevr
8503
8504@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8505Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8506directory only when its mtime changes unexpectedly or when we can't find
8507the mail otherwise.
8508Defaults to @samp{#f}.
8509@end deftypevr
8510
8511@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8512Which locking methods to use for locking mbox. There are four
8513available:
8514
8515@table @code
8516@item dotlock
8517Create <mailbox>.lock file. This is the oldest and most NFS-safe
8518solution. If you want to use /var/mail/ like directory, the users will
8519need write access to that directory.
8520@item dotlock-try
8521Same as dotlock, but if it fails because of permissions or because there
8522isn't enough disk space, just skip it.
8523@item fcntl
8524Use this if possible. Works with NFS too if lockd is used.
8525@item flock
8526May not exist in all systems. Doesn't work with NFS.
8527@item lockf
8528May not exist in all systems. Doesn't work with NFS.
8529@end table
8530
8531You can use multiple locking methods; if you do the order they're declared
8532in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8533locking methods as well. Some operating systems don't allow using some of
8534them simultaneously.
8535@end deftypevr
8536
8537@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8538
8539@end deftypevr
8540
8541@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8542Maximum time to wait for lock (all of them) before aborting.
8543Defaults to @samp{"5 mins"}.
8544@end deftypevr
8545
8546@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8547If dotlock exists but the mailbox isn't modified in any way,
8548override the lock file after this much time.
8549Defaults to @samp{"2 mins"}.
8550@end deftypevr
8551
8552@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8553When mbox changes unexpectedly we have to fully read it to find out
8554what changed. If the mbox is large this can take a long time. Since
8555the change is usually just a newly appended mail, it'd be faster to
8556simply read the new mails. If this setting is enabled, Dovecot does
8557this but still safely fallbacks to re-reading the whole mbox file
8558whenever something in mbox isn't how it's expected to be. The only real
8559downside to this setting is that if some other MUA changes message
8560flags, Dovecot doesn't notice it immediately. Note that a full sync is
8561done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8562Defaults to @samp{#t}.
8563@end deftypevr
8564
8565@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8566Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8567EXAMINE, EXPUNGE or CHECK commands. If this is set,
8568@samp{mbox-dirty-syncs} is ignored.
8569Defaults to @samp{#f}.
8570@end deftypevr
8571
8572@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8573Delay writing mbox headers until doing a full write sync (EXPUNGE
8574and CHECK commands and when closing the mailbox). This is especially
8575useful for POP3 where clients often delete all mails. The downside is
8576that our changes aren't immediately visible to other MUAs.
8577Defaults to @samp{#t}.
8578@end deftypevr
8579
8580@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8581If mbox size is smaller than this (e.g. 100k), don't write index
8582files. If an index file already exists it's still read, just not
8583updated.
8584Defaults to @samp{0}.
8585@end deftypevr
8586
8587@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8588Maximum dbox file size until it's rotated.
8589Defaults to @samp{2000000}.
8590@end deftypevr
8591
8592@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8593Maximum dbox file age until it's rotated. Typically in days. Day
8594begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8595disabled.
8596Defaults to @samp{"1d"}.
8597@end deftypevr
8598
8599@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8600When creating new mdbox files, immediately preallocate their size to
8601@samp{mdbox-rotate-size}. This setting currently works only in Linux
8602with some filesystems (ext4, xfs).
8603Defaults to @samp{#f}.
8604@end deftypevr
8605
8606@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8607sdbox and mdbox support saving mail attachments to external files,
8608which also allows single instance storage for them. Other backends
8609don't support this for now.
8610
8611WARNING: This feature hasn't been tested much yet. Use at your own risk.
8612
8613Directory root where to store mail attachments. Disabled, if empty.
8614Defaults to @samp{""}.
8615@end deftypevr
8616
8617@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8618Attachments smaller than this aren't saved externally. It's also
8619possible to write a plugin to disable saving specific attachments
8620externally.
8621Defaults to @samp{128000}.
8622@end deftypevr
8623
8624@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8625Filesystem backend to use for saving attachments:
8626@table @code
8627@item posix
8628No SiS done by Dovecot (but this might help FS's own deduplication)
8629@item sis posix
8630SiS with immediate byte-by-byte comparison during saving
8631@item sis-queue posix
8632SiS with delayed comparison and deduplication.
8633@end table
8634Defaults to @samp{"sis posix"}.
8635@end deftypevr
8636
8637@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8638Hash format to use in attachment filenames. You can add any text and
8639variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8640@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8641truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8642Defaults to @samp{"%@{sha1@}"}.
8643@end deftypevr
8644
8645@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8646
8647Defaults to @samp{100}.
8648@end deftypevr
8649
8650@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8651
8652Defaults to @samp{1000}.
8653@end deftypevr
8654
8655@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8656Default VSZ (virtual memory size) limit for service processes.
8657This is mainly intended to catch and kill processes that leak memory
8658before they eat up everything.
8659Defaults to @samp{256000000}.
8660@end deftypevr
8661
8662@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8663Login user is internally used by login processes. This is the most
8664untrusted user in Dovecot system. It shouldn't have access to anything
8665at all.
8666Defaults to @samp{"dovenull"}.
8667@end deftypevr
8668
8669@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8670Internal user is used by unprivileged processes. It should be
8671separate from login user, so that login processes can't disturb other
8672processes.
8673Defaults to @samp{"dovecot"}.
8674@end deftypevr
8675
8676@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8677SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8678Defaults to @samp{"required"}.
8679@end deftypevr
8680
8681@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8682PEM encoded X.509 SSL/TLS certificate (public key).
8683Defaults to @samp{"</etc/dovecot/default.pem"}.
8684@end deftypevr
8685
8686@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8687PEM encoded SSL/TLS private key. The key is opened before
8688dropping root privileges, so keep the key file unreadable by anyone but
8689root.
8690Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8691@end deftypevr
8692
8693@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8694If key file is password protected, give the password here.
8695Alternatively give it when starting dovecot with -p parameter. Since
8696this file is often world-readable, you may want to place this setting
8697instead to a different.
8698Defaults to @samp{""}.
8699@end deftypevr
8700
8701@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8702PEM encoded trusted certificate authority. Set this only if you
8703intend to use @samp{ssl-verify-client-cert? #t}. The file should
8704contain the CA certificate(s) followed by the matching
8705CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8706Defaults to @samp{""}.
8707@end deftypevr
8708
8709@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8710Require that CRL check succeeds for client certificates.
8711Defaults to @samp{#t}.
8712@end deftypevr
8713
8714@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8715Request client to send a certificate. If you also want to require
8716it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8717Defaults to @samp{#f}.
8718@end deftypevr
8719
8720@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8721Which field from certificate to use for username. commonName and
8722x500UniqueIdentifier are the usual choices. You'll also need to set
8723@samp{auth-ssl-username-from-cert? #t}.
8724Defaults to @samp{"commonName"}.
8725@end deftypevr
8726
8727@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8728How often to regenerate the SSL parameters file. Generation is
8729quite CPU intensive operation. The value is in hours, 0 disables
8730regeneration entirely.
8731Defaults to @samp{168}.
8732@end deftypevr
8733
8734@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8735SSL protocols to use.
8736Defaults to @samp{"!SSLv2"}.
8737@end deftypevr
8738
8739@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8740SSL ciphers to use.
8741Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8742@end deftypevr
8743
8744@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8745SSL crypto device to use, for valid values run "openssl engine".
8746Defaults to @samp{""}.
8747@end deftypevr
8748
8749@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8750Address to use when sending rejection mails.
8751Default is postmaster@@<your domain>. %d expands to recipient domain.
8752Defaults to @samp{""}.
8753@end deftypevr
8754
8755@deftypevr {@code{dovecot-configuration} parameter} string hostname
8756Hostname to use in various parts of sent mails (e.g. in Message-Id)
8757and in LMTP replies. Default is the system's real hostname@@domain.
8758Defaults to @samp{""}.
8759@end deftypevr
8760
8761@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8762If user is over quota, return with temporary failure instead of
8763bouncing the mail.
8764Defaults to @samp{#f}.
8765@end deftypevr
8766
8767@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8768Binary to use for sending mails.
8769Defaults to @samp{"/usr/sbin/sendmail"}.
8770@end deftypevr
8771
8772@deftypevr {@code{dovecot-configuration} parameter} string submission-host
8773If non-empty, send mails via this SMTP host[:port] instead of
8774sendmail.
8775Defaults to @samp{""}.
8776@end deftypevr
8777
8778@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8779Subject: header to use for rejection mails. You can use the same
8780variables as for @samp{rejection-reason} below.
8781Defaults to @samp{"Rejected: %s"}.
8782@end deftypevr
8783
8784@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8785Human readable error message for rejection mails. You can use
8786variables:
8787
8788@table @code
8789@item %n
8790CRLF
8791@item %r
8792reason
8793@item %s
8794original subject
8795@item %t
8796recipient
8797@end table
8798Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8799@end deftypevr
8800
8801@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8802Delimiter character between local-part and detail in email
8803address.
8804Defaults to @samp{"+"}.
8805@end deftypevr
8806
8807@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8808Header where the original recipient address (SMTP's RCPT TO:
8809address) is taken from if not available elsewhere. With dovecot-lda -a
8810parameter overrides this. A commonly used header for this is
8811X-Original-To.
8812Defaults to @samp{""}.
8813@end deftypevr
8814
8815@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8816Should saving a mail to a nonexistent mailbox automatically create
8817it?.
8818Defaults to @samp{#f}.
8819@end deftypevr
8820
8821@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8822Should automatically created mailboxes be also automatically
8823subscribed?.
8824Defaults to @samp{#f}.
8825@end deftypevr
8826
8827@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8828Maximum IMAP command line length. Some clients generate very long
8829command lines with huge mailboxes, so you may need to raise this if you
8830get "Too long argument" or "IMAP command line too large" errors
8831often.
8832Defaults to @samp{64000}.
8833@end deftypevr
8834
8835@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8836IMAP logout format string:
8837@table @code
8838@item %i
8839total number of bytes read from client
8840@item %o
8841total number of bytes sent to client.
8842@end table
8843Defaults to @samp{"in=%i out=%o"}.
8844@end deftypevr
8845
8846@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8847Override the IMAP CAPABILITY response. If the value begins with '+',
8848add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8849Defaults to @samp{""}.
8850@end deftypevr
8851
8852@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8853How long to wait between "OK Still here" notifications when client
8854is IDLEing.
8855Defaults to @samp{"2 mins"}.
8856@end deftypevr
8857
8858@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8859ID field names and values to send to clients. Using * as the value
8860makes Dovecot use the default value. The following fields have default
8861values currently: name, version, os, os-version, support-url,
8862support-email.
8863Defaults to @samp{""}.
8864@end deftypevr
8865
8866@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8867ID fields sent by client to log. * means everything.
8868Defaults to @samp{""}.
8869@end deftypevr
8870
8871@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8872Workarounds for various client bugs:
8873
8874@table @code
8875@item delay-newmail
8876Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8877CHECK commands. Some clients ignore them otherwise, for example OSX
8878Mail (<v2.1). Outlook Express breaks more badly though, without this it
8879may show user "Message no longer in server" errors. Note that OE6
8880still breaks even with this workaround if synchronization is set to
8881"Headers Only".
8882
8883@item tb-extra-mailbox-sep
8884Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8885adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8886ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8887
8888@item tb-lsub-flags
8889Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8890This makes Thunderbird realize they aren't selectable and show them
8891greyed out, instead of only later giving "not selectable" popup error.
8892@end table
8893Defaults to @samp{()}.
8894@end deftypevr
8895
8896@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8897Host allowed in URLAUTH URLs sent by client. "*" allows all.
8898Defaults to @samp{""}.
8899@end deftypevr
8900
8901
8902Whew! Lots of configuration options. The nice thing about it though is
8903that GuixSD has a complete interface to Dovecot's configuration
8904language. This allows not only a nice way to declare configurations,
8905but also offers reflective capabilities as well: users can write code to
8906inspect and transform configurations from within Scheme.
8907
8908However, it could be that you just want to get a @code{dovecot.conf} up
8909and running. In that case, you can pass an
8910@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8911@code{dovecot-service}. As its name indicates, an opaque configuration
8912does not have easy reflective capabilities.
8913
8914Available @code{opaque-dovecot-configuration} fields are:
8915
8916@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8917The dovecot package.
8918@end deftypevr
8919
8920@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8921The contents of the @code{dovecot.conf}, as a string.
8922@end deftypevr
8923
8924For example, if your @code{dovecot.conf} is just the empty string, you
8925could instantiate a dovecot service like this:
8926
8927@example
8928(dovecot-service #:config
8929 (opaque-dovecot-configuration
8930 (string "")))
8931@end example
8932
58724c48
DT
8933@node Web Services
8934@subsubsection Web Services
8935
8936The @code{(gnu services web)} module provides the following service:
8937
be1c2c54 8938@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
8939 [#:log-directory ``/var/log/nginx''] @
8940 [#:run-directory ``/var/run/nginx''] @
8941 [#:config-file]
8942
8943Return a service that runs @var{nginx}, the nginx web server.
8944
8945The nginx daemon loads its runtime configuration from @var{config-file}.
8946Log files are written to @var{log-directory} and temporary runtime data
8947files are written to @var{run-directory}. For proper operation, these
8948arguments should match what is in @var{config-file} to ensure that the
8949directories are created when the service is activated.
8950
8951@end deffn
8952
fe1a39d3
LC
8953@node Various Services
8954@subsubsection Various Services
8955
8956The @code{(gnu services lirc)} module provides the following service.
8957
be1c2c54 8958@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
8959 [#:device #f] [#:driver #f] [#:config-file #f] @
8960 [#:extra-options '()]
8961Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
8962decodes infrared signals from remote controls.
8963
8964Optionally, @var{device}, @var{driver} and @var{config-file}
8965(configuration file name) may be specified. See @command{lircd} manual
8966for details.
8967
8968Finally, @var{extra-options} is a list of additional command-line options
8969passed to @command{lircd}.
8970@end deffn
8971
8972
0ae8c15a
LC
8973@node Setuid Programs
8974@subsection Setuid Programs
8975
8976@cindex setuid programs
8977Some programs need to run with ``root'' privileges, even when they are
8978launched by unprivileged users. A notorious example is the
4d40227c
LC
8979@command{passwd} program, which users can run to change their
8980password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
8981@file{/etc/shadow} files---something normally restricted to root, for
8982obvious security reasons. To address that, these executables are
8983@dfn{setuid-root}, meaning that they always run with root privileges
8984(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 8985for more info about the setuid mechanism.)
0ae8c15a
LC
8986
8987The store itself @emph{cannot} contain setuid programs: that would be a
8988security issue since any user on the system can write derivations that
8989populate the store (@pxref{The Store}). Thus, a different mechanism is
8990used: instead of changing the setuid bit directly on files that are in
8991the store, we let the system administrator @emph{declare} which programs
8992should be setuid root.
8993
8994The @code{setuid-programs} field of an @code{operating-system}
8995declaration contains a list of G-expressions denoting the names of
8996programs to be setuid-root (@pxref{Using the Configuration System}).
8997For instance, the @command{passwd} program, which is part of the Shadow
8998package, can be designated by this G-expression (@pxref{G-Expressions}):
8999
9000@example
9001#~(string-append #$shadow "/bin/passwd")
9002@end example
9003
9004A default set of setuid programs is defined by the
9005@code{%setuid-programs} variable of the @code{(gnu system)} module.
9006
9007@defvr {Scheme Variable} %setuid-programs
9008A list of G-expressions denoting common programs that are setuid-root.
9009
9010The list includes commands such as @command{passwd}, @command{ping},
9011@command{su}, and @command{sudo}.
9012@end defvr
9013
9014Under the hood, the actual setuid programs are created in the
9015@file{/run/setuid-programs} directory at system activation time. The
9016files in this directory refer to the ``real'' binaries, which are in the
9017store.
9018
efb5e833
LC
9019@node X.509 Certificates
9020@subsection X.509 Certificates
9021
9022@cindex HTTPS, certificates
9023@cindex X.509 certificates
9024@cindex TLS
9025Web servers available over HTTPS (that is, HTTP over the transport-layer
9026security mechanism, TLS) send client programs an @dfn{X.509 certificate}
9027that the client can then use to @emph{authenticate} the server. To do
9028that, clients verify that the server's certificate is signed by a
9029so-called @dfn{certificate authority} (CA). But to verify the CA's
9030signature, clients must have first acquired the CA's certificate.
9031
9032Web browsers such as GNU@tie{}IceCat include their own set of CA
9033certificates, such that they are able to verify CA signatures
9034out-of-the-box.
9035
9036However, most other programs that can talk HTTPS---@command{wget},
9037@command{git}, @command{w3m}, etc.---need to be told where CA
9038certificates can be found.
9039
9040@cindex @code{nss-certs}
9041In GuixSD, this is done by adding a package that provides certificates
9042to the @code{packages} field of the @code{operating-system} declaration
9043(@pxref{operating-system Reference}). GuixSD includes one such package,
9044@code{nss-certs}, which is a set of CA certificates provided as part of
9045Mozilla's Network Security Services.
9046
9047Note that it is @emph{not} part of @var{%base-packages}, so you need to
9048explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9049most applications and libraries look for certificates by default, points
9050to the certificates installed globally.
9051
9052Unprivileged users can also install their own certificate package in
9053their profile. A number of environment variables need to be defined so
9054that applications and libraries know where to find them. Namely, the
9055OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9056variables. Some applications add their own environment variables; for
9057instance, the Git version control system honors the certificate bundle
9058pointed to by the @code{GIT_SSL_CAINFO} environment variable.
9059
9060
996ed739
LC
9061@node Name Service Switch
9062@subsection Name Service Switch
9063
9064@cindex name service switch
9065@cindex NSS
9066The @code{(gnu system nss)} module provides bindings to the
1068f26b 9067configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
9068(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9069Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9070extended with new ``name'' lookup methods for system databases, which
9071includes host names, service names, user accounts, and more (@pxref{Name
9072Service Switch, System Databases and Name Service Switch,, libc, The GNU
9073C Library Reference Manual}).
9074
9075The NSS configuration specifies, for each system database, which lookup
9076method is to be used, and how the various methods are chained
9077together---for instance, under which circumstances NSS should try the
9078next method in the list. The NSS configuration is given in the
9079@code{name-service-switch} field of @code{operating-system} declarations
9080(@pxref{operating-system Reference, @code{name-service-switch}}).
9081
4c9050c6
LC
9082@cindex nss-mdns
9083@cindex .local, host name lookup
996ed739 9084As an example, the declaration below configures the NSS to use the
4c9050c6
LC
9085@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9086back-end}, which supports host name lookups over multicast DNS (mDNS)
9087for host names ending in @code{.local}:
996ed739
LC
9088
9089@example
9090(name-service-switch
9091 (hosts (list %files ;first, check /etc/hosts
9092
9093 ;; If the above did not succeed, try
9094 ;; with 'mdns_minimal'.
9095 (name-service
9096 (name "mdns_minimal")
9097
9098 ;; 'mdns_minimal' is authoritative for
9099 ;; '.local'. When it returns "not found",
9100 ;; no need to try the next methods.
9101 (reaction (lookup-specification
9102 (not-found => return))))
9103
9104 ;; Then fall back to DNS.
9105 (name-service
9106 (name "dns"))
9107
9108 ;; Finally, try with the "full" 'mdns'.
9109 (name-service
9110 (name "mdns")))))
9111@end example
9112
1068f26b
AE
9113Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
9114contains this configuration, so you will not have to type it if all you
15137a29
LC
9115want is to have @code{.local} host lookup working.
9116
4c9050c6
LC
9117Note that, in this case, in addition to setting the
9118@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
9119you also need to use @code{avahi-service} (@pxref{Networking Services,
9120@code{avahi-service}}), or @var{%desktop-services}, which includes it
9121(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9122to the name service cache daemon (@pxref{Base Services,
9123@code{nscd-service}}).
15137a29
LC
9124
9125For convenience, the following variables provide typical NSS
9126configurations.
9127
9128@defvr {Scheme Variable} %default-nss
9129This is the default name service switch configuration, a
9130@code{name-service-switch} object.
9131@end defvr
9132
9133@defvr {Scheme Variable} %mdns-host-lookup-nss
9134This is the name service switch configuration with support for host name
9135lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9136@end defvr
4c9050c6 9137
996ed739 9138The reference for name service switch configuration is given below. It
1068f26b 9139is a direct mapping of the configuration file format of the C library , so
996ed739
LC
9140please refer to the C library manual for more information (@pxref{NSS
9141Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 9142Compared to the configuration file format of libc NSS, it has the advantage
996ed739 9143not only of adding this warm parenthetic feel that we like, but also
1068f26b 9144static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
9145run @command{guix system}.
9146
996ed739
LC
9147@deftp {Data Type} name-service-switch
9148
9149This is the data type representation the configuration of libc's name
9150service switch (NSS). Each field below represents one of the supported
9151system databases.
9152
9153@table @code
9154@item aliases
9155@itemx ethers
9156@itemx group
9157@itemx gshadow
9158@itemx hosts
9159@itemx initgroups
9160@itemx netgroup
9161@itemx networks
9162@itemx password
9163@itemx public-key
9164@itemx rpc
9165@itemx services
9166@itemx shadow
9167The system databases handled by the NSS. Each of these fields must be a
1068f26b 9168list of @code{<name-service>} objects (see below).
996ed739
LC
9169@end table
9170@end deftp
9171
9172@deftp {Data Type} name-service
9173
9174This is the data type representing an actual name service and the
9175associated lookup action.
9176
9177@table @code
9178@item name
9179A string denoting the name service (@pxref{Services in the NSS
9180configuration,,, libc, The GNU C Library Reference Manual}).
9181
4aee6e60
LC
9182Note that name services listed here must be visible to nscd. This is
9183achieved by passing the @code{#:name-services} argument to
9184@code{nscd-service} the list of packages providing the needed name
9185services (@pxref{Base Services, @code{nscd-service}}).
9186
996ed739
LC
9187@item reaction
9188An action specified using the @code{lookup-specification} macro
9189(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
9190Reference Manual}). For example:
9191
9192@example
9193(lookup-specification (unavailable => continue)
9194 (success => return))
9195@end example
9196@end table
9197@end deftp
0ae8c15a 9198
fd1b1fa2
LC
9199@node Initial RAM Disk
9200@subsection Initial RAM Disk
9201
9202@cindex initial RAM disk (initrd)
9203@cindex initrd (initial RAM disk)
9204For bootstrapping purposes, the Linux-Libre kernel is passed an
9205@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 9206root file system as well as an initialization script. The latter is
fd1b1fa2
LC
9207responsible for mounting the real root file system, and for loading any
9208kernel modules that may be needed to achieve that.
9209
9210The @code{initrd} field of an @code{operating-system} declaration allows
9211you to specify which initrd you would like to use. The @code{(gnu
9212system linux-initrd)} module provides two ways to build an initrd: the
9213high-level @code{base-initrd} procedure, and the low-level
9214@code{expression->initrd} procedure.
9215
9216The @code{base-initrd} procedure is intended to cover most common uses.
9217For example, if you want to add a bunch of kernel modules to be loaded
9218at boot time, you can define the @code{initrd} field of the operating
9219system declaration like this:
9220
9221@example
52ac153e 9222(initrd (lambda (file-systems . rest)
027981d6
LC
9223 ;; Create a standard initrd that has modules "foo.ko"
9224 ;; and "bar.ko", as well as their dependencies, in
9225 ;; addition to the modules available by default.
52ac153e 9226 (apply base-initrd file-systems
027981d6 9227 #:extra-modules '("foo" "bar")
52ac153e 9228 rest)))
fd1b1fa2
LC
9229@end example
9230
52ac153e 9231The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
9232involves using the system as a QEMU guest, or as a ``live'' system with
9233volatile root file system.
fd1b1fa2 9234
e90cf6c1
LC
9235The initial RAM disk produced by @code{base-initrd} honors several
9236options passed on the Linux kernel command line (that is, arguments
1068f26b
AE
9237passed @i{via} the @code{linux} command of GRUB, or the
9238@code{-append} option) of QEMU, notably:
e90cf6c1
LC
9239
9240@table @code
9241@item --load=@var{boot}
9242Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
9243program, once it has mounted the root file system.
9244
9245GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 9246service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
9247initialization system.
9248
9249@item --root=@var{root}
1068f26b 9250Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
9251device name like @code{/dev/sda1}, a partition label, or a partition
9252UUID.
9253
9254@item --system=@var{system}
9255Have @file{/run/booted-system} and @file{/run/current-system} point to
9256@var{system}.
9257
9258@item modprobe.blacklist=@var{modules}@dots{}
9259@cindex module, black-listing
9260@cindex black list, of kernel modules
9261Instruct the initial RAM disk as well as the @command{modprobe} command
9262(from the kmod package) to refuse to load @var{modules}. @var{modules}
9263must be a comma-separated list of module names---e.g.,
9264@code{usbkbd,9pnet}.
9265
9266@item --repl
9267Start a read-eval-print loop (REPL) from the initial RAM disk before it
9268tries to load kernel modules and to mount the root file system. Our
9269marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
9270love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
9271Manual}, for more information on Guile's REPL.
9272
9273@end table
9274
9275Now that you know all the features that initial RAM disks produced by
9276@code{base-initrd} provide, here is how to use it and customize it
9277further.
9278
fd1b1fa2 9279@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 9280 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 9281 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2 9282Return a monadic derivation that builds a generic initrd. @var{file-systems} is
1068f26b 9283a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 9284the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
9285@var{mapped-devices} is a list of device mappings to realize before
9286@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
9287
9288When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
9289parameters. When @var{virtio?} is true, load additional modules so that the
9290initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
9291
9292When @var{volatile-root?} is true, the root file system is writable but any changes
9293to it are lost.
9294
9295The initrd is automatically populated with all the kernel modules necessary
9296for @var{file-systems} and for the given options. However, additional kernel
9297modules can be listed in @var{extra-modules}. They will be added to the initrd, and
9298loaded at boot time in the order in which they appear.
9299@end deffn
9300
9301Needless to say, the initrds we produce and use embed a
9302statically-linked Guile, and the initialization program is a Guile
9303program. That gives a lot of flexibility. The
9304@code{expression->initrd} procedure builds such an initrd, given the
9305program to run in that initrd.
9306
9307@deffn {Monadic Procedure} expression->initrd @var{exp} @
9308 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 9309 [#:modules '()]
fd1b1fa2
LC
9310Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9311containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
9312upon booting. All the derivations referenced by @var{exp} are
9313automatically copied to the initrd.
fd1b1fa2 9314
42d10464
LC
9315@var{modules} is a list of Guile module names to be embedded in the
9316initrd.
fd1b1fa2
LC
9317@end deffn
9318
88faf933
LC
9319@node GRUB Configuration
9320@subsection GRUB Configuration
9321
9322@cindex GRUB
9323@cindex boot loader
9324
9325The operating system uses GNU@tie{}GRUB as its boot loader
9326(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
9327configured using a @code{grub-configuration} declaration. This data type
9328is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
9329
9330@deftp {Data Type} grub-configuration
9331The type of a GRUB configuration declaration.
9332
9333@table @asis
9334
9335@item @code{device}
9336This is a string denoting the boot device. It must be a device name
9337understood by the @command{grub-install} command, such as
9338@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9339GNU GRUB Manual}).
9340
9341@item @code{menu-entries} (default: @code{()})
9342A possibly empty list of @code{menu-entry} objects (see below), denoting
9343entries to appear in the GRUB boot menu, in addition to the current
9344system entry and the entry pointing to previous system generations.
9345
9346@item @code{default-entry} (default: @code{0})
1068f26b
AE
9347The index of the default boot menu entry. Index 0 is for the entry of the
9348current system.
88faf933
LC
9349
9350@item @code{timeout} (default: @code{5})
9351The number of seconds to wait for keyboard input before booting. Set to
93520 to boot immediately, and to -1 to wait indefinitely.
9353
9354@item @code{theme} (default: @var{%default-theme})
9355The @code{grub-theme} object describing the theme to use.
9356@end table
9357
9358@end deftp
9359
9360Should you want to list additional boot menu entries @i{via} the
9361@code{menu-entries} field above, you will need to create them with the
9362@code{menu-entry} form:
9363
9364@deftp {Data Type} menu-entry
9365The type of an entry in the GRUB boot menu.
9366
9367@table @asis
9368
9369@item @code{label}
35ed9306 9370The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
9371
9372@item @code{linux}
9373The Linux kernel to boot.
9374
9375@item @code{linux-arguments} (default: @code{()})
9376The list of extra Linux kernel command-line arguments---e.g.,
9377@code{("console=ttyS0")}.
9378
9379@item @code{initrd}
9380A G-Expression or string denoting the file name of the initial RAM disk
9381to use (@pxref{G-Expressions}).
9382
9383@end table
9384@end deftp
9385
9386@c FIXME: Write documentation once it's stable.
9387Themes are created using the @code{grub-theme} form, which is not
9388documented yet.
9389
9390@defvr {Scheme Variable} %default-theme
9391This is the default GRUB theme used by the operating system, with a
9392fancy background image displaying the GNU and Guix logos.
9393@end defvr
9394
9395
cf4a9129
LC
9396@node Invoking guix system
9397@subsection Invoking @code{guix system}
0918e64a 9398
1068f26b 9399Once you have written an operating system declaration as seen in the
cf4a9129
LC
9400previous section, it can be @dfn{instantiated} using the @command{guix
9401system} command. The synopsis is:
4af2447e 9402
cf4a9129
LC
9403@example
9404guix system @var{options}@dots{} @var{action} @var{file}
9405@end example
4af2447e 9406
cf4a9129
LC
9407@var{file} must be the name of a file containing an
9408@code{operating-system} declaration. @var{action} specifies how the
a40424bd 9409operating system is instantiated. Currently the following values are
cf4a9129 9410supported:
4af2447e 9411
cf4a9129
LC
9412@table @code
9413@item reconfigure
9414Build the operating system described in @var{file}, activate it, and
9415switch to it@footnote{This action is usable only on systems already
65797bff 9416running GuixSD.}.
4af2447e 9417
cf4a9129
LC
9418This effects all the configuration specified in @var{file}: user
9419accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
9420The command starts system services specified in @var{file} that are not
9421currently running; if a service is currently running, it does not
1068f26b 9422attempt to upgrade it since this would not be possible without stopping it
240b57f0 9423first.
4af2447e 9424
cf4a9129
LC
9425It also adds a GRUB menu entry for the new OS configuration, and moves
9426entries for older configurations to a submenu---unless
9427@option{--no-grub} is passed.
4af2447e 9428
240b57f0 9429@quotation Note
bf2479c7
LC
9430@c The paragraph below refers to the problem discussed at
9431@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9432It is highly recommended to run @command{guix pull} once before you run
9433@command{guix system reconfigure} for the first time (@pxref{Invoking
9434guix pull}). Failing to do that you would see an older version of Guix
9435once @command{reconfigure} has completed.
240b57f0 9436@end quotation
bf2479c7 9437
cf4a9129 9438@item build
1068f26b 9439Build the derivation of the operating system, which includes all the
cf4a9129
LC
9440configuration files and programs needed to boot and run the system.
9441This action does not actually install anything.
113daf62 9442
cf4a9129
LC
9443@item init
9444Populate the given directory with all the files necessary to run the
9445operating system specified in @var{file}. This is useful for first-time
4705641f 9446installations of GuixSD. For instance:
113daf62
LC
9447
9448@example
cf4a9129 9449guix system init my-os-config.scm /mnt
113daf62
LC
9450@end example
9451
cf4a9129
LC
9452copies to @file{/mnt} all the store items required by the configuration
9453specified in @file{my-os-config.scm}. This includes configuration
9454files, packages, and so on. It also creates other essential files
9455needed for the system to operate correctly---e.g., the @file{/etc},
9456@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 9457
cf4a9129
LC
9458This command also installs GRUB on the device specified in
9459@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 9460
cf4a9129
LC
9461@item vm
9462@cindex virtual machine
0276f697 9463@cindex VM
f535dcbe 9464@anchor{guix system vm}
1068f26b 9465Build a virtual machine that contains the operating system declared in
cf4a9129 9466@var{file}, and return a script to run that virtual machine (VM).
1068f26b 9467Arguments given to the script are passed to QEMU.
113daf62 9468
cf4a9129 9469The VM shares its store with the host system.
113daf62 9470
0276f697
LC
9471Additional file systems can be shared between the host and the VM using
9472the @code{--share} and @code{--expose} command-line options: the former
9473specifies a directory to be shared with write access, while the latter
9474provides read-only access to the shared directory.
9475
9476The example below creates a VM in which the user's home directory is
9477accessible read-only, and where the @file{/exchange} directory is a
1068f26b 9478read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
9479
9480@example
9481guix system vm my-config.scm \
9482 --expose=$HOME --share=$HOME/tmp=/exchange
9483@end example
9484
6aa260af
LC
9485On GNU/Linux, the default is to boot directly to the kernel; this has
9486the advantage of requiring only a very tiny root disk image since the
1068f26b 9487store of the host can then be mounted.
6aa260af
LC
9488
9489The @code{--full-boot} option forces a complete boot sequence, starting
9490with the bootloader. This requires more disk space since a root image
9491containing at least the kernel, initrd, and bootloader data files must
9492be created. The @code{--image-size} option can be used to specify the
1068f26b 9493size of the image.
ab11f0be 9494
cf4a9129
LC
9495@item vm-image
9496@itemx disk-image
9497Return a virtual machine or disk image of the operating system declared
9498in @var{file} that stands alone. Use the @option{--image-size} option
9499to specify the size of the image.
113daf62 9500
cf4a9129 9501When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
9502the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
9503for more information on how to run the image in a virtual machine.
113daf62 9504
cf4a9129
LC
9505When using @code{disk-image}, a raw disk image is produced; it can be
9506copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 9507the device corresponding to a USB stick, one can copy the image to it
cf4a9129 9508using the following command:
113daf62 9509
cf4a9129
LC
9510@example
9511# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9512@end example
113daf62 9513
1c8a81b1
DT
9514@item container
9515Return a script to run the operating system declared in @var{file}
9516within a container. Containers are a set of lightweight isolation
9517mechanisms provided by the kernel Linux-libre. Containers are
9518substantially less resource-demanding than full virtual machines since
9519the kernel, shared objects, and other resources can be shared with the
9520host system; this also means they provide thinner isolation.
9521
9522Currently, the script must be run as root in order to support more than
9523a single user and group. The container shares its store with the host
9524system.
9525
9526As with the @code{vm} action (@pxref{guix system vm}), additional file
9527systems to be shared between the host and container can be specified
9528using the @option{--share} and @option{--expose} options:
9529
9530@example
9531guix system container my-config.scm \
9532 --expose=$HOME --share=$HOME/tmp=/exchange
9533@end example
9534
0f252e26 9535@quotation Note
cfd35b4e 9536This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9537@end quotation
9538
cf4a9129 9539@end table
113daf62 9540
ccd7158d
LC
9541@var{options} can contain any of the common build options (@pxref{Common
9542Build Options}). In addition, @var{options} can contain one of the
9543following:
113daf62 9544
cf4a9129
LC
9545@table @option
9546@item --system=@var{system}
9547@itemx -s @var{system}
1068f26b 9548Attempt to build for @var{system} instead of the host system type.
cf4a9129 9549This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9550
f3f427c2
LC
9551@item --derivation
9552@itemx -d
9553Return the derivation file name of the given operating system without
9554building anything.
9555
cf4a9129
LC
9556@item --image-size=@var{size}
9557For the @code{vm-image} and @code{disk-image} actions, create an image
9558of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9559include a unit as a suffix (@pxref{Block size, size specifications,,
9560coreutils, GNU Coreutils}).
db030303
LC
9561
9562@item --on-error=@var{strategy}
9563Apply @var{strategy} when an error occurs when reading @var{file}.
9564@var{strategy} may be one of the following:
9565
9566@table @code
9567@item nothing-special
9568Report the error concisely and exit. This is the default strategy.
9569
9570@item backtrace
9571Likewise, but also display a backtrace.
9572
9573@item debug
9574Report the error and enter Guile's debugger. From there, you can run
9575commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
9576display local variable values, and more generally inspect the state of the
9577program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
9578a list of available debugging commands.
9579@end table
113daf62 9580@end table
113daf62 9581
cf4a9129
LC
9582Note that all the actions above, except @code{build} and @code{init},
9583rely on KVM support in the Linux-Libre kernel. Specifically, the
9584machine should have hardware virtualization support, the corresponding
9585KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b
AE
9586must exist and be readable and writable by the user and by the
9587build users of the daemon.
8451a568 9588
65797bff
LC
9589Once you have built, configured, re-configured, and re-re-configured
9590your GuixSD installation, you may find it useful to list the operating
9591system generations available on disk---and that you can choose from the
9592GRUB boot menu:
9593
9594@table @code
9595
9596@item list-generations
9597List a summary of each generation of the operating system available on
9598disk, in a human-readable way. This is similar to the
9599@option{--list-generations} option of @command{guix package}
9600(@pxref{Invoking guix package}).
9601
9602Optionally, one can specify a pattern, with the same syntax that is used
9603in @command{guix package --list-generations}, to restrict the list of
9604generations displayed. For instance, the following command displays
1068f26b 9605generations that are up to 10 days old:
65797bff
LC
9606
9607@example
9608$ guix system list-generations 10d
9609@end example
9610
9611@end table
9612
d6c3267a
LC
9613The @command{guix system} command has even more to offer! The following
9614sub-commands allow you to visualize how your system services relate to
9615each other:
9616
9617@anchor{system-extension-graph}
9618@table @code
9619
9620@item extension-graph
9621Emit in Dot/Graphviz format to standard output the @dfn{service
9622extension graph} of the operating system defined in @var{file}
9623(@pxref{Service Composition}, for more information on service
9624extensions.)
9625
9626The command:
9627
9628@example
9629$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9630@end example
9631
9632produces a PDF file showing the extension relations among services.
9633
710fa231
AK
9634@anchor{system-shepherd-graph}
9635@item shepherd-graph
6f305ea5 9636Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
9637graph} of shepherd services of the operating system defined in
9638@var{file}. @xref{Shepherd Services}, for more information and for an
9639example graph.
6f305ea5 9640
d6c3267a
LC
9641@end table
9642
97d76250 9643@node Running GuixSD in a VM
70ac09a5 9644@subsection Running GuixSD in a Virtual Machine
97d76250
LF
9645
9646One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
9647virtual machine image using @command{guix system vm-image}
9648(@pxref{Invoking guix system}). The returned image is in qcow2 format,
9649which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
9650
9651To run the image in QEMU, copy it out of the store (@pxref{The Store})
9652and give yourself permission to write to the copy. When invoking QEMU,
9653you must choose a system emulator that is suitable for your hardware
9654platform. Here is a minimal QEMU invocation that will boot the result
9655of @command{guix system vm-image} on x86_64 hardware:
9656
9657@example
9658$ qemu-system-x86_64 \
9659 -net user -net nic,model=virtio \
9660 -enable-kvm -m 256 /tmp/qemu-image
9661@end example
9662
9663Here is what each of these options means:
9664
9665@table @code
9666@item qemu-system-x86_64
9667This specifies the hardware platform to emulate. This should match the
9668host.
9669
9670@item -net user
9671Enable the unprivileged user-mode network stack. The guest OS can
9672access the host but not vice versa. This is the simplest way to get the
1068f26b 9673guest OS online. If you do not choose a network stack, the boot will
97d76250
LF
9674fail.
9675
9676@item -net nic,model=virtio
1068f26b 9677You must create a network interface of a given model. If you do not
97d76250
LF
9678create a NIC, the boot will fail. Assuming your hardware platform is
9679x86_64, you can get a list of available NIC models by running
9680@command{qemu-system-x86_64 -net nic,model=help}.
9681
9682@item -enable-kvm
9683If your system has hardware virtualization extensions, enabling the
1068f26b 9684virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
9685faster.
9686
9687@item -m 256
9688RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
9689which may be insufficent for some operations.
9690
9691@item /tmp/qemu-image
9692The file name of the qcow2 image.
9693@end table
d6c3267a 9694
cf4a9129
LC
9695@node Defining Services
9696@subsection Defining Services
8451a568 9697
eb524192 9698The previous sections show the available services and how one can combine
0adfe95a
LC
9699them in an @code{operating-system} declaration. But how do we define
9700them in the first place? And what is a service anyway?
8451a568 9701
0adfe95a
LC
9702@menu
9703* Service Composition:: The model for composing services.
9704* Service Types and Services:: Types and services.
9705* Service Reference:: API reference.
dd17bc38 9706* Shepherd Services:: A particular type of service.
0adfe95a
LC
9707@end menu
9708
9709@node Service Composition
9710@subsubsection Service Composition
9711
9712@cindex services
9713@cindex daemons
9714Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 9715functionality of the operating system. Often a service is a process---a
0adfe95a
LC
9716@dfn{daemon}---started when the system boots: a secure shell server, a
9717Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9718whose execution can be triggered by another daemon---e.g., an FTP server
9719started by @command{inetd} or a D-Bus service activated by
9720@command{dbus-daemon}. Occasionally, a service does not map to a
9721daemon. For instance, the ``account'' service collects user accounts
9722and makes sure they exist when the system runs; the ``udev'' service
9723collects device management rules and makes them available to the eudev
1068f26b
AE
9724daemon; the @file{/etc} service populates the @file{/etc} directory
9725of the system.
0adfe95a 9726
d6c3267a 9727@cindex service extensions
0adfe95a 9728GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 9729secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
9730initialization system, running as PID@tie{}1---by giving it the command
9731lines to start and stop the secure shell daemon (@pxref{Networking
9732Services, @code{lsh-service}}); the UPower service extends the D-Bus
9733service by passing it its @file{.service} specification, and extends the
9734udev service by passing it device management rules (@pxref{Desktop
9735Services, @code{upower-service}}); the Guix daemon service extends the
9736Shepherd by passing it the command lines to start and stop the daemon,
9737and extends the account service by passing it a list of required build
9738user accounts (@pxref{Base Services}).
0adfe95a
LC
9739
9740All in all, services and their ``extends'' relations form a directed
9741acyclic graph (DAG). If we represent services as boxes and extensions
9742as arrows, a typical system might provide something like this:
9743
9744@image{images/service-graph,,5in,Typical service extension graph.}
9745
d62e201c
LC
9746@cindex system service
9747At the bottom, we see the @dfn{system service}, which produces the
9748directory containing everything to run and boot the system, as returned
9749by the @command{guix system build} command. @xref{Service Reference},
9750to learn about the other service types shown here.
d6c3267a
LC
9751@xref{system-extension-graph, the @command{guix system extension-graph}
9752command}, for information on how to generate this representation for a
9753particular operating system definition.
0adfe95a
LC
9754
9755@cindex service types
9756Technically, developers can define @dfn{service types} to express these
9757relations. There can be any number of services of a given type on the
9758system---for instance, a system running two instances of the GNU secure
9759shell server (lsh) has two instances of @var{lsh-service-type}, with
9760different parameters.
9761
9762The following section describes the programming interface for service
9763types and services.
9764
9765@node Service Types and Services
9766@subsubsection Service Types and Services
9767
9768A @dfn{service type} is a node in the DAG described above. Let us start
9769with a simple example, the service type for the Guix build daemon
9770(@pxref{Invoking guix-daemon}):
9771
9772@example
9773(define guix-service-type
9774 (service-type
9775 (name 'guix)
9776 (extensions
d4053c71 9777 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
9778 (service-extension account-service-type guix-accounts)
9779 (service-extension activation-service-type guix-activation)))))
9780@end example
8451a568 9781
cf4a9129 9782@noindent
1068f26b 9783It defines two things:
0adfe95a
LC
9784
9785@enumerate
9786@item
9787A name, whose sole purpose is to make inspection and debugging easier.
9788
9789@item
9790A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
9791target service type and a procedure that, given the parameters of the
9792service, returns a list of objects to extend the service of that type.
0adfe95a
LC
9793
9794Every service type has at least one service extension. The only
9795exception is the @dfn{boot service type}, which is the ultimate service.
9796@end enumerate
9797
9798In this example, @var{guix-service-type} extends three services:
9799
9800@table @var
d4053c71
AK
9801@item shepherd-root-service-type
9802The @var{guix-shepherd-service} procedure defines how the Shepherd
9803service is extended. Namely, it returns a @code{<shepherd-service>}
9804object that defines how @command{guix-daemon} is started and stopped
9805(@pxref{Shepherd Services}).
0adfe95a
LC
9806
9807@item account-service-type
9808This extension for this service is computed by @var{guix-accounts},
9809which returns a list of @code{user-group} and @code{user-account}
9810objects representing the build user accounts (@pxref{Invoking
9811guix-daemon}).
9812
9813@item activation-service-type
9814Here @var{guix-activation} is a procedure that returns a gexp, which is
9815a code snippet to run at ``activation time''---e.g., when the service is
9816booted.
9817@end table
9818
9819A service of this type is instantiated like this:
9820
9821@example
9822(service guix-service-type
9823 (guix-configuration
9824 (build-accounts 5)
9825 (use-substitutes? #f)))
9826@end example
9827
9828The second argument to the @code{service} form is a value representing
9829the parameters of this specific service instance.
9830@xref{guix-configuration-type, @code{guix-configuration}}, for
9831information about the @code{guix-configuration} data type.
9832
9833@var{guix-service-type} is quite simple because it extends other
9834services but is not extensible itself.
9835
9836@c @subsubsubsection Extensible Service Types
9837
9838The service type for an @emph{extensible} service looks like this:
9839
9840@example
9841(define udev-service-type
9842 (service-type (name 'udev)
9843 (extensions
d4053c71
AK
9844 (list (service-extension shepherd-root-service-type
9845 udev-shepherd-service)))
0adfe95a
LC
9846
9847 (compose concatenate) ;concatenate the list of rules
9848 (extend (lambda (config rules)
9849 (match config
9850 (($ <udev-configuration> udev initial-rules)
9851 (udev-configuration
9852 (udev udev) ;the udev package to use
9853 (rules (append initial-rules rules)))))))))
9854@end example
9855
9856This is the service type for the
9857@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9858management daemon}. Compared to the previous example, in addition to an
d4053c71 9859extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
9860
9861@table @code
9862@item compose
9863This is the procedure to @dfn{compose} the list of extensions to
9864services of this type.
9865
9866Services can extend the udev service by passing it lists of rules; we
9867compose those extensions simply by concatenating them.
9868
9869@item extend
1068f26b 9870This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
9871the composition of the extensions.
9872
9873Udev extensions are composed into a list of rules, but the udev service
9874value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 9875extend that record by appending the list of rules it contains to the
0adfe95a
LC
9876list of contributed rules.
9877@end table
9878
9879There can be only one instance of an extensible service type such as
9880@var{udev-service-type}. If there were more, the
9881@code{service-extension} specifications would be ambiguous.
9882
9883Still here? The next section provides a reference of the programming
9884interface for services.
9885
9886@node Service Reference
9887@subsubsection Service Reference
9888
9889We have seen an overview of service types (@pxref{Service Types and
9890Services}). This section provides a reference on how to manipulate
9891services and service types. This interface is provided by the
9892@code{(gnu services)} module.
9893
9894@deffn {Scheme Procedure} service @var{type} @var{value}
9895Return a new service of @var{type}, a @code{<service-type>} object (see
9896below.) @var{value} can be any object; it represents the parameters of
9897this particular service instance.
9898@end deffn
9899
9900@deffn {Scheme Procedure} service? @var{obj}
9901Return true if @var{obj} is a service.
9902@end deffn
8451a568 9903
0adfe95a
LC
9904@deffn {Scheme Procedure} service-kind @var{service}
9905Return the type of @var{service}---i.e., a @code{<service-type>} object.
9906@end deffn
9907
9908@deffn {Scheme Procedure} service-parameters @var{service}
9909Return the value associated with @var{service}. It represents its
9910parameters.
9911@end deffn
9912
9913Here is an example of how a service is created and manipulated:
9914
9915@example
9916(define s
9917 (service nginx-service-type
9918 (nginx-configuration
9919 (nginx nginx)
9920 (log-directory log-directory)
9921 (run-directory run-directory)
9922 (file config-file))))
9923
9924(service? s)
9925@result{} #t
9926
9927(eq? (service-kind s) nginx-service-type)
9928@result{} #t
9929@end example
9930
cd6f6c22
LC
9931The @code{modify-services} form provides a handy way to change the
9932parameters of some of the services of a list such as
9933@var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9934course, you could always use standard list combinators such as
9935@code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9936guile, GNU Guile Reference Manual}); @code{modify-services} simply
9937provides a more concise form for this common pattern.
9938
9939@deffn {Scheme Syntax} modify-services @var{services} @
9940 (@var{type} @var{variable} => @var{body}) @dots{}
9941
9942Modify the services listed in @var{services} according to the given
9943clauses. Each clause has the form:
9944
9945@example
9946(@var{type} @var{variable} => @var{body})
9947@end example
9948
9949where @var{type} is a service type, such as @var{guix-service-type}, and
9950@var{variable} is an identifier that is bound within @var{body} to the
9951value of the service of that @var{type}. @xref{Using the Configuration
9952System}, for an example.
9953
9954This is a shorthand for:
9955
9956@example
9957(map (lambda (service) @dots{}) @var{services})
9958@end example
9959@end deffn
9960
9961Next comes the programming interface for service types. This is
9962something you want to know when writing new service definitions, but not
9963necessarily when simply looking for ways to customize your
9964@code{operating-system} declaration.
9965
0adfe95a
LC
9966@deftp {Data Type} service-type
9967@cindex service type
9968This is the representation of a @dfn{service type} (@pxref{Service Types
9969and Services}).
9970
9971@table @asis
9972@item @code{name}
9973This is a symbol, used only to simplify inspection and debugging.
9974
9975@item @code{extensions}
1068f26b 9976A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
9977
9978@item @code{compose} (default: @code{#f})
9979If this is @code{#f}, then the service type denotes services that cannot
9980be extended---i.e., services that do not receive ``values'' from other
9981services.
9982
9983Otherwise, it must be a one-argument procedure. The procedure is called
9984by @code{fold-services} and is passed a list of values collected from
9985extensions. It must return a value that is a valid parameter value for
9986the service instance.
9987
9988@item @code{extend} (default: @code{#f})
9989If this is @code{#f}, services of this type cannot be extended.
9990
9991Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 9992calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
9993and the result of applying @code{compose} to the extension values as the
9994second argument.
9995@end table
9996
9997@xref{Service Types and Services}, for examples.
9998@end deftp
9999
10000@deffn {Scheme Procedure} service-extension @var{target-type} @
10001 @var{compute}
10002Return a new extension for services of type @var{target-type}.
10003@var{compute} must be a one-argument procedure: @code{fold-services}
10004calls it, passing it the value associated with the service that provides
10005the extension; it must return a valid value for the target service.
10006@end deffn
10007
10008@deffn {Scheme Procedure} service-extension? @var{obj}
10009Return true if @var{obj} is a service extension.
10010@end deffn
10011
10012At the core of the service abstraction lies the @code{fold-services}
10013procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
10014down to a single directory that contains everything needed to boot and
10015run the system---the directory shown by the @command{guix system build}
10016command (@pxref{Invoking guix system}). In essence, it propagates
10017service extensions down the service graph, updating each node parameters
10018on the way, until it reaches the root node.
0adfe95a
LC
10019
10020@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 10021 [#:target-type @var{system-service-type}]
0adfe95a
LC
10022Fold @var{services} by propagating their extensions down to the root of
10023type @var{target-type}; return the root service adjusted accordingly.
10024@end deffn
10025
10026Lastly, the @code{(gnu services)} module also defines several essential
10027service types, some of which are listed below.
10028
d62e201c
LC
10029@defvr {Scheme Variable} system-service-type
10030This is the root of the service graph. It produces the system directory
10031as returned by the @command{guix system build} command.
10032@end defvr
10033
0adfe95a 10034@defvr {Scheme Variable} boot-service-type
d62e201c
LC
10035The type of the ``boot service'', which produces the @dfn{boot script}.
10036The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
10037@end defvr
10038
10039@defvr {Scheme Variable} etc-service-type
10040The type of the @file{/etc} service. This service can be extended by
10041passing it name/file tuples such as:
10042
10043@example
10044(list `("issue" ,(plain-file "issue" "Welcome!\n")))
10045@end example
10046
10047In this example, the effect would be to add an @file{/etc/issue} file
10048pointing to the given file.
10049@end defvr
10050
10051@defvr {Scheme Variable} setuid-program-service-type
10052Type for the ``setuid-program service''. This service collects lists of
10053executable file names, passed as gexps, and adds them to the set of
10054setuid-root programs on the system (@pxref{Setuid Programs}).
10055@end defvr
10056
af4c3fd5
LC
10057@defvr {Scheme Variable} profile-service-type
10058Type of the service that populates the @dfn{system profile}---i.e., the
10059programs under @file{/run/current-system/profile}. Other services can
10060extend it by passing it lists of packages to add to the system profile.
10061@end defvr
10062
0adfe95a 10063
dd17bc38
AK
10064@node Shepherd Services
10065@subsubsection Shepherd Services
0adfe95a
LC
10066
10067@cindex PID 1
10068@cindex init system
a40424bd
CM
10069The @code{(gnu services shepherd)} module provides a way to define
10070services managed by the GNU@tie{}Shepherd, which is the GuixSD
10071initialization system---the first process that is started when the
1068f26b
AE
10072system boots, also known as PID@tie{}1
10073(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 10074
dd17bc38
AK
10075Services in the Shepherd can depend on each other. For instance, the
10076SSH daemon may need to be started after the syslog daemon has been
10077started, which in turn can only happen once all the file systems have
10078been mounted. The simple operating system defined earlier (@pxref{Using
10079the Configuration System}) results in a service graph like this:
6f305ea5 10080
710fa231 10081@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
10082
10083You can actually generate such a graph for any operating system
710fa231
AK
10084definition using the @command{guix system shepherd-graph} command
10085(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 10086
d4053c71
AK
10087The @var{%shepherd-root-service} is a service object representing
10088PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10089by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 10090
d4053c71 10091@deftp {Data Type} shepherd-service
dd17bc38 10092The data type representing a service managed by the Shepherd.
0adfe95a
LC
10093
10094@table @asis
10095@item @code{provision}
10096This is a list of symbols denoting what the service provides.
10097
dd17bc38
AK
10098These are the names that may be passed to @command{herd start},
10099@command{herd status}, and similar commands (@pxref{Invoking herd,,,
10100shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10101@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
10102
10103@item @code{requirements} (default: @code{'()})
dd17bc38 10104List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
10105
10106@item @code{respawn?} (default: @code{#t})
10107Whether to restart the service when it stops, for instance when the
10108underlying process dies.
10109
10110@item @code{start}
10111@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
10112The @code{start} and @code{stop} fields refer to the Shepherd's
10113facilities to start and stop processes (@pxref{Service De- and
10114Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10115G-expressions that get expanded in the Shepherd configuration file
10116(@pxref{G-Expressions}).
0adfe95a
LC
10117
10118@item @code{documentation}
10119A documentation string, as shown when running:
10120
10121@example
dd17bc38 10122herd doc @var{service-name}
0adfe95a
LC
10123@end example
10124
10125where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 10126(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
10127
10128@item @code{modules} (default: @var{%default-modules})
10129This is the list of modules that must be in scope when @code{start} and
10130@code{stop} are evaluated.
10131
10132@item @code{imported-modules} (default: @var{%default-imported-modules})
10133This is the list of modules to import in the execution environment of
dd17bc38 10134the Shepherd.
fae685b9 10135
0adfe95a
LC
10136@end table
10137@end deftp
10138
d4053c71 10139@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 10140The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
10141
10142This is the service type that extensions target when they want to create
dd17bc38 10143shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 10144Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
10145@end defvr
10146
d4053c71 10147@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
10148This service represents PID@tie{}1.
10149@end defvr
8451a568 10150
8451a568 10151
cf4a9129
LC
10152@node Installing Debugging Files
10153@section Installing Debugging Files
8451a568 10154
cf4a9129
LC
10155@cindex debugging files
10156Program binaries, as produced by the GCC compilers for instance, are
10157typically written in the ELF format, with a section containing
10158@dfn{debugging information}. Debugging information is what allows the
10159debugger, GDB, to map binary code to source code; it is required to
10160debug a compiled program in good conditions.
8451a568 10161
cf4a9129
LC
10162The problem with debugging information is that is takes up a fair amount
10163of disk space. For example, debugging information for the GNU C Library
10164weighs in at more than 60 MiB. Thus, as a user, keeping all the
10165debugging info of all the installed programs is usually not an option.
10166Yet, space savings should not come at the cost of an impediment to
10167debugging---especially in the GNU system, which should make it easier
10168for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 10169
cf4a9129
LC
10170Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
10171mechanism that allows users to get the best of both worlds: debugging
10172information can be stripped from the binaries and stored in separate
10173files. GDB is then able to load debugging information from those files,
10174when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
10175with GDB}).
8451a568 10176
cf4a9129
LC
10177The GNU distribution takes advantage of this by storing debugging
10178information in the @code{lib/debug} sub-directory of a separate package
10179output unimaginatively called @code{debug} (@pxref{Packages with
10180Multiple Outputs}). Users can choose to install the @code{debug} output
10181of a package when they need it. For instance, the following command
10182installs the debugging information for the GNU C Library and for GNU
10183Guile:
8451a568
LC
10184
10185@example
cf4a9129 10186guix package -i glibc:debug guile:debug
8451a568
LC
10187@end example
10188
cf4a9129
LC
10189GDB must then be told to look for debug files in the user's profile, by
10190setting the @code{debug-file-directory} variable (consider setting it
10191from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
10192GDB}):
8451a568 10193
cf4a9129
LC
10194@example
10195(gdb) set debug-file-directory ~/.guix-profile/lib/debug
10196@end example
8451a568 10197
cf4a9129
LC
10198From there on, GDB will pick up debugging information from the
10199@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 10200
cf4a9129
LC
10201In addition, you will most likely want GDB to be able to show the source
10202code being debugged. To do that, you will have to unpack the source
10203code of the package of interest (obtained with @code{guix build
10204--source}, @pxref{Invoking guix build}), and to point GDB to that source
10205directory using the @code{directory} command (@pxref{Source Path,
10206@code{directory},, gdb, Debugging with GDB}).
8451a568 10207
cf4a9129
LC
10208@c XXX: keep me up-to-date
10209The @code{debug} output mechanism in Guix is implemented by the
10210@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
10211opt-in---debugging information is available only for the packages
10212with definitions explicitly declaring a @code{debug} output. This may be
10213changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
10214the load. To check whether a package has a @code{debug} output, use
10215@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 10216
8451a568 10217
05962f29
LC
10218@node Security Updates
10219@section Security Updates
10220
843858b8
LC
10221@quotation Note
10222As of version @value{VERSION}, the feature described in this section is
10223experimental.
10224@end quotation
05962f29
LC
10225
10226@cindex security updates
10227Occasionally, important security vulnerabilities are discovered in core
10228software packages and must be patched. Guix follows a functional
10229package management discipline (@pxref{Introduction}), which implies
10230that, when a package is changed, @emph{every package that depends on it}
10231must be rebuilt. This can significantly slow down the deployment of
10232fixes in core packages such as libc or Bash, since basically the whole
10233distribution would need to be rebuilt. Using pre-built binaries helps
10234(@pxref{Substitutes}), but deployment may still take more time than
10235desired.
10236
10237@cindex grafts
1068f26b 10238To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
10239for fast deployment of critical updates without the costs associated
10240with a whole-distribution rebuild. The idea is to rebuild only the
10241package that needs to be patched, and then to ``graft'' it onto packages
10242explicitly installed by the user and that were previously referring to
10243the original package. The cost of grafting is typically very low, and
10244order of magnitudes lower than a full rebuild of the dependency chain.
10245
10246@cindex replacements of packages, for grafts
10247For instance, suppose a security update needs to be applied to Bash.
10248Guix developers will provide a package definition for the ``fixed''
10249Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
10250Packages}). Then, the original package definition is augmented with a
10251@code{replacement} field pointing to the package containing the bug fix:
10252
10253@example
10254(define bash
10255 (package
10256 (name "bash")
10257 ;; @dots{}
10258 (replacement bash-fixed)))
10259@end example
10260
c22a1324
LC
10261From there on, any package depending directly or indirectly on Bash---as
10262reported by @command{guix gc --requisites} (@pxref{Invoking guix
10263gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 10264@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 10265time proportional to the size of the package, usually less than a
c22a1324
LC
10266minute for an ``average'' package on a recent machine. Grafting is
10267recursive: when an indirect dependency requires grafting, then grafting
10268``propagates'' up to the package that the user is installing.
05962f29
LC
10269
10270Currently, the graft and the package it replaces (@var{bash-fixed} and
10271@var{bash} in the example above) must have the exact same @code{name}
10272and @code{version} fields. This restriction mostly comes from the fact
10273that grafting works by patching files, including binary files, directly.
10274Other restrictions may apply: for instance, when adding a graft to a
10275package providing a shared library, the original shared library and its
10276replacement must have the same @code{SONAME} and be binary-compatible.
10277
59a4dd50
LC
10278The @option{--no-grafts} command-line option allows you to forcefully
10279avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
10280Thus, the command:
10281
10282@example
10283guix build bash --no-grafts
10284@end example
10285
10286@noindent
10287returns the store file name of the original Bash, whereas:
10288
10289@example
10290guix build bash
10291@end example
10292
10293@noindent
10294returns the store file name of the ``fixed'', replacement Bash. This
10295allows you to distinguish between the two variants of Bash.
10296
10297To verify which Bash your whole profile refers to, you can run
10298(@pxref{Invoking guix gc}):
10299
10300@example
10301guix gc -R `readlink -f ~/.guix-profile` | grep bash
10302@end example
10303
10304@noindent
10305@dots{} and compare the store file names that you get with those above.
10306Likewise for a complete GuixSD system generation:
10307
10308@example
10309guix gc -R `guix system build my-config.scm` | grep bash
10310@end example
10311
10312Lastly, to check which Bash running processes are using, you can use the
10313@command{lsof} command:
10314
10315@example
10316lsof | grep /gnu/store/.*bash
10317@end example
10318
05962f29 10319
cf4a9129
LC
10320@node Package Modules
10321@section Package Modules
8451a568 10322
cf4a9129
LC
10323From a programming viewpoint, the package definitions of the
10324GNU distribution are provided by Guile modules in the @code{(gnu packages
10325@dots{})} name space@footnote{Note that packages under the @code{(gnu
10326packages @dots{})} module name space are not necessarily ``GNU
10327packages''. This module naming scheme follows the usual Guile module
10328naming convention: @code{gnu} means that these modules are distributed
10329as part of the GNU system, and @code{packages} identifies modules that
10330define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
10331Reference Manual}). For instance, the @code{(gnu packages emacs)}
10332module exports a variable named @code{emacs}, which is bound to a
10333@code{<package>} object (@pxref{Defining Packages}).
113daf62 10334
300868ba 10335The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
10336automatically scanned for packages by the command-line tools. For
10337instance, when running @code{guix package -i emacs}, all the @code{(gnu
10338packages @dots{})} modules are scanned until one that exports a package
10339object whose name is @code{emacs} is found. This package search
10340facility is implemented in the @code{(gnu packages)} module.
113daf62 10341
300868ba 10342@cindex customization, of packages
8689901f 10343@cindex package module search path
cf4a9129 10344Users can store package definitions in modules with different
60142854 10345names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
10346name and module name must match. For instance, the @code{(my-packages
10347emacs)} module must be stored in a @file{my-packages/emacs.scm} file
10348relative to the load path specified with @option{--load-path} or
10349@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
10350guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
10351will not be visible by default. Users can invoke commands such as
10352@command{guix package} and @command{guix build} with the
c95ded7e
LC
10353@code{-e} option so that they know where to find the package. Better
10354yet, they can use the
300868ba 10355@code{-L} option of these commands to make those modules visible
8689901f
LC
10356(@pxref{Invoking guix build, @code{--load-path}}), or define the
10357@code{GUIX_PACKAGE_PATH} environment variable. This environment
10358variable makes it easy to extend or customize the distribution and is
10359honored by all the user interfaces.
10360
10361@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
10362This is a colon-separated list of directories to search for additional
10363package modules. Directories listed in this variable take precedence
10364over the own modules of the distribution.
8689901f 10365@end defvr
ef5dd60a 10366
cf4a9129
LC
10367The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
10368each package is built based solely on other packages in the
10369distribution. The root of this dependency graph is a small set of
10370@dfn{bootstrap binaries}, provided by the @code{(gnu packages
10371bootstrap)} module. For more information on bootstrapping,
081145cf 10372@pxref{Bootstrapping}.
ef5dd60a 10373
cf4a9129
LC
10374@node Packaging Guidelines
10375@section Packaging Guidelines
ef5dd60a 10376
cf4a9129
LC
10377The GNU distribution is nascent and may well lack some of your favorite
10378packages. This section describes how you can help make the distribution
10379grow. @xref{Contributing}, for additional information on how you can
10380help.
ef5dd60a 10381
cf4a9129
LC
10382Free software packages are usually distributed in the form of
10383@dfn{source code tarballs}---typically @file{tar.gz} files that contain
10384all the source files. Adding a package to the distribution means
10385essentially two things: adding a @dfn{recipe} that describes how to
10386build the package, including a list of other packages required to build
f97c9175 10387it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 10388description and licensing information.
ef5dd60a 10389
cf4a9129
LC
10390In Guix all this information is embodied in @dfn{package definitions}.
10391Package definitions provide a high-level view of the package. They are
10392written using the syntax of the Scheme programming language; in fact,
10393for each package we define a variable bound to the package definition,
10394and export that variable from a module (@pxref{Package Modules}).
10395However, in-depth Scheme knowledge is @emph{not} a prerequisite for
10396creating packages. For more information on package definitions,
081145cf 10397@pxref{Defining Packages}.
ef5dd60a 10398
cf4a9129
LC
10399Once a package definition is in place, stored in a file in the Guix
10400source tree, it can be tested using the @command{guix build} command
10401(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
10402called @code{gnew}, you may run this command from the Guix build tree
10403(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
10404
10405@example
cf4a9129 10406./pre-inst-env guix build gnew --keep-failed
ef5dd60a 10407@end example
ef5dd60a 10408
cf4a9129
LC
10409Using @code{--keep-failed} makes it easier to debug build failures since
10410it provides access to the failed build tree. Another useful
10411command-line option when debugging is @code{--log-file}, to access the
10412build log.
ef5dd60a 10413
cf4a9129
LC
10414If the package is unknown to the @command{guix} command, it may be that
10415the source file contains a syntax error, or lacks a @code{define-public}
10416clause to export the package variable. To figure it out, you may load
10417the module from Guile to get more information about the actual error:
ef5dd60a 10418
cf4a9129
LC
10419@example
10420./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
10421@end example
ef5dd60a 10422
cf4a9129
LC
10423Once your package builds correctly, please send us a patch
10424(@pxref{Contributing}). Well, if you need help, we will be happy to
10425help you too. Once the patch is committed in the Guix repository, the
10426new package automatically gets built on the supported platforms by
2b1cee21 10427@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 10428system}.
ef5dd60a 10429
cf4a9129
LC
10430@cindex substituter
10431Users can obtain the new package definition simply by running
10432@command{guix pull} (@pxref{Invoking guix pull}). When
10433@code{hydra.gnu.org} is done building the package, installing the
10434package automatically downloads binaries from there
10435(@pxref{Substitutes}). The only place where human intervention is
10436needed is to review and apply the patch.
ef5dd60a 10437
ef5dd60a 10438
cf4a9129 10439@menu
ec0339cd
LC
10440* Software Freedom:: What may go into the distribution.
10441* Package Naming:: What's in a name?
10442* Version Numbers:: When the name is not enough.
cbd02397 10443* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
10444* Python Modules:: Taming the snake.
10445* Perl Modules:: Little pearls.
10446* Fonts:: Fond of fonts.
cf4a9129 10447@end menu
ef5dd60a 10448
cf4a9129
LC
10449@node Software Freedom
10450@subsection Software Freedom
ef5dd60a 10451
cf4a9129 10452@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 10453
cf4a9129
LC
10454The GNU operating system has been developed so that users can have
10455freedom in their computing. GNU is @dfn{free software}, meaning that
10456users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10457essential freedoms}: to run the program, to study and change the program
10458in source code form, to redistribute exact copies, and to distribute
10459modified versions. Packages found in the GNU distribution provide only
10460software that conveys these four freedoms.
c11a6eb1 10461
cf4a9129
LC
10462In addition, the GNU distribution follow the
10463@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10464software distribution guidelines}. Among other things, these guidelines
10465reject non-free firmware, recommendations of non-free software, and
10466discuss ways to deal with trademarks and patents.
ef5dd60a 10467
1068f26b
AE
10468Some otherwise free upstream package sources contain a small and optional
10469subset that violates the above guidelines, for instance because this subset
10470is itself non-free code. When that happens, the offending items are removed
10471with appropriate patches or code snippets in the @code{origin} form of the
10472package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
10473build --source} returns the ``freed'' source rather than the unmodified
10474upstream source.
ef5dd60a 10475
ef5dd60a 10476
cf4a9129
LC
10477@node Package Naming
10478@subsection Package Naming
ef5dd60a 10479
cf4a9129
LC
10480A package has actually two names associated with it:
10481First, there is the name of the @emph{Scheme variable}, the one following
10482@code{define-public}. By this name, the package can be made known in the
10483Scheme code, for instance as input to another package. Second, there is
10484the string in the @code{name} field of a package definition. This name
10485is used by package management commands such as
10486@command{guix package} and @command{guix build}.
ef5dd60a 10487
cf4a9129
LC
10488Both are usually the same and correspond to the lowercase conversion of
10489the project name chosen upstream, with underscores replaced with
10490hyphens. For instance, GNUnet is available as @code{gnunet}, and
10491SDL_net as @code{sdl-net}.
927097ef 10492
cf4a9129 10493We do not add @code{lib} prefixes for library packages, unless these are
081145cf 10494already part of the official project name. But @pxref{Python
cf4a9129
LC
10495Modules} and @ref{Perl Modules} for special rules concerning modules for
10496the Python and Perl languages.
927097ef 10497
1b366ee4 10498Font package names are handled differently, @pxref{Fonts}.
7fec52b7 10499
ef5dd60a 10500
cf4a9129
LC
10501@node Version Numbers
10502@subsection Version Numbers
ef5dd60a 10503
cf4a9129
LC
10504We usually package only the latest version of a given free software
10505project. But sometimes, for instance for incompatible library versions,
10506two (or more) versions of the same package are needed. These require
10507different Scheme variable names. We use the name as defined
10508in @ref{Package Naming}
10509for the most recent version; previous versions use the same name, suffixed
10510by @code{-} and the smallest prefix of the version number that may
10511distinguish the two versions.
ef5dd60a 10512
cf4a9129
LC
10513The name inside the package definition is the same for all versions of a
10514package and does not contain any version number.
ef5dd60a 10515
cf4a9129 10516For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 10517
cf4a9129
LC
10518@example
10519(define-public gtk+
10520 (package
17d8e33f
ML
10521 (name "gtk+")
10522 (version "3.9.12")
10523 ...))
cf4a9129
LC
10524(define-public gtk+-2
10525 (package
17d8e33f
ML
10526 (name "gtk+")
10527 (version "2.24.20")
10528 ...))
cf4a9129
LC
10529@end example
10530If we also wanted GTK+ 3.8.2, this would be packaged as
10531@example
10532(define-public gtk+-3.8
10533 (package
17d8e33f
ML
10534 (name "gtk+")
10535 (version "3.8.2")
10536 ...))
cf4a9129 10537@end example
ef5dd60a 10538
880d647d
LC
10539@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
10540@c for a discussion of what follows.
10541@cindex version number, for VCS snapshots
10542Occasionally, we package snapshots of upstream's version control system
10543(VCS) instead of formal releases. This should remain exceptional,
10544because it is up to upstream developers to clarify what the stable
10545release is. Yet, it is sometimes necessary. So, what should we put in
10546the @code{version} field?
10547
10548Clearly, we need to make the commit identifier of the VCS snapshot
10549visible in the version string, but we also need to make sure that the
10550version string is monotonically increasing so that @command{guix package
10551--upgrade} can determine which version is newer. Since commit
10552identifiers, notably with Git, are not monotonically increasing, we add
10553a revision number that we increase each time we upgrade to a newer
10554snapshot. The resulting version string looks like this:
10555
10556@example
105572.0.11-3.cabba9e
10558 ^ ^ ^
10559 | | `-- upstream commit ID
10560 | |
10561 | `--- Guix package revision
10562 |
10563latest upstream version
10564@end example
10565
10566It is a good idea to strip commit identifiers in the @code{version}
10567field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
10568aesthetics have a role to play here) as well as problems related to OS
10569limits such as the maximum shebang length (127 bytes for the Linux
10570kernel.) It is best to use the full commit identifiers in
561360a5
LC
10571@code{origin}s, though, to avoid ambiguities. A typical package
10572definition may look like this:
10573
10574@example
10575(define my-package
10576 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
10577 (package
10578 (version (string-append "0.9-1."
10579 (string-take commit 7)))
10580 (source (origin
10581 (method git-fetch)
10582 (uri (git-reference
10583 (url "git://example.org/my-package.git")
10584 (commit commit)))
10585 (sha256 (base32 "1mbikn@dots{}"))
10586 (file-name (string-append "my-package-" version
10587 "-checkout"))))
10588 ;; @dots{}
10589 )))
10590@end example
880d647d 10591
cbd02397
LC
10592@node Synopses and Descriptions
10593@subsection Synopses and Descriptions
10594
10595As we have seen before, each package in GNU@tie{}Guix includes a
10596synopsis and a description (@pxref{Defining Packages}). Synopses and
10597descriptions are important: They are what @command{guix package
10598--search} searches, and a crucial piece of information to help users
10599determine whether a given package suits their needs. Consequently,
10600packagers should pay attention to what goes into them.
10601
10602Synopses must start with a capital letter and must not end with a
10603period. They must not start with ``a'' or ``the'', which usually does
10604not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10605tool that frobs files''. The synopsis should say what the package
10606is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10607used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10608matching a pattern''.
10609
10610Keep in mind that the synopsis must be meaningful for a very wide
10611audience. For example, ``Manipulate alignments in the SAM format''
10612might make sense for a seasoned bioinformatics researcher, but might be
10613fairly unhelpful or even misleading to a non-specialized audience. It
10614is a good idea to come up with a synopsis that gives an idea of the
10615application domain of the package. In this example, this might give
10616something like ``Manipulate nucleotide sequence alignments'', which
10617hopefully gives the user a better idea of whether this is what they are
10618looking for.
10619
10620@cindex Texinfo markup, in package descriptions
10621Descriptions should take between five and ten lines. Use full
10622sentences, and avoid using acronyms without first introducing them.
10623Descriptions can include Texinfo markup, which is useful to introduce
10624ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
10625hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10626should be careful when using some characters for example @samp{@@} and
10627curly braces which are the basic special characters in Texinfo
10628(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10629such as @command{guix package --show} take care of rendering it
10630appropriately.
cbd02397
LC
10631
10632Synopses and descriptions are translated by volunteers
10633@uref{http://translationproject.org/domain/guix-packages.html, at the
10634Translation Project} so that as many users as possible can read them in
10635their native language. User interfaces search them and display them in
10636the language specified by the current locale.
10637
10638Translation is a lot of work so, as a packager, please pay even more
10639attention to your synopses and descriptions as every change may entail
ba7d6c76 10640additional work for translators. In order to help them, it is possible
36743e71 10641to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
10642special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10643Gettext}):
10644
10645@example
10646;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10647(description "ARandR is designed to provide a simple visual front end
10648for the X11 resize-and-rotate (RandR) extension. @dots{}")
10649@end example
cbd02397 10650
ef5dd60a 10651
cf4a9129
LC
10652@node Python Modules
10653@subsection Python Modules
ef5dd60a 10654
cf4a9129
LC
10655We currently package Python 2 and Python 3, under the Scheme variable names
10656@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10657To avoid confusion and naming clashes with other programming languages, it
10658seems desirable that the name of a package for a Python module contains
10659the word @code{python}.
ef5dd60a 10660
cf4a9129
LC
10661Some modules are compatible with only one version of Python, others with both.
10662If the package Foo compiles only with Python 3, we name it
10663@code{python-foo}; if it compiles only with Python 2, we name it
10664@code{python2-foo}. If it is compatible with both versions, we create two
10665packages with the corresponding names.
ef5dd60a 10666
cf4a9129
LC
10667If a project already contains the word @code{python}, we drop this;
10668for instance, the module python-dateutil is packaged under the names
10669@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10670
523e4896 10671
cf4a9129
LC
10672@node Perl Modules
10673@subsection Perl Modules
523e4896 10674
cf4a9129
LC
10675Perl programs standing for themselves are named as any other package,
10676using the lowercase upstream name.
10677For Perl packages containing a single class, we use the lowercase class name,
10678replace all occurrences of @code{::} by dashes and prepend the prefix
10679@code{perl-}.
10680So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10681Modules containing several classes keep their lowercase upstream name and
10682are also prepended by @code{perl-}. Such modules tend to have the word
10683@code{perl} somewhere in their name, which gets dropped in favor of the
10684prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10685
523e4896 10686
7fec52b7
AE
10687@node Fonts
10688@subsection Fonts
10689
10690For fonts that are in general not installed by a user for typesetting
10691purposes, or that are distributed as part of a larger software package,
10692we rely on the general packaging rules for software; for instance, this
10693applies to the fonts delivered as part of the X.Org system or fonts that
10694are part of TeX Live.
10695
10696To make it easier for a user to search for fonts, names for other packages
10697containing only fonts are constructed as follows, independently of the
10698upstream package name.
10699
10700The name of a package containing only one font family starts with
10701@code{font-}; it is followed by the foundry name and a dash @code{-}
10702if the foundry is known, and the font family name, in which spaces are
10703replaced by dashes (and as usual, all upper case letters are transformed
10704to lower case).
10705For example, the Gentium font family by SIL is packaged under the name
10706@code{font-sil-gentium}.
10707
10708For a package containing several font families, the name of the collection
10709is used in the place of the font family name.
10710For instance, the Liberation fonts consist of three families,
10711Liberation Sans, Liberation Serif and Liberation Mono.
10712These could be packaged separately under the names
10713@code{font-liberation-sans} and so on; but as they are distributed together
10714under a common name, we prefer to package them together as
10715@code{font-liberation}.
10716
10717In the case where several formats of the same font family or font collection
10718are packaged separately, a short form of the format, prepended by a dash,
10719is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10720@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10721fonts.
10722
10723
b25937e3 10724
cf4a9129
LC
10725@node Bootstrapping
10726@section Bootstrapping
b25937e3 10727
cf4a9129 10728@c Adapted from the ELS 2013 paper.
b25937e3 10729
cf4a9129 10730@cindex bootstrapping
7889394e 10731
cf4a9129
LC
10732Bootstrapping in our context refers to how the distribution gets built
10733``from nothing''. Remember that the build environment of a derivation
10734contains nothing but its declared inputs (@pxref{Introduction}). So
10735there's an obvious chicken-and-egg problem: how does the first package
10736get built? How does the first compiler get compiled? Note that this is
10737a question of interest only to the curious hacker, not to the regular
10738user, so you can shamelessly skip this section if you consider yourself
10739a ``regular user''.
72b9d60d 10740
cf4a9129
LC
10741@cindex bootstrap binaries
10742The GNU system is primarily made of C code, with libc at its core. The
10743GNU build system itself assumes the availability of a Bourne shell and
10744command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10745`grep'. Furthermore, build programs---programs that run
10746@code{./configure}, @code{make}, etc.---are written in Guile Scheme
10747(@pxref{Derivations}). Consequently, to be able to build anything at
10748all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10749Binutils, libc, and the other packages mentioned above---the
10750@dfn{bootstrap binaries}.
72b9d60d 10751
cf4a9129
LC
10752These bootstrap binaries are ``taken for granted'', though we can also
10753re-create them if needed (more on that later).
72b9d60d 10754
cf4a9129 10755@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 10756
cf4a9129
LC
10757@c As of Emacs 24.3, Info-mode displays the image, but since it's a
10758@c large image, it's hard to scroll. Oh well.
10759@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 10760
cf4a9129
LC
10761The figure above shows the very beginning of the dependency graph of the
10762distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
10763packages bootstrap)} module. A similar figure can be generated with
10764@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
10765
10766@example
10767guix graph -t derivation \
10768 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
10769 | dot -Tps > t.ps
10770@end example
10771
10772At this level of detail, things are
cf4a9129
LC
10773slightly complex. First, Guile itself consists of an ELF executable,
10774along with many source and compiled Scheme files that are dynamically
10775loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10776tarball shown in this graph. This tarball is part of Guix's ``source''
10777distribution, and gets inserted into the store with @code{add-to-store}
10778(@pxref{The Store}).
2e7b5cea 10779
cf4a9129
LC
10780But how do we write a derivation that unpacks this tarball and adds it
10781to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10782derivation---the first one that gets built---uses @code{bash} as its
10783builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10784@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10785@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10786the Guix source distribution, whose sole purpose is to allow the Guile
10787tarball to be unpacked.
fb729425 10788
cf4a9129
LC
10789Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10790Guile that can be used to run subsequent build programs. Its first task
10791is to download tarballs containing the other pre-built binaries---this
10792is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10793@code{ftp-client.scm} are used for this purpose. The
10794@code{module-import.drv} derivations import those modules in a directory
10795in the store, using the original layout. The
10796@code{module-import-compiled.drv} derivations compile those modules, and
10797write them in an output directory with the right layout. This
10798corresponds to the @code{#:modules} argument of
10799@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 10800
cf4a9129
LC
10801Finally, the various tarballs are unpacked by the
10802derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10803etc., at which point we have a working C tool chain.
fb729425 10804
fb729425 10805
cf4a9129 10806@unnumberedsubsec Building the Build Tools
523e4896 10807
cf4a9129
LC
10808Bootstrapping is complete when we have a full tool chain that does not
10809depend on the pre-built bootstrap tools discussed above. This
10810no-dependency requirement is verified by checking whether the files of
10811the final tool chain contain references to the @file{/gnu/store}
10812directories of the bootstrap inputs. The process that leads to this
10813``final'' tool chain is described by the package definitions found in
1f6f57df 10814the @code{(gnu packages commencement)} module.
df2ce343 10815
d33fa0c7
LC
10816The @command{guix graph} command allows us to ``zoom out'' compared to
10817the graph above, by looking at the level of package objects instead of
10818individual derivations---remember that a package may translate to
10819several derivations, typically one derivation to download its source,
10820one to build the Guile modules it needs, and one to actually build the
10821package from source. The command:
10822
10823@example
10824guix graph -t bag \
10825 -e '(@@@@ (gnu packages commencement)
10826 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
10827@end example
10828
10829@noindent
10830produces the dependency graph leading to the ``final'' C
10831library@footnote{You may notice the @code{glibc-intermediate} label,
10832suggesting that it is not @emph{quite} final, but as a good
10833approximation, we will consider it final.}, depicted below.
10834
10835@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
10836
cf4a9129
LC
10837@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10838The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
10839GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
10840for all the following packages. From there Findutils and Diffutils get
10841built.
523e4896 10842
cf4a9129
LC
10843Then come the first-stage Binutils and GCC, built as pseudo cross
10844tools---i.e., with @code{--target} equal to @code{--host}. They are
10845used to build libc. Thanks to this cross-build trick, this libc is
10846guaranteed not to hold any reference to the initial tool chain.
4af2447e 10847
d33fa0c7
LC
10848From there the final Binutils and GCC (not shown above) are built.
10849GCC uses @code{ld}
cf4a9129
LC
10850from the final Binutils, and links programs against the just-built libc.
10851This tool chain is used to build the other packages used by Guix and by
10852the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 10853
cf4a9129
LC
10854And voilà! At this point we have the complete set of build tools that
10855the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
10856variable of the @code{(gnu packages commencement)} module, and are
10857implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 10858(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 10859
4af2447e 10860
cf4a9129 10861@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 10862
cf4a9129
LC
10863Because the final tool chain does not depend on the bootstrap binaries,
10864those rarely need to be updated. Nevertheless, it is useful to have an
10865automated way to produce them, should an update occur, and this is what
10866the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 10867
cf4a9129
LC
10868The following command builds the tarballs containing the bootstrap
10869binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10870of Coreutils and other basic command-line tools):
4b2615e1 10871
cf4a9129
LC
10872@example
10873guix build bootstrap-tarballs
10874@end example
10875
10876The generated tarballs are those that should be referred to in the
10877@code{(gnu packages bootstrap)} module mentioned at the beginning of
10878this section.
10879
10880Still here? Then perhaps by now you've started to wonder: when do we
10881reach a fixed point? That is an interesting question! The answer is
10882unknown, but if you would like to investigate further (and have
10883significant computational and storage resources to do so), then let us
10884know.
10885
10886@node Porting
10887@section Porting to a New Platform
10888
10889As discussed above, the GNU distribution is self-contained, and
10890self-containment is achieved by relying on pre-built ``bootstrap
10891binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10892operating system kernel, CPU architecture, and application binary
10893interface (ABI). Thus, to port the distribution to a platform that is
10894not yet supported, one must build those bootstrap binaries, and update
10895the @code{(gnu packages bootstrap)} module to use them on that platform.
10896
10897Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10898When everything goes well, and assuming the GNU tool chain supports the
10899target platform, this can be as simple as running a command like this
10900one:
10901
10902@example
10903guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10904@end example
10905
1c0c417d
LC
10906For this to work, the @code{glibc-dynamic-linker} procedure in
10907@code{(gnu packages bootstrap)} must be augmented to return the right
10908file name for libc's dynamic linker on that platform; likewise,
10909@code{system->linux-architecture} in @code{(gnu packages linux)} must be
10910taught about the new platform.
10911
cf4a9129 10912Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
10913to be updated to refer to these binaries on the target platform. That
10914is, the hashes and URLs of the bootstrap tarballs for the new platform
10915must be added alongside those of the currently supported platforms. The
10916bootstrap Guile tarball is treated specially: it is expected to be
10917available locally, and @file{gnu-system.am} has rules do download it for
10918the supported architectures; a rule for the new platform must be added
10919as well.
cf4a9129
LC
10920
10921In practice, there may be some complications. First, it may be that the
10922extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10923above) is not recognized by all the GNU tools. Typically, glibc
10924recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10925configure flag (see @code{gcc.scm} for examples of how to handle this).
10926Second, some of the required packages could fail to build for that
10927platform. Lastly, the generated binaries could be broken for some
10928reason.
4af2447e 10929
9bf3c1a7 10930@c *********************************************************************
8c01b9d0 10931@include contributing.texi
c78bd12b 10932
568717fd
LC
10933@c *********************************************************************
10934@node Acknowledgments
10935@chapter Acknowledgments
10936
136787cb
LC
10937Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10938which was designed and
4c7ac9aa
LC
10939implemented by Eelco Dolstra, with contributions from other people (see
10940the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
10941management, and promoted unprecedented features, such as transactional
10942package upgrades and rollbacks, per-user profiles, and referentially
10943transparent build processes. Without this work, Guix would not exist.
10944
10945The Nix-based software distributions, Nixpkgs and NixOS, have also been
10946an inspiration for Guix.
10947
4c7ac9aa
LC
10948GNU@tie{}Guix itself is a collective work with contributions from a
10949number of people. See the @file{AUTHORS} file in Guix for more
10950information on these fine people. The @file{THANKS} file lists people
10951who have helped by reporting bugs, taking care of the infrastructure,
10952providing artwork and themes, making suggestions, and more---thank you!
10953
10954
568717fd
LC
10955@c *********************************************************************
10956@node GNU Free Documentation License
10957@appendix GNU Free Documentation License
10958
10959@include fdl-1.3.texi
10960
10961@c *********************************************************************
10962@node Concept Index
10963@unnumbered Concept Index
10964@printindex cp
10965
a85b83d2
LC
10966@node Programming Index
10967@unnumbered Programming Index
10968@syncodeindex tp fn
10969@syncodeindex vr fn
568717fd
LC
10970@printindex fn
10971
10972@bye
10973
10974@c Local Variables:
10975@c ispell-local-dictionary: "american";
10976@c End: