store: 'references/substitutes' correctly handles the order of substitutes.
[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
3839guix build --keep-going \
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
34a1783f
DT
4073@item --file=@var{file}
4074@itemx -f @var{file}
4075
4076Build the package or derivation that the code within @var{file}
4077evaluates to.
4078
4079As an example, @var{file} might contain a package definition like this
4080(@pxref{Defining Packages}):
4081
4082@example
4083@verbatiminclude package-hello.scm
4084@end example
4085
c78bd12b
LC
4086@item --expression=@var{expr}
4087@itemx -e @var{expr}
ac5de156 4088Build the package or derivation @var{expr} evaluates to.
c78bd12b 4089
5401dd75 4090For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
4091guile-1.8)}, which unambiguously designates this specific variant of
4092version 1.8 of Guile.
4093
f97c9175 4094Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
4095as a build program passed to @code{gexp->derivation}
4096(@pxref{G-Expressions}).
4097
4098Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
4099(@pxref{The Store Monad}). The procedure must return a derivation as a
4100monadic value, which is then passed through @code{run-with-store}.
4101
c78bd12b
LC
4102@item --source
4103@itemx -S
f97c9175 4104Build the source derivations of the packages, rather than the packages
c78bd12b
LC
4105themselves.
4106
e49951eb 4107For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
4108@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4109source tarball.
c78bd12b 4110
f9cc8971 4111The returned source tarball is the result of applying any patches and
f97c9175 4112code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
4113Packages}).
4114
2cdfe13d
EB
4115@item --sources
4116Fetch and return the source of @var{package-or-derivation} and all their
4117dependencies, recursively. This is a handy way to obtain a local copy
4118of all the source code needed to build @var{packages}, allowing you to
4119eventually build them even without network access. It is an extension
4120of the @code{--source} option and can accept one of the following
4121optional argument values:
4122
4123@table @code
4124@item package
4125This value causes the @code{--sources} option to behave in the same way
4126as the @code{--source} option.
4127
4128@item all
f97c9175
AE
4129Build the source derivations of all packages, including any source that
4130might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
4131
4132@example
4133$ guix build --sources tzdata
4134The following derivations will be built:
4135 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4136 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4137@end example
4138
4139@item transitive
f97c9175
AE
4140Build the source derivations of all packages, as well of all transitive
4141inputs to the packages. This can be used e.g. to
2cdfe13d
EB
4142prefetch package source for later offline building.
4143
4144@example
4145$ guix build --sources=transitive tzdata
4146The following derivations will be built:
4147 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4148 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4149 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4150 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4151 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4152 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4153@dots{}
4154@end example
4155
4156@end table
4157
c78bd12b
LC
4158@item --system=@var{system}
4159@itemx -s @var{system}
4160Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 4161the system type of the build host.
c78bd12b
LC
4162
4163An example use of this is on Linux-based systems, which can emulate
4164different personalities. For instance, passing
4165@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4166to build packages in a complete 32-bit environment.
4167
e55ec43d
LC
4168@item --target=@var{triplet}
4169@cindex cross-compilation
4170Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4171as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4172configuration triplets,, configure, GNU Configure and Build System}).
4173
a8d65643
LC
4174@anchor{build-check}
4175@item --check
4176@cindex determinism, checking
4177@cindex reproducibility, checking
4178Rebuild @var{package-or-derivation}, which are already available in the
4179store, and raise an error if the build results are not bit-for-bit
4180identical.
4181
f97c9175
AE
4182This mechanism allows you to check whether previously installed
4183substitutes are genuine (@pxref{Substitutes}), or whether the build result
4184of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
4185background information and tools.
4186
c78bd12b
LC
4187@item --derivations
4188@itemx -d
4189Return the derivation paths, not the output paths, of the given
4190packages.
4191
70ee5642
LC
4192@item --root=@var{file}
4193@itemx -r @var{file}
4194Make @var{file} a symlink to the result, and register it as a garbage
4195collector root.
4196
4197@item --log-file
3f208ad7 4198Return the build log file names or URLs for the given
f97c9175 4199@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
4200missing.
4201
4202This works regardless of how packages or derivations are specified. For
4203instance, the following invocations are equivalent:
4204
4205@example
4206guix build --log-file `guix build -d guile`
4207guix build --log-file `guix build guile`
4208guix build --log-file guile
4209guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4210@end example
4211
3f208ad7
LC
4212If a log is unavailable locally, and unless @code{--no-substitutes} is
4213passed, the command looks for a corresponding log on one of the
4214substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 4215
f97c9175
AE
4216So for instance, imagine you want to see the build log of GDB on MIPS,
4217but you are actually on an @code{x86_64} machine:
3f208ad7
LC
4218
4219@example
4220$ guix build --log-file gdb -s mips64el-linux
4221http://hydra.gnu.org/log/@dots{}-gdb-7.10
4222@end example
4223
4224You can freely access a huge library of build logs!
70ee5642
LC
4225@end table
4226
16eb115e 4227
39bee8a2
LC
4228@node Invoking guix edit
4229@section Invoking @command{guix edit}
4230
4231@cindex package definition, editing
4232So many packages, so many source files! The @command{guix edit} command
4233facilitates the life of packagers by pointing their editor at the source
4234file containing the definition of the specified packages. For instance:
4235
4236@example
4237guix edit gcc-4.8 vim
4238@end example
4239
4240@noindent
6237b9fa
LC
4241launches the program specified in the @code{VISUAL} or in the
4242@code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4243and that of Vim.
39bee8a2 4244
f97c9175 4245If you are using Emacs, note that the Emacs user interface provides the
7c1b1ae2 4246@kbd{M-x guix-edit} command and a similar functionality in the ``package
f97c9175 4247info'' and ``package list'' buffers created by the @kbd{M-x
7c1b1ae2 4248guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
39bee8a2
LC
4249
4250
210cc920
LC
4251@node Invoking guix download
4252@section Invoking @command{guix download}
4253
4254When writing a package definition, developers typically need to download
f97c9175 4255a source tarball, compute its SHA256 hash, and write that
210cc920
LC
4256hash in the package definition (@pxref{Defining Packages}). The
4257@command{guix download} tool helps with this task: it downloads a file
4258from the given URI, adds it to the store, and prints both its file name
4259in the store and its SHA256 hash.
4260
4261The fact that the downloaded file is added to the store saves bandwidth:
4262when the developer eventually tries to build the newly defined package
4263with @command{guix build}, the source tarball will not have to be
4264downloaded again because it is already in the store. It is also a
4265convenient way to temporarily stash files, which may be deleted
4266eventually (@pxref{Invoking guix gc}).
4267
4268The @command{guix download} command supports the same URIs as used in
4269package definitions. In particular, it supports @code{mirror://} URIs.
4270@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4271Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4272they are not available, an error is raised. @xref{Guile Preparations,
4273how to install the GnuTLS bindings for Guile,, gnutls-guile,
4274GnuTLS-Guile}, for more information.
210cc920
LC
4275
4276The following option is available:
4277
4278@table @code
4279@item --format=@var{fmt}
4280@itemx -f @var{fmt}
4281Write the hash in the format specified by @var{fmt}. For more
081145cf 4282information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
4283@end table
4284
6c365eca
NK
4285@node Invoking guix hash
4286@section Invoking @command{guix hash}
4287
210cc920 4288The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4289It is primarily a convenience tool for anyone contributing to the
4290distribution: it computes the cryptographic hash of a file, which can be
4291used in the definition of a package (@pxref{Defining Packages}).
4292
4293The general syntax is:
4294
4295@example
4296guix hash @var{option} @var{file}
4297@end example
4298
4299@command{guix hash} has the following option:
4300
4301@table @code
4302
4303@item --format=@var{fmt}
4304@itemx -f @var{fmt}
210cc920 4305Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4306
4307Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4308(@code{hex} and @code{hexadecimal} can be used as well).
4309
4310If the @option{--format} option is not specified, @command{guix hash}
4311will output the hash in @code{nix-base32}. This representation is used
4312in the definitions of packages.
4313
3140f2df
LC
4314@item --recursive
4315@itemx -r
4316Compute the hash on @var{file} recursively.
4317
4318In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
4319including its children if it is a directory. Some of the metadata of
4320@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 4321regular file, the hash is different depending on whether @var{file} is
f97c9175 4322executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
4323hash (@pxref{Invoking guix archive}).
4324@c FIXME: Replace xref above with xref to an ``Archive'' section when
4325@c it exists.
4326
6c365eca
NK
4327@end table
4328
2f7d2d91
LC
4329@node Invoking guix import
4330@section Invoking @command{guix import}
4331
4332@cindex importing packages
4333@cindex package import
4334@cindex package conversion
f97c9175
AE
4335The @command{guix import} command is useful for people who would like to
4336add a package to the distribution with as little work as
4337possible---a legitimate demand. The command knows of a few
4338repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
4339is a package definition, or a template thereof, in the format we know
4340(@pxref{Defining Packages}).
4341
4342The general syntax is:
4343
4344@example
4345guix import @var{importer} @var{options}@dots{}
4346@end example
4347
4348@var{importer} specifies the source from which to import package
f97c9175 4349metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
4350options specific to @var{importer}. Currently, the available
4351``importers'' are:
4352
4353@table @code
4354@item gnu
f97c9175 4355Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
4356for the latest version of that GNU package, including the hash of its
4357source tarball, and its canonical synopsis and description.
4358
f97c9175 4359Additional information such as the package dependencies and its
2f7d2d91
LC
4360license needs to be figured out manually.
4361
4362For example, the following command returns a package definition for
4363GNU@tie{}Hello:
4364
4365@example
4366guix import gnu hello
4367@end example
4368
4369Specific command-line options are:
4370
4371@table @code
4372@item --key-download=@var{policy}
4373As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 4374keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
4375refresh, @code{--key-download}}.
4376@end table
4377
4378@item pypi
4379@cindex pypi
f97c9175 4380Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
4381Index}@footnote{This functionality requires Guile-JSON to be installed.
4382@xref{Requirements}.}. Information is taken from the JSON-formatted
4383description available at @code{pypi.python.org} and usually includes all
4384the relevant information, including package dependencies.
4385
f97c9175 4386The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
4387package:
4388
4389@example
4390guix import pypi itsdangerous
4391@end example
4392
3aae8145
DT
4393@item gem
4394@cindex gem
f97c9175 4395Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
4396RubyGems}@footnote{This functionality requires Guile-JSON to be
4397installed. @xref{Requirements}.}. Information is taken from the
4398JSON-formatted description available at @code{rubygems.org} and includes
4399most relevant information, including runtime dependencies. There are
f97c9175 4400some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
4401synopses and descriptions, so the same string is used for both fields.
4402Additionally, the details of non-Ruby dependencies required to build
4403native extensions is unavailable and left as an exercise to the
4404packager.
4405
f97c9175 4406The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
4407
4408@example
4409guix import gem rails
4410@end example
4411
d45dc6da
EB
4412@item cpan
4413@cindex CPAN
3c192e4e
AE
4414Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4415functionality requires Guile-JSON to be installed.
4416@xref{Requirements}.}.
f97c9175 4417Information is taken from the JSON-formatted metadata provided through
d45dc6da 4418@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4419relevant information, such as module dependencies. License information
4420should be checked closely. If Perl is available in the store, then the
4421@code{corelist} utility will be used to filter core modules out of the
4422list of dependencies.
d45dc6da 4423
f97c9175 4424The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
4425Perl module:
4426
4427@example
4428guix import cpan Acme::Boolean
4429@end example
4430
e1248602
RW
4431@item cran
4432@cindex CRAN
d0bd632f 4433@cindex Bioconductor
f97c9175 4434Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
4435central repository for the @uref{http://r-project.org, GNU@tie{}R
4436statistical and graphical environment}.
4437
f97c9175 4438Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 4439
f97c9175 4440The command command below imports metadata for the @code{Cairo}
e1248602
RW
4441R package:
4442
4443@example
4444guix import cran Cairo
4445@end example
4446
f97c9175 4447When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
4448@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4449packages for for the analysis and comprehension of high-throughput
4450genomic data in bioinformatics.
4451
f97c9175 4452Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
4453published on the web interface of the Bioconductor SVN repository.
4454
f97c9175 4455The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
4456R package:
4457
4458@example
4459guix import cran --archive=bioconductor GenomicRanges
4460@end example
4461
2f7d2d91 4462@item nix
f97c9175 4463Import metadata from a local copy of the source of the
2f7d2d91
LC
4464@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4465relies on the @command{nix-instantiate} command of
4466@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4467typically written in a mixture of Nix-language and Bash code. This
4468command only imports the high-level package structure that is written in
4469the Nix language. It normally includes all the basic fields of a
4470package definition.
4471
4472When importing a GNU package, the synopsis and descriptions are replaced
4473by their canonical upstream variant.
4474
961d0d2d
LC
4475Usually, you will first need to do:
4476
4477@example
4478export NIX_REMOTE=daemon
4479@end example
4480
4481@noindent
4482so that @command{nix-instantiate} does not try to open the Nix database.
4483
2f7d2d91
LC
4484As an example, the command below imports the package definition of
4485LibreOffice (more precisely, it imports the definition of the package
4486bound to the @code{libreoffice} top-level attribute):
4487
4488@example
4489guix import nix ~/path/to/nixpkgs libreoffice
4490@end example
863af4e1
FB
4491
4492@item hackage
4493@cindex hackage
f97c9175 4494Import metadata from the Haskell community's central package archive
863af4e1
FB
4495@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4496Cabal files and includes all the relevant information, including package
4497dependencies.
4498
4499Specific command-line options are:
4500
4501@table @code
a4154748
FB
4502@item --stdin
4503@itemx -s
f97c9175 4504Read a Cabal file from standard input.
863af4e1
FB
4505@item --no-test-dependencies
4506@itemx -t
f97c9175 4507Do not include dependencies required only by the test suites.
a4154748
FB
4508@item --cabal-environment=@var{alist}
4509@itemx -e @var{alist}
4510@var{alist} is a Scheme alist defining the environment in which the
4511Cabal conditionals are evaluated. The accepted keys are: @code{os},
4512@code{arch}, @code{impl} and a string representing the name of a flag.
4513The value associated with a flag has to be either the symbol
4514@code{true} or @code{false}. The value associated with other keys
4515has to conform to the Cabal file format definition. The default value
4516associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 4517@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
4518@end table
4519
f97c9175 4520The command below imports metadata for the latest version of the
a4154748
FB
4521@code{HTTP} Haskell package without including test dependencies and
4522specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4523
4524@example
a4154748 4525guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4526@end example
4527
4528A specific package version may optionally be specified by following the
1b846da8 4529package name by an at-sign and a version number as in the following example:
863af4e1
FB
4530
4531@example
1b846da8 4532guix import hackage mtl@@2.1.3.1
863af4e1 4533@end example
7f74a931
FB
4534
4535@item elpa
4536@cindex elpa
f97c9175 4537Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
4538repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4539
4540Specific command-line options are:
4541
4542@table @code
4543@item --archive=@var{repo}
4544@itemx -a @var{repo}
4545@var{repo} identifies the archive repository from which to retrieve the
4546information. Currently the supported repositories and their identifiers
4547are:
4548@itemize -
4549@item
840bd1d3 4550@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4551identifier. This is the default.
4552
4553@item
840bd1d3 4554@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4555@code{melpa-stable} identifier.
4556
4557@item
840bd1d3 4558@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4559identifier.
4560@end itemize
4561@end table
2f7d2d91
LC
4562@end table
4563
4564The structure of the @command{guix import} code is modular. It would be
4565useful to have more importers for other package formats, and your help
4566is welcome here (@pxref{Contributing}).
4567
37166310
LC
4568@node Invoking guix refresh
4569@section Invoking @command{guix refresh}
4570
4571The primary audience of the @command{guix refresh} command is developers
4572of the GNU software distribution. By default, it reports any packages
4573provided by the distribution that are outdated compared to the latest
4574upstream version, like this:
4575
4576@example
4577$ guix refresh
4578gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4579gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4580@end example
4581
f97c9175
AE
4582It does so by browsing the FTP directory of each package and determining
4583the highest version number of the source tarballs therein. The command
bcb571cb
LC
4584knows how to update specific types of packages: GNU packages, ELPA
4585packages, etc.---see the documentation for @option{--type} below. The
4586are many packages, though, for which it lacks a method to determine
4587whether a new upstream release is available. However, the mechanism is
4588extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4589
4590When passed @code{--update}, it modifies distribution source files to
f97c9175 4591update the version numbers and source tarball hashes of those package
37166310
LC
4592recipes (@pxref{Defining Packages}). This is achieved by downloading
4593each package's latest source tarball and its associated OpenPGP
4594signature, authenticating the downloaded tarball against its signature
4595using @command{gpg}, and finally computing its hash. When the public
4596key used to sign the tarball is missing from the user's keyring, an
4597attempt is made to automatically retrieve it from a public key server;
f97c9175 4598when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
4599@command{guix refresh} reports an error.
4600
4601The following options are supported:
4602
4603@table @code
4604
2d7fc7da
LC
4605@item --expression=@var{expr}
4606@itemx -e @var{expr}
4607Consider the package @var{expr} evaluates to.
4608
4609This is useful to precisely refer to a package, as in this example:
4610
4611@example
4612guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4613@end example
4614
4615This command lists the dependents of the ``final'' libc (essentially all
4616the packages.)
4617
37166310
LC
4618@item --update
4619@itemx -u
38e16b49
LC
4620Update distribution source files (package recipes) in place. This is
4621usually run from a checkout of the Guix source tree (@pxref{Running
4622Guix Before It Is Installed}):
4623
4624@example
4625$ ./pre-inst-env guix refresh -s non-core
4626@end example
4627
081145cf 4628@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4629
4630@item --select=[@var{subset}]
4631@itemx -s @var{subset}
4632Select all the packages in @var{subset}, one of @code{core} or
4633@code{non-core}.
4634
4635The @code{core} subset refers to all the packages at the core of the
4636distribution---i.e., packages that are used to build ``everything
4637else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4638changing one of these packages in the distribution entails a rebuild of
4639all the others. Thus, such updates are an inconvenience to users in
4640terms of build time or bandwidth used to achieve the upgrade.
4641
4642The @code{non-core} subset refers to the remaining packages. It is
4643typically useful in cases where an update of the core packages would be
4644inconvenient.
4645
bcb571cb
LC
4646@item --type=@var{updater}
4647@itemx -t @var{updater}
7191adc5
AK
4648Select only packages handled by @var{updater} (may be a comma-separated
4649list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
4650
4651@table @code
4652@item gnu
4653the updater for GNU packages;
e80c0f85
LC
4654@item gnome
4655the updater for GNOME packages;
62061d6b
AW
4656@item xorg
4657the updater for X.org packages;
bcb571cb 4658@item elpa
d882c235
LC
4659the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4660@item cran
b9d044ef 4661the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
4662@item bioconductor
4663the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
bab020d7 4664@item pypi
b9d044ef 4665the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
4666@item gem
4667the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
4668@item github
4669the updater for @uref{https://github.com, GitHub} packages.
bcb571cb
LC
4670@end table
4671
f97c9175
AE
4672For instance, the following command only checks for updates of Emacs
4673packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
4674
4675@example
7191adc5 4676$ guix refresh --type=elpa,cran
d882c235 4677gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4678gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4679@end example
4680
37166310
LC
4681@end table
4682
4683In addition, @command{guix refresh} can be passed one or more package
4684names, as in this example:
4685
4686@example
38e16b49 4687$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4688@end example
4689
4690@noindent
4691The command above specifically updates the @code{emacs} and
4692@code{idutils} packages. The @code{--select} option would have no
4693effect in this case.
4694
7d193ec3
EB
4695When considering whether to upgrade a package, it is sometimes
4696convenient to know which packages would be affected by the upgrade and
4697should be checked for compatibility. For this the following option may
4698be used when passing @command{guix refresh} one or more package names:
4699
4700@table @code
4701
6ffa706b
AK
4702@item --list-updaters
4703@itemx -L
4704List available updaters and exit (see @option{--type} above.)
4705
7d193ec3
EB
4706@item --list-dependent
4707@itemx -l
4708List top-level dependent packages that would need to be rebuilt as a
4709result of upgrading one or more packages.
4710
4711@end table
4712
4713Be aware that the @code{--list-dependent} option only
4714@emph{approximates} the rebuilds that would be required as a result of
4715an upgrade. More rebuilds might be required under some circumstances.
4716
4717@example
7779ab61
LC
4718$ guix refresh --list-dependent flex
4719Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4720hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4721@end example
4722
4723The command above lists a set of packages that could be built to check
4724for compatibility with an upgraded @code{flex} package.
4725
f9230085
LC
4726The following options can be used to customize GnuPG operation:
4727
4728@table @code
4729
f9230085
LC
4730@item --gpg=@var{command}
4731Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4732for in @code{$PATH}.
4733
2bc53ba9
LC
4734@item --key-download=@var{policy}
4735Handle missing OpenPGP keys according to @var{policy}, which may be one
4736of:
4737
4738@table @code
4739@item always
4740Always download missing OpenPGP keys from the key server, and add them
4741to the user's GnuPG keyring.
4742
4743@item never
4744Never try to download missing OpenPGP keys. Instead just bail out.
4745
4746@item interactive
4747When a package signed with an unknown OpenPGP key is encountered, ask
4748the user whether to download it or not. This is the default behavior.
4749@end table
4750
4751@item --key-server=@var{host}
4752Use @var{host} as the OpenPGP key server when importing a public key.
4753
f9230085
LC
4754@end table
4755
917a2a58
BW
4756The @code{github} updater uses the
4757@uref{https://developer.github.com/v3/, GitHub API} to query for new
4758releases. When used repeatedly e.g. when refreshing all packages,
4759GitHub will eventually refuse to answer any further API requests. By
4760default 60 API requests per hour are allowed, and a full refresh on all
4761GitHub packages in Guix requires more than this. Authentication with
4762GitHub through the use of an API token alleviates these limits. To use
4763an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
4764token procured from @uref{https://github.com/settings/tokens} or
4765otherwise.
4766
4767
b4f5e0e8
CR
4768@node Invoking guix lint
4769@section Invoking @command{guix lint}
f97c9175
AE
4770The @command{guix lint} command is meant to help package developers avoid
4771common errors and use a consistent style. It runs a number of checks on
4772a given set of packages in order to find common mistakes in their
873c4085
LC
4773definitions. Available @dfn{checkers} include (see
4774@code{--list-checkers} for a complete list):
4775
4776@table @code
4777@item synopsis
4778@itemx description
4779Validate certain typographical and stylistic rules about package
4780descriptions and synopses.
4781
4782@item inputs-should-be-native
4783Identify inputs that should most likely be native inputs.
4784
4785@item source
4786@itemx home-page
50f5c46d 4787@itemx source-file-name
873c4085 4788Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d 4789invalid. Check that the source file name is meaningful, e.g. is not
f97c9175
AE
4790just a version number or ``git-checkout'', without a declared
4791@code{file-name} (@pxref{origin Reference}).
40a7d4e5 4792
5432734b
LC
4793@item cve
4794Report known vulnerabilities found in the Common Vulnerabilities and
4795Exposures (CVE) database
4796@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4797NIST}.
4798
40a7d4e5
LC
4799@item formatting
4800Warn about obvious source code formatting issues: trailing white space,
4801use of tabulations, etc.
873c4085 4802@end table
b4f5e0e8
CR
4803
4804The general syntax is:
4805
4806@example
4807guix lint @var{options} @var{package}@dots{}
4808@end example
4809
4810If no package is given on the command line, then all packages are checked.
4811The @var{options} may be zero or more of the following:
4812
4813@table @code
f97c9175
AE
4814@item --list-checkers
4815@itemx -l
4816List and describe all the available checkers that will be run on packages
4817and exit.
b4f5e0e8 4818
dd7c013d
CR
4819@item --checkers
4820@itemx -c
4821Only enable the checkers specified in a comma-separated list using the
4822names returned by @code{--list-checkers}.
4823
b4f5e0e8 4824@end table
37166310 4825
fcc58db6
LC
4826@node Invoking guix size
4827@section Invoking @command{guix size}
4828
4829The @command{guix size} command helps package developers profile the
4830disk usage of packages. It is easy to overlook the impact of an
4831additional dependency added to a package, or the impact of using a
4832single output for a package that could easily be split (@pxref{Packages
f97c9175 4833with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
4834@command{guix size} can highlight.
4835
4836The command can be passed a package specification such as @code{gcc-4.8}
4837or @code{guile:debug}, or a file name in the store. Consider this
4838example:
4839
4840@example
4841$ guix size coreutils
4842store item total self
4843/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4844/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4845/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4846/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4847/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4848/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4849@end example
4850
4851@cindex closure
4852The store items listed here constitute the @dfn{transitive closure} of
4853Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4854would be returned by:
4855
4856@example
4857$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4858@end example
4859
f97c9175 4860Here the output shows three columns next to store items. The first column,
fcc58db6
LC
4861labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4862the store item---that is, its own size plus the size of all its
4863dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
4864item itself. The last column shows the ratio of the size of the item
4865itself to the space occupied by all the items listed here.
fcc58db6
LC
4866
4867In this example, we see that the closure of Coreutils weighs in at
486870@tie{}MiB, half of which is taken by libc. (That libc represents a
4869large fraction of the closure is not a problem @i{per se} because it is
4870always available on the system anyway.)
4871
4872When the package passed to @command{guix size} is available in the
4873store, @command{guix size} queries the daemon to determine its
4874dependencies, and measures its size in the store, similar to @command{du
4875-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4876Coreutils}).
4877
4878When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
4879reports information based on the available substitutes
4880(@pxref{Substitutes}). This makes it possible it to profile disk usage of
4881store items that are not even on disk, only available remotely.
fcc58db6 4882
a8f996c6 4883The available options are:
fcc58db6
LC
4884
4885@table @option
4886
d490d06e
LC
4887@item --substitute-urls=@var{urls}
4888Use substitute information from @var{urls}.
4889@xref{client-substitute-urls, the same option for @code{guix build}}.
4890
a8f996c6 4891@item --map-file=@var{file}
f97c9175 4892Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
4893
4894For the example above, the map looks like this:
4895
4896@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4897produced by @command{guix size}}
4898
4899This option requires that
4900@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4901installed and visible in Guile's module search path. When that is not
4902the case, @command{guix size} fails as it tries to load it.
4903
fcc58db6
LC
4904@item --system=@var{system}
4905@itemx -s @var{system}
4906Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4907
4908@end table
4909
88856916
LC
4910@node Invoking guix graph
4911@section Invoking @command{guix graph}
4912
4913@cindex DAG
4914Packages and their dependencies form a @dfn{graph}, specifically a
4915directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175
AE
4916mental model of the package DAG, so the @command{guix graph} command
4917provides a visual representation of the DAG. @command{guix graph}
4918emits a DAG representation in the input format of
88856916 4919@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
f97c9175 4920directly to the @command{dot} command of Graphviz. The general
88856916
LC
4921syntax is:
4922
4923@example
4924guix graph @var{options} @var{package}@dots{}
4925@end example
4926
4927For example, the following command generates a PDF file representing the
4928package DAG for the GNU@tie{}Core Utilities, showing its build-time
4929dependencies:
4930
4931@example
4932guix graph coreutils | dot -Tpdf > dag.pdf
4933@end example
4934
4935The output looks like this:
4936
4937@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4938
4939Nice little graph, no?
4940
f97c9175 4941But there is more than one graph! The one above is concise: it is the
88856916 4942graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
4943grep, etc. It is often useful to have such a concise graph, but
4944sometimes one may want to see more details. @command{guix graph} supports
4945several types of graphs, allowing you to choose the level of detail:
88856916
LC
4946
4947@table @code
4948@item package
f97c9175 4949This is the default type used in the example above. It shows the DAG of
88856916
LC
4950package objects, excluding implicit dependencies. It is concise, but
4951filters out many details.
4952
4953@item bag-emerged
4954This is the package DAG, @emph{including} implicit inputs.
4955
4956For instance, the following command:
4957
4958@example
4959guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
4960@end example
4961
4962... yields this bigger graph:
4963
4964@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
4965
4966At the bottom of the graph, we see all the implicit inputs of
4967@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
4968
f97c9175 4969Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
4970@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
4971here, for conciseness.
4972
4973@item bag
4974Similar to @code{bag-emerged}, but this time including all the bootstrap
4975dependencies.
4976
38b92daa
LC
4977@item bag-with-origins
4978Similar to @code{bag}, but also showing origins and their dependencies.
4979
88856916
LC
4980@item derivations
4981This is the most detailed representation: It shows the DAG of
4982derivations (@pxref{Derivations}) and plain store items. Compared to
4983the above representation, many additional nodes are visible, including
f97c9175 4984build scripts, patches, Guile modules, etc.
88856916
LC
4985
4986@end table
4987
f97c9175 4988All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
4989following graph type represents the @emph{run-time dependencies}:
4990
4991@table @code
4992@item references
4993This is the graph of @dfn{references} of a package output, as returned
4994by @command{guix gc --references} (@pxref{Invoking guix gc}).
4995
4996If the given package output is not available in the store, @command{guix
4997graph} attempts to obtain dependency information from substitutes.
4998@end table
4999
5000The available options are the following:
5001
5002@table @option
5003@item --type=@var{type}
5004@itemx -t @var{type}
5005Produce a graph output of @var{type}, where @var{type} must be one of
5006the values listed above.
5007
5008@item --list-types
5009List the supported graph types.
4c8f997a
LC
5010
5011@item --expression=@var{expr}
5012@itemx -e @var{expr}
5013Consider the package @var{expr} evaluates to.
5014
5015This is useful to precisely refer to a package, as in this example:
5016
5017@example
5018guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5019@end example
88856916
LC
5020@end table
5021
5022
372c4bbc
DT
5023@node Invoking guix environment
5024@section Invoking @command{guix environment}
5025
f5fd4fd2 5026@cindex reproducible build environments
fe36d84e 5027@cindex development environments
372c4bbc
DT
5028The purpose of @command{guix environment} is to assist hackers in
5029creating reproducible development environments without polluting their
5030package profile. The @command{guix environment} tool takes one or more
f97c9175 5031packages, builds all of their inputs, and creates a shell
372c4bbc
DT
5032environment to use them.
5033
5034The general syntax is:
5035
5036@example
5037guix environment @var{options} @var{package}@dots{}
5038@end example
5039
fe36d84e
LC
5040The following example spawns a new shell set up for the development of
5041GNU@tie{}Guile:
372c4bbc
DT
5042
5043@example
5044guix environment guile
5045@end example
5046
f97c9175
AE
5047If the needed dependencies are not built yet, @command{guix environment}
5048automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
5049version of the environment that @command{guix environment} was run in.
5050It contains the necessary search paths for building the given package
5051added to the existing environment variables. To create a ``pure''
f97c9175 5052environment, in which the original environment variables have been unset,
50500f7c
LC
5053use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5054environment variables such as @code{PATH} in their @file{~/.bashrc}
5055file. As a consequence, when @code{guix environment} launches it, Bash
5056may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5057environment variables. It is an error to define such environment
5058variables in @file{.bashrc}; instead, they should be defined in
5059@file{.bash_profile}, which is sourced only by log-in shells.
5060@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5061details on Bash start-up files.}.
372c4bbc 5062
28de8d25
LC
5063@vindex GUIX_ENVIRONMENT
5064@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
f97c9175 5065variable in the shell it spawns. This allows users to, say, define a
28de8d25
LC
5066specific prompt for development environments in their @file{.bashrc}
5067(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5068
5069@example
5070if [ -n "$GUIX_ENVIRONMENT" ]
5071then
5072 export PS1="\u@@\h \w [dev]\$ "
5073fi
5074@end example
5075
372c4bbc
DT
5076Additionally, more than one package may be specified, in which case the
5077union of the inputs for the given packages are used. For example, the
5078command below spawns a shell where all of the dependencies of both Guile
5079and Emacs are available:
5080
5081@example
5082guix environment guile emacs
5083@end example
5084
1de2fe95
DT
5085Sometimes an interactive shell session is not desired. An arbitrary
5086command may be invoked by placing the @code{--} token to separate the
5087command from the rest of the arguments:
372c4bbc
DT
5088
5089@example
1de2fe95 5090guix environment guile -- make -j4
372c4bbc
DT
5091@end example
5092
fe36d84e
LC
5093In other situations, it is more convenient to specify the list of
5094packages needed in the environment. For example, the following command
5095runs @command{python} from an environment containing Python@tie{}2.7 and
5096NumPy:
5097
5098@example
1de2fe95 5099guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
5100@end example
5101
cc90fbbf
DT
5102Furthermore, one might want the dependencies of a package and also some
5103additional packages that are not build-time or runtime dependencies, but
5104are useful when developing nonetheless. Because of this, the
5105@code{--ad-hoc} flag is positional. Packages appearing before
5106@code{--ad-hoc} are interpreted as packages whose dependencies will be
5107added to the environment. Packages appearing after are interpreted as
5108packages that will be added to the environment directly. For example,
5109the following command creates a Guix development environment that
5110additionally includes Git and strace:
5111
5112@example
5113guix environment guix --ad-hoc git strace
5114@end example
5115
f535dcbe
DT
5116Sometimes it is desirable to isolate the environment as much as
5117possible, for maximal purity and reproducibility. In particular, when
5118using Guix on a host distro that is not GuixSD, it is desirable to
5119prevent access to @file{/usr/bin} and other system-wide resources from
5120the development environment. For example, the following command spawns
5121a Guile REPL in a ``container'' where only the store and the current
5122working directory are mounted:
5123
5124@example
5125guix environment --ad-hoc --container guile -- guile
5126@end example
5127
0f252e26 5128@quotation Note
cfd35b4e 5129The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
5130@end quotation
5131
fe36d84e 5132The available options are summarized below.
372c4bbc
DT
5133
5134@table @code
5135@item --expression=@var{expr}
5136@itemx -e @var{expr}
c9c282ce
DT
5137Create an environment for the package or list of packages that
5138@var{expr} evaluates to.
372c4bbc 5139
fe36d84e
LC
5140For example, running:
5141
5142@example
5143guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5144@end example
5145
5146starts a shell with the environment for this specific variant of the
5147PETSc package.
5148
c9c282ce
DT
5149Running:
5150
5151@example
5c2b2f00 5152guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
5153@end example
5154
5155starts a shell with all the GuixSD base packages available.
5156
779aa003
DT
5157The above commands only the use default output of the given packages.
5158To select other outputs, two element tuples can be specified:
5159
5160@example
5161guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5162@end example
5163
372c4bbc
DT
5164@item --load=@var{file}
5165@itemx -l @var{file}
c9c282ce
DT
5166Create an environment for the package or list of packages that the code
5167within @var{file} evaluates to.
372c4bbc 5168
fe36d84e
LC
5169As an example, @var{file} might contain a definition like this
5170(@pxref{Defining Packages}):
5171
5172@example
5173@verbatiminclude environment-gdb.scm
5174@end example
5175
a54bd6d7
DT
5176@item --ad-hoc
5177Include all specified packages in the resulting environment, as if an
5178@i{ad hoc} package were defined with them as inputs. This option is
5179useful for quickly creating an environment without having to write a
5180package expression to contain the desired inputs.
5181
5182For instance, the command:
5183
5184@example
1de2fe95 5185guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
5186@end example
5187
5188runs @command{guile} in an environment where Guile and Guile-SDL are
5189available.
5190
417c39f1 5191Note that this example implicitly asks for the default output of
f97c9175 5192@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
5193specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5194of @code{glib} (@pxref{Packages with Multiple Outputs}).
5195
cc90fbbf
DT
5196This option may be composed with the default behavior of @command{guix
5197environment}. Packages appearing before @code{--ad-hoc} are interpreted
5198as packages whose dependencies will be added to the environment, the
5199default behavior. Packages appearing after are interpreted as packages
5200that will be added to the environment directly.
5201
372c4bbc
DT
5202@item --pure
5203Unset existing environment variables when building the new environment.
5204This has the effect of creating an environment in which search paths
5205only contain package inputs.
5206
5207@item --search-paths
5208Display the environment variable definitions that make up the
5209environment.
ce367ef3
LC
5210
5211@item --system=@var{system}
5212@itemx -s @var{system}
5213Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
5214
5215@item --container
5216@itemx -C
5217@cindex container
5218Run @var{command} within an isolated container. The current working
56b6befb 5219directory outside the container is mapped inside the
f535dcbe
DT
5220container. Additionally, the spawned process runs as the current user
5221outside the container, but has root privileges in the context of the
5222container.
5223
5224@item --network
5225@itemx -N
5226For containers, share the network namespace with the host system.
5227Containers created without this flag only have access to the loopback
5228device.
5229
5230@item --expose=@var{source}[=@var{target}]
5231For containers, expose the file system @var{source} from the host system
5232as the read-only file system @var{target} within the container. If
5233@var{target} is not specified, @var{source} is used as the target mount
5234point in the container.
5235
5236The example below spawns a Guile REPL in a container in which the user's
5237home directory is accessible read-only via the @file{/exchange}
5238directory:
5239
5240@example
5241guix environment --container --expose=$HOME=/exchange guile -- guile
5242@end example
5243
5c2b2f00 5244@item --share=@var{source}[=@var{target}]
f535dcbe
DT
5245For containers, share the file system @var{source} from the host system
5246as the writable file system @var{target} within the container. If
5247@var{target} is not specified, @var{source} is used as the target mount
5248point in the container.
5249
5250The example below spawns a Guile REPL in a container in which the user's
5251home directory is accessible for both reading and writing via the
5252@file{/exchange} directory:
5253
5254@example
5255guix environment --container --share=$HOME=/exchange guile -- guile
5256@end example
372c4bbc
DT
5257@end table
5258
5259It also supports all of the common build options that @command{guix
ccd7158d 5260build} supports (@pxref{Common Build Options}).
372c4bbc 5261
aff8ce7c
DT
5262@node Invoking guix publish
5263@section Invoking @command{guix publish}
5264
5265The purpose of @command{guix publish} is to enable users to easily share
f97c9175 5266their store with others, who can then use it as a substitute server
8ce229fc
LC
5267(@pxref{Substitutes}).
5268
5269When @command{guix publish} runs, it spawns an HTTP server which allows
5270anyone with network access to obtain substitutes from it. This means
5271that any machine running Guix can also act as if it were a build farm,
5272since the HTTP interface is compatible with Hydra, the software behind
5273the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5274
5275For security, each substitute is signed, allowing recipients to check
5276their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 5277@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
5278readable by the system administrator, it must be started as root; the
5279@code{--user} option makes it drop root privileges early on.
aff8ce7c 5280
b18812b6
LC
5281The signing key pair must be generated before @command{guix publish} is
5282launched, using @command{guix archive --generate-key} (@pxref{Invoking
5283guix archive}).
5284
aff8ce7c
DT
5285The general syntax is:
5286
5287@example
5288guix publish @var{options}@dots{}
5289@end example
5290
5291Running @command{guix publish} without any additional arguments will
5292spawn an HTTP server on port 8080:
5293
5294@example
5295guix publish
5296@end example
5297
5298Once a publishing server has been authorized (@pxref{Invoking guix
5299archive}), the daemon may download substitutes from it:
5300
5301@example
5302guix-daemon --substitute-urls=http://example.org:8080
5303@end example
5304
5305The following options are available:
5306
5307@table @code
5308@item --port=@var{port}
5309@itemx -p @var{port}
5310Listen for HTTP requests on @var{port}.
5311
9e2292ef
LC
5312@item --listen=@var{host}
5313Listen on the network interface for @var{host}. The default is to
5314accept connections from any interface.
5315
5463fe51
LC
5316@item --user=@var{user}
5317@itemx -u @var{user}
5318Change privileges to @var{user} as soon as possible---i.e., once the
5319server socket is open and the signing key has been read.
5320
aff8ce7c
DT
5321@item --repl[=@var{port}]
5322@itemx -r [@var{port}]
5323Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
5324Reference Manual}) on @var{port} (37146 by default). This is used
5325primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
5326@end table
5327
1c52181f
LC
5328Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5329add a call to @code{guix-publish-service} in the @code{services} field
5330of the @code{operating-system} declaration (@pxref{guix-publish-service,
5331@code{guix-publish-service}}).
5332
d23c20f1
LC
5333
5334@node Invoking guix challenge
5335@section Invoking @command{guix challenge}
5336
5337@cindex reproducible builds
5338@cindex verifiable builds
5339
5340Do the binaries provided by this server really correspond to the source
f97c9175 5341code it claims to build? Is a package build process deterministic?
d23c20f1
LC
5342These are the questions the @command{guix challenge} command attempts to
5343answer.
5344
5345The former is obviously an important question: Before using a substitute
f97c9175 5346server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
5347provides the right binaries, and thus @emph{challenge} it. The latter
5348is what enables the former: If package builds are deterministic, then
5349independent builds of the package should yield the exact same result,
5350bit for bit; if a server provides a binary different from the one
5351obtained locally, it may be either corrupt or malicious.
5352
5353We know that the hash that shows up in @file{/gnu/store} file names is
5354the hash of all the inputs of the process that built the file or
5355directory---compilers, libraries, build scripts,
5356etc. (@pxref{Introduction}). Assuming deterministic build processes,
5357one store file name should map to exactly one build output.
5358@command{guix challenge} checks whether there is, indeed, a single
5359mapping by comparing the build outputs of several independent builds of
5360any given store item.
5361
f97c9175 5362The command output looks like this:
d23c20f1
LC
5363
5364@smallexample
5365$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5366updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5367updating list of substitutes from 'http://guix.example.org'... 100.0%
5368/gnu/store/@dots{}-openssl-1.0.2d contents differ:
5369 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5370 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5371 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5372/gnu/store/@dots{}-git-2.5.0 contents differ:
5373 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5374 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5375 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5376/gnu/store/@dots{}-pius-2.1.1 contents differ:
5377 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5378 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5379 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5380@end smallexample
5381
5382@noindent
5383In this example, @command{guix challenge} first scans the store to
5384determine the set of locally-built derivations---as opposed to store
5385items that were downloaded from a substitute server---and then queries
5386all the substitute servers. It then reports those store items for which
5387the servers obtained a result different from the local build.
5388
5389@cindex non-determinism, in package builds
5390As an example, @code{guix.example.org} always gets a different answer.
5391Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5392case of Git. This might indicate that the build process of Git is
5393non-deterministic, meaning that its output varies as a function of
5394various things that Guix does not fully control, in spite of building
5395packages in isolated environments (@pxref{Features}). Most common
5396sources of non-determinism include the addition of timestamps in build
5397results, the inclusion of random numbers, and directory listings sorted
5398by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5399more information.
5400
f97c9175 5401To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
5402these lines (@pxref{Invoking guix archive}):
5403
5404@example
5405$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5406 | guix archive -x /tmp/git
043f4698 5407$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
5408@end example
5409
5410This command shows the difference between the files resulting from the
5411local build, and the files resulting from the build on
5412@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5413diffutils, Comparing and Merging Files}). The @command{diff} command
5414works great for text files. When binary files differ, a better option
5415is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5416visualize differences for all kinds of files.
5417
f97c9175 5418Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
5419to a non-deterministic build process or to a malicious server. We try
5420hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
5421to verify substitutes, but of course, this is a process that
5422involves not just Guix, but a large part of the free software community.
d23c20f1
LC
5423In the meantime, @command{guix challenge} is one tool to help address
5424the problem.
5425
5426If you are writing packages for Guix, you are encouraged to check
5427whether @code{hydra.gnu.org} and other substitute servers obtain the
5428same build result as you did with:
5429
5430@example
5431$ guix challenge @var{package}
5432@end example
5433
5434@noindent
f97c9175 5435where @var{package} is a package specification such as
d23c20f1
LC
5436@code{guile-2.0} or @code{glibc:debug}.
5437
5438The general syntax is:
5439
5440@example
5441guix challenge @var{options} [@var{packages}@dots{}]
5442@end example
5443
5444The one option that matters is:
5445
5446@table @code
5447
5448@item --substitute-urls=@var{urls}
5449Consider @var{urls} the whitespace-separated list of substitute source
5450URLs to compare to.
5451
5452@end table
5453
5454
32efa254
DT
5455@node Invoking guix container
5456@section Invoking @command{guix container}
5457@cindex container
5458
5459@quotation Note
5460As of version @value{VERSION}, this tool is experimental. The interface
5461is subject to radical change in the future.
5462@end quotation
5463
5464The purpose of @command{guix container} is to manipulate processes
5465running within an isolated environment, commonly known as a
46c36586 5466``container'', typically created by the @command{guix environment}
32efa254
DT
5467(@pxref{Invoking guix environment}) and @command{guix system container}
5468(@pxref{Invoking guix system}) commands.
5469
5470The general syntax is:
5471
5472@example
5473guix container @var{action} @var{options}@dots{}
5474@end example
5475
5476@var{action} specifies the operation to perform with a container, and
5477@var{options} specifies the context-specific arguments for the action.
5478
5479The following actions are available:
5480
5481@table @code
5482@item exec
5483Execute a command within the context of a running container.
5484
5485The syntax is:
5486
5487@example
5488guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5489@end example
5490
5491@var{pid} specifies the process ID of the running container.
f97c9175
AE
5492@var{program} specifies an executable file name within the root file
5493system of the container. @var{arguments} are the additional options that
5494will be passed to @var{program}.
32efa254
DT
5495
5496The following command launches an interactive login shell inside a
5497GuixSD container, started by @command{guix system container}, and whose
5498process ID is 9001:
5499
5500@example
5501guix container exec 9001 /run/current-system/profile/bin/bash --login
5502@end example
5503
5504Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 5505must be PID 1 of the container or one of its child processes.
32efa254
DT
5506
5507@end table
5508
a1ba8475
LC
5509@c *********************************************************************
5510@node GNU Distribution
5511@chapter GNU Distribution
5512
3ca2731c 5513@cindex Guix System Distribution
4705641f 5514@cindex GuixSD
3ca2731c
LC
5515Guix comes with a distribution of the GNU system consisting entirely of
5516free software@footnote{The term ``free'' here refers to the
a1ba8475 5517@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 5518users of that software}.}. The
35ed9306
LC
5519distribution can be installed on its own (@pxref{System Installation}),
5520but it is also possible to install Guix as a package manager on top of
5521an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5522between the two, we refer to the standalone distribution as the Guix
4705641f 5523System Distribution, or GuixSD.
35ed9306
LC
5524
5525The distribution provides core GNU packages such as GNU libc, GCC, and
5526Binutils, as well as many GNU and non-GNU applications. The complete
5527list of available packages can be browsed
093ae1be 5528@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5529running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5530
5531@example
e49951eb 5532guix package --list-available
a1ba8475
LC
5533@end example
5534
f97c9175 5535Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
5536Linux-based and other variants of GNU, with a focus on the promotion and
5537tight integration of GNU components, and an emphasis on programs and
5538tools that help users exert that freedom.
5539
3ca2731c 5540Packages are currently available on the following platforms:
c320011d
LC
5541
5542@table @code
5543
5544@item x86_64-linux
5545Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5546
5547@item i686-linux
5548Intel 32-bit architecture (IA32), Linux-Libre kernel;
5549
aa1e1947 5550@item armhf-linux
aa725117 5551ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
5552using the EABI hard-float application binary interface (ABI),
5553and Linux-Libre kernel.
aa1e1947 5554
c320011d
LC
5555@item mips64el-linux
5556little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 5557n32 ABI, and Linux-Libre kernel.
c320011d
LC
5558
5559@end table
5560
4705641f 5561GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5562
c320011d
LC
5563@noindent
5564For information on porting to other architectures or kernels,
f97c9175 5565@pxref{Porting}.
c320011d 5566
401c53c4 5567@menu
5af6de3e 5568* System Installation:: Installing the whole operating system.
35ed9306 5569* System Configuration:: Configuring the operating system.
91ef73d4 5570* Installing Debugging Files:: Feeding the debugger.
05962f29 5571* Security Updates:: Deploying security fixes quickly.
401c53c4 5572* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5573* Packaging Guidelines:: Growing the distribution.
401c53c4 5574* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5575* Porting:: Targeting another platform or kernel.
401c53c4
LC
5576@end menu
5577
5578Building this distribution is a cooperative effort, and you are invited
081145cf 5579to join! @xref{Contributing}, for information about how you can help.
401c53c4 5580
5af6de3e
LC
5581@node System Installation
5582@section System Installation
5583
3ca2731c
LC
5584@cindex Guix System Distribution
5585This section explains how to install the Guix System Distribution
5586on a machine. The Guix package manager can
35ed9306
LC
5587also be installed on top of a running GNU/Linux system,
5588@pxref{Installation}.
5af6de3e
LC
5589
5590@ifinfo
5591@c This paragraph is for people reading this from tty2 of the
5592@c installation image.
1068f26b 5593You are reading this documentation with an Info reader. For details on
5af6de3e 5594how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 5595link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
5596@kbd{l} afterwards to come back here.
5597@end ifinfo
5598
dedb8d5e
LC
5599@menu
5600* Limitations:: What you can expect.
5601* USB Stick Installation:: Preparing the installation medium.
5602* Preparing for Installation:: Networking, partitioning, etc.
5603* Proceeding with the Installation:: The real thing.
5604* Building the Installation Image:: How this comes to be.
5605@end menu
5606
5607@node Limitations
8aaaae38
LC
5608@subsection Limitations
5609
4705641f 5610As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5611not production-ready. It may contain bugs and lack important
8aaaae38
LC
5612features. Thus, if you are looking for a stable production system that
5613respects your freedom as a computer user, a good solution at this point
5614is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 5615the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5616to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5617also keep using your distribution and try out the package manager on top
5618of it (@pxref{Installation}).
5619
5620Before you proceed with the installation, be aware of the following
5621noteworthy limitations applicable to version @value{VERSION}:
5622
5623@itemize
5624@item
5625The installation process does not include a graphical user interface and
5626requires familiarity with GNU/Linux (see the following subsections to
5627get a feel of what that means.)
5628
5629@item
093ae1be 5630The system does not yet provide full GNOME and KDE desktops. Xfce and
f97c9175 5631Enlightenment are available, though, if graphical desktop environments
093ae1be 5632are your thing, as well as a number of X11 window managers.
8aaaae38
LC
5633
5634@item
dbcb0ab1 5635Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5636
5637@item
5638Few system services are currently supported out-of-the-box
5639(@pxref{Services}).
5640
5641@item
dedb8d5e 5642More than 3,000 packages are available, but you may
8aaaae38
LC
5643occasionally find that a useful package is missing.
5644@end itemize
5645
f97c9175
AE
5646You have been warned! But more than a disclaimer, this is an invitation
5647to report issues (and success stories!), and to join us in improving it.
8aaaae38 5648@xref{Contributing}, for more info.
5af6de3e 5649
dedb8d5e 5650@node USB Stick Installation
5af6de3e
LC
5651@subsection USB Stick Installation
5652
5653An installation image for USB sticks can be downloaded from
4705641f 5654@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5655where @var{system} is one of:
5656
5657@table @code
5658@item x86_64-linux
5659for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5660
5661@item i686-linux
5662for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5663@end table
5664
5665This image contains a single partition with the tools necessary for an
5666installation. It is meant to be copied @emph{as is} to a large-enough
5667USB stick.
5668
5669To copy the image to a USB stick, follow these steps:
5670
5671@enumerate
5672@item
5673Decompress the image using the @command{xz} command:
5674
5675@example
4705641f 5676xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5677@end example
5678
5679@item
f97c9175
AE
5680Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
5681its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
5682copy the image with:
5683
5684@example
4705641f 5685dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5686@end example
5687
5688Access to @file{/dev/sdX} usually requires root privileges.
5689@end enumerate
5690
5691Once this is done, you should be able to reboot the system and boot from
5692the USB stick. The latter usually requires you to get in the BIOS' boot
5693menu, where you can choose to boot from the USB stick.
5694
dedb8d5e 5695@node Preparing for Installation
5af6de3e
LC
5696@subsection Preparing for Installation
5697
5698Once you have successfully booted the image on the USB stick, you should
5699end up with a root prompt. Several console TTYs are configured and can
5700be used to run commands as root. TTY2 shows this documentation,
5701browsable using the Info reader commands (@pxref{Help,,, info, Info: An
ae7ffa9e
LC
5702Introduction}). The installation system runs the GPM mouse daemon,
5703which allows you to select text with the left mouse button and to paste
5704it with the middle button.
5af6de3e 5705
dedb8d5e 5706@subsubsection Keyboard Layout
5af6de3e 5707
dedb8d5e
LC
5708@cindex keyboard layout
5709The installation image uses the US qwerty keyboard layout. If you want
5710to change it, you can use the @command{loadkeys} command. For example,
5711the following command selects the Dvorak keyboard layout:
5af6de3e 5712
dedb8d5e
LC
5713@example
5714loadkeys dvorak
5715@end example
5716
5717See the files under @file{/run/current-system/profile/share/keymaps} for
5718a list of available keyboard layouts. Run @command{man loadkeys} for
5719more information.
5720
5721@subsubsection Networking
5722
5723Run the following command see what your network interfaces are called:
235cba85
LC
5724
5725@example
dedb8d5e 5726ifconfig -a
235cba85
LC
5727@end example
5728
95c559c1 5729@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
5730Wired interfaces have a name starting with @samp{e}; for example, the
5731interface corresponding to the first on-board Ethernet controller is
5732called @samp{eno1}. Wireless interfaces have a name starting with
5733@samp{w}, like @samp{w1p2s0}.
5734
5735@table @asis
5736@item Wired connection
5737To configure a wired network run the following command, substituting
5738@var{interface} with the name of the wired interface you want to use.
5739
5740@example
5741ifconfig @var{interface} up
5742@end example
5743
5744@item Wireless connection
5745To configure wireless networking, you can create a configuration file
5746for the @command{wpa_supplicant} configuration tool (its location is not
5747important) using one of the available text editors such as
5748@command{zile}:
5749
5750@example
5751zile wpa_supplicant.conf
5752@end example
5753
5754As an example, the following stanza can go to this file and will work
5755for many wireless networks, provided you give the actual SSID and
5756passphrase for the network you are connecting to:
5757
5758@example
5759network=@{
5760 ssid=@var{my-ssid}
5761 key_mgmt=WPA-PSK
5762 psk="the network's secret passphrase"
5763@}
5764@end example
5765
5766Start the wireless service and run it in the background with the
5767following command (substitute @var{interface} with the name of the
5768network interface you want to use):
5769
5770@example
5771wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
5772@end example
5773
5774Run @command{man wpa_supplication} for more information.
5775@end table
5776
5777At this point, you need to acquire an IP address. On a network where IP
5778addresses are automatically assigned @i{via} DHCP, you can run:
5779
5780@example
5781dhclient @var{interface}
5782@end example
5af6de3e 5783
dedb8d5e
LC
5784Try to ping a server to see if networking is up and running:
5785
5786@example
5787ping -c 3 gnu.org
5788@end example
5af6de3e
LC
5789
5790Setting up network access is almost always a requirement because the
5791image does not contain all the software and tools that may be needed.
5792
dedb8d5e
LC
5793@subsubsection Disk Partitioning
5794
5795Unless this has already been done, the next step is to partition, and
5796then format the target partition(s).
5797
5798The installation image includes several partitioning tools, including
5799Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
5800@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
5801the partition layout you want:
5802
5803@example
5804cfdisk
5805@end example
5806
5807Once you are done partitioning the target hard disk drive, you have to
5808create a file system on the relevant partition(s)@footnote{Currently
5809GuixSD pretty much assumes an ext4 file system. In particular, code
5810that reads partition UUIDs and labels only works with ext4. This will
5811be fixed in the future.}.
5af6de3e 5812
7ab44369
LC
5813Preferably, assign partitions a label so that you can easily and
5814reliably refer to them in @code{file-system} declarations (@pxref{File
5815Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
5816@command{mkfs.ext4} and related commands. So, assuming the target root
5817partition lives at @file{/dev/sda1}, a file system with the label
5818@code{my-root} can be created with:
7ab44369 5819
dedb8d5e
LC
5820@example
5821mkfs.ext4 -L my-root /dev/sda1
5822@end example
dd816355 5823
316d65be
LC
5824@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5825@c A typical command sequence may be:
5826@c
5827@c @example
5828@c # fdisk /dev/sdX
5829@c @dots{} Create partitions etc.@dots{}
5830@c # cryptsetup luksFormat /dev/sdX1
5831@c # cryptsetup open --type luks /dev/sdX1 my-partition
5832@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5833@c @end example
6d6e6281 5834
dedb8d5e
LC
5835In addition to e2fsprogs, the suite of tools to manipulate
5836ext2/ext3/ext4 file systems, the installation image includes
5837Cryptsetup/LUKS for disk encryption.
5af6de3e 5838
dedb8d5e
LC
5839Once that is done, mount the target root partition under @file{/mnt}
5840with a command like (again, assuming @file{/dev/sda1} is the root
5841partition):
83a17b62 5842
dedb8d5e
LC
5843@example
5844mount /dev/sda1 /mnt
5845@end example
83a17b62 5846
dedb8d5e
LC
5847@node Proceeding with the Installation
5848@subsection Proceeding with the Installation
83a17b62 5849
dedb8d5e
LC
5850With the target partitions ready and the target root mounted on
5851@file{/mnt}, we're ready to go. First, run:
5af6de3e 5852
dedb8d5e
LC
5853@example
5854herd start cow-store /mnt
5855@end example
5af6de3e 5856
dedb8d5e
LC
5857This makes @file{/gnu/store} copy-on-write, such that packages added to
5858it during the installation phase are written to the target disk rather
5859than kept in memory.
5af6de3e 5860
dedb8d5e 5861Next, you have to edit a file and
5af6de3e
LC
5862provide the declaration of the operating system to be installed. To
5863that end, the installation system comes with two text editors: GNU nano
5864(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5865It is better to store that file on the target root file system, say, as
5866@file{/mnt/etc/config.scm}.
5867
dedb8d5e
LC
5868@xref{Using the Configuration System}, for an overview of the
5869configuration file. The example configurations discussed in that
5870section are available under @file{/etc/configuration} in the
5871installation image. Thus, to get started with a system configuration
5872providing a graphical display server (a ``desktop'' system), you can run
5873something along these lines:
5874
5875@example
5876# mkdir /mnt/etc
5877# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
5878# zile /mnt/etc/config.scm
5879@end example
5880
5881You should pay attention to what your configuration file contains, and
5882in particular:
5883
5884@itemize
5885@item
5886Make sure the @code{grub-configuration} form refers to the device you
5887want to install GRUB on.
5888
5889@item
5890Be sure that your partition labels match the value of their respective
5891@code{device} fields in your @code{file-system} configuration, assuming
5892your @code{file-system} configuration sets the value of @code{title} to
5893@code{'label}.
5894@end itemize
5af6de3e 5895
dd51caac
LC
5896Once you are done preparing the configuration file, the new system must
5897be initialized (remember that the target root file system is mounted
5898under @file{/mnt}):
5af6de3e
LC
5899
5900@example
5901guix system init /mnt/etc/config.scm /mnt
5902@end example
5903
5904@noindent
dedb8d5e 5905This copies all the necessary files and installs GRUB on
5af6de3e 5906@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 5907more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
5908downloads or builds of missing packages, which can take some time.
5909
1bd4e6db
LC
5910Once that command has completed---and hopefully succeeded!---you can run
5911@command{reboot} and boot into the new system. The @code{root} password
5912in the new system is initially empty; other users' passwords need to be
5913initialized by running the @command{passwd} command as @code{root},
5914unless your configuration specifies otherwise
5915(@pxref{user-account-password, user account passwords}).
5916
5917Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
5918@file{guix-devel@@gnu.org} to share your experience---good or not so
5919good.
5920
dedb8d5e 5921@node Building the Installation Image
5af6de3e
LC
5922@subsection Building the Installation Image
5923
5924The installation image described above was built using the @command{guix
5925system} command, specifically:
5926
5927@example
8a225c66 5928guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
5929@end example
5930
1068f26b 5931@xref{Invoking guix system} and
5af6de3e
LC
5932@file{gnu/system/install.scm} in the source tree for more information
5933about the installation image.
5934
cf4a9129
LC
5935@node System Configuration
5936@section System Configuration
b208a005 5937
cf4a9129 5938@cindex system configuration
3ca2731c 5939The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
5940mechanism. By that we mean that all aspects of the global system
5941configuration---such as the available system services, timezone and
5942locale settings, user accounts---are declared in a single place. Such
5943a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 5944
cf4a9129
LC
5945One of the advantages of putting all the system configuration under the
5946control of Guix is that it supports transactional system upgrades, and
1068f26b 5947makes it possible to roll back to a previous system instantiation,
cf4a9129 5948should something go wrong with the new one (@pxref{Features}). Another
1068f26b 5949advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
5950across different machines, or at different points in time, without
5951having to resort to additional administration tools layered on top of
1068f26b 5952the own tools of the system.
cf4a9129 5953@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 5954
cf4a9129
LC
5955This section describes this mechanism. First we focus on the system
5956administrator's viewpoint---explaining how the system is configured and
5957instantiated. Then we show how this mechanism can be extended, for
5958instance to support new system services.
91ef73d4 5959
cf4a9129
LC
5960@menu
5961* Using the Configuration System:: Customizing your GNU system.
7313a52e 5962* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 5963* File Systems:: Configuring file system mounts.
510f9d86 5964* Mapped Devices:: Block device extra processing.
cf4a9129 5965* User Accounts:: Specifying user accounts.
598e19dc 5966* Locales:: Language and cultural convention settings.
cf4a9129 5967* Services:: Specifying system services.
0ae8c15a 5968* Setuid Programs:: Programs running with root privileges.
efb5e833 5969* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 5970* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 5971* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 5972* GRUB Configuration:: Configuring the boot loader.
cf4a9129 5973* Invoking guix system:: Instantiating a system configuration.
97d76250 5974* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
5975* Defining Services:: Adding new service definitions.
5976@end menu
91ef73d4 5977
cf4a9129
LC
5978@node Using the Configuration System
5979@subsection Using the Configuration System
64d76fa6 5980
cf4a9129
LC
5981The operating system is configured by providing an
5982@code{operating-system} declaration in a file that can then be passed to
5983the @command{guix system} command (@pxref{Invoking guix system}). A
5984simple setup, with the default system services, the default Linux-Libre
5985kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 5986
cf4a9129
LC
5987@findex operating-system
5988@lisp
dd51caac 5989@include os-config-bare-bones.texi
cf4a9129 5990@end lisp
401c53c4 5991
cf4a9129
LC
5992This example should be self-describing. Some of the fields defined
5993above, such as @code{host-name} and @code{bootloader}, are mandatory.
5994Others, such as @code{packages} and @code{services}, can be omitted, in
5995which case they get a default value.
e7f34eb0 5996
5d94ac51
LC
5997Below we discuss the effect of some of the most important fields
5998(@pxref{operating-system Reference}, for details about all the available
5999fields), and how to @dfn{instantiate} the operating system using
6000@command{guix system}.
6001
6002@unnumberedsubsubsec Globally-Visible Packages
6003
cf4a9129 6004@vindex %base-packages
5d94ac51
LC
6005The @code{packages} field lists packages that will be globally visible
6006on the system, for all user accounts---i.e., in every user's @code{PATH}
6007environment variable---in addition to the per-user profiles
6008(@pxref{Invoking guix package}). The @var{%base-packages} variable
6009provides all the tools one would expect for basic user and administrator
6010tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6011the GNU Zile lightweight text editor, @command{find}, @command{grep},
6012etc. The example above adds tcpdump to those, taken from the @code{(gnu
6013packages admin)} module (@pxref{Package Modules}).
e7f34eb0 6014
f6c9fb1b
LC
6015@findex specification->package
6016Referring to packages by variable name, like @var{tcpdump} above, has
6017the advantage of being unambiguous; it also allows typos and such to be
6018diagnosed right away as ``unbound variables''. The downside is that one
6019needs to know which module defines which package, and to augment the
6020@code{use-package-modules} line accordingly. To avoid that, one can use
6021the @code{specification->package} procedure of the @code{(gnu packages)}
6022module, which returns the best package for a given name or name and
6023version:
6024
6025@lisp
6026(use-modules (gnu packages))
6027
6028(operating-system
6029 ;; ...
6030 (packages (append (map specification->package
6031 '("tcpdump" "htop" "gnupg-2.0"))
6032 %base-packages)))
6033@end lisp
6034
5d94ac51
LC
6035@unnumberedsubsubsec System Services
6036
cf4a9129
LC
6037@vindex %base-services
6038The @code{services} field lists @dfn{system services} to be made
6039available when the system starts (@pxref{Services}).
6040The @code{operating-system} declaration above specifies that, in
6041addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
6042daemon listening on port 2222 (@pxref{Networking Services,
6043@code{lsh-service}}). Under the hood,
cf4a9129
LC
6044@code{lsh-service} arranges so that @code{lshd} is started with the
6045right command-line options, possibly with supporting configuration files
cd6f6c22
LC
6046generated as needed (@pxref{Defining Services}).
6047
6048@cindex customization, of services
6049@findex modify-services
6050Occasionally, instead of using the base services as is, you will want to
6051customize them. For instance, to change the configuration of
6052@code{guix-daemon} and Mingetty (the console log-in), you may write the
6053following instead of @var{%base-services}:
6054
6055@lisp
6056(modify-services %base-services
6057 (guix-service-type config =>
6058 (guix-configuration
6059 (inherit config)
6060 (use-substitutes? #f)
6061 (extra-options '("--gc-keep-outputs"))))
6062 (mingetty-service-type config =>
6063 (mingetty-configuration
6064 (inherit config)
6065 (motd (plain-file "motd" "Hi there!")))))
6066@end lisp
6067
6068@noindent
6069The effect here is to change the options passed to @command{guix-daemon}
6070when it is started, as well as the ``message of the day'' that appears
6071when logging in at the console. @xref{Service Reference,
6072@code{modify-services}}, for more on that.
a1ba8475 6073
dd51caac 6074The configuration for a typical ``desktop'' usage, with the X11 display
cd6f6c22 6075server, a desktop environment, network management, power management, and
dd51caac
LC
6076more, would look like this:
6077
6078@lisp
6079@include os-config-desktop.texi
6080@end lisp
6081
6082@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
6083@var{%desktop-services}. @xref{X.509 Certificates}, for background
6084information about the @code{nss-certs} package that is used here.
dd51caac 6085
5d94ac51
LC
6086Again, @var{%desktop-services} is just a list of service objects. If
6087you want to remove services from there, you can do so using the
6088procedures for list filtering (@pxref{SRFI-1 Filtering and
6089Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6090following expression returns a list that contains all the services in
6091@var{%desktop-services} minus the Avahi service:
6092
6093@example
6094(remove (lambda (service)
6095 (eq? (service-kind service) avahi-service-type))
6096 %desktop-services)
6097@end example
6098
6099@unnumberedsubsubsec Instantiating the System
6100
6101Assuming the @code{operating-system} declaration
6102is stored in the @file{my-system-config.scm}
cf4a9129
LC
6103file, the @command{guix system reconfigure my-system-config.scm} command
6104instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
6105entry (@pxref{Invoking guix system}).
6106
1068f26b 6107The normal way to change the system configuration is by updating this
65797bff
LC
6108file and re-running @command{guix system reconfigure}. One should never
6109have to touch files in @command{/etc} or to run commands that modify the
6110system state such as @command{useradd} or @command{grub-install}. In
6111fact, you must avoid that since that would not only void your warranty
6112but also prevent you from rolling back to previous versions of your
6113system, should you ever need to.
6114
6115@cindex roll-back, of the operating system
6116Speaking of roll-back, each time you run @command{guix system
6117reconfigure}, a new @dfn{generation} of the system is created---without
6118modifying or deleting previous generations. Old system generations get
6119an entry in the GRUB boot menu, allowing you to boot them in case
6120something went wrong with the latest generation. Reassuring, no? The
6121@command{guix system list-generations} command lists the system
6122generations available on disk.
b81e1947 6123
5d94ac51
LC
6124@unnumberedsubsubsec The Programming Interface
6125
cf4a9129
LC
6126At the Scheme level, the bulk of an @code{operating-system} declaration
6127is instantiated with the following monadic procedure (@pxref{The Store
6128Monad}):
b81e1947 6129
cf4a9129
LC
6130@deffn {Monadic Procedure} operating-system-derivation os
6131Return a derivation that builds @var{os}, an @code{operating-system}
6132object (@pxref{Derivations}).
b81e1947 6133
cf4a9129
LC
6134The output of the derivation is a single directory that refers to all
6135the packages, configuration files, and other supporting files needed to
6136instantiate @var{os}.
6137@end deffn
b81e1947 6138
5d94ac51
LC
6139This procedure is provided by the @code{(gnu system)} module. Along
6140with @code{(gnu services)} (@pxref{Services}), this module contains the
6141guts of GuixSD. Make sure to visit it!
6142
6143
7313a52e
LC
6144@node operating-system Reference
6145@subsection @code{operating-system} Reference
6146
6147This section summarizes all the options available in
6148@code{operating-system} declarations (@pxref{Using the Configuration
6149System}).
6150
6151@deftp {Data Type} operating-system
6152This is the data type representing an operating system configuration.
6153By that, we mean all the global system configuration, not per-user
6154configuration (@pxref{Using the Configuration System}).
6155
6156@table @asis
6157@item @code{kernel} (default: @var{linux-libre})
fbb25e56 6158The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
6159only the Linux-libre kernel is supported. In the future, it will be
6160possible to use the GNU@tie{}Hurd.}.
6161
ee2a6304
LC
6162@item @code{kernel-arguments} (default: @code{'()})
6163List of strings or gexps representing additional arguments to pass on
1068f26b 6164the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 6165
7313a52e 6166@item @code{bootloader}
88faf933 6167The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
6168
6169@item @code{initrd} (default: @code{base-initrd})
6170A two-argument monadic procedure that returns an initial RAM disk for
6171the Linux kernel. @xref{Initial RAM Disk}.
6172
f34c56be
LC
6173@item @code{firmware} (default: @var{%base-firmware})
6174@cindex firmware
6175List of firmware packages loadable by the operating system kernel.
6176
6177The default includes firmware needed for Atheros-based WiFi devices
6178(Linux-libre module @code{ath9k}.)
6179
7313a52e
LC
6180@item @code{host-name}
6181The host name.
6182
6183@item @code{hosts-file}
6184@cindex hosts file
24e02c28 6185A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 6186@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 6187Reference Manual}). The default is a file with entries for
7313a52e
LC
6188@code{localhost} and @var{host-name}.
6189
6190@item @code{mapped-devices} (default: @code{'()})
6191A list of mapped devices. @xref{Mapped Devices}.
6192
6193@item @code{file-systems}
6194A list of file systems. @xref{File Systems}.
6195
6196@item @code{swap-devices} (default: @code{'()})
6197@cindex swap devices
6198A list of strings identifying devices to be used for ``swap space''
6199(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6200For example, @code{'("/dev/sda3")}.
6201
bf87f38a 6202@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
6203@itemx @code{groups} (default: @var{%base-groups})
6204List of user accounts and groups. @xref{User Accounts}.
6205
6206@item @code{skeletons} (default: @code{(default-skeletons)})
6207A monadic list of pairs of target file name and files. These are the
6208files that will be used as skeletons as new accounts are created.
6209
6210For instance, a valid value may look like this:
6211
6212@example
6213(mlet %store-monad ((bashrc (text-file "bashrc" "\
6214 export PATH=$HOME/.guix-profile/bin")))
6215 (return `((".bashrc" ,bashrc))))
6216@end example
6217
6218@item @code{issue} (default: @var{%default-issue})
6219A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 6220displayed when users log in on a text console.
7313a52e
LC
6221
6222@item @code{packages} (default: @var{%base-packages})
6223The set of packages installed in the global profile, which is accessible
6224at @file{/run/current-system/profile}.
6225
1068f26b 6226The default set includes core utilities and it is good practice to
7313a52e
LC
6227install non-core utilities in user profiles (@pxref{Invoking guix
6228package}).
6229
6230@item @code{timezone}
6231A timezone identifying string---e.g., @code{"Europe/Paris"}.
6232
17c20385
LC
6233You can run the @command{tzselect} command to find out which timezone
6234string corresponds to your region. Choosing an invalid timezone name
6235causes @command{guix system} to fail.
6236
598e19dc
LC
6237@item @code{locale} (default: @code{"en_US.utf8"})
6238The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
6239Library Reference Manual}). @xref{Locales}, for more information.
6240
6241@item @code{locale-definitions} (default: @var{%default-locale-definitions})
6242The list of locale definitions to be compiled and that may be used at
6243run time. @xref{Locales}.
7313a52e 6244
34760ae7
LC
6245@item @code{locale-libcs} (default: @code{(list @var{glibc})})
6246The list of GNU@tie{}libc packages whose locale data and tools are used
6247to build the locale definitions. @xref{Locales}, for compatibility
6248considerations that justify this option.
6249
996ed739 6250@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 6251Configuration of the libc name service switch (NSS)---a
996ed739
LC
6252@code{<name-service-switch>} object. @xref{Name Service Switch}, for
6253details.
6254
7313a52e 6255@item @code{services} (default: @var{%base-services})
28d939af 6256A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
6257
6258@item @code{pam-services} (default: @code{(base-pam-services)})
6259@cindex PAM
6260@cindex pluggable authentication modules
6261Linux @dfn{pluggable authentication module} (PAM) services.
6262@c FIXME: Add xref to PAM services section.
6263
6264@item @code{setuid-programs} (default: @var{%setuid-programs})
6265List of string-valued G-expressions denoting setuid programs.
6266@xref{Setuid Programs}.
6267
f5a9ffa0
AK
6268@item @code{sudoers-file} (default: @var{%sudoers-specification})
6269@cindex sudoers file
84765839
LC
6270The contents of the @file{/etc/sudoers} file as a file-like object
6271(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
6272
6273This file specifies which users can use the @command{sudo} command, what
6274they are allowed to do, and what privileges they may gain. The default
6275is that only @code{root} and members of the @code{wheel} group may use
6276@code{sudo}.
6277
6278@end table
6279@end deftp
6280
cf4a9129
LC
6281@node File Systems
6282@subsection File Systems
b81e1947 6283
cf4a9129 6284The list of file systems to be mounted is specified in the
1068f26b 6285@code{file-systems} field of the operating system declaration
cf4a9129
LC
6286(@pxref{Using the Configuration System}). Each file system is declared
6287using the @code{file-system} form, like this:
b81e1947
LC
6288
6289@example
cf4a9129
LC
6290(file-system
6291 (mount-point "/home")
6292 (device "/dev/sda3")
6293 (type "ext4"))
b81e1947
LC
6294@end example
6295
cf4a9129
LC
6296As usual, some of the fields are mandatory---those shown in the example
6297above---while others can be omitted. These are described below.
b81e1947 6298
cf4a9129
LC
6299@deftp {Data Type} file-system
6300Objects of this type represent file systems to be mounted. They
6301contain the following members:
5ff3c4b8 6302
cf4a9129
LC
6303@table @asis
6304@item @code{type}
6305This is a string specifying the type of the file system---e.g.,
6306@code{"ext4"}.
5ff3c4b8 6307
cf4a9129
LC
6308@item @code{mount-point}
6309This designates the place where the file system is to be mounted.
b81e1947 6310
cf4a9129
LC
6311@item @code{device}
6312This names the ``source'' of the file system. By default it is the name
6313of a node under @file{/dev}, but its meaning depends on the @code{title}
6314field described below.
401c53c4 6315
cf4a9129
LC
6316@item @code{title} (default: @code{'device})
6317This is a symbol that specifies how the @code{device} field is to be
6318interpreted.
401c53c4 6319
cf4a9129
LC
6320When it is the symbol @code{device}, then the @code{device} field is
6321interpreted as a file name; when it is @code{label}, then @code{device}
6322is interpreted as a partition label name; when it is @code{uuid},
6323@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 6324
661a1d79 6325UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
6326@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
6327@code{uuid} form expects 16-byte UUIDs as defined in
6328@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
6329form of UUID used by the ext2 family of file systems and others, but it
6330is different from ``UUIDs'' found in FAT file systems, for instance.},
6331like this:
661a1d79
LC
6332
6333@example
6334(file-system
6335 (mount-point "/home")
6336 (type "ext4")
6337 (title 'uuid)
6338 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6339@end example
6340
cf4a9129 6341The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
6342partitions without having to hard-code their actual device
6343name@footnote{Note that, while it is tempting to use
6344@file{/dev/disk/by-uuid} and similar device names to achieve the same
6345result, this is not recommended: These special device nodes are created
6346by the udev daemon and may be unavailable at the time the device is
6347mounted.}.
da7cabd4 6348
1068f26b 6349However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
6350Devices}), its @code{device} field @emph{must} refer to the mapped
6351device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6352@code{title} must be set to @code{'device}. This is required so that
6353the system knows that mounting the file system depends on having the
6354corresponding device mapping established.
6355
cf4a9129
LC
6356@item @code{flags} (default: @code{'()})
6357This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
6358include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6359access to special files), @code{no-suid} (ignore setuid and setgid
6360bits), and @code{no-exec} (disallow program execution.)
da7cabd4 6361
cf4a9129
LC
6362@item @code{options} (default: @code{#f})
6363This is either @code{#f}, or a string denoting mount options.
da7cabd4 6364
be21979d
LC
6365@item @code{mount?} (default: @code{#t})
6366This value indicates whether to automatically mount the file system when
6367the system is brought up. When set to @code{#f}, the file system gets
6368an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6369is not automatically mounted.
6370
cf4a9129
LC
6371@item @code{needed-for-boot?} (default: @code{#f})
6372This Boolean value indicates whether the file system is needed when
6373booting. If that is true, then the file system is mounted when the
6374initial RAM disk (initrd) is loaded. This is always the case, for
6375instance, for the root file system.
da7cabd4 6376
cf4a9129
LC
6377@item @code{check?} (default: @code{#t})
6378This Boolean indicates whether the file system needs to be checked for
6379errors before being mounted.
f9cc8971 6380
4e469051
LC
6381@item @code{create-mount-point?} (default: @code{#f})
6382When true, the mount point is created if it does not exist yet.
6383
e51710d1
LC
6384@item @code{dependencies} (default: @code{'()})
6385This is a list of @code{<file-system>} objects representing file systems
6386that must be mounted before (and unmounted after) this one.
6387
6388As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6389a dependency of @file{/sys/fs/cgroup/cpu} and
6390@file{/sys/fs/cgroup/memory}.
6391
cf4a9129
LC
6392@end table
6393@end deftp
da7cabd4 6394
a69576ea
LC
6395The @code{(gnu system file-systems)} exports the following useful
6396variables.
6397
6398@defvr {Scheme Variable} %base-file-systems
6399These are essential file systems that are required on normal systems,
cc0e575a 6400such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
6401below.) Operating system declarations should always contain at least
6402these.
a69576ea
LC
6403@end defvr
6404
7f239fd3
LC
6405@defvr {Scheme Variable} %pseudo-terminal-file-system
6406This is the file system to be mounted as @file{/dev/pts}. It supports
6407@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6408functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6409Manual}). Pseudo-terminals are used by terminal emulators such as
6410@command{xterm}.
6411@end defvr
6412
db17ae5c
LC
6413@defvr {Scheme Variable} %shared-memory-file-system
6414This file system is mounted as @file{/dev/shm} and is used to support
6415memory sharing across processes (@pxref{Memory-mapped I/O,
6416@code{shm_open},, libc, The GNU C Library Reference Manual}).
6417@end defvr
6418
3392ce5d
LC
6419@defvr {Scheme Variable} %immutable-store
6420This file system performs a read-only ``bind mount'' of
6421@file{/gnu/store}, making it read-only for all the users including
6422@code{root}. This prevents against accidental modification by software
6423running as @code{root} or by system administrators.
6424
6425The daemon itself is still able to write to the store: it remounts it
6426read-write in its own ``name space.''
6427@end defvr
6428
a69576ea
LC
6429@defvr {Scheme Variable} %binary-format-file-system
6430The @code{binfmt_misc} file system, which allows handling of arbitrary
6431executable file types to be delegated to user space. This requires the
6432@code{binfmt.ko} kernel module to be loaded.
6433@end defvr
6434
6435@defvr {Scheme Variable} %fuse-control-file-system
6436The @code{fusectl} file system, which allows unprivileged users to mount
6437and unmount user-space FUSE file systems. This requires the
6438@code{fuse.ko} kernel module to be loaded.
6439@end defvr
6440
510f9d86
LC
6441@node Mapped Devices
6442@subsection Mapped Devices
6443
6444@cindex device mapping
6445@cindex mapped devices
6446The Linux kernel has a notion of @dfn{device mapping}: a block device,
6447such as a hard disk partition, can be @dfn{mapped} into another device,
6448with additional processing over the data that flows through
6449it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6450concept of a ``mapped device'' and that of a file system: both boil down
6451to @emph{translating} input/output operations made on a file to
6452operations on its backing store. Thus, the Hurd implements mapped
6453devices, like file systems, using the generic @dfn{translator} mechanism
6454(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6455typical example is encryption device mapping: all writes to the mapped
6456device are encrypted, and all reads are deciphered, transparently.
6457
6458Mapped devices are declared using the @code{mapped-device} form:
6459
6460@example
6461(mapped-device
6462 (source "/dev/sda3")
6463 (target "home")
6464 (type luks-device-mapping))
6465@end example
6466
6467@noindent
6468@cindex disk encryption
6469@cindex LUKS
6470This example specifies a mapping from @file{/dev/sda3} to
6471@file{/dev/mapper/home} using LUKS---the
6472@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6473standard mechanism for disk encryption. The @file{/dev/mapper/home}
6474device can then be used as the @code{device} of a @code{file-system}
6475declaration (@pxref{File Systems}). The @code{mapped-device} form is
6476detailed below.
6477
6478@deftp {Data Type} mapped-device
6479Objects of this type represent device mappings that will be made when
6480the system boots up.
6481
9cb426b8
LC
6482@table @code
6483@item source
510f9d86
LC
6484This string specifies the name of the block device to be mapped, such as
6485@code{"/dev/sda3"}.
6486
9cb426b8 6487@item target
510f9d86
LC
6488This string specifies the name of the mapping to be established. For
6489example, specifying @code{"my-partition"} will lead to the creation of
6490the @code{"/dev/mapper/my-partition"} device.
6491
9cb426b8 6492@item type
510f9d86
LC
6493This must be a @code{mapped-device-kind} object, which specifies how
6494@var{source} is mapped to @var{target}.
6495@end table
6496@end deftp
6497
6498@defvr {Scheme Variable} luks-device-mapping
6499This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 6500command from the package with the same name. It relies on the
510f9d86
LC
6501@code{dm-crypt} Linux kernel module.
6502@end defvr
6503
cf4a9129
LC
6504@node User Accounts
6505@subsection User Accounts
ee85f3db 6506
9bea87a5
LC
6507User accounts and groups are entirely managed through the
6508@code{operating-system} declaration. They are specified with the
6509@code{user-account} and @code{user-group} forms:
ee85f3db 6510
cf4a9129
LC
6511@example
6512(user-account
6513 (name "alice")
6514 (group "users")
24e752c0
LC
6515 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6516 "audio" ;sound card
6517 "video" ;video devices such as webcams
6518 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
6519 (comment "Bob's sister")
6520 (home-directory "/home/alice"))
6521@end example
25083588 6522
9bea87a5
LC
6523When booting or upon completion of @command{guix system reconfigure},
6524the system ensures that only the user accounts and groups specified in
6525the @code{operating-system} declaration exist, and with the specified
6526properties. Thus, account or group creations or modifications made by
6527directly invoking commands such as @command{useradd} are lost upon
6528reconfiguration or reboot. This ensures that the system remains exactly
6529as declared.
6530
cf4a9129
LC
6531@deftp {Data Type} user-account
6532Objects of this type represent user accounts. The following members may
6533be specified:
ee85f3db 6534
cf4a9129
LC
6535@table @asis
6536@item @code{name}
6537The name of the user account.
ee85f3db 6538
cf4a9129
LC
6539@item @code{group}
6540This is the name (a string) or identifier (a number) of the user group
6541this account belongs to.
ee85f3db 6542
cf4a9129
LC
6543@item @code{supplementary-groups} (default: @code{'()})
6544Optionally, this can be defined as a list of group names that this
6545account belongs to.
ee85f3db 6546
cf4a9129
LC
6547@item @code{uid} (default: @code{#f})
6548This is the user ID for this account (a number), or @code{#f}. In the
6549latter case, a number is automatically chosen by the system when the
6550account is created.
ee85f3db 6551
cf4a9129 6552@item @code{comment} (default: @code{""})
1068f26b 6553A comment about the account, such as the account owner's full name.
c8c871d1 6554
cf4a9129
LC
6555@item @code{home-directory}
6556This is the name of the home directory for the account.
ee85f3db 6557
cf4a9129
LC
6558@item @code{shell} (default: Bash)
6559This is a G-expression denoting the file name of a program to be used as
6560the shell (@pxref{G-Expressions}).
ee85f3db 6561
cf4a9129
LC
6562@item @code{system?} (default: @code{#f})
6563This Boolean value indicates whether the account is a ``system''
6564account. System accounts are sometimes treated specially; for instance,
6565graphical login managers do not list them.
ee85f3db 6566
1bd4e6db 6567@anchor{user-account-password}
cf4a9129 6568@item @code{password} (default: @code{#f})
eb59595c
LC
6569You would normally leave this field to @code{#f}, initialize user
6570passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
6571users change it with @command{passwd}. Passwords set with
6572@command{passwd} are of course preserved across reboot and
6573reconfiguration.
eb59595c
LC
6574
6575If you @emph{do} want to have a preset password for an account, then
6576this field must contain the encrypted password, as a string.
5d1f1177
LC
6577@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6578on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 6579Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 6580
cf4a9129
LC
6581@end table
6582@end deftp
ee85f3db 6583
cf4a9129 6584User group declarations are even simpler:
ee85f3db 6585
cf4a9129
LC
6586@example
6587(user-group (name "students"))
6588@end example
ee85f3db 6589
cf4a9129
LC
6590@deftp {Data Type} user-group
6591This type is for, well, user groups. There are just a few fields:
af8a56b8 6592
cf4a9129
LC
6593@table @asis
6594@item @code{name}
1068f26b 6595The name of the group.
ee85f3db 6596
cf4a9129
LC
6597@item @code{id} (default: @code{#f})
6598The group identifier (a number). If @code{#f}, a new number is
6599automatically allocated when the group is created.
ee85f3db 6600
c8fa3426
LC
6601@item @code{system?} (default: @code{#f})
6602This Boolean value indicates whether the group is a ``system'' group.
6603System groups have low numerical IDs.
6604
cf4a9129
LC
6605@item @code{password} (default: @code{#f})
6606What, user groups can have a password? Well, apparently yes. Unless
1068f26b 6607@code{#f}, this field specifies the password of the group.
ee85f3db 6608
cf4a9129
LC
6609@end table
6610@end deftp
401c53c4 6611
cf4a9129
LC
6612For convenience, a variable lists all the basic user groups one may
6613expect:
401c53c4 6614
cf4a9129
LC
6615@defvr {Scheme Variable} %base-groups
6616This is the list of basic user groups that users and/or packages expect
6617to be present on the system. This includes groups such as ``root'',
6618``wheel'', and ``users'', as well as groups used to control access to
6619specific devices such as ``audio'', ``disk'', and ``cdrom''.
6620@end defvr
401c53c4 6621
bf87f38a
LC
6622@defvr {Scheme Variable} %base-user-accounts
6623This is the list of basic system accounts that programs may expect to
6624find on a GNU/Linux system, such as the ``nobody'' account.
6625
6626Note that the ``root'' account is not included here. It is a
6627special-case and is automatically added whether or not it is specified.
6628@end defvr
6629
598e19dc
LC
6630@node Locales
6631@subsection Locales
6632
6633@cindex locale
6634A @dfn{locale} defines cultural conventions for a particular language
6635and region of the world (@pxref{Locales,,, libc, The GNU C Library
6636Reference Manual}). Each locale has a name that typically has the form
b2636518 6637@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
6638@code{fr_LU.utf8} designates the locale for the French language, with
6639cultural conventions from Luxembourg, and using the UTF-8 encoding.
6640
6641@cindex locale definition
6642Usually, you will want to specify the default locale for the machine
6643using the @code{locale} field of the @code{operating-system} declaration
6644(@pxref{operating-system Reference, @code{locale}}).
6645
f5582b2c
LC
6646The selected locale is automatically added to the @dfn{locale
6647definitions} known to the system if needed, with its codeset inferred
6648from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
6649@code{UTF-8} codeset. Additional locale definitions can be specified in
6650the @code{locale-definitions} slot of @code{operating-system}---this is
6651useful, for instance, if the codeset could not be inferred from the
6652locale name. The default set of locale definitions includes some widely
6653used locales, but not all the available locales, in order to save space.
6654
6655For instance, to add the North Frisian locale for Germany, the value of
6656that field may be:
598e19dc
LC
6657
6658@example
6659(cons (locale-definition
6660 (name "fy_DE.utf8") (source "fy_DE"))
6661 %default-locale-definitions)
6662@end example
6663
6664Likewise, to save space, one might want @code{locale-definitions} to
6665list only the locales that are actually used, as in:
6666
6667@example
6668(list (locale-definition
6669 (name "ja_JP.eucjp") (source "ja_JP")
6670 (charset "EUC-JP")))
6671@end example
6672
5c3c1427
LC
6673@vindex LOCPATH
6674The compiled locale definitions are available at
46bd6edd
LC
6675@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6676version, which is the default location where the GNU@tie{}libc provided
6677by Guix looks for locale data. This can be overridden using the
6678@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
6679@code{LOCPATH} and locale packages}).
6680
598e19dc
LC
6681The @code{locale-definition} form is provided by the @code{(gnu system
6682locale)} module. Details are given below.
6683
6684@deftp {Data Type} locale-definition
6685This is the data type of a locale definition.
6686
6687@table @asis
6688
6689@item @code{name}
6690The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6691Reference Manual}, for more information on locale names.
6692
6693@item @code{source}
6694The name of the source for that locale. This is typically the
6695@code{@var{language}_@var{territory}} part of the locale name.
6696
6697@item @code{charset} (default: @code{"UTF-8"})
6698The ``character set'' or ``code set'' for that locale,
6699@uref{http://www.iana.org/assignments/character-sets, as defined by
6700IANA}.
6701
6702@end table
6703@end deftp
6704
6705@defvr {Scheme Variable} %default-locale-definitions
1068f26b 6706A list of commonly used UTF-8 locales, used as the default
b2636518 6707value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 6708declarations.
b2636518
LC
6709
6710@cindex locale name
6711@cindex normalized codeset in locale names
6712These locale definitions use the @dfn{normalized codeset} for the part
6713that follows the dot in the name (@pxref{Using gettextized software,
6714normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6715instance it has @code{uk_UA.utf8} but @emph{not}, say,
6716@code{uk_UA.UTF-8}.
598e19dc 6717@end defvr
401c53c4 6718
34760ae7
LC
6719@subsubsection Locale Data Compatibility Considerations
6720
6721@cindex incompatibility, of locale data
6722@code{operating-system} declarations provide a @code{locale-libcs} field
6723to specify the GNU@tie{}libc packages that are used to compile locale
6724declarations (@pxref{operating-system Reference}). ``Why would I
6725care?'', you may ask. Well, it turns out that the binary format of
6726locale data is occasionally incompatible from one libc version to
6727another.
6728
6729@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6730@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6731For instance, a program linked against libc version 2.21 is unable to
6732read locale data produced with libc 2.22; worse, that program
6733@emph{aborts} instead of simply ignoring the incompatible locale
6734data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6735the incompatible locale data, which is already an improvement.}.
6736Similarly, a program linked against libc 2.22 can read most, but not
6737all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6738data is incompatible); thus calls to @code{setlocale} may fail, but
6739programs will not abort.
6740
6741The ``problem'' in GuixSD is that users have a lot of freedom: They can
6742choose whether and when to upgrade software in their profiles, and might
6743be using a libc version different from the one the system administrator
6744used to build the system-wide locale data.
6745
6746Fortunately, unprivileged users can also install their own locale data
6747and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6748@code{GUIX_LOCPATH} and locale packages}).
6749
6750Still, it is best if the system-wide locale data at
6751@file{/run/current-system/locale} is built for all the libc versions
6752actually in use on the system, so that all the programs can access
6753it---this is especially crucial on a multi-user system. To do that, the
6754administrator can specify several libc packages in the
6755@code{locale-libcs} field of @code{operating-system}:
6756
6757@example
6758(use-package-modules base)
6759
6760(operating-system
6761 ;; @dots{}
6762 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6763@end example
6764
6765This example would lead to a system containing locale definitions for
6766both libc 2.21 and the current version of libc in
6767@file{/run/current-system/locale}.
6768
6769
cf4a9129
LC
6770@node Services
6771@subsection Services
401c53c4 6772
cf4a9129
LC
6773@cindex system services
6774An important part of preparing an @code{operating-system} declaration is
6775listing @dfn{system services} and their configuration (@pxref{Using the
6776Configuration System}). System services are typically daemons launched
6777when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
6778configuring network access.
6779
dd17bc38
AK
6780Services are managed by the GNU@tie{}Shepherd (@pxref{Introduction,,,
6781shepherd, The GNU Shepherd Manual}). On a running system, the
6782@command{herd} command allows you to list the available services, show
6783their status, start and stop them, or do other specific operations
6784(@pxref{Jump Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
6785
6786@example
dd17bc38 6787# herd status
d8b94dbd
LC
6788@end example
6789
6790The above command, run as @code{root}, lists the currently defined
dd17bc38 6791services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
6792service:
6793
6794@example
dd17bc38 6795# herd doc nscd
d8b94dbd
LC
6796Run libc's name service cache daemon (nscd).
6797@end example
6798
6799The @command{start}, @command{stop}, and @command{restart} sub-commands
6800have the effect you would expect. For instance, the commands below stop
6801the nscd service and restart the Xorg display server:
6802
6803@example
dd17bc38 6804# herd stop nscd
d8b94dbd 6805Service nscd has been stopped.
dd17bc38 6806# herd restart xorg-server
d8b94dbd
LC
6807Service xorg-server has been stopped.
6808Service xorg-server has been started.
6809@end example
401c53c4 6810
cf4a9129 6811The following sections document the available services, starting with
d8b94dbd
LC
6812the core services, that may be used in an @code{operating-system}
6813declaration.
401c53c4 6814
cf4a9129
LC
6815@menu
6816* Base Services:: Essential system services.
6817* Networking Services:: Network setup, SSH daemon, etc.
6818* X Window:: Graphical display.
fe1a39d3 6819* Desktop Services:: D-Bus and desktop services.
105369a4 6820* Database Services:: SQL databases.
d8c18af8 6821* Mail Services:: IMAP, POP3, SMTP, and all that.
58724c48 6822* Web Services:: Web servers.
aa4ed923 6823* Various Services:: Other services.
cf4a9129 6824@end menu
401c53c4 6825
cf4a9129
LC
6826@node Base Services
6827@subsubsection Base Services
a1ba8475 6828
cf4a9129
LC
6829The @code{(gnu services base)} module provides definitions for the basic
6830services that one expects from the system. The services exported by
6831this module are listed below.
401c53c4 6832
cf4a9129 6833@defvr {Scheme Variable} %base-services
31771497
LC
6834This variable contains a list of basic services (@pxref{Service Types
6835and Services}, for more information on service objects) one would
cf4a9129 6836expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 6837the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 6838more.
401c53c4 6839
cf4a9129
LC
6840This is the default value of the @code{services} field of
6841@code{operating-system} declarations. Usually, when customizing a
6842system, you will want to append services to @var{%base-services}, like
6843this:
401c53c4 6844
cf4a9129 6845@example
fa1e31b8 6846(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
6847@end example
6848@end defvr
401c53c4 6849
be1c2c54 6850@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
6851Return a service that sets the host name to @var{name}.
6852@end deffn
401c53c4 6853
66e4f01c
LC
6854@deffn {Scheme Procedure} mingetty-service @var{config}
6855Return a service to run mingetty according to @var{config}, a
6856@code{<mingetty-configuration>} object, which specifies the tty to run, among
6857other things.
cf4a9129 6858@end deffn
401c53c4 6859
66e4f01c
LC
6860@deftp {Data Type} mingetty-configuration
6861This is the data type representing the configuration of Mingetty, which
6862implements console log-in.
6863
6864@table @asis
6865
6866@item @code{tty}
6867The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6868
6869@item @code{motd}
6870A file-like object containing the ``message of the day''.
6871
6872@item @code{auto-login} (default: @code{#f})
6873When true, this field must be a string denoting the user name under
f9b9a033 6874which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
6875user name and password must be entered to log in.
6876
6877@item @code{login-program} (default: @code{#f})
6878This must be either @code{#f}, in which case the default log-in program
6879is used (@command{login} from the Shadow tool suite), or a gexp denoting
6880the name of the log-in program.
6881
6882@item @code{login-pause?} (default: @code{#f})
6883When set to @code{#t} in conjunction with @var{auto-login}, the user
6884will have to press a key before the log-in shell is launched.
6885
6886@item @code{mingetty} (default: @var{mingetty})
6887The Mingetty package to use.
6888
6889@end table
6890@end deftp
6891
6454b333
LC
6892@cindex name service cache daemon
6893@cindex nscd
be1c2c54 6894@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 6895 [#:name-services '()]
1068f26b 6896Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
6897given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6898Service Switch}, for an example.
cf4a9129 6899@end deffn
401c53c4 6900
6454b333
LC
6901@defvr {Scheme Variable} %nscd-default-configuration
6902This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 6903by @code{nscd-service}. It uses the caches defined by
6454b333
LC
6904@var{%nscd-default-caches}; see below.
6905@end defvr
6906
6907@deftp {Data Type} nscd-configuration
1068f26b 6908This is the data type representing the name service cache daemon (nscd)
6454b333
LC
6909configuration.
6910
6911@table @asis
6912
b893f1ae
LC
6913@item @code{name-services} (default: @code{'()})
6914List of packages denoting @dfn{name services} that must be visible to
6915the nscd---e.g., @code{(list @var{nss-mdns})}.
6916
6917@item @code{glibc} (default: @var{glibc})
6918Package object denoting the GNU C Library providing the @command{nscd}
6919command.
6920
6454b333 6921@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 6922Name of the nscd log file. This is where debugging output goes when
6454b333
LC
6923@code{debug-level} is strictly positive.
6924
6925@item @code{debug-level} (default: @code{0})
1068f26b 6926Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
6927debugging output is logged.
6928
6929@item @code{caches} (default: @var{%nscd-default-caches})
6930List of @code{<nscd-cache>} objects denoting things to be cached; see
6931below.
6932
6933@end table
6934@end deftp
6935
6936@deftp {Data Type} nscd-cache
6937Data type representing a cache database of nscd and its parameters.
6938
6939@table @asis
6940
6941@item @code{database}
6942This is a symbol representing the name of the database to be cached.
6943Valid values are @code{passwd}, @code{group}, @code{hosts}, and
6944@code{services}, which designate the corresponding NSS database
6945(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
6946
6947@item @code{positive-time-to-live}
6948@itemx @code{negative-time-to-live} (default: @code{20})
6949A number representing the number of seconds during which a positive or
6950negative lookup result remains in cache.
6951
6952@item @code{check-files?} (default: @code{#t})
6953Whether to check for updates of the files corresponding to
6954@var{database}.
6955
6956For instance, when @var{database} is @code{hosts}, setting this flag
6957instructs nscd to check for updates in @file{/etc/hosts} and to take
6958them into account.
6959
6960@item @code{persistent?} (default: @code{#t})
6961Whether the cache should be stored persistently on disk.
6962
6963@item @code{shared?} (default: @code{#t})
6964Whether the cache should be shared among users.
6965
6966@item @code{max-database-size} (default: 32@tie{}MiB)
6967Maximum size in bytes of the database cache.
6968
6969@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
6970@c settings, so leave them out.
6971
6972@end table
6973@end deftp
6974
6975@defvr {Scheme Variable} %nscd-default-caches
6976List of @code{<nscd-cache>} objects used by default by
1068f26b 6977@code{nscd-configuration} (see above).
6454b333
LC
6978
6979It enables persistent and aggressive caching of service and host name
6980lookups. The latter provides better host name lookup performance,
6981resilience in the face of unreliable name servers, and also better
6982privacy---often the result of host name lookups is in local cache, so
6983external name servers do not even need to be queried.
6984@end defvr
6985
6986
44abcb28
LC
6987@deffn {Scheme Procedure} syslog-service @
6988 [#:config-file @var{%default-syslog.conf}]
1068f26b 6989Return a service that runs @command{syslogd}. If the configuration file
44abcb28 6990name @var{config-file} is not specified, use some reasonable default
cf4a9129 6991settings.
44abcb28
LC
6992
6993@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
6994information on the configuration file syntax.
cf4a9129 6995@end deffn
401c53c4 6996
0adfe95a
LC
6997@anchor{guix-configuration-type}
6998@deftp {Data Type} guix-configuration
6999This data type represents the configuration of the Guix build daemon.
7000@xref{Invoking guix-daemon}, for more information.
7001
7002@table @asis
7003@item @code{guix} (default: @var{guix})
7004The Guix package to use.
401c53c4 7005
0adfe95a
LC
7006@item @code{build-group} (default: @code{"guixbuild"})
7007Name of the group for build user accounts.
401c53c4 7008
0adfe95a
LC
7009@item @code{build-accounts} (default: @code{10})
7010Number of build user accounts to create.
401c53c4 7011
0adfe95a
LC
7012@item @code{authorize-key?} (default: @code{#t})
7013Whether to authorize the substitute key for @code{hydra.gnu.org}
7014(@pxref{Substitutes}).
7015
7016@item @code{use-substitutes?} (default: @code{#t})
7017Whether to use substitutes.
7018
b0b9f6e0
LC
7019@item @code{substitute-urls} (default: @var{%default-substitute-urls})
7020The list of URLs where to look for substitutes by default.
7021
0adfe95a
LC
7022@item @code{extra-options} (default: @code{'()})
7023List of extra command-line options for @command{guix-daemon}.
7024
7025@item @code{lsof} (default: @var{lsof})
7026@itemx @code{lsh} (default: @var{lsh})
7027The lsof and lsh packages to use.
7028
7029@end table
7030@end deftp
7031
7032@deffn {Scheme Procedure} guix-service @var{config}
7033Return a service that runs the Guix build daemon according to
7034@var{config}.
cf4a9129 7035@end deffn
a1ba8475 7036
be1c2c54 7037@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
7038Run @var{udev}, which populates the @file{/dev} directory dynamically.
7039@end deffn
401c53c4 7040
be1c2c54 7041@deffn {Scheme Procedure} console-keymap-service @var{file}
dedb8d5e 7042@cindex keyboard layout
5eca9459
AK
7043Return a service to load console keymap from @var{file} using
7044@command{loadkeys} command.
7045@end deffn
7046
8664cc88
LC
7047@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
7048 [#:options]
7049Run @var{gpm}, the general-purpose mouse daemon, with the given
7050command-line @var{options}. GPM allows users to use the mouse in the console,
7051notably to select, copy, and paste text. The default value of @var{options}
7052uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7053
7054This service is not part of @var{%base-services}.
7055@end deffn
7056
1c52181f
LC
7057@anchor{guix-publish-service}
7058@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7059 [#:port 80] [#:host "localhost"]
7060Return a service that runs @command{guix publish} listening on @var{host}
7061and @var{port} (@pxref{Invoking guix publish}).
7062
7063This assumes that @file{/etc/guix} already contains a signing key pair as
7064created by @command{guix archive --generate-key} (@pxref{Invoking guix
7065archive}). If that is not the case, the service will fail to start.
7066@end deffn
7067
a69576ea 7068
cf4a9129
LC
7069@node Networking Services
7070@subsubsection Networking Services
401c53c4 7071
fa1e31b8 7072The @code{(gnu services networking)} module provides services to configure
cf4a9129 7073the network interface.
a1ba8475 7074
a023cca8 7075@cindex DHCP, networking service
be1c2c54 7076@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
7077Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7078Protocol (DHCP) client, on all the non-loopback network interfaces.
7079@end deffn
7080
be1c2c54 7081@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
7082 [#:gateway #f] [#:name-services @code{'()}]
7083Return a service that starts @var{interface} with address @var{ip}. If
7084@var{gateway} is true, it must be a string specifying the default network
7085gateway.
7086@end deffn
8b315a6d 7087
b7d0c494 7088@cindex wicd
87f40011 7089@cindex network management
be1c2c54 7090@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
7091Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7092management daemon that aims to simplify wired and wireless networking.
7093
7094This service adds the @var{wicd} package to the global profile, providing
7095several commands to interact with the daemon and configure networking:
7096@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7097and @command{wicd-curses} user interfaces.
b7d0c494
MW
7098@end deffn
7099
c0a9589d
SB
7100@cindex NetworkManager
7101@deffn {Scheme Procedure} network-manager-service @
7102 [#:network-manager @var{network-manager}]
7103Return a service that runs NetworkManager, a network connection manager
1068f26b 7104attempting to keep network connectivity active when available.
c0a9589d
SB
7105@end deffn
7106
be1c2c54 7107@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
7108 [#:name-service @var{%ntp-servers}]
7109Return a service that runs the daemon from @var{ntp}, the
7110@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7111keep the system clock synchronized with that of @var{servers}.
7112@end deffn
7113
7114@defvr {Scheme Variable} %ntp-servers
7115List of host names used as the default NTP servers.
7116@end defvr
7117
375c6108
LC
7118@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7119Return a service to run the @uref{https://torproject.org, Tor} anonymous
7120networking daemon.
8b315a6d 7121
375c6108 7122The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
7123@var{config-file}, a file-like object, with an additional @code{User tor} line
7124and lines for hidden services added via @code{tor-hidden-service}. Run
7125@command{man tor} for information about the configuration file.
7126@end deffn
7127
24a8ef3b 7128@cindex hidden service
6331bde7
LC
7129@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7130Define a new Tor @dfn{hidden service} called @var{name} and implementing
7131@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7132
7133@example
24a8ef3b
LC
7134 '((22 "127.0.0.1:22")
7135 (80 "127.0.0.1:8080"))
6331bde7
LC
7136@end example
7137
7138In this example, port 22 of the hidden service is mapped to local port 22, and
7139port 80 is mapped to local port 8080.
7140
6629099a
LC
7141This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7142the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
7143service.
7144
7145See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7146project's documentation} for more information.
cf4a9129 7147@end deffn
8b315a6d 7148
be1c2c54 7149@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
7150 [#:interface "127.0.0.1"] [#:port 6667] @
7151 [#:extra-settings ""]
7152Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7153acts as a gateway between IRC and chat networks.
7154
7155The daemon will listen to the interface corresponding to the IP address
7156specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7157local clients can connect, whereas @code{0.0.0.0} means that connections can
7158come from any networking interface.
7159
7160In addition, @var{extra-settings} specifies a string to append to the
7161configuration file.
7162@end deffn
7163
f4391bec 7164Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 7165
be1c2c54 7166@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 7167 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
7168 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7169 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7170 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 7171 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
7172Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7173@var{host-key} must designate a file containing the host key, and readable
7174only by root.
72e25e35 7175
5833bf33
DP
7176When @var{daemonic?} is true, @command{lshd} will detach from the
7177controlling terminal and log its output to syslogd, unless one sets
7178@var{syslog-output?} to false. Obviously, it also makes lsh-service
7179depend on existence of syslogd service. When @var{pid-file?} is true,
7180@command{lshd} writes its PID to the file called @var{pid-file}.
7181
cf4a9129
LC
7182When @var{initialize?} is true, automatically create the seed and host key
7183upon service activation if they do not exist yet. This may take long and
7184require interaction.
8b315a6d 7185
20dd519c
LC
7186When @var{initialize?} is false, it is up to the user to initialize the
7187randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7188a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7189basics,,, lsh, LSH Manual}).
7190
cf4a9129
LC
7191When @var{interfaces} is empty, lshd listens for connections on all the
7192network interfaces; otherwise, @var{interfaces} must be a list of host names
7193or addresses.
9bf3c1a7 7194
20dd519c
LC
7195@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7196passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 7197root.
4af2447e 7198
cf4a9129
LC
7199The other options should be self-descriptive.
7200@end deffn
4af2447e 7201
fa0c1d61
LC
7202@defvr {Scheme Variable} %facebook-host-aliases
7203This variable contains a string for use in @file{/etc/hosts}
7204(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7205line contains a entry that maps a known server name of the Facebook
7206on-line service---e.g., @code{www.facebook.com}---to the local
7207host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7208
7209This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
7210@code{operating-system} declaration (@pxref{operating-system Reference,
7211@file{/etc/hosts}}):
fa0c1d61
LC
7212
7213@example
7214(use-modules (gnu) (guix))
7215
7216(operating-system
7217 (host-name "mymachine")
7218 ;; ...
7219 (hosts-file
7220 ;; Create a /etc/hosts file with aliases for "localhost"
7221 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
7222 (plain-file "hosts"
7223 (string-append (local-host-aliases host-name)
7224 %facebook-host-aliases))))
fa0c1d61
LC
7225@end example
7226
7227This mechanism can prevent programs running locally, such as Web
7228browsers, from accessing Facebook.
7229@end defvr
7230
965a7332
LC
7231The @code{(gnu services avahi)} provides the following definition.
7232
be1c2c54 7233@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
7234 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7235 [#:ipv6? #t] [#:wide-area? #f] @
7236 [#:domains-to-browse '()]
7237Return a service that runs @command{avahi-daemon}, a system-wide
7238mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
7239"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7240extends the name service cache daemon (nscd) so that it can resolve
7241@code{.local} host names using
1065bed9
LC
7242@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7243add the @var{avahi} package to the system profile so that commands such as
7244@command{avahi-browse} are directly usable.
965a7332
LC
7245
7246If @var{host-name} is different from @code{#f}, use that as the host name to
7247publish for this machine; otherwise, use the machine's actual host name.
7248
7249When @var{publish?} is true, publishing of host names and services is allowed;
7250in particular, avahi-daemon will publish the machine's host name and IP
7251address via mDNS on the local network.
7252
7253When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7254
7255Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7256sockets.
7257@end deffn
7258
7259
cf4a9129
LC
7260@node X Window
7261@subsubsection X Window
68ad877c 7262
cf4a9129
LC
7263Support for the X Window graphical display system---specifically
7264Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7265there is no @code{xorg-service} procedure. Instead, the X server is
7266started by the @dfn{login manager}, currently SLiM.
4af2447e 7267
be1c2c54 7268@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
7269 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7270 [#:theme @var{%default-slim-theme}] @
4bd43bbe 7271 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
7272Return a service that spawns the SLiM graphical login manager, which in
7273turn starts the X display server with @var{startx}, a command as returned by
7274@code{xorg-start-command}.
4af2447e 7275
04e4e6ab
LC
7276@cindex X session
7277
7278SLiM automatically looks for session types described by the @file{.desktop}
7279files in @file{/run/current-system/profile/share/xsessions} and allows users
7280to choose a session from the log-in screen using @kbd{F1}. Packages such as
7281@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
7282adding them to the system-wide set of packages automatically makes them
7283available at the log-in screen.
7284
7285In addition, @file{~/.xsession} files are honored. When available,
7286@file{~/.xsession} must be an executable that starts a window manager
7287and/or other X clients.
7288
cf4a9129
LC
7289When @var{allow-empty-passwords?} is true, allow logins with an empty
7290password. When @var{auto-login?} is true, log in automatically as
7291@var{default-user}.
0ecc3bf3 7292
1068f26b 7293If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
7294@var{theme} must be a gexp denoting the name of a directory containing the
7295theme to use. In that case, @var{theme-name} specifies the name of the
7296theme.
cf4a9129 7297@end deffn
4af2447e 7298
0ecc3bf3
LC
7299@defvr {Scheme Variable} %default-theme
7300@defvrx {Scheme Variable} %default-theme-name
7301The G-Expression denoting the default SLiM theme and its name.
7302@end defvr
7303
be1c2c54 7304@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 7305 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 7306Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
7307from @var{xorg-server}. @var{configuration-file} is the server configuration
7308file or a derivation that builds it; when omitted, the result of
7309@code{xorg-configuration-file} is used.
7310
7311Usually the X server is started by a login manager.
7312@end deffn
7313
be1c2c54 7314@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 7315 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
7316Return a configuration file for the Xorg server containing search paths for
7317all the common drivers.
f703413e
LC
7318
7319@var{drivers} must be either the empty list, in which case Xorg chooses a
7320graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 7321this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
7322
7323Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7324appropriate screen resolution; otherwise, it must be a list of
7325resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
7326
7327Last, @var{extra-config} is a list of strings or objects appended to the
7328@code{text-file*} argument list. It is used to pass extra text to be added
7329verbatim to the configuration file.
f703413e 7330@end deffn
4af2447e 7331
6726282b
LC
7332@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7333Add @var{package}, a package for a screen-locker or screen-saver whose
7334command is @var{program}, to the set of setuid programs and add a PAM entry
7335for it. For example:
7336
7337@lisp
7338(screen-locker-service xlockmore "xlock")
7339@end lisp
7340
7341makes the good ol' XlockMore usable.
7342@end deffn
7343
7344
fe1a39d3
LC
7345@node Desktop Services
7346@subsubsection Desktop Services
aa4ed923 7347
fe1a39d3
LC
7348The @code{(gnu services desktop)} module provides services that are
7349usually useful in the context of a ``desktop'' setup---that is, on a
7350machine running a graphical display server, possibly with graphical user
7351interfaces, etc.
aa4ed923 7352
4467be21
LC
7353To simplify things, the module defines a variable containing the set of
7354services that users typically expect on a machine with a graphical
7355environment and networking:
7356
7357@defvr {Scheme Variable} %desktop-services
7358This is a list of services that builds upon @var{%base-services} and
1068f26b 7359adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
7360
7361In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
7362@code{slim-service}}), screen lockers,
7363a network management tool (@pxref{Networking
4467be21 7364Services, @code{wicd-service}}), energy and color management services,
4650a77e 7365the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
7366the GeoClue location service, an NTP client (@pxref{Networking
7367Services}), the Avahi daemon, and has the name service switch service
7368configured to be able to use @code{nss-mdns} (@pxref{Name Service
7369Switch, mDNS}).
4467be21
LC
7370@end defvr
7371
7372The @var{%desktop-services} variable can be used as the @code{services}
7373field of an @code{operating-system} declaration (@pxref{operating-system
7374Reference, @code{services}}).
7375
0adfe95a
LC
7376The actual service definitions provided by @code{(gnu services dbus)}
7377and @code{(gnu services desktop)} are described below.
4467be21 7378
0adfe95a 7379@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
7380Return a service that runs the ``system bus'', using @var{dbus}, with
7381support for @var{services}.
aa4ed923 7382
fe1a39d3
LC
7383@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7384facility. Its system bus is used to allow system services to communicate
1068f26b 7385and to be notified of system-wide events.
aa4ed923 7386
fe1a39d3
LC
7387@var{services} must be a list of packages that provide an
7388@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7389and policy files. For example, to allow avahi-daemon to use the system bus,
7390@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
7391@end deffn
7392
0adfe95a 7393@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
7394Return a service that runs the @code{elogind} login and
7395seat management daemon. @uref{https://github.com/andywingo/elogind,
7396Elogind} exposes a D-Bus interface that can be used to know which users
7397are logged in, know what kind of sessions they have open, suspend the
7398system, inhibit system suspend, reboot the system, and other tasks.
7399
7400Elogind handles most system-level power events for a computer, for
7401example suspending the system when a lid is closed, or shutting it down
7402when the power button is pressed.
7403
7404The @var{config} keyword argument specifies the configuration for
1068f26b 7405elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
7406(@var{parameter} @var{value})...)} invocation. Available parameters and
7407their default values are:
7408
7409@table @code
7410@item kill-user-processes?
7411@code{#f}
7412@item kill-only-users
7413@code{()}
7414@item kill-exclude-users
7415@code{("root")}
7416@item inhibit-delay-max-seconds
7417@code{5}
7418@item handle-power-key
7419@code{poweroff}
7420@item handle-suspend-key
7421@code{suspend}
7422@item handle-hibernate-key
7423@code{hibernate}
7424@item handle-lid-switch
7425@code{suspend}
7426@item handle-lid-switch-docked
7427@code{ignore}
7428@item power-key-ignore-inhibited?
7429@code{#f}
7430@item suspend-key-ignore-inhibited?
7431@code{#f}
7432@item hibernate-key-ignore-inhibited?
7433@code{#f}
7434@item lid-switch-ignore-inhibited?
7435@code{#t}
7436@item holdoff-timeout-seconds
7437@code{30}
7438@item idle-action
7439@code{ignore}
7440@item idle-action-seconds
7441@code{(* 30 60)}
7442@item runtime-directory-size-percent
7443@code{10}
7444@item runtime-directory-size
7445@code{#f}
7446@item remove-ipc?
7447@code{#t}
7448@item suspend-state
7449@code{("mem" "standby" "freeze")}
7450@item suspend-mode
7451@code{()}
7452@item hibernate-state
7453@code{("disk")}
7454@item hibernate-mode
7455@code{("platform" "shutdown")}
7456@item hybrid-sleep-state
7457@code{("disk")}
7458@item hybrid-sleep-mode
7459@code{("suspend" "platform" "shutdown")}
7460@end table
7461@end deffn
7462
be1c2c54 7463@deffn {Scheme Procedure} polkit-service @
4650a77e 7464 [#:polkit @var{polkit}]
222e3319
LC
7465Return a service that runs the
7466@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7467management service}, which allows system administrators to grant access to
7468privileged operations in a structured way. By querying the Polkit service, a
7469privileged system component can know when it should grant additional
7470capabilities to ordinary users. For example, an ordinary user can be granted
7471the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7472@end deffn
7473
be1c2c54 7474@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7475 [#:watts-up-pro? #f] @
7476 [#:poll-batteries? #t] @
7477 [#:ignore-lid? #f] @
7478 [#:use-percentage-for-policy? #f] @
7479 [#:percentage-low 10] @
7480 [#:percentage-critical 3] @
7481 [#:percentage-action 2] @
7482 [#:time-low 1200] @
7483 [#:time-critical 300] @
7484 [#:time-action 120] @
7485 [#:critical-power-action 'hybrid-sleep]
7486Return a service that runs @uref{http://upower.freedesktop.org/,
7487@command{upowerd}}, a system-wide monitor for power consumption and battery
7488levels, with the given configuration settings. It implements the
7489@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7490GNOME.
7491@end deffn
7492
2b9e0a94
LC
7493@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7494Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7495UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7496notifications and ways to mount/unmount disks. Programs that talk to UDisks
7497include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7498@end deffn
7499
be1c2c54 7500@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7501Return a service that runs @command{colord}, a system service with a D-Bus
7502interface to manage the color profiles of input and output devices such as
7503screens and scanners. It is notably used by the GNOME Color Manager graphical
7504tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7505site} for more information.
7506@end deffn
7507
cee32ee4 7508@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 7509Return a configuration allowing an application to access GeoClue
cee32ee4
AW
7510location data. @var{name} is the Desktop ID of the application, without
7511the @code{.desktop} part. If @var{allowed?} is true, the application
7512will have access to location information by default. The boolean
1068f26b 7513@var{system?} value indicates whether an application is a system component
cee32ee4
AW
7514or not. Finally @var{users} is a list of UIDs of all users for which
7515this application is allowed location info access. An empty users list
7516means that all users are allowed.
7517@end deffn
7518
7519@defvr {Scheme Variable} %standard-geoclue-applications
7520The standard list of well-known GeoClue application configurations,
1068f26b
AE
7521granting authority to the GNOME date-and-time utility to ask for the
7522current location in order to set the time zone, and allowing the
7523IceCat and Epiphany web browsers to request location information.
7524IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
7525know the user's location.
7526@end defvr
7527
be1c2c54 7528@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7529 [#:whitelist '()] @
7530 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7531 [#:submit-data? #f]
7532 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7533 [#:submission-nick "geoclue"] @
7534 [#:applications %standard-geoclue-applications]
7535Return a service that runs the GeoClue location service. This service
7536provides a D-Bus interface to allow applications to request access to a
7537user's physical location, and optionally to add information to online
7538location databases. See
7539@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7540web site} for more information.
7541@end deffn
7542
105369a4
DT
7543@node Database Services
7544@subsubsection Database Services
7545
7546The @code{(gnu services databases)} module provides the following service.
7547
be1c2c54 7548@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7549 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7550Return a service that runs @var{postgresql}, the PostgreSQL database
7551server.
7552
7553The PostgreSQL daemon loads its runtime configuration from
7554@var{config-file} and stores the database cluster in
7555@var{data-directory}.
7556@end deffn
fe1a39d3 7557
d8c18af8
AW
7558@node Mail Services
7559@subsubsection Mail Services
7560
7561The @code{(gnu services mail)} module provides Guix service definitions
7562for mail services. Currently the only implemented service is Dovecot,
7563an IMAP, POP3, and LMTP server.
7564
7565Guix does not yet have a mail transfer agent (MTA), although for some
7566lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7567is needed to properly integrate a full MTA, such as Postfix. Patches
7568welcome!
7569
7570To add an IMAP/POP3 server to a GuixSD system, add a
7571@code{dovecot-service} to the operating system definition:
7572
7573@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7574Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7575@end deffn
7576
1068f26b 7577By default, Dovecot does not need much configuration; the default
d8c18af8
AW
7578configuration object created by @code{(dovecot-configuration)} will
7579suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7580certificate will be generated for TLS-protected connections, though
7581Dovecot will also listen on cleartext ports by default. There are a
1068f26b 7582number of options, though, which mail administrators might need to change,
d8c18af8
AW
7583and as is the case with other services, Guix allows the system
7584administrator to specify these parameters via a uniform Scheme interface.
7585
7586For example, to specify that mail is located at @code{maildir~/.mail},
7587one would instantiate the Dovecot service like this:
7588
7589@example
7590(dovecot-service #:config
7591 (dovecot-configuration
7592 (mail-location "maildir:~/.mail")))
7593@end example
7594
7595The available configuration parameters follow. Each parameter
7596definition is preceded by its type; for example, @samp{string-list foo}
7597indicates that the @code{foo} parameter should be specified as a list of
7598strings. There is also a way to specify the configuration as a string,
7599if you have an old @code{dovecot.conf} file that you want to port over
7600from some other system; see the end for more details.
7601
7602@c The following documentation was initially generated by
7603@c (generate-documentation) in (gnu services mail). Manually maintained
7604@c documentation is better, so we shouldn't hesitate to edit below as
7605@c needed. However if the change you want to make to this documentation
7606@c can be done in an automated way, it's probably easier to change
7607@c (generate-documentation) than to make it below and have to deal with
7608@c the churn as dovecot updates.
7609
7610Available @code{dovecot-configuration} fields are:
7611
7612@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7613The dovecot package.
7614@end deftypevr
7615
7616@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
7617A list of IPs or hosts where to listen for connections. @samp{*}
7618listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
7619interfaces. If you want to specify non-default ports or anything more
7620complex, customize the address and port fields of the
7621@samp{inet-listener} of the specific services you are interested in.
7622@end deftypevr
7623
7624@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7625List of protocols we want to serve. Available protocols include
7626@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7627
7628Available @code{protocol-configuration} fields are:
7629
7630@deftypevr {@code{protocol-configuration} parameter} string name
7631The name of the protocol.
7632@end deftypevr
7633
7634@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 7635UNIX socket path to the master authentication server to find users.
d8c18af8 7636This is used by imap (for shared users) and lda.
1068f26b 7637It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
7638@end deftypevr
7639
7640@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7641Space separated list of plugins to load.
7642@end deftypevr
7643
7644@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7645Maximum number of IMAP connections allowed for a user from each IP
7646address. NOTE: The username is compared case-sensitively.
7647Defaults to @samp{10}.
7648@end deftypevr
7649
7650@end deftypevr
7651
7652@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7653List of services to enable. Available services include @samp{imap},
7654@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7655@samp{lmtp}.
7656
7657Available @code{service-configuration} fields are:
7658
7659@deftypevr {@code{service-configuration} parameter} string kind
7660The service kind. Valid values include @code{director},
7661@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7662@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7663@code{tcpwrap}, @code{quota-warning}, or anything else.
7664@end deftypevr
7665
7666@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 7667Listeners for the service. A listener is either a
d8c18af8
AW
7668@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7669an @code{inet-listener-configuration}.
7670Defaults to @samp{()}.
7671
7672Available @code{unix-listener-configuration} fields are:
7673
7674@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7675The file name on which to listen.
7676@end deftypevr
7677
7678@deftypevr {@code{unix-listener-configuration} parameter} string mode
7679The access mode for the socket.
7680Defaults to @samp{"0600"}.
7681@end deftypevr
7682
7683@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 7684The user to own the socket.
d8c18af8
AW
7685Defaults to @samp{""}.
7686@end deftypevr
7687
7688@deftypevr {@code{unix-listener-configuration} parameter} string group
7689The group to own the socket.
7690Defaults to @samp{""}.
7691@end deftypevr
7692
7693
7694Available @code{fifo-listener-configuration} fields are:
7695
7696@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7697The file name on which to listen.
7698@end deftypevr
7699
7700@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7701The access mode for the socket.
7702Defaults to @samp{"0600"}.
7703@end deftypevr
7704
7705@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 7706The user to own the socket.
d8c18af8
AW
7707Defaults to @samp{""}.
7708@end deftypevr
7709
7710@deftypevr {@code{fifo-listener-configuration} parameter} string group
7711The group to own the socket.
7712Defaults to @samp{""}.
7713@end deftypevr
7714
7715
7716Available @code{inet-listener-configuration} fields are:
7717
7718@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7719The protocol to listen for.
7720@end deftypevr
7721
7722@deftypevr {@code{inet-listener-configuration} parameter} string address
7723The address on which to listen, or empty for all addresses.
7724Defaults to @samp{""}.
7725@end deftypevr
7726
7727@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7728The port on which to listen.
7729@end deftypevr
7730
7731@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7732Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7733@samp{required}.
7734Defaults to @samp{#t}.
7735@end deftypevr
7736
7737@end deftypevr
7738
7739@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7740Number of connections to handle before starting a new process.
7741Typically the only useful values are 0 (unlimited) or 1. 1 is more
7742secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7743Defaults to @samp{1}.
7744@end deftypevr
7745
7746@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7747Number of processes to always keep waiting for more connections.
7748Defaults to @samp{0}.
7749@end deftypevr
7750
7751@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7752If you set @samp{service-count 0}, you probably need to grow
7753this.
7754Defaults to @samp{256000000}.
7755@end deftypevr
7756
7757@end deftypevr
7758
7759@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7760Dict configuration, as created by the @code{dict-configuration}
7761constructor.
7762
7763Available @code{dict-configuration} fields are:
7764
7765@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7766A list of key-value pairs that this dict should hold.
7767Defaults to @samp{()}.
7768@end deftypevr
7769
7770@end deftypevr
7771
7772@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 7773A list of passdb configurations, each one created by the
d8c18af8
AW
7774@code{passdb-configuration} constructor.
7775
7776Available @code{passdb-configuration} fields are:
7777
7778@deftypevr {@code{passdb-configuration} parameter} string driver
7779The driver that the passdb should use. Valid values include
7780@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7781@samp{static}.
7782Defaults to @samp{"pam"}.
7783@end deftypevr
7784
7785@deftypevr {@code{passdb-configuration} parameter} free-form-args args
7786A list of key-value args to the passdb driver.
7787Defaults to @samp{()}.
7788@end deftypevr
7789
7790@end deftypevr
7791
7792@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7793List of userdb configurations, each one created by the
7794@code{userdb-configuration} constructor.
7795
7796Available @code{userdb-configuration} fields are:
7797
7798@deftypevr {@code{userdb-configuration} parameter} string driver
7799The driver that the userdb should use. Valid values include
7800@samp{passwd} and @samp{static}.
7801Defaults to @samp{"passwd"}.
7802@end deftypevr
7803
7804@deftypevr {@code{userdb-configuration} parameter} free-form-args args
7805A list of key-value args to the userdb driver.
7806Defaults to @samp{()}.
7807@end deftypevr
7808
7809@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7810Override fields from passwd.
7811Defaults to @samp{()}.
7812@end deftypevr
7813
7814@end deftypevr
7815
7816@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7817Plug-in configuration, created by the @code{plugin-configuration}
7818constructor.
7819@end deftypevr
7820
7821@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7822List of namespaces. Each item in the list is created by the
7823@code{namespace-configuration} constructor.
7824
7825Available @code{namespace-configuration} fields are:
7826
7827@deftypevr {@code{namespace-configuration} parameter} string name
7828Name for this namespace.
7829@end deftypevr
7830
7831@deftypevr {@code{namespace-configuration} parameter} string type
7832Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7833Defaults to @samp{"private"}.
7834@end deftypevr
7835
7836@deftypevr {@code{namespace-configuration} parameter} string separator
7837Hierarchy separator to use. You should use the same separator for
7838all namespaces or some clients get confused. @samp{/} is usually a good
7839one. The default however depends on the underlying mail storage
7840format.
7841Defaults to @samp{""}.
7842@end deftypevr
7843
7844@deftypevr {@code{namespace-configuration} parameter} string prefix
7845Prefix required to access this namespace. This needs to be
7846different for all namespaces. For example @samp{Public/}.
7847Defaults to @samp{""}.
7848@end deftypevr
7849
7850@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 7851Physical location of the mailbox. This is in the same format as
d8c18af8
AW
7852mail_location, which is also the default for it.
7853Defaults to @samp{""}.
7854@end deftypevr
7855
7856@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7857There can be only one INBOX, and this setting defines which
7858namespace has it.
7859Defaults to @samp{#f}.
7860@end deftypevr
7861
7862@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7863If namespace is hidden, it's not advertised to clients via NAMESPACE
7864extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7865useful when converting from another server with different namespaces
7866which you want to deprecate but still keep working. For example you can
7867create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7868and @samp{mail/}.
7869Defaults to @samp{#f}.
7870@end deftypevr
7871
7872@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
7873Show the mailboxes under this namespace with the LIST command. This
7874makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
7875extension. The special @code{children} value lists child mailboxes, but
7876hides the namespace prefix.
7877Defaults to @samp{#t}.
7878@end deftypevr
7879
7880@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7881Namespace handles its own subscriptions. If set to @code{#f}, the
7882parent namespace handles them. The empty prefix should always have this
1068f26b 7883as @code{#t}).
d8c18af8
AW
7884Defaults to @samp{#t}.
7885@end deftypevr
7886
7887@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7888List of predefined mailboxes in this namespace.
7889Defaults to @samp{()}.
7890
7891Available @code{mailbox-configuration} fields are:
7892
7893@deftypevr {@code{mailbox-configuration} parameter} string name
7894Name for this mailbox.
7895@end deftypevr
7896
7897@deftypevr {@code{mailbox-configuration} parameter} string auto
7898@samp{create} will automatically create this mailbox.
7899@samp{subscribe} will both create and subscribe to the mailbox.
7900Defaults to @samp{"no"}.
7901@end deftypevr
7902
7903@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7904List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7905Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7906@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7907Defaults to @samp{()}.
7908@end deftypevr
7909
7910@end deftypevr
7911
7912@end deftypevr
7913
7914@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7915Base directory where to store runtime data.
7916Defaults to @samp{"/var/run/dovecot/"}.
7917@end deftypevr
7918
7919@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7920Greeting message for clients.
7921Defaults to @samp{"Dovecot ready."}.
7922@end deftypevr
7923
7924@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7925List of trusted network ranges. Connections from these IPs are
7926allowed to override their IP addresses and ports (for logging and for
7927authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 7928for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
7929here.
7930Defaults to @samp{()}.
7931@end deftypevr
7932
7933@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7934List of login access check sockets (e.g. tcpwrap).
7935Defaults to @samp{()}.
7936@end deftypevr
7937
7938@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7939Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
7940and IP address. Useful for seeing who is actually using the IMAP
7941processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
7942accounts).
7943Defaults to @samp{#f}.
7944@end deftypevr
7945
7946@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
7947Should all processes be killed when Dovecot master process shuts down.
7948Setting this to @code{#f} means that Dovecot can be upgraded without
7949forcing existing client connections to close (although that could also
1068f26b 7950be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
7951Defaults to @samp{#t}.
7952@end deftypevr
7953
7954@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
7955If non-zero, run mail commands via this many connections to doveadm
7956server, instead of running them directly in the same process.
7957Defaults to @samp{0}.
7958@end deftypevr
7959
7960@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
7961UNIX socket or host:port used for connecting to doveadm server.
7962Defaults to @samp{"doveadm-server"}.
7963@end deftypevr
7964
7965@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
7966List of environment variables that are preserved on Dovecot startup
7967and passed down to all of its child processes. You can also give
7968key=value pairs to always set specific settings.
7969@end deftypevr
7970
7971@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
7972Disable LOGIN command and all other plaintext authentications unless
7973SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
7974matches the local IP (i.e. you're connecting from the same computer),
7975the connection is considered secure and plaintext authentication is
7976allowed. See also ssl=required setting.
7977Defaults to @samp{#t}.
7978@end deftypevr
7979
7980@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
7981Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
7982Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
7983for caching to be used.
7984Defaults to @samp{0}.
7985@end deftypevr
7986
7987@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
7988Time to live for cached data. After TTL expires the cached record
7989is no longer used, *except* if the main database lookup returns internal
7990failure. We also try to handle password changes automatically: If
7991user's previous authentication was successful, but this one wasn't, the
7992cache isn't used. For now this works only with plaintext
7993authentication.
7994Defaults to @samp{"1 hour"}.
7995@end deftypevr
7996
7997@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
7998TTL for negative hits (user not found, password mismatch).
79990 disables caching them completely.
8000Defaults to @samp{"1 hour"}.
8001@end deftypevr
8002
8003@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
8004List of realms for SASL authentication mechanisms that need them.
8005You can leave it empty if you don't want to support multiple realms.
8006Many clients simply use the first one listed here, so keep the default
8007realm first.
8008Defaults to @samp{()}.
8009@end deftypevr
8010
8011@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
8012Default realm/domain to use if none was specified. This is used for
8013both SASL realms and appending @@domain to username in plaintext
8014logins.
8015Defaults to @samp{""}.
8016@end deftypevr
8017
8018@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
8019List of allowed characters in username. If the user-given username
8020contains a character not listed in here, the login automatically fails.
8021This is just an extra check to make sure user can't exploit any
8022potential quote escaping vulnerabilities with SQL/LDAP databases. If
8023you want to allow all characters, set this value to empty.
8024Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8025@end deftypevr
8026
8027@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8028Username character translations before it's looked up from
8029databases. The value contains series of from -> to characters. For
8030example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8031translated to @samp{@@}.
8032Defaults to @samp{""}.
8033@end deftypevr
8034
8035@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8036Username formatting before it's looked up from databases. You can
8037use the standard variables here, e.g. %Lu would lowercase the username,
8038%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8039change the @samp{@@} into @samp{-AT-}. This translation is done after
8040@samp{auth-username-translation} changes.
8041Defaults to @samp{"%Lu"}.
8042@end deftypevr
8043
8044@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8045If you want to allow master users to log in by specifying the master
8046username within the normal username string (i.e. not using SASL
8047mechanism's support for it), you can specify the separator character
8048here. The format is then <username><separator><master username>.
8049UW-IMAP uses @samp{*} as the separator, so that could be a good
8050choice.
8051Defaults to @samp{""}.
8052@end deftypevr
8053
8054@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8055Username to use for users logging in with ANONYMOUS SASL
8056mechanism.
8057Defaults to @samp{"anonymous"}.
8058@end deftypevr
8059
8060@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8061Maximum number of dovecot-auth worker processes. They're used to
8062execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8063They're automatically created and destroyed as needed.
8064Defaults to @samp{30}.
8065@end deftypevr
8066
8067@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8068Host name to use in GSSAPI principal names. The default is to use
8069the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8070allow all keytab entries.
8071Defaults to @samp{""}.
8072@end deftypevr
8073
8074@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8075Kerberos keytab to use for the GSSAPI mechanism. Will use the
8076system default (usually /etc/krb5.keytab) if not specified. You may
8077need to change the auth service to run as root to be able to read this
8078file.
8079Defaults to @samp{""}.
8080@end deftypevr
8081
8082@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8083Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8084and @samp{ntlm-auth} helper.
8085<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8086Defaults to @samp{#f}.
8087@end deftypevr
8088
8089@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8090Path for Samba's @samp{ntlm-auth} helper binary.
8091Defaults to @samp{"/usr/bin/ntlm_auth"}.
8092@end deftypevr
8093
8094@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8095Time to delay before replying to failed authentications.
8096Defaults to @samp{"2 secs"}.
8097@end deftypevr
8098
8099@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8100Require a valid SSL client certificate or the authentication
8101fails.
8102Defaults to @samp{#f}.
8103@end deftypevr
8104
8105@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8106Take the username from client's SSL certificate, using
8107@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8108CommonName.
8109Defaults to @samp{#f}.
8110@end deftypevr
8111
8112@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8113List of wanted authentication mechanisms. Supported mechanisms are:
8114@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8115@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8116@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8117@samp{disable-plaintext-auth} setting.
8118@end deftypevr
8119
8120@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8121List of IPs or hostnames to all director servers, including ourself.
8122Ports can be specified as ip:port. The default port is the same as what
8123director service's @samp{inet-listener} is using.
8124Defaults to @samp{()}.
8125@end deftypevr
8126
8127@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8128List of IPs or hostnames to all backend mail servers. Ranges are
8129allowed too, like 10.0.0.10-10.0.0.30.
8130Defaults to @samp{()}.
8131@end deftypevr
8132
8133@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8134How long to redirect users to a specific server after it no longer
8135has any connections.
8136Defaults to @samp{"15 min"}.
8137@end deftypevr
8138
8139@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8140TCP/IP port that accepts doveadm connections (instead of director
8141connections) If you enable this, you'll also need to add
8142@samp{inet-listener} for the port.
8143Defaults to @samp{0}.
8144@end deftypevr
8145
8146@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8147How the username is translated before being hashed. Useful values
8148include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8149are shared within domain.
8150Defaults to @samp{"%Lu"}.
8151@end deftypevr
8152
8153@deftypevr {@code{dovecot-configuration} parameter} string log-path
8154Log file to use for error messages. @samp{syslog} logs to syslog,
8155@samp{/dev/stderr} logs to stderr.
8156Defaults to @samp{"syslog"}.
8157@end deftypevr
8158
8159@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8160Log file to use for informational messages. Defaults to
8161@samp{log-path}.
8162Defaults to @samp{""}.
8163@end deftypevr
8164
8165@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8166Log file to use for debug messages. Defaults to
8167@samp{info-log-path}.
8168Defaults to @samp{""}.
8169@end deftypevr
8170
8171@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8172Syslog facility to use if you're logging to syslog. Usually if you
8173don't want to use @samp{mail}, you'll use local0..local7. Also other
8174standard facilities are supported.
8175Defaults to @samp{"mail"}.
8176@end deftypevr
8177
8178@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8179Log unsuccessful authentication attempts and the reasons why they
8180failed.
8181Defaults to @samp{#f}.
8182@end deftypevr
8183
8184@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8185In case of password mismatches, log the attempted password. Valid
8186values are no, plain and sha1. sha1 can be useful for detecting brute
8187force password attempts vs. user simply trying the same password over
8188and over again. You can also truncate the value to n chars by appending
8189":n" (e.g. sha1:6).
8190Defaults to @samp{#f}.
8191@end deftypevr
8192
8193@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8194Even more verbose logging for debugging purposes. Shows for example
8195SQL queries.
8196Defaults to @samp{#f}.
8197@end deftypevr
8198
8199@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
8200In case of password mismatches, log the passwords and used scheme so
8201the problem can be debugged. Enabling this also enables
8202@samp{auth-debug}.
8203Defaults to @samp{#f}.
8204@end deftypevr
8205
8206@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
8207Enable mail process debugging. This can help you figure out why
8208Dovecot isn't finding your mails.
8209Defaults to @samp{#f}.
8210@end deftypevr
8211
8212@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
8213Show protocol level SSL errors.
8214Defaults to @samp{#f}.
8215@end deftypevr
8216
8217@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
8218Prefix for each line written to log file. % codes are in
8219strftime(3) format.
8220Defaults to @samp{"\"%b %d %H:%M:%S \""}.
8221@end deftypevr
8222
8223@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
8224List of elements we want to log. The elements which have a
8225non-empty variable value are joined together to form a comma-separated
8226string.
8227@end deftypevr
8228
8229@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
8230Login log format. %s contains @samp{login-log-format-elements}
8231string, %$ contains the data we want to log.
8232Defaults to @samp{"%$: %s"}.
8233@end deftypevr
8234
8235@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
8236Log prefix for mail processes. See doc/wiki/Variables.txt for list
8237of possible variables you can use.
8238Defaults to @samp{"\"%s(%u): \""}.
8239@end deftypevr
8240
8241@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
8242Format to use for logging mail deliveries. You can use variables:
8243@table @code
8244@item %$
8245Delivery status message (e.g. @samp{saved to INBOX})
8246@item %m
8247Message-ID
8248@item %s
8249Subject
8250@item %f
8251From address
8252@item %p
8253Physical size
8254@item %w
8255Virtual size.
8256@end table
8257Defaults to @samp{"msgid=%m: %$"}.
8258@end deftypevr
8259
8260@deftypevr {@code{dovecot-configuration} parameter} string mail-location
8261Location for users' mailboxes. The default is empty, which means
8262that Dovecot tries to find the mailboxes automatically. This won't work
8263if the user doesn't yet have any mail, so you should explicitly tell
8264Dovecot the full location.
8265
8266If you're using mbox, giving a path to the INBOX
8267file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
8268where the other mailboxes are kept. This is called the "root mail
8269directory", and it must be the first path given in the
8270@samp{mail-location} setting.
8271
8272There are a few special variables you can use, eg.:
8273
8274@table @samp
8275@item %u
8276username
8277@item %n
8278user part in user@@domain, same as %u if there's no domain
8279@item %d
8280domain part in user@@domain, empty if there's no domain
8281@item %h
8282home director
8283@end table
8284
8285See doc/wiki/Variables.txt for full list. Some examples:
8286@table @samp
8287@item maildir:~/Maildir
8288@item mbox:~/mail:INBOX=/var/mail/%u
8289@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
8290@end table
8291Defaults to @samp{""}.
8292@end deftypevr
8293
8294@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8295System user and group used to access mails. If you use multiple,
8296userdb can override these by returning uid or gid fields. You can use
8297either numbers or names. <doc/wiki/UserIds.txt>.
8298Defaults to @samp{""}.
8299@end deftypevr
8300
8301@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8302
8303Defaults to @samp{""}.
8304@end deftypevr
8305
8306@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8307Group to enable temporarily for privileged operations. Currently
8308this is used only with INBOX when either its initial creation or
8309dotlocking fails. Typically this is set to "mail" to give access to
8310/var/mail.
8311Defaults to @samp{""}.
8312@end deftypevr
8313
8314@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8315Grant access to these supplementary groups for mail processes.
8316Typically these are used to set up access to shared mailboxes. Note
8317that it may be dangerous to set these if users can create
8318symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8319could allow a user to delete others' mailboxes, or ln -s
8320/secret/shared/box ~/mail/mybox would allow reading it).
8321Defaults to @samp{""}.
8322@end deftypevr
8323
8324@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8325Allow full filesystem access to clients. There's no access checks
8326other than what the operating system does for the active UID/GID. It
8327works with both maildir and mboxes, allowing you to prefix mailboxes
8328names with e.g. /path/ or ~user/.
8329Defaults to @samp{#f}.
8330@end deftypevr
8331
8332@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8333Don't use mmap() at all. This is required if you store indexes to
8334shared filesystems (NFS or clustered filesystem).
8335Defaults to @samp{#f}.
8336@end deftypevr
8337
8338@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8339Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8340supports @samp{O_EXCL} since version 3, so this should be safe to use
8341nowadays by default.
8342Defaults to @samp{#t}.
8343@end deftypevr
8344
8345@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8346When to use fsync() or fdatasync() calls:
8347@table @code
8348@item optimized
8349Whenever necessary to avoid losing important data
8350@item always
8351Useful with e.g. NFS when write()s are delayed
8352@item never
8353Never use it (best performance, but crashes can lose data).
8354@end table
8355Defaults to @samp{"optimized"}.
8356@end deftypevr
8357
8358@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8359Mail storage exists in NFS. Set this to yes to make Dovecot flush
8360NFS caches whenever needed. If you're using only a single mail server
8361this isn't needed.
8362Defaults to @samp{#f}.
8363@end deftypevr
8364
8365@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8366Mail index files also exist in NFS. Setting this to yes requires
8367@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8368Defaults to @samp{#f}.
8369@end deftypevr
8370
8371@deftypevr {@code{dovecot-configuration} parameter} string lock-method
8372Locking method for index files. Alternatives are fcntl, flock and
8373dotlock. Dotlocking uses some tricks which may create more disk I/O
8374than other locking methods. NFS users: flock doesn't work, remember to
8375change @samp{mmap-disable}.
8376Defaults to @samp{"fcntl"}.
8377@end deftypevr
8378
8379@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8380Directory in which LDA/LMTP temporarily stores incoming mails >128
8381kB.
8382Defaults to @samp{"/tmp"}.
8383@end deftypevr
8384
8385@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8386Valid UID range for users. This is mostly to make sure that users can't
8387log in as daemons or other system users. Note that denying root logins is
8388hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8389is set to 0.
8390Defaults to @samp{500}.
8391@end deftypevr
8392
8393@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8394
8395Defaults to @samp{0}.
8396@end deftypevr
8397
8398@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8399Valid GID range for users. Users having non-valid GID as primary group ID
8400aren't allowed to log in. If user belongs to supplementary groups with
8401non-valid GIDs, those groups are not set.
8402Defaults to @samp{1}.
8403@end deftypevr
8404
8405@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8406
8407Defaults to @samp{0}.
8408@end deftypevr
8409
8410@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8411Maximum allowed length for mail keyword name. It's only forced when
8412trying to create new keywords.
8413Defaults to @samp{50}.
8414@end deftypevr
8415
8416@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8417List of directories under which chrooting is allowed for mail
8418processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8419too). This setting doesn't affect @samp{login-chroot}
8420@samp{mail-chroot} or auth chroot settings. If this setting is empty,
8421"/./" in home dirs are ignored. WARNING: Never add directories here
8422which local users can modify, that may lead to root exploit. Usually
8423this should be done only if you don't allow shell access for users.
8424<doc/wiki/Chrooting.txt>.
8425Defaults to @samp{()}.
8426@end deftypevr
8427
8428@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8429Default chroot directory for mail processes. This can be overridden
8430for specific users in user database by giving /./ in user's home
8431directory (e.g. /home/./user chroots into /home). Note that usually
8432there is no real need to do chrooting, Dovecot doesn't allow users to
8433access files outside their mail directory anyway. If your home
8434directories are prefixed with the chroot directory, append "/." to
8435@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8436Defaults to @samp{""}.
8437@end deftypevr
8438
8439@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8440UNIX socket path to master authentication server to find users.
8441This is used by imap (for shared users) and lda.
8442Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8443@end deftypevr
8444
8445@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8446Directory where to look up mail plugins.
8447Defaults to @samp{"/usr/lib/dovecot"}.
8448@end deftypevr
8449
8450@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8451List of plugins to load for all services. Plugins specific to IMAP,
8452LDA, etc. are added to this list in their own .conf files.
8453Defaults to @samp{()}.
8454@end deftypevr
8455
8456@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8457The minimum number of mails in a mailbox before updates are done to
8458cache file. This allows optimizing Dovecot's behavior to do less disk
8459writes at the cost of more disk reads.
8460Defaults to @samp{0}.
8461@end deftypevr
8462
8463@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8464When IDLE command is running, mailbox is checked once in a while to
8465see if there are any new mails or other changes. This setting defines
8466the minimum time to wait between those checks. Dovecot can also use
8467dnotify, inotify and kqueue to find out immediately when changes
8468occur.
8469Defaults to @samp{"30 secs"}.
8470@end deftypevr
8471
8472@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8473Save mails with CR+LF instead of plain LF. This makes sending those
8474mails take less CPU, especially with sendfile() syscall with Linux and
8475FreeBSD. But it also creates a bit more disk I/O which may just make it
8476slower. Also note that if other software reads the mboxes/maildirs,
8477they may handle the extra CRs wrong and cause problems.
8478Defaults to @samp{#f}.
8479@end deftypevr
8480
8481@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8482By default LIST command returns all entries in maildir beginning
8483with a dot. Enabling this option makes Dovecot return only entries
8484which are directories. This is done by stat()ing each entry, so it
8485causes more disk I/O.
8486 (For systems setting struct @samp{dirent->d_type} this check is free
8487and it's done always regardless of this setting).
8488Defaults to @samp{#f}.
8489@end deftypevr
8490
8491@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8492When copying a message, do it with hard links whenever possible.
8493This makes the performance much better, and it's unlikely to have any
8494side effects.
8495Defaults to @samp{#t}.
8496@end deftypevr
8497
8498@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8499Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8500directory only when its mtime changes unexpectedly or when we can't find
8501the mail otherwise.
8502Defaults to @samp{#f}.
8503@end deftypevr
8504
8505@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8506Which locking methods to use for locking mbox. There are four
8507available:
8508
8509@table @code
8510@item dotlock
8511Create <mailbox>.lock file. This is the oldest and most NFS-safe
8512solution. If you want to use /var/mail/ like directory, the users will
8513need write access to that directory.
8514@item dotlock-try
8515Same as dotlock, but if it fails because of permissions or because there
8516isn't enough disk space, just skip it.
8517@item fcntl
8518Use this if possible. Works with NFS too if lockd is used.
8519@item flock
8520May not exist in all systems. Doesn't work with NFS.
8521@item lockf
8522May not exist in all systems. Doesn't work with NFS.
8523@end table
8524
8525You can use multiple locking methods; if you do the order they're declared
8526in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8527locking methods as well. Some operating systems don't allow using some of
8528them simultaneously.
8529@end deftypevr
8530
8531@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8532
8533@end deftypevr
8534
8535@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8536Maximum time to wait for lock (all of them) before aborting.
8537Defaults to @samp{"5 mins"}.
8538@end deftypevr
8539
8540@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8541If dotlock exists but the mailbox isn't modified in any way,
8542override the lock file after this much time.
8543Defaults to @samp{"2 mins"}.
8544@end deftypevr
8545
8546@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8547When mbox changes unexpectedly we have to fully read it to find out
8548what changed. If the mbox is large this can take a long time. Since
8549the change is usually just a newly appended mail, it'd be faster to
8550simply read the new mails. If this setting is enabled, Dovecot does
8551this but still safely fallbacks to re-reading the whole mbox file
8552whenever something in mbox isn't how it's expected to be. The only real
8553downside to this setting is that if some other MUA changes message
8554flags, Dovecot doesn't notice it immediately. Note that a full sync is
8555done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8556Defaults to @samp{#t}.
8557@end deftypevr
8558
8559@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8560Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8561EXAMINE, EXPUNGE or CHECK commands. If this is set,
8562@samp{mbox-dirty-syncs} is ignored.
8563Defaults to @samp{#f}.
8564@end deftypevr
8565
8566@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8567Delay writing mbox headers until doing a full write sync (EXPUNGE
8568and CHECK commands and when closing the mailbox). This is especially
8569useful for POP3 where clients often delete all mails. The downside is
8570that our changes aren't immediately visible to other MUAs.
8571Defaults to @samp{#t}.
8572@end deftypevr
8573
8574@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8575If mbox size is smaller than this (e.g. 100k), don't write index
8576files. If an index file already exists it's still read, just not
8577updated.
8578Defaults to @samp{0}.
8579@end deftypevr
8580
8581@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8582Maximum dbox file size until it's rotated.
8583Defaults to @samp{2000000}.
8584@end deftypevr
8585
8586@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8587Maximum dbox file age until it's rotated. Typically in days. Day
8588begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8589disabled.
8590Defaults to @samp{"1d"}.
8591@end deftypevr
8592
8593@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8594When creating new mdbox files, immediately preallocate their size to
8595@samp{mdbox-rotate-size}. This setting currently works only in Linux
8596with some filesystems (ext4, xfs).
8597Defaults to @samp{#f}.
8598@end deftypevr
8599
8600@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8601sdbox and mdbox support saving mail attachments to external files,
8602which also allows single instance storage for them. Other backends
8603don't support this for now.
8604
8605WARNING: This feature hasn't been tested much yet. Use at your own risk.
8606
8607Directory root where to store mail attachments. Disabled, if empty.
8608Defaults to @samp{""}.
8609@end deftypevr
8610
8611@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8612Attachments smaller than this aren't saved externally. It's also
8613possible to write a plugin to disable saving specific attachments
8614externally.
8615Defaults to @samp{128000}.
8616@end deftypevr
8617
8618@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8619Filesystem backend to use for saving attachments:
8620@table @code
8621@item posix
8622No SiS done by Dovecot (but this might help FS's own deduplication)
8623@item sis posix
8624SiS with immediate byte-by-byte comparison during saving
8625@item sis-queue posix
8626SiS with delayed comparison and deduplication.
8627@end table
8628Defaults to @samp{"sis posix"}.
8629@end deftypevr
8630
8631@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8632Hash format to use in attachment filenames. You can add any text and
8633variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8634@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8635truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8636Defaults to @samp{"%@{sha1@}"}.
8637@end deftypevr
8638
8639@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8640
8641Defaults to @samp{100}.
8642@end deftypevr
8643
8644@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8645
8646Defaults to @samp{1000}.
8647@end deftypevr
8648
8649@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8650Default VSZ (virtual memory size) limit for service processes.
8651This is mainly intended to catch and kill processes that leak memory
8652before they eat up everything.
8653Defaults to @samp{256000000}.
8654@end deftypevr
8655
8656@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8657Login user is internally used by login processes. This is the most
8658untrusted user in Dovecot system. It shouldn't have access to anything
8659at all.
8660Defaults to @samp{"dovenull"}.
8661@end deftypevr
8662
8663@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8664Internal user is used by unprivileged processes. It should be
8665separate from login user, so that login processes can't disturb other
8666processes.
8667Defaults to @samp{"dovecot"}.
8668@end deftypevr
8669
8670@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8671SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8672Defaults to @samp{"required"}.
8673@end deftypevr
8674
8675@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8676PEM encoded X.509 SSL/TLS certificate (public key).
8677Defaults to @samp{"</etc/dovecot/default.pem"}.
8678@end deftypevr
8679
8680@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8681PEM encoded SSL/TLS private key. The key is opened before
8682dropping root privileges, so keep the key file unreadable by anyone but
8683root.
8684Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8685@end deftypevr
8686
8687@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8688If key file is password protected, give the password here.
8689Alternatively give it when starting dovecot with -p parameter. Since
8690this file is often world-readable, you may want to place this setting
8691instead to a different.
8692Defaults to @samp{""}.
8693@end deftypevr
8694
8695@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8696PEM encoded trusted certificate authority. Set this only if you
8697intend to use @samp{ssl-verify-client-cert? #t}. The file should
8698contain the CA certificate(s) followed by the matching
8699CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8700Defaults to @samp{""}.
8701@end deftypevr
8702
8703@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8704Require that CRL check succeeds for client certificates.
8705Defaults to @samp{#t}.
8706@end deftypevr
8707
8708@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8709Request client to send a certificate. If you also want to require
8710it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8711Defaults to @samp{#f}.
8712@end deftypevr
8713
8714@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8715Which field from certificate to use for username. commonName and
8716x500UniqueIdentifier are the usual choices. You'll also need to set
8717@samp{auth-ssl-username-from-cert? #t}.
8718Defaults to @samp{"commonName"}.
8719@end deftypevr
8720
8721@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8722How often to regenerate the SSL parameters file. Generation is
8723quite CPU intensive operation. The value is in hours, 0 disables
8724regeneration entirely.
8725Defaults to @samp{168}.
8726@end deftypevr
8727
8728@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8729SSL protocols to use.
8730Defaults to @samp{"!SSLv2"}.
8731@end deftypevr
8732
8733@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8734SSL ciphers to use.
8735Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8736@end deftypevr
8737
8738@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8739SSL crypto device to use, for valid values run "openssl engine".
8740Defaults to @samp{""}.
8741@end deftypevr
8742
8743@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8744Address to use when sending rejection mails.
8745Default is postmaster@@<your domain>. %d expands to recipient domain.
8746Defaults to @samp{""}.
8747@end deftypevr
8748
8749@deftypevr {@code{dovecot-configuration} parameter} string hostname
8750Hostname to use in various parts of sent mails (e.g. in Message-Id)
8751and in LMTP replies. Default is the system's real hostname@@domain.
8752Defaults to @samp{""}.
8753@end deftypevr
8754
8755@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8756If user is over quota, return with temporary failure instead of
8757bouncing the mail.
8758Defaults to @samp{#f}.
8759@end deftypevr
8760
8761@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8762Binary to use for sending mails.
8763Defaults to @samp{"/usr/sbin/sendmail"}.
8764@end deftypevr
8765
8766@deftypevr {@code{dovecot-configuration} parameter} string submission-host
8767If non-empty, send mails via this SMTP host[:port] instead of
8768sendmail.
8769Defaults to @samp{""}.
8770@end deftypevr
8771
8772@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8773Subject: header to use for rejection mails. You can use the same
8774variables as for @samp{rejection-reason} below.
8775Defaults to @samp{"Rejected: %s"}.
8776@end deftypevr
8777
8778@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8779Human readable error message for rejection mails. You can use
8780variables:
8781
8782@table @code
8783@item %n
8784CRLF
8785@item %r
8786reason
8787@item %s
8788original subject
8789@item %t
8790recipient
8791@end table
8792Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8793@end deftypevr
8794
8795@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8796Delimiter character between local-part and detail in email
8797address.
8798Defaults to @samp{"+"}.
8799@end deftypevr
8800
8801@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8802Header where the original recipient address (SMTP's RCPT TO:
8803address) is taken from if not available elsewhere. With dovecot-lda -a
8804parameter overrides this. A commonly used header for this is
8805X-Original-To.
8806Defaults to @samp{""}.
8807@end deftypevr
8808
8809@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8810Should saving a mail to a nonexistent mailbox automatically create
8811it?.
8812Defaults to @samp{#f}.
8813@end deftypevr
8814
8815@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8816Should automatically created mailboxes be also automatically
8817subscribed?.
8818Defaults to @samp{#f}.
8819@end deftypevr
8820
8821@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8822Maximum IMAP command line length. Some clients generate very long
8823command lines with huge mailboxes, so you may need to raise this if you
8824get "Too long argument" or "IMAP command line too large" errors
8825often.
8826Defaults to @samp{64000}.
8827@end deftypevr
8828
8829@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8830IMAP logout format string:
8831@table @code
8832@item %i
8833total number of bytes read from client
8834@item %o
8835total number of bytes sent to client.
8836@end table
8837Defaults to @samp{"in=%i out=%o"}.
8838@end deftypevr
8839
8840@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8841Override the IMAP CAPABILITY response. If the value begins with '+',
8842add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8843Defaults to @samp{""}.
8844@end deftypevr
8845
8846@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8847How long to wait between "OK Still here" notifications when client
8848is IDLEing.
8849Defaults to @samp{"2 mins"}.
8850@end deftypevr
8851
8852@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8853ID field names and values to send to clients. Using * as the value
8854makes Dovecot use the default value. The following fields have default
8855values currently: name, version, os, os-version, support-url,
8856support-email.
8857Defaults to @samp{""}.
8858@end deftypevr
8859
8860@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8861ID fields sent by client to log. * means everything.
8862Defaults to @samp{""}.
8863@end deftypevr
8864
8865@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8866Workarounds for various client bugs:
8867
8868@table @code
8869@item delay-newmail
8870Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8871CHECK commands. Some clients ignore them otherwise, for example OSX
8872Mail (<v2.1). Outlook Express breaks more badly though, without this it
8873may show user "Message no longer in server" errors. Note that OE6
8874still breaks even with this workaround if synchronization is set to
8875"Headers Only".
8876
8877@item tb-extra-mailbox-sep
8878Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8879adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8880ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8881
8882@item tb-lsub-flags
8883Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8884This makes Thunderbird realize they aren't selectable and show them
8885greyed out, instead of only later giving "not selectable" popup error.
8886@end table
8887Defaults to @samp{()}.
8888@end deftypevr
8889
8890@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8891Host allowed in URLAUTH URLs sent by client. "*" allows all.
8892Defaults to @samp{""}.
8893@end deftypevr
8894
8895
8896Whew! Lots of configuration options. The nice thing about it though is
8897that GuixSD has a complete interface to Dovecot's configuration
8898language. This allows not only a nice way to declare configurations,
8899but also offers reflective capabilities as well: users can write code to
8900inspect and transform configurations from within Scheme.
8901
8902However, it could be that you just want to get a @code{dovecot.conf} up
8903and running. In that case, you can pass an
8904@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8905@code{dovecot-service}. As its name indicates, an opaque configuration
8906does not have easy reflective capabilities.
8907
8908Available @code{opaque-dovecot-configuration} fields are:
8909
8910@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8911The dovecot package.
8912@end deftypevr
8913
8914@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8915The contents of the @code{dovecot.conf}, as a string.
8916@end deftypevr
8917
8918For example, if your @code{dovecot.conf} is just the empty string, you
8919could instantiate a dovecot service like this:
8920
8921@example
8922(dovecot-service #:config
8923 (opaque-dovecot-configuration
8924 (string "")))
8925@end example
8926
58724c48
DT
8927@node Web Services
8928@subsubsection Web Services
8929
8930The @code{(gnu services web)} module provides the following service:
8931
be1c2c54 8932@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
8933 [#:log-directory ``/var/log/nginx''] @
8934 [#:run-directory ``/var/run/nginx''] @
8935 [#:config-file]
8936
8937Return a service that runs @var{nginx}, the nginx web server.
8938
8939The nginx daemon loads its runtime configuration from @var{config-file}.
8940Log files are written to @var{log-directory} and temporary runtime data
8941files are written to @var{run-directory}. For proper operation, these
8942arguments should match what is in @var{config-file} to ensure that the
8943directories are created when the service is activated.
8944
8945@end deffn
8946
fe1a39d3
LC
8947@node Various Services
8948@subsubsection Various Services
8949
8950The @code{(gnu services lirc)} module provides the following service.
8951
be1c2c54 8952@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
8953 [#:device #f] [#:driver #f] [#:config-file #f] @
8954 [#:extra-options '()]
8955Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
8956decodes infrared signals from remote controls.
8957
8958Optionally, @var{device}, @var{driver} and @var{config-file}
8959(configuration file name) may be specified. See @command{lircd} manual
8960for details.
8961
8962Finally, @var{extra-options} is a list of additional command-line options
8963passed to @command{lircd}.
8964@end deffn
8965
8966
0ae8c15a
LC
8967@node Setuid Programs
8968@subsection Setuid Programs
8969
8970@cindex setuid programs
8971Some programs need to run with ``root'' privileges, even when they are
8972launched by unprivileged users. A notorious example is the
4d40227c
LC
8973@command{passwd} program, which users can run to change their
8974password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
8975@file{/etc/shadow} files---something normally restricted to root, for
8976obvious security reasons. To address that, these executables are
8977@dfn{setuid-root}, meaning that they always run with root privileges
8978(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 8979for more info about the setuid mechanism.)
0ae8c15a
LC
8980
8981The store itself @emph{cannot} contain setuid programs: that would be a
8982security issue since any user on the system can write derivations that
8983populate the store (@pxref{The Store}). Thus, a different mechanism is
8984used: instead of changing the setuid bit directly on files that are in
8985the store, we let the system administrator @emph{declare} which programs
8986should be setuid root.
8987
8988The @code{setuid-programs} field of an @code{operating-system}
8989declaration contains a list of G-expressions denoting the names of
8990programs to be setuid-root (@pxref{Using the Configuration System}).
8991For instance, the @command{passwd} program, which is part of the Shadow
8992package, can be designated by this G-expression (@pxref{G-Expressions}):
8993
8994@example
8995#~(string-append #$shadow "/bin/passwd")
8996@end example
8997
8998A default set of setuid programs is defined by the
8999@code{%setuid-programs} variable of the @code{(gnu system)} module.
9000
9001@defvr {Scheme Variable} %setuid-programs
9002A list of G-expressions denoting common programs that are setuid-root.
9003
9004The list includes commands such as @command{passwd}, @command{ping},
9005@command{su}, and @command{sudo}.
9006@end defvr
9007
9008Under the hood, the actual setuid programs are created in the
9009@file{/run/setuid-programs} directory at system activation time. The
9010files in this directory refer to the ``real'' binaries, which are in the
9011store.
9012
efb5e833
LC
9013@node X.509 Certificates
9014@subsection X.509 Certificates
9015
9016@cindex HTTPS, certificates
9017@cindex X.509 certificates
9018@cindex TLS
9019Web servers available over HTTPS (that is, HTTP over the transport-layer
9020security mechanism, TLS) send client programs an @dfn{X.509 certificate}
9021that the client can then use to @emph{authenticate} the server. To do
9022that, clients verify that the server's certificate is signed by a
9023so-called @dfn{certificate authority} (CA). But to verify the CA's
9024signature, clients must have first acquired the CA's certificate.
9025
9026Web browsers such as GNU@tie{}IceCat include their own set of CA
9027certificates, such that they are able to verify CA signatures
9028out-of-the-box.
9029
9030However, most other programs that can talk HTTPS---@command{wget},
9031@command{git}, @command{w3m}, etc.---need to be told where CA
9032certificates can be found.
9033
9034@cindex @code{nss-certs}
9035In GuixSD, this is done by adding a package that provides certificates
9036to the @code{packages} field of the @code{operating-system} declaration
9037(@pxref{operating-system Reference}). GuixSD includes one such package,
9038@code{nss-certs}, which is a set of CA certificates provided as part of
9039Mozilla's Network Security Services.
9040
9041Note that it is @emph{not} part of @var{%base-packages}, so you need to
9042explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9043most applications and libraries look for certificates by default, points
9044to the certificates installed globally.
9045
9046Unprivileged users can also install their own certificate package in
9047their profile. A number of environment variables need to be defined so
9048that applications and libraries know where to find them. Namely, the
9049OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9050variables. Some applications add their own environment variables; for
9051instance, the Git version control system honors the certificate bundle
9052pointed to by the @code{GIT_SSL_CAINFO} environment variable.
9053
9054
996ed739
LC
9055@node Name Service Switch
9056@subsection Name Service Switch
9057
9058@cindex name service switch
9059@cindex NSS
9060The @code{(gnu system nss)} module provides bindings to the
1068f26b 9061configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
9062(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9063Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9064extended with new ``name'' lookup methods for system databases, which
9065includes host names, service names, user accounts, and more (@pxref{Name
9066Service Switch, System Databases and Name Service Switch,, libc, The GNU
9067C Library Reference Manual}).
9068
9069The NSS configuration specifies, for each system database, which lookup
9070method is to be used, and how the various methods are chained
9071together---for instance, under which circumstances NSS should try the
9072next method in the list. The NSS configuration is given in the
9073@code{name-service-switch} field of @code{operating-system} declarations
9074(@pxref{operating-system Reference, @code{name-service-switch}}).
9075
4c9050c6
LC
9076@cindex nss-mdns
9077@cindex .local, host name lookup
996ed739 9078As an example, the declaration below configures the NSS to use the
4c9050c6
LC
9079@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9080back-end}, which supports host name lookups over multicast DNS (mDNS)
9081for host names ending in @code{.local}:
996ed739
LC
9082
9083@example
9084(name-service-switch
9085 (hosts (list %files ;first, check /etc/hosts
9086
9087 ;; If the above did not succeed, try
9088 ;; with 'mdns_minimal'.
9089 (name-service
9090 (name "mdns_minimal")
9091
9092 ;; 'mdns_minimal' is authoritative for
9093 ;; '.local'. When it returns "not found",
9094 ;; no need to try the next methods.
9095 (reaction (lookup-specification
9096 (not-found => return))))
9097
9098 ;; Then fall back to DNS.
9099 (name-service
9100 (name "dns"))
9101
9102 ;; Finally, try with the "full" 'mdns'.
9103 (name-service
9104 (name "mdns")))))
9105@end example
9106
1068f26b
AE
9107Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
9108contains this configuration, so you will not have to type it if all you
15137a29
LC
9109want is to have @code{.local} host lookup working.
9110
4c9050c6
LC
9111Note that, in this case, in addition to setting the
9112@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
9113you also need to use @code{avahi-service} (@pxref{Networking Services,
9114@code{avahi-service}}), or @var{%desktop-services}, which includes it
9115(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9116to the name service cache daemon (@pxref{Base Services,
9117@code{nscd-service}}).
15137a29
LC
9118
9119For convenience, the following variables provide typical NSS
9120configurations.
9121
9122@defvr {Scheme Variable} %default-nss
9123This is the default name service switch configuration, a
9124@code{name-service-switch} object.
9125@end defvr
9126
9127@defvr {Scheme Variable} %mdns-host-lookup-nss
9128This is the name service switch configuration with support for host name
9129lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9130@end defvr
4c9050c6 9131
996ed739 9132The reference for name service switch configuration is given below. It
1068f26b 9133is a direct mapping of the configuration file format of the C library , so
996ed739
LC
9134please refer to the C library manual for more information (@pxref{NSS
9135Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 9136Compared to the configuration file format of libc NSS, it has the advantage
996ed739 9137not only of adding this warm parenthetic feel that we like, but also
1068f26b 9138static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
9139run @command{guix system}.
9140
996ed739
LC
9141@deftp {Data Type} name-service-switch
9142
9143This is the data type representation the configuration of libc's name
9144service switch (NSS). Each field below represents one of the supported
9145system databases.
9146
9147@table @code
9148@item aliases
9149@itemx ethers
9150@itemx group
9151@itemx gshadow
9152@itemx hosts
9153@itemx initgroups
9154@itemx netgroup
9155@itemx networks
9156@itemx password
9157@itemx public-key
9158@itemx rpc
9159@itemx services
9160@itemx shadow
9161The system databases handled by the NSS. Each of these fields must be a
1068f26b 9162list of @code{<name-service>} objects (see below).
996ed739
LC
9163@end table
9164@end deftp
9165
9166@deftp {Data Type} name-service
9167
9168This is the data type representing an actual name service and the
9169associated lookup action.
9170
9171@table @code
9172@item name
9173A string denoting the name service (@pxref{Services in the NSS
9174configuration,,, libc, The GNU C Library Reference Manual}).
9175
4aee6e60
LC
9176Note that name services listed here must be visible to nscd. This is
9177achieved by passing the @code{#:name-services} argument to
9178@code{nscd-service} the list of packages providing the needed name
9179services (@pxref{Base Services, @code{nscd-service}}).
9180
996ed739
LC
9181@item reaction
9182An action specified using the @code{lookup-specification} macro
9183(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
9184Reference Manual}). For example:
9185
9186@example
9187(lookup-specification (unavailable => continue)
9188 (success => return))
9189@end example
9190@end table
9191@end deftp
0ae8c15a 9192
fd1b1fa2
LC
9193@node Initial RAM Disk
9194@subsection Initial RAM Disk
9195
9196@cindex initial RAM disk (initrd)
9197@cindex initrd (initial RAM disk)
9198For bootstrapping purposes, the Linux-Libre kernel is passed an
9199@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 9200root file system as well as an initialization script. The latter is
fd1b1fa2
LC
9201responsible for mounting the real root file system, and for loading any
9202kernel modules that may be needed to achieve that.
9203
9204The @code{initrd} field of an @code{operating-system} declaration allows
9205you to specify which initrd you would like to use. The @code{(gnu
9206system linux-initrd)} module provides two ways to build an initrd: the
9207high-level @code{base-initrd} procedure, and the low-level
9208@code{expression->initrd} procedure.
9209
9210The @code{base-initrd} procedure is intended to cover most common uses.
9211For example, if you want to add a bunch of kernel modules to be loaded
9212at boot time, you can define the @code{initrd} field of the operating
9213system declaration like this:
9214
9215@example
52ac153e 9216(initrd (lambda (file-systems . rest)
027981d6
LC
9217 ;; Create a standard initrd that has modules "foo.ko"
9218 ;; and "bar.ko", as well as their dependencies, in
9219 ;; addition to the modules available by default.
52ac153e 9220 (apply base-initrd file-systems
027981d6 9221 #:extra-modules '("foo" "bar")
52ac153e 9222 rest)))
fd1b1fa2
LC
9223@end example
9224
52ac153e 9225The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
9226involves using the system as a QEMU guest, or as a ``live'' system with
9227volatile root file system.
fd1b1fa2 9228
e90cf6c1
LC
9229The initial RAM disk produced by @code{base-initrd} honors several
9230options passed on the Linux kernel command line (that is, arguments
1068f26b
AE
9231passed @i{via} the @code{linux} command of GRUB, or the
9232@code{-append} option) of QEMU, notably:
e90cf6c1
LC
9233
9234@table @code
9235@item --load=@var{boot}
9236Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
9237program, once it has mounted the root file system.
9238
9239GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 9240service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
9241initialization system.
9242
9243@item --root=@var{root}
1068f26b 9244Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
9245device name like @code{/dev/sda1}, a partition label, or a partition
9246UUID.
9247
9248@item --system=@var{system}
9249Have @file{/run/booted-system} and @file{/run/current-system} point to
9250@var{system}.
9251
9252@item modprobe.blacklist=@var{modules}@dots{}
9253@cindex module, black-listing
9254@cindex black list, of kernel modules
9255Instruct the initial RAM disk as well as the @command{modprobe} command
9256(from the kmod package) to refuse to load @var{modules}. @var{modules}
9257must be a comma-separated list of module names---e.g.,
9258@code{usbkbd,9pnet}.
9259
9260@item --repl
9261Start a read-eval-print loop (REPL) from the initial RAM disk before it
9262tries to load kernel modules and to mount the root file system. Our
9263marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
9264love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
9265Manual}, for more information on Guile's REPL.
9266
9267@end table
9268
9269Now that you know all the features that initial RAM disks produced by
9270@code{base-initrd} provide, here is how to use it and customize it
9271further.
9272
fd1b1fa2 9273@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 9274 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 9275 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2 9276Return a monadic derivation that builds a generic initrd. @var{file-systems} is
1068f26b 9277a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 9278the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
9279@var{mapped-devices} is a list of device mappings to realize before
9280@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
9281
9282When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
9283parameters. When @var{virtio?} is true, load additional modules so that the
9284initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
9285
9286When @var{volatile-root?} is true, the root file system is writable but any changes
9287to it are lost.
9288
9289The initrd is automatically populated with all the kernel modules necessary
9290for @var{file-systems} and for the given options. However, additional kernel
9291modules can be listed in @var{extra-modules}. They will be added to the initrd, and
9292loaded at boot time in the order in which they appear.
9293@end deffn
9294
9295Needless to say, the initrds we produce and use embed a
9296statically-linked Guile, and the initialization program is a Guile
9297program. That gives a lot of flexibility. The
9298@code{expression->initrd} procedure builds such an initrd, given the
9299program to run in that initrd.
9300
9301@deffn {Monadic Procedure} expression->initrd @var{exp} @
9302 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 9303 [#:modules '()]
fd1b1fa2
LC
9304Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9305containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
9306upon booting. All the derivations referenced by @var{exp} are
9307automatically copied to the initrd.
fd1b1fa2 9308
42d10464
LC
9309@var{modules} is a list of Guile module names to be embedded in the
9310initrd.
fd1b1fa2
LC
9311@end deffn
9312
88faf933
LC
9313@node GRUB Configuration
9314@subsection GRUB Configuration
9315
9316@cindex GRUB
9317@cindex boot loader
9318
9319The operating system uses GNU@tie{}GRUB as its boot loader
9320(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
9321configured using a @code{grub-configuration} declaration. This data type
9322is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
9323
9324@deftp {Data Type} grub-configuration
9325The type of a GRUB configuration declaration.
9326
9327@table @asis
9328
9329@item @code{device}
9330This is a string denoting the boot device. It must be a device name
9331understood by the @command{grub-install} command, such as
9332@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9333GNU GRUB Manual}).
9334
9335@item @code{menu-entries} (default: @code{()})
9336A possibly empty list of @code{menu-entry} objects (see below), denoting
9337entries to appear in the GRUB boot menu, in addition to the current
9338system entry and the entry pointing to previous system generations.
9339
9340@item @code{default-entry} (default: @code{0})
1068f26b
AE
9341The index of the default boot menu entry. Index 0 is for the entry of the
9342current system.
88faf933
LC
9343
9344@item @code{timeout} (default: @code{5})
9345The number of seconds to wait for keyboard input before booting. Set to
93460 to boot immediately, and to -1 to wait indefinitely.
9347
9348@item @code{theme} (default: @var{%default-theme})
9349The @code{grub-theme} object describing the theme to use.
9350@end table
9351
9352@end deftp
9353
9354Should you want to list additional boot menu entries @i{via} the
9355@code{menu-entries} field above, you will need to create them with the
9356@code{menu-entry} form:
9357
9358@deftp {Data Type} menu-entry
9359The type of an entry in the GRUB boot menu.
9360
9361@table @asis
9362
9363@item @code{label}
35ed9306 9364The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
9365
9366@item @code{linux}
9367The Linux kernel to boot.
9368
9369@item @code{linux-arguments} (default: @code{()})
9370The list of extra Linux kernel command-line arguments---e.g.,
9371@code{("console=ttyS0")}.
9372
9373@item @code{initrd}
9374A G-Expression or string denoting the file name of the initial RAM disk
9375to use (@pxref{G-Expressions}).
9376
9377@end table
9378@end deftp
9379
9380@c FIXME: Write documentation once it's stable.
9381Themes are created using the @code{grub-theme} form, which is not
9382documented yet.
9383
9384@defvr {Scheme Variable} %default-theme
9385This is the default GRUB theme used by the operating system, with a
9386fancy background image displaying the GNU and Guix logos.
9387@end defvr
9388
9389
cf4a9129
LC
9390@node Invoking guix system
9391@subsection Invoking @code{guix system}
0918e64a 9392
1068f26b 9393Once you have written an operating system declaration as seen in the
cf4a9129
LC
9394previous section, it can be @dfn{instantiated} using the @command{guix
9395system} command. The synopsis is:
4af2447e 9396
cf4a9129
LC
9397@example
9398guix system @var{options}@dots{} @var{action} @var{file}
9399@end example
4af2447e 9400
cf4a9129
LC
9401@var{file} must be the name of a file containing an
9402@code{operating-system} declaration. @var{action} specifies how the
a40424bd 9403operating system is instantiated. Currently the following values are
cf4a9129 9404supported:
4af2447e 9405
cf4a9129
LC
9406@table @code
9407@item reconfigure
9408Build the operating system described in @var{file}, activate it, and
9409switch to it@footnote{This action is usable only on systems already
65797bff 9410running GuixSD.}.
4af2447e 9411
cf4a9129
LC
9412This effects all the configuration specified in @var{file}: user
9413accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
9414The command starts system services specified in @var{file} that are not
9415currently running; if a service is currently running, it does not
1068f26b 9416attempt to upgrade it since this would not be possible without stopping it
240b57f0 9417first.
4af2447e 9418
cf4a9129
LC
9419It also adds a GRUB menu entry for the new OS configuration, and moves
9420entries for older configurations to a submenu---unless
9421@option{--no-grub} is passed.
4af2447e 9422
240b57f0 9423@quotation Note
bf2479c7
LC
9424@c The paragraph below refers to the problem discussed at
9425@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9426It is highly recommended to run @command{guix pull} once before you run
9427@command{guix system reconfigure} for the first time (@pxref{Invoking
9428guix pull}). Failing to do that you would see an older version of Guix
9429once @command{reconfigure} has completed.
240b57f0 9430@end quotation
bf2479c7 9431
cf4a9129 9432@item build
1068f26b 9433Build the derivation of the operating system, which includes all the
cf4a9129
LC
9434configuration files and programs needed to boot and run the system.
9435This action does not actually install anything.
113daf62 9436
cf4a9129
LC
9437@item init
9438Populate the given directory with all the files necessary to run the
9439operating system specified in @var{file}. This is useful for first-time
4705641f 9440installations of GuixSD. For instance:
113daf62
LC
9441
9442@example
cf4a9129 9443guix system init my-os-config.scm /mnt
113daf62
LC
9444@end example
9445
cf4a9129
LC
9446copies to @file{/mnt} all the store items required by the configuration
9447specified in @file{my-os-config.scm}. This includes configuration
9448files, packages, and so on. It also creates other essential files
9449needed for the system to operate correctly---e.g., the @file{/etc},
9450@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 9451
cf4a9129
LC
9452This command also installs GRUB on the device specified in
9453@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 9454
cf4a9129
LC
9455@item vm
9456@cindex virtual machine
0276f697 9457@cindex VM
f535dcbe 9458@anchor{guix system vm}
1068f26b 9459Build a virtual machine that contains the operating system declared in
cf4a9129 9460@var{file}, and return a script to run that virtual machine (VM).
1068f26b 9461Arguments given to the script are passed to QEMU.
113daf62 9462
cf4a9129 9463The VM shares its store with the host system.
113daf62 9464
0276f697
LC
9465Additional file systems can be shared between the host and the VM using
9466the @code{--share} and @code{--expose} command-line options: the former
9467specifies a directory to be shared with write access, while the latter
9468provides read-only access to the shared directory.
9469
9470The example below creates a VM in which the user's home directory is
9471accessible read-only, and where the @file{/exchange} directory is a
1068f26b 9472read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
9473
9474@example
9475guix system vm my-config.scm \
9476 --expose=$HOME --share=$HOME/tmp=/exchange
9477@end example
9478
6aa260af
LC
9479On GNU/Linux, the default is to boot directly to the kernel; this has
9480the advantage of requiring only a very tiny root disk image since the
1068f26b 9481store of the host can then be mounted.
6aa260af
LC
9482
9483The @code{--full-boot} option forces a complete boot sequence, starting
9484with the bootloader. This requires more disk space since a root image
9485containing at least the kernel, initrd, and bootloader data files must
9486be created. The @code{--image-size} option can be used to specify the
1068f26b 9487size of the image.
ab11f0be 9488
cf4a9129
LC
9489@item vm-image
9490@itemx disk-image
9491Return a virtual machine or disk image of the operating system declared
9492in @var{file} that stands alone. Use the @option{--image-size} option
9493to specify the size of the image.
113daf62 9494
cf4a9129 9495When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
9496the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
9497for more information on how to run the image in a virtual machine.
113daf62 9498
cf4a9129
LC
9499When using @code{disk-image}, a raw disk image is produced; it can be
9500copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 9501the device corresponding to a USB stick, one can copy the image to it
cf4a9129 9502using the following command:
113daf62 9503
cf4a9129
LC
9504@example
9505# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9506@end example
113daf62 9507
1c8a81b1
DT
9508@item container
9509Return a script to run the operating system declared in @var{file}
9510within a container. Containers are a set of lightweight isolation
9511mechanisms provided by the kernel Linux-libre. Containers are
9512substantially less resource-demanding than full virtual machines since
9513the kernel, shared objects, and other resources can be shared with the
9514host system; this also means they provide thinner isolation.
9515
9516Currently, the script must be run as root in order to support more than
9517a single user and group. The container shares its store with the host
9518system.
9519
9520As with the @code{vm} action (@pxref{guix system vm}), additional file
9521systems to be shared between the host and container can be specified
9522using the @option{--share} and @option{--expose} options:
9523
9524@example
9525guix system container my-config.scm \
9526 --expose=$HOME --share=$HOME/tmp=/exchange
9527@end example
9528
0f252e26 9529@quotation Note
cfd35b4e 9530This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9531@end quotation
9532
cf4a9129 9533@end table
113daf62 9534
ccd7158d
LC
9535@var{options} can contain any of the common build options (@pxref{Common
9536Build Options}). In addition, @var{options} can contain one of the
9537following:
113daf62 9538
cf4a9129
LC
9539@table @option
9540@item --system=@var{system}
9541@itemx -s @var{system}
1068f26b 9542Attempt to build for @var{system} instead of the host system type.
cf4a9129 9543This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9544
f3f427c2
LC
9545@item --derivation
9546@itemx -d
9547Return the derivation file name of the given operating system without
9548building anything.
9549
cf4a9129
LC
9550@item --image-size=@var{size}
9551For the @code{vm-image} and @code{disk-image} actions, create an image
9552of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9553include a unit as a suffix (@pxref{Block size, size specifications,,
9554coreutils, GNU Coreutils}).
db030303
LC
9555
9556@item --on-error=@var{strategy}
9557Apply @var{strategy} when an error occurs when reading @var{file}.
9558@var{strategy} may be one of the following:
9559
9560@table @code
9561@item nothing-special
9562Report the error concisely and exit. This is the default strategy.
9563
9564@item backtrace
9565Likewise, but also display a backtrace.
9566
9567@item debug
9568Report the error and enter Guile's debugger. From there, you can run
9569commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
9570display local variable values, and more generally inspect the state of the
9571program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
9572a list of available debugging commands.
9573@end table
113daf62 9574@end table
113daf62 9575
cf4a9129
LC
9576Note that all the actions above, except @code{build} and @code{init},
9577rely on KVM support in the Linux-Libre kernel. Specifically, the
9578machine should have hardware virtualization support, the corresponding
9579KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b
AE
9580must exist and be readable and writable by the user and by the
9581build users of the daemon.
8451a568 9582
65797bff
LC
9583Once you have built, configured, re-configured, and re-re-configured
9584your GuixSD installation, you may find it useful to list the operating
9585system generations available on disk---and that you can choose from the
9586GRUB boot menu:
9587
9588@table @code
9589
9590@item list-generations
9591List a summary of each generation of the operating system available on
9592disk, in a human-readable way. This is similar to the
9593@option{--list-generations} option of @command{guix package}
9594(@pxref{Invoking guix package}).
9595
9596Optionally, one can specify a pattern, with the same syntax that is used
9597in @command{guix package --list-generations}, to restrict the list of
9598generations displayed. For instance, the following command displays
1068f26b 9599generations that are up to 10 days old:
65797bff
LC
9600
9601@example
9602$ guix system list-generations 10d
9603@end example
9604
9605@end table
9606
d6c3267a
LC
9607The @command{guix system} command has even more to offer! The following
9608sub-commands allow you to visualize how your system services relate to
9609each other:
9610
9611@anchor{system-extension-graph}
9612@table @code
9613
9614@item extension-graph
9615Emit in Dot/Graphviz format to standard output the @dfn{service
9616extension graph} of the operating system defined in @var{file}
9617(@pxref{Service Composition}, for more information on service
9618extensions.)
9619
9620The command:
9621
9622@example
9623$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9624@end example
9625
9626produces a PDF file showing the extension relations among services.
9627
710fa231
AK
9628@anchor{system-shepherd-graph}
9629@item shepherd-graph
6f305ea5 9630Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
9631graph} of shepherd services of the operating system defined in
9632@var{file}. @xref{Shepherd Services}, for more information and for an
9633example graph.
6f305ea5 9634
d6c3267a
LC
9635@end table
9636
97d76250 9637@node Running GuixSD in a VM
70ac09a5 9638@subsection Running GuixSD in a Virtual Machine
97d76250
LF
9639
9640One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
9641virtual machine image using @command{guix system vm-image}
9642(@pxref{Invoking guix system}). The returned image is in qcow2 format,
9643which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
9644
9645To run the image in QEMU, copy it out of the store (@pxref{The Store})
9646and give yourself permission to write to the copy. When invoking QEMU,
9647you must choose a system emulator that is suitable for your hardware
9648platform. Here is a minimal QEMU invocation that will boot the result
9649of @command{guix system vm-image} on x86_64 hardware:
9650
9651@example
9652$ qemu-system-x86_64 \
9653 -net user -net nic,model=virtio \
9654 -enable-kvm -m 256 /tmp/qemu-image
9655@end example
9656
9657Here is what each of these options means:
9658
9659@table @code
9660@item qemu-system-x86_64
9661This specifies the hardware platform to emulate. This should match the
9662host.
9663
9664@item -net user
9665Enable the unprivileged user-mode network stack. The guest OS can
9666access the host but not vice versa. This is the simplest way to get the
1068f26b 9667guest OS online. If you do not choose a network stack, the boot will
97d76250
LF
9668fail.
9669
9670@item -net nic,model=virtio
1068f26b 9671You must create a network interface of a given model. If you do not
97d76250
LF
9672create a NIC, the boot will fail. Assuming your hardware platform is
9673x86_64, you can get a list of available NIC models by running
9674@command{qemu-system-x86_64 -net nic,model=help}.
9675
9676@item -enable-kvm
9677If your system has hardware virtualization extensions, enabling the
1068f26b 9678virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
9679faster.
9680
9681@item -m 256
9682RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
9683which may be insufficent for some operations.
9684
9685@item /tmp/qemu-image
9686The file name of the qcow2 image.
9687@end table
d6c3267a 9688
cf4a9129
LC
9689@node Defining Services
9690@subsection Defining Services
8451a568 9691
eb524192 9692The previous sections show the available services and how one can combine
0adfe95a
LC
9693them in an @code{operating-system} declaration. But how do we define
9694them in the first place? And what is a service anyway?
8451a568 9695
0adfe95a
LC
9696@menu
9697* Service Composition:: The model for composing services.
9698* Service Types and Services:: Types and services.
9699* Service Reference:: API reference.
dd17bc38 9700* Shepherd Services:: A particular type of service.
0adfe95a
LC
9701@end menu
9702
9703@node Service Composition
9704@subsubsection Service Composition
9705
9706@cindex services
9707@cindex daemons
9708Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 9709functionality of the operating system. Often a service is a process---a
0adfe95a
LC
9710@dfn{daemon}---started when the system boots: a secure shell server, a
9711Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9712whose execution can be triggered by another daemon---e.g., an FTP server
9713started by @command{inetd} or a D-Bus service activated by
9714@command{dbus-daemon}. Occasionally, a service does not map to a
9715daemon. For instance, the ``account'' service collects user accounts
9716and makes sure they exist when the system runs; the ``udev'' service
9717collects device management rules and makes them available to the eudev
1068f26b
AE
9718daemon; the @file{/etc} service populates the @file{/etc} directory
9719of the system.
0adfe95a 9720
d6c3267a 9721@cindex service extensions
0adfe95a 9722GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 9723secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
9724initialization system, running as PID@tie{}1---by giving it the command
9725lines to start and stop the secure shell daemon (@pxref{Networking
9726Services, @code{lsh-service}}); the UPower service extends the D-Bus
9727service by passing it its @file{.service} specification, and extends the
9728udev service by passing it device management rules (@pxref{Desktop
9729Services, @code{upower-service}}); the Guix daemon service extends the
9730Shepherd by passing it the command lines to start and stop the daemon,
9731and extends the account service by passing it a list of required build
9732user accounts (@pxref{Base Services}).
0adfe95a
LC
9733
9734All in all, services and their ``extends'' relations form a directed
9735acyclic graph (DAG). If we represent services as boxes and extensions
9736as arrows, a typical system might provide something like this:
9737
9738@image{images/service-graph,,5in,Typical service extension graph.}
9739
d62e201c
LC
9740@cindex system service
9741At the bottom, we see the @dfn{system service}, which produces the
9742directory containing everything to run and boot the system, as returned
9743by the @command{guix system build} command. @xref{Service Reference},
9744to learn about the other service types shown here.
d6c3267a
LC
9745@xref{system-extension-graph, the @command{guix system extension-graph}
9746command}, for information on how to generate this representation for a
9747particular operating system definition.
0adfe95a
LC
9748
9749@cindex service types
9750Technically, developers can define @dfn{service types} to express these
9751relations. There can be any number of services of a given type on the
9752system---for instance, a system running two instances of the GNU secure
9753shell server (lsh) has two instances of @var{lsh-service-type}, with
9754different parameters.
9755
9756The following section describes the programming interface for service
9757types and services.
9758
9759@node Service Types and Services
9760@subsubsection Service Types and Services
9761
9762A @dfn{service type} is a node in the DAG described above. Let us start
9763with a simple example, the service type for the Guix build daemon
9764(@pxref{Invoking guix-daemon}):
9765
9766@example
9767(define guix-service-type
9768 (service-type
9769 (name 'guix)
9770 (extensions
d4053c71 9771 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
9772 (service-extension account-service-type guix-accounts)
9773 (service-extension activation-service-type guix-activation)))))
9774@end example
8451a568 9775
cf4a9129 9776@noindent
1068f26b 9777It defines two things:
0adfe95a
LC
9778
9779@enumerate
9780@item
9781A name, whose sole purpose is to make inspection and debugging easier.
9782
9783@item
9784A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
9785target service type and a procedure that, given the parameters of the
9786service, returns a list of objects to extend the service of that type.
0adfe95a
LC
9787
9788Every service type has at least one service extension. The only
9789exception is the @dfn{boot service type}, which is the ultimate service.
9790@end enumerate
9791
9792In this example, @var{guix-service-type} extends three services:
9793
9794@table @var
d4053c71
AK
9795@item shepherd-root-service-type
9796The @var{guix-shepherd-service} procedure defines how the Shepherd
9797service is extended. Namely, it returns a @code{<shepherd-service>}
9798object that defines how @command{guix-daemon} is started and stopped
9799(@pxref{Shepherd Services}).
0adfe95a
LC
9800
9801@item account-service-type
9802This extension for this service is computed by @var{guix-accounts},
9803which returns a list of @code{user-group} and @code{user-account}
9804objects representing the build user accounts (@pxref{Invoking
9805guix-daemon}).
9806
9807@item activation-service-type
9808Here @var{guix-activation} is a procedure that returns a gexp, which is
9809a code snippet to run at ``activation time''---e.g., when the service is
9810booted.
9811@end table
9812
9813A service of this type is instantiated like this:
9814
9815@example
9816(service guix-service-type
9817 (guix-configuration
9818 (build-accounts 5)
9819 (use-substitutes? #f)))
9820@end example
9821
9822The second argument to the @code{service} form is a value representing
9823the parameters of this specific service instance.
9824@xref{guix-configuration-type, @code{guix-configuration}}, for
9825information about the @code{guix-configuration} data type.
9826
9827@var{guix-service-type} is quite simple because it extends other
9828services but is not extensible itself.
9829
9830@c @subsubsubsection Extensible Service Types
9831
9832The service type for an @emph{extensible} service looks like this:
9833
9834@example
9835(define udev-service-type
9836 (service-type (name 'udev)
9837 (extensions
d4053c71
AK
9838 (list (service-extension shepherd-root-service-type
9839 udev-shepherd-service)))
0adfe95a
LC
9840
9841 (compose concatenate) ;concatenate the list of rules
9842 (extend (lambda (config rules)
9843 (match config
9844 (($ <udev-configuration> udev initial-rules)
9845 (udev-configuration
9846 (udev udev) ;the udev package to use
9847 (rules (append initial-rules rules)))))))))
9848@end example
9849
9850This is the service type for the
9851@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9852management daemon}. Compared to the previous example, in addition to an
d4053c71 9853extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
9854
9855@table @code
9856@item compose
9857This is the procedure to @dfn{compose} the list of extensions to
9858services of this type.
9859
9860Services can extend the udev service by passing it lists of rules; we
9861compose those extensions simply by concatenating them.
9862
9863@item extend
1068f26b 9864This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
9865the composition of the extensions.
9866
9867Udev extensions are composed into a list of rules, but the udev service
9868value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 9869extend that record by appending the list of rules it contains to the
0adfe95a
LC
9870list of contributed rules.
9871@end table
9872
9873There can be only one instance of an extensible service type such as
9874@var{udev-service-type}. If there were more, the
9875@code{service-extension} specifications would be ambiguous.
9876
9877Still here? The next section provides a reference of the programming
9878interface for services.
9879
9880@node Service Reference
9881@subsubsection Service Reference
9882
9883We have seen an overview of service types (@pxref{Service Types and
9884Services}). This section provides a reference on how to manipulate
9885services and service types. This interface is provided by the
9886@code{(gnu services)} module.
9887
9888@deffn {Scheme Procedure} service @var{type} @var{value}
9889Return a new service of @var{type}, a @code{<service-type>} object (see
9890below.) @var{value} can be any object; it represents the parameters of
9891this particular service instance.
9892@end deffn
9893
9894@deffn {Scheme Procedure} service? @var{obj}
9895Return true if @var{obj} is a service.
9896@end deffn
8451a568 9897
0adfe95a
LC
9898@deffn {Scheme Procedure} service-kind @var{service}
9899Return the type of @var{service}---i.e., a @code{<service-type>} object.
9900@end deffn
9901
9902@deffn {Scheme Procedure} service-parameters @var{service}
9903Return the value associated with @var{service}. It represents its
9904parameters.
9905@end deffn
9906
9907Here is an example of how a service is created and manipulated:
9908
9909@example
9910(define s
9911 (service nginx-service-type
9912 (nginx-configuration
9913 (nginx nginx)
9914 (log-directory log-directory)
9915 (run-directory run-directory)
9916 (file config-file))))
9917
9918(service? s)
9919@result{} #t
9920
9921(eq? (service-kind s) nginx-service-type)
9922@result{} #t
9923@end example
9924
cd6f6c22
LC
9925The @code{modify-services} form provides a handy way to change the
9926parameters of some of the services of a list such as
9927@var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9928course, you could always use standard list combinators such as
9929@code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9930guile, GNU Guile Reference Manual}); @code{modify-services} simply
9931provides a more concise form for this common pattern.
9932
9933@deffn {Scheme Syntax} modify-services @var{services} @
9934 (@var{type} @var{variable} => @var{body}) @dots{}
9935
9936Modify the services listed in @var{services} according to the given
9937clauses. Each clause has the form:
9938
9939@example
9940(@var{type} @var{variable} => @var{body})
9941@end example
9942
9943where @var{type} is a service type, such as @var{guix-service-type}, and
9944@var{variable} is an identifier that is bound within @var{body} to the
9945value of the service of that @var{type}. @xref{Using the Configuration
9946System}, for an example.
9947
9948This is a shorthand for:
9949
9950@example
9951(map (lambda (service) @dots{}) @var{services})
9952@end example
9953@end deffn
9954
9955Next comes the programming interface for service types. This is
9956something you want to know when writing new service definitions, but not
9957necessarily when simply looking for ways to customize your
9958@code{operating-system} declaration.
9959
0adfe95a
LC
9960@deftp {Data Type} service-type
9961@cindex service type
9962This is the representation of a @dfn{service type} (@pxref{Service Types
9963and Services}).
9964
9965@table @asis
9966@item @code{name}
9967This is a symbol, used only to simplify inspection and debugging.
9968
9969@item @code{extensions}
1068f26b 9970A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
9971
9972@item @code{compose} (default: @code{#f})
9973If this is @code{#f}, then the service type denotes services that cannot
9974be extended---i.e., services that do not receive ``values'' from other
9975services.
9976
9977Otherwise, it must be a one-argument procedure. The procedure is called
9978by @code{fold-services} and is passed a list of values collected from
9979extensions. It must return a value that is a valid parameter value for
9980the service instance.
9981
9982@item @code{extend} (default: @code{#f})
9983If this is @code{#f}, services of this type cannot be extended.
9984
9985Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 9986calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
9987and the result of applying @code{compose} to the extension values as the
9988second argument.
9989@end table
9990
9991@xref{Service Types and Services}, for examples.
9992@end deftp
9993
9994@deffn {Scheme Procedure} service-extension @var{target-type} @
9995 @var{compute}
9996Return a new extension for services of type @var{target-type}.
9997@var{compute} must be a one-argument procedure: @code{fold-services}
9998calls it, passing it the value associated with the service that provides
9999the extension; it must return a valid value for the target service.
10000@end deffn
10001
10002@deffn {Scheme Procedure} service-extension? @var{obj}
10003Return true if @var{obj} is a service extension.
10004@end deffn
10005
10006At the core of the service abstraction lies the @code{fold-services}
10007procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
10008down to a single directory that contains everything needed to boot and
10009run the system---the directory shown by the @command{guix system build}
10010command (@pxref{Invoking guix system}). In essence, it propagates
10011service extensions down the service graph, updating each node parameters
10012on the way, until it reaches the root node.
0adfe95a
LC
10013
10014@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 10015 [#:target-type @var{system-service-type}]
0adfe95a
LC
10016Fold @var{services} by propagating their extensions down to the root of
10017type @var{target-type}; return the root service adjusted accordingly.
10018@end deffn
10019
10020Lastly, the @code{(gnu services)} module also defines several essential
10021service types, some of which are listed below.
10022
d62e201c
LC
10023@defvr {Scheme Variable} system-service-type
10024This is the root of the service graph. It produces the system directory
10025as returned by the @command{guix system build} command.
10026@end defvr
10027
0adfe95a 10028@defvr {Scheme Variable} boot-service-type
d62e201c
LC
10029The type of the ``boot service'', which produces the @dfn{boot script}.
10030The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
10031@end defvr
10032
10033@defvr {Scheme Variable} etc-service-type
10034The type of the @file{/etc} service. This service can be extended by
10035passing it name/file tuples such as:
10036
10037@example
10038(list `("issue" ,(plain-file "issue" "Welcome!\n")))
10039@end example
10040
10041In this example, the effect would be to add an @file{/etc/issue} file
10042pointing to the given file.
10043@end defvr
10044
10045@defvr {Scheme Variable} setuid-program-service-type
10046Type for the ``setuid-program service''. This service collects lists of
10047executable file names, passed as gexps, and adds them to the set of
10048setuid-root programs on the system (@pxref{Setuid Programs}).
10049@end defvr
10050
af4c3fd5
LC
10051@defvr {Scheme Variable} profile-service-type
10052Type of the service that populates the @dfn{system profile}---i.e., the
10053programs under @file{/run/current-system/profile}. Other services can
10054extend it by passing it lists of packages to add to the system profile.
10055@end defvr
10056
0adfe95a 10057
dd17bc38
AK
10058@node Shepherd Services
10059@subsubsection Shepherd Services
0adfe95a
LC
10060
10061@cindex PID 1
10062@cindex init system
a40424bd
CM
10063The @code{(gnu services shepherd)} module provides a way to define
10064services managed by the GNU@tie{}Shepherd, which is the GuixSD
10065initialization system---the first process that is started when the
1068f26b
AE
10066system boots, also known as PID@tie{}1
10067(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 10068
dd17bc38
AK
10069Services in the Shepherd can depend on each other. For instance, the
10070SSH daemon may need to be started after the syslog daemon has been
10071started, which in turn can only happen once all the file systems have
10072been mounted. The simple operating system defined earlier (@pxref{Using
10073the Configuration System}) results in a service graph like this:
6f305ea5 10074
710fa231 10075@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
10076
10077You can actually generate such a graph for any operating system
710fa231
AK
10078definition using the @command{guix system shepherd-graph} command
10079(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 10080
d4053c71
AK
10081The @var{%shepherd-root-service} is a service object representing
10082PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10083by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 10084
d4053c71 10085@deftp {Data Type} shepherd-service
dd17bc38 10086The data type representing a service managed by the Shepherd.
0adfe95a
LC
10087
10088@table @asis
10089@item @code{provision}
10090This is a list of symbols denoting what the service provides.
10091
dd17bc38
AK
10092These are the names that may be passed to @command{herd start},
10093@command{herd status}, and similar commands (@pxref{Invoking herd,,,
10094shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10095@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
10096
10097@item @code{requirements} (default: @code{'()})
dd17bc38 10098List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
10099
10100@item @code{respawn?} (default: @code{#t})
10101Whether to restart the service when it stops, for instance when the
10102underlying process dies.
10103
10104@item @code{start}
10105@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
10106The @code{start} and @code{stop} fields refer to the Shepherd's
10107facilities to start and stop processes (@pxref{Service De- and
10108Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10109G-expressions that get expanded in the Shepherd configuration file
10110(@pxref{G-Expressions}).
0adfe95a
LC
10111
10112@item @code{documentation}
10113A documentation string, as shown when running:
10114
10115@example
dd17bc38 10116herd doc @var{service-name}
0adfe95a
LC
10117@end example
10118
10119where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 10120(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
10121
10122@item @code{modules} (default: @var{%default-modules})
10123This is the list of modules that must be in scope when @code{start} and
10124@code{stop} are evaluated.
10125
10126@item @code{imported-modules} (default: @var{%default-imported-modules})
10127This is the list of modules to import in the execution environment of
dd17bc38 10128the Shepherd.
fae685b9 10129
0adfe95a
LC
10130@end table
10131@end deftp
10132
d4053c71 10133@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 10134The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
10135
10136This is the service type that extensions target when they want to create
dd17bc38 10137shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 10138Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
10139@end defvr
10140
d4053c71 10141@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
10142This service represents PID@tie{}1.
10143@end defvr
8451a568 10144
8451a568 10145
cf4a9129
LC
10146@node Installing Debugging Files
10147@section Installing Debugging Files
8451a568 10148
cf4a9129
LC
10149@cindex debugging files
10150Program binaries, as produced by the GCC compilers for instance, are
10151typically written in the ELF format, with a section containing
10152@dfn{debugging information}. Debugging information is what allows the
10153debugger, GDB, to map binary code to source code; it is required to
10154debug a compiled program in good conditions.
8451a568 10155
cf4a9129
LC
10156The problem with debugging information is that is takes up a fair amount
10157of disk space. For example, debugging information for the GNU C Library
10158weighs in at more than 60 MiB. Thus, as a user, keeping all the
10159debugging info of all the installed programs is usually not an option.
10160Yet, space savings should not come at the cost of an impediment to
10161debugging---especially in the GNU system, which should make it easier
10162for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 10163
cf4a9129
LC
10164Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
10165mechanism that allows users to get the best of both worlds: debugging
10166information can be stripped from the binaries and stored in separate
10167files. GDB is then able to load debugging information from those files,
10168when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
10169with GDB}).
8451a568 10170
cf4a9129
LC
10171The GNU distribution takes advantage of this by storing debugging
10172information in the @code{lib/debug} sub-directory of a separate package
10173output unimaginatively called @code{debug} (@pxref{Packages with
10174Multiple Outputs}). Users can choose to install the @code{debug} output
10175of a package when they need it. For instance, the following command
10176installs the debugging information for the GNU C Library and for GNU
10177Guile:
8451a568
LC
10178
10179@example
cf4a9129 10180guix package -i glibc:debug guile:debug
8451a568
LC
10181@end example
10182
cf4a9129
LC
10183GDB must then be told to look for debug files in the user's profile, by
10184setting the @code{debug-file-directory} variable (consider setting it
10185from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
10186GDB}):
8451a568 10187
cf4a9129
LC
10188@example
10189(gdb) set debug-file-directory ~/.guix-profile/lib/debug
10190@end example
8451a568 10191
cf4a9129
LC
10192From there on, GDB will pick up debugging information from the
10193@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 10194
cf4a9129
LC
10195In addition, you will most likely want GDB to be able to show the source
10196code being debugged. To do that, you will have to unpack the source
10197code of the package of interest (obtained with @code{guix build
10198--source}, @pxref{Invoking guix build}), and to point GDB to that source
10199directory using the @code{directory} command (@pxref{Source Path,
10200@code{directory},, gdb, Debugging with GDB}).
8451a568 10201
cf4a9129
LC
10202@c XXX: keep me up-to-date
10203The @code{debug} output mechanism in Guix is implemented by the
10204@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
10205opt-in---debugging information is available only for the packages
10206with definitions explicitly declaring a @code{debug} output. This may be
10207changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
10208the load. To check whether a package has a @code{debug} output, use
10209@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 10210
8451a568 10211
05962f29
LC
10212@node Security Updates
10213@section Security Updates
10214
843858b8
LC
10215@quotation Note
10216As of version @value{VERSION}, the feature described in this section is
10217experimental.
10218@end quotation
05962f29
LC
10219
10220@cindex security updates
10221Occasionally, important security vulnerabilities are discovered in core
10222software packages and must be patched. Guix follows a functional
10223package management discipline (@pxref{Introduction}), which implies
10224that, when a package is changed, @emph{every package that depends on it}
10225must be rebuilt. This can significantly slow down the deployment of
10226fixes in core packages such as libc or Bash, since basically the whole
10227distribution would need to be rebuilt. Using pre-built binaries helps
10228(@pxref{Substitutes}), but deployment may still take more time than
10229desired.
10230
10231@cindex grafts
1068f26b 10232To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
10233for fast deployment of critical updates without the costs associated
10234with a whole-distribution rebuild. The idea is to rebuild only the
10235package that needs to be patched, and then to ``graft'' it onto packages
10236explicitly installed by the user and that were previously referring to
10237the original package. The cost of grafting is typically very low, and
10238order of magnitudes lower than a full rebuild of the dependency chain.
10239
10240@cindex replacements of packages, for grafts
10241For instance, suppose a security update needs to be applied to Bash.
10242Guix developers will provide a package definition for the ``fixed''
10243Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
10244Packages}). Then, the original package definition is augmented with a
10245@code{replacement} field pointing to the package containing the bug fix:
10246
10247@example
10248(define bash
10249 (package
10250 (name "bash")
10251 ;; @dots{}
10252 (replacement bash-fixed)))
10253@end example
10254
c22a1324
LC
10255From there on, any package depending directly or indirectly on Bash---as
10256reported by @command{guix gc --requisites} (@pxref{Invoking guix
10257gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 10258@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 10259time proportional to the size of the package, usually less than a
c22a1324
LC
10260minute for an ``average'' package on a recent machine. Grafting is
10261recursive: when an indirect dependency requires grafting, then grafting
10262``propagates'' up to the package that the user is installing.
05962f29
LC
10263
10264Currently, the graft and the package it replaces (@var{bash-fixed} and
10265@var{bash} in the example above) must have the exact same @code{name}
10266and @code{version} fields. This restriction mostly comes from the fact
10267that grafting works by patching files, including binary files, directly.
10268Other restrictions may apply: for instance, when adding a graft to a
10269package providing a shared library, the original shared library and its
10270replacement must have the same @code{SONAME} and be binary-compatible.
10271
10272
cf4a9129
LC
10273@node Package Modules
10274@section Package Modules
8451a568 10275
cf4a9129
LC
10276From a programming viewpoint, the package definitions of the
10277GNU distribution are provided by Guile modules in the @code{(gnu packages
10278@dots{})} name space@footnote{Note that packages under the @code{(gnu
10279packages @dots{})} module name space are not necessarily ``GNU
10280packages''. This module naming scheme follows the usual Guile module
10281naming convention: @code{gnu} means that these modules are distributed
10282as part of the GNU system, and @code{packages} identifies modules that
10283define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
10284Reference Manual}). For instance, the @code{(gnu packages emacs)}
10285module exports a variable named @code{emacs}, which is bound to a
10286@code{<package>} object (@pxref{Defining Packages}).
113daf62 10287
300868ba 10288The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
10289automatically scanned for packages by the command-line tools. For
10290instance, when running @code{guix package -i emacs}, all the @code{(gnu
10291packages @dots{})} modules are scanned until one that exports a package
10292object whose name is @code{emacs} is found. This package search
10293facility is implemented in the @code{(gnu packages)} module.
113daf62 10294
300868ba 10295@cindex customization, of packages
8689901f 10296@cindex package module search path
cf4a9129 10297Users can store package definitions in modules with different
60142854 10298names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
10299name and module name must match. For instance, the @code{(my-packages
10300emacs)} module must be stored in a @file{my-packages/emacs.scm} file
10301relative to the load path specified with @option{--load-path} or
10302@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
10303guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
10304will not be visible by default. Users can invoke commands such as
10305@command{guix package} and @command{guix build} with the
c95ded7e
LC
10306@code{-e} option so that they know where to find the package. Better
10307yet, they can use the
300868ba 10308@code{-L} option of these commands to make those modules visible
8689901f
LC
10309(@pxref{Invoking guix build, @code{--load-path}}), or define the
10310@code{GUIX_PACKAGE_PATH} environment variable. This environment
10311variable makes it easy to extend or customize the distribution and is
10312honored by all the user interfaces.
10313
10314@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
10315This is a colon-separated list of directories to search for additional
10316package modules. Directories listed in this variable take precedence
10317over the own modules of the distribution.
8689901f 10318@end defvr
ef5dd60a 10319
cf4a9129
LC
10320The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
10321each package is built based solely on other packages in the
10322distribution. The root of this dependency graph is a small set of
10323@dfn{bootstrap binaries}, provided by the @code{(gnu packages
10324bootstrap)} module. For more information on bootstrapping,
081145cf 10325@pxref{Bootstrapping}.
ef5dd60a 10326
cf4a9129
LC
10327@node Packaging Guidelines
10328@section Packaging Guidelines
ef5dd60a 10329
cf4a9129
LC
10330The GNU distribution is nascent and may well lack some of your favorite
10331packages. This section describes how you can help make the distribution
10332grow. @xref{Contributing}, for additional information on how you can
10333help.
ef5dd60a 10334
cf4a9129
LC
10335Free software packages are usually distributed in the form of
10336@dfn{source code tarballs}---typically @file{tar.gz} files that contain
10337all the source files. Adding a package to the distribution means
10338essentially two things: adding a @dfn{recipe} that describes how to
10339build the package, including a list of other packages required to build
f97c9175 10340it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 10341description and licensing information.
ef5dd60a 10342
cf4a9129
LC
10343In Guix all this information is embodied in @dfn{package definitions}.
10344Package definitions provide a high-level view of the package. They are
10345written using the syntax of the Scheme programming language; in fact,
10346for each package we define a variable bound to the package definition,
10347and export that variable from a module (@pxref{Package Modules}).
10348However, in-depth Scheme knowledge is @emph{not} a prerequisite for
10349creating packages. For more information on package definitions,
081145cf 10350@pxref{Defining Packages}.
ef5dd60a 10351
cf4a9129
LC
10352Once a package definition is in place, stored in a file in the Guix
10353source tree, it can be tested using the @command{guix build} command
10354(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
10355called @code{gnew}, you may run this command from the Guix build tree
10356(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
10357
10358@example
cf4a9129 10359./pre-inst-env guix build gnew --keep-failed
ef5dd60a 10360@end example
ef5dd60a 10361
cf4a9129
LC
10362Using @code{--keep-failed} makes it easier to debug build failures since
10363it provides access to the failed build tree. Another useful
10364command-line option when debugging is @code{--log-file}, to access the
10365build log.
ef5dd60a 10366
cf4a9129
LC
10367If the package is unknown to the @command{guix} command, it may be that
10368the source file contains a syntax error, or lacks a @code{define-public}
10369clause to export the package variable. To figure it out, you may load
10370the module from Guile to get more information about the actual error:
ef5dd60a 10371
cf4a9129
LC
10372@example
10373./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
10374@end example
ef5dd60a 10375
cf4a9129
LC
10376Once your package builds correctly, please send us a patch
10377(@pxref{Contributing}). Well, if you need help, we will be happy to
10378help you too. Once the patch is committed in the Guix repository, the
10379new package automatically gets built on the supported platforms by
2b1cee21 10380@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 10381system}.
ef5dd60a 10382
cf4a9129
LC
10383@cindex substituter
10384Users can obtain the new package definition simply by running
10385@command{guix pull} (@pxref{Invoking guix pull}). When
10386@code{hydra.gnu.org} is done building the package, installing the
10387package automatically downloads binaries from there
10388(@pxref{Substitutes}). The only place where human intervention is
10389needed is to review and apply the patch.
ef5dd60a 10390
ef5dd60a 10391
cf4a9129 10392@menu
ec0339cd
LC
10393* Software Freedom:: What may go into the distribution.
10394* Package Naming:: What's in a name?
10395* Version Numbers:: When the name is not enough.
cbd02397 10396* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
10397* Python Modules:: Taming the snake.
10398* Perl Modules:: Little pearls.
10399* Fonts:: Fond of fonts.
cf4a9129 10400@end menu
ef5dd60a 10401
cf4a9129
LC
10402@node Software Freedom
10403@subsection Software Freedom
ef5dd60a 10404
cf4a9129 10405@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 10406
cf4a9129
LC
10407The GNU operating system has been developed so that users can have
10408freedom in their computing. GNU is @dfn{free software}, meaning that
10409users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10410essential freedoms}: to run the program, to study and change the program
10411in source code form, to redistribute exact copies, and to distribute
10412modified versions. Packages found in the GNU distribution provide only
10413software that conveys these four freedoms.
c11a6eb1 10414
cf4a9129
LC
10415In addition, the GNU distribution follow the
10416@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10417software distribution guidelines}. Among other things, these guidelines
10418reject non-free firmware, recommendations of non-free software, and
10419discuss ways to deal with trademarks and patents.
ef5dd60a 10420
1068f26b
AE
10421Some otherwise free upstream package sources contain a small and optional
10422subset that violates the above guidelines, for instance because this subset
10423is itself non-free code. When that happens, the offending items are removed
10424with appropriate patches or code snippets in the @code{origin} form of the
10425package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
10426build --source} returns the ``freed'' source rather than the unmodified
10427upstream source.
ef5dd60a 10428
ef5dd60a 10429
cf4a9129
LC
10430@node Package Naming
10431@subsection Package Naming
ef5dd60a 10432
cf4a9129
LC
10433A package has actually two names associated with it:
10434First, there is the name of the @emph{Scheme variable}, the one following
10435@code{define-public}. By this name, the package can be made known in the
10436Scheme code, for instance as input to another package. Second, there is
10437the string in the @code{name} field of a package definition. This name
10438is used by package management commands such as
10439@command{guix package} and @command{guix build}.
ef5dd60a 10440
cf4a9129
LC
10441Both are usually the same and correspond to the lowercase conversion of
10442the project name chosen upstream, with underscores replaced with
10443hyphens. For instance, GNUnet is available as @code{gnunet}, and
10444SDL_net as @code{sdl-net}.
927097ef 10445
cf4a9129 10446We do not add @code{lib} prefixes for library packages, unless these are
081145cf 10447already part of the official project name. But @pxref{Python
cf4a9129
LC
10448Modules} and @ref{Perl Modules} for special rules concerning modules for
10449the Python and Perl languages.
927097ef 10450
1b366ee4 10451Font package names are handled differently, @pxref{Fonts}.
7fec52b7 10452
ef5dd60a 10453
cf4a9129
LC
10454@node Version Numbers
10455@subsection Version Numbers
ef5dd60a 10456
cf4a9129
LC
10457We usually package only the latest version of a given free software
10458project. But sometimes, for instance for incompatible library versions,
10459two (or more) versions of the same package are needed. These require
10460different Scheme variable names. We use the name as defined
10461in @ref{Package Naming}
10462for the most recent version; previous versions use the same name, suffixed
10463by @code{-} and the smallest prefix of the version number that may
10464distinguish the two versions.
ef5dd60a 10465
cf4a9129
LC
10466The name inside the package definition is the same for all versions of a
10467package and does not contain any version number.
ef5dd60a 10468
cf4a9129 10469For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 10470
cf4a9129
LC
10471@example
10472(define-public gtk+
10473 (package
17d8e33f
ML
10474 (name "gtk+")
10475 (version "3.9.12")
10476 ...))
cf4a9129
LC
10477(define-public gtk+-2
10478 (package
17d8e33f
ML
10479 (name "gtk+")
10480 (version "2.24.20")
10481 ...))
cf4a9129
LC
10482@end example
10483If we also wanted GTK+ 3.8.2, this would be packaged as
10484@example
10485(define-public gtk+-3.8
10486 (package
17d8e33f
ML
10487 (name "gtk+")
10488 (version "3.8.2")
10489 ...))
cf4a9129 10490@end example
ef5dd60a 10491
880d647d
LC
10492@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
10493@c for a discussion of what follows.
10494@cindex version number, for VCS snapshots
10495Occasionally, we package snapshots of upstream's version control system
10496(VCS) instead of formal releases. This should remain exceptional,
10497because it is up to upstream developers to clarify what the stable
10498release is. Yet, it is sometimes necessary. So, what should we put in
10499the @code{version} field?
10500
10501Clearly, we need to make the commit identifier of the VCS snapshot
10502visible in the version string, but we also need to make sure that the
10503version string is monotonically increasing so that @command{guix package
10504--upgrade} can determine which version is newer. Since commit
10505identifiers, notably with Git, are not monotonically increasing, we add
10506a revision number that we increase each time we upgrade to a newer
10507snapshot. The resulting version string looks like this:
10508
10509@example
105102.0.11-3.cabba9e
10511 ^ ^ ^
10512 | | `-- upstream commit ID
10513 | |
10514 | `--- Guix package revision
10515 |
10516latest upstream version
10517@end example
10518
10519It is a good idea to strip commit identifiers in the @code{version}
10520field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
10521aesthetics have a role to play here) as well as problems related to OS
10522limits such as the maximum shebang length (127 bytes for the Linux
10523kernel.) It is best to use the full commit identifiers in
561360a5
LC
10524@code{origin}s, though, to avoid ambiguities. A typical package
10525definition may look like this:
10526
10527@example
10528(define my-package
10529 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
10530 (package
10531 (version (string-append "0.9-1."
10532 (string-take commit 7)))
10533 (source (origin
10534 (method git-fetch)
10535 (uri (git-reference
10536 (url "git://example.org/my-package.git")
10537 (commit commit)))
10538 (sha256 (base32 "1mbikn@dots{}"))
10539 (file-name (string-append "my-package-" version
10540 "-checkout"))))
10541 ;; @dots{}
10542 )))
10543@end example
880d647d 10544
cbd02397
LC
10545@node Synopses and Descriptions
10546@subsection Synopses and Descriptions
10547
10548As we have seen before, each package in GNU@tie{}Guix includes a
10549synopsis and a description (@pxref{Defining Packages}). Synopses and
10550descriptions are important: They are what @command{guix package
10551--search} searches, and a crucial piece of information to help users
10552determine whether a given package suits their needs. Consequently,
10553packagers should pay attention to what goes into them.
10554
10555Synopses must start with a capital letter and must not end with a
10556period. They must not start with ``a'' or ``the'', which usually does
10557not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10558tool that frobs files''. The synopsis should say what the package
10559is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10560used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10561matching a pattern''.
10562
10563Keep in mind that the synopsis must be meaningful for a very wide
10564audience. For example, ``Manipulate alignments in the SAM format''
10565might make sense for a seasoned bioinformatics researcher, but might be
10566fairly unhelpful or even misleading to a non-specialized audience. It
10567is a good idea to come up with a synopsis that gives an idea of the
10568application domain of the package. In this example, this might give
10569something like ``Manipulate nucleotide sequence alignments'', which
10570hopefully gives the user a better idea of whether this is what they are
10571looking for.
10572
10573@cindex Texinfo markup, in package descriptions
10574Descriptions should take between five and ten lines. Use full
10575sentences, and avoid using acronyms without first introducing them.
10576Descriptions can include Texinfo markup, which is useful to introduce
10577ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
10578hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10579should be careful when using some characters for example @samp{@@} and
10580curly braces which are the basic special characters in Texinfo
10581(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10582such as @command{guix package --show} take care of rendering it
10583appropriately.
cbd02397
LC
10584
10585Synopses and descriptions are translated by volunteers
10586@uref{http://translationproject.org/domain/guix-packages.html, at the
10587Translation Project} so that as many users as possible can read them in
10588their native language. User interfaces search them and display them in
10589the language specified by the current locale.
10590
10591Translation is a lot of work so, as a packager, please pay even more
10592attention to your synopses and descriptions as every change may entail
ba7d6c76 10593additional work for translators. In order to help them, it is possible
36743e71 10594to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
10595special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10596Gettext}):
10597
10598@example
10599;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10600(description "ARandR is designed to provide a simple visual front end
10601for the X11 resize-and-rotate (RandR) extension. @dots{}")
10602@end example
cbd02397 10603
ef5dd60a 10604
cf4a9129
LC
10605@node Python Modules
10606@subsection Python Modules
ef5dd60a 10607
cf4a9129
LC
10608We currently package Python 2 and Python 3, under the Scheme variable names
10609@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10610To avoid confusion and naming clashes with other programming languages, it
10611seems desirable that the name of a package for a Python module contains
10612the word @code{python}.
ef5dd60a 10613
cf4a9129
LC
10614Some modules are compatible with only one version of Python, others with both.
10615If the package Foo compiles only with Python 3, we name it
10616@code{python-foo}; if it compiles only with Python 2, we name it
10617@code{python2-foo}. If it is compatible with both versions, we create two
10618packages with the corresponding names.
ef5dd60a 10619
cf4a9129
LC
10620If a project already contains the word @code{python}, we drop this;
10621for instance, the module python-dateutil is packaged under the names
10622@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10623
523e4896 10624
cf4a9129
LC
10625@node Perl Modules
10626@subsection Perl Modules
523e4896 10627
cf4a9129
LC
10628Perl programs standing for themselves are named as any other package,
10629using the lowercase upstream name.
10630For Perl packages containing a single class, we use the lowercase class name,
10631replace all occurrences of @code{::} by dashes and prepend the prefix
10632@code{perl-}.
10633So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10634Modules containing several classes keep their lowercase upstream name and
10635are also prepended by @code{perl-}. Such modules tend to have the word
10636@code{perl} somewhere in their name, which gets dropped in favor of the
10637prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10638
523e4896 10639
7fec52b7
AE
10640@node Fonts
10641@subsection Fonts
10642
10643For fonts that are in general not installed by a user for typesetting
10644purposes, or that are distributed as part of a larger software package,
10645we rely on the general packaging rules for software; for instance, this
10646applies to the fonts delivered as part of the X.Org system or fonts that
10647are part of TeX Live.
10648
10649To make it easier for a user to search for fonts, names for other packages
10650containing only fonts are constructed as follows, independently of the
10651upstream package name.
10652
10653The name of a package containing only one font family starts with
10654@code{font-}; it is followed by the foundry name and a dash @code{-}
10655if the foundry is known, and the font family name, in which spaces are
10656replaced by dashes (and as usual, all upper case letters are transformed
10657to lower case).
10658For example, the Gentium font family by SIL is packaged under the name
10659@code{font-sil-gentium}.
10660
10661For a package containing several font families, the name of the collection
10662is used in the place of the font family name.
10663For instance, the Liberation fonts consist of three families,
10664Liberation Sans, Liberation Serif and Liberation Mono.
10665These could be packaged separately under the names
10666@code{font-liberation-sans} and so on; but as they are distributed together
10667under a common name, we prefer to package them together as
10668@code{font-liberation}.
10669
10670In the case where several formats of the same font family or font collection
10671are packaged separately, a short form of the format, prepended by a dash,
10672is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10673@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10674fonts.
10675
10676
b25937e3 10677
cf4a9129
LC
10678@node Bootstrapping
10679@section Bootstrapping
b25937e3 10680
cf4a9129 10681@c Adapted from the ELS 2013 paper.
b25937e3 10682
cf4a9129 10683@cindex bootstrapping
7889394e 10684
cf4a9129
LC
10685Bootstrapping in our context refers to how the distribution gets built
10686``from nothing''. Remember that the build environment of a derivation
10687contains nothing but its declared inputs (@pxref{Introduction}). So
10688there's an obvious chicken-and-egg problem: how does the first package
10689get built? How does the first compiler get compiled? Note that this is
10690a question of interest only to the curious hacker, not to the regular
10691user, so you can shamelessly skip this section if you consider yourself
10692a ``regular user''.
72b9d60d 10693
cf4a9129
LC
10694@cindex bootstrap binaries
10695The GNU system is primarily made of C code, with libc at its core. The
10696GNU build system itself assumes the availability of a Bourne shell and
10697command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10698`grep'. Furthermore, build programs---programs that run
10699@code{./configure}, @code{make}, etc.---are written in Guile Scheme
10700(@pxref{Derivations}). Consequently, to be able to build anything at
10701all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10702Binutils, libc, and the other packages mentioned above---the
10703@dfn{bootstrap binaries}.
72b9d60d 10704
cf4a9129
LC
10705These bootstrap binaries are ``taken for granted'', though we can also
10706re-create them if needed (more on that later).
72b9d60d 10707
cf4a9129 10708@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 10709
cf4a9129
LC
10710@c As of Emacs 24.3, Info-mode displays the image, but since it's a
10711@c large image, it's hard to scroll. Oh well.
10712@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 10713
cf4a9129
LC
10714The figure above shows the very beginning of the dependency graph of the
10715distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
10716packages bootstrap)} module. A similar figure can be generated with
10717@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
10718
10719@example
10720guix graph -t derivation \
10721 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
10722 | dot -Tps > t.ps
10723@end example
10724
10725At this level of detail, things are
cf4a9129
LC
10726slightly complex. First, Guile itself consists of an ELF executable,
10727along with many source and compiled Scheme files that are dynamically
10728loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10729tarball shown in this graph. This tarball is part of Guix's ``source''
10730distribution, and gets inserted into the store with @code{add-to-store}
10731(@pxref{The Store}).
2e7b5cea 10732
cf4a9129
LC
10733But how do we write a derivation that unpacks this tarball and adds it
10734to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10735derivation---the first one that gets built---uses @code{bash} as its
10736builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10737@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10738@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10739the Guix source distribution, whose sole purpose is to allow the Guile
10740tarball to be unpacked.
fb729425 10741
cf4a9129
LC
10742Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10743Guile that can be used to run subsequent build programs. Its first task
10744is to download tarballs containing the other pre-built binaries---this
10745is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10746@code{ftp-client.scm} are used for this purpose. The
10747@code{module-import.drv} derivations import those modules in a directory
10748in the store, using the original layout. The
10749@code{module-import-compiled.drv} derivations compile those modules, and
10750write them in an output directory with the right layout. This
10751corresponds to the @code{#:modules} argument of
10752@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 10753
cf4a9129
LC
10754Finally, the various tarballs are unpacked by the
10755derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10756etc., at which point we have a working C tool chain.
fb729425 10757
fb729425 10758
cf4a9129 10759@unnumberedsubsec Building the Build Tools
523e4896 10760
cf4a9129
LC
10761Bootstrapping is complete when we have a full tool chain that does not
10762depend on the pre-built bootstrap tools discussed above. This
10763no-dependency requirement is verified by checking whether the files of
10764the final tool chain contain references to the @file{/gnu/store}
10765directories of the bootstrap inputs. The process that leads to this
10766``final'' tool chain is described by the package definitions found in
1f6f57df 10767the @code{(gnu packages commencement)} module.
df2ce343 10768
d33fa0c7
LC
10769The @command{guix graph} command allows us to ``zoom out'' compared to
10770the graph above, by looking at the level of package objects instead of
10771individual derivations---remember that a package may translate to
10772several derivations, typically one derivation to download its source,
10773one to build the Guile modules it needs, and one to actually build the
10774package from source. The command:
10775
10776@example
10777guix graph -t bag \
10778 -e '(@@@@ (gnu packages commencement)
10779 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
10780@end example
10781
10782@noindent
10783produces the dependency graph leading to the ``final'' C
10784library@footnote{You may notice the @code{glibc-intermediate} label,
10785suggesting that it is not @emph{quite} final, but as a good
10786approximation, we will consider it final.}, depicted below.
10787
10788@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
10789
cf4a9129
LC
10790@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10791The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
10792GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
10793for all the following packages. From there Findutils and Diffutils get
10794built.
523e4896 10795
cf4a9129
LC
10796Then come the first-stage Binutils and GCC, built as pseudo cross
10797tools---i.e., with @code{--target} equal to @code{--host}. They are
10798used to build libc. Thanks to this cross-build trick, this libc is
10799guaranteed not to hold any reference to the initial tool chain.
4af2447e 10800
d33fa0c7
LC
10801From there the final Binutils and GCC (not shown above) are built.
10802GCC uses @code{ld}
cf4a9129
LC
10803from the final Binutils, and links programs against the just-built libc.
10804This tool chain is used to build the other packages used by Guix and by
10805the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 10806
cf4a9129
LC
10807And voilà! At this point we have the complete set of build tools that
10808the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
10809variable of the @code{(gnu packages commencement)} module, and are
10810implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 10811(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 10812
4af2447e 10813
cf4a9129 10814@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 10815
cf4a9129
LC
10816Because the final tool chain does not depend on the bootstrap binaries,
10817those rarely need to be updated. Nevertheless, it is useful to have an
10818automated way to produce them, should an update occur, and this is what
10819the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 10820
cf4a9129
LC
10821The following command builds the tarballs containing the bootstrap
10822binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10823of Coreutils and other basic command-line tools):
4b2615e1 10824
cf4a9129
LC
10825@example
10826guix build bootstrap-tarballs
10827@end example
10828
10829The generated tarballs are those that should be referred to in the
10830@code{(gnu packages bootstrap)} module mentioned at the beginning of
10831this section.
10832
10833Still here? Then perhaps by now you've started to wonder: when do we
10834reach a fixed point? That is an interesting question! The answer is
10835unknown, but if you would like to investigate further (and have
10836significant computational and storage resources to do so), then let us
10837know.
10838
10839@node Porting
10840@section Porting to a New Platform
10841
10842As discussed above, the GNU distribution is self-contained, and
10843self-containment is achieved by relying on pre-built ``bootstrap
10844binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10845operating system kernel, CPU architecture, and application binary
10846interface (ABI). Thus, to port the distribution to a platform that is
10847not yet supported, one must build those bootstrap binaries, and update
10848the @code{(gnu packages bootstrap)} module to use them on that platform.
10849
10850Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10851When everything goes well, and assuming the GNU tool chain supports the
10852target platform, this can be as simple as running a command like this
10853one:
10854
10855@example
10856guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10857@end example
10858
1c0c417d
LC
10859For this to work, the @code{glibc-dynamic-linker} procedure in
10860@code{(gnu packages bootstrap)} must be augmented to return the right
10861file name for libc's dynamic linker on that platform; likewise,
10862@code{system->linux-architecture} in @code{(gnu packages linux)} must be
10863taught about the new platform.
10864
cf4a9129 10865Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
10866to be updated to refer to these binaries on the target platform. That
10867is, the hashes and URLs of the bootstrap tarballs for the new platform
10868must be added alongside those of the currently supported platforms. The
10869bootstrap Guile tarball is treated specially: it is expected to be
10870available locally, and @file{gnu-system.am} has rules do download it for
10871the supported architectures; a rule for the new platform must be added
10872as well.
cf4a9129
LC
10873
10874In practice, there may be some complications. First, it may be that the
10875extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10876above) is not recognized by all the GNU tools. Typically, glibc
10877recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10878configure flag (see @code{gcc.scm} for examples of how to handle this).
10879Second, some of the required packages could fail to build for that
10880platform. Lastly, the generated binaries could be broken for some
10881reason.
4af2447e 10882
9bf3c1a7 10883@c *********************************************************************
8c01b9d0 10884@include contributing.texi
c78bd12b 10885
568717fd
LC
10886@c *********************************************************************
10887@node Acknowledgments
10888@chapter Acknowledgments
10889
136787cb
LC
10890Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10891which was designed and
4c7ac9aa
LC
10892implemented by Eelco Dolstra, with contributions from other people (see
10893the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
10894management, and promoted unprecedented features, such as transactional
10895package upgrades and rollbacks, per-user profiles, and referentially
10896transparent build processes. Without this work, Guix would not exist.
10897
10898The Nix-based software distributions, Nixpkgs and NixOS, have also been
10899an inspiration for Guix.
10900
4c7ac9aa
LC
10901GNU@tie{}Guix itself is a collective work with contributions from a
10902number of people. See the @file{AUTHORS} file in Guix for more
10903information on these fine people. The @file{THANKS} file lists people
10904who have helped by reporting bugs, taking care of the infrastructure,
10905providing artwork and themes, making suggestions, and more---thank you!
10906
10907
568717fd
LC
10908@c *********************************************************************
10909@node GNU Free Documentation License
10910@appendix GNU Free Documentation License
10911
10912@include fdl-1.3.texi
10913
10914@c *********************************************************************
10915@node Concept Index
10916@unnumbered Concept Index
10917@printindex cp
10918
a85b83d2
LC
10919@node Programming Index
10920@unnumbered Programming Index
10921@syncodeindex tp fn
10922@syncodeindex vr fn
568717fd
LC
10923@printindex fn
10924
10925@bye
10926
10927@c Local Variables:
10928@c ispell-local-dictionary: "american";
10929@c End: