build: Add Ant build system.
[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
9b7bd1b1
LC
487@item
488Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
489access @code{https} URLs for substitutes, which is highly recommended
490(@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
491@command{guix download} command (@pxref{Invoking guix download}), the
492@command{guix import pypi} command, and the @command{guix import cpan}
493command. @xref{Guile Preparations, how to install the GnuTLS bindings
494for Guile,, gnutls-guile, GnuTLS-Guile}.
495
288dca55 496@item
8a96bd4b 497Installing
288dca55 498@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
499allow you to use the @command{guix import pypi} command (@pxref{Invoking
500guix import}). It is of
288dca55 501interest primarily for developers and not for casual users.
bd5e766b
LC
502@end itemize
503
504Unless @code{--disable-daemon} was passed to @command{configure}, the
505following packages are also needed:
506
507@itemize
368d08f7
LC
508@item @url{http://sqlite.org, SQLite 3};
509@item @url{http://www.bzip.org, libbz2};
510@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
511C++11 standard.
bd5e766b
LC
512@end itemize
513
4bfc4ea3
NK
514When a working installation of @url{http://nixos.org/nix/, the Nix package
515manager} is available, you
bd5e766b 516can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 517Nix replaces the three dependencies above.
bd5e766b 518
b22a12fd
LC
519Guix is compatible with Nix, so it is possible to share the same store
520between both. To do so, you must pass @command{configure} not only the
521same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
522@code{--localstatedir} value. The latter is essential because it
523specifies where the database that stores metadata about the store is
834129e0 524located, among other things. The default values for Nix are
b22a12fd 525@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
526Note that @code{--disable-daemon} is not required if
527your goal is to share the store with Nix.
b22a12fd 528
ec0339cd
LC
529@node Running the Test Suite
530@section Running the Test Suite
531
532After a successful @command{configure} and @code{make} run, it is a good
533idea to run the test suite. It can help catch issues with the setup or
534environment, or bugs in Guix itself---and really, reporting test
535failures is a good way to help improve the software. To run the test
536suite, type:
537
538@example
539make check
540@end example
541
542Test cases can run in parallel: you can use the @code{-j} option of
543GNU@tie{}make to speed things up. The first run may take a few minutes
544on a recent machine; subsequent runs will be faster because the store
545that is created for test purposes will already have various things in
546cache.
547
a887fd8d
LC
548It is also possible to run a subset of the tests by defining the
549@code{TESTS} makefile variable as in this example:
550
551@example
552make check TESTS="tests/store.scm tests/cpio.scm"
553@end example
554
ec0339cd
LC
555Upon failure, please email @email{bug-guix@@gnu.org} and attach the
556@file{test-suite.log} file. When @file{tests/@var{something}.scm}
557fails, please also attach the @file{@var{something}.log} file available
558in the top-level build directory. Please specify the Guix version being
559used as well as version numbers of the dependencies
560(@pxref{Requirements}) in your message.
561
bd5e766b
LC
562@node Setting Up the Daemon
563@section Setting Up the Daemon
564
565@cindex daemon
566Operations such as building a package or running the garbage collector
49e6291a 567are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
568behalf of clients. Only the daemon may access the store and its
569associated database. Thus, any operation that manipulates the store
570goes through the daemon. For instance, command-line tools such as
e49951eb 571@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
572daemon (@i{via} remote procedure calls) to instruct it what to do.
573
49e6291a 574The following sections explain how to prepare the build daemon's
f97c9175 575environment. See also @ref{Substitutes}, for information on how to allow
225dafde 576the daemon to download pre-built binaries.
49e6291a
LC
577
578@menu
579* Build Environment Setup:: Preparing the isolated build environment.
580* Daemon Offload Setup:: Offloading builds to remote machines.
581@end menu
582
583@node Build Environment Setup
584@subsection Build Environment Setup
585
bd5e766b
LC
586In a standard multi-user setup, Guix and its daemon---the
587@command{guix-daemon} program---are installed by the system
834129e0 588administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
589@command{guix-daemon} runs as @code{root}. Unprivileged users may use
590Guix tools to build packages or otherwise access the store, and the
591daemon will do it on their behalf, ensuring that the store is kept in a
592consistent state, and allowing built packages to be shared among users.
593
594@cindex build users
595When @command{guix-daemon} runs as @code{root}, you may not want package
596build processes themselves to run as @code{root} too, for obvious
597security reasons. To avoid that, a special pool of @dfn{build users}
598should be created for use by build processes started by the daemon.
599These build users need not have a shell and a home directory: they will
600just be used when the daemon drops @code{root} privileges in build
601processes. Having several such users allows the daemon to launch
602distinct build processes under separate UIDs, which guarantees that they
603do not interfere with each other---an essential feature since builds are
604regarded as pure functions (@pxref{Introduction}).
605
606On a GNU/Linux system, a build user pool may be created like this (using
607Bash syntax and the @code{shadow} commands):
608
091196b3
LC
609@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
610@c for why `-G' is needed.
bd5e766b 611@example
cfc149dc
LC
612# groupadd --system guixbuild
613# for i in `seq -w 1 10`;
bd5e766b 614 do
cfc149dc
LC
615 useradd -g guixbuild -G guixbuild \
616 -d /var/empty -s `which nologin` \
617 -c "Guix build user $i" --system \
618 guixbuilder$i;
bd5e766b
LC
619 done
620@end example
621
622@noindent
54eb03ab
LC
623The number of build users determines how many build jobs may run in
624parallel, as specified by the @option{--max-jobs} option
d2825c96
LC
625(@pxref{Invoking guix-daemon, @option{--max-jobs}}). The
626@code{guix-daemon} program may then be run as @code{root} with the
627following command@footnote{If your machine uses the systemd init system,
628dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
629file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
630@command{guix-daemon} is automatically started. Similarly, if your
631machine uses the Upstart init system, drop the
632@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
633file in @file{/etc/init}.}:
bd5e766b
LC
634
635@example
cfc149dc 636# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
637@end example
638
e900c503 639@cindex chroot
b095792f
LC
640@noindent
641This way, the daemon starts build processes in a chroot, under one of
cfc149dc 642the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
643environment contains nothing but:
644
645@c Keep this list in sync with libstore/build.cc! -----------------------
646@itemize
647@item
4743a4da
LC
648a minimal @code{/dev} directory, created mostly independently from the
649host @code{/dev}@footnote{``Mostly'', because while the set of files
650that appear in the chroot's @code{/dev} is fixed, most of these files
651can only be created if the host has them.};
652
653@item
f97c9175 654the @code{/proc} directory; it only shows the processes of the container
4743a4da 655since a separate PID name space is used;
6dc99317
LC
656
657@item
658@file{/etc/passwd} with an entry for the current user and an entry for
659user @file{nobody};
660
661@item
662@file{/etc/group} with an entry for the user's group;
663
664@item
665@file{/etc/hosts} with an entry that maps @code{localhost} to
666@code{127.0.0.1};
667
668@item
669a writable @file{/tmp} directory.
670@end itemize
b095792f 671
cb960102
ED
672You can influence the directory where the daemon stores build trees
673@i{via} the @code{TMPDIR} environment variable. However, the build tree
f97c9175 674within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
675where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
676This way, the value of @code{TMPDIR} does not leak inside build
677environments, which avoids discrepancies in cases where build processes
678capture the name of their build tree.
679
e0c941fe
LC
680@vindex http_proxy
681The daemon also honors the @code{http_proxy} environment variable for
682HTTP downloads it performs, be it for fixed-output derivations
683(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
684
1e2644bb
LC
685If you are installing Guix as an unprivileged user, it is still possible
686to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
687However, build processes will not be isolated from one another, and not
688from the rest of the system. Thus, build processes may interfere with
689each other, and may access programs, libraries, and other files
690available on the system---making it much harder to view them as
691@emph{pure} functions.
bd5e766b 692
49e6291a
LC
693
694@node Daemon Offload Setup
695@subsection Using the Offload Facility
696
697@cindex offloading
4ec2e92d
LC
698@cindex build hook
699When desired, the build daemon can @dfn{offload}
700derivation builds to other machines
49e6291a
LC
701running Guix, using the @code{offload} @dfn{build hook}. When that
702feature is enabled, a list of user-specified build machines is read from
f97c9175 703@file{/etc/guix/machines.scm}; every time a build is requested, for
49e6291a 704instance via @code{guix build}, the daemon attempts to offload it to one
f97c9175 705of the machines that satisfy the constraints of the derivation, in
49e6291a
LC
706particular its system type---e.g., @file{x86_64-linux}. Missing
707prerequisites for the build are copied over SSH to the target machine,
708which then proceeds with the build; upon success the output(s) of the
709build are copied back to the initial machine.
710
4ec2e92d 711The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
712
713@example
714(list (build-machine
715 (name "eightysix.example.org")
716 (system "x86_64-linux")
717 (user "bob")
718 (speed 2.)) ; incredibly fast!
719
720 (build-machine
721 (name "meeps.example.org")
722 (system "mips64el-linux")
723 (user "alice")
724 (private-key
725 (string-append (getenv "HOME")
c4fdfd6f 726 "/.lsh/identity-for-guix"))))
49e6291a
LC
727@end example
728
729@noindent
730In the example above we specify a list of two build machines, one for
731the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
732architecture.
733
734In fact, this file is---not surprisingly!---a Scheme file that is
735evaluated when the @code{offload} hook is started. Its return value
736must be a list of @code{build-machine} objects. While this example
737shows a fixed list of build machines, one could imagine, say, using
738DNS-SD to return a list of potential build machines discovered in the
739local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
740Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
741detailed below.
4ec2e92d 742
c678a4ee 743@deftp {Data Type} build-machine
f97c9175
AE
744This data type represents build machines to which the daemon may offload
745builds. The important fields are:
49e6291a
LC
746
747@table @code
748
749@item name
f97c9175 750The host name of the remote machine.
49e6291a
LC
751
752@item system
f97c9175 753The system type of the remote machine---e.g., @code{"x86_64-linux"}.
49e6291a
LC
754
755@item user
756The user account to use when connecting to the remote machine over SSH.
757Note that the SSH key pair must @emph{not} be passphrase-protected, to
758allow non-interactive logins.
759
760@end table
761
4ec2e92d 762A number of optional fields may be specified:
49e6291a
LC
763
764@table @code
765
cecd72d5 766@item port
f97c9175 767Port number of SSH server on the machine (default: 22).
cecd72d5 768
49e6291a
LC
769@item private-key
770The SSH private key file to use when connecting to the machine.
771
c4fdfd6f
LC
772Currently offloading uses GNU@tie{}lsh as its SSH client
773(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
774be an lsh key file. This may change in the future, though.
775
49e6291a
LC
776@item parallel-builds
777The number of builds that may run in parallel on the machine (1 by
778default.)
779
780@item speed
781A ``relative speed factor''. The offload scheduler will tend to prefer
782machines with a higher speed factor.
783
784@item features
785A list of strings denoting specific features supported by the machine.
786An example is @code{"kvm"} for machines that have the KVM Linux modules
787and corresponding hardware support. Derivations can request features by
788name, and they will be scheduled on matching build machines.
789
790@end table
c678a4ee 791@end deftp
49e6291a
LC
792
793The @code{guix} command must be in the search path on the build
794machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
795@code{guix build} commands. In addition, the Guix modules must be in
796@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
797this is the case by running:
798
799@example
74273b6f 800lsh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 801@end example
49e6291a 802
f97c9175 803There is one last thing to do once @file{machines.scm} is in place. As
49e6291a 804explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
805between the machine stores. For this to work, you first need to
806generate a key pair on each machine to allow the daemon to export signed
807archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
808
809@example
810# guix archive --generate-key
811@end example
812
813@noindent
c4fdfd6f
LC
814Each build machine must authorize the key of the master machine so that
815it accepts store items it receives from the master:
816
817@example
818# guix archive --authorize < master-public-key.txt
819@end example
820
821@noindent
822Likewise, the master machine must authorize the key of each build machine.
823
824All the fuss with keys is here to express pairwise mutual trust
825relations between the master and the build machines. Concretely, when
826the master receives files from a build machine (and @i{vice versa}), its
827build daemon can make sure they are genuine, have not been tampered
828with, and that they are signed by an authorized key.
49e6291a
LC
829
830
bd5e766b
LC
831@node Invoking guix-daemon
832@section Invoking @command{guix-daemon}
833
834The @command{guix-daemon} program implements all the functionality to
835access the store. This includes launching build processes, running the
836garbage collector, querying the availability of a build result, etc. It
837is normally run as @code{root} like this:
838
839@example
cfc149dc 840# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
841@end example
842
843@noindent
081145cf 844For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 845
e900c503
LC
846@cindex chroot
847@cindex container, build environment
848@cindex build environment
849@cindex reproducible builds
bd5e766b
LC
850By default, @command{guix-daemon} launches build processes under
851different UIDs, taken from the build group specified with
852@code{--build-users-group}. In addition, each build process is run in a
853chroot environment that only contains the subset of the store that the
854build process depends on, as specified by its derivation
855(@pxref{Programming Interface, derivation}), plus a set of specific
856system directories. By default, the latter contains @file{/dev} and
e900c503
LC
857@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
858@dfn{container}: in addition to having its own file system tree, it has
859a separate mount name space, its own PID name space, network name space,
860etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 861
cbc538fe
LC
862When the daemon performs a build on behalf of the user, it creates a
863build directory under @file{/tmp} or under the directory specified by
864its @code{TMPDIR} environment variable; this directory is shared with
865the container for the duration of the build. Be aware that using a
866directory other than @file{/tmp} can affect build results---for example,
867with a longer directory name, a build process that uses Unix-domain
868sockets might hit the name length limitation for @code{sun_path}, which
869it would otherwise not hit.
870
871The build directory is automatically deleted upon completion, unless the
872build failed and the client specified @option{--keep-failed}
873(@pxref{Invoking guix build, @option{--keep-failed}}).
874
bd5e766b
LC
875The following command-line options are supported:
876
877@table @code
878@item --build-users-group=@var{group}
879Take users from @var{group} to run build processes (@pxref{Setting Up
880the Daemon, build users}).
881
6858f9d1 882@item --no-substitutes
b5385b52 883@cindex substitutes
6858f9d1 884Do not use substitutes for build products. That is, always build things
c4202d60
LC
885locally instead of allowing downloads of pre-built binaries
886(@pxref{Substitutes}).
6858f9d1 887
b5385b52
LC
888By default substitutes are used, unless the client---such as the
889@command{guix package} command---is explicitly invoked with
890@code{--no-substitutes}.
891
892When the daemon runs with @code{--no-substitutes}, clients can still
893explicitly enable substitution @i{via} the @code{set-build-options}
894remote procedure call (@pxref{The Store}).
895
9176607e 896@item --substitute-urls=@var{urls}
f8a8e0fe 897@anchor{daemon-substitute-urls}
9176607e 898Consider @var{urls} the default whitespace-separated list of substitute
ae806096 899source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org}
9176607e
LC
900is used.
901
902This means that substitutes may be downloaded from @var{urls}, as long
903as they are signed by a trusted signature (@pxref{Substitutes}).
904
4ec2e92d
LC
905@cindex build hook
906@item --no-build-hook
907Do not use the @dfn{build hook}.
908
909The build hook is a helper program that the daemon can start and to
910which it submits build requests. This mechanism is used to offload
911builds to other machines (@pxref{Daemon Offload Setup}).
912
bd5e766b
LC
913@item --cache-failures
914Cache build failures. By default, only successful builds are cached.
915
30d9aa54
LC
916When this option is used, @command{guix gc --list-failures} can be used
917to query the set of store items marked as failed; @command{guix gc
918--clear-failures} removes store items from the set of cached failures.
919@xref{Invoking guix gc}.
920
bd5e766b
LC
921@item --cores=@var{n}
922@itemx -c @var{n}
923Use @var{n} CPU cores to build each derivation; @code{0} means as many
924as available.
925
6efc160e 926The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
927as the @code{--cores} option of @command{guix build} (@pxref{Invoking
928guix build}).
bd5e766b
LC
929
930The effect is to define the @code{NIX_BUILD_CORES} environment variable
931in the build process, which can then use it to exploit internal
932parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
933
934@item --max-jobs=@var{n}
935@itemx -M @var{n}
936Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
937@code{1}. Setting it to @code{0} means that no builds will be performed
938locally; instead, the daemon will offload builds (@pxref{Daemon Offload
939Setup}), or simply fail.
bd5e766b 940
ecf84b7c
LC
941@item --rounds=@var{N}
942Build each derivation @var{n} times in a row, and raise an error if
943consecutive build results are not bit-for-bit identical. Note that this
944setting can be overridden by clients such as @command{guix build}
945(@pxref{Invoking guix build}).
946
bd5e766b
LC
947@item --debug
948Produce debugging output.
949
950This is useful to debug daemon start-up issues, but then it may be
951overridden by clients, for example the @code{--verbosity} option of
e49951eb 952@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
953
954@item --chroot-directory=@var{dir}
955Add @var{dir} to the build chroot.
956
957Doing this may change the result of build processes---for instance if
958they use optional dependencies found in @var{dir} when it is available,
959and not otherwise. For that reason, it is not recommended to do so.
960Instead, make sure that each derivation declares all the inputs that it
961needs.
962
963@item --disable-chroot
964Disable chroot builds.
965
966Using this option is not recommended since, again, it would allow build
1e2644bb
LC
967processes to gain access to undeclared dependencies. It is necessary,
968though, when @command{guix-daemon} is running under an unprivileged user
969account.
bd5e766b
LC
970
971@item --disable-log-compression
972Disable compression of the build logs.
973
1da983b9
LC
974Unless @code{--lose-logs} is used, all the build logs are kept in the
975@var{localstatedir}. To save space, the daemon automatically compresses
976them with bzip2 by default. This option disables that.
977
ab3893d7
LC
978@item --disable-deduplication
979@cindex deduplication
bd5e766b
LC
980Disable automatic file ``deduplication'' in the store.
981
1da983b9 982By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
983if a newly added file is identical to another one found in the store,
984the daemon makes the new file a hard link to the other file. This can
4988dd40 985noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
986input/output load at the end of a build process. This option disables
987this optimization.
1da983b9 988
6e37066e
LC
989@item --gc-keep-outputs[=yes|no]
990Tell whether the garbage collector (GC) must keep outputs of live
991derivations.
992
993When set to ``yes'', the GC will keep the outputs of any live derivation
994available in the store---the @code{.drv} files. The default is ``no'',
995meaning that derivation outputs are kept only if they are GC roots.
996
997@item --gc-keep-derivations[=yes|no]
998Tell whether the garbage collector (GC) must keep derivations
999corresponding to live outputs.
1000
1001When set to ``yes'', as is the case by default, the GC keeps
1002derivations---i.e., @code{.drv} files---as long as at least one of their
1003outputs is live. This allows users to keep track of the origins of
1004items in their store. Setting it to ``no'' saves a bit of disk space.
1005
1006Note that when both @code{--gc-keep-derivations} and
1007@code{--gc-keep-outputs} are used, the effect is to keep all the build
1008prerequisites (the sources, compiler, libraries, and other build-time
1009tools) of live objects in the store, regardless of whether these
1010prerequisites are live. This is convenient for developers since it
1011saves rebuilds or downloads.
1012
bd5e766b
LC
1013@item --impersonate-linux-2.6
1014On Linux-based systems, impersonate Linux 2.6. This means that the
1015kernel's @code{uname} system call will report 2.6 as the release number.
1016
1017This might be helpful to build programs that (usually wrongfully) depend
1018on the kernel version number.
1019
1020@item --lose-logs
1021Do not keep build logs. By default they are kept under
ce33631f 1022@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
1023
1024@item --system=@var{system}
1025Assume @var{system} as the current system type. By default it is the
1026architecture/kernel pair found at configure time, such as
1027@code{x86_64-linux}.
b8d2aa26
LC
1028
1029@item --listen=@var{socket}
1030Listen for connections on @var{socket}, the file name of a Unix-domain
1031socket. The default socket is
1032@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1033useful in exceptional circumstances, such as if you need to run several
1034daemons on the same machine.
bd5e766b
LC
1035@end table
1036
1037
0e2d0213
LC
1038@node Application Setup
1039@section Application Setup
1040
85e57214
LC
1041When using Guix on top of GNU/Linux distribution other than GuixSD---a
1042so-called @dfn{foreign distro}---a few additional steps are needed to
1043get everything in place. Here are some of them.
0e2d0213
LC
1044
1045@subsection Locales
1046
5c3c1427 1047@anchor{locales-and-locpath}
0e2d0213 1048@cindex locales, when not on GuixSD
5c3c1427 1049@vindex LOCPATH
85e57214 1050@vindex GUIX_LOCPATH
f97c9175
AE
1051Packages installed @i{via} Guix will not use the locale data of the
1052host system. Instead, you must first install one of the locale packages
85e57214
LC
1053available with Guix and then define the @code{GUIX_LOCPATH} environment
1054variable:
0e2d0213
LC
1055
1056@example
1057$ guix package -i glibc-locales
85e57214 1058$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1059@end example
1060
1061Note that the @code{glibc-locales} package contains data for all the
1062locales supported by the GNU@tie{}libc and weighs in at around
f97c9175 1063110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
0e2d0213
LC
1064limited to a few UTF-8 locales.
1065
85e57214
LC
1066The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1067(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1068Manual}). There are two important differences though:
1069
1070@enumerate
1071@item
f97c9175 1072@code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
85e57214 1073provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f97c9175 1074to make sure the programs of the foreign distro will not end up loading
85e57214
LC
1075incompatible locale data.
1076
1077@item
1078libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1079@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1080should your Guix profile contain a mixture of programs linked against
1081different libc version, each libc version will only try to load locale
1082data in the right format.
1083@end enumerate
1084
1085This is important because the locale data format used by different libc
1086versions may be incompatible.
1087
0e2d0213
LC
1088@subsection X11 Fonts
1089
4988dd40 1090The majority of graphical applications use Fontconfig to locate and
f97c9175
AE
1091load fonts and perform X11-client-side rendering. The @code{fontconfig}
1092package in Guix looks for fonts in @file{$HOME/.guix-profile}
0e2d0213 1093by default. Thus, to allow graphical applications installed with Guix
f97c9175 1094to display fonts, you have to install fonts with Guix as well.
0e2d0213 1095Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1096@code{font-gnu-freefont-ttf}.
0e2d0213 1097
5c36edc8
LC
1098To display text written in Chinese languages, Japanese, or Korean in
1099graphical applications, consider installing
1100@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1101has multiple outputs, one per language family (@pxref{Packages with
1102Multiple Outputs}). For instance, the following command installs fonts
1103for Chinese languages:
1104
1105@example
1106guix package -i font-adobe-source-han-sans:cn
1107@end example
1108
6d97319c
AK
1109@subsection Emacs Packages
1110
1111When you install Emacs packages with Guix, the elisp files may be placed
1112either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1113sub-directories of
1114@file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1115directory exists because potentially there may exist thousands of Emacs
1116packages and storing all their files in a single directory may be not
1117reliable (because of name conflicts). So we think using a separate
1118directory for each package is a good idea. It is very similar to how
1119the Emacs package system organizes the file structure (@pxref{Package
1120Files,,, emacs, The GNU Emacs Manual}).
1121
1122By default, Emacs (installed with Guix) ``knows'' where these packages
f97c9175 1123are placed, so you do not need to perform any configuration. If, for
6d97319c 1124some reason, you want to avoid auto-loading Emacs packages installed
f97c9175 1125with Guix, you can do so by running Emacs with @code{--no-site-file}
6d97319c
AK
1126option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1127
0e2d0213
LC
1128@c TODO What else?
1129
eeaf4427
LC
1130@c *********************************************************************
1131@node Package Management
1132@chapter Package Management
1133
f8348b91 1134The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427 1135remove software packages, without having to know about their build
f97c9175 1136procedures or dependencies. Guix also goes beyond this obvious set of
eeaf4427
LC
1137features.
1138
1139This chapter describes the main features of Guix, as well as the package
c1941588 1140management tools it provides. Two user interfaces are provided for
c554de89
AK
1141routine package management tasks: A command-line interface described below
1142(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1143interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
1144
1145@menu
1146* Features:: How Guix will make your life brighter.
e49951eb 1147* Invoking guix package:: Package installation, removal, etc.
c4202d60 1148* Substitutes:: Downloading pre-built binaries.
760c60d6 1149* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1150* Invoking guix gc:: Running the garbage collector.
f651b477 1151* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1152* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1153@end menu
1154
1155@node Features
1156@section Features
1157
1158When using Guix, each package ends up in the @dfn{package store}, in its
1159own directory---something that resembles
9a130e19
AK
1160@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1161(note that Guix comes with an Emacs extension to shorten those file
081145cf 1162names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1163
1164Instead of referring to these directories, users have their own
1165@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1166use. These profiles are stored within each user's home directory, at
1167@code{$HOME/.guix-profile}.
eeaf4427 1168
821b0015 1169For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1170@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1171@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1172@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1173simply continues to point to
834129e0 1174@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1175coexist on the same system without any interference.
eeaf4427 1176
e49951eb 1177The @command{guix package} command is the central tool to manage
f97c9175 1178packages (@pxref{Invoking guix package}). It operates on the per-user
821b0015 1179profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
1180
1181The command provides the obvious install, remove, and upgrade
1182operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1183the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1184@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1185or if a power outage occurs during the transaction, then the user's
1186profile remains in its previous state, and remains usable.
1187
1188In addition, any package transaction may be @emph{rolled back}. So, if,
1189for example, an upgrade installs a new version of a package that turns
1190out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
1191of their profile, which was known to work well. Similarly, the global
1192system configuration is subject to transactional upgrades and roll-back
1193(@pxref{Using the Configuration System}).
eeaf4427 1194
f97c9175
AE
1195All packages in the package store may be @emph{garbage-collected}.
1196Guix can determine which packages are still referenced by user
fe8ff028 1197profiles, and remove those that are provably no longer referenced
e49951eb 1198(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1199generations of their profile so that the packages they refer to can be
1200collected.
eeaf4427 1201
e900c503
LC
1202@cindex reproducibility
1203@cindex reproducible builds
eeaf4427
LC
1204Finally, Guix takes a @dfn{purely functional} approach to package
1205management, as described in the introduction (@pxref{Introduction}).
834129e0 1206Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1207inputs that were used to build that package---compiler, libraries, build
1208scripts, etc. This direct correspondence allows users to make sure a
1209given package installation matches the current state of their
e900c503
LC
1210distribution. It also helps maximize @dfn{build reproducibility}:
1211thanks to the isolated build environments that are used, a given build
1212is likely to yield bit-identical files when performed on different
1213machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1214
c4202d60 1215@cindex substitutes
eeaf4427 1216This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1217deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1218available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1219downloads it and unpacks it;
1220otherwise, it builds the package from source, locally
1221(@pxref{Substitutes}).
eeaf4427 1222
f5fd4fd2
LC
1223Control over the build environment is a feature that is also useful for
1224developers. The @command{guix environment} command allows developers of
1225a package to quickly set up the right development environment for their
f97c9175
AE
1226package, without having to manually install the dependencies of the
1227package into their profile (@pxref{Invoking guix environment}).
f5fd4fd2 1228
e49951eb
MW
1229@node Invoking guix package
1230@section Invoking @command{guix package}
eeaf4427 1231
e49951eb 1232The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1233install, upgrade, and remove packages, as well as rolling back to
1234previous configurations. It operates only on the user's own profile,
1235and works with normal user privileges (@pxref{Features}). Its syntax
1236is:
1237
1238@example
e49951eb 1239guix package @var{options}
eeaf4427
LC
1240@end example
1241
ba55b1cb 1242Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1243the transaction. Upon completion, a new profile is created, but
99bd74d5 1244previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1245want to roll back.
1246
6447738c
MW
1247For example, to remove @code{lua} and install @code{guile} and
1248@code{guile-cairo} in a single transaction:
1249
1250@example
1251guix package -r lua -i guile guile-cairo
1252@end example
1253
99bd74d5
LC
1254@command{guix package} also supports a @dfn{declarative approach}
1255whereby the user specifies the exact set of packages to be available and
1256passes it @i{via} the @option{--manifest} option
1257(@pxref{profile-manifest, @option{--manifest}}).
1258
b9e5c0a9 1259For each user, a symlink to the user's default profile is automatically
0ec1af59 1260created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1261current generation of the user's default profile. Thus, users can add
1262@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1263variable, and so on.
d664f1b4
LC
1264@cindex search paths
1265If you are not using the Guix System Distribution, consider adding the
1266following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1267Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1268shells get all the right environment variable definitions:
1269
1270@example
1271GUIX_PROFILE="$HOME/.guix-profile" \
1272source "$HOME/.guix-profile/etc/profile"
1273@end example
b9e5c0a9 1274
4379c35b
LC
1275In a multi-user setup, user profiles are stored in a place registered as
1276a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1277to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1278@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1279@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1280@code{--localstatedir}, and @var{user} is the user name. The
1281@file{per-user} directory is created when @command{guix-daemon} is
1282started, and the @var{user} sub-directory is created by @command{guix
1283package}.
0ec1af59
LC
1284
1285The @var{options} can be among the following:
1286
eeaf4427
LC
1287@table @code
1288
6447738c
MW
1289@item --install=@var{package} @dots{}
1290@itemx -i @var{package} @dots{}
1291Install the specified @var{package}s.
eeaf4427 1292
6447738c 1293Each @var{package} may specify either a simple package name, such as
1b846da8
ML
1294@code{guile}, or a package name followed by an at-sign and version number,
1295such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
724311a2
LC
1296case, the newest version prefixed by @code{1.8} is selected.)
1297
1298If no version number is specified, the
dc5669cd
MW
1299newest available version will be selected. In addition, @var{package}
1300may contain a colon, followed by the name of one of the outputs of the
1b846da8 1301package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
e7f34eb0
LC
1302(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1303name (and optionally version) are searched for among the GNU
1304distribution modules (@pxref{Package Modules}).
eeaf4427 1305
461572cc
LC
1306@cindex propagated inputs
1307Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1308that automatically get installed along with the required package
1309(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1310@code{package} objects}, for information about propagated inputs in
1311package definitions).
461572cc 1312
21461f27 1313@anchor{package-cmd-propagated-inputs}
461572cc
LC
1314An example is the GNU MPC library: its C header files refer to those of
1315the GNU MPFR library, which in turn refer to those of the GMP library.
1316Thus, when installing MPC, the MPFR and GMP libraries also get installed
1317in the profile; removing MPC also removes MPFR and GMP---unless they had
f97c9175 1318also been explicitly installed by the user.
461572cc 1319
ba7ea5ce 1320Besides, packages sometimes rely on the definition of environment
5924080d 1321variables for their search paths (see explanation of
ba7ea5ce 1322@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1323environment variable definitions are reported here.
1324
ef010c0f 1325@c XXX: keep me up-to-date
5924080d 1326Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
1327availability of a newer upstream version. In the future, it may provide
1328the option of installing directly from the upstream version, even if
1329that version is not yet in the distribution.
1330
5d4b411f
LC
1331@item --install-from-expression=@var{exp}
1332@itemx -e @var{exp}
1333Install the package @var{exp} evaluates to.
1334
1335@var{exp} must be a Scheme expression that evaluates to a
1336@code{<package>} object. This option is notably useful to disambiguate
1337between same-named variants of a package, with expressions such as
1338@code{(@@ (gnu packages base) guile-final)}.
1339
1340Note that this option installs the first output of the specified
1341package, which may be insufficient when needing a specific output of a
1342multiple-output package.
1343
0d279400
DT
1344@item --install-from-file=@var{file}
1345@itemx -f @var{file}
1346Install the package that the code within @var{file} evaluates to.
1347
1348As an example, @var{file} might contain a definition like this
1349(@pxref{Defining Packages}):
1350
1351@example
1352@verbatiminclude package-hello.scm
1353@end example
1354
baacf042 1355Developers may find it useful to include such a @file{guix.scm} file
f97c9175 1356in the root of their project source tree that can be used to test
0d279400
DT
1357development snapshots and create reproducible development environments
1358(@pxref{Invoking guix environment}).
1359
6447738c
MW
1360@item --remove=@var{package} @dots{}
1361@itemx -r @var{package} @dots{}
1362Remove the specified @var{package}s.
eeaf4427 1363
6447738c 1364As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1365and/or output name in addition to the package name. For instance,
1366@code{-r glibc:debug} would remove the @code{debug} output of
1367@code{glibc}.
1368
6447738c
MW
1369@item --upgrade[=@var{regexp} @dots{}]
1370@itemx -u [@var{regexp} @dots{}]
1371Upgrade all the installed packages. If one or more @var{regexp}s are
1372specified, upgrade only installed packages whose name matches a
d5f01e48 1373@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1374
f651b477
LC
1375Note that this upgrades package to the latest version of packages found
1376in the distribution currently installed. To update your distribution,
1377you should regularly run @command{guix pull} (@pxref{Invoking guix
1378pull}).
1379
d5f01e48
MW
1380@item --do-not-upgrade[=@var{regexp} @dots{}]
1381When used together with the @code{--upgrade} option, do @emph{not}
1382upgrade any packages whose name matches a @var{regexp}. For example, to
1383upgrade all packages in the current profile except those containing the
1384substring ``emacs'':
1385
1386@example
1387$ guix package --upgrade . --do-not-upgrade emacs
1388@end example
1389
99bd74d5 1390@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1391@itemx -m @var{file}
99bd74d5
LC
1392@cindex profile declaration
1393@cindex profile manifest
1394Create a new generation of the profile from the manifest object
1b676447
DT
1395returned by the Scheme code in @var{file}.
1396
99bd74d5
LC
1397This allows you to @emph{declare} the profile's contents rather than
1398constructing it through a sequence of @code{--install} and similar
1399commands. The advantage is that @var{file} can be put under version
1400control, copied to different machines to reproduce the same profile, and
1401so on.
1402
1403@c FIXME: Add reference to (guix profile) documentation when available.
1404@var{file} must return a @dfn{manifest} object, which is roughly a list
1405of packages:
1b676447 1406
99bd74d5 1407@findex packages->manifest
1b676447 1408@example
99bd74d5 1409(use-package-modules guile emacs)
1b676447
DT
1410
1411(packages->manifest
99bd74d5
LC
1412 (list emacs
1413 guile-2.0
1b676447 1414 ;; Use a specific package output.
99bd74d5 1415 (list guile-2.0 "debug")))
1b676447
DT
1416@end example
1417
24e262f0
LC
1418@item --roll-back
1419Roll back to the previous @dfn{generation} of the profile---i.e., undo
1420the last transaction.
1421
1422When combined with options such as @code{--install}, roll back occurs
1423before any other actions.
1424
d9307267 1425When rolling back from the first generation that actually contains
4b2bc804 1426installed packages, the profile is made to point to the @dfn{zeroth
f97c9175 1427generation}, which contains no files apart from its own metadata.
d9307267 1428
f97c9175
AE
1429After having rolled back, installing, removing, or upgrading packages
1430overwrites previous future generations. Thus, the history of the
1431generations in a profile is always linear.
82fe08ed 1432
b3bb82f1
AK
1433@item --switch-generation=@var{pattern}
1434@itemx -S @var{pattern}
1435Switch to a particular generation defined by @var{pattern}.
1436
1437@var{pattern} may be either a generation number or a number prefixed
1438with ``+'' or ``-''. The latter means: move forward/backward by a
1439specified number of generations. For example, if you want to return to
1440the latest generation after @code{--roll-back}, use
1441@code{--switch-generation=+1}.
1442
1443The difference between @code{--roll-back} and
1444@code{--switch-generation=-1} is that @code{--switch-generation} will
1445not make a zeroth generation, so if a specified generation does not
1446exist, the current generation will not be changed.
1447
dbc31ab2 1448@item --search-paths[=@var{kind}]
5924080d
LC
1449@cindex search paths
1450Report environment variable definitions, in Bash syntax, that may be
1451needed in order to use the set of installed packages. These environment
1452variables are used to specify @dfn{search paths} for files used by some
1453of the installed packages.
1454
1455For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1456environment variables to be defined so it can look for headers and
1457libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1458Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1459library are installed in the profile, then @code{--search-paths} will
1460suggest setting these variables to @code{@var{profile}/include} and
1461@code{@var{profile}/lib}, respectively.
1462
dbc31ab2
LC
1463The typical use case is to define these environment variables in the
1464shell:
1465
1466@example
1467$ eval `guix package --search-paths`
1468@end example
1469
1470@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1471meaning that the returned environment variable definitions will either
1472be exact settings, or prefixes or suffixes of the current value of these
1473variables. When omitted, @var{kind} defaults to @code{exact}.
1474
fc2d2339
LC
1475This option can also be used to compute the @emph{combined} search paths
1476of several profiles. Consider this example:
1477
1478@example
1479$ guix package -p foo -i guile
1480$ guix package -p bar -i guile-json
1481$ guix package -p foo -p bar --search-paths
1482@end example
1483
1484The last command above reports about the @code{GUILE_LOAD_PATH}
1485variable, even though, taken individually, neither @file{foo} nor
1486@file{bar} would lead to that recommendation.
1487
1488
eeaf4427
LC
1489@item --profile=@var{profile}
1490@itemx -p @var{profile}
1491Use @var{profile} instead of the user's default profile.
1492
70915c1a 1493@item --verbose
f97c9175
AE
1494Produce verbose output. In particular, emit the build log of the
1495environment on the standard error port.
70915c1a 1496
eeaf4427
LC
1497@item --bootstrap
1498Use the bootstrap Guile to build the profile. This option is only
1499useful to distribution developers.
1500
1501@end table
1502
f97c9175 1503In addition to these actions, @command{guix package} supports the
733b4130
LC
1504following options to query the current state of a profile, or the
1505availability of packages:
eeaf4427 1506
733b4130
LC
1507@table @option
1508
acc08466
NK
1509@item --search=@var{regexp}
1510@itemx -s @var{regexp}
b110869d 1511@cindex searching for packages
5763ad92 1512List the available packages whose name, synopsis, or description matches
f97c9175 1513@var{regexp}. Print all the metadata of matching packages in
299112d3
LC
1514@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1515GNU recutils manual}).
acc08466 1516
299112d3
LC
1517This allows specific fields to be extracted using the @command{recsel}
1518command, for instance:
1519
1520@example
e49951eb 1521$ guix package -s malloc | recsel -p name,version
299112d3
LC
1522name: glibc
1523version: 2.17
1524
1525name: libgc
1526version: 7.2alpha6
1527@end example
acc08466 1528
a12d92f5
LC
1529Similarly, to show the name of all the packages available under the
1530terms of the GNU@tie{}LGPL version 3:
1531
1532@example
1533$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1534name: elfutils
1535
1536name: gmp
1537@dots{}
1538@end example
1539
db5a9444
LC
1540It is also possible to refine search results using several @code{-s}
1541flags. For example, the following command returns a list of board
1542games:
1543
1544@example
1545$ guix package -s '\<board\>' -s game | recsel -p name
1546name: gnubg
1547@dots{}
1548@end example
1549
1550If we were to omit @code{-s game}, we would also get software packages
1551that deal with printed circuit boards; removing the angle brackets
1552around @code{board} would further add packages that have to do with
1553keyboards.
1554
b110869d
LC
1555And now for a more elaborate example. The following command searches
1556for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1557libraries, and prints the name and synopsis of the matching packages:
1558
1559@example
1560$ guix package -s crypto -s library | \
1561 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1562@end example
1563
1564@noindent
1565@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1566information on @dfn{selection expressions} for @code{recsel -e}.
1567
2aa6efb0
CR
1568@item --show=@var{package}
1569Show details about @var{package}, taken from the list of available packages, in
1570@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1571recutils manual}).
1572
1573@example
1574$ guix package --show=python | recsel -p name,version
1575name: python
1576version: 2.7.6
1577
1578name: python
1579version: 3.3.5
1580@end example
1581
1582You may also specify the full name of a package to only get details about a
1583specific version of it:
1584@example
1585$ guix package --show=python-3.3.5 | recsel -p name,version
1586name: python
1587version: 3.3.5
1588@end example
1589
1590
1591
733b4130
LC
1592@item --list-installed[=@var{regexp}]
1593@itemx -I [@var{regexp}]
bd9bde1c
LC
1594List the currently installed packages in the specified profile, with the
1595most recently installed packages shown last. When @var{regexp} is
1596specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1597
1598For each installed package, print the following items, separated by
1599tabs: the package name, its version string, the part of the package that
1600is installed (for instance, @code{out} for the default output,
1601@code{include} for its headers, etc.), and the path of this package in
1602the store.
1603
64fc89b6
LC
1604@item --list-available[=@var{regexp}]
1605@itemx -A [@var{regexp}]
5763ad92 1606List packages currently available in the distribution for this system
a1ba8475
LC
1607(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1608installed packages whose name matches @var{regexp}.
64fc89b6
LC
1609
1610For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1611its version string, the parts of the package (@pxref{Packages with
1612Multiple Outputs}), and the source location of its definition.
64fc89b6 1613
f566d765
LC
1614@item --list-generations[=@var{pattern}]
1615@itemx -l [@var{pattern}]
1616Return a list of generations along with their creation dates; for each
1617generation, show the installed packages, with the most recently
4b2bc804
NK
1618installed packages shown last. Note that the zeroth generation is never
1619shown.
f566d765
LC
1620
1621For each installed package, print the following items, separated by
1622tabs: the name of a package, its version string, the part of the package
1623that is installed (@pxref{Packages with Multiple Outputs}), and the
1624location of this package in the store.
1625
1626When @var{pattern} is used, the command returns only matching
1627generations. Valid patterns include:
1628
1629@itemize
1630@item @emph{Integers and comma-separated integers}. Both patterns denote
1631generation numbers. For instance, @code{--list-generations=1} returns
1632the first one.
1633
1634And @code{--list-generations=1,8,2} outputs three generations in the
1635specified order. Neither spaces nor trailing commas are allowed.
1636
1637@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1638specified generations and everything in between. Note that the start of
f97c9175 1639a range must be smaller than its end.
f566d765
LC
1640
1641It is also possible to omit the endpoint. For example,
1642@code{--list-generations=2..}, returns all generations starting from the
1643second one.
1644
1645@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1646or months by passing an integer along with the first letter of the
d7ddb257
LC
1647duration. For example, @code{--list-generations=20d} lists generations
1648that are up to 20 days old.
f566d765
LC
1649@end itemize
1650
b7884ca3
NK
1651@item --delete-generations[=@var{pattern}]
1652@itemx -d [@var{pattern}]
d7ddb257
LC
1653When @var{pattern} is omitted, delete all generations except the current
1654one.
b7884ca3
NK
1655
1656This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1657When @var{pattern} is specified, delete the matching generations. When
1658@var{pattern} specifies a duration, generations @emph{older} than the
1659specified duration match. For instance, @code{--delete-generations=1m}
1660deletes generations that are more than one month old.
1661
391bdd8f
LC
1662If the current generation matches, it is @emph{not} deleted. Also, the
1663zeroth generation is never deleted.
b7884ca3 1664
f97c9175 1665Note that deleting generations prevents rolling back to them.
1bb9900a
LC
1666Consequently, this command must be used with care.
1667
733b4130 1668@end table
eeaf4427 1669
70ee5642 1670Finally, since @command{guix package} may actually start build
ccd7158d 1671processes, it supports all the common build options (@pxref{Common Build
f97c9175 1672Options}). It also supports package transformation options, such as
b8638f03
LC
1673@option{--with-source} (@pxref{Package Transformation Options}).
1674However, note that package transformations are lost when upgrading; to
f97c9175 1675preserve transformations across upgrades, you should define your own
b8638f03
LC
1676package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1677(@pxref{Defining Packages}).
1678
70ee5642 1679
c4202d60
LC
1680@node Substitutes
1681@section Substitutes
1682
1683@cindex substitutes
1684@cindex pre-built binaries
1685Guix supports transparent source/binary deployment, which means that it
1686can either build things locally, or download pre-built items from a
1687server. We call these pre-built items @dfn{substitutes}---they are
1688substitutes for local build results. In many cases, downloading a
1689substitute is much faster than building things locally.
1690
1691Substitutes can be anything resulting from a derivation build
1692(@pxref{Derivations}). Of course, in the common case, they are
1693pre-built package binaries, but source tarballs, for instance, which
1694also result from derivation builds, can be available as substitutes.
1695
1696The @code{hydra.gnu.org} server is a front-end to a build farm that
1697builds packages from the GNU distribution continuously for some
32950fc8
AK
1698architectures, and makes them available as substitutes (@pxref{Emacs
1699Hydra}, for information on how to query the continuous integration
1700server). This is the
f8a8e0fe
LC
1701default source of substitutes; it can be overridden by passing the
1702@option{--substitute-urls} option either to @command{guix-daemon}
1703(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1704or to client tools such as @command{guix package}
1705(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1706option}).
c4202d60 1707
9b7bd1b1
LC
1708Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1709the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
1710HTTPS is recommended because communications are encrypted; conversely,
1711using HTTP makes all communications visible to an eavesdropper, who
1712could use the information gathered to determine, for instance, whether
1713your system has unpatched security vulnerabilities.
1714
c4202d60
LC
1715@cindex security
1716@cindex digital signatures
1717To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1718must add its public key to the access control list (ACL) of archive
1719imports, using the @command{guix archive} command (@pxref{Invoking guix
1720archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1721be compromised and to serve genuine substitutes.
1722
1723This public key is installed along with Guix, in
1724@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1725the installation prefix of Guix. If you installed Guix from source,
1726make sure you checked the GPG signature of
1727@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1728Then, you can run something like this:
1729
1730@example
1731# guix archive --authorize < hydra.gnu.org.pub
1732@end example
1733
1734Once this is in place, the output of a command like @code{guix build}
1735should change from something like:
1736
1737@example
1738$ guix build emacs --dry-run
1739The following derivations would be built:
1740 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1741 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1742 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1743 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1744@dots{}
1745@end example
1746
1747@noindent
1748to something like:
1749
1750@example
1751$ guix build emacs --dry-run
1752The following files would be downloaded:
1753 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1754 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1755 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1756 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1757@dots{}
1758@end example
1759
1760@noindent
1761This indicates that substitutes from @code{hydra.gnu.org} are usable and
1762will be downloaded, when possible, for future builds.
1763
1764Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1765one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1766when attempting to use a substitute that has been tampered with.
1767
e0c941fe 1768@vindex http_proxy
9b7bd1b1
LC
1769Substitutes are downloaded over HTTP or HTTPS.
1770The @code{http_proxy} environment
e0c941fe
LC
1771variable can be set in the environment of @command{guix-daemon} and is
1772honored for downloads of substitutes. Note that the value of
1773@code{http_proxy} in the environment where @command{guix build},
1774@command{guix package}, and other client commands are run has
1775@emph{absolutely no effect}.
1776
9b7bd1b1
LC
1777When using HTTPS, the server's X.509 certificate is @emph{not} validated
1778(in other words, the server is not authenticated), contrary to what
1779HTTPS clients such as Web browsers usually do. This is because Guix
1780authenticates substitute information itself, as explained above, which
1781is what we care about (whereas X.509 certificates are about
1782authenticating bindings between domain names and public keys.)
1783
c4202d60
LC
1784The substitute mechanism can be disabled globally by running
1785@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1786guix-daemon}). It can also be disabled temporarily by passing the
1787@code{--no-substitutes} option to @command{guix package}, @command{guix
1788build}, and other command-line tools.
1789
1790
9b7bd1b1
LC
1791@unnumberedsubsec On Trusting Binaries
1792
c4202d60
LC
1793Today, each individual's control over their own computing is at the
1794mercy of institutions, corporations, and groups with enough power and
1795determination to subvert the computing infrastructure and exploit its
1796weaknesses. While using @code{hydra.gnu.org} substitutes can be
1797convenient, we encourage users to also build on their own, or even run
1798their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1799interesting target. One way to help is by publishing the software you
1800build using @command{guix publish} so that others have one more choice
1801of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1802
1803Guix has the foundations to maximize build reproducibility
1804(@pxref{Features}). In most cases, independent builds of a given
1805package or derivation should yield bit-identical results. Thus, through
1806a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
1807integrity of our systems. The @command{guix challenge} command aims to
1808help users assess substitute servers, and to assist developers in
1809finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
1810challenge}). Similarly, the @option{--check} option of @command{guix
1811build} allows users to check whether previously-installed substitutes
1812are genuine by rebuilding them locally (@pxref{build-check,
1813@command{guix build --check}}).
c4202d60
LC
1814
1815In the future, we want Guix to have support to publish and retrieve
1816binaries to/from other users, in a peer-to-peer fashion. If you would
1817like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1818
1819
6e721c4d
LC
1820@node Packages with Multiple Outputs
1821@section Packages with Multiple Outputs
1822
1823@cindex multiple-output packages
1824@cindex package outputs
1825
1826Often, packages defined in Guix have a single @dfn{output}---i.e., the
f97c9175 1827source package leads to exactly one directory in the store. When running
6e721c4d
LC
1828@command{guix package -i glibc}, one installs the default output of the
1829GNU libc package; the default output is called @code{out}, but its name
1830can be omitted as shown in this command. In this particular case, the
1831default output of @code{glibc} contains all the C header files, shared
1832libraries, static libraries, Info documentation, and other supporting
1833files.
1834
1835Sometimes it is more appropriate to separate the various types of files
1836produced from a single source package into separate outputs. For
1837instance, the GLib C library (used by GTK+ and related packages)
1838installs more than 20 MiB of reference documentation as HTML pages.
1839To save space for users who do not need it, the documentation goes to a
1840separate output, called @code{doc}. To install the main GLib output,
1841which contains everything but the documentation, one would run:
1842
1843@example
1844guix package -i glib
1845@end example
1846
1847The command to install its documentation is:
1848
1849@example
1850guix package -i glib:doc
1851@end example
1852
1853Some packages install programs with different ``dependency footprints''.
f97c9175 1854For instance, the WordNet package installs both command-line tools and
6e721c4d
LC
1855graphical user interfaces (GUIs). The former depend solely on the C
1856library, whereas the latter depend on Tcl/Tk and the underlying X
1857libraries. In this case, we leave the command-line tools in the default
1858output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
1859who do not need the GUIs to save space. The @command{guix size} command
1860can help find out about such situations (@pxref{Invoking guix size}).
88856916 1861@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
1862
1863There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1864Other conventional output names include @code{lib} for libraries and
1865possibly header files, @code{bin} for stand-alone programs, and
1866@code{debug} for debugging information (@pxref{Installing Debugging
1867Files}). The outputs of a packages are listed in the third column of
1868the output of @command{guix package --list-available} (@pxref{Invoking
1869guix package}).
6e721c4d 1870
eeaf4427 1871
e49951eb
MW
1872@node Invoking guix gc
1873@section Invoking @command{guix gc}
fe8ff028
LC
1874
1875@cindex garbage collector
f97c9175 1876Packages that are installed, but not used, may be @dfn{garbage-collected}.
e49951eb 1877The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1878collector to reclaim space from the @file{/gnu/store} directory. It is
1879the @emph{only} way to remove files from @file{/gnu/store}---removing
1880files or directories manually may break it beyond repair!
fe8ff028
LC
1881
1882The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1883@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1884cannot be deleted; any other file is considered @dfn{dead} and may be
1885deleted. The set of garbage collector roots includes default user
e49951eb
MW
1886profiles, and may be augmented with @command{guix build --root}, for
1887example (@pxref{Invoking guix build}).
fe8ff028 1888
1bb9900a
LC
1889Prior to running @code{guix gc --collect-garbage} to make space, it is
1890often useful to remove old generations from user profiles; that way, old
1891package builds referenced by those generations can be reclaimed. This
1892is achieved by running @code{guix package --delete-generations}
1893(@pxref{Invoking guix package}).
1894
e49951eb 1895The @command{guix gc} command has three modes of operation: it can be
fe8ff028 1896used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
1897files (the @code{--delete} option), to print garbage-collector
1898information, or for more advanced queries. The garbage collection
1899options are as follows:
fe8ff028
LC
1900
1901@table @code
1902@item --collect-garbage[=@var{min}]
1903@itemx -C [@var{min}]
834129e0 1904Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1905sub-directories. This is the default operation when no option is
1906specified.
1907
1908When @var{min} is given, stop once @var{min} bytes have been collected.
1909@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1910suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1911(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1912
1913When @var{min} is omitted, collect all the garbage.
1914
1915@item --delete
1916@itemx -d
1917Attempt to delete all the store files and directories specified as
1918arguments. This fails if some of the files are not in the store, or if
1919they are still live.
1920
30d9aa54
LC
1921@item --list-failures
1922List store items corresponding to cached build failures.
1923
1924This prints nothing unless the daemon was started with
1925@option{--cache-failures} (@pxref{Invoking guix-daemon,
1926@option{--cache-failures}}).
1927
1928@item --clear-failures
1929Remove the specified store items from the failed-build cache.
1930
1931Again, this option only makes sense when the daemon is started with
1932@option{--cache-failures}. Otherwise, it does nothing.
1933
fe8ff028
LC
1934@item --list-dead
1935Show the list of dead files and directories still present in the
1936store---i.e., files and directories no longer reachable from any root.
1937
1938@item --list-live
1939Show the list of live store files and directories.
ba8b732d
LC
1940
1941@end table
1942
1943In addition, the references among existing store files can be queried:
1944
1945@table @code
1946
1947@item --references
1948@itemx --referrers
1949List the references (respectively, the referrers) of store files given
1950as arguments.
1951
8e59fdd5
LC
1952@item --requisites
1953@itemx -R
fcc58db6 1954@cindex closure
8e59fdd5
LC
1955List the requisites of the store files passed as arguments. Requisites
1956include the store files themselves, their references, and the references
1957of these, recursively. In other words, the returned list is the
1958@dfn{transitive closure} of the store files.
1959
f97c9175
AE
1960@xref{Invoking guix size}, for a tool to profile the size of the closure
1961of an element. @xref{Invoking guix graph}, for a tool to visualize
88856916 1962the graph of references.
fcc58db6 1963
fe8ff028
LC
1964@end table
1965
7770aafc
LC
1966Lastly, the following options allow you to check the integrity of the
1967store and to control disk usage.
1968
1969@table @option
1970
1971@item --verify[=@var{options}]
1972@cindex integrity, of the store
1973@cindex integrity checking
1974Verify the integrity of the store.
1975
1976By default, make sure that all the store items marked as valid in the
f97c9175 1977database of the daemon actually exist in @file{/gnu/store}.
7770aafc 1978
f97c9175 1979When provided, @var{options} must be a comma-separated list containing one
7770aafc
LC
1980or more of @code{contents} and @code{repair}.
1981
f97c9175
AE
1982When passing @option{--verify=contents}, the daemon computse the
1983content hash of each store item and compares it against its hash in the
7770aafc
LC
1984database. Hash mismatches are reported as data corruptions. Because it
1985traverses @emph{all the files in the store}, this command can take a
1986long time, especially on systems with a slow disk drive.
1987
1988@cindex repairing the store
1989Using @option{--verify=repair} or @option{--verify=contents,repair}
1990causes the daemon to try to repair corrupt store items by fetching
1991substitutes for them (@pxref{Substitutes}). Because repairing is not
1992atomic, and thus potentially dangerous, it is available only to the
1993system administrator.
1994
1995@item --optimize
1996@cindex deduplication
1997Optimize the store by hard-linking identical files---this is
1998@dfn{deduplication}.
1999
2000The daemon performs deduplication after each successful build or archive
2001import, unless it was started with @code{--disable-deduplication}
2002(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2003this option is primarily useful when the daemon was running with
2004@code{--disable-deduplication}.
2005
2006@end table
eeaf4427 2007
f651b477
LC
2008@node Invoking guix pull
2009@section Invoking @command{guix pull}
2010
2011Packages are installed or upgraded to the latest version available in
2012the distribution currently available on your local machine. To update
2013that distribution, along with the Guix tools, you must run @command{guix
2014pull}: the command downloads the latest Guix source code and package
2015descriptions, and deploys it.
2016
2017On completion, @command{guix package} will use packages and package
2018versions from this just-retrieved copy of Guix. Not only that, but all
2019the Guix commands and Scheme modules will also be taken from that latest
2020version. New @command{guix} sub-commands added by the update also
cb05108a
LC
2021become available.
2022
2023Any user can update their Guix copy using @command{guix pull}, and the
2024effect is limited to the user who run @command{guix pull}. For
2025instance, when user @code{root} runs @command{guix pull}, this has no
2026effect on the version of Guix that user @code{alice} sees, and vice
2027versa@footnote{Under the hood, @command{guix pull} updates the
2028@file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2029and the @command{guix} command loads code from there.}.
f651b477
LC
2030
2031The @command{guix pull} command is usually invoked with no arguments,
2032but it supports the following options:
2033
2034@table @code
2035@item --verbose
2036Produce verbose output, writing build logs to the standard error output.
2037
ab5d72ad
LC
2038@item --url=@var{url}
2039Download the source tarball of Guix from @var{url}.
2040
2041By default, the tarball is taken from its canonical address at
2042@code{gnu.org}, for the stable branch of Guix.
2043
f651b477
LC
2044@item --bootstrap
2045Use the bootstrap Guile to build the latest Guix. This option is only
2046useful to Guix developers.
2047@end table
2048
760c60d6
LC
2049
2050@node Invoking guix archive
2051@section Invoking @command{guix archive}
2052
2053The @command{guix archive} command allows users to @dfn{export} files
2054from the store into a single archive, and to later @dfn{import} them.
2055In particular, it allows store files to be transferred from one machine
4d4c4816
AE
2056to the store on another machine.
2057
2058To export store files as an archive to standard output, run:
2059
2060@example
2061guix archive --export @var{options} @var{specifications}...
2062@end example
2063
2064@var{specifications} may be either store file names or package
2065specifications, as for @command{guix package} (@pxref{Invoking guix
2066package}). For instance, the following command creates an archive
2067containing the @code{gui} output of the @code{git} package and the main
2068output of @code{emacs}:
2069
2070@example
2071guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2072@end example
2073
2074If the specified packages are not built yet, @command{guix archive}
2075automatically builds them. The build process may be controlled with the
2076common build options (@pxref{Common Build Options}).
2077
2078To transfer the @code{emacs} package to a machine connected over SSH,
2079one would run:
760c60d6
LC
2080
2081@example
56607088 2082guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
2083@end example
2084
87236aed 2085@noindent
56607088
LC
2086Similarly, a complete user profile may be transferred from one machine
2087to another like this:
2088
2089@example
2090guix archive --export -r $(readlink -f ~/.guix-profile) | \
2091 ssh the-machine guix-archive --import
2092@end example
2093
2094@noindent
2095However, note that, in both examples, all of @code{emacs} and the
2096profile as well as all of their dependencies are transferred (due to
f97c9175
AE
2097@code{-r}), regardless of what is already available in the store on the
2098target machine. The @code{--missing} option can help figure out which
2099items are missing from the target store.
87236aed 2100
760c60d6 2101Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
2102comparable in spirit to `tar', but with a few noteworthy differences
2103that make it more appropriate for our purposes. First, rather than
f97c9175 2104recording all Unix metadata for each file, the Nar format only mentions
0dbd88db
LC
2105the file type (regular, directory, or symbolic link); Unix permissions
2106and owner/group are dismissed. Second, the order in which directory
2107entries are stored always follows the order of file names according to
2108the C locale collation order. This makes archive production fully
2109deterministic.
2110
2111When exporting, the daemon digitally signs the contents of the archive,
2112and that digital signature is appended. When importing, the daemon
2113verifies the signature and rejects the import in case of an invalid
2114signature or if the signing key is not authorized.
760c60d6
LC
2115@c FIXME: Add xref to daemon doc about signatures.
2116
2117The main options are:
2118
2119@table @code
2120@item --export
2121Export the specified store files or packages (see below.) Write the
2122resulting archive to the standard output.
2123
56607088
LC
2124Dependencies are @emph{not} included in the output, unless
2125@code{--recursive} is passed.
2126
2127@item -r
2128@itemx --recursive
2129When combined with @code{--export}, this instructs @command{guix
2130archive} to include dependencies of the given items in the archive.
2131Thus, the resulting archive is self-contained: it contains the closure
2132of the exported store items.
2133
760c60d6
LC
2134@item --import
2135Read an archive from the standard input, and import the files listed
2136therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2137signature, or if it is signed by a public key not among the authorized
2138keys (see @code{--authorize} below.)
554f26ec 2139
87236aed
LC
2140@item --missing
2141Read a list of store file names from the standard input, one per line,
2142and write on the standard output the subset of these files missing from
2143the store.
2144
554f26ec 2145@item --generate-key[=@var{parameters}]
f82cc5fd 2146@cindex signing, archives
f97c9175 2147Generate a new key pair for the daemon. This is a prerequisite before
554f26ec
LC
2148archives can be exported with @code{--export}. Note that this operation
2149usually takes time, because it needs to gather enough entropy to
2150generate the key pair.
2151
2152The generated key pair is typically stored under @file{/etc/guix}, in
2153@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2154key, which must be kept secret.) When @var{parameters} is omitted,
2155an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2156versions before 1.6.0, it is a 4096-bit RSA key.
f97c9175 2157Alternatively, @var{parameters} can specify
554f26ec
LC
2158@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2159public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2160Libgcrypt Reference Manual}).
f82cc5fd
LC
2161
2162@item --authorize
2163@cindex authorizing, archives
2164Authorize imports signed by the public key passed on standard input.
2165The public key must be in ``s-expression advanced format''---i.e., the
2166same format as the @file{signing-key.pub} file.
2167
2168The list of authorized keys is kept in the human-editable file
2169@file{/etc/guix/acl}. The file contains
2170@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2171s-expressions''} and is structured as an access-control list in the
2172@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2173(SPKI)}.
c6f8e9dd
LC
2174
2175@item --extract=@var{directory}
2176@itemx -x @var{directory}
2177Read a single-item archive as served by substitute servers
2178(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2179low-level operation needed in only very narrow use cases; see below.
2180
2181For example, the following command extracts the substitute for Emacs
2182served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2183
2184@example
2185$ wget -O - \
2186 http://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
2187 | bunzip2 | guix archive -x /tmp/emacs
2188@end example
2189
2190Single-item archives are different from multiple-item archives produced
2191by @command{guix archive --export}; they contain a single store item,
2192and they do @emph{not} embed a signature. Thus this operation does
2193@emph{no} signature verification and its output should be considered
2194unsafe.
2195
2196The primary purpose of this operation is to facilitate inspection of
2197archive contents coming from possibly untrusted substitute servers.
2198
760c60d6
LC
2199@end table
2200
c554de89
AK
2201@c *********************************************************************
2202@include emacs.texi
760c60d6 2203
568717fd
LC
2204@c *********************************************************************
2205@node Programming Interface
2206@chapter Programming Interface
2207
3dc1970d
LC
2208GNU Guix provides several Scheme programming interfaces (APIs) to
2209define, build, and query packages. The first interface allows users to
2210write high-level package definitions. These definitions refer to
2211familiar packaging concepts, such as the name and version of a package,
2212its build system, and its dependencies. These definitions can then be
2213turned into concrete build actions.
2214
ba55b1cb 2215Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2216standard setup, the daemon has write access to the store---the
834129e0 2217@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2218setup also has the daemon perform builds in chroots, under a specific
2219build users, to minimize interference with the rest of the system.
2220
2221@cindex derivation
2222Lower-level APIs are available to interact with the daemon and the
2223store. To instruct the daemon to perform a build action, users actually
2224provide it with a @dfn{derivation}. A derivation is a low-level
2225representation of the build actions to be taken, and the environment in
2226which they should occur---derivations are to package definitions what
49ad317a
LC
2227assembly is to C programs. The term ``derivation'' comes from the fact
2228that build results @emph{derive} from them.
3dc1970d
LC
2229
2230This chapter describes all these APIs in turn, starting from high-level
2231package definitions.
2232
568717fd 2233@menu
b860f382 2234* Defining Packages:: Defining new packages.
7458bd0a 2235* Build Systems:: Specifying how packages are built.
b860f382
LC
2236* The Store:: Manipulating the package store.
2237* Derivations:: Low-level interface to package derivations.
2238* The Store Monad:: Purely functional interface to the store.
21b679f6 2239* G-Expressions:: Manipulating build expressions.
568717fd
LC
2240@end menu
2241
2242@node Defining Packages
2243@section Defining Packages
2244
3dc1970d
LC
2245The high-level interface to package definitions is implemented in the
2246@code{(guix packages)} and @code{(guix build-system)} modules. As an
2247example, the package definition, or @dfn{recipe}, for the GNU Hello
2248package looks like this:
2249
2250@example
e7f34eb0
LC
2251(define-module (gnu packages hello)
2252 #:use-module (guix packages)
2253 #:use-module (guix download)
2254 #:use-module (guix build-system gnu)
a6dcdcac
SB
2255 #:use-module (guix licenses)
2256 #:use-module (gnu packages gawk))
b22a12fd 2257
79f5dd59 2258(define-public hello
3dc1970d
LC
2259 (package
2260 (name "hello")
17d8e33f 2261 (version "2.10")
3dc1970d 2262 (source (origin
17d8e33f
ML
2263 (method url-fetch)
2264 (uri (string-append "mirror://gnu/hello/hello-" version
2265 ".tar.gz"))
2266 (sha256
2267 (base32
2268 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2269 (build-system gnu-build-system)
7458bd0a 2270 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2271 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2272 (synopsis "Hello, GNU world: An example GNU package")
2273 (description "Guess what GNU Hello prints!")
3dc1970d 2274 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2275 (license gpl3+)))
3dc1970d
LC
2276@end example
2277
2278@noindent
2279Without being a Scheme expert, the reader may have guessed the meaning
f97c9175
AE
2280of the various fields here. This expression binds the variable
2281@code{hello} to a @code{<package>} object, which is essentially a record
3dc1970d
LC
2282(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2283This package object can be inspected using procedures found in the
2284@code{(guix packages)} module; for instance, @code{(package-name hello)}
2285returns---surprise!---@code{"hello"}.
2286
2f7d2d91
LC
2287With luck, you may be able to import part or all of the definition of
2288the package you are interested in from another repository, using the
2289@code{guix import} command (@pxref{Invoking guix import}).
2290
f97c9175 2291In the example above, @var{hello} is defined in a module of its own,
e7f34eb0
LC
2292@code{(gnu packages hello)}. Technically, this is not strictly
2293necessary, but it is convenient to do so: all the packages defined in
2294modules under @code{(gnu packages @dots{})} are automatically known to
2295the command-line tools (@pxref{Package Modules}).
2296
3dc1970d
LC
2297There are a few points worth noting in the above package definition:
2298
2299@itemize
2300@item
a2bf4907
LC
2301The @code{source} field of the package is an @code{<origin>} object
2302(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2303Here, the @code{url-fetch} method from @code{(guix download)} is used,
2304meaning that the source is a file to be downloaded over FTP or HTTP.
2305
2306The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2307the GNU mirrors defined in @code{(guix download)}.
2308
2309The @code{sha256} field specifies the expected SHA256 hash of the file
2310being downloaded. It is mandatory, and allows Guix to check the
2311integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2312base32 representation of the hash. You can obtain this information with
210cc920
LC
2313@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2314hash} (@pxref{Invoking guix hash}).
3dc1970d 2315
f9cc8971
LC
2316@cindex patches
2317When needed, the @code{origin} form can also have a @code{patches} field
2318listing patches to be applied, and a @code{snippet} field giving a
2319Scheme expression to modify the source code.
2320
3dc1970d
LC
2321@item
2322@cindex GNU Build System
7458bd0a
LC
2323The @code{build-system} field specifies the procedure to build the
2324package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2325represents the familiar GNU Build System, where packages may be
2326configured, built, and installed with the usual @code{./configure &&
2327make && make check && make install} command sequence.
2328
2329@item
2330The @code{arguments} field specifies options for the build system
2331(@pxref{Build Systems}). Here it is interpreted by
2332@var{gnu-build-system} as a request run @file{configure} with the
2333@code{--enable-silent-rules} flag.
3dc1970d
LC
2334
2335@item
2336The @code{inputs} field specifies inputs to the build process---i.e.,
2337build-time or run-time dependencies of the package. Here, we define an
2338input called @code{"gawk"} whose value is that of the @var{gawk}
2339variable; @var{gawk} is itself bound to a @code{<package>} object.
2340
2341Note that GCC, Coreutils, Bash, and other essential tools do not need to
2342be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2343of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2344
2345However, any other dependencies need to be specified in the
2346@code{inputs} field. Any dependency not specified here will simply be
2347unavailable to the build process, possibly leading to a build failure.
2348@end itemize
2349
87eafdbd
TUBK
2350@xref{package Reference}, for a full description of possible fields.
2351
2f7d2d91 2352Once a package definition is in place, the
e49951eb 2353package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2354tool (@pxref{Invoking guix build}). You can easily jump back to the
2355package definition using the @command{guix edit} command
2356(@pxref{Invoking guix edit}).
2357@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2358more information on how to test package definitions, and
2359@ref{Invoking guix lint}, for information on how to check a definition
2360for style conformance.
2361
f97c9175 2362Finally, updating the package definition to a new upstream version
7458bd0a
LC
2363can be partly automated by the @command{guix refresh} command
2364(@pxref{Invoking guix refresh}).
3dc1970d
LC
2365
2366Behind the scenes, a derivation corresponding to the @code{<package>}
2367object is first computed by the @code{package-derivation} procedure.
834129e0 2368That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2369The build actions it prescribes may then be realized by using the
3dc1970d
LC
2370@code{build-derivations} procedure (@pxref{The Store}).
2371
2372@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2373Return the @code{<derivation>} object of @var{package} for @var{system}
2374(@pxref{Derivations}).
3dc1970d
LC
2375
2376@var{package} must be a valid @code{<package>} object, and @var{system}
2377must be a string denoting the target system type---e.g.,
2378@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2379must be a connection to the daemon, which operates on the store
2380(@pxref{The Store}).
2381@end deffn
568717fd 2382
9c1edabd
LC
2383@noindent
2384@cindex cross-compilation
2385Similarly, it is possible to compute a derivation that cross-builds a
2386package for some other system:
2387
2388@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2389 @var{package} @var{target} [@var{system}]
59688fc4
LC
2390Return the @code{<derivation>} object of @var{package} cross-built from
2391@var{system} to @var{target}.
9c1edabd
LC
2392
2393@var{target} must be a valid GNU triplet denoting the target hardware
2394and operating system, such as @code{"mips64el-linux-gnu"}
2395(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2396Configure and Build System}).
2397@end deffn
2398
87eafdbd
TUBK
2399@menu
2400* package Reference :: The package data type.
2401* origin Reference:: The origin data type.
2402@end menu
2403
2404
2405@node package Reference
2406@subsection @code{package} Reference
2407
2408This section summarizes all the options available in @code{package}
2409declarations (@pxref{Defining Packages}).
2410
2411@deftp {Data Type} package
2412This is the data type representing a package recipe.
2413
2414@table @asis
2415@item @code{name}
2416The name of the package, as a string.
2417
2418@item @code{version}
2419The version of the package, as a string.
2420
2421@item @code{source}
2422An origin object telling how the source code for the package should be
2423acquired (@pxref{origin Reference}).
2424
2425@item @code{build-system}
2426The build system that should be used to build the package (@pxref{Build
2427Systems}).
2428
2429@item @code{arguments} (default: @code{'()})
2430The arguments that should be passed to the build system. This is a
2431list, typically containing sequential keyword-value pairs.
2432
2433@item @code{inputs} (default: @code{'()})
70650c68
LC
2434@itemx @code{native-inputs} (default: @code{'()})
2435@itemx @code{propagated-inputs} (default: @code{'()})
2436@cindex inputs, of packages
2437These fields list dependencies of the package. Each one is a list of
2438tuples, where each tuple has a label for the input (a string) as its
2439first element, a package, origin, or derivation as its second element,
2440and optionally the name of the output thereof that should be used, which
2441defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
f97c9175 2442more on package outputs). For example, the list below specifies three
70650c68 2443inputs:
87eafdbd 2444
70650c68
LC
2445@example
2446`(("libffi" ,libffi)
2447 ("libunistring" ,libunistring)
2448 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2449@end example
2450
2451@cindex cross compilation, package dependencies
2452The distinction between @code{native-inputs} and @code{inputs} is
2453necessary when considering cross-compilation. When cross-compiling,
2454dependencies listed in @code{inputs} are built for the @emph{target}
2455architecture; conversely, dependencies listed in @code{native-inputs}
2456are built for the architecture of the @emph{build} machine.
2457
f97c9175
AE
2458@code{native-inputs} is typically used to list tools needed at
2459build time, but not at run time, such as Autoconf, Automake, pkg-config,
70650c68
LC
2460Gettext, or Bison. @command{guix lint} can report likely mistakes in
2461this area (@pxref{Invoking guix lint}).
2462
2463@anchor{package-propagated-inputs}
2464Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
f97c9175
AE
2465specified packages will be automatically installed alongside the package
2466they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
70650c68
LC
2467package}}, for information on how @command{guix package} deals with
2468propagated inputs.)
21461f27 2469
e0508b6b
LC
2470For example this is necessary when a C/C++ library needs headers of
2471another library to compile, or when a pkg-config file refers to another
2472one @i{via} its @code{Requires} field.
2473
f97c9175
AE
2474Another example where @code{propagated-inputs} is useful is for languages
2475that lack a facility to record the run-time search path akin to the
2476@code{RUNPATH}of ELF files; this includes Guile, Python, Perl, GHC, and
e0508b6b
LC
2477more. To ensure that libraries written in those languages can find
2478library code they depend on at run time, run-time dependencies must be
2479listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2480
87eafdbd
TUBK
2481@item @code{self-native-input?} (default: @code{#f})
2482This is a Boolean field telling whether the package should use itself as
2483a native input when cross-compiling.
2484
2485@item @code{outputs} (default: @code{'("out")})
2486The list of output names of the package. @xref{Packages with Multiple
2487Outputs}, for typical uses of additional outputs.
2488
2489@item @code{native-search-paths} (default: @code{'()})
2490@itemx @code{search-paths} (default: @code{'()})
2491A list of @code{search-path-specification} objects describing
2492search-path environment variables honored by the package.
2493
2494@item @code{replacement} (default: @code{#f})
f97c9175 2495This must be either @code{#f} or a package object that will be used as a
87eafdbd
TUBK
2496@dfn{replacement} for this package. @xref{Security Updates, grafts},
2497for details.
2498
2499@item @code{synopsis}
2500A one-line description of the package.
2501
2502@item @code{description}
2503A more elaborate description of the package.
2504
2505@item @code{license}
f97c9175
AE
2506The license of the package; a value from @code{(guix licenses)},
2507or a list of such values.
87eafdbd
TUBK
2508
2509@item @code{home-page}
2510The URL to the home-page of the package, as a string.
2511
2512@item @code{supported-systems} (default: @var{%supported-systems})
2513The list of systems supported by the package, as strings of the form
2514@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2515
2516@item @code{maintainers} (default: @code{'()})
2517The list of maintainers of the package, as @code{maintainer} objects.
2518
2519@item @code{location} (default: source location of the @code{package} form)
f97c9175 2520The source location of the package. It is useful to override this when
87eafdbd
TUBK
2521inheriting from another package, in which case this field is not
2522automatically corrected.
2523@end table
2524@end deftp
2525
2526
2527@node origin Reference
2528@subsection @code{origin} Reference
2529
2530This section summarizes all the options available in @code{origin}
2531declarations (@pxref{Defining Packages}).
2532
2533@deftp {Data Type} origin
2534This is the data type representing a source code origin.
2535
2536@table @asis
2537@item @code{uri}
2538An object containing the URI of the source. The object type depends on
2539the @code{method} (see below). For example, when using the
2540@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2541values are: a URL represented as a string, or a list thereof.
2542
2543@item @code{method}
f97c9175 2544A procedure that handles the URI.
87eafdbd
TUBK
2545
2546Examples include:
2547
2548@table @asis
2549@item @var{url-fetch} from @code{(guix download)}
f97c9175 2550download a file from the HTTP, HTTPS, or FTP URL specified in the
87eafdbd
TUBK
2551@code{uri} field;
2552
2553@item @var{git-fetch} from @code{(guix git-download)}
2554clone the Git version control repository, and check out the revision
2555specified in the @code{uri} field as a @code{git-reference} object; a
2556@code{git-reference} looks like this:
2557
2558@example
2559(git-reference
2560 (url "git://git.debian.org/git/pkg-shadow/shadow")
2561 (commit "v4.1.5.1"))
2562@end example
2563@end table
2564
2565@item @code{sha256}
2566A bytevector containing the SHA-256 hash of the source. Typically the
2567@code{base32} form is used here to generate the bytevector from a
2568base-32 string.
2569
2570@item @code{file-name} (default: @code{#f})
2571The file name under which the source code should be saved. When this is
2572@code{#f}, a sensible default value will be used in most cases. In case
2573the source is fetched from a URL, the file name from the URL will be
f97c9175 2574used. For version control checkouts, it is recommended to provide the
87eafdbd
TUBK
2575file name explicitly because the default is not very descriptive.
2576
2577@item @code{patches} (default: @code{'()})
2578A list of file names containing patches to be applied to the source.
2579
2580@item @code{snippet} (default: @code{#f})
2581A quoted piece of code that will be run in the source directory to make
2582any modifications, which is sometimes more convenient than a patch.
2583
2584@item @code{patch-flags} (default: @code{'("-p1")})
2585A list of command-line flags that should be passed to the @code{patch}
2586command.
2587
2588@item @code{patch-inputs} (default: @code{#f})
2589Input packages or derivations to the patching process. When this is
2590@code{#f}, the usual set of inputs necessary for patching are provided,
2591such as GNU@tie{}Patch.
2592
2593@item @code{modules} (default: @code{'()})
2594A list of Guile modules that should be loaded during the patching
2595process and while running the code in the @code{snippet} field.
2596
2597@item @code{imported-modules} (default: @code{'()})
2598The list of Guile modules to import in the patch derivation, for use by
2599the @code{snippet}.
2600
2601@item @code{patch-guile} (default: @code{#f})
2602The Guile package that should be used in the patching process. When
2603this is @code{#f}, a sensible default is used.
2604@end table
2605@end deftp
2606
9c1edabd 2607
7458bd0a
LC
2608@node Build Systems
2609@section Build Systems
2610
2611@cindex build system
2612Each package definition specifies a @dfn{build system} and arguments for
2613that build system (@pxref{Defining Packages}). This @code{build-system}
f97c9175 2614field represents the build procedure of the package, as well as implicit
7458bd0a
LC
2615dependencies of that build procedure.
2616
2617Build systems are @code{<build-system>} objects. The interface to
2618create and manipulate them is provided by the @code{(guix build-system)}
2619module, and actual build systems are exported by specific modules.
2620
f5fd4fd2 2621@cindex bag (low-level package representation)
0d5a559f
LC
2622Under the hood, build systems first compile package objects to
2623@dfn{bags}. A @dfn{bag} is like a package, but with less
2624ornamentation---in other words, a bag is a lower-level representation of
2625a package, which includes all the inputs of that package, including some
2626that were implicitly added by the build system. This intermediate
2627representation is then compiled to a derivation (@pxref{Derivations}).
2628
7458bd0a
LC
2629Build systems accept an optional list of @dfn{arguments}. In package
2630definitions, these are passed @i{via} the @code{arguments} field
2631(@pxref{Defining Packages}). They are typically keyword arguments
2632(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2633Guile Reference Manual}). The value of these arguments is usually
2634evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2635by the daemon (@pxref{Derivations}).
2636
2637The main build system is @var{gnu-build-system}, which implements the
f97c9175 2638standard build procedure for GNU and many other packages. It
7458bd0a
LC
2639is provided by the @code{(guix build-system gnu)} module.
2640
2641@defvr {Scheme Variable} gnu-build-system
2642@var{gnu-build-system} represents the GNU Build System, and variants
2643thereof (@pxref{Configuration, configuration and makefile conventions,,
2644standards, GNU Coding Standards}).
2645
2646@cindex build phases
f97c9175 2647In a nutshell, packages using it are configured, built, and installed with
7458bd0a
LC
2648the usual @code{./configure && make && make check && make install}
2649command sequence. In practice, a few additional steps are often needed.
2650All these steps are split up in separate @dfn{phases},
2651notably@footnote{Please see the @code{(guix build gnu-build-system)}
2652modules for more details about the build phases.}:
2653
2654@table @code
2655@item unpack
2656Unpack the source tarball, and change the current directory to the
2657extracted source tree. If the source is actually a directory, copy it
2658to the build tree, and enter that directory.
2659
2660@item patch-source-shebangs
2661Patch shebangs encountered in source files so they refer to the right
2662store file names. For instance, this changes @code{#!/bin/sh} to
2663@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2664
2665@item configure
2666Run the @file{configure} script with a number of default options, such
2667as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2668by the @code{#:configure-flags} argument.
2669
2670@item build
2671Run @code{make} with the list of flags specified with
0917e80e 2672@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
2673(the default), build with @code{make -j}.
2674
2675@item check
2676Run @code{make check}, or some other target specified with
2677@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2678@code{#:parallel-tests?} argument is true (the default), run @code{make
2679check -j}.
2680
2681@item install
2682Run @code{make install} with the flags listed in @code{#:make-flags}.
2683
2684@item patch-shebangs
2685Patch shebangs on the installed executable files.
2686
2687@item strip
2688Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2689is false), copying them to the @code{debug} output when available
2690(@pxref{Installing Debugging Files}).
2691@end table
2692
2693@vindex %standard-phases
2694The build-side module @code{(guix build gnu-build-system)} defines
2695@var{%standard-phases} as the default list of build phases.
2696@var{%standard-phases} is a list of symbol/procedure pairs, where the
2697procedure implements the actual phase.
2698
2699The list of phases used for a particular package can be changed with the
2700@code{#:phases} parameter. For instance, passing:
2701
2702@example
c2c5dc79 2703#:phases (modify-phases %standard-phases (delete 'configure))
7458bd0a
LC
2704@end example
2705
9bf404e9 2706means that all the phases described above will be used, except the
7458bd0a
LC
2707@code{configure} phase.
2708
2709In addition, this build system ensures that the ``standard'' environment
2710for GNU packages is available. This includes tools such as GCC, libc,
2711Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
f97c9175
AE
2712build-system gnu)} module for a complete list). We call these the
2713@dfn{implicit inputs} of a package, because package definitions do not
7458bd0a
LC
2714have to mention them.
2715@end defvr
2716
2717Other @code{<build-system>} objects are defined to support other
2718conventions and tools used by free software packages. They inherit most
2719of @var{gnu-build-system}, and differ mainly in the set of inputs
2720implicitly added to the build process, and in the list of phases
2721executed. Some of these build systems are listed below.
2722
5f7a1a4d
RW
2723@defvr {Scheme Variable} ant-build-system
2724This variable is exported by @code{(guix build-system ant)}. It
2725implements the build procedure for Java packages that can be built with
2726@url{http://ant.apache.org/, Ant build tool}.
2727
2728It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
2729provided by the @code{icedtea} package to the set of inputs. Different
2730packages can be specified with the @code{#:ant} and @code{#:jdk}
2731parameters, respectively.
2732
2733When the original package does not provide a suitable Ant build file,
2734the parameter @code{#:jar-name} can be used to generate a minimal Ant
2735build file @file{build.xml} with tasks to build the specified jar
2736archive.
2737
2738The parameter @code{#:build-target} can be used to specify the Ant task
2739that should be run during the @code{build} phase. By default the
2740``jar'' task will be run.
2741
2742@end defvr
2743
7458bd0a
LC
2744@defvr {Scheme Variable} cmake-build-system
2745This variable is exported by @code{(guix build-system cmake)}. It
2746implements the build procedure for packages using the
2747@url{http://www.cmake.org, CMake build tool}.
2748
2749It automatically adds the @code{cmake} package to the set of inputs.
2750Which package is used can be specified with the @code{#:cmake}
2751parameter.
9849cfc1
LC
2752
2753The @code{#:configure-flags} parameter is taken as a list of flags
2754passed to the @command{cmake} command. The @code{#:build-type}
2755parameter specifies in abstract terms the flags passed to the compiler;
2756it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
2757debugging information''), which roughly means that code is compiled with
2758@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
2759@end defvr
2760
3afcf52b
FB
2761@defvr {Scheme Variable} glib-or-gtk-build-system
2762This variable is exported by @code{(guix build-system glib-or-gtk)}. It
2763is intended for use with packages making use of GLib or GTK+.
2764
2765This build system adds the following two phases to the ones defined by
2766@var{gnu-build-system}:
2767
2768@table @code
2769@item glib-or-gtk-wrap
f97c9175
AE
2770The phase @code{glib-or-gtk-wrap} ensures that programs in
2771@file{bin/} are able to find GLib ``schemas'' and
3afcf52b
FB
2772@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
2773modules}. This is achieved by wrapping the programs in launch scripts
2774that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
2775environment variables.
2776
73aa8ddb
LC
2777It is possible to exclude specific package outputs from that wrapping
2778process by listing their names in the
2779@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
2780when an output is known not to contain any GLib or GTK+ binaries, and
2781where wrapping would gratuitously add a dependency of that output on
2782GLib and GTK+.
2783
3afcf52b 2784@item glib-or-gtk-compile-schemas
f97c9175 2785The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3afcf52b 2786@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
f97c9175 2787GSettings schemas} of GLib are compiled. Compilation is performed by the
3afcf52b
FB
2788@command{glib-compile-schemas} program. It is provided by the package
2789@code{glib:bin} which is automatically imported by the build system.
2790The @code{glib} package providing @command{glib-compile-schemas} can be
2791specified with the @code{#:glib} parameter.
2792@end table
2793
2794Both phases are executed after the @code{install} phase.
2795@end defvr
2796
7458bd0a
LC
2797@defvr {Scheme Variable} python-build-system
2798This variable is exported by @code{(guix build-system python)}. It
2799implements the more or less standard build procedure used by Python
2800packages, which consists in running @code{python setup.py build} and
2801then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
2802
2803For packages that install stand-alone Python programs under @code{bin/},
f97c9175 2804it takes care of wrapping these programs so that their @code{PYTHONPATH}
7458bd0a
LC
2805environment variable points to all the Python libraries they depend on.
2806
2807Which Python package is used can be specified with the @code{#:python}
2808parameter.
2809@end defvr
2810
2811@defvr {Scheme Variable} perl-build-system
2812This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2813implements the standard build procedure for Perl packages, which either
2814consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2815followed by @code{Build} and @code{Build install}; or in running
2816@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
f97c9175 2817@code{make} and @code{make install}, depending on which of
2d2a53fc
EB
2818@code{Build.PL} or @code{Makefile.PL} is present in the package
2819distribution. Preference is given to the former if both @code{Build.PL}
2820and @code{Makefile.PL} exist in the package distribution. This
2821preference can be reversed by specifying @code{#t} for the
2822@code{#:make-maker?} parameter.
2823
2824The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2825passes flags specified by the @code{#:make-maker-flags} or
2826@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2827
2828Which Perl package is used can be specified with @code{#:perl}.
2829@end defvr
2830
f8f3bef6
RW
2831@defvr {Scheme Variable} r-build-system
2832This variable is exported by @code{(guix build-system r)}. It
2833implements the build procedure used by @uref{http://r-project.org, R}
2834packages, which essentially is little more than running @code{R CMD
2835INSTALL --library=/gnu/store/@dots{}} in an environment where
2836@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
2837are run after installation using the R function
2838@code{tools::testInstalledPackage}.
2839@end defvr
2840
c08f9818
DT
2841@defvr {Scheme Variable} ruby-build-system
2842This variable is exported by @code{(guix build-system ruby)}. It
2843implements the RubyGems build procedure used by Ruby packages, which
2844involves running @code{gem build} followed by @code{gem install}.
2845
5dc87623
DT
2846The @code{source} field of a package that uses this build system
2847typically references a gem archive, since this is the format that Ruby
2848developers use when releasing their software. The build system unpacks
2849the gem archive, potentially patches the source, runs the test suite,
2850repackages the gem, and installs it. Additionally, directories and
2851tarballs may be referenced to allow building unreleased gems from Git or
2852a traditional source release tarball.
e83c6d00 2853
c08f9818 2854Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
2855parameter. A list of additional flags to be passed to the @command{gem}
2856command can be specified with the @code{#:gem-flags} parameter.
c08f9818 2857@end defvr
7458bd0a 2858
a677c726
RW
2859@defvr {Scheme Variable} waf-build-system
2860This variable is exported by @code{(guix build-system waf)}. It
2861implements a build procedure around the @code{waf} script. The common
2862phases---@code{configure}, @code{build}, and @code{install}---are
2863implemented by passing their names as arguments to the @code{waf}
2864script.
2865
2866The @code{waf} script is executed by the Python interpreter. Which
2867Python package is used to run the script can be specified with the
2868@code{#:python} parameter.
2869@end defvr
2870
14dfdf2e
FB
2871@defvr {Scheme Variable} haskell-build-system
2872This variable is exported by @code{(guix build-system haskell)}. It
2873implements the Cabal build procedure used by Haskell packages, which
2874involves running @code{runhaskell Setup.hs configure
2875--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2876Instead of installing the package by running @code{runhaskell Setup.hs
2877install}, to avoid trying to register libraries in the read-only
2878compiler store directory, the build system uses @code{runhaskell
2879Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2880addition, the build system generates the package documentation by
2881running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2882is passed. Optional Haddock parameters can be passed with the help of
2883the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2884not found, the build system looks for @code{Setup.lhs} instead.
2885
2886Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 2887parameter which defaults to @code{ghc}.
14dfdf2e
FB
2888@end defvr
2889
e9137a53
FB
2890@defvr {Scheme Variable} emacs-build-system
2891This variable is exported by @code{(guix build-system emacs)}. It
f97c9175
AE
2892implements an installation procedure similar to the packaging system
2893of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
e9137a53
FB
2894
2895It first creates the @code{@var{package}-autoloads.el} file, then it
2896byte compiles all Emacs Lisp files. Differently from the Emacs
2897packaging system, the Info documentation files are moved to the standard
2898documentation directory and the @file{dir} file is deleted. Each
2899package is installed in its own directory under
2900@file{share/emacs/site-lisp/guix.d}.
2901@end defvr
2902
7458bd0a
LC
2903Lastly, for packages that do not need anything as sophisticated, a
2904``trivial'' build system is provided. It is trivial in the sense that
2905it provides basically no support: it does not pull any implicit inputs,
2906and does not have a notion of build phases.
2907
2908@defvr {Scheme Variable} trivial-build-system
2909This variable is exported by @code{(guix build-system trivial)}.
2910
2911This build system requires a @code{#:builder} argument. This argument
f97c9175 2912must be a Scheme expression that builds the package output(s)---as
7458bd0a
LC
2913with @code{build-expression->derivation} (@pxref{Derivations,
2914@code{build-expression->derivation}}).
2915@end defvr
2916
568717fd
LC
2917@node The Store
2918@section The Store
2919
e531ac2a 2920@cindex store
1ddee424 2921@cindex store items
e531ac2a
LC
2922@cindex store paths
2923
f97c9175
AE
2924Conceptually, the @dfn{store} is the place where derivations that have
2925been built successfully are stored---by default, @file{/gnu/store}.
1ddee424
LC
2926Sub-directories in the store are referred to as @dfn{store items} or
2927sometimes @dfn{store paths}. The store has an associated database that
2928contains information such as the store paths referred to by each store
2929path, and the list of @emph{valid} store items---results of successful
2930builds. This database resides in @file{/var/guix/db} (or under whatever
2931state directory was specified @i{via} @option{--localstatedir} at
2932configure time).
2933
2934The store is @emph{always} accessed by the daemon on behalf of its clients
e531ac2a 2935(@pxref{Invoking guix-daemon}). To manipulate the store, clients
f97c9175
AE
2936connect to the daemon over a Unix-domain socket, send requests to it,
2937and read the result---these are remote procedure calls, or RPCs.
e531ac2a 2938
1ddee424
LC
2939@quotation Note
2940Users must @emph{never} modify files under @file{/gnu/store} directly.
2941This would lead to inconsistencies and break the immutability
2942assumptions of Guix's functional model (@pxref{Introduction}).
2943
2944@xref{Invoking guix gc, @command{guix gc --verify}}, for information on
2945how to check the integrity of the store and attempt recovery from
2946accidental modifications.
2947@end quotation
2948
e531ac2a
LC
2949The @code{(guix store)} module provides procedures to connect to the
2950daemon, and to perform RPCs. These are described below.
2951
2952@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2953Connect to the daemon over the Unix-domain socket at @var{file}. When
2954@var{reserve-space?} is true, instruct it to reserve a little bit of
2955extra space on the file system so that the garbage collector can still
f97c9175 2956operate should the disk become full. Return a server object.
e531ac2a
LC
2957
2958@var{file} defaults to @var{%default-socket-path}, which is the normal
2959location given the options that were passed to @command{configure}.
2960@end deffn
2961
2962@deffn {Scheme Procedure} close-connection @var{server}
2963Close the connection to @var{server}.
2964@end deffn
2965
2966@defvr {Scheme Variable} current-build-output-port
2967This variable is bound to a SRFI-39 parameter, which refers to the port
2968where build and error logs sent by the daemon should be written.
2969@end defvr
2970
2971Procedures that make RPCs all take a server object as their first
2972argument.
2973
2974@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
06b76acc
LC
2975@cindex invalid store items
2976Return @code{#t} when @var{path} designates a valid store item and
2977@code{#f} otherwise (an invalid item may exist on disk but still be
2978invalid, for instance because it is the result of an aborted or failed
2979build.)
2980
2981A @code{&nix-protocol-error} condition is raised if @var{path} is not
2982prefixed by the store directory (@file{/gnu/store}).
e531ac2a
LC
2983@end deffn
2984
cfbf9160 2985@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
2986Add @var{text} under file @var{name} in the store, and return its store
2987path. @var{references} is the list of store paths referred to by the
2988resulting store path.
2989@end deffn
2990
874e6874 2991@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
2992Build @var{derivations} (a list of @code{<derivation>} objects or
2993derivation paths), and return when the worker is done building them.
2994Return @code{#t} on success.
874e6874
LC
2995@end deffn
2996
b860f382
LC
2997Note that the @code{(guix monads)} module provides a monad as well as
2998monadic versions of the above procedures, with the goal of making it
2999more convenient to work with code that accesses the store (@pxref{The
3000Store Monad}).
3001
e531ac2a
LC
3002@c FIXME
3003@i{This section is currently incomplete.}
568717fd
LC
3004
3005@node Derivations
3006@section Derivations
3007
874e6874
LC
3008@cindex derivations
3009Low-level build actions and the environment in which they are performed
3010are represented by @dfn{derivations}. A derivation contain the
3011following pieces of information:
3012
3013@itemize
3014@item
3015The outputs of the derivation---derivations produce at least one file or
3016directory in the store, but may produce more.
3017
3018@item
3019The inputs of the derivations, which may be other derivations or plain
3020files in the store (patches, build scripts, etc.)
3021
3022@item
3023The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3024
3025@item
3026The file name of a build script in the store, along with the arguments
3027to be passed.
3028
3029@item
3030A list of environment variables to be defined.
3031
3032@end itemize
3033
3034@cindex derivation path
3035Derivations allow clients of the daemon to communicate build actions to
3036the store. They exist in two forms: as an in-memory representation,
3037both on the client- and daemon-side, and as files in the store whose
3038name end in @code{.drv}---these files are referred to as @dfn{derivation
3039paths}. Derivations paths can be passed to the @code{build-derivations}
3040procedure to perform the build actions they prescribe (@pxref{The
3041Store}).
3042
3043The @code{(guix derivations)} module provides a representation of
3044derivations as Scheme objects, along with procedures to create and
3045otherwise manipulate derivations. The lowest-level primitive to create
3046a derivation is the @code{derivation} procedure:
3047
1909431c
LC
3048@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3049 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 3050 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 3051 [#:system (%current-system)] [#:references-graphs #f] @
4a6aeb67
LC
3052 [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @
3053 [#:substitutable? #t]
59688fc4
LC
3054Build a derivation with the given arguments, and return the resulting
3055@code{<derivation>} object.
874e6874 3056
2096ef47 3057When @var{hash} and @var{hash-algo} are given, a
874e6874 3058@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
3059known in advance, such as a file download. If, in addition,
3060@var{recursive?} is true, then that fixed output may be an executable
3061file or a directory and @var{hash} must be the hash of an archive
3062containing this output.
5b0c9d16 3063
858e9282 3064When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
3065name/store path pairs. In that case, the reference graph of each store
3066path is exported in the build environment in the corresponding file, in
3067a simple text format.
1909431c 3068
b53be755
LC
3069When @var{allowed-references} is true, it must be a list of store items
3070or outputs that the derivation's output may refer to.
3071
c0468155
LC
3072When @var{leaked-env-vars} is true, it must be a list of strings
3073denoting environment variables that are allowed to ``leak'' from the
3074daemon's environment to the build environment. This is only applicable
3075to fixed-output derivations---i.e., when @var{hash} is true. The main
3076use is to allow variables such as @code{http_proxy} to be passed to
3077derivations that download files.
3078
1909431c
LC
3079When @var{local-build?} is true, declare that the derivation is not a
3080good candidate for offloading and should rather be built locally
3081(@pxref{Daemon Offload Setup}). This is the case for small derivations
3082where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
3083
3084When @var{substitutable?} is false, declare that substitutes of the
3085derivation's output should not be used (@pxref{Substitutes}). This is
3086useful, for instance, when building packages that capture details of the
3087host CPU instruction set.
874e6874
LC
3088@end deffn
3089
3090@noindent
3091Here's an example with a shell script as its builder, assuming
3092@var{store} is an open connection to the daemon, and @var{bash} points
3093to a Bash executable in the store:
3094
3095@lisp
3096(use-modules (guix utils)
3097 (guix store)
3098 (guix derivations))
3099
59688fc4
LC
3100(let ((builder ; add the Bash script to the store
3101 (add-text-to-store store "my-builder.sh"
3102 "echo hello world > $out\n" '())))
3103 (derivation store "foo"
3104 bash `("-e" ,builder)
21b679f6 3105 #:inputs `((,bash) (,builder))
59688fc4 3106 #:env-vars '(("HOME" . "/homeless"))))
834129e0 3107@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
3108@end lisp
3109
21b679f6
LC
3110As can be guessed, this primitive is cumbersome to use directly. A
3111better approach is to write build scripts in Scheme, of course! The
3112best course of action for that is to write the build code as a
3113``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 3114information, @pxref{G-Expressions}.
21b679f6 3115
f2fadbc1
AE
3116Once upon a time, @code{gexp->derivation} did not exist and constructing
3117derivations with build code written in Scheme was achieved with
3118@code{build-expression->derivation}, documented below. This procedure
3119is now deprecated in favor of the much nicer @code{gexp->derivation}.
3120
3121@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3122 @var{name} @var{exp} @
3123 [#:system (%current-system)] [#:inputs '()] @
3124 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3125 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3126 [#:references-graphs #f] [#:allowed-references #f] @
3127 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3128Return a derivation that executes Scheme expression @var{exp} as a
3129builder for derivation @var{name}. @var{inputs} must be a list of
3130@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3131@code{"out"} is assumed. @var{modules} is a list of names of Guile
3132modules from the current search path to be copied in the store,
3133compiled, and made available in the load path during the execution of
3134@var{exp}---e.g., @code{((guix build utils) (guix build
3135gnu-build-system))}.
3136
3137@var{exp} is evaluated in an environment where @code{%outputs} is bound
3138to a list of output/path pairs, and where @code{%build-inputs} is bound
3139to a list of string/output-path pairs made from @var{inputs}.
3140Optionally, @var{env-vars} is a list of string pairs specifying the name
3141and value of environment variables visible to the builder. The builder
3142terminates by passing the result of @var{exp} to @code{exit}; thus, when
3143@var{exp} returns @code{#f}, the build is considered to have failed.
3144
3145@var{exp} is built using @var{guile-for-build} (a derivation). When
3146@var{guile-for-build} is omitted or is @code{#f}, the value of the
3147@code{%guile-for-build} fluid is used instead.
3148
3149See the @code{derivation} procedure for the meaning of
3150@var{references-graphs}, @var{allowed-references}, @var{local-build?},
3151and @var{substitutable?}.
3152@end deffn
3153
3154@noindent
3155Here's an example of a single-output derivation that creates a directory
3156containing one file:
3157
3158@lisp
3159(let ((builder '(let ((out (assoc-ref %outputs "out")))
3160 (mkdir out) ; create /gnu/store/@dots{}-goo
3161 (call-with-output-file (string-append out "/test")
3162 (lambda (p)
3163 (display '(hello guix) p))))))
3164 (build-expression->derivation store "goo" builder))
3165
3166@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3167@end lisp
3168
568717fd 3169
b860f382
LC
3170@node The Store Monad
3171@section The Store Monad
3172
3173@cindex monad
3174
3175The procedures that operate on the store described in the previous
3176sections all take an open connection to the build daemon as their first
3177argument. Although the underlying model is functional, they either have
3178side effects or depend on the current state of the store.
3179
3180The former is inconvenient: the connection to the build daemon has to be
3181carried around in all those functions, making it impossible to compose
3182functions that do not take that parameter with functions that do. The
3183latter can be problematic: since store operations have side effects
3184and/or depend on external state, they have to be properly sequenced.
3185
3186@cindex monadic values
3187@cindex monadic functions
3188This is where the @code{(guix monads)} module comes in. This module
3189provides a framework for working with @dfn{monads}, and a particularly
3190useful monad for our uses, the @dfn{store monad}. Monads are a
3191construct that allows two things: associating ``context'' with values
3192(in our case, the context is the store), and building sequences of
561fb6c3 3193computations (here computations include accesses to the store.) Values
b860f382
LC
3194in a monad---values that carry this additional context---are called
3195@dfn{monadic values}; procedures that return such values are called
3196@dfn{monadic procedures}.
3197
3198Consider this ``normal'' procedure:
3199
3200@example
45adbd62
LC
3201(define (sh-symlink store)
3202 ;; Return a derivation that symlinks the 'bash' executable.
3203 (let* ((drv (package-derivation store bash))
3204 (out (derivation->output-path drv))
3205 (sh (string-append out "/bin/bash")))
3206 (build-expression->derivation store "sh"
3207 `(symlink ,sh %output))))
b860f382
LC
3208@end example
3209
c6f30b81
LC
3210Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3211as a monadic function:
b860f382
LC
3212
3213@example
45adbd62 3214(define (sh-symlink)
b860f382 3215 ;; Same, but return a monadic value.
c6f30b81
LC
3216 (mlet %store-monad ((drv (package->derivation bash)))
3217 (gexp->derivation "sh"
3218 #~(symlink (string-append #$drv "/bin/bash")
3219 #$output))))
b860f382
LC
3220@end example
3221
c6f30b81
LC
3222There several things to note in the second version: the @code{store}
3223parameter is now implicit and is ``threaded'' in the calls to the
3224@code{package->derivation} and @code{gexp->derivation} monadic
3225procedures, and the monadic value returned by @code{package->derivation}
3226is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3227
3228As it turns out, the call to @code{package->derivation} can even be
3229omitted since it will take place implicitly, as we will see later
3230(@pxref{G-Expressions}):
3231
3232@example
3233(define (sh-symlink)
3234 (gexp->derivation "sh"
3235 #~(symlink (string-append #$bash "/bin/bash")
3236 #$output)))
3237@end example
b860f382 3238
7ce21611
LC
3239@c See
3240@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
3241@c for the funny quote.
3242Calling the monadic @code{sh-symlink} has no effect. As someone once
3243said, ``you exit a monad like you exit a building on fire: by running''.
3244So, to exit the monad and get the desired effect, one must use
3245@code{run-with-store}:
b860f382
LC
3246
3247@example
8e9aa37f
CAW
3248(run-with-store (open-connection) (sh-symlink))
3249@result{} /gnu/store/...-sh-symlink
b860f382
LC
3250@end example
3251
f97c9175 3252Note that the @code{(guix monad-repl)} module extends the Guile REPL with
b9b86078 3253new ``meta-commands'' to make it easier to deal with monadic procedures:
f97c9175 3254@code{run-in-store}, and @code{enter-store-monad}. The former is used
b9b86078
LC
3255to ``run'' a single monadic value through the store:
3256
3257@example
3258scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3259$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3260@end example
3261
3262The latter enters a recursive REPL, where all the return values are
3263automatically run through the store:
3264
3265@example
3266scheme@@(guile-user)> ,enter-store-monad
3267store-monad@@(guile-user) [1]> (package->derivation hello)
3268$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3269store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3270$3 = "/gnu/store/@dots{}-foo"
3271store-monad@@(guile-user) [1]> ,q
3272scheme@@(guile-user)>
3273@end example
3274
3275@noindent
3276Note that non-monadic values cannot be returned in the
3277@code{store-monad} REPL.
3278
e87f0591
LC
3279The main syntactic forms to deal with monads in general are provided by
3280the @code{(guix monads)} module and are described below.
b860f382
LC
3281
3282@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3283Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3284in @var{monad}.
3285@end deffn
3286
3287@deffn {Scheme Syntax} return @var{val}
3288Return a monadic value that encapsulates @var{val}.
3289@end deffn
3290
751630c9 3291@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3292@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3293procedures @var{mproc}@dots{}@footnote{This operation is commonly
3294referred to as ``bind'', but that name denotes an unrelated procedure in
3295Guile. Thus we use this somewhat cryptic symbol inherited from the
3296Haskell language.}. There can be one @var{mproc} or several of them, as
3297in this example:
3298
3299@example
3300(run-with-state
3301 (with-monad %state-monad
3302 (>>= (return 1)
3303 (lambda (x) (return (+ 1 x)))
3304 (lambda (x) (return (* 2 x)))))
3305 'some-state)
3306
3307@result{} 4
3308@result{} some-state
3309@end example
b860f382
LC
3310@end deffn
3311
3312@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3313 @var{body} ...
3314@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3315 @var{body} ...
3316Bind the variables @var{var} to the monadic values @var{mval} in
3317@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3318``normal'' value @var{val}, as per @code{let}.
3319
3320@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3321(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3322@end deffn
3323
405a9d4e
LC
3324@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3325Bind @var{mexp} and the following monadic expressions in sequence,
3326returning the result of the last expression.
3327
3328This is akin to @code{mlet}, except that the return values of the
3329monadic expressions are ignored. In that sense, it is analogous to
3330@code{begin}, but applied to monadic expressions.
3331@end deffn
3332
561fb6c3
LC
3333@cindex state monad
3334The @code{(guix monads)} module provides the @dfn{state monad}, which
3335allows an additional value---the state---to be @emph{threaded} through
3336monadic procedure calls.
3337
3338@defvr {Scheme Variable} %state-monad
3339The state monad. Procedures in the state monad can access and change
3340the state that is threaded.
3341
3342Consider the example below. The @code{square} procedure returns a value
3343in the state monad. It returns the square of its argument, but also
3344increments the current state value:
3345
3346@example
3347(define (square x)
3348 (mlet %state-monad ((count (current-state)))
3349 (mbegin %state-monad
3350 (set-current-state (+ 1 count))
3351 (return (* x x)))))
3352
3353(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3354@result{} (0 1 4)
3355@result{} 3
3356@end example
3357
3358When ``run'' through @var{%state-monad}, we obtain that additional state
3359value, which is the number of @code{square} calls.
3360@end defvr
3361
3362@deffn {Monadic Procedure} current-state
3363Return the current state as a monadic value.
3364@end deffn
3365
3366@deffn {Monadic Procedure} set-current-state @var{value}
3367Set the current state to @var{value} and return the previous state as a
3368monadic value.
3369@end deffn
3370
3371@deffn {Monadic Procedure} state-push @var{value}
3372Push @var{value} to the current state, which is assumed to be a list,
3373and return the previous state as a monadic value.
3374@end deffn
3375
3376@deffn {Monadic Procedure} state-pop
3377Pop a value from the current state and return it as a monadic value.
3378The state is assumed to be a list.
3379@end deffn
3380
3381@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3382Run monadic value @var{mval} starting with @var{state} as the initial
3383state. Return two values: the resulting value, and the resulting state.
3384@end deffn
3385
e87f0591
LC
3386The main interface to the store monad, provided by the @code{(guix
3387store)} module, is as follows.
b860f382
LC
3388
3389@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3390The store monad---an alias for @var{%state-monad}.
3391
3392Values in the store monad encapsulate accesses to the store. When its
3393effect is needed, a value of the store monad must be ``evaluated'' by
3394passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3395@end defvr
3396
3397@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3398Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3399open store connection.
3400@end deffn
3401
ad372953 3402@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3403Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3404containing @var{text}, a string. @var{references} is a list of store items that the
3405resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3406@end deffn
3407
0a90af15
LC
3408@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
3409 [#:recursive? #t]
3410Return the name of @var{file} once interned in the store. Use
3411@var{name} as its store name, or the basename of @var{file} if
3412@var{name} is omitted.
3413
3414When @var{recursive?} is true, the contents of @var{file} are added
3415recursively; if @var{file} designates a flat file and @var{recursive?}
3416is true, its contents are added, and its permission bits are kept.
3417
3418The example below adds a file to the store, under two different names:
3419
3420@example
3421(run-with-store (open-connection)
3422 (mlet %store-monad ((a (interned-file "README"))
3423 (b (interned-file "README" "LEGU-MIN")))
3424 (return (list a b))))
3425
3426@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3427@end example
3428
3429@end deffn
3430
e87f0591
LC
3431The @code{(guix packages)} module exports the following package-related
3432monadic procedures:
3433
b860f382 3434@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b 3435 [#:system (%current-system)] [#:target #f] @
f97c9175
AE
3436 [#:output "out"]
3437Return as a monadic
b860f382
LC
3438value in the absolute file name of @var{file} within the @var{output}
3439directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3440of the @var{output} directory of @var{package}. When @var{target} is
3441true, use it as a cross-compilation target triplet.
b860f382
LC
3442@end deffn
3443
b860f382 3444@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3445@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3446 @var{target} [@var{system}]
3447Monadic version of @code{package-derivation} and
3448@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3449@end deffn
3450
3451
21b679f6
LC
3452@node G-Expressions
3453@section G-Expressions
3454
3455@cindex G-expression
3456@cindex build code quoting
3457So we have ``derivations'', which represent a sequence of build actions
3458to be performed to produce an item in the store (@pxref{Derivations}).
f97c9175 3459These build actions are performed when asking the daemon to actually
21b679f6
LC
3460build the derivations; they are run by the daemon in a container
3461(@pxref{Invoking guix-daemon}).
3462
3463@cindex strata of code
f97c9175 3464It should come as no surprise that we like to write these build actions
21b679f6
LC
3465in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3466code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3467Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3468Kiselyov, who has written insightful
3469@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3470on this topic}, refers to this kind of code generation as
3471@dfn{staging}.}: the ``host code''---code that defines packages, talks
3472to the daemon, etc.---and the ``build code''---code that actually
3473performs build actions, such as making directories, invoking
3474@command{make}, etc.
21b679f6
LC
3475
3476To describe a derivation and its build actions, one typically needs to
3477embed build code inside host code. It boils down to manipulating build
f97c9175 3478code as data, and the homoiconicity of Scheme---code has a direct
21b679f6 3479representation as data---comes in handy for that. But we need more than
f97c9175 3480the normal @code{quasiquote} mechanism in Scheme to construct build
21b679f6
LC
3481expressions.
3482
3483The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3484S-expressions adapted to build expressions. G-expressions, or
f97c9175 3485@dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
21b679f6 3486@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
f97c9175
AE
3487@code{#$}, and @code{#$@@}), which are comparable to
3488@code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
3489respectivel (@pxref{Expression Syntax, @code{quasiquote},, guile,
3490GNU Guile Reference Manual}). However, there are major differences:
21b679f6
LC
3491
3492@itemize
3493@item
3494Gexps are meant to be written to a file and run or manipulated by other
3495processes.
3496
3497@item
b39fc6f7
LC
3498When a high-level object such as a package or derivation is unquoted
3499inside a gexp, the result is as if its output file name had been
3500introduced.
ff40e9b7 3501
21b679f6
LC
3502@item
3503Gexps carry information about the packages or derivations they refer to,
3504and these dependencies are automatically added as inputs to the build
3505processes that use them.
3506@end itemize
3507
c2b84676 3508@cindex lowering, of high-level objects in gexps
343eacbe
LC
3509This mechanism is not limited to package and derivation
3510objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3511derivations or files in the store can be defined,
3512such that these objects can also be inserted
f97c9175 3513into gexps. For example, a useful type of high-level objects that can be
343eacbe 3514inserted in a gexp is ``file-like objects'', which make it easy to
f97c9175 3515add files to the store and to refer to them in
558e8b11
LC
3516derivations and such (see @code{local-file} and @code{plain-file}
3517below.)
b39fc6f7 3518
21b679f6
LC
3519To illustrate the idea, here is an example of a gexp:
3520
3521@example
3522(define build-exp
3523 #~(begin
3524 (mkdir #$output)
3525 (chdir #$output)
aff8ce7c 3526 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3527 "list-files")))
3528@end example
3529
3530This gexp can be passed to @code{gexp->derivation}; we obtain a
3531derivation that builds a directory containing exactly one symlink to
3532@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3533
3534@example
3535(gexp->derivation "the-thing" build-exp)
3536@end example
3537
e20fd1bf 3538As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3539substituted to the reference to the @var{coreutils} package in the
3540actual build code, and @var{coreutils} is automatically made an input to
3541the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
f97c9175
AE
3542output)}) is replaced by a string containing the directory name of the
3543output of the derivation.
667b2508
LC
3544
3545@cindex cross compilation
3546In a cross-compilation context, it is useful to distinguish between
3547references to the @emph{native} build of a package---that can run on the
3548host---versus references to cross builds of a package. To that end, the
3549@code{#+} plays the same role as @code{#$}, but is a reference to a
3550native package build:
3551
3552@example
3553(gexp->derivation "vi"
3554 #~(begin
3555 (mkdir #$output)
3556 (system* (string-append #+coreutils "/bin/ln")
3557 "-s"
3558 (string-append #$emacs "/bin/emacs")
3559 (string-append #$output "/bin/vi")))
3560 #:target "mips64el-linux")
3561@end example
3562
3563@noindent
3564In the example above, the native build of @var{coreutils} is used, so
3565that @command{ln} can actually run on the host; but then the
3566cross-compiled build of @var{emacs} is referenced.
3567
3568The syntactic form to construct gexps is summarized below.
21b679f6
LC
3569
3570@deffn {Scheme Syntax} #~@var{exp}
3571@deffnx {Scheme Syntax} (gexp @var{exp})
3572Return a G-expression containing @var{exp}. @var{exp} may contain one
3573or more of the following forms:
3574
3575@table @code
3576@item #$@var{obj}
3577@itemx (ungexp @var{obj})
b39fc6f7
LC
3578Introduce a reference to @var{obj}. @var{obj} may have one of the
3579supported types, for example a package or a
21b679f6
LC
3580derivation, in which case the @code{ungexp} form is replaced by its
3581output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3582
b39fc6f7
LC
3583If @var{obj} is a list, it is traversed and references to supported
3584objects are substituted similarly.
21b679f6
LC
3585
3586If @var{obj} is another gexp, its contents are inserted and its
3587dependencies are added to those of the containing gexp.
3588
3589If @var{obj} is another kind of object, it is inserted as is.
3590
b39fc6f7
LC
3591@item #$@var{obj}:@var{output}
3592@itemx (ungexp @var{obj} @var{output})
21b679f6 3593This is like the form above, but referring explicitly to the
b39fc6f7
LC
3594@var{output} of @var{obj}---this is useful when @var{obj} produces
3595multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3596
667b2508
LC
3597@item #+@var{obj}
3598@itemx #+@var{obj}:output
3599@itemx (ungexp-native @var{obj})
3600@itemx (ungexp-native @var{obj} @var{output})
3601Same as @code{ungexp}, but produces a reference to the @emph{native}
3602build of @var{obj} when used in a cross compilation context.
3603
21b679f6
LC
3604@item #$output[:@var{output}]
3605@itemx (ungexp output [@var{output}])
3606Insert a reference to derivation output @var{output}, or to the main
3607output when @var{output} is omitted.
3608
3609This only makes sense for gexps passed to @code{gexp->derivation}.
3610
3611@item #$@@@var{lst}
3612@itemx (ungexp-splicing @var{lst})
3613Like the above, but splices the contents of @var{lst} inside the
3614containing list.
3615
667b2508
LC
3616@item #+@@@var{lst}
3617@itemx (ungexp-native-splicing @var{lst})
3618Like the above, but refers to native builds of the objects listed in
3619@var{lst}.
3620
21b679f6
LC
3621@end table
3622
3623G-expressions created by @code{gexp} or @code{#~} are run-time objects
3624of the @code{gexp?} type (see below.)
3625@end deffn
3626
3627@deffn {Scheme Procedure} gexp? @var{obj}
3628Return @code{#t} if @var{obj} is a G-expression.
3629@end deffn
3630
3631G-expressions are meant to be written to disk, either as code building
3632some derivation, or as plain files in the store. The monadic procedures
3633below allow you to do that (@pxref{The Store Monad}, for more
3634information about monads.)
3635
3636@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 3637 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
3638 [#:hash #f] [#:hash-algo #f] @
3639 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 3640 [#:module-path @var{%load-path}] @
c8351d9a 3641 [#:references-graphs #f] [#:allowed-references #f] @
c0468155 3642 [#:leaked-env-vars #f] @
0309e1b0 3643 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 3644 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 3645Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
3646@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
3647stored in a file called @var{script-name}. When @var{target} is true,
3648it is used as the cross-compilation target triplet for packages referred
3649to by @var{exp}.
21b679f6 3650
ce45eb4c
LC
3651Make @var{modules} available in the evaluation context of @var{exp};
3652@var{modules} is a list of names of Guile modules searched in
3653@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
3654the load path during the execution of @var{exp}---e.g., @code{((guix
3655build utils) (guix build gnu-build-system))}.
3656
ce45eb4c
LC
3657@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
3658applicable.
3659
b53833b2
LC
3660When @var{references-graphs} is true, it must be a list of tuples of one of the
3661following forms:
3662
3663@example
3664(@var{file-name} @var{package})
3665(@var{file-name} @var{package} @var{output})
3666(@var{file-name} @var{derivation})
3667(@var{file-name} @var{derivation} @var{output})
3668(@var{file-name} @var{store-item})
3669@end example
3670
3671The right-hand-side of each element of @var{references-graphs} is automatically made
3672an input of the build process of @var{exp}. In the build environment, each
3673@var{file-name} contains the reference graph of the corresponding item, in a simple
3674text format.
3675
c8351d9a
LC
3676@var{allowed-references} must be either @code{#f} or a list of output names and packages.
3677In the latter case, the list denotes store items that the result is allowed to
3678refer to. Any reference to another store item will lead to a build error.
3679
e20fd1bf 3680The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
3681@end deffn
3682
343eacbe 3683@cindex file-like objects
e1c153e0
LC
3684The @code{local-file}, @code{plain-file}, @code{computed-file},
3685@code{program-file}, and @code{scheme-file} procedures below return
3686@dfn{file-like objects}. That is, when unquoted in a G-expression,
3687these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
3688
3689@example
3690#~(system* (string-append #$glibc "/sbin/nscd") "-f"
3691 #$(local-file "/tmp/my-nscd.conf"))
3692@end example
3693
3694The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
3695to the store. Once expanded, for instance @i{via}
3696@code{gexp->derivation}, the G-expression refers to that copy under
3697@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
3698does not have any effect on what the G-expression does.
3699@code{plain-file} can be used similarly; it differs in that the file
3700content is directly passed as a string.
3701
d9ae938f
LC
3702@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
3703 [#:recursive? #t]
3704Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
3705object can be used in a gexp. If @var{file} is a relative file name, it is looked
3706up relative to the source file where this form appears. @var{file} will be added to
3707the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
3708
3709When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
3710designates a flat file and @var{recursive?} is true, its contents are added, and its
3711permission bits are kept.
3712
3713This is the declarative counterpart of the @code{interned-file} monadic
3714procedure (@pxref{The Store Monad, @code{interned-file}}).
3715@end deffn
3716
558e8b11
LC
3717@deffn {Scheme Procedure} plain-file @var{name} @var{content}
3718Return an object representing a text file called @var{name} with the given
3719@var{content} (a string) to be added to the store.
3720
3721This is the declarative counterpart of @code{text-file}.
3722@end deffn
3723
91937029
LC
3724@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
3725 [#:modules '()] [#:options '(#:local-build? #t)]
3726Return an object representing the store item @var{name}, a file or
3727directory computed by @var{gexp}. @var{modules} specifies the set of
3728modules visible in the execution context of @var{gexp}. @var{options}
3729is a list of additional arguments to pass to @code{gexp->derivation}.
3730
3731This is the declarative counterpart of @code{gexp->derivation}.
3732@end deffn
3733
21b679f6
LC
3734@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
3735Return an executable script @var{name} that runs @var{exp} using
3736@var{guile} with @var{modules} in its search path.
3737
3738The example below builds a script that simply invokes the @command{ls}
3739command:
3740
3741@example
3742(use-modules (guix gexp) (gnu packages base))
3743
3744(gexp->script "list-files"
3745 #~(execl (string-append #$coreutils "/bin/ls")
3746 "ls"))
3747@end example
3748
3749When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 3750@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
3751executable file @file{/gnu/store/@dots{}-list-files} along these lines:
3752
3753@example
3754#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
3755!#
3756(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
3757 "ls")
3758@end example
3759@end deffn
3760
15a01c72
LC
3761@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
3762 [#:modules '()] [#:guile #f]
3763Return an object representing the executable store item @var{name} that
3764runs @var{gexp}. @var{guile} is the Guile package used to execute that
3765script, and @var{modules} is the list of modules visible to that script.
3766
3767This is the declarative counterpart of @code{gexp->script}.
3768@end deffn
3769
21b679f6
LC
3770@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
3771Return a derivation that builds a file @var{name} containing @var{exp}.
3772
3773The resulting file holds references to all the dependencies of @var{exp}
3774or a subset thereof.
3775@end deffn
1ed19464 3776
e1c153e0
LC
3777@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
3778Return an object representing the Scheme file @var{name} that contains
3779@var{exp}.
3780
3781This is the declarative counterpart of @code{gexp->file}.
3782@end deffn
3783
1ed19464
LC
3784@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
3785Return as a monadic value a derivation that builds a text file
3786containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
3787strings, objects of any type that can be used in a gexp: packages,
3788derivations, local file objects, etc. The resulting store file holds
3789references to all these.
1ed19464
LC
3790
3791This variant should be preferred over @code{text-file} anytime the file
3792to create will reference items from the store. This is typically the
3793case when building a configuration file that embeds store file names,
3794like this:
3795
3796@example
3797(define (profile.sh)
3798 ;; Return the name of a shell script in the store that
3799 ;; initializes the 'PATH' environment variable.
3800 (text-file* "profile.sh"
3801 "export PATH=" coreutils "/bin:"
3802 grep "/bin:" sed "/bin\n"))
3803@end example
3804
3805In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
3806will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
3807preventing them from being garbage-collected during its lifetime.
3808@end deffn
21b679f6 3809
b751cde3
LC
3810@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
3811Return an object representing store file @var{name} containing
3812@var{text}. @var{text} is a sequence of strings and file-like objects,
3813as in:
3814
3815@example
3816(mixed-text-file "profile"
3817 "export PATH=" coreutils "/bin:" grep "/bin")
3818@end example
3819
3820This is the declarative counterpart of @code{text-file*}.
3821@end deffn
3822
21b679f6
LC
3823Of course, in addition to gexps embedded in ``host'' code, there are
3824also modules containing build tools. To make it clear that they are
3825meant to be used in the build stratum, these modules are kept in the
3826@code{(guix build @dots{})} name space.
3827
c2b84676
LC
3828@cindex lowering, of high-level objects in gexps
3829Internally, high-level objects are @dfn{lowered}, using their compiler,
3830to either derivations or store items. For instance, lowering a package
3831yields a derivation, and lowering a @code{plain-file} yields a store
3832item. This is achieved using the @code{lower-object} monadic procedure.
3833
3834@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
3835 [#:target #f]
3836Return as a value in @var{%store-monad} the derivation or store item
3837corresponding to @var{obj} for @var{system}, cross-compiling for
3838@var{target} if @var{target} is true. @var{obj} must be an object that
3839has an associated gexp compiler, such as a @code{<package>}.
3840@end deffn
3841
21b679f6 3842
568717fd
LC
3843@c *********************************************************************
3844@node Utilities
3845@chapter Utilities
3846
210cc920
LC
3847This section describes tools primarily targeted at developers and users
3848who write new package definitions. They complement the Scheme
3849programming interface of Guix in a convenient way.
3850
568717fd 3851@menu
37166310 3852* Invoking guix build:: Building packages from the command line.
39bee8a2 3853* Invoking guix edit:: Editing package definitions.
210cc920 3854* Invoking guix download:: Downloading a file and printing its hash.
37166310 3855* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 3856* Invoking guix import:: Importing package definitions.
37166310 3857* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 3858* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 3859* Invoking guix size:: Profiling disk usage.
88856916 3860* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 3861* Invoking guix environment:: Setting up development environments.
aff8ce7c 3862* Invoking guix publish:: Sharing substitutes.
d23c20f1 3863* Invoking guix challenge:: Challenging substitute servers.
32efa254 3864* Invoking guix container:: Process isolation.
568717fd
LC
3865@end menu
3866
e49951eb
MW
3867@node Invoking guix build
3868@section Invoking @command{guix build}
568717fd 3869
e49951eb 3870The @command{guix build} command builds packages or derivations and
6798a8e4
LC
3871their dependencies, and prints the resulting store paths. Note that it
3872does not modify the user's profile---this is the job of the
e49951eb 3873@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
3874it is mainly useful for distribution developers.
3875
3876The general syntax is:
c78bd12b
LC
3877
3878@example
e49951eb 3879guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
3880@end example
3881
f97c9175 3882As an example, the following command builds the latest versions of Emacs
ccd7158d
LC
3883and of Guile, displays their build logs, and finally displays the
3884resulting directories:
3885
3886@example
3887guix build emacs guile
3888@end example
3889
3890Similarly, the following command builds all the available packages:
3891
3892@example
5284339d 3893guix build --quiet --keep-going \
ccd7158d
LC
3894 `guix package -A | cut -f1,2 --output-delimiter=@@`
3895@end example
3896
c78bd12b 3897@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
3898the software distribution such as @code{coreutils} or
3899@code{coreutils-8.20}, or a derivation such as
834129e0 3900@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
3901package with the corresponding name (and optionally version) is searched
3902for among the GNU distribution modules (@pxref{Package Modules}).
3903
3904Alternatively, the @code{--expression} option may be used to specify a
3905Scheme expression that evaluates to a package; this is useful when
3906disambiguation among several same-named packages or package variants is
3907needed.
c78bd12b 3908
ccd7158d
LC
3909There may be zero or more @var{options}. The available options are
3910described in the subsections below.
3911
3912@menu
3913* Common Build Options:: Build options for most commands.
88ad6ded 3914* Package Transformation Options:: Creating variants of packages.
ccd7158d
LC
3915* Additional Build Options:: Options specific to 'guix build'.
3916@end menu
3917
3918@node Common Build Options
3919@subsection Common Build Options
3920
3921A number of options that control the build process are common to
3922@command{guix build} and other commands that can spawn builds, such as
3923@command{guix package} or @command{guix archive}. These are the
3924following:
3925
3926@table @code
3927
3928@item --load-path=@var{directory}
3929@itemx -L @var{directory}
3930Add @var{directory} to the front of the package module search path
3931(@pxref{Package Modules}).
3932
3933This allows users to define their own packages and make them visible to
3934the command-line tools.
3935
3936@item --keep-failed
3937@itemx -K
3938Keep the build tree of failed builds. Thus, if a build fail, its build
3939tree is kept under @file{/tmp}, in a directory whose name is shown at
3940the end of the build log. This is useful when debugging build issues.
3941
3942@item --keep-going
3943@itemx -k
3944Keep going when some of the derivations fail to build; return only once
3945all the builds have either completed or failed.
3946
3947The default behavior is to stop as soon as one of the specified
3948derivations has failed.
3949
3950@item --dry-run
3951@itemx -n
3952Do not build the derivations.
3953
3954@item --fallback
3955When substituting a pre-built binary fails, fall back to building
3956packages locally.
3957
3958@item --substitute-urls=@var{urls}
3959@anchor{client-substitute-urls}
3960Consider @var{urls} the whitespace-separated list of substitute source
3961URLs, overriding the default list of URLs of @command{guix-daemon}
3962(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
3963
3964This means that substitutes may be downloaded from @var{urls}, provided
3965they are signed by a key authorized by the system administrator
3966(@pxref{Substitutes}).
3967
3968@item --no-substitutes
3969Do not use substitutes for build products. That is, always build things
3970locally instead of allowing downloads of pre-built binaries
3971(@pxref{Substitutes}).
3972
7573d30f
LC
3973@item --no-grafts
3974Do not ``graft'' packages. In practice, this means that package updates
3975available as grafts are not applied. @xref{Security Updates}, for more
3976information on grafts.
3977
ccd7158d
LC
3978@item --rounds=@var{n}
3979Build each derivation @var{n} times in a row, and raise an error if
3980consecutive build results are not bit-for-bit identical.
3981
3982This is a useful way to detect non-deterministic builds processes.
3983Non-deterministic build processes are a problem because they make it
3984practically impossible for users to @emph{verify} whether third-party
3985binaries are genuine. @xref{Invoking guix challenge}, for more.
3986
3987Note that, currently, the differing build results are not kept around,
3988so you will have to manually investigate in case of an error---e.g., by
3989stashing one of the build results with @code{guix archive --export},
3990then rebuilding, and finally comparing the two results.
3991
3992@item --no-build-hook
f97c9175 3993Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
ccd7158d
LC
3994(@pxref{Daemon Offload Setup}). That is, always build things locally
3995instead of offloading builds to remote machines.
3996
3997@item --max-silent-time=@var{seconds}
3998When the build or substitution process remains silent for more than
3999@var{seconds}, terminate it and report a build failure.
4000
4001@item --timeout=@var{seconds}
4002Likewise, when the build or substitution process lasts for more than
4003@var{seconds}, terminate it and report a build failure.
4004
4005By default there is no timeout. This behavior can be restored with
4006@code{--timeout=0}.
4007
4008@item --verbosity=@var{level}
4009Use the given verbosity level. @var{level} must be an integer between 0
4010and 5; higher means more verbose output. Setting a level of 4 or more
4011may be helpful when debugging setup issues with the build daemon.
4012
4013@item --cores=@var{n}
4014@itemx -c @var{n}
4015Allow the use of up to @var{n} CPU cores for the build. The special
4016value @code{0} means to use as many CPU cores as available.
4017
4018@item --max-jobs=@var{n}
4019@itemx -M @var{n}
4020Allow at most @var{n} build jobs in parallel. @xref{Invoking
4021guix-daemon, @code{--max-jobs}}, for details about this option and the
4022equivalent @command{guix-daemon} option.
4023
4024@end table
4025
4026Behind the scenes, @command{guix build} is essentially an interface to
4027the @code{package-derivation} procedure of the @code{(guix packages)}
4028module, and to the @code{build-derivations} procedure of the @code{(guix
4029derivations)} module.
4030
4031In addition to options explicitly passed on the command line,
4032@command{guix build} and other @command{guix} commands that support
4033building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4034
4035@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4036Users can define this variable to a list of command line options that
4037will automatically be used by @command{guix build} and other
4038@command{guix} commands that can perform builds, as in the example
4039below:
4040
4041@example
4042$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4043@end example
4044
4045These options are parsed independently, and the result is appended to
4046the parsed command-line options.
4047@end defvr
4048
88ad6ded
LC
4049
4050@node Package Transformation Options
4051@subsection Package Transformation Options
4052
4053@cindex package variants
4054Another set of command-line options supported by @command{guix build}
b8638f03 4055and also @command{guix package} are @dfn{package transformation
f97c9175 4056options}. These are options that make it possible to define @dfn{package
b8638f03
LC
4057variants}---for instance, packages built from different source code.
4058This is a convenient way to create customized packages on the fly
4059without having to type in the definitions of package variants
4060(@pxref{Defining Packages}).
88ad6ded
LC
4061
4062@table @code
4063
4064@item --with-source=@var{source}
4065Use @var{source} as the source of the corresponding package.
4066@var{source} must be a file name or a URL, as for @command{guix
4067download} (@pxref{Invoking guix download}).
4068
f97c9175
AE
4069The ``corresponding package'' is taken to be the one specified on the
4070command line the name of which matches the base of @var{source}---e.g.,
4071if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
88ad6ded 4072package is @code{guile}. Likewise, the version string is inferred from
f97c9175 4073@var{source}; in the previous example, it is @code{2.0.10}.
88ad6ded
LC
4074
4075This option allows users to try out versions of packages other than the
4076one provided by the distribution. The example below downloads
4077@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4078the @code{ed} package:
4079
4080@example
4081guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4082@end example
4083
4084As a developer, @code{--with-source} makes it easy to test release
4085candidates:
4086
4087@example
4088guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4089@end example
4090
4091@dots{} or to build from a checkout in a pristine environment:
4092
4093@example
4094$ git clone git://git.sv.gnu.org/guix.git
4095$ guix build guix --with-source=./guix
4096@end example
4097
47c0f92c
LC
4098@item --with-input=@var{package}=@var{replacement}
4099Replace dependency on @var{package} by a dependency on
4100@var{replacement}. @var{package} must be a package name, and
4101@var{replacement} must be a package specification such as @code{guile}
4102or @code{guile@@1.8}.
4103
f97c9175 4104For instance, the following command builds Guix, but replaces its
47c0f92c
LC
4105dependency on the current stable version of Guile with a dependency on
4106the development version of Guile, @code{guile-next}:
4107
4108@example
4109guix build --with-input=guile=guile-next guix
4110@end example
4111
4112This is a recursive, deep replacement. So in this example, both
4113@code{guix} and its dependency @code{guile-json} (which also depends on
4114@code{guile}) get rebuilt against @code{guile-next}.
4115
4116However, implicit inputs are left unchanged.
88ad6ded
LC
4117@end table
4118
ccd7158d
LC
4119@node Additional Build Options
4120@subsection Additional Build Options
4121
4122The command-line options presented below are specific to @command{guix
4123build}.
c78bd12b
LC
4124
4125@table @code
4126
5284339d
LC
4127@item --quiet
4128@itemx -q
4129Build quietly, without displaying the build log. Upon completion, the
4130build log is kept in @file{/var} (or similar) and can always be
4131retrieved using the @option{--log-file} option.
4132
34a1783f
DT
4133@item --file=@var{file}
4134@itemx -f @var{file}
4135
4136Build the package or derivation that the code within @var{file}
4137evaluates to.
4138
4139As an example, @var{file} might contain a package definition like this
4140(@pxref{Defining Packages}):
4141
4142@example
4143@verbatiminclude package-hello.scm
4144@end example
4145
c78bd12b
LC
4146@item --expression=@var{expr}
4147@itemx -e @var{expr}
ac5de156 4148Build the package or derivation @var{expr} evaluates to.
c78bd12b 4149
5401dd75 4150For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
4151guile-1.8)}, which unambiguously designates this specific variant of
4152version 1.8 of Guile.
4153
f97c9175 4154Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
4155as a build program passed to @code{gexp->derivation}
4156(@pxref{G-Expressions}).
4157
4158Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
4159(@pxref{The Store Monad}). The procedure must return a derivation as a
4160monadic value, which is then passed through @code{run-with-store}.
4161
c78bd12b
LC
4162@item --source
4163@itemx -S
f97c9175 4164Build the source derivations of the packages, rather than the packages
c78bd12b
LC
4165themselves.
4166
e49951eb 4167For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
4168@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4169source tarball.
c78bd12b 4170
f9cc8971 4171The returned source tarball is the result of applying any patches and
f97c9175 4172code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
4173Packages}).
4174
2cdfe13d
EB
4175@item --sources
4176Fetch and return the source of @var{package-or-derivation} and all their
4177dependencies, recursively. This is a handy way to obtain a local copy
4178of all the source code needed to build @var{packages}, allowing you to
4179eventually build them even without network access. It is an extension
4180of the @code{--source} option and can accept one of the following
4181optional argument values:
4182
4183@table @code
4184@item package
4185This value causes the @code{--sources} option to behave in the same way
4186as the @code{--source} option.
4187
4188@item all
f97c9175
AE
4189Build the source derivations of all packages, including any source that
4190might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
4191
4192@example
4193$ guix build --sources tzdata
4194The following derivations will be built:
4195 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4196 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4197@end example
4198
4199@item transitive
f97c9175
AE
4200Build the source derivations of all packages, as well of all transitive
4201inputs to the packages. This can be used e.g. to
2cdfe13d
EB
4202prefetch package source for later offline building.
4203
4204@example
4205$ guix build --sources=transitive tzdata
4206The following derivations will be built:
4207 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4208 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4209 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4210 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4211 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4212 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4213@dots{}
4214@end example
4215
4216@end table
4217
c78bd12b
LC
4218@item --system=@var{system}
4219@itemx -s @var{system}
4220Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 4221the system type of the build host.
c78bd12b
LC
4222
4223An example use of this is on Linux-based systems, which can emulate
4224different personalities. For instance, passing
4225@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4226to build packages in a complete 32-bit environment.
4227
e55ec43d
LC
4228@item --target=@var{triplet}
4229@cindex cross-compilation
4230Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4231as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4232configuration triplets,, configure, GNU Configure and Build System}).
4233
a8d65643
LC
4234@anchor{build-check}
4235@item --check
4236@cindex determinism, checking
4237@cindex reproducibility, checking
4238Rebuild @var{package-or-derivation}, which are already available in the
4239store, and raise an error if the build results are not bit-for-bit
4240identical.
4241
f97c9175
AE
4242This mechanism allows you to check whether previously installed
4243substitutes are genuine (@pxref{Substitutes}), or whether the build result
4244of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
4245background information and tools.
4246
c78bd12b
LC
4247@item --derivations
4248@itemx -d
4249Return the derivation paths, not the output paths, of the given
4250packages.
4251
70ee5642
LC
4252@item --root=@var{file}
4253@itemx -r @var{file}
4254Make @var{file} a symlink to the result, and register it as a garbage
4255collector root.
4256
4257@item --log-file
3f208ad7 4258Return the build log file names or URLs for the given
f97c9175 4259@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
4260missing.
4261
4262This works regardless of how packages or derivations are specified. For
4263instance, the following invocations are equivalent:
4264
4265@example
4266guix build --log-file `guix build -d guile`
4267guix build --log-file `guix build guile`
4268guix build --log-file guile
4269guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4270@end example
4271
3f208ad7
LC
4272If a log is unavailable locally, and unless @code{--no-substitutes} is
4273passed, the command looks for a corresponding log on one of the
4274substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 4275
f97c9175
AE
4276So for instance, imagine you want to see the build log of GDB on MIPS,
4277but you are actually on an @code{x86_64} machine:
3f208ad7
LC
4278
4279@example
4280$ guix build --log-file gdb -s mips64el-linux
4281http://hydra.gnu.org/log/@dots{}-gdb-7.10
4282@end example
4283
4284You can freely access a huge library of build logs!
70ee5642
LC
4285@end table
4286
16eb115e 4287
39bee8a2
LC
4288@node Invoking guix edit
4289@section Invoking @command{guix edit}
4290
4291@cindex package definition, editing
4292So many packages, so many source files! The @command{guix edit} command
4293facilitates the life of packagers by pointing their editor at the source
4294file containing the definition of the specified packages. For instance:
4295
4296@example
4297guix edit gcc-4.8 vim
4298@end example
4299
4300@noindent
6237b9fa
LC
4301launches the program specified in the @code{VISUAL} or in the
4302@code{EDITOR} environment variable to edit the recipe of GCC@tie{}4.8.4
4303and that of Vim.
39bee8a2 4304
f97c9175 4305If you are using Emacs, note that the Emacs user interface provides the
7c1b1ae2 4306@kbd{M-x guix-edit} command and a similar functionality in the ``package
f97c9175 4307info'' and ``package list'' buffers created by the @kbd{M-x
7c1b1ae2 4308guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
39bee8a2
LC
4309
4310
210cc920
LC
4311@node Invoking guix download
4312@section Invoking @command{guix download}
4313
4314When writing a package definition, developers typically need to download
f97c9175 4315a source tarball, compute its SHA256 hash, and write that
210cc920
LC
4316hash in the package definition (@pxref{Defining Packages}). The
4317@command{guix download} tool helps with this task: it downloads a file
4318from the given URI, adds it to the store, and prints both its file name
4319in the store and its SHA256 hash.
4320
4321The fact that the downloaded file is added to the store saves bandwidth:
4322when the developer eventually tries to build the newly defined package
4323with @command{guix build}, the source tarball will not have to be
4324downloaded again because it is already in the store. It is also a
4325convenient way to temporarily stash files, which may be deleted
4326eventually (@pxref{Invoking guix gc}).
4327
4328The @command{guix download} command supports the same URIs as used in
4329package definitions. In particular, it supports @code{mirror://} URIs.
4330@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4331Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4332they are not available, an error is raised. @xref{Guile Preparations,
4333how to install the GnuTLS bindings for Guile,, gnutls-guile,
4334GnuTLS-Guile}, for more information.
210cc920
LC
4335
4336The following option is available:
4337
4338@table @code
4339@item --format=@var{fmt}
4340@itemx -f @var{fmt}
4341Write the hash in the format specified by @var{fmt}. For more
081145cf 4342information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
4343@end table
4344
6c365eca
NK
4345@node Invoking guix hash
4346@section Invoking @command{guix hash}
4347
210cc920 4348The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4349It is primarily a convenience tool for anyone contributing to the
4350distribution: it computes the cryptographic hash of a file, which can be
4351used in the definition of a package (@pxref{Defining Packages}).
4352
4353The general syntax is:
4354
4355@example
4356guix hash @var{option} @var{file}
4357@end example
4358
4359@command{guix hash} has the following option:
4360
4361@table @code
4362
4363@item --format=@var{fmt}
4364@itemx -f @var{fmt}
210cc920 4365Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4366
4367Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4368(@code{hex} and @code{hexadecimal} can be used as well).
4369
4370If the @option{--format} option is not specified, @command{guix hash}
4371will output the hash in @code{nix-base32}. This representation is used
4372in the definitions of packages.
4373
3140f2df
LC
4374@item --recursive
4375@itemx -r
4376Compute the hash on @var{file} recursively.
4377
4378In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
4379including its children if it is a directory. Some of the metadata of
4380@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 4381regular file, the hash is different depending on whether @var{file} is
f97c9175 4382executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
4383hash (@pxref{Invoking guix archive}).
4384@c FIXME: Replace xref above with xref to an ``Archive'' section when
4385@c it exists.
4386
6c365eca
NK
4387@end table
4388
2f7d2d91
LC
4389@node Invoking guix import
4390@section Invoking @command{guix import}
4391
4392@cindex importing packages
4393@cindex package import
4394@cindex package conversion
f97c9175
AE
4395The @command{guix import} command is useful for people who would like to
4396add a package to the distribution with as little work as
4397possible---a legitimate demand. The command knows of a few
4398repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
4399is a package definition, or a template thereof, in the format we know
4400(@pxref{Defining Packages}).
4401
4402The general syntax is:
4403
4404@example
4405guix import @var{importer} @var{options}@dots{}
4406@end example
4407
4408@var{importer} specifies the source from which to import package
f97c9175 4409metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
4410options specific to @var{importer}. Currently, the available
4411``importers'' are:
4412
4413@table @code
4414@item gnu
f97c9175 4415Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
4416for the latest version of that GNU package, including the hash of its
4417source tarball, and its canonical synopsis and description.
4418
f97c9175 4419Additional information such as the package dependencies and its
2f7d2d91
LC
4420license needs to be figured out manually.
4421
4422For example, the following command returns a package definition for
4423GNU@tie{}Hello:
4424
4425@example
4426guix import gnu hello
4427@end example
4428
4429Specific command-line options are:
4430
4431@table @code
4432@item --key-download=@var{policy}
4433As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 4434keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
4435refresh, @code{--key-download}}.
4436@end table
4437
4438@item pypi
4439@cindex pypi
f97c9175 4440Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
4441Index}@footnote{This functionality requires Guile-JSON to be installed.
4442@xref{Requirements}.}. Information is taken from the JSON-formatted
4443description available at @code{pypi.python.org} and usually includes all
4444the relevant information, including package dependencies.
4445
f97c9175 4446The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
4447package:
4448
4449@example
4450guix import pypi itsdangerous
4451@end example
4452
3aae8145
DT
4453@item gem
4454@cindex gem
f97c9175 4455Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
4456RubyGems}@footnote{This functionality requires Guile-JSON to be
4457installed. @xref{Requirements}.}. Information is taken from the
4458JSON-formatted description available at @code{rubygems.org} and includes
4459most relevant information, including runtime dependencies. There are
f97c9175 4460some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
4461synopses and descriptions, so the same string is used for both fields.
4462Additionally, the details of non-Ruby dependencies required to build
4463native extensions is unavailable and left as an exercise to the
4464packager.
4465
f97c9175 4466The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
4467
4468@example
4469guix import gem rails
4470@end example
4471
d45dc6da
EB
4472@item cpan
4473@cindex CPAN
3c192e4e
AE
4474Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4475functionality requires Guile-JSON to be installed.
4476@xref{Requirements}.}.
f97c9175 4477Information is taken from the JSON-formatted metadata provided through
d45dc6da 4478@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
4479relevant information, such as module dependencies. License information
4480should be checked closely. If Perl is available in the store, then the
4481@code{corelist} utility will be used to filter core modules out of the
4482list of dependencies.
d45dc6da 4483
f97c9175 4484The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
4485Perl module:
4486
4487@example
4488guix import cpan Acme::Boolean
4489@end example
4490
e1248602
RW
4491@item cran
4492@cindex CRAN
d0bd632f 4493@cindex Bioconductor
f97c9175 4494Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
4495central repository for the @uref{http://r-project.org, GNU@tie{}R
4496statistical and graphical environment}.
4497
f97c9175 4498Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 4499
f97c9175 4500The command command below imports metadata for the @code{Cairo}
e1248602
RW
4501R package:
4502
4503@example
4504guix import cran Cairo
4505@end example
4506
f97c9175 4507When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
4508@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
4509packages for for the analysis and comprehension of high-throughput
4510genomic data in bioinformatics.
4511
f97c9175 4512Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
4513published on the web interface of the Bioconductor SVN repository.
4514
f97c9175 4515The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
4516R package:
4517
4518@example
4519guix import cran --archive=bioconductor GenomicRanges
4520@end example
4521
2f7d2d91 4522@item nix
f97c9175 4523Import metadata from a local copy of the source of the
2f7d2d91
LC
4524@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
4525relies on the @command{nix-instantiate} command of
4526@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
4527typically written in a mixture of Nix-language and Bash code. This
4528command only imports the high-level package structure that is written in
4529the Nix language. It normally includes all the basic fields of a
4530package definition.
4531
4532When importing a GNU package, the synopsis and descriptions are replaced
4533by their canonical upstream variant.
4534
961d0d2d
LC
4535Usually, you will first need to do:
4536
4537@example
4538export NIX_REMOTE=daemon
4539@end example
4540
4541@noindent
4542so that @command{nix-instantiate} does not try to open the Nix database.
4543
2f7d2d91
LC
4544As an example, the command below imports the package definition of
4545LibreOffice (more precisely, it imports the definition of the package
4546bound to the @code{libreoffice} top-level attribute):
4547
4548@example
4549guix import nix ~/path/to/nixpkgs libreoffice
4550@end example
863af4e1
FB
4551
4552@item hackage
4553@cindex hackage
f97c9175 4554Import metadata from the Haskell community's central package archive
863af4e1
FB
4555@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
4556Cabal files and includes all the relevant information, including package
4557dependencies.
4558
4559Specific command-line options are:
4560
4561@table @code
a4154748
FB
4562@item --stdin
4563@itemx -s
f97c9175 4564Read a Cabal file from standard input.
863af4e1
FB
4565@item --no-test-dependencies
4566@itemx -t
f97c9175 4567Do not include dependencies required only by the test suites.
a4154748
FB
4568@item --cabal-environment=@var{alist}
4569@itemx -e @var{alist}
4570@var{alist} is a Scheme alist defining the environment in which the
4571Cabal conditionals are evaluated. The accepted keys are: @code{os},
4572@code{arch}, @code{impl} and a string representing the name of a flag.
4573The value associated with a flag has to be either the symbol
4574@code{true} or @code{false}. The value associated with other keys
4575has to conform to the Cabal file format definition. The default value
4576associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 4577@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
4578@end table
4579
f97c9175 4580The command below imports metadata for the latest version of the
a4154748
FB
4581@code{HTTP} Haskell package without including test dependencies and
4582specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
4583
4584@example
a4154748 4585guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
4586@end example
4587
4588A specific package version may optionally be specified by following the
1b846da8 4589package name by an at-sign and a version number as in the following example:
863af4e1
FB
4590
4591@example
1b846da8 4592guix import hackage mtl@@2.1.3.1
863af4e1 4593@end example
7f74a931
FB
4594
4595@item elpa
4596@cindex elpa
f97c9175 4597Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
4598repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
4599
4600Specific command-line options are:
4601
4602@table @code
4603@item --archive=@var{repo}
4604@itemx -a @var{repo}
4605@var{repo} identifies the archive repository from which to retrieve the
4606information. Currently the supported repositories and their identifiers
4607are:
4608@itemize -
4609@item
840bd1d3 4610@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
4611identifier. This is the default.
4612
4613@item
840bd1d3 4614@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
4615@code{melpa-stable} identifier.
4616
4617@item
840bd1d3 4618@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
4619identifier.
4620@end itemize
4621@end table
2f7d2d91
LC
4622@end table
4623
4624The structure of the @command{guix import} code is modular. It would be
4625useful to have more importers for other package formats, and your help
4626is welcome here (@pxref{Contributing}).
4627
37166310
LC
4628@node Invoking guix refresh
4629@section Invoking @command{guix refresh}
4630
4631The primary audience of the @command{guix refresh} command is developers
4632of the GNU software distribution. By default, it reports any packages
4633provided by the distribution that are outdated compared to the latest
4634upstream version, like this:
4635
4636@example
4637$ guix refresh
4638gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
4639gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
4640@end example
4641
f97c9175
AE
4642It does so by browsing the FTP directory of each package and determining
4643the highest version number of the source tarballs therein. The command
bcb571cb
LC
4644knows how to update specific types of packages: GNU packages, ELPA
4645packages, etc.---see the documentation for @option{--type} below. The
4646are many packages, though, for which it lacks a method to determine
4647whether a new upstream release is available. However, the mechanism is
4648extensible, so feel free to get in touch with us to add a new method!
37166310
LC
4649
4650When passed @code{--update}, it modifies distribution source files to
f97c9175 4651update the version numbers and source tarball hashes of those package
37166310
LC
4652recipes (@pxref{Defining Packages}). This is achieved by downloading
4653each package's latest source tarball and its associated OpenPGP
4654signature, authenticating the downloaded tarball against its signature
4655using @command{gpg}, and finally computing its hash. When the public
4656key used to sign the tarball is missing from the user's keyring, an
4657attempt is made to automatically retrieve it from a public key server;
f97c9175 4658when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
4659@command{guix refresh} reports an error.
4660
4661The following options are supported:
4662
4663@table @code
4664
2d7fc7da
LC
4665@item --expression=@var{expr}
4666@itemx -e @var{expr}
4667Consider the package @var{expr} evaluates to.
4668
4669This is useful to precisely refer to a package, as in this example:
4670
4671@example
4672guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
4673@end example
4674
4675This command lists the dependents of the ``final'' libc (essentially all
4676the packages.)
4677
37166310
LC
4678@item --update
4679@itemx -u
38e16b49
LC
4680Update distribution source files (package recipes) in place. This is
4681usually run from a checkout of the Guix source tree (@pxref{Running
4682Guix Before It Is Installed}):
4683
4684@example
4685$ ./pre-inst-env guix refresh -s non-core
4686@end example
4687
081145cf 4688@xref{Defining Packages}, for more information on package definitions.
37166310
LC
4689
4690@item --select=[@var{subset}]
4691@itemx -s @var{subset}
4692Select all the packages in @var{subset}, one of @code{core} or
4693@code{non-core}.
4694
4695The @code{core} subset refers to all the packages at the core of the
4696distribution---i.e., packages that are used to build ``everything
4697else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
4698changing one of these packages in the distribution entails a rebuild of
4699all the others. Thus, such updates are an inconvenience to users in
4700terms of build time or bandwidth used to achieve the upgrade.
4701
4702The @code{non-core} subset refers to the remaining packages. It is
4703typically useful in cases where an update of the core packages would be
4704inconvenient.
4705
bcb571cb
LC
4706@item --type=@var{updater}
4707@itemx -t @var{updater}
7191adc5
AK
4708Select only packages handled by @var{updater} (may be a comma-separated
4709list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
4710
4711@table @code
4712@item gnu
4713the updater for GNU packages;
e80c0f85
LC
4714@item gnome
4715the updater for GNOME packages;
62061d6b
AW
4716@item xorg
4717the updater for X.org packages;
bcb571cb 4718@item elpa
d882c235
LC
4719the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
4720@item cran
b9d044ef 4721the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
4722@item bioconductor
4723the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
bab020d7 4724@item pypi
b9d044ef 4725the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
4726@item gem
4727the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
4728@item github
4729the updater for @uref{https://github.com, GitHub} packages.
bcb571cb
LC
4730@end table
4731
f97c9175
AE
4732For instance, the following command only checks for updates of Emacs
4733packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
4734
4735@example
7191adc5 4736$ guix refresh --type=elpa,cran
d882c235 4737gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
4738gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
4739@end example
4740
37166310
LC
4741@end table
4742
4743In addition, @command{guix refresh} can be passed one or more package
4744names, as in this example:
4745
4746@example
38e16b49 4747$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
4748@end example
4749
4750@noindent
4751The command above specifically updates the @code{emacs} and
4752@code{idutils} packages. The @code{--select} option would have no
4753effect in this case.
4754
7d193ec3
EB
4755When considering whether to upgrade a package, it is sometimes
4756convenient to know which packages would be affected by the upgrade and
4757should be checked for compatibility. For this the following option may
4758be used when passing @command{guix refresh} one or more package names:
4759
4760@table @code
4761
6ffa706b
AK
4762@item --list-updaters
4763@itemx -L
4764List available updaters and exit (see @option{--type} above.)
4765
7d193ec3
EB
4766@item --list-dependent
4767@itemx -l
4768List top-level dependent packages that would need to be rebuilt as a
4769result of upgrading one or more packages.
4770
4771@end table
4772
4773Be aware that the @code{--list-dependent} option only
4774@emph{approximates} the rebuilds that would be required as a result of
4775an upgrade. More rebuilds might be required under some circumstances.
4776
4777@example
7779ab61
LC
4778$ guix refresh --list-dependent flex
4779Building the following 120 packages would ensure 213 dependent packages are rebuilt:
4780hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
4781@end example
4782
4783The command above lists a set of packages that could be built to check
4784for compatibility with an upgraded @code{flex} package.
4785
f9230085
LC
4786The following options can be used to customize GnuPG operation:
4787
4788@table @code
4789
f9230085
LC
4790@item --gpg=@var{command}
4791Use @var{command} as the GnuPG 2.x command. @var{command} is searched
4792for in @code{$PATH}.
4793
2bc53ba9
LC
4794@item --key-download=@var{policy}
4795Handle missing OpenPGP keys according to @var{policy}, which may be one
4796of:
4797
4798@table @code
4799@item always
4800Always download missing OpenPGP keys from the key server, and add them
4801to the user's GnuPG keyring.
4802
4803@item never
4804Never try to download missing OpenPGP keys. Instead just bail out.
4805
4806@item interactive
4807When a package signed with an unknown OpenPGP key is encountered, ask
4808the user whether to download it or not. This is the default behavior.
4809@end table
4810
4811@item --key-server=@var{host}
4812Use @var{host} as the OpenPGP key server when importing a public key.
4813
f9230085
LC
4814@end table
4815
917a2a58
BW
4816The @code{github} updater uses the
4817@uref{https://developer.github.com/v3/, GitHub API} to query for new
4818releases. When used repeatedly e.g. when refreshing all packages,
4819GitHub will eventually refuse to answer any further API requests. By
4820default 60 API requests per hour are allowed, and a full refresh on all
4821GitHub packages in Guix requires more than this. Authentication with
4822GitHub through the use of an API token alleviates these limits. To use
4823an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
4824token procured from @uref{https://github.com/settings/tokens} or
4825otherwise.
4826
4827
b4f5e0e8
CR
4828@node Invoking guix lint
4829@section Invoking @command{guix lint}
f97c9175
AE
4830The @command{guix lint} command is meant to help package developers avoid
4831common errors and use a consistent style. It runs a number of checks on
4832a given set of packages in order to find common mistakes in their
873c4085
LC
4833definitions. Available @dfn{checkers} include (see
4834@code{--list-checkers} for a complete list):
4835
4836@table @code
4837@item synopsis
4838@itemx description
4839Validate certain typographical and stylistic rules about package
4840descriptions and synopses.
4841
4842@item inputs-should-be-native
4843Identify inputs that should most likely be native inputs.
4844
4845@item source
4846@itemx home-page
50f5c46d 4847@itemx source-file-name
873c4085 4848Probe @code{home-page} and @code{source} URLs and report those that are
50f5c46d 4849invalid. Check that the source file name is meaningful, e.g. is not
f97c9175
AE
4850just a version number or ``git-checkout'', without a declared
4851@code{file-name} (@pxref{origin Reference}).
40a7d4e5 4852
5432734b
LC
4853@item cve
4854Report known vulnerabilities found in the Common Vulnerabilities and
4855Exposures (CVE) database
4856@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
4857NIST}.
4858
40a7d4e5
LC
4859@item formatting
4860Warn about obvious source code formatting issues: trailing white space,
4861use of tabulations, etc.
873c4085 4862@end table
b4f5e0e8
CR
4863
4864The general syntax is:
4865
4866@example
4867guix lint @var{options} @var{package}@dots{}
4868@end example
4869
4870If no package is given on the command line, then all packages are checked.
4871The @var{options} may be zero or more of the following:
4872
4873@table @code
f97c9175
AE
4874@item --list-checkers
4875@itemx -l
4876List and describe all the available checkers that will be run on packages
4877and exit.
b4f5e0e8 4878
dd7c013d
CR
4879@item --checkers
4880@itemx -c
4881Only enable the checkers specified in a comma-separated list using the
4882names returned by @code{--list-checkers}.
4883
b4f5e0e8 4884@end table
37166310 4885
fcc58db6
LC
4886@node Invoking guix size
4887@section Invoking @command{guix size}
4888
4889The @command{guix size} command helps package developers profile the
4890disk usage of packages. It is easy to overlook the impact of an
4891additional dependency added to a package, or the impact of using a
4892single output for a package that could easily be split (@pxref{Packages
f97c9175 4893with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
4894@command{guix size} can highlight.
4895
4896The command can be passed a package specification such as @code{gcc-4.8}
4897or @code{guile:debug}, or a file name in the store. Consider this
4898example:
4899
4900@example
4901$ guix size coreutils
4902store item total self
4903/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
4904/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
4905/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
4906/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
4907/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
4908/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
4909@end example
4910
4911@cindex closure
4912The store items listed here constitute the @dfn{transitive closure} of
4913Coreutils---i.e., Coreutils and all its dependencies, recursively---as
4914would be returned by:
4915
4916@example
4917$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
4918@end example
4919
f97c9175 4920Here the output shows three columns next to store items. The first column,
fcc58db6
LC
4921labeled ``total'', shows the size in mebibytes (MiB) of the closure of
4922the store item---that is, its own size plus the size of all its
4923dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
4924item itself. The last column shows the ratio of the size of the item
4925itself to the space occupied by all the items listed here.
fcc58db6
LC
4926
4927In this example, we see that the closure of Coreutils weighs in at
492870@tie{}MiB, half of which is taken by libc. (That libc represents a
4929large fraction of the closure is not a problem @i{per se} because it is
4930always available on the system anyway.)
4931
4932When the package passed to @command{guix size} is available in the
4933store, @command{guix size} queries the daemon to determine its
4934dependencies, and measures its size in the store, similar to @command{du
4935-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
4936Coreutils}).
4937
4938When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
4939reports information based on the available substitutes
4940(@pxref{Substitutes}). This makes it possible it to profile disk usage of
4941store items that are not even on disk, only available remotely.
fcc58db6 4942
a8f996c6 4943The available options are:
fcc58db6
LC
4944
4945@table @option
4946
d490d06e
LC
4947@item --substitute-urls=@var{urls}
4948Use substitute information from @var{urls}.
4949@xref{client-substitute-urls, the same option for @code{guix build}}.
4950
a8f996c6 4951@item --map-file=@var{file}
f97c9175 4952Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
4953
4954For the example above, the map looks like this:
4955
4956@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
4957produced by @command{guix size}}
4958
4959This option requires that
4960@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
4961installed and visible in Guile's module search path. When that is not
4962the case, @command{guix size} fails as it tries to load it.
4963
fcc58db6
LC
4964@item --system=@var{system}
4965@itemx -s @var{system}
4966Consider packages for @var{system}---e.g., @code{x86_64-linux}.
4967
4968@end table
4969
88856916
LC
4970@node Invoking guix graph
4971@section Invoking @command{guix graph}
4972
4973@cindex DAG
4974Packages and their dependencies form a @dfn{graph}, specifically a
4975directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175
AE
4976mental model of the package DAG, so the @command{guix graph} command
4977provides a visual representation of the DAG. @command{guix graph}
4978emits a DAG representation in the input format of
88856916 4979@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
f97c9175 4980directly to the @command{dot} command of Graphviz. The general
88856916
LC
4981syntax is:
4982
4983@example
4984guix graph @var{options} @var{package}@dots{}
4985@end example
4986
4987For example, the following command generates a PDF file representing the
4988package DAG for the GNU@tie{}Core Utilities, showing its build-time
4989dependencies:
4990
4991@example
4992guix graph coreutils | dot -Tpdf > dag.pdf
4993@end example
4994
4995The output looks like this:
4996
4997@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
4998
4999Nice little graph, no?
5000
f97c9175 5001But there is more than one graph! The one above is concise: it is the
88856916 5002graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
5003grep, etc. It is often useful to have such a concise graph, but
5004sometimes one may want to see more details. @command{guix graph} supports
5005several types of graphs, allowing you to choose the level of detail:
88856916
LC
5006
5007@table @code
5008@item package
f97c9175 5009This is the default type used in the example above. It shows the DAG of
88856916
LC
5010package objects, excluding implicit dependencies. It is concise, but
5011filters out many details.
5012
5013@item bag-emerged
5014This is the package DAG, @emph{including} implicit inputs.
5015
5016For instance, the following command:
5017
5018@example
5019guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5020@end example
5021
5022... yields this bigger graph:
5023
5024@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5025
5026At the bottom of the graph, we see all the implicit inputs of
5027@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5028
f97c9175 5029Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
5030@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5031here, for conciseness.
5032
5033@item bag
5034Similar to @code{bag-emerged}, but this time including all the bootstrap
5035dependencies.
5036
38b92daa
LC
5037@item bag-with-origins
5038Similar to @code{bag}, but also showing origins and their dependencies.
5039
88856916
LC
5040@item derivations
5041This is the most detailed representation: It shows the DAG of
5042derivations (@pxref{Derivations}) and plain store items. Compared to
5043the above representation, many additional nodes are visible, including
f97c9175 5044build scripts, patches, Guile modules, etc.
88856916
LC
5045
5046@end table
5047
f97c9175 5048All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
5049following graph type represents the @emph{run-time dependencies}:
5050
5051@table @code
5052@item references
5053This is the graph of @dfn{references} of a package output, as returned
5054by @command{guix gc --references} (@pxref{Invoking guix gc}).
5055
5056If the given package output is not available in the store, @command{guix
5057graph} attempts to obtain dependency information from substitutes.
5058@end table
5059
5060The available options are the following:
5061
5062@table @option
5063@item --type=@var{type}
5064@itemx -t @var{type}
5065Produce a graph output of @var{type}, where @var{type} must be one of
5066the values listed above.
5067
5068@item --list-types
5069List the supported graph types.
4c8f997a
LC
5070
5071@item --expression=@var{expr}
5072@itemx -e @var{expr}
5073Consider the package @var{expr} evaluates to.
5074
5075This is useful to precisely refer to a package, as in this example:
5076
5077@example
5078guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5079@end example
88856916
LC
5080@end table
5081
5082
372c4bbc
DT
5083@node Invoking guix environment
5084@section Invoking @command{guix environment}
5085
f5fd4fd2 5086@cindex reproducible build environments
fe36d84e 5087@cindex development environments
372c4bbc
DT
5088The purpose of @command{guix environment} is to assist hackers in
5089creating reproducible development environments without polluting their
5090package profile. The @command{guix environment} tool takes one or more
f97c9175 5091packages, builds all of their inputs, and creates a shell
372c4bbc
DT
5092environment to use them.
5093
5094The general syntax is:
5095
5096@example
5097guix environment @var{options} @var{package}@dots{}
5098@end example
5099
fe36d84e
LC
5100The following example spawns a new shell set up for the development of
5101GNU@tie{}Guile:
372c4bbc
DT
5102
5103@example
5104guix environment guile
5105@end example
5106
f97c9175
AE
5107If the needed dependencies are not built yet, @command{guix environment}
5108automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
5109version of the environment that @command{guix environment} was run in.
5110It contains the necessary search paths for building the given package
5111added to the existing environment variables. To create a ``pure''
f97c9175 5112environment, in which the original environment variables have been unset,
50500f7c
LC
5113use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5114environment variables such as @code{PATH} in their @file{~/.bashrc}
5115file. As a consequence, when @code{guix environment} launches it, Bash
5116may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5117environment variables. It is an error to define such environment
5118variables in @file{.bashrc}; instead, they should be defined in
5119@file{.bash_profile}, which is sourced only by log-in shells.
5120@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5121details on Bash start-up files.}.
372c4bbc 5122
28de8d25
LC
5123@vindex GUIX_ENVIRONMENT
5124@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
f97c9175 5125variable in the shell it spawns. This allows users to, say, define a
28de8d25
LC
5126specific prompt for development environments in their @file{.bashrc}
5127(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5128
5129@example
5130if [ -n "$GUIX_ENVIRONMENT" ]
5131then
5132 export PS1="\u@@\h \w [dev]\$ "
5133fi
5134@end example
5135
372c4bbc
DT
5136Additionally, more than one package may be specified, in which case the
5137union of the inputs for the given packages are used. For example, the
5138command below spawns a shell where all of the dependencies of both Guile
5139and Emacs are available:
5140
5141@example
5142guix environment guile emacs
5143@end example
5144
1de2fe95
DT
5145Sometimes an interactive shell session is not desired. An arbitrary
5146command may be invoked by placing the @code{--} token to separate the
5147command from the rest of the arguments:
372c4bbc
DT
5148
5149@example
1de2fe95 5150guix environment guile -- make -j4
372c4bbc
DT
5151@end example
5152
fe36d84e
LC
5153In other situations, it is more convenient to specify the list of
5154packages needed in the environment. For example, the following command
5155runs @command{python} from an environment containing Python@tie{}2.7 and
5156NumPy:
5157
5158@example
1de2fe95 5159guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
5160@end example
5161
cc90fbbf
DT
5162Furthermore, one might want the dependencies of a package and also some
5163additional packages that are not build-time or runtime dependencies, but
5164are useful when developing nonetheless. Because of this, the
5165@code{--ad-hoc} flag is positional. Packages appearing before
5166@code{--ad-hoc} are interpreted as packages whose dependencies will be
5167added to the environment. Packages appearing after are interpreted as
5168packages that will be added to the environment directly. For example,
5169the following command creates a Guix development environment that
5170additionally includes Git and strace:
5171
5172@example
5173guix environment guix --ad-hoc git strace
5174@end example
5175
f535dcbe
DT
5176Sometimes it is desirable to isolate the environment as much as
5177possible, for maximal purity and reproducibility. In particular, when
5178using Guix on a host distro that is not GuixSD, it is desirable to
5179prevent access to @file{/usr/bin} and other system-wide resources from
5180the development environment. For example, the following command spawns
5181a Guile REPL in a ``container'' where only the store and the current
5182working directory are mounted:
5183
5184@example
5185guix environment --ad-hoc --container guile -- guile
5186@end example
5187
0f252e26 5188@quotation Note
cfd35b4e 5189The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
5190@end quotation
5191
fe36d84e 5192The available options are summarized below.
372c4bbc
DT
5193
5194@table @code
5195@item --expression=@var{expr}
5196@itemx -e @var{expr}
c9c282ce
DT
5197Create an environment for the package or list of packages that
5198@var{expr} evaluates to.
372c4bbc 5199
fe36d84e
LC
5200For example, running:
5201
5202@example
5203guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5204@end example
5205
5206starts a shell with the environment for this specific variant of the
5207PETSc package.
5208
c9c282ce
DT
5209Running:
5210
5211@example
5c2b2f00 5212guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
5213@end example
5214
5215starts a shell with all the GuixSD base packages available.
5216
779aa003
DT
5217The above commands only the use default output of the given packages.
5218To select other outputs, two element tuples can be specified:
5219
5220@example
5221guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5222@end example
5223
372c4bbc
DT
5224@item --load=@var{file}
5225@itemx -l @var{file}
c9c282ce
DT
5226Create an environment for the package or list of packages that the code
5227within @var{file} evaluates to.
372c4bbc 5228
fe36d84e
LC
5229As an example, @var{file} might contain a definition like this
5230(@pxref{Defining Packages}):
5231
5232@example
5233@verbatiminclude environment-gdb.scm
5234@end example
5235
a54bd6d7
DT
5236@item --ad-hoc
5237Include all specified packages in the resulting environment, as if an
5238@i{ad hoc} package were defined with them as inputs. This option is
5239useful for quickly creating an environment without having to write a
5240package expression to contain the desired inputs.
5241
5242For instance, the command:
5243
5244@example
1de2fe95 5245guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
5246@end example
5247
5248runs @command{guile} in an environment where Guile and Guile-SDL are
5249available.
5250
417c39f1 5251Note that this example implicitly asks for the default output of
f97c9175 5252@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
5253specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5254of @code{glib} (@pxref{Packages with Multiple Outputs}).
5255
cc90fbbf
DT
5256This option may be composed with the default behavior of @command{guix
5257environment}. Packages appearing before @code{--ad-hoc} are interpreted
5258as packages whose dependencies will be added to the environment, the
5259default behavior. Packages appearing after are interpreted as packages
5260that will be added to the environment directly.
5261
372c4bbc
DT
5262@item --pure
5263Unset existing environment variables when building the new environment.
5264This has the effect of creating an environment in which search paths
5265only contain package inputs.
5266
5267@item --search-paths
5268Display the environment variable definitions that make up the
5269environment.
ce367ef3
LC
5270
5271@item --system=@var{system}
5272@itemx -s @var{system}
5273Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
5274
5275@item --container
5276@itemx -C
5277@cindex container
5278Run @var{command} within an isolated container. The current working
56b6befb 5279directory outside the container is mapped inside the
f535dcbe
DT
5280container. Additionally, the spawned process runs as the current user
5281outside the container, but has root privileges in the context of the
5282container.
5283
5284@item --network
5285@itemx -N
5286For containers, share the network namespace with the host system.
5287Containers created without this flag only have access to the loopback
5288device.
5289
5290@item --expose=@var{source}[=@var{target}]
5291For containers, expose the file system @var{source} from the host system
5292as the read-only file system @var{target} within the container. If
5293@var{target} is not specified, @var{source} is used as the target mount
5294point in the container.
5295
5296The example below spawns a Guile REPL in a container in which the user's
5297home directory is accessible read-only via the @file{/exchange}
5298directory:
5299
5300@example
5301guix environment --container --expose=$HOME=/exchange guile -- guile
5302@end example
5303
5c2b2f00 5304@item --share=@var{source}[=@var{target}]
f535dcbe
DT
5305For containers, share the file system @var{source} from the host system
5306as the writable file system @var{target} within the container. If
5307@var{target} is not specified, @var{source} is used as the target mount
5308point in the container.
5309
5310The example below spawns a Guile REPL in a container in which the user's
5311home directory is accessible for both reading and writing via the
5312@file{/exchange} directory:
5313
5314@example
5315guix environment --container --share=$HOME=/exchange guile -- guile
5316@end example
372c4bbc
DT
5317@end table
5318
5319It also supports all of the common build options that @command{guix
ccd7158d 5320build} supports (@pxref{Common Build Options}).
372c4bbc 5321
aff8ce7c
DT
5322@node Invoking guix publish
5323@section Invoking @command{guix publish}
5324
5325The purpose of @command{guix publish} is to enable users to easily share
f97c9175 5326their store with others, who can then use it as a substitute server
8ce229fc
LC
5327(@pxref{Substitutes}).
5328
5329When @command{guix publish} runs, it spawns an HTTP server which allows
5330anyone with network access to obtain substitutes from it. This means
5331that any machine running Guix can also act as if it were a build farm,
5332since the HTTP interface is compatible with Hydra, the software behind
5333the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5334
5335For security, each substitute is signed, allowing recipients to check
5336their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 5337@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
5338readable by the system administrator, it must be started as root; the
5339@code{--user} option makes it drop root privileges early on.
aff8ce7c 5340
b18812b6
LC
5341The signing key pair must be generated before @command{guix publish} is
5342launched, using @command{guix archive --generate-key} (@pxref{Invoking
5343guix archive}).
5344
aff8ce7c
DT
5345The general syntax is:
5346
5347@example
5348guix publish @var{options}@dots{}
5349@end example
5350
5351Running @command{guix publish} without any additional arguments will
5352spawn an HTTP server on port 8080:
5353
5354@example
5355guix publish
5356@end example
5357
5358Once a publishing server has been authorized (@pxref{Invoking guix
5359archive}), the daemon may download substitutes from it:
5360
5361@example
5362guix-daemon --substitute-urls=http://example.org:8080
5363@end example
5364
5365The following options are available:
5366
5367@table @code
5368@item --port=@var{port}
5369@itemx -p @var{port}
5370Listen for HTTP requests on @var{port}.
5371
9e2292ef
LC
5372@item --listen=@var{host}
5373Listen on the network interface for @var{host}. The default is to
5374accept connections from any interface.
5375
5463fe51
LC
5376@item --user=@var{user}
5377@itemx -u @var{user}
5378Change privileges to @var{user} as soon as possible---i.e., once the
5379server socket is open and the signing key has been read.
5380
aff8ce7c
DT
5381@item --repl[=@var{port}]
5382@itemx -r [@var{port}]
5383Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
5384Reference Manual}) on @var{port} (37146 by default). This is used
5385primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
5386@end table
5387
1c52181f
LC
5388Enabling @command{guix publish} on a GuixSD system is a one-liner: just
5389add a call to @code{guix-publish-service} in the @code{services} field
5390of the @code{operating-system} declaration (@pxref{guix-publish-service,
5391@code{guix-publish-service}}).
5392
d23c20f1
LC
5393
5394@node Invoking guix challenge
5395@section Invoking @command{guix challenge}
5396
5397@cindex reproducible builds
5398@cindex verifiable builds
5399
5400Do the binaries provided by this server really correspond to the source
f97c9175 5401code it claims to build? Is a package build process deterministic?
d23c20f1
LC
5402These are the questions the @command{guix challenge} command attempts to
5403answer.
5404
5405The former is obviously an important question: Before using a substitute
f97c9175 5406server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
5407provides the right binaries, and thus @emph{challenge} it. The latter
5408is what enables the former: If package builds are deterministic, then
5409independent builds of the package should yield the exact same result,
5410bit for bit; if a server provides a binary different from the one
5411obtained locally, it may be either corrupt or malicious.
5412
5413We know that the hash that shows up in @file{/gnu/store} file names is
5414the hash of all the inputs of the process that built the file or
5415directory---compilers, libraries, build scripts,
5416etc. (@pxref{Introduction}). Assuming deterministic build processes,
5417one store file name should map to exactly one build output.
5418@command{guix challenge} checks whether there is, indeed, a single
5419mapping by comparing the build outputs of several independent builds of
5420any given store item.
5421
f97c9175 5422The command output looks like this:
d23c20f1
LC
5423
5424@smallexample
5425$ guix challenge --substitute-urls="http://hydra.gnu.org http://guix.example.org"
5426updating list of substitutes from 'http://hydra.gnu.org'... 100.0%
5427updating list of substitutes from 'http://guix.example.org'... 100.0%
5428/gnu/store/@dots{}-openssl-1.0.2d contents differ:
5429 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5430 http://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
5431 http://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
5432/gnu/store/@dots{}-git-2.5.0 contents differ:
5433 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
5434 http://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
5435 http://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
5436/gnu/store/@dots{}-pius-2.1.1 contents differ:
5437 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5438 http://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
5439 http://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
5440@end smallexample
5441
5442@noindent
5443In this example, @command{guix challenge} first scans the store to
5444determine the set of locally-built derivations---as opposed to store
5445items that were downloaded from a substitute server---and then queries
5446all the substitute servers. It then reports those store items for which
5447the servers obtained a result different from the local build.
5448
5449@cindex non-determinism, in package builds
5450As an example, @code{guix.example.org} always gets a different answer.
5451Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
5452case of Git. This might indicate that the build process of Git is
5453non-deterministic, meaning that its output varies as a function of
5454various things that Guix does not fully control, in spite of building
5455packages in isolated environments (@pxref{Features}). Most common
5456sources of non-determinism include the addition of timestamps in build
5457results, the inclusion of random numbers, and directory listings sorted
5458by inode number. See @uref{http://reproducible.debian.net/howto/}, for
5459more information.
5460
f97c9175 5461To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
5462these lines (@pxref{Invoking guix archive}):
5463
5464@example
5465$ wget -q -O - http://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
5466 | guix archive -x /tmp/git
043f4698 5467$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
5468@end example
5469
5470This command shows the difference between the files resulting from the
5471local build, and the files resulting from the build on
5472@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
5473diffutils, Comparing and Merging Files}). The @command{diff} command
5474works great for text files. When binary files differ, a better option
5475is @uref{http://diffoscope.org/, Diffoscope}, a tool that helps
5476visualize differences for all kinds of files.
5477
f97c9175 5478Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
5479to a non-deterministic build process or to a malicious server. We try
5480hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
5481to verify substitutes, but of course, this is a process that
5482involves not just Guix, but a large part of the free software community.
d23c20f1
LC
5483In the meantime, @command{guix challenge} is one tool to help address
5484the problem.
5485
5486If you are writing packages for Guix, you are encouraged to check
5487whether @code{hydra.gnu.org} and other substitute servers obtain the
5488same build result as you did with:
5489
5490@example
5491$ guix challenge @var{package}
5492@end example
5493
5494@noindent
f97c9175 5495where @var{package} is a package specification such as
d23c20f1
LC
5496@code{guile-2.0} or @code{glibc:debug}.
5497
5498The general syntax is:
5499
5500@example
5501guix challenge @var{options} [@var{packages}@dots{}]
5502@end example
5503
5504The one option that matters is:
5505
5506@table @code
5507
5508@item --substitute-urls=@var{urls}
5509Consider @var{urls} the whitespace-separated list of substitute source
5510URLs to compare to.
5511
5512@end table
5513
5514
32efa254
DT
5515@node Invoking guix container
5516@section Invoking @command{guix container}
5517@cindex container
5518
5519@quotation Note
5520As of version @value{VERSION}, this tool is experimental. The interface
5521is subject to radical change in the future.
5522@end quotation
5523
5524The purpose of @command{guix container} is to manipulate processes
5525running within an isolated environment, commonly known as a
46c36586 5526``container'', typically created by the @command{guix environment}
32efa254
DT
5527(@pxref{Invoking guix environment}) and @command{guix system container}
5528(@pxref{Invoking guix system}) commands.
5529
5530The general syntax is:
5531
5532@example
5533guix container @var{action} @var{options}@dots{}
5534@end example
5535
5536@var{action} specifies the operation to perform with a container, and
5537@var{options} specifies the context-specific arguments for the action.
5538
5539The following actions are available:
5540
5541@table @code
5542@item exec
5543Execute a command within the context of a running container.
5544
5545The syntax is:
5546
5547@example
5548guix container exec @var{pid} @var{program} @var{arguments}@dots{}
5549@end example
5550
5551@var{pid} specifies the process ID of the running container.
f97c9175
AE
5552@var{program} specifies an executable file name within the root file
5553system of the container. @var{arguments} are the additional options that
5554will be passed to @var{program}.
32efa254
DT
5555
5556The following command launches an interactive login shell inside a
5557GuixSD container, started by @command{guix system container}, and whose
5558process ID is 9001:
5559
5560@example
5561guix container exec 9001 /run/current-system/profile/bin/bash --login
5562@end example
5563
5564Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 5565must be PID 1 of the container or one of its child processes.
32efa254
DT
5566
5567@end table
5568
a1ba8475
LC
5569@c *********************************************************************
5570@node GNU Distribution
5571@chapter GNU Distribution
5572
3ca2731c 5573@cindex Guix System Distribution
4705641f 5574@cindex GuixSD
3ca2731c
LC
5575Guix comes with a distribution of the GNU system consisting entirely of
5576free software@footnote{The term ``free'' here refers to the
a1ba8475 5577@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 5578users of that software}.}. The
35ed9306
LC
5579distribution can be installed on its own (@pxref{System Installation}),
5580but it is also possible to install Guix as a package manager on top of
5581an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 5582between the two, we refer to the standalone distribution as the Guix
4705641f 5583System Distribution, or GuixSD.
35ed9306
LC
5584
5585The distribution provides core GNU packages such as GNU libc, GCC, and
5586Binutils, as well as many GNU and non-GNU applications. The complete
5587list of available packages can be browsed
093ae1be 5588@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 5589running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
5590
5591@example
e49951eb 5592guix package --list-available
a1ba8475
LC
5593@end example
5594
f97c9175 5595Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
5596Linux-based and other variants of GNU, with a focus on the promotion and
5597tight integration of GNU components, and an emphasis on programs and
5598tools that help users exert that freedom.
5599
3ca2731c 5600Packages are currently available on the following platforms:
c320011d
LC
5601
5602@table @code
5603
5604@item x86_64-linux
5605Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
5606
5607@item i686-linux
5608Intel 32-bit architecture (IA32), Linux-Libre kernel;
5609
aa1e1947 5610@item armhf-linux
aa725117 5611ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
5612using the EABI hard-float application binary interface (ABI),
5613and Linux-Libre kernel.
aa1e1947 5614
c320011d
LC
5615@item mips64el-linux
5616little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 5617n32 ABI, and Linux-Libre kernel.
c320011d
LC
5618
5619@end table
5620
4705641f 5621GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 5622
c320011d
LC
5623@noindent
5624For information on porting to other architectures or kernels,
f97c9175 5625@pxref{Porting}.
c320011d 5626
401c53c4 5627@menu
5af6de3e 5628* System Installation:: Installing the whole operating system.
35ed9306 5629* System Configuration:: Configuring the operating system.
91ef73d4 5630* Installing Debugging Files:: Feeding the debugger.
05962f29 5631* Security Updates:: Deploying security fixes quickly.
401c53c4 5632* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 5633* Packaging Guidelines:: Growing the distribution.
401c53c4 5634* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 5635* Porting:: Targeting another platform or kernel.
401c53c4
LC
5636@end menu
5637
5638Building this distribution is a cooperative effort, and you are invited
081145cf 5639to join! @xref{Contributing}, for information about how you can help.
401c53c4 5640
5af6de3e
LC
5641@node System Installation
5642@section System Installation
5643
3ca2731c
LC
5644@cindex Guix System Distribution
5645This section explains how to install the Guix System Distribution
5646on a machine. The Guix package manager can
35ed9306
LC
5647also be installed on top of a running GNU/Linux system,
5648@pxref{Installation}.
5af6de3e
LC
5649
5650@ifinfo
5651@c This paragraph is for people reading this from tty2 of the
5652@c installation image.
1068f26b 5653You are reading this documentation with an Info reader. For details on
5af6de3e 5654how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 5655link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
5656@kbd{l} afterwards to come back here.
5657@end ifinfo
5658
dedb8d5e
LC
5659@menu
5660* Limitations:: What you can expect.
5661* USB Stick Installation:: Preparing the installation medium.
5662* Preparing for Installation:: Networking, partitioning, etc.
5663* Proceeding with the Installation:: The real thing.
5664* Building the Installation Image:: How this comes to be.
5665@end menu
5666
5667@node Limitations
8aaaae38
LC
5668@subsection Limitations
5669
4705641f 5670As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 5671not production-ready. It may contain bugs and lack important
8aaaae38
LC
5672features. Thus, if you are looking for a stable production system that
5673respects your freedom as a computer user, a good solution at this point
5674is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 5675the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 5676to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
5677also keep using your distribution and try out the package manager on top
5678of it (@pxref{Installation}).
5679
5680Before you proceed with the installation, be aware of the following
5681noteworthy limitations applicable to version @value{VERSION}:
5682
5683@itemize
5684@item
5685The installation process does not include a graphical user interface and
5686requires familiarity with GNU/Linux (see the following subsections to
5687get a feel of what that means.)
5688
5689@item
093ae1be 5690The system does not yet provide full GNOME and KDE desktops. Xfce and
f97c9175 5691Enlightenment are available, though, if graphical desktop environments
093ae1be 5692are your thing, as well as a number of X11 window managers.
8aaaae38
LC
5693
5694@item
dbcb0ab1 5695Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
5696
5697@item
5698Few system services are currently supported out-of-the-box
5699(@pxref{Services}).
5700
5701@item
dedb8d5e 5702More than 3,000 packages are available, but you may
8aaaae38
LC
5703occasionally find that a useful package is missing.
5704@end itemize
5705
f97c9175
AE
5706You have been warned! But more than a disclaimer, this is an invitation
5707to report issues (and success stories!), and to join us in improving it.
8aaaae38 5708@xref{Contributing}, for more info.
5af6de3e 5709
dedb8d5e 5710@node USB Stick Installation
5af6de3e
LC
5711@subsection USB Stick Installation
5712
5713An installation image for USB sticks can be downloaded from
4705641f 5714@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
5715where @var{system} is one of:
5716
5717@table @code
5718@item x86_64-linux
5719for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
5720
5721@item i686-linux
5722for a 32-bit GNU/Linux system on Intel-compatible CPUs.
5723@end table
5724
5725This image contains a single partition with the tools necessary for an
5726installation. It is meant to be copied @emph{as is} to a large-enough
5727USB stick.
5728
5729To copy the image to a USB stick, follow these steps:
5730
5731@enumerate
5732@item
5733Decompress the image using the @command{xz} command:
5734
5735@example
4705641f 5736xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
5737@end example
5738
5739@item
f97c9175
AE
5740Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
5741its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
5742copy the image with:
5743
5744@example
4705641f 5745dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
5746@end example
5747
5748Access to @file{/dev/sdX} usually requires root privileges.
5749@end enumerate
5750
5751Once this is done, you should be able to reboot the system and boot from
5752the USB stick. The latter usually requires you to get in the BIOS' boot
5753menu, where you can choose to boot from the USB stick.
5754
dedb8d5e 5755@node Preparing for Installation
5af6de3e
LC
5756@subsection Preparing for Installation
5757
5758Once you have successfully booted the image on the USB stick, you should
5759end up with a root prompt. Several console TTYs are configured and can
5760be used to run commands as root. TTY2 shows this documentation,
5761browsable using the Info reader commands (@pxref{Help,,, info, Info: An
ae7ffa9e
LC
5762Introduction}). The installation system runs the GPM mouse daemon,
5763which allows you to select text with the left mouse button and to paste
5764it with the middle button.
5af6de3e 5765
dedb8d5e 5766@subsubsection Keyboard Layout
5af6de3e 5767
dedb8d5e
LC
5768@cindex keyboard layout
5769The installation image uses the US qwerty keyboard layout. If you want
5770to change it, you can use the @command{loadkeys} command. For example,
5771the following command selects the Dvorak keyboard layout:
5af6de3e 5772
dedb8d5e
LC
5773@example
5774loadkeys dvorak
5775@end example
5776
5777See the files under @file{/run/current-system/profile/share/keymaps} for
5778a list of available keyboard layouts. Run @command{man loadkeys} for
5779more information.
5780
5781@subsubsection Networking
5782
5783Run the following command see what your network interfaces are called:
235cba85
LC
5784
5785@example
dedb8d5e 5786ifconfig -a
235cba85
LC
5787@end example
5788
95c559c1 5789@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
5790Wired interfaces have a name starting with @samp{e}; for example, the
5791interface corresponding to the first on-board Ethernet controller is
5792called @samp{eno1}. Wireless interfaces have a name starting with
5793@samp{w}, like @samp{w1p2s0}.
5794
5795@table @asis
5796@item Wired connection
5797To configure a wired network run the following command, substituting
5798@var{interface} with the name of the wired interface you want to use.
5799
5800@example
5801ifconfig @var{interface} up
5802@end example
5803
5804@item Wireless connection
5805To configure wireless networking, you can create a configuration file
5806for the @command{wpa_supplicant} configuration tool (its location is not
5807important) using one of the available text editors such as
5808@command{zile}:
5809
5810@example
5811zile wpa_supplicant.conf
5812@end example
5813
5814As an example, the following stanza can go to this file and will work
5815for many wireless networks, provided you give the actual SSID and
5816passphrase for the network you are connecting to:
5817
5818@example
5819network=@{
5820 ssid=@var{my-ssid}
5821 key_mgmt=WPA-PSK
5822 psk="the network's secret passphrase"
5823@}
5824@end example
5825
5826Start the wireless service and run it in the background with the
5827following command (substitute @var{interface} with the name of the
5828network interface you want to use):
5829
5830@example
5831wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
5832@end example
5833
5834Run @command{man wpa_supplication} for more information.
5835@end table
5836
5837At this point, you need to acquire an IP address. On a network where IP
5838addresses are automatically assigned @i{via} DHCP, you can run:
5839
5840@example
5841dhclient @var{interface}
5842@end example
5af6de3e 5843
dedb8d5e
LC
5844Try to ping a server to see if networking is up and running:
5845
5846@example
5847ping -c 3 gnu.org
5848@end example
5af6de3e
LC
5849
5850Setting up network access is almost always a requirement because the
5851image does not contain all the software and tools that may be needed.
5852
dedb8d5e
LC
5853@subsubsection Disk Partitioning
5854
5855Unless this has already been done, the next step is to partition, and
5856then format the target partition(s).
5857
5858The installation image includes several partitioning tools, including
5859Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
5860@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
5861the partition layout you want:
5862
5863@example
5864cfdisk
5865@end example
5866
5867Once you are done partitioning the target hard disk drive, you have to
5868create a file system on the relevant partition(s)@footnote{Currently
5869GuixSD pretty much assumes an ext4 file system. In particular, code
5870that reads partition UUIDs and labels only works with ext4. This will
5871be fixed in the future.}.
5af6de3e 5872
7ab44369
LC
5873Preferably, assign partitions a label so that you can easily and
5874reliably refer to them in @code{file-system} declarations (@pxref{File
5875Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
5876@command{mkfs.ext4} and related commands. So, assuming the target root
5877partition lives at @file{/dev/sda1}, a file system with the label
5878@code{my-root} can be created with:
7ab44369 5879
dedb8d5e
LC
5880@example
5881mkfs.ext4 -L my-root /dev/sda1
5882@end example
dd816355 5883
316d65be
LC
5884@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
5885@c A typical command sequence may be:
5886@c
5887@c @example
5888@c # fdisk /dev/sdX
5889@c @dots{} Create partitions etc.@dots{}
5890@c # cryptsetup luksFormat /dev/sdX1
5891@c # cryptsetup open --type luks /dev/sdX1 my-partition
5892@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
5893@c @end example
6d6e6281 5894
dedb8d5e
LC
5895In addition to e2fsprogs, the suite of tools to manipulate
5896ext2/ext3/ext4 file systems, the installation image includes
5897Cryptsetup/LUKS for disk encryption.
5af6de3e 5898
dedb8d5e
LC
5899Once that is done, mount the target root partition under @file{/mnt}
5900with a command like (again, assuming @file{/dev/sda1} is the root
5901partition):
83a17b62 5902
dedb8d5e
LC
5903@example
5904mount /dev/sda1 /mnt
5905@end example
83a17b62 5906
dedb8d5e
LC
5907@node Proceeding with the Installation
5908@subsection Proceeding with the Installation
83a17b62 5909
dedb8d5e
LC
5910With the target partitions ready and the target root mounted on
5911@file{/mnt}, we're ready to go. First, run:
5af6de3e 5912
dedb8d5e
LC
5913@example
5914herd start cow-store /mnt
5915@end example
5af6de3e 5916
dedb8d5e
LC
5917This makes @file{/gnu/store} copy-on-write, such that packages added to
5918it during the installation phase are written to the target disk rather
5919than kept in memory.
5af6de3e 5920
dedb8d5e 5921Next, you have to edit a file and
5af6de3e
LC
5922provide the declaration of the operating system to be installed. To
5923that end, the installation system comes with two text editors: GNU nano
5924(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
5925It is better to store that file on the target root file system, say, as
5926@file{/mnt/etc/config.scm}.
5927
dedb8d5e
LC
5928@xref{Using the Configuration System}, for an overview of the
5929configuration file. The example configurations discussed in that
5930section are available under @file{/etc/configuration} in the
5931installation image. Thus, to get started with a system configuration
5932providing a graphical display server (a ``desktop'' system), you can run
5933something along these lines:
5934
5935@example
5936# mkdir /mnt/etc
5937# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
5938# zile /mnt/etc/config.scm
5939@end example
5940
5941You should pay attention to what your configuration file contains, and
5942in particular:
5943
5944@itemize
5945@item
5946Make sure the @code{grub-configuration} form refers to the device you
5947want to install GRUB on.
5948
5949@item
5950Be sure that your partition labels match the value of their respective
5951@code{device} fields in your @code{file-system} configuration, assuming
5952your @code{file-system} configuration sets the value of @code{title} to
5953@code{'label}.
5954@end itemize
5af6de3e 5955
dd51caac
LC
5956Once you are done preparing the configuration file, the new system must
5957be initialized (remember that the target root file system is mounted
5958under @file{/mnt}):
5af6de3e
LC
5959
5960@example
5961guix system init /mnt/etc/config.scm /mnt
5962@end example
5963
5964@noindent
dedb8d5e 5965This copies all the necessary files and installs GRUB on
5af6de3e 5966@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 5967more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
5968downloads or builds of missing packages, which can take some time.
5969
1bd4e6db
LC
5970Once that command has completed---and hopefully succeeded!---you can run
5971@command{reboot} and boot into the new system. The @code{root} password
5972in the new system is initially empty; other users' passwords need to be
5973initialized by running the @command{passwd} command as @code{root},
5974unless your configuration specifies otherwise
5975(@pxref{user-account-password, user account passwords}).
5976
5977Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
5978@file{guix-devel@@gnu.org} to share your experience---good or not so
5979good.
5980
dedb8d5e 5981@node Building the Installation Image
5af6de3e
LC
5982@subsection Building the Installation Image
5983
5984The installation image described above was built using the @command{guix
5985system} command, specifically:
5986
5987@example
8a225c66 5988guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
5989@end example
5990
1068f26b 5991@xref{Invoking guix system} and
5af6de3e
LC
5992@file{gnu/system/install.scm} in the source tree for more information
5993about the installation image.
5994
cf4a9129
LC
5995@node System Configuration
5996@section System Configuration
b208a005 5997
cf4a9129 5998@cindex system configuration
3ca2731c 5999The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
6000mechanism. By that we mean that all aspects of the global system
6001configuration---such as the available system services, timezone and
6002locale settings, user accounts---are declared in a single place. Such
6003a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 6004
cf4a9129
LC
6005One of the advantages of putting all the system configuration under the
6006control of Guix is that it supports transactional system upgrades, and
1068f26b 6007makes it possible to roll back to a previous system instantiation,
cf4a9129 6008should something go wrong with the new one (@pxref{Features}). Another
1068f26b 6009advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
6010across different machines, or at different points in time, without
6011having to resort to additional administration tools layered on top of
1068f26b 6012the own tools of the system.
cf4a9129 6013@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 6014
cf4a9129
LC
6015This section describes this mechanism. First we focus on the system
6016administrator's viewpoint---explaining how the system is configured and
6017instantiated. Then we show how this mechanism can be extended, for
6018instance to support new system services.
91ef73d4 6019
cf4a9129
LC
6020@menu
6021* Using the Configuration System:: Customizing your GNU system.
7313a52e 6022* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 6023* File Systems:: Configuring file system mounts.
510f9d86 6024* Mapped Devices:: Block device extra processing.
cf4a9129 6025* User Accounts:: Specifying user accounts.
598e19dc 6026* Locales:: Language and cultural convention settings.
cf4a9129 6027* Services:: Specifying system services.
0ae8c15a 6028* Setuid Programs:: Programs running with root privileges.
efb5e833 6029* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 6030* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 6031* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 6032* GRUB Configuration:: Configuring the boot loader.
cf4a9129 6033* Invoking guix system:: Instantiating a system configuration.
97d76250 6034* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
6035* Defining Services:: Adding new service definitions.
6036@end menu
91ef73d4 6037
cf4a9129
LC
6038@node Using the Configuration System
6039@subsection Using the Configuration System
64d76fa6 6040
cf4a9129
LC
6041The operating system is configured by providing an
6042@code{operating-system} declaration in a file that can then be passed to
6043the @command{guix system} command (@pxref{Invoking guix system}). A
6044simple setup, with the default system services, the default Linux-Libre
6045kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 6046
cf4a9129
LC
6047@findex operating-system
6048@lisp
dd51caac 6049@include os-config-bare-bones.texi
cf4a9129 6050@end lisp
401c53c4 6051
cf4a9129
LC
6052This example should be self-describing. Some of the fields defined
6053above, such as @code{host-name} and @code{bootloader}, are mandatory.
6054Others, such as @code{packages} and @code{services}, can be omitted, in
6055which case they get a default value.
e7f34eb0 6056
5d94ac51
LC
6057Below we discuss the effect of some of the most important fields
6058(@pxref{operating-system Reference}, for details about all the available
6059fields), and how to @dfn{instantiate} the operating system using
6060@command{guix system}.
6061
6062@unnumberedsubsubsec Globally-Visible Packages
6063
cf4a9129 6064@vindex %base-packages
5d94ac51
LC
6065The @code{packages} field lists packages that will be globally visible
6066on the system, for all user accounts---i.e., in every user's @code{PATH}
6067environment variable---in addition to the per-user profiles
6068(@pxref{Invoking guix package}). The @var{%base-packages} variable
6069provides all the tools one would expect for basic user and administrator
6070tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6071the GNU Zile lightweight text editor, @command{find}, @command{grep},
6072etc. The example above adds tcpdump to those, taken from the @code{(gnu
6073packages admin)} module (@pxref{Package Modules}).
e7f34eb0 6074
f6c9fb1b
LC
6075@findex specification->package
6076Referring to packages by variable name, like @var{tcpdump} above, has
6077the advantage of being unambiguous; it also allows typos and such to be
6078diagnosed right away as ``unbound variables''. The downside is that one
6079needs to know which module defines which package, and to augment the
6080@code{use-package-modules} line accordingly. To avoid that, one can use
6081the @code{specification->package} procedure of the @code{(gnu packages)}
6082module, which returns the best package for a given name or name and
6083version:
6084
6085@lisp
6086(use-modules (gnu packages))
6087
6088(operating-system
6089 ;; ...
6090 (packages (append (map specification->package
6091 '("tcpdump" "htop" "gnupg-2.0"))
6092 %base-packages)))
6093@end lisp
6094
5d94ac51
LC
6095@unnumberedsubsubsec System Services
6096
cf4a9129
LC
6097@vindex %base-services
6098The @code{services} field lists @dfn{system services} to be made
6099available when the system starts (@pxref{Services}).
6100The @code{operating-system} declaration above specifies that, in
6101addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
6102daemon listening on port 2222 (@pxref{Networking Services,
6103@code{lsh-service}}). Under the hood,
cf4a9129
LC
6104@code{lsh-service} arranges so that @code{lshd} is started with the
6105right command-line options, possibly with supporting configuration files
cd6f6c22
LC
6106generated as needed (@pxref{Defining Services}).
6107
6108@cindex customization, of services
6109@findex modify-services
6110Occasionally, instead of using the base services as is, you will want to
6111customize them. For instance, to change the configuration of
6112@code{guix-daemon} and Mingetty (the console log-in), you may write the
6113following instead of @var{%base-services}:
6114
6115@lisp
6116(modify-services %base-services
6117 (guix-service-type config =>
6118 (guix-configuration
6119 (inherit config)
6120 (use-substitutes? #f)
6121 (extra-options '("--gc-keep-outputs"))))
6122 (mingetty-service-type config =>
6123 (mingetty-configuration
6124 (inherit config)
6125 (motd (plain-file "motd" "Hi there!")))))
6126@end lisp
6127
6128@noindent
6129The effect here is to change the options passed to @command{guix-daemon}
6130when it is started, as well as the ``message of the day'' that appears
6131when logging in at the console. @xref{Service Reference,
6132@code{modify-services}}, for more on that.
a1ba8475 6133
dd51caac 6134The configuration for a typical ``desktop'' usage, with the X11 display
cd6f6c22 6135server, a desktop environment, network management, power management, and
dd51caac
LC
6136more, would look like this:
6137
6138@lisp
6139@include os-config-desktop.texi
6140@end lisp
6141
6142@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
6143@var{%desktop-services}. @xref{X.509 Certificates}, for background
6144information about the @code{nss-certs} package that is used here.
dd51caac 6145
5d94ac51
LC
6146Again, @var{%desktop-services} is just a list of service objects. If
6147you want to remove services from there, you can do so using the
6148procedures for list filtering (@pxref{SRFI-1 Filtering and
6149Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
6150following expression returns a list that contains all the services in
6151@var{%desktop-services} minus the Avahi service:
6152
6153@example
6154(remove (lambda (service)
6155 (eq? (service-kind service) avahi-service-type))
6156 %desktop-services)
6157@end example
6158
6159@unnumberedsubsubsec Instantiating the System
6160
6161Assuming the @code{operating-system} declaration
6162is stored in the @file{my-system-config.scm}
cf4a9129
LC
6163file, the @command{guix system reconfigure my-system-config.scm} command
6164instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
6165entry (@pxref{Invoking guix system}).
6166
1068f26b 6167The normal way to change the system configuration is by updating this
65797bff
LC
6168file and re-running @command{guix system reconfigure}. One should never
6169have to touch files in @command{/etc} or to run commands that modify the
6170system state such as @command{useradd} or @command{grub-install}. In
6171fact, you must avoid that since that would not only void your warranty
6172but also prevent you from rolling back to previous versions of your
6173system, should you ever need to.
6174
6175@cindex roll-back, of the operating system
6176Speaking of roll-back, each time you run @command{guix system
6177reconfigure}, a new @dfn{generation} of the system is created---without
6178modifying or deleting previous generations. Old system generations get
6179an entry in the GRUB boot menu, allowing you to boot them in case
6180something went wrong with the latest generation. Reassuring, no? The
6181@command{guix system list-generations} command lists the system
6182generations available on disk.
b81e1947 6183
5d94ac51
LC
6184@unnumberedsubsubsec The Programming Interface
6185
cf4a9129
LC
6186At the Scheme level, the bulk of an @code{operating-system} declaration
6187is instantiated with the following monadic procedure (@pxref{The Store
6188Monad}):
b81e1947 6189
cf4a9129
LC
6190@deffn {Monadic Procedure} operating-system-derivation os
6191Return a derivation that builds @var{os}, an @code{operating-system}
6192object (@pxref{Derivations}).
b81e1947 6193
cf4a9129
LC
6194The output of the derivation is a single directory that refers to all
6195the packages, configuration files, and other supporting files needed to
6196instantiate @var{os}.
6197@end deffn
b81e1947 6198
5d94ac51
LC
6199This procedure is provided by the @code{(gnu system)} module. Along
6200with @code{(gnu services)} (@pxref{Services}), this module contains the
6201guts of GuixSD. Make sure to visit it!
6202
6203
7313a52e
LC
6204@node operating-system Reference
6205@subsection @code{operating-system} Reference
6206
6207This section summarizes all the options available in
6208@code{operating-system} declarations (@pxref{Using the Configuration
6209System}).
6210
6211@deftp {Data Type} operating-system
6212This is the data type representing an operating system configuration.
6213By that, we mean all the global system configuration, not per-user
6214configuration (@pxref{Using the Configuration System}).
6215
6216@table @asis
6217@item @code{kernel} (default: @var{linux-libre})
fbb25e56 6218The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
6219only the Linux-libre kernel is supported. In the future, it will be
6220possible to use the GNU@tie{}Hurd.}.
6221
ee2a6304
LC
6222@item @code{kernel-arguments} (default: @code{'()})
6223List of strings or gexps representing additional arguments to pass on
1068f26b 6224the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 6225
7313a52e 6226@item @code{bootloader}
88faf933 6227The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
6228
6229@item @code{initrd} (default: @code{base-initrd})
6230A two-argument monadic procedure that returns an initial RAM disk for
6231the Linux kernel. @xref{Initial RAM Disk}.
6232
f34c56be
LC
6233@item @code{firmware} (default: @var{%base-firmware})
6234@cindex firmware
6235List of firmware packages loadable by the operating system kernel.
6236
6237The default includes firmware needed for Atheros-based WiFi devices
6238(Linux-libre module @code{ath9k}.)
6239
7313a52e
LC
6240@item @code{host-name}
6241The host name.
6242
6243@item @code{hosts-file}
6244@cindex hosts file
24e02c28 6245A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 6246@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 6247Reference Manual}). The default is a file with entries for
7313a52e
LC
6248@code{localhost} and @var{host-name}.
6249
6250@item @code{mapped-devices} (default: @code{'()})
6251A list of mapped devices. @xref{Mapped Devices}.
6252
6253@item @code{file-systems}
6254A list of file systems. @xref{File Systems}.
6255
6256@item @code{swap-devices} (default: @code{'()})
6257@cindex swap devices
6258A list of strings identifying devices to be used for ``swap space''
6259(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
6260For example, @code{'("/dev/sda3")}.
6261
bf87f38a 6262@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
6263@itemx @code{groups} (default: @var{%base-groups})
6264List of user accounts and groups. @xref{User Accounts}.
6265
6266@item @code{skeletons} (default: @code{(default-skeletons)})
6267A monadic list of pairs of target file name and files. These are the
6268files that will be used as skeletons as new accounts are created.
6269
6270For instance, a valid value may look like this:
6271
6272@example
6273(mlet %store-monad ((bashrc (text-file "bashrc" "\
6274 export PATH=$HOME/.guix-profile/bin")))
6275 (return `((".bashrc" ,bashrc))))
6276@end example
6277
6278@item @code{issue} (default: @var{%default-issue})
6279A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 6280displayed when users log in on a text console.
7313a52e
LC
6281
6282@item @code{packages} (default: @var{%base-packages})
6283The set of packages installed in the global profile, which is accessible
6284at @file{/run/current-system/profile}.
6285
1068f26b 6286The default set includes core utilities and it is good practice to
7313a52e
LC
6287install non-core utilities in user profiles (@pxref{Invoking guix
6288package}).
6289
6290@item @code{timezone}
6291A timezone identifying string---e.g., @code{"Europe/Paris"}.
6292
17c20385
LC
6293You can run the @command{tzselect} command to find out which timezone
6294string corresponds to your region. Choosing an invalid timezone name
6295causes @command{guix system} to fail.
6296
598e19dc
LC
6297@item @code{locale} (default: @code{"en_US.utf8"})
6298The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
6299Library Reference Manual}). @xref{Locales}, for more information.
6300
6301@item @code{locale-definitions} (default: @var{%default-locale-definitions})
6302The list of locale definitions to be compiled and that may be used at
6303run time. @xref{Locales}.
7313a52e 6304
34760ae7
LC
6305@item @code{locale-libcs} (default: @code{(list @var{glibc})})
6306The list of GNU@tie{}libc packages whose locale data and tools are used
6307to build the locale definitions. @xref{Locales}, for compatibility
6308considerations that justify this option.
6309
996ed739 6310@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 6311Configuration of the libc name service switch (NSS)---a
996ed739
LC
6312@code{<name-service-switch>} object. @xref{Name Service Switch}, for
6313details.
6314
7313a52e 6315@item @code{services} (default: @var{%base-services})
28d939af 6316A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
6317
6318@item @code{pam-services} (default: @code{(base-pam-services)})
6319@cindex PAM
6320@cindex pluggable authentication modules
6321Linux @dfn{pluggable authentication module} (PAM) services.
6322@c FIXME: Add xref to PAM services section.
6323
6324@item @code{setuid-programs} (default: @var{%setuid-programs})
6325List of string-valued G-expressions denoting setuid programs.
6326@xref{Setuid Programs}.
6327
f5a9ffa0
AK
6328@item @code{sudoers-file} (default: @var{%sudoers-specification})
6329@cindex sudoers file
84765839
LC
6330The contents of the @file{/etc/sudoers} file as a file-like object
6331(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
6332
6333This file specifies which users can use the @command{sudo} command, what
6334they are allowed to do, and what privileges they may gain. The default
6335is that only @code{root} and members of the @code{wheel} group may use
6336@code{sudo}.
6337
6338@end table
6339@end deftp
6340
cf4a9129
LC
6341@node File Systems
6342@subsection File Systems
b81e1947 6343
cf4a9129 6344The list of file systems to be mounted is specified in the
1068f26b 6345@code{file-systems} field of the operating system declaration
cf4a9129
LC
6346(@pxref{Using the Configuration System}). Each file system is declared
6347using the @code{file-system} form, like this:
b81e1947
LC
6348
6349@example
cf4a9129
LC
6350(file-system
6351 (mount-point "/home")
6352 (device "/dev/sda3")
6353 (type "ext4"))
b81e1947
LC
6354@end example
6355
cf4a9129
LC
6356As usual, some of the fields are mandatory---those shown in the example
6357above---while others can be omitted. These are described below.
b81e1947 6358
cf4a9129
LC
6359@deftp {Data Type} file-system
6360Objects of this type represent file systems to be mounted. They
6361contain the following members:
5ff3c4b8 6362
cf4a9129
LC
6363@table @asis
6364@item @code{type}
6365This is a string specifying the type of the file system---e.g.,
6366@code{"ext4"}.
5ff3c4b8 6367
cf4a9129
LC
6368@item @code{mount-point}
6369This designates the place where the file system is to be mounted.
b81e1947 6370
cf4a9129
LC
6371@item @code{device}
6372This names the ``source'' of the file system. By default it is the name
6373of a node under @file{/dev}, but its meaning depends on the @code{title}
6374field described below.
401c53c4 6375
cf4a9129
LC
6376@item @code{title} (default: @code{'device})
6377This is a symbol that specifies how the @code{device} field is to be
6378interpreted.
401c53c4 6379
cf4a9129
LC
6380When it is the symbol @code{device}, then the @code{device} field is
6381interpreted as a file name; when it is @code{label}, then @code{device}
6382is interpreted as a partition label name; when it is @code{uuid},
6383@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 6384
661a1d79 6385UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
6386@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
6387@code{uuid} form expects 16-byte UUIDs as defined in
6388@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
6389form of UUID used by the ext2 family of file systems and others, but it
6390is different from ``UUIDs'' found in FAT file systems, for instance.},
6391like this:
661a1d79
LC
6392
6393@example
6394(file-system
6395 (mount-point "/home")
6396 (type "ext4")
6397 (title 'uuid)
6398 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
6399@end example
6400
cf4a9129 6401The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
6402partitions without having to hard-code their actual device
6403name@footnote{Note that, while it is tempting to use
6404@file{/dev/disk/by-uuid} and similar device names to achieve the same
6405result, this is not recommended: These special device nodes are created
6406by the udev daemon and may be unavailable at the time the device is
6407mounted.}.
da7cabd4 6408
1068f26b 6409However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
6410Devices}), its @code{device} field @emph{must} refer to the mapped
6411device name---e.g., @file{/dev/mapper/root-partition}---and consequently
6412@code{title} must be set to @code{'device}. This is required so that
6413the system knows that mounting the file system depends on having the
6414corresponding device mapping established.
6415
cf4a9129
LC
6416@item @code{flags} (default: @code{'()})
6417This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
6418include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
6419access to special files), @code{no-suid} (ignore setuid and setgid
6420bits), and @code{no-exec} (disallow program execution.)
da7cabd4 6421
cf4a9129
LC
6422@item @code{options} (default: @code{#f})
6423This is either @code{#f}, or a string denoting mount options.
da7cabd4 6424
be21979d
LC
6425@item @code{mount?} (default: @code{#t})
6426This value indicates whether to automatically mount the file system when
6427the system is brought up. When set to @code{#f}, the file system gets
6428an entry in @file{/etc/fstab} (read by the @command{mount} command) but
6429is not automatically mounted.
6430
cf4a9129
LC
6431@item @code{needed-for-boot?} (default: @code{#f})
6432This Boolean value indicates whether the file system is needed when
6433booting. If that is true, then the file system is mounted when the
6434initial RAM disk (initrd) is loaded. This is always the case, for
6435instance, for the root file system.
da7cabd4 6436
cf4a9129
LC
6437@item @code{check?} (default: @code{#t})
6438This Boolean indicates whether the file system needs to be checked for
6439errors before being mounted.
f9cc8971 6440
4e469051
LC
6441@item @code{create-mount-point?} (default: @code{#f})
6442When true, the mount point is created if it does not exist yet.
6443
e51710d1
LC
6444@item @code{dependencies} (default: @code{'()})
6445This is a list of @code{<file-system>} objects representing file systems
6446that must be mounted before (and unmounted after) this one.
6447
6448As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
6449a dependency of @file{/sys/fs/cgroup/cpu} and
6450@file{/sys/fs/cgroup/memory}.
6451
cf4a9129
LC
6452@end table
6453@end deftp
da7cabd4 6454
a69576ea
LC
6455The @code{(gnu system file-systems)} exports the following useful
6456variables.
6457
6458@defvr {Scheme Variable} %base-file-systems
6459These are essential file systems that are required on normal systems,
cc0e575a 6460such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
6461below.) Operating system declarations should always contain at least
6462these.
a69576ea
LC
6463@end defvr
6464
7f239fd3
LC
6465@defvr {Scheme Variable} %pseudo-terminal-file-system
6466This is the file system to be mounted as @file{/dev/pts}. It supports
6467@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
6468functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
6469Manual}). Pseudo-terminals are used by terminal emulators such as
6470@command{xterm}.
6471@end defvr
6472
db17ae5c
LC
6473@defvr {Scheme Variable} %shared-memory-file-system
6474This file system is mounted as @file{/dev/shm} and is used to support
6475memory sharing across processes (@pxref{Memory-mapped I/O,
6476@code{shm_open},, libc, The GNU C Library Reference Manual}).
6477@end defvr
6478
3392ce5d
LC
6479@defvr {Scheme Variable} %immutable-store
6480This file system performs a read-only ``bind mount'' of
6481@file{/gnu/store}, making it read-only for all the users including
6482@code{root}. This prevents against accidental modification by software
6483running as @code{root} or by system administrators.
6484
6485The daemon itself is still able to write to the store: it remounts it
6486read-write in its own ``name space.''
6487@end defvr
6488
a69576ea
LC
6489@defvr {Scheme Variable} %binary-format-file-system
6490The @code{binfmt_misc} file system, which allows handling of arbitrary
6491executable file types to be delegated to user space. This requires the
6492@code{binfmt.ko} kernel module to be loaded.
6493@end defvr
6494
6495@defvr {Scheme Variable} %fuse-control-file-system
6496The @code{fusectl} file system, which allows unprivileged users to mount
6497and unmount user-space FUSE file systems. This requires the
6498@code{fuse.ko} kernel module to be loaded.
6499@end defvr
6500
510f9d86
LC
6501@node Mapped Devices
6502@subsection Mapped Devices
6503
6504@cindex device mapping
6505@cindex mapped devices
6506The Linux kernel has a notion of @dfn{device mapping}: a block device,
6507such as a hard disk partition, can be @dfn{mapped} into another device,
6508with additional processing over the data that flows through
6509it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
6510concept of a ``mapped device'' and that of a file system: both boil down
6511to @emph{translating} input/output operations made on a file to
6512operations on its backing store. Thus, the Hurd implements mapped
6513devices, like file systems, using the generic @dfn{translator} mechanism
6514(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
6515typical example is encryption device mapping: all writes to the mapped
6516device are encrypted, and all reads are deciphered, transparently.
6517
6518Mapped devices are declared using the @code{mapped-device} form:
6519
6520@example
6521(mapped-device
6522 (source "/dev/sda3")
6523 (target "home")
6524 (type luks-device-mapping))
6525@end example
6526
6527@noindent
6528@cindex disk encryption
6529@cindex LUKS
6530This example specifies a mapping from @file{/dev/sda3} to
6531@file{/dev/mapper/home} using LUKS---the
6532@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
6533standard mechanism for disk encryption. The @file{/dev/mapper/home}
6534device can then be used as the @code{device} of a @code{file-system}
6535declaration (@pxref{File Systems}). The @code{mapped-device} form is
6536detailed below.
6537
6538@deftp {Data Type} mapped-device
6539Objects of this type represent device mappings that will be made when
6540the system boots up.
6541
9cb426b8
LC
6542@table @code
6543@item source
510f9d86
LC
6544This string specifies the name of the block device to be mapped, such as
6545@code{"/dev/sda3"}.
6546
9cb426b8 6547@item target
510f9d86
LC
6548This string specifies the name of the mapping to be established. For
6549example, specifying @code{"my-partition"} will lead to the creation of
6550the @code{"/dev/mapper/my-partition"} device.
6551
9cb426b8 6552@item type
510f9d86
LC
6553This must be a @code{mapped-device-kind} object, which specifies how
6554@var{source} is mapped to @var{target}.
6555@end table
6556@end deftp
6557
6558@defvr {Scheme Variable} luks-device-mapping
6559This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 6560command from the package with the same name. It relies on the
510f9d86
LC
6561@code{dm-crypt} Linux kernel module.
6562@end defvr
6563
cf4a9129
LC
6564@node User Accounts
6565@subsection User Accounts
ee85f3db 6566
9bea87a5
LC
6567User accounts and groups are entirely managed through the
6568@code{operating-system} declaration. They are specified with the
6569@code{user-account} and @code{user-group} forms:
ee85f3db 6570
cf4a9129
LC
6571@example
6572(user-account
6573 (name "alice")
6574 (group "users")
24e752c0
LC
6575 (supplementary-groups '("wheel" ;allow use of sudo, etc.
6576 "audio" ;sound card
6577 "video" ;video devices such as webcams
6578 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
6579 (comment "Bob's sister")
6580 (home-directory "/home/alice"))
6581@end example
25083588 6582
9bea87a5
LC
6583When booting or upon completion of @command{guix system reconfigure},
6584the system ensures that only the user accounts and groups specified in
6585the @code{operating-system} declaration exist, and with the specified
6586properties. Thus, account or group creations or modifications made by
6587directly invoking commands such as @command{useradd} are lost upon
6588reconfiguration or reboot. This ensures that the system remains exactly
6589as declared.
6590
cf4a9129
LC
6591@deftp {Data Type} user-account
6592Objects of this type represent user accounts. The following members may
6593be specified:
ee85f3db 6594
cf4a9129
LC
6595@table @asis
6596@item @code{name}
6597The name of the user account.
ee85f3db 6598
cf4a9129
LC
6599@item @code{group}
6600This is the name (a string) or identifier (a number) of the user group
6601this account belongs to.
ee85f3db 6602
cf4a9129
LC
6603@item @code{supplementary-groups} (default: @code{'()})
6604Optionally, this can be defined as a list of group names that this
6605account belongs to.
ee85f3db 6606
cf4a9129
LC
6607@item @code{uid} (default: @code{#f})
6608This is the user ID for this account (a number), or @code{#f}. In the
6609latter case, a number is automatically chosen by the system when the
6610account is created.
ee85f3db 6611
cf4a9129 6612@item @code{comment} (default: @code{""})
1068f26b 6613A comment about the account, such as the account owner's full name.
c8c871d1 6614
cf4a9129
LC
6615@item @code{home-directory}
6616This is the name of the home directory for the account.
ee85f3db 6617
cf4a9129
LC
6618@item @code{shell} (default: Bash)
6619This is a G-expression denoting the file name of a program to be used as
6620the shell (@pxref{G-Expressions}).
ee85f3db 6621
cf4a9129
LC
6622@item @code{system?} (default: @code{#f})
6623This Boolean value indicates whether the account is a ``system''
6624account. System accounts are sometimes treated specially; for instance,
6625graphical login managers do not list them.
ee85f3db 6626
1bd4e6db 6627@anchor{user-account-password}
cf4a9129 6628@item @code{password} (default: @code{#f})
eb59595c
LC
6629You would normally leave this field to @code{#f}, initialize user
6630passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
6631users change it with @command{passwd}. Passwords set with
6632@command{passwd} are of course preserved across reboot and
6633reconfiguration.
eb59595c
LC
6634
6635If you @emph{do} want to have a preset password for an account, then
6636this field must contain the encrypted password, as a string.
5d1f1177
LC
6637@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
6638on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 6639Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 6640
cf4a9129
LC
6641@end table
6642@end deftp
ee85f3db 6643
cf4a9129 6644User group declarations are even simpler:
ee85f3db 6645
cf4a9129
LC
6646@example
6647(user-group (name "students"))
6648@end example
ee85f3db 6649
cf4a9129
LC
6650@deftp {Data Type} user-group
6651This type is for, well, user groups. There are just a few fields:
af8a56b8 6652
cf4a9129
LC
6653@table @asis
6654@item @code{name}
1068f26b 6655The name of the group.
ee85f3db 6656
cf4a9129
LC
6657@item @code{id} (default: @code{#f})
6658The group identifier (a number). If @code{#f}, a new number is
6659automatically allocated when the group is created.
ee85f3db 6660
c8fa3426
LC
6661@item @code{system?} (default: @code{#f})
6662This Boolean value indicates whether the group is a ``system'' group.
6663System groups have low numerical IDs.
6664
cf4a9129
LC
6665@item @code{password} (default: @code{#f})
6666What, user groups can have a password? Well, apparently yes. Unless
1068f26b 6667@code{#f}, this field specifies the password of the group.
ee85f3db 6668
cf4a9129
LC
6669@end table
6670@end deftp
401c53c4 6671
cf4a9129
LC
6672For convenience, a variable lists all the basic user groups one may
6673expect:
401c53c4 6674
cf4a9129
LC
6675@defvr {Scheme Variable} %base-groups
6676This is the list of basic user groups that users and/or packages expect
6677to be present on the system. This includes groups such as ``root'',
6678``wheel'', and ``users'', as well as groups used to control access to
6679specific devices such as ``audio'', ``disk'', and ``cdrom''.
6680@end defvr
401c53c4 6681
bf87f38a
LC
6682@defvr {Scheme Variable} %base-user-accounts
6683This is the list of basic system accounts that programs may expect to
6684find on a GNU/Linux system, such as the ``nobody'' account.
6685
6686Note that the ``root'' account is not included here. It is a
6687special-case and is automatically added whether or not it is specified.
6688@end defvr
6689
598e19dc
LC
6690@node Locales
6691@subsection Locales
6692
6693@cindex locale
6694A @dfn{locale} defines cultural conventions for a particular language
6695and region of the world (@pxref{Locales,,, libc, The GNU C Library
6696Reference Manual}). Each locale has a name that typically has the form
b2636518 6697@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
6698@code{fr_LU.utf8} designates the locale for the French language, with
6699cultural conventions from Luxembourg, and using the UTF-8 encoding.
6700
6701@cindex locale definition
6702Usually, you will want to specify the default locale for the machine
6703using the @code{locale} field of the @code{operating-system} declaration
6704(@pxref{operating-system Reference, @code{locale}}).
6705
f5582b2c
LC
6706The selected locale is automatically added to the @dfn{locale
6707definitions} known to the system if needed, with its codeset inferred
6708from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
6709@code{UTF-8} codeset. Additional locale definitions can be specified in
6710the @code{locale-definitions} slot of @code{operating-system}---this is
6711useful, for instance, if the codeset could not be inferred from the
6712locale name. The default set of locale definitions includes some widely
6713used locales, but not all the available locales, in order to save space.
6714
6715For instance, to add the North Frisian locale for Germany, the value of
6716that field may be:
598e19dc
LC
6717
6718@example
6719(cons (locale-definition
6720 (name "fy_DE.utf8") (source "fy_DE"))
6721 %default-locale-definitions)
6722@end example
6723
6724Likewise, to save space, one might want @code{locale-definitions} to
6725list only the locales that are actually used, as in:
6726
6727@example
6728(list (locale-definition
6729 (name "ja_JP.eucjp") (source "ja_JP")
6730 (charset "EUC-JP")))
6731@end example
6732
5c3c1427
LC
6733@vindex LOCPATH
6734The compiled locale definitions are available at
46bd6edd
LC
6735@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
6736version, which is the default location where the GNU@tie{}libc provided
6737by Guix looks for locale data. This can be overridden using the
6738@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
6739@code{LOCPATH} and locale packages}).
6740
598e19dc
LC
6741The @code{locale-definition} form is provided by the @code{(gnu system
6742locale)} module. Details are given below.
6743
6744@deftp {Data Type} locale-definition
6745This is the data type of a locale definition.
6746
6747@table @asis
6748
6749@item @code{name}
6750The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
6751Reference Manual}, for more information on locale names.
6752
6753@item @code{source}
6754The name of the source for that locale. This is typically the
6755@code{@var{language}_@var{territory}} part of the locale name.
6756
6757@item @code{charset} (default: @code{"UTF-8"})
6758The ``character set'' or ``code set'' for that locale,
6759@uref{http://www.iana.org/assignments/character-sets, as defined by
6760IANA}.
6761
6762@end table
6763@end deftp
6764
6765@defvr {Scheme Variable} %default-locale-definitions
1068f26b 6766A list of commonly used UTF-8 locales, used as the default
b2636518 6767value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 6768declarations.
b2636518
LC
6769
6770@cindex locale name
6771@cindex normalized codeset in locale names
6772These locale definitions use the @dfn{normalized codeset} for the part
6773that follows the dot in the name (@pxref{Using gettextized software,
6774normalized codeset,, libc, The GNU C Library Reference Manual}). So for
6775instance it has @code{uk_UA.utf8} but @emph{not}, say,
6776@code{uk_UA.UTF-8}.
598e19dc 6777@end defvr
401c53c4 6778
34760ae7
LC
6779@subsubsection Locale Data Compatibility Considerations
6780
6781@cindex incompatibility, of locale data
6782@code{operating-system} declarations provide a @code{locale-libcs} field
6783to specify the GNU@tie{}libc packages that are used to compile locale
6784declarations (@pxref{operating-system Reference}). ``Why would I
6785care?'', you may ask. Well, it turns out that the binary format of
6786locale data is occasionally incompatible from one libc version to
6787another.
6788
6789@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
6790@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
6791For instance, a program linked against libc version 2.21 is unable to
6792read locale data produced with libc 2.22; worse, that program
6793@emph{aborts} instead of simply ignoring the incompatible locale
6794data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
6795the incompatible locale data, which is already an improvement.}.
6796Similarly, a program linked against libc 2.22 can read most, but not
6797all, the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
6798data is incompatible); thus calls to @code{setlocale} may fail, but
6799programs will not abort.
6800
6801The ``problem'' in GuixSD is that users have a lot of freedom: They can
6802choose whether and when to upgrade software in their profiles, and might
6803be using a libc version different from the one the system administrator
6804used to build the system-wide locale data.
6805
6806Fortunately, unprivileged users can also install their own locale data
6807and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
6808@code{GUIX_LOCPATH} and locale packages}).
6809
6810Still, it is best if the system-wide locale data at
6811@file{/run/current-system/locale} is built for all the libc versions
6812actually in use on the system, so that all the programs can access
6813it---this is especially crucial on a multi-user system. To do that, the
6814administrator can specify several libc packages in the
6815@code{locale-libcs} field of @code{operating-system}:
6816
6817@example
6818(use-package-modules base)
6819
6820(operating-system
6821 ;; @dots{}
6822 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
6823@end example
6824
6825This example would lead to a system containing locale definitions for
6826both libc 2.21 and the current version of libc in
6827@file{/run/current-system/locale}.
6828
6829
cf4a9129
LC
6830@node Services
6831@subsection Services
401c53c4 6832
cf4a9129
LC
6833@cindex system services
6834An important part of preparing an @code{operating-system} declaration is
6835listing @dfn{system services} and their configuration (@pxref{Using the
6836Configuration System}). System services are typically daemons launched
6837when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
6838configuring network access.
6839
dd17bc38
AK
6840Services are managed by the GNU@tie{}Shepherd (@pxref{Introduction,,,
6841shepherd, The GNU Shepherd Manual}). On a running system, the
6842@command{herd} command allows you to list the available services, show
6843their status, start and stop them, or do other specific operations
6844(@pxref{Jump Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
6845
6846@example
dd17bc38 6847# herd status
d8b94dbd
LC
6848@end example
6849
6850The above command, run as @code{root}, lists the currently defined
dd17bc38 6851services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
6852service:
6853
6854@example
dd17bc38 6855# herd doc nscd
d8b94dbd
LC
6856Run libc's name service cache daemon (nscd).
6857@end example
6858
6859The @command{start}, @command{stop}, and @command{restart} sub-commands
6860have the effect you would expect. For instance, the commands below stop
6861the nscd service and restart the Xorg display server:
6862
6863@example
dd17bc38 6864# herd stop nscd
d8b94dbd 6865Service nscd has been stopped.
dd17bc38 6866# herd restart xorg-server
d8b94dbd
LC
6867Service xorg-server has been stopped.
6868Service xorg-server has been started.
6869@end example
401c53c4 6870
cf4a9129 6871The following sections document the available services, starting with
d8b94dbd
LC
6872the core services, that may be used in an @code{operating-system}
6873declaration.
401c53c4 6874
cf4a9129
LC
6875@menu
6876* Base Services:: Essential system services.
6877* Networking Services:: Network setup, SSH daemon, etc.
6878* X Window:: Graphical display.
fe1a39d3 6879* Desktop Services:: D-Bus and desktop services.
105369a4 6880* Database Services:: SQL databases.
d8c18af8 6881* Mail Services:: IMAP, POP3, SMTP, and all that.
58724c48 6882* Web Services:: Web servers.
aa4ed923 6883* Various Services:: Other services.
cf4a9129 6884@end menu
401c53c4 6885
cf4a9129
LC
6886@node Base Services
6887@subsubsection Base Services
a1ba8475 6888
cf4a9129
LC
6889The @code{(gnu services base)} module provides definitions for the basic
6890services that one expects from the system. The services exported by
6891this module are listed below.
401c53c4 6892
cf4a9129 6893@defvr {Scheme Variable} %base-services
31771497
LC
6894This variable contains a list of basic services (@pxref{Service Types
6895and Services}, for more information on service objects) one would
cf4a9129 6896expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 6897the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 6898more.
401c53c4 6899
cf4a9129
LC
6900This is the default value of the @code{services} field of
6901@code{operating-system} declarations. Usually, when customizing a
6902system, you will want to append services to @var{%base-services}, like
6903this:
401c53c4 6904
cf4a9129 6905@example
fa1e31b8 6906(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
6907@end example
6908@end defvr
401c53c4 6909
be1c2c54 6910@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
6911Return a service that sets the host name to @var{name}.
6912@end deffn
401c53c4 6913
66e4f01c
LC
6914@deffn {Scheme Procedure} mingetty-service @var{config}
6915Return a service to run mingetty according to @var{config}, a
6916@code{<mingetty-configuration>} object, which specifies the tty to run, among
6917other things.
cf4a9129 6918@end deffn
401c53c4 6919
66e4f01c
LC
6920@deftp {Data Type} mingetty-configuration
6921This is the data type representing the configuration of Mingetty, which
6922implements console log-in.
6923
6924@table @asis
6925
6926@item @code{tty}
6927The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
6928
6929@item @code{motd}
6930A file-like object containing the ``message of the day''.
6931
6932@item @code{auto-login} (default: @code{#f})
6933When true, this field must be a string denoting the user name under
f9b9a033 6934which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
6935user name and password must be entered to log in.
6936
6937@item @code{login-program} (default: @code{#f})
6938This must be either @code{#f}, in which case the default log-in program
6939is used (@command{login} from the Shadow tool suite), or a gexp denoting
6940the name of the log-in program.
6941
6942@item @code{login-pause?} (default: @code{#f})
6943When set to @code{#t} in conjunction with @var{auto-login}, the user
6944will have to press a key before the log-in shell is launched.
6945
6946@item @code{mingetty} (default: @var{mingetty})
6947The Mingetty package to use.
6948
6949@end table
6950@end deftp
6951
6454b333
LC
6952@cindex name service cache daemon
6953@cindex nscd
be1c2c54 6954@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 6955 [#:name-services '()]
1068f26b 6956Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
6957given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
6958Service Switch}, for an example.
cf4a9129 6959@end deffn
401c53c4 6960
6454b333
LC
6961@defvr {Scheme Variable} %nscd-default-configuration
6962This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 6963by @code{nscd-service}. It uses the caches defined by
6454b333
LC
6964@var{%nscd-default-caches}; see below.
6965@end defvr
6966
6967@deftp {Data Type} nscd-configuration
1068f26b 6968This is the data type representing the name service cache daemon (nscd)
6454b333
LC
6969configuration.
6970
6971@table @asis
6972
b893f1ae
LC
6973@item @code{name-services} (default: @code{'()})
6974List of packages denoting @dfn{name services} that must be visible to
6975the nscd---e.g., @code{(list @var{nss-mdns})}.
6976
6977@item @code{glibc} (default: @var{glibc})
6978Package object denoting the GNU C Library providing the @command{nscd}
6979command.
6980
6454b333 6981@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 6982Name of the nscd log file. This is where debugging output goes when
6454b333
LC
6983@code{debug-level} is strictly positive.
6984
6985@item @code{debug-level} (default: @code{0})
1068f26b 6986Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
6987debugging output is logged.
6988
6989@item @code{caches} (default: @var{%nscd-default-caches})
6990List of @code{<nscd-cache>} objects denoting things to be cached; see
6991below.
6992
6993@end table
6994@end deftp
6995
6996@deftp {Data Type} nscd-cache
6997Data type representing a cache database of nscd and its parameters.
6998
6999@table @asis
7000
7001@item @code{database}
7002This is a symbol representing the name of the database to be cached.
7003Valid values are @code{passwd}, @code{group}, @code{hosts}, and
7004@code{services}, which designate the corresponding NSS database
7005(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
7006
7007@item @code{positive-time-to-live}
7008@itemx @code{negative-time-to-live} (default: @code{20})
7009A number representing the number of seconds during which a positive or
7010negative lookup result remains in cache.
7011
7012@item @code{check-files?} (default: @code{#t})
7013Whether to check for updates of the files corresponding to
7014@var{database}.
7015
7016For instance, when @var{database} is @code{hosts}, setting this flag
7017instructs nscd to check for updates in @file{/etc/hosts} and to take
7018them into account.
7019
7020@item @code{persistent?} (default: @code{#t})
7021Whether the cache should be stored persistently on disk.
7022
7023@item @code{shared?} (default: @code{#t})
7024Whether the cache should be shared among users.
7025
7026@item @code{max-database-size} (default: 32@tie{}MiB)
7027Maximum size in bytes of the database cache.
7028
7029@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
7030@c settings, so leave them out.
7031
7032@end table
7033@end deftp
7034
7035@defvr {Scheme Variable} %nscd-default-caches
7036List of @code{<nscd-cache>} objects used by default by
1068f26b 7037@code{nscd-configuration} (see above).
6454b333
LC
7038
7039It enables persistent and aggressive caching of service and host name
7040lookups. The latter provides better host name lookup performance,
7041resilience in the face of unreliable name servers, and also better
7042privacy---often the result of host name lookups is in local cache, so
7043external name servers do not even need to be queried.
7044@end defvr
7045
7046
44abcb28
LC
7047@deffn {Scheme Procedure} syslog-service @
7048 [#:config-file @var{%default-syslog.conf}]
1068f26b 7049Return a service that runs @command{syslogd}. If the configuration file
44abcb28 7050name @var{config-file} is not specified, use some reasonable default
cf4a9129 7051settings.
44abcb28
LC
7052
7053@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
7054information on the configuration file syntax.
cf4a9129 7055@end deffn
401c53c4 7056
0adfe95a
LC
7057@anchor{guix-configuration-type}
7058@deftp {Data Type} guix-configuration
7059This data type represents the configuration of the Guix build daemon.
7060@xref{Invoking guix-daemon}, for more information.
7061
7062@table @asis
7063@item @code{guix} (default: @var{guix})
7064The Guix package to use.
401c53c4 7065
0adfe95a
LC
7066@item @code{build-group} (default: @code{"guixbuild"})
7067Name of the group for build user accounts.
401c53c4 7068
0adfe95a
LC
7069@item @code{build-accounts} (default: @code{10})
7070Number of build user accounts to create.
401c53c4 7071
0adfe95a
LC
7072@item @code{authorize-key?} (default: @code{#t})
7073Whether to authorize the substitute key for @code{hydra.gnu.org}
7074(@pxref{Substitutes}).
7075
7076@item @code{use-substitutes?} (default: @code{#t})
7077Whether to use substitutes.
7078
b0b9f6e0
LC
7079@item @code{substitute-urls} (default: @var{%default-substitute-urls})
7080The list of URLs where to look for substitutes by default.
7081
0adfe95a
LC
7082@item @code{extra-options} (default: @code{'()})
7083List of extra command-line options for @command{guix-daemon}.
7084
7085@item @code{lsof} (default: @var{lsof})
7086@itemx @code{lsh} (default: @var{lsh})
7087The lsof and lsh packages to use.
7088
7089@end table
7090@end deftp
7091
7092@deffn {Scheme Procedure} guix-service @var{config}
7093Return a service that runs the Guix build daemon according to
7094@var{config}.
cf4a9129 7095@end deffn
a1ba8475 7096
be1c2c54 7097@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
7098Run @var{udev}, which populates the @file{/dev} directory dynamically.
7099@end deffn
401c53c4 7100
be1c2c54 7101@deffn {Scheme Procedure} console-keymap-service @var{file}
dedb8d5e 7102@cindex keyboard layout
5eca9459
AK
7103Return a service to load console keymap from @var{file} using
7104@command{loadkeys} command.
7105@end deffn
7106
8664cc88
LC
7107@deffn {Scheme Procedure} gpm-service-type [#:gpm @var{gpm}] @
7108 [#:options]
7109Run @var{gpm}, the general-purpose mouse daemon, with the given
7110command-line @var{options}. GPM allows users to use the mouse in the console,
7111notably to select, copy, and paste text. The default value of @var{options}
7112uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
7113
7114This service is not part of @var{%base-services}.
7115@end deffn
7116
1c52181f
LC
7117@anchor{guix-publish-service}
7118@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
7119 [#:port 80] [#:host "localhost"]
7120Return a service that runs @command{guix publish} listening on @var{host}
7121and @var{port} (@pxref{Invoking guix publish}).
7122
7123This assumes that @file{/etc/guix} already contains a signing key pair as
7124created by @command{guix archive --generate-key} (@pxref{Invoking guix
7125archive}). If that is not the case, the service will fail to start.
7126@end deffn
7127
a69576ea 7128
cf4a9129
LC
7129@node Networking Services
7130@subsubsection Networking Services
401c53c4 7131
fa1e31b8 7132The @code{(gnu services networking)} module provides services to configure
cf4a9129 7133the network interface.
a1ba8475 7134
a023cca8 7135@cindex DHCP, networking service
be1c2c54 7136@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
7137Return a service that runs @var{dhcp}, a Dynamic Host Configuration
7138Protocol (DHCP) client, on all the non-loopback network interfaces.
7139@end deffn
7140
be1c2c54 7141@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
cf4a9129
LC
7142 [#:gateway #f] [#:name-services @code{'()}]
7143Return a service that starts @var{interface} with address @var{ip}. If
7144@var{gateway} is true, it must be a string specifying the default network
7145gateway.
7146@end deffn
8b315a6d 7147
b7d0c494 7148@cindex wicd
87f40011 7149@cindex network management
be1c2c54 7150@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
7151Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
7152management daemon that aims to simplify wired and wireless networking.
7153
7154This service adds the @var{wicd} package to the global profile, providing
7155several commands to interact with the daemon and configure networking:
7156@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
7157and @command{wicd-curses} user interfaces.
b7d0c494
MW
7158@end deffn
7159
c0a9589d
SB
7160@cindex NetworkManager
7161@deffn {Scheme Procedure} network-manager-service @
7162 [#:network-manager @var{network-manager}]
7163Return a service that runs NetworkManager, a network connection manager
1068f26b 7164attempting to keep network connectivity active when available.
c0a9589d
SB
7165@end deffn
7166
be1c2c54 7167@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
63854bcb
LC
7168 [#:name-service @var{%ntp-servers}]
7169Return a service that runs the daemon from @var{ntp}, the
7170@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
7171keep the system clock synchronized with that of @var{servers}.
7172@end deffn
7173
7174@defvr {Scheme Variable} %ntp-servers
7175List of host names used as the default NTP servers.
7176@end defvr
7177
375c6108
LC
7178@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
7179Return a service to run the @uref{https://torproject.org, Tor} anonymous
7180networking daemon.
8b315a6d 7181
375c6108 7182The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
7183@var{config-file}, a file-like object, with an additional @code{User tor} line
7184and lines for hidden services added via @code{tor-hidden-service}. Run
7185@command{man tor} for information about the configuration file.
7186@end deffn
7187
24a8ef3b 7188@cindex hidden service
6331bde7
LC
7189@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
7190Define a new Tor @dfn{hidden service} called @var{name} and implementing
7191@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
7192
7193@example
24a8ef3b
LC
7194 '((22 "127.0.0.1:22")
7195 (80 "127.0.0.1:8080"))
6331bde7
LC
7196@end example
7197
7198In this example, port 22 of the hidden service is mapped to local port 22, and
7199port 80 is mapped to local port 8080.
7200
6629099a
LC
7201This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
7202the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
7203service.
7204
7205See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
7206project's documentation} for more information.
cf4a9129 7207@end deffn
8b315a6d 7208
be1c2c54 7209@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
7210 [#:interface "127.0.0.1"] [#:port 6667] @
7211 [#:extra-settings ""]
7212Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
7213acts as a gateway between IRC and chat networks.
7214
7215The daemon will listen to the interface corresponding to the IP address
7216specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
7217local clients can connect, whereas @code{0.0.0.0} means that connections can
7218come from any networking interface.
7219
7220In addition, @var{extra-settings} specifies a string to append to the
7221configuration file.
7222@end deffn
7223
f4391bec 7224Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 7225
be1c2c54 7226@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 7227 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
7228 [#:allow-empty-passwords? #f] [#:root-login? #f] @
7229 [#:syslog-output? #t] [#:x11-forwarding? #t] @
7230 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 7231 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
7232Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
7233@var{host-key} must designate a file containing the host key, and readable
7234only by root.
72e25e35 7235
5833bf33
DP
7236When @var{daemonic?} is true, @command{lshd} will detach from the
7237controlling terminal and log its output to syslogd, unless one sets
7238@var{syslog-output?} to false. Obviously, it also makes lsh-service
7239depend on existence of syslogd service. When @var{pid-file?} is true,
7240@command{lshd} writes its PID to the file called @var{pid-file}.
7241
cf4a9129
LC
7242When @var{initialize?} is true, automatically create the seed and host key
7243upon service activation if they do not exist yet. This may take long and
7244require interaction.
8b315a6d 7245
20dd519c
LC
7246When @var{initialize?} is false, it is up to the user to initialize the
7247randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
7248a key pair with the private key stored in file @var{host-key} (@pxref{lshd
7249basics,,, lsh, LSH Manual}).
7250
cf4a9129
LC
7251When @var{interfaces} is empty, lshd listens for connections on all the
7252network interfaces; otherwise, @var{interfaces} must be a list of host names
7253or addresses.
9bf3c1a7 7254
20dd519c
LC
7255@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
7256passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 7257root.
4af2447e 7258
cf4a9129
LC
7259The other options should be self-descriptive.
7260@end deffn
4af2447e 7261
fa0c1d61
LC
7262@defvr {Scheme Variable} %facebook-host-aliases
7263This variable contains a string for use in @file{/etc/hosts}
7264(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
7265line contains a entry that maps a known server name of the Facebook
7266on-line service---e.g., @code{www.facebook.com}---to the local
7267host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
7268
7269This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
7270@code{operating-system} declaration (@pxref{operating-system Reference,
7271@file{/etc/hosts}}):
fa0c1d61
LC
7272
7273@example
7274(use-modules (gnu) (guix))
7275
7276(operating-system
7277 (host-name "mymachine")
7278 ;; ...
7279 (hosts-file
7280 ;; Create a /etc/hosts file with aliases for "localhost"
7281 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
7282 (plain-file "hosts"
7283 (string-append (local-host-aliases host-name)
7284 %facebook-host-aliases))))
fa0c1d61
LC
7285@end example
7286
7287This mechanism can prevent programs running locally, such as Web
7288browsers, from accessing Facebook.
7289@end defvr
7290
965a7332
LC
7291The @code{(gnu services avahi)} provides the following definition.
7292
be1c2c54 7293@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
7294 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
7295 [#:ipv6? #t] [#:wide-area? #f] @
7296 [#:domains-to-browse '()]
7297Return a service that runs @command{avahi-daemon}, a system-wide
7298mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
7299"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
7300extends the name service cache daemon (nscd) so that it can resolve
7301@code{.local} host names using
1065bed9
LC
7302@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
7303add the @var{avahi} package to the system profile so that commands such as
7304@command{avahi-browse} are directly usable.
965a7332
LC
7305
7306If @var{host-name} is different from @code{#f}, use that as the host name to
7307publish for this machine; otherwise, use the machine's actual host name.
7308
7309When @var{publish?} is true, publishing of host names and services is allowed;
7310in particular, avahi-daemon will publish the machine's host name and IP
7311address via mDNS on the local network.
7312
7313When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
7314
7315Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
7316sockets.
7317@end deffn
7318
7319
cf4a9129
LC
7320@node X Window
7321@subsubsection X Window
68ad877c 7322
cf4a9129
LC
7323Support for the X Window graphical display system---specifically
7324Xorg---is provided by the @code{(gnu services xorg)} module. Note that
7325there is no @code{xorg-service} procedure. Instead, the X server is
7326started by the @dfn{login manager}, currently SLiM.
4af2447e 7327
be1c2c54 7328@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
7329 [#:auto-login? #f] [#:default-user ""] [#:startx] @
7330 [#:theme @var{%default-slim-theme}] @
4bd43bbe 7331 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
7332Return a service that spawns the SLiM graphical login manager, which in
7333turn starts the X display server with @var{startx}, a command as returned by
7334@code{xorg-start-command}.
4af2447e 7335
04e4e6ab
LC
7336@cindex X session
7337
7338SLiM automatically looks for session types described by the @file{.desktop}
7339files in @file{/run/current-system/profile/share/xsessions} and allows users
7340to choose a session from the log-in screen using @kbd{F1}. Packages such as
7341@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
7342adding them to the system-wide set of packages automatically makes them
7343available at the log-in screen.
7344
7345In addition, @file{~/.xsession} files are honored. When available,
7346@file{~/.xsession} must be an executable that starts a window manager
7347and/or other X clients.
7348
cf4a9129
LC
7349When @var{allow-empty-passwords?} is true, allow logins with an empty
7350password. When @var{auto-login?} is true, log in automatically as
7351@var{default-user}.
0ecc3bf3 7352
1068f26b 7353If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
7354@var{theme} must be a gexp denoting the name of a directory containing the
7355theme to use. In that case, @var{theme-name} specifies the name of the
7356theme.
cf4a9129 7357@end deffn
4af2447e 7358
0ecc3bf3
LC
7359@defvr {Scheme Variable} %default-theme
7360@defvrx {Scheme Variable} %default-theme-name
7361The G-Expression denoting the default SLiM theme and its name.
7362@end defvr
7363
be1c2c54 7364@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 7365 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 7366Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
7367from @var{xorg-server}. @var{configuration-file} is the server configuration
7368file or a derivation that builds it; when omitted, the result of
7369@code{xorg-configuration-file} is used.
7370
7371Usually the X server is started by a login manager.
7372@end deffn
7373
be1c2c54 7374@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 7375 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
7376Return a configuration file for the Xorg server containing search paths for
7377all the common drivers.
f703413e
LC
7378
7379@var{drivers} must be either the empty list, in which case Xorg chooses a
7380graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 7381this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
7382
7383Likewise, when @var{resolutions} is the empty list, Xorg chooses an
7384appropriate screen resolution; otherwise, it must be a list of
7385resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
7386
7387Last, @var{extra-config} is a list of strings or objects appended to the
7388@code{text-file*} argument list. It is used to pass extra text to be added
7389verbatim to the configuration file.
f703413e 7390@end deffn
4af2447e 7391
6726282b
LC
7392@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
7393Add @var{package}, a package for a screen-locker or screen-saver whose
7394command is @var{program}, to the set of setuid programs and add a PAM entry
7395for it. For example:
7396
7397@lisp
7398(screen-locker-service xlockmore "xlock")
7399@end lisp
7400
7401makes the good ol' XlockMore usable.
7402@end deffn
7403
7404
fe1a39d3
LC
7405@node Desktop Services
7406@subsubsection Desktop Services
aa4ed923 7407
fe1a39d3
LC
7408The @code{(gnu services desktop)} module provides services that are
7409usually useful in the context of a ``desktop'' setup---that is, on a
7410machine running a graphical display server, possibly with graphical user
7411interfaces, etc.
aa4ed923 7412
4467be21
LC
7413To simplify things, the module defines a variable containing the set of
7414services that users typically expect on a machine with a graphical
7415environment and networking:
7416
7417@defvr {Scheme Variable} %desktop-services
7418This is a list of services that builds upon @var{%base-services} and
1068f26b 7419adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
7420
7421In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
7422@code{slim-service}}), screen lockers,
7423a network management tool (@pxref{Networking
4467be21 7424Services, @code{wicd-service}}), energy and color management services,
4650a77e 7425the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
7426the GeoClue location service, an NTP client (@pxref{Networking
7427Services}), the Avahi daemon, and has the name service switch service
7428configured to be able to use @code{nss-mdns} (@pxref{Name Service
7429Switch, mDNS}).
4467be21
LC
7430@end defvr
7431
7432The @var{%desktop-services} variable can be used as the @code{services}
7433field of an @code{operating-system} declaration (@pxref{operating-system
7434Reference, @code{services}}).
7435
0adfe95a
LC
7436The actual service definitions provided by @code{(gnu services dbus)}
7437and @code{(gnu services desktop)} are described below.
4467be21 7438
0adfe95a 7439@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
7440Return a service that runs the ``system bus'', using @var{dbus}, with
7441support for @var{services}.
aa4ed923 7442
fe1a39d3
LC
7443@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
7444facility. Its system bus is used to allow system services to communicate
1068f26b 7445and to be notified of system-wide events.
aa4ed923 7446
fe1a39d3
LC
7447@var{services} must be a list of packages that provide an
7448@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
7449and policy files. For example, to allow avahi-daemon to use the system bus,
7450@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
7451@end deffn
7452
0adfe95a 7453@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
7454Return a service that runs the @code{elogind} login and
7455seat management daemon. @uref{https://github.com/andywingo/elogind,
7456Elogind} exposes a D-Bus interface that can be used to know which users
7457are logged in, know what kind of sessions they have open, suspend the
7458system, inhibit system suspend, reboot the system, and other tasks.
7459
7460Elogind handles most system-level power events for a computer, for
7461example suspending the system when a lid is closed, or shutting it down
7462when the power button is pressed.
7463
7464The @var{config} keyword argument specifies the configuration for
1068f26b 7465elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
7466(@var{parameter} @var{value})...)} invocation. Available parameters and
7467their default values are:
7468
7469@table @code
7470@item kill-user-processes?
7471@code{#f}
7472@item kill-only-users
7473@code{()}
7474@item kill-exclude-users
7475@code{("root")}
7476@item inhibit-delay-max-seconds
7477@code{5}
7478@item handle-power-key
7479@code{poweroff}
7480@item handle-suspend-key
7481@code{suspend}
7482@item handle-hibernate-key
7483@code{hibernate}
7484@item handle-lid-switch
7485@code{suspend}
7486@item handle-lid-switch-docked
7487@code{ignore}
7488@item power-key-ignore-inhibited?
7489@code{#f}
7490@item suspend-key-ignore-inhibited?
7491@code{#f}
7492@item hibernate-key-ignore-inhibited?
7493@code{#f}
7494@item lid-switch-ignore-inhibited?
7495@code{#t}
7496@item holdoff-timeout-seconds
7497@code{30}
7498@item idle-action
7499@code{ignore}
7500@item idle-action-seconds
7501@code{(* 30 60)}
7502@item runtime-directory-size-percent
7503@code{10}
7504@item runtime-directory-size
7505@code{#f}
7506@item remove-ipc?
7507@code{#t}
7508@item suspend-state
7509@code{("mem" "standby" "freeze")}
7510@item suspend-mode
7511@code{()}
7512@item hibernate-state
7513@code{("disk")}
7514@item hibernate-mode
7515@code{("platform" "shutdown")}
7516@item hybrid-sleep-state
7517@code{("disk")}
7518@item hybrid-sleep-mode
7519@code{("suspend" "platform" "shutdown")}
7520@end table
7521@end deffn
7522
be1c2c54 7523@deffn {Scheme Procedure} polkit-service @
4650a77e 7524 [#:polkit @var{polkit}]
222e3319
LC
7525Return a service that runs the
7526@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
7527management service}, which allows system administrators to grant access to
7528privileged operations in a structured way. By querying the Polkit service, a
7529privileged system component can know when it should grant additional
7530capabilities to ordinary users. For example, an ordinary user can be granted
7531the capability to suspend the system if the user is logged in locally.
4650a77e
AW
7532@end deffn
7533
be1c2c54 7534@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
7535 [#:watts-up-pro? #f] @
7536 [#:poll-batteries? #t] @
7537 [#:ignore-lid? #f] @
7538 [#:use-percentage-for-policy? #f] @
7539 [#:percentage-low 10] @
7540 [#:percentage-critical 3] @
7541 [#:percentage-action 2] @
7542 [#:time-low 1200] @
7543 [#:time-critical 300] @
7544 [#:time-action 120] @
7545 [#:critical-power-action 'hybrid-sleep]
7546Return a service that runs @uref{http://upower.freedesktop.org/,
7547@command{upowerd}}, a system-wide monitor for power consumption and battery
7548levels, with the given configuration settings. It implements the
7549@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
7550GNOME.
7551@end deffn
7552
2b9e0a94
LC
7553@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
7554Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
7555UDisks}, a @dfn{disk management} daemon that provides user interfaces with
7556notifications and ways to mount/unmount disks. Programs that talk to UDisks
7557include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
7558@end deffn
7559
be1c2c54 7560@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
7561Return a service that runs @command{colord}, a system service with a D-Bus
7562interface to manage the color profiles of input and output devices such as
7563screens and scanners. It is notably used by the GNOME Color Manager graphical
7564tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
7565site} for more information.
7566@end deffn
7567
cee32ee4 7568@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 7569Return a configuration allowing an application to access GeoClue
cee32ee4
AW
7570location data. @var{name} is the Desktop ID of the application, without
7571the @code{.desktop} part. If @var{allowed?} is true, the application
7572will have access to location information by default. The boolean
1068f26b 7573@var{system?} value indicates whether an application is a system component
cee32ee4
AW
7574or not. Finally @var{users} is a list of UIDs of all users for which
7575this application is allowed location info access. An empty users list
7576means that all users are allowed.
7577@end deffn
7578
7579@defvr {Scheme Variable} %standard-geoclue-applications
7580The standard list of well-known GeoClue application configurations,
1068f26b
AE
7581granting authority to the GNOME date-and-time utility to ask for the
7582current location in order to set the time zone, and allowing the
7583IceCat and Epiphany web browsers to request location information.
7584IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
7585know the user's location.
7586@end defvr
7587
be1c2c54 7588@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
7589 [#:whitelist '()] @
7590 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
7591 [#:submit-data? #f]
7592 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
7593 [#:submission-nick "geoclue"] @
7594 [#:applications %standard-geoclue-applications]
7595Return a service that runs the GeoClue location service. This service
7596provides a D-Bus interface to allow applications to request access to a
7597user's physical location, and optionally to add information to online
7598location databases. See
7599@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
7600web site} for more information.
7601@end deffn
7602
105369a4
DT
7603@node Database Services
7604@subsubsection Database Services
7605
7606The @code{(gnu services databases)} module provides the following service.
7607
be1c2c54 7608@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
7609 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
7610Return a service that runs @var{postgresql}, the PostgreSQL database
7611server.
7612
7613The PostgreSQL daemon loads its runtime configuration from
7614@var{config-file} and stores the database cluster in
7615@var{data-directory}.
7616@end deffn
fe1a39d3 7617
d8c18af8
AW
7618@node Mail Services
7619@subsubsection Mail Services
7620
7621The @code{(gnu services mail)} module provides Guix service definitions
7622for mail services. Currently the only implemented service is Dovecot,
7623an IMAP, POP3, and LMTP server.
7624
7625Guix does not yet have a mail transfer agent (MTA), although for some
7626lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
7627is needed to properly integrate a full MTA, such as Postfix. Patches
7628welcome!
7629
7630To add an IMAP/POP3 server to a GuixSD system, add a
7631@code{dovecot-service} to the operating system definition:
7632
7633@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
7634Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
7635@end deffn
7636
1068f26b 7637By default, Dovecot does not need much configuration; the default
d8c18af8
AW
7638configuration object created by @code{(dovecot-configuration)} will
7639suffice if your mail is delivered to @code{~/Maildir}. A self-signed
7640certificate will be generated for TLS-protected connections, though
7641Dovecot will also listen on cleartext ports by default. There are a
1068f26b 7642number of options, though, which mail administrators might need to change,
d8c18af8
AW
7643and as is the case with other services, Guix allows the system
7644administrator to specify these parameters via a uniform Scheme interface.
7645
7646For example, to specify that mail is located at @code{maildir~/.mail},
7647one would instantiate the Dovecot service like this:
7648
7649@example
7650(dovecot-service #:config
7651 (dovecot-configuration
7652 (mail-location "maildir:~/.mail")))
7653@end example
7654
7655The available configuration parameters follow. Each parameter
7656definition is preceded by its type; for example, @samp{string-list foo}
7657indicates that the @code{foo} parameter should be specified as a list of
7658strings. There is also a way to specify the configuration as a string,
7659if you have an old @code{dovecot.conf} file that you want to port over
7660from some other system; see the end for more details.
7661
7662@c The following documentation was initially generated by
7663@c (generate-documentation) in (gnu services mail). Manually maintained
7664@c documentation is better, so we shouldn't hesitate to edit below as
7665@c needed. However if the change you want to make to this documentation
7666@c can be done in an automated way, it's probably easier to change
7667@c (generate-documentation) than to make it below and have to deal with
7668@c the churn as dovecot updates.
7669
7670Available @code{dovecot-configuration} fields are:
7671
7672@deftypevr {@code{dovecot-configuration} parameter} package dovecot
7673The dovecot package.
7674@end deftypevr
7675
7676@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
7677A list of IPs or hosts where to listen for connections. @samp{*}
7678listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
7679interfaces. If you want to specify non-default ports or anything more
7680complex, customize the address and port fields of the
7681@samp{inet-listener} of the specific services you are interested in.
7682@end deftypevr
7683
7684@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
7685List of protocols we want to serve. Available protocols include
7686@samp{imap}, @samp{pop3}, and @samp{lmtp}.
7687
7688Available @code{protocol-configuration} fields are:
7689
7690@deftypevr {@code{protocol-configuration} parameter} string name
7691The name of the protocol.
7692@end deftypevr
7693
7694@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 7695UNIX socket path to the master authentication server to find users.
d8c18af8 7696This is used by imap (for shared users) and lda.
1068f26b 7697It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
7698@end deftypevr
7699
7700@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
7701Space separated list of plugins to load.
7702@end deftypevr
7703
7704@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
7705Maximum number of IMAP connections allowed for a user from each IP
7706address. NOTE: The username is compared case-sensitively.
7707Defaults to @samp{10}.
7708@end deftypevr
7709
7710@end deftypevr
7711
7712@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
7713List of services to enable. Available services include @samp{imap},
7714@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
7715@samp{lmtp}.
7716
7717Available @code{service-configuration} fields are:
7718
7719@deftypevr {@code{service-configuration} parameter} string kind
7720The service kind. Valid values include @code{director},
7721@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
7722@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
7723@code{tcpwrap}, @code{quota-warning}, or anything else.
7724@end deftypevr
7725
7726@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 7727Listeners for the service. A listener is either a
d8c18af8
AW
7728@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
7729an @code{inet-listener-configuration}.
7730Defaults to @samp{()}.
7731
7732Available @code{unix-listener-configuration} fields are:
7733
7734@deftypevr {@code{unix-listener-configuration} parameter} file-name path
7735The file name on which to listen.
7736@end deftypevr
7737
7738@deftypevr {@code{unix-listener-configuration} parameter} string mode
7739The access mode for the socket.
7740Defaults to @samp{"0600"}.
7741@end deftypevr
7742
7743@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 7744The user to own the socket.
d8c18af8
AW
7745Defaults to @samp{""}.
7746@end deftypevr
7747
7748@deftypevr {@code{unix-listener-configuration} parameter} string group
7749The group to own the socket.
7750Defaults to @samp{""}.
7751@end deftypevr
7752
7753
7754Available @code{fifo-listener-configuration} fields are:
7755
7756@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
7757The file name on which to listen.
7758@end deftypevr
7759
7760@deftypevr {@code{fifo-listener-configuration} parameter} string mode
7761The access mode for the socket.
7762Defaults to @samp{"0600"}.
7763@end deftypevr
7764
7765@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 7766The user to own the socket.
d8c18af8
AW
7767Defaults to @samp{""}.
7768@end deftypevr
7769
7770@deftypevr {@code{fifo-listener-configuration} parameter} string group
7771The group to own the socket.
7772Defaults to @samp{""}.
7773@end deftypevr
7774
7775
7776Available @code{inet-listener-configuration} fields are:
7777
7778@deftypevr {@code{inet-listener-configuration} parameter} string protocol
7779The protocol to listen for.
7780@end deftypevr
7781
7782@deftypevr {@code{inet-listener-configuration} parameter} string address
7783The address on which to listen, or empty for all addresses.
7784Defaults to @samp{""}.
7785@end deftypevr
7786
7787@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
7788The port on which to listen.
7789@end deftypevr
7790
7791@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
7792Whether to use SSL for this service; @samp{yes}, @samp{no}, or
7793@samp{required}.
7794Defaults to @samp{#t}.
7795@end deftypevr
7796
7797@end deftypevr
7798
7799@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
7800Number of connections to handle before starting a new process.
7801Typically the only useful values are 0 (unlimited) or 1. 1 is more
7802secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
7803Defaults to @samp{1}.
7804@end deftypevr
7805
7806@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
7807Number of processes to always keep waiting for more connections.
7808Defaults to @samp{0}.
7809@end deftypevr
7810
7811@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
7812If you set @samp{service-count 0}, you probably need to grow
7813this.
7814Defaults to @samp{256000000}.
7815@end deftypevr
7816
7817@end deftypevr
7818
7819@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
7820Dict configuration, as created by the @code{dict-configuration}
7821constructor.
7822
7823Available @code{dict-configuration} fields are:
7824
7825@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
7826A list of key-value pairs that this dict should hold.
7827Defaults to @samp{()}.
7828@end deftypevr
7829
7830@end deftypevr
7831
7832@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 7833A list of passdb configurations, each one created by the
d8c18af8
AW
7834@code{passdb-configuration} constructor.
7835
7836Available @code{passdb-configuration} fields are:
7837
7838@deftypevr {@code{passdb-configuration} parameter} string driver
7839The driver that the passdb should use. Valid values include
7840@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
7841@samp{static}.
7842Defaults to @samp{"pam"}.
7843@end deftypevr
7844
7845@deftypevr {@code{passdb-configuration} parameter} free-form-args args
7846A list of key-value args to the passdb driver.
7847Defaults to @samp{()}.
7848@end deftypevr
7849
7850@end deftypevr
7851
7852@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
7853List of userdb configurations, each one created by the
7854@code{userdb-configuration} constructor.
7855
7856Available @code{userdb-configuration} fields are:
7857
7858@deftypevr {@code{userdb-configuration} parameter} string driver
7859The driver that the userdb should use. Valid values include
7860@samp{passwd} and @samp{static}.
7861Defaults to @samp{"passwd"}.
7862@end deftypevr
7863
7864@deftypevr {@code{userdb-configuration} parameter} free-form-args args
7865A list of key-value args to the userdb driver.
7866Defaults to @samp{()}.
7867@end deftypevr
7868
7869@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
7870Override fields from passwd.
7871Defaults to @samp{()}.
7872@end deftypevr
7873
7874@end deftypevr
7875
7876@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
7877Plug-in configuration, created by the @code{plugin-configuration}
7878constructor.
7879@end deftypevr
7880
7881@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
7882List of namespaces. Each item in the list is created by the
7883@code{namespace-configuration} constructor.
7884
7885Available @code{namespace-configuration} fields are:
7886
7887@deftypevr {@code{namespace-configuration} parameter} string name
7888Name for this namespace.
7889@end deftypevr
7890
7891@deftypevr {@code{namespace-configuration} parameter} string type
7892Namespace type: @samp{private}, @samp{shared} or @samp{public}.
7893Defaults to @samp{"private"}.
7894@end deftypevr
7895
7896@deftypevr {@code{namespace-configuration} parameter} string separator
7897Hierarchy separator to use. You should use the same separator for
7898all namespaces or some clients get confused. @samp{/} is usually a good
7899one. The default however depends on the underlying mail storage
7900format.
7901Defaults to @samp{""}.
7902@end deftypevr
7903
7904@deftypevr {@code{namespace-configuration} parameter} string prefix
7905Prefix required to access this namespace. This needs to be
7906different for all namespaces. For example @samp{Public/}.
7907Defaults to @samp{""}.
7908@end deftypevr
7909
7910@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 7911Physical location of the mailbox. This is in the same format as
d8c18af8
AW
7912mail_location, which is also the default for it.
7913Defaults to @samp{""}.
7914@end deftypevr
7915
7916@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
7917There can be only one INBOX, and this setting defines which
7918namespace has it.
7919Defaults to @samp{#f}.
7920@end deftypevr
7921
7922@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
7923If namespace is hidden, it's not advertised to clients via NAMESPACE
7924extension. You'll most likely also want to set @samp{list? #f}. This is mostly
7925useful when converting from another server with different namespaces
7926which you want to deprecate but still keep working. For example you can
7927create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
7928and @samp{mail/}.
7929Defaults to @samp{#f}.
7930@end deftypevr
7931
7932@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
7933Show the mailboxes under this namespace with the LIST command. This
7934makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
7935extension. The special @code{children} value lists child mailboxes, but
7936hides the namespace prefix.
7937Defaults to @samp{#t}.
7938@end deftypevr
7939
7940@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
7941Namespace handles its own subscriptions. If set to @code{#f}, the
7942parent namespace handles them. The empty prefix should always have this
1068f26b 7943as @code{#t}).
d8c18af8
AW
7944Defaults to @samp{#t}.
7945@end deftypevr
7946
7947@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
7948List of predefined mailboxes in this namespace.
7949Defaults to @samp{()}.
7950
7951Available @code{mailbox-configuration} fields are:
7952
7953@deftypevr {@code{mailbox-configuration} parameter} string name
7954Name for this mailbox.
7955@end deftypevr
7956
7957@deftypevr {@code{mailbox-configuration} parameter} string auto
7958@samp{create} will automatically create this mailbox.
7959@samp{subscribe} will both create and subscribe to the mailbox.
7960Defaults to @samp{"no"}.
7961@end deftypevr
7962
7963@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
7964List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
7965Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
7966@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
7967Defaults to @samp{()}.
7968@end deftypevr
7969
7970@end deftypevr
7971
7972@end deftypevr
7973
7974@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
7975Base directory where to store runtime data.
7976Defaults to @samp{"/var/run/dovecot/"}.
7977@end deftypevr
7978
7979@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
7980Greeting message for clients.
7981Defaults to @samp{"Dovecot ready."}.
7982@end deftypevr
7983
7984@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
7985List of trusted network ranges. Connections from these IPs are
7986allowed to override their IP addresses and ports (for logging and for
7987authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 7988for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
7989here.
7990Defaults to @samp{()}.
7991@end deftypevr
7992
7993@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
7994List of login access check sockets (e.g. tcpwrap).
7995Defaults to @samp{()}.
7996@end deftypevr
7997
7998@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
7999Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
8000and IP address. Useful for seeing who is actually using the IMAP
8001processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
8002accounts).
8003Defaults to @samp{#f}.
8004@end deftypevr
8005
8006@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
8007Should all processes be killed when Dovecot master process shuts down.
8008Setting this to @code{#f} means that Dovecot can be upgraded without
8009forcing existing client connections to close (although that could also
1068f26b 8010be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
8011Defaults to @samp{#t}.
8012@end deftypevr
8013
8014@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
8015If non-zero, run mail commands via this many connections to doveadm
8016server, instead of running them directly in the same process.
8017Defaults to @samp{0}.
8018@end deftypevr
8019
8020@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
8021UNIX socket or host:port used for connecting to doveadm server.
8022Defaults to @samp{"doveadm-server"}.
8023@end deftypevr
8024
8025@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
8026List of environment variables that are preserved on Dovecot startup
8027and passed down to all of its child processes. You can also give
8028key=value pairs to always set specific settings.
8029@end deftypevr
8030
8031@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
8032Disable LOGIN command and all other plaintext authentications unless
8033SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
8034matches the local IP (i.e. you're connecting from the same computer),
8035the connection is considered secure and plaintext authentication is
8036allowed. See also ssl=required setting.
8037Defaults to @samp{#t}.
8038@end deftypevr
8039
8040@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
8041Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
8042Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
8043for caching to be used.
8044Defaults to @samp{0}.
8045@end deftypevr
8046
8047@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
8048Time to live for cached data. After TTL expires the cached record
8049is no longer used, *except* if the main database lookup returns internal
8050failure. We also try to handle password changes automatically: If
8051user's previous authentication was successful, but this one wasn't, the
8052cache isn't used. For now this works only with plaintext
8053authentication.
8054Defaults to @samp{"1 hour"}.
8055@end deftypevr
8056
8057@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
8058TTL for negative hits (user not found, password mismatch).
80590 disables caching them completely.
8060Defaults to @samp{"1 hour"}.
8061@end deftypevr
8062
8063@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
8064List of realms for SASL authentication mechanisms that need them.
8065You can leave it empty if you don't want to support multiple realms.
8066Many clients simply use the first one listed here, so keep the default
8067realm first.
8068Defaults to @samp{()}.
8069@end deftypevr
8070
8071@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
8072Default realm/domain to use if none was specified. This is used for
8073both SASL realms and appending @@domain to username in plaintext
8074logins.
8075Defaults to @samp{""}.
8076@end deftypevr
8077
8078@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
8079List of allowed characters in username. If the user-given username
8080contains a character not listed in here, the login automatically fails.
8081This is just an extra check to make sure user can't exploit any
8082potential quote escaping vulnerabilities with SQL/LDAP databases. If
8083you want to allow all characters, set this value to empty.
8084Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
8085@end deftypevr
8086
8087@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
8088Username character translations before it's looked up from
8089databases. The value contains series of from -> to characters. For
8090example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
8091translated to @samp{@@}.
8092Defaults to @samp{""}.
8093@end deftypevr
8094
8095@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
8096Username formatting before it's looked up from databases. You can
8097use the standard variables here, e.g. %Lu would lowercase the username,
8098%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
8099change the @samp{@@} into @samp{-AT-}. This translation is done after
8100@samp{auth-username-translation} changes.
8101Defaults to @samp{"%Lu"}.
8102@end deftypevr
8103
8104@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
8105If you want to allow master users to log in by specifying the master
8106username within the normal username string (i.e. not using SASL
8107mechanism's support for it), you can specify the separator character
8108here. The format is then <username><separator><master username>.
8109UW-IMAP uses @samp{*} as the separator, so that could be a good
8110choice.
8111Defaults to @samp{""}.
8112@end deftypevr
8113
8114@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
8115Username to use for users logging in with ANONYMOUS SASL
8116mechanism.
8117Defaults to @samp{"anonymous"}.
8118@end deftypevr
8119
8120@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
8121Maximum number of dovecot-auth worker processes. They're used to
8122execute blocking passdb and userdb queries (e.g. MySQL and PAM).
8123They're automatically created and destroyed as needed.
8124Defaults to @samp{30}.
8125@end deftypevr
8126
8127@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
8128Host name to use in GSSAPI principal names. The default is to use
8129the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
8130allow all keytab entries.
8131Defaults to @samp{""}.
8132@end deftypevr
8133
8134@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
8135Kerberos keytab to use for the GSSAPI mechanism. Will use the
8136system default (usually /etc/krb5.keytab) if not specified. You may
8137need to change the auth service to run as root to be able to read this
8138file.
8139Defaults to @samp{""}.
8140@end deftypevr
8141
8142@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
8143Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
8144and @samp{ntlm-auth} helper.
8145<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
8146Defaults to @samp{#f}.
8147@end deftypevr
8148
8149@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
8150Path for Samba's @samp{ntlm-auth} helper binary.
8151Defaults to @samp{"/usr/bin/ntlm_auth"}.
8152@end deftypevr
8153
8154@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
8155Time to delay before replying to failed authentications.
8156Defaults to @samp{"2 secs"}.
8157@end deftypevr
8158
8159@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
8160Require a valid SSL client certificate or the authentication
8161fails.
8162Defaults to @samp{#f}.
8163@end deftypevr
8164
8165@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
8166Take the username from client's SSL certificate, using
8167@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
8168CommonName.
8169Defaults to @samp{#f}.
8170@end deftypevr
8171
8172@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
8173List of wanted authentication mechanisms. Supported mechanisms are:
8174@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
8175@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
8176@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
8177@samp{disable-plaintext-auth} setting.
8178@end deftypevr
8179
8180@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
8181List of IPs or hostnames to all director servers, including ourself.
8182Ports can be specified as ip:port. The default port is the same as what
8183director service's @samp{inet-listener} is using.
8184Defaults to @samp{()}.
8185@end deftypevr
8186
8187@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
8188List of IPs or hostnames to all backend mail servers. Ranges are
8189allowed too, like 10.0.0.10-10.0.0.30.
8190Defaults to @samp{()}.
8191@end deftypevr
8192
8193@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
8194How long to redirect users to a specific server after it no longer
8195has any connections.
8196Defaults to @samp{"15 min"}.
8197@end deftypevr
8198
8199@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
8200TCP/IP port that accepts doveadm connections (instead of director
8201connections) If you enable this, you'll also need to add
8202@samp{inet-listener} for the port.
8203Defaults to @samp{0}.
8204@end deftypevr
8205
8206@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
8207How the username is translated before being hashed. Useful values
8208include %Ln if user can log in with or without @@domain, %Ld if mailboxes
8209are shared within domain.
8210Defaults to @samp{"%Lu"}.
8211@end deftypevr
8212
8213@deftypevr {@code{dovecot-configuration} parameter} string log-path
8214Log file to use for error messages. @samp{syslog} logs to syslog,
8215@samp{/dev/stderr} logs to stderr.
8216Defaults to @samp{"syslog"}.
8217@end deftypevr
8218
8219@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
8220Log file to use for informational messages. Defaults to
8221@samp{log-path}.
8222Defaults to @samp{""}.
8223@end deftypevr
8224
8225@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
8226Log file to use for debug messages. Defaults to
8227@samp{info-log-path}.
8228Defaults to @samp{""}.
8229@end deftypevr
8230
8231@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
8232Syslog facility to use if you're logging to syslog. Usually if you
8233don't want to use @samp{mail}, you'll use local0..local7. Also other
8234standard facilities are supported.
8235Defaults to @samp{"mail"}.
8236@end deftypevr
8237
8238@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
8239Log unsuccessful authentication attempts and the reasons why they
8240failed.
8241Defaults to @samp{#f}.
8242@end deftypevr
8243
8244@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
8245In case of password mismatches, log the attempted password. Valid
8246values are no, plain and sha1. sha1 can be useful for detecting brute
8247force password attempts vs. user simply trying the same password over
8248and over again. You can also truncate the value to n chars by appending
8249":n" (e.g. sha1:6).
8250Defaults to @samp{#f}.
8251@end deftypevr
8252
8253@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
8254Even more verbose logging for debugging purposes. Shows for example
8255SQL queries.
8256Defaults to @samp{#f}.
8257@end deftypevr
8258
8259@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
8260In case of password mismatches, log the passwords and used scheme so
8261the problem can be debugged. Enabling this also enables
8262@samp{auth-debug}.
8263Defaults to @samp{#f}.
8264@end deftypevr
8265
8266@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
8267Enable mail process debugging. This can help you figure out why
8268Dovecot isn't finding your mails.
8269Defaults to @samp{#f}.
8270@end deftypevr
8271
8272@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
8273Show protocol level SSL errors.
8274Defaults to @samp{#f}.
8275@end deftypevr
8276
8277@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
8278Prefix for each line written to log file. % codes are in
8279strftime(3) format.
8280Defaults to @samp{"\"%b %d %H:%M:%S \""}.
8281@end deftypevr
8282
8283@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
8284List of elements we want to log. The elements which have a
8285non-empty variable value are joined together to form a comma-separated
8286string.
8287@end deftypevr
8288
8289@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
8290Login log format. %s contains @samp{login-log-format-elements}
8291string, %$ contains the data we want to log.
8292Defaults to @samp{"%$: %s"}.
8293@end deftypevr
8294
8295@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
8296Log prefix for mail processes. See doc/wiki/Variables.txt for list
8297of possible variables you can use.
8298Defaults to @samp{"\"%s(%u): \""}.
8299@end deftypevr
8300
8301@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
8302Format to use for logging mail deliveries. You can use variables:
8303@table @code
8304@item %$
8305Delivery status message (e.g. @samp{saved to INBOX})
8306@item %m
8307Message-ID
8308@item %s
8309Subject
8310@item %f
8311From address
8312@item %p
8313Physical size
8314@item %w
8315Virtual size.
8316@end table
8317Defaults to @samp{"msgid=%m: %$"}.
8318@end deftypevr
8319
8320@deftypevr {@code{dovecot-configuration} parameter} string mail-location
8321Location for users' mailboxes. The default is empty, which means
8322that Dovecot tries to find the mailboxes automatically. This won't work
8323if the user doesn't yet have any mail, so you should explicitly tell
8324Dovecot the full location.
8325
8326If you're using mbox, giving a path to the INBOX
8327file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
8328where the other mailboxes are kept. This is called the "root mail
8329directory", and it must be the first path given in the
8330@samp{mail-location} setting.
8331
8332There are a few special variables you can use, eg.:
8333
8334@table @samp
8335@item %u
8336username
8337@item %n
8338user part in user@@domain, same as %u if there's no domain
8339@item %d
8340domain part in user@@domain, empty if there's no domain
8341@item %h
8342home director
8343@end table
8344
8345See doc/wiki/Variables.txt for full list. Some examples:
8346@table @samp
8347@item maildir:~/Maildir
8348@item mbox:~/mail:INBOX=/var/mail/%u
8349@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
8350@end table
8351Defaults to @samp{""}.
8352@end deftypevr
8353
8354@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
8355System user and group used to access mails. If you use multiple,
8356userdb can override these by returning uid or gid fields. You can use
8357either numbers or names. <doc/wiki/UserIds.txt>.
8358Defaults to @samp{""}.
8359@end deftypevr
8360
8361@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
8362
8363Defaults to @samp{""}.
8364@end deftypevr
8365
8366@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
8367Group to enable temporarily for privileged operations. Currently
8368this is used only with INBOX when either its initial creation or
8369dotlocking fails. Typically this is set to "mail" to give access to
8370/var/mail.
8371Defaults to @samp{""}.
8372@end deftypevr
8373
8374@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
8375Grant access to these supplementary groups for mail processes.
8376Typically these are used to set up access to shared mailboxes. Note
8377that it may be dangerous to set these if users can create
8378symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
8379could allow a user to delete others' mailboxes, or ln -s
8380/secret/shared/box ~/mail/mybox would allow reading it).
8381Defaults to @samp{""}.
8382@end deftypevr
8383
8384@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8385Allow full filesystem access to clients. There's no access checks
8386other than what the operating system does for the active UID/GID. It
8387works with both maildir and mboxes, allowing you to prefix mailboxes
8388names with e.g. /path/ or ~user/.
8389Defaults to @samp{#f}.
8390@end deftypevr
8391
8392@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
8393Don't use mmap() at all. This is required if you store indexes to
8394shared filesystems (NFS or clustered filesystem).
8395Defaults to @samp{#f}.
8396@end deftypevr
8397
8398@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
8399Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
8400supports @samp{O_EXCL} since version 3, so this should be safe to use
8401nowadays by default.
8402Defaults to @samp{#t}.
8403@end deftypevr
8404
8405@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
8406When to use fsync() or fdatasync() calls:
8407@table @code
8408@item optimized
8409Whenever necessary to avoid losing important data
8410@item always
8411Useful with e.g. NFS when write()s are delayed
8412@item never
8413Never use it (best performance, but crashes can lose data).
8414@end table
8415Defaults to @samp{"optimized"}.
8416@end deftypevr
8417
8418@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
8419Mail storage exists in NFS. Set this to yes to make Dovecot flush
8420NFS caches whenever needed. If you're using only a single mail server
8421this isn't needed.
8422Defaults to @samp{#f}.
8423@end deftypevr
8424
8425@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
8426Mail index files also exist in NFS. Setting this to yes requires
8427@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
8428Defaults to @samp{#f}.
8429@end deftypevr
8430
8431@deftypevr {@code{dovecot-configuration} parameter} string lock-method
8432Locking method for index files. Alternatives are fcntl, flock and
8433dotlock. Dotlocking uses some tricks which may create more disk I/O
8434than other locking methods. NFS users: flock doesn't work, remember to
8435change @samp{mmap-disable}.
8436Defaults to @samp{"fcntl"}.
8437@end deftypevr
8438
8439@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
8440Directory in which LDA/LMTP temporarily stores incoming mails >128
8441kB.
8442Defaults to @samp{"/tmp"}.
8443@end deftypevr
8444
8445@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
8446Valid UID range for users. This is mostly to make sure that users can't
8447log in as daemons or other system users. Note that denying root logins is
8448hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
8449is set to 0.
8450Defaults to @samp{500}.
8451@end deftypevr
8452
8453@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
8454
8455Defaults to @samp{0}.
8456@end deftypevr
8457
8458@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
8459Valid GID range for users. Users having non-valid GID as primary group ID
8460aren't allowed to log in. If user belongs to supplementary groups with
8461non-valid GIDs, those groups are not set.
8462Defaults to @samp{1}.
8463@end deftypevr
8464
8465@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
8466
8467Defaults to @samp{0}.
8468@end deftypevr
8469
8470@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
8471Maximum allowed length for mail keyword name. It's only forced when
8472trying to create new keywords.
8473Defaults to @samp{50}.
8474@end deftypevr
8475
8476@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
8477List of directories under which chrooting is allowed for mail
8478processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
8479too). This setting doesn't affect @samp{login-chroot}
8480@samp{mail-chroot} or auth chroot settings. If this setting is empty,
8481"/./" in home dirs are ignored. WARNING: Never add directories here
8482which local users can modify, that may lead to root exploit. Usually
8483this should be done only if you don't allow shell access for users.
8484<doc/wiki/Chrooting.txt>.
8485Defaults to @samp{()}.
8486@end deftypevr
8487
8488@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
8489Default chroot directory for mail processes. This can be overridden
8490for specific users in user database by giving /./ in user's home
8491directory (e.g. /home/./user chroots into /home). Note that usually
8492there is no real need to do chrooting, Dovecot doesn't allow users to
8493access files outside their mail directory anyway. If your home
8494directories are prefixed with the chroot directory, append "/." to
8495@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
8496Defaults to @samp{""}.
8497@end deftypevr
8498
8499@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
8500UNIX socket path to master authentication server to find users.
8501This is used by imap (for shared users) and lda.
8502Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
8503@end deftypevr
8504
8505@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
8506Directory where to look up mail plugins.
8507Defaults to @samp{"/usr/lib/dovecot"}.
8508@end deftypevr
8509
8510@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
8511List of plugins to load for all services. Plugins specific to IMAP,
8512LDA, etc. are added to this list in their own .conf files.
8513Defaults to @samp{()}.
8514@end deftypevr
8515
8516@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
8517The minimum number of mails in a mailbox before updates are done to
8518cache file. This allows optimizing Dovecot's behavior to do less disk
8519writes at the cost of more disk reads.
8520Defaults to @samp{0}.
8521@end deftypevr
8522
8523@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
8524When IDLE command is running, mailbox is checked once in a while to
8525see if there are any new mails or other changes. This setting defines
8526the minimum time to wait between those checks. Dovecot can also use
8527dnotify, inotify and kqueue to find out immediately when changes
8528occur.
8529Defaults to @samp{"30 secs"}.
8530@end deftypevr
8531
8532@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
8533Save mails with CR+LF instead of plain LF. This makes sending those
8534mails take less CPU, especially with sendfile() syscall with Linux and
8535FreeBSD. But it also creates a bit more disk I/O which may just make it
8536slower. Also note that if other software reads the mboxes/maildirs,
8537they may handle the extra CRs wrong and cause problems.
8538Defaults to @samp{#f}.
8539@end deftypevr
8540
8541@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
8542By default LIST command returns all entries in maildir beginning
8543with a dot. Enabling this option makes Dovecot return only entries
8544which are directories. This is done by stat()ing each entry, so it
8545causes more disk I/O.
8546 (For systems setting struct @samp{dirent->d_type} this check is free
8547and it's done always regardless of this setting).
8548Defaults to @samp{#f}.
8549@end deftypevr
8550
8551@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
8552When copying a message, do it with hard links whenever possible.
8553This makes the performance much better, and it's unlikely to have any
8554side effects.
8555Defaults to @samp{#t}.
8556@end deftypevr
8557
8558@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
8559Assume Dovecot is the only MUA accessing Maildir: Scan cur/
8560directory only when its mtime changes unexpectedly or when we can't find
8561the mail otherwise.
8562Defaults to @samp{#f}.
8563@end deftypevr
8564
8565@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
8566Which locking methods to use for locking mbox. There are four
8567available:
8568
8569@table @code
8570@item dotlock
8571Create <mailbox>.lock file. This is the oldest and most NFS-safe
8572solution. If you want to use /var/mail/ like directory, the users will
8573need write access to that directory.
8574@item dotlock-try
8575Same as dotlock, but if it fails because of permissions or because there
8576isn't enough disk space, just skip it.
8577@item fcntl
8578Use this if possible. Works with NFS too if lockd is used.
8579@item flock
8580May not exist in all systems. Doesn't work with NFS.
8581@item lockf
8582May not exist in all systems. Doesn't work with NFS.
8583@end table
8584
8585You can use multiple locking methods; if you do the order they're declared
8586in is important to avoid deadlocks if other MTAs/MUAs are using multiple
8587locking methods as well. Some operating systems don't allow using some of
8588them simultaneously.
8589@end deftypevr
8590
8591@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
8592
8593@end deftypevr
8594
8595@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
8596Maximum time to wait for lock (all of them) before aborting.
8597Defaults to @samp{"5 mins"}.
8598@end deftypevr
8599
8600@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
8601If dotlock exists but the mailbox isn't modified in any way,
8602override the lock file after this much time.
8603Defaults to @samp{"2 mins"}.
8604@end deftypevr
8605
8606@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
8607When mbox changes unexpectedly we have to fully read it to find out
8608what changed. If the mbox is large this can take a long time. Since
8609the change is usually just a newly appended mail, it'd be faster to
8610simply read the new mails. If this setting is enabled, Dovecot does
8611this but still safely fallbacks to re-reading the whole mbox file
8612whenever something in mbox isn't how it's expected to be. The only real
8613downside to this setting is that if some other MUA changes message
8614flags, Dovecot doesn't notice it immediately. Note that a full sync is
8615done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
8616Defaults to @samp{#t}.
8617@end deftypevr
8618
8619@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
8620Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
8621EXAMINE, EXPUNGE or CHECK commands. If this is set,
8622@samp{mbox-dirty-syncs} is ignored.
8623Defaults to @samp{#f}.
8624@end deftypevr
8625
8626@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
8627Delay writing mbox headers until doing a full write sync (EXPUNGE
8628and CHECK commands and when closing the mailbox). This is especially
8629useful for POP3 where clients often delete all mails. The downside is
8630that our changes aren't immediately visible to other MUAs.
8631Defaults to @samp{#t}.
8632@end deftypevr
8633
8634@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
8635If mbox size is smaller than this (e.g. 100k), don't write index
8636files. If an index file already exists it's still read, just not
8637updated.
8638Defaults to @samp{0}.
8639@end deftypevr
8640
8641@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
8642Maximum dbox file size until it's rotated.
8643Defaults to @samp{2000000}.
8644@end deftypevr
8645
8646@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
8647Maximum dbox file age until it's rotated. Typically in days. Day
8648begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
8649disabled.
8650Defaults to @samp{"1d"}.
8651@end deftypevr
8652
8653@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
8654When creating new mdbox files, immediately preallocate their size to
8655@samp{mdbox-rotate-size}. This setting currently works only in Linux
8656with some filesystems (ext4, xfs).
8657Defaults to @samp{#f}.
8658@end deftypevr
8659
8660@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
8661sdbox and mdbox support saving mail attachments to external files,
8662which also allows single instance storage for them. Other backends
8663don't support this for now.
8664
8665WARNING: This feature hasn't been tested much yet. Use at your own risk.
8666
8667Directory root where to store mail attachments. Disabled, if empty.
8668Defaults to @samp{""}.
8669@end deftypevr
8670
8671@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
8672Attachments smaller than this aren't saved externally. It's also
8673possible to write a plugin to disable saving specific attachments
8674externally.
8675Defaults to @samp{128000}.
8676@end deftypevr
8677
8678@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8679Filesystem backend to use for saving attachments:
8680@table @code
8681@item posix
8682No SiS done by Dovecot (but this might help FS's own deduplication)
8683@item sis posix
8684SiS with immediate byte-by-byte comparison during saving
8685@item sis-queue posix
8686SiS with delayed comparison and deduplication.
8687@end table
8688Defaults to @samp{"sis posix"}.
8689@end deftypevr
8690
8691@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
8692Hash format to use in attachment filenames. You can add any text and
8693variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
8694@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
8695truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
8696Defaults to @samp{"%@{sha1@}"}.
8697@end deftypevr
8698
8699@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
8700
8701Defaults to @samp{100}.
8702@end deftypevr
8703
8704@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
8705
8706Defaults to @samp{1000}.
8707@end deftypevr
8708
8709@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
8710Default VSZ (virtual memory size) limit for service processes.
8711This is mainly intended to catch and kill processes that leak memory
8712before they eat up everything.
8713Defaults to @samp{256000000}.
8714@end deftypevr
8715
8716@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
8717Login user is internally used by login processes. This is the most
8718untrusted user in Dovecot system. It shouldn't have access to anything
8719at all.
8720Defaults to @samp{"dovenull"}.
8721@end deftypevr
8722
8723@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
8724Internal user is used by unprivileged processes. It should be
8725separate from login user, so that login processes can't disturb other
8726processes.
8727Defaults to @samp{"dovecot"}.
8728@end deftypevr
8729
8730@deftypevr {@code{dovecot-configuration} parameter} string ssl?
8731SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
8732Defaults to @samp{"required"}.
8733@end deftypevr
8734
8735@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
8736PEM encoded X.509 SSL/TLS certificate (public key).
8737Defaults to @samp{"</etc/dovecot/default.pem"}.
8738@end deftypevr
8739
8740@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
8741PEM encoded SSL/TLS private key. The key is opened before
8742dropping root privileges, so keep the key file unreadable by anyone but
8743root.
8744Defaults to @samp{"</etc/dovecot/private/default.pem"}.
8745@end deftypevr
8746
8747@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
8748If key file is password protected, give the password here.
8749Alternatively give it when starting dovecot with -p parameter. Since
8750this file is often world-readable, you may want to place this setting
8751instead to a different.
8752Defaults to @samp{""}.
8753@end deftypevr
8754
8755@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
8756PEM encoded trusted certificate authority. Set this only if you
8757intend to use @samp{ssl-verify-client-cert? #t}. The file should
8758contain the CA certificate(s) followed by the matching
8759CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
8760Defaults to @samp{""}.
8761@end deftypevr
8762
8763@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
8764Require that CRL check succeeds for client certificates.
8765Defaults to @samp{#t}.
8766@end deftypevr
8767
8768@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
8769Request client to send a certificate. If you also want to require
8770it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
8771Defaults to @samp{#f}.
8772@end deftypevr
8773
8774@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
8775Which field from certificate to use for username. commonName and
8776x500UniqueIdentifier are the usual choices. You'll also need to set
8777@samp{auth-ssl-username-from-cert? #t}.
8778Defaults to @samp{"commonName"}.
8779@end deftypevr
8780
8781@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
8782How often to regenerate the SSL parameters file. Generation is
8783quite CPU intensive operation. The value is in hours, 0 disables
8784regeneration entirely.
8785Defaults to @samp{168}.
8786@end deftypevr
8787
8788@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
8789SSL protocols to use.
8790Defaults to @samp{"!SSLv2"}.
8791@end deftypevr
8792
8793@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
8794SSL ciphers to use.
8795Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
8796@end deftypevr
8797
8798@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
8799SSL crypto device to use, for valid values run "openssl engine".
8800Defaults to @samp{""}.
8801@end deftypevr
8802
8803@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
8804Address to use when sending rejection mails.
8805Default is postmaster@@<your domain>. %d expands to recipient domain.
8806Defaults to @samp{""}.
8807@end deftypevr
8808
8809@deftypevr {@code{dovecot-configuration} parameter} string hostname
8810Hostname to use in various parts of sent mails (e.g. in Message-Id)
8811and in LMTP replies. Default is the system's real hostname@@domain.
8812Defaults to @samp{""}.
8813@end deftypevr
8814
8815@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
8816If user is over quota, return with temporary failure instead of
8817bouncing the mail.
8818Defaults to @samp{#f}.
8819@end deftypevr
8820
8821@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
8822Binary to use for sending mails.
8823Defaults to @samp{"/usr/sbin/sendmail"}.
8824@end deftypevr
8825
8826@deftypevr {@code{dovecot-configuration} parameter} string submission-host
8827If non-empty, send mails via this SMTP host[:port] instead of
8828sendmail.
8829Defaults to @samp{""}.
8830@end deftypevr
8831
8832@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
8833Subject: header to use for rejection mails. You can use the same
8834variables as for @samp{rejection-reason} below.
8835Defaults to @samp{"Rejected: %s"}.
8836@end deftypevr
8837
8838@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
8839Human readable error message for rejection mails. You can use
8840variables:
8841
8842@table @code
8843@item %n
8844CRLF
8845@item %r
8846reason
8847@item %s
8848original subject
8849@item %t
8850recipient
8851@end table
8852Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
8853@end deftypevr
8854
8855@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
8856Delimiter character between local-part and detail in email
8857address.
8858Defaults to @samp{"+"}.
8859@end deftypevr
8860
8861@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
8862Header where the original recipient address (SMTP's RCPT TO:
8863address) is taken from if not available elsewhere. With dovecot-lda -a
8864parameter overrides this. A commonly used header for this is
8865X-Original-To.
8866Defaults to @samp{""}.
8867@end deftypevr
8868
8869@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
8870Should saving a mail to a nonexistent mailbox automatically create
8871it?.
8872Defaults to @samp{#f}.
8873@end deftypevr
8874
8875@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
8876Should automatically created mailboxes be also automatically
8877subscribed?.
8878Defaults to @samp{#f}.
8879@end deftypevr
8880
8881@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
8882Maximum IMAP command line length. Some clients generate very long
8883command lines with huge mailboxes, so you may need to raise this if you
8884get "Too long argument" or "IMAP command line too large" errors
8885often.
8886Defaults to @samp{64000}.
8887@end deftypevr
8888
8889@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
8890IMAP logout format string:
8891@table @code
8892@item %i
8893total number of bytes read from client
8894@item %o
8895total number of bytes sent to client.
8896@end table
8897Defaults to @samp{"in=%i out=%o"}.
8898@end deftypevr
8899
8900@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
8901Override the IMAP CAPABILITY response. If the value begins with '+',
8902add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
8903Defaults to @samp{""}.
8904@end deftypevr
8905
8906@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
8907How long to wait between "OK Still here" notifications when client
8908is IDLEing.
8909Defaults to @samp{"2 mins"}.
8910@end deftypevr
8911
8912@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
8913ID field names and values to send to clients. Using * as the value
8914makes Dovecot use the default value. The following fields have default
8915values currently: name, version, os, os-version, support-url,
8916support-email.
8917Defaults to @samp{""}.
8918@end deftypevr
8919
8920@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
8921ID fields sent by client to log. * means everything.
8922Defaults to @samp{""}.
8923@end deftypevr
8924
8925@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
8926Workarounds for various client bugs:
8927
8928@table @code
8929@item delay-newmail
8930Send EXISTS/RECENT new mail notifications only when replying to NOOP and
8931CHECK commands. Some clients ignore them otherwise, for example OSX
8932Mail (<v2.1). Outlook Express breaks more badly though, without this it
8933may show user "Message no longer in server" errors. Note that OE6
8934still breaks even with this workaround if synchronization is set to
8935"Headers Only".
8936
8937@item tb-extra-mailbox-sep
8938Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
8939adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
8940ignore the extra @samp{/} instead of treating it as invalid mailbox name.
8941
8942@item tb-lsub-flags
8943Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
8944This makes Thunderbird realize they aren't selectable and show them
8945greyed out, instead of only later giving "not selectable" popup error.
8946@end table
8947Defaults to @samp{()}.
8948@end deftypevr
8949
8950@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
8951Host allowed in URLAUTH URLs sent by client. "*" allows all.
8952Defaults to @samp{""}.
8953@end deftypevr
8954
8955
8956Whew! Lots of configuration options. The nice thing about it though is
8957that GuixSD has a complete interface to Dovecot's configuration
8958language. This allows not only a nice way to declare configurations,
8959but also offers reflective capabilities as well: users can write code to
8960inspect and transform configurations from within Scheme.
8961
8962However, it could be that you just want to get a @code{dovecot.conf} up
8963and running. In that case, you can pass an
8964@code{opaque-dovecot-configuration} as the @code{#:config} paramter to
8965@code{dovecot-service}. As its name indicates, an opaque configuration
8966does not have easy reflective capabilities.
8967
8968Available @code{opaque-dovecot-configuration} fields are:
8969
8970@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
8971The dovecot package.
8972@end deftypevr
8973
8974@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
8975The contents of the @code{dovecot.conf}, as a string.
8976@end deftypevr
8977
8978For example, if your @code{dovecot.conf} is just the empty string, you
8979could instantiate a dovecot service like this:
8980
8981@example
8982(dovecot-service #:config
8983 (opaque-dovecot-configuration
8984 (string "")))
8985@end example
8986
58724c48
DT
8987@node Web Services
8988@subsubsection Web Services
8989
8990The @code{(gnu services web)} module provides the following service:
8991
be1c2c54 8992@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
8993 [#:log-directory ``/var/log/nginx''] @
8994 [#:run-directory ``/var/run/nginx''] @
8995 [#:config-file]
8996
8997Return a service that runs @var{nginx}, the nginx web server.
8998
8999The nginx daemon loads its runtime configuration from @var{config-file}.
9000Log files are written to @var{log-directory} and temporary runtime data
9001files are written to @var{run-directory}. For proper operation, these
9002arguments should match what is in @var{config-file} to ensure that the
9003directories are created when the service is activated.
9004
9005@end deffn
9006
fe1a39d3
LC
9007@node Various Services
9008@subsubsection Various Services
9009
9010The @code{(gnu services lirc)} module provides the following service.
9011
be1c2c54 9012@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
9013 [#:device #f] [#:driver #f] [#:config-file #f] @
9014 [#:extra-options '()]
9015Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
9016decodes infrared signals from remote controls.
9017
9018Optionally, @var{device}, @var{driver} and @var{config-file}
9019(configuration file name) may be specified. See @command{lircd} manual
9020for details.
9021
9022Finally, @var{extra-options} is a list of additional command-line options
9023passed to @command{lircd}.
9024@end deffn
9025
9026
0ae8c15a
LC
9027@node Setuid Programs
9028@subsection Setuid Programs
9029
9030@cindex setuid programs
9031Some programs need to run with ``root'' privileges, even when they are
9032launched by unprivileged users. A notorious example is the
4d40227c
LC
9033@command{passwd} program, which users can run to change their
9034password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
9035@file{/etc/shadow} files---something normally restricted to root, for
9036obvious security reasons. To address that, these executables are
9037@dfn{setuid-root}, meaning that they always run with root privileges
9038(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 9039for more info about the setuid mechanism.)
0ae8c15a
LC
9040
9041The store itself @emph{cannot} contain setuid programs: that would be a
9042security issue since any user on the system can write derivations that
9043populate the store (@pxref{The Store}). Thus, a different mechanism is
9044used: instead of changing the setuid bit directly on files that are in
9045the store, we let the system administrator @emph{declare} which programs
9046should be setuid root.
9047
9048The @code{setuid-programs} field of an @code{operating-system}
9049declaration contains a list of G-expressions denoting the names of
9050programs to be setuid-root (@pxref{Using the Configuration System}).
9051For instance, the @command{passwd} program, which is part of the Shadow
9052package, can be designated by this G-expression (@pxref{G-Expressions}):
9053
9054@example
9055#~(string-append #$shadow "/bin/passwd")
9056@end example
9057
9058A default set of setuid programs is defined by the
9059@code{%setuid-programs} variable of the @code{(gnu system)} module.
9060
9061@defvr {Scheme Variable} %setuid-programs
9062A list of G-expressions denoting common programs that are setuid-root.
9063
9064The list includes commands such as @command{passwd}, @command{ping},
9065@command{su}, and @command{sudo}.
9066@end defvr
9067
9068Under the hood, the actual setuid programs are created in the
9069@file{/run/setuid-programs} directory at system activation time. The
9070files in this directory refer to the ``real'' binaries, which are in the
9071store.
9072
efb5e833
LC
9073@node X.509 Certificates
9074@subsection X.509 Certificates
9075
9076@cindex HTTPS, certificates
9077@cindex X.509 certificates
9078@cindex TLS
9079Web servers available over HTTPS (that is, HTTP over the transport-layer
9080security mechanism, TLS) send client programs an @dfn{X.509 certificate}
9081that the client can then use to @emph{authenticate} the server. To do
9082that, clients verify that the server's certificate is signed by a
9083so-called @dfn{certificate authority} (CA). But to verify the CA's
9084signature, clients must have first acquired the CA's certificate.
9085
9086Web browsers such as GNU@tie{}IceCat include their own set of CA
9087certificates, such that they are able to verify CA signatures
9088out-of-the-box.
9089
9090However, most other programs that can talk HTTPS---@command{wget},
9091@command{git}, @command{w3m}, etc.---need to be told where CA
9092certificates can be found.
9093
9094@cindex @code{nss-certs}
9095In GuixSD, this is done by adding a package that provides certificates
9096to the @code{packages} field of the @code{operating-system} declaration
9097(@pxref{operating-system Reference}). GuixSD includes one such package,
9098@code{nss-certs}, which is a set of CA certificates provided as part of
9099Mozilla's Network Security Services.
9100
9101Note that it is @emph{not} part of @var{%base-packages}, so you need to
9102explicitly add it. The @file{/etc/ssl/certs} directory, which is where
9103most applications and libraries look for certificates by default, points
9104to the certificates installed globally.
9105
9106Unprivileged users can also install their own certificate package in
9107their profile. A number of environment variables need to be defined so
9108that applications and libraries know where to find them. Namely, the
9109OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
9110variables. Some applications add their own environment variables; for
9111instance, the Git version control system honors the certificate bundle
9112pointed to by the @code{GIT_SSL_CAINFO} environment variable.
9113
9114
996ed739
LC
9115@node Name Service Switch
9116@subsection Name Service Switch
9117
9118@cindex name service switch
9119@cindex NSS
9120The @code{(gnu system nss)} module provides bindings to the
1068f26b 9121configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
9122(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
9123Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
9124extended with new ``name'' lookup methods for system databases, which
9125includes host names, service names, user accounts, and more (@pxref{Name
9126Service Switch, System Databases and Name Service Switch,, libc, The GNU
9127C Library Reference Manual}).
9128
9129The NSS configuration specifies, for each system database, which lookup
9130method is to be used, and how the various methods are chained
9131together---for instance, under which circumstances NSS should try the
9132next method in the list. The NSS configuration is given in the
9133@code{name-service-switch} field of @code{operating-system} declarations
9134(@pxref{operating-system Reference, @code{name-service-switch}}).
9135
4c9050c6
LC
9136@cindex nss-mdns
9137@cindex .local, host name lookup
996ed739 9138As an example, the declaration below configures the NSS to use the
4c9050c6
LC
9139@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
9140back-end}, which supports host name lookups over multicast DNS (mDNS)
9141for host names ending in @code{.local}:
996ed739
LC
9142
9143@example
9144(name-service-switch
9145 (hosts (list %files ;first, check /etc/hosts
9146
9147 ;; If the above did not succeed, try
9148 ;; with 'mdns_minimal'.
9149 (name-service
9150 (name "mdns_minimal")
9151
9152 ;; 'mdns_minimal' is authoritative for
9153 ;; '.local'. When it returns "not found",
9154 ;; no need to try the next methods.
9155 (reaction (lookup-specification
9156 (not-found => return))))
9157
9158 ;; Then fall back to DNS.
9159 (name-service
9160 (name "dns"))
9161
9162 ;; Finally, try with the "full" 'mdns'.
9163 (name-service
9164 (name "mdns")))))
9165@end example
9166
1068f26b
AE
9167Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
9168contains this configuration, so you will not have to type it if all you
15137a29
LC
9169want is to have @code{.local} host lookup working.
9170
4c9050c6
LC
9171Note that, in this case, in addition to setting the
9172@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
9173you also need to use @code{avahi-service} (@pxref{Networking Services,
9174@code{avahi-service}}), or @var{%desktop-services}, which includes it
9175(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
9176to the name service cache daemon (@pxref{Base Services,
9177@code{nscd-service}}).
15137a29
LC
9178
9179For convenience, the following variables provide typical NSS
9180configurations.
9181
9182@defvr {Scheme Variable} %default-nss
9183This is the default name service switch configuration, a
9184@code{name-service-switch} object.
9185@end defvr
9186
9187@defvr {Scheme Variable} %mdns-host-lookup-nss
9188This is the name service switch configuration with support for host name
9189lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
9190@end defvr
4c9050c6 9191
996ed739 9192The reference for name service switch configuration is given below. It
1068f26b 9193is a direct mapping of the configuration file format of the C library , so
996ed739
LC
9194please refer to the C library manual for more information (@pxref{NSS
9195Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 9196Compared to the configuration file format of libc NSS, it has the advantage
996ed739 9197not only of adding this warm parenthetic feel that we like, but also
1068f26b 9198static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
9199run @command{guix system}.
9200
996ed739
LC
9201@deftp {Data Type} name-service-switch
9202
9203This is the data type representation the configuration of libc's name
9204service switch (NSS). Each field below represents one of the supported
9205system databases.
9206
9207@table @code
9208@item aliases
9209@itemx ethers
9210@itemx group
9211@itemx gshadow
9212@itemx hosts
9213@itemx initgroups
9214@itemx netgroup
9215@itemx networks
9216@itemx password
9217@itemx public-key
9218@itemx rpc
9219@itemx services
9220@itemx shadow
9221The system databases handled by the NSS. Each of these fields must be a
1068f26b 9222list of @code{<name-service>} objects (see below).
996ed739
LC
9223@end table
9224@end deftp
9225
9226@deftp {Data Type} name-service
9227
9228This is the data type representing an actual name service and the
9229associated lookup action.
9230
9231@table @code
9232@item name
9233A string denoting the name service (@pxref{Services in the NSS
9234configuration,,, libc, The GNU C Library Reference Manual}).
9235
4aee6e60
LC
9236Note that name services listed here must be visible to nscd. This is
9237achieved by passing the @code{#:name-services} argument to
9238@code{nscd-service} the list of packages providing the needed name
9239services (@pxref{Base Services, @code{nscd-service}}).
9240
996ed739
LC
9241@item reaction
9242An action specified using the @code{lookup-specification} macro
9243(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
9244Reference Manual}). For example:
9245
9246@example
9247(lookup-specification (unavailable => continue)
9248 (success => return))
9249@end example
9250@end table
9251@end deftp
0ae8c15a 9252
fd1b1fa2
LC
9253@node Initial RAM Disk
9254@subsection Initial RAM Disk
9255
9256@cindex initial RAM disk (initrd)
9257@cindex initrd (initial RAM disk)
9258For bootstrapping purposes, the Linux-Libre kernel is passed an
9259@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 9260root file system as well as an initialization script. The latter is
fd1b1fa2
LC
9261responsible for mounting the real root file system, and for loading any
9262kernel modules that may be needed to achieve that.
9263
9264The @code{initrd} field of an @code{operating-system} declaration allows
9265you to specify which initrd you would like to use. The @code{(gnu
9266system linux-initrd)} module provides two ways to build an initrd: the
9267high-level @code{base-initrd} procedure, and the low-level
9268@code{expression->initrd} procedure.
9269
9270The @code{base-initrd} procedure is intended to cover most common uses.
9271For example, if you want to add a bunch of kernel modules to be loaded
9272at boot time, you can define the @code{initrd} field of the operating
9273system declaration like this:
9274
9275@example
52ac153e 9276(initrd (lambda (file-systems . rest)
027981d6
LC
9277 ;; Create a standard initrd that has modules "foo.ko"
9278 ;; and "bar.ko", as well as their dependencies, in
9279 ;; addition to the modules available by default.
52ac153e 9280 (apply base-initrd file-systems
027981d6 9281 #:extra-modules '("foo" "bar")
52ac153e 9282 rest)))
fd1b1fa2
LC
9283@end example
9284
52ac153e 9285The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
9286involves using the system as a QEMU guest, or as a ``live'' system with
9287volatile root file system.
fd1b1fa2 9288
e90cf6c1
LC
9289The initial RAM disk produced by @code{base-initrd} honors several
9290options passed on the Linux kernel command line (that is, arguments
1068f26b
AE
9291passed @i{via} the @code{linux} command of GRUB, or the
9292@code{-append} option) of QEMU, notably:
e90cf6c1
LC
9293
9294@table @code
9295@item --load=@var{boot}
9296Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
9297program, once it has mounted the root file system.
9298
9299GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 9300service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
9301initialization system.
9302
9303@item --root=@var{root}
1068f26b 9304Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
9305device name like @code{/dev/sda1}, a partition label, or a partition
9306UUID.
9307
9308@item --system=@var{system}
9309Have @file{/run/booted-system} and @file{/run/current-system} point to
9310@var{system}.
9311
9312@item modprobe.blacklist=@var{modules}@dots{}
9313@cindex module, black-listing
9314@cindex black list, of kernel modules
9315Instruct the initial RAM disk as well as the @command{modprobe} command
9316(from the kmod package) to refuse to load @var{modules}. @var{modules}
9317must be a comma-separated list of module names---e.g.,
9318@code{usbkbd,9pnet}.
9319
9320@item --repl
9321Start a read-eval-print loop (REPL) from the initial RAM disk before it
9322tries to load kernel modules and to mount the root file system. Our
9323marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
9324love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
9325Manual}, for more information on Guile's REPL.
9326
9327@end table
9328
9329Now that you know all the features that initial RAM disks produced by
9330@code{base-initrd} provide, here is how to use it and customize it
9331further.
9332
fd1b1fa2 9333@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 9334 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 9335 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2 9336Return a monadic derivation that builds a generic initrd. @var{file-systems} is
1068f26b 9337a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 9338the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
9339@var{mapped-devices} is a list of device mappings to realize before
9340@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
9341
9342When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
9343parameters. When @var{virtio?} is true, load additional modules so that the
9344initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
9345
9346When @var{volatile-root?} is true, the root file system is writable but any changes
9347to it are lost.
9348
9349The initrd is automatically populated with all the kernel modules necessary
9350for @var{file-systems} and for the given options. However, additional kernel
9351modules can be listed in @var{extra-modules}. They will be added to the initrd, and
9352loaded at boot time in the order in which they appear.
9353@end deffn
9354
9355Needless to say, the initrds we produce and use embed a
9356statically-linked Guile, and the initialization program is a Guile
9357program. That gives a lot of flexibility. The
9358@code{expression->initrd} procedure builds such an initrd, given the
9359program to run in that initrd.
9360
9361@deffn {Monadic Procedure} expression->initrd @var{exp} @
9362 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 9363 [#:modules '()]
fd1b1fa2
LC
9364Return a derivation that builds a Linux initrd (a gzipped cpio archive)
9365containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
9366upon booting. All the derivations referenced by @var{exp} are
9367automatically copied to the initrd.
fd1b1fa2 9368
42d10464
LC
9369@var{modules} is a list of Guile module names to be embedded in the
9370initrd.
fd1b1fa2
LC
9371@end deffn
9372
88faf933
LC
9373@node GRUB Configuration
9374@subsection GRUB Configuration
9375
9376@cindex GRUB
9377@cindex boot loader
9378
9379The operating system uses GNU@tie{}GRUB as its boot loader
9380(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
9381configured using a @code{grub-configuration} declaration. This data type
9382is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
9383
9384@deftp {Data Type} grub-configuration
9385The type of a GRUB configuration declaration.
9386
9387@table @asis
9388
9389@item @code{device}
9390This is a string denoting the boot device. It must be a device name
9391understood by the @command{grub-install} command, such as
9392@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
9393GNU GRUB Manual}).
9394
9395@item @code{menu-entries} (default: @code{()})
9396A possibly empty list of @code{menu-entry} objects (see below), denoting
9397entries to appear in the GRUB boot menu, in addition to the current
9398system entry and the entry pointing to previous system generations.
9399
9400@item @code{default-entry} (default: @code{0})
1068f26b
AE
9401The index of the default boot menu entry. Index 0 is for the entry of the
9402current system.
88faf933
LC
9403
9404@item @code{timeout} (default: @code{5})
9405The number of seconds to wait for keyboard input before booting. Set to
94060 to boot immediately, and to -1 to wait indefinitely.
9407
9408@item @code{theme} (default: @var{%default-theme})
9409The @code{grub-theme} object describing the theme to use.
9410@end table
9411
9412@end deftp
9413
9414Should you want to list additional boot menu entries @i{via} the
9415@code{menu-entries} field above, you will need to create them with the
9416@code{menu-entry} form:
9417
9418@deftp {Data Type} menu-entry
9419The type of an entry in the GRUB boot menu.
9420
9421@table @asis
9422
9423@item @code{label}
35ed9306 9424The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
9425
9426@item @code{linux}
9427The Linux kernel to boot.
9428
9429@item @code{linux-arguments} (default: @code{()})
9430The list of extra Linux kernel command-line arguments---e.g.,
9431@code{("console=ttyS0")}.
9432
9433@item @code{initrd}
9434A G-Expression or string denoting the file name of the initial RAM disk
9435to use (@pxref{G-Expressions}).
9436
9437@end table
9438@end deftp
9439
9440@c FIXME: Write documentation once it's stable.
9441Themes are created using the @code{grub-theme} form, which is not
9442documented yet.
9443
9444@defvr {Scheme Variable} %default-theme
9445This is the default GRUB theme used by the operating system, with a
9446fancy background image displaying the GNU and Guix logos.
9447@end defvr
9448
9449
cf4a9129
LC
9450@node Invoking guix system
9451@subsection Invoking @code{guix system}
0918e64a 9452
1068f26b 9453Once you have written an operating system declaration as seen in the
cf4a9129
LC
9454previous section, it can be @dfn{instantiated} using the @command{guix
9455system} command. The synopsis is:
4af2447e 9456
cf4a9129
LC
9457@example
9458guix system @var{options}@dots{} @var{action} @var{file}
9459@end example
4af2447e 9460
cf4a9129
LC
9461@var{file} must be the name of a file containing an
9462@code{operating-system} declaration. @var{action} specifies how the
a40424bd 9463operating system is instantiated. Currently the following values are
cf4a9129 9464supported:
4af2447e 9465
cf4a9129
LC
9466@table @code
9467@item reconfigure
9468Build the operating system described in @var{file}, activate it, and
9469switch to it@footnote{This action is usable only on systems already
65797bff 9470running GuixSD.}.
4af2447e 9471
cf4a9129
LC
9472This effects all the configuration specified in @var{file}: user
9473accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
9474The command starts system services specified in @var{file} that are not
9475currently running; if a service is currently running, it does not
1068f26b 9476attempt to upgrade it since this would not be possible without stopping it
240b57f0 9477first.
4af2447e 9478
cf4a9129
LC
9479It also adds a GRUB menu entry for the new OS configuration, and moves
9480entries for older configurations to a submenu---unless
9481@option{--no-grub} is passed.
4af2447e 9482
240b57f0 9483@quotation Note
bf2479c7
LC
9484@c The paragraph below refers to the problem discussed at
9485@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
9486It is highly recommended to run @command{guix pull} once before you run
9487@command{guix system reconfigure} for the first time (@pxref{Invoking
9488guix pull}). Failing to do that you would see an older version of Guix
9489once @command{reconfigure} has completed.
240b57f0 9490@end quotation
bf2479c7 9491
cf4a9129 9492@item build
1068f26b 9493Build the derivation of the operating system, which includes all the
cf4a9129
LC
9494configuration files and programs needed to boot and run the system.
9495This action does not actually install anything.
113daf62 9496
cf4a9129
LC
9497@item init
9498Populate the given directory with all the files necessary to run the
9499operating system specified in @var{file}. This is useful for first-time
4705641f 9500installations of GuixSD. For instance:
113daf62
LC
9501
9502@example
cf4a9129 9503guix system init my-os-config.scm /mnt
113daf62
LC
9504@end example
9505
cf4a9129
LC
9506copies to @file{/mnt} all the store items required by the configuration
9507specified in @file{my-os-config.scm}. This includes configuration
9508files, packages, and so on. It also creates other essential files
9509needed for the system to operate correctly---e.g., the @file{/etc},
9510@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 9511
cf4a9129
LC
9512This command also installs GRUB on the device specified in
9513@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 9514
cf4a9129
LC
9515@item vm
9516@cindex virtual machine
0276f697 9517@cindex VM
f535dcbe 9518@anchor{guix system vm}
1068f26b 9519Build a virtual machine that contains the operating system declared in
cf4a9129 9520@var{file}, and return a script to run that virtual machine (VM).
1068f26b 9521Arguments given to the script are passed to QEMU.
113daf62 9522
cf4a9129 9523The VM shares its store with the host system.
113daf62 9524
0276f697
LC
9525Additional file systems can be shared between the host and the VM using
9526the @code{--share} and @code{--expose} command-line options: the former
9527specifies a directory to be shared with write access, while the latter
9528provides read-only access to the shared directory.
9529
9530The example below creates a VM in which the user's home directory is
9531accessible read-only, and where the @file{/exchange} directory is a
1068f26b 9532read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
9533
9534@example
9535guix system vm my-config.scm \
9536 --expose=$HOME --share=$HOME/tmp=/exchange
9537@end example
9538
6aa260af
LC
9539On GNU/Linux, the default is to boot directly to the kernel; this has
9540the advantage of requiring only a very tiny root disk image since the
1068f26b 9541store of the host can then be mounted.
6aa260af
LC
9542
9543The @code{--full-boot} option forces a complete boot sequence, starting
9544with the bootloader. This requires more disk space since a root image
9545containing at least the kernel, initrd, and bootloader data files must
9546be created. The @code{--image-size} option can be used to specify the
1068f26b 9547size of the image.
ab11f0be 9548
cf4a9129
LC
9549@item vm-image
9550@itemx disk-image
9551Return a virtual machine or disk image of the operating system declared
9552in @var{file} that stands alone. Use the @option{--image-size} option
9553to specify the size of the image.
113daf62 9554
cf4a9129 9555When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
9556the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
9557for more information on how to run the image in a virtual machine.
113daf62 9558
cf4a9129
LC
9559When using @code{disk-image}, a raw disk image is produced; it can be
9560copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 9561the device corresponding to a USB stick, one can copy the image to it
cf4a9129 9562using the following command:
113daf62 9563
cf4a9129
LC
9564@example
9565# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
9566@end example
113daf62 9567
1c8a81b1
DT
9568@item container
9569Return a script to run the operating system declared in @var{file}
9570within a container. Containers are a set of lightweight isolation
9571mechanisms provided by the kernel Linux-libre. Containers are
9572substantially less resource-demanding than full virtual machines since
9573the kernel, shared objects, and other resources can be shared with the
9574host system; this also means they provide thinner isolation.
9575
9576Currently, the script must be run as root in order to support more than
9577a single user and group. The container shares its store with the host
9578system.
9579
9580As with the @code{vm} action (@pxref{guix system vm}), additional file
9581systems to be shared between the host and container can be specified
9582using the @option{--share} and @option{--expose} options:
9583
9584@example
9585guix system container my-config.scm \
9586 --expose=$HOME --share=$HOME/tmp=/exchange
9587@end example
9588
0f252e26 9589@quotation Note
cfd35b4e 9590This option requires Linux-libre 3.19 or newer.
0f252e26
DT
9591@end quotation
9592
cf4a9129 9593@end table
113daf62 9594
ccd7158d
LC
9595@var{options} can contain any of the common build options (@pxref{Common
9596Build Options}). In addition, @var{options} can contain one of the
9597following:
113daf62 9598
cf4a9129
LC
9599@table @option
9600@item --system=@var{system}
9601@itemx -s @var{system}
1068f26b 9602Attempt to build for @var{system} instead of the host system type.
cf4a9129 9603This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 9604
f3f427c2
LC
9605@item --derivation
9606@itemx -d
9607Return the derivation file name of the given operating system without
9608building anything.
9609
cf4a9129
LC
9610@item --image-size=@var{size}
9611For the @code{vm-image} and @code{disk-image} actions, create an image
9612of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
9613include a unit as a suffix (@pxref{Block size, size specifications,,
9614coreutils, GNU Coreutils}).
db030303
LC
9615
9616@item --on-error=@var{strategy}
9617Apply @var{strategy} when an error occurs when reading @var{file}.
9618@var{strategy} may be one of the following:
9619
9620@table @code
9621@item nothing-special
9622Report the error concisely and exit. This is the default strategy.
9623
9624@item backtrace
9625Likewise, but also display a backtrace.
9626
9627@item debug
9628Report the error and enter Guile's debugger. From there, you can run
9629commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
9630display local variable values, and more generally inspect the state of the
9631program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
9632a list of available debugging commands.
9633@end table
113daf62 9634@end table
113daf62 9635
cf4a9129
LC
9636Note that all the actions above, except @code{build} and @code{init},
9637rely on KVM support in the Linux-Libre kernel. Specifically, the
9638machine should have hardware virtualization support, the corresponding
9639KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b
AE
9640must exist and be readable and writable by the user and by the
9641build users of the daemon.
8451a568 9642
65797bff
LC
9643Once you have built, configured, re-configured, and re-re-configured
9644your GuixSD installation, you may find it useful to list the operating
9645system generations available on disk---and that you can choose from the
9646GRUB boot menu:
9647
9648@table @code
9649
9650@item list-generations
9651List a summary of each generation of the operating system available on
9652disk, in a human-readable way. This is similar to the
9653@option{--list-generations} option of @command{guix package}
9654(@pxref{Invoking guix package}).
9655
9656Optionally, one can specify a pattern, with the same syntax that is used
9657in @command{guix package --list-generations}, to restrict the list of
9658generations displayed. For instance, the following command displays
1068f26b 9659generations that are up to 10 days old:
65797bff
LC
9660
9661@example
9662$ guix system list-generations 10d
9663@end example
9664
9665@end table
9666
d6c3267a
LC
9667The @command{guix system} command has even more to offer! The following
9668sub-commands allow you to visualize how your system services relate to
9669each other:
9670
9671@anchor{system-extension-graph}
9672@table @code
9673
9674@item extension-graph
9675Emit in Dot/Graphviz format to standard output the @dfn{service
9676extension graph} of the operating system defined in @var{file}
9677(@pxref{Service Composition}, for more information on service
9678extensions.)
9679
9680The command:
9681
9682@example
9683$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
9684@end example
9685
9686produces a PDF file showing the extension relations among services.
9687
710fa231
AK
9688@anchor{system-shepherd-graph}
9689@item shepherd-graph
6f305ea5 9690Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
9691graph} of shepherd services of the operating system defined in
9692@var{file}. @xref{Shepherd Services}, for more information and for an
9693example graph.
6f305ea5 9694
d6c3267a
LC
9695@end table
9696
97d76250 9697@node Running GuixSD in a VM
70ac09a5 9698@subsection Running GuixSD in a Virtual Machine
97d76250
LF
9699
9700One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
9701virtual machine image using @command{guix system vm-image}
9702(@pxref{Invoking guix system}). The returned image is in qcow2 format,
9703which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
9704
9705To run the image in QEMU, copy it out of the store (@pxref{The Store})
9706and give yourself permission to write to the copy. When invoking QEMU,
9707you must choose a system emulator that is suitable for your hardware
9708platform. Here is a minimal QEMU invocation that will boot the result
9709of @command{guix system vm-image} on x86_64 hardware:
9710
9711@example
9712$ qemu-system-x86_64 \
9713 -net user -net nic,model=virtio \
9714 -enable-kvm -m 256 /tmp/qemu-image
9715@end example
9716
9717Here is what each of these options means:
9718
9719@table @code
9720@item qemu-system-x86_64
9721This specifies the hardware platform to emulate. This should match the
9722host.
9723
9724@item -net user
9725Enable the unprivileged user-mode network stack. The guest OS can
9726access the host but not vice versa. This is the simplest way to get the
1068f26b 9727guest OS online. If you do not choose a network stack, the boot will
97d76250
LF
9728fail.
9729
9730@item -net nic,model=virtio
1068f26b 9731You must create a network interface of a given model. If you do not
97d76250
LF
9732create a NIC, the boot will fail. Assuming your hardware platform is
9733x86_64, you can get a list of available NIC models by running
9734@command{qemu-system-x86_64 -net nic,model=help}.
9735
9736@item -enable-kvm
9737If your system has hardware virtualization extensions, enabling the
1068f26b 9738virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
9739faster.
9740
9741@item -m 256
9742RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
9743which may be insufficent for some operations.
9744
9745@item /tmp/qemu-image
9746The file name of the qcow2 image.
9747@end table
d6c3267a 9748
cf4a9129
LC
9749@node Defining Services
9750@subsection Defining Services
8451a568 9751
eb524192 9752The previous sections show the available services and how one can combine
0adfe95a
LC
9753them in an @code{operating-system} declaration. But how do we define
9754them in the first place? And what is a service anyway?
8451a568 9755
0adfe95a
LC
9756@menu
9757* Service Composition:: The model for composing services.
9758* Service Types and Services:: Types and services.
9759* Service Reference:: API reference.
dd17bc38 9760* Shepherd Services:: A particular type of service.
0adfe95a
LC
9761@end menu
9762
9763@node Service Composition
9764@subsubsection Service Composition
9765
9766@cindex services
9767@cindex daemons
9768Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 9769functionality of the operating system. Often a service is a process---a
0adfe95a
LC
9770@dfn{daemon}---started when the system boots: a secure shell server, a
9771Web server, the Guix build daemon, etc. Sometimes a service is a daemon
9772whose execution can be triggered by another daemon---e.g., an FTP server
9773started by @command{inetd} or a D-Bus service activated by
9774@command{dbus-daemon}. Occasionally, a service does not map to a
9775daemon. For instance, the ``account'' service collects user accounts
9776and makes sure they exist when the system runs; the ``udev'' service
9777collects device management rules and makes them available to the eudev
1068f26b
AE
9778daemon; the @file{/etc} service populates the @file{/etc} directory
9779of the system.
0adfe95a 9780
d6c3267a 9781@cindex service extensions
0adfe95a 9782GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 9783secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
9784initialization system, running as PID@tie{}1---by giving it the command
9785lines to start and stop the secure shell daemon (@pxref{Networking
9786Services, @code{lsh-service}}); the UPower service extends the D-Bus
9787service by passing it its @file{.service} specification, and extends the
9788udev service by passing it device management rules (@pxref{Desktop
9789Services, @code{upower-service}}); the Guix daemon service extends the
9790Shepherd by passing it the command lines to start and stop the daemon,
9791and extends the account service by passing it a list of required build
9792user accounts (@pxref{Base Services}).
0adfe95a
LC
9793
9794All in all, services and their ``extends'' relations form a directed
9795acyclic graph (DAG). If we represent services as boxes and extensions
9796as arrows, a typical system might provide something like this:
9797
9798@image{images/service-graph,,5in,Typical service extension graph.}
9799
d62e201c
LC
9800@cindex system service
9801At the bottom, we see the @dfn{system service}, which produces the
9802directory containing everything to run and boot the system, as returned
9803by the @command{guix system build} command. @xref{Service Reference},
9804to learn about the other service types shown here.
d6c3267a
LC
9805@xref{system-extension-graph, the @command{guix system extension-graph}
9806command}, for information on how to generate this representation for a
9807particular operating system definition.
0adfe95a
LC
9808
9809@cindex service types
9810Technically, developers can define @dfn{service types} to express these
9811relations. There can be any number of services of a given type on the
9812system---for instance, a system running two instances of the GNU secure
9813shell server (lsh) has two instances of @var{lsh-service-type}, with
9814different parameters.
9815
9816The following section describes the programming interface for service
9817types and services.
9818
9819@node Service Types and Services
9820@subsubsection Service Types and Services
9821
9822A @dfn{service type} is a node in the DAG described above. Let us start
9823with a simple example, the service type for the Guix build daemon
9824(@pxref{Invoking guix-daemon}):
9825
9826@example
9827(define guix-service-type
9828 (service-type
9829 (name 'guix)
9830 (extensions
d4053c71 9831 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
9832 (service-extension account-service-type guix-accounts)
9833 (service-extension activation-service-type guix-activation)))))
9834@end example
8451a568 9835
cf4a9129 9836@noindent
1068f26b 9837It defines two things:
0adfe95a
LC
9838
9839@enumerate
9840@item
9841A name, whose sole purpose is to make inspection and debugging easier.
9842
9843@item
9844A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
9845target service type and a procedure that, given the parameters of the
9846service, returns a list of objects to extend the service of that type.
0adfe95a
LC
9847
9848Every service type has at least one service extension. The only
9849exception is the @dfn{boot service type}, which is the ultimate service.
9850@end enumerate
9851
9852In this example, @var{guix-service-type} extends three services:
9853
9854@table @var
d4053c71
AK
9855@item shepherd-root-service-type
9856The @var{guix-shepherd-service} procedure defines how the Shepherd
9857service is extended. Namely, it returns a @code{<shepherd-service>}
9858object that defines how @command{guix-daemon} is started and stopped
9859(@pxref{Shepherd Services}).
0adfe95a
LC
9860
9861@item account-service-type
9862This extension for this service is computed by @var{guix-accounts},
9863which returns a list of @code{user-group} and @code{user-account}
9864objects representing the build user accounts (@pxref{Invoking
9865guix-daemon}).
9866
9867@item activation-service-type
9868Here @var{guix-activation} is a procedure that returns a gexp, which is
9869a code snippet to run at ``activation time''---e.g., when the service is
9870booted.
9871@end table
9872
9873A service of this type is instantiated like this:
9874
9875@example
9876(service guix-service-type
9877 (guix-configuration
9878 (build-accounts 5)
9879 (use-substitutes? #f)))
9880@end example
9881
9882The second argument to the @code{service} form is a value representing
9883the parameters of this specific service instance.
9884@xref{guix-configuration-type, @code{guix-configuration}}, for
9885information about the @code{guix-configuration} data type.
9886
9887@var{guix-service-type} is quite simple because it extends other
9888services but is not extensible itself.
9889
9890@c @subsubsubsection Extensible Service Types
9891
9892The service type for an @emph{extensible} service looks like this:
9893
9894@example
9895(define udev-service-type
9896 (service-type (name 'udev)
9897 (extensions
d4053c71
AK
9898 (list (service-extension shepherd-root-service-type
9899 udev-shepherd-service)))
0adfe95a
LC
9900
9901 (compose concatenate) ;concatenate the list of rules
9902 (extend (lambda (config rules)
9903 (match config
9904 (($ <udev-configuration> udev initial-rules)
9905 (udev-configuration
9906 (udev udev) ;the udev package to use
9907 (rules (append initial-rules rules)))))))))
9908@end example
9909
9910This is the service type for the
9911@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
9912management daemon}. Compared to the previous example, in addition to an
d4053c71 9913extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
9914
9915@table @code
9916@item compose
9917This is the procedure to @dfn{compose} the list of extensions to
9918services of this type.
9919
9920Services can extend the udev service by passing it lists of rules; we
9921compose those extensions simply by concatenating them.
9922
9923@item extend
1068f26b 9924This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
9925the composition of the extensions.
9926
9927Udev extensions are composed into a list of rules, but the udev service
9928value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 9929extend that record by appending the list of rules it contains to the
0adfe95a
LC
9930list of contributed rules.
9931@end table
9932
9933There can be only one instance of an extensible service type such as
9934@var{udev-service-type}. If there were more, the
9935@code{service-extension} specifications would be ambiguous.
9936
9937Still here? The next section provides a reference of the programming
9938interface for services.
9939
9940@node Service Reference
9941@subsubsection Service Reference
9942
9943We have seen an overview of service types (@pxref{Service Types and
9944Services}). This section provides a reference on how to manipulate
9945services and service types. This interface is provided by the
9946@code{(gnu services)} module.
9947
9948@deffn {Scheme Procedure} service @var{type} @var{value}
9949Return a new service of @var{type}, a @code{<service-type>} object (see
9950below.) @var{value} can be any object; it represents the parameters of
9951this particular service instance.
9952@end deffn
9953
9954@deffn {Scheme Procedure} service? @var{obj}
9955Return true if @var{obj} is a service.
9956@end deffn
8451a568 9957
0adfe95a
LC
9958@deffn {Scheme Procedure} service-kind @var{service}
9959Return the type of @var{service}---i.e., a @code{<service-type>} object.
9960@end deffn
9961
9962@deffn {Scheme Procedure} service-parameters @var{service}
9963Return the value associated with @var{service}. It represents its
9964parameters.
9965@end deffn
9966
9967Here is an example of how a service is created and manipulated:
9968
9969@example
9970(define s
9971 (service nginx-service-type
9972 (nginx-configuration
9973 (nginx nginx)
9974 (log-directory log-directory)
9975 (run-directory run-directory)
9976 (file config-file))))
9977
9978(service? s)
9979@result{} #t
9980
9981(eq? (service-kind s) nginx-service-type)
9982@result{} #t
9983@end example
9984
cd6f6c22
LC
9985The @code{modify-services} form provides a handy way to change the
9986parameters of some of the services of a list such as
9987@var{%base-services} (@pxref{Base Services, @code{%base-services}}). Of
9988course, you could always use standard list combinators such as
9989@code{map} and @code{fold} to do that (@pxref{SRFI-1, List Library,,
9990guile, GNU Guile Reference Manual}); @code{modify-services} simply
9991provides a more concise form for this common pattern.
9992
9993@deffn {Scheme Syntax} modify-services @var{services} @
9994 (@var{type} @var{variable} => @var{body}) @dots{}
9995
9996Modify the services listed in @var{services} according to the given
9997clauses. Each clause has the form:
9998
9999@example
10000(@var{type} @var{variable} => @var{body})
10001@end example
10002
10003where @var{type} is a service type, such as @var{guix-service-type}, and
10004@var{variable} is an identifier that is bound within @var{body} to the
10005value of the service of that @var{type}. @xref{Using the Configuration
10006System}, for an example.
10007
10008This is a shorthand for:
10009
10010@example
10011(map (lambda (service) @dots{}) @var{services})
10012@end example
10013@end deffn
10014
10015Next comes the programming interface for service types. This is
10016something you want to know when writing new service definitions, but not
10017necessarily when simply looking for ways to customize your
10018@code{operating-system} declaration.
10019
0adfe95a
LC
10020@deftp {Data Type} service-type
10021@cindex service type
10022This is the representation of a @dfn{service type} (@pxref{Service Types
10023and Services}).
10024
10025@table @asis
10026@item @code{name}
10027This is a symbol, used only to simplify inspection and debugging.
10028
10029@item @code{extensions}
1068f26b 10030A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
10031
10032@item @code{compose} (default: @code{#f})
10033If this is @code{#f}, then the service type denotes services that cannot
10034be extended---i.e., services that do not receive ``values'' from other
10035services.
10036
10037Otherwise, it must be a one-argument procedure. The procedure is called
10038by @code{fold-services} and is passed a list of values collected from
10039extensions. It must return a value that is a valid parameter value for
10040the service instance.
10041
10042@item @code{extend} (default: @code{#f})
10043If this is @code{#f}, services of this type cannot be extended.
10044
10045Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 10046calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
10047and the result of applying @code{compose} to the extension values as the
10048second argument.
10049@end table
10050
10051@xref{Service Types and Services}, for examples.
10052@end deftp
10053
10054@deffn {Scheme Procedure} service-extension @var{target-type} @
10055 @var{compute}
10056Return a new extension for services of type @var{target-type}.
10057@var{compute} must be a one-argument procedure: @code{fold-services}
10058calls it, passing it the value associated with the service that provides
10059the extension; it must return a valid value for the target service.
10060@end deffn
10061
10062@deffn {Scheme Procedure} service-extension? @var{obj}
10063Return true if @var{obj} is a service extension.
10064@end deffn
10065
10066At the core of the service abstraction lies the @code{fold-services}
10067procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
10068down to a single directory that contains everything needed to boot and
10069run the system---the directory shown by the @command{guix system build}
10070command (@pxref{Invoking guix system}). In essence, it propagates
10071service extensions down the service graph, updating each node parameters
10072on the way, until it reaches the root node.
0adfe95a
LC
10073
10074@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 10075 [#:target-type @var{system-service-type}]
0adfe95a
LC
10076Fold @var{services} by propagating their extensions down to the root of
10077type @var{target-type}; return the root service adjusted accordingly.
10078@end deffn
10079
10080Lastly, the @code{(gnu services)} module also defines several essential
10081service types, some of which are listed below.
10082
d62e201c
LC
10083@defvr {Scheme Variable} system-service-type
10084This is the root of the service graph. It produces the system directory
10085as returned by the @command{guix system build} command.
10086@end defvr
10087
0adfe95a 10088@defvr {Scheme Variable} boot-service-type
d62e201c
LC
10089The type of the ``boot service'', which produces the @dfn{boot script}.
10090The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
10091@end defvr
10092
10093@defvr {Scheme Variable} etc-service-type
10094The type of the @file{/etc} service. This service can be extended by
10095passing it name/file tuples such as:
10096
10097@example
10098(list `("issue" ,(plain-file "issue" "Welcome!\n")))
10099@end example
10100
10101In this example, the effect would be to add an @file{/etc/issue} file
10102pointing to the given file.
10103@end defvr
10104
10105@defvr {Scheme Variable} setuid-program-service-type
10106Type for the ``setuid-program service''. This service collects lists of
10107executable file names, passed as gexps, and adds them to the set of
10108setuid-root programs on the system (@pxref{Setuid Programs}).
10109@end defvr
10110
af4c3fd5
LC
10111@defvr {Scheme Variable} profile-service-type
10112Type of the service that populates the @dfn{system profile}---i.e., the
10113programs under @file{/run/current-system/profile}. Other services can
10114extend it by passing it lists of packages to add to the system profile.
10115@end defvr
10116
0adfe95a 10117
dd17bc38
AK
10118@node Shepherd Services
10119@subsubsection Shepherd Services
0adfe95a
LC
10120
10121@cindex PID 1
10122@cindex init system
a40424bd
CM
10123The @code{(gnu services shepherd)} module provides a way to define
10124services managed by the GNU@tie{}Shepherd, which is the GuixSD
10125initialization system---the first process that is started when the
1068f26b
AE
10126system boots, also known as PID@tie{}1
10127(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 10128
dd17bc38
AK
10129Services in the Shepherd can depend on each other. For instance, the
10130SSH daemon may need to be started after the syslog daemon has been
10131started, which in turn can only happen once all the file systems have
10132been mounted. The simple operating system defined earlier (@pxref{Using
10133the Configuration System}) results in a service graph like this:
6f305ea5 10134
710fa231 10135@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
10136
10137You can actually generate such a graph for any operating system
710fa231
AK
10138definition using the @command{guix system shepherd-graph} command
10139(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 10140
d4053c71
AK
10141The @var{%shepherd-root-service} is a service object representing
10142PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
10143by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 10144
d4053c71 10145@deftp {Data Type} shepherd-service
dd17bc38 10146The data type representing a service managed by the Shepherd.
0adfe95a
LC
10147
10148@table @asis
10149@item @code{provision}
10150This is a list of symbols denoting what the service provides.
10151
dd17bc38
AK
10152These are the names that may be passed to @command{herd start},
10153@command{herd status}, and similar commands (@pxref{Invoking herd,,,
10154shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
10155@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
10156
10157@item @code{requirements} (default: @code{'()})
dd17bc38 10158List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
10159
10160@item @code{respawn?} (default: @code{#t})
10161Whether to restart the service when it stops, for instance when the
10162underlying process dies.
10163
10164@item @code{start}
10165@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
10166The @code{start} and @code{stop} fields refer to the Shepherd's
10167facilities to start and stop processes (@pxref{Service De- and
10168Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
10169G-expressions that get expanded in the Shepherd configuration file
10170(@pxref{G-Expressions}).
0adfe95a
LC
10171
10172@item @code{documentation}
10173A documentation string, as shown when running:
10174
10175@example
dd17bc38 10176herd doc @var{service-name}
0adfe95a
LC
10177@end example
10178
10179where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 10180(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
10181
10182@item @code{modules} (default: @var{%default-modules})
10183This is the list of modules that must be in scope when @code{start} and
10184@code{stop} are evaluated.
10185
10186@item @code{imported-modules} (default: @var{%default-imported-modules})
10187This is the list of modules to import in the execution environment of
dd17bc38 10188the Shepherd.
fae685b9 10189
0adfe95a
LC
10190@end table
10191@end deftp
10192
d4053c71 10193@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 10194The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
10195
10196This is the service type that extensions target when they want to create
dd17bc38 10197shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 10198Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
10199@end defvr
10200
d4053c71 10201@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
10202This service represents PID@tie{}1.
10203@end defvr
8451a568 10204
8451a568 10205
cf4a9129
LC
10206@node Installing Debugging Files
10207@section Installing Debugging Files
8451a568 10208
cf4a9129
LC
10209@cindex debugging files
10210Program binaries, as produced by the GCC compilers for instance, are
10211typically written in the ELF format, with a section containing
10212@dfn{debugging information}. Debugging information is what allows the
10213debugger, GDB, to map binary code to source code; it is required to
10214debug a compiled program in good conditions.
8451a568 10215
cf4a9129
LC
10216The problem with debugging information is that is takes up a fair amount
10217of disk space. For example, debugging information for the GNU C Library
10218weighs in at more than 60 MiB. Thus, as a user, keeping all the
10219debugging info of all the installed programs is usually not an option.
10220Yet, space savings should not come at the cost of an impediment to
10221debugging---especially in the GNU system, which should make it easier
10222for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 10223
cf4a9129
LC
10224Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
10225mechanism that allows users to get the best of both worlds: debugging
10226information can be stripped from the binaries and stored in separate
10227files. GDB is then able to load debugging information from those files,
10228when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
10229with GDB}).
8451a568 10230
cf4a9129
LC
10231The GNU distribution takes advantage of this by storing debugging
10232information in the @code{lib/debug} sub-directory of a separate package
10233output unimaginatively called @code{debug} (@pxref{Packages with
10234Multiple Outputs}). Users can choose to install the @code{debug} output
10235of a package when they need it. For instance, the following command
10236installs the debugging information for the GNU C Library and for GNU
10237Guile:
8451a568
LC
10238
10239@example
cf4a9129 10240guix package -i glibc:debug guile:debug
8451a568
LC
10241@end example
10242
cf4a9129
LC
10243GDB must then be told to look for debug files in the user's profile, by
10244setting the @code{debug-file-directory} variable (consider setting it
10245from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
10246GDB}):
8451a568 10247
cf4a9129
LC
10248@example
10249(gdb) set debug-file-directory ~/.guix-profile/lib/debug
10250@end example
8451a568 10251
cf4a9129
LC
10252From there on, GDB will pick up debugging information from the
10253@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 10254
cf4a9129
LC
10255In addition, you will most likely want GDB to be able to show the source
10256code being debugged. To do that, you will have to unpack the source
10257code of the package of interest (obtained with @code{guix build
10258--source}, @pxref{Invoking guix build}), and to point GDB to that source
10259directory using the @code{directory} command (@pxref{Source Path,
10260@code{directory},, gdb, Debugging with GDB}).
8451a568 10261
cf4a9129
LC
10262@c XXX: keep me up-to-date
10263The @code{debug} output mechanism in Guix is implemented by the
10264@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
10265opt-in---debugging information is available only for the packages
10266with definitions explicitly declaring a @code{debug} output. This may be
10267changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
10268the load. To check whether a package has a @code{debug} output, use
10269@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 10270
8451a568 10271
05962f29
LC
10272@node Security Updates
10273@section Security Updates
10274
843858b8
LC
10275@quotation Note
10276As of version @value{VERSION}, the feature described in this section is
10277experimental.
10278@end quotation
05962f29
LC
10279
10280@cindex security updates
10281Occasionally, important security vulnerabilities are discovered in core
10282software packages and must be patched. Guix follows a functional
10283package management discipline (@pxref{Introduction}), which implies
10284that, when a package is changed, @emph{every package that depends on it}
10285must be rebuilt. This can significantly slow down the deployment of
10286fixes in core packages such as libc or Bash, since basically the whole
10287distribution would need to be rebuilt. Using pre-built binaries helps
10288(@pxref{Substitutes}), but deployment may still take more time than
10289desired.
10290
10291@cindex grafts
1068f26b 10292To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
10293for fast deployment of critical updates without the costs associated
10294with a whole-distribution rebuild. The idea is to rebuild only the
10295package that needs to be patched, and then to ``graft'' it onto packages
10296explicitly installed by the user and that were previously referring to
10297the original package. The cost of grafting is typically very low, and
10298order of magnitudes lower than a full rebuild of the dependency chain.
10299
10300@cindex replacements of packages, for grafts
10301For instance, suppose a security update needs to be applied to Bash.
10302Guix developers will provide a package definition for the ``fixed''
10303Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
10304Packages}). Then, the original package definition is augmented with a
10305@code{replacement} field pointing to the package containing the bug fix:
10306
10307@example
10308(define bash
10309 (package
10310 (name "bash")
10311 ;; @dots{}
10312 (replacement bash-fixed)))
10313@end example
10314
c22a1324
LC
10315From there on, any package depending directly or indirectly on Bash---as
10316reported by @command{guix gc --requisites} (@pxref{Invoking guix
10317gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 10318@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 10319time proportional to the size of the package, usually less than a
c22a1324
LC
10320minute for an ``average'' package on a recent machine. Grafting is
10321recursive: when an indirect dependency requires grafting, then grafting
10322``propagates'' up to the package that the user is installing.
05962f29
LC
10323
10324Currently, the graft and the package it replaces (@var{bash-fixed} and
10325@var{bash} in the example above) must have the exact same @code{name}
10326and @code{version} fields. This restriction mostly comes from the fact
10327that grafting works by patching files, including binary files, directly.
10328Other restrictions may apply: for instance, when adding a graft to a
10329package providing a shared library, the original shared library and its
10330replacement must have the same @code{SONAME} and be binary-compatible.
10331
59a4dd50
LC
10332The @option{--no-grafts} command-line option allows you to forcefully
10333avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
10334Thus, the command:
10335
10336@example
10337guix build bash --no-grafts
10338@end example
10339
10340@noindent
10341returns the store file name of the original Bash, whereas:
10342
10343@example
10344guix build bash
10345@end example
10346
10347@noindent
10348returns the store file name of the ``fixed'', replacement Bash. This
10349allows you to distinguish between the two variants of Bash.
10350
10351To verify which Bash your whole profile refers to, you can run
10352(@pxref{Invoking guix gc}):
10353
10354@example
10355guix gc -R `readlink -f ~/.guix-profile` | grep bash
10356@end example
10357
10358@noindent
10359@dots{} and compare the store file names that you get with those above.
10360Likewise for a complete GuixSD system generation:
10361
10362@example
10363guix gc -R `guix system build my-config.scm` | grep bash
10364@end example
10365
10366Lastly, to check which Bash running processes are using, you can use the
10367@command{lsof} command:
10368
10369@example
10370lsof | grep /gnu/store/.*bash
10371@end example
10372
05962f29 10373
cf4a9129
LC
10374@node Package Modules
10375@section Package Modules
8451a568 10376
cf4a9129
LC
10377From a programming viewpoint, the package definitions of the
10378GNU distribution are provided by Guile modules in the @code{(gnu packages
10379@dots{})} name space@footnote{Note that packages under the @code{(gnu
10380packages @dots{})} module name space are not necessarily ``GNU
10381packages''. This module naming scheme follows the usual Guile module
10382naming convention: @code{gnu} means that these modules are distributed
10383as part of the GNU system, and @code{packages} identifies modules that
10384define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
10385Reference Manual}). For instance, the @code{(gnu packages emacs)}
10386module exports a variable named @code{emacs}, which is bound to a
10387@code{<package>} object (@pxref{Defining Packages}).
113daf62 10388
300868ba 10389The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
10390automatically scanned for packages by the command-line tools. For
10391instance, when running @code{guix package -i emacs}, all the @code{(gnu
10392packages @dots{})} modules are scanned until one that exports a package
10393object whose name is @code{emacs} is found. This package search
10394facility is implemented in the @code{(gnu packages)} module.
113daf62 10395
300868ba 10396@cindex customization, of packages
8689901f 10397@cindex package module search path
cf4a9129 10398Users can store package definitions in modules with different
60142854 10399names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
10400name and module name must match. For instance, the @code{(my-packages
10401emacs)} module must be stored in a @file{my-packages/emacs.scm} file
10402relative to the load path specified with @option{--load-path} or
10403@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
10404guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
10405will not be visible by default. Users can invoke commands such as
10406@command{guix package} and @command{guix build} with the
c95ded7e
LC
10407@code{-e} option so that they know where to find the package. Better
10408yet, they can use the
300868ba 10409@code{-L} option of these commands to make those modules visible
8689901f
LC
10410(@pxref{Invoking guix build, @code{--load-path}}), or define the
10411@code{GUIX_PACKAGE_PATH} environment variable. This environment
10412variable makes it easy to extend or customize the distribution and is
10413honored by all the user interfaces.
10414
10415@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
10416This is a colon-separated list of directories to search for additional
10417package modules. Directories listed in this variable take precedence
10418over the own modules of the distribution.
8689901f 10419@end defvr
ef5dd60a 10420
cf4a9129
LC
10421The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
10422each package is built based solely on other packages in the
10423distribution. The root of this dependency graph is a small set of
10424@dfn{bootstrap binaries}, provided by the @code{(gnu packages
10425bootstrap)} module. For more information on bootstrapping,
081145cf 10426@pxref{Bootstrapping}.
ef5dd60a 10427
cf4a9129
LC
10428@node Packaging Guidelines
10429@section Packaging Guidelines
ef5dd60a 10430
cf4a9129
LC
10431The GNU distribution is nascent and may well lack some of your favorite
10432packages. This section describes how you can help make the distribution
10433grow. @xref{Contributing}, for additional information on how you can
10434help.
ef5dd60a 10435
cf4a9129
LC
10436Free software packages are usually distributed in the form of
10437@dfn{source code tarballs}---typically @file{tar.gz} files that contain
10438all the source files. Adding a package to the distribution means
10439essentially two things: adding a @dfn{recipe} that describes how to
10440build the package, including a list of other packages required to build
f97c9175 10441it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 10442description and licensing information.
ef5dd60a 10443
cf4a9129
LC
10444In Guix all this information is embodied in @dfn{package definitions}.
10445Package definitions provide a high-level view of the package. They are
10446written using the syntax of the Scheme programming language; in fact,
10447for each package we define a variable bound to the package definition,
10448and export that variable from a module (@pxref{Package Modules}).
10449However, in-depth Scheme knowledge is @emph{not} a prerequisite for
10450creating packages. For more information on package definitions,
081145cf 10451@pxref{Defining Packages}.
ef5dd60a 10452
cf4a9129
LC
10453Once a package definition is in place, stored in a file in the Guix
10454source tree, it can be tested using the @command{guix build} command
10455(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
10456called @code{gnew}, you may run this command from the Guix build tree
10457(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
10458
10459@example
cf4a9129 10460./pre-inst-env guix build gnew --keep-failed
ef5dd60a 10461@end example
ef5dd60a 10462
cf4a9129
LC
10463Using @code{--keep-failed} makes it easier to debug build failures since
10464it provides access to the failed build tree. Another useful
10465command-line option when debugging is @code{--log-file}, to access the
10466build log.
ef5dd60a 10467
cf4a9129
LC
10468If the package is unknown to the @command{guix} command, it may be that
10469the source file contains a syntax error, or lacks a @code{define-public}
10470clause to export the package variable. To figure it out, you may load
10471the module from Guile to get more information about the actual error:
ef5dd60a 10472
cf4a9129
LC
10473@example
10474./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
10475@end example
ef5dd60a 10476
cf4a9129
LC
10477Once your package builds correctly, please send us a patch
10478(@pxref{Contributing}). Well, if you need help, we will be happy to
10479help you too. Once the patch is committed in the Guix repository, the
10480new package automatically gets built on the supported platforms by
2b1cee21 10481@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 10482system}.
ef5dd60a 10483
cf4a9129
LC
10484@cindex substituter
10485Users can obtain the new package definition simply by running
10486@command{guix pull} (@pxref{Invoking guix pull}). When
10487@code{hydra.gnu.org} is done building the package, installing the
10488package automatically downloads binaries from there
10489(@pxref{Substitutes}). The only place where human intervention is
10490needed is to review and apply the patch.
ef5dd60a 10491
ef5dd60a 10492
cf4a9129 10493@menu
ec0339cd
LC
10494* Software Freedom:: What may go into the distribution.
10495* Package Naming:: What's in a name?
10496* Version Numbers:: When the name is not enough.
cbd02397 10497* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
10498* Python Modules:: Taming the snake.
10499* Perl Modules:: Little pearls.
10500* Fonts:: Fond of fonts.
cf4a9129 10501@end menu
ef5dd60a 10502
cf4a9129
LC
10503@node Software Freedom
10504@subsection Software Freedom
ef5dd60a 10505
cf4a9129 10506@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 10507
cf4a9129
LC
10508The GNU operating system has been developed so that users can have
10509freedom in their computing. GNU is @dfn{free software}, meaning that
10510users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
10511essential freedoms}: to run the program, to study and change the program
10512in source code form, to redistribute exact copies, and to distribute
10513modified versions. Packages found in the GNU distribution provide only
10514software that conveys these four freedoms.
c11a6eb1 10515
cf4a9129
LC
10516In addition, the GNU distribution follow the
10517@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
10518software distribution guidelines}. Among other things, these guidelines
10519reject non-free firmware, recommendations of non-free software, and
10520discuss ways to deal with trademarks and patents.
ef5dd60a 10521
1068f26b
AE
10522Some otherwise free upstream package sources contain a small and optional
10523subset that violates the above guidelines, for instance because this subset
10524is itself non-free code. When that happens, the offending items are removed
10525with appropriate patches or code snippets in the @code{origin} form of the
10526package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
10527build --source} returns the ``freed'' source rather than the unmodified
10528upstream source.
ef5dd60a 10529
ef5dd60a 10530
cf4a9129
LC
10531@node Package Naming
10532@subsection Package Naming
ef5dd60a 10533
cf4a9129
LC
10534A package has actually two names associated with it:
10535First, there is the name of the @emph{Scheme variable}, the one following
10536@code{define-public}. By this name, the package can be made known in the
10537Scheme code, for instance as input to another package. Second, there is
10538the string in the @code{name} field of a package definition. This name
10539is used by package management commands such as
10540@command{guix package} and @command{guix build}.
ef5dd60a 10541
cf4a9129
LC
10542Both are usually the same and correspond to the lowercase conversion of
10543the project name chosen upstream, with underscores replaced with
10544hyphens. For instance, GNUnet is available as @code{gnunet}, and
10545SDL_net as @code{sdl-net}.
927097ef 10546
cf4a9129 10547We do not add @code{lib} prefixes for library packages, unless these are
081145cf 10548already part of the official project name. But @pxref{Python
cf4a9129
LC
10549Modules} and @ref{Perl Modules} for special rules concerning modules for
10550the Python and Perl languages.
927097ef 10551
1b366ee4 10552Font package names are handled differently, @pxref{Fonts}.
7fec52b7 10553
ef5dd60a 10554
cf4a9129
LC
10555@node Version Numbers
10556@subsection Version Numbers
ef5dd60a 10557
cf4a9129
LC
10558We usually package only the latest version of a given free software
10559project. But sometimes, for instance for incompatible library versions,
10560two (or more) versions of the same package are needed. These require
10561different Scheme variable names. We use the name as defined
10562in @ref{Package Naming}
10563for the most recent version; previous versions use the same name, suffixed
10564by @code{-} and the smallest prefix of the version number that may
10565distinguish the two versions.
ef5dd60a 10566
cf4a9129
LC
10567The name inside the package definition is the same for all versions of a
10568package and does not contain any version number.
ef5dd60a 10569
cf4a9129 10570For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 10571
cf4a9129
LC
10572@example
10573(define-public gtk+
10574 (package
17d8e33f
ML
10575 (name "gtk+")
10576 (version "3.9.12")
10577 ...))
cf4a9129
LC
10578(define-public gtk+-2
10579 (package
17d8e33f
ML
10580 (name "gtk+")
10581 (version "2.24.20")
10582 ...))
cf4a9129
LC
10583@end example
10584If we also wanted GTK+ 3.8.2, this would be packaged as
10585@example
10586(define-public gtk+-3.8
10587 (package
17d8e33f
ML
10588 (name "gtk+")
10589 (version "3.8.2")
10590 ...))
cf4a9129 10591@end example
ef5dd60a 10592
880d647d
LC
10593@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
10594@c for a discussion of what follows.
10595@cindex version number, for VCS snapshots
10596Occasionally, we package snapshots of upstream's version control system
10597(VCS) instead of formal releases. This should remain exceptional,
10598because it is up to upstream developers to clarify what the stable
10599release is. Yet, it is sometimes necessary. So, what should we put in
10600the @code{version} field?
10601
10602Clearly, we need to make the commit identifier of the VCS snapshot
10603visible in the version string, but we also need to make sure that the
10604version string is monotonically increasing so that @command{guix package
10605--upgrade} can determine which version is newer. Since commit
10606identifiers, notably with Git, are not monotonically increasing, we add
10607a revision number that we increase each time we upgrade to a newer
10608snapshot. The resulting version string looks like this:
10609
10610@example
106112.0.11-3.cabba9e
10612 ^ ^ ^
10613 | | `-- upstream commit ID
10614 | |
10615 | `--- Guix package revision
10616 |
10617latest upstream version
10618@end example
10619
10620It is a good idea to strip commit identifiers in the @code{version}
10621field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
10622aesthetics have a role to play here) as well as problems related to OS
10623limits such as the maximum shebang length (127 bytes for the Linux
10624kernel.) It is best to use the full commit identifiers in
561360a5
LC
10625@code{origin}s, though, to avoid ambiguities. A typical package
10626definition may look like this:
10627
10628@example
10629(define my-package
10630 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7"))
10631 (package
10632 (version (string-append "0.9-1."
10633 (string-take commit 7)))
10634 (source (origin
10635 (method git-fetch)
10636 (uri (git-reference
10637 (url "git://example.org/my-package.git")
10638 (commit commit)))
10639 (sha256 (base32 "1mbikn@dots{}"))
10640 (file-name (string-append "my-package-" version
10641 "-checkout"))))
10642 ;; @dots{}
10643 )))
10644@end example
880d647d 10645
cbd02397
LC
10646@node Synopses and Descriptions
10647@subsection Synopses and Descriptions
10648
10649As we have seen before, each package in GNU@tie{}Guix includes a
10650synopsis and a description (@pxref{Defining Packages}). Synopses and
10651descriptions are important: They are what @command{guix package
10652--search} searches, and a crucial piece of information to help users
10653determine whether a given package suits their needs. Consequently,
10654packagers should pay attention to what goes into them.
10655
10656Synopses must start with a capital letter and must not end with a
10657period. They must not start with ``a'' or ``the'', which usually does
10658not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
10659tool that frobs files''. The synopsis should say what the package
10660is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
10661used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
10662matching a pattern''.
10663
10664Keep in mind that the synopsis must be meaningful for a very wide
10665audience. For example, ``Manipulate alignments in the SAM format''
10666might make sense for a seasoned bioinformatics researcher, but might be
10667fairly unhelpful or even misleading to a non-specialized audience. It
10668is a good idea to come up with a synopsis that gives an idea of the
10669application domain of the package. In this example, this might give
10670something like ``Manipulate nucleotide sequence alignments'', which
10671hopefully gives the user a better idea of whether this is what they are
10672looking for.
10673
10674@cindex Texinfo markup, in package descriptions
10675Descriptions should take between five and ten lines. Use full
10676sentences, and avoid using acronyms without first introducing them.
10677Descriptions can include Texinfo markup, which is useful to introduce
10678ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
10679hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
10680should be careful when using some characters for example @samp{@@} and
10681curly braces which are the basic special characters in Texinfo
10682(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
10683such as @command{guix package --show} take care of rendering it
10684appropriately.
cbd02397
LC
10685
10686Synopses and descriptions are translated by volunteers
10687@uref{http://translationproject.org/domain/guix-packages.html, at the
10688Translation Project} so that as many users as possible can read them in
10689their native language. User interfaces search them and display them in
10690the language specified by the current locale.
10691
10692Translation is a lot of work so, as a packager, please pay even more
10693attention to your synopses and descriptions as every change may entail
ba7d6c76 10694additional work for translators. In order to help them, it is possible
36743e71 10695to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
10696special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
10697Gettext}):
10698
10699@example
10700;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
10701(description "ARandR is designed to provide a simple visual front end
10702for the X11 resize-and-rotate (RandR) extension. @dots{}")
10703@end example
cbd02397 10704
ef5dd60a 10705
cf4a9129
LC
10706@node Python Modules
10707@subsection Python Modules
ef5dd60a 10708
cf4a9129
LC
10709We currently package Python 2 and Python 3, under the Scheme variable names
10710@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
10711To avoid confusion and naming clashes with other programming languages, it
10712seems desirable that the name of a package for a Python module contains
10713the word @code{python}.
ef5dd60a 10714
cf4a9129
LC
10715Some modules are compatible with only one version of Python, others with both.
10716If the package Foo compiles only with Python 3, we name it
10717@code{python-foo}; if it compiles only with Python 2, we name it
10718@code{python2-foo}. If it is compatible with both versions, we create two
10719packages with the corresponding names.
ef5dd60a 10720
cf4a9129
LC
10721If a project already contains the word @code{python}, we drop this;
10722for instance, the module python-dateutil is packaged under the names
10723@code{python-dateutil} and @code{python2-dateutil}.
113daf62 10724
523e4896 10725
cf4a9129
LC
10726@node Perl Modules
10727@subsection Perl Modules
523e4896 10728
cf4a9129
LC
10729Perl programs standing for themselves are named as any other package,
10730using the lowercase upstream name.
10731For Perl packages containing a single class, we use the lowercase class name,
10732replace all occurrences of @code{::} by dashes and prepend the prefix
10733@code{perl-}.
10734So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
10735Modules containing several classes keep their lowercase upstream name and
10736are also prepended by @code{perl-}. Such modules tend to have the word
10737@code{perl} somewhere in their name, which gets dropped in favor of the
10738prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 10739
523e4896 10740
7fec52b7
AE
10741@node Fonts
10742@subsection Fonts
10743
10744For fonts that are in general not installed by a user for typesetting
10745purposes, or that are distributed as part of a larger software package,
10746we rely on the general packaging rules for software; for instance, this
10747applies to the fonts delivered as part of the X.Org system or fonts that
10748are part of TeX Live.
10749
10750To make it easier for a user to search for fonts, names for other packages
10751containing only fonts are constructed as follows, independently of the
10752upstream package name.
10753
10754The name of a package containing only one font family starts with
10755@code{font-}; it is followed by the foundry name and a dash @code{-}
10756if the foundry is known, and the font family name, in which spaces are
10757replaced by dashes (and as usual, all upper case letters are transformed
10758to lower case).
10759For example, the Gentium font family by SIL is packaged under the name
10760@code{font-sil-gentium}.
10761
10762For a package containing several font families, the name of the collection
10763is used in the place of the font family name.
10764For instance, the Liberation fonts consist of three families,
10765Liberation Sans, Liberation Serif and Liberation Mono.
10766These could be packaged separately under the names
10767@code{font-liberation-sans} and so on; but as they are distributed together
10768under a common name, we prefer to package them together as
10769@code{font-liberation}.
10770
10771In the case where several formats of the same font family or font collection
10772are packaged separately, a short form of the format, prepended by a dash,
10773is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 10774@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
10775fonts.
10776
10777
b25937e3 10778
cf4a9129
LC
10779@node Bootstrapping
10780@section Bootstrapping
b25937e3 10781
cf4a9129 10782@c Adapted from the ELS 2013 paper.
b25937e3 10783
cf4a9129 10784@cindex bootstrapping
7889394e 10785
cf4a9129
LC
10786Bootstrapping in our context refers to how the distribution gets built
10787``from nothing''. Remember that the build environment of a derivation
10788contains nothing but its declared inputs (@pxref{Introduction}). So
10789there's an obvious chicken-and-egg problem: how does the first package
10790get built? How does the first compiler get compiled? Note that this is
10791a question of interest only to the curious hacker, not to the regular
10792user, so you can shamelessly skip this section if you consider yourself
10793a ``regular user''.
72b9d60d 10794
cf4a9129
LC
10795@cindex bootstrap binaries
10796The GNU system is primarily made of C code, with libc at its core. The
10797GNU build system itself assumes the availability of a Bourne shell and
10798command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
10799`grep'. Furthermore, build programs---programs that run
10800@code{./configure}, @code{make}, etc.---are written in Guile Scheme
10801(@pxref{Derivations}). Consequently, to be able to build anything at
10802all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
10803Binutils, libc, and the other packages mentioned above---the
10804@dfn{bootstrap binaries}.
72b9d60d 10805
cf4a9129
LC
10806These bootstrap binaries are ``taken for granted'', though we can also
10807re-create them if needed (more on that later).
72b9d60d 10808
cf4a9129 10809@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 10810
cf4a9129
LC
10811@c As of Emacs 24.3, Info-mode displays the image, but since it's a
10812@c large image, it's hard to scroll. Oh well.
10813@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 10814
cf4a9129
LC
10815The figure above shows the very beginning of the dependency graph of the
10816distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
10817packages bootstrap)} module. A similar figure can be generated with
10818@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
10819
10820@example
10821guix graph -t derivation \
10822 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
10823 | dot -Tps > t.ps
10824@end example
10825
10826At this level of detail, things are
cf4a9129
LC
10827slightly complex. First, Guile itself consists of an ELF executable,
10828along with many source and compiled Scheme files that are dynamically
10829loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
10830tarball shown in this graph. This tarball is part of Guix's ``source''
10831distribution, and gets inserted into the store with @code{add-to-store}
10832(@pxref{The Store}).
2e7b5cea 10833
cf4a9129
LC
10834But how do we write a derivation that unpacks this tarball and adds it
10835to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
10836derivation---the first one that gets built---uses @code{bash} as its
10837builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
10838@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
10839@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
10840the Guix source distribution, whose sole purpose is to allow the Guile
10841tarball to be unpacked.
fb729425 10842
cf4a9129
LC
10843Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
10844Guile that can be used to run subsequent build programs. Its first task
10845is to download tarballs containing the other pre-built binaries---this
10846is what the @code{.tar.xz.drv} derivations do. Guix modules such as
10847@code{ftp-client.scm} are used for this purpose. The
10848@code{module-import.drv} derivations import those modules in a directory
10849in the store, using the original layout. The
10850@code{module-import-compiled.drv} derivations compile those modules, and
10851write them in an output directory with the right layout. This
10852corresponds to the @code{#:modules} argument of
10853@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 10854
cf4a9129
LC
10855Finally, the various tarballs are unpacked by the
10856derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
10857etc., at which point we have a working C tool chain.
fb729425 10858
fb729425 10859
cf4a9129 10860@unnumberedsubsec Building the Build Tools
523e4896 10861
cf4a9129
LC
10862Bootstrapping is complete when we have a full tool chain that does not
10863depend on the pre-built bootstrap tools discussed above. This
10864no-dependency requirement is verified by checking whether the files of
10865the final tool chain contain references to the @file{/gnu/store}
10866directories of the bootstrap inputs. The process that leads to this
10867``final'' tool chain is described by the package definitions found in
1f6f57df 10868the @code{(gnu packages commencement)} module.
df2ce343 10869
d33fa0c7
LC
10870The @command{guix graph} command allows us to ``zoom out'' compared to
10871the graph above, by looking at the level of package objects instead of
10872individual derivations---remember that a package may translate to
10873several derivations, typically one derivation to download its source,
10874one to build the Guile modules it needs, and one to actually build the
10875package from source. The command:
10876
10877@example
10878guix graph -t bag \
10879 -e '(@@@@ (gnu packages commencement)
10880 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
10881@end example
10882
10883@noindent
10884produces the dependency graph leading to the ``final'' C
10885library@footnote{You may notice the @code{glibc-intermediate} label,
10886suggesting that it is not @emph{quite} final, but as a good
10887approximation, we will consider it final.}, depicted below.
10888
10889@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
10890
cf4a9129
LC
10891@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
10892The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
10893GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
10894for all the following packages. From there Findutils and Diffutils get
10895built.
523e4896 10896
cf4a9129
LC
10897Then come the first-stage Binutils and GCC, built as pseudo cross
10898tools---i.e., with @code{--target} equal to @code{--host}. They are
10899used to build libc. Thanks to this cross-build trick, this libc is
10900guaranteed not to hold any reference to the initial tool chain.
4af2447e 10901
d33fa0c7
LC
10902From there the final Binutils and GCC (not shown above) are built.
10903GCC uses @code{ld}
cf4a9129
LC
10904from the final Binutils, and links programs against the just-built libc.
10905This tool chain is used to build the other packages used by Guix and by
10906the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 10907
cf4a9129
LC
10908And voilà! At this point we have the complete set of build tools that
10909the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
10910variable of the @code{(gnu packages commencement)} module, and are
10911implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 10912(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 10913
4af2447e 10914
cf4a9129 10915@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 10916
cf4a9129
LC
10917Because the final tool chain does not depend on the bootstrap binaries,
10918those rarely need to be updated. Nevertheless, it is useful to have an
10919automated way to produce them, should an update occur, and this is what
10920the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 10921
cf4a9129
LC
10922The following command builds the tarballs containing the bootstrap
10923binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
10924of Coreutils and other basic command-line tools):
4b2615e1 10925
cf4a9129
LC
10926@example
10927guix build bootstrap-tarballs
10928@end example
10929
10930The generated tarballs are those that should be referred to in the
10931@code{(gnu packages bootstrap)} module mentioned at the beginning of
10932this section.
10933
10934Still here? Then perhaps by now you've started to wonder: when do we
10935reach a fixed point? That is an interesting question! The answer is
10936unknown, but if you would like to investigate further (and have
10937significant computational and storage resources to do so), then let us
10938know.
10939
10940@node Porting
10941@section Porting to a New Platform
10942
10943As discussed above, the GNU distribution is self-contained, and
10944self-containment is achieved by relying on pre-built ``bootstrap
10945binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
10946operating system kernel, CPU architecture, and application binary
10947interface (ABI). Thus, to port the distribution to a platform that is
10948not yet supported, one must build those bootstrap binaries, and update
10949the @code{(gnu packages bootstrap)} module to use them on that platform.
10950
10951Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
10952When everything goes well, and assuming the GNU tool chain supports the
10953target platform, this can be as simple as running a command like this
10954one:
10955
10956@example
10957guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
10958@end example
10959
1c0c417d
LC
10960For this to work, the @code{glibc-dynamic-linker} procedure in
10961@code{(gnu packages bootstrap)} must be augmented to return the right
10962file name for libc's dynamic linker on that platform; likewise,
10963@code{system->linux-architecture} in @code{(gnu packages linux)} must be
10964taught about the new platform.
10965
cf4a9129 10966Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
10967to be updated to refer to these binaries on the target platform. That
10968is, the hashes and URLs of the bootstrap tarballs for the new platform
10969must be added alongside those of the currently supported platforms. The
10970bootstrap Guile tarball is treated specially: it is expected to be
10971available locally, and @file{gnu-system.am} has rules do download it for
10972the supported architectures; a rule for the new platform must be added
10973as well.
cf4a9129
LC
10974
10975In practice, there may be some complications. First, it may be that the
10976extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
10977above) is not recognized by all the GNU tools. Typically, glibc
10978recognizes some of these, whereas GCC uses an extra @code{--with-abi}
10979configure flag (see @code{gcc.scm} for examples of how to handle this).
10980Second, some of the required packages could fail to build for that
10981platform. Lastly, the generated binaries could be broken for some
10982reason.
4af2447e 10983
9bf3c1a7 10984@c *********************************************************************
8c01b9d0 10985@include contributing.texi
c78bd12b 10986
568717fd
LC
10987@c *********************************************************************
10988@node Acknowledgments
10989@chapter Acknowledgments
10990
136787cb
LC
10991Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
10992which was designed and
4c7ac9aa
LC
10993implemented by Eelco Dolstra, with contributions from other people (see
10994the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
10995management, and promoted unprecedented features, such as transactional
10996package upgrades and rollbacks, per-user profiles, and referentially
10997transparent build processes. Without this work, Guix would not exist.
10998
10999The Nix-based software distributions, Nixpkgs and NixOS, have also been
11000an inspiration for Guix.
11001
4c7ac9aa
LC
11002GNU@tie{}Guix itself is a collective work with contributions from a
11003number of people. See the @file{AUTHORS} file in Guix for more
11004information on these fine people. The @file{THANKS} file lists people
11005who have helped by reporting bugs, taking care of the infrastructure,
11006providing artwork and themes, making suggestions, and more---thank you!
11007
11008
568717fd
LC
11009@c *********************************************************************
11010@node GNU Free Documentation License
11011@appendix GNU Free Documentation License
11012
11013@include fdl-1.3.texi
11014
11015@c *********************************************************************
11016@node Concept Index
11017@unnumbered Concept Index
11018@printindex cp
11019
a85b83d2
LC
11020@node Programming Index
11021@unnumbered Programming Index
11022@syncodeindex tp fn
11023@syncodeindex vr fn
568717fd
LC
11024@printindex fn
11025
11026@bye
11027
11028@c Local Variables:
11029@c ispell-local-dictionary: "american";
11030@c End: