doc: Improve Info categories.
[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.
5593You're reading this documentation with an Info reader. For details on
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
5931@xref{Invoking guix system}, for more information. See
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
5947makes it possible to roll-back to a previous system instantiation,
5948should something go wrong with the new one (@pxref{Features}). Another
5949one is that it makes it easy to replicate the exact same configuration
5950across different machines, or at different points in time, without
5951having to resort to additional administration tools layered on top of
5952the system's own tools.
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
6107The normal way to change the system's configuration is by updating this
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
6164the kernel's command-line---e.g., @code{("console=ttyS0")}.
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
6220what displayed when users log in on a text console.
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
6226The default set includes core utilities, but it is good practice to
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
LC
6250@item @code{name-service-switch} (default: @var{%default-nss})
6251Configuration of libc's name service switch (NSS)---a
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
LC
6284The list of file systems to be mounted is specified in the
6285@code{file-systems} field of the operating system's declaration
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
5f86a66e
LC
6349However, when a file system's source is a mapped device (@pxref{Mapped
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}
6500command, from the same-named package. This relies on the
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
LC
6552@item @code{comment} (default: @code{""})
6553A comment about the account, such as the account's owner 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}
6595The group's name.
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
6607@code{#f}, this field specifies the group's password.
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
b2636518
LC
6706An arbitrary list of commonly used UTF-8 locales, used as the default
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
LC
6836expect from the system: a login service (mingetty) on each tty, syslogd,
6837libc's name service cache daemon (nscd), the udev device manager, and
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 '()]
b893f1ae
LC
6896Return a service that runs libc's name service cache daemon (nscd) with the
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
6903by @code{nscd-service}. This uses the caches defined by
6904@var{%nscd-default-caches}; see below.
6905@end defvr
6906
6907@deftp {Data Type} nscd-configuration
6908This is the type representing the name service cache daemon (nscd)
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
LC
6921@item @code{log-file} (default: @code{"/var/log/nscd.log"})
6922Name of nscd's log file. This is where debugging output goes when
6923@code{debug-level} is strictly positive.
6924
6925@item @code{debug-level} (default: @code{0})
6926Integer denoting the debugging levels. Higher numbers mean more
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
6977@code{nscd-configuration} (see above.)
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
be1c2c54 6987@deffn {Scheme Procedure} syslog-service [#:config-file #f]
1bb76f75
AK
6988Return a service that runs @code{syslogd}. If configuration file name
6989@var{config-file} is not specified, use some reasonable default
cf4a9129
LC
6990settings.
6991@end deffn
401c53c4 6992
0adfe95a
LC
6993@anchor{guix-configuration-type}
6994@deftp {Data Type} guix-configuration
6995This data type represents the configuration of the Guix build daemon.
6996@xref{Invoking guix-daemon}, for more information.
6997
6998@table @asis
6999@item @code{guix} (default: @var{guix})
7000The Guix package to use.
401c53c4 7001
0adfe95a
LC
7002@item @code{build-group} (default: @code{"guixbuild"})
7003Name of the group for build user accounts.
401c53c4 7004
0adfe95a
LC
7005@item @code{build-accounts} (default: @code{10})
7006Number of build user accounts to create.
401c53c4 7007
0adfe95a
LC
7008@item @code{authorize-key?} (default: @code{#t})
7009Whether to authorize the substitute key for @code{hydra.gnu.org}
7010(@pxref{Substitutes}).
7011
7012@item @code{use-substitutes?} (default: @code{#t})
7013Whether to use substitutes.
7014
b0b9f6e0
LC
7015@item @code{substitute-urls} (default: @var{%default-substitute-urls})
7016The list of URLs where to look for substitutes by default.
7017
0adfe95a
LC
7018@item @code{extra-options} (default: @code{'()})
7019List of extra command-line options for @command{guix-daemon}.
7020
7021@item @code{lsof} (default: @var{lsof})
7022@itemx @code{lsh} (default: @var{lsh})
7023The lsof and lsh packages to use.
7024
7025@end table
7026@end deftp
7027
7028@deffn {Scheme Procedure} guix-service @var{config}
7029Return a service that runs the Guix build daemon according to
7030@var{config}.
cf4a9129 7031@end deffn
a1ba8475 7032
be1c2c54 7033@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
7034Run @var{udev}, which populates the @file{/dev} directory dynamically.
7035@end deffn
401c53c4 7036
be1c2c54 7037@deffn {Scheme Procedure} console-keymap-service @var{file}
dedb8d5e 7038@cindex keyboard layout
5eca9459
AK
7039Return a service to load console keymap from @var{file} using
7040@command{loadkeys} command.
7041@end deffn
7042
8664cc88
LC
7043@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
7044 [#:options]
7045Run @var{gpm}, the general-purpose mouse daemon, with the given
7046command-line @var{options}. GPM allows users to use the mouse in the console,
7047notably to select, copy, and paste text. The default value of @var{options}
7048uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7049
7050This service is not part of @var{%base-services}.
7051@end deffn
7052
1c52181f
LC
7053@anchor{guix-publish-service}
7054@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7055 [#:port 80] [#:host "localhost"]
7056Return a service that runs @command{guix publish} listening on @var{host}
7057and @var{port} (@pxref{Invoking guix publish}).
7058
7059This assumes that @file{/etc/guix} already contains a signing key pair as
7060created by @command{guix archive --generate-key} (@pxref{Invoking guix
7061archive}). If that is not the case, the service will fail to start.
7062@end deffn
7063
a69576ea 7064
cf4a9129
LC
7065@node Networking Services
7066@subsubsection Networking Services
401c53c4 7067
fa1e31b8 7068The @code{(gnu services networking)} module provides services to configure
cf4a9129 7069the network interface.
a1ba8475 7070
a023cca8 7071@cindex DHCP, networking service
be1c2c54 7072@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
7073Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7074Protocol (DHCP) client, on all the non-loopback network interfaces.
7075@end deffn
7076
be1c2c54 7077@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
7078 [#:gateway #f] [#:name-services @code{'()}]
7079Return a service that starts @var{interface} with address @var{ip}. If
7080@var{gateway} is true, it must be a string specifying the default network
7081gateway.
7082@end deffn
8b315a6d 7083
b7d0c494 7084@cindex wicd
87f40011 7085@cindex network management
be1c2c54 7086@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
7087Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7088management daemon that aims to simplify wired and wireless networking.
7089
7090This service adds the @var{wicd} package to the global profile, providing
7091several commands to interact with the daemon and configure networking:
7092@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7093and @command{wicd-curses} user interfaces.
b7d0c494
MW
7094@end deffn
7095
c0a9589d
SB
7096@cindex NetworkManager
7097@deffn {Scheme Procedure} network-manager-service @
7098 [#:network-manager @var{network-manager}]
7099Return a service that runs NetworkManager, a network connection manager
7100that attempting to keep active network connectivity when available.
7101@end deffn
7102
be1c2c54 7103@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
7104 [#:name-service @var{%ntp-servers}]
7105Return a service that runs the daemon from @var{ntp}, the
7106@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7107keep the system clock synchronized with that of @var{servers}.
7108@end deffn
7109
7110@defvr {Scheme Variable} %ntp-servers
7111List of host names used as the default NTP servers.
7112@end defvr
7113
375c6108
LC
7114@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7115Return a service to run the @uref{https://torproject.org, Tor} anonymous
7116networking daemon.
8b315a6d 7117
375c6108 7118The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
7119@var{config-file}, a file-like object, with an additional @code{User tor} line
7120and lines for hidden services added via @code{tor-hidden-service}. Run
7121@command{man tor} for information about the configuration file.
7122@end deffn
7123
24a8ef3b 7124@cindex hidden service
6331bde7
LC
7125@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7126Define a new Tor @dfn{hidden service} called @var{name} and implementing
7127@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7128
7129@example
24a8ef3b
LC
7130 '((22 "127.0.0.1:22")
7131 (80 "127.0.0.1:8080"))
6331bde7
LC
7132@end example
7133
7134In this example, port 22 of the hidden service is mapped to local port 22, and
7135port 80 is mapped to local port 8080.
7136
6629099a
LC
7137This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7138the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
7139service.
7140
7141See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7142project's documentation} for more information.
cf4a9129 7143@end deffn
8b315a6d 7144
be1c2c54 7145@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
7146 [#:interface "127.0.0.1"] [#:port 6667] @
7147 [#:extra-settings ""]
7148Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7149acts as a gateway between IRC and chat networks.
7150
7151The daemon will listen to the interface corresponding to the IP address
7152specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7153local clients can connect, whereas @code{0.0.0.0} means that connections can
7154come from any networking interface.
7155
7156In addition, @var{extra-settings} specifies a string to append to the
7157configuration file.
7158@end deffn
7159
f4391bec 7160Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 7161
be1c2c54 7162@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 7163 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
7164 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7165 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7166 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 7167 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
7168Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7169@var{host-key} must designate a file containing the host key, and readable
7170only by root.
72e25e35 7171
5833bf33
DP
7172When @var{daemonic?} is true, @command{lshd} will detach from the
7173controlling terminal and log its output to syslogd, unless one sets
7174@var{syslog-output?} to false. Obviously, it also makes lsh-service
7175depend on existence of syslogd service. When @var{pid-file?} is true,
7176@command{lshd} writes its PID to the file called @var{pid-file}.
7177
cf4a9129
LC
7178When @var{initialize?} is true, automatically create the seed and host key
7179upon service activation if they do not exist yet. This may take long and
7180require interaction.
8b315a6d 7181
20dd519c
LC
7182When @var{initialize?} is false, it is up to the user to initialize the
7183randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7184a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7185basics,,, lsh, LSH Manual}).
7186
cf4a9129
LC
7187When @var{interfaces} is empty, lshd listens for connections on all the
7188network interfaces; otherwise, @var{interfaces} must be a list of host names
7189or addresses.
9bf3c1a7 7190
20dd519c
LC
7191@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7192passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 7193root.
4af2447e 7194
cf4a9129
LC
7195The other options should be self-descriptive.
7196@end deffn
4af2447e 7197
fa0c1d61
LC
7198@defvr {Scheme Variable} %facebook-host-aliases
7199This variable contains a string for use in @file{/etc/hosts}
7200(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7201line contains a entry that maps a known server name of the Facebook
7202on-line service---e.g., @code{www.facebook.com}---to the local
7203host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7204
7205This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
7206@code{operating-system} declaration (@pxref{operating-system Reference,
7207@file{/etc/hosts}}):
fa0c1d61
LC
7208
7209@example
7210(use-modules (gnu) (guix))
7211
7212(operating-system
7213 (host-name "mymachine")
7214 ;; ...
7215 (hosts-file
7216 ;; Create a /etc/hosts file with aliases for "localhost"
7217 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
7218 (plain-file "hosts"
7219 (string-append (local-host-aliases host-name)
7220 %facebook-host-aliases))))
fa0c1d61
LC
7221@end example
7222
7223This mechanism can prevent programs running locally, such as Web
7224browsers, from accessing Facebook.
7225@end defvr
7226
965a7332
LC
7227The @code{(gnu services avahi)} provides the following definition.
7228
be1c2c54 7229@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
7230 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7231 [#:ipv6? #t] [#:wide-area? #f] @
7232 [#:domains-to-browse '()]
7233Return a service that runs @command{avahi-daemon}, a system-wide
7234mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
7235"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7236extends the name service cache daemon (nscd) so that it can resolve
7237@code{.local} host names using
1065bed9
LC
7238@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7239add the @var{avahi} package to the system profile so that commands such as
7240@command{avahi-browse} are directly usable.
965a7332
LC
7241
7242If @var{host-name} is different from @code{#f}, use that as the host name to
7243publish for this machine; otherwise, use the machine's actual host name.
7244
7245When @var{publish?} is true, publishing of host names and services is allowed;
7246in particular, avahi-daemon will publish the machine's host name and IP
7247address via mDNS on the local network.
7248
7249When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7250
7251Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7252sockets.
7253@end deffn
7254
7255
cf4a9129
LC
7256@node X Window
7257@subsubsection X Window
68ad877c 7258
cf4a9129
LC
7259Support for the X Window graphical display system---specifically
7260Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7261there is no @code{xorg-service} procedure. Instead, the X server is
7262started by the @dfn{login manager}, currently SLiM.
4af2447e 7263
be1c2c54 7264@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
7265 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7266 [#:theme @var{%default-slim-theme}] @
4bd43bbe 7267 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
7268Return a service that spawns the SLiM graphical login manager, which in
7269turn starts the X display server with @var{startx}, a command as returned by
7270@code{xorg-start-command}.
4af2447e 7271
04e4e6ab
LC
7272@cindex X session
7273
7274SLiM automatically looks for session types described by the @file{.desktop}
7275files in @file{/run/current-system/profile/share/xsessions} and allows users
7276to choose a session from the log-in screen using @kbd{F1}. Packages such as
7277@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
7278adding them to the system-wide set of packages automatically makes them
7279available at the log-in screen.
7280
7281In addition, @file{~/.xsession} files are honored. When available,
7282@file{~/.xsession} must be an executable that starts a window manager
7283and/or other X clients.
7284
cf4a9129
LC
7285When @var{allow-empty-passwords?} is true, allow logins with an empty
7286password. When @var{auto-login?} is true, log in automatically as
7287@var{default-user}.
0ecc3bf3
LC
7288
7289If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
7290@var{theme} must be a gexp denoting the name of a directory containing the
7291theme to use. In that case, @var{theme-name} specifies the name of the
7292theme.
cf4a9129 7293@end deffn
4af2447e 7294
0ecc3bf3
LC
7295@defvr {Scheme Variable} %default-theme
7296@defvrx {Scheme Variable} %default-theme-name
7297The G-Expression denoting the default SLiM theme and its name.
7298@end defvr
7299
be1c2c54 7300@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 7301 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 7302Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
7303from @var{xorg-server}. @var{configuration-file} is the server configuration
7304file or a derivation that builds it; when omitted, the result of
7305@code{xorg-configuration-file} is used.
7306
7307Usually the X server is started by a login manager.
7308@end deffn
7309
be1c2c54 7310@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 7311 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
7312Return a configuration file for the Xorg server containing search paths for
7313all the common drivers.
f703413e
LC
7314
7315@var{drivers} must be either the empty list, in which case Xorg chooses a
7316graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 7317this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
7318
7319Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7320appropriate screen resolution; otherwise, it must be a list of
7321resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
7322
7323Last, @var{extra-config} is a list of strings or objects appended to the
7324@code{text-file*} argument list. It is used to pass extra text to be added
7325verbatim to the configuration file.
f703413e 7326@end deffn
4af2447e 7327
6726282b
LC
7328@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7329Add @var{package}, a package for a screen-locker or screen-saver whose
7330command is @var{program}, to the set of setuid programs and add a PAM entry
7331for it. For example:
7332
7333@lisp
7334(screen-locker-service xlockmore "xlock")
7335@end lisp
7336
7337makes the good ol' XlockMore usable.
7338@end deffn
7339
7340
fe1a39d3
LC
7341@node Desktop Services
7342@subsubsection Desktop Services
aa4ed923 7343
fe1a39d3
LC
7344The @code{(gnu services desktop)} module provides services that are
7345usually useful in the context of a ``desktop'' setup---that is, on a
7346machine running a graphical display server, possibly with graphical user
7347interfaces, etc.
aa4ed923 7348
4467be21
LC
7349To simplify things, the module defines a variable containing the set of
7350services that users typically expect on a machine with a graphical
7351environment and networking:
7352
7353@defvr {Scheme Variable} %desktop-services
7354This is a list of services that builds upon @var{%base-services} and
7355adds or adjust services for a typical ``desktop'' setup.
7356
7357In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
7358@code{slim-service}}), screen lockers,
7359a network management tool (@pxref{Networking
4467be21 7360Services, @code{wicd-service}}), energy and color management services,
4650a77e 7361the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
7362the GeoClue location service, an NTP client (@pxref{Networking
7363Services}), the Avahi daemon, and has the name service switch service
7364configured to be able to use @code{nss-mdns} (@pxref{Name Service
7365Switch, mDNS}).
4467be21
LC
7366@end defvr
7367
7368The @var{%desktop-services} variable can be used as the @code{services}
7369field of an @code{operating-system} declaration (@pxref{operating-system
7370Reference, @code{services}}).
7371
0adfe95a
LC
7372The actual service definitions provided by @code{(gnu services dbus)}
7373and @code{(gnu services desktop)} are described below.
4467be21 7374
0adfe95a 7375@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
7376Return a service that runs the ``system bus'', using @var{dbus}, with
7377support for @var{services}.
aa4ed923 7378
fe1a39d3
LC
7379@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7380facility. Its system bus is used to allow system services to communicate
7381and be notified of system-wide events.
aa4ed923 7382
fe1a39d3
LC
7383@var{services} must be a list of packages that provide an
7384@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7385and policy files. For example, to allow avahi-daemon to use the system bus,
7386@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
7387@end deffn
7388
0adfe95a 7389@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
7390Return a service that runs the @code{elogind} login and
7391seat management daemon. @uref{https://github.com/andywingo/elogind,
7392Elogind} exposes a D-Bus interface that can be used to know which users
7393are logged in, know what kind of sessions they have open, suspend the
7394system, inhibit system suspend, reboot the system, and other tasks.
7395
7396Elogind handles most system-level power events for a computer, for
7397example suspending the system when a lid is closed, or shutting it down
7398when the power button is pressed.
7399
7400The @var{config} keyword argument specifies the configuration for
7401elogind, and should be the result of a @code{(elogind-configuration
7402(@var{parameter} @var{value})...)} invocation. Available parameters and
7403their default values are:
7404
7405@table @code
7406@item kill-user-processes?
7407@code{#f}
7408@item kill-only-users
7409@code{()}
7410@item kill-exclude-users
7411@code{("root")}
7412@item inhibit-delay-max-seconds
7413@code{5}
7414@item handle-power-key
7415@code{poweroff}
7416@item handle-suspend-key
7417@code{suspend}
7418@item handle-hibernate-key
7419@code{hibernate}
7420@item handle-lid-switch
7421@code{suspend}
7422@item handle-lid-switch-docked
7423@code{ignore}
7424@item power-key-ignore-inhibited?
7425@code{#f}
7426@item suspend-key-ignore-inhibited?
7427@code{#f}
7428@item hibernate-key-ignore-inhibited?
7429@code{#f}
7430@item lid-switch-ignore-inhibited?
7431@code{#t}
7432@item holdoff-timeout-seconds
7433@code{30}
7434@item idle-action
7435@code{ignore}
7436@item idle-action-seconds
7437@code{(* 30 60)}
7438@item runtime-directory-size-percent
7439@code{10}
7440@item runtime-directory-size
7441@code{#f}
7442@item remove-ipc?
7443@code{#t}
7444@item suspend-state
7445@code{("mem" "standby" "freeze")}
7446@item suspend-mode
7447@code{()}
7448@item hibernate-state
7449@code{("disk")}
7450@item hibernate-mode
7451@code{("platform" "shutdown")}
7452@item hybrid-sleep-state
7453@code{("disk")}
7454@item hybrid-sleep-mode
7455@code{("suspend" "platform" "shutdown")}
7456@end table
7457@end deffn
7458
be1c2c54 7459@deffn {Scheme Procedure} polkit-service @
4650a77e 7460 [#:polkit @var{polkit}]
222e3319
LC
7461Return a service that runs the
7462@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7463management service}, which allows system administrators to grant access to
7464privileged operations in a structured way. By querying the Polkit service, a
7465privileged system component can know when it should grant additional
7466capabilities to ordinary users. For example, an ordinary user can be granted
7467the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7468@end deffn
7469
be1c2c54 7470@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7471 [#:watts-up-pro? #f] @
7472 [#:poll-batteries? #t] @
7473 [#:ignore-lid? #f] @
7474 [#:use-percentage-for-policy? #f] @
7475 [#:percentage-low 10] @
7476 [#:percentage-critical 3] @
7477 [#:percentage-action 2] @
7478 [#:time-low 1200] @
7479 [#:time-critical 300] @
7480 [#:time-action 120] @
7481 [#:critical-power-action 'hybrid-sleep]
7482Return a service that runs @uref{http://upower.freedesktop.org/,
7483@command{upowerd}}, a system-wide monitor for power consumption and battery
7484levels, with the given configuration settings. It implements the
7485@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7486GNOME.
7487@end deffn
7488
2b9e0a94
LC
7489@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7490Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7491UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7492notifications and ways to mount/unmount disks. Programs that talk to UDisks
7493include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7494@end deffn
7495
be1c2c54 7496@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7497Return a service that runs @command{colord}, a system service with a D-Bus
7498interface to manage the color profiles of input and output devices such as
7499screens and scanners. It is notably used by the GNOME Color Manager graphical
7500tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7501site} for more information.
7502@end deffn
7503
cee32ee4
AW
7504@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
7505Return an configuration allowing an application to access GeoClue
7506location data. @var{name} is the Desktop ID of the application, without
7507the @code{.desktop} part. If @var{allowed?} is true, the application
7508will have access to location information by default. The boolean
7509@var{system?} value indicates that an application is a system component
7510or not. Finally @var{users} is a list of UIDs of all users for which
7511this application is allowed location info access. An empty users list
7512means that all users are allowed.
7513@end deffn
7514
7515@defvr {Scheme Variable} %standard-geoclue-applications
7516The standard list of well-known GeoClue application configurations,
7517granting authority to GNOME's date-and-time utility to ask for the
7518current location in order to set the time zone, and allowing the Firefox
7519(IceCat) and Epiphany web browsers to request location information.
7520Firefox and Epiphany both query the user before allowing a web page to
7521know the user's location.
7522@end defvr
7523
be1c2c54 7524@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7525 [#:whitelist '()] @
7526 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7527 [#:submit-data? #f]
7528 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7529 [#:submission-nick "geoclue"] @
7530 [#:applications %standard-geoclue-applications]
7531Return a service that runs the GeoClue location service. This service
7532provides a D-Bus interface to allow applications to request access to a
7533user's physical location, and optionally to add information to online
7534location databases. See
7535@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7536web site} for more information.
7537@end deffn
7538
105369a4
DT
7539@node Database Services
7540@subsubsection Database Services
7541
7542The @code{(gnu services databases)} module provides the following service.
7543
be1c2c54 7544@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7545 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7546Return a service that runs @var{postgresql}, the PostgreSQL database
7547server.
7548
7549The PostgreSQL daemon loads its runtime configuration from
7550@var{config-file} and stores the database cluster in
7551@var{data-directory}.
7552@end deffn
fe1a39d3 7553
d8c18af8
AW
7554@node Mail Services
7555@subsubsection Mail Services
7556
7557The @code{(gnu services mail)} module provides Guix service definitions
7558for mail services. Currently the only implemented service is Dovecot,
7559an IMAP, POP3, and LMTP server.
7560
7561Guix does not yet have a mail transfer agent (MTA), although for some
7562lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7563is needed to properly integrate a full MTA, such as Postfix. Patches
7564welcome!
7565
7566To add an IMAP/POP3 server to a GuixSD system, add a
7567@code{dovecot-service} to the operating system definition:
7568
7569@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7570Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7571@end deffn
7572
7573By default, Dovecot doesn't need much configuration; the default
7574configuration object created by @code{(dovecot-configuration)} will
7575suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7576certificate will be generated for TLS-protected connections, though
7577Dovecot will also listen on cleartext ports by default. There are a
7578number of options though which mail administrators might need to change,
7579and as is the case with other services, Guix allows the system
7580administrator to specify these parameters via a uniform Scheme interface.
7581
7582For example, to specify that mail is located at @code{maildir~/.mail},
7583one would instantiate the Dovecot service like this:
7584
7585@example
7586(dovecot-service #:config
7587 (dovecot-configuration
7588 (mail-location "maildir:~/.mail")))
7589@end example
7590
7591The available configuration parameters follow. Each parameter
7592definition is preceded by its type; for example, @samp{string-list foo}
7593indicates that the @code{foo} parameter should be specified as a list of
7594strings. There is also a way to specify the configuration as a string,
7595if you have an old @code{dovecot.conf} file that you want to port over
7596from some other system; see the end for more details.
7597
7598@c The following documentation was initially generated by
7599@c (generate-documentation) in (gnu services mail). Manually maintained
7600@c documentation is better, so we shouldn't hesitate to edit below as
7601@c needed. However if the change you want to make to this documentation
7602@c can be done in an automated way, it's probably easier to change
7603@c (generate-documentation) than to make it below and have to deal with
7604@c the churn as dovecot updates.
7605
7606Available @code{dovecot-configuration} fields are:
7607
7608@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7609The dovecot package.
7610@end deftypevr
7611
7612@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
7613A list of IPs or hosts where to listen in for connections. @samp{*}
7614listens in all IPv4 interfaces, @samp{::} listens in all IPv6
7615interfaces. If you want to specify non-default ports or anything more
7616complex, customize the address and port fields of the
7617@samp{inet-listener} of the specific services you are interested in.
7618@end deftypevr
7619
7620@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7621List of protocols we want to serve. Available protocols include
7622@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7623
7624Available @code{protocol-configuration} fields are:
7625
7626@deftypevr {@code{protocol-configuration} parameter} string name
7627The name of the protocol.
7628@end deftypevr
7629
7630@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
7631UNIX socket path to master authentication server to find users.
7632This is used by imap (for shared users) and lda.
7633Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
7634@end deftypevr
7635
7636@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7637Space separated list of plugins to load.
7638@end deftypevr
7639
7640@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7641Maximum number of IMAP connections allowed for a user from each IP
7642address. NOTE: The username is compared case-sensitively.
7643Defaults to @samp{10}.
7644@end deftypevr
7645
7646@end deftypevr
7647
7648@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7649List of services to enable. Available services include @samp{imap},
7650@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7651@samp{lmtp}.
7652
7653Available @code{service-configuration} fields are:
7654
7655@deftypevr {@code{service-configuration} parameter} string kind
7656The service kind. Valid values include @code{director},
7657@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7658@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7659@code{tcpwrap}, @code{quota-warning}, or anything else.
7660@end deftypevr
7661
7662@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
7663Listeners for the service. A listener is either an
7664@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7665an @code{inet-listener-configuration}.
7666Defaults to @samp{()}.
7667
7668Available @code{unix-listener-configuration} fields are:
7669
7670@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7671The file name on which to listen.
7672@end deftypevr
7673
7674@deftypevr {@code{unix-listener-configuration} parameter} string mode
7675The access mode for the socket.
7676Defaults to @samp{"0600"}.
7677@end deftypevr
7678
7679@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 7680The user to own the socket.
d8c18af8
AW
7681Defaults to @samp{""}.
7682@end deftypevr
7683
7684@deftypevr {@code{unix-listener-configuration} parameter} string group
7685The group to own the socket.
7686Defaults to @samp{""}.
7687@end deftypevr
7688
7689
7690Available @code{fifo-listener-configuration} fields are:
7691
7692@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7693The file name on which to listen.
7694@end deftypevr
7695
7696@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7697The access mode for the socket.
7698Defaults to @samp{"0600"}.
7699@end deftypevr
7700
7701@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 7702The user to own the socket.
d8c18af8
AW
7703Defaults to @samp{""}.
7704@end deftypevr
7705
7706@deftypevr {@code{fifo-listener-configuration} parameter} string group
7707The group to own the socket.
7708Defaults to @samp{""}.
7709@end deftypevr
7710
7711
7712Available @code{inet-listener-configuration} fields are:
7713
7714@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7715The protocol to listen for.
7716@end deftypevr
7717
7718@deftypevr {@code{inet-listener-configuration} parameter} string address
7719The address on which to listen, or empty for all addresses.
7720Defaults to @samp{""}.
7721@end deftypevr
7722
7723@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7724The port on which to listen.
7725@end deftypevr
7726
7727@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7728Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7729@samp{required}.
7730Defaults to @samp{#t}.
7731@end deftypevr
7732
7733@end deftypevr
7734
7735@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7736Number of connections to handle before starting a new process.
7737Typically the only useful values are 0 (unlimited) or 1. 1 is more
7738secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7739Defaults to @samp{1}.
7740@end deftypevr
7741
7742@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7743Number of processes to always keep waiting for more connections.
7744Defaults to @samp{0}.
7745@end deftypevr
7746
7747@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7748If you set @samp{service-count 0}, you probably need to grow
7749this.
7750Defaults to @samp{256000000}.
7751@end deftypevr
7752
7753@end deftypevr
7754
7755@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7756Dict configuration, as created by the @code{dict-configuration}
7757constructor.
7758
7759Available @code{dict-configuration} fields are:
7760
7761@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7762A list of key-value pairs that this dict should hold.
7763Defaults to @samp{()}.
7764@end deftypevr
7765
7766@end deftypevr
7767
7768@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
7769List of passdb configurations, each one created by the
7770@code{passdb-configuration} constructor.
7771
7772Available @code{passdb-configuration} fields are:
7773
7774@deftypevr {@code{passdb-configuration} parameter} string driver
7775The driver that the passdb should use. Valid values include
7776@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7777@samp{static}.
7778Defaults to @samp{"pam"}.
7779@end deftypevr
7780
7781@deftypevr {@code{passdb-configuration} parameter} free-form-args args
7782A list of key-value args to the passdb driver.
7783Defaults to @samp{()}.
7784@end deftypevr
7785
7786@end deftypevr
7787
7788@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7789List of userdb configurations, each one created by the
7790@code{userdb-configuration} constructor.
7791
7792Available @code{userdb-configuration} fields are:
7793
7794@deftypevr {@code{userdb-configuration} parameter} string driver
7795The driver that the userdb should use. Valid values include
7796@samp{passwd} and @samp{static}.
7797Defaults to @samp{"passwd"}.
7798@end deftypevr
7799
7800@deftypevr {@code{userdb-configuration} parameter} free-form-args args
7801A list of key-value args to the userdb driver.
7802Defaults to @samp{()}.
7803@end deftypevr
7804
7805@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7806Override fields from passwd.
7807Defaults to @samp{()}.
7808@end deftypevr
7809
7810@end deftypevr
7811
7812@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7813Plug-in configuration, created by the @code{plugin-configuration}
7814constructor.
7815@end deftypevr
7816
7817@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7818List of namespaces. Each item in the list is created by the
7819@code{namespace-configuration} constructor.
7820
7821Available @code{namespace-configuration} fields are:
7822
7823@deftypevr {@code{namespace-configuration} parameter} string name
7824Name for this namespace.
7825@end deftypevr
7826
7827@deftypevr {@code{namespace-configuration} parameter} string type
7828Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7829Defaults to @samp{"private"}.
7830@end deftypevr
7831
7832@deftypevr {@code{namespace-configuration} parameter} string separator
7833Hierarchy separator to use. You should use the same separator for
7834all namespaces or some clients get confused. @samp{/} is usually a good
7835one. The default however depends on the underlying mail storage
7836format.
7837Defaults to @samp{""}.
7838@end deftypevr
7839
7840@deftypevr {@code{namespace-configuration} parameter} string prefix
7841Prefix required to access this namespace. This needs to be
7842different for all namespaces. For example @samp{Public/}.
7843Defaults to @samp{""}.
7844@end deftypevr
7845
7846@deftypevr {@code{namespace-configuration} parameter} string location
7847Physical location of the mailbox. This is in same format as
7848mail_location, which is also the default for it.
7849Defaults to @samp{""}.
7850@end deftypevr
7851
7852@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7853There can be only one INBOX, and this setting defines which
7854namespace has it.
7855Defaults to @samp{#f}.
7856@end deftypevr
7857
7858@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7859If namespace is hidden, it's not advertised to clients via NAMESPACE
7860extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7861useful when converting from another server with different namespaces
7862which you want to deprecate but still keep working. For example you can
7863create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7864and @samp{mail/}.
7865Defaults to @samp{#f}.
7866@end deftypevr
7867
7868@deftypevr {@code{namespace-configuration} parameter} boolean list?
7869Show the mailboxes under this namespace with LIST command. This
7870makes the namespace visible for clients that don't support NAMESPACE
7871extension. The special @code{children} value lists child mailboxes, but
7872hides the namespace prefix.
7873Defaults to @samp{#t}.
7874@end deftypevr
7875
7876@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7877Namespace handles its own subscriptions. If set to @code{#f}, the
7878parent namespace handles them. The empty prefix should always have this
7879as @code{#t}.)
7880Defaults to @samp{#t}.
7881@end deftypevr
7882
7883@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7884List of predefined mailboxes in this namespace.
7885Defaults to @samp{()}.
7886
7887Available @code{mailbox-configuration} fields are:
7888
7889@deftypevr {@code{mailbox-configuration} parameter} string name
7890Name for this mailbox.
7891@end deftypevr
7892
7893@deftypevr {@code{mailbox-configuration} parameter} string auto
7894@samp{create} will automatically create this mailbox.
7895@samp{subscribe} will both create and subscribe to the mailbox.
7896Defaults to @samp{"no"}.
7897@end deftypevr
7898
7899@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7900List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7901Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7902@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7903Defaults to @samp{()}.
7904@end deftypevr
7905
7906@end deftypevr
7907
7908@end deftypevr
7909
7910@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7911Base directory where to store runtime data.
7912Defaults to @samp{"/var/run/dovecot/"}.
7913@end deftypevr
7914
7915@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7916Greeting message for clients.
7917Defaults to @samp{"Dovecot ready."}.
7918@end deftypevr
7919
7920@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7921List of trusted network ranges. Connections from these IPs are
7922allowed to override their IP addresses and ports (for logging and for
7923authentication checks). @samp{disable-plaintext-auth} is also ignored
7924for these networks. Typically you'd specify your IMAP proxy servers
7925here.
7926Defaults to @samp{()}.
7927@end deftypevr
7928
7929@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7930List of login access check sockets (e.g. tcpwrap).
7931Defaults to @samp{()}.
7932@end deftypevr
7933
7934@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7935Show more verbose process titles (in ps). Currently shows user name
7936and IP address. Useful for seeing who are actually using the IMAP
7937processes (e.g. shared mailboxes or if same uid is used for multiple
7938accounts).
7939Defaults to @samp{#f}.
7940@end deftypevr
7941
7942@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
7943Should all processes be killed when Dovecot master process shuts down.
7944Setting this to @code{#f} means that Dovecot can be upgraded without
7945forcing existing client connections to close (although that could also
7946be a problem if the upgrade is e.g. because of a security fix).
7947Defaults to @samp{#t}.
7948@end deftypevr
7949
7950@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
7951If non-zero, run mail commands via this many connections to doveadm
7952server, instead of running them directly in the same process.
7953Defaults to @samp{0}.
7954@end deftypevr
7955
7956@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
7957UNIX socket or host:port used for connecting to doveadm server.
7958Defaults to @samp{"doveadm-server"}.
7959@end deftypevr
7960
7961@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
7962List of environment variables that are preserved on Dovecot startup
7963and passed down to all of its child processes. You can also give
7964key=value pairs to always set specific settings.
7965@end deftypevr
7966
7967@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
7968Disable LOGIN command and all other plaintext authentications unless
7969SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
7970matches the local IP (i.e. you're connecting from the same computer),
7971the connection is considered secure and plaintext authentication is
7972allowed. See also ssl=required setting.
7973Defaults to @samp{#t}.
7974@end deftypevr
7975
7976@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
7977Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
7978Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
7979for caching to be used.
7980Defaults to @samp{0}.
7981@end deftypevr
7982
7983@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
7984Time to live for cached data. After TTL expires the cached record
7985is no longer used, *except* if the main database lookup returns internal
7986failure. We also try to handle password changes automatically: If
7987user's previous authentication was successful, but this one wasn't, the
7988cache isn't used. For now this works only with plaintext
7989authentication.
7990Defaults to @samp{"1 hour"}.
7991@end deftypevr
7992
7993@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
7994TTL for negative hits (user not found, password mismatch).
79950 disables caching them completely.
7996Defaults to @samp{"1 hour"}.
7997@end deftypevr
7998
7999@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
8000List of realms for SASL authentication mechanisms that need them.
8001You can leave it empty if you don't want to support multiple realms.
8002Many clients simply use the first one listed here, so keep the default
8003realm first.
8004Defaults to @samp{()}.
8005@end deftypevr
8006
8007@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
8008Default realm/domain to use if none was specified. This is used for
8009both SASL realms and appending @@domain to username in plaintext
8010logins.
8011Defaults to @samp{""}.
8012@end deftypevr
8013
8014@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
8015List of allowed characters in username. If the user-given username
8016contains a character not listed in here, the login automatically fails.
8017This is just an extra check to make sure user can't exploit any
8018potential quote escaping vulnerabilities with SQL/LDAP databases. If
8019you want to allow all characters, set this value to empty.
8020Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8021@end deftypevr
8022
8023@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8024Username character translations before it's looked up from
8025databases. The value contains series of from -> to characters. For
8026example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8027translated to @samp{@@}.
8028Defaults to @samp{""}.
8029@end deftypevr
8030
8031@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8032Username formatting before it's looked up from databases. You can
8033use the standard variables here, e.g. %Lu would lowercase the username,
8034%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8035change the @samp{@@} into @samp{-AT-}. This translation is done after
8036@samp{auth-username-translation} changes.
8037Defaults to @samp{"%Lu"}.
8038@end deftypevr
8039
8040@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8041If you want to allow master users to log in by specifying the master
8042username within the normal username string (i.e. not using SASL
8043mechanism's support for it), you can specify the separator character
8044here. The format is then <username><separator><master username>.
8045UW-IMAP uses @samp{*} as the separator, so that could be a good
8046choice.
8047Defaults to @samp{""}.
8048@end deftypevr
8049
8050@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8051Username to use for users logging in with ANONYMOUS SASL
8052mechanism.
8053Defaults to @samp{"anonymous"}.
8054@end deftypevr
8055
8056@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8057Maximum number of dovecot-auth worker processes. They're used to
8058execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8059They're automatically created and destroyed as needed.
8060Defaults to @samp{30}.
8061@end deftypevr
8062
8063@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8064Host name to use in GSSAPI principal names. The default is to use
8065the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8066allow all keytab entries.
8067Defaults to @samp{""}.
8068@end deftypevr
8069
8070@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8071Kerberos keytab to use for the GSSAPI mechanism. Will use the
8072system default (usually /etc/krb5.keytab) if not specified. You may
8073need to change the auth service to run as root to be able to read this
8074file.
8075Defaults to @samp{""}.
8076@end deftypevr
8077
8078@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8079Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8080and @samp{ntlm-auth} helper.
8081<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8082Defaults to @samp{#f}.
8083@end deftypevr
8084
8085@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8086Path for Samba's @samp{ntlm-auth} helper binary.
8087Defaults to @samp{"/usr/bin/ntlm_auth"}.
8088@end deftypevr
8089
8090@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8091Time to delay before replying to failed authentications.
8092Defaults to @samp{"2 secs"}.
8093@end deftypevr
8094
8095@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8096Require a valid SSL client certificate or the authentication
8097fails.
8098Defaults to @samp{#f}.
8099@end deftypevr
8100
8101@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8102Take the username from client's SSL certificate, using
8103@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8104CommonName.
8105Defaults to @samp{#f}.
8106@end deftypevr
8107
8108@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8109List of wanted authentication mechanisms. Supported mechanisms are:
8110@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8111@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8112@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8113@samp{disable-plaintext-auth} setting.
8114@end deftypevr
8115
8116@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8117List of IPs or hostnames to all director servers, including ourself.
8118Ports can be specified as ip:port. The default port is the same as what
8119director service's @samp{inet-listener} is using.
8120Defaults to @samp{()}.
8121@end deftypevr
8122
8123@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8124List of IPs or hostnames to all backend mail servers. Ranges are
8125allowed too, like 10.0.0.10-10.0.0.30.
8126Defaults to @samp{()}.
8127@end deftypevr
8128
8129@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8130How long to redirect users to a specific server after it no longer
8131has any connections.
8132Defaults to @samp{"15 min"}.
8133@end deftypevr
8134
8135@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8136TCP/IP port that accepts doveadm connections (instead of director
8137connections) If you enable this, you'll also need to add
8138@samp{inet-listener} for the port.
8139Defaults to @samp{0}.
8140@end deftypevr
8141
8142@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8143How the username is translated before being hashed. Useful values
8144include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8145are shared within domain.
8146Defaults to @samp{"%Lu"}.
8147@end deftypevr
8148
8149@deftypevr {@code{dovecot-configuration} parameter} string log-path
8150Log file to use for error messages. @samp{syslog} logs to syslog,
8151@samp{/dev/stderr} logs to stderr.
8152Defaults to @samp{"syslog"}.
8153@end deftypevr
8154
8155@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8156Log file to use for informational messages. Defaults to
8157@samp{log-path}.
8158Defaults to @samp{""}.
8159@end deftypevr
8160
8161@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8162Log file to use for debug messages. Defaults to
8163@samp{info-log-path}.
8164Defaults to @samp{""}.
8165@end deftypevr
8166
8167@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8168Syslog facility to use if you're logging to syslog. Usually if you
8169don't want to use @samp{mail}, you'll use local0..local7. Also other
8170standard facilities are supported.
8171Defaults to @samp{"mail"}.
8172@end deftypevr
8173
8174@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8175Log unsuccessful authentication attempts and the reasons why they
8176failed.
8177Defaults to @samp{#f}.
8178@end deftypevr
8179
8180@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8181In case of password mismatches, log the attempted password. Valid
8182values are no, plain and sha1. sha1 can be useful for detecting brute
8183force password attempts vs. user simply trying the same password over
8184and over again. You can also truncate the value to n chars by appending
8185":n" (e.g. sha1:6).
8186Defaults to @samp{#f}.
8187@end deftypevr
8188
8189@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8190Even more verbose logging for debugging purposes. Shows for example
8191SQL queries.
8192Defaults to @samp{#f}.
8193@end deftypevr
8194
8195@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
8196In case of password mismatches, log the passwords and used scheme so
8197the problem can be debugged. Enabling this also enables
8198@samp{auth-debug}.
8199Defaults to @samp{#f}.
8200@end deftypevr
8201
8202@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
8203Enable mail process debugging. This can help you figure out why
8204Dovecot isn't finding your mails.
8205Defaults to @samp{#f}.
8206@end deftypevr
8207
8208@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
8209Show protocol level SSL errors.
8210Defaults to @samp{#f}.
8211@end deftypevr
8212
8213@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
8214Prefix for each line written to log file. % codes are in
8215strftime(3) format.
8216Defaults to @samp{"\"%b %d %H:%M:%S \""}.
8217@end deftypevr
8218
8219@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
8220List of elements we want to log. The elements which have a
8221non-empty variable value are joined together to form a comma-separated
8222string.
8223@end deftypevr
8224
8225@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
8226Login log format. %s contains @samp{login-log-format-elements}
8227string, %$ contains the data we want to log.
8228Defaults to @samp{"%$: %s"}.
8229@end deftypevr
8230
8231@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
8232Log prefix for mail processes. See doc/wiki/Variables.txt for list
8233of possible variables you can use.
8234Defaults to @samp{"\"%s(%u): \""}.
8235@end deftypevr
8236
8237@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
8238Format to use for logging mail deliveries. You can use variables:
8239@table @code
8240@item %$
8241Delivery status message (e.g. @samp{saved to INBOX})
8242@item %m
8243Message-ID
8244@item %s
8245Subject
8246@item %f
8247From address
8248@item %p
8249Physical size
8250@item %w
8251Virtual size.
8252@end table
8253Defaults to @samp{"msgid=%m: %$"}.
8254@end deftypevr
8255
8256@deftypevr {@code{dovecot-configuration} parameter} string mail-location
8257Location for users' mailboxes. The default is empty, which means
8258that Dovecot tries to find the mailboxes automatically. This won't work
8259if the user doesn't yet have any mail, so you should explicitly tell
8260Dovecot the full location.
8261
8262If you're using mbox, giving a path to the INBOX
8263file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
8264where the other mailboxes are kept. This is called the "root mail
8265directory", and it must be the first path given in the
8266@samp{mail-location} setting.
8267
8268There are a few special variables you can use, eg.:
8269
8270@table @samp
8271@item %u
8272username
8273@item %n
8274user part in user@@domain, same as %u if there's no domain
8275@item %d
8276domain part in user@@domain, empty if there's no domain
8277@item %h
8278home director
8279@end table
8280
8281See doc/wiki/Variables.txt for full list. Some examples:
8282@table @samp
8283@item maildir:~/Maildir
8284@item mbox:~/mail:INBOX=/var/mail/%u
8285@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
8286@end table
8287Defaults to @samp{""}.
8288@end deftypevr
8289
8290@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8291System user and group used to access mails. If you use multiple,
8292userdb can override these by returning uid or gid fields. You can use
8293either numbers or names. <doc/wiki/UserIds.txt>.
8294Defaults to @samp{""}.
8295@end deftypevr
8296
8297@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8298
8299Defaults to @samp{""}.
8300@end deftypevr
8301
8302@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8303Group to enable temporarily for privileged operations. Currently
8304this is used only with INBOX when either its initial creation or
8305dotlocking fails. Typically this is set to "mail" to give access to
8306/var/mail.
8307Defaults to @samp{""}.
8308@end deftypevr
8309
8310@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8311Grant access to these supplementary groups for mail processes.
8312Typically these are used to set up access to shared mailboxes. Note
8313that it may be dangerous to set these if users can create
8314symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8315could allow a user to delete others' mailboxes, or ln -s
8316/secret/shared/box ~/mail/mybox would allow reading it).
8317Defaults to @samp{""}.
8318@end deftypevr
8319
8320@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8321Allow full filesystem access to clients. There's no access checks
8322other than what the operating system does for the active UID/GID. It
8323works with both maildir and mboxes, allowing you to prefix mailboxes
8324names with e.g. /path/ or ~user/.
8325Defaults to @samp{#f}.
8326@end deftypevr
8327
8328@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8329Don't use mmap() at all. This is required if you store indexes to
8330shared filesystems (NFS or clustered filesystem).
8331Defaults to @samp{#f}.
8332@end deftypevr
8333
8334@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8335Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8336supports @samp{O_EXCL} since version 3, so this should be safe to use
8337nowadays by default.
8338Defaults to @samp{#t}.
8339@end deftypevr
8340
8341@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8342When to use fsync() or fdatasync() calls:
8343@table @code
8344@item optimized
8345Whenever necessary to avoid losing important data
8346@item always
8347Useful with e.g. NFS when write()s are delayed
8348@item never
8349Never use it (best performance, but crashes can lose data).
8350@end table
8351Defaults to @samp{"optimized"}.
8352@end deftypevr
8353
8354@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8355Mail storage exists in NFS. Set this to yes to make Dovecot flush
8356NFS caches whenever needed. If you're using only a single mail server
8357this isn't needed.
8358Defaults to @samp{#f}.
8359@end deftypevr
8360
8361@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8362Mail index files also exist in NFS. Setting this to yes requires
8363@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8364Defaults to @samp{#f}.
8365@end deftypevr
8366
8367@deftypevr {@code{dovecot-configuration} parameter} string lock-method
8368Locking method for index files. Alternatives are fcntl, flock and
8369dotlock. Dotlocking uses some tricks which may create more disk I/O
8370than other locking methods. NFS users: flock doesn't work, remember to
8371change @samp{mmap-disable}.
8372Defaults to @samp{"fcntl"}.
8373@end deftypevr
8374
8375@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8376Directory in which LDA/LMTP temporarily stores incoming mails >128
8377kB.
8378Defaults to @samp{"/tmp"}.
8379@end deftypevr
8380
8381@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8382Valid UID range for users. This is mostly to make sure that users can't
8383log in as daemons or other system users. Note that denying root logins is
8384hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8385is set to 0.
8386Defaults to @samp{500}.
8387@end deftypevr
8388
8389@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8390
8391Defaults to @samp{0}.
8392@end deftypevr
8393
8394@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8395Valid GID range for users. Users having non-valid GID as primary group ID
8396aren't allowed to log in. If user belongs to supplementary groups with
8397non-valid GIDs, those groups are not set.
8398Defaults to @samp{1}.
8399@end deftypevr
8400
8401@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8402
8403Defaults to @samp{0}.
8404@end deftypevr
8405
8406@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8407Maximum allowed length for mail keyword name. It's only forced when
8408trying to create new keywords.
8409Defaults to @samp{50}.
8410@end deftypevr
8411
8412@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8413List of directories under which chrooting is allowed for mail
8414processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8415too). This setting doesn't affect @samp{login-chroot}
8416@samp{mail-chroot} or auth chroot settings. If this setting is empty,
8417"/./" in home dirs are ignored. WARNING: Never add directories here
8418which local users can modify, that may lead to root exploit. Usually
8419this should be done only if you don't allow shell access for users.
8420<doc/wiki/Chrooting.txt>.
8421Defaults to @samp{()}.
8422@end deftypevr
8423
8424@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8425Default chroot directory for mail processes. This can be overridden
8426for specific users in user database by giving /./ in user's home
8427directory (e.g. /home/./user chroots into /home). Note that usually
8428there is no real need to do chrooting, Dovecot doesn't allow users to
8429access files outside their mail directory anyway. If your home
8430directories are prefixed with the chroot directory, append "/." to
8431@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8432Defaults to @samp{""}.
8433@end deftypevr
8434
8435@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8436UNIX socket path to master authentication server to find users.
8437This is used by imap (for shared users) and lda.
8438Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8439@end deftypevr
8440
8441@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8442Directory where to look up mail plugins.
8443Defaults to @samp{"/usr/lib/dovecot"}.
8444@end deftypevr
8445
8446@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8447List of plugins to load for all services. Plugins specific to IMAP,
8448LDA, etc. are added to this list in their own .conf files.
8449Defaults to @samp{()}.
8450@end deftypevr
8451
8452@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8453The minimum number of mails in a mailbox before updates are done to
8454cache file. This allows optimizing Dovecot's behavior to do less disk
8455writes at the cost of more disk reads.
8456Defaults to @samp{0}.
8457@end deftypevr
8458
8459@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8460When IDLE command is running, mailbox is checked once in a while to
8461see if there are any new mails or other changes. This setting defines
8462the minimum time to wait between those checks. Dovecot can also use
8463dnotify, inotify and kqueue to find out immediately when changes
8464occur.
8465Defaults to @samp{"30 secs"}.
8466@end deftypevr
8467
8468@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8469Save mails with CR+LF instead of plain LF. This makes sending those
8470mails take less CPU, especially with sendfile() syscall with Linux and
8471FreeBSD. But it also creates a bit more disk I/O which may just make it
8472slower. Also note that if other software reads the mboxes/maildirs,
8473they may handle the extra CRs wrong and cause problems.
8474Defaults to @samp{#f}.
8475@end deftypevr
8476
8477@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8478By default LIST command returns all entries in maildir beginning
8479with a dot. Enabling this option makes Dovecot return only entries
8480which are directories. This is done by stat()ing each entry, so it
8481causes more disk I/O.
8482 (For systems setting struct @samp{dirent->d_type} this check is free
8483and it's done always regardless of this setting).
8484Defaults to @samp{#f}.
8485@end deftypevr
8486
8487@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8488When copying a message, do it with hard links whenever possible.
8489This makes the performance much better, and it's unlikely to have any
8490side effects.
8491Defaults to @samp{#t}.
8492@end deftypevr
8493
8494@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8495Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8496directory only when its mtime changes unexpectedly or when we can't find
8497the mail otherwise.
8498Defaults to @samp{#f}.
8499@end deftypevr
8500
8501@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8502Which locking methods to use for locking mbox. There are four
8503available:
8504
8505@table @code
8506@item dotlock
8507Create <mailbox>.lock file. This is the oldest and most NFS-safe
8508solution. If you want to use /var/mail/ like directory, the users will
8509need write access to that directory.
8510@item dotlock-try
8511Same as dotlock, but if it fails because of permissions or because there
8512isn't enough disk space, just skip it.
8513@item fcntl
8514Use this if possible. Works with NFS too if lockd is used.
8515@item flock
8516May not exist in all systems. Doesn't work with NFS.
8517@item lockf
8518May not exist in all systems. Doesn't work with NFS.
8519@end table
8520
8521You can use multiple locking methods; if you do the order they're declared
8522in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8523locking methods as well. Some operating systems don't allow using some of
8524them simultaneously.
8525@end deftypevr
8526
8527@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8528
8529@end deftypevr
8530
8531@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8532Maximum time to wait for lock (all of them) before aborting.
8533Defaults to @samp{"5 mins"}.
8534@end deftypevr
8535
8536@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8537If dotlock exists but the mailbox isn't modified in any way,
8538override the lock file after this much time.
8539Defaults to @samp{"2 mins"}.
8540@end deftypevr
8541
8542@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8543When mbox changes unexpectedly we have to fully read it to find out
8544what changed. If the mbox is large this can take a long time. Since
8545the change is usually just a newly appended mail, it'd be faster to
8546simply read the new mails. If this setting is enabled, Dovecot does
8547this but still safely fallbacks to re-reading the whole mbox file
8548whenever something in mbox isn't how it's expected to be. The only real
8549downside to this setting is that if some other MUA changes message
8550flags, Dovecot doesn't notice it immediately. Note that a full sync is
8551done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8552Defaults to @samp{#t}.
8553@end deftypevr
8554
8555@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8556Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8557EXAMINE, EXPUNGE or CHECK commands. If this is set,
8558@samp{mbox-dirty-syncs} is ignored.
8559Defaults to @samp{#f}.
8560@end deftypevr
8561
8562@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8563Delay writing mbox headers until doing a full write sync (EXPUNGE
8564and CHECK commands and when closing the mailbox). This is especially
8565useful for POP3 where clients often delete all mails. The downside is
8566that our changes aren't immediately visible to other MUAs.
8567Defaults to @samp{#t}.
8568@end deftypevr
8569
8570@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8571If mbox size is smaller than this (e.g. 100k), don't write index
8572files. If an index file already exists it's still read, just not
8573updated.
8574Defaults to @samp{0}.
8575@end deftypevr
8576
8577@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8578Maximum dbox file size until it's rotated.
8579Defaults to @samp{2000000}.
8580@end deftypevr
8581
8582@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8583Maximum dbox file age until it's rotated. Typically in days. Day
8584begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8585disabled.
8586Defaults to @samp{"1d"}.
8587@end deftypevr
8588
8589@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8590When creating new mdbox files, immediately preallocate their size to
8591@samp{mdbox-rotate-size}. This setting currently works only in Linux
8592with some filesystems (ext4, xfs).
8593Defaults to @samp{#f}.
8594@end deftypevr
8595
8596@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8597sdbox and mdbox support saving mail attachments to external files,
8598which also allows single instance storage for them. Other backends
8599don't support this for now.
8600
8601WARNING: This feature hasn't been tested much yet. Use at your own risk.
8602
8603Directory root where to store mail attachments. Disabled, if empty.
8604Defaults to @samp{""}.
8605@end deftypevr
8606
8607@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8608Attachments smaller than this aren't saved externally. It's also
8609possible to write a plugin to disable saving specific attachments
8610externally.
8611Defaults to @samp{128000}.
8612@end deftypevr
8613
8614@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8615Filesystem backend to use for saving attachments:
8616@table @code
8617@item posix
8618No SiS done by Dovecot (but this might help FS's own deduplication)
8619@item sis posix
8620SiS with immediate byte-by-byte comparison during saving
8621@item sis-queue posix
8622SiS with delayed comparison and deduplication.
8623@end table
8624Defaults to @samp{"sis posix"}.
8625@end deftypevr
8626
8627@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8628Hash format to use in attachment filenames. You can add any text and
8629variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8630@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8631truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8632Defaults to @samp{"%@{sha1@}"}.
8633@end deftypevr
8634
8635@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8636
8637Defaults to @samp{100}.
8638@end deftypevr
8639
8640@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8641
8642Defaults to @samp{1000}.
8643@end deftypevr
8644
8645@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8646Default VSZ (virtual memory size) limit for service processes.
8647This is mainly intended to catch and kill processes that leak memory
8648before they eat up everything.
8649Defaults to @samp{256000000}.
8650@end deftypevr
8651
8652@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8653Login user is internally used by login processes. This is the most
8654untrusted user in Dovecot system. It shouldn't have access to anything
8655at all.
8656Defaults to @samp{"dovenull"}.
8657@end deftypevr
8658
8659@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8660Internal user is used by unprivileged processes. It should be
8661separate from login user, so that login processes can't disturb other
8662processes.
8663Defaults to @samp{"dovecot"}.
8664@end deftypevr
8665
8666@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8667SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8668Defaults to @samp{"required"}.
8669@end deftypevr
8670
8671@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8672PEM encoded X.509 SSL/TLS certificate (public key).
8673Defaults to @samp{"</etc/dovecot/default.pem"}.
8674@end deftypevr
8675
8676@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8677PEM encoded SSL/TLS private key. The key is opened before
8678dropping root privileges, so keep the key file unreadable by anyone but
8679root.
8680Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8681@end deftypevr
8682
8683@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8684If key file is password protected, give the password here.
8685Alternatively give it when starting dovecot with -p parameter. Since
8686this file is often world-readable, you may want to place this setting
8687instead to a different.
8688Defaults to @samp{""}.
8689@end deftypevr
8690
8691@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8692PEM encoded trusted certificate authority. Set this only if you
8693intend to use @samp{ssl-verify-client-cert? #t}. The file should
8694contain the CA certificate(s) followed by the matching
8695CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8696Defaults to @samp{""}.
8697@end deftypevr
8698
8699@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8700Require that CRL check succeeds for client certificates.
8701Defaults to @samp{#t}.
8702@end deftypevr
8703
8704@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8705Request client to send a certificate. If you also want to require
8706it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8707Defaults to @samp{#f}.
8708@end deftypevr
8709
8710@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8711Which field from certificate to use for username. commonName and
8712x500UniqueIdentifier are the usual choices. You'll also need to set
8713@samp{auth-ssl-username-from-cert? #t}.
8714Defaults to @samp{"commonName"}.
8715@end deftypevr
8716
8717@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8718How often to regenerate the SSL parameters file. Generation is
8719quite CPU intensive operation. The value is in hours, 0 disables
8720regeneration entirely.
8721Defaults to @samp{168}.
8722@end deftypevr
8723
8724@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8725SSL protocols to use.
8726Defaults to @samp{"!SSLv2"}.
8727@end deftypevr
8728
8729@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8730SSL ciphers to use.
8731Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8732@end deftypevr
8733
8734@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8735SSL crypto device to use, for valid values run "openssl engine".
8736Defaults to @samp{""}.
8737@end deftypevr
8738
8739@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8740Address to use when sending rejection mails.
8741Default is postmaster@@<your domain>. %d expands to recipient domain.
8742Defaults to @samp{""}.
8743@end deftypevr
8744
8745@deftypevr {@code{dovecot-configuration} parameter} string hostname
8746Hostname to use in various parts of sent mails (e.g. in Message-Id)
8747and in LMTP replies. Default is the system's real hostname@@domain.
8748Defaults to @samp{""}.
8749@end deftypevr
8750
8751@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8752If user is over quota, return with temporary failure instead of
8753bouncing the mail.
8754Defaults to @samp{#f}.
8755@end deftypevr
8756
8757@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8758Binary to use for sending mails.
8759Defaults to @samp{"/usr/sbin/sendmail"}.
8760@end deftypevr
8761
8762@deftypevr {@code{dovecot-configuration} parameter} string submission-host
8763If non-empty, send mails via this SMTP host[:port] instead of
8764sendmail.
8765Defaults to @samp{""}.
8766@end deftypevr
8767
8768@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8769Subject: header to use for rejection mails. You can use the same
8770variables as for @samp{rejection-reason} below.
8771Defaults to @samp{"Rejected: %s"}.
8772@end deftypevr
8773
8774@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8775Human readable error message for rejection mails. You can use
8776variables:
8777
8778@table @code
8779@item %n
8780CRLF
8781@item %r
8782reason
8783@item %s
8784original subject
8785@item %t
8786recipient
8787@end table
8788Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8789@end deftypevr
8790
8791@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8792Delimiter character between local-part and detail in email
8793address.
8794Defaults to @samp{"+"}.
8795@end deftypevr
8796
8797@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8798Header where the original recipient address (SMTP's RCPT TO:
8799address) is taken from if not available elsewhere. With dovecot-lda -a
8800parameter overrides this. A commonly used header for this is
8801X-Original-To.
8802Defaults to @samp{""}.
8803@end deftypevr
8804
8805@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8806Should saving a mail to a nonexistent mailbox automatically create
8807it?.
8808Defaults to @samp{#f}.
8809@end deftypevr
8810
8811@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8812Should automatically created mailboxes be also automatically
8813subscribed?.
8814Defaults to @samp{#f}.
8815@end deftypevr
8816
8817@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8818Maximum IMAP command line length. Some clients generate very long
8819command lines with huge mailboxes, so you may need to raise this if you
8820get "Too long argument" or "IMAP command line too large" errors
8821often.
8822Defaults to @samp{64000}.
8823@end deftypevr
8824
8825@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8826IMAP logout format string:
8827@table @code
8828@item %i
8829total number of bytes read from client
8830@item %o
8831total number of bytes sent to client.
8832@end table
8833Defaults to @samp{"in=%i out=%o"}.
8834@end deftypevr
8835
8836@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8837Override the IMAP CAPABILITY response. If the value begins with '+',
8838add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8839Defaults to @samp{""}.
8840@end deftypevr
8841
8842@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8843How long to wait between "OK Still here" notifications when client
8844is IDLEing.
8845Defaults to @samp{"2 mins"}.
8846@end deftypevr
8847
8848@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8849ID field names and values to send to clients. Using * as the value
8850makes Dovecot use the default value. The following fields have default
8851values currently: name, version, os, os-version, support-url,
8852support-email.
8853Defaults to @samp{""}.
8854@end deftypevr
8855
8856@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8857ID fields sent by client to log. * means everything.
8858Defaults to @samp{""}.
8859@end deftypevr
8860
8861@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8862Workarounds for various client bugs:
8863
8864@table @code
8865@item delay-newmail
8866Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8867CHECK commands. Some clients ignore them otherwise, for example OSX
8868Mail (<v2.1). Outlook Express breaks more badly though, without this it
8869may show user "Message no longer in server" errors. Note that OE6
8870still breaks even with this workaround if synchronization is set to
8871"Headers Only".
8872
8873@item tb-extra-mailbox-sep
8874Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8875adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8876ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8877
8878@item tb-lsub-flags
8879Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8880This makes Thunderbird realize they aren't selectable and show them
8881greyed out, instead of only later giving "not selectable" popup error.
8882@end table
8883Defaults to @samp{()}.
8884@end deftypevr
8885
8886@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8887Host allowed in URLAUTH URLs sent by client. "*" allows all.
8888Defaults to @samp{""}.
8889@end deftypevr
8890
8891
8892Whew! Lots of configuration options. The nice thing about it though is
8893that GuixSD has a complete interface to Dovecot's configuration
8894language. This allows not only a nice way to declare configurations,
8895but also offers reflective capabilities as well: users can write code to
8896inspect and transform configurations from within Scheme.
8897
8898However, it could be that you just want to get a @code{dovecot.conf} up
8899and running. In that case, you can pass an
8900@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8901@code{dovecot-service}. As its name indicates, an opaque configuration
8902does not have easy reflective capabilities.
8903
8904Available @code{opaque-dovecot-configuration} fields are:
8905
8906@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8907The dovecot package.
8908@end deftypevr
8909
8910@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8911The contents of the @code{dovecot.conf}, as a string.
8912@end deftypevr
8913
8914For example, if your @code{dovecot.conf} is just the empty string, you
8915could instantiate a dovecot service like this:
8916
8917@example
8918(dovecot-service #:config
8919 (opaque-dovecot-configuration
8920 (string "")))
8921@end example
8922
58724c48
DT
8923@node Web Services
8924@subsubsection Web Services
8925
8926The @code{(gnu services web)} module provides the following service:
8927
be1c2c54 8928@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
8929 [#:log-directory ``/var/log/nginx''] @
8930 [#:run-directory ``/var/run/nginx''] @
8931 [#:config-file]
8932
8933Return a service that runs @var{nginx}, the nginx web server.
8934
8935The nginx daemon loads its runtime configuration from @var{config-file}.
8936Log files are written to @var{log-directory} and temporary runtime data
8937files are written to @var{run-directory}. For proper operation, these
8938arguments should match what is in @var{config-file} to ensure that the
8939directories are created when the service is activated.
8940
8941@end deffn
8942
fe1a39d3
LC
8943@node Various Services
8944@subsubsection Various Services
8945
8946The @code{(gnu services lirc)} module provides the following service.
8947
be1c2c54 8948@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
8949 [#:device #f] [#:driver #f] [#:config-file #f] @
8950 [#:extra-options '()]
8951Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
8952decodes infrared signals from remote controls.
8953
8954Optionally, @var{device}, @var{driver} and @var{config-file}
8955(configuration file name) may be specified. See @command{lircd} manual
8956for details.
8957
8958Finally, @var{extra-options} is a list of additional command-line options
8959passed to @command{lircd}.
8960@end deffn
8961
8962
0ae8c15a
LC
8963@node Setuid Programs
8964@subsection Setuid Programs
8965
8966@cindex setuid programs
8967Some programs need to run with ``root'' privileges, even when they are
8968launched by unprivileged users. A notorious example is the
4d40227c
LC
8969@command{passwd} program, which users can run to change their
8970password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
8971@file{/etc/shadow} files---something normally restricted to root, for
8972obvious security reasons. To address that, these executables are
8973@dfn{setuid-root}, meaning that they always run with root privileges
8974(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 8975for more info about the setuid mechanism.)
0ae8c15a
LC
8976
8977The store itself @emph{cannot} contain setuid programs: that would be a
8978security issue since any user on the system can write derivations that
8979populate the store (@pxref{The Store}). Thus, a different mechanism is
8980used: instead of changing the setuid bit directly on files that are in
8981the store, we let the system administrator @emph{declare} which programs
8982should be setuid root.
8983
8984The @code{setuid-programs} field of an @code{operating-system}
8985declaration contains a list of G-expressions denoting the names of
8986programs to be setuid-root (@pxref{Using the Configuration System}).
8987For instance, the @command{passwd} program, which is part of the Shadow
8988package, can be designated by this G-expression (@pxref{G-Expressions}):
8989
8990@example
8991#~(string-append #$shadow "/bin/passwd")
8992@end example
8993
8994A default set of setuid programs is defined by the
8995@code{%setuid-programs} variable of the @code{(gnu system)} module.
8996
8997@defvr {Scheme Variable} %setuid-programs
8998A list of G-expressions denoting common programs that are setuid-root.
8999
9000The list includes commands such as @command{passwd}, @command{ping},
9001@command{su}, and @command{sudo}.
9002@end defvr
9003
9004Under the hood, the actual setuid programs are created in the
9005@file{/run/setuid-programs} directory at system activation time. The
9006files in this directory refer to the ``real'' binaries, which are in the
9007store.
9008
efb5e833
LC
9009@node X.509 Certificates
9010@subsection X.509 Certificates
9011
9012@cindex HTTPS, certificates
9013@cindex X.509 certificates
9014@cindex TLS
9015Web servers available over HTTPS (that is, HTTP over the transport-layer
9016security mechanism, TLS) send client programs an @dfn{X.509 certificate}
9017that the client can then use to @emph{authenticate} the server. To do
9018that, clients verify that the server's certificate is signed by a
9019so-called @dfn{certificate authority} (CA). But to verify the CA's
9020signature, clients must have first acquired the CA's certificate.
9021
9022Web browsers such as GNU@tie{}IceCat include their own set of CA
9023certificates, such that they are able to verify CA signatures
9024out-of-the-box.
9025
9026However, most other programs that can talk HTTPS---@command{wget},
9027@command{git}, @command{w3m}, etc.---need to be told where CA
9028certificates can be found.
9029
9030@cindex @code{nss-certs}
9031In GuixSD, this is done by adding a package that provides certificates
9032to the @code{packages} field of the @code{operating-system} declaration
9033(@pxref{operating-system Reference}). GuixSD includes one such package,
9034@code{nss-certs}, which is a set of CA certificates provided as part of
9035Mozilla's Network Security Services.
9036
9037Note that it is @emph{not} part of @var{%base-packages}, so you need to
9038explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9039most applications and libraries look for certificates by default, points
9040to the certificates installed globally.
9041
9042Unprivileged users can also install their own certificate package in
9043their profile. A number of environment variables need to be defined so
9044that applications and libraries know where to find them. Namely, the
9045OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9046variables. Some applications add their own environment variables; for
9047instance, the Git version control system honors the certificate bundle
9048pointed to by the @code{GIT_SSL_CAINFO} environment variable.
9049
9050
996ed739
LC
9051@node Name Service Switch
9052@subsection Name Service Switch
9053
9054@cindex name service switch
9055@cindex NSS
9056The @code{(gnu system nss)} module provides bindings to the
9057configuration file of libc's @dfn{name service switch} or @dfn{NSS}
9058(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9059Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9060extended with new ``name'' lookup methods for system databases, which
9061includes host names, service names, user accounts, and more (@pxref{Name
9062Service Switch, System Databases and Name Service Switch,, libc, The GNU
9063C Library Reference Manual}).
9064
9065The NSS configuration specifies, for each system database, which lookup
9066method is to be used, and how the various methods are chained
9067together---for instance, under which circumstances NSS should try the
9068next method in the list. The NSS configuration is given in the
9069@code{name-service-switch} field of @code{operating-system} declarations
9070(@pxref{operating-system Reference, @code{name-service-switch}}).
9071
4c9050c6
LC
9072@cindex nss-mdns
9073@cindex .local, host name lookup
996ed739 9074As an example, the declaration below configures the NSS to use the
4c9050c6
LC
9075@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9076back-end}, which supports host name lookups over multicast DNS (mDNS)
9077for host names ending in @code{.local}:
996ed739
LC
9078
9079@example
9080(name-service-switch
9081 (hosts (list %files ;first, check /etc/hosts
9082
9083 ;; If the above did not succeed, try
9084 ;; with 'mdns_minimal'.
9085 (name-service
9086 (name "mdns_minimal")
9087
9088 ;; 'mdns_minimal' is authoritative for
9089 ;; '.local'. When it returns "not found",
9090 ;; no need to try the next methods.
9091 (reaction (lookup-specification
9092 (not-found => return))))
9093
9094 ;; Then fall back to DNS.
9095 (name-service
9096 (name "dns"))
9097
9098 ;; Finally, try with the "full" 'mdns'.
9099 (name-service
9100 (name "mdns")))))
9101@end example
9102
15137a29
LC
9103Don't worry: the @code{%mdns-host-lookup-nss} variable (see below)
9104contains this configuration, so you won't have to type it if all you
9105want is to have @code{.local} host lookup working.
9106
4c9050c6
LC
9107Note that, in this case, in addition to setting the
9108@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
9109you also need to use @code{avahi-service} (@pxref{Networking Services,
9110@code{avahi-service}}), or @var{%desktop-services}, which includes it
9111(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9112to the name service cache daemon (@pxref{Base Services,
9113@code{nscd-service}}).
15137a29
LC
9114
9115For convenience, the following variables provide typical NSS
9116configurations.
9117
9118@defvr {Scheme Variable} %default-nss
9119This is the default name service switch configuration, a
9120@code{name-service-switch} object.
9121@end defvr
9122
9123@defvr {Scheme Variable} %mdns-host-lookup-nss
9124This is the name service switch configuration with support for host name
9125lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9126@end defvr
4c9050c6 9127
996ed739
LC
9128The reference for name service switch configuration is given below. It
9129is a direct mapping of the C library's configuration file format, so
9130please refer to the C library manual for more information (@pxref{NSS
9131Configuration File,,, libc, The GNU C Library Reference Manual}).
9132Compared to libc's NSS configuration file format, it has the advantage
9133not only of adding this warm parenthetic feel that we like, but also
9134static checks: you'll know about syntax errors and typos as soon as you
9135run @command{guix system}.
9136
996ed739
LC
9137@deftp {Data Type} name-service-switch
9138
9139This is the data type representation the configuration of libc's name
9140service switch (NSS). Each field below represents one of the supported
9141system databases.
9142
9143@table @code
9144@item aliases
9145@itemx ethers
9146@itemx group
9147@itemx gshadow
9148@itemx hosts
9149@itemx initgroups
9150@itemx netgroup
9151@itemx networks
9152@itemx password
9153@itemx public-key
9154@itemx rpc
9155@itemx services
9156@itemx shadow
9157The system databases handled by the NSS. Each of these fields must be a
9158list of @code{<name-service>} objects (see below.)
9159@end table
9160@end deftp
9161
9162@deftp {Data Type} name-service
9163
9164This is the data type representing an actual name service and the
9165associated lookup action.
9166
9167@table @code
9168@item name
9169A string denoting the name service (@pxref{Services in the NSS
9170configuration,,, libc, The GNU C Library Reference Manual}).
9171
4aee6e60
LC
9172Note that name services listed here must be visible to nscd. This is
9173achieved by passing the @code{#:name-services} argument to
9174@code{nscd-service} the list of packages providing the needed name
9175services (@pxref{Base Services, @code{nscd-service}}).
9176
996ed739
LC
9177@item reaction
9178An action specified using the @code{lookup-specification} macro
9179(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
9180Reference Manual}). For example:
9181
9182@example
9183(lookup-specification (unavailable => continue)
9184 (success => return))
9185@end example
9186@end table
9187@end deftp
0ae8c15a 9188
fd1b1fa2
LC
9189@node Initial RAM Disk
9190@subsection Initial RAM Disk
9191
9192@cindex initial RAM disk (initrd)
9193@cindex initrd (initial RAM disk)
9194For bootstrapping purposes, the Linux-Libre kernel is passed an
9195@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
9196root file system, as well as an initialization script. The latter is
9197responsible for mounting the real root file system, and for loading any
9198kernel modules that may be needed to achieve that.
9199
9200The @code{initrd} field of an @code{operating-system} declaration allows
9201you to specify which initrd you would like to use. The @code{(gnu
9202system linux-initrd)} module provides two ways to build an initrd: the
9203high-level @code{base-initrd} procedure, and the low-level
9204@code{expression->initrd} procedure.
9205
9206The @code{base-initrd} procedure is intended to cover most common uses.
9207For example, if you want to add a bunch of kernel modules to be loaded
9208at boot time, you can define the @code{initrd} field of the operating
9209system declaration like this:
9210
9211@example
52ac153e 9212(initrd (lambda (file-systems . rest)
027981d6
LC
9213 ;; Create a standard initrd that has modules "foo.ko"
9214 ;; and "bar.ko", as well as their dependencies, in
9215 ;; addition to the modules available by default.
52ac153e 9216 (apply base-initrd file-systems
027981d6 9217 #:extra-modules '("foo" "bar")
52ac153e 9218 rest)))
fd1b1fa2
LC
9219@end example
9220
52ac153e
LC
9221The @code{base-initrd} procedure also handles common use cases that
9222involves using the system as a QEMU guest, or as a ``live'' system whose
9223root file system is volatile.
fd1b1fa2 9224
e90cf6c1
LC
9225The initial RAM disk produced by @code{base-initrd} honors several
9226options passed on the Linux kernel command line (that is, arguments
9227passed @i{via} GRUB's @code{linux} command, or with QEMU's
9228@code{-append} option), notably:
9229
9230@table @code
9231@item --load=@var{boot}
9232Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
9233program, once it has mounted the root file system.
9234
9235GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 9236service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
9237initialization system.
9238
9239@item --root=@var{root}
9240Mount @var{root} as the root file system. @var{root} can be a device
9241device name like @code{/dev/sda1}, a partition label, or a partition
9242UUID.
9243
9244@item --system=@var{system}
9245Have @file{/run/booted-system} and @file{/run/current-system} point to
9246@var{system}.
9247
9248@item modprobe.blacklist=@var{modules}@dots{}
9249@cindex module, black-listing
9250@cindex black list, of kernel modules
9251Instruct the initial RAM disk as well as the @command{modprobe} command
9252(from the kmod package) to refuse to load @var{modules}. @var{modules}
9253must be a comma-separated list of module names---e.g.,
9254@code{usbkbd,9pnet}.
9255
9256@item --repl
9257Start a read-eval-print loop (REPL) from the initial RAM disk before it
9258tries to load kernel modules and to mount the root file system. Our
9259marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
9260love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
9261Manual}, for more information on Guile's REPL.
9262
9263@end table
9264
9265Now that you know all the features that initial RAM disks produced by
9266@code{base-initrd} provide, here is how to use it and customize it
9267further.
9268
fd1b1fa2 9269@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 9270 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 9271 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
9272Return a monadic derivation that builds a generic initrd. @var{file-systems} is
9273a list of file-systems to be mounted by the initrd, possibly in addition to
9274the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
9275@var{mapped-devices} is a list of device mappings to realize before
9276@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
9277
9278When @var{qemu-networking?} is true, set up networking with the standard QEMU
9279parameters. When @var{virtio?} is true, load additional modules so the initrd can
9280be used as a QEMU guest with para-virtualized I/O drivers.
9281
9282When @var{volatile-root?} is true, the root file system is writable but any changes
9283to it are lost.
9284
9285The initrd is automatically populated with all the kernel modules necessary
9286for @var{file-systems} and for the given options. However, additional kernel
9287modules can be listed in @var{extra-modules}. They will be added to the initrd, and
9288loaded at boot time in the order in which they appear.
9289@end deffn
9290
9291Needless to say, the initrds we produce and use embed a
9292statically-linked Guile, and the initialization program is a Guile
9293program. That gives a lot of flexibility. The
9294@code{expression->initrd} procedure builds such an initrd, given the
9295program to run in that initrd.
9296
9297@deffn {Monadic Procedure} expression->initrd @var{exp} @
9298 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 9299 [#:modules '()]
fd1b1fa2
LC
9300Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9301containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
9302upon booting. All the derivations referenced by @var{exp} are
9303automatically copied to the initrd.
fd1b1fa2 9304
42d10464
LC
9305@var{modules} is a list of Guile module names to be embedded in the
9306initrd.
fd1b1fa2
LC
9307@end deffn
9308
88faf933
LC
9309@node GRUB Configuration
9310@subsection GRUB Configuration
9311
9312@cindex GRUB
9313@cindex boot loader
9314
9315The operating system uses GNU@tie{}GRUB as its boot loader
9316(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
9317configured using @code{grub-configuration} declarations. This data type
9318is exported by the @code{(gnu system grub)} module, and described below.
9319
9320@deftp {Data Type} grub-configuration
9321The type of a GRUB configuration declaration.
9322
9323@table @asis
9324
9325@item @code{device}
9326This is a string denoting the boot device. It must be a device name
9327understood by the @command{grub-install} command, such as
9328@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9329GNU GRUB Manual}).
9330
9331@item @code{menu-entries} (default: @code{()})
9332A possibly empty list of @code{menu-entry} objects (see below), denoting
9333entries to appear in the GRUB boot menu, in addition to the current
9334system entry and the entry pointing to previous system generations.
9335
9336@item @code{default-entry} (default: @code{0})
9337The index of the default boot menu entry. Index 0 is for the current
9338system's entry.
9339
9340@item @code{timeout} (default: @code{5})
9341The number of seconds to wait for keyboard input before booting. Set to
93420 to boot immediately, and to -1 to wait indefinitely.
9343
9344@item @code{theme} (default: @var{%default-theme})
9345The @code{grub-theme} object describing the theme to use.
9346@end table
9347
9348@end deftp
9349
9350Should you want to list additional boot menu entries @i{via} the
9351@code{menu-entries} field above, you will need to create them with the
9352@code{menu-entry} form:
9353
9354@deftp {Data Type} menu-entry
9355The type of an entry in the GRUB boot menu.
9356
9357@table @asis
9358
9359@item @code{label}
35ed9306 9360The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
9361
9362@item @code{linux}
9363The Linux kernel to boot.
9364
9365@item @code{linux-arguments} (default: @code{()})
9366The list of extra Linux kernel command-line arguments---e.g.,
9367@code{("console=ttyS0")}.
9368
9369@item @code{initrd}
9370A G-Expression or string denoting the file name of the initial RAM disk
9371to use (@pxref{G-Expressions}).
9372
9373@end table
9374@end deftp
9375
9376@c FIXME: Write documentation once it's stable.
9377Themes are created using the @code{grub-theme} form, which is not
9378documented yet.
9379
9380@defvr {Scheme Variable} %default-theme
9381This is the default GRUB theme used by the operating system, with a
9382fancy background image displaying the GNU and Guix logos.
9383@end defvr
9384
9385
cf4a9129
LC
9386@node Invoking guix system
9387@subsection Invoking @code{guix system}
0918e64a 9388
cf4a9129
LC
9389Once you have written an operating system declaration, as seen in the
9390previous section, it can be @dfn{instantiated} using the @command{guix
9391system} command. The synopsis is:
4af2447e 9392
cf4a9129
LC
9393@example
9394guix system @var{options}@dots{} @var{action} @var{file}
9395@end example
4af2447e 9396
cf4a9129
LC
9397@var{file} must be the name of a file containing an
9398@code{operating-system} declaration. @var{action} specifies how the
a40424bd 9399operating system is instantiated. Currently the following values are
cf4a9129 9400supported:
4af2447e 9401
cf4a9129
LC
9402@table @code
9403@item reconfigure
9404Build the operating system described in @var{file}, activate it, and
9405switch to it@footnote{This action is usable only on systems already
65797bff 9406running GuixSD.}.
4af2447e 9407
cf4a9129
LC
9408This effects all the configuration specified in @var{file}: user
9409accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
9410The command starts system services specified in @var{file} that are not
9411currently running; if a service is currently running, it does not
9412attempt to upgrade it since it would not be possible without stopping it
9413first.
4af2447e 9414
cf4a9129
LC
9415It also adds a GRUB menu entry for the new OS configuration, and moves
9416entries for older configurations to a submenu---unless
9417@option{--no-grub} is passed.
4af2447e 9418
240b57f0 9419@quotation Note
bf2479c7
LC
9420@c The paragraph below refers to the problem discussed at
9421@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9422It is highly recommended to run @command{guix pull} once before you run
9423@command{guix system reconfigure} for the first time (@pxref{Invoking
9424guix pull}). Failing to do that you would see an older version of Guix
9425once @command{reconfigure} has completed.
240b57f0 9426@end quotation
bf2479c7 9427
cf4a9129
LC
9428@item build
9429Build the operating system's derivation, which includes all the
9430configuration files and programs needed to boot and run the system.
9431This action does not actually install anything.
113daf62 9432
cf4a9129
LC
9433@item init
9434Populate the given directory with all the files necessary to run the
9435operating system specified in @var{file}. This is useful for first-time
4705641f 9436installations of GuixSD. For instance:
113daf62
LC
9437
9438@example
cf4a9129 9439guix system init my-os-config.scm /mnt
113daf62
LC
9440@end example
9441
cf4a9129
LC
9442copies to @file{/mnt} all the store items required by the configuration
9443specified in @file{my-os-config.scm}. This includes configuration
9444files, packages, and so on. It also creates other essential files
9445needed for the system to operate correctly---e.g., the @file{/etc},
9446@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 9447
cf4a9129
LC
9448This command also installs GRUB on the device specified in
9449@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 9450
cf4a9129
LC
9451@item vm
9452@cindex virtual machine
0276f697 9453@cindex VM
f535dcbe 9454@anchor{guix system vm}
cf4a9129
LC
9455Build a virtual machine that contain the operating system declared in
9456@var{file}, and return a script to run that virtual machine (VM).
810568b3 9457Arguments given to the script are passed as is to QEMU.
113daf62 9458
cf4a9129 9459The VM shares its store with the host system.
113daf62 9460
0276f697
LC
9461Additional file systems can be shared between the host and the VM using
9462the @code{--share} and @code{--expose} command-line options: the former
9463specifies a directory to be shared with write access, while the latter
9464provides read-only access to the shared directory.
9465
9466The example below creates a VM in which the user's home directory is
9467accessible read-only, and where the @file{/exchange} directory is a
9468read-write mapping of the host's @file{$HOME/tmp}:
9469
9470@example
9471guix system vm my-config.scm \
9472 --expose=$HOME --share=$HOME/tmp=/exchange
9473@end example
9474
6aa260af
LC
9475On GNU/Linux, the default is to boot directly to the kernel; this has
9476the advantage of requiring only a very tiny root disk image since the
9477host's store can then be mounted.
9478
9479The @code{--full-boot} option forces a complete boot sequence, starting
9480with the bootloader. This requires more disk space since a root image
9481containing at least the kernel, initrd, and bootloader data files must
9482be created. The @code{--image-size} option can be used to specify the
9483image's size.
ab11f0be 9484
cf4a9129
LC
9485@item vm-image
9486@itemx disk-image
9487Return a virtual machine or disk image of the operating system declared
9488in @var{file} that stands alone. Use the @option{--image-size} option
9489to specify the size of the image.
113daf62 9490
cf4a9129 9491When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
9492the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
9493for more information on how to run the image in a virtual machine.
113daf62 9494
cf4a9129
LC
9495When using @code{disk-image}, a raw disk image is produced; it can be
9496copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
9497the device corresponding to a USB stick, one can copy the image on it
9498using the following command:
113daf62 9499
cf4a9129
LC
9500@example
9501# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9502@end example
113daf62 9503
1c8a81b1
DT
9504@item container
9505Return a script to run the operating system declared in @var{file}
9506within a container. Containers are a set of lightweight isolation
9507mechanisms provided by the kernel Linux-libre. Containers are
9508substantially less resource-demanding than full virtual machines since
9509the kernel, shared objects, and other resources can be shared with the
9510host system; this also means they provide thinner isolation.
9511
9512Currently, the script must be run as root in order to support more than
9513a single user and group. The container shares its store with the host
9514system.
9515
9516As with the @code{vm} action (@pxref{guix system vm}), additional file
9517systems to be shared between the host and container can be specified
9518using the @option{--share} and @option{--expose} options:
9519
9520@example
9521guix system container my-config.scm \
9522 --expose=$HOME --share=$HOME/tmp=/exchange
9523@end example
9524
0f252e26 9525@quotation Note
cfd35b4e 9526This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9527@end quotation
9528
cf4a9129 9529@end table
113daf62 9530
ccd7158d
LC
9531@var{options} can contain any of the common build options (@pxref{Common
9532Build Options}). In addition, @var{options} can contain one of the
9533following:
113daf62 9534
cf4a9129
LC
9535@table @option
9536@item --system=@var{system}
9537@itemx -s @var{system}
9538Attempt to build for @var{system} instead of the host's system type.
9539This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9540
f3f427c2
LC
9541@item --derivation
9542@itemx -d
9543Return the derivation file name of the given operating system without
9544building anything.
9545
cf4a9129
LC
9546@item --image-size=@var{size}
9547For the @code{vm-image} and @code{disk-image} actions, create an image
9548of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9549include a unit as a suffix (@pxref{Block size, size specifications,,
9550coreutils, GNU Coreutils}).
db030303
LC
9551
9552@item --on-error=@var{strategy}
9553Apply @var{strategy} when an error occurs when reading @var{file}.
9554@var{strategy} may be one of the following:
9555
9556@table @code
9557@item nothing-special
9558Report the error concisely and exit. This is the default strategy.
9559
9560@item backtrace
9561Likewise, but also display a backtrace.
9562
9563@item debug
9564Report the error and enter Guile's debugger. From there, you can run
9565commands such as @code{,bt} to get a backtrace, @code{,locals} to
9566display local variable values, and more generally inspect the program's
9567state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
9568a list of available debugging commands.
9569@end table
113daf62 9570@end table
113daf62 9571
cf4a9129
LC
9572Note that all the actions above, except @code{build} and @code{init},
9573rely on KVM support in the Linux-Libre kernel. Specifically, the
9574machine should have hardware virtualization support, the corresponding
9575KVM kernel module should be loaded, and the @file{/dev/kvm} device node
9576must exist and be readable and writable by the user and by the daemon's
9577build users.
8451a568 9578
65797bff
LC
9579Once you have built, configured, re-configured, and re-re-configured
9580your GuixSD installation, you may find it useful to list the operating
9581system generations available on disk---and that you can choose from the
9582GRUB boot menu:
9583
9584@table @code
9585
9586@item list-generations
9587List a summary of each generation of the operating system available on
9588disk, in a human-readable way. This is similar to the
9589@option{--list-generations} option of @command{guix package}
9590(@pxref{Invoking guix package}).
9591
9592Optionally, one can specify a pattern, with the same syntax that is used
9593in @command{guix package --list-generations}, to restrict the list of
9594generations displayed. For instance, the following command displays
9595generations up to 10-day old:
9596
9597@example
9598$ guix system list-generations 10d
9599@end example
9600
9601@end table
9602
d6c3267a
LC
9603The @command{guix system} command has even more to offer! The following
9604sub-commands allow you to visualize how your system services relate to
9605each other:
9606
9607@anchor{system-extension-graph}
9608@table @code
9609
9610@item extension-graph
9611Emit in Dot/Graphviz format to standard output the @dfn{service
9612extension graph} of the operating system defined in @var{file}
9613(@pxref{Service Composition}, for more information on service
9614extensions.)
9615
9616The command:
9617
9618@example
9619$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9620@end example
9621
9622produces a PDF file showing the extension relations among services.
9623
710fa231
AK
9624@anchor{system-shepherd-graph}
9625@item shepherd-graph
6f305ea5 9626Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
9627graph} of shepherd services of the operating system defined in
9628@var{file}. @xref{Shepherd Services}, for more information and for an
9629example graph.
6f305ea5 9630
d6c3267a
LC
9631@end table
9632
97d76250 9633@node Running GuixSD in a VM
70ac09a5 9634@subsection Running GuixSD in a Virtual Machine
97d76250
LF
9635
9636One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
9637virtual machine image using @command{guix system vm-image}
9638(@pxref{Invoking guix system}). The returned image is in qcow2 format,
9639which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
9640
9641To run the image in QEMU, copy it out of the store (@pxref{The Store})
9642and give yourself permission to write to the copy. When invoking QEMU,
9643you must choose a system emulator that is suitable for your hardware
9644platform. Here is a minimal QEMU invocation that will boot the result
9645of @command{guix system vm-image} on x86_64 hardware:
9646
9647@example
9648$ qemu-system-x86_64 \
9649 -net user -net nic,model=virtio \
9650 -enable-kvm -m 256 /tmp/qemu-image
9651@end example
9652
9653Here is what each of these options means:
9654
9655@table @code
9656@item qemu-system-x86_64
9657This specifies the hardware platform to emulate. This should match the
9658host.
9659
9660@item -net user
9661Enable the unprivileged user-mode network stack. The guest OS can
9662access the host but not vice versa. This is the simplest way to get the
9663guest OS online. If you don't choose a network stack, the boot will
9664fail.
9665
9666@item -net nic,model=virtio
9667You must create a network interface of a given model. If you don't
9668create a NIC, the boot will fail. Assuming your hardware platform is
9669x86_64, you can get a list of available NIC models by running
9670@command{qemu-system-x86_64 -net nic,model=help}.
9671
9672@item -enable-kvm
9673If your system has hardware virtualization extensions, enabling the
9674Linux kernel's virtual machine support (KVM) will make things run
9675faster.
9676
9677@item -m 256
9678RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
9679which may be insufficent for some operations.
9680
9681@item /tmp/qemu-image
9682The file name of the qcow2 image.
9683@end table
d6c3267a 9684
cf4a9129
LC
9685@node Defining Services
9686@subsection Defining Services
8451a568 9687
eb524192 9688The previous sections show the available services and how one can combine
0adfe95a
LC
9689them in an @code{operating-system} declaration. But how do we define
9690them in the first place? And what is a service anyway?
8451a568 9691
0adfe95a
LC
9692@menu
9693* Service Composition:: The model for composing services.
9694* Service Types and Services:: Types and services.
9695* Service Reference:: API reference.
dd17bc38 9696* Shepherd Services:: A particular type of service.
0adfe95a
LC
9697@end menu
9698
9699@node Service Composition
9700@subsubsection Service Composition
9701
9702@cindex services
9703@cindex daemons
9704Here we define a @dfn{service} as, broadly, something that extends the
9705operating system's functionality. Often a service is a process---a
9706@dfn{daemon}---started when the system boots: a secure shell server, a
9707Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9708whose execution can be triggered by another daemon---e.g., an FTP server
9709started by @command{inetd} or a D-Bus service activated by
9710@command{dbus-daemon}. Occasionally, a service does not map to a
9711daemon. For instance, the ``account'' service collects user accounts
9712and makes sure they exist when the system runs; the ``udev'' service
9713collects device management rules and makes them available to the eudev
9714daemon; the @file{/etc} service populates the system's @file{/etc}
9715directory.
9716
d6c3267a 9717@cindex service extensions
0adfe95a 9718GuixSD services are connected by @dfn{extensions}. For instance, the
dd17bc38
AK
9719secure shell service @emph{extends} the Shepherd---GuixSD's
9720initialization system, running as PID@tie{}1---by giving it the command
9721lines to start and stop the secure shell daemon (@pxref{Networking
9722Services, @code{lsh-service}}); the UPower service extends the D-Bus
9723service by passing it its @file{.service} specification, and extends the
9724udev service by passing it device management rules (@pxref{Desktop
9725Services, @code{upower-service}}); the Guix daemon service extends the
9726Shepherd by passing it the command lines to start and stop the daemon,
9727and extends the account service by passing it a list of required build
9728user accounts (@pxref{Base Services}).
0adfe95a
LC
9729
9730All in all, services and their ``extends'' relations form a directed
9731acyclic graph (DAG). If we represent services as boxes and extensions
9732as arrows, a typical system might provide something like this:
9733
9734@image{images/service-graph,,5in,Typical service extension graph.}
9735
d62e201c
LC
9736@cindex system service
9737At the bottom, we see the @dfn{system service}, which produces the
9738directory containing everything to run and boot the system, as returned
9739by the @command{guix system build} command. @xref{Service Reference},
9740to learn about the other service types shown here.
d6c3267a
LC
9741@xref{system-extension-graph, the @command{guix system extension-graph}
9742command}, for information on how to generate this representation for a
9743particular operating system definition.
0adfe95a
LC
9744
9745@cindex service types
9746Technically, developers can define @dfn{service types} to express these
9747relations. There can be any number of services of a given type on the
9748system---for instance, a system running two instances of the GNU secure
9749shell server (lsh) has two instances of @var{lsh-service-type}, with
9750different parameters.
9751
9752The following section describes the programming interface for service
9753types and services.
9754
9755@node Service Types and Services
9756@subsubsection Service Types and Services
9757
9758A @dfn{service type} is a node in the DAG described above. Let us start
9759with a simple example, the service type for the Guix build daemon
9760(@pxref{Invoking guix-daemon}):
9761
9762@example
9763(define guix-service-type
9764 (service-type
9765 (name 'guix)
9766 (extensions
d4053c71 9767 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
9768 (service-extension account-service-type guix-accounts)
9769 (service-extension activation-service-type guix-activation)))))
9770@end example
8451a568 9771
cf4a9129 9772@noindent
0adfe95a
LC
9773It defines a two things:
9774
9775@enumerate
9776@item
9777A name, whose sole purpose is to make inspection and debugging easier.
9778
9779@item
9780A list of @dfn{service extensions}, where each extension designates the
9781target service type and a procedure that, given the service's
9782parameters, returns a list of object to extend the service of that type.
9783
9784Every service type has at least one service extension. The only
9785exception is the @dfn{boot service type}, which is the ultimate service.
9786@end enumerate
9787
9788In this example, @var{guix-service-type} extends three services:
9789
9790@table @var
d4053c71
AK
9791@item shepherd-root-service-type
9792The @var{guix-shepherd-service} procedure defines how the Shepherd
9793service is extended. Namely, it returns a @code{<shepherd-service>}
9794object that defines how @command{guix-daemon} is started and stopped
9795(@pxref{Shepherd Services}).
0adfe95a
LC
9796
9797@item account-service-type
9798This extension for this service is computed by @var{guix-accounts},
9799which returns a list of @code{user-group} and @code{user-account}
9800objects representing the build user accounts (@pxref{Invoking
9801guix-daemon}).
9802
9803@item activation-service-type
9804Here @var{guix-activation} is a procedure that returns a gexp, which is
9805a code snippet to run at ``activation time''---e.g., when the service is
9806booted.
9807@end table
9808
9809A service of this type is instantiated like this:
9810
9811@example
9812(service guix-service-type
9813 (guix-configuration
9814 (build-accounts 5)
9815 (use-substitutes? #f)))
9816@end example
9817
9818The second argument to the @code{service} form is a value representing
9819the parameters of this specific service instance.
9820@xref{guix-configuration-type, @code{guix-configuration}}, for
9821information about the @code{guix-configuration} data type.
9822
9823@var{guix-service-type} is quite simple because it extends other
9824services but is not extensible itself.
9825
9826@c @subsubsubsection Extensible Service Types
9827
9828The service type for an @emph{extensible} service looks like this:
9829
9830@example
9831(define udev-service-type
9832 (service-type (name 'udev)
9833 (extensions
d4053c71
AK
9834 (list (service-extension shepherd-root-service-type
9835 udev-shepherd-service)))
0adfe95a
LC
9836
9837 (compose concatenate) ;concatenate the list of rules
9838 (extend (lambda (config rules)
9839 (match config
9840 (($ <udev-configuration> udev initial-rules)
9841 (udev-configuration
9842 (udev udev) ;the udev package to use
9843 (rules (append initial-rules rules)))))))))
9844@end example
9845
9846This is the service type for the
9847@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9848management daemon}. Compared to the previous example, in addition to an
d4053c71 9849extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
9850
9851@table @code
9852@item compose
9853This is the procedure to @dfn{compose} the list of extensions to
9854services of this type.
9855
9856Services can extend the udev service by passing it lists of rules; we
9857compose those extensions simply by concatenating them.
9858
9859@item extend
9860This procedure defines how the service's value is @dfn{extended} with
9861the composition of the extensions.
9862
9863Udev extensions are composed into a list of rules, but the udev service
9864value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 9865extend that record by appending the list of rules it contains to the
0adfe95a
LC
9866list of contributed rules.
9867@end table
9868
9869There can be only one instance of an extensible service type such as
9870@var{udev-service-type}. If there were more, the
9871@code{service-extension} specifications would be ambiguous.
9872
9873Still here? The next section provides a reference of the programming
9874interface for services.
9875
9876@node Service Reference
9877@subsubsection Service Reference
9878
9879We have seen an overview of service types (@pxref{Service Types and
9880Services}). This section provides a reference on how to manipulate
9881services and service types. This interface is provided by the
9882@code{(gnu services)} module.
9883
9884@deffn {Scheme Procedure} service @var{type} @var{value}
9885Return a new service of @var{type}, a @code{<service-type>} object (see
9886below.) @var{value} can be any object; it represents the parameters of
9887this particular service instance.
9888@end deffn
9889
9890@deffn {Scheme Procedure} service? @var{obj}
9891Return true if @var{obj} is a service.
9892@end deffn
8451a568 9893
0adfe95a
LC
9894@deffn {Scheme Procedure} service-kind @var{service}
9895Return the type of @var{service}---i.e., a @code{<service-type>} object.
9896@end deffn
9897
9898@deffn {Scheme Procedure} service-parameters @var{service}
9899Return the value associated with @var{service}. It represents its
9900parameters.
9901@end deffn
9902
9903Here is an example of how a service is created and manipulated:
9904
9905@example
9906(define s
9907 (service nginx-service-type
9908 (nginx-configuration
9909 (nginx nginx)
9910 (log-directory log-directory)
9911 (run-directory run-directory)
9912 (file config-file))))
9913
9914(service? s)
9915@result{} #t
9916
9917(eq? (service-kind s) nginx-service-type)
9918@result{} #t
9919@end example
9920
cd6f6c22
LC
9921The @code{modify-services} form provides a handy way to change the
9922parameters of some of the services of a list such as
9923@var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9924course, you could always use standard list combinators such as
9925@code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9926guile, GNU Guile Reference Manual}); @code{modify-services} simply
9927provides a more concise form for this common pattern.
9928
9929@deffn {Scheme Syntax} modify-services @var{services} @
9930 (@var{type} @var{variable} => @var{body}) @dots{}
9931
9932Modify the services listed in @var{services} according to the given
9933clauses. Each clause has the form:
9934
9935@example
9936(@var{type} @var{variable} => @var{body})
9937@end example
9938
9939where @var{type} is a service type, such as @var{guix-service-type}, and
9940@var{variable} is an identifier that is bound within @var{body} to the
9941value of the service of that @var{type}. @xref{Using the Configuration
9942System}, for an example.
9943
9944This is a shorthand for:
9945
9946@example
9947(map (lambda (service) @dots{}) @var{services})
9948@end example
9949@end deffn
9950
9951Next comes the programming interface for service types. This is
9952something you want to know when writing new service definitions, but not
9953necessarily when simply looking for ways to customize your
9954@code{operating-system} declaration.
9955
0adfe95a
LC
9956@deftp {Data Type} service-type
9957@cindex service type
9958This is the representation of a @dfn{service type} (@pxref{Service Types
9959and Services}).
9960
9961@table @asis
9962@item @code{name}
9963This is a symbol, used only to simplify inspection and debugging.
9964
9965@item @code{extensions}
9966A non-empty list of @code{<service-extension>} objects (see below.)
9967
9968@item @code{compose} (default: @code{#f})
9969If this is @code{#f}, then the service type denotes services that cannot
9970be extended---i.e., services that do not receive ``values'' from other
9971services.
9972
9973Otherwise, it must be a one-argument procedure. The procedure is called
9974by @code{fold-services} and is passed a list of values collected from
9975extensions. It must return a value that is a valid parameter value for
9976the service instance.
9977
9978@item @code{extend} (default: @code{#f})
9979If this is @code{#f}, services of this type cannot be extended.
9980
9981Otherwise, it must be a two-argument procedure: @code{fold-services}
9982calls it, passing it the service's initial value as the first argument
9983and the result of applying @code{compose} to the extension values as the
9984second argument.
9985@end table
9986
9987@xref{Service Types and Services}, for examples.
9988@end deftp
9989
9990@deffn {Scheme Procedure} service-extension @var{target-type} @
9991 @var{compute}
9992Return a new extension for services of type @var{target-type}.
9993@var{compute} must be a one-argument procedure: @code{fold-services}
9994calls it, passing it the value associated with the service that provides
9995the extension; it must return a valid value for the target service.
9996@end deffn
9997
9998@deffn {Scheme Procedure} service-extension? @var{obj}
9999Return true if @var{obj} is a service extension.
10000@end deffn
10001
10002At the core of the service abstraction lies the @code{fold-services}
10003procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
10004down to a single directory that contains everything needed to boot and
10005run the system---the directory shown by the @command{guix system build}
10006command (@pxref{Invoking guix system}). In essence, it propagates
10007service extensions down the service graph, updating each node parameters
10008on the way, until it reaches the root node.
0adfe95a
LC
10009
10010@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 10011 [#:target-type @var{system-service-type}]
0adfe95a
LC
10012Fold @var{services} by propagating their extensions down to the root of
10013type @var{target-type}; return the root service adjusted accordingly.
10014@end deffn
10015
10016Lastly, the @code{(gnu services)} module also defines several essential
10017service types, some of which are listed below.
10018
d62e201c
LC
10019@defvr {Scheme Variable} system-service-type
10020This is the root of the service graph. It produces the system directory
10021as returned by the @command{guix system build} command.
10022@end defvr
10023
0adfe95a 10024@defvr {Scheme Variable} boot-service-type
d62e201c
LC
10025The type of the ``boot service'', which produces the @dfn{boot script}.
10026The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
10027@end defvr
10028
10029@defvr {Scheme Variable} etc-service-type
10030The type of the @file{/etc} service. This service can be extended by
10031passing it name/file tuples such as:
10032
10033@example
10034(list `("issue" ,(plain-file "issue" "Welcome!\n")))
10035@end example
10036
10037In this example, the effect would be to add an @file{/etc/issue} file
10038pointing to the given file.
10039@end defvr
10040
10041@defvr {Scheme Variable} setuid-program-service-type
10042Type for the ``setuid-program service''. This service collects lists of
10043executable file names, passed as gexps, and adds them to the set of
10044setuid-root programs on the system (@pxref{Setuid Programs}).
10045@end defvr
10046
af4c3fd5
LC
10047@defvr {Scheme Variable} profile-service-type
10048Type of the service that populates the @dfn{system profile}---i.e., the
10049programs under @file{/run/current-system/profile}. Other services can
10050extend it by passing it lists of packages to add to the system profile.
10051@end defvr
10052
0adfe95a 10053
dd17bc38
AK
10054@node Shepherd Services
10055@subsubsection Shepherd Services
0adfe95a
LC
10056
10057@cindex PID 1
10058@cindex init system
a40424bd
CM
10059The @code{(gnu services shepherd)} module provides a way to define
10060services managed by the GNU@tie{}Shepherd, which is the GuixSD
10061initialization system---the first process that is started when the
10062system boots, aka. PID@tie{}1 (@pxref{Introduction,,, shepherd, The GNU
10063Shepherd Manual}).
6f305ea5 10064
dd17bc38
AK
10065Services in the Shepherd can depend on each other. For instance, the
10066SSH daemon may need to be started after the syslog daemon has been
10067started, which in turn can only happen once all the file systems have
10068been mounted. The simple operating system defined earlier (@pxref{Using
10069the Configuration System}) results in a service graph like this:
6f305ea5 10070
710fa231 10071@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
10072
10073You can actually generate such a graph for any operating system
710fa231
AK
10074definition using the @command{guix system shepherd-graph} command
10075(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 10076
d4053c71
AK
10077The @var{%shepherd-root-service} is a service object representing
10078PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10079by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 10080
d4053c71 10081@deftp {Data Type} shepherd-service
dd17bc38 10082The data type representing a service managed by the Shepherd.
0adfe95a
LC
10083
10084@table @asis
10085@item @code{provision}
10086This is a list of symbols denoting what the service provides.
10087
dd17bc38
AK
10088These are the names that may be passed to @command{herd start},
10089@command{herd status}, and similar commands (@pxref{Invoking herd,,,
10090shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10091@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
10092
10093@item @code{requirements} (default: @code{'()})
dd17bc38 10094List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
10095
10096@item @code{respawn?} (default: @code{#t})
10097Whether to restart the service when it stops, for instance when the
10098underlying process dies.
10099
10100@item @code{start}
10101@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
10102The @code{start} and @code{stop} fields refer to the Shepherd's
10103facilities to start and stop processes (@pxref{Service De- and
10104Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10105G-expressions that get expanded in the Shepherd configuration file
10106(@pxref{G-Expressions}).
0adfe95a
LC
10107
10108@item @code{documentation}
10109A documentation string, as shown when running:
10110
10111@example
dd17bc38 10112herd doc @var{service-name}
0adfe95a
LC
10113@end example
10114
10115where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 10116(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
10117
10118@item @code{modules} (default: @var{%default-modules})
10119This is the list of modules that must be in scope when @code{start} and
10120@code{stop} are evaluated.
10121
10122@item @code{imported-modules} (default: @var{%default-imported-modules})
10123This is the list of modules to import in the execution environment of
dd17bc38 10124the Shepherd.
fae685b9 10125
0adfe95a
LC
10126@end table
10127@end deftp
10128
d4053c71 10129@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 10130The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
10131
10132This is the service type that extensions target when they want to create
dd17bc38 10133shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 10134Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
10135@end defvr
10136
d4053c71 10137@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
10138This service represents PID@tie{}1.
10139@end defvr
8451a568 10140
8451a568 10141
cf4a9129
LC
10142@node Installing Debugging Files
10143@section Installing Debugging Files
8451a568 10144
cf4a9129
LC
10145@cindex debugging files
10146Program binaries, as produced by the GCC compilers for instance, are
10147typically written in the ELF format, with a section containing
10148@dfn{debugging information}. Debugging information is what allows the
10149debugger, GDB, to map binary code to source code; it is required to
10150debug a compiled program in good conditions.
8451a568 10151
cf4a9129
LC
10152The problem with debugging information is that is takes up a fair amount
10153of disk space. For example, debugging information for the GNU C Library
10154weighs in at more than 60 MiB. Thus, as a user, keeping all the
10155debugging info of all the installed programs is usually not an option.
10156Yet, space savings should not come at the cost of an impediment to
10157debugging---especially in the GNU system, which should make it easier
10158for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 10159
cf4a9129
LC
10160Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
10161mechanism that allows users to get the best of both worlds: debugging
10162information can be stripped from the binaries and stored in separate
10163files. GDB is then able to load debugging information from those files,
10164when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
10165with GDB}).
8451a568 10166
cf4a9129
LC
10167The GNU distribution takes advantage of this by storing debugging
10168information in the @code{lib/debug} sub-directory of a separate package
10169output unimaginatively called @code{debug} (@pxref{Packages with
10170Multiple Outputs}). Users can choose to install the @code{debug} output
10171of a package when they need it. For instance, the following command
10172installs the debugging information for the GNU C Library and for GNU
10173Guile:
8451a568
LC
10174
10175@example
cf4a9129 10176guix package -i glibc:debug guile:debug
8451a568
LC
10177@end example
10178
cf4a9129
LC
10179GDB must then be told to look for debug files in the user's profile, by
10180setting the @code{debug-file-directory} variable (consider setting it
10181from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
10182GDB}):
8451a568 10183
cf4a9129
LC
10184@example
10185(gdb) set debug-file-directory ~/.guix-profile/lib/debug
10186@end example
8451a568 10187
cf4a9129
LC
10188From there on, GDB will pick up debugging information from the
10189@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 10190
cf4a9129
LC
10191In addition, you will most likely want GDB to be able to show the source
10192code being debugged. To do that, you will have to unpack the source
10193code of the package of interest (obtained with @code{guix build
10194--source}, @pxref{Invoking guix build}), and to point GDB to that source
10195directory using the @code{directory} command (@pxref{Source Path,
10196@code{directory},, gdb, Debugging with GDB}).
8451a568 10197
cf4a9129
LC
10198@c XXX: keep me up-to-date
10199The @code{debug} output mechanism in Guix is implemented by the
10200@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
10201opt-in---debugging information is available only for those packages
10202whose definition explicitly declares a @code{debug} output. This may be
10203changed to opt-out in the future, if our build farm servers can handle
10204the load. To check whether a package has a @code{debug} output, use
10205@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 10206
8451a568 10207
05962f29
LC
10208@node Security Updates
10209@section Security Updates
10210
843858b8
LC
10211@quotation Note
10212As of version @value{VERSION}, the feature described in this section is
10213experimental.
10214@end quotation
05962f29
LC
10215
10216@cindex security updates
10217Occasionally, important security vulnerabilities are discovered in core
10218software packages and must be patched. Guix follows a functional
10219package management discipline (@pxref{Introduction}), which implies
10220that, when a package is changed, @emph{every package that depends on it}
10221must be rebuilt. This can significantly slow down the deployment of
10222fixes in core packages such as libc or Bash, since basically the whole
10223distribution would need to be rebuilt. Using pre-built binaries helps
10224(@pxref{Substitutes}), but deployment may still take more time than
10225desired.
10226
10227@cindex grafts
10228To address that, Guix implements @dfn{grafts}, a mechanism that allows
10229for fast deployment of critical updates without the costs associated
10230with a whole-distribution rebuild. The idea is to rebuild only the
10231package that needs to be patched, and then to ``graft'' it onto packages
10232explicitly installed by the user and that were previously referring to
10233the original package. The cost of grafting is typically very low, and
10234order of magnitudes lower than a full rebuild of the dependency chain.
10235
10236@cindex replacements of packages, for grafts
10237For instance, suppose a security update needs to be applied to Bash.
10238Guix developers will provide a package definition for the ``fixed''
10239Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
10240Packages}). Then, the original package definition is augmented with a
10241@code{replacement} field pointing to the package containing the bug fix:
10242
10243@example
10244(define bash
10245 (package
10246 (name "bash")
10247 ;; @dots{}
10248 (replacement bash-fixed)))
10249@end example
10250
c22a1324
LC
10251From there on, any package depending directly or indirectly on Bash---as
10252reported by @command{guix gc --requisites} (@pxref{Invoking guix
10253gc})---that is installed is automatically ``rewritten'' to refer to
05962f29
LC
10254@var{bash-fixed} instead of @var{bash}. This grafting process takes
10255time proportional to the size of the package, but expect less than a
c22a1324
LC
10256minute for an ``average'' package on a recent machine. Grafting is
10257recursive: when an indirect dependency requires grafting, then grafting
10258``propagates'' up to the package that the user is installing.
05962f29
LC
10259
10260Currently, the graft and the package it replaces (@var{bash-fixed} and
10261@var{bash} in the example above) must have the exact same @code{name}
10262and @code{version} fields. This restriction mostly comes from the fact
10263that grafting works by patching files, including binary files, directly.
10264Other restrictions may apply: for instance, when adding a graft to a
10265package providing a shared library, the original shared library and its
10266replacement must have the same @code{SONAME} and be binary-compatible.
10267
10268
cf4a9129
LC
10269@node Package Modules
10270@section Package Modules
8451a568 10271
cf4a9129
LC
10272From a programming viewpoint, the package definitions of the
10273GNU distribution are provided by Guile modules in the @code{(gnu packages
10274@dots{})} name space@footnote{Note that packages under the @code{(gnu
10275packages @dots{})} module name space are not necessarily ``GNU
10276packages''. This module naming scheme follows the usual Guile module
10277naming convention: @code{gnu} means that these modules are distributed
10278as part of the GNU system, and @code{packages} identifies modules that
10279define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
10280Reference Manual}). For instance, the @code{(gnu packages emacs)}
10281module exports a variable named @code{emacs}, which is bound to a
10282@code{<package>} object (@pxref{Defining Packages}).
113daf62 10283
300868ba 10284The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
10285automatically scanned for packages by the command-line tools. For
10286instance, when running @code{guix package -i emacs}, all the @code{(gnu
10287packages @dots{})} modules are scanned until one that exports a package
10288object whose name is @code{emacs} is found. This package search
10289facility is implemented in the @code{(gnu packages)} module.
113daf62 10290
300868ba 10291@cindex customization, of packages
8689901f 10292@cindex package module search path
cf4a9129 10293Users can store package definitions in modules with different
60142854 10294names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
10295name and module name must match. For instance, the @code{(my-packages
10296emacs)} module must be stored in a @file{my-packages/emacs.scm} file
10297relative to the load path specified with @option{--load-path} or
10298@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
10299guile, GNU Guile Reference Manual}, for details.}. These package definitions
300868ba
LC
10300will not be visible by default. Thus, users can invoke commands such as
10301@command{guix package} and @command{guix build} have to be used with the
c95ded7e
LC
10302@code{-e} option so that they know where to find the package. Better
10303yet, they can use the
300868ba 10304@code{-L} option of these commands to make those modules visible
8689901f
LC
10305(@pxref{Invoking guix build, @code{--load-path}}), or define the
10306@code{GUIX_PACKAGE_PATH} environment variable. This environment
10307variable makes it easy to extend or customize the distribution and is
10308honored by all the user interfaces.
10309
10310@defvr {Environment Variable} GUIX_PACKAGE_PATH
10311This is a colon-separated list of directories to search for package
10312modules. Directories listed in this variable take precedence over the
10313distribution's own modules.
10314@end defvr
ef5dd60a 10315
cf4a9129
LC
10316The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
10317each package is built based solely on other packages in the
10318distribution. The root of this dependency graph is a small set of
10319@dfn{bootstrap binaries}, provided by the @code{(gnu packages
10320bootstrap)} module. For more information on bootstrapping,
081145cf 10321@pxref{Bootstrapping}.
ef5dd60a 10322
cf4a9129
LC
10323@node Packaging Guidelines
10324@section Packaging Guidelines
ef5dd60a 10325
cf4a9129
LC
10326The GNU distribution is nascent and may well lack some of your favorite
10327packages. This section describes how you can help make the distribution
10328grow. @xref{Contributing}, for additional information on how you can
10329help.
ef5dd60a 10330
cf4a9129
LC
10331Free software packages are usually distributed in the form of
10332@dfn{source code tarballs}---typically @file{tar.gz} files that contain
10333all the source files. Adding a package to the distribution means
10334essentially two things: adding a @dfn{recipe} that describes how to
10335build the package, including a list of other packages required to build
f97c9175 10336it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 10337description and licensing information.
ef5dd60a 10338
cf4a9129
LC
10339In Guix all this information is embodied in @dfn{package definitions}.
10340Package definitions provide a high-level view of the package. They are
10341written using the syntax of the Scheme programming language; in fact,
10342for each package we define a variable bound to the package definition,
10343and export that variable from a module (@pxref{Package Modules}).
10344However, in-depth Scheme knowledge is @emph{not} a prerequisite for
10345creating packages. For more information on package definitions,
081145cf 10346@pxref{Defining Packages}.
ef5dd60a 10347
cf4a9129
LC
10348Once a package definition is in place, stored in a file in the Guix
10349source tree, it can be tested using the @command{guix build} command
10350(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
10351called @code{gnew}, you may run this command from the Guix build tree
10352(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
10353
10354@example
cf4a9129 10355./pre-inst-env guix build gnew --keep-failed
ef5dd60a 10356@end example
ef5dd60a 10357
cf4a9129
LC
10358Using @code{--keep-failed} makes it easier to debug build failures since
10359it provides access to the failed build tree. Another useful
10360command-line option when debugging is @code{--log-file}, to access the
10361build log.
ef5dd60a 10362
cf4a9129
LC
10363If the package is unknown to the @command{guix} command, it may be that
10364the source file contains a syntax error, or lacks a @code{define-public}
10365clause to export the package variable. To figure it out, you may load
10366the module from Guile to get more information about the actual error:
ef5dd60a 10367
cf4a9129
LC
10368@example
10369./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
10370@end example
ef5dd60a 10371
cf4a9129
LC
10372Once your package builds correctly, please send us a patch
10373(@pxref{Contributing}). Well, if you need help, we will be happy to
10374help you too. Once the patch is committed in the Guix repository, the
10375new package automatically gets built on the supported platforms by
2b1cee21 10376@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 10377system}.
ef5dd60a 10378
cf4a9129
LC
10379@cindex substituter
10380Users can obtain the new package definition simply by running
10381@command{guix pull} (@pxref{Invoking guix pull}). When
10382@code{hydra.gnu.org} is done building the package, installing the
10383package automatically downloads binaries from there
10384(@pxref{Substitutes}). The only place where human intervention is
10385needed is to review and apply the patch.
ef5dd60a 10386
ef5dd60a 10387
cf4a9129 10388@menu
ec0339cd
LC
10389* Software Freedom:: What may go into the distribution.
10390* Package Naming:: What's in a name?
10391* Version Numbers:: When the name is not enough.
cbd02397 10392* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
10393* Python Modules:: Taming the snake.
10394* Perl Modules:: Little pearls.
10395* Fonts:: Fond of fonts.
cf4a9129 10396@end menu
ef5dd60a 10397
cf4a9129
LC
10398@node Software Freedom
10399@subsection Software Freedom
ef5dd60a 10400
cf4a9129 10401@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 10402
cf4a9129
LC
10403The GNU operating system has been developed so that users can have
10404freedom in their computing. GNU is @dfn{free software}, meaning that
10405users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10406essential freedoms}: to run the program, to study and change the program
10407in source code form, to redistribute exact copies, and to distribute
10408modified versions. Packages found in the GNU distribution provide only
10409software that conveys these four freedoms.
c11a6eb1 10410
cf4a9129
LC
10411In addition, the GNU distribution follow the
10412@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10413software distribution guidelines}. Among other things, these guidelines
10414reject non-free firmware, recommendations of non-free software, and
10415discuss ways to deal with trademarks and patents.
ef5dd60a 10416
cf4a9129
LC
10417Some packages contain a small and optional subset that violates the
10418above guidelines, for instance because this subset is itself non-free
10419code. When that happens, the offending items are removed with
10420appropriate patches or code snippets in the package definition's
10421@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
10422build --source} returns the ``freed'' source rather than the unmodified
10423upstream source.
ef5dd60a 10424
ef5dd60a 10425
cf4a9129
LC
10426@node Package Naming
10427@subsection Package Naming
ef5dd60a 10428
cf4a9129
LC
10429A package has actually two names associated with it:
10430First, there is the name of the @emph{Scheme variable}, the one following
10431@code{define-public}. By this name, the package can be made known in the
10432Scheme code, for instance as input to another package. Second, there is
10433the string in the @code{name} field of a package definition. This name
10434is used by package management commands such as
10435@command{guix package} and @command{guix build}.
ef5dd60a 10436
cf4a9129
LC
10437Both are usually the same and correspond to the lowercase conversion of
10438the project name chosen upstream, with underscores replaced with
10439hyphens. For instance, GNUnet is available as @code{gnunet}, and
10440SDL_net as @code{sdl-net}.
927097ef 10441
cf4a9129 10442We do not add @code{lib} prefixes for library packages, unless these are
081145cf 10443already part of the official project name. But @pxref{Python
cf4a9129
LC
10444Modules} and @ref{Perl Modules} for special rules concerning modules for
10445the Python and Perl languages.
927097ef 10446
1b366ee4 10447Font package names are handled differently, @pxref{Fonts}.
7fec52b7 10448
ef5dd60a 10449
cf4a9129
LC
10450@node Version Numbers
10451@subsection Version Numbers
ef5dd60a 10452
cf4a9129
LC
10453We usually package only the latest version of a given free software
10454project. But sometimes, for instance for incompatible library versions,
10455two (or more) versions of the same package are needed. These require
10456different Scheme variable names. We use the name as defined
10457in @ref{Package Naming}
10458for the most recent version; previous versions use the same name, suffixed
10459by @code{-} and the smallest prefix of the version number that may
10460distinguish the two versions.
ef5dd60a 10461
cf4a9129
LC
10462The name inside the package definition is the same for all versions of a
10463package and does not contain any version number.
ef5dd60a 10464
cf4a9129 10465For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 10466
cf4a9129
LC
10467@example
10468(define-public gtk+
10469 (package
17d8e33f
ML
10470 (name "gtk+")
10471 (version "3.9.12")
10472 ...))
cf4a9129
LC
10473(define-public gtk+-2
10474 (package
17d8e33f
ML
10475 (name "gtk+")
10476 (version "2.24.20")
10477 ...))
cf4a9129
LC
10478@end example
10479If we also wanted GTK+ 3.8.2, this would be packaged as
10480@example
10481(define-public gtk+-3.8
10482 (package
17d8e33f
ML
10483 (name "gtk+")
10484 (version "3.8.2")
10485 ...))
cf4a9129 10486@end example
ef5dd60a 10487
880d647d
LC
10488@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
10489@c for a discussion of what follows.
10490@cindex version number, for VCS snapshots
10491Occasionally, we package snapshots of upstream's version control system
10492(VCS) instead of formal releases. This should remain exceptional,
10493because it is up to upstream developers to clarify what the stable
10494release is. Yet, it is sometimes necessary. So, what should we put in
10495the @code{version} field?
10496
10497Clearly, we need to make the commit identifier of the VCS snapshot
10498visible in the version string, but we also need to make sure that the
10499version string is monotonically increasing so that @command{guix package
10500--upgrade} can determine which version is newer. Since commit
10501identifiers, notably with Git, are not monotonically increasing, we add
10502a revision number that we increase each time we upgrade to a newer
10503snapshot. The resulting version string looks like this:
10504
10505@example
105062.0.11-3.cabba9e
10507 ^ ^ ^
10508 | | `-- upstream commit ID
10509 | |
10510 | `--- Guix package revision
10511 |
10512latest upstream version
10513@end example
10514
10515It is a good idea to strip commit identifiers in the @code{version}
10516field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
10517aesthetics have a role to play here) as well as problems related to OS
10518limits such as the maximum shebang length (127 bytes for the Linux
10519kernel.) It is best to use the full commit identifiers in
561360a5
LC
10520@code{origin}s, though, to avoid ambiguities. A typical package
10521definition may look like this:
10522
10523@example
10524(define my-package
10525 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
10526 (package
10527 (version (string-append "0.9-1."
10528 (string-take commit 7)))
10529 (source (origin
10530 (method git-fetch)
10531 (uri (git-reference
10532 (url "git://example.org/my-package.git")
10533 (commit commit)))
10534 (sha256 (base32 "1mbikn@dots{}"))
10535 (file-name (string-append "my-package-" version
10536 "-checkout"))))
10537 ;; @dots{}
10538 )))
10539@end example
880d647d 10540
cbd02397
LC
10541@node Synopses and Descriptions
10542@subsection Synopses and Descriptions
10543
10544As we have seen before, each package in GNU@tie{}Guix includes a
10545synopsis and a description (@pxref{Defining Packages}). Synopses and
10546descriptions are important: They are what @command{guix package
10547--search} searches, and a crucial piece of information to help users
10548determine whether a given package suits their needs. Consequently,
10549packagers should pay attention to what goes into them.
10550
10551Synopses must start with a capital letter and must not end with a
10552period. They must not start with ``a'' or ``the'', which usually does
10553not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10554tool that frobs files''. The synopsis should say what the package
10555is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10556used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10557matching a pattern''.
10558
10559Keep in mind that the synopsis must be meaningful for a very wide
10560audience. For example, ``Manipulate alignments in the SAM format''
10561might make sense for a seasoned bioinformatics researcher, but might be
10562fairly unhelpful or even misleading to a non-specialized audience. It
10563is a good idea to come up with a synopsis that gives an idea of the
10564application domain of the package. In this example, this might give
10565something like ``Manipulate nucleotide sequence alignments'', which
10566hopefully gives the user a better idea of whether this is what they are
10567looking for.
10568
10569@cindex Texinfo markup, in package descriptions
10570Descriptions should take between five and ten lines. Use full
10571sentences, and avoid using acronyms without first introducing them.
10572Descriptions can include Texinfo markup, which is useful to introduce
10573ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
10574hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10575should be careful when using some characters for example @samp{@@} and
10576curly braces which are the basic special characters in Texinfo
10577(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10578such as @command{guix package --show} take care of rendering it
10579appropriately.
cbd02397
LC
10580
10581Synopses and descriptions are translated by volunteers
10582@uref{http://translationproject.org/domain/guix-packages.html, at the
10583Translation Project} so that as many users as possible can read them in
10584their native language. User interfaces search them and display them in
10585the language specified by the current locale.
10586
10587Translation is a lot of work so, as a packager, please pay even more
10588attention to your synopses and descriptions as every change may entail
ba7d6c76 10589additional work for translators. In order to help them, it is possible
36743e71 10590to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
10591special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10592Gettext}):
10593
10594@example
10595;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10596(description "ARandR is designed to provide a simple visual front end
10597for the X11 resize-and-rotate (RandR) extension. @dots{}")
10598@end example
cbd02397 10599
ef5dd60a 10600
cf4a9129
LC
10601@node Python Modules
10602@subsection Python Modules
ef5dd60a 10603
cf4a9129
LC
10604We currently package Python 2 and Python 3, under the Scheme variable names
10605@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10606To avoid confusion and naming clashes with other programming languages, it
10607seems desirable that the name of a package for a Python module contains
10608the word @code{python}.
ef5dd60a 10609
cf4a9129
LC
10610Some modules are compatible with only one version of Python, others with both.
10611If the package Foo compiles only with Python 3, we name it
10612@code{python-foo}; if it compiles only with Python 2, we name it
10613@code{python2-foo}. If it is compatible with both versions, we create two
10614packages with the corresponding names.
ef5dd60a 10615
cf4a9129
LC
10616If a project already contains the word @code{python}, we drop this;
10617for instance, the module python-dateutil is packaged under the names
10618@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10619
523e4896 10620
cf4a9129
LC
10621@node Perl Modules
10622@subsection Perl Modules
523e4896 10623
cf4a9129
LC
10624Perl programs standing for themselves are named as any other package,
10625using the lowercase upstream name.
10626For Perl packages containing a single class, we use the lowercase class name,
10627replace all occurrences of @code{::} by dashes and prepend the prefix
10628@code{perl-}.
10629So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10630Modules containing several classes keep their lowercase upstream name and
10631are also prepended by @code{perl-}. Such modules tend to have the word
10632@code{perl} somewhere in their name, which gets dropped in favor of the
10633prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10634
523e4896 10635
7fec52b7
AE
10636@node Fonts
10637@subsection Fonts
10638
10639For fonts that are in general not installed by a user for typesetting
10640purposes, or that are distributed as part of a larger software package,
10641we rely on the general packaging rules for software; for instance, this
10642applies to the fonts delivered as part of the X.Org system or fonts that
10643are part of TeX Live.
10644
10645To make it easier for a user to search for fonts, names for other packages
10646containing only fonts are constructed as follows, independently of the
10647upstream package name.
10648
10649The name of a package containing only one font family starts with
10650@code{font-}; it is followed by the foundry name and a dash @code{-}
10651if the foundry is known, and the font family name, in which spaces are
10652replaced by dashes (and as usual, all upper case letters are transformed
10653to lower case).
10654For example, the Gentium font family by SIL is packaged under the name
10655@code{font-sil-gentium}.
10656
10657For a package containing several font families, the name of the collection
10658is used in the place of the font family name.
10659For instance, the Liberation fonts consist of three families,
10660Liberation Sans, Liberation Serif and Liberation Mono.
10661These could be packaged separately under the names
10662@code{font-liberation-sans} and so on; but as they are distributed together
10663under a common name, we prefer to package them together as
10664@code{font-liberation}.
10665
10666In the case where several formats of the same font family or font collection
10667are packaged separately, a short form of the format, prepended by a dash,
10668is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10669@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10670fonts.
10671
10672
b25937e3 10673
cf4a9129
LC
10674@node Bootstrapping
10675@section Bootstrapping
b25937e3 10676
cf4a9129 10677@c Adapted from the ELS 2013 paper.
b25937e3 10678
cf4a9129 10679@cindex bootstrapping
7889394e 10680
cf4a9129
LC
10681Bootstrapping in our context refers to how the distribution gets built
10682``from nothing''. Remember that the build environment of a derivation
10683contains nothing but its declared inputs (@pxref{Introduction}). So
10684there's an obvious chicken-and-egg problem: how does the first package
10685get built? How does the first compiler get compiled? Note that this is
10686a question of interest only to the curious hacker, not to the regular
10687user, so you can shamelessly skip this section if you consider yourself
10688a ``regular user''.
72b9d60d 10689
cf4a9129
LC
10690@cindex bootstrap binaries
10691The GNU system is primarily made of C code, with libc at its core. The
10692GNU build system itself assumes the availability of a Bourne shell and
10693command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10694`grep'. Furthermore, build programs---programs that run
10695@code{./configure}, @code{make}, etc.---are written in Guile Scheme
10696(@pxref{Derivations}). Consequently, to be able to build anything at
10697all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10698Binutils, libc, and the other packages mentioned above---the
10699@dfn{bootstrap binaries}.
72b9d60d 10700
cf4a9129
LC
10701These bootstrap binaries are ``taken for granted'', though we can also
10702re-create them if needed (more on that later).
72b9d60d 10703
cf4a9129 10704@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 10705
cf4a9129
LC
10706@c As of Emacs 24.3, Info-mode displays the image, but since it's a
10707@c large image, it's hard to scroll. Oh well.
10708@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 10709
cf4a9129
LC
10710The figure above shows the very beginning of the dependency graph of the
10711distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
10712packages bootstrap)} module. A similar figure can be generated with
10713@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
10714
10715@example
10716guix graph -t derivation \
10717 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
10718 | dot -Tps > t.ps
10719@end example
10720
10721At this level of detail, things are
cf4a9129
LC
10722slightly complex. First, Guile itself consists of an ELF executable,
10723along with many source and compiled Scheme files that are dynamically
10724loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10725tarball shown in this graph. This tarball is part of Guix's ``source''
10726distribution, and gets inserted into the store with @code{add-to-store}
10727(@pxref{The Store}).
2e7b5cea 10728
cf4a9129
LC
10729But how do we write a derivation that unpacks this tarball and adds it
10730to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10731derivation---the first one that gets built---uses @code{bash} as its
10732builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10733@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10734@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10735the Guix source distribution, whose sole purpose is to allow the Guile
10736tarball to be unpacked.
fb729425 10737
cf4a9129
LC
10738Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10739Guile that can be used to run subsequent build programs. Its first task
10740is to download tarballs containing the other pre-built binaries---this
10741is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10742@code{ftp-client.scm} are used for this purpose. The
10743@code{module-import.drv} derivations import those modules in a directory
10744in the store, using the original layout. The
10745@code{module-import-compiled.drv} derivations compile those modules, and
10746write them in an output directory with the right layout. This
10747corresponds to the @code{#:modules} argument of
10748@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 10749
cf4a9129
LC
10750Finally, the various tarballs are unpacked by the
10751derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10752etc., at which point we have a working C tool chain.
fb729425 10753
fb729425 10754
cf4a9129 10755@unnumberedsubsec Building the Build Tools
523e4896 10756
cf4a9129
LC
10757Bootstrapping is complete when we have a full tool chain that does not
10758depend on the pre-built bootstrap tools discussed above. This
10759no-dependency requirement is verified by checking whether the files of
10760the final tool chain contain references to the @file{/gnu/store}
10761directories of the bootstrap inputs. The process that leads to this
10762``final'' tool chain is described by the package definitions found in
1f6f57df 10763the @code{(gnu packages commencement)} module.
df2ce343 10764
d33fa0c7
LC
10765The @command{guix graph} command allows us to ``zoom out'' compared to
10766the graph above, by looking at the level of package objects instead of
10767individual derivations---remember that a package may translate to
10768several derivations, typically one derivation to download its source,
10769one to build the Guile modules it needs, and one to actually build the
10770package from source. The command:
10771
10772@example
10773guix graph -t bag \
10774 -e '(@@@@ (gnu packages commencement)
10775 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
10776@end example
10777
10778@noindent
10779produces the dependency graph leading to the ``final'' C
10780library@footnote{You may notice the @code{glibc-intermediate} label,
10781suggesting that it is not @emph{quite} final, but as a good
10782approximation, we will consider it final.}, depicted below.
10783
10784@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
10785
cf4a9129
LC
10786@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10787The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
10788GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
10789for all the following packages. From there Findutils and Diffutils get
10790built.
523e4896 10791
cf4a9129
LC
10792Then come the first-stage Binutils and GCC, built as pseudo cross
10793tools---i.e., with @code{--target} equal to @code{--host}. They are
10794used to build libc. Thanks to this cross-build trick, this libc is
10795guaranteed not to hold any reference to the initial tool chain.
4af2447e 10796
d33fa0c7
LC
10797From there the final Binutils and GCC (not shown above) are built.
10798GCC uses @code{ld}
cf4a9129
LC
10799from the final Binutils, and links programs against the just-built libc.
10800This tool chain is used to build the other packages used by Guix and by
10801the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 10802
cf4a9129
LC
10803And voilà! At this point we have the complete set of build tools that
10804the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
10805variable of the @code{(gnu packages commencement)} module, and are
10806implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 10807(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 10808
4af2447e 10809
cf4a9129 10810@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 10811
cf4a9129
LC
10812Because the final tool chain does not depend on the bootstrap binaries,
10813those rarely need to be updated. Nevertheless, it is useful to have an
10814automated way to produce them, should an update occur, and this is what
10815the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 10816
cf4a9129
LC
10817The following command builds the tarballs containing the bootstrap
10818binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10819of Coreutils and other basic command-line tools):
4b2615e1 10820
cf4a9129
LC
10821@example
10822guix build bootstrap-tarballs
10823@end example
10824
10825The generated tarballs are those that should be referred to in the
10826@code{(gnu packages bootstrap)} module mentioned at the beginning of
10827this section.
10828
10829Still here? Then perhaps by now you've started to wonder: when do we
10830reach a fixed point? That is an interesting question! The answer is
10831unknown, but if you would like to investigate further (and have
10832significant computational and storage resources to do so), then let us
10833know.
10834
10835@node Porting
10836@section Porting to a New Platform
10837
10838As discussed above, the GNU distribution is self-contained, and
10839self-containment is achieved by relying on pre-built ``bootstrap
10840binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10841operating system kernel, CPU architecture, and application binary
10842interface (ABI). Thus, to port the distribution to a platform that is
10843not yet supported, one must build those bootstrap binaries, and update
10844the @code{(gnu packages bootstrap)} module to use them on that platform.
10845
10846Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10847When everything goes well, and assuming the GNU tool chain supports the
10848target platform, this can be as simple as running a command like this
10849one:
10850
10851@example
10852guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10853@end example
10854
1c0c417d
LC
10855For this to work, the @code{glibc-dynamic-linker} procedure in
10856@code{(gnu packages bootstrap)} must be augmented to return the right
10857file name for libc's dynamic linker on that platform; likewise,
10858@code{system->linux-architecture} in @code{(gnu packages linux)} must be
10859taught about the new platform.
10860
cf4a9129 10861Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
10862to be updated to refer to these binaries on the target platform. That
10863is, the hashes and URLs of the bootstrap tarballs for the new platform
10864must be added alongside those of the currently supported platforms. The
10865bootstrap Guile tarball is treated specially: it is expected to be
10866available locally, and @file{gnu-system.am} has rules do download it for
10867the supported architectures; a rule for the new platform must be added
10868as well.
cf4a9129
LC
10869
10870In practice, there may be some complications. First, it may be that the
10871extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10872above) is not recognized by all the GNU tools. Typically, glibc
10873recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10874configure flag (see @code{gcc.scm} for examples of how to handle this).
10875Second, some of the required packages could fail to build for that
10876platform. Lastly, the generated binaries could be broken for some
10877reason.
4af2447e 10878
9bf3c1a7 10879@c *********************************************************************
8c01b9d0 10880@include contributing.texi
c78bd12b 10881
568717fd
LC
10882@c *********************************************************************
10883@node Acknowledgments
10884@chapter Acknowledgments
10885
136787cb
LC
10886Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10887which was designed and
4c7ac9aa
LC
10888implemented by Eelco Dolstra, with contributions from other people (see
10889the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
10890management, and promoted unprecedented features, such as transactional
10891package upgrades and rollbacks, per-user profiles, and referentially
10892transparent build processes. Without this work, Guix would not exist.
10893
10894The Nix-based software distributions, Nixpkgs and NixOS, have also been
10895an inspiration for Guix.
10896
4c7ac9aa
LC
10897GNU@tie{}Guix itself is a collective work with contributions from a
10898number of people. See the @file{AUTHORS} file in Guix for more
10899information on these fine people. The @file{THANKS} file lists people
10900who have helped by reporting bugs, taking care of the infrastructure,
10901providing artwork and themes, making suggestions, and more---thank you!
10902
10903
568717fd
LC
10904@c *********************************************************************
10905@node GNU Free Documentation License
10906@appendix GNU Free Documentation License
10907
10908@include fdl-1.3.texi
10909
10910@c *********************************************************************
10911@node Concept Index
10912@unnumbered Concept Index
10913@printindex cp
10914
a85b83d2
LC
10915@node Programming Index
10916@unnumbered Programming Index
10917@syncodeindex tp fn
10918@syncodeindex vr fn
568717fd
LC
10919@printindex fn
10920
10921@bye
10922
10923@c Local Variables:
10924@c ispell-local-dictionary: "american";
10925@c End: