Add system start-up files for "guix publish".
[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 11
debc6360 12@c Identifier of the OpenPGP key used to sign tarballs and such.
5564c011 13@set OPENPGP-SIGNING-KEY-ID 3CE464558A84FDC69DB40CFB090B11993D9AEBB5
debc6360 14
7df7a74e 15@copying
db5a9444 16Copyright @copyright{} 2012, 2013, 2014, 2015, 2016 Ludovic Courtès@*
f97c9175 17Copyright @copyright{} 2013, 2014, 2016 Andreas Enge@*
87eafdbd 18Copyright @copyright{} 2013 Nikita Karetnikov@*
1a3e6b15 19Copyright @copyright{} 2014, 2015, 2016 Alex Kost@*
1b846da8 20Copyright @copyright{} 2015, 2016 Mathieu Lirzin@*
8c01b9d0 21Copyright @copyright{} 2014 Pierre-Antoine Rault@*
97d76250 22Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer@*
4d343a14 23Copyright @copyright{} 2015, 2016 Leo Famulari@*
909147e4 24Copyright @copyright{} 2015, 2016 Ricardo Wurmus@*
4d343a14 25Copyright @copyright{} 2016 Ben Woodcroft@*
76192896 26Copyright @copyright{} 2016 Chris Marusich@*
6e42660b 27Copyright @copyright{} 2016 Efraim Flashner@*
d6a07ee6 28Copyright @copyright{} 2016 John Darrington@*
92c03a87 29Copyright @copyright{} 2016 ng0@*
8c00b838
JL
30Copyright @copyright{} 2016 Jan Nieuwenhuizen@*
31Copyright @copyright{} 2016 Julien Lepiller
7df7a74e
NK
32
33Permission is granted to copy, distribute and/or modify this document
34under the terms of the GNU Free Documentation License, Version 1.3 or
35any later version published by the Free Software Foundation; with no
36Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
37copy of the license is included in the section entitled ``GNU Free
38Documentation License''.
39@end copying
568717fd 40
abd67856 41@dircategory System administration
568717fd 42@direntry
abd67856
LC
43* Guix: (guix). Manage installed software and system configuration.
44* guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
45* guix build: (guix)Invoking guix build. Building packages.
46* guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
47* guix pull: (guix)Invoking guix pull. Update the list of available packages.
48* guix system: (guix)Invoking guix system. Manage the operating system configuration.
568717fd 49@end direntry
568717fd 50
372c4bbc
DT
51@dircategory Software development
52@direntry
abd67856 53* guix environment: (guix)Invoking guix environment. Building development environments with Guix.
372c4bbc
DT
54@end direntry
55
abd67856
LC
56@dircategory Emacs
57@direntry
58* Guix user interface: (guix)Emacs Interface. Package management from the comfort of Emacs.
59@end direntry
60
61
568717fd 62@titlepage
7730d112
LC
63@title GNU Guix Reference Manual
64@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 65@author The GNU Guix Developers
568717fd
LC
66
67@page
68@vskip 0pt plus 1filll
69Edition @value{EDITION} @*
70@value{UPDATED} @*
71
7df7a74e 72@insertcopying
568717fd
LC
73@end titlepage
74
568717fd
LC
75@contents
76
77@c *********************************************************************
78@node Top
f8348b91 79@top GNU Guix
568717fd 80
f8348b91
LC
81This document describes GNU Guix version @value{VERSION}, a functional
82package management tool written for the GNU system.
568717fd
LC
83
84@menu
85* Introduction:: What is Guix about?
bd5e766b 86* Installation:: Installing Guix.
eeaf4427 87* Package Management:: Package installation, upgrade, etc.
c554de89 88* Emacs Interface:: Using Guix from Emacs.
568717fd
LC
89* Programming Interface:: Using Guix in Scheme.
90* Utilities:: Package management commands.
a1ba8475 91* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 92* Contributing:: Your help needed!
568717fd
LC
93
94* Acknowledgments:: Thanks!
95* GNU Free Documentation License:: The license of this manual.
96* Concept Index:: Concepts.
a85b83d2 97* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
98
99@detailmenu
100 --- The Detailed Node Listing ---
101
102Installation
103
1b2b8177 104* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 105* Requirements:: Software needed to build and run Guix.
ec0339cd 106* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
107* Setting Up the Daemon:: Preparing the build daemon's environment.
108* Invoking guix-daemon:: Running the build daemon.
0e2d0213 109* Application Setup:: Application-specific setup.
aaa3eaa9
LC
110
111Setting Up the Daemon
112
113* Build Environment Setup:: Preparing the isolated build environment.
114* Daemon Offload Setup:: Offloading builds to remote machines.
115
116Package Management
117
118* Features:: How Guix will make your life brighter.
119* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
120* Substitutes:: Downloading pre-built binaries.
121* Packages with Multiple Outputs:: Single source package, multiple outputs.
122* Invoking guix gc:: Running the garbage collector.
123* Invoking guix pull:: Fetching the latest Guix and distribution.
124* Invoking guix archive:: Exporting and importing store files.
125
c554de89
AK
126Emacs Interface
127
128* Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}.
129* Package Management: Emacs Package Management. Managing packages and generations.
687c9bc0 130* Licenses: Emacs Licenses. Interface for licenses of Guix packages.
b5e3cbbb 131* Package Source Locations: Emacs Package Locations. Interface for package location files.
9b0afb0d 132* Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands.
c554de89 133* Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names.
34850cd5 134* Build Log Mode: Emacs Build Log. Highlighting Guix build logs.
187f80c6
AK
135* Completions: Emacs Completions. Completing @command{guix} shell command.
136* Development: Emacs Development. Tools for Guix developers.
32950fc8 137* Hydra: Emacs Hydra. Interface for Guix build farm.
c554de89 138
aaa3eaa9
LC
139Programming Interface
140
141* Defining Packages:: Defining new packages.
142* Build Systems:: Specifying how packages are built.
143* The Store:: Manipulating the package store.
144* Derivations:: Low-level interface to package derivations.
145* The Store Monad:: Purely functional interface to the store.
146* G-Expressions:: Manipulating build expressions.
147
92492b23
LC
148Defining Packages
149
150* package Reference:: The package data type.
151* origin Reference:: The origin data type.
152
aaa3eaa9
LC
153Utilities
154
155* Invoking guix build:: Building packages from the command line.
fcc58db6 156* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
157* Invoking guix download:: Downloading a file and printing its hash.
158* Invoking guix hash:: Computing the cryptographic hash of a file.
159* Invoking guix import:: Importing package definitions.
160* Invoking guix refresh:: Updating package definitions.
161* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 162* Invoking guix size:: Profiling disk usage.
88856916 163* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 164* Invoking guix environment:: Setting up development environments.
aff8ce7c 165* Invoking guix publish:: Sharing substitutes.
d23c20f1 166* Invoking guix challenge:: Challenging substitute servers.
32efa254 167* Invoking guix container:: Process isolation.
aaa3eaa9 168
e3009f60
LC
169Invoking @command{guix build}
170
171* Common Build Options:: Build options for most commands.
172* Package Transformation Options:: Creating variants of packages.
173* Additional Build Options:: Options specific to 'guix build'.
174
aaa3eaa9
LC
175GNU Distribution
176
177* System Installation:: Installing the whole operating system.
35ed9306 178* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
179* Installing Debugging Files:: Feeding the debugger.
180* Security Updates:: Deploying security fixes quickly.
181* Package Modules:: Packages from the programmer's viewpoint.
182* Packaging Guidelines:: Growing the distribution.
183* Bootstrapping:: GNU/Linux built from scratch.
184* Porting:: Targeting another platform or kernel.
185
e3009f60
LC
186System Installation
187
188* Limitations:: What you can expect.
189* Hardware Considerations:: Supported hardware.
190* USB Stick Installation:: Preparing the installation medium.
191* Preparing for Installation:: Networking, partitioning, etc.
192* Proceeding with the Installation:: The real thing.
c8b54374 193* Installing GuixSD in a VM:: GuixSD playground.
e3009f60
LC
194* Building the Installation Image:: How this comes to be.
195
aaa3eaa9
LC
196System Configuration
197
198* Using the Configuration System:: Customizing your GNU system.
199* operating-system Reference:: Detail of operating-system declarations.
200* File Systems:: Configuring file system mounts.
201* Mapped Devices:: Block device extra processing.
202* User Accounts:: Specifying user accounts.
598e19dc 203* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
204* Services:: Specifying system services.
205* Setuid Programs:: Programs running with root privileges.
1b2b8177 206* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 207* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
208* Initial RAM Disk:: Linux-Libre bootstrapping.
209* GRUB Configuration:: Configuring the boot loader.
210* Invoking guix system:: Instantiating a system configuration.
97d76250 211* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
aaa3eaa9
LC
212* Defining Services:: Adding new service definitions.
213
214Services
215
216* Base Services:: Essential system services.
c311089b 217* Scheduled Job Execution:: The mcron service.
92c03a87 218* Log Rotation:: The rottlog service.
aaa3eaa9
LC
219* Networking Services:: Network setup, SSH daemon, etc.
220* X Window:: Graphical display.
1b2b8177
LC
221* Desktop Services:: D-Bus and desktop services.
222* Database Services:: SQL databases.
d8c18af8 223* Mail Services:: IMAP, POP3, SMTP, and all that.
859e367d 224* Kerberos Services:: Kerberos services.
cbd02397 225* Web Services:: Web servers.
eb419bc9 226* Network File System:: NFS related services.
dbc6d370 227* Miscellaneous Services:: Other services.
aaa3eaa9 228
0adfe95a
LC
229Defining Services
230
231* Service Composition:: The model for composing services.
232* Service Types and Services:: Types and services.
233* Service Reference:: API reference.
dd17bc38 234* Shepherd Services:: A particular type of service.
0adfe95a 235
aaa3eaa9
LC
236Packaging Guidelines
237
ec0339cd
LC
238* Software Freedom:: What may go into the distribution.
239* Package Naming:: What's in a name?
240* Version Numbers:: When the name is not enough.
cbd02397 241* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
242* Python Modules:: Taming the snake.
243* Perl Modules:: Little pearls.
e1c963bf 244* Java Packages:: Coffee break.
ec0339cd 245* Fonts:: Fond of fonts.
aaa3eaa9 246
8c01b9d0
ML
247Contributing
248
249* Building from Git:: The latest and greatest.
250* Running Guix Before It Is Installed:: Hacker tricks.
251* The Perfect Setup:: The right tools.
252* Coding Style:: Hygiene of the contributor.
253* Submitting Patches:: Share your work.
254
255Coding Style
256
257* Programming Paradigm:: How to compose your elements.
258* Modules:: Where to store your code?
259* Data Types and Pattern Matching:: Implementing data structures.
260* Formatting Code:: Writing conventions.
261
aaa3eaa9 262@end detailmenu
568717fd
LC
263@end menu
264
265@c *********************************************************************
266@node Introduction
267@chapter Introduction
268
6f773606 269@cindex purpose
c80e7e55 270GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
6f773606
LC
271using the international phonetic alphabet (IPA).} is a package
272management tool for the GNU system. Guix makes it easy for unprivileged
273users to install, upgrade, or remove packages, to roll back to a
274previous package set, to build packages from source, and generally
275assists with the creation and maintenance of software environments.
276
277@cindex user interfaces
278Guix provides a command-line package management interface
279(@pxref{Invoking guix package}), a set of command-line utilities
280(@pxref{Utilities}), a visual user interface in Emacs (@pxref{Emacs
281Interface}), as well as Scheme programming interfaces
282(@pxref{Programming Interface}).
283@cindex build daemon
284Its @dfn{build daemon} is responsible for building packages on behalf of
285users (@pxref{Setting Up the Daemon}) and for downloading pre-built
286binaries from authorized sources (@pxref{Substitutes}).
287
288@cindex extensibility of the distribution
e32171ee 289@cindex customization, of packages
6f773606
LC
290Guix includes package definitions for many GNU and non-GNU packages, all
291of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
292user's computing freedom}. It is @emph{extensible}: users can write
293their own package definitions (@pxref{Defining Packages}) and make them
294available as independent package modules (@pxref{Package Modules}). It
295is also @emph{customizable}: users can @emph{derive} specialized package
296definitions from existing ones, including from the command line
297(@pxref{Package Transformation Options}).
298
299@cindex Guix System Distribution
300@cindex GuixSD
301You can install GNU@tie{}Guix on top of an existing GNU/Linux system
302where it complements the available tools without interference
303(@pxref{Installation}), or you can use it as part of the standalone
304@dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
305With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
306system configuration and Guix takes care of instantiating the
307configuration in a transactional, reproducible, and stateless fashion
308(@pxref{System Configuration}).
568717fd
LC
309
310@cindex functional package management
6f773606 311Under the hood, Guix implements the @dfn{functional package management}
136787cb
LC
312discipline pioneered by Nix (@pxref{Acknowledgments}).
313In Guix, the package build and installation process is seen
6f773606 314as a @emph{function}, in the mathematical sense. That function takes inputs,
4bfc4ea3
NK
315such as build scripts, a compiler, and libraries, and
316returns an installed package. As a pure function, its result depends
568717fd
LC
317solely on its inputs---for instance, it cannot refer to software or
318scripts that were not explicitly passed as inputs. A build function
4bfc4ea3 319always produces the same result when passed a given set of inputs. It
f97c9175 320cannot alter the environment of the running system in
568717fd
LC
321any way; for instance, it cannot create, modify, or delete files outside
322of its build and installation directories. This is achieved by running
e900c503 323build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 324explicit inputs are visible.
568717fd 325
e531ac2a 326@cindex store
568717fd 327The result of package build functions is @dfn{cached} in the file
e531ac2a 328system, in a special directory called @dfn{the store} (@pxref{The
f97c9175 329Store}). Each package is installed in a directory of its own in the
834129e0 330store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
331a hash of all the inputs used to build that package; thus, changing an
332input yields a different directory name.
333
f97c9175
AE
334This approach is the foundation for the salient features of Guix: support
335for transactional package upgrade and rollback, per-user installation, and
eeaf4427 336garbage collection of packages (@pxref{Features}).
568717fd 337
a1ba8475 338
bd5e766b
LC
339@c *********************************************************************
340@node Installation
341@chapter Installation
342
e32171ee 343@cindex installing Guix
48febeb8
LC
344GNU Guix is available for download from its website at
345@url{http://www.gnu.org/software/guix/}. This section describes the
346software requirements of Guix, as well as how to install it and get
347ready to use it.
bd5e766b 348
5af6de3e
LC
349Note that this section is concerned with the installation of the package
350manager, which can be done on top of a running GNU/Linux system. If,
351instead, you want to install the complete GNU operating system,
6621cdb6 352@pxref{System Installation}.
5af6de3e 353
d23ef788
LC
354@cindex foreign distro
355When installed on a running GNU/Linux system---thereafter called a
356@dfn{foreign distro}---GNU@tie{}Guix complements the available tools
357without interference. Its data lives exclusively in two directories,
358usually @file{/gnu/store} and @file{/var/guix}; other files on your
359system, such as @file{/etc}, are left untouched.
360
bd5e766b 361@menu
09722b11 362* Binary Installation:: Getting Guix running in no time!
bd5e766b 363* Requirements:: Software needed to build and run Guix.
ec0339cd 364* Running the Test Suite:: Testing Guix.
bd5e766b
LC
365* Setting Up the Daemon:: Preparing the build daemon's environment.
366* Invoking guix-daemon:: Running the build daemon.
0e2d0213 367* Application Setup:: Application-specific setup.
bd5e766b
LC
368@end menu
369
09722b11
LC
370@node Binary Installation
371@section Binary Installation
372
e32171ee 373@cindex installing Guix from binaries
09722b11
LC
374This section describes how to install Guix on an arbitrary system from a
375self-contained tarball providing binaries for Guix and for all its
376dependencies. This is often quicker than installing from source, which
377is described in the next sections. The only requirement is to have
378GNU@tie{}tar and Xz.
379
380Installing goes along these lines:
381
382@enumerate
383@item
e32171ee 384@cindex downloading Guix binary
09722b11 385Download the binary tarball from
daa8922a
LC
386@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
387where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
388already running the kernel Linux, and so on.
389
debc6360 390@c The following is somewhat duplicated in ``System Installation''.
daa8922a
LC
391Make sure to download the associated @file{.sig} file and to verify the
392authenticity of the tarball against it, along these lines:
393
394@example
395$ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
396$ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
397@end example
398
f97c9175 399If that command fails because you do not have the required public key,
daa8922a
LC
400then run this command to import it:
401
402@example
debc6360 403$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
daa8922a
LC
404@end example
405
406@noindent
407and rerun the @code{gpg --verify} command.
debc6360 408@c end authentication part
09722b11
LC
409
410@item
411As @code{root}, run:
412
413@example
5dc42964 414# cd /tmp
254b1c2e
LC
415# tar --warning=no-timestamp -xf \
416 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 417# mv var/guix /var/ && mv gnu /
09722b11
LC
418@end example
419
7acd3439
LC
420This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
421The latter contains a ready-to-use profile for @code{root} (see next
422step.)
09722b11 423
5dc3ce5f
LC
424Do @emph{not} unpack the tarball on a working Guix system since that
425would overwrite its own essential files.
426
254b1c2e 427The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
428not emit warnings about ``implausibly old time stamps'' (such
429warnings were triggered by GNU@tie{}tar 1.26 and older; recent
430versions are fine.)
431They stem from the fact that all the
254b1c2e
LC
432files in the archive have their modification time set to zero (which
433means January 1st, 1970.) This is done on purpose to make sure the
434archive content is independent of its creation time, thus making it
435reproducible.
436
7acd3439
LC
437@item
438Make @code{root}'s profile available under @file{~/.guix-profile}:
439
440@example
441# ln -sf /var/guix/profiles/per-user/root/guix-profile \
442 ~root/.guix-profile
443@end example
444
43c33047
LC
445@item
446Create the group and user accounts for build users as explained below
447(@pxref{Build Environment Setup}).
448
09722b11 449@item
bf98aea9 450Run the daemon, and set it to automatically start on boot.
c8e26887 451
bf98aea9
LC
452If your host distro uses the systemd init system, this can be achieved
453with these commands:
c8e26887
GC
454
455@example
b7230de5 456# ln -s ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
c8e26887
GC
457 /etc/systemd/system/
458# systemctl start guix-daemon && systemctl enable guix-daemon
459@end example
460
461If your host distro uses the Upstart init system:
09722b11
LC
462
463@example
b7230de5 464# ln -s ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
bf98aea9 465# start guix-daemon
09722b11
LC
466@end example
467
c8e26887
GC
468Otherwise, you can still start the daemon manually with:
469
470@example
471# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
472@end example
d2825c96 473
09722b11
LC
474@item
475Make the @command{guix} command available to other users on the machine,
476for instance with:
477
478@example
479# mkdir -p /usr/local/bin
480# cd /usr/local/bin
d72d05f9 481# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 482@end example
39f8ed14 483
aca738f3
LC
484It is also a good idea to make the Info version of this manual available
485there:
486
487@example
488# mkdir -p /usr/local/share/info
489# cd /usr/local/share/info
490# for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
491 do ln -s $i ; done
492@end example
493
494That way, assuming @file{/usr/local/share/info} is in the search path,
495running @command{info guix} will open this manual (@pxref{Other Info
496Directories,,, texinfo, GNU Texinfo}, for more details on changing the
497Info search path.)
498
39f8ed14 499@item
e32171ee 500@cindex substitutes, authorization thereof
df061d07
LC
501To use substitutes from @code{hydra.gnu.org} or one of its mirrors
502(@pxref{Substitutes}), authorize them:
39f8ed14
LC
503
504@example
7acd3439 505# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 506@end example
09722b11
LC
507@end enumerate
508
bf98aea9 509This completes root-level install of Guix. Each user will need to
7414de0a 510perform additional steps to make their Guix environment ready for use,
c8e26887 511@pxref{Application Setup}.
09722b11 512
c8e26887
GC
513You can confirm that Guix is working by installing a sample package into
514the root profile:
09722b11
LC
515
516@example
c8e26887 517# guix package -i hello
09722b11
LC
518@end example
519
c8e26887
GC
520The @code{guix} package must remain available in @code{root}'s profile,
521or it would become subject to garbage collection---in which case you
522would find yourself badly handicapped by the lack of the @command{guix}
bf98aea9
LC
523command. In other words, do not remove @code{guix} by running
524@code{guix package -r guix}.
525
526The binary installation tarball can be (re)produced and verified simply
527by running the following command in the Guix source tree:
528
529@example
530make guix-binary.@var{system}.tar.xz
531@end example
c8e26887 532
09722b11 533
bd5e766b
LC
534@node Requirements
535@section Requirements
536
09722b11
LC
537This section lists requirements when building Guix from source. The
538build procedure for Guix is the same as for other GNU software, and is
539not covered here. Please see the files @file{README} and @file{INSTALL}
540in the Guix source tree for additional details.
541
bd5e766b
LC
542GNU Guix depends on the following packages:
543
544@itemize
47c66da0 545@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 546@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 547@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
548@end itemize
549
550The following dependencies are optional:
551
552@itemize
9b7bd1b1
LC
553@item
554Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
555access @code{https} URLs for substitutes, which is highly recommended
556(@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
557@command{guix download} command (@pxref{Invoking guix download}), the
558@command{guix import pypi} command, and the @command{guix import cpan}
559command. @xref{Guile Preparations, how to install the GnuTLS bindings
560for Guile,, gnutls-guile, GnuTLS-Guile}.
561
288dca55 562@item
8a96bd4b 563Installing
288dca55 564@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
565allow you to use the @command{guix import pypi} command (@pxref{Invoking
566guix import}). It is of
288dca55 567interest primarily for developers and not for casual users.
4591c02e
LC
568
569@item
570When @url{http://zlib.net, zlib} is available, @command{guix publish}
571can compress build byproducts (@pxref{Invoking guix publish}).
bd5e766b
LC
572@end itemize
573
574Unless @code{--disable-daemon} was passed to @command{configure}, the
575following packages are also needed:
576
577@itemize
368d08f7
LC
578@item @url{http://sqlite.org, SQLite 3};
579@item @url{http://www.bzip.org, libbz2};
580@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
581C++11 standard.
bd5e766b
LC
582@end itemize
583
e32171ee 584@cindex state directory
ef5f5c86
LC
585When configuring Guix on a system that already has a Guix installation,
586be sure to specify the same state directory as the existing installation
587using the @code{--localstatedir} option of the @command{configure}
588script (@pxref{Directory Variables, @code{localstatedir},, standards,
589GNU Coding Standards}). The @command{configure} script protects against
590unintended misconfiguration of @var{localstatedir} so you do not
591inadvertently corrupt your store (@pxref{The Store}).
592
e32171ee 593@cindex Nix, compatibility
4bfc4ea3
NK
594When a working installation of @url{http://nixos.org/nix/, the Nix package
595manager} is available, you
bd5e766b 596can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 597Nix replaces the three dependencies above.
bd5e766b 598
b22a12fd
LC
599Guix is compatible with Nix, so it is possible to share the same store
600between both. To do so, you must pass @command{configure} not only the
601same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
602@code{--localstatedir} value. The latter is essential because it
603specifies where the database that stores metadata about the store is
834129e0 604located, among other things. The default values for Nix are
b22a12fd 605@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
606Note that @code{--disable-daemon} is not required if
607your goal is to share the store with Nix.
b22a12fd 608
ec0339cd
LC
609@node Running the Test Suite
610@section Running the Test Suite
611
e32171ee 612@cindex test suite
ec0339cd
LC
613After a successful @command{configure} and @code{make} run, it is a good
614idea to run the test suite. It can help catch issues with the setup or
615environment, or bugs in Guix itself---and really, reporting test
616failures is a good way to help improve the software. To run the test
617suite, type:
618
619@example
620make check
621@end example
622
623Test cases can run in parallel: you can use the @code{-j} option of
624GNU@tie{}make to speed things up. The first run may take a few minutes
625on a recent machine; subsequent runs will be faster because the store
626that is created for test purposes will already have various things in
627cache.
628
a887fd8d
LC
629It is also possible to run a subset of the tests by defining the
630@code{TESTS} makefile variable as in this example:
631
632@example
633make check TESTS="tests/store.scm tests/cpio.scm"
634@end example
635
a9edb211
ML
636By default, tests results are displayed at a file level. In order to
637see the details of every individual test cases, it is possible to define
638the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
639
640@example
641make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
642@end example
643
ec0339cd 644Upon failure, please email @email{bug-guix@@gnu.org} and attach the
a9edb211
ML
645@file{test-suite.log} file. Please specify the Guix version being used
646as well as version numbers of the dependencies (@pxref{Requirements}) in
647your message.
ec0339cd 648
0a2f2848
LC
649Guix also comes with a whole-system test suite that tests complete
650GuixSD operating system instances. It can only run on systems where
651Guix is already installed, using:
652
653@example
654make check-system
655@end example
656
657@noindent
658or, again, by defining @code{TESTS} to select a subset of tests to run:
659
660@example
661make check-system TESTS="basic mcron"
662@end example
663
664These system tests are defined in the @code{(gnu tests @dots{})}
665modules. They work by running the operating systems under test with
666lightweight instrumentation in a virtual machine (VM). They can be
667computationally intensive or rather cheap, depending on whether
668substitutes are available for their dependencies (@pxref{Substitutes}).
669Some of them require a lot of storage space to hold VM images.
670
671Again in case of test failures, please send @email{bug-guix@@gnu.org}
672all the details.
673
bd5e766b
LC
674@node Setting Up the Daemon
675@section Setting Up the Daemon
676
677@cindex daemon
678Operations such as building a package or running the garbage collector
49e6291a 679are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
680behalf of clients. Only the daemon may access the store and its
681associated database. Thus, any operation that manipulates the store
682goes through the daemon. For instance, command-line tools such as
e49951eb 683@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
684daemon (@i{via} remote procedure calls) to instruct it what to do.
685
49e6291a 686The following sections explain how to prepare the build daemon's
f97c9175 687environment. See also @ref{Substitutes}, for information on how to allow
225dafde 688the daemon to download pre-built binaries.
49e6291a
LC
689
690@menu
691* Build Environment Setup:: Preparing the isolated build environment.
692* Daemon Offload Setup:: Offloading builds to remote machines.
693@end menu
694
695@node Build Environment Setup
696@subsection Build Environment Setup
697
e32171ee 698@cindex build environment
bd5e766b
LC
699In a standard multi-user setup, Guix and its daemon---the
700@command{guix-daemon} program---are installed by the system
834129e0 701administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
702@command{guix-daemon} runs as @code{root}. Unprivileged users may use
703Guix tools to build packages or otherwise access the store, and the
704daemon will do it on their behalf, ensuring that the store is kept in a
705consistent state, and allowing built packages to be shared among users.
706
707@cindex build users
708When @command{guix-daemon} runs as @code{root}, you may not want package
709build processes themselves to run as @code{root} too, for obvious
710security reasons. To avoid that, a special pool of @dfn{build users}
711should be created for use by build processes started by the daemon.
712These build users need not have a shell and a home directory: they will
713just be used when the daemon drops @code{root} privileges in build
714processes. Having several such users allows the daemon to launch
715distinct build processes under separate UIDs, which guarantees that they
716do not interfere with each other---an essential feature since builds are
717regarded as pure functions (@pxref{Introduction}).
718
719On a GNU/Linux system, a build user pool may be created like this (using
720Bash syntax and the @code{shadow} commands):
721
091196b3
LC
722@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
723@c for why `-G' is needed.
bd5e766b 724@example
cfc149dc
LC
725# groupadd --system guixbuild
726# for i in `seq -w 1 10`;
bd5e766b 727 do
cfc149dc
LC
728 useradd -g guixbuild -G guixbuild \
729 -d /var/empty -s `which nologin` \
730 -c "Guix build user $i" --system \
731 guixbuilder$i;
bd5e766b
LC
732 done
733@end example
734
735@noindent
54eb03ab
LC
736The number of build users determines how many build jobs may run in
737parallel, as specified by the @option{--max-jobs} option
eca69fc0
LC
738(@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
739@command{guix system vm} and related commands, you may need to add the
740build users to the @code{kvm} group so they can access @file{/dev/kvm},
741using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
742(@pxref{Invoking guix system}).
743
744The @code{guix-daemon} program may then be run as @code{root} with the
d2825c96
LC
745following command@footnote{If your machine uses the systemd init system,
746dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
747file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
748@command{guix-daemon} is automatically started. Similarly, if your
749machine uses the Upstart init system, drop the
750@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
751file in @file{/etc/init}.}:
bd5e766b
LC
752
753@example
cfc149dc 754# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
755@end example
756
e900c503 757@cindex chroot
b095792f
LC
758@noindent
759This way, the daemon starts build processes in a chroot, under one of
cfc149dc 760the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
761environment contains nothing but:
762
763@c Keep this list in sync with libstore/build.cc! -----------------------
764@itemize
765@item
4743a4da
LC
766a minimal @code{/dev} directory, created mostly independently from the
767host @code{/dev}@footnote{``Mostly'', because while the set of files
768that appear in the chroot's @code{/dev} is fixed, most of these files
769can only be created if the host has them.};
770
771@item
f97c9175 772the @code{/proc} directory; it only shows the processes of the container
4743a4da 773since a separate PID name space is used;
6dc99317
LC
774
775@item
776@file{/etc/passwd} with an entry for the current user and an entry for
777user @file{nobody};
778
779@item
780@file{/etc/group} with an entry for the user's group;
781
782@item
783@file{/etc/hosts} with an entry that maps @code{localhost} to
784@code{127.0.0.1};
785
786@item
787a writable @file{/tmp} directory.
788@end itemize
b095792f 789
cb960102
ED
790You can influence the directory where the daemon stores build trees
791@i{via} the @code{TMPDIR} environment variable. However, the build tree
f97c9175 792within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
793where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
794This way, the value of @code{TMPDIR} does not leak inside build
795environments, which avoids discrepancies in cases where build processes
796capture the name of their build tree.
797
e0c941fe
LC
798@vindex http_proxy
799The daemon also honors the @code{http_proxy} environment variable for
800HTTP downloads it performs, be it for fixed-output derivations
801(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
802
1e2644bb
LC
803If you are installing Guix as an unprivileged user, it is still possible
804to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
805However, build processes will not be isolated from one another, and not
806from the rest of the system. Thus, build processes may interfere with
807each other, and may access programs, libraries, and other files
808available on the system---making it much harder to view them as
809@emph{pure} functions.
bd5e766b 810
49e6291a
LC
811
812@node Daemon Offload Setup
813@subsection Using the Offload Facility
814
815@cindex offloading
4ec2e92d
LC
816@cindex build hook
817When desired, the build daemon can @dfn{offload}
818derivation builds to other machines
49e6291a
LC
819running Guix, using the @code{offload} @dfn{build hook}. When that
820feature is enabled, a list of user-specified build machines is read from
f97c9175 821@file{/etc/guix/machines.scm}; every time a build is requested, for
49e6291a 822instance via @code{guix build}, the daemon attempts to offload it to one
f97c9175 823of the machines that satisfy the constraints of the derivation, in
49e6291a
LC
824particular its system type---e.g., @file{x86_64-linux}. Missing
825prerequisites for the build are copied over SSH to the target machine,
826which then proceeds with the build; upon success the output(s) of the
827build are copied back to the initial machine.
828
4ec2e92d 829The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
830
831@example
832(list (build-machine
833 (name "eightysix.example.org")
834 (system "x86_64-linux")
835 (user "bob")
836 (speed 2.)) ; incredibly fast!
837
838 (build-machine
839 (name "meeps.example.org")
840 (system "mips64el-linux")
841 (user "alice")
842 (private-key
843 (string-append (getenv "HOME")
c4fdfd6f 844 "/.lsh/identity-for-guix"))))
49e6291a
LC
845@end example
846
847@noindent
848In the example above we specify a list of two build machines, one for
849the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
850architecture.
851
852In fact, this file is---not surprisingly!---a Scheme file that is
853evaluated when the @code{offload} hook is started. Its return value
854must be a list of @code{build-machine} objects. While this example
855shows a fixed list of build machines, one could imagine, say, using
856DNS-SD to return a list of potential build machines discovered in the
857local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
858Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
859detailed below.
4ec2e92d 860
c678a4ee 861@deftp {Data Type} build-machine
f97c9175
AE
862This data type represents build machines to which the daemon may offload
863builds. The important fields are:
49e6291a
LC
864
865@table @code
866
867@item name
f97c9175 868The host name of the remote machine.
49e6291a
LC
869
870@item system
f97c9175 871The system type of the remote machine---e.g., @code{"x86_64-linux"}.
49e6291a
LC
872
873@item user
874The user account to use when connecting to the remote machine over SSH.
875Note that the SSH key pair must @emph{not} be passphrase-protected, to
876allow non-interactive logins.
877
878@end table
879
4ec2e92d 880A number of optional fields may be specified:
49e6291a
LC
881
882@table @code
883
cecd72d5 884@item port
f97c9175 885Port number of SSH server on the machine (default: 22).
cecd72d5 886
49e6291a
LC
887@item private-key
888The SSH private key file to use when connecting to the machine.
889
c4fdfd6f
LC
890Currently offloading uses GNU@tie{}lsh as its SSH client
891(@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must
892be an lsh key file. This may change in the future, though.
893
49e6291a
LC
894@item parallel-builds
895The number of builds that may run in parallel on the machine (1 by
896default.)
897
898@item speed
899A ``relative speed factor''. The offload scheduler will tend to prefer
900machines with a higher speed factor.
901
902@item features
903A list of strings denoting specific features supported by the machine.
904An example is @code{"kvm"} for machines that have the KVM Linux modules
905and corresponding hardware support. Derivations can request features by
906name, and they will be scheduled on matching build machines.
907
908@end table
c678a4ee 909@end deftp
49e6291a
LC
910
911The @code{guix} command must be in the search path on the build
912machines, since offloading works by invoking the @code{guix archive} and
c4fdfd6f
LC
913@code{guix build} commands. In addition, the Guix modules must be in
914@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
915this is the case by running:
916
917@example
74273b6f 918lsh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 919@end example
49e6291a 920
f97c9175 921There is one last thing to do once @file{machines.scm} is in place. As
49e6291a 922explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
923between the machine stores. For this to work, you first need to
924generate a key pair on each machine to allow the daemon to export signed
925archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
926
927@example
928# guix archive --generate-key
929@end example
930
931@noindent
c4fdfd6f
LC
932Each build machine must authorize the key of the master machine so that
933it accepts store items it receives from the master:
934
935@example
936# guix archive --authorize < master-public-key.txt
937@end example
938
939@noindent
940Likewise, the master machine must authorize the key of each build machine.
941
942All the fuss with keys is here to express pairwise mutual trust
943relations between the master and the build machines. Concretely, when
944the master receives files from a build machine (and @i{vice versa}), its
945build daemon can make sure they are genuine, have not been tampered
946with, and that they are signed by an authorized key.
49e6291a
LC
947
948
bd5e766b
LC
949@node Invoking guix-daemon
950@section Invoking @command{guix-daemon}
951
952The @command{guix-daemon} program implements all the functionality to
953access the store. This includes launching build processes, running the
954garbage collector, querying the availability of a build result, etc. It
955is normally run as @code{root} like this:
956
957@example
cfc149dc 958# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
959@end example
960
961@noindent
081145cf 962For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 963
e900c503
LC
964@cindex chroot
965@cindex container, build environment
966@cindex build environment
967@cindex reproducible builds
bd5e766b
LC
968By default, @command{guix-daemon} launches build processes under
969different UIDs, taken from the build group specified with
970@code{--build-users-group}. In addition, each build process is run in a
971chroot environment that only contains the subset of the store that the
972build process depends on, as specified by its derivation
973(@pxref{Programming Interface, derivation}), plus a set of specific
974system directories. By default, the latter contains @file{/dev} and
e900c503
LC
975@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
976@dfn{container}: in addition to having its own file system tree, it has
977a separate mount name space, its own PID name space, network name space,
978etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 979
cbc538fe
LC
980When the daemon performs a build on behalf of the user, it creates a
981build directory under @file{/tmp} or under the directory specified by
982its @code{TMPDIR} environment variable; this directory is shared with
983the container for the duration of the build. Be aware that using a
984directory other than @file{/tmp} can affect build results---for example,
985with a longer directory name, a build process that uses Unix-domain
986sockets might hit the name length limitation for @code{sun_path}, which
987it would otherwise not hit.
988
989The build directory is automatically deleted upon completion, unless the
990build failed and the client specified @option{--keep-failed}
991(@pxref{Invoking guix build, @option{--keep-failed}}).
992
bd5e766b
LC
993The following command-line options are supported:
994
995@table @code
996@item --build-users-group=@var{group}
997Take users from @var{group} to run build processes (@pxref{Setting Up
998the Daemon, build users}).
999
6858f9d1 1000@item --no-substitutes
b5385b52 1001@cindex substitutes
6858f9d1 1002Do not use substitutes for build products. That is, always build things
c4202d60
LC
1003locally instead of allowing downloads of pre-built binaries
1004(@pxref{Substitutes}).
6858f9d1 1005
b5385b52
LC
1006By default substitutes are used, unless the client---such as the
1007@command{guix package} command---is explicitly invoked with
1008@code{--no-substitutes}.
1009
1010When the daemon runs with @code{--no-substitutes}, clients can still
1011explicitly enable substitution @i{via} the @code{set-build-options}
1012remote procedure call (@pxref{The Store}).
1013
9176607e 1014@item --substitute-urls=@var{urls}
f8a8e0fe 1015@anchor{daemon-substitute-urls}
9176607e 1016Consider @var{urls} the default whitespace-separated list of substitute
df061d07
LC
1017source URLs. When this option is omitted,
1018@indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
1019(@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
9176607e
LC
1020
1021This means that substitutes may be downloaded from @var{urls}, as long
1022as they are signed by a trusted signature (@pxref{Substitutes}).
1023
4ec2e92d
LC
1024@cindex build hook
1025@item --no-build-hook
1026Do not use the @dfn{build hook}.
1027
1028The build hook is a helper program that the daemon can start and to
1029which it submits build requests. This mechanism is used to offload
1030builds to other machines (@pxref{Daemon Offload Setup}).
1031
bd5e766b
LC
1032@item --cache-failures
1033Cache build failures. By default, only successful builds are cached.
1034
30d9aa54
LC
1035When this option is used, @command{guix gc --list-failures} can be used
1036to query the set of store items marked as failed; @command{guix gc
1037--clear-failures} removes store items from the set of cached failures.
1038@xref{Invoking guix gc}.
1039
bd5e766b
LC
1040@item --cores=@var{n}
1041@itemx -c @var{n}
1042Use @var{n} CPU cores to build each derivation; @code{0} means as many
1043as available.
1044
6efc160e 1045The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
1046as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1047guix build}).
bd5e766b
LC
1048
1049The effect is to define the @code{NIX_BUILD_CORES} environment variable
1050in the build process, which can then use it to exploit internal
1051parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1052
1053@item --max-jobs=@var{n}
1054@itemx -M @var{n}
1055Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
1056@code{1}. Setting it to @code{0} means that no builds will be performed
1057locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1058Setup}), or simply fail.
bd5e766b 1059
ecf84b7c
LC
1060@item --rounds=@var{N}
1061Build each derivation @var{n} times in a row, and raise an error if
1062consecutive build results are not bit-for-bit identical. Note that this
1063setting can be overridden by clients such as @command{guix build}
1064(@pxref{Invoking guix build}).
1065
b4528110
ED
1066When used in conjunction with @option{--keep-failed}, the differing
1067output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1068This makes it easy to look for differences between the two results.
1069
bd5e766b
LC
1070@item --debug
1071Produce debugging output.
1072
1073This is useful to debug daemon start-up issues, but then it may be
1074overridden by clients, for example the @code{--verbosity} option of
e49951eb 1075@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
1076
1077@item --chroot-directory=@var{dir}
1078Add @var{dir} to the build chroot.
1079
1080Doing this may change the result of build processes---for instance if
1081they use optional dependencies found in @var{dir} when it is available,
1082and not otherwise. For that reason, it is not recommended to do so.
1083Instead, make sure that each derivation declares all the inputs that it
1084needs.
1085
1086@item --disable-chroot
1087Disable chroot builds.
1088
1089Using this option is not recommended since, again, it would allow build
1e2644bb
LC
1090processes to gain access to undeclared dependencies. It is necessary,
1091though, when @command{guix-daemon} is running under an unprivileged user
1092account.
bd5e766b
LC
1093
1094@item --disable-log-compression
1095Disable compression of the build logs.
1096
1da983b9
LC
1097Unless @code{--lose-logs} is used, all the build logs are kept in the
1098@var{localstatedir}. To save space, the daemon automatically compresses
1099them with bzip2 by default. This option disables that.
1100
ab3893d7
LC
1101@item --disable-deduplication
1102@cindex deduplication
bd5e766b
LC
1103Disable automatic file ``deduplication'' in the store.
1104
1da983b9 1105By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
1106if a newly added file is identical to another one found in the store,
1107the daemon makes the new file a hard link to the other file. This can
4988dd40 1108noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
1109input/output load at the end of a build process. This option disables
1110this optimization.
1da983b9 1111
6e37066e
LC
1112@item --gc-keep-outputs[=yes|no]
1113Tell whether the garbage collector (GC) must keep outputs of live
1114derivations.
1115
1116When set to ``yes'', the GC will keep the outputs of any live derivation
1117available in the store---the @code{.drv} files. The default is ``no'',
1118meaning that derivation outputs are kept only if they are GC roots.
1119
1120@item --gc-keep-derivations[=yes|no]
1121Tell whether the garbage collector (GC) must keep derivations
1122corresponding to live outputs.
1123
1124When set to ``yes'', as is the case by default, the GC keeps
1125derivations---i.e., @code{.drv} files---as long as at least one of their
1126outputs is live. This allows users to keep track of the origins of
1127items in their store. Setting it to ``no'' saves a bit of disk space.
1128
1129Note that when both @code{--gc-keep-derivations} and
1130@code{--gc-keep-outputs} are used, the effect is to keep all the build
1131prerequisites (the sources, compiler, libraries, and other build-time
1132tools) of live objects in the store, regardless of whether these
1133prerequisites are live. This is convenient for developers since it
1134saves rebuilds or downloads.
1135
bd5e766b
LC
1136@item --impersonate-linux-2.6
1137On Linux-based systems, impersonate Linux 2.6. This means that the
1138kernel's @code{uname} system call will report 2.6 as the release number.
1139
1140This might be helpful to build programs that (usually wrongfully) depend
1141on the kernel version number.
1142
1143@item --lose-logs
1144Do not keep build logs. By default they are kept under
ce33631f 1145@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
1146
1147@item --system=@var{system}
1148Assume @var{system} as the current system type. By default it is the
1149architecture/kernel pair found at configure time, such as
1150@code{x86_64-linux}.
b8d2aa26
LC
1151
1152@item --listen=@var{socket}
1153Listen for connections on @var{socket}, the file name of a Unix-domain
1154socket. The default socket is
1155@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1156useful in exceptional circumstances, such as if you need to run several
1157daemons on the same machine.
bd5e766b
LC
1158@end table
1159
1160
0e2d0213
LC
1161@node Application Setup
1162@section Application Setup
1163
d23ef788 1164@cindex foreign distro
85e57214
LC
1165When using Guix on top of GNU/Linux distribution other than GuixSD---a
1166so-called @dfn{foreign distro}---a few additional steps are needed to
1167get everything in place. Here are some of them.
0e2d0213
LC
1168
1169@subsection Locales
1170
5c3c1427 1171@anchor{locales-and-locpath}
0e2d0213 1172@cindex locales, when not on GuixSD
5c3c1427 1173@vindex LOCPATH
85e57214 1174@vindex GUIX_LOCPATH
f97c9175
AE
1175Packages installed @i{via} Guix will not use the locale data of the
1176host system. Instead, you must first install one of the locale packages
85e57214
LC
1177available with Guix and then define the @code{GUIX_LOCPATH} environment
1178variable:
0e2d0213
LC
1179
1180@example
1181$ guix package -i glibc-locales
85e57214 1182$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1183@end example
1184
1185Note that the @code{glibc-locales} package contains data for all the
1186locales supported by the GNU@tie{}libc and weighs in at around
f97c9175 1187110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
0e2d0213
LC
1188limited to a few UTF-8 locales.
1189
85e57214
LC
1190The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1191(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1192Manual}). There are two important differences though:
1193
1194@enumerate
1195@item
f97c9175 1196@code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
85e57214 1197provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f97c9175 1198to make sure the programs of the foreign distro will not end up loading
85e57214
LC
1199incompatible locale data.
1200
1201@item
1202libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1203@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1204should your Guix profile contain a mixture of programs linked against
1205different libc version, each libc version will only try to load locale
1206data in the right format.
1207@end enumerate
1208
1209This is important because the locale data format used by different libc
1210versions may be incompatible.
1211
0e2d0213
LC
1212@subsection X11 Fonts
1213
e32171ee 1214@cindex fonts
4988dd40 1215The majority of graphical applications use Fontconfig to locate and
f97c9175
AE
1216load fonts and perform X11-client-side rendering. The @code{fontconfig}
1217package in Guix looks for fonts in @file{$HOME/.guix-profile}
0e2d0213 1218by default. Thus, to allow graphical applications installed with Guix
f97c9175 1219to display fonts, you have to install fonts with Guix as well.
0e2d0213 1220Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1221@code{font-gnu-freefont-ttf}.
0e2d0213 1222
5c36edc8
LC
1223To display text written in Chinese languages, Japanese, or Korean in
1224graphical applications, consider installing
1225@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1226has multiple outputs, one per language family (@pxref{Packages with
1227Multiple Outputs}). For instance, the following command installs fonts
1228for Chinese languages:
1229
1230@example
1231guix package -i font-adobe-source-han-sans:cn
1232@end example
1233
e32171ee 1234@cindex @code{xterm}
1a3e6b15
AK
1235Older programs such as @command{xterm} do not use Fontconfig and instead
1236rely on server-side font rendering. Such programs require to specify a
1237full name of a font using XLFD (X Logical Font Description), like this:
1238
1239@example
1240-*-dejavu sans-medium-r-normal-*-*-100-*-*-*-*-*-1
1241@end example
1242
1243To be able to use such full names for the TrueType fonts installed in
1244your Guix profile, you need to extend the font path of the X server:
1245
1246@example
1247xset +fp ~/.guix-profile/share/fonts/truetype
1248@end example
1249
e32171ee 1250@cindex @code{xlsfonts}
1a3e6b15
AK
1251After that, you can run @code{xlsfonts} (from @code{xlsfonts} package)
1252to make sure your TrueType fonts are listed there.
1253
b3129f2b
LC
1254@subsection X.509 Certificates
1255
e32171ee 1256@cindex @code{nss-certs}
b3129f2b
LC
1257The @code{nss-certs} package provides X.509 certificates, which allow
1258programs to authenticate Web servers accessed over HTTPS.
1259
1260When using Guix on a foreign distro, you can install this package and
1261define the relevant environment variables so that packages know where to
80d944b7 1262look for certificates. @xref{X.509 Certificates}, for detailed
b3129f2b
LC
1263information.
1264
6d97319c
AK
1265@subsection Emacs Packages
1266
e32171ee 1267@cindex @code{emacs}
6d97319c
AK
1268When you install Emacs packages with Guix, the elisp files may be placed
1269either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1270sub-directories of
1271@file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1272directory exists because potentially there may exist thousands of Emacs
1273packages and storing all their files in a single directory may be not
1274reliable (because of name conflicts). So we think using a separate
1275directory for each package is a good idea. It is very similar to how
1276the Emacs package system organizes the file structure (@pxref{Package
1277Files,,, emacs, The GNU Emacs Manual}).
1278
1279By default, Emacs (installed with Guix) ``knows'' where these packages
f97c9175 1280are placed, so you do not need to perform any configuration. If, for
6d97319c 1281some reason, you want to avoid auto-loading Emacs packages installed
f97c9175 1282with Guix, you can do so by running Emacs with @code{--no-site-file}
6d97319c
AK
1283option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1284
0e2d0213
LC
1285@c TODO What else?
1286
eeaf4427
LC
1287@c *********************************************************************
1288@node Package Management
1289@chapter Package Management
1290
e32171ee 1291@cindex packages
f8348b91 1292The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427 1293remove software packages, without having to know about their build
f97c9175 1294procedures or dependencies. Guix also goes beyond this obvious set of
eeaf4427
LC
1295features.
1296
1297This chapter describes the main features of Guix, as well as the package
c1941588 1298management tools it provides. Two user interfaces are provided for
c554de89
AK
1299routine package management tasks: A command-line interface described below
1300(@pxref{Invoking guix package, @code{guix package}}), as well as a visual user
1301interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}).
eeaf4427
LC
1302
1303@menu
1304* Features:: How Guix will make your life brighter.
e49951eb 1305* Invoking guix package:: Package installation, removal, etc.
c4202d60 1306* Substitutes:: Downloading pre-built binaries.
760c60d6 1307* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1308* Invoking guix gc:: Running the garbage collector.
f651b477 1309* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1310* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1311@end menu
1312
1313@node Features
1314@section Features
1315
1316When using Guix, each package ends up in the @dfn{package store}, in its
1317own directory---something that resembles
9a130e19
AK
1318@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
1319(note that Guix comes with an Emacs extension to shorten those file
081145cf 1320names, @pxref{Emacs Prettify}.)
eeaf4427
LC
1321
1322Instead of referring to these directories, users have their own
1323@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1324use. These profiles are stored within each user's home directory, at
1325@code{$HOME/.guix-profile}.
eeaf4427 1326
821b0015 1327For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1328@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1329@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1330@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1331simply continues to point to
834129e0 1332@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1333coexist on the same system without any interference.
eeaf4427 1334
e49951eb 1335The @command{guix package} command is the central tool to manage
f97c9175 1336packages (@pxref{Invoking guix package}). It operates on the per-user
821b0015 1337profiles, and can be used @emph{with normal user privileges}.
eeaf4427 1338
e32171ee 1339@cindex transactions
eeaf4427
LC
1340The command provides the obvious install, remove, and upgrade
1341operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1342the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1343@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1344or if a power outage occurs during the transaction, then the user's
1345profile remains in its previous state, and remains usable.
1346
1347In addition, any package transaction may be @emph{rolled back}. So, if,
1348for example, an upgrade installs a new version of a package that turns
1349out to have a serious bug, users may roll back to the previous instance
4af2447e 1350of their profile, which was known to work well. Similarly, the global
6f773606
LC
1351system configuration on GuixSD is subject to
1352transactional upgrades and roll-back
4af2447e 1353(@pxref{Using the Configuration System}).
eeaf4427 1354
f97c9175
AE
1355All packages in the package store may be @emph{garbage-collected}.
1356Guix can determine which packages are still referenced by user
fe8ff028 1357profiles, and remove those that are provably no longer referenced
e49951eb 1358(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1359generations of their profile so that the packages they refer to can be
1360collected.
eeaf4427 1361
e900c503
LC
1362@cindex reproducibility
1363@cindex reproducible builds
eeaf4427
LC
1364Finally, Guix takes a @dfn{purely functional} approach to package
1365management, as described in the introduction (@pxref{Introduction}).
834129e0 1366Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1367inputs that were used to build that package---compiler, libraries, build
1368scripts, etc. This direct correspondence allows users to make sure a
1369given package installation matches the current state of their
e900c503
LC
1370distribution. It also helps maximize @dfn{build reproducibility}:
1371thanks to the isolated build environments that are used, a given build
1372is likely to yield bit-identical files when performed on different
1373machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1374
c4202d60 1375@cindex substitutes
eeaf4427 1376This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1377deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1378available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1379downloads it and unpacks it;
1380otherwise, it builds the package from source, locally
bf9eacd2
LC
1381(@pxref{Substitutes}). Because build results are usually bit-for-bit
1382reproducible, users do not have to trust servers that provide
1383substitutes: they can force a local build and @emph{challenge} providers
1384(@pxref{Invoking guix challenge}).
eeaf4427 1385
f5fd4fd2
LC
1386Control over the build environment is a feature that is also useful for
1387developers. The @command{guix environment} command allows developers of
1388a package to quickly set up the right development environment for their
f97c9175
AE
1389package, without having to manually install the dependencies of the
1390package into their profile (@pxref{Invoking guix environment}).
f5fd4fd2 1391
e49951eb
MW
1392@node Invoking guix package
1393@section Invoking @command{guix package}
eeaf4427 1394
e32171ee
JD
1395@cindex installing packages
1396@cindex removing packages
1397@cindex package installation
1398@cindex package removal
e49951eb 1399The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1400install, upgrade, and remove packages, as well as rolling back to
1401previous configurations. It operates only on the user's own profile,
1402and works with normal user privileges (@pxref{Features}). Its syntax
1403is:
1404
1405@example
e49951eb 1406guix package @var{options}
eeaf4427 1407@end example
e32171ee 1408@cindex transactions
ba55b1cb 1409Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1410the transaction. Upon completion, a new profile is created, but
99bd74d5 1411previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1412want to roll back.
1413
6447738c
MW
1414For example, to remove @code{lua} and install @code{guile} and
1415@code{guile-cairo} in a single transaction:
1416
1417@example
1418guix package -r lua -i guile guile-cairo
1419@end example
1420
99bd74d5
LC
1421@command{guix package} also supports a @dfn{declarative approach}
1422whereby the user specifies the exact set of packages to be available and
1423passes it @i{via} the @option{--manifest} option
1424(@pxref{profile-manifest, @option{--manifest}}).
1425
e32171ee 1426@cindex profile
b9e5c0a9 1427For each user, a symlink to the user's default profile is automatically
0ec1af59 1428created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1429current generation of the user's default profile. Thus, users can add
1430@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1431variable, and so on.
d664f1b4
LC
1432@cindex search paths
1433If you are not using the Guix System Distribution, consider adding the
1434following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1435Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1436shells get all the right environment variable definitions:
1437
1438@example
1439GUIX_PROFILE="$HOME/.guix-profile" \
1440source "$HOME/.guix-profile/etc/profile"
1441@end example
b9e5c0a9 1442
4379c35b
LC
1443In a multi-user setup, user profiles are stored in a place registered as
1444a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1445to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1446@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1447@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1448@code{--localstatedir}, and @var{user} is the user name. The
1449@file{per-user} directory is created when @command{guix-daemon} is
1450started, and the @var{user} sub-directory is created by @command{guix
1451package}.
0ec1af59
LC
1452
1453The @var{options} can be among the following:
1454
eeaf4427
LC
1455@table @code
1456
6447738c
MW
1457@item --install=@var{package} @dots{}
1458@itemx -i @var{package} @dots{}
1459Install the specified @var{package}s.
eeaf4427 1460
6447738c 1461Each @var{package} may specify either a simple package name, such as
1b846da8
ML
1462@code{guile}, or a package name followed by an at-sign and version number,
1463such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
724311a2
LC
1464case, the newest version prefixed by @code{1.8} is selected.)
1465
1466If no version number is specified, the
dc5669cd
MW
1467newest available version will be selected. In addition, @var{package}
1468may contain a colon, followed by the name of one of the outputs of the
1b846da8 1469package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
e7f34eb0
LC
1470(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1471name (and optionally version) are searched for among the GNU
1472distribution modules (@pxref{Package Modules}).
eeaf4427 1473
461572cc
LC
1474@cindex propagated inputs
1475Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1476that automatically get installed along with the required package
1477(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1478@code{package} objects}, for information about propagated inputs in
1479package definitions).
461572cc 1480
21461f27 1481@anchor{package-cmd-propagated-inputs}
461572cc
LC
1482An example is the GNU MPC library: its C header files refer to those of
1483the GNU MPFR library, which in turn refer to those of the GMP library.
1484Thus, when installing MPC, the MPFR and GMP libraries also get installed
1485in the profile; removing MPC also removes MPFR and GMP---unless they had
f97c9175 1486also been explicitly installed by the user.
461572cc 1487
ba7ea5ce 1488Besides, packages sometimes rely on the definition of environment
5924080d 1489variables for their search paths (see explanation of
ba7ea5ce 1490@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1491environment variable definitions are reported here.
1492
5d4b411f
LC
1493@item --install-from-expression=@var{exp}
1494@itemx -e @var{exp}
1495Install the package @var{exp} evaluates to.
1496
1497@var{exp} must be a Scheme expression that evaluates to a
1498@code{<package>} object. This option is notably useful to disambiguate
1499between same-named variants of a package, with expressions such as
1500@code{(@@ (gnu packages base) guile-final)}.
1501
1502Note that this option installs the first output of the specified
1503package, which may be insufficient when needing a specific output of a
1504multiple-output package.
1505
0d279400
DT
1506@item --install-from-file=@var{file}
1507@itemx -f @var{file}
1508Install the package that the code within @var{file} evaluates to.
1509
1510As an example, @var{file} might contain a definition like this
1511(@pxref{Defining Packages}):
1512
1513@example
1514@verbatiminclude package-hello.scm
1515@end example
1516
baacf042 1517Developers may find it useful to include such a @file{guix.scm} file
f97c9175 1518in the root of their project source tree that can be used to test
0d279400
DT
1519development snapshots and create reproducible development environments
1520(@pxref{Invoking guix environment}).
1521
6447738c
MW
1522@item --remove=@var{package} @dots{}
1523@itemx -r @var{package} @dots{}
1524Remove the specified @var{package}s.
eeaf4427 1525
6447738c 1526As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1527and/or output name in addition to the package name. For instance,
1528@code{-r glibc:debug} would remove the @code{debug} output of
1529@code{glibc}.
1530
6447738c
MW
1531@item --upgrade[=@var{regexp} @dots{}]
1532@itemx -u [@var{regexp} @dots{}]
e32171ee 1533@cindex upgrading packages
6447738c
MW
1534Upgrade all the installed packages. If one or more @var{regexp}s are
1535specified, upgrade only installed packages whose name matches a
d5f01e48 1536@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1537
f651b477
LC
1538Note that this upgrades package to the latest version of packages found
1539in the distribution currently installed. To update your distribution,
1540you should regularly run @command{guix pull} (@pxref{Invoking guix
1541pull}).
1542
d5f01e48
MW
1543@item --do-not-upgrade[=@var{regexp} @dots{}]
1544When used together with the @code{--upgrade} option, do @emph{not}
1545upgrade any packages whose name matches a @var{regexp}. For example, to
1546upgrade all packages in the current profile except those containing the
1547substring ``emacs'':
1548
1549@example
1550$ guix package --upgrade . --do-not-upgrade emacs
1551@end example
1552
99bd74d5 1553@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1554@itemx -m @var{file}
99bd74d5
LC
1555@cindex profile declaration
1556@cindex profile manifest
1557Create a new generation of the profile from the manifest object
1b676447
DT
1558returned by the Scheme code in @var{file}.
1559
99bd74d5
LC
1560This allows you to @emph{declare} the profile's contents rather than
1561constructing it through a sequence of @code{--install} and similar
1562commands. The advantage is that @var{file} can be put under version
1563control, copied to different machines to reproduce the same profile, and
1564so on.
1565
1566@c FIXME: Add reference to (guix profile) documentation when available.
1567@var{file} must return a @dfn{manifest} object, which is roughly a list
1568of packages:
1b676447 1569
99bd74d5 1570@findex packages->manifest
1b676447 1571@example
99bd74d5 1572(use-package-modules guile emacs)
1b676447
DT
1573
1574(packages->manifest
99bd74d5
LC
1575 (list emacs
1576 guile-2.0
1b676447 1577 ;; Use a specific package output.
99bd74d5 1578 (list guile-2.0 "debug")))
1b676447
DT
1579@end example
1580
24e262f0 1581@item --roll-back
e32171ee
JD
1582@cindex rolling back
1583@cindex undoing transactions
1584@cindex transactions, undoing
24e262f0
LC
1585Roll back to the previous @dfn{generation} of the profile---i.e., undo
1586the last transaction.
1587
1588When combined with options such as @code{--install}, roll back occurs
1589before any other actions.
1590
d9307267 1591When rolling back from the first generation that actually contains
4b2bc804 1592installed packages, the profile is made to point to the @dfn{zeroth
f97c9175 1593generation}, which contains no files apart from its own metadata.
d9307267 1594
f97c9175
AE
1595After having rolled back, installing, removing, or upgrading packages
1596overwrites previous future generations. Thus, the history of the
1597generations in a profile is always linear.
82fe08ed 1598
b3bb82f1
AK
1599@item --switch-generation=@var{pattern}
1600@itemx -S @var{pattern}
e32171ee 1601@cindex generations
b3bb82f1
AK
1602Switch to a particular generation defined by @var{pattern}.
1603
1604@var{pattern} may be either a generation number or a number prefixed
1605with ``+'' or ``-''. The latter means: move forward/backward by a
1606specified number of generations. For example, if you want to return to
1607the latest generation after @code{--roll-back}, use
1608@code{--switch-generation=+1}.
1609
1610The difference between @code{--roll-back} and
1611@code{--switch-generation=-1} is that @code{--switch-generation} will
1612not make a zeroth generation, so if a specified generation does not
1613exist, the current generation will not be changed.
1614
dbc31ab2 1615@item --search-paths[=@var{kind}]
5924080d
LC
1616@cindex search paths
1617Report environment variable definitions, in Bash syntax, that may be
1618needed in order to use the set of installed packages. These environment
1619variables are used to specify @dfn{search paths} for files used by some
1620of the installed packages.
1621
1622For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1623environment variables to be defined so it can look for headers and
1624libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1625Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1626library are installed in the profile, then @code{--search-paths} will
1627suggest setting these variables to @code{@var{profile}/include} and
1628@code{@var{profile}/lib}, respectively.
1629
dbc31ab2
LC
1630The typical use case is to define these environment variables in the
1631shell:
1632
1633@example
1634$ eval `guix package --search-paths`
1635@end example
1636
1637@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1638meaning that the returned environment variable definitions will either
1639be exact settings, or prefixes or suffixes of the current value of these
1640variables. When omitted, @var{kind} defaults to @code{exact}.
1641
fc2d2339
LC
1642This option can also be used to compute the @emph{combined} search paths
1643of several profiles. Consider this example:
1644
1645@example
1646$ guix package -p foo -i guile
1647$ guix package -p bar -i guile-json
1648$ guix package -p foo -p bar --search-paths
1649@end example
1650
1651The last command above reports about the @code{GUILE_LOAD_PATH}
1652variable, even though, taken individually, neither @file{foo} nor
1653@file{bar} would lead to that recommendation.
1654
1655
eeaf4427
LC
1656@item --profile=@var{profile}
1657@itemx -p @var{profile}
1658Use @var{profile} instead of the user's default profile.
1659
70915c1a 1660@item --verbose
f97c9175
AE
1661Produce verbose output. In particular, emit the build log of the
1662environment on the standard error port.
70915c1a 1663
eeaf4427
LC
1664@item --bootstrap
1665Use the bootstrap Guile to build the profile. This option is only
1666useful to distribution developers.
1667
1668@end table
1669
f97c9175 1670In addition to these actions, @command{guix package} supports the
733b4130
LC
1671following options to query the current state of a profile, or the
1672availability of packages:
eeaf4427 1673
733b4130
LC
1674@table @option
1675
acc08466
NK
1676@item --search=@var{regexp}
1677@itemx -s @var{regexp}
b110869d 1678@cindex searching for packages
5763ad92 1679List the available packages whose name, synopsis, or description matches
f97c9175 1680@var{regexp}. Print all the metadata of matching packages in
299112d3
LC
1681@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1682GNU recutils manual}).
acc08466 1683
299112d3
LC
1684This allows specific fields to be extracted using the @command{recsel}
1685command, for instance:
1686
1687@example
e49951eb 1688$ guix package -s malloc | recsel -p name,version
299112d3
LC
1689name: glibc
1690version: 2.17
1691
1692name: libgc
1693version: 7.2alpha6
1694@end example
acc08466 1695
a12d92f5
LC
1696Similarly, to show the name of all the packages available under the
1697terms of the GNU@tie{}LGPL version 3:
1698
1699@example
1700$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1701name: elfutils
1702
1703name: gmp
1704@dots{}
1705@end example
1706
db5a9444
LC
1707It is also possible to refine search results using several @code{-s}
1708flags. For example, the following command returns a list of board
1709games:
1710
1711@example
1712$ guix package -s '\<board\>' -s game | recsel -p name
1713name: gnubg
1714@dots{}
1715@end example
1716
1717If we were to omit @code{-s game}, we would also get software packages
1718that deal with printed circuit boards; removing the angle brackets
1719around @code{board} would further add packages that have to do with
1720keyboards.
1721
b110869d
LC
1722And now for a more elaborate example. The following command searches
1723for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1724libraries, and prints the name and synopsis of the matching packages:
1725
1726@example
1727$ guix package -s crypto -s library | \
1728 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1729@end example
1730
1731@noindent
1732@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1733information on @dfn{selection expressions} for @code{recsel -e}.
1734
2aa6efb0
CR
1735@item --show=@var{package}
1736Show details about @var{package}, taken from the list of available packages, in
1737@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1738recutils manual}).
1739
1740@example
1741$ guix package --show=python | recsel -p name,version
1742name: python
1743version: 2.7.6
1744
1745name: python
1746version: 3.3.5
1747@end example
1748
1749You may also specify the full name of a package to only get details about a
1750specific version of it:
1751@example
ea206df4 1752$ guix package --show=python@@3.4 | recsel -p name,version
2aa6efb0 1753name: python
ea206df4 1754version: 3.4.3
2aa6efb0
CR
1755@end example
1756
1757
1758
733b4130
LC
1759@item --list-installed[=@var{regexp}]
1760@itemx -I [@var{regexp}]
bd9bde1c
LC
1761List the currently installed packages in the specified profile, with the
1762most recently installed packages shown last. When @var{regexp} is
1763specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1764
1765For each installed package, print the following items, separated by
1766tabs: the package name, its version string, the part of the package that
1767is installed (for instance, @code{out} for the default output,
1768@code{include} for its headers, etc.), and the path of this package in
1769the store.
1770
64fc89b6
LC
1771@item --list-available[=@var{regexp}]
1772@itemx -A [@var{regexp}]
5763ad92 1773List packages currently available in the distribution for this system
a1ba8475
LC
1774(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1775installed packages whose name matches @var{regexp}.
64fc89b6
LC
1776
1777For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1778its version string, the parts of the package (@pxref{Packages with
1779Multiple Outputs}), and the source location of its definition.
64fc89b6 1780
f566d765
LC
1781@item --list-generations[=@var{pattern}]
1782@itemx -l [@var{pattern}]
e32171ee 1783@cindex generations
f566d765
LC
1784Return a list of generations along with their creation dates; for each
1785generation, show the installed packages, with the most recently
4b2bc804
NK
1786installed packages shown last. Note that the zeroth generation is never
1787shown.
f566d765
LC
1788
1789For each installed package, print the following items, separated by
1790tabs: the name of a package, its version string, the part of the package
1791that is installed (@pxref{Packages with Multiple Outputs}), and the
1792location of this package in the store.
1793
1794When @var{pattern} is used, the command returns only matching
1795generations. Valid patterns include:
1796
1797@itemize
1798@item @emph{Integers and comma-separated integers}. Both patterns denote
1799generation numbers. For instance, @code{--list-generations=1} returns
1800the first one.
1801
1802And @code{--list-generations=1,8,2} outputs three generations in the
1803specified order. Neither spaces nor trailing commas are allowed.
1804
1805@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1806specified generations and everything in between. Note that the start of
f97c9175 1807a range must be smaller than its end.
f566d765
LC
1808
1809It is also possible to omit the endpoint. For example,
1810@code{--list-generations=2..}, returns all generations starting from the
1811second one.
1812
1813@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1814or months by passing an integer along with the first letter of the
d7ddb257
LC
1815duration. For example, @code{--list-generations=20d} lists generations
1816that are up to 20 days old.
f566d765
LC
1817@end itemize
1818
b7884ca3
NK
1819@item --delete-generations[=@var{pattern}]
1820@itemx -d [@var{pattern}]
d7ddb257
LC
1821When @var{pattern} is omitted, delete all generations except the current
1822one.
b7884ca3
NK
1823
1824This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1825When @var{pattern} is specified, delete the matching generations. When
1826@var{pattern} specifies a duration, generations @emph{older} than the
1827specified duration match. For instance, @code{--delete-generations=1m}
1828deletes generations that are more than one month old.
1829
391bdd8f
LC
1830If the current generation matches, it is @emph{not} deleted. Also, the
1831zeroth generation is never deleted.
b7884ca3 1832
f97c9175 1833Note that deleting generations prevents rolling back to them.
1bb9900a
LC
1834Consequently, this command must be used with care.
1835
733b4130 1836@end table
eeaf4427 1837
70ee5642 1838Finally, since @command{guix package} may actually start build
ccd7158d 1839processes, it supports all the common build options (@pxref{Common Build
f97c9175 1840Options}). It also supports package transformation options, such as
b8638f03
LC
1841@option{--with-source} (@pxref{Package Transformation Options}).
1842However, note that package transformations are lost when upgrading; to
f97c9175 1843preserve transformations across upgrades, you should define your own
b8638f03
LC
1844package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1845(@pxref{Defining Packages}).
1846
70ee5642 1847
c4202d60
LC
1848@node Substitutes
1849@section Substitutes
1850
1851@cindex substitutes
1852@cindex pre-built binaries
1853Guix supports transparent source/binary deployment, which means that it
1854can either build things locally, or download pre-built items from a
1855server. We call these pre-built items @dfn{substitutes}---they are
1856substitutes for local build results. In many cases, downloading a
1857substitute is much faster than building things locally.
1858
1859Substitutes can be anything resulting from a derivation build
1860(@pxref{Derivations}). Of course, in the common case, they are
1861pre-built package binaries, but source tarballs, for instance, which
1862also result from derivation builds, can be available as substitutes.
1863
1864The @code{hydra.gnu.org} server is a front-end to a build farm that
1865builds packages from the GNU distribution continuously for some
32950fc8
AK
1866architectures, and makes them available as substitutes (@pxref{Emacs
1867Hydra}, for information on how to query the continuous integration
1868server). This is the
f8a8e0fe
LC
1869default source of substitutes; it can be overridden by passing the
1870@option{--substitute-urls} option either to @command{guix-daemon}
1871(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1872or to client tools such as @command{guix package}
1873(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1874option}).
c4202d60 1875
9b7bd1b1
LC
1876Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1877the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
1878HTTPS is recommended because communications are encrypted; conversely,
1879using HTTP makes all communications visible to an eavesdropper, who
1880could use the information gathered to determine, for instance, whether
1881your system has unpatched security vulnerabilities.
1882
c4202d60
LC
1883@cindex security
1884@cindex digital signatures
e32171ee 1885@cindex substitutes, authorization thereof
df061d07
LC
1886To allow Guix to download substitutes from @code{hydra.gnu.org} or a
1887mirror thereof, you
c4202d60
LC
1888must add its public key to the access control list (ACL) of archive
1889imports, using the @command{guix archive} command (@pxref{Invoking guix
1890archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1891be compromised and to serve genuine substitutes.
1892
1893This public key is installed along with Guix, in
1894@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1895the installation prefix of Guix. If you installed Guix from source,
1896make sure you checked the GPG signature of
1897@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1898Then, you can run something like this:
1899
1900@example
1901# guix archive --authorize < hydra.gnu.org.pub
1902@end example
1903
1904Once this is in place, the output of a command like @code{guix build}
1905should change from something like:
1906
1907@example
1908$ guix build emacs --dry-run
1909The following derivations would be built:
1910 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1911 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1912 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1913 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1914@dots{}
1915@end example
1916
1917@noindent
1918to something like:
1919
1920@example
1921$ guix build emacs --dry-run
1922The following files would be downloaded:
1923 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1924 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1925 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1926 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1927@dots{}
1928@end example
1929
1930@noindent
1931This indicates that substitutes from @code{hydra.gnu.org} are usable and
1932will be downloaded, when possible, for future builds.
1933
1934Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1935one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1936when attempting to use a substitute that has been tampered with.
1937
e0c941fe 1938@vindex http_proxy
9b7bd1b1
LC
1939Substitutes are downloaded over HTTP or HTTPS.
1940The @code{http_proxy} environment
e0c941fe
LC
1941variable can be set in the environment of @command{guix-daemon} and is
1942honored for downloads of substitutes. Note that the value of
1943@code{http_proxy} in the environment where @command{guix build},
1944@command{guix package}, and other client commands are run has
1945@emph{absolutely no effect}.
1946
9b7bd1b1
LC
1947When using HTTPS, the server's X.509 certificate is @emph{not} validated
1948(in other words, the server is not authenticated), contrary to what
1949HTTPS clients such as Web browsers usually do. This is because Guix
1950authenticates substitute information itself, as explained above, which
1951is what we care about (whereas X.509 certificates are about
1952authenticating bindings between domain names and public keys.)
1953
c4202d60
LC
1954The substitute mechanism can be disabled globally by running
1955@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1956guix-daemon}). It can also be disabled temporarily by passing the
1957@code{--no-substitutes} option to @command{guix package}, @command{guix
1958build}, and other command-line tools.
1959
1960
9b7bd1b1
LC
1961@unnumberedsubsec On Trusting Binaries
1962
c4202d60
LC
1963Today, each individual's control over their own computing is at the
1964mercy of institutions, corporations, and groups with enough power and
1965determination to subvert the computing infrastructure and exploit its
1966weaknesses. While using @code{hydra.gnu.org} substitutes can be
1967convenient, we encourage users to also build on their own, or even run
1968their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
1969interesting target. One way to help is by publishing the software you
1970build using @command{guix publish} so that others have one more choice
1971of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
1972
1973Guix has the foundations to maximize build reproducibility
1974(@pxref{Features}). In most cases, independent builds of a given
1975package or derivation should yield bit-identical results. Thus, through
1976a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
1977integrity of our systems. The @command{guix challenge} command aims to
1978help users assess substitute servers, and to assist developers in
1979finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
1980challenge}). Similarly, the @option{--check} option of @command{guix
1981build} allows users to check whether previously-installed substitutes
1982are genuine by rebuilding them locally (@pxref{build-check,
1983@command{guix build --check}}).
c4202d60
LC
1984
1985In the future, we want Guix to have support to publish and retrieve
1986binaries to/from other users, in a peer-to-peer fashion. If you would
1987like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1988
1989
6e721c4d
LC
1990@node Packages with Multiple Outputs
1991@section Packages with Multiple Outputs
1992
1993@cindex multiple-output packages
1994@cindex package outputs
e32171ee 1995@cindex outputs
6e721c4d
LC
1996
1997Often, packages defined in Guix have a single @dfn{output}---i.e., the
f97c9175 1998source package leads to exactly one directory in the store. When running
6e721c4d
LC
1999@command{guix package -i glibc}, one installs the default output of the
2000GNU libc package; the default output is called @code{out}, but its name
2001can be omitted as shown in this command. In this particular case, the
2002default output of @code{glibc} contains all the C header files, shared
2003libraries, static libraries, Info documentation, and other supporting
2004files.
2005
2006Sometimes it is more appropriate to separate the various types of files
2007produced from a single source package into separate outputs. For
2008instance, the GLib C library (used by GTK+ and related packages)
2009installs more than 20 MiB of reference documentation as HTML pages.
2010To save space for users who do not need it, the documentation goes to a
2011separate output, called @code{doc}. To install the main GLib output,
2012which contains everything but the documentation, one would run:
2013
2014@example
2015guix package -i glib
2016@end example
2017
e32171ee 2018@cindex documentation
6e721c4d
LC
2019The command to install its documentation is:
2020
2021@example
2022guix package -i glib:doc
2023@end example
2024
2025Some packages install programs with different ``dependency footprints''.
f97c9175 2026For instance, the WordNet package installs both command-line tools and
6e721c4d
LC
2027graphical user interfaces (GUIs). The former depend solely on the C
2028library, whereas the latter depend on Tcl/Tk and the underlying X
2029libraries. In this case, we leave the command-line tools in the default
2030output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
2031who do not need the GUIs to save space. The @command{guix size} command
2032can help find out about such situations (@pxref{Invoking guix size}).
88856916 2033@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
2034
2035There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
2036Other conventional output names include @code{lib} for libraries and
2037possibly header files, @code{bin} for stand-alone programs, and
2038@code{debug} for debugging information (@pxref{Installing Debugging
2039Files}). The outputs of a packages are listed in the third column of
2040the output of @command{guix package --list-available} (@pxref{Invoking
2041guix package}).
6e721c4d 2042
eeaf4427 2043
e49951eb
MW
2044@node Invoking guix gc
2045@section Invoking @command{guix gc}
fe8ff028
LC
2046
2047@cindex garbage collector
e32171ee 2048@cindex disk space
f97c9175 2049Packages that are installed, but not used, may be @dfn{garbage-collected}.
e49951eb 2050The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
2051collector to reclaim space from the @file{/gnu/store} directory. It is
2052the @emph{only} way to remove files from @file{/gnu/store}---removing
2053files or directories manually may break it beyond repair!
fe8ff028
LC
2054
2055The garbage collector has a set of known @dfn{roots}: any file under
834129e0 2056@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
2057cannot be deleted; any other file is considered @dfn{dead} and may be
2058deleted. The set of garbage collector roots includes default user
e49951eb
MW
2059profiles, and may be augmented with @command{guix build --root}, for
2060example (@pxref{Invoking guix build}).
fe8ff028 2061
1bb9900a
LC
2062Prior to running @code{guix gc --collect-garbage} to make space, it is
2063often useful to remove old generations from user profiles; that way, old
2064package builds referenced by those generations can be reclaimed. This
2065is achieved by running @code{guix package --delete-generations}
2066(@pxref{Invoking guix package}).
2067
e49951eb 2068The @command{guix gc} command has three modes of operation: it can be
fe8ff028 2069used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
2070files (the @code{--delete} option), to print garbage-collector
2071information, or for more advanced queries. The garbage collection
2072options are as follows:
fe8ff028
LC
2073
2074@table @code
2075@item --collect-garbage[=@var{min}]
2076@itemx -C [@var{min}]
834129e0 2077Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
2078sub-directories. This is the default operation when no option is
2079specified.
2080
2081When @var{min} is given, stop once @var{min} bytes have been collected.
2082@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
2083suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2084(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
2085
2086When @var{min} is omitted, collect all the garbage.
2087
0054e470
LC
2088@item --free-space=@var{free}
2089@itemx -F @var{free}
2090Collect garbage until @var{free} space is available under
2091@file{/gnu/store}, if possible; @var{free} denotes storage space, such
2092as @code{500MiB}, as described above.
2093
2094When @var{free} or more is already available in @file{/gnu/store}, do
2095nothing and exit immediately.
2096
fe8ff028
LC
2097@item --delete
2098@itemx -d
2099Attempt to delete all the store files and directories specified as
2100arguments. This fails if some of the files are not in the store, or if
2101they are still live.
2102
30d9aa54
LC
2103@item --list-failures
2104List store items corresponding to cached build failures.
2105
2106This prints nothing unless the daemon was started with
2107@option{--cache-failures} (@pxref{Invoking guix-daemon,
2108@option{--cache-failures}}).
2109
2110@item --clear-failures
2111Remove the specified store items from the failed-build cache.
2112
2113Again, this option only makes sense when the daemon is started with
2114@option{--cache-failures}. Otherwise, it does nothing.
2115
fe8ff028
LC
2116@item --list-dead
2117Show the list of dead files and directories still present in the
2118store---i.e., files and directories no longer reachable from any root.
2119
2120@item --list-live
2121Show the list of live store files and directories.
ba8b732d
LC
2122
2123@end table
2124
2125In addition, the references among existing store files can be queried:
2126
2127@table @code
2128
2129@item --references
2130@itemx --referrers
e32171ee 2131@cindex package dependencies
ba8b732d
LC
2132List the references (respectively, the referrers) of store files given
2133as arguments.
2134
8e59fdd5
LC
2135@item --requisites
2136@itemx -R
fcc58db6 2137@cindex closure
8e59fdd5
LC
2138List the requisites of the store files passed as arguments. Requisites
2139include the store files themselves, their references, and the references
2140of these, recursively. In other words, the returned list is the
2141@dfn{transitive closure} of the store files.
2142
f97c9175
AE
2143@xref{Invoking guix size}, for a tool to profile the size of the closure
2144of an element. @xref{Invoking guix graph}, for a tool to visualize
88856916 2145the graph of references.
fcc58db6 2146
fe8ff028
LC
2147@end table
2148
7770aafc
LC
2149Lastly, the following options allow you to check the integrity of the
2150store and to control disk usage.
2151
2152@table @option
2153
2154@item --verify[=@var{options}]
2155@cindex integrity, of the store
2156@cindex integrity checking
2157Verify the integrity of the store.
2158
2159By default, make sure that all the store items marked as valid in the
f97c9175 2160database of the daemon actually exist in @file{/gnu/store}.
7770aafc 2161
f97c9175 2162When provided, @var{options} must be a comma-separated list containing one
7770aafc
LC
2163or more of @code{contents} and @code{repair}.
2164
7414de0a 2165When passing @option{--verify=contents}, the daemon computes the
f97c9175 2166content hash of each store item and compares it against its hash in the
7770aafc
LC
2167database. Hash mismatches are reported as data corruptions. Because it
2168traverses @emph{all the files in the store}, this command can take a
2169long time, especially on systems with a slow disk drive.
2170
2171@cindex repairing the store
2172Using @option{--verify=repair} or @option{--verify=contents,repair}
2173causes the daemon to try to repair corrupt store items by fetching
2174substitutes for them (@pxref{Substitutes}). Because repairing is not
2175atomic, and thus potentially dangerous, it is available only to the
2176system administrator.
2177
2178@item --optimize
2179@cindex deduplication
2180Optimize the store by hard-linking identical files---this is
2181@dfn{deduplication}.
2182
2183The daemon performs deduplication after each successful build or archive
2184import, unless it was started with @code{--disable-deduplication}
2185(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2186this option is primarily useful when the daemon was running with
2187@code{--disable-deduplication}.
2188
2189@end table
eeaf4427 2190
f651b477
LC
2191@node Invoking guix pull
2192@section Invoking @command{guix pull}
2193
e32171ee
JD
2194@cindex upgrading Guix
2195@cindex @command{guix pull}
2196@cindex pull
f651b477
LC
2197Packages are installed or upgraded to the latest version available in
2198the distribution currently available on your local machine. To update
2199that distribution, along with the Guix tools, you must run @command{guix
2200pull}: the command downloads the latest Guix source code and package
2201descriptions, and deploys it.
2202
2203On completion, @command{guix package} will use packages and package
2204versions from this just-retrieved copy of Guix. Not only that, but all
2205the Guix commands and Scheme modules will also be taken from that latest
2206version. New @command{guix} sub-commands added by the update also
cb05108a
LC
2207become available.
2208
2209Any user can update their Guix copy using @command{guix pull}, and the
2210effect is limited to the user who run @command{guix pull}. For
2211instance, when user @code{root} runs @command{guix pull}, this has no
2212effect on the version of Guix that user @code{alice} sees, and vice
2213versa@footnote{Under the hood, @command{guix pull} updates the
2214@file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2215and the @command{guix} command loads code from there.}.
f651b477
LC
2216
2217The @command{guix pull} command is usually invoked with no arguments,
2218but it supports the following options:
2219
2220@table @code
2221@item --verbose
2222Produce verbose output, writing build logs to the standard error output.
2223
ab5d72ad
LC
2224@item --url=@var{url}
2225Download the source tarball of Guix from @var{url}.
2226
2227By default, the tarball is taken from its canonical address at
2228@code{gnu.org}, for the stable branch of Guix.
2229
f651b477
LC
2230@item --bootstrap
2231Use the bootstrap Guile to build the latest Guix. This option is only
2232useful to Guix developers.
2233@end table
2234
760c60d6
LC
2235
2236@node Invoking guix archive
2237@section Invoking @command{guix archive}
2238
e32171ee
JD
2239@cindex @command{guix archive}
2240@cindex archive
760c60d6
LC
2241The @command{guix archive} command allows users to @dfn{export} files
2242from the store into a single archive, and to later @dfn{import} them.
2243In particular, it allows store files to be transferred from one machine
4d4c4816
AE
2244to the store on another machine.
2245
e32171ee 2246@cindex exporting store items
4d4c4816
AE
2247To export store files as an archive to standard output, run:
2248
2249@example
2250guix archive --export @var{options} @var{specifications}...
2251@end example
2252
2253@var{specifications} may be either store file names or package
2254specifications, as for @command{guix package} (@pxref{Invoking guix
2255package}). For instance, the following command creates an archive
2256containing the @code{gui} output of the @code{git} package and the main
2257output of @code{emacs}:
2258
2259@example
2260guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2261@end example
2262
2263If the specified packages are not built yet, @command{guix archive}
2264automatically builds them. The build process may be controlled with the
2265common build options (@pxref{Common Build Options}).
2266
2267To transfer the @code{emacs} package to a machine connected over SSH,
2268one would run:
760c60d6
LC
2269
2270@example
56607088 2271guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
2272@end example
2273
87236aed 2274@noindent
56607088
LC
2275Similarly, a complete user profile may be transferred from one machine
2276to another like this:
2277
2278@example
2279guix archive --export -r $(readlink -f ~/.guix-profile) | \
2280 ssh the-machine guix-archive --import
2281@end example
2282
2283@noindent
2284However, note that, in both examples, all of @code{emacs} and the
2285profile as well as all of their dependencies are transferred (due to
f97c9175
AE
2286@code{-r}), regardless of what is already available in the store on the
2287target machine. The @code{--missing} option can help figure out which
2288items are missing from the target store.
87236aed 2289
760c60d6 2290Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
2291comparable in spirit to `tar', but with a few noteworthy differences
2292that make it more appropriate for our purposes. First, rather than
f97c9175 2293recording all Unix metadata for each file, the Nar format only mentions
0dbd88db
LC
2294the file type (regular, directory, or symbolic link); Unix permissions
2295and owner/group are dismissed. Second, the order in which directory
2296entries are stored always follows the order of file names according to
2297the C locale collation order. This makes archive production fully
2298deterministic.
2299
2300When exporting, the daemon digitally signs the contents of the archive,
2301and that digital signature is appended. When importing, the daemon
2302verifies the signature and rejects the import in case of an invalid
2303signature or if the signing key is not authorized.
760c60d6
LC
2304@c FIXME: Add xref to daemon doc about signatures.
2305
2306The main options are:
2307
2308@table @code
2309@item --export
2310Export the specified store files or packages (see below.) Write the
2311resulting archive to the standard output.
2312
56607088
LC
2313Dependencies are @emph{not} included in the output, unless
2314@code{--recursive} is passed.
2315
2316@item -r
2317@itemx --recursive
2318When combined with @code{--export}, this instructs @command{guix
2319archive} to include dependencies of the given items in the archive.
2320Thus, the resulting archive is self-contained: it contains the closure
2321of the exported store items.
2322
760c60d6
LC
2323@item --import
2324Read an archive from the standard input, and import the files listed
2325therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2326signature, or if it is signed by a public key not among the authorized
2327keys (see @code{--authorize} below.)
554f26ec 2328
87236aed
LC
2329@item --missing
2330Read a list of store file names from the standard input, one per line,
2331and write on the standard output the subset of these files missing from
2332the store.
2333
554f26ec 2334@item --generate-key[=@var{parameters}]
f82cc5fd 2335@cindex signing, archives
f97c9175 2336Generate a new key pair for the daemon. This is a prerequisite before
554f26ec
LC
2337archives can be exported with @code{--export}. Note that this operation
2338usually takes time, because it needs to gather enough entropy to
2339generate the key pair.
2340
2341The generated key pair is typically stored under @file{/etc/guix}, in
2342@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2343key, which must be kept secret.) When @var{parameters} is omitted,
2344an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2345versions before 1.6.0, it is a 4096-bit RSA key.
f97c9175 2346Alternatively, @var{parameters} can specify
554f26ec
LC
2347@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2348public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2349Libgcrypt Reference Manual}).
f82cc5fd
LC
2350
2351@item --authorize
2352@cindex authorizing, archives
2353Authorize imports signed by the public key passed on standard input.
2354The public key must be in ``s-expression advanced format''---i.e., the
2355same format as the @file{signing-key.pub} file.
2356
2357The list of authorized keys is kept in the human-editable file
2358@file{/etc/guix/acl}. The file contains
2359@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2360s-expressions''} and is structured as an access-control list in the
2361@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2362(SPKI)}.
c6f8e9dd
LC
2363
2364@item --extract=@var{directory}
2365@itemx -x @var{directory}
2366Read a single-item archive as served by substitute servers
2367(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2368low-level operation needed in only very narrow use cases; see below.
2369
2370For example, the following command extracts the substitute for Emacs
2371served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2372
2373@example
2374$ wget -O - \
df061d07 2375 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
c6f8e9dd
LC
2376 | bunzip2 | guix archive -x /tmp/emacs
2377@end example
2378
2379Single-item archives are different from multiple-item archives produced
2380by @command{guix archive --export}; they contain a single store item,
2381and they do @emph{not} embed a signature. Thus this operation does
2382@emph{no} signature verification and its output should be considered
2383unsafe.
2384
2385The primary purpose of this operation is to facilitate inspection of
2386archive contents coming from possibly untrusted substitute servers.
2387
760c60d6
LC
2388@end table
2389
c554de89
AK
2390@c *********************************************************************
2391@include emacs.texi
760c60d6 2392
568717fd
LC
2393@c *********************************************************************
2394@node Programming Interface
2395@chapter Programming Interface
2396
3dc1970d
LC
2397GNU Guix provides several Scheme programming interfaces (APIs) to
2398define, build, and query packages. The first interface allows users to
2399write high-level package definitions. These definitions refer to
2400familiar packaging concepts, such as the name and version of a package,
2401its build system, and its dependencies. These definitions can then be
2402turned into concrete build actions.
2403
ba55b1cb 2404Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2405standard setup, the daemon has write access to the store---the
834129e0 2406@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2407setup also has the daemon perform builds in chroots, under a specific
2408build users, to minimize interference with the rest of the system.
2409
2410@cindex derivation
2411Lower-level APIs are available to interact with the daemon and the
2412store. To instruct the daemon to perform a build action, users actually
2413provide it with a @dfn{derivation}. A derivation is a low-level
2414representation of the build actions to be taken, and the environment in
2415which they should occur---derivations are to package definitions what
49ad317a
LC
2416assembly is to C programs. The term ``derivation'' comes from the fact
2417that build results @emph{derive} from them.
3dc1970d
LC
2418
2419This chapter describes all these APIs in turn, starting from high-level
2420package definitions.
2421
568717fd 2422@menu
b860f382 2423* Defining Packages:: Defining new packages.
7458bd0a 2424* Build Systems:: Specifying how packages are built.
b860f382
LC
2425* The Store:: Manipulating the package store.
2426* Derivations:: Low-level interface to package derivations.
2427* The Store Monad:: Purely functional interface to the store.
21b679f6 2428* G-Expressions:: Manipulating build expressions.
568717fd
LC
2429@end menu
2430
2431@node Defining Packages
2432@section Defining Packages
2433
3dc1970d
LC
2434The high-level interface to package definitions is implemented in the
2435@code{(guix packages)} and @code{(guix build-system)} modules. As an
2436example, the package definition, or @dfn{recipe}, for the GNU Hello
2437package looks like this:
2438
2439@example
e7f34eb0
LC
2440(define-module (gnu packages hello)
2441 #:use-module (guix packages)
2442 #:use-module (guix download)
2443 #:use-module (guix build-system gnu)
a6dcdcac
SB
2444 #:use-module (guix licenses)
2445 #:use-module (gnu packages gawk))
b22a12fd 2446
79f5dd59 2447(define-public hello
3dc1970d
LC
2448 (package
2449 (name "hello")
17d8e33f 2450 (version "2.10")
3dc1970d 2451 (source (origin
17d8e33f
ML
2452 (method url-fetch)
2453 (uri (string-append "mirror://gnu/hello/hello-" version
2454 ".tar.gz"))
2455 (sha256
2456 (base32
2457 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2458 (build-system gnu-build-system)
654c0d97 2459 (arguments '(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2460 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2461 (synopsis "Hello, GNU world: An example GNU package")
2462 (description "Guess what GNU Hello prints!")
3dc1970d 2463 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2464 (license gpl3+)))
3dc1970d
LC
2465@end example
2466
2467@noindent
2468Without being a Scheme expert, the reader may have guessed the meaning
f97c9175
AE
2469of the various fields here. This expression binds the variable
2470@code{hello} to a @code{<package>} object, which is essentially a record
3dc1970d
LC
2471(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2472This package object can be inspected using procedures found in the
2473@code{(guix packages)} module; for instance, @code{(package-name hello)}
2474returns---surprise!---@code{"hello"}.
2475
2f7d2d91
LC
2476With luck, you may be able to import part or all of the definition of
2477the package you are interested in from another repository, using the
2478@code{guix import} command (@pxref{Invoking guix import}).
2479
f97c9175 2480In the example above, @var{hello} is defined in a module of its own,
e7f34eb0
LC
2481@code{(gnu packages hello)}. Technically, this is not strictly
2482necessary, but it is convenient to do so: all the packages defined in
2483modules under @code{(gnu packages @dots{})} are automatically known to
2484the command-line tools (@pxref{Package Modules}).
2485
3dc1970d
LC
2486There are a few points worth noting in the above package definition:
2487
2488@itemize
2489@item
a2bf4907
LC
2490The @code{source} field of the package is an @code{<origin>} object
2491(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2492Here, the @code{url-fetch} method from @code{(guix download)} is used,
2493meaning that the source is a file to be downloaded over FTP or HTTP.
2494
2495The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2496the GNU mirrors defined in @code{(guix download)}.
2497
2498The @code{sha256} field specifies the expected SHA256 hash of the file
2499being downloaded. It is mandatory, and allows Guix to check the
2500integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2501base32 representation of the hash. You can obtain this information with
210cc920
LC
2502@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2503hash} (@pxref{Invoking guix hash}).
3dc1970d 2504
f9cc8971
LC
2505@cindex patches
2506When needed, the @code{origin} form can also have a @code{patches} field
2507listing patches to be applied, and a @code{snippet} field giving a
2508Scheme expression to modify the source code.
2509
3dc1970d
LC
2510@item
2511@cindex GNU Build System
7458bd0a
LC
2512The @code{build-system} field specifies the procedure to build the
2513package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2514represents the familiar GNU Build System, where packages may be
2515configured, built, and installed with the usual @code{./configure &&
2516make && make check && make install} command sequence.
2517
2518@item
2519The @code{arguments} field specifies options for the build system
2520(@pxref{Build Systems}). Here it is interpreted by
2521@var{gnu-build-system} as a request run @file{configure} with the
2522@code{--enable-silent-rules} flag.
3dc1970d 2523
654c0d97
LC
2524@cindex quote
2525@cindex quoting
2526@findex '
2527@findex quote
2528What about these quote (@code{'}) characters? They are Scheme syntax to
2529introduce a literal list; @code{'} is synonymous with @code{quote}.
2530@xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
2531for details. Here the value of the @code{arguments} field is a list of
2532arguments passed to the build system down the road, as with @code{apply}
2533(@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
2534Manual}).
2535
2536The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
2537(@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
2538@code{#:configure-flags} is a keyword used to pass a keyword argument
2539to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
2540Reference Manual}).
2541
3dc1970d
LC
2542@item
2543The @code{inputs} field specifies inputs to the build process---i.e.,
2544build-time or run-time dependencies of the package. Here, we define an
2545input called @code{"gawk"} whose value is that of the @var{gawk}
2546variable; @var{gawk} is itself bound to a @code{<package>} object.
2547
654c0d97
LC
2548@cindex backquote (quasiquote)
2549@findex `
2550@findex quasiquote
2551@cindex comma (unquote)
2552@findex ,
2553@findex unquote
2554@findex ,@@
2555@findex unquote-splicing
2556Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
2557us to introduce a literal list in the @code{inputs} field, while
2558@code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
2559value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
2560Reference Manual}).
2561
3dc1970d
LC
2562Note that GCC, Coreutils, Bash, and other essential tools do not need to
2563be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2564of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2565
2566However, any other dependencies need to be specified in the
2567@code{inputs} field. Any dependency not specified here will simply be
2568unavailable to the build process, possibly leading to a build failure.
2569@end itemize
2570
87eafdbd
TUBK
2571@xref{package Reference}, for a full description of possible fields.
2572
2f7d2d91 2573Once a package definition is in place, the
e49951eb 2574package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2575tool (@pxref{Invoking guix build}). You can easily jump back to the
2576package definition using the @command{guix edit} command
2577(@pxref{Invoking guix edit}).
2578@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2579more information on how to test package definitions, and
2580@ref{Invoking guix lint}, for information on how to check a definition
2581for style conformance.
2582
f97c9175 2583Finally, updating the package definition to a new upstream version
7458bd0a
LC
2584can be partly automated by the @command{guix refresh} command
2585(@pxref{Invoking guix refresh}).
3dc1970d
LC
2586
2587Behind the scenes, a derivation corresponding to the @code{<package>}
2588object is first computed by the @code{package-derivation} procedure.
834129e0 2589That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2590The build actions it prescribes may then be realized by using the
3dc1970d
LC
2591@code{build-derivations} procedure (@pxref{The Store}).
2592
2593@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2594Return the @code{<derivation>} object of @var{package} for @var{system}
2595(@pxref{Derivations}).
3dc1970d
LC
2596
2597@var{package} must be a valid @code{<package>} object, and @var{system}
2598must be a string denoting the target system type---e.g.,
2599@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2600must be a connection to the daemon, which operates on the store
2601(@pxref{The Store}).
2602@end deffn
568717fd 2603
9c1edabd
LC
2604@noindent
2605@cindex cross-compilation
2606Similarly, it is possible to compute a derivation that cross-builds a
2607package for some other system:
2608
2609@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2610 @var{package} @var{target} [@var{system}]
59688fc4
LC
2611Return the @code{<derivation>} object of @var{package} cross-built from
2612@var{system} to @var{target}.
9c1edabd
LC
2613
2614@var{target} must be a valid GNU triplet denoting the target hardware
2615and operating system, such as @code{"mips64el-linux-gnu"}
2616(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2617Configure and Build System}).
2618@end deffn
2619
2a75b0b6
LC
2620@cindex package transformations
2621@cindex input rewriting
2622@cindex dependency tree rewriting
2623Packages can be manipulated in arbitrary ways. An example of a useful
2624transformation is @dfn{input rewriting}, whereby the dependency tree of
2625a package is rewritten by replacing specific inputs by others:
2626
2627@deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
2628 [@var{rewrite-name}]
2629Return a procedure that, when passed a package, replaces its direct and
2630indirect dependencies (but not its implicit inputs) according to
2631@var{replacements}. @var{replacements} is a list of package pairs; the
2632first element of each pair is the package to replace, and the second one
2633is the replacement.
2634
2635Optionally, @var{rewrite-name} is a one-argument procedure that takes
2636the name of a package and returns its new name after rewrite.
2637@end deffn
2638
2639@noindent
2640Consider this example:
2641
2642@example
2643(define libressl-instead-of-openssl
2644 ;; This is a procedure to replace OPENSSL by LIBRESSL,
2645 ;; recursively.
2646 (package-input-rewriting `((,openssl . ,libressl))))
2647
2648(define git-with-libressl
2649 (libressl-instead-of-openssl git))
2650@end example
2651
2652@noindent
2653Here we first define a rewriting procedure that replaces @var{openssl}
2654with @var{libressl}. Then we use it to define a @dfn{variant} of the
2655@var{git} package that uses @var{libressl} instead of @var{openssl}.
2656This is exactly what the @option{--with-input} command-line option does
2657(@pxref{Package Transformation Options, @option{--with-input}}).
2658
87eafdbd
TUBK
2659@menu
2660* package Reference :: The package data type.
2661* origin Reference:: The origin data type.
2662@end menu
2663
2664
2665@node package Reference
2666@subsection @code{package} Reference
2667
2668This section summarizes all the options available in @code{package}
2669declarations (@pxref{Defining Packages}).
2670
2671@deftp {Data Type} package
2672This is the data type representing a package recipe.
2673
2674@table @asis
2675@item @code{name}
2676The name of the package, as a string.
2677
2678@item @code{version}
2679The version of the package, as a string.
2680
2681@item @code{source}
da675305
LC
2682An object telling how the source code for the package should be
2683acquired. Most of the time, this is an @code{origin} object, which
2684denotes a file fetched from the Internet (@pxref{origin Reference}). It
2685can also be any other ``file-like'' object such as a @code{local-file},
2686which denotes a file from the local file system (@pxref{G-Expressions,
2687@code{local-file}}).
87eafdbd
TUBK
2688
2689@item @code{build-system}
2690The build system that should be used to build the package (@pxref{Build
2691Systems}).
2692
2693@item @code{arguments} (default: @code{'()})
2694The arguments that should be passed to the build system. This is a
2695list, typically containing sequential keyword-value pairs.
2696
2697@item @code{inputs} (default: @code{'()})
70650c68
LC
2698@itemx @code{native-inputs} (default: @code{'()})
2699@itemx @code{propagated-inputs} (default: @code{'()})
2700@cindex inputs, of packages
2701These fields list dependencies of the package. Each one is a list of
2702tuples, where each tuple has a label for the input (a string) as its
2703first element, a package, origin, or derivation as its second element,
2704and optionally the name of the output thereof that should be used, which
2705defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
f97c9175 2706more on package outputs). For example, the list below specifies three
70650c68 2707inputs:
87eafdbd 2708
70650c68
LC
2709@example
2710`(("libffi" ,libffi)
2711 ("libunistring" ,libunistring)
2712 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2713@end example
2714
2715@cindex cross compilation, package dependencies
2716The distinction between @code{native-inputs} and @code{inputs} is
2717necessary when considering cross-compilation. When cross-compiling,
2718dependencies listed in @code{inputs} are built for the @emph{target}
2719architecture; conversely, dependencies listed in @code{native-inputs}
2720are built for the architecture of the @emph{build} machine.
2721
f97c9175
AE
2722@code{native-inputs} is typically used to list tools needed at
2723build time, but not at run time, such as Autoconf, Automake, pkg-config,
70650c68
LC
2724Gettext, or Bison. @command{guix lint} can report likely mistakes in
2725this area (@pxref{Invoking guix lint}).
2726
2727@anchor{package-propagated-inputs}
2728Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
f97c9175
AE
2729specified packages will be automatically installed alongside the package
2730they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
70650c68
LC
2731package}}, for information on how @command{guix package} deals with
2732propagated inputs.)
21461f27 2733
e0508b6b
LC
2734For example this is necessary when a C/C++ library needs headers of
2735another library to compile, or when a pkg-config file refers to another
2736one @i{via} its @code{Requires} field.
2737
f97c9175
AE
2738Another example where @code{propagated-inputs} is useful is for languages
2739that lack a facility to record the run-time search path akin to the
c8ebb4c4 2740@code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
e0508b6b
LC
2741more. To ensure that libraries written in those languages can find
2742library code they depend on at run time, run-time dependencies must be
2743listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2744
87eafdbd
TUBK
2745@item @code{self-native-input?} (default: @code{#f})
2746This is a Boolean field telling whether the package should use itself as
2747a native input when cross-compiling.
2748
2749@item @code{outputs} (default: @code{'("out")})
2750The list of output names of the package. @xref{Packages with Multiple
2751Outputs}, for typical uses of additional outputs.
2752
2753@item @code{native-search-paths} (default: @code{'()})
2754@itemx @code{search-paths} (default: @code{'()})
2755A list of @code{search-path-specification} objects describing
2756search-path environment variables honored by the package.
2757
2758@item @code{replacement} (default: @code{#f})
f97c9175 2759This must be either @code{#f} or a package object that will be used as a
87eafdbd
TUBK
2760@dfn{replacement} for this package. @xref{Security Updates, grafts},
2761for details.
2762
2763@item @code{synopsis}
2764A one-line description of the package.
2765
2766@item @code{description}
2767A more elaborate description of the package.
2768
2769@item @code{license}
e32171ee 2770@cindex license, of packages
f97c9175
AE
2771The license of the package; a value from @code{(guix licenses)},
2772or a list of such values.
87eafdbd
TUBK
2773
2774@item @code{home-page}
2775The URL to the home-page of the package, as a string.
2776
2777@item @code{supported-systems} (default: @var{%supported-systems})
2778The list of systems supported by the package, as strings of the form
2779@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2780
2781@item @code{maintainers} (default: @code{'()})
2782The list of maintainers of the package, as @code{maintainer} objects.
2783
2784@item @code{location} (default: source location of the @code{package} form)
f97c9175 2785The source location of the package. It is useful to override this when
87eafdbd
TUBK
2786inheriting from another package, in which case this field is not
2787automatically corrected.
2788@end table
2789@end deftp
2790
2791
2792@node origin Reference
2793@subsection @code{origin} Reference
2794
2795This section summarizes all the options available in @code{origin}
2796declarations (@pxref{Defining Packages}).
2797
2798@deftp {Data Type} origin
2799This is the data type representing a source code origin.
2800
2801@table @asis
2802@item @code{uri}
2803An object containing the URI of the source. The object type depends on
2804the @code{method} (see below). For example, when using the
2805@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2806values are: a URL represented as a string, or a list thereof.
2807
2808@item @code{method}
f97c9175 2809A procedure that handles the URI.
87eafdbd
TUBK
2810
2811Examples include:
2812
2813@table @asis
2814@item @var{url-fetch} from @code{(guix download)}
f97c9175 2815download a file from the HTTP, HTTPS, or FTP URL specified in the
87eafdbd
TUBK
2816@code{uri} field;
2817
db97a03a 2818@vindex git-fetch
87eafdbd
TUBK
2819@item @var{git-fetch} from @code{(guix git-download)}
2820clone the Git version control repository, and check out the revision
2821specified in the @code{uri} field as a @code{git-reference} object; a
2822@code{git-reference} looks like this:
2823
2824@example
2825(git-reference
2826 (url "git://git.debian.org/git/pkg-shadow/shadow")
2827 (commit "v4.1.5.1"))
2828@end example
2829@end table
2830
2831@item @code{sha256}
2832A bytevector containing the SHA-256 hash of the source. Typically the
2833@code{base32} form is used here to generate the bytevector from a
2834base-32 string.
2835
db97a03a
LC
2836You can obtain this information using @code{guix download}
2837(@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
2838guix hash}).
2839
87eafdbd
TUBK
2840@item @code{file-name} (default: @code{#f})
2841The file name under which the source code should be saved. When this is
2842@code{#f}, a sensible default value will be used in most cases. In case
2843the source is fetched from a URL, the file name from the URL will be
f97c9175 2844used. For version control checkouts, it is recommended to provide the
87eafdbd
TUBK
2845file name explicitly because the default is not very descriptive.
2846
2847@item @code{patches} (default: @code{'()})
2848A list of file names containing patches to be applied to the source.
2849
0dfebdaa
LC
2850This list of patches must be unconditional. In particular, it cannot
2851depend on the value of @code{%current-system} or
2852@code{%current-target-system}.
2853
87eafdbd 2854@item @code{snippet} (default: @code{#f})
1929fdba
LC
2855A G-expression (@pxref{G-Expressions}) or S-expression that will be run
2856in the source directory. This is a convenient way to modify the source,
2857sometimes more convenient than a patch.
87eafdbd
TUBK
2858
2859@item @code{patch-flags} (default: @code{'("-p1")})
2860A list of command-line flags that should be passed to the @code{patch}
2861command.
2862
2863@item @code{patch-inputs} (default: @code{#f})
2864Input packages or derivations to the patching process. When this is
2865@code{#f}, the usual set of inputs necessary for patching are provided,
2866such as GNU@tie{}Patch.
2867
2868@item @code{modules} (default: @code{'()})
2869A list of Guile modules that should be loaded during the patching
2870process and while running the code in the @code{snippet} field.
2871
87eafdbd
TUBK
2872@item @code{patch-guile} (default: @code{#f})
2873The Guile package that should be used in the patching process. When
2874this is @code{#f}, a sensible default is used.
2875@end table
2876@end deftp
2877
9c1edabd 2878
7458bd0a
LC
2879@node Build Systems
2880@section Build Systems
2881
2882@cindex build system
2883Each package definition specifies a @dfn{build system} and arguments for
2884that build system (@pxref{Defining Packages}). This @code{build-system}
f97c9175 2885field represents the build procedure of the package, as well as implicit
7458bd0a
LC
2886dependencies of that build procedure.
2887
2888Build systems are @code{<build-system>} objects. The interface to
2889create and manipulate them is provided by the @code{(guix build-system)}
2890module, and actual build systems are exported by specific modules.
2891
f5fd4fd2 2892@cindex bag (low-level package representation)
0d5a559f
LC
2893Under the hood, build systems first compile package objects to
2894@dfn{bags}. A @dfn{bag} is like a package, but with less
2895ornamentation---in other words, a bag is a lower-level representation of
2896a package, which includes all the inputs of that package, including some
2897that were implicitly added by the build system. This intermediate
2898representation is then compiled to a derivation (@pxref{Derivations}).
2899
7458bd0a
LC
2900Build systems accept an optional list of @dfn{arguments}. In package
2901definitions, these are passed @i{via} the @code{arguments} field
2902(@pxref{Defining Packages}). They are typically keyword arguments
2903(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
2904Guile Reference Manual}). The value of these arguments is usually
2905evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
2906by the daemon (@pxref{Derivations}).
2907
2908The main build system is @var{gnu-build-system}, which implements the
f97c9175 2909standard build procedure for GNU and many other packages. It
7458bd0a
LC
2910is provided by the @code{(guix build-system gnu)} module.
2911
2912@defvr {Scheme Variable} gnu-build-system
2913@var{gnu-build-system} represents the GNU Build System, and variants
2914thereof (@pxref{Configuration, configuration and makefile conventions,,
2915standards, GNU Coding Standards}).
2916
2917@cindex build phases
f97c9175 2918In a nutshell, packages using it are configured, built, and installed with
7458bd0a
LC
2919the usual @code{./configure && make && make check && make install}
2920command sequence. In practice, a few additional steps are often needed.
2921All these steps are split up in separate @dfn{phases},
2922notably@footnote{Please see the @code{(guix build gnu-build-system)}
2923modules for more details about the build phases.}:
2924
2925@table @code
2926@item unpack
2927Unpack the source tarball, and change the current directory to the
2928extracted source tree. If the source is actually a directory, copy it
2929to the build tree, and enter that directory.
2930
2931@item patch-source-shebangs
2932Patch shebangs encountered in source files so they refer to the right
2933store file names. For instance, this changes @code{#!/bin/sh} to
2934@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
2935
2936@item configure
2937Run the @file{configure} script with a number of default options, such
2938as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
2939by the @code{#:configure-flags} argument.
2940
2941@item build
2942Run @code{make} with the list of flags specified with
0917e80e 2943@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
2944(the default), build with @code{make -j}.
2945
2946@item check
2947Run @code{make check}, or some other target specified with
2948@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
2949@code{#:parallel-tests?} argument is true (the default), run @code{make
2950check -j}.
2951
2952@item install
2953Run @code{make install} with the flags listed in @code{#:make-flags}.
2954
2955@item patch-shebangs
2956Patch shebangs on the installed executable files.
2957
2958@item strip
2959Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
2960is false), copying them to the @code{debug} output when available
2961(@pxref{Installing Debugging Files}).
2962@end table
2963
2964@vindex %standard-phases
2965The build-side module @code{(guix build gnu-build-system)} defines
2966@var{%standard-phases} as the default list of build phases.
2967@var{%standard-phases} is a list of symbol/procedure pairs, where the
2968procedure implements the actual phase.
2969
2970The list of phases used for a particular package can be changed with the
2971@code{#:phases} parameter. For instance, passing:
2972
2973@example
c2c5dc79 2974#:phases (modify-phases %standard-phases (delete 'configure))
7458bd0a
LC
2975@end example
2976
9bf404e9 2977means that all the phases described above will be used, except the
7458bd0a
LC
2978@code{configure} phase.
2979
2980In addition, this build system ensures that the ``standard'' environment
2981for GNU packages is available. This includes tools such as GCC, libc,
2982Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
f97c9175
AE
2983build-system gnu)} module for a complete list). We call these the
2984@dfn{implicit inputs} of a package, because package definitions do not
7458bd0a
LC
2985have to mention them.
2986@end defvr
2987
2988Other @code{<build-system>} objects are defined to support other
2989conventions and tools used by free software packages. They inherit most
2990of @var{gnu-build-system}, and differ mainly in the set of inputs
2991implicitly added to the build process, and in the list of phases
2992executed. Some of these build systems are listed below.
2993
5f7a1a4d
RW
2994@defvr {Scheme Variable} ant-build-system
2995This variable is exported by @code{(guix build-system ant)}. It
2996implements the build procedure for Java packages that can be built with
2997@url{http://ant.apache.org/, Ant build tool}.
2998
2999It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
3000provided by the @code{icedtea} package to the set of inputs. Different
3001packages can be specified with the @code{#:ant} and @code{#:jdk}
3002parameters, respectively.
3003
3004When the original package does not provide a suitable Ant build file,
3005the parameter @code{#:jar-name} can be used to generate a minimal Ant
3006build file @file{build.xml} with tasks to build the specified jar
3007archive.
3008
3009The parameter @code{#:build-target} can be used to specify the Ant task
3010that should be run during the @code{build} phase. By default the
3011``jar'' task will be run.
3012
3013@end defvr
3014
a1b30f99
AP
3015@defvr {Scheme Variable} asdf-build-system/source
3016@defvrx {Scheme Variable} asdf-build-system/sbcl
3017@defvrx {Scheme Variable} asdf-build-system/ecl
3018
3019These variables, exported by @code{(guix build-system asdf)}, implement
3020build procedures for Common Lisp packages using
3021@url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
3022definition facility for Common Lisp programs and libraries.
3023
3024The @code{asdf-build-system/source} system installs the packages in
3025source form, and can be loaded using any common lisp implementation, via
3026ASDF. The others, such as @code{asdf-build-system/sbcl}, install binary
3027systems in the format which a particular implementation understands.
3028These build systems can also be used to produce executable programs, or
3029lisp images which contain a set of packages pre-loaded.
3030
3031The build system uses naming conventions. For binary packages, the
3032package itself as well as its run-time dependencies should begin their
3033name with the lisp implementation, such as @code{sbcl-} for
3034@code{asdf-build-system/sbcl}. Beginning the input name with this
3035prefix will allow the build system to encode its location into the
3036resulting library, so that the input can be found at run-time.
3037
3038If dependencies are used only for tests, it is convenient to use a
3039different prefix in order to avoid having a run-time dependency on such
3040systems. For example,
3041
3042@example
3043(define-public sbcl-bordeaux-threads
3044 (package
3045 ...
3046 (native-inputs `(("tests:cl-fiveam" ,sbcl-fiveam)))
3047 ...))
3048@end example
3049
3050Additionally, the corresponding source package should be labeled using
3051the same convention as python packages (see @ref{Python Modules}), using
3052the @code{cl-} prefix.
3053
3054For binary packages, each system should be defined as a Guix package.
3055If one package @code{origin} contains several systems, package variants
3056can be created in order to build all the systems. Source packages,
3057which use @code{asdf-build-system/source}, may contain several systems.
3058
3059In order to create executable programs and images, the build-side
3060procedures @code{build-program} and @code{build-image} can be used.
3061They should be called in a build phase after the @code{create-symlinks}
3062phase, so that the system which was just built can be used within the
3063resulting image. @code{build-program} requires a list of Common Lisp
3064expressions to be passed as the @code{#:entry-program} argument.
3065
3066If the system is not defined within its own @code{.asd} file of the same
3067name, then the @code{#:asd-file} parameter should be used to specify
3068which file the system is defined in.
3069
3070@end defvr
3071
7458bd0a
LC
3072@defvr {Scheme Variable} cmake-build-system
3073This variable is exported by @code{(guix build-system cmake)}. It
3074implements the build procedure for packages using the
3075@url{http://www.cmake.org, CMake build tool}.
3076
3077It automatically adds the @code{cmake} package to the set of inputs.
3078Which package is used can be specified with the @code{#:cmake}
3079parameter.
9849cfc1
LC
3080
3081The @code{#:configure-flags} parameter is taken as a list of flags
3082passed to the @command{cmake} command. The @code{#:build-type}
3083parameter specifies in abstract terms the flags passed to the compiler;
3084it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
3085debugging information''), which roughly means that code is compiled with
3086@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
3087@end defvr
3088
3afcf52b
FB
3089@defvr {Scheme Variable} glib-or-gtk-build-system
3090This variable is exported by @code{(guix build-system glib-or-gtk)}. It
3091is intended for use with packages making use of GLib or GTK+.
3092
3093This build system adds the following two phases to the ones defined by
3094@var{gnu-build-system}:
3095
3096@table @code
3097@item glib-or-gtk-wrap
f97c9175
AE
3098The phase @code{glib-or-gtk-wrap} ensures that programs in
3099@file{bin/} are able to find GLib ``schemas'' and
3afcf52b
FB
3100@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
3101modules}. This is achieved by wrapping the programs in launch scripts
3102that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
3103environment variables.
3104
73aa8ddb
LC
3105It is possible to exclude specific package outputs from that wrapping
3106process by listing their names in the
3107@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
3108when an output is known not to contain any GLib or GTK+ binaries, and
3109where wrapping would gratuitously add a dependency of that output on
3110GLib and GTK+.
3111
3afcf52b 3112@item glib-or-gtk-compile-schemas
f97c9175 3113The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3afcf52b 3114@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
f97c9175 3115GSettings schemas} of GLib are compiled. Compilation is performed by the
3afcf52b
FB
3116@command{glib-compile-schemas} program. It is provided by the package
3117@code{glib:bin} which is automatically imported by the build system.
3118The @code{glib} package providing @command{glib-compile-schemas} can be
3119specified with the @code{#:glib} parameter.
3120@end table
3121
3122Both phases are executed after the @code{install} phase.
3123@end defvr
3124
7458bd0a
LC
3125@defvr {Scheme Variable} python-build-system
3126This variable is exported by @code{(guix build-system python)}. It
3127implements the more or less standard build procedure used by Python
3128packages, which consists in running @code{python setup.py build} and
3129then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
3130
3131For packages that install stand-alone Python programs under @code{bin/},
f97c9175 3132it takes care of wrapping these programs so that their @code{PYTHONPATH}
7458bd0a
LC
3133environment variable points to all the Python libraries they depend on.
3134
8a46205b
CM
3135Which Python package is used to perform the build can be specified with
3136the @code{#:python} parameter. This is a useful way to force a package
3137to be built for a specific version of the Python interpreter, which
3138might be necessary if the package is only compatible with a single
3139interpreter version.
7458bd0a
LC
3140@end defvr
3141
3142@defvr {Scheme Variable} perl-build-system
3143This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
3144implements the standard build procedure for Perl packages, which either
3145consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
3146followed by @code{Build} and @code{Build install}; or in running
3147@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
f97c9175 3148@code{make} and @code{make install}, depending on which of
2d2a53fc
EB
3149@code{Build.PL} or @code{Makefile.PL} is present in the package
3150distribution. Preference is given to the former if both @code{Build.PL}
3151and @code{Makefile.PL} exist in the package distribution. This
3152preference can be reversed by specifying @code{#t} for the
3153@code{#:make-maker?} parameter.
3154
3155The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
3156passes flags specified by the @code{#:make-maker-flags} or
3157@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
3158
3159Which Perl package is used can be specified with @code{#:perl}.
3160@end defvr
3161
f8f3bef6
RW
3162@defvr {Scheme Variable} r-build-system
3163This variable is exported by @code{(guix build-system r)}. It
3164implements the build procedure used by @uref{http://r-project.org, R}
3165packages, which essentially is little more than running @code{R CMD
3166INSTALL --library=/gnu/store/@dots{}} in an environment where
3167@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
3168are run after installation using the R function
3169@code{tools::testInstalledPackage}.
3170@end defvr
3171
c08f9818
DT
3172@defvr {Scheme Variable} ruby-build-system
3173This variable is exported by @code{(guix build-system ruby)}. It
3174implements the RubyGems build procedure used by Ruby packages, which
3175involves running @code{gem build} followed by @code{gem install}.
3176
5dc87623
DT
3177The @code{source} field of a package that uses this build system
3178typically references a gem archive, since this is the format that Ruby
3179developers use when releasing their software. The build system unpacks
3180the gem archive, potentially patches the source, runs the test suite,
3181repackages the gem, and installs it. Additionally, directories and
3182tarballs may be referenced to allow building unreleased gems from Git or
3183a traditional source release tarball.
e83c6d00 3184
c08f9818 3185Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
3186parameter. A list of additional flags to be passed to the @command{gem}
3187command can be specified with the @code{#:gem-flags} parameter.
c08f9818 3188@end defvr
7458bd0a 3189
a677c726
RW
3190@defvr {Scheme Variable} waf-build-system
3191This variable is exported by @code{(guix build-system waf)}. It
3192implements a build procedure around the @code{waf} script. The common
3193phases---@code{configure}, @code{build}, and @code{install}---are
3194implemented by passing their names as arguments to the @code{waf}
3195script.
3196
3197The @code{waf} script is executed by the Python interpreter. Which
3198Python package is used to run the script can be specified with the
3199@code{#:python} parameter.
3200@end defvr
3201
14dfdf2e
FB
3202@defvr {Scheme Variable} haskell-build-system
3203This variable is exported by @code{(guix build-system haskell)}. It
3204implements the Cabal build procedure used by Haskell packages, which
3205involves running @code{runhaskell Setup.hs configure
3206--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
3207Instead of installing the package by running @code{runhaskell Setup.hs
3208install}, to avoid trying to register libraries in the read-only
3209compiler store directory, the build system uses @code{runhaskell
3210Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
3211addition, the build system generates the package documentation by
3212running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
3213is passed. Optional Haddock parameters can be passed with the help of
3214the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
3215not found, the build system looks for @code{Setup.lhs} instead.
3216
3217Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 3218parameter which defaults to @code{ghc}.
14dfdf2e
FB
3219@end defvr
3220
e9137a53
FB
3221@defvr {Scheme Variable} emacs-build-system
3222This variable is exported by @code{(guix build-system emacs)}. It
f97c9175
AE
3223implements an installation procedure similar to the packaging system
3224of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
e9137a53
FB
3225
3226It first creates the @code{@var{package}-autoloads.el} file, then it
3227byte compiles all Emacs Lisp files. Differently from the Emacs
3228packaging system, the Info documentation files are moved to the standard
3229documentation directory and the @file{dir} file is deleted. Each
3230package is installed in its own directory under
3231@file{share/emacs/site-lisp/guix.d}.
3232@end defvr
3233
7458bd0a
LC
3234Lastly, for packages that do not need anything as sophisticated, a
3235``trivial'' build system is provided. It is trivial in the sense that
3236it provides basically no support: it does not pull any implicit inputs,
3237and does not have a notion of build phases.
3238
3239@defvr {Scheme Variable} trivial-build-system
3240This variable is exported by @code{(guix build-system trivial)}.
3241
3242This build system requires a @code{#:builder} argument. This argument
f97c9175 3243must be a Scheme expression that builds the package output(s)---as
7458bd0a
LC
3244with @code{build-expression->derivation} (@pxref{Derivations,
3245@code{build-expression->derivation}}).
3246@end defvr
3247
568717fd
LC
3248@node The Store
3249@section The Store
3250
e531ac2a 3251@cindex store
1ddee424 3252@cindex store items
e531ac2a
LC
3253@cindex store paths
3254
f97c9175
AE
3255Conceptually, the @dfn{store} is the place where derivations that have
3256been built successfully are stored---by default, @file{/gnu/store}.
1ddee424
LC
3257Sub-directories in the store are referred to as @dfn{store items} or
3258sometimes @dfn{store paths}. The store has an associated database that
3259contains information such as the store paths referred to by each store
3260path, and the list of @emph{valid} store items---results of successful
ef5f5c86
LC
3261builds. This database resides in @file{@var{localstatedir}/guix/db},
3262where @var{localstatedir} is the state directory specified @i{via}
3263@option{--localstatedir} at configure time, usually @file{/var}.
1ddee424
LC
3264
3265The store is @emph{always} accessed by the daemon on behalf of its clients
e531ac2a 3266(@pxref{Invoking guix-daemon}). To manipulate the store, clients
f97c9175
AE
3267connect to the daemon over a Unix-domain socket, send requests to it,
3268and read the result---these are remote procedure calls, or RPCs.
e531ac2a 3269
1ddee424
LC
3270@quotation Note
3271Users must @emph{never} modify files under @file{/gnu/store} directly.
3272This would lead to inconsistencies and break the immutability
3273assumptions of Guix's functional model (@pxref{Introduction}).
3274
3275@xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3276how to check the integrity of the store and attempt recovery from
3277accidental modifications.
3278@end quotation
3279
e531ac2a
LC
3280The @code{(guix store)} module provides procedures to connect to the
3281daemon, and to perform RPCs. These are described below.
3282
3283@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3284Connect to the daemon over the Unix-domain socket at @var{file}. When
3285@var{reserve-space?} is true, instruct it to reserve a little bit of
3286extra space on the file system so that the garbage collector can still
f97c9175 3287operate should the disk become full. Return a server object.
e531ac2a
LC
3288
3289@var{file} defaults to @var{%default-socket-path}, which is the normal
3290location given the options that were passed to @command{configure}.
3291@end deffn
3292
3293@deffn {Scheme Procedure} close-connection @var{server}
3294Close the connection to @var{server}.
3295@end deffn
3296
3297@defvr {Scheme Variable} current-build-output-port
3298This variable is bound to a SRFI-39 parameter, which refers to the port
3299where build and error logs sent by the daemon should be written.
3300@end defvr
3301
3302Procedures that make RPCs all take a server object as their first
3303argument.
3304
3305@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
06b76acc
LC
3306@cindex invalid store items
3307Return @code{#t} when @var{path} designates a valid store item and
3308@code{#f} otherwise (an invalid item may exist on disk but still be
3309invalid, for instance because it is the result of an aborted or failed
3310build.)
3311
3312A @code{&nix-protocol-error} condition is raised if @var{path} is not
3313prefixed by the store directory (@file{/gnu/store}).
e531ac2a
LC
3314@end deffn
3315
cfbf9160 3316@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
3317Add @var{text} under file @var{name} in the store, and return its store
3318path. @var{references} is the list of store paths referred to by the
3319resulting store path.
3320@end deffn
3321
874e6874 3322@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
3323Build @var{derivations} (a list of @code{<derivation>} objects or
3324derivation paths), and return when the worker is done building them.
3325Return @code{#t} on success.
874e6874
LC
3326@end deffn
3327
b860f382
LC
3328Note that the @code{(guix monads)} module provides a monad as well as
3329monadic versions of the above procedures, with the goal of making it
3330more convenient to work with code that accesses the store (@pxref{The
3331Store Monad}).
3332
e531ac2a
LC
3333@c FIXME
3334@i{This section is currently incomplete.}
568717fd
LC
3335
3336@node Derivations
3337@section Derivations
3338
874e6874
LC
3339@cindex derivations
3340Low-level build actions and the environment in which they are performed
70458ed5 3341are represented by @dfn{derivations}. A derivation contains the
874e6874
LC
3342following pieces of information:
3343
3344@itemize
3345@item
3346The outputs of the derivation---derivations produce at least one file or
3347directory in the store, but may produce more.
3348
3349@item
3350The inputs of the derivations, which may be other derivations or plain
3351files in the store (patches, build scripts, etc.)
3352
3353@item
3354The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3355
3356@item
3357The file name of a build script in the store, along with the arguments
3358to be passed.
3359
3360@item
3361A list of environment variables to be defined.
3362
3363@end itemize
3364
3365@cindex derivation path
3366Derivations allow clients of the daemon to communicate build actions to
3367the store. They exist in two forms: as an in-memory representation,
3368both on the client- and daemon-side, and as files in the store whose
3369name end in @code{.drv}---these files are referred to as @dfn{derivation
3370paths}. Derivations paths can be passed to the @code{build-derivations}
3371procedure to perform the build actions they prescribe (@pxref{The
3372Store}).
3373
3374The @code{(guix derivations)} module provides a representation of
3375derivations as Scheme objects, along with procedures to create and
3376otherwise manipulate derivations. The lowest-level primitive to create
3377a derivation is the @code{derivation} procedure:
3378
1909431c
LC
3379@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3380 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 3381 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 3382 [#:system (%current-system)] [#:references-graphs #f] @
35b5ca78
LC
3383 [#:allowed-references #f] [#:disallowed-references #f] @
3384 [#:leaked-env-vars #f] [#:local-build? #f] @
4a6aeb67 3385 [#:substitutable? #t]
59688fc4
LC
3386Build a derivation with the given arguments, and return the resulting
3387@code{<derivation>} object.
874e6874 3388
2096ef47 3389When @var{hash} and @var{hash-algo} are given, a
874e6874 3390@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
3391known in advance, such as a file download. If, in addition,
3392@var{recursive?} is true, then that fixed output may be an executable
3393file or a directory and @var{hash} must be the hash of an archive
3394containing this output.
5b0c9d16 3395
858e9282 3396When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
3397name/store path pairs. In that case, the reference graph of each store
3398path is exported in the build environment in the corresponding file, in
3399a simple text format.
1909431c 3400
b53be755 3401When @var{allowed-references} is true, it must be a list of store items
35b5ca78
LC
3402or outputs that the derivation's output may refer to. Likewise,
3403@var{disallowed-references}, if true, must be a list of things the
3404outputs may @emph{not} refer to.
b53be755 3405
c0468155
LC
3406When @var{leaked-env-vars} is true, it must be a list of strings
3407denoting environment variables that are allowed to ``leak'' from the
3408daemon's environment to the build environment. This is only applicable
3409to fixed-output derivations---i.e., when @var{hash} is true. The main
3410use is to allow variables such as @code{http_proxy} to be passed to
3411derivations that download files.
3412
1909431c
LC
3413When @var{local-build?} is true, declare that the derivation is not a
3414good candidate for offloading and should rather be built locally
3415(@pxref{Daemon Offload Setup}). This is the case for small derivations
3416where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
3417
3418When @var{substitutable?} is false, declare that substitutes of the
3419derivation's output should not be used (@pxref{Substitutes}). This is
3420useful, for instance, when building packages that capture details of the
3421host CPU instruction set.
874e6874
LC
3422@end deffn
3423
3424@noindent
3425Here's an example with a shell script as its builder, assuming
3426@var{store} is an open connection to the daemon, and @var{bash} points
3427to a Bash executable in the store:
3428
3429@lisp
3430(use-modules (guix utils)
3431 (guix store)
3432 (guix derivations))
3433
59688fc4
LC
3434(let ((builder ; add the Bash script to the store
3435 (add-text-to-store store "my-builder.sh"
3436 "echo hello world > $out\n" '())))
3437 (derivation store "foo"
3438 bash `("-e" ,builder)
21b679f6 3439 #:inputs `((,bash) (,builder))
59688fc4 3440 #:env-vars '(("HOME" . "/homeless"))))
834129e0 3441@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
3442@end lisp
3443
21b679f6
LC
3444As can be guessed, this primitive is cumbersome to use directly. A
3445better approach is to write build scripts in Scheme, of course! The
3446best course of action for that is to write the build code as a
3447``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 3448information, @pxref{G-Expressions}.
21b679f6 3449
f2fadbc1
AE
3450Once upon a time, @code{gexp->derivation} did not exist and constructing
3451derivations with build code written in Scheme was achieved with
3452@code{build-expression->derivation}, documented below. This procedure
3453is now deprecated in favor of the much nicer @code{gexp->derivation}.
3454
3455@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3456 @var{name} @var{exp} @
3457 [#:system (%current-system)] [#:inputs '()] @
3458 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3459 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3460 [#:references-graphs #f] [#:allowed-references #f] @
35b5ca78 3461 [#:disallowed-references #f] @
f2fadbc1
AE
3462 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3463Return a derivation that executes Scheme expression @var{exp} as a
3464builder for derivation @var{name}. @var{inputs} must be a list of
3465@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3466@code{"out"} is assumed. @var{modules} is a list of names of Guile
3467modules from the current search path to be copied in the store,
3468compiled, and made available in the load path during the execution of
3469@var{exp}---e.g., @code{((guix build utils) (guix build
3470gnu-build-system))}.
3471
3472@var{exp} is evaluated in an environment where @code{%outputs} is bound
3473to a list of output/path pairs, and where @code{%build-inputs} is bound
3474to a list of string/output-path pairs made from @var{inputs}.
3475Optionally, @var{env-vars} is a list of string pairs specifying the name
3476and value of environment variables visible to the builder. The builder
3477terminates by passing the result of @var{exp} to @code{exit}; thus, when
3478@var{exp} returns @code{#f}, the build is considered to have failed.
3479
3480@var{exp} is built using @var{guile-for-build} (a derivation). When
3481@var{guile-for-build} is omitted or is @code{#f}, the value of the
3482@code{%guile-for-build} fluid is used instead.
3483
3484See the @code{derivation} procedure for the meaning of
35b5ca78
LC
3485@var{references-graphs}, @var{allowed-references},
3486@var{disallowed-references}, @var{local-build?}, and
3487@var{substitutable?}.
f2fadbc1
AE
3488@end deffn
3489
3490@noindent
3491Here's an example of a single-output derivation that creates a directory
3492containing one file:
3493
3494@lisp
3495(let ((builder '(let ((out (assoc-ref %outputs "out")))
3496 (mkdir out) ; create /gnu/store/@dots{}-goo
3497 (call-with-output-file (string-append out "/test")
3498 (lambda (p)
3499 (display '(hello guix) p))))))
3500 (build-expression->derivation store "goo" builder))
3501
3502@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3503@end lisp
3504
568717fd 3505
b860f382
LC
3506@node The Store Monad
3507@section The Store Monad
3508
3509@cindex monad
3510
3511The procedures that operate on the store described in the previous
3512sections all take an open connection to the build daemon as their first
3513argument. Although the underlying model is functional, they either have
3514side effects or depend on the current state of the store.
3515
3516The former is inconvenient: the connection to the build daemon has to be
3517carried around in all those functions, making it impossible to compose
3518functions that do not take that parameter with functions that do. The
3519latter can be problematic: since store operations have side effects
3520and/or depend on external state, they have to be properly sequenced.
3521
3522@cindex monadic values
3523@cindex monadic functions
3524This is where the @code{(guix monads)} module comes in. This module
3525provides a framework for working with @dfn{monads}, and a particularly
3526useful monad for our uses, the @dfn{store monad}. Monads are a
3527construct that allows two things: associating ``context'' with values
3528(in our case, the context is the store), and building sequences of
4827b36d 3529computations (here computations include accesses to the store). Values
b860f382
LC
3530in a monad---values that carry this additional context---are called
3531@dfn{monadic values}; procedures that return such values are called
3532@dfn{monadic procedures}.
3533
3534Consider this ``normal'' procedure:
3535
3536@example
45adbd62
LC
3537(define (sh-symlink store)
3538 ;; Return a derivation that symlinks the 'bash' executable.
3539 (let* ((drv (package-derivation store bash))
3540 (out (derivation->output-path drv))
3541 (sh (string-append out "/bin/bash")))
3542 (build-expression->derivation store "sh"
3543 `(symlink ,sh %output))))
b860f382
LC
3544@end example
3545
c6f30b81
LC
3546Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3547as a monadic function:
b860f382
LC
3548
3549@example
45adbd62 3550(define (sh-symlink)
b860f382 3551 ;; Same, but return a monadic value.
c6f30b81
LC
3552 (mlet %store-monad ((drv (package->derivation bash)))
3553 (gexp->derivation "sh"
3554 #~(symlink (string-append #$drv "/bin/bash")
3555 #$output))))
b860f382
LC
3556@end example
3557
4827b36d 3558There are several things to note in the second version: the @code{store}
c6f30b81
LC
3559parameter is now implicit and is ``threaded'' in the calls to the
3560@code{package->derivation} and @code{gexp->derivation} monadic
3561procedures, and the monadic value returned by @code{package->derivation}
3562is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3563
3564As it turns out, the call to @code{package->derivation} can even be
3565omitted since it will take place implicitly, as we will see later
3566(@pxref{G-Expressions}):
3567
3568@example
3569(define (sh-symlink)
3570 (gexp->derivation "sh"
3571 #~(symlink (string-append #$bash "/bin/bash")
3572 #$output)))
3573@end example
b860f382 3574
7ce21611 3575@c See
a01ad638 3576@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
7ce21611
LC
3577@c for the funny quote.
3578Calling the monadic @code{sh-symlink} has no effect. As someone once
3579said, ``you exit a monad like you exit a building on fire: by running''.
3580So, to exit the monad and get the desired effect, one must use
3581@code{run-with-store}:
b860f382
LC
3582
3583@example
8e9aa37f
CAW
3584(run-with-store (open-connection) (sh-symlink))
3585@result{} /gnu/store/...-sh-symlink
b860f382
LC
3586@end example
3587
f97c9175 3588Note that the @code{(guix monad-repl)} module extends the Guile REPL with
b9b86078 3589new ``meta-commands'' to make it easier to deal with monadic procedures:
f97c9175 3590@code{run-in-store}, and @code{enter-store-monad}. The former is used
b9b86078
LC
3591to ``run'' a single monadic value through the store:
3592
3593@example
3594scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3595$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3596@end example
3597
3598The latter enters a recursive REPL, where all the return values are
3599automatically run through the store:
3600
3601@example
3602scheme@@(guile-user)> ,enter-store-monad
3603store-monad@@(guile-user) [1]> (package->derivation hello)
3604$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3605store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3606$3 = "/gnu/store/@dots{}-foo"
3607store-monad@@(guile-user) [1]> ,q
3608scheme@@(guile-user)>
3609@end example
3610
3611@noindent
3612Note that non-monadic values cannot be returned in the
3613@code{store-monad} REPL.
3614
e87f0591
LC
3615The main syntactic forms to deal with monads in general are provided by
3616the @code{(guix monads)} module and are described below.
b860f382
LC
3617
3618@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3619Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3620in @var{monad}.
3621@end deffn
3622
3623@deffn {Scheme Syntax} return @var{val}
3624Return a monadic value that encapsulates @var{val}.
3625@end deffn
3626
751630c9 3627@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3628@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3629procedures @var{mproc}@dots{}@footnote{This operation is commonly
3630referred to as ``bind'', but that name denotes an unrelated procedure in
3631Guile. Thus we use this somewhat cryptic symbol inherited from the
3632Haskell language.}. There can be one @var{mproc} or several of them, as
3633in this example:
3634
3635@example
3636(run-with-state
3637 (with-monad %state-monad
3638 (>>= (return 1)
3639 (lambda (x) (return (+ 1 x)))
3640 (lambda (x) (return (* 2 x)))))
3641 'some-state)
3642
3643@result{} 4
3644@result{} some-state
3645@end example
b860f382
LC
3646@end deffn
3647
3648@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3649 @var{body} ...
3650@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3651 @var{body} ...
3652Bind the variables @var{var} to the monadic values @var{mval} in
3653@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3654``normal'' value @var{val}, as per @code{let}.
3655
3656@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3657(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3658@end deffn
3659
405a9d4e
LC
3660@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3661Bind @var{mexp} and the following monadic expressions in sequence,
3662returning the result of the last expression.
3663
3664This is akin to @code{mlet}, except that the return values of the
3665monadic expressions are ignored. In that sense, it is analogous to
3666@code{begin}, but applied to monadic expressions.
3667@end deffn
3668
561fb6c3
LC
3669@cindex state monad
3670The @code{(guix monads)} module provides the @dfn{state monad}, which
3671allows an additional value---the state---to be @emph{threaded} through
3672monadic procedure calls.
3673
3674@defvr {Scheme Variable} %state-monad
3675The state monad. Procedures in the state monad can access and change
3676the state that is threaded.
3677
3678Consider the example below. The @code{square} procedure returns a value
3679in the state monad. It returns the square of its argument, but also
3680increments the current state value:
3681
3682@example
3683(define (square x)
3684 (mlet %state-monad ((count (current-state)))
3685 (mbegin %state-monad
3686 (set-current-state (+ 1 count))
3687 (return (* x x)))))
3688
3689(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3690@result{} (0 1 4)
3691@result{} 3
3692@end example
3693
3694When ``run'' through @var{%state-monad}, we obtain that additional state
3695value, which is the number of @code{square} calls.
3696@end defvr
3697
3698@deffn {Monadic Procedure} current-state
3699Return the current state as a monadic value.
3700@end deffn
3701
3702@deffn {Monadic Procedure} set-current-state @var{value}
3703Set the current state to @var{value} and return the previous state as a
3704monadic value.
3705@end deffn
3706
3707@deffn {Monadic Procedure} state-push @var{value}
3708Push @var{value} to the current state, which is assumed to be a list,
3709and return the previous state as a monadic value.
3710@end deffn
3711
3712@deffn {Monadic Procedure} state-pop
3713Pop a value from the current state and return it as a monadic value.
3714The state is assumed to be a list.
3715@end deffn
3716
3717@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3718Run monadic value @var{mval} starting with @var{state} as the initial
3719state. Return two values: the resulting value, and the resulting state.
3720@end deffn
3721
e87f0591
LC
3722The main interface to the store monad, provided by the @code{(guix
3723store)} module, is as follows.
b860f382
LC
3724
3725@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3726The store monad---an alias for @var{%state-monad}.
3727
3728Values in the store monad encapsulate accesses to the store. When its
3729effect is needed, a value of the store monad must be ``evaluated'' by
3730passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3731@end defvr
3732
3733@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3734Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3735open store connection.
3736@end deffn
3737
ad372953 3738@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3739Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3740containing @var{text}, a string. @var{references} is a list of store items that the
3741resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3742@end deffn
3743
0a90af15 3744@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
1ec32f4a 3745 [#:recursive? #t] [#:select? (const #t)]
0a90af15
LC
3746Return the name of @var{file} once interned in the store. Use
3747@var{name} as its store name, or the basename of @var{file} if
3748@var{name} is omitted.
3749
3750When @var{recursive?} is true, the contents of @var{file} are added
3751recursively; if @var{file} designates a flat file and @var{recursive?}
3752is true, its contents are added, and its permission bits are kept.
3753
1ec32f4a
LC
3754When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3755@var{stat})} for each directory entry, where @var{file} is the entry's
3756absolute file name and @var{stat} is the result of @code{lstat}; exclude
3757entries for which @var{select?} does not return true.
3758
0a90af15
LC
3759The example below adds a file to the store, under two different names:
3760
3761@example
3762(run-with-store (open-connection)
3763 (mlet %store-monad ((a (interned-file "README"))
3764 (b (interned-file "README" "LEGU-MIN")))
3765 (return (list a b))))
3766
3767@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3768@end example
3769
3770@end deffn
3771
e87f0591
LC
3772The @code{(guix packages)} module exports the following package-related
3773monadic procedures:
3774
b860f382 3775@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b 3776 [#:system (%current-system)] [#:target #f] @
f97c9175
AE
3777 [#:output "out"]
3778Return as a monadic
b860f382
LC
3779value in the absolute file name of @var{file} within the @var{output}
3780directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3781of the @var{output} directory of @var{package}. When @var{target} is
3782true, use it as a cross-compilation target triplet.
b860f382
LC
3783@end deffn
3784
b860f382 3785@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3786@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3787 @var{target} [@var{system}]
3788Monadic version of @code{package-derivation} and
3789@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3790@end deffn
3791
3792
21b679f6
LC
3793@node G-Expressions
3794@section G-Expressions
3795
3796@cindex G-expression
3797@cindex build code quoting
3798So we have ``derivations'', which represent a sequence of build actions
3799to be performed to produce an item in the store (@pxref{Derivations}).
f97c9175 3800These build actions are performed when asking the daemon to actually
21b679f6
LC
3801build the derivations; they are run by the daemon in a container
3802(@pxref{Invoking guix-daemon}).
3803
3804@cindex strata of code
f97c9175 3805It should come as no surprise that we like to write these build actions
21b679f6
LC
3806in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3807code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3808Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3809Kiselyov, who has written insightful
3810@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3811on this topic}, refers to this kind of code generation as
3812@dfn{staging}.}: the ``host code''---code that defines packages, talks
3813to the daemon, etc.---and the ``build code''---code that actually
3814performs build actions, such as making directories, invoking
3815@command{make}, etc.
21b679f6
LC
3816
3817To describe a derivation and its build actions, one typically needs to
3818embed build code inside host code. It boils down to manipulating build
f97c9175 3819code as data, and the homoiconicity of Scheme---code has a direct
21b679f6 3820representation as data---comes in handy for that. But we need more than
f97c9175 3821the normal @code{quasiquote} mechanism in Scheme to construct build
21b679f6
LC
3822expressions.
3823
3824The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3825S-expressions adapted to build expressions. G-expressions, or
f97c9175 3826@dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
21b679f6 3827@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
f97c9175
AE
3828@code{#$}, and @code{#$@@}), which are comparable to
3829@code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
4827b36d 3830respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
f97c9175 3831GNU Guile Reference Manual}). However, there are major differences:
21b679f6
LC
3832
3833@itemize
3834@item
3835Gexps are meant to be written to a file and run or manipulated by other
3836processes.
3837
3838@item
b39fc6f7
LC
3839When a high-level object such as a package or derivation is unquoted
3840inside a gexp, the result is as if its output file name had been
3841introduced.
ff40e9b7 3842
21b679f6
LC
3843@item
3844Gexps carry information about the packages or derivations they refer to,
3845and these dependencies are automatically added as inputs to the build
3846processes that use them.
3847@end itemize
3848
c2b84676 3849@cindex lowering, of high-level objects in gexps
343eacbe
LC
3850This mechanism is not limited to package and derivation
3851objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3852derivations or files in the store can be defined,
3853such that these objects can also be inserted
f97c9175 3854into gexps. For example, a useful type of high-level objects that can be
343eacbe 3855inserted in a gexp is ``file-like objects'', which make it easy to
f97c9175 3856add files to the store and to refer to them in
558e8b11
LC
3857derivations and such (see @code{local-file} and @code{plain-file}
3858below.)
b39fc6f7 3859
21b679f6
LC
3860To illustrate the idea, here is an example of a gexp:
3861
3862@example
3863(define build-exp
3864 #~(begin
3865 (mkdir #$output)
3866 (chdir #$output)
aff8ce7c 3867 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3868 "list-files")))
3869@end example
3870
3871This gexp can be passed to @code{gexp->derivation}; we obtain a
3872derivation that builds a directory containing exactly one symlink to
3873@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3874
3875@example
3876(gexp->derivation "the-thing" build-exp)
3877@end example
3878
e20fd1bf 3879As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
3880substituted to the reference to the @var{coreutils} package in the
3881actual build code, and @var{coreutils} is automatically made an input to
3882the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
f97c9175
AE
3883output)}) is replaced by a string containing the directory name of the
3884output of the derivation.
667b2508
LC
3885
3886@cindex cross compilation
3887In a cross-compilation context, it is useful to distinguish between
3888references to the @emph{native} build of a package---that can run on the
3889host---versus references to cross builds of a package. To that end, the
3890@code{#+} plays the same role as @code{#$}, but is a reference to a
3891native package build:
3892
3893@example
3894(gexp->derivation "vi"
3895 #~(begin
3896 (mkdir #$output)
3897 (system* (string-append #+coreutils "/bin/ln")
3898 "-s"
3899 (string-append #$emacs "/bin/emacs")
3900 (string-append #$output "/bin/vi")))
4a3b6aa5 3901 #:target "mips64el-linux-gnu")
667b2508
LC
3902@end example
3903
3904@noindent
3905In the example above, the native build of @var{coreutils} is used, so
3906that @command{ln} can actually run on the host; but then the
3907cross-compiled build of @var{emacs} is referenced.
3908
0bb9929e
LC
3909@cindex imported modules, for gexps
3910@findex with-imported-modules
3911Another gexp feature is @dfn{imported modules}: sometimes you want to be
3912able to use certain Guile modules from the ``host environment'' in the
3913gexp, so those modules should be imported in the ``build environment''.
3914The @code{with-imported-modules} form allows you to express that:
3915
3916@example
3917(let ((build (with-imported-modules '((guix build utils))
3918 #~(begin
3919 (use-modules (guix build utils))
3920 (mkdir-p (string-append #$output "/bin"))))))
3921 (gexp->derivation "empty-dir"
3922 #~(begin
3923 #$build
3924 (display "success!\n")
3925 #t)))
3926@end example
3927
3928@noindent
3929In this example, the @code{(guix build utils)} module is automatically
3930pulled into the isolated build environment of our gexp, such that
3931@code{(use-modules (guix build utils))} works as expected.
3932
7ca87354
LC
3933@cindex module closure
3934@findex source-module-closure
3935Usually you want the @emph{closure} of the module to be imported---i.e.,
3936the module itself and all the modules it depends on---rather than just
3937the module; failing to do that, attempts to use the module will fail
3938because of missing dependent modules. The @code{source-module-closure}
3939procedure computes the closure of a module by looking at its source file
3940headers, which comes in handy in this case:
3941
3942@example
3943(use-modules (guix modules)) ;for 'source-module-closure'
3944
3945(with-imported-modules (source-module-closure
3946 '((guix build utils)
3947 (gnu build vm)))
3948 (gexp->derivation "something-with-vms"
3949 #~(begin
3950 (use-modules (guix build utils)
3951 (gnu build vm))
3952 @dots{})))
3953@end example
3954
667b2508 3955The syntactic form to construct gexps is summarized below.
21b679f6
LC
3956
3957@deffn {Scheme Syntax} #~@var{exp}
3958@deffnx {Scheme Syntax} (gexp @var{exp})
3959Return a G-expression containing @var{exp}. @var{exp} may contain one
3960or more of the following forms:
3961
3962@table @code
3963@item #$@var{obj}
3964@itemx (ungexp @var{obj})
b39fc6f7
LC
3965Introduce a reference to @var{obj}. @var{obj} may have one of the
3966supported types, for example a package or a
21b679f6
LC
3967derivation, in which case the @code{ungexp} form is replaced by its
3968output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
3969
b39fc6f7
LC
3970If @var{obj} is a list, it is traversed and references to supported
3971objects are substituted similarly.
21b679f6
LC
3972
3973If @var{obj} is another gexp, its contents are inserted and its
3974dependencies are added to those of the containing gexp.
3975
3976If @var{obj} is another kind of object, it is inserted as is.
3977
b39fc6f7
LC
3978@item #$@var{obj}:@var{output}
3979@itemx (ungexp @var{obj} @var{output})
21b679f6 3980This is like the form above, but referring explicitly to the
b39fc6f7
LC
3981@var{output} of @var{obj}---this is useful when @var{obj} produces
3982multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 3983
667b2508
LC
3984@item #+@var{obj}
3985@itemx #+@var{obj}:output
3986@itemx (ungexp-native @var{obj})
3987@itemx (ungexp-native @var{obj} @var{output})
3988Same as @code{ungexp}, but produces a reference to the @emph{native}
3989build of @var{obj} when used in a cross compilation context.
3990
21b679f6
LC
3991@item #$output[:@var{output}]
3992@itemx (ungexp output [@var{output}])
3993Insert a reference to derivation output @var{output}, or to the main
3994output when @var{output} is omitted.
3995
3996This only makes sense for gexps passed to @code{gexp->derivation}.
3997
3998@item #$@@@var{lst}
3999@itemx (ungexp-splicing @var{lst})
4000Like the above, but splices the contents of @var{lst} inside the
4001containing list.
4002
667b2508
LC
4003@item #+@@@var{lst}
4004@itemx (ungexp-native-splicing @var{lst})
4005Like the above, but refers to native builds of the objects listed in
4006@var{lst}.
4007
21b679f6
LC
4008@end table
4009
4010G-expressions created by @code{gexp} or @code{#~} are run-time objects
4011of the @code{gexp?} type (see below.)
4012@end deffn
4013
0bb9929e
LC
4014@deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
4015Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
4016in their execution environment. @var{modules} must be a list of Guile
4017module names, such as @code{'((guix build utils) (guix build gremlin))}.
4018
4019This form has @emph{lexical} scope: it has an effect on the gexps
4020directly defined in @var{body}@dots{}, but not on those defined, say, in
4021procedures called from @var{body}@dots{}.
4022@end deffn
4023
21b679f6
LC
4024@deffn {Scheme Procedure} gexp? @var{obj}
4025Return @code{#t} if @var{obj} is a G-expression.
4026@end deffn
4027
4028G-expressions are meant to be written to disk, either as code building
4029some derivation, or as plain files in the store. The monadic procedures
4030below allow you to do that (@pxref{The Store Monad}, for more
4031information about monads.)
4032
4033@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 4034 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
4035 [#:hash #f] [#:hash-algo #f] @
4036 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 4037 [#:module-path @var{%load-path}] @
c8351d9a 4038 [#:references-graphs #f] [#:allowed-references #f] @
3f4ecf32 4039 [#:disallowed-references #f] @
c0468155 4040 [#:leaked-env-vars #f] @
0309e1b0 4041 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 4042 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 4043Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
4044@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
4045stored in a file called @var{script-name}. When @var{target} is true,
4046it is used as the cross-compilation target triplet for packages referred
4047to by @var{exp}.
21b679f6 4048
0bb9929e
LC
4049@var{modules} is deprecated in favor of @code{with-imported-modules}.
4050Its meaning is to
4051make @var{modules} available in the evaluation context of @var{exp};
ce45eb4c
LC
4052@var{modules} is a list of names of Guile modules searched in
4053@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
4054the load path during the execution of @var{exp}---e.g., @code{((guix
4055build utils) (guix build gnu-build-system))}.
4056
ce45eb4c
LC
4057@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
4058applicable.
4059
b53833b2
LC
4060When @var{references-graphs} is true, it must be a list of tuples of one of the
4061following forms:
4062
4063@example
4064(@var{file-name} @var{package})
4065(@var{file-name} @var{package} @var{output})
4066(@var{file-name} @var{derivation})
4067(@var{file-name} @var{derivation} @var{output})
4068(@var{file-name} @var{store-item})
4069@end example
4070
4071The right-hand-side of each element of @var{references-graphs} is automatically made
4072an input of the build process of @var{exp}. In the build environment, each
4073@var{file-name} contains the reference graph of the corresponding item, in a simple
4074text format.
4075
c8351d9a
LC
4076@var{allowed-references} must be either @code{#f} or a list of output names and packages.
4077In the latter case, the list denotes store items that the result is allowed to
4078refer to. Any reference to another store item will lead to a build error.
3f4ecf32
LC
4079Similarly for @var{disallowed-references}, which can list items that must not be
4080referenced by the outputs.
c8351d9a 4081
e20fd1bf 4082The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
4083@end deffn
4084
343eacbe 4085@cindex file-like objects
e1c153e0
LC
4086The @code{local-file}, @code{plain-file}, @code{computed-file},
4087@code{program-file}, and @code{scheme-file} procedures below return
4088@dfn{file-like objects}. That is, when unquoted in a G-expression,
4089these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
4090
4091@example
a9e5e92f 4092#~(system* #$(file-append glibc "/sbin/nscd") "-f"
343eacbe
LC
4093 #$(local-file "/tmp/my-nscd.conf"))
4094@end example
4095
4096The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
4097to the store. Once expanded, for instance @i{via}
4098@code{gexp->derivation}, the G-expression refers to that copy under
4099@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
4100does not have any effect on what the G-expression does.
4101@code{plain-file} can be used similarly; it differs in that the file
4102content is directly passed as a string.
4103
d9ae938f 4104@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
0687fc9c 4105 [#:recursive? #f] [#:select? (const #t)]
d9ae938f 4106Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
4107object can be used in a gexp. If @var{file} is a relative file name, it is looked
4108up relative to the source file where this form appears. @var{file} will be added to
4109the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
4110
4111When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
4112designates a flat file and @var{recursive?} is true, its contents are added, and its
4113permission bits are kept.
4114
0687fc9c
LC
4115When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4116@var{stat})} for each directory entry, where @var{file} is the entry's
4117absolute file name and @var{stat} is the result of @code{lstat}; exclude
4118entries for which @var{select?} does not return true.
4119
d9ae938f
LC
4120This is the declarative counterpart of the @code{interned-file} monadic
4121procedure (@pxref{The Store Monad, @code{interned-file}}).
4122@end deffn
4123
558e8b11
LC
4124@deffn {Scheme Procedure} plain-file @var{name} @var{content}
4125Return an object representing a text file called @var{name} with the given
4126@var{content} (a string) to be added to the store.
4127
4128This is the declarative counterpart of @code{text-file}.
4129@end deffn
4130
91937029 4131@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
a769bffb 4132 [#:options '(#:local-build? #t)]
91937029 4133Return an object representing the store item @var{name}, a file or
a769bffb 4134directory computed by @var{gexp}. @var{options}
91937029
LC
4135is a list of additional arguments to pass to @code{gexp->derivation}.
4136
4137This is the declarative counterpart of @code{gexp->derivation}.
4138@end deffn
4139
21b679f6
LC
4140@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
4141Return an executable script @var{name} that runs @var{exp} using
9c14a487 4142@var{guile}, with @var{exp}'s imported modules in its search path.
21b679f6
LC
4143
4144The example below builds a script that simply invokes the @command{ls}
4145command:
4146
4147@example
4148(use-modules (guix gexp) (gnu packages base))
4149
4150(gexp->script "list-files"
a9e5e92f 4151 #~(execl #$(file-append coreutils "/bin/ls")
21b679f6
LC
4152 "ls"))
4153@end example
4154
4155When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 4156@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
4157executable file @file{/gnu/store/@dots{}-list-files} along these lines:
4158
4159@example
4160#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
4161!#
a9e5e92f 4162(execl "/gnu/store/@dots{}-coreutils-8.22"/bin/ls" "ls")
21b679f6
LC
4163@end example
4164@end deffn
4165
15a01c72 4166@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
9c14a487 4167 [#:guile #f]
15a01c72
LC
4168Return an object representing the executable store item @var{name} that
4169runs @var{gexp}. @var{guile} is the Guile package used to execute that
9c14a487 4170script.
15a01c72
LC
4171
4172This is the declarative counterpart of @code{gexp->script}.
4173@end deffn
4174
2b418579
LC
4175@deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
4176 [#:set-load-path? #t]
21b679f6 4177Return a derivation that builds a file @var{name} containing @var{exp}.
2b418579
LC
4178When @var{set-load-path?} is true, emit code in the resulting file to
4179set @code{%load-path} and @code{%load-compiled-path} to honor
4180@var{exp}'s imported modules.
21b679f6
LC
4181
4182The resulting file holds references to all the dependencies of @var{exp}
4183or a subset thereof.
4184@end deffn
1ed19464 4185
e1c153e0
LC
4186@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
4187Return an object representing the Scheme file @var{name} that contains
4188@var{exp}.
4189
4190This is the declarative counterpart of @code{gexp->file}.
4191@end deffn
4192
1ed19464
LC
4193@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
4194Return as a monadic value a derivation that builds a text file
4195containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
4196strings, objects of any type that can be used in a gexp: packages,
4197derivations, local file objects, etc. The resulting store file holds
4198references to all these.
1ed19464
LC
4199
4200This variant should be preferred over @code{text-file} anytime the file
4201to create will reference items from the store. This is typically the
4202case when building a configuration file that embeds store file names,
4203like this:
4204
4205@example
4206(define (profile.sh)
4207 ;; Return the name of a shell script in the store that
4208 ;; initializes the 'PATH' environment variable.
4209 (text-file* "profile.sh"
4210 "export PATH=" coreutils "/bin:"
4211 grep "/bin:" sed "/bin\n"))
4212@end example
4213
4214In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
b7899749 4215will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
1ed19464
LC
4216preventing them from being garbage-collected during its lifetime.
4217@end deffn
21b679f6 4218
b751cde3
LC
4219@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
4220Return an object representing store file @var{name} containing
4221@var{text}. @var{text} is a sequence of strings and file-like objects,
4222as in:
4223
4224@example
4225(mixed-text-file "profile"
4226 "export PATH=" coreutils "/bin:" grep "/bin")
4227@end example
4228
4229This is the declarative counterpart of @code{text-file*}.
4230@end deffn
4231
a9e5e92f
LC
4232@deffn {Scheme Procedure} file-append @var{obj} @var{suffix} @dots{}
4233Return a file-like object that expands to the concatenation of @var{obj}
4234and @var{suffix}, where @var{obj} is a lowerable object and each
4235@var{suffix} is a string.
4236
4237As an example, consider this gexp:
4238
4239@example
4240(gexp->script "run-uname"
4241 #~(system* #$(file-append coreutils
4242 "/bin/uname")))
4243@end example
4244
4245The same effect could be achieved with:
4246
4247@example
4248(gexp->script "run-uname"
4249 #~(system* (string-append #$coreutils
4250 "/bin/uname")))
4251@end example
4252
4253There is one difference though: in the @code{file-append} case, the
4254resulting script contains the absolute file name as a string, whereas in
4255the second case, the resulting script contains a @code{(string-append
4256@dots{})} expression to construct the file name @emph{at run time}.
4257@end deffn
4258
4259
21b679f6
LC
4260Of course, in addition to gexps embedded in ``host'' code, there are
4261also modules containing build tools. To make it clear that they are
4262meant to be used in the build stratum, these modules are kept in the
4263@code{(guix build @dots{})} name space.
4264
c2b84676
LC
4265@cindex lowering, of high-level objects in gexps
4266Internally, high-level objects are @dfn{lowered}, using their compiler,
4267to either derivations or store items. For instance, lowering a package
4268yields a derivation, and lowering a @code{plain-file} yields a store
4269item. This is achieved using the @code{lower-object} monadic procedure.
4270
4271@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
4272 [#:target #f]
4273Return as a value in @var{%store-monad} the derivation or store item
4274corresponding to @var{obj} for @var{system}, cross-compiling for
4275@var{target} if @var{target} is true. @var{obj} must be an object that
4276has an associated gexp compiler, such as a @code{<package>}.
4277@end deffn
4278
21b679f6 4279
568717fd
LC
4280@c *********************************************************************
4281@node Utilities
4282@chapter Utilities
4283
6f773606
LC
4284This section describes Guix command-line utilities. Some of them are
4285primarily targeted at developers and users who write new package
4286definitions, while others are more generally useful. They complement
4287the Scheme programming interface of Guix in a convenient way.
210cc920 4288
568717fd 4289@menu
37166310 4290* Invoking guix build:: Building packages from the command line.
39bee8a2 4291* Invoking guix edit:: Editing package definitions.
210cc920 4292* Invoking guix download:: Downloading a file and printing its hash.
37166310 4293* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 4294* Invoking guix import:: Importing package definitions.
37166310 4295* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 4296* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 4297* Invoking guix size:: Profiling disk usage.
88856916 4298* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 4299* Invoking guix environment:: Setting up development environments.
aff8ce7c 4300* Invoking guix publish:: Sharing substitutes.
d23c20f1 4301* Invoking guix challenge:: Challenging substitute servers.
32efa254 4302* Invoking guix container:: Process isolation.
568717fd
LC
4303@end menu
4304
e49951eb
MW
4305@node Invoking guix build
4306@section Invoking @command{guix build}
568717fd 4307
e32171ee
JD
4308@cindex package building
4309@cindex @command{guix build}
e49951eb 4310The @command{guix build} command builds packages or derivations and
6798a8e4
LC
4311their dependencies, and prints the resulting store paths. Note that it
4312does not modify the user's profile---this is the job of the
e49951eb 4313@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
4314it is mainly useful for distribution developers.
4315
4316The general syntax is:
c78bd12b
LC
4317
4318@example
e49951eb 4319guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
4320@end example
4321
f97c9175 4322As an example, the following command builds the latest versions of Emacs
ccd7158d
LC
4323and of Guile, displays their build logs, and finally displays the
4324resulting directories:
4325
4326@example
4327guix build emacs guile
4328@end example
4329
4330Similarly, the following command builds all the available packages:
4331
4332@example
5284339d 4333guix build --quiet --keep-going \
ccd7158d
LC
4334 `guix package -A | cut -f1,2 --output-delimiter=@@`
4335@end example
4336
c78bd12b 4337@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
4338the software distribution such as @code{coreutils} or
4339@code{coreutils-8.20}, or a derivation such as
834129e0 4340@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
4341package with the corresponding name (and optionally version) is searched
4342for among the GNU distribution modules (@pxref{Package Modules}).
4343
4344Alternatively, the @code{--expression} option may be used to specify a
4345Scheme expression that evaluates to a package; this is useful when
b7899749 4346disambiguating among several same-named packages or package variants is
e7f34eb0 4347needed.
c78bd12b 4348
ccd7158d
LC
4349There may be zero or more @var{options}. The available options are
4350described in the subsections below.
4351
4352@menu
4353* Common Build Options:: Build options for most commands.
88ad6ded 4354* Package Transformation Options:: Creating variants of packages.
ccd7158d
LC
4355* Additional Build Options:: Options specific to 'guix build'.
4356@end menu
4357
4358@node Common Build Options
4359@subsection Common Build Options
4360
4361A number of options that control the build process are common to
4362@command{guix build} and other commands that can spawn builds, such as
4363@command{guix package} or @command{guix archive}. These are the
4364following:
4365
4366@table @code
4367
4368@item --load-path=@var{directory}
4369@itemx -L @var{directory}
4370Add @var{directory} to the front of the package module search path
4371(@pxref{Package Modules}).
4372
4373This allows users to define their own packages and make them visible to
4374the command-line tools.
4375
4376@item --keep-failed
4377@itemx -K
b7899749 4378Keep the build tree of failed builds. Thus, if a build fails, its build
ccd7158d
LC
4379tree is kept under @file{/tmp}, in a directory whose name is shown at
4380the end of the build log. This is useful when debugging build issues.
4381
4382@item --keep-going
4383@itemx -k
4384Keep going when some of the derivations fail to build; return only once
4385all the builds have either completed or failed.
4386
4387The default behavior is to stop as soon as one of the specified
4388derivations has failed.
4389
4390@item --dry-run
4391@itemx -n
4392Do not build the derivations.
4393
4394@item --fallback
4395When substituting a pre-built binary fails, fall back to building
4396packages locally.
4397
4398@item --substitute-urls=@var{urls}
4399@anchor{client-substitute-urls}
4400Consider @var{urls} the whitespace-separated list of substitute source
4401URLs, overriding the default list of URLs of @command{guix-daemon}
4402(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4403
4404This means that substitutes may be downloaded from @var{urls}, provided
4405they are signed by a key authorized by the system administrator
4406(@pxref{Substitutes}).
4407
71e2065a
LC
4408When @var{urls} is the empty string, substitutes are effectively
4409disabled.
4410
ccd7158d
LC
4411@item --no-substitutes
4412Do not use substitutes for build products. That is, always build things
4413locally instead of allowing downloads of pre-built binaries
4414(@pxref{Substitutes}).
4415
7573d30f
LC
4416@item --no-grafts
4417Do not ``graft'' packages. In practice, this means that package updates
4418available as grafts are not applied. @xref{Security Updates}, for more
4419information on grafts.
4420
ccd7158d
LC
4421@item --rounds=@var{n}
4422Build each derivation @var{n} times in a row, and raise an error if
4423consecutive build results are not bit-for-bit identical.
4424
4425This is a useful way to detect non-deterministic builds processes.
4426Non-deterministic build processes are a problem because they make it
4427practically impossible for users to @emph{verify} whether third-party
4428binaries are genuine. @xref{Invoking guix challenge}, for more.
4429
4430Note that, currently, the differing build results are not kept around,
4431so you will have to manually investigate in case of an error---e.g., by
e66d1f59
ML
4432stashing one of the build results with @code{guix archive --export}
4433(@pxref{Invoking guix archive}), then rebuilding, and finally comparing
4434the two results.
ccd7158d
LC
4435
4436@item --no-build-hook
f97c9175 4437Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
ccd7158d
LC
4438(@pxref{Daemon Offload Setup}). That is, always build things locally
4439instead of offloading builds to remote machines.
4440
4441@item --max-silent-time=@var{seconds}
4442When the build or substitution process remains silent for more than
4443@var{seconds}, terminate it and report a build failure.
4444
4445@item --timeout=@var{seconds}
4446Likewise, when the build or substitution process lasts for more than
4447@var{seconds}, terminate it and report a build failure.
4448
4449By default there is no timeout. This behavior can be restored with
4450@code{--timeout=0}.
4451
4452@item --verbosity=@var{level}
4453Use the given verbosity level. @var{level} must be an integer between 0
4454and 5; higher means more verbose output. Setting a level of 4 or more
4455may be helpful when debugging setup issues with the build daemon.
4456
4457@item --cores=@var{n}
4458@itemx -c @var{n}
4459Allow the use of up to @var{n} CPU cores for the build. The special
4460value @code{0} means to use as many CPU cores as available.
4461
4462@item --max-jobs=@var{n}
4463@itemx -M @var{n}
4464Allow at most @var{n} build jobs in parallel. @xref{Invoking
4465guix-daemon, @code{--max-jobs}}, for details about this option and the
4466equivalent @command{guix-daemon} option.
4467
4468@end table
4469
4470Behind the scenes, @command{guix build} is essentially an interface to
4471the @code{package-derivation} procedure of the @code{(guix packages)}
4472module, and to the @code{build-derivations} procedure of the @code{(guix
4473derivations)} module.
4474
4475In addition to options explicitly passed on the command line,
4476@command{guix build} and other @command{guix} commands that support
4477building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4478
4479@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4480Users can define this variable to a list of command line options that
4481will automatically be used by @command{guix build} and other
4482@command{guix} commands that can perform builds, as in the example
4483below:
4484
4485@example
4486$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4487@end example
4488
4489These options are parsed independently, and the result is appended to
4490the parsed command-line options.
4491@end defvr
4492
88ad6ded
LC
4493
4494@node Package Transformation Options
4495@subsection Package Transformation Options
4496
4497@cindex package variants
4498Another set of command-line options supported by @command{guix build}
b8638f03 4499and also @command{guix package} are @dfn{package transformation
f97c9175 4500options}. These are options that make it possible to define @dfn{package
b8638f03
LC
4501variants}---for instance, packages built from different source code.
4502This is a convenient way to create customized packages on the fly
4503without having to type in the definitions of package variants
4504(@pxref{Defining Packages}).
88ad6ded
LC
4505
4506@table @code
4507
4508@item --with-source=@var{source}
4509Use @var{source} as the source of the corresponding package.
4510@var{source} must be a file name or a URL, as for @command{guix
4511download} (@pxref{Invoking guix download}).
4512
f97c9175
AE
4513The ``corresponding package'' is taken to be the one specified on the
4514command line the name of which matches the base of @var{source}---e.g.,
4515if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
88ad6ded 4516package is @code{guile}. Likewise, the version string is inferred from
f97c9175 4517@var{source}; in the previous example, it is @code{2.0.10}.
88ad6ded
LC
4518
4519This option allows users to try out versions of packages other than the
4520one provided by the distribution. The example below downloads
4521@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4522the @code{ed} package:
4523
4524@example
4525guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4526@end example
4527
4528As a developer, @code{--with-source} makes it easy to test release
4529candidates:
4530
4531@example
4532guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4533@end example
4534
4535@dots{} or to build from a checkout in a pristine environment:
4536
4537@example
4538$ git clone git://git.sv.gnu.org/guix.git
4539$ guix build guix --with-source=./guix
4540@end example
4541
47c0f92c
LC
4542@item --with-input=@var{package}=@var{replacement}
4543Replace dependency on @var{package} by a dependency on
4544@var{replacement}. @var{package} must be a package name, and
4545@var{replacement} must be a package specification such as @code{guile}
4546or @code{guile@@1.8}.
4547
f97c9175 4548For instance, the following command builds Guix, but replaces its
47c0f92c
LC
4549dependency on the current stable version of Guile with a dependency on
4550the development version of Guile, @code{guile-next}:
4551
4552@example
4553guix build --with-input=guile=guile-next guix
4554@end example
4555
4556This is a recursive, deep replacement. So in this example, both
4557@code{guix} and its dependency @code{guile-json} (which also depends on
4558@code{guile}) get rebuilt against @code{guile-next}.
4559
2a75b0b6
LC
4560This is implemented using the @code{package-input-rewriting} Scheme
4561procedure (@pxref{Defining Packages, @code{package-input-rewriting}}).
645b9df8
LC
4562
4563@item --with-graft=@var{package}=@var{replacement}
4564This is similar to @code{--with-input} but with an important difference:
4565instead of rebuilding all the dependency chain, @var{replacement} is
4566built and then @dfn{grafted} onto the binaries that were initially
4567referring to @var{package}. @xref{Security Updates}, for more
4568information on grafts.
4569
4570For example, the command below grafts version 3.5.4 of GnuTLS onto Wget
4571and all its dependencies, replacing references to the version of GnuTLS
4572they currently refer to:
4573
4574@example
4575guix build --with-graft=gnutls=gnutls@@3.5.4 wget
4576@end example
4577
4578This has the advantage of being much faster than rebuilding everything.
4579But there is a caveat: it works if and only if @var{package} and
4580@var{replacement} are strictly compatible---for example, if they provide
4581a library, the application binary interface (ABI) of those libraries
4582must be compatible. If @var{replacement} is somehow incompatible with
4583@var{package}, then the resulting package may be unusable. Use with
4584care!
4585
88ad6ded
LC
4586@end table
4587
ccd7158d
LC
4588@node Additional Build Options
4589@subsection Additional Build Options
4590
4591The command-line options presented below are specific to @command{guix
4592build}.
c78bd12b
LC
4593
4594@table @code
4595
5284339d
LC
4596@item --quiet
4597@itemx -q
4598Build quietly, without displaying the build log. Upon completion, the
4599build log is kept in @file{/var} (or similar) and can always be
4600retrieved using the @option{--log-file} option.
4601
34a1783f
DT
4602@item --file=@var{file}
4603@itemx -f @var{file}
4604
4605Build the package or derivation that the code within @var{file}
4606evaluates to.
4607
4608As an example, @var{file} might contain a package definition like this
4609(@pxref{Defining Packages}):
4610
4611@example
4612@verbatiminclude package-hello.scm
4613@end example
4614
c78bd12b
LC
4615@item --expression=@var{expr}
4616@itemx -e @var{expr}
ac5de156 4617Build the package or derivation @var{expr} evaluates to.
c78bd12b 4618
5401dd75 4619For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
4620guile-1.8)}, which unambiguously designates this specific variant of
4621version 1.8 of Guile.
4622
f97c9175 4623Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
4624as a build program passed to @code{gexp->derivation}
4625(@pxref{G-Expressions}).
4626
4627Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
4628(@pxref{The Store Monad}). The procedure must return a derivation as a
4629monadic value, which is then passed through @code{run-with-store}.
4630
c78bd12b
LC
4631@item --source
4632@itemx -S
f97c9175 4633Build the source derivations of the packages, rather than the packages
c78bd12b
LC
4634themselves.
4635
e49951eb 4636For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
4637@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4638source tarball.
c78bd12b 4639
f9cc8971 4640The returned source tarball is the result of applying any patches and
f97c9175 4641code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
4642Packages}).
4643
2cdfe13d
EB
4644@item --sources
4645Fetch and return the source of @var{package-or-derivation} and all their
4646dependencies, recursively. This is a handy way to obtain a local copy
4647of all the source code needed to build @var{packages}, allowing you to
4648eventually build them even without network access. It is an extension
4649of the @code{--source} option and can accept one of the following
4650optional argument values:
4651
4652@table @code
4653@item package
4654This value causes the @code{--sources} option to behave in the same way
4655as the @code{--source} option.
4656
4657@item all
f97c9175
AE
4658Build the source derivations of all packages, including any source that
4659might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
4660
4661@example
4662$ guix build --sources tzdata
4663The following derivations will be built:
4664 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4665 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4666@end example
4667
4668@item transitive
f97c9175
AE
4669Build the source derivations of all packages, as well of all transitive
4670inputs to the packages. This can be used e.g. to
2cdfe13d
EB
4671prefetch package source for later offline building.
4672
4673@example
4674$ guix build --sources=transitive tzdata
4675The following derivations will be built:
4676 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4677 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4678 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4679 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4680 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4681 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4682@dots{}
4683@end example
4684
4685@end table
4686
c78bd12b
LC
4687@item --system=@var{system}
4688@itemx -s @var{system}
4689Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 4690the system type of the build host.
c78bd12b
LC
4691
4692An example use of this is on Linux-based systems, which can emulate
4693different personalities. For instance, passing
4694@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4695to build packages in a complete 32-bit environment.
4696
e55ec43d
LC
4697@item --target=@var{triplet}
4698@cindex cross-compilation
4699Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4700as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4701configuration triplets,, configure, GNU Configure and Build System}).
4702
a8d65643
LC
4703@anchor{build-check}
4704@item --check
4705@cindex determinism, checking
4706@cindex reproducibility, checking
4707Rebuild @var{package-or-derivation}, which are already available in the
4708store, and raise an error if the build results are not bit-for-bit
4709identical.
4710
f97c9175
AE
4711This mechanism allows you to check whether previously installed
4712substitutes are genuine (@pxref{Substitutes}), or whether the build result
4713of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
4714background information and tools.
4715
7f3b2510
ED
4716When used in conjunction with @option{--keep-failed}, the differing
4717output is kept in the store, under @file{/gnu/store/@dots{}-check}.
4718This makes it easy to look for differences between the two results.
4719
c78bd12b
LC
4720@item --derivations
4721@itemx -d
4722Return the derivation paths, not the output paths, of the given
4723packages.
4724
70ee5642
LC
4725@item --root=@var{file}
4726@itemx -r @var{file}
4727Make @var{file} a symlink to the result, and register it as a garbage
4728collector root.
4729
4730@item --log-file
3f208ad7 4731Return the build log file names or URLs for the given
f97c9175 4732@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
4733missing.
4734
4735This works regardless of how packages or derivations are specified. For
4736instance, the following invocations are equivalent:
4737
4738@example
4739guix build --log-file `guix build -d guile`
4740guix build --log-file `guix build guile`
4741guix build --log-file guile
4742guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4743@end example
4744
3f208ad7
LC
4745If a log is unavailable locally, and unless @code{--no-substitutes} is
4746passed, the command looks for a corresponding log on one of the
4747substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 4748
f97c9175
AE
4749So for instance, imagine you want to see the build log of GDB on MIPS,
4750but you are actually on an @code{x86_64} machine:
3f208ad7
LC
4751
4752@example
a01ad638 4753$ guix build --log-file gdb -s mips64el-linux
df061d07 4754https://hydra.gnu.org/log/@dots{}-gdb-7.10
3f208ad7
LC
4755@end example
4756
4757You can freely access a huge library of build logs!
70ee5642
LC
4758@end table
4759
16eb115e 4760
39bee8a2
LC
4761@node Invoking guix edit
4762@section Invoking @command{guix edit}
4763
e32171ee 4764@cindex @command{guix edit}
39bee8a2
LC
4765@cindex package definition, editing
4766So many packages, so many source files! The @command{guix edit} command
424a323e
GC
4767facilitates the life of users and packagers by pointing their editor at
4768the source file containing the definition of the specified packages.
4769For instance:
39bee8a2
LC
4770
4771@example
7b9a66e5 4772guix edit gcc@@4.9 vim
39bee8a2
LC
4773@end example
4774
4775@noindent
6237b9fa 4776launches the program specified in the @code{VISUAL} or in the
424a323e 4777@code{EDITOR} environment variable to view the recipe of GCC@tie{}4.9.3
6237b9fa 4778and that of Vim.
39bee8a2 4779
424a323e
GC
4780If you are using a Guix Git checkout (@pxref{Building from Git}), or
4781have created your own packages on @code{GUIX_PACKAGE_PATH}
4782(@pxref{Defining Packages}), you will be able to edit the package
4783recipes. Otherwise, you will be able to examine the read-only recipes
4784for packages currently in the store.
4785
f97c9175 4786If you are using Emacs, note that the Emacs user interface provides the
7c1b1ae2 4787@kbd{M-x guix-edit} command and a similar functionality in the ``package
f97c9175 4788info'' and ``package list'' buffers created by the @kbd{M-x
7c1b1ae2 4789guix-search-by-name} and similar commands (@pxref{Emacs Commands}).
39bee8a2
LC
4790
4791
210cc920
LC
4792@node Invoking guix download
4793@section Invoking @command{guix download}
4794
e32171ee
JD
4795@cindex @command{guix download}
4796@cindex downloading package sources
210cc920 4797When writing a package definition, developers typically need to download
f97c9175 4798a source tarball, compute its SHA256 hash, and write that
210cc920
LC
4799hash in the package definition (@pxref{Defining Packages}). The
4800@command{guix download} tool helps with this task: it downloads a file
4801from the given URI, adds it to the store, and prints both its file name
4802in the store and its SHA256 hash.
4803
4804The fact that the downloaded file is added to the store saves bandwidth:
4805when the developer eventually tries to build the newly defined package
4806with @command{guix build}, the source tarball will not have to be
4807downloaded again because it is already in the store. It is also a
4808convenient way to temporarily stash files, which may be deleted
4809eventually (@pxref{Invoking guix gc}).
4810
4811The @command{guix download} command supports the same URIs as used in
4812package definitions. In particular, it supports @code{mirror://} URIs.
4813@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4814Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4815they are not available, an error is raised. @xref{Guile Preparations,
4816how to install the GnuTLS bindings for Guile,, gnutls-guile,
4817GnuTLS-Guile}, for more information.
210cc920 4818
bc3c41ce
LC
4819@command{guix download} verifies HTTPS server certificates by loading
4820the certificates of X.509 authorities from the directory pointed to by
4821the @code{SSL_CERT_DIR} environment variable (@pxref{X.509
64b8695c 4822Certificates}), unless @option{--no-check-certificate} is used.
bc3c41ce 4823
64b8695c 4824The following options are available:
210cc920
LC
4825
4826@table @code
4827@item --format=@var{fmt}
4828@itemx -f @var{fmt}
4829Write the hash in the format specified by @var{fmt}. For more
081145cf 4830information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
64b8695c
LC
4831
4832@item --no-check-certificate
4833Do not validate the X.509 certificates of HTTPS servers.
4834
4835When using this option, you have @emph{absolutely no guarantee} that you
4836are communicating with the authentic server responsible for the given
4837URL, which makes you vulnerable to ``man-in-the-middle'' attacks.
4838
1bcc87bb
LC
4839@item --output=@var{file}
4840@itemx -o @var{file}
4841Save the downloaded file to @var{file} instead of adding it to the
4842store.
210cc920
LC
4843@end table
4844
6c365eca
NK
4845@node Invoking guix hash
4846@section Invoking @command{guix hash}
4847
e32171ee 4848@cindex @command{guix hash}
210cc920 4849The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4850It is primarily a convenience tool for anyone contributing to the
4851distribution: it computes the cryptographic hash of a file, which can be
4852used in the definition of a package (@pxref{Defining Packages}).
4853
4854The general syntax is:
4855
4856@example
4857guix hash @var{option} @var{file}
4858@end example
4859
343dc117
LC
4860When @var{file} is @code{-} (a hyphen), @command{guix hash} computes the
4861hash of data read from standard input. @command{guix hash} has the
4862following options:
6c365eca
NK
4863
4864@table @code
4865
4866@item --format=@var{fmt}
4867@itemx -f @var{fmt}
210cc920 4868Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4869
4870Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4871(@code{hex} and @code{hexadecimal} can be used as well).
4872
4873If the @option{--format} option is not specified, @command{guix hash}
4874will output the hash in @code{nix-base32}. This representation is used
4875in the definitions of packages.
4876
3140f2df
LC
4877@item --recursive
4878@itemx -r
4879Compute the hash on @var{file} recursively.
4880
4881In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
4882including its children if it is a directory. Some of the metadata of
4883@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 4884regular file, the hash is different depending on whether @var{file} is
f97c9175 4885executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
4886hash (@pxref{Invoking guix archive}).
4887@c FIXME: Replace xref above with xref to an ``Archive'' section when
4888@c it exists.
4889
392a4e12
JN
4890@item --exclude-vcs
4891@itemx -x
4892When combined with @option{--recursive}, exclude version control system
4893directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
4894
db97a03a
LC
4895@vindex git-fetch
4896As an example, here is how you would compute the hash of a Git checkout,
4897which is useful when using the @code{git-fetch} method (@pxref{origin
4898Reference}):
4899
4900@example
4901$ git clone http://example.org/foo.git
4902$ cd foo
392a4e12 4903$ guix hash -rx .
db97a03a 4904@end example
6c365eca
NK
4905@end table
4906
2f7d2d91
LC
4907@node Invoking guix import
4908@section Invoking @command{guix import}
4909
4910@cindex importing packages
4911@cindex package import
4912@cindex package conversion
e32171ee 4913@cindex Invoking @command{guix import}
f97c9175
AE
4914The @command{guix import} command is useful for people who would like to
4915add a package to the distribution with as little work as
4916possible---a legitimate demand. The command knows of a few
4917repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
4918is a package definition, or a template thereof, in the format we know
4919(@pxref{Defining Packages}).
4920
4921The general syntax is:
4922
4923@example
4924guix import @var{importer} @var{options}@dots{}
4925@end example
4926
4927@var{importer} specifies the source from which to import package
f97c9175 4928metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
4929options specific to @var{importer}. Currently, the available
4930``importers'' are:
4931
4932@table @code
4933@item gnu
f97c9175 4934Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
4935for the latest version of that GNU package, including the hash of its
4936source tarball, and its canonical synopsis and description.
4937
f97c9175 4938Additional information such as the package dependencies and its
2f7d2d91
LC
4939license needs to be figured out manually.
4940
4941For example, the following command returns a package definition for
4942GNU@tie{}Hello:
4943
4944@example
4945guix import gnu hello
4946@end example
4947
4948Specific command-line options are:
4949
4950@table @code
4951@item --key-download=@var{policy}
4952As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 4953keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
4954refresh, @code{--key-download}}.
4955@end table
4956
4957@item pypi
4958@cindex pypi
f97c9175 4959Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
4960Index}@footnote{This functionality requires Guile-JSON to be installed.
4961@xref{Requirements}.}. Information is taken from the JSON-formatted
4962description available at @code{pypi.python.org} and usually includes all
266785d2
CR
4963the relevant information, including package dependencies. For maximum
4964efficiency, it is recommended to install the @command{unzip} utility, so
4965that the importer can unzip Python wheels and gather data from them.
2f7d2d91 4966
f97c9175 4967The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
4968package:
4969
4970@example
4971guix import pypi itsdangerous
4972@end example
4973
3aae8145
DT
4974@item gem
4975@cindex gem
f97c9175 4976Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
4977RubyGems}@footnote{This functionality requires Guile-JSON to be
4978installed. @xref{Requirements}.}. Information is taken from the
4979JSON-formatted description available at @code{rubygems.org} and includes
4980most relevant information, including runtime dependencies. There are
f97c9175 4981some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
4982synopses and descriptions, so the same string is used for both fields.
4983Additionally, the details of non-Ruby dependencies required to build
4984native extensions is unavailable and left as an exercise to the
4985packager.
4986
f97c9175 4987The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
4988
4989@example
4990guix import gem rails
4991@end example
4992
d45dc6da
EB
4993@item cpan
4994@cindex CPAN
3c192e4e
AE
4995Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
4996functionality requires Guile-JSON to be installed.
4997@xref{Requirements}.}.
f97c9175 4998Information is taken from the JSON-formatted metadata provided through
d45dc6da 4999@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
5000relevant information, such as module dependencies. License information
5001should be checked closely. If Perl is available in the store, then the
5002@code{corelist} utility will be used to filter core modules out of the
5003list of dependencies.
d45dc6da 5004
f97c9175 5005The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
5006Perl module:
5007
5008@example
5009guix import cpan Acme::Boolean
5010@end example
5011
e1248602
RW
5012@item cran
5013@cindex CRAN
d0bd632f 5014@cindex Bioconductor
f97c9175 5015Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
5016central repository for the @uref{http://r-project.org, GNU@tie{}R
5017statistical and graphical environment}.
5018
f97c9175 5019Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 5020
f97c9175 5021The command command below imports metadata for the @code{Cairo}
e1248602
RW
5022R package:
5023
5024@example
5025guix import cran Cairo
5026@end example
5027
f97c9175 5028When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
5029@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
5030packages for for the analysis and comprehension of high-throughput
5031genomic data in bioinformatics.
5032
f97c9175 5033Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
5034published on the web interface of the Bioconductor SVN repository.
5035
f97c9175 5036The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
5037R package:
5038
5039@example
5040guix import cran --archive=bioconductor GenomicRanges
5041@end example
5042
2f7d2d91 5043@item nix
f97c9175 5044Import metadata from a local copy of the source of the
2f7d2d91
LC
5045@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
5046relies on the @command{nix-instantiate} command of
5047@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
5048typically written in a mixture of Nix-language and Bash code. This
5049command only imports the high-level package structure that is written in
5050the Nix language. It normally includes all the basic fields of a
5051package definition.
5052
5053When importing a GNU package, the synopsis and descriptions are replaced
5054by their canonical upstream variant.
5055
961d0d2d
LC
5056Usually, you will first need to do:
5057
5058@example
5059export NIX_REMOTE=daemon
5060@end example
5061
5062@noindent
5063so that @command{nix-instantiate} does not try to open the Nix database.
5064
2f7d2d91
LC
5065As an example, the command below imports the package definition of
5066LibreOffice (more precisely, it imports the definition of the package
5067bound to the @code{libreoffice} top-level attribute):
5068
5069@example
5070guix import nix ~/path/to/nixpkgs libreoffice
5071@end example
863af4e1
FB
5072
5073@item hackage
5074@cindex hackage
f97c9175 5075Import metadata from the Haskell community's central package archive
863af4e1
FB
5076@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
5077Cabal files and includes all the relevant information, including package
5078dependencies.
5079
5080Specific command-line options are:
5081
5082@table @code
a4154748
FB
5083@item --stdin
5084@itemx -s
f97c9175 5085Read a Cabal file from standard input.
863af4e1
FB
5086@item --no-test-dependencies
5087@itemx -t
f97c9175 5088Do not include dependencies required only by the test suites.
a4154748
FB
5089@item --cabal-environment=@var{alist}
5090@itemx -e @var{alist}
5091@var{alist} is a Scheme alist defining the environment in which the
5092Cabal conditionals are evaluated. The accepted keys are: @code{os},
5093@code{arch}, @code{impl} and a string representing the name of a flag.
5094The value associated with a flag has to be either the symbol
5095@code{true} or @code{false}. The value associated with other keys
5096has to conform to the Cabal file format definition. The default value
5097associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 5098@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
5099@end table
5100
f97c9175 5101The command below imports metadata for the latest version of the
a4154748
FB
5102@code{HTTP} Haskell package without including test dependencies and
5103specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
5104
5105@example
a4154748 5106guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
5107@end example
5108
5109A specific package version may optionally be specified by following the
1b846da8 5110package name by an at-sign and a version number as in the following example:
863af4e1
FB
5111
5112@example
1b846da8 5113guix import hackage mtl@@2.1.3.1
863af4e1 5114@end example
7f74a931
FB
5115
5116@item elpa
5117@cindex elpa
f97c9175 5118Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
5119repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
5120
5121Specific command-line options are:
5122
5123@table @code
5124@item --archive=@var{repo}
5125@itemx -a @var{repo}
5126@var{repo} identifies the archive repository from which to retrieve the
5127information. Currently the supported repositories and their identifiers
5128are:
5129@itemize -
5130@item
840bd1d3 5131@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
5132identifier. This is the default.
5133
624144e0
LC
5134Packages from @code{elpa.gnu.org} are signed with one of the keys
5135contained in the GnuPG keyring at
5136@file{share/emacs/25.1/etc/package-keyring.gpg} (or similar) in the
5137@code{emacs} package (@pxref{Package Installation, ELPA package
5138signatures,, emacs, The GNU Emacs Manual}).
5139
7f74a931 5140@item
840bd1d3 5141@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
5142@code{melpa-stable} identifier.
5143
5144@item
840bd1d3 5145@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
5146identifier.
5147@end itemize
5148@end table
2f7d2d91
LC
5149@end table
5150
5151The structure of the @command{guix import} code is modular. It would be
5152useful to have more importers for other package formats, and your help
5153is welcome here (@pxref{Contributing}).
5154
37166310
LC
5155@node Invoking guix refresh
5156@section Invoking @command{guix refresh}
5157
e32171ee 5158@cindex @command {guix refresh}
37166310
LC
5159The primary audience of the @command{guix refresh} command is developers
5160of the GNU software distribution. By default, it reports any packages
5161provided by the distribution that are outdated compared to the latest
5162upstream version, like this:
5163
5164@example
5165$ guix refresh
5166gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
5167gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
5168@end example
5169
f97c9175
AE
5170It does so by browsing the FTP directory of each package and determining
5171the highest version number of the source tarballs therein. The command
bcb571cb
LC
5172knows how to update specific types of packages: GNU packages, ELPA
5173packages, etc.---see the documentation for @option{--type} below. The
5174are many packages, though, for which it lacks a method to determine
5175whether a new upstream release is available. However, the mechanism is
5176extensible, so feel free to get in touch with us to add a new method!
37166310
LC
5177
5178When passed @code{--update}, it modifies distribution source files to
f97c9175 5179update the version numbers and source tarball hashes of those package
37166310
LC
5180recipes (@pxref{Defining Packages}). This is achieved by downloading
5181each package's latest source tarball and its associated OpenPGP
5182signature, authenticating the downloaded tarball against its signature
5183using @command{gpg}, and finally computing its hash. When the public
5184key used to sign the tarball is missing from the user's keyring, an
5185attempt is made to automatically retrieve it from a public key server;
f97c9175 5186when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
5187@command{guix refresh} reports an error.
5188
5189The following options are supported:
5190
5191@table @code
5192
2d7fc7da
LC
5193@item --expression=@var{expr}
5194@itemx -e @var{expr}
5195Consider the package @var{expr} evaluates to.
5196
5197This is useful to precisely refer to a package, as in this example:
5198
5199@example
5200guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
5201@end example
5202
5203This command lists the dependents of the ``final'' libc (essentially all
5204the packages.)
5205
37166310
LC
5206@item --update
5207@itemx -u
38e16b49
LC
5208Update distribution source files (package recipes) in place. This is
5209usually run from a checkout of the Guix source tree (@pxref{Running
5210Guix Before It Is Installed}):
5211
5212@example
5213$ ./pre-inst-env guix refresh -s non-core
5214@end example
5215
081145cf 5216@xref{Defining Packages}, for more information on package definitions.
37166310
LC
5217
5218@item --select=[@var{subset}]
5219@itemx -s @var{subset}
5220Select all the packages in @var{subset}, one of @code{core} or
5221@code{non-core}.
5222
5223The @code{core} subset refers to all the packages at the core of the
5224distribution---i.e., packages that are used to build ``everything
5225else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
5226changing one of these packages in the distribution entails a rebuild of
5227all the others. Thus, such updates are an inconvenience to users in
5228terms of build time or bandwidth used to achieve the upgrade.
5229
5230The @code{non-core} subset refers to the remaining packages. It is
5231typically useful in cases where an update of the core packages would be
5232inconvenient.
5233
bcb571cb
LC
5234@item --type=@var{updater}
5235@itemx -t @var{updater}
7191adc5
AK
5236Select only packages handled by @var{updater} (may be a comma-separated
5237list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
5238
5239@table @code
5240@item gnu
5241the updater for GNU packages;
e80c0f85
LC
5242@item gnome
5243the updater for GNOME packages;
9c97afe8
DC
5244@item kde
5245the updater for KDE packages;
62061d6b
AW
5246@item xorg
5247the updater for X.org packages;
bcb571cb 5248@item elpa
d882c235
LC
5249the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
5250@item cran
b9d044ef 5251the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
5252@item bioconductor
5253the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
bab020d7 5254@item pypi
b9d044ef 5255the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
5256@item gem
5257the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
5258@item github
5259the updater for @uref{https://github.com, GitHub} packages.
42efe27a
EB
5260@item hackage
5261the updater for @uref{https://hackage.haskell.org, Hackage} packages.
bcb571cb
LC
5262@end table
5263
f97c9175
AE
5264For instance, the following command only checks for updates of Emacs
5265packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
5266
5267@example
7191adc5 5268$ guix refresh --type=elpa,cran
d882c235 5269gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
5270gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
5271@end example
5272
37166310
LC
5273@end table
5274
5275In addition, @command{guix refresh} can be passed one or more package
5276names, as in this example:
5277
5278@example
38e16b49 5279$ ./pre-inst-env guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
5280@end example
5281
5282@noindent
5283The command above specifically updates the @code{emacs} and
5284@code{idutils} packages. The @code{--select} option would have no
5285effect in this case.
5286
7d193ec3
EB
5287When considering whether to upgrade a package, it is sometimes
5288convenient to know which packages would be affected by the upgrade and
5289should be checked for compatibility. For this the following option may
5290be used when passing @command{guix refresh} one or more package names:
5291
5292@table @code
5293
6ffa706b
AK
5294@item --list-updaters
5295@itemx -L
5296List available updaters and exit (see @option{--type} above.)
5297
7d193ec3
EB
5298@item --list-dependent
5299@itemx -l
5300List top-level dependent packages that would need to be rebuilt as a
5301result of upgrading one or more packages.
5302
5303@end table
5304
5305Be aware that the @code{--list-dependent} option only
5306@emph{approximates} the rebuilds that would be required as a result of
5307an upgrade. More rebuilds might be required under some circumstances.
5308
5309@example
7779ab61
LC
5310$ guix refresh --list-dependent flex
5311Building the following 120 packages would ensure 213 dependent packages are rebuilt:
5312hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
5313@end example
5314
5315The command above lists a set of packages that could be built to check
5316for compatibility with an upgraded @code{flex} package.
5317
f9230085
LC
5318The following options can be used to customize GnuPG operation:
5319
5320@table @code
5321
f9230085
LC
5322@item --gpg=@var{command}
5323Use @var{command} as the GnuPG 2.x command. @var{command} is searched
5324for in @code{$PATH}.
5325
2bc53ba9
LC
5326@item --key-download=@var{policy}
5327Handle missing OpenPGP keys according to @var{policy}, which may be one
5328of:
5329
5330@table @code
5331@item always
5332Always download missing OpenPGP keys from the key server, and add them
5333to the user's GnuPG keyring.
5334
5335@item never
5336Never try to download missing OpenPGP keys. Instead just bail out.
5337
5338@item interactive
5339When a package signed with an unknown OpenPGP key is encountered, ask
5340the user whether to download it or not. This is the default behavior.
5341@end table
5342
5343@item --key-server=@var{host}
5344Use @var{host} as the OpenPGP key server when importing a public key.
5345
f9230085
LC
5346@end table
5347
917a2a58
BW
5348The @code{github} updater uses the
5349@uref{https://developer.github.com/v3/, GitHub API} to query for new
5350releases. When used repeatedly e.g. when refreshing all packages,
5351GitHub will eventually refuse to answer any further API requests. By
5352default 60 API requests per hour are allowed, and a full refresh on all
5353GitHub packages in Guix requires more than this. Authentication with
5354GitHub through the use of an API token alleviates these limits. To use
5355an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
5356token procured from @uref{https://github.com/settings/tokens} or
5357otherwise.
5358
5359
b4f5e0e8
CR
5360@node Invoking guix lint
5361@section Invoking @command{guix lint}
e32171ee
JD
5362
5363@cindex @command{guix lint}
5364@cindex package, checking for errors
f97c9175
AE
5365The @command{guix lint} command is meant to help package developers avoid
5366common errors and use a consistent style. It runs a number of checks on
5367a given set of packages in order to find common mistakes in their
873c4085
LC
5368definitions. Available @dfn{checkers} include (see
5369@code{--list-checkers} for a complete list):
5370
5371@table @code
5372@item synopsis
5373@itemx description
5374Validate certain typographical and stylistic rules about package
5375descriptions and synopses.
5376
5377@item inputs-should-be-native
5378Identify inputs that should most likely be native inputs.
5379
5380@item source
5381@itemx home-page
fac46e3f 5382@itemx mirror-url
50f5c46d 5383@itemx source-file-name
873c4085 5384Probe @code{home-page} and @code{source} URLs and report those that are
fac46e3f
LC
5385invalid. Suggest a @code{mirror://} URL when applicable. Check that
5386the source file name is meaningful, e.g. is not
f97c9175
AE
5387just a version number or ``git-checkout'', without a declared
5388@code{file-name} (@pxref{origin Reference}).
40a7d4e5 5389
5432734b 5390@item cve
09866b39
LC
5391@cindex security vulnerabilities
5392@cindex CVE, Common Vulnerabilities and Exposures
5432734b 5393Report known vulnerabilities found in the Common Vulnerabilities and
09866b39 5394Exposures (CVE) databases of the current and past year
5432734b
LC
5395@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
5396NIST}.
5397
09866b39
LC
5398To view information about a particular vulnerability, visit pages such as:
5399
5400@itemize
5401@item
5402@indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
5403@item
5404@indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
5405@end itemize
5406
5407@noindent
5408where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
5409@code{CVE-2015-7554}.
5410
99effc8f
LC
5411Package developers can specify in package recipes the
5412@uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
5413name and version of the package when they differ from the name that Guix
5414uses, as in this example:
5415
5416@example
5417(package
5418 (name "grub")
5419 ;; @dots{}
5420 ;; CPE calls this package "grub2".
5421 (properties '((cpe-name . "grub2"))))
5422@end example
5423
40a7d4e5
LC
5424@item formatting
5425Warn about obvious source code formatting issues: trailing white space,
5426use of tabulations, etc.
873c4085 5427@end table
b4f5e0e8
CR
5428
5429The general syntax is:
5430
5431@example
5432guix lint @var{options} @var{package}@dots{}
5433@end example
5434
5435If no package is given on the command line, then all packages are checked.
5436The @var{options} may be zero or more of the following:
5437
5438@table @code
f97c9175
AE
5439@item --list-checkers
5440@itemx -l
5441List and describe all the available checkers that will be run on packages
5442and exit.
b4f5e0e8 5443
dd7c013d
CR
5444@item --checkers
5445@itemx -c
5446Only enable the checkers specified in a comma-separated list using the
5447names returned by @code{--list-checkers}.
5448
b4f5e0e8 5449@end table
37166310 5450
fcc58db6
LC
5451@node Invoking guix size
5452@section Invoking @command{guix size}
5453
e32171ee
JD
5454@cindex size
5455@cindex package size
5456@cindex closure
5457@cindex @command{guix size}
fcc58db6
LC
5458The @command{guix size} command helps package developers profile the
5459disk usage of packages. It is easy to overlook the impact of an
5460additional dependency added to a package, or the impact of using a
5461single output for a package that could easily be split (@pxref{Packages
f97c9175 5462with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
5463@command{guix size} can highlight.
5464
5465The command can be passed a package specification such as @code{gcc-4.8}
5466or @code{guile:debug}, or a file name in the store. Consider this
5467example:
5468
5469@example
5470$ guix size coreutils
5471store item total self
5472/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
5473/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
5474/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
5475/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
5476/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
5477/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
5478@end example
5479
5480@cindex closure
5481The store items listed here constitute the @dfn{transitive closure} of
5482Coreutils---i.e., Coreutils and all its dependencies, recursively---as
5483would be returned by:
5484
5485@example
5486$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
5487@end example
5488
f97c9175 5489Here the output shows three columns next to store items. The first column,
fcc58db6
LC
5490labeled ``total'', shows the size in mebibytes (MiB) of the closure of
5491the store item---that is, its own size plus the size of all its
5492dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
5493item itself. The last column shows the ratio of the size of the item
5494itself to the space occupied by all the items listed here.
fcc58db6
LC
5495
5496In this example, we see that the closure of Coreutils weighs in at
549770@tie{}MiB, half of which is taken by libc. (That libc represents a
5498large fraction of the closure is not a problem @i{per se} because it is
5499always available on the system anyway.)
5500
5501When the package passed to @command{guix size} is available in the
5502store, @command{guix size} queries the daemon to determine its
5503dependencies, and measures its size in the store, similar to @command{du
5504-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5505Coreutils}).
5506
5507When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
5508reports information based on the available substitutes
5509(@pxref{Substitutes}). This makes it possible it to profile disk usage of
5510store items that are not even on disk, only available remotely.
fcc58db6 5511
db761534
LC
5512You can also specify several package names:
5513
5514@example
5515$ guix size coreutils grep sed bash
5516store item total self
5517/gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
5518/gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
5519/gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
5520/gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
5521@dots{}
5522total: 102.3 MiB
5523@end example
5524
5525@noindent
5526In this example we see that the combination of the four packages takes
5527102.3@tie{}MiB in total, which is much less than the sum of each closure
5528since they have a lot of dependencies in common.
5529
a8f996c6 5530The available options are:
fcc58db6
LC
5531
5532@table @option
5533
d490d06e
LC
5534@item --substitute-urls=@var{urls}
5535Use substitute information from @var{urls}.
5536@xref{client-substitute-urls, the same option for @code{guix build}}.
5537
a8f996c6 5538@item --map-file=@var{file}
f97c9175 5539Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
5540
5541For the example above, the map looks like this:
5542
5543@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5544produced by @command{guix size}}
5545
5546This option requires that
5547@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5548installed and visible in Guile's module search path. When that is not
5549the case, @command{guix size} fails as it tries to load it.
5550
fcc58db6
LC
5551@item --system=@var{system}
5552@itemx -s @var{system}
5553Consider packages for @var{system}---e.g., @code{x86_64-linux}.
5554
5555@end table
5556
88856916
LC
5557@node Invoking guix graph
5558@section Invoking @command{guix graph}
5559
5560@cindex DAG
e32171ee
JD
5561@cindex @command{guix graph}
5562@cindex package dependencies
88856916
LC
5563Packages and their dependencies form a @dfn{graph}, specifically a
5564directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175
AE
5565mental model of the package DAG, so the @command{guix graph} command
5566provides a visual representation of the DAG. @command{guix graph}
5567emits a DAG representation in the input format of
88856916 5568@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
f97c9175 5569directly to the @command{dot} command of Graphviz. The general
88856916
LC
5570syntax is:
5571
5572@example
5573guix graph @var{options} @var{package}@dots{}
5574@end example
5575
5576For example, the following command generates a PDF file representing the
5577package DAG for the GNU@tie{}Core Utilities, showing its build-time
5578dependencies:
5579
5580@example
5581guix graph coreutils | dot -Tpdf > dag.pdf
5582@end example
5583
5584The output looks like this:
5585
5586@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
5587
5588Nice little graph, no?
5589
f97c9175 5590But there is more than one graph! The one above is concise: it is the
88856916 5591graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
5592grep, etc. It is often useful to have such a concise graph, but
5593sometimes one may want to see more details. @command{guix graph} supports
5594several types of graphs, allowing you to choose the level of detail:
88856916
LC
5595
5596@table @code
5597@item package
f97c9175 5598This is the default type used in the example above. It shows the DAG of
88856916
LC
5599package objects, excluding implicit dependencies. It is concise, but
5600filters out many details.
5601
5602@item bag-emerged
5603This is the package DAG, @emph{including} implicit inputs.
5604
5605For instance, the following command:
5606
5607@example
5608guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5609@end example
5610
5611... yields this bigger graph:
5612
5613@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5614
5615At the bottom of the graph, we see all the implicit inputs of
5616@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5617
f97c9175 5618Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
5619@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5620here, for conciseness.
5621
5622@item bag
5623Similar to @code{bag-emerged}, but this time including all the bootstrap
5624dependencies.
5625
38b92daa
LC
5626@item bag-with-origins
5627Similar to @code{bag}, but also showing origins and their dependencies.
5628
88856916
LC
5629@item derivations
5630This is the most detailed representation: It shows the DAG of
5631derivations (@pxref{Derivations}) and plain store items. Compared to
5632the above representation, many additional nodes are visible, including
f97c9175 5633build scripts, patches, Guile modules, etc.
88856916 5634
a773c314
LC
5635For this type of graph, it is also possible to pass a @file{.drv} file
5636name instead of a package name, as in:
5637
5638@example
5639guix graph -t derivation `guix system build -d my-config.scm`
5640@end example
88856916
LC
5641@end table
5642
f97c9175 5643All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
5644following graph type represents the @emph{run-time dependencies}:
5645
5646@table @code
5647@item references
5648This is the graph of @dfn{references} of a package output, as returned
5649by @command{guix gc --references} (@pxref{Invoking guix gc}).
5650
5651If the given package output is not available in the store, @command{guix
5652graph} attempts to obtain dependency information from substitutes.
a773c314
LC
5653
5654Here you can also pass a store file name instead of a package name. For
5655example, the command below produces the reference graph of your profile
5656(which can be big!):
5657
5658@example
5659guix graph -t references `readlink -f ~/.guix-profile`
5660@end example
7f8fec0f
LC
5661
5662@item referrers
5663This is the graph of the @dfn{referrers} of a store item, as returned by
5664@command{guix gc --referrers} (@pxref{Invoking guix gc}).
5665
5666This relies exclusively on local information from your store. For
5667instance, let us suppose that the current Inkscape is available in 10
5668profiles on your machine; @command{guix graph -t referrers inkscape}
5669will show a graph rooted at Inkscape and with those 10 profiles linked
5670to it.
5671
5672It can help determine what is preventing a store item from being garbage
5673collected.
5674
88856916
LC
5675@end table
5676
5677The available options are the following:
5678
5679@table @option
5680@item --type=@var{type}
5681@itemx -t @var{type}
5682Produce a graph output of @var{type}, where @var{type} must be one of
5683the values listed above.
5684
5685@item --list-types
5686List the supported graph types.
4c8f997a
LC
5687
5688@item --expression=@var{expr}
5689@itemx -e @var{expr}
5690Consider the package @var{expr} evaluates to.
5691
5692This is useful to precisely refer to a package, as in this example:
5693
5694@example
5695guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5696@end example
88856916
LC
5697@end table
5698
5699
372c4bbc
DT
5700@node Invoking guix environment
5701@section Invoking @command{guix environment}
5702
f5fd4fd2 5703@cindex reproducible build environments
fe36d84e 5704@cindex development environments
e32171ee
JD
5705@cindex @command{guix environment}
5706@cindex environment, package build environment
372c4bbc
DT
5707The purpose of @command{guix environment} is to assist hackers in
5708creating reproducible development environments without polluting their
5709package profile. The @command{guix environment} tool takes one or more
f97c9175 5710packages, builds all of their inputs, and creates a shell
372c4bbc
DT
5711environment to use them.
5712
5713The general syntax is:
5714
5715@example
5716guix environment @var{options} @var{package}@dots{}
5717@end example
5718
fe36d84e
LC
5719The following example spawns a new shell set up for the development of
5720GNU@tie{}Guile:
372c4bbc
DT
5721
5722@example
5723guix environment guile
5724@end example
5725
f97c9175
AE
5726If the needed dependencies are not built yet, @command{guix environment}
5727automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
5728version of the environment that @command{guix environment} was run in.
5729It contains the necessary search paths for building the given package
5730added to the existing environment variables. To create a ``pure''
f97c9175 5731environment, in which the original environment variables have been unset,
50500f7c
LC
5732use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5733environment variables such as @code{PATH} in their @file{~/.bashrc}
5734file. As a consequence, when @code{guix environment} launches it, Bash
5735may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5736environment variables. It is an error to define such environment
5737variables in @file{.bashrc}; instead, they should be defined in
5738@file{.bash_profile}, which is sourced only by log-in shells.
5739@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5740details on Bash start-up files.}.
372c4bbc 5741
28de8d25
LC
5742@vindex GUIX_ENVIRONMENT
5743@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
20185522
LC
5744variable in the shell it spawns; its value is the file name of the
5745profile of this environment. This allows users to, say, define a
28de8d25
LC
5746specific prompt for development environments in their @file{.bashrc}
5747(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5748
5749@example
5750if [ -n "$GUIX_ENVIRONMENT" ]
5751then
5752 export PS1="\u@@\h \w [dev]\$ "
5753fi
5754@end example
5755
20185522
LC
5756@noindent
5757... or to browse the profile:
5758
5759@example
5760$ ls "$GUIX_ENVIRONMENT/bin"
5761@end example
5762
372c4bbc
DT
5763Additionally, more than one package may be specified, in which case the
5764union of the inputs for the given packages are used. For example, the
5765command below spawns a shell where all of the dependencies of both Guile
5766and Emacs are available:
5767
5768@example
5769guix environment guile emacs
5770@end example
5771
1de2fe95
DT
5772Sometimes an interactive shell session is not desired. An arbitrary
5773command may be invoked by placing the @code{--} token to separate the
5774command from the rest of the arguments:
372c4bbc
DT
5775
5776@example
1de2fe95 5777guix environment guile -- make -j4
372c4bbc
DT
5778@end example
5779
fe36d84e
LC
5780In other situations, it is more convenient to specify the list of
5781packages needed in the environment. For example, the following command
5782runs @command{python} from an environment containing Python@tie{}2.7 and
5783NumPy:
5784
5785@example
1de2fe95 5786guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
5787@end example
5788
cc90fbbf
DT
5789Furthermore, one might want the dependencies of a package and also some
5790additional packages that are not build-time or runtime dependencies, but
5791are useful when developing nonetheless. Because of this, the
5792@code{--ad-hoc} flag is positional. Packages appearing before
5793@code{--ad-hoc} are interpreted as packages whose dependencies will be
5794added to the environment. Packages appearing after are interpreted as
5795packages that will be added to the environment directly. For example,
5796the following command creates a Guix development environment that
5797additionally includes Git and strace:
5798
5799@example
5800guix environment guix --ad-hoc git strace
5801@end example
5802
f535dcbe
DT
5803Sometimes it is desirable to isolate the environment as much as
5804possible, for maximal purity and reproducibility. In particular, when
5805using Guix on a host distro that is not GuixSD, it is desirable to
5806prevent access to @file{/usr/bin} and other system-wide resources from
5807the development environment. For example, the following command spawns
5808a Guile REPL in a ``container'' where only the store and the current
5809working directory are mounted:
5810
5811@example
5812guix environment --ad-hoc --container guile -- guile
5813@end example
5814
0f252e26 5815@quotation Note
cfd35b4e 5816The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
5817@end quotation
5818
fe36d84e 5819The available options are summarized below.
372c4bbc
DT
5820
5821@table @code
5822@item --expression=@var{expr}
5823@itemx -e @var{expr}
c9c282ce
DT
5824Create an environment for the package or list of packages that
5825@var{expr} evaluates to.
372c4bbc 5826
fe36d84e
LC
5827For example, running:
5828
5829@example
5830guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
5831@end example
5832
5833starts a shell with the environment for this specific variant of the
5834PETSc package.
5835
c9c282ce
DT
5836Running:
5837
5838@example
5c2b2f00 5839guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
5840@end example
5841
5842starts a shell with all the GuixSD base packages available.
5843
779aa003
DT
5844The above commands only the use default output of the given packages.
5845To select other outputs, two element tuples can be specified:
5846
5847@example
5848guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
5849@end example
5850
372c4bbc
DT
5851@item --load=@var{file}
5852@itemx -l @var{file}
c9c282ce
DT
5853Create an environment for the package or list of packages that the code
5854within @var{file} evaluates to.
372c4bbc 5855
fe36d84e
LC
5856As an example, @var{file} might contain a definition like this
5857(@pxref{Defining Packages}):
5858
5859@example
5860@verbatiminclude environment-gdb.scm
5861@end example
5862
a54bd6d7
DT
5863@item --ad-hoc
5864Include all specified packages in the resulting environment, as if an
5865@i{ad hoc} package were defined with them as inputs. This option is
5866useful for quickly creating an environment without having to write a
5867package expression to contain the desired inputs.
5868
5869For instance, the command:
5870
5871@example
1de2fe95 5872guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
5873@end example
5874
5875runs @command{guile} in an environment where Guile and Guile-SDL are
5876available.
5877
417c39f1 5878Note that this example implicitly asks for the default output of
f97c9175 5879@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
5880specific output---e.g., @code{glib:bin} asks for the @code{bin} output
5881of @code{glib} (@pxref{Packages with Multiple Outputs}).
5882
cc90fbbf
DT
5883This option may be composed with the default behavior of @command{guix
5884environment}. Packages appearing before @code{--ad-hoc} are interpreted
5885as packages whose dependencies will be added to the environment, the
5886default behavior. Packages appearing after are interpreted as packages
5887that will be added to the environment directly.
5888
372c4bbc
DT
5889@item --pure
5890Unset existing environment variables when building the new environment.
5891This has the effect of creating an environment in which search paths
5892only contain package inputs.
5893
5894@item --search-paths
5895Display the environment variable definitions that make up the
5896environment.
ce367ef3
LC
5897
5898@item --system=@var{system}
5899@itemx -s @var{system}
5900Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
5901
5902@item --container
5903@itemx -C
5904@cindex container
5905Run @var{command} within an isolated container. The current working
a01ad638
DT
5906directory outside the container is mapped inside the container.
5907Additionally, a dummy home directory is created that matches the current
5908user's home directory, and @file{/etc/passwd} is configured accordingly.
5909The spawned process runs as the current user outside the container, but
5910has root privileges in the context of the container.
f535dcbe
DT
5911
5912@item --network
5913@itemx -N
5914For containers, share the network namespace with the host system.
5915Containers created without this flag only have access to the loopback
5916device.
5917
5918@item --expose=@var{source}[=@var{target}]
5919For containers, expose the file system @var{source} from the host system
5920as the read-only file system @var{target} within the container. If
5921@var{target} is not specified, @var{source} is used as the target mount
5922point in the container.
5923
5924The example below spawns a Guile REPL in a container in which the user's
5925home directory is accessible read-only via the @file{/exchange}
5926directory:
5927
5928@example
5929guix environment --container --expose=$HOME=/exchange guile -- guile
5930@end example
5931
5c2b2f00 5932@item --share=@var{source}[=@var{target}]
f535dcbe
DT
5933For containers, share the file system @var{source} from the host system
5934as the writable file system @var{target} within the container. If
5935@var{target} is not specified, @var{source} is used as the target mount
5936point in the container.
5937
5938The example below spawns a Guile REPL in a container in which the user's
5939home directory is accessible for both reading and writing via the
5940@file{/exchange} directory:
5941
5942@example
5943guix environment --container --share=$HOME=/exchange guile -- guile
5944@end example
372c4bbc
DT
5945@end table
5946
5947It also supports all of the common build options that @command{guix
ccd7158d 5948build} supports (@pxref{Common Build Options}).
372c4bbc 5949
aff8ce7c
DT
5950@node Invoking guix publish
5951@section Invoking @command{guix publish}
5952
e32171ee 5953@cindex @command{guix publish}
aff8ce7c 5954The purpose of @command{guix publish} is to enable users to easily share
f97c9175 5955their store with others, who can then use it as a substitute server
8ce229fc
LC
5956(@pxref{Substitutes}).
5957
5958When @command{guix publish} runs, it spawns an HTTP server which allows
5959anyone with network access to obtain substitutes from it. This means
5960that any machine running Guix can also act as if it were a build farm,
5961since the HTTP interface is compatible with Hydra, the software behind
5962the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
5963
5964For security, each substitute is signed, allowing recipients to check
5965their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 5966@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
5967readable by the system administrator, it must be started as root; the
5968@code{--user} option makes it drop root privileges early on.
aff8ce7c 5969
b18812b6
LC
5970The signing key pair must be generated before @command{guix publish} is
5971launched, using @command{guix archive --generate-key} (@pxref{Invoking
5972guix archive}).
5973
aff8ce7c
DT
5974The general syntax is:
5975
5976@example
5977guix publish @var{options}@dots{}
5978@end example
5979
5980Running @command{guix publish} without any additional arguments will
5981spawn an HTTP server on port 8080:
5982
5983@example
5984guix publish
5985@end example
5986
5987Once a publishing server has been authorized (@pxref{Invoking guix
5988archive}), the daemon may download substitutes from it:
5989
5990@example
5991guix-daemon --substitute-urls=http://example.org:8080
5992@end example
5993
ff6638d1
LC
5994As a bonus, @command{guix publish} also serves as a content-addressed
5995mirror for source files referenced in @code{origin} records
5996(@pxref{origin Reference}). For instance, assuming @command{guix
5997publish} is running on @code{example.org}, the following URL returns the
5998raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
5999(represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
6000
6001@example
6002http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
6003@end example
6004
6005Obviously, these URLs only work for files that are in the store; in
6006other cases, they return 404 (``Not Found'').
6007
aff8ce7c
DT
6008The following options are available:
6009
6010@table @code
6011@item --port=@var{port}
6012@itemx -p @var{port}
6013Listen for HTTP requests on @var{port}.
6014
9e2292ef
LC
6015@item --listen=@var{host}
6016Listen on the network interface for @var{host}. The default is to
6017accept connections from any interface.
6018
5463fe51
LC
6019@item --user=@var{user}
6020@itemx -u @var{user}
6021Change privileges to @var{user} as soon as possible---i.e., once the
6022server socket is open and the signing key has been read.
6023
4a1fc562
LC
6024@item --compression[=@var{level}]
6025@itemx -C [@var{level}]
6026Compress data using the given @var{level}. When @var{level} is zero,
6027disable compression. The range 1 to 9 corresponds to different gzip
6028compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
6029The default is 3.
6030
4591c02e 6031Compression occurs on the fly and the compressed streams are not
4a1fc562
LC
6032cached. Thus, to reduce load on the machine that runs @command{guix
6033publish}, it may be a good idea to choose a low compression level, or to
6034run @command{guix publish} behind a caching proxy.
6035
e4c7a5f7
LC
6036@item --ttl=@var{ttl}
6037Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
6038(TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
6039days, @code{1m} means 1 month, and so on.
6040
6041This allows the user's Guix to keep substitute information in cache for
6042@var{ttl}. However, note that @code{guix publish} does not itself
6043guarantee that the store items it provides will indeed remain available
6044for as long as @var{ttl}.
6045
aff8ce7c
DT
6046@item --repl[=@var{port}]
6047@itemx -r [@var{port}]
6048Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
6049Reference Manual}) on @var{port} (37146 by default). This is used
6050primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
6051@end table
6052
1c52181f
LC
6053Enabling @command{guix publish} on a GuixSD system is a one-liner: just
6054add a call to @code{guix-publish-service} in the @code{services} field
6055of the @code{operating-system} declaration (@pxref{guix-publish-service,
6056@code{guix-publish-service}}).
6057
332d7903
HG
6058If you are instead running Guix on a ``foreign distro'', follow these
6059instructions:”
6060
6061@itemize
6062@item
6063If your host distro uses the systemd init system:
6064
6065@example
6066# ln -s ~root/.guix-profile/lib/systemd/system/guix-publish.service \
6067 /etc/systemd/system/
6068# systemctl start guix-publish && systemctl enable guix-publish
6069@end example
6070
6071@item
6072If your host distro uses the Upstart init system:
6073
6074@example
6075# ln -s ~root/.guix-profile/lib/upstart/system/guix-publish.conf /etc/init/
6076# start guix-publish
6077@end example
6078
6079@item
6080Otherwise, proceed similarly with your distro's init system.
6081@end itemize
d23c20f1
LC
6082
6083@node Invoking guix challenge
6084@section Invoking @command{guix challenge}
6085
6086@cindex reproducible builds
6087@cindex verifiable builds
e32171ee
JD
6088@cindex @command{guix challenge}
6089@cindex challenge
d23c20f1 6090Do the binaries provided by this server really correspond to the source
f97c9175 6091code it claims to build? Is a package build process deterministic?
d23c20f1
LC
6092These are the questions the @command{guix challenge} command attempts to
6093answer.
6094
6095The former is obviously an important question: Before using a substitute
f97c9175 6096server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
6097provides the right binaries, and thus @emph{challenge} it. The latter
6098is what enables the former: If package builds are deterministic, then
6099independent builds of the package should yield the exact same result,
6100bit for bit; if a server provides a binary different from the one
6101obtained locally, it may be either corrupt or malicious.
6102
6103We know that the hash that shows up in @file{/gnu/store} file names is
6104the hash of all the inputs of the process that built the file or
6105directory---compilers, libraries, build scripts,
6106etc. (@pxref{Introduction}). Assuming deterministic build processes,
6107one store file name should map to exactly one build output.
6108@command{guix challenge} checks whether there is, indeed, a single
6109mapping by comparing the build outputs of several independent builds of
6110any given store item.
6111
f97c9175 6112The command output looks like this:
d23c20f1
LC
6113
6114@smallexample
ddbc7f7d
LC
6115$ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
6116updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
6117updating list of substitutes from 'https://guix.example.org'... 100.0%
d23c20f1
LC
6118/gnu/store/@dots{}-openssl-1.0.2d contents differ:
6119 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
ddbc7f7d
LC
6120 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
6121 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
d23c20f1
LC
6122/gnu/store/@dots{}-git-2.5.0 contents differ:
6123 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
ddbc7f7d
LC
6124 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
6125 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
d23c20f1
LC
6126/gnu/store/@dots{}-pius-2.1.1 contents differ:
6127 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
ddbc7f7d
LC
6128 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
6129 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
d23c20f1
LC
6130@end smallexample
6131
6132@noindent
6133In this example, @command{guix challenge} first scans the store to
6134determine the set of locally-built derivations---as opposed to store
6135items that were downloaded from a substitute server---and then queries
6136all the substitute servers. It then reports those store items for which
6137the servers obtained a result different from the local build.
6138
6139@cindex non-determinism, in package builds
6140As an example, @code{guix.example.org} always gets a different answer.
6141Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
6142case of Git. This might indicate that the build process of Git is
6143non-deterministic, meaning that its output varies as a function of
6144various things that Guix does not fully control, in spite of building
6145packages in isolated environments (@pxref{Features}). Most common
6146sources of non-determinism include the addition of timestamps in build
6147results, the inclusion of random numbers, and directory listings sorted
a70a5004 6148by inode number. See @uref{https://reproducible-builds.org/docs/}, for
d23c20f1
LC
6149more information.
6150
f97c9175 6151To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
6152these lines (@pxref{Invoking guix archive}):
6153
6154@example
ddbc7f7d 6155$ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
d23c20f1 6156 | guix archive -x /tmp/git
043f4698 6157$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
6158@end example
6159
6160This command shows the difference between the files resulting from the
6161local build, and the files resulting from the build on
6162@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
6163diffutils, Comparing and Merging Files}). The @command{diff} command
6164works great for text files. When binary files differ, a better option
ddbc7f7d 6165is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
d23c20f1
LC
6166visualize differences for all kinds of files.
6167
f97c9175 6168Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
6169to a non-deterministic build process or to a malicious server. We try
6170hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
6171to verify substitutes, but of course, this is a process that
6172involves not just Guix, but a large part of the free software community.
d23c20f1
LC
6173In the meantime, @command{guix challenge} is one tool to help address
6174the problem.
6175
6176If you are writing packages for Guix, you are encouraged to check
6177whether @code{hydra.gnu.org} and other substitute servers obtain the
6178same build result as you did with:
6179
6180@example
6181$ guix challenge @var{package}
6182@end example
6183
6184@noindent
f97c9175 6185where @var{package} is a package specification such as
7cffaeb6 6186@code{guile@@2.0} or @code{glibc:debug}.
d23c20f1
LC
6187
6188The general syntax is:
6189
6190@example
6191guix challenge @var{options} [@var{packages}@dots{}]
6192@end example
6193
7cffaeb6
LC
6194When a difference is found between the hash of a locally-built item and
6195that of a server-provided substitute, or among substitutes provided by
6196different servers, the command displays it as in the example above and
a17417a8
LC
6197its exit code is 2 (other non-zero exit codes denote other kinds of
6198errors.)
7cffaeb6 6199
d23c20f1
LC
6200The one option that matters is:
6201
6202@table @code
6203
6204@item --substitute-urls=@var{urls}
6205Consider @var{urls} the whitespace-separated list of substitute source
6206URLs to compare to.
6207
6208@end table
6209
6210
32efa254
DT
6211@node Invoking guix container
6212@section Invoking @command{guix container}
6213@cindex container
e32171ee 6214@cindex @command{guix container}
32efa254
DT
6215@quotation Note
6216As of version @value{VERSION}, this tool is experimental. The interface
6217is subject to radical change in the future.
6218@end quotation
6219
6220The purpose of @command{guix container} is to manipulate processes
6221running within an isolated environment, commonly known as a
46c36586 6222``container'', typically created by the @command{guix environment}
32efa254
DT
6223(@pxref{Invoking guix environment}) and @command{guix system container}
6224(@pxref{Invoking guix system}) commands.
6225
6226The general syntax is:
6227
6228@example
6229guix container @var{action} @var{options}@dots{}
6230@end example
6231
6232@var{action} specifies the operation to perform with a container, and
6233@var{options} specifies the context-specific arguments for the action.
6234
6235The following actions are available:
6236
6237@table @code
6238@item exec
6239Execute a command within the context of a running container.
6240
6241The syntax is:
6242
6243@example
6244guix container exec @var{pid} @var{program} @var{arguments}@dots{}
6245@end example
6246
6247@var{pid} specifies the process ID of the running container.
f97c9175
AE
6248@var{program} specifies an executable file name within the root file
6249system of the container. @var{arguments} are the additional options that
6250will be passed to @var{program}.
32efa254
DT
6251
6252The following command launches an interactive login shell inside a
6253GuixSD container, started by @command{guix system container}, and whose
6254process ID is 9001:
6255
6256@example
6257guix container exec 9001 /run/current-system/profile/bin/bash --login
6258@end example
6259
6260Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 6261must be PID 1 of the container or one of its child processes.
32efa254
DT
6262
6263@end table
6264
a1ba8475
LC
6265@c *********************************************************************
6266@node GNU Distribution
6267@chapter GNU Distribution
6268
3ca2731c 6269@cindex Guix System Distribution
4705641f 6270@cindex GuixSD
3ca2731c
LC
6271Guix comes with a distribution of the GNU system consisting entirely of
6272free software@footnote{The term ``free'' here refers to the
a1ba8475 6273@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 6274users of that software}.}. The
35ed9306
LC
6275distribution can be installed on its own (@pxref{System Installation}),
6276but it is also possible to install Guix as a package manager on top of
6277an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 6278between the two, we refer to the standalone distribution as the Guix
4705641f 6279System Distribution, or GuixSD.
35ed9306
LC
6280
6281The distribution provides core GNU packages such as GNU libc, GCC, and
6282Binutils, as well as many GNU and non-GNU applications. The complete
6283list of available packages can be browsed
093ae1be 6284@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 6285running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
6286
6287@example
e49951eb 6288guix package --list-available
a1ba8475
LC
6289@end example
6290
f97c9175 6291Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
6292Linux-based and other variants of GNU, with a focus on the promotion and
6293tight integration of GNU components, and an emphasis on programs and
6294tools that help users exert that freedom.
6295
3ca2731c 6296Packages are currently available on the following platforms:
c320011d
LC
6297
6298@table @code
6299
6300@item x86_64-linux
6301Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
6302
6303@item i686-linux
6304Intel 32-bit architecture (IA32), Linux-Libre kernel;
6305
aa1e1947 6306@item armhf-linux
aa725117 6307ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
6308using the EABI hard-float application binary interface (ABI),
6309and Linux-Libre kernel.
aa1e1947 6310
c320011d
LC
6311@item mips64el-linux
6312little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 6313n32 ABI, and Linux-Libre kernel.
c320011d
LC
6314
6315@end table
6316
4705641f 6317GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 6318
c320011d
LC
6319@noindent
6320For information on porting to other architectures or kernels,
f97c9175 6321@pxref{Porting}.
c320011d 6322
401c53c4 6323@menu
5af6de3e 6324* System Installation:: Installing the whole operating system.
35ed9306 6325* System Configuration:: Configuring the operating system.
91ef73d4 6326* Installing Debugging Files:: Feeding the debugger.
05962f29 6327* Security Updates:: Deploying security fixes quickly.
401c53c4 6328* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 6329* Packaging Guidelines:: Growing the distribution.
401c53c4 6330* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 6331* Porting:: Targeting another platform or kernel.
401c53c4
LC
6332@end menu
6333
6334Building this distribution is a cooperative effort, and you are invited
081145cf 6335to join! @xref{Contributing}, for information about how you can help.
401c53c4 6336
5af6de3e
LC
6337@node System Installation
6338@section System Installation
6339
e32171ee 6340@cindex installing GuixSD
3ca2731c 6341@cindex Guix System Distribution
c8b54374 6342This section explains how to install the Guix System Distribution (GuixSD)
3ca2731c 6343on a machine. The Guix package manager can
35ed9306
LC
6344also be installed on top of a running GNU/Linux system,
6345@pxref{Installation}.
5af6de3e
LC
6346
6347@ifinfo
9c18cf9b 6348@quotation Note
5af6de3e
LC
6349@c This paragraph is for people reading this from tty2 of the
6350@c installation image.
1068f26b 6351You are reading this documentation with an Info reader. For details on
5af6de3e 6352how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
de341e7c
LC
6353link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
6354Info}. Hit @kbd{l} afterwards to come back here.
9c18cf9b
LC
6355
6356Alternately, run @command{info info} in another tty to keep the manual
6357available.
6358@end quotation
5af6de3e
LC
6359@end ifinfo
6360
dedb8d5e 6361@menu
e3009f60
LC
6362* Limitations:: What you can expect.
6363* Hardware Considerations:: Supported hardware.
6364* USB Stick Installation:: Preparing the installation medium.
6365* Preparing for Installation:: Networking, partitioning, etc.
6366* Proceeding with the Installation:: The real thing.
c8b54374 6367* Installing GuixSD in a VM:: GuixSD playground.
e3009f60 6368* Building the Installation Image:: How this comes to be.
dedb8d5e
LC
6369@end menu
6370
6371@node Limitations
8aaaae38
LC
6372@subsection Limitations
6373
4705641f 6374As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 6375not production-ready. It may contain bugs and lack important
8aaaae38
LC
6376features. Thus, if you are looking for a stable production system that
6377respects your freedom as a computer user, a good solution at this point
6378is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 6379the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 6380to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
6381also keep using your distribution and try out the package manager on top
6382of it (@pxref{Installation}).
6383
6384Before you proceed with the installation, be aware of the following
6385noteworthy limitations applicable to version @value{VERSION}:
6386
6387@itemize
6388@item
6389The installation process does not include a graphical user interface and
6390requires familiarity with GNU/Linux (see the following subsections to
6391get a feel of what that means.)
6392
8aaaae38 6393@item
dbcb0ab1 6394Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
6395
6396@item
6397Few system services are currently supported out-of-the-box
6398(@pxref{Services}).
6399
6400@item
29e53b95 6401More than 4,000 packages are available, but you may
8aaaae38 6402occasionally find that a useful package is missing.
5fe01c2d
LC
6403
6404@item
6405GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
6406as well as a number of X11 window managers. However, some graphical
6407applications may be missing, as well as KDE.
8aaaae38
LC
6408@end itemize
6409
f97c9175
AE
6410You have been warned! But more than a disclaimer, this is an invitation
6411to report issues (and success stories!), and to join us in improving it.
8aaaae38 6412@xref{Contributing}, for more info.
5af6de3e 6413
e3009f60
LC
6414
6415@node Hardware Considerations
6416@subsection Hardware Considerations
6417
6418@cindex hardware support on GuixSD
6419GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
6420builds around the kernel Linux-libre, which means that only hardware for
e0b3f97e 6421which free software drivers and firmware exist is supported. Nowadays,
e3009f60
LC
6422a wide range of off-the-shelf hardware is supported on
6423GNU/Linux-libre---from keyboards to graphics cards to scanners and
6424Ethernet controllers. Unfortunately, there are still areas where
6425hardware vendors deny users control over their own computing, and such
6426hardware is not supported on GuixSD.
6427
6428@cindex WiFi, hardware support
e0b3f97e 6429One of the main areas where free drivers or firmware are lacking is WiFi
e3009f60
LC
6430devices. WiFi devices known to work include those using Atheros chips
6431(AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
52db41af
EB
6432driver, and those using Broadcom/AirForce chips (BCM43xx with
6433Wireless-Core Revision 5), which corresponds to the @code{b43-open}
6434Linux-libre driver. Free firmware exists for both and is available
e3009f60
LC
6435out-of-the-box on GuixSD, as part of @var{%base-firmware}
6436(@pxref{operating-system Reference, @code{firmware}}).
6437
6438@cindex RYF, Respects Your Freedom
6439The @uref{https://www.fsf.org/, Free Software Foundation} runs
e0b3f97e 6440@uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
e3009f60
LC
6441certification program for hardware products that respect your freedom
6442and your privacy and ensure that you have control over your device. We
e0b3f97e 6443encourage you to check the list of RYF-certified devices.
e3009f60
LC
6444
6445Another useful resource is the @uref{https://www.h-node.org/, H-Node}
6446web site. It contains a catalog of hardware devices with information
6447about their support in GNU/Linux.
6448
6449
dedb8d5e 6450@node USB Stick Installation
5af6de3e
LC
6451@subsection USB Stick Installation
6452
6453An installation image for USB sticks can be downloaded from
4705641f 6454@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
6455where @var{system} is one of:
6456
6457@table @code
6458@item x86_64-linux
6459for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
6460
6461@item i686-linux
6462for a 32-bit GNU/Linux system on Intel-compatible CPUs.
6463@end table
6464
debc6360
LC
6465@c start duplication of authentication part from ``Binary Installation''
6466Make sure to download the associated @file{.sig} file and to verify the
6467authenticity of the image against it, along these lines:
6468
6469@example
6470$ wget ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6471$ gpg --verify guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6472@end example
6473
6474If that command fails because you do not have the required public key,
6475then run this command to import it:
6476
6477@example
6478$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
6479@end example
6480
6481@noindent
6482and rerun the @code{gpg --verify} command.
6483@c end duplication
6484
5af6de3e
LC
6485This image contains a single partition with the tools necessary for an
6486installation. It is meant to be copied @emph{as is} to a large-enough
6487USB stick.
6488
6489To copy the image to a USB stick, follow these steps:
6490
6491@enumerate
6492@item
6493Decompress the image using the @command{xz} command:
6494
6495@example
4705641f 6496xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
6497@end example
6498
6499@item
f97c9175
AE
6500Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
6501its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
6502copy the image with:
6503
6504@example
4705641f 6505dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
6506@end example
6507
6508Access to @file{/dev/sdX} usually requires root privileges.
6509@end enumerate
6510
6511Once this is done, you should be able to reboot the system and boot from
6512the USB stick. The latter usually requires you to get in the BIOS' boot
6513menu, where you can choose to boot from the USB stick.
6514
c8b54374
VL
6515@xref{Installing GuixSD in a VM}, if, instead, you would like to install
6516GuixSD in a virtual machine (VM).
6517
dedb8d5e 6518@node Preparing for Installation
5af6de3e
LC
6519@subsection Preparing for Installation
6520
6521Once you have successfully booted the image on the USB stick, you should
6522end up with a root prompt. Several console TTYs are configured and can
6523be used to run commands as root. TTY2 shows this documentation,
de341e7c
LC
6524browsable using the Info reader commands (@pxref{Top,,, info-stnd,
6525Stand-alone GNU Info}). The installation system runs the GPM mouse
6526daemon, which allows you to select text with the left mouse button and
6527to paste it with the middle button.
5af6de3e 6528
ff925d37
LC
6529@quotation Note
6530Installation requires access to the Internet so that any missing
6531dependencies of your system configuration can be downloaded. See the
6532``Networking'' section below.
6533@end quotation
6534
0e69cf67
LC
6535The installation system includes many common tools needed for this task.
6536But it is also a full-blown GuixSD system, which means that you can
6537install additional packages, should you need it, using @command{guix
6538package} (@pxref{Invoking guix package}).
6539
dedb8d5e 6540@subsubsection Keyboard Layout
5af6de3e 6541
dedb8d5e
LC
6542@cindex keyboard layout
6543The installation image uses the US qwerty keyboard layout. If you want
6544to change it, you can use the @command{loadkeys} command. For example,
6545the following command selects the Dvorak keyboard layout:
5af6de3e 6546
dedb8d5e
LC
6547@example
6548loadkeys dvorak
6549@end example
6550
6551See the files under @file{/run/current-system/profile/share/keymaps} for
6552a list of available keyboard layouts. Run @command{man loadkeys} for
6553more information.
6554
6555@subsubsection Networking
6556
6557Run the following command see what your network interfaces are called:
235cba85
LC
6558
6559@example
dedb8d5e 6560ifconfig -a
235cba85
LC
6561@end example
6562
1713c37f
LC
6563@noindent
6564@dots{} or, using the GNU/Linux-specific @command{ip} command:
6565
6566@example
6567ip a
6568@end example
6569
95c559c1 6570@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
6571Wired interfaces have a name starting with @samp{e}; for example, the
6572interface corresponding to the first on-board Ethernet controller is
6573called @samp{eno1}. Wireless interfaces have a name starting with
6574@samp{w}, like @samp{w1p2s0}.
6575
6576@table @asis
6577@item Wired connection
6578To configure a wired network run the following command, substituting
6579@var{interface} with the name of the wired interface you want to use.
6580
6581@example
6582ifconfig @var{interface} up
6583@end example
6584
6585@item Wireless connection
e32171ee
JD
6586@cindex wireless
6587@cindex WiFi
dedb8d5e
LC
6588To configure wireless networking, you can create a configuration file
6589for the @command{wpa_supplicant} configuration tool (its location is not
6590important) using one of the available text editors such as
6591@command{zile}:
6592
6593@example
6594zile wpa_supplicant.conf
6595@end example
6596
6597As an example, the following stanza can go to this file and will work
6598for many wireless networks, provided you give the actual SSID and
6599passphrase for the network you are connecting to:
6600
6601@example
6602network=@{
ae768308 6603 ssid="@var{my-ssid}"
dedb8d5e
LC
6604 key_mgmt=WPA-PSK
6605 psk="the network's secret passphrase"
6606@}
6607@end example
6608
6609Start the wireless service and run it in the background with the
6610following command (substitute @var{interface} with the name of the
6611network interface you want to use):
6612
6613@example
6614wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
6615@end example
6616
641d0518 6617Run @command{man wpa_supplicant} for more information.
dedb8d5e
LC
6618@end table
6619
e32171ee 6620@cindex DHCP
dedb8d5e
LC
6621At this point, you need to acquire an IP address. On a network where IP
6622addresses are automatically assigned @i{via} DHCP, you can run:
6623
6624@example
15650ac2 6625dhclient -v @var{interface}
dedb8d5e 6626@end example
5af6de3e 6627
dedb8d5e
LC
6628Try to ping a server to see if networking is up and running:
6629
6630@example
6631ping -c 3 gnu.org
6632@end example
5af6de3e
LC
6633
6634Setting up network access is almost always a requirement because the
6635image does not contain all the software and tools that may be needed.
6636
dedb8d5e
LC
6637@subsubsection Disk Partitioning
6638
6639Unless this has already been done, the next step is to partition, and
6640then format the target partition(s).
6641
6642The installation image includes several partitioning tools, including
6643Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
6644@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
6645the partition layout you want:
6646
6647@example
6648cfdisk
6649@end example
6650
6651Once you are done partitioning the target hard disk drive, you have to
6652create a file system on the relevant partition(s)@footnote{Currently
6653GuixSD pretty much assumes an ext4 file system. In particular, code
6654that reads partition UUIDs and labels only works with ext4. This will
6655be fixed in the future.}.
5af6de3e 6656
7ab44369
LC
6657Preferably, assign partitions a label so that you can easily and
6658reliably refer to them in @code{file-system} declarations (@pxref{File
6659Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
6660@command{mkfs.ext4} and related commands. So, assuming the target root
6661partition lives at @file{/dev/sda1}, a file system with the label
6662@code{my-root} can be created with:
7ab44369 6663
dedb8d5e
LC
6664@example
6665mkfs.ext4 -L my-root /dev/sda1
6666@end example
dd816355 6667
316d65be
LC
6668@c FIXME: Uncomment this once GRUB fully supports encrypted roots.
6669@c A typical command sequence may be:
6670@c
6671@c @example
6672@c # fdisk /dev/sdX
6673@c @dots{} Create partitions etc.@dots{}
6674@c # cryptsetup luksFormat /dev/sdX1
6675@c # cryptsetup open --type luks /dev/sdX1 my-partition
6676@c # mkfs.ext4 -L my-root /dev/mapper/my-partition
6677@c @end example
6d6e6281 6678
dedb8d5e
LC
6679In addition to e2fsprogs, the suite of tools to manipulate
6680ext2/ext3/ext4 file systems, the installation image includes
6681Cryptsetup/LUKS for disk encryption.
5af6de3e 6682
dedb8d5e
LC
6683Once that is done, mount the target root partition under @file{/mnt}
6684with a command like (again, assuming @file{/dev/sda1} is the root
6685partition):
83a17b62 6686
dedb8d5e
LC
6687@example
6688mount /dev/sda1 /mnt
6689@end example
83a17b62 6690
31b6cdf8
LC
6691Finally, if you plan to use one or more swap partitions (@pxref{Memory
6692Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
6693sure to initialize them with @command{mkswap}. Assuming you have one
6694swap partition on @file{/dev/sda2}, you would run:
6695
6696@example
6697mkswap /dev/sda2
6698@end example
6699
dedb8d5e
LC
6700@node Proceeding with the Installation
6701@subsection Proceeding with the Installation
83a17b62 6702
dedb8d5e
LC
6703With the target partitions ready and the target root mounted on
6704@file{/mnt}, we're ready to go. First, run:
5af6de3e 6705
dedb8d5e
LC
6706@example
6707herd start cow-store /mnt
6708@end example
5af6de3e 6709
b397c0d5
LC
6710This makes @file{/gnu/store} copy-on-write, such that packages added to it
6711during the installation phase are written to the target disk on @file{/mnt}
6712rather than kept in memory. This is necessary because the first phase of
6713the @command{guix system init} command (see below) entails downloads or
6714builds to @file{/gnu/store} which, initially, is an in-memory file system.
5af6de3e 6715
dedb8d5e 6716Next, you have to edit a file and
5af6de3e 6717provide the declaration of the operating system to be installed. To
a8cb87ab
LC
6718that end, the installation system comes with three text editors: GNU nano
6719(@pxref{Top,,, nano, GNU nano Manual}), GNU Zile (an Emacs clone), and
6720nvi (a clone of the original BSD @command{vi} editor).
efa77c6c
LC
6721We strongly recommend storing that file on the target root file system, say,
6722as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
6723configuration file once you have rebooted into the newly-installed system.
5af6de3e 6724
dedb8d5e
LC
6725@xref{Using the Configuration System}, for an overview of the
6726configuration file. The example configurations discussed in that
6727section are available under @file{/etc/configuration} in the
6728installation image. Thus, to get started with a system configuration
6729providing a graphical display server (a ``desktop'' system), you can run
6730something along these lines:
6731
6732@example
6733# mkdir /mnt/etc
6734# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
6735# zile /mnt/etc/config.scm
6736@end example
6737
6738You should pay attention to what your configuration file contains, and
6739in particular:
6740
6741@itemize
6742@item
6743Make sure the @code{grub-configuration} form refers to the device you
6744want to install GRUB on.
6745
6746@item
6747Be sure that your partition labels match the value of their respective
6748@code{device} fields in your @code{file-system} configuration, assuming
6749your @code{file-system} configuration sets the value of @code{title} to
6750@code{'label}.
6751@end itemize
5af6de3e 6752
dd51caac
LC
6753Once you are done preparing the configuration file, the new system must
6754be initialized (remember that the target root file system is mounted
6755under @file{/mnt}):
5af6de3e
LC
6756
6757@example
6758guix system init /mnt/etc/config.scm /mnt
6759@end example
6760
6761@noindent
dedb8d5e 6762This copies all the necessary files and installs GRUB on
5af6de3e 6763@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 6764more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
6765downloads or builds of missing packages, which can take some time.
6766
1bd4e6db
LC
6767Once that command has completed---and hopefully succeeded!---you can run
6768@command{reboot} and boot into the new system. The @code{root} password
6769in the new system is initially empty; other users' passwords need to be
6770initialized by running the @command{passwd} command as @code{root},
6771unless your configuration specifies otherwise
6772(@pxref{user-account-password, user account passwords}).
6773
6774Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
6775@file{guix-devel@@gnu.org} to share your experience---good or not so
6776good.
6777
c8b54374
VL
6778@node Installing GuixSD in a VM
6779@subsection Installing GuixSD in a Virtual Machine
6780
6781@cindex virtual machine, GuixSD installation
6782If you'd like to install GuixSD in a virtual machine (VM) rather than on
6783your beloved machine, this section is for you.
6784
6785To boot a @uref{http://qemu.org/,QEMU} VM for installing GuixSD in a
6786disk image, follow these steps:
6787
6788@enumerate
6789@item
6790First, retrieve the GuixSD installation image as described previously
6791(@pxref{USB Stick Installation}).
6792
6793@item
6794Create a disk image that will hold the installed system. To make a
6795qcow2-formatted disk image, use the @command{qemu-img} command:
6796
6797@example
6798qemu-img create -f qcow2 guixsd.img 5G
6799@end example
6800
6801This will create a 5GB file.
6802
6803@item
6804Boot the USB installation image in an VM:
6805
6806@example
6807qemu-system-x86_64 -m 1024 -smp 1 \
6808 -net default -net nic,model=virtio -boot menu=on \
6809 -drive file=guixsd.img \
6810 -drive file=guixsd-usb-install-@value{VERSION}.@var{system}
6811@end example
6812
6813In the VM console, quickly press the @kbd{F12} key to enter the boot
6814menu. Then press the @kbd{2} key and the @kbd{RET} key to validate your
6815selection.
6816
6817@item
6818You're now root in the VM, proceed with the installation process.
6819@xref{Preparing for Installation}, and follow the instructions.
6820@end enumerate
6821
6822Once installation is complete, you can boot the system that's on your
6823@file{guixsd.img} image. @xref{Running GuixSD in a VM}, for how to do
6824that.
6825
dedb8d5e 6826@node Building the Installation Image
5af6de3e
LC
6827@subsection Building the Installation Image
6828
e32171ee 6829@cindex installation image
5af6de3e
LC
6830The installation image described above was built using the @command{guix
6831system} command, specifically:
6832
622b2304 6833@c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
5af6de3e 6834@example
622b2304 6835guix system disk-image --image-size=1G gnu/system/install.scm
5af6de3e
LC
6836@end example
6837
6e6a0401
AE
6838Have a look at @file{gnu/system/install.scm} in the source tree,
6839and see also @ref{Invoking guix system} for more information
5af6de3e
LC
6840about the installation image.
6841
cf4a9129
LC
6842@node System Configuration
6843@section System Configuration
b208a005 6844
cf4a9129 6845@cindex system configuration
3ca2731c 6846The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
6847mechanism. By that we mean that all aspects of the global system
6848configuration---such as the available system services, timezone and
6849locale settings, user accounts---are declared in a single place. Such
6850a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 6851
cf4a9129
LC
6852One of the advantages of putting all the system configuration under the
6853control of Guix is that it supports transactional system upgrades, and
1068f26b 6854makes it possible to roll back to a previous system instantiation,
cf4a9129 6855should something go wrong with the new one (@pxref{Features}). Another
1068f26b 6856advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
6857across different machines, or at different points in time, without
6858having to resort to additional administration tools layered on top of
1068f26b 6859the own tools of the system.
cf4a9129 6860@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 6861
cf4a9129
LC
6862This section describes this mechanism. First we focus on the system
6863administrator's viewpoint---explaining how the system is configured and
6864instantiated. Then we show how this mechanism can be extended, for
6865instance to support new system services.
91ef73d4 6866
cf4a9129
LC
6867@menu
6868* Using the Configuration System:: Customizing your GNU system.
7313a52e 6869* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 6870* File Systems:: Configuring file system mounts.
510f9d86 6871* Mapped Devices:: Block device extra processing.
cf4a9129 6872* User Accounts:: Specifying user accounts.
598e19dc 6873* Locales:: Language and cultural convention settings.
cf4a9129 6874* Services:: Specifying system services.
0ae8c15a 6875* Setuid Programs:: Programs running with root privileges.
efb5e833 6876* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 6877* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 6878* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 6879* GRUB Configuration:: Configuring the boot loader.
cf4a9129 6880* Invoking guix system:: Instantiating a system configuration.
97d76250 6881* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
6882* Defining Services:: Adding new service definitions.
6883@end menu
91ef73d4 6884
cf4a9129
LC
6885@node Using the Configuration System
6886@subsection Using the Configuration System
64d76fa6 6887
cf4a9129
LC
6888The operating system is configured by providing an
6889@code{operating-system} declaration in a file that can then be passed to
6890the @command{guix system} command (@pxref{Invoking guix system}). A
6891simple setup, with the default system services, the default Linux-Libre
6892kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 6893
cf4a9129
LC
6894@findex operating-system
6895@lisp
dd51caac 6896@include os-config-bare-bones.texi
cf4a9129 6897@end lisp
401c53c4 6898
cf4a9129
LC
6899This example should be self-describing. Some of the fields defined
6900above, such as @code{host-name} and @code{bootloader}, are mandatory.
6901Others, such as @code{packages} and @code{services}, can be omitted, in
6902which case they get a default value.
e7f34eb0 6903
5d94ac51
LC
6904Below we discuss the effect of some of the most important fields
6905(@pxref{operating-system Reference}, for details about all the available
6906fields), and how to @dfn{instantiate} the operating system using
6907@command{guix system}.
6908
6909@unnumberedsubsubsec Globally-Visible Packages
6910
cf4a9129 6911@vindex %base-packages
5d94ac51
LC
6912The @code{packages} field lists packages that will be globally visible
6913on the system, for all user accounts---i.e., in every user's @code{PATH}
6914environment variable---in addition to the per-user profiles
6915(@pxref{Invoking guix package}). The @var{%base-packages} variable
6916provides all the tools one would expect for basic user and administrator
6917tasks---including the GNU Core Utilities, the GNU Networking Utilities,
6918the GNU Zile lightweight text editor, @command{find}, @command{grep},
6919etc. The example above adds tcpdump to those, taken from the @code{(gnu
6920packages admin)} module (@pxref{Package Modules}).
e7f34eb0 6921
f6c9fb1b
LC
6922@findex specification->package
6923Referring to packages by variable name, like @var{tcpdump} above, has
6924the advantage of being unambiguous; it also allows typos and such to be
6925diagnosed right away as ``unbound variables''. The downside is that one
6926needs to know which module defines which package, and to augment the
6927@code{use-package-modules} line accordingly. To avoid that, one can use
6928the @code{specification->package} procedure of the @code{(gnu packages)}
6929module, which returns the best package for a given name or name and
6930version:
6931
6932@lisp
6933(use-modules (gnu packages))
6934
6935(operating-system
6936 ;; ...
6937 (packages (append (map specification->package
d5e59248 6938 '("tcpdump" "htop" "gnupg@@2.0"))
f6c9fb1b
LC
6939 %base-packages)))
6940@end lisp
6941
5d94ac51
LC
6942@unnumberedsubsubsec System Services
6943
e32171ee 6944@cindex services
cf4a9129
LC
6945@vindex %base-services
6946The @code{services} field lists @dfn{system services} to be made
6947available when the system starts (@pxref{Services}).
6948The @code{operating-system} declaration above specifies that, in
6949addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
6950daemon listening on port 2222 (@pxref{Networking Services,
6951@code{lsh-service}}). Under the hood,
cf4a9129
LC
6952@code{lsh-service} arranges so that @code{lshd} is started with the
6953right command-line options, possibly with supporting configuration files
cd6f6c22
LC
6954generated as needed (@pxref{Defining Services}).
6955
6956@cindex customization, of services
6957@findex modify-services
6958Occasionally, instead of using the base services as is, you will want to
4d343a14
CM
6959customize them. To do this, use @code{modify-services} (@pxref{Service
6960Reference, @code{modify-services}}) to modify the list.
6961
6962For example, suppose you want to modify @code{guix-daemon} and Mingetty
6963(the console log-in) in the @var{%base-services} list (@pxref{Base
6964Services, @code{%base-services}}). To do that, you can write the
6965following in your operating system declaration:
cd6f6c22
LC
6966
6967@lisp
4d343a14
CM
6968(define %my-services
6969 ;; My very own list of services.
6970 (modify-services %base-services
6971 (guix-service-type config =>
6972 (guix-configuration
6973 (inherit config)
6974 (use-substitutes? #f)
6975 (extra-options '("--gc-keep-derivations"))))
6976 (mingetty-service-type config =>
6977 (mingetty-configuration
317d3b47 6978 (inherit config)))))
4d343a14
CM
6979
6980(operating-system
6981 ;; @dots{}
6982 (services %my-services))
cd6f6c22
LC
6983@end lisp
6984
4d343a14
CM
6985This changes the configuration---i.e., the service parameters---of the
6986@code{guix-service-type} instance, and that of all the
6987@code{mingetty-service-type} instances in the @var{%base-services} list.
6988Observe how this is accomplished: first, we arrange for the original
6989configuration to be bound to the identifier @code{config} in the
6990@var{body}, and then we write the @var{body} so that it evaluates to the
6991desired configuration. In particular, notice how we use @code{inherit}
6992to create a new configuration which has the same values as the old
6993configuration, but with a few modifications.
a1ba8475 6994
dd51caac 6995The configuration for a typical ``desktop'' usage, with the X11 display
d038b674
LC
6996server, GNOME and Xfce (users can choose which of these desktop
6997environments to use at the log-in screen by pressing @kbd{F1}), network
6998management, power management, and more, would look like this:
dd51caac
LC
6999
7000@lisp
7001@include os-config-desktop.texi
7002@end lisp
7003
d038b674
LC
7004A graphical environment with a choice of lightweight window managers
7005instead of full-blown desktop environments would look like this:
7006
7007@lisp
7008@include os-config-lightweight-desktop.texi
7009@end lisp
7010
dd51caac 7011@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
7012@var{%desktop-services}. @xref{X.509 Certificates}, for background
7013information about the @code{nss-certs} package that is used here.
dd51caac 7014
5d94ac51
LC
7015Again, @var{%desktop-services} is just a list of service objects. If
7016you want to remove services from there, you can do so using the
7017procedures for list filtering (@pxref{SRFI-1 Filtering and
7018Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
7019following expression returns a list that contains all the services in
7020@var{%desktop-services} minus the Avahi service:
7021
7022@example
7023(remove (lambda (service)
7024 (eq? (service-kind service) avahi-service-type))
7025 %desktop-services)
7026@end example
7027
7028@unnumberedsubsubsec Instantiating the System
7029
7030Assuming the @code{operating-system} declaration
7031is stored in the @file{my-system-config.scm}
cf4a9129
LC
7032file, the @command{guix system reconfigure my-system-config.scm} command
7033instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
7034entry (@pxref{Invoking guix system}).
7035
1068f26b 7036The normal way to change the system configuration is by updating this
65797bff
LC
7037file and re-running @command{guix system reconfigure}. One should never
7038have to touch files in @command{/etc} or to run commands that modify the
7039system state such as @command{useradd} or @command{grub-install}. In
7040fact, you must avoid that since that would not only void your warranty
7041but also prevent you from rolling back to previous versions of your
7042system, should you ever need to.
7043
7044@cindex roll-back, of the operating system
7045Speaking of roll-back, each time you run @command{guix system
7046reconfigure}, a new @dfn{generation} of the system is created---without
7047modifying or deleting previous generations. Old system generations get
7048an entry in the GRUB boot menu, allowing you to boot them in case
7049something went wrong with the latest generation. Reassuring, no? The
7050@command{guix system list-generations} command lists the system
7051generations available on disk.
b81e1947 7052
5d94ac51
LC
7053@unnumberedsubsubsec The Programming Interface
7054
cf4a9129
LC
7055At the Scheme level, the bulk of an @code{operating-system} declaration
7056is instantiated with the following monadic procedure (@pxref{The Store
7057Monad}):
b81e1947 7058
cf4a9129
LC
7059@deffn {Monadic Procedure} operating-system-derivation os
7060Return a derivation that builds @var{os}, an @code{operating-system}
7061object (@pxref{Derivations}).
b81e1947 7062
cf4a9129
LC
7063The output of the derivation is a single directory that refers to all
7064the packages, configuration files, and other supporting files needed to
7065instantiate @var{os}.
7066@end deffn
b81e1947 7067
5d94ac51
LC
7068This procedure is provided by the @code{(gnu system)} module. Along
7069with @code{(gnu services)} (@pxref{Services}), this module contains the
7070guts of GuixSD. Make sure to visit it!
7071
7072
7313a52e
LC
7073@node operating-system Reference
7074@subsection @code{operating-system} Reference
7075
7076This section summarizes all the options available in
7077@code{operating-system} declarations (@pxref{Using the Configuration
7078System}).
7079
7080@deftp {Data Type} operating-system
7081This is the data type representing an operating system configuration.
7082By that, we mean all the global system configuration, not per-user
7083configuration (@pxref{Using the Configuration System}).
7084
7085@table @asis
7086@item @code{kernel} (default: @var{linux-libre})
fbb25e56 7087The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
7088only the Linux-libre kernel is supported. In the future, it will be
7089possible to use the GNU@tie{}Hurd.}.
7090
ee2a6304
LC
7091@item @code{kernel-arguments} (default: @code{'()})
7092List of strings or gexps representing additional arguments to pass on
1068f26b 7093the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 7094
7313a52e 7095@item @code{bootloader}
88faf933 7096The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
7097
7098@item @code{initrd} (default: @code{base-initrd})
e32171ee
JD
7099@cindex initrd
7100@cindex initial RAM disk
7313a52e
LC
7101A two-argument monadic procedure that returns an initial RAM disk for
7102the Linux kernel. @xref{Initial RAM Disk}.
7103
f34c56be
LC
7104@item @code{firmware} (default: @var{%base-firmware})
7105@cindex firmware
7106List of firmware packages loadable by the operating system kernel.
7107
52db41af
EB
7108The default includes firmware needed for Atheros- and Broadcom-based
7109WiFi devices (Linux-libre modules @code{ath9k} and @code{b43-open},
7110respectively). @xref{Hardware Considerations}, for more info on
7111supported hardware.
f34c56be 7112
7313a52e
LC
7113@item @code{host-name}
7114The host name.
7115
7116@item @code{hosts-file}
7117@cindex hosts file
24e02c28 7118A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 7119@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 7120Reference Manual}). The default is a file with entries for
7313a52e
LC
7121@code{localhost} and @var{host-name}.
7122
7123@item @code{mapped-devices} (default: @code{'()})
7124A list of mapped devices. @xref{Mapped Devices}.
7125
7126@item @code{file-systems}
7127A list of file systems. @xref{File Systems}.
7128
7129@item @code{swap-devices} (default: @code{'()})
7130@cindex swap devices
7131A list of strings identifying devices to be used for ``swap space''
7132(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
7133For example, @code{'("/dev/sda3")}.
7134
bf87f38a 7135@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
7136@itemx @code{groups} (default: @var{%base-groups})
7137List of user accounts and groups. @xref{User Accounts}.
7138
7139@item @code{skeletons} (default: @code{(default-skeletons)})
e9dffec1
LC
7140A list target file name/file-like object tuples (@pxref{G-Expressions,
7141file-like objects}). These are the skeleton files that will be added to
7142the home directory of newly-created user accounts.
7313a52e
LC
7143
7144For instance, a valid value may look like this:
7145
7146@example
e9dffec1
LC
7147`((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
7148 (".guile" ,(plain-file "guile"
7149 "(use-modules (ice-9 readline))
7150 (activate-readline)")))
7313a52e
LC
7151@end example
7152
7153@item @code{issue} (default: @var{%default-issue})
7154A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 7155displayed when users log in on a text console.
7313a52e
LC
7156
7157@item @code{packages} (default: @var{%base-packages})
7158The set of packages installed in the global profile, which is accessible
7159at @file{/run/current-system/profile}.
7160
1068f26b 7161The default set includes core utilities and it is good practice to
7313a52e
LC
7162install non-core utilities in user profiles (@pxref{Invoking guix
7163package}).
7164
7165@item @code{timezone}
7166A timezone identifying string---e.g., @code{"Europe/Paris"}.
7167
17c20385
LC
7168You can run the @command{tzselect} command to find out which timezone
7169string corresponds to your region. Choosing an invalid timezone name
7170causes @command{guix system} to fail.
7171
598e19dc
LC
7172@item @code{locale} (default: @code{"en_US.utf8"})
7173The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
7174Library Reference Manual}). @xref{Locales}, for more information.
7175
7176@item @code{locale-definitions} (default: @var{%default-locale-definitions})
7177The list of locale definitions to be compiled and that may be used at
7178run time. @xref{Locales}.
7313a52e 7179
34760ae7
LC
7180@item @code{locale-libcs} (default: @code{(list @var{glibc})})
7181The list of GNU@tie{}libc packages whose locale data and tools are used
7182to build the locale definitions. @xref{Locales}, for compatibility
7183considerations that justify this option.
7184
996ed739 7185@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 7186Configuration of the libc name service switch (NSS)---a
996ed739
LC
7187@code{<name-service-switch>} object. @xref{Name Service Switch}, for
7188details.
7189
7313a52e 7190@item @code{services} (default: @var{%base-services})
28d939af 7191A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
7192
7193@item @code{pam-services} (default: @code{(base-pam-services)})
7194@cindex PAM
7195@cindex pluggable authentication modules
7196Linux @dfn{pluggable authentication module} (PAM) services.
7197@c FIXME: Add xref to PAM services section.
7198
7199@item @code{setuid-programs} (default: @var{%setuid-programs})
7200List of string-valued G-expressions denoting setuid programs.
7201@xref{Setuid Programs}.
7202
f5a9ffa0
AK
7203@item @code{sudoers-file} (default: @var{%sudoers-specification})
7204@cindex sudoers file
84765839
LC
7205The contents of the @file{/etc/sudoers} file as a file-like object
7206(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
7207
7208This file specifies which users can use the @command{sudo} command, what
7209they are allowed to do, and what privileges they may gain. The default
7210is that only @code{root} and members of the @code{wheel} group may use
7211@code{sudo}.
7212
7213@end table
7214@end deftp
7215
cf4a9129
LC
7216@node File Systems
7217@subsection File Systems
b81e1947 7218
cf4a9129 7219The list of file systems to be mounted is specified in the
1068f26b 7220@code{file-systems} field of the operating system declaration
cf4a9129
LC
7221(@pxref{Using the Configuration System}). Each file system is declared
7222using the @code{file-system} form, like this:
b81e1947
LC
7223
7224@example
cf4a9129
LC
7225(file-system
7226 (mount-point "/home")
7227 (device "/dev/sda3")
7228 (type "ext4"))
b81e1947
LC
7229@end example
7230
cf4a9129
LC
7231As usual, some of the fields are mandatory---those shown in the example
7232above---while others can be omitted. These are described below.
b81e1947 7233
cf4a9129
LC
7234@deftp {Data Type} file-system
7235Objects of this type represent file systems to be mounted. They
7236contain the following members:
5ff3c4b8 7237
cf4a9129
LC
7238@table @asis
7239@item @code{type}
7240This is a string specifying the type of the file system---e.g.,
7241@code{"ext4"}.
5ff3c4b8 7242
cf4a9129
LC
7243@item @code{mount-point}
7244This designates the place where the file system is to be mounted.
b81e1947 7245
cf4a9129
LC
7246@item @code{device}
7247This names the ``source'' of the file system. By default it is the name
7248of a node under @file{/dev}, but its meaning depends on the @code{title}
7249field described below.
401c53c4 7250
cf4a9129
LC
7251@item @code{title} (default: @code{'device})
7252This is a symbol that specifies how the @code{device} field is to be
7253interpreted.
401c53c4 7254
cf4a9129
LC
7255When it is the symbol @code{device}, then the @code{device} field is
7256interpreted as a file name; when it is @code{label}, then @code{device}
7257is interpreted as a partition label name; when it is @code{uuid},
7258@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 7259
661a1d79 7260UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
7261@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
7262@code{uuid} form expects 16-byte UUIDs as defined in
7263@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
7264form of UUID used by the ext2 family of file systems and others, but it
7265is different from ``UUIDs'' found in FAT file systems, for instance.},
7266like this:
661a1d79
LC
7267
7268@example
7269(file-system
7270 (mount-point "/home")
7271 (type "ext4")
7272 (title 'uuid)
7273 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
7274@end example
7275
cf4a9129 7276The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
7277partitions without having to hard-code their actual device
7278name@footnote{Note that, while it is tempting to use
7279@file{/dev/disk/by-uuid} and similar device names to achieve the same
7280result, this is not recommended: These special device nodes are created
7281by the udev daemon and may be unavailable at the time the device is
7282mounted.}.
da7cabd4 7283
1068f26b 7284However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
7285Devices}), its @code{device} field @emph{must} refer to the mapped
7286device name---e.g., @file{/dev/mapper/root-partition}---and consequently
7287@code{title} must be set to @code{'device}. This is required so that
7288the system knows that mounting the file system depends on having the
7289corresponding device mapping established.
7290
cf4a9129
LC
7291@item @code{flags} (default: @code{'()})
7292This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
7293include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
7294access to special files), @code{no-suid} (ignore setuid and setgid
7295bits), and @code{no-exec} (disallow program execution.)
da7cabd4 7296
cf4a9129
LC
7297@item @code{options} (default: @code{#f})
7298This is either @code{#f}, or a string denoting mount options.
da7cabd4 7299
be21979d
LC
7300@item @code{mount?} (default: @code{#t})
7301This value indicates whether to automatically mount the file system when
7302the system is brought up. When set to @code{#f}, the file system gets
7303an entry in @file{/etc/fstab} (read by the @command{mount} command) but
7304is not automatically mounted.
7305
cf4a9129
LC
7306@item @code{needed-for-boot?} (default: @code{#f})
7307This Boolean value indicates whether the file system is needed when
7308booting. If that is true, then the file system is mounted when the
7309initial RAM disk (initrd) is loaded. This is always the case, for
7310instance, for the root file system.
da7cabd4 7311
cf4a9129
LC
7312@item @code{check?} (default: @code{#t})
7313This Boolean indicates whether the file system needs to be checked for
7314errors before being mounted.
f9cc8971 7315
4e469051
LC
7316@item @code{create-mount-point?} (default: @code{#f})
7317When true, the mount point is created if it does not exist yet.
7318
e51710d1
LC
7319@item @code{dependencies} (default: @code{'()})
7320This is a list of @code{<file-system>} objects representing file systems
7321that must be mounted before (and unmounted after) this one.
7322
7323As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
7324a dependency of @file{/sys/fs/cgroup/cpu} and
7325@file{/sys/fs/cgroup/memory}.
7326
cf4a9129
LC
7327@end table
7328@end deftp
da7cabd4 7329
a69576ea
LC
7330The @code{(gnu system file-systems)} exports the following useful
7331variables.
7332
7333@defvr {Scheme Variable} %base-file-systems
7334These are essential file systems that are required on normal systems,
cc0e575a 7335such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
7336below.) Operating system declarations should always contain at least
7337these.
a69576ea
LC
7338@end defvr
7339
7f239fd3
LC
7340@defvr {Scheme Variable} %pseudo-terminal-file-system
7341This is the file system to be mounted as @file{/dev/pts}. It supports
7342@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
7343functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
7344Manual}). Pseudo-terminals are used by terminal emulators such as
7345@command{xterm}.
7346@end defvr
7347
db17ae5c
LC
7348@defvr {Scheme Variable} %shared-memory-file-system
7349This file system is mounted as @file{/dev/shm} and is used to support
7350memory sharing across processes (@pxref{Memory-mapped I/O,
7351@code{shm_open},, libc, The GNU C Library Reference Manual}).
7352@end defvr
7353
3392ce5d
LC
7354@defvr {Scheme Variable} %immutable-store
7355This file system performs a read-only ``bind mount'' of
7356@file{/gnu/store}, making it read-only for all the users including
7357@code{root}. This prevents against accidental modification by software
7358running as @code{root} or by system administrators.
7359
7360The daemon itself is still able to write to the store: it remounts it
7361read-write in its own ``name space.''
7362@end defvr
7363
a69576ea
LC
7364@defvr {Scheme Variable} %binary-format-file-system
7365The @code{binfmt_misc} file system, which allows handling of arbitrary
7366executable file types to be delegated to user space. This requires the
7367@code{binfmt.ko} kernel module to be loaded.
7368@end defvr
7369
7370@defvr {Scheme Variable} %fuse-control-file-system
7371The @code{fusectl} file system, which allows unprivileged users to mount
7372and unmount user-space FUSE file systems. This requires the
7373@code{fuse.ko} kernel module to be loaded.
7374@end defvr
7375
510f9d86
LC
7376@node Mapped Devices
7377@subsection Mapped Devices
7378
7379@cindex device mapping
7380@cindex mapped devices
7381The Linux kernel has a notion of @dfn{device mapping}: a block device,
7382such as a hard disk partition, can be @dfn{mapped} into another device,
97c8aef1 7383usually in @code{/dev/mapper/},
510f9d86
LC
7384with additional processing over the data that flows through
7385it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
7386concept of a ``mapped device'' and that of a file system: both boil down
7387to @emph{translating} input/output operations made on a file to
7388operations on its backing store. Thus, the Hurd implements mapped
7389devices, like file systems, using the generic @dfn{translator} mechanism
7390(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
7391typical example is encryption device mapping: all writes to the mapped
7392device are encrypted, and all reads are deciphered, transparently.
97c8aef1
AE
7393Guix extends this notion by considering any device or set of devices that
7394are @dfn{transformed} in some way to create a new device; for instance,
7395RAID devices are obtained by @dfn{assembling} several other devices, such
7396as hard disks or partitions, into a new one that behaves as one partition.
7397Other examples, not yet implemented, are LVM logical volumes.
510f9d86 7398
97c8aef1
AE
7399Mapped devices are declared using the @code{mapped-device} form,
7400defined as follows; for examples, see below.
510f9d86
LC
7401
7402@deftp {Data Type} mapped-device
7403Objects of this type represent device mappings that will be made when
7404the system boots up.
7405
9cb426b8
LC
7406@table @code
7407@item source
97c8aef1
AE
7408This is either a string specifying the name of the block device to be mapped,
7409such as @code{"/dev/sda3"}, or a list of such strings when several devices
7410need to be assembled for creating a new one.
510f9d86 7411
9cb426b8 7412@item target
97c8aef1
AE
7413This string specifies the name of the resulting mapped device. For
7414kernel mappers such as encrypted devices of type @code{luks-device-mapping},
7415specifying @code{"my-partition"} leads to the creation of
510f9d86 7416the @code{"/dev/mapper/my-partition"} device.
97c8aef1
AE
7417For RAID devices of type @code{raid-device-mapping}, the full device name
7418such as @code{"/dev/md0"} needs to be given.
510f9d86 7419
9cb426b8 7420@item type
510f9d86
LC
7421This must be a @code{mapped-device-kind} object, which specifies how
7422@var{source} is mapped to @var{target}.
7423@end table
7424@end deftp
7425
7426@defvr {Scheme Variable} luks-device-mapping
7427This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 7428command from the package with the same name. It relies on the
510f9d86
LC
7429@code{dm-crypt} Linux kernel module.
7430@end defvr
7431
97c8aef1
AE
7432@defvr {Scheme Variable} raid-device-mapping
7433This defines a RAID device, which is assembled using the @code{mdadm}
7434command from the package with the same name. It requires a Linux kernel
7435module for the appropriate RAID level to be loaded, such as @code{raid456}
7436for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
7437@end defvr
7438
7439@cindex disk encryption
7440@cindex LUKS
7441The following example specifies a mapping from @file{/dev/sda3} to
7442@file{/dev/mapper/home} using LUKS---the
7443@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
7444standard mechanism for disk encryption.
7445The @file{/dev/mapper/home}
7446device can then be used as the @code{device} of a @code{file-system}
7447declaration (@pxref{File Systems}).
7448
7449@example
7450(mapped-device
7451 (source "/dev/sda3")
7452 (target "home")
7453 (type luks-device-mapping))
7454@end example
7455
7456Alternatively, to become independent of device numbering, one may obtain
7457the LUKS UUID (@dfn{unique identifier}) of the source device by a
7458command like:
7459
7460@example
7461cryptsetup luksUUID /dev/sda3
7462@end example
7463
7464and use it as follows:
7465
7466@example
7467(mapped-device
7468 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
7469 (target "home")
7470 (type luks-device-mapping))
7471@end example
7472
7473A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1}
7474may be declared as follows:
7475
7476@example
7477(mapped-device
7478 (source (list "/dev/sda1" "/dev/sdb1"))
7479 (target "/dev/md0")
7480 (type raid-device-mapping))
7481@end example
7482
7483The @file{/dev/md0} device can then be used as the @code{device} of a
7484@code{file-system} declaration (@pxref{File Systems}).
7485Note that the RAID level need not be given; it is chosen during the
7486initial creation and formatting of the RAID device and is determined
7487automatically later.
7488
7489
cf4a9129
LC
7490@node User Accounts
7491@subsection User Accounts
ee85f3db 7492
e32171ee
JD
7493@cindex users
7494@cindex accounts
7495@cindex user accounts
9bea87a5
LC
7496User accounts and groups are entirely managed through the
7497@code{operating-system} declaration. They are specified with the
7498@code{user-account} and @code{user-group} forms:
ee85f3db 7499
cf4a9129
LC
7500@example
7501(user-account
7502 (name "alice")
7503 (group "users")
24e752c0
LC
7504 (supplementary-groups '("wheel" ;allow use of sudo, etc.
7505 "audio" ;sound card
7506 "video" ;video devices such as webcams
7507 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
7508 (comment "Bob's sister")
7509 (home-directory "/home/alice"))
7510@end example
25083588 7511
9bea87a5
LC
7512When booting or upon completion of @command{guix system reconfigure},
7513the system ensures that only the user accounts and groups specified in
7514the @code{operating-system} declaration exist, and with the specified
7515properties. Thus, account or group creations or modifications made by
7516directly invoking commands such as @command{useradd} are lost upon
7517reconfiguration or reboot. This ensures that the system remains exactly
7518as declared.
7519
cf4a9129
LC
7520@deftp {Data Type} user-account
7521Objects of this type represent user accounts. The following members may
7522be specified:
ee85f3db 7523
cf4a9129
LC
7524@table @asis
7525@item @code{name}
7526The name of the user account.
ee85f3db 7527
cf4a9129 7528@item @code{group}
e32171ee 7529@cindex groups
cf4a9129
LC
7530This is the name (a string) or identifier (a number) of the user group
7531this account belongs to.
ee85f3db 7532
cf4a9129
LC
7533@item @code{supplementary-groups} (default: @code{'()})
7534Optionally, this can be defined as a list of group names that this
7535account belongs to.
ee85f3db 7536
cf4a9129
LC
7537@item @code{uid} (default: @code{#f})
7538This is the user ID for this account (a number), or @code{#f}. In the
7539latter case, a number is automatically chosen by the system when the
7540account is created.
ee85f3db 7541
cf4a9129 7542@item @code{comment} (default: @code{""})
1068f26b 7543A comment about the account, such as the account owner's full name.
c8c871d1 7544
cf4a9129
LC
7545@item @code{home-directory}
7546This is the name of the home directory for the account.
ee85f3db 7547
eb56ee02
LC
7548@item @code{create-home-directory?} (default: @code{#t})
7549Indicates whether the home directory of this account should be created
7550if it does not exist yet.
7551
cf4a9129
LC
7552@item @code{shell} (default: Bash)
7553This is a G-expression denoting the file name of a program to be used as
7554the shell (@pxref{G-Expressions}).
ee85f3db 7555
cf4a9129
LC
7556@item @code{system?} (default: @code{#f})
7557This Boolean value indicates whether the account is a ``system''
7558account. System accounts are sometimes treated specially; for instance,
7559graphical login managers do not list them.
ee85f3db 7560
1bd4e6db 7561@anchor{user-account-password}
cf4a9129 7562@item @code{password} (default: @code{#f})
eb59595c
LC
7563You would normally leave this field to @code{#f}, initialize user
7564passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
7565users change it with @command{passwd}. Passwords set with
7566@command{passwd} are of course preserved across reboot and
7567reconfiguration.
eb59595c
LC
7568
7569If you @emph{do} want to have a preset password for an account, then
7570this field must contain the encrypted password, as a string.
5d1f1177
LC
7571@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
7572on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 7573Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 7574
cf4a9129
LC
7575@end table
7576@end deftp
ee85f3db 7577
e32171ee 7578@cindex groups
cf4a9129 7579User group declarations are even simpler:
ee85f3db 7580
cf4a9129
LC
7581@example
7582(user-group (name "students"))
7583@end example
ee85f3db 7584
cf4a9129
LC
7585@deftp {Data Type} user-group
7586This type is for, well, user groups. There are just a few fields:
af8a56b8 7587
cf4a9129
LC
7588@table @asis
7589@item @code{name}
1068f26b 7590The name of the group.
ee85f3db 7591
cf4a9129
LC
7592@item @code{id} (default: @code{#f})
7593The group identifier (a number). If @code{#f}, a new number is
7594automatically allocated when the group is created.
ee85f3db 7595
c8fa3426
LC
7596@item @code{system?} (default: @code{#f})
7597This Boolean value indicates whether the group is a ``system'' group.
7598System groups have low numerical IDs.
7599
cf4a9129
LC
7600@item @code{password} (default: @code{#f})
7601What, user groups can have a password? Well, apparently yes. Unless
1068f26b 7602@code{#f}, this field specifies the password of the group.
ee85f3db 7603
cf4a9129
LC
7604@end table
7605@end deftp
401c53c4 7606
cf4a9129
LC
7607For convenience, a variable lists all the basic user groups one may
7608expect:
401c53c4 7609
cf4a9129
LC
7610@defvr {Scheme Variable} %base-groups
7611This is the list of basic user groups that users and/or packages expect
7612to be present on the system. This includes groups such as ``root'',
7613``wheel'', and ``users'', as well as groups used to control access to
7614specific devices such as ``audio'', ``disk'', and ``cdrom''.
7615@end defvr
401c53c4 7616
bf87f38a
LC
7617@defvr {Scheme Variable} %base-user-accounts
7618This is the list of basic system accounts that programs may expect to
7619find on a GNU/Linux system, such as the ``nobody'' account.
7620
7621Note that the ``root'' account is not included here. It is a
7622special-case and is automatically added whether or not it is specified.
7623@end defvr
7624
598e19dc
LC
7625@node Locales
7626@subsection Locales
7627
7628@cindex locale
7629A @dfn{locale} defines cultural conventions for a particular language
7630and region of the world (@pxref{Locales,,, libc, The GNU C Library
7631Reference Manual}). Each locale has a name that typically has the form
b2636518 7632@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
7633@code{fr_LU.utf8} designates the locale for the French language, with
7634cultural conventions from Luxembourg, and using the UTF-8 encoding.
7635
7636@cindex locale definition
7637Usually, you will want to specify the default locale for the machine
7638using the @code{locale} field of the @code{operating-system} declaration
7639(@pxref{operating-system Reference, @code{locale}}).
7640
f5582b2c
LC
7641The selected locale is automatically added to the @dfn{locale
7642definitions} known to the system if needed, with its codeset inferred
7643from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
7644@code{UTF-8} codeset. Additional locale definitions can be specified in
7645the @code{locale-definitions} slot of @code{operating-system}---this is
7646useful, for instance, if the codeset could not be inferred from the
7647locale name. The default set of locale definitions includes some widely
7648used locales, but not all the available locales, in order to save space.
7649
7650For instance, to add the North Frisian locale for Germany, the value of
7651that field may be:
598e19dc
LC
7652
7653@example
7654(cons (locale-definition
7655 (name "fy_DE.utf8") (source "fy_DE"))
7656 %default-locale-definitions)
7657@end example
7658
7659Likewise, to save space, one might want @code{locale-definitions} to
7660list only the locales that are actually used, as in:
7661
7662@example
7663(list (locale-definition
7664 (name "ja_JP.eucjp") (source "ja_JP")
7665 (charset "EUC-JP")))
7666@end example
7667
5c3c1427
LC
7668@vindex LOCPATH
7669The compiled locale definitions are available at
46bd6edd
LC
7670@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
7671version, which is the default location where the GNU@tie{}libc provided
7672by Guix looks for locale data. This can be overridden using the
7673@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
7674@code{LOCPATH} and locale packages}).
7675
598e19dc
LC
7676The @code{locale-definition} form is provided by the @code{(gnu system
7677locale)} module. Details are given below.
7678
7679@deftp {Data Type} locale-definition
7680This is the data type of a locale definition.
7681
7682@table @asis
7683
7684@item @code{name}
7685The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
7686Reference Manual}, for more information on locale names.
7687
7688@item @code{source}
7689The name of the source for that locale. This is typically the
7690@code{@var{language}_@var{territory}} part of the locale name.
7691
7692@item @code{charset} (default: @code{"UTF-8"})
7693The ``character set'' or ``code set'' for that locale,
7694@uref{http://www.iana.org/assignments/character-sets, as defined by
7695IANA}.
7696
7697@end table
7698@end deftp
7699
7700@defvr {Scheme Variable} %default-locale-definitions
1068f26b 7701A list of commonly used UTF-8 locales, used as the default
b2636518 7702value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 7703declarations.
b2636518
LC
7704
7705@cindex locale name
7706@cindex normalized codeset in locale names
7707These locale definitions use the @dfn{normalized codeset} for the part
7708that follows the dot in the name (@pxref{Using gettextized software,
7709normalized codeset,, libc, The GNU C Library Reference Manual}). So for
7710instance it has @code{uk_UA.utf8} but @emph{not}, say,
7711@code{uk_UA.UTF-8}.
598e19dc 7712@end defvr
401c53c4 7713
34760ae7
LC
7714@subsubsection Locale Data Compatibility Considerations
7715
7716@cindex incompatibility, of locale data
7717@code{operating-system} declarations provide a @code{locale-libcs} field
7718to specify the GNU@tie{}libc packages that are used to compile locale
7719declarations (@pxref{operating-system Reference}). ``Why would I
7720care?'', you may ask. Well, it turns out that the binary format of
7721locale data is occasionally incompatible from one libc version to
7722another.
7723
7724@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
7725@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
7726For instance, a program linked against libc version 2.21 is unable to
7727read locale data produced with libc 2.22; worse, that program
7728@emph{aborts} instead of simply ignoring the incompatible locale
7729data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
7730the incompatible locale data, which is already an improvement.}.
7731Similarly, a program linked against libc 2.22 can read most, but not
201fff9e 7732all, of the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
34760ae7
LC
7733data is incompatible); thus calls to @code{setlocale} may fail, but
7734programs will not abort.
7735
7736The ``problem'' in GuixSD is that users have a lot of freedom: They can
7737choose whether and when to upgrade software in their profiles, and might
7738be using a libc version different from the one the system administrator
7739used to build the system-wide locale data.
7740
7741Fortunately, unprivileged users can also install their own locale data
7742and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
7743@code{GUIX_LOCPATH} and locale packages}).
7744
7745Still, it is best if the system-wide locale data at
7746@file{/run/current-system/locale} is built for all the libc versions
7747actually in use on the system, so that all the programs can access
7748it---this is especially crucial on a multi-user system. To do that, the
7749administrator can specify several libc packages in the
7750@code{locale-libcs} field of @code{operating-system}:
7751
7752@example
7753(use-package-modules base)
7754
7755(operating-system
7756 ;; @dots{}
7757 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
7758@end example
7759
7760This example would lead to a system containing locale definitions for
7761both libc 2.21 and the current version of libc in
7762@file{/run/current-system/locale}.
7763
7764
cf4a9129
LC
7765@node Services
7766@subsection Services
401c53c4 7767
cf4a9129
LC
7768@cindex system services
7769An important part of preparing an @code{operating-system} declaration is
7770listing @dfn{system services} and their configuration (@pxref{Using the
7771Configuration System}). System services are typically daemons launched
7772when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
7773configuring network access.
7774
e8b652d4
LC
7775GuixSD has a broad definition of ``service'' (@pxref{Service
7776Composition}), but many services are managed by the GNU@tie{}Shepherd
7777(@pxref{Shepherd Services}). On a running system, the @command{herd}
7778command allows you to list the available services, show their status,
7779start and stop them, or do other specific operations (@pxref{Jump
7780Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
7781
7782@example
dd17bc38 7783# herd status
d8b94dbd
LC
7784@end example
7785
7786The above command, run as @code{root}, lists the currently defined
dd17bc38 7787services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
7788service:
7789
7790@example
dd17bc38 7791# herd doc nscd
d8b94dbd
LC
7792Run libc's name service cache daemon (nscd).
7793@end example
7794
7795The @command{start}, @command{stop}, and @command{restart} sub-commands
7796have the effect you would expect. For instance, the commands below stop
7797the nscd service and restart the Xorg display server:
7798
7799@example
dd17bc38 7800# herd stop nscd
d8b94dbd 7801Service nscd has been stopped.
dd17bc38 7802# herd restart xorg-server
d8b94dbd
LC
7803Service xorg-server has been stopped.
7804Service xorg-server has been started.
7805@end example
401c53c4 7806
cf4a9129 7807The following sections document the available services, starting with
d8b94dbd
LC
7808the core services, that may be used in an @code{operating-system}
7809declaration.
401c53c4 7810
cf4a9129
LC
7811@menu
7812* Base Services:: Essential system services.
c311089b 7813* Scheduled Job Execution:: The mcron service.
92c03a87 7814* Log Rotation:: The rottlog service.
cf4a9129
LC
7815* Networking Services:: Network setup, SSH daemon, etc.
7816* X Window:: Graphical display.
f2ec23d1 7817* Printing Services:: Local and remote printer support.
fe1a39d3 7818* Desktop Services:: D-Bus and desktop services.
105369a4 7819* Database Services:: SQL databases.
d8c18af8 7820* Mail Services:: IMAP, POP3, SMTP, and all that.
859e367d 7821* Kerberos Services:: Kerberos services.
58724c48 7822* Web Services:: Web servers.
eb419bc9 7823* Network File System:: NFS related services.
dbc6d370 7824* Miscellaneous Services:: Other services.
cf4a9129 7825@end menu
401c53c4 7826
cf4a9129
LC
7827@node Base Services
7828@subsubsection Base Services
a1ba8475 7829
cf4a9129
LC
7830The @code{(gnu services base)} module provides definitions for the basic
7831services that one expects from the system. The services exported by
7832this module are listed below.
401c53c4 7833
cf4a9129 7834@defvr {Scheme Variable} %base-services
31771497
LC
7835This variable contains a list of basic services (@pxref{Service Types
7836and Services}, for more information on service objects) one would
cf4a9129 7837expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 7838the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 7839more.
401c53c4 7840
cf4a9129
LC
7841This is the default value of the @code{services} field of
7842@code{operating-system} declarations. Usually, when customizing a
7843system, you will want to append services to @var{%base-services}, like
7844this:
401c53c4 7845
cf4a9129 7846@example
fa1e31b8 7847(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
7848@end example
7849@end defvr
401c53c4 7850
be1c2c54 7851@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
7852Return a service that sets the host name to @var{name}.
7853@end deffn
401c53c4 7854
317d3b47
DC
7855@deffn {Scheme Procedure} login-service @var{config}
7856Return a service to run login according to @var{config}, a
7857@code{<login-configuration>} object, which specifies the message of the day,
7858among other things.
7859@end deffn
7860
7861@deftp {Data Type} login-configuration
7862This is the data type representing the configuration of login.
7863
7864@table @asis
7865
7866@item @code{motd}
e32171ee 7867@cindex message of the day
317d3b47
DC
7868A file-like object containing the ``message of the day''.
7869
7870@item @code{allow-empty-passwords?} (default: @code{#t})
7871Allow empty passwords by default so that first-time users can log in when
7872the 'root' account has just been created.
7873
7874@end table
7875@end deftp
7876
66e4f01c
LC
7877@deffn {Scheme Procedure} mingetty-service @var{config}
7878Return a service to run mingetty according to @var{config}, a
7879@code{<mingetty-configuration>} object, which specifies the tty to run, among
7880other things.
cf4a9129 7881@end deffn
401c53c4 7882
66e4f01c
LC
7883@deftp {Data Type} mingetty-configuration
7884This is the data type representing the configuration of Mingetty, which
7885implements console log-in.
7886
7887@table @asis
7888
7889@item @code{tty}
7890The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
7891
66e4f01c
LC
7892@item @code{auto-login} (default: @code{#f})
7893When true, this field must be a string denoting the user name under
f9b9a033 7894which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
7895user name and password must be entered to log in.
7896
7897@item @code{login-program} (default: @code{#f})
7898This must be either @code{#f}, in which case the default log-in program
7899is used (@command{login} from the Shadow tool suite), or a gexp denoting
7900the name of the log-in program.
7901
7902@item @code{login-pause?} (default: @code{#f})
7903When set to @code{#t} in conjunction with @var{auto-login}, the user
7904will have to press a key before the log-in shell is launched.
7905
7906@item @code{mingetty} (default: @var{mingetty})
7907The Mingetty package to use.
7908
7909@end table
7910@end deftp
7911
46ec2707
DC
7912@deffn {Scheme Procedure} kmscon-service-type @var{config}
7913Return a service to run @uref{https://www.freedesktop.org/wiki/Software/kmscon,kmscon}
7914according to @var{config}, a @code{<kmscon-configuration>} object, which
7915specifies the tty to run, among other things.
7916@end deffn
7917
7918@deftp {Data Type} kmscon-configuration
7919This is the data type representing the configuration of Kmscon, which
7920implements console log-in.
7921
7922@table @asis
7923
7924@item @code{virtual-terminal}
7925The name of the console this Kmscon runs on---e.g., @code{"tty1"}.
7926
7927@item @code{login-program} (default: @code{#~(string-append #$shadow "/bin/login")})
7928A gexp denoting the name of the log-in program. The default log-in program is
7929@command{login} from the Shadow tool suite.
7930
7931@item @code{login-arguments} (default: @code{'("-p")})
7932A list of arguments to pass to @command{login}.
7933
7934@item @code{hardware-acceleration?} (default: #f)
7935Whether to use hardware acceleration.
7936
7937@item @code{kmscon} (default: @var{kmscon})
7938The Kmscon package to use.
7939
7940@end table
7941@end deftp
7942
6454b333
LC
7943@cindex name service cache daemon
7944@cindex nscd
be1c2c54 7945@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 7946 [#:name-services '()]
1068f26b 7947Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
7948given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
7949Service Switch}, for an example.
cf4a9129 7950@end deffn
401c53c4 7951
6454b333
LC
7952@defvr {Scheme Variable} %nscd-default-configuration
7953This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 7954by @code{nscd-service}. It uses the caches defined by
6454b333
LC
7955@var{%nscd-default-caches}; see below.
7956@end defvr
7957
7958@deftp {Data Type} nscd-configuration
1068f26b 7959This is the data type representing the name service cache daemon (nscd)
6454b333
LC
7960configuration.
7961
7962@table @asis
7963
b893f1ae
LC
7964@item @code{name-services} (default: @code{'()})
7965List of packages denoting @dfn{name services} that must be visible to
7966the nscd---e.g., @code{(list @var{nss-mdns})}.
7967
7968@item @code{glibc} (default: @var{glibc})
7969Package object denoting the GNU C Library providing the @command{nscd}
7970command.
7971
6454b333 7972@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 7973Name of the nscd log file. This is where debugging output goes when
6454b333
LC
7974@code{debug-level} is strictly positive.
7975
7976@item @code{debug-level} (default: @code{0})
1068f26b 7977Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
7978debugging output is logged.
7979
7980@item @code{caches} (default: @var{%nscd-default-caches})
7981List of @code{<nscd-cache>} objects denoting things to be cached; see
7982below.
7983
7984@end table
7985@end deftp
7986
7987@deftp {Data Type} nscd-cache
7988Data type representing a cache database of nscd and its parameters.
7989
7990@table @asis
7991
7992@item @code{database}
7993This is a symbol representing the name of the database to be cached.
7994Valid values are @code{passwd}, @code{group}, @code{hosts}, and
7995@code{services}, which designate the corresponding NSS database
7996(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
7997
7998@item @code{positive-time-to-live}
7999@itemx @code{negative-time-to-live} (default: @code{20})
8000A number representing the number of seconds during which a positive or
8001negative lookup result remains in cache.
8002
8003@item @code{check-files?} (default: @code{#t})
8004Whether to check for updates of the files corresponding to
8005@var{database}.
8006
8007For instance, when @var{database} is @code{hosts}, setting this flag
8008instructs nscd to check for updates in @file{/etc/hosts} and to take
8009them into account.
8010
8011@item @code{persistent?} (default: @code{#t})
8012Whether the cache should be stored persistently on disk.
8013
8014@item @code{shared?} (default: @code{#t})
8015Whether the cache should be shared among users.
8016
8017@item @code{max-database-size} (default: 32@tie{}MiB)
8018Maximum size in bytes of the database cache.
8019
8020@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
8021@c settings, so leave them out.
8022
8023@end table
8024@end deftp
8025
8026@defvr {Scheme Variable} %nscd-default-caches
8027List of @code{<nscd-cache>} objects used by default by
1068f26b 8028@code{nscd-configuration} (see above).
6454b333
LC
8029
8030It enables persistent and aggressive caching of service and host name
8031lookups. The latter provides better host name lookup performance,
8032resilience in the face of unreliable name servers, and also better
8033privacy---often the result of host name lookups is in local cache, so
8034external name servers do not even need to be queried.
8035@end defvr
8036
ec2e2f6c 8037@anchor{syslog-configuration-type}
e32171ee
JD
8038@cindex syslog
8039@cindex logging
ec2e2f6c
DC
8040@deftp {Data Type} syslog-configuration
8041This data type represents the configuration of the syslog daemon.
6454b333 8042
ec2e2f6c
DC
8043@table @asis
8044@item @code{syslogd} (default: @code{#~(string-append #$inetutils "/libexec/syslogd")})
8045The syslog daemon to use.
8046
8047@item @code{config-file} (default: @code{%default-syslog.conf})
8048The syslog configuration file to use.
8049
8050@end table
8051@end deftp
8052
8053@anchor{syslog-service}
e32171ee 8054@cindex syslog
ec2e2f6c
DC
8055@deffn {Scheme Procedure} syslog-service @var{config}
8056Return a service that runs a syslog daemon according to @var{config}.
44abcb28
LC
8057
8058@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
8059information on the configuration file syntax.
cf4a9129 8060@end deffn
401c53c4 8061
0adfe95a
LC
8062@anchor{guix-configuration-type}
8063@deftp {Data Type} guix-configuration
8064This data type represents the configuration of the Guix build daemon.
8065@xref{Invoking guix-daemon}, for more information.
8066
8067@table @asis
8068@item @code{guix} (default: @var{guix})
8069The Guix package to use.
401c53c4 8070
0adfe95a
LC
8071@item @code{build-group} (default: @code{"guixbuild"})
8072Name of the group for build user accounts.
401c53c4 8073
0adfe95a
LC
8074@item @code{build-accounts} (default: @code{10})
8075Number of build user accounts to create.
401c53c4 8076
0adfe95a 8077@item @code{authorize-key?} (default: @code{#t})
e32171ee 8078@cindex substitutes, authorization thereof
5b58c28b
LC
8079Whether to authorize the substitute keys listed in
8080@code{authorized-keys}---by default that of @code{hydra.gnu.org}
0adfe95a
LC
8081(@pxref{Substitutes}).
8082
5b58c28b
LC
8083@vindex %default-authorized-guix-keys
8084@item @code{authorized-keys} (default: @var{%default-authorized-guix-keys})
8085The list of authorized key files for archive imports, as a list of
8086string-valued gexps (@pxref{Invoking guix archive}). By default, it
8087contains that of @code{hydra.gnu.org} (@pxref{Substitutes}).
8088
0adfe95a
LC
8089@item @code{use-substitutes?} (default: @code{#t})
8090Whether to use substitutes.
8091
b0b9f6e0
LC
8092@item @code{substitute-urls} (default: @var{%default-substitute-urls})
8093The list of URLs where to look for substitutes by default.
8094
0adfe95a
LC
8095@item @code{extra-options} (default: @code{'()})
8096List of extra command-line options for @command{guix-daemon}.
8097
8098@item @code{lsof} (default: @var{lsof})
8099@itemx @code{lsh} (default: @var{lsh})
8100The lsof and lsh packages to use.
8101
8102@end table
8103@end deftp
8104
8105@deffn {Scheme Procedure} guix-service @var{config}
8106Return a service that runs the Guix build daemon according to
8107@var{config}.
cf4a9129 8108@end deffn
a1ba8475 8109
be1c2c54 8110@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
8111Run @var{udev}, which populates the @file{/dev} directory dynamically.
8112@end deffn
401c53c4 8113
a535e122
LF
8114@deffn {Scheme Procedure} urandom-seed-service @var{#f}
8115Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
8116when rebooting.
8117@end deffn
8118
8119@defvr {Scheme Variable} %random-seed-file
8120This is the name of the file where some random bytes are saved by
8121@var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
8122It defaults to @file{/var/lib/random-seed}.
8123@end defvr
8124
e32171ee
JD
8125@cindex keymap
8126@cindex keyboard
b3d05f48 8127@deffn {Scheme Procedure} console-keymap-service @var{files} ...
dedb8d5e 8128@cindex keyboard layout
b3d05f48
AK
8129Return a service to load console keymaps from @var{files} using
8130@command{loadkeys} command. Most likely, you want to load some default
8131keymap, which can be done like this:
8132
8133@example
8134(console-keymap-service "dvorak")
8135@end example
8136
8137Or, for example, for a Swedish keyboard, you may need to combine
8138the following keymaps:
8139@example
8140(console-keymap-service "se-lat6" "se-fi-lat6")
8141@end example
8142
8143Also you can specify a full file name (or file names) of your keymap(s).
8144See @code{man loadkeys} for details.
8145
5eca9459
AK
8146@end deffn
8147
e32171ee
JD
8148@cindex mouse
8149@cindex gpm
1aaf116d 8150@deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
8664cc88
LC
8151 [#:options]
8152Run @var{gpm}, the general-purpose mouse daemon, with the given
8153command-line @var{options}. GPM allows users to use the mouse in the console,
8154notably to select, copy, and paste text. The default value of @var{options}
8155uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
8156
8157This service is not part of @var{%base-services}.
8158@end deffn
8159
1c52181f
LC
8160@anchor{guix-publish-service}
8161@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
8162 [#:port 80] [#:host "localhost"]
8163Return a service that runs @command{guix publish} listening on @var{host}
8164and @var{port} (@pxref{Invoking guix publish}).
8165
8166This assumes that @file{/etc/guix} already contains a signing key pair as
8167created by @command{guix archive --generate-key} (@pxref{Invoking guix
8168archive}). If that is not the case, the service will fail to start.
8169@end deffn
8170
b58cbf9a
DC
8171@anchor{rngd-service}
8172@deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
8173 [#:device "/dev/hwrng"]
8174Return a service that runs the @command{rngd} program from @var{rng-tools}
8175to add @var{device} to the kernel's entropy pool. The service will fail if
8176@var{device} does not exist.
8177@end deffn
a69576ea 8178
909147e4
RW
8179@anchor{pam-limits-service}
8180@cindex session limits
8181@cindex ulimit
8182@cindex priority
8183@deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
8184
8185Return a service that installs a configuration file for the
8186@uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
8187@code{pam_limits} module}. The procedure optionally takes a list of
8188@code{pam-limits-entry} values, which can be used to specify
8189@code{ulimit} limits and nice priority limits to user sessions.
8190
8191The following limits definition sets two hard and soft limits for all
8192login sessions of users in the @code{realtime} group:
8193
8194@example
8195(pam-limits-service
8196 (list
8197 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
8198 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
8199@end example
8200
8201The first entry increases the maximum realtime priority for
8202non-privileged processes; the second entry lifts any restriction of the
8203maximum address space that can be locked in memory. These settings are
8204commonly used for real-time audio systems.
8205@end deffn
8206
c311089b
LC
8207@node Scheduled Job Execution
8208@subsubsection Scheduled Job Execution
8209
8210@cindex cron
e32171ee 8211@cindex mcron
c311089b
LC
8212@cindex scheduling jobs
8213The @code{(gnu services mcron)} module provides an interface to
8214GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
8215mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
8216Unix @command{cron} daemon; the main difference is that it is
8217implemented in Guile Scheme, which provides a lot of flexibility when
8218specifying the scheduling of jobs and their actions.
8219
8ac6282c 8220The example below defines an operating system that runs the
c311089b 8221@command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
8ac6282c
LC
8222and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
8223well as the @command{mkid} command on behalf of an unprivileged user
8224(@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
8225gexps to introduce job definitions that are passed to mcron
8226(@pxref{G-Expressions}).
c311089b
LC
8227
8228@lisp
8229(use-modules (guix) (gnu) (gnu services mcron))
8ac6282c 8230(use-package-modules base idutils)
c311089b
LC
8231
8232(define updatedb-job
8ac6282c
LC
8233 ;; Run 'updatedb' at 3AM every day. Here we write the
8234 ;; job's action as a Scheme procedure.
c311089b 8235 #~(job '(next-hour '(3))
8ac6282c
LC
8236 (lambda ()
8237 (execl (string-append #$findutils "/bin/updatedb")
8238 "updatedb"
8239 "--prunepaths=/tmp /var/tmp /gnu/store"))))
c311089b
LC
8240
8241(define garbage-collector-job
8242 ;; Collect garbage 5 minutes after midnight every day.
8ac6282c 8243 ;; The job's action is a shell command.
c311089b
LC
8244 #~(job "5 0 * * *" ;Vixie cron syntax
8245 "guix gc -F 1G"))
8246
80d944b7 8247(define idutils-job
8ac6282c
LC
8248 ;; Update the index database as user "charlie" at 12:15PM
8249 ;; and 19:15PM. This runs from the user's home directory.
8250 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
8251 (string-append #$idutils "/bin/mkid src")
8252 #:user "charlie"))
8253
c311089b
LC
8254(operating-system
8255 ;; @dots{}
8256 (services (cons (mcron-service (list garbage-collector-job
8ac6282c
LC
8257 updatedb-job
8258 idutils-job))
c311089b
LC
8259 %base-services)))
8260@end lisp
8261
8262@xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
8263for more information on mcron job specifications. Below is the
8264reference of the mcron service.
8265
8266@deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
8267Return an mcron service running @var{mcron} that schedules @var{jobs}, a
8268list of gexps denoting mcron job specifications.
8269
8270This is a shorthand for:
8271@example
80d944b7
LC
8272(service mcron-service-type
8273 (mcron-configuration (mcron mcron) (jobs jobs)))
c311089b
LC
8274@end example
8275@end deffn
8276
8277@defvr {Scheme Variable} mcron-service-type
8278This is the type of the @code{mcron} service, whose value is an
8279@code{mcron-configuration} object.
8280
8281This service type can be the target of a service extension that provides
8282it additional job specifications (@pxref{Service Composition}). In
80d944b7 8283other words, it is possible to define services that provide additional
c311089b
LC
8284mcron jobs to run.
8285@end defvr
8286
8287@deftp {Data Type} mcron-configuration
8288Data type representing the configuration of mcron.
8289
8290@table @asis
8291@item @code{mcron} (default: @var{mcron2})
8292The mcron package to use.
8293
8294@item @code{jobs}
8295This is a list of gexps (@pxref{G-Expressions}), where each gexp
8296corresponds to an mcron job specification (@pxref{Syntax, mcron job
8297specifications,, mcron, GNU@tie{}mcron}).
8298@end table
8299@end deftp
8300
8301
92c03a87
JN
8302@node Log Rotation
8303@subsubsection Log Rotation
8304
8305@cindex rottlog
8306@cindex log rotation
e32171ee 8307@cindex logging
92c03a87
JN
8308Log files such as those found in @file{/var/log} tend to grow endlessly,
8309so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
8310their contents in separate files, possibly compressed. The @code{(gnu
8311services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
8312log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
8313
8314The example below defines an operating system that provides log rotation
8315with the default settings.
8316
8317@lisp
8318(use-modules (guix) (gnu))
8319(use-service-modules admin mcron)
8320(use-package-modules base idutils)
8321
8322(operating-system
8323 ;; @dots{}
8324 (services (cons* (mcron-service)
8325 (service rottlog-service-type (rottlog-configuration))
8326 %base-services)))
8327@end lisp
8328
8329@defvr {Scheme Variable} rottlog-service-type
8330This is the type of the Rottlog service, whose value is a
8331@code{rottlog-configuration} object.
8332
8333This service type can define mcron jobs (@pxref{Scheduled Job
8334Execution}) to run the rottlog service.
8335@end defvr
8336
8337@deftp {Data Type} rottlog-configuration
8338Data type representing the configuration of rottlog.
8339
8340@table @asis
8341@item @code{rottlog} (default: @code{rottlog})
8342The Rottlog package to use.
8343
8344@item @code{rc-file} (default: @code{(file-append rottlog "/etc/rc")})
8345The Rottlog configuration file to use (@pxref{Mandatory RC Variables,,,
8346rottlog, GNU Rot[t]log Manual}).
8347
8348@item @code{periodic-rotations} (default: @code{`(("weekly" %default-rotatations))})
8349A list of Rottlog period-name/period-config tuples.
8350
8351For example, taking an example from the Rottlog manual (@pxref{Period
8352Related File Examples,,, rottlog, GNU Rot[t]log Manual}), a valid tuple
8353might be:
8354
8355@example
8356("daily" ,(plain-file "daily"
8357 "\
8358 /var/log/apache/* @{
8359 storedir apache-archives
8360 rotate 6
8361 notifempty
8362 nocompress
8363 @}"))
8364@end example
8365
8366@item @code{jobs}
8367This is a list of gexps where each gexp corresponds to an mcron job
8368specification (@pxref{Scheduled Job Execution}).
8369@end table
8370@end deftp
8371
8372@defvr {Scheme Variable} %default-rotations
8373Specifies weekly rotation of @var{%rotated-files} and
8374@code{"/var/log/shepherd.log"}.
8375@end defvr
8376
8377@defvr {Scheme Variable} %rotated-files
8378The list of syslog-controlled files to be rotated. By default it is:
8379@code{'("/var/log/messages" "/var/log/secure")}.
8380@end defvr
8381
cf4a9129
LC
8382@node Networking Services
8383@subsubsection Networking Services
401c53c4 8384
fa1e31b8 8385The @code{(gnu services networking)} module provides services to configure
cf4a9129 8386the network interface.
a1ba8475 8387
a023cca8 8388@cindex DHCP, networking service
be1c2c54 8389@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
8390Return a service that runs @var{dhcp}, a Dynamic Host Configuration
8391Protocol (DHCP) client, on all the non-loopback network interfaces.
8392@end deffn
8393
be1c2c54 8394@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
1f9803c2 8395 [#:netmask #f] [#:gateway #f] [#:name-servers @code{'()}]
cf4a9129 8396Return a service that starts @var{interface} with address @var{ip}. If
1f9803c2
LC
8397@var{netmask} is true, use it as the network mask. If @var{gateway} is true,
8398it must be a string specifying the default network gateway.
cf4a9129 8399@end deffn
8b315a6d 8400
b7d0c494 8401@cindex wicd
e32171ee
JD
8402@cindex wireless
8403@cindex WiFi
87f40011 8404@cindex network management
be1c2c54 8405@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
8406Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
8407management daemon that aims to simplify wired and wireless networking.
8408
8409This service adds the @var{wicd} package to the global profile, providing
8410several commands to interact with the daemon and configure networking:
8411@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
8412and @command{wicd-curses} user interfaces.
b7d0c494
MW
8413@end deffn
8414
c0a9589d
SB
8415@cindex NetworkManager
8416@deffn {Scheme Procedure} network-manager-service @
8417 [#:network-manager @var{network-manager}]
8418Return a service that runs NetworkManager, a network connection manager
1068f26b 8419attempting to keep network connectivity active when available.
c0a9589d
SB
8420@end deffn
8421
76192896
EF
8422@cindex Connman
8423@deffn {Scheme Procedure} connman-service @
8424 [#:connman @var{connman}]
8425Return a service that runs @url{https://01.org/connman,Connman}, a network
8426connection manager.
8427
8428This service adds the @var{connman} package to the global profile, providing
8429several the @command{connmanctl} command to interact with the daemon and
8430configure networking."
8431@end deffn
8432
2cccbc2a
8433@cindex WPA Supplicant
8434@deffn {Scheme Procedure} wpa-supplicant-service @
8435 [#:wpa-supplicant @var{wpa-supplicant}]
8436Return a service that runs @url{https://w1.fi/wpa_supplicant/,WPA
8437supplicant}, an authentication daemon required to authenticate against
8438encrypted WiFi or ethernet networks. Service is started to listen for
8439requests on D-Bus.
8440@end deffn
8441
e32171ee
JD
8442@cindex NTP
8443@cindex real time clock
be1c2c54 8444@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
dc0322b5
LC
8445 [#:servers @var{%ntp-servers}] @
8446 [#:allow-large-adjustment? #f]
63854bcb
LC
8447Return a service that runs the daemon from @var{ntp}, the
8448@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
8449keep the system clock synchronized with that of @var{servers}.
dc0322b5
LC
8450@var{allow-large-adjustment?} determines whether @command{ntpd} is allowed to
8451make an initial adjustment of more than 1,000 seconds.
63854bcb
LC
8452@end deffn
8453
8454@defvr {Scheme Variable} %ntp-servers
8455List of host names used as the default NTP servers.
8456@end defvr
8457
e32171ee 8458@cindex Tor
375c6108
LC
8459@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
8460Return a service to run the @uref{https://torproject.org, Tor} anonymous
8461networking daemon.
8b315a6d 8462
375c6108 8463The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
8464@var{config-file}, a file-like object, with an additional @code{User tor} line
8465and lines for hidden services added via @code{tor-hidden-service}. Run
8466@command{man tor} for information about the configuration file.
8467@end deffn
8468
24a8ef3b 8469@cindex hidden service
6331bde7
LC
8470@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
8471Define a new Tor @dfn{hidden service} called @var{name} and implementing
8472@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
8473
8474@example
24a8ef3b
LC
8475 '((22 "127.0.0.1:22")
8476 (80 "127.0.0.1:8080"))
6331bde7
LC
8477@end example
8478
8479In this example, port 22 of the hidden service is mapped to local port 22, and
8480port 80 is mapped to local port 8080.
8481
6629099a
LC
8482This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
8483the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
8484service.
8485
8486See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
8487project's documentation} for more information.
cf4a9129 8488@end deffn
8b315a6d 8489
be1c2c54 8490@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
8491 [#:interface "127.0.0.1"] [#:port 6667] @
8492 [#:extra-settings ""]
8493Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
8494acts as a gateway between IRC and chat networks.
8495
8496The daemon will listen to the interface corresponding to the IP address
8497specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
8498local clients can connect, whereas @code{0.0.0.0} means that connections can
8499come from any networking interface.
8500
8501In addition, @var{extra-settings} specifies a string to append to the
8502configuration file.
8503@end deffn
8504
71b0601a 8505Furthermore, @code{(gnu services ssh)} provides the following services.
e32171ee
JD
8506@cindex SSH
8507@cindex SSH server
8b315a6d 8508
be1c2c54 8509@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 8510 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
8511 [#:allow-empty-passwords? #f] [#:root-login? #f] @
8512 [#:syslog-output? #t] [#:x11-forwarding? #t] @
8513 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 8514 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
8515Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
8516@var{host-key} must designate a file containing the host key, and readable
8517only by root.
72e25e35 8518
5833bf33
DP
8519When @var{daemonic?} is true, @command{lshd} will detach from the
8520controlling terminal and log its output to syslogd, unless one sets
8521@var{syslog-output?} to false. Obviously, it also makes lsh-service
8522depend on existence of syslogd service. When @var{pid-file?} is true,
8523@command{lshd} writes its PID to the file called @var{pid-file}.
8524
cf4a9129
LC
8525When @var{initialize?} is true, automatically create the seed and host key
8526upon service activation if they do not exist yet. This may take long and
8527require interaction.
8b315a6d 8528
20dd519c
LC
8529When @var{initialize?} is false, it is up to the user to initialize the
8530randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
8531a key pair with the private key stored in file @var{host-key} (@pxref{lshd
8532basics,,, lsh, LSH Manual}).
8533
cf4a9129
LC
8534When @var{interfaces} is empty, lshd listens for connections on all the
8535network interfaces; otherwise, @var{interfaces} must be a list of host names
8536or addresses.
9bf3c1a7 8537
20dd519c
LC
8538@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
8539passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 8540root.
4af2447e 8541
cf4a9129
LC
8542The other options should be self-descriptive.
8543@end deffn
4af2447e 8544
e32171ee
JD
8545@cindex SSH
8546@cindex SSH server
d8f31281
LC
8547@deffn {Scheme Variable} openssh-service-type
8548This is the type for the @uref{http://www.openssh.org, OpenSSH} secure
8549shell daemon, @command{sshd}. Its value must be an
8550@code{openssh-configuration} record as in this example:
8551
8552@example
8553(service openssh-service-type
8554 (openssh-configuration
8555 (x11-forwarding? #t)
8556 (permit-root-login 'without-password)))
8557@end example
8558
8559See below for details about @code{openssh-configuration}.
86d8f6d3
JL
8560@end deffn
8561
d8f31281
LC
8562@deftp {Data Type} openssh-configuration
8563This is the configuration record for OpenSSH's @command{sshd}.
8564
8565@table @asis
8566@item @code{pid-file} (default: @code{"/var/run/sshd.pid"})
8567Name of the file where @command{sshd} writes its PID.
8568
8569@item @code{port-number} (default: @code{22})
8570TCP port on which @command{sshd} listens for incoming connections.
8571
8572@item @code{permit-root-login} (default: @code{#f})
8573This field determines whether and when to allow logins as root. If
8574@code{#f}, root logins are disallowed; if @code{#t}, they are allowed.
8575If it's the symbol @code{'without-password}, then root logins are
8576permitted but not with password-based authentication.
8577
8578@item @code{allow-empty-passwords?} (default: @code{#f})
8579When true, users with empty passwords may log in. When false, they may
8580not.
8581
8582@item @code{password-authentication?} (default: @code{#t})
8583When true, users may log in with their password. When false, they have
8584other authentication methods.
8585
8586@item @code{public-key-authentication?} (default: @code{#t})
8587When true, users may log in using public key authentication. When
8588false, users have to use other authentication method.
8589
8590Authorized public keys are stored in @file{~/.ssh/authorized_keys}.
8591This is used only by protocol version 2.
8592
8593@item @code{rsa-authentication?} (default: @code{#t})
8594When true, users may log in using pure RSA authentication. When false,
8595users have to use other means of authentication. This is used only by
8596protocol 1.
8597
8598@item @code{x11-forwarding?} (default: @code{#f})
8599When true, forwarding of X11 graphical client connections is
8600enabled---in other words, @command{ssh} options @option{-X} and
8601@option{-Y} will work.
8602
8603@item @code{protocol-number} (default: @code{2})
8604The SSH protocol number to use.
8605@end table
8606@end deftp
8607
71b0601a
DC
8608@deffn {Scheme Procedure} dropbear-service [@var{config}]
8609Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
8610daemon} with the given @var{config}, a @code{<dropbear-configuration>}
8611object.
8612
8613For example, to specify a Dropbear service listening on port 1234, add
8614this call to the operating system's @code{services} field:
8615
8616@example
8617(dropbear-service (dropbear-configuration
8618 (port-number 1234)))
8619@end example
8620@end deffn
8621
8622@deftp {Data Type} dropbear-configuration
8623This data type represents the configuration of a Dropbear SSH daemon.
8624
8625@table @asis
8626@item @code{dropbear} (default: @var{dropbear})
8627The Dropbear package to use.
8628
8629@item @code{port-number} (default: 22)
8630The TCP port where the daemon waits for incoming connections.
8631
8632@item @code{syslog-output?} (default: @code{#t})
8633Whether to enable syslog output.
8634
8635@item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
8636File name of the daemon's PID file.
8637
8638@item @code{root-login?} (default: @code{#f})
8639Whether to allow @code{root} logins.
8640
8641@item @code{allow-empty-passwords?} (default: @code{#f})
8642Whether to allow empty passwords.
8643
8644@item @code{password-authentication?} (default: @code{#t})
8645Whether to enable password-based authentication.
8646@end table
8647@end deftp
8648
fa0c1d61
LC
8649@defvr {Scheme Variable} %facebook-host-aliases
8650This variable contains a string for use in @file{/etc/hosts}
8651(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
8652line contains a entry that maps a known server name of the Facebook
8653on-line service---e.g., @code{www.facebook.com}---to the local
8654host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
8655
8656This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
8657@code{operating-system} declaration (@pxref{operating-system Reference,
8658@file{/etc/hosts}}):
fa0c1d61
LC
8659
8660@example
8661(use-modules (gnu) (guix))
8662
8663(operating-system
8664 (host-name "mymachine")
8665 ;; ...
8666 (hosts-file
8667 ;; Create a /etc/hosts file with aliases for "localhost"
8668 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
8669 (plain-file "hosts"
8670 (string-append (local-host-aliases host-name)
8671 %facebook-host-aliases))))
fa0c1d61
LC
8672@end example
8673
8674This mechanism can prevent programs running locally, such as Web
8675browsers, from accessing Facebook.
8676@end defvr
8677
965a7332
LC
8678The @code{(gnu services avahi)} provides the following definition.
8679
be1c2c54 8680@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
8681 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
8682 [#:ipv6? #t] [#:wide-area? #f] @
c8695f32 8683 [#:domains-to-browse '()] [#:debug? #f]
965a7332
LC
8684Return a service that runs @command{avahi-daemon}, a system-wide
8685mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
8686"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
8687extends the name service cache daemon (nscd) so that it can resolve
8688@code{.local} host names using
1065bed9
LC
8689@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
8690add the @var{avahi} package to the system profile so that commands such as
8691@command{avahi-browse} are directly usable.
965a7332
LC
8692
8693If @var{host-name} is different from @code{#f}, use that as the host name to
8694publish for this machine; otherwise, use the machine's actual host name.
8695
8696When @var{publish?} is true, publishing of host names and services is allowed;
8697in particular, avahi-daemon will publish the machine's host name and IP
8698address via mDNS on the local network.
8699
8700When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
8701
8702Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
8703sockets.
8704@end deffn
8705
8706
cf4a9129
LC
8707@node X Window
8708@subsubsection X Window
68ad877c 8709
e32171ee
JD
8710@cindex X11
8711@cindex X Window System
cf4a9129
LC
8712Support for the X Window graphical display system---specifically
8713Xorg---is provided by the @code{(gnu services xorg)} module. Note that
8714there is no @code{xorg-service} procedure. Instead, the X server is
8715started by the @dfn{login manager}, currently SLiM.
4af2447e 8716
935644c0
DC
8717@deftp {Data Type} sddm-configuration
8718This is the data type representing the sddm service configuration.
8719
8720@table @asis
8721@item @code{display-server} (default: "x11")
8722Select display server to use for the greeter. Valid values are "x11"
8723or "wayland".
8724
8725@item @code{numlock} (default: "on")
8726Valid values are "on", "off" or "none".
8727
8728@item @code{halt-command} (default @code{#~(string-apppend #$shepherd "/sbin/halt")})
8729Command to run when halting.
8730
8731@item @code{reboot-command} (default @code{#~(string-append #$shepherd "/sbin/reboot")})
8732Command to run when rebooting.
8733
8734@item @code{theme} (default "maldives")
8735Theme to use. Default themes provided by SDDM are "elarun" or "maldives".
8736
8737@item @code{themes-directory} (default "/run/current-system/profile/share/sddm/themes")
8738Directory to look for themes.
8739
8740@item @code{faces-directory} (default "/run/current-system/profile/share/sddm/faces")
8741Directory to look for faces.
8742
8743@item @code{default-path} (default "/run/current-system/profile/bin")
8744Default PATH to use.
8745
8746@item @code{minimum-uid} (default 1000)
8747Minimum UID to display in SDDM.
8748
8749@item @code{maximum-uid} (default 2000)
8750Maximum UID to display in SDDM
8751
8752@item @code{remember-last-user?} (default #t)
8753Remember last user.
8754
8755@item @code{remember-last-session?} (default #t)
8756Remember last session.
8757
8758@item @code{hide-users} (default "")
8759Usernames to hide from SDDM greeter.
8760
8761@item @code{hide-shells} (default @code{#~(string-append #$shadow "/sbin/nologin")})
8762Users with shells listed will be hidden from the SDDM greeter.
8763
8764@item @code{session-command} (default @code{#~(string-append #$sddm "/share/sddm/scripts/wayland-session")})
8765Script to run before starting a wayland session.
8766
8767@item @code{sessions-directory} (default "/run/current-system/profile/share/wayland-sessions")
8768Directory to look for desktop files starting wayland sessions.
8769
8770@item @code{xorg-server-path} (default @code{xorg-start-command})
8771Path to xorg-server.
8772
8773@item @code{xauth-path} (default @code{#~(string-append #$xauth "/bin/xauth")})
8774Path to xauth.
8775
8776@item @code{xephyr-path} (default @code{#~(string-append #$xorg-server "/bin/Xephyr")})
8777Path to Xephyr.
8778
8779@item @code{xdisplay-start} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xsetup")})
8780Script to run after starting xorg-server.
8781
8782@item @code{xdisplay-stop} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xstop")})
8783Script to run before stopping xorg-server.
8784
8785@item @code{xsession-command} (default: @code{xinitr })
8786Script to run before starting a X session.
8787
8788@item @code{xsessions-directory} (default: "/run/current-system/profile/share/xsessions")
8789Directory to look for desktop files starting X sessions.
8790
8791@item @code{minimum-vt} (default: 7)
8792Minimum VT to use.
8793
8794@item @code{xserver-arguments} (default "-nolisten tcp")
8795Arguments to pass to xorg-server.
8796
8797@item @code{auto-login-user} (default "")
8798User to use for auto-login.
8799
8800@item @code{auto-login-session} (default "")
8801Desktop file to use for auto-login.
8802
8803@item @code{relogin?} (default #f)
8804Relogin after logout.
8805
8806@end table
8807@end deftp
8808
e32171ee 8809@cindex login manager
935644c0
DC
8810@deffn {Scheme Procedure} sddm-service config
8811Return a service that spawns the SDDM graphical login manager for config of
8812type @code{<sddm-configuration>}.
8813
8814@example
8815 (sddm-service (sddm-configuration
8816 (auto-login-user "Alice")
8817 (auto-login-session "xfce.desktop")))
8818@end example
8819@end deffn
8820
be1c2c54 8821@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
8822 [#:auto-login? #f] [#:default-user ""] [#:startx] @
8823 [#:theme @var{%default-slim-theme}] @
4bd43bbe 8824 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
8825Return a service that spawns the SLiM graphical login manager, which in
8826turn starts the X display server with @var{startx}, a command as returned by
8827@code{xorg-start-command}.
4af2447e 8828
04e4e6ab
LC
8829@cindex X session
8830
8831SLiM automatically looks for session types described by the @file{.desktop}
8832files in @file{/run/current-system/profile/share/xsessions} and allows users
8833to choose a session from the log-in screen using @kbd{F1}. Packages such as
8834@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
8835adding them to the system-wide set of packages automatically makes them
8836available at the log-in screen.
8837
8838In addition, @file{~/.xsession} files are honored. When available,
8839@file{~/.xsession} must be an executable that starts a window manager
8840and/or other X clients.
8841
cf4a9129
LC
8842When @var{allow-empty-passwords?} is true, allow logins with an empty
8843password. When @var{auto-login?} is true, log in automatically as
8844@var{default-user}.
0ecc3bf3 8845
1068f26b 8846If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
8847@var{theme} must be a gexp denoting the name of a directory containing the
8848theme to use. In that case, @var{theme-name} specifies the name of the
8849theme.
cf4a9129 8850@end deffn
4af2447e 8851
0ecc3bf3
LC
8852@defvr {Scheme Variable} %default-theme
8853@defvrx {Scheme Variable} %default-theme-name
8854The G-Expression denoting the default SLiM theme and its name.
8855@end defvr
8856
be1c2c54 8857@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 8858 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 8859Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
8860from @var{xorg-server}. @var{configuration-file} is the server configuration
8861file or a derivation that builds it; when omitted, the result of
8862@code{xorg-configuration-file} is used.
8863
8864Usually the X server is started by a login manager.
8865@end deffn
8866
be1c2c54 8867@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 8868 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
8869Return a configuration file for the Xorg server containing search paths for
8870all the common drivers.
f703413e
LC
8871
8872@var{drivers} must be either the empty list, in which case Xorg chooses a
8873graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 8874this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
8875
8876Likewise, when @var{resolutions} is the empty list, Xorg chooses an
8877appropriate screen resolution; otherwise, it must be a list of
8878resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
8879
8880Last, @var{extra-config} is a list of strings or objects appended to the
8881@code{text-file*} argument list. It is used to pass extra text to be added
8882verbatim to the configuration file.
f703413e 8883@end deffn
4af2447e 8884
6726282b
LC
8885@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
8886Add @var{package}, a package for a screen-locker or screen-saver whose
8887command is @var{program}, to the set of setuid programs and add a PAM entry
8888for it. For example:
8889
8890@lisp
8891(screen-locker-service xlockmore "xlock")
8892@end lisp
8893
8894makes the good ol' XlockMore usable.
8895@end deffn
8896
8897
f2ec23d1
AW
8898@node Printing Services
8899@subsubsection Printing Services
8900
8901The @code{(gnu services cups)} module provides a Guix service definition
8902for the CUPS printing service. To add printer support to a GuixSD
8903system, add a @code{cups-service} to the operating system definition:
8904
8905@deffn {Scheme Variable} cups-service-type
8906The service type for the CUPS print server. Its value should be a valid
8907CUPS configuration (see below). For example:
8908@example
8909(service cups-service-type (cups-configuration))
8910@end example
8911@end deffn
8912
8913The CUPS configuration controls the basic things about your CUPS
8914installation: what interfaces it listens on, what to do if a print job
8915fails, how much logging to do, and so on. To actually add a printer,
8916you have to visit the @url{http://localhost:631} URL, or use a tool such
8917as GNOME's printer configuration services. By default, configuring a
8918CUPS service will generate a self-signed certificate if needed, for
8919secure connections to the print server.
8920
8921One way you might want to customize CUPS is to enable or disable the web
8922interface. You can do that directly, like this:
8923
8924@example
8925(service cups-service-type
8926 (cups-configuration
8927 (web-interface? #f)))
8928@end example
8929
8930The available configuration parameters follow. Each parameter
8931definition is preceded by its type; for example, @samp{string-list foo}
8932indicates that the @code{foo} parameter should be specified as a list of
8933strings. There is also a way to specify the configuration as a string,
8934if you have an old @code{cupsd.conf} file that you want to port over
8935from some other system; see the end for more details.
8936
8937@c The following documentation was initially generated by
8938@c (generate-documentation) in (gnu services cups). Manually maintained
8939@c documentation is better, so we shouldn't hesitate to edit below as
8940@c needed. However if the change you want to make to this documentation
8941@c can be done in an automated way, it's probably easier to change
8942@c (generate-documentation) than to make it below and have to deal with
8943@c the churn as CUPS updates.
8944
8945
8946Available @code{cups-configuration} fields are:
8947
8948@deftypevr {@code{cups-configuration} parameter} package cups
8949The CUPS package.
8950@end deftypevr
8951
8952@deftypevr {@code{cups-configuration} parameter} package-list extensions
8953Drivers and other extensions to the CUPS package.
8954@end deftypevr
8955
8956@deftypevr {@code{cups-configuration} parameter} files-configuration files-configuration
8957Configuration of where to write logs, what directories to use for print
8958spools, and related privileged configuration parameters.
8959
8960Available @code{files-configuration} fields are:
8961
8962@deftypevr {@code{files-configuration} parameter} log-location access-log
8963Defines the access log filename. Specifying a blank filename disables
8964access log generation. The value @code{stderr} causes log entries to be
8965sent to the standard error file when the scheduler is running in the
8966foreground, or to the system log daemon when run in the background. The
8967value @code{syslog} causes log entries to be sent to the system log
8968daemon. The server name may be included in filenames using the string
8969@code{%s}, as in @code{/var/log/cups/%s-access_log}.
8970
8971Defaults to @samp{"/var/log/cups/access_log"}.
8972@end deftypevr
8973
8974@deftypevr {@code{files-configuration} parameter} file-name cache-dir
8975Where CUPS should cache data.
8976
8977Defaults to @samp{"/var/cache/cups"}.
8978@end deftypevr
8979
8980@deftypevr {@code{files-configuration} parameter} string config-file-perm
8981Specifies the permissions for all configuration files that the scheduler
8982writes.
8983
8984Note that the permissions for the printers.conf file are currently
8985masked to only allow access from the scheduler user (typically root).
8986This is done because printer device URIs sometimes contain sensitive
8987authentication information that should not be generally known on the
8988system. There is no way to disable this security feature.
8989
8990Defaults to @samp{"0640"}.
8991@end deftypevr
8992
8993@deftypevr {@code{files-configuration} parameter} log-location error-log
8994Defines the error log filename. Specifying a blank filename disables
8995access log generation. The value @code{stderr} causes log entries to be
8996sent to the standard error file when the scheduler is running in the
8997foreground, or to the system log daemon when run in the background. The
8998value @code{syslog} causes log entries to be sent to the system log
8999daemon. The server name may be included in filenames using the string
9000@code{%s}, as in @code{/var/log/cups/%s-error_log}.
9001
9002Defaults to @samp{"/var/log/cups/error_log"}.
9003@end deftypevr
9004
9005@deftypevr {@code{files-configuration} parameter} string fatal-errors
9006Specifies which errors are fatal, causing the scheduler to exit. The
9007kind strings are:
9008
9009@table @code
9010@item none
9011No errors are fatal.
9012
9013@item all
9014All of the errors below are fatal.
9015
9016@item browse
9017Browsing initialization errors are fatal, for example failed connections
9018to the DNS-SD daemon.
9019
9020@item config
9021Configuration file syntax errors are fatal.
9022
9023@item listen
9024Listen or Port errors are fatal, except for IPv6 failures on the
9025loopback or @code{any} addresses.
9026
9027@item log
9028Log file creation or write errors are fatal.
9029
9030@item permissions
9031Bad startup file permissions are fatal, for example shared TLS
9032certificate and key files with world-read permissions.
9033@end table
9034
9035Defaults to @samp{"all -browse"}.
9036@end deftypevr
9037
9038@deftypevr {@code{files-configuration} parameter} boolean file-device?
9039Specifies whether the file pseudo-device can be used for new printer
9040queues. The URI @uref{file:///dev/null} is always allowed.
9041
9042Defaults to @samp{#f}.
9043@end deftypevr
9044
9045@deftypevr {@code{files-configuration} parameter} string group
9046Specifies the group name or ID that will be used when executing external
9047programs.
9048
9049Defaults to @samp{"lp"}.
9050@end deftypevr
9051
9052@deftypevr {@code{files-configuration} parameter} string log-file-perm
9053Specifies the permissions for all log files that the scheduler writes.
9054
9055Defaults to @samp{"0644"}.
9056@end deftypevr
9057
9058@deftypevr {@code{files-configuration} parameter} log-location page-log
9059Defines the page log filename. Specifying a blank filename disables
9060access log generation. The value @code{stderr} causes log entries to be
9061sent to the standard error file when the scheduler is running in the
9062foreground, or to the system log daemon when run in the background. The
9063value @code{syslog} causes log entries to be sent to the system log
9064daemon. The server name may be included in filenames using the string
9065@code{%s}, as in @code{/var/log/cups/%s-page_log}.
9066
9067Defaults to @samp{"/var/log/cups/page_log"}.
9068@end deftypevr
9069
9070@deftypevr {@code{files-configuration} parameter} string remote-root
9071Specifies the username that is associated with unauthenticated accesses
9072by clients claiming to be the root user. The default is @code{remroot}.
9073
9074Defaults to @samp{"remroot"}.
9075@end deftypevr
9076
9077@deftypevr {@code{files-configuration} parameter} file-name request-root
9078Specifies the directory that contains print jobs and other HTTP request
9079data.
9080
9081Defaults to @samp{"/var/spool/cups"}.
9082@end deftypevr
9083
9084@deftypevr {@code{files-configuration} parameter} sandboxing sandboxing
9085Specifies the level of security sandboxing that is applied to print
9086filters, backends, and other child processes of the scheduler; either
9087@code{relaxed} or @code{strict}. This directive is currently only
9088used/supported on macOS.
9089
9090Defaults to @samp{strict}.
9091@end deftypevr
9092
9093@deftypevr {@code{files-configuration} parameter} file-name server-keychain
9094Specifies the location of TLS certificates and private keys. CUPS will
9095look for public and private keys in this directory: a @code{.crt} files
9096for PEM-encoded certificates and corresponding @code{.key} files for
9097PEM-encoded private keys.
9098
9099Defaults to @samp{"/etc/cups/ssl"}.
9100@end deftypevr
9101
9102@deftypevr {@code{files-configuration} parameter} file-name server-root
9103Specifies the directory containing the server configuration files.
9104
9105Defaults to @samp{"/etc/cups"}.
9106@end deftypevr
9107
9108@deftypevr {@code{files-configuration} parameter} boolean sync-on-close?
9109Specifies whether the scheduler calls fsync(2) after writing
9110configuration or state files.
9111
9112Defaults to @samp{#f}.
9113@end deftypevr
9114
9115@deftypevr {@code{files-configuration} parameter} space-separated-string-list system-group
9116Specifies the group(s) to use for @code{@@SYSTEM} group authentication.
9117@end deftypevr
9118
9119@deftypevr {@code{files-configuration} parameter} file-name temp-dir
9120Specifies the directory where temporary files are stored.
9121
9122Defaults to @samp{"/var/spool/cups/tmp"}.
9123@end deftypevr
9124
9125@deftypevr {@code{files-configuration} parameter} string user
9126Specifies the user name or ID that is used when running external
9127programs.
9128
9129Defaults to @samp{"lp"}.
9130@end deftypevr
9131@end deftypevr
9132
9133@deftypevr {@code{cups-configuration} parameter} access-log-level access-log-level
9134Specifies the logging level for the AccessLog file. The @code{config}
9135level logs when printers and classes are added, deleted, or modified and
9136when configuration files are accessed or updated. The @code{actions}
9137level logs when print jobs are submitted, held, released, modified, or
9138canceled, and any of the conditions for @code{config}. The @code{all}
9139level logs all requests.
9140
9141Defaults to @samp{actions}.
9142@end deftypevr
9143
9144@deftypevr {@code{cups-configuration} parameter} boolean auto-purge-jobs?
9145Specifies whether to purge job history data automatically when it is no
9146longer required for quotas.
9147
9148Defaults to @samp{#f}.
9149@end deftypevr
9150
9151@deftypevr {@code{cups-configuration} parameter} browse-local-protocols browse-local-protocols
9152Specifies which protocols to use for local printer sharing.
9153
9154Defaults to @samp{dnssd}.
9155@end deftypevr
9156
9157@deftypevr {@code{cups-configuration} parameter} boolean browse-web-if?
9158Specifies whether the CUPS web interface is advertised.
9159
9160Defaults to @samp{#f}.
9161@end deftypevr
9162
9163@deftypevr {@code{cups-configuration} parameter} boolean browsing?
9164Specifies whether shared printers are advertised.
9165
9166Defaults to @samp{#f}.
9167@end deftypevr
9168
9169@deftypevr {@code{cups-configuration} parameter} string classification
9170Specifies the security classification of the server. Any valid banner
9171name can be used, including "classified", "confidential", "secret",
9172"topsecret", and "unclassified", or the banner can be omitted to disable
9173secure printing functions.
9174
9175Defaults to @samp{""}.
9176@end deftypevr
9177
9178@deftypevr {@code{cups-configuration} parameter} boolean classify-override?
9179Specifies whether users may override the classification (cover page) of
9180individual print jobs using the @code{job-sheets} option.
9181
9182Defaults to @samp{#f}.
9183@end deftypevr
9184
9185@deftypevr {@code{cups-configuration} parameter} default-auth-type default-auth-type
9186Specifies the default type of authentication to use.
9187
9188Defaults to @samp{Basic}.
9189@end deftypevr
9190
9191@deftypevr {@code{cups-configuration} parameter} default-encryption default-encryption
9192Specifies whether encryption will be used for authenticated requests.
9193
9194Defaults to @samp{Required}.
9195@end deftypevr
9196
9197@deftypevr {@code{cups-configuration} parameter} string default-language
9198Specifies the default language to use for text and web content.
9199
9200Defaults to @samp{"en"}.
9201@end deftypevr
9202
9203@deftypevr {@code{cups-configuration} parameter} string default-paper-size
9204Specifies the default paper size for new print queues. @samp{"Auto"}
9205uses a locale-specific default, while @samp{"None"} specifies there is
9206no default paper size. Specific size names are typically
9207@samp{"Letter"} or @samp{"A4"}.
9208
9209Defaults to @samp{"Auto"}.
9210@end deftypevr
9211
9212@deftypevr {@code{cups-configuration} parameter} string default-policy
9213Specifies the default access policy to use.
9214
9215Defaults to @samp{"default"}.
9216@end deftypevr
9217
9218@deftypevr {@code{cups-configuration} parameter} boolean default-shared?
9219Specifies whether local printers are shared by default.
9220
9221Defaults to @samp{#t}.
9222@end deftypevr
9223
9224@deftypevr {@code{cups-configuration} parameter} non-negative-integer dirty-clean-interval
9225Specifies the delay for updating of configuration and state files, in
9226seconds. A value of 0 causes the update to happen as soon as possible,
9227typically within a few milliseconds.
9228
9229Defaults to @samp{30}.
9230@end deftypevr
9231
9232@deftypevr {@code{cups-configuration} parameter} error-policy error-policy
9233Specifies what to do when an error occurs. Possible values are
9234@code{abort-job}, which will discard the failed print job;
9235@code{retry-job}, which will retry the job at a later time;
9236@code{retry-this-job}, which retries the failed job immediately; and
9237@code{stop-printer}, which stops the printer.
9238
9239Defaults to @samp{stop-printer}.
9240@end deftypevr
9241
9242@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-limit
9243Specifies the maximum cost of filters that are run concurrently, which
9244can be used to minimize disk, memory, and CPU resource problems. A
9245limit of 0 disables filter limiting. An average print to a
9246non-PostScript printer needs a filter limit of about 200. A PostScript
9247printer needs about half that (100). Setting the limit below these
9248thresholds will effectively limit the scheduler to printing a single job
9249at any time.
9250
9251Defaults to @samp{0}.
9252@end deftypevr
9253
9254@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-nice
9255Specifies the scheduling priority of filters that are run to print a
9256job. The nice value ranges from 0, the highest priority, to 19, the
9257lowest priority.
9258
9259Defaults to @samp{0}.
9260@end deftypevr
9261
9262@deftypevr {@code{cups-configuration} parameter} host-name-lookups host-name-lookups
9263Specifies whether to do reverse lookups on connecting clients. The
9264@code{double} setting causes @code{cupsd} to verify that the hostname
9265resolved from the address matches one of the addresses returned for that
9266hostname. Double lookups also prevent clients with unregistered
9267addresses from connecting to your server. Only set this option to
9268@code{#t} or @code{double} if absolutely required.
9269
9270Defaults to @samp{#f}.
9271@end deftypevr
9272
9273@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-kill-delay
9274Specifies the number of seconds to wait before killing the filters and
9275backend associated with a canceled or held job.
9276
9277Defaults to @samp{30}.
9278@end deftypevr
9279
9280@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-interval
9281Specifies the interval between retries of jobs in seconds. This is
9282typically used for fax queues but can also be used with normal print
9283queues whose error policy is @code{retry-job} or
9284@code{retry-current-job}.
9285
9286Defaults to @samp{30}.
9287@end deftypevr
9288
9289@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-limit
9290Specifies the number of retries that are done for jobs. This is
9291typically used for fax queues but can also be used with normal print
9292queues whose error policy is @code{retry-job} or
9293@code{retry-current-job}.
9294
9295Defaults to @samp{5}.
9296@end deftypevr
9297
9298@deftypevr {@code{cups-configuration} parameter} boolean keep-alive?
9299Specifies whether to support HTTP keep-alive connections.
9300
9301Defaults to @samp{#t}.
9302@end deftypevr
9303
9304@deftypevr {@code{cups-configuration} parameter} non-negative-integer keep-alive-timeout
9305Specifies how long an idle client connection remains open, in seconds.
9306
9307Defaults to @samp{30}.
9308@end deftypevr
9309
9310@deftypevr {@code{cups-configuration} parameter} non-negative-integer limit-request-body
9311Specifies the maximum size of print files, IPP requests, and HTML form
9312data. A limit of 0 disables the limit check.
9313
9314Defaults to @samp{0}.
9315@end deftypevr
9316
9317@deftypevr {@code{cups-configuration} parameter} multiline-string-list listen
9318Listens on the specified interfaces for connections. Valid values are
9319of the form @var{address}:@var{port}, where @var{address} is either an
9320IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to
9321indicate all addresses. Values can also be file names of local UNIX
9322domain sockets. The Listen directive is similar to the Port directive
9323but allows you to restrict access to specific interfaces or networks.
9324@end deftypevr
9325
9326@deftypevr {@code{cups-configuration} parameter} non-negative-integer listen-back-log
9327Specifies the number of pending connections that will be allowed. This
9328normally only affects very busy servers that have reached the MaxClients
9329limit, but can also be triggered by large numbers of simultaneous
9330connections. When the limit is reached, the operating system will
9331refuse additional connections until the scheduler can accept the pending
9332ones.
9333
9334Defaults to @samp{128}.
9335@end deftypevr
9336
9337@deftypevr {@code{cups-configuration} parameter} location-access-control-list location-access-controls
9338Specifies a set of additional access controls.
9339
9340Available @code{location-access-controls} fields are:
9341
9342@deftypevr {@code{location-access-controls} parameter} file-name path
9343Specifies the URI path to which the access control applies.
9344@end deftypevr
9345
9346@deftypevr {@code{location-access-controls} parameter} access-control-list access-controls
9347Access controls for all access to this path, in the same format as the
9348@code{access-controls} of @code{operation-access-control}.
9349
9350Defaults to @samp{()}.
9351@end deftypevr
9352
9353@deftypevr {@code{location-access-controls} parameter} method-access-control-list method-access-controls
9354Access controls for method-specific access to this path.
9355
9356Defaults to @samp{()}.
9357
9358Available @code{method-access-controls} fields are:
9359
9360@deftypevr {@code{method-access-controls} parameter} boolean reverse?
9361If @code{#t}, apply access controls to all methods except the listed
9362methods. Otherwise apply to only the listed methods.
9363
9364Defaults to @samp{#f}.
9365@end deftypevr
9366
9367@deftypevr {@code{method-access-controls} parameter} method-list methods
9368Methods to which this access control applies.
9369
9370Defaults to @samp{()}.
9371@end deftypevr
9372
9373@deftypevr {@code{method-access-controls} parameter} access-control-list access-controls
9374Access control directives, as a list of strings. Each string should be
9375one directive, such as "Order allow,deny".
9376
9377Defaults to @samp{()}.
9378@end deftypevr
9379@end deftypevr
9380@end deftypevr
9381
9382@deftypevr {@code{cups-configuration} parameter} non-negative-integer log-debug-history
9383Specifies the number of debugging messages that are retained for logging
9384if an error occurs in a print job. Debug messages are logged regardless
9385of the LogLevel setting.
9386
9387Defaults to @samp{100}.
9388@end deftypevr
9389
9390@deftypevr {@code{cups-configuration} parameter} log-level log-level
9391Specifies the level of logging for the ErrorLog file. The value
9392@code{none} stops all logging while @code{debug2} logs everything.
9393
9394Defaults to @samp{info}.
9395@end deftypevr
9396
9397@deftypevr {@code{cups-configuration} parameter} log-time-format log-time-format
9398Specifies the format of the date and time in the log files. The value
9399@code{standard} logs whole seconds while @code{usecs} logs microseconds.
9400
9401Defaults to @samp{standard}.
9402@end deftypevr
9403
9404@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients
9405Specifies the maximum number of simultaneous clients that are allowed by
9406the scheduler.
9407
9408Defaults to @samp{100}.
9409@end deftypevr
9410
9411@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients-per-host
9412Specifies the maximum number of simultaneous clients that are allowed
9413from a single address.
9414
9415Defaults to @samp{100}.
9416@end deftypevr
9417
9418@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-copies
9419Specifies the maximum number of copies that a user can print of each
9420job.
9421
9422Defaults to @samp{9999}.
9423@end deftypevr
9424
9425@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-hold-time
9426Specifies the maximum time a job may remain in the @code{indefinite}
9427hold state before it is canceled. A value of 0 disables cancellation of
9428held jobs.
9429
9430Defaults to @samp{0}.
9431@end deftypevr
9432
9433@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs
9434Specifies the maximum number of simultaneous jobs that are allowed. Set
9435to 0 to allow an unlimited number of jobs.
9436
9437Defaults to @samp{500}.
9438@end deftypevr
9439
9440@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-printer
9441Specifies the maximum number of simultaneous jobs that are allowed per
9442printer. A value of 0 allows up to MaxJobs jobs per printer.
9443
9444Defaults to @samp{0}.
9445@end deftypevr
9446
9447@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-user
9448Specifies the maximum number of simultaneous jobs that are allowed per
9449user. A value of 0 allows up to MaxJobs jobs per user.
9450
9451Defaults to @samp{0}.
9452@end deftypevr
9453
9454@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-job-time
9455Specifies the maximum time a job may take to print before it is
9456canceled, in seconds. Set to 0 to disable cancellation of "stuck" jobs.
9457
9458Defaults to @samp{10800}.
9459@end deftypevr
9460
9461@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-log-size
9462Specifies the maximum size of the log files before they are rotated, in
9463bytes. The value 0 disables log rotation.
9464
9465Defaults to @samp{1048576}.
9466@end deftypevr
9467
9468@deftypevr {@code{cups-configuration} parameter} non-negative-integer multiple-operation-timeout
9469Specifies the maximum amount of time to allow between files in a
9470multiple file print job, in seconds.
9471
9472Defaults to @samp{300}.
9473@end deftypevr
9474
9475@deftypevr {@code{cups-configuration} parameter} string page-log-format
9476Specifies the format of PageLog lines. Sequences beginning with percent
9477(@samp{%}) characters are replaced with the corresponding information,
9478while all other characters are copied literally. The following percent
9479sequences are recognized:
9480
9481@table @samp
9482@item %%
9483insert a single percent character
9484
9485@item %@{name@}
9486insert the value of the specified IPP attribute
9487
9488@item %C
9489insert the number of copies for the current page
9490
9491@item %P
9492insert the current page number
9493
9494@item %T
9495insert the current date and time in common log format
9496
9497@item %j
9498insert the job ID
9499
9500@item %p
9501insert the printer name
9502
9503@item %u
9504insert the username
9505@end table
9506
9507A value of the empty string disables page logging. The string @code{%p
9508%u %j %T %P %C %@{job-billing@} %@{job-originating-host-name@}
9509%@{job-name@} %@{media@} %@{sides@}} creates a page log with the
9510standard items.
9511
9512Defaults to @samp{""}.
9513@end deftypevr
9514
9515@deftypevr {@code{cups-configuration} parameter} environment-variables environment-variables
9516Passes the specified environment variable(s) to child processes; a list
9517of strings.
9518
9519Defaults to @samp{()}.
9520@end deftypevr
9521
9522@deftypevr {@code{cups-configuration} parameter} policy-configuration-list policies
9523Specifies named access control policies.
9524
9525Available @code{policy-configuration} fields are:
9526
9527@deftypevr {@code{policy-configuration} parameter} string name
9528Name of the policy.
9529@end deftypevr
9530
9531@deftypevr {@code{policy-configuration} parameter} string job-private-access
9532Specifies an access list for a job's private values. @code{@@ACL} maps
9533to the printer's requesting-user-name-allowed or
9534requesting-user-name-denied values. @code{@@OWNER} maps to the job's
9535owner. @code{@@SYSTEM} maps to the groups listed for the
9536@code{system-group} field of the @code{files-config} configuration,
9537which is reified into the @code{cups-files.conf(5)} file. Other
9538possible elements of the access list include specific user names, and
9539@code{@@@var{group}} to indicate members of a specific group. The
9540access list may also be simply @code{all} or @code{default}.
9541
9542Defaults to @samp{"@@OWNER @@SYSTEM"}.
9543@end deftypevr
9544
9545@deftypevr {@code{policy-configuration} parameter} string job-private-values
9546Specifies the list of job values to make private, or @code{all},
9547@code{default}, or @code{none}.
9548
9549Defaults to @samp{"job-name job-originating-host-name
9550job-originating-user-name phone"}.
9551@end deftypevr
9552
9553@deftypevr {@code{policy-configuration} parameter} string subscription-private-access
9554Specifies an access list for a subscription's private values.
9555@code{@@ACL} maps to the printer's requesting-user-name-allowed or
9556requesting-user-name-denied values. @code{@@OWNER} maps to the job's
9557owner. @code{@@SYSTEM} maps to the groups listed for the
9558@code{system-group} field of the @code{files-config} configuration,
9559which is reified into the @code{cups-files.conf(5)} file. Other
9560possible elements of the access list include specific user names, and
9561@code{@@@var{group}} to indicate members of a specific group. The
9562access list may also be simply @code{all} or @code{default}.
9563
9564Defaults to @samp{"@@OWNER @@SYSTEM"}.
9565@end deftypevr
9566
9567@deftypevr {@code{policy-configuration} parameter} string subscription-private-values
9568Specifies the list of job values to make private, or @code{all},
9569@code{default}, or @code{none}.
9570
9571Defaults to @samp{"notify-events notify-pull-method notify-recipient-uri
9572notify-subscriber-user-name notify-user-data"}.
9573@end deftypevr
9574
9575@deftypevr {@code{policy-configuration} parameter} operation-access-control-list access-controls
9576Access control by IPP operation.
9577
9578Defaults to @samp{()}.
9579@end deftypevr
9580@end deftypevr
9581
9582@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-files
9583Specifies whether job files (documents) are preserved after a job is
9584printed. If a numeric value is specified, job files are preserved for
9585the indicated number of seconds after printing. Otherwise a boolean
9586value applies indefinitely.
9587
9588Defaults to @samp{86400}.
9589@end deftypevr
9590
9591@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-history
9592Specifies whether the job history is preserved after a job is printed.
9593If a numeric value is specified, the job history is preserved for the
9594indicated number of seconds after printing. If @code{#t}, the job
9595history is preserved until the MaxJobs limit is reached.
9596
9597Defaults to @samp{#t}.
9598@end deftypevr
9599
9600@deftypevr {@code{cups-configuration} parameter} non-negative-integer reload-timeout
9601Specifies the amount of time to wait for job completion before
9602restarting the scheduler.
9603
9604Defaults to @samp{30}.
9605@end deftypevr
9606
9607@deftypevr {@code{cups-configuration} parameter} string rip-cache
9608Specifies the maximum amount of memory to use when converting documents
9609into bitmaps for a printer.
9610
9611Defaults to @samp{"128m"}.
9612@end deftypevr
9613
9614@deftypevr {@code{cups-configuration} parameter} string server-admin
9615Specifies the email address of the server administrator.
9616
9617Defaults to @samp{"root@@localhost.localdomain"}.
9618@end deftypevr
9619
9620@deftypevr {@code{cups-configuration} parameter} host-name-list-or-* server-alias
9621The ServerAlias directive is used for HTTP Host header validation when
9622clients connect to the scheduler from external interfaces. Using the
9623special name @code{*} can expose your system to known browser-based DNS
9624rebinding attacks, even when accessing sites through a firewall. If the
9625auto-discovery of alternate names does not work, we recommend listing
9626each alternate name with a ServerAlias directive instead of using
9627@code{*}.
9628
9629Defaults to @samp{*}.
9630@end deftypevr
9631
9632@deftypevr {@code{cups-configuration} parameter} string server-name
9633Specifies the fully-qualified host name of the server.
9634
9635Defaults to @samp{"localhost"}.
9636@end deftypevr
9637
9638@deftypevr {@code{cups-configuration} parameter} server-tokens server-tokens
9639Specifies what information is included in the Server header of HTTP
9640responses. @code{None} disables the Server header. @code{ProductOnly}
9641reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
9642reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}.
9643@code{OS} reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is
9644the output of the @code{uname} command. @code{Full} reports @code{CUPS
96452.0.0 (@var{uname}) IPP/2.0}.
9646
9647Defaults to @samp{Minimal}.
9648@end deftypevr
9649
9650@deftypevr {@code{cups-configuration} parameter} string set-env
9651Set the specified environment variable to be passed to child processes.
9652
9653Defaults to @samp{"variable value"}.
9654@end deftypevr
9655
9656@deftypevr {@code{cups-configuration} parameter} multiline-string-list ssl-listen
9657Listens on the specified interfaces for encrypted connections. Valid
9658values are of the form @var{address}:@var{port}, where @var{address} is
9659either an IPv6 address enclosed in brackets, an IPv4 address, or
9660@code{*} to indicate all addresses.
9661
9662Defaults to @samp{()}.
9663@end deftypevr
9664
9665@deftypevr {@code{cups-configuration} parameter} ssl-options ssl-options
9666Sets encryption options. By default, CUPS only supports encryption
9667using TLS v1.0 or higher using known secure cipher suites. The
9668@code{AllowRC4} option enables the 128-bit RC4 cipher suites, which are
9669required for some older clients that do not implement newer ones. The
9670@code{AllowSSL3} option enables SSL v3.0, which is required for some
9671older clients that do not support TLS v1.0.
9672
9673Defaults to @samp{()}.
9674@end deftypevr
9675
9676@deftypevr {@code{cups-configuration} parameter} boolean strict-conformance?
9677Specifies whether the scheduler requires clients to strictly adhere to
9678the IPP specifications.
9679
9680Defaults to @samp{#f}.
9681@end deftypevr
9682
9683@deftypevr {@code{cups-configuration} parameter} non-negative-integer timeout
9684Specifies the HTTP request timeout, in seconds.
9685
9686Defaults to @samp{300}.
9687
9688@end deftypevr
9689
9690@deftypevr {@code{cups-configuration} parameter} boolean web-interface?
9691Specifies whether the web interface is enabled.
9692
9693Defaults to @samp{#f}.
9694@end deftypevr
9695
9696At this point you're probably thinking ``oh dear, Guix manual, I like
9697you but you can stop already with the configuration options''. Indeed.
9698However, one more point: it could be that you have an existing
9699@code{cupsd.conf} that you want to use. In that case, you can pass an
9700@code{opaque-cups-configuration} as the configuration of a
9701@code{cups-service-type}.
9702
9703Available @code{opaque-cups-configuration} fields are:
9704
9705@deftypevr {@code{opaque-cups-configuration} parameter} package cups
9706The CUPS package.
9707@end deftypevr
9708
9709@deftypevr {@code{opaque-cups-configuration} parameter} string cupsd.conf
9710The contents of the @code{cupsd.conf}, as a string.
9711@end deftypevr
9712
9713@deftypevr {@code{opaque-cups-configuration} parameter} string cups-files.conf
9714The contents of the @code{cups-files.conf} file, as a string.
9715@end deftypevr
9716
9717For example, if your @code{cupsd.conf} and @code{cups-files.conf} are in
9718strings of the same name, you could instantiate a CUPS service like
9719this:
9720
9721@example
9722(service cups-service-type
9723 (opaque-cups-configuration
9724 (cupsd.conf cupsd.conf)
9725 (cups-files.conf cups-files.conf)))
9726@end example
9727
9728
fe1a39d3
LC
9729@node Desktop Services
9730@subsubsection Desktop Services
aa4ed923 9731
fe1a39d3
LC
9732The @code{(gnu services desktop)} module provides services that are
9733usually useful in the context of a ``desktop'' setup---that is, on a
9734machine running a graphical display server, possibly with graphical user
7a2413e4
AW
9735interfaces, etc. It also defines services that provide specific desktop
9736environments like GNOME and XFCE.
aa4ed923 9737
4467be21
LC
9738To simplify things, the module defines a variable containing the set of
9739services that users typically expect on a machine with a graphical
9740environment and networking:
9741
9742@defvr {Scheme Variable} %desktop-services
9743This is a list of services that builds upon @var{%base-services} and
1068f26b 9744adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
9745
9746In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
9747@code{slim-service}}), screen lockers,
9748a network management tool (@pxref{Networking
4467be21 9749Services, @code{wicd-service}}), energy and color management services,
4650a77e 9750the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
9751the GeoClue location service, an NTP client (@pxref{Networking
9752Services}), the Avahi daemon, and has the name service switch service
9753configured to be able to use @code{nss-mdns} (@pxref{Name Service
9754Switch, mDNS}).
4467be21
LC
9755@end defvr
9756
9757The @var{%desktop-services} variable can be used as the @code{services}
9758field of an @code{operating-system} declaration (@pxref{operating-system
9759Reference, @code{services}}).
9760
7a2413e4
AW
9761Additionally, the @code{gnome-desktop-service} and
9762@code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
9763system. To ``add GNOME'' means that system-level services like the
9764backlight adjustment helpers and the power management utilities are
9765added to the system, extending @code{polkit} and @code{dbus}
9766appropriately, allowing GNOME to operate with elevated privileges on a
9767limited number of special-purpose system interfaces. Additionally,
9768adding a service made by @code{gnome-desktop-service} adds the GNOME
9769metapackage to the system profile. Likewise, adding the XFCE service
9770not only adds the @code{xfce} metapackage to the system profile, but it
9771also gives the Thunar file manager the ability to open a ``root-mode''
9772file management window, if the user authenticates using the
9773administrator's password via the standard polkit graphical interface.
9774
9775@deffn {Scheme Procedure} gnome-desktop-service
9776Return a service that adds the @code{gnome} package to the system
9777profile, and extends polkit with the actions from
9778@code{gnome-settings-daemon}.
9779@end deffn
9780
9781@deffn {Scheme Procedure} xfce-desktop-service
9782Return a service that adds the @code{xfce} package to the system profile,
5741e3e5 9783and extends polkit with the ability for @code{thunar} to manipulate the
7a2413e4
AW
9784file system as root from within a user session, after the user has
9785authenticated with the administrator's password.
9786@end deffn
9787
9788Because the GNOME and XFCE desktop services pull in so many packages,
9789the default @code{%desktop-services} variable doesn't include either of
9790them by default. To add GNOME or XFCE, just @code{cons} them onto
9791@code{%desktop-services} in the @code{services} field of your
9792@code{operating-system}:
9793
9794@example
9795(use-modules (gnu))
9796(use-service-modules desktop)
9797(operating-system
9798 ...
9799 ;; cons* adds items to the list given as its last argument.
9800 (services (cons* (gnome-desktop-service)
9801 (xfce-desktop-service)
9802 %desktop-services))
9803 ...)
9804@end example
9805
9806These desktop environments will then be available as options in the
9807graphical login window.
9808
9809The actual service definitions included in @code{%desktop-services} and
9810provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
9811are described below.
4467be21 9812
0adfe95a 9813@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
9814Return a service that runs the ``system bus'', using @var{dbus}, with
9815support for @var{services}.
aa4ed923 9816
fe1a39d3
LC
9817@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
9818facility. Its system bus is used to allow system services to communicate
1068f26b 9819and to be notified of system-wide events.
aa4ed923 9820
fe1a39d3
LC
9821@var{services} must be a list of packages that provide an
9822@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
9823and policy files. For example, to allow avahi-daemon to use the system bus,
9824@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
9825@end deffn
9826
0adfe95a 9827@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
9828Return a service that runs the @code{elogind} login and
9829seat management daemon. @uref{https://github.com/andywingo/elogind,
9830Elogind} exposes a D-Bus interface that can be used to know which users
9831are logged in, know what kind of sessions they have open, suspend the
9832system, inhibit system suspend, reboot the system, and other tasks.
9833
9834Elogind handles most system-level power events for a computer, for
9835example suspending the system when a lid is closed, or shutting it down
9836when the power button is pressed.
9837
9838The @var{config} keyword argument specifies the configuration for
1068f26b 9839elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
9840(@var{parameter} @var{value})...)} invocation. Available parameters and
9841their default values are:
9842
9843@table @code
9844@item kill-user-processes?
9845@code{#f}
9846@item kill-only-users
9847@code{()}
9848@item kill-exclude-users
9849@code{("root")}
9850@item inhibit-delay-max-seconds
9851@code{5}
9852@item handle-power-key
9853@code{poweroff}
9854@item handle-suspend-key
9855@code{suspend}
9856@item handle-hibernate-key
9857@code{hibernate}
9858@item handle-lid-switch
9859@code{suspend}
9860@item handle-lid-switch-docked
9861@code{ignore}
9862@item power-key-ignore-inhibited?
9863@code{#f}
9864@item suspend-key-ignore-inhibited?
9865@code{#f}
9866@item hibernate-key-ignore-inhibited?
9867@code{#f}
9868@item lid-switch-ignore-inhibited?
9869@code{#t}
9870@item holdoff-timeout-seconds
9871@code{30}
9872@item idle-action
9873@code{ignore}
9874@item idle-action-seconds
9875@code{(* 30 60)}
9876@item runtime-directory-size-percent
9877@code{10}
9878@item runtime-directory-size
9879@code{#f}
9880@item remove-ipc?
9881@code{#t}
9882@item suspend-state
9883@code{("mem" "standby" "freeze")}
9884@item suspend-mode
9885@code{()}
9886@item hibernate-state
9887@code{("disk")}
9888@item hibernate-mode
9889@code{("platform" "shutdown")}
9890@item hybrid-sleep-state
9891@code{("disk")}
9892@item hybrid-sleep-mode
9893@code{("suspend" "platform" "shutdown")}
9894@end table
9895@end deffn
9896
be1c2c54 9897@deffn {Scheme Procedure} polkit-service @
4650a77e 9898 [#:polkit @var{polkit}]
222e3319
LC
9899Return a service that runs the
9900@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
9901management service}, which allows system administrators to grant access to
9902privileged operations in a structured way. By querying the Polkit service, a
9903privileged system component can know when it should grant additional
9904capabilities to ordinary users. For example, an ordinary user can be granted
9905the capability to suspend the system if the user is logged in locally.
4650a77e
AW
9906@end deffn
9907
be1c2c54 9908@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
9909 [#:watts-up-pro? #f] @
9910 [#:poll-batteries? #t] @
9911 [#:ignore-lid? #f] @
9912 [#:use-percentage-for-policy? #f] @
9913 [#:percentage-low 10] @
9914 [#:percentage-critical 3] @
9915 [#:percentage-action 2] @
9916 [#:time-low 1200] @
9917 [#:time-critical 300] @
9918 [#:time-action 120] @
9919 [#:critical-power-action 'hybrid-sleep]
9920Return a service that runs @uref{http://upower.freedesktop.org/,
9921@command{upowerd}}, a system-wide monitor for power consumption and battery
9922levels, with the given configuration settings. It implements the
9923@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
9924GNOME.
9925@end deffn
9926
2b9e0a94
LC
9927@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
9928Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
9929UDisks}, a @dfn{disk management} daemon that provides user interfaces with
9930notifications and ways to mount/unmount disks. Programs that talk to UDisks
9931include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
9932@end deffn
9933
be1c2c54 9934@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
9935Return a service that runs @command{colord}, a system service with a D-Bus
9936interface to manage the color profiles of input and output devices such as
9937screens and scanners. It is notably used by the GNOME Color Manager graphical
9938tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
9939site} for more information.
9940@end deffn
9941
cee32ee4 9942@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 9943Return a configuration allowing an application to access GeoClue
cee32ee4
AW
9944location data. @var{name} is the Desktop ID of the application, without
9945the @code{.desktop} part. If @var{allowed?} is true, the application
9946will have access to location information by default. The boolean
1068f26b 9947@var{system?} value indicates whether an application is a system component
cee32ee4
AW
9948or not. Finally @var{users} is a list of UIDs of all users for which
9949this application is allowed location info access. An empty users list
9950means that all users are allowed.
9951@end deffn
9952
9953@defvr {Scheme Variable} %standard-geoclue-applications
9954The standard list of well-known GeoClue application configurations,
1068f26b
AE
9955granting authority to the GNOME date-and-time utility to ask for the
9956current location in order to set the time zone, and allowing the
9957IceCat and Epiphany web browsers to request location information.
9958IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
9959know the user's location.
9960@end defvr
9961
be1c2c54 9962@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
9963 [#:whitelist '()] @
9964 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
9965 [#:submit-data? #f]
9966 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
9967 [#:submission-nick "geoclue"] @
9968 [#:applications %standard-geoclue-applications]
9969Return a service that runs the GeoClue location service. This service
9970provides a D-Bus interface to allow applications to request access to a
9971user's physical location, and optionally to add information to online
9972location databases. See
9973@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
9974web site} for more information.
9975@end deffn
9976
922e21f4
SB
9977@deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
9978Return a service that runs the @command{bluetoothd} daemon, which manages
9979all the Bluetooth devices and provides a number of D-Bus interfaces.
9980
9981Users need to be in the @code{lp} group to access the D-Bus service.
9982@end deffn
9983
105369a4
DT
9984@node Database Services
9985@subsubsection Database Services
9986
e32171ee
JD
9987@cindex database
9988@cindex SQL
6575183b 9989The @code{(gnu services databases)} module provides the following services.
105369a4 9990
be1c2c54 9991@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
105369a4
DT
9992 [#:config-file] [#:data-directory ``/var/lib/postgresql/data'']
9993Return a service that runs @var{postgresql}, the PostgreSQL database
9994server.
9995
9996The PostgreSQL daemon loads its runtime configuration from
9997@var{config-file} and stores the database cluster in
9998@var{data-directory}.
9999@end deffn
fe1a39d3 10000
6575183b
SB
10001@deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
10002Return a service that runs @command{mysqld}, the MySQL or MariaDB
10003database server.
10004
10005The optional @var{config} argument specifies the configuration for
10006@command{mysqld}, which should be a @code{<mysql-configuraiton>} object.
10007@end deffn
10008
10009@deftp {Data Type} mysql-configuration
10010Data type representing the configuration of @var{mysql-service}.
10011
10012@table @asis
10013@item @code{mysql} (default: @var{mariadb})
10014Package object of the MySQL database server, can be either @var{mariadb}
10015or @var{mysql}.
10016
7414de0a 10017For MySQL, a temporary root password will be displayed at activation time.
6575183b
SB
10018For MariaDB, the root password is empty.
10019@end table
10020@end deftp
10021
d8c18af8
AW
10022@node Mail Services
10023@subsubsection Mail Services
10024
e32171ee
JD
10025@cindex mail
10026@cindex email
d8c18af8
AW
10027The @code{(gnu services mail)} module provides Guix service definitions
10028for mail services. Currently the only implemented service is Dovecot,
10029an IMAP, POP3, and LMTP server.
10030
10031Guix does not yet have a mail transfer agent (MTA), although for some
10032lightweight purposes the @code{esmtp} relay-only MTA may suffice. Help
10033is needed to properly integrate a full MTA, such as Postfix. Patches
10034welcome!
10035
10036To add an IMAP/POP3 server to a GuixSD system, add a
10037@code{dovecot-service} to the operating system definition:
10038
10039@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
10040Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
10041@end deffn
10042
1068f26b 10043By default, Dovecot does not need much configuration; the default
d8c18af8
AW
10044configuration object created by @code{(dovecot-configuration)} will
10045suffice if your mail is delivered to @code{~/Maildir}. A self-signed
10046certificate will be generated for TLS-protected connections, though
10047Dovecot will also listen on cleartext ports by default. There are a
1068f26b 10048number of options, though, which mail administrators might need to change,
d8c18af8
AW
10049and as is the case with other services, Guix allows the system
10050administrator to specify these parameters via a uniform Scheme interface.
10051
10052For example, to specify that mail is located at @code{maildir~/.mail},
10053one would instantiate the Dovecot service like this:
10054
10055@example
10056(dovecot-service #:config
10057 (dovecot-configuration
10058 (mail-location "maildir:~/.mail")))
10059@end example
10060
10061The available configuration parameters follow. Each parameter
10062definition is preceded by its type; for example, @samp{string-list foo}
10063indicates that the @code{foo} parameter should be specified as a list of
10064strings. There is also a way to specify the configuration as a string,
10065if you have an old @code{dovecot.conf} file that you want to port over
10066from some other system; see the end for more details.
10067
10068@c The following documentation was initially generated by
10069@c (generate-documentation) in (gnu services mail). Manually maintained
10070@c documentation is better, so we shouldn't hesitate to edit below as
10071@c needed. However if the change you want to make to this documentation
10072@c can be done in an automated way, it's probably easier to change
10073@c (generate-documentation) than to make it below and have to deal with
10074@c the churn as dovecot updates.
10075
10076Available @code{dovecot-configuration} fields are:
10077
10078@deftypevr {@code{dovecot-configuration} parameter} package dovecot
10079The dovecot package.
10080@end deftypevr
10081
10082@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
10083A list of IPs or hosts where to listen for connections. @samp{*}
10084listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
10085interfaces. If you want to specify non-default ports or anything more
10086complex, customize the address and port fields of the
10087@samp{inet-listener} of the specific services you are interested in.
10088@end deftypevr
10089
10090@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
10091List of protocols we want to serve. Available protocols include
10092@samp{imap}, @samp{pop3}, and @samp{lmtp}.
10093
10094Available @code{protocol-configuration} fields are:
10095
10096@deftypevr {@code{protocol-configuration} parameter} string name
10097The name of the protocol.
10098@end deftypevr
10099
10100@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 10101UNIX socket path to the master authentication server to find users.
d8c18af8 10102This is used by imap (for shared users) and lda.
1068f26b 10103It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
10104@end deftypevr
10105
10106@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
10107Space separated list of plugins to load.
10108@end deftypevr
10109
10110@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
10111Maximum number of IMAP connections allowed for a user from each IP
10112address. NOTE: The username is compared case-sensitively.
10113Defaults to @samp{10}.
10114@end deftypevr
10115
10116@end deftypevr
10117
10118@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
10119List of services to enable. Available services include @samp{imap},
10120@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
10121@samp{lmtp}.
10122
10123Available @code{service-configuration} fields are:
10124
10125@deftypevr {@code{service-configuration} parameter} string kind
10126The service kind. Valid values include @code{director},
10127@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
10128@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
10129@code{tcpwrap}, @code{quota-warning}, or anything else.
10130@end deftypevr
10131
10132@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 10133Listeners for the service. A listener is either a
d8c18af8
AW
10134@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
10135an @code{inet-listener-configuration}.
10136Defaults to @samp{()}.
10137
10138Available @code{unix-listener-configuration} fields are:
10139
10140@deftypevr {@code{unix-listener-configuration} parameter} file-name path
10141The file name on which to listen.
10142@end deftypevr
10143
10144@deftypevr {@code{unix-listener-configuration} parameter} string mode
10145The access mode for the socket.
10146Defaults to @samp{"0600"}.
10147@end deftypevr
10148
10149@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 10150The user to own the socket.
d8c18af8
AW
10151Defaults to @samp{""}.
10152@end deftypevr
10153
10154@deftypevr {@code{unix-listener-configuration} parameter} string group
10155The group to own the socket.
10156Defaults to @samp{""}.
10157@end deftypevr
10158
10159
10160Available @code{fifo-listener-configuration} fields are:
10161
10162@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
10163The file name on which to listen.
10164@end deftypevr
10165
10166@deftypevr {@code{fifo-listener-configuration} parameter} string mode
10167The access mode for the socket.
10168Defaults to @samp{"0600"}.
10169@end deftypevr
10170
10171@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 10172The user to own the socket.
d8c18af8
AW
10173Defaults to @samp{""}.
10174@end deftypevr
10175
10176@deftypevr {@code{fifo-listener-configuration} parameter} string group
10177The group to own the socket.
10178Defaults to @samp{""}.
10179@end deftypevr
10180
10181
10182Available @code{inet-listener-configuration} fields are:
10183
10184@deftypevr {@code{inet-listener-configuration} parameter} string protocol
10185The protocol to listen for.
10186@end deftypevr
10187
10188@deftypevr {@code{inet-listener-configuration} parameter} string address
10189The address on which to listen, or empty for all addresses.
10190Defaults to @samp{""}.
10191@end deftypevr
10192
10193@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
10194The port on which to listen.
10195@end deftypevr
10196
10197@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
10198Whether to use SSL for this service; @samp{yes}, @samp{no}, or
10199@samp{required}.
10200Defaults to @samp{#t}.
10201@end deftypevr
10202
10203@end deftypevr
10204
10205@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
10206Number of connections to handle before starting a new process.
10207Typically the only useful values are 0 (unlimited) or 1. 1 is more
10208secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
10209Defaults to @samp{1}.
10210@end deftypevr
10211
10212@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
10213Number of processes to always keep waiting for more connections.
10214Defaults to @samp{0}.
10215@end deftypevr
10216
10217@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
10218If you set @samp{service-count 0}, you probably need to grow
10219this.
10220Defaults to @samp{256000000}.
10221@end deftypevr
10222
10223@end deftypevr
10224
10225@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
10226Dict configuration, as created by the @code{dict-configuration}
10227constructor.
10228
10229Available @code{dict-configuration} fields are:
10230
10231@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
10232A list of key-value pairs that this dict should hold.
10233Defaults to @samp{()}.
10234@end deftypevr
10235
10236@end deftypevr
10237
10238@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 10239A list of passdb configurations, each one created by the
d8c18af8
AW
10240@code{passdb-configuration} constructor.
10241
10242Available @code{passdb-configuration} fields are:
10243
10244@deftypevr {@code{passdb-configuration} parameter} string driver
10245The driver that the passdb should use. Valid values include
10246@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
10247@samp{static}.
10248Defaults to @samp{"pam"}.
10249@end deftypevr
10250
10251@deftypevr {@code{passdb-configuration} parameter} free-form-args args
10252A list of key-value args to the passdb driver.
10253Defaults to @samp{()}.
10254@end deftypevr
10255
10256@end deftypevr
10257
10258@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
10259List of userdb configurations, each one created by the
10260@code{userdb-configuration} constructor.
10261
10262Available @code{userdb-configuration} fields are:
10263
10264@deftypevr {@code{userdb-configuration} parameter} string driver
10265The driver that the userdb should use. Valid values include
10266@samp{passwd} and @samp{static}.
10267Defaults to @samp{"passwd"}.
10268@end deftypevr
10269
10270@deftypevr {@code{userdb-configuration} parameter} free-form-args args
10271A list of key-value args to the userdb driver.
10272Defaults to @samp{()}.
10273@end deftypevr
10274
10275@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
10276Override fields from passwd.
10277Defaults to @samp{()}.
10278@end deftypevr
10279
10280@end deftypevr
10281
10282@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
10283Plug-in configuration, created by the @code{plugin-configuration}
10284constructor.
10285@end deftypevr
10286
10287@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
10288List of namespaces. Each item in the list is created by the
10289@code{namespace-configuration} constructor.
10290
10291Available @code{namespace-configuration} fields are:
10292
10293@deftypevr {@code{namespace-configuration} parameter} string name
10294Name for this namespace.
10295@end deftypevr
10296
10297@deftypevr {@code{namespace-configuration} parameter} string type
10298Namespace type: @samp{private}, @samp{shared} or @samp{public}.
10299Defaults to @samp{"private"}.
10300@end deftypevr
10301
10302@deftypevr {@code{namespace-configuration} parameter} string separator
10303Hierarchy separator to use. You should use the same separator for
10304all namespaces or some clients get confused. @samp{/} is usually a good
10305one. The default however depends on the underlying mail storage
10306format.
10307Defaults to @samp{""}.
10308@end deftypevr
10309
10310@deftypevr {@code{namespace-configuration} parameter} string prefix
10311Prefix required to access this namespace. This needs to be
10312different for all namespaces. For example @samp{Public/}.
10313Defaults to @samp{""}.
10314@end deftypevr
10315
10316@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 10317Physical location of the mailbox. This is in the same format as
d8c18af8
AW
10318mail_location, which is also the default for it.
10319Defaults to @samp{""}.
10320@end deftypevr
10321
10322@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
10323There can be only one INBOX, and this setting defines which
10324namespace has it.
10325Defaults to @samp{#f}.
10326@end deftypevr
10327
10328@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
10329If namespace is hidden, it's not advertised to clients via NAMESPACE
10330extension. You'll most likely also want to set @samp{list? #f}. This is mostly
10331useful when converting from another server with different namespaces
10332which you want to deprecate but still keep working. For example you can
10333create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
10334and @samp{mail/}.
10335Defaults to @samp{#f}.
10336@end deftypevr
10337
10338@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
10339Show the mailboxes under this namespace with the LIST command. This
10340makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
10341extension. The special @code{children} value lists child mailboxes, but
10342hides the namespace prefix.
10343Defaults to @samp{#t}.
10344@end deftypevr
10345
10346@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
10347Namespace handles its own subscriptions. If set to @code{#f}, the
10348parent namespace handles them. The empty prefix should always have this
1068f26b 10349as @code{#t}).
d8c18af8
AW
10350Defaults to @samp{#t}.
10351@end deftypevr
10352
10353@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
10354List of predefined mailboxes in this namespace.
10355Defaults to @samp{()}.
10356
10357Available @code{mailbox-configuration} fields are:
10358
10359@deftypevr {@code{mailbox-configuration} parameter} string name
10360Name for this mailbox.
10361@end deftypevr
10362
10363@deftypevr {@code{mailbox-configuration} parameter} string auto
10364@samp{create} will automatically create this mailbox.
10365@samp{subscribe} will both create and subscribe to the mailbox.
10366Defaults to @samp{"no"}.
10367@end deftypevr
10368
10369@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
10370List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
10371Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
10372@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
10373Defaults to @samp{()}.
10374@end deftypevr
10375
10376@end deftypevr
10377
10378@end deftypevr
10379
10380@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
10381Base directory where to store runtime data.
10382Defaults to @samp{"/var/run/dovecot/"}.
10383@end deftypevr
10384
10385@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
10386Greeting message for clients.
10387Defaults to @samp{"Dovecot ready."}.
10388@end deftypevr
10389
10390@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
10391List of trusted network ranges. Connections from these IPs are
10392allowed to override their IP addresses and ports (for logging and for
10393authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 10394for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
10395here.
10396Defaults to @samp{()}.
10397@end deftypevr
10398
10399@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
10400List of login access check sockets (e.g. tcpwrap).
10401Defaults to @samp{()}.
10402@end deftypevr
10403
10404@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
10405Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
10406and IP address. Useful for seeing who is actually using the IMAP
10407processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
10408accounts).
10409Defaults to @samp{#f}.
10410@end deftypevr
10411
10412@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
10413Should all processes be killed when Dovecot master process shuts down.
10414Setting this to @code{#f} means that Dovecot can be upgraded without
10415forcing existing client connections to close (although that could also
1068f26b 10416be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
10417Defaults to @samp{#t}.
10418@end deftypevr
10419
10420@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
10421If non-zero, run mail commands via this many connections to doveadm
10422server, instead of running them directly in the same process.
10423Defaults to @samp{0}.
10424@end deftypevr
10425
10426@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
10427UNIX socket or host:port used for connecting to doveadm server.
10428Defaults to @samp{"doveadm-server"}.
10429@end deftypevr
10430
10431@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
10432List of environment variables that are preserved on Dovecot startup
10433and passed down to all of its child processes. You can also give
10434key=value pairs to always set specific settings.
10435@end deftypevr
10436
10437@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
10438Disable LOGIN command and all other plaintext authentications unless
10439SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
10440matches the local IP (i.e. you're connecting from the same computer),
10441the connection is considered secure and plaintext authentication is
10442allowed. See also ssl=required setting.
10443Defaults to @samp{#t}.
10444@end deftypevr
10445
10446@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
10447Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
10448Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
10449for caching to be used.
10450Defaults to @samp{0}.
10451@end deftypevr
10452
10453@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
10454Time to live for cached data. After TTL expires the cached record
10455is no longer used, *except* if the main database lookup returns internal
10456failure. We also try to handle password changes automatically: If
10457user's previous authentication was successful, but this one wasn't, the
10458cache isn't used. For now this works only with plaintext
10459authentication.
10460Defaults to @samp{"1 hour"}.
10461@end deftypevr
10462
10463@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
10464TTL for negative hits (user not found, password mismatch).
104650 disables caching them completely.
10466Defaults to @samp{"1 hour"}.
10467@end deftypevr
10468
10469@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
10470List of realms for SASL authentication mechanisms that need them.
10471You can leave it empty if you don't want to support multiple realms.
10472Many clients simply use the first one listed here, so keep the default
10473realm first.
10474Defaults to @samp{()}.
10475@end deftypevr
10476
10477@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
10478Default realm/domain to use if none was specified. This is used for
10479both SASL realms and appending @@domain to username in plaintext
10480logins.
10481Defaults to @samp{""}.
10482@end deftypevr
10483
10484@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
10485List of allowed characters in username. If the user-given username
10486contains a character not listed in here, the login automatically fails.
10487This is just an extra check to make sure user can't exploit any
10488potential quote escaping vulnerabilities with SQL/LDAP databases. If
10489you want to allow all characters, set this value to empty.
10490Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
10491@end deftypevr
10492
10493@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
10494Username character translations before it's looked up from
10495databases. The value contains series of from -> to characters. For
10496example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
10497translated to @samp{@@}.
10498Defaults to @samp{""}.
10499@end deftypevr
10500
10501@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
10502Username formatting before it's looked up from databases. You can
10503use the standard variables here, e.g. %Lu would lowercase the username,
10504%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
10505change the @samp{@@} into @samp{-AT-}. This translation is done after
10506@samp{auth-username-translation} changes.
10507Defaults to @samp{"%Lu"}.
10508@end deftypevr
10509
10510@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
10511If you want to allow master users to log in by specifying the master
10512username within the normal username string (i.e. not using SASL
10513mechanism's support for it), you can specify the separator character
10514here. The format is then <username><separator><master username>.
10515UW-IMAP uses @samp{*} as the separator, so that could be a good
10516choice.
10517Defaults to @samp{""}.
10518@end deftypevr
10519
10520@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
10521Username to use for users logging in with ANONYMOUS SASL
10522mechanism.
10523Defaults to @samp{"anonymous"}.
10524@end deftypevr
10525
10526@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
10527Maximum number of dovecot-auth worker processes. They're used to
10528execute blocking passdb and userdb queries (e.g. MySQL and PAM).
10529They're automatically created and destroyed as needed.
10530Defaults to @samp{30}.
10531@end deftypevr
10532
10533@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
10534Host name to use in GSSAPI principal names. The default is to use
10535the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
10536allow all keytab entries.
10537Defaults to @samp{""}.
10538@end deftypevr
10539
10540@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
10541Kerberos keytab to use for the GSSAPI mechanism. Will use the
10542system default (usually /etc/krb5.keytab) if not specified. You may
10543need to change the auth service to run as root to be able to read this
10544file.
10545Defaults to @samp{""}.
10546@end deftypevr
10547
10548@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
10549Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
10550and @samp{ntlm-auth} helper.
10551<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
10552Defaults to @samp{#f}.
10553@end deftypevr
10554
10555@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
10556Path for Samba's @samp{ntlm-auth} helper binary.
10557Defaults to @samp{"/usr/bin/ntlm_auth"}.
10558@end deftypevr
10559
10560@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
10561Time to delay before replying to failed authentications.
10562Defaults to @samp{"2 secs"}.
10563@end deftypevr
10564
10565@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
10566Require a valid SSL client certificate or the authentication
10567fails.
10568Defaults to @samp{#f}.
10569@end deftypevr
10570
10571@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
10572Take the username from client's SSL certificate, using
10573@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
10574CommonName.
10575Defaults to @samp{#f}.
10576@end deftypevr
10577
10578@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
10579List of wanted authentication mechanisms. Supported mechanisms are:
10580@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
10581@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
10582@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
10583@samp{disable-plaintext-auth} setting.
10584@end deftypevr
10585
10586@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
10587List of IPs or hostnames to all director servers, including ourself.
10588Ports can be specified as ip:port. The default port is the same as what
10589director service's @samp{inet-listener} is using.
10590Defaults to @samp{()}.
10591@end deftypevr
10592
10593@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
10594List of IPs or hostnames to all backend mail servers. Ranges are
10595allowed too, like 10.0.0.10-10.0.0.30.
10596Defaults to @samp{()}.
10597@end deftypevr
10598
10599@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
10600How long to redirect users to a specific server after it no longer
10601has any connections.
10602Defaults to @samp{"15 min"}.
10603@end deftypevr
10604
10605@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
10606TCP/IP port that accepts doveadm connections (instead of director
10607connections) If you enable this, you'll also need to add
10608@samp{inet-listener} for the port.
10609Defaults to @samp{0}.
10610@end deftypevr
10611
10612@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
10613How the username is translated before being hashed. Useful values
10614include %Ln if user can log in with or without @@domain, %Ld if mailboxes
10615are shared within domain.
10616Defaults to @samp{"%Lu"}.
10617@end deftypevr
10618
10619@deftypevr {@code{dovecot-configuration} parameter} string log-path
10620Log file to use for error messages. @samp{syslog} logs to syslog,
10621@samp{/dev/stderr} logs to stderr.
10622Defaults to @samp{"syslog"}.
10623@end deftypevr
10624
10625@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
10626Log file to use for informational messages. Defaults to
10627@samp{log-path}.
10628Defaults to @samp{""}.
10629@end deftypevr
10630
10631@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
10632Log file to use for debug messages. Defaults to
10633@samp{info-log-path}.
10634Defaults to @samp{""}.
10635@end deftypevr
10636
10637@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
10638Syslog facility to use if you're logging to syslog. Usually if you
10639don't want to use @samp{mail}, you'll use local0..local7. Also other
10640standard facilities are supported.
10641Defaults to @samp{"mail"}.
10642@end deftypevr
10643
10644@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
10645Log unsuccessful authentication attempts and the reasons why they
10646failed.
10647Defaults to @samp{#f}.
10648@end deftypevr
10649
10650@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
10651In case of password mismatches, log the attempted password. Valid
10652values are no, plain and sha1. sha1 can be useful for detecting brute
10653force password attempts vs. user simply trying the same password over
10654and over again. You can also truncate the value to n chars by appending
10655":n" (e.g. sha1:6).
10656Defaults to @samp{#f}.
10657@end deftypevr
10658
10659@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
10660Even more verbose logging for debugging purposes. Shows for example
10661SQL queries.
10662Defaults to @samp{#f}.
10663@end deftypevr
10664
10665@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
10666In case of password mismatches, log the passwords and used scheme so
10667the problem can be debugged. Enabling this also enables
10668@samp{auth-debug}.
10669Defaults to @samp{#f}.
10670@end deftypevr
10671
10672@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
10673Enable mail process debugging. This can help you figure out why
10674Dovecot isn't finding your mails.
10675Defaults to @samp{#f}.
10676@end deftypevr
10677
10678@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
10679Show protocol level SSL errors.
10680Defaults to @samp{#f}.
10681@end deftypevr
10682
10683@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
10684Prefix for each line written to log file. % codes are in
10685strftime(3) format.
10686Defaults to @samp{"\"%b %d %H:%M:%S \""}.
10687@end deftypevr
10688
10689@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
10690List of elements we want to log. The elements which have a
10691non-empty variable value are joined together to form a comma-separated
10692string.
10693@end deftypevr
10694
10695@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
10696Login log format. %s contains @samp{login-log-format-elements}
10697string, %$ contains the data we want to log.
10698Defaults to @samp{"%$: %s"}.
10699@end deftypevr
10700
10701@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
10702Log prefix for mail processes. See doc/wiki/Variables.txt for list
10703of possible variables you can use.
10704Defaults to @samp{"\"%s(%u): \""}.
10705@end deftypevr
10706
10707@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
10708Format to use for logging mail deliveries. You can use variables:
10709@table @code
10710@item %$
10711Delivery status message (e.g. @samp{saved to INBOX})
10712@item %m
10713Message-ID
10714@item %s
10715Subject
10716@item %f
10717From address
10718@item %p
10719Physical size
10720@item %w
10721Virtual size.
10722@end table
10723Defaults to @samp{"msgid=%m: %$"}.
10724@end deftypevr
10725
10726@deftypevr {@code{dovecot-configuration} parameter} string mail-location
10727Location for users' mailboxes. The default is empty, which means
10728that Dovecot tries to find the mailboxes automatically. This won't work
10729if the user doesn't yet have any mail, so you should explicitly tell
10730Dovecot the full location.
10731
10732If you're using mbox, giving a path to the INBOX
10733file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
10734where the other mailboxes are kept. This is called the "root mail
10735directory", and it must be the first path given in the
10736@samp{mail-location} setting.
10737
10738There are a few special variables you can use, eg.:
10739
10740@table @samp
10741@item %u
10742username
10743@item %n
10744user part in user@@domain, same as %u if there's no domain
10745@item %d
10746domain part in user@@domain, empty if there's no domain
10747@item %h
10748home director
10749@end table
10750
10751See doc/wiki/Variables.txt for full list. Some examples:
10752@table @samp
10753@item maildir:~/Maildir
10754@item mbox:~/mail:INBOX=/var/mail/%u
10755@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
10756@end table
10757Defaults to @samp{""}.
10758@end deftypevr
10759
10760@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
10761System user and group used to access mails. If you use multiple,
10762userdb can override these by returning uid or gid fields. You can use
10763either numbers or names. <doc/wiki/UserIds.txt>.
10764Defaults to @samp{""}.
10765@end deftypevr
10766
10767@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
10768
10769Defaults to @samp{""}.
10770@end deftypevr
10771
10772@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
10773Group to enable temporarily for privileged operations. Currently
10774this is used only with INBOX when either its initial creation or
10775dotlocking fails. Typically this is set to "mail" to give access to
10776/var/mail.
10777Defaults to @samp{""}.
10778@end deftypevr
10779
10780@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
10781Grant access to these supplementary groups for mail processes.
10782Typically these are used to set up access to shared mailboxes. Note
10783that it may be dangerous to set these if users can create
10784symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
10785could allow a user to delete others' mailboxes, or ln -s
10786/secret/shared/box ~/mail/mybox would allow reading it).
10787Defaults to @samp{""}.
10788@end deftypevr
10789
10790@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8f65585b 10791Allow full file system access to clients. There's no access checks
d8c18af8
AW
10792other than what the operating system does for the active UID/GID. It
10793works with both maildir and mboxes, allowing you to prefix mailboxes
10794names with e.g. /path/ or ~user/.
10795Defaults to @samp{#f}.
10796@end deftypevr
10797
10798@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
10799Don't use mmap() at all. This is required if you store indexes to
8f65585b 10800shared file systems (NFS or clustered file system).
d8c18af8
AW
10801Defaults to @samp{#f}.
10802@end deftypevr
10803
10804@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
10805Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
10806supports @samp{O_EXCL} since version 3, so this should be safe to use
10807nowadays by default.
10808Defaults to @samp{#t}.
10809@end deftypevr
10810
10811@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
10812When to use fsync() or fdatasync() calls:
10813@table @code
10814@item optimized
10815Whenever necessary to avoid losing important data
10816@item always
10817Useful with e.g. NFS when write()s are delayed
10818@item never
10819Never use it (best performance, but crashes can lose data).
10820@end table
10821Defaults to @samp{"optimized"}.
10822@end deftypevr
10823
10824@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
10825Mail storage exists in NFS. Set this to yes to make Dovecot flush
10826NFS caches whenever needed. If you're using only a single mail server
10827this isn't needed.
10828Defaults to @samp{#f}.
10829@end deftypevr
10830
10831@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
10832Mail index files also exist in NFS. Setting this to yes requires
10833@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
10834Defaults to @samp{#f}.
10835@end deftypevr
10836
10837@deftypevr {@code{dovecot-configuration} parameter} string lock-method
10838Locking method for index files. Alternatives are fcntl, flock and
10839dotlock. Dotlocking uses some tricks which may create more disk I/O
10840than other locking methods. NFS users: flock doesn't work, remember to
10841change @samp{mmap-disable}.
10842Defaults to @samp{"fcntl"}.
10843@end deftypevr
10844
10845@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
10846Directory in which LDA/LMTP temporarily stores incoming mails >128
10847kB.
10848Defaults to @samp{"/tmp"}.
10849@end deftypevr
10850
10851@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
10852Valid UID range for users. This is mostly to make sure that users can't
10853log in as daemons or other system users. Note that denying root logins is
10854hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
10855is set to 0.
10856Defaults to @samp{500}.
10857@end deftypevr
10858
10859@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
10860
10861Defaults to @samp{0}.
10862@end deftypevr
10863
10864@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
10865Valid GID range for users. Users having non-valid GID as primary group ID
10866aren't allowed to log in. If user belongs to supplementary groups with
10867non-valid GIDs, those groups are not set.
10868Defaults to @samp{1}.
10869@end deftypevr
10870
10871@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
10872
10873Defaults to @samp{0}.
10874@end deftypevr
10875
10876@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
10877Maximum allowed length for mail keyword name. It's only forced when
10878trying to create new keywords.
10879Defaults to @samp{50}.
10880@end deftypevr
10881
10882@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
10883List of directories under which chrooting is allowed for mail
10884processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
10885too). This setting doesn't affect @samp{login-chroot}
10886@samp{mail-chroot} or auth chroot settings. If this setting is empty,
10887"/./" in home dirs are ignored. WARNING: Never add directories here
10888which local users can modify, that may lead to root exploit. Usually
10889this should be done only if you don't allow shell access for users.
10890<doc/wiki/Chrooting.txt>.
10891Defaults to @samp{()}.
10892@end deftypevr
10893
10894@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
10895Default chroot directory for mail processes. This can be overridden
10896for specific users in user database by giving /./ in user's home
10897directory (e.g. /home/./user chroots into /home). Note that usually
10898there is no real need to do chrooting, Dovecot doesn't allow users to
10899access files outside their mail directory anyway. If your home
10900directories are prefixed with the chroot directory, append "/." to
10901@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
10902Defaults to @samp{""}.
10903@end deftypevr
10904
10905@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
10906UNIX socket path to master authentication server to find users.
10907This is used by imap (for shared users) and lda.
10908Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
10909@end deftypevr
10910
10911@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
10912Directory where to look up mail plugins.
10913Defaults to @samp{"/usr/lib/dovecot"}.
10914@end deftypevr
10915
10916@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
10917List of plugins to load for all services. Plugins specific to IMAP,
10918LDA, etc. are added to this list in their own .conf files.
10919Defaults to @samp{()}.
10920@end deftypevr
10921
10922@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
10923The minimum number of mails in a mailbox before updates are done to
10924cache file. This allows optimizing Dovecot's behavior to do less disk
10925writes at the cost of more disk reads.
10926Defaults to @samp{0}.
10927@end deftypevr
10928
10929@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
10930When IDLE command is running, mailbox is checked once in a while to
10931see if there are any new mails or other changes. This setting defines
10932the minimum time to wait between those checks. Dovecot can also use
10933dnotify, inotify and kqueue to find out immediately when changes
10934occur.
10935Defaults to @samp{"30 secs"}.
10936@end deftypevr
10937
10938@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
10939Save mails with CR+LF instead of plain LF. This makes sending those
10940mails take less CPU, especially with sendfile() syscall with Linux and
10941FreeBSD. But it also creates a bit more disk I/O which may just make it
10942slower. Also note that if other software reads the mboxes/maildirs,
10943they may handle the extra CRs wrong and cause problems.
10944Defaults to @samp{#f}.
10945@end deftypevr
10946
10947@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
10948By default LIST command returns all entries in maildir beginning
10949with a dot. Enabling this option makes Dovecot return only entries
10950which are directories. This is done by stat()ing each entry, so it
10951causes more disk I/O.
10952 (For systems setting struct @samp{dirent->d_type} this check is free
10953and it's done always regardless of this setting).
10954Defaults to @samp{#f}.
10955@end deftypevr
10956
10957@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
10958When copying a message, do it with hard links whenever possible.
10959This makes the performance much better, and it's unlikely to have any
10960side effects.
10961Defaults to @samp{#t}.
10962@end deftypevr
10963
10964@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
10965Assume Dovecot is the only MUA accessing Maildir: Scan cur/
10966directory only when its mtime changes unexpectedly or when we can't find
10967the mail otherwise.
10968Defaults to @samp{#f}.
10969@end deftypevr
10970
10971@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
10972Which locking methods to use for locking mbox. There are four
10973available:
10974
10975@table @code
10976@item dotlock
10977Create <mailbox>.lock file. This is the oldest and most NFS-safe
10978solution. If you want to use /var/mail/ like directory, the users will
10979need write access to that directory.
10980@item dotlock-try
10981Same as dotlock, but if it fails because of permissions or because there
10982isn't enough disk space, just skip it.
10983@item fcntl
10984Use this if possible. Works with NFS too if lockd is used.
10985@item flock
a01ad638 10986May not exist in all systems. Doesn't work with NFS.
d8c18af8
AW
10987@item lockf
10988May not exist in all systems. Doesn't work with NFS.
10989@end table
10990
10991You can use multiple locking methods; if you do the order they're declared
10992in is important to avoid deadlocks if other MTAs/MUAs are using multiple
10993locking methods as well. Some operating systems don't allow using some of
10994them simultaneously.
10995@end deftypevr
10996
10997@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
10998
10999@end deftypevr
11000
11001@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
11002Maximum time to wait for lock (all of them) before aborting.
11003Defaults to @samp{"5 mins"}.
11004@end deftypevr
11005
11006@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
11007If dotlock exists but the mailbox isn't modified in any way,
11008override the lock file after this much time.
11009Defaults to @samp{"2 mins"}.
11010@end deftypevr
11011
11012@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
11013When mbox changes unexpectedly we have to fully read it to find out
11014what changed. If the mbox is large this can take a long time. Since
11015the change is usually just a newly appended mail, it'd be faster to
11016simply read the new mails. If this setting is enabled, Dovecot does
11017this but still safely fallbacks to re-reading the whole mbox file
11018whenever something in mbox isn't how it's expected to be. The only real
11019downside to this setting is that if some other MUA changes message
11020flags, Dovecot doesn't notice it immediately. Note that a full sync is
11021done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
11022Defaults to @samp{#t}.
11023@end deftypevr
11024
11025@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
11026Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
11027EXAMINE, EXPUNGE or CHECK commands. If this is set,
11028@samp{mbox-dirty-syncs} is ignored.
11029Defaults to @samp{#f}.
11030@end deftypevr
11031
11032@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
11033Delay writing mbox headers until doing a full write sync (EXPUNGE
11034and CHECK commands and when closing the mailbox). This is especially
11035useful for POP3 where clients often delete all mails. The downside is
11036that our changes aren't immediately visible to other MUAs.
11037Defaults to @samp{#t}.
11038@end deftypevr
11039
11040@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
11041If mbox size is smaller than this (e.g. 100k), don't write index
11042files. If an index file already exists it's still read, just not
11043updated.
11044Defaults to @samp{0}.
11045@end deftypevr
11046
11047@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
11048Maximum dbox file size until it's rotated.
11049Defaults to @samp{2000000}.
11050@end deftypevr
11051
11052@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
11053Maximum dbox file age until it's rotated. Typically in days. Day
11054begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
11055disabled.
11056Defaults to @samp{"1d"}.
11057@end deftypevr
11058
11059@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
11060When creating new mdbox files, immediately preallocate their size to
11061@samp{mdbox-rotate-size}. This setting currently works only in Linux
8f65585b 11062with some file systems (ext4, xfs).
d8c18af8
AW
11063Defaults to @samp{#f}.
11064@end deftypevr
11065
11066@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
11067sdbox and mdbox support saving mail attachments to external files,
11068which also allows single instance storage for them. Other backends
11069don't support this for now.
11070
11071WARNING: This feature hasn't been tested much yet. Use at your own risk.
11072
11073Directory root where to store mail attachments. Disabled, if empty.
11074Defaults to @samp{""}.
11075@end deftypevr
11076
11077@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
11078Attachments smaller than this aren't saved externally. It's also
11079possible to write a plugin to disable saving specific attachments
11080externally.
11081Defaults to @samp{128000}.
11082@end deftypevr
11083
11084@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8f65585b 11085File system backend to use for saving attachments:
d8c18af8
AW
11086@table @code
11087@item posix
11088No SiS done by Dovecot (but this might help FS's own deduplication)
11089@item sis posix
11090SiS with immediate byte-by-byte comparison during saving
11091@item sis-queue posix
11092SiS with delayed comparison and deduplication.
11093@end table
11094Defaults to @samp{"sis posix"}.
11095@end deftypevr
11096
11097@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
11098Hash format to use in attachment filenames. You can add any text and
11099variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
11100@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
11101truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
11102Defaults to @samp{"%@{sha1@}"}.
11103@end deftypevr
11104
11105@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
11106
11107Defaults to @samp{100}.
11108@end deftypevr
11109
11110@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
11111
11112Defaults to @samp{1000}.
11113@end deftypevr
11114
11115@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
11116Default VSZ (virtual memory size) limit for service processes.
11117This is mainly intended to catch and kill processes that leak memory
11118before they eat up everything.
11119Defaults to @samp{256000000}.
11120@end deftypevr
11121
11122@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
11123Login user is internally used by login processes. This is the most
11124untrusted user in Dovecot system. It shouldn't have access to anything
11125at all.
11126Defaults to @samp{"dovenull"}.
11127@end deftypevr
11128
11129@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
11130Internal user is used by unprivileged processes. It should be
11131separate from login user, so that login processes can't disturb other
11132processes.
11133Defaults to @samp{"dovecot"}.
11134@end deftypevr
11135
11136@deftypevr {@code{dovecot-configuration} parameter} string ssl?
11137SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
11138Defaults to @samp{"required"}.
11139@end deftypevr
11140
11141@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
11142PEM encoded X.509 SSL/TLS certificate (public key).
11143Defaults to @samp{"</etc/dovecot/default.pem"}.
11144@end deftypevr
11145
11146@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
11147PEM encoded SSL/TLS private key. The key is opened before
11148dropping root privileges, so keep the key file unreadable by anyone but
11149root.
11150Defaults to @samp{"</etc/dovecot/private/default.pem"}.
11151@end deftypevr
11152
11153@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
11154If key file is password protected, give the password here.
11155Alternatively give it when starting dovecot with -p parameter. Since
11156this file is often world-readable, you may want to place this setting
11157instead to a different.
11158Defaults to @samp{""}.
11159@end deftypevr
11160
11161@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
11162PEM encoded trusted certificate authority. Set this only if you
11163intend to use @samp{ssl-verify-client-cert? #t}. The file should
11164contain the CA certificate(s) followed by the matching
11165CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
11166Defaults to @samp{""}.
11167@end deftypevr
11168
11169@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
11170Require that CRL check succeeds for client certificates.
11171Defaults to @samp{#t}.
11172@end deftypevr
11173
11174@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
11175Request client to send a certificate. If you also want to require
11176it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
11177Defaults to @samp{#f}.
11178@end deftypevr
11179
11180@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
11181Which field from certificate to use for username. commonName and
11182x500UniqueIdentifier are the usual choices. You'll also need to set
11183@samp{auth-ssl-username-from-cert? #t}.
11184Defaults to @samp{"commonName"}.
11185@end deftypevr
11186
11187@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
11188How often to regenerate the SSL parameters file. Generation is
11189quite CPU intensive operation. The value is in hours, 0 disables
11190regeneration entirely.
11191Defaults to @samp{168}.
11192@end deftypevr
11193
11194@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
11195SSL protocols to use.
11196Defaults to @samp{"!SSLv2"}.
11197@end deftypevr
11198
11199@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
11200SSL ciphers to use.
11201Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
11202@end deftypevr
11203
11204@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
11205SSL crypto device to use, for valid values run "openssl engine".
11206Defaults to @samp{""}.
11207@end deftypevr
11208
11209@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
11210Address to use when sending rejection mails.
66329c23
AW
11211%d expands to recipient domain.
11212Defaults to @samp{"postmaster@@%d"}.
d8c18af8
AW
11213@end deftypevr
11214
11215@deftypevr {@code{dovecot-configuration} parameter} string hostname
11216Hostname to use in various parts of sent mails (e.g. in Message-Id)
11217and in LMTP replies. Default is the system's real hostname@@domain.
11218Defaults to @samp{""}.
11219@end deftypevr
11220
11221@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
11222If user is over quota, return with temporary failure instead of
11223bouncing the mail.
11224Defaults to @samp{#f}.
11225@end deftypevr
11226
11227@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
11228Binary to use for sending mails.
11229Defaults to @samp{"/usr/sbin/sendmail"}.
11230@end deftypevr
11231
11232@deftypevr {@code{dovecot-configuration} parameter} string submission-host
11233If non-empty, send mails via this SMTP host[:port] instead of
11234sendmail.
11235Defaults to @samp{""}.
11236@end deftypevr
11237
11238@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
11239Subject: header to use for rejection mails. You can use the same
11240variables as for @samp{rejection-reason} below.
11241Defaults to @samp{"Rejected: %s"}.
11242@end deftypevr
11243
11244@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
11245Human readable error message for rejection mails. You can use
11246variables:
11247
11248@table @code
11249@item %n
11250CRLF
11251@item %r
11252reason
11253@item %s
11254original subject
11255@item %t
11256recipient
11257@end table
11258Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
11259@end deftypevr
11260
11261@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
11262Delimiter character between local-part and detail in email
11263address.
11264Defaults to @samp{"+"}.
11265@end deftypevr
11266
11267@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
11268Header where the original recipient address (SMTP's RCPT TO:
11269address) is taken from if not available elsewhere. With dovecot-lda -a
11270parameter overrides this. A commonly used header for this is
11271X-Original-To.
11272Defaults to @samp{""}.
11273@end deftypevr
11274
11275@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
11276Should saving a mail to a nonexistent mailbox automatically create
11277it?.
11278Defaults to @samp{#f}.
11279@end deftypevr
11280
11281@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
11282Should automatically created mailboxes be also automatically
11283subscribed?.
11284Defaults to @samp{#f}.
11285@end deftypevr
11286
11287@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
11288Maximum IMAP command line length. Some clients generate very long
11289command lines with huge mailboxes, so you may need to raise this if you
11290get "Too long argument" or "IMAP command line too large" errors
11291often.
11292Defaults to @samp{64000}.
11293@end deftypevr
11294
11295@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
11296IMAP logout format string:
11297@table @code
11298@item %i
11299total number of bytes read from client
11300@item %o
11301total number of bytes sent to client.
11302@end table
11303Defaults to @samp{"in=%i out=%o"}.
11304@end deftypevr
11305
11306@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
11307Override the IMAP CAPABILITY response. If the value begins with '+',
11308add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
11309Defaults to @samp{""}.
11310@end deftypevr
11311
11312@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
11313How long to wait between "OK Still here" notifications when client
11314is IDLEing.
11315Defaults to @samp{"2 mins"}.
11316@end deftypevr
11317
11318@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
11319ID field names and values to send to clients. Using * as the value
11320makes Dovecot use the default value. The following fields have default
11321values currently: name, version, os, os-version, support-url,
11322support-email.
11323Defaults to @samp{""}.
11324@end deftypevr
11325
11326@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
11327ID fields sent by client to log. * means everything.
11328Defaults to @samp{""}.
11329@end deftypevr
11330
11331@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
11332Workarounds for various client bugs:
11333
11334@table @code
11335@item delay-newmail
11336Send EXISTS/RECENT new mail notifications only when replying to NOOP and
11337CHECK commands. Some clients ignore them otherwise, for example OSX
11338Mail (<v2.1). Outlook Express breaks more badly though, without this it
11339may show user "Message no longer in server" errors. Note that OE6
11340still breaks even with this workaround if synchronization is set to
11341"Headers Only".
11342
11343@item tb-extra-mailbox-sep
11344Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
11345adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
11346ignore the extra @samp{/} instead of treating it as invalid mailbox name.
11347
11348@item tb-lsub-flags
11349Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
11350This makes Thunderbird realize they aren't selectable and show them
11351greyed out, instead of only later giving "not selectable" popup error.
11352@end table
11353Defaults to @samp{()}.
11354@end deftypevr
11355
11356@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
11357Host allowed in URLAUTH URLs sent by client. "*" allows all.
11358Defaults to @samp{""}.
11359@end deftypevr
11360
11361
11362Whew! Lots of configuration options. The nice thing about it though is
11363that GuixSD has a complete interface to Dovecot's configuration
11364language. This allows not only a nice way to declare configurations,
11365but also offers reflective capabilities as well: users can write code to
11366inspect and transform configurations from within Scheme.
11367
11368However, it could be that you just want to get a @code{dovecot.conf} up
11369and running. In that case, you can pass an
7414de0a 11370@code{opaque-dovecot-configuration} as the @code{#:config} parameter to
d8c18af8
AW
11371@code{dovecot-service}. As its name indicates, an opaque configuration
11372does not have easy reflective capabilities.
11373
11374Available @code{opaque-dovecot-configuration} fields are:
11375
11376@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
11377The dovecot package.
11378@end deftypevr
11379
11380@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
11381The contents of the @code{dovecot.conf}, as a string.
11382@end deftypevr
11383
11384For example, if your @code{dovecot.conf} is just the empty string, you
11385could instantiate a dovecot service like this:
11386
11387@example
11388(dovecot-service #:config
11389 (opaque-dovecot-configuration
11390 (string "")))
11391@end example
11392
859e367d
JD
11393
11394@node Kerberos Services
11395@subsubsection Kerberos Services
11396@cindex Kerberos
11397
11398The @code{(gnu services Kerberos)} module provides services relating to
11399the authentication protocol @dfn{Kerberos}.
11400
11401@subsubheading PAM krb5 Service
11402@cindex pam-krb5
11403
11404The pam-krb5 service allows for login authentication and password
11405management via Kerberos.
11406You will need this service if you want PAM enabled applications to authenticate
11407users using Kerberos.
11408
11409@defvr {Scheme Variable} pam-krb5-service-type
11410A service type for the Kerberos 5 PAM module.
11411@end defvr
11412
11413@deftp {Data Type} pam-krb5-configuration
11414Data type representing the configuration of the Kerberos 5 PAM module
11415This type has the following parameters:
11416@table @asis
11417@item @code{pam-krb5} (default: @code{pam-krb5})
11418The pam-krb5 package to use.
11419
11420@item @code{minimum-uid} (default: @code{1000})
11421The smallest user ID for which Kerberos authentications should be attempted.
11422Local accounts with lower values will silently fail to authenticate.
11423@end table
11424@end deftp
11425
11426
58724c48
DT
11427@node Web Services
11428@subsubsection Web Services
11429
e32171ee
JD
11430@cindex web
11431@cindex www
11432@cindex HTTP
58724c48
DT
11433The @code{(gnu services web)} module provides the following service:
11434
be1c2c54 11435@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
11436 [#:log-directory ``/var/log/nginx''] @
11437 [#:run-directory ``/var/run/nginx''] @
8c00b838 11438 [#:vhost-list (list (nginx-vhost-configuration))] @
58724c48
DT
11439 [#:config-file]
11440
11441Return a service that runs @var{nginx}, the nginx web server.
11442
11443The nginx daemon loads its runtime configuration from @var{config-file}.
11444Log files are written to @var{log-directory} and temporary runtime data
11445files are written to @var{run-directory}. For proper operation, these
11446arguments should match what is in @var{config-file} to ensure that the
11447directories are created when the service is activated.
11448
8c00b838
JL
11449As an alternative to using a @var{config-file}, @var{vhost-list} can be
11450used to specify the list of @dfn{virtual hosts} required on the host. For
11451this to work, use the default value for @var{config-file}.
11452
58724c48
DT
11453@end deffn
11454
8c00b838
JL
11455@deftp {Data Type} nginx-vhost-configuration
11456Data type representing the configuration of an nginx virtual host.
11457This type has the following parameters:
11458
11459@table @asis
11460@item @code{http-port} (default: @code{80})
11461Nginx will listen for HTTP connection on this port. Set it at @code{#f} if
11462nginx should not listen for HTTP (non secure) connection for this
11463@dfn{virtual host}.
11464
11465@item @code{https-port} (default: @code{443})
11466Nginx will listen for HTTPS connection on this port. Set it at @code{#f} if
11467nginx should not listen for HTTPS (secure) connection for this @dfn{virtual host}.
11468
11469Note that nginx can listen for HTTP and HTTPS connections in the same
11470@dfn{virtual host}.
11471
11472@item @code{server-name} (default: @code{(list 'default)})
11473A list of server names this vhost represents. @code{'default} represents the
11474default vhost for connections matching no other vhost.
11475
11476@item @code{root} (default: @code{"/srv/http"})
11477Root of the website nginx will serve.
11478
11479@item @code{index} (default: @code{(list "index.html")})
11480Index files to look for when clients ask for a directory. If it cannot be found,
11481Nginx will send the list of files in the directory.
11482
11483@item @code{ssl-certificate} (default: @code{"/etc/nginx/cert.pem"})
11484Where to find the certificate for secure connections. Set it to @code{#f} if
11485you don't have a certificate or you don't want to use HTTPS.
11486
11487@item @code{ssl-certificate-key} (default: @code{"/etc/nginx/key.pem"})
11488Where to find the private key for secure connections. Set it to @code{#f} if
11489you don't have a key or you don't want to use HTTPS.
11490
11491@item @code{server-tokens?} (default: @code{#f})
11492Whether the server should add its configuration to response.
11493
11494@end table
11495@end deftp
11496
eb419bc9
JD
11497@node Network File System
11498@subsubsection Network File System
11499@cindex NFS
fe1a39d3 11500
eb419bc9
JD
11501The @code{(gnu services nfs)} module provides the following services,
11502which are most commonly used in relation to mounting or exporting
11503directory trees as @dfn{network file systems} (NFS).
d6a07ee6
JD
11504
11505@subsubheading RPC Bind Service
11506@cindex rpcbind
11507
eb419bc9
JD
11508The RPC Bind service provides a facility to map program numbers into
11509universal addresses.
11510Many NFS related services use this facility. Hence it is automatically
11511started when a dependent service starts.
d6a07ee6
JD
11512
11513@defvr {Scheme Variable} rpcbind-service-type
11514A service type for the RPC portmapper daemon.
11515@end defvr
11516
11517
11518@deftp {Data Type} rpcbind-configuration
11519Data type representing the configuration of the RPC Bind Service.
11520This type has the following parameters:
11521@table @asis
11522@item @code{rpcbind} (default: @code{rpcbind})
11523The rpcbind package to use.
11524
11525@item @code{warm-start?} (default: @code{#t})
11526If this parameter is @code{#t}, then the daemon will read a
11527state file on startup thus reloading state information saved by a previous
11528instance.
11529@end table
11530@end deftp
11531
eb419bc9
JD
11532
11533@subsubheading Pipefs Pseudo File System
11534@cindex pipefs
11535@cindex rpc_pipefs
11536
11537The pipefs file system is used to transfer NFS related data
11538between the kernel and user space programs.
11539
11540@defvr {Scheme Variable} pipefs-service-type
11541A service type for the pipefs pseudo file system.
11542@end defvr
11543
11544@deftp {Data Type} pipefs-configuration
11545Data type representing the configuration of the pipefs pseudo file system service.
11546This type has the following parameters:
11547@table @asis
11548@item @code{mount-point} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11549The directory to which the file system is to be attached.
11550@end table
11551@end deftp
11552
11553
11554@subsubheading GSS Daemon Service
11555@cindex GSSD
11556@cindex GSS
11557@cindex global security system
11558
11559The @dfn{global security system} (GSS) daemon provides strong security for RPC
11560based protocols.
11561Before exchanging RPC requests an RPC client must establish a security
11562context. Typically this is done using the Kerberos command @command{kinit}
859e367d 11563or automatically at login time using PAM services (@pxref{Kerberos Services}).
eb419bc9
JD
11564
11565@defvr {Scheme Variable} gss-service-type
11566A service type for the Global Security System (GSS) daemon.
11567@end defvr
11568
11569@deftp {Data Type} gss-configuration
11570Data type representing the configuration of the GSS daemon service.
11571This type has the following parameters:
11572@table @asis
11573@item @code{nfs-utils} (default: @code{nfs-utils})
11574The package in which the @command{rpc.gssd} command is to be found.
11575
11576@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11577The directory where the pipefs file system is mounted.
11578
11579@end table
11580@end deftp
11581
11582
11583@subsubheading IDMAP Daemon Service
11584@cindex idmapd
11585@cindex name mapper
11586
11587The idmap daemon service provides mapping between user IDs and user names.
11588Typically it is required in order to access file systems mounted via NFSv4.
11589
11590@defvr {Scheme Variable} idmap-service-type
11591A service type for the Identity Mapper (IDMAP) daemon.
11592@end defvr
11593
11594@deftp {Data Type} idmap-configuration
11595Data type representing the configuration of the IDMAP daemon service.
11596This type has the following parameters:
11597@table @asis
11598@item @code{nfs-utils} (default: @code{nfs-utils})
11599The package in which the @command{rpc.idmapd} command is to be found.
11600
11601@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11602The directory where the pipefs file system is mounted.
11603
11604@item @code{domain} (default: @code{#f})
11605The local NFSv4 domain name.
11606This must be a string or @code{#f}.
11607If it is @code{#f} then the daemon will use the host's fully qualified domain name.
11608
11609@end table
11610@end deftp
11611
11612
11613@node Miscellaneous Services
11614@subsubsection Miscellaneous Services
11615
11616
8ff4dcbe
DC
11617@cindex lirc
11618@subsubheading Lirc Service
11619
fe1a39d3
LC
11620The @code{(gnu services lirc)} module provides the following service.
11621
be1c2c54 11622@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
11623 [#:device #f] [#:driver #f] [#:config-file #f] @
11624 [#:extra-options '()]
11625Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
11626decodes infrared signals from remote controls.
11627
11628Optionally, @var{device}, @var{driver} and @var{config-file}
11629(configuration file name) may be specified. See @command{lircd} manual
11630for details.
11631
11632Finally, @var{extra-options} is a list of additional command-line options
11633passed to @command{lircd}.
11634@end deffn
11635
00f46905
DC
11636@cindex spice
11637@subsubheading Spice Service
11638
11639The @code{(gnu services spice)} module provides the following service.
11640
11641@deffn {Scheme Procedure} spice-vdagent-service [#:spice-vdagent]
11642Returns a service that runs @url{http://www.spice-space.org,VDAGENT}, a daemon
11643that enables sharing the clipboard with a vm and setting the guest display
11644resolution when the graphical console window resizes.
11645@end deffn
11646
c3d38b2b 11647@subsubsection Dictionary Services
e32171ee 11648@cindex dictionary
c3d38b2b
SB
11649The @code{(gnu services dict)} module provides the following service:
11650
11651@deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
11652Return a service that runs the @command{dicod} daemon, an implementation
11653of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
11654
11655The optional @var{config} argument specifies the configuration for
11656@command{dicod}, which should be a @code{<dicod-configuration>} object, by
11657default it serves the GNU Collaborative International Dictonary of English.
11658
11659You can add @command{open localhost} to your @file{~/.dico} file to make
11660@code{localhost} the default server for @command{dico} client
11661(@pxref{Initialization File,,, dico, GNU Dico Manual}).
11662@end deffn
11663
11664@deftp {Data Type} dicod-configuration
11665Data type representing the configuration of dicod.
11666
11667@table @asis
11668@item @code{dico} (default: @var{dico})
11669Package object of the GNU Dico dictionary server.
11670
a1b48465
LC
11671@item @code{interfaces} (default: @var{'("localhost")})
11672This is the list of IP addresses and ports and possibly socket file
11673names to listen to (@pxref{Server Settings, @code{listen} directive,,
11674dico, GNU Dico Manual}).
11675
c3d38b2b
SB
11676@item @code{databases} (default: @var{(list %dicod-database:gcide)})
11677List of @code{<dicod-database>} objects denoting dictionaries to be served.
11678@end table
11679@end deftp
11680
11681@deftp {Data Type} dicod-database
11682Data type representing a dictionary database.
11683
11684@table @asis
11685@item @code{name}
11686Name of the database, will be used in DICT commands.
11687
11688@item @code{module}
11689Name of the dicod module used by this database
11690(@pxref{Modules,,, dico, GNU Dico Manual}).
11691
11692@item @code{options}
11693List of strings or gexps representing the arguments for the module handler
11694(@pxref{Handlers,,, dico, GNU Dico Manual}).
11695@end table
11696@end deftp
11697
11698@defvr {Scheme Variable} %dicod-database:gcide
11699A @code{<dicod-database>} object serving the GNU Collaborative International
11700Dictonary of English using the @code{gcide} package.
11701@end defvr
fe1a39d3 11702
e01e2c6c 11703@subsubsection Version Control
11704
11705The @code{(gnu services version-control)} module provides the following services:
11706
11707@subsubheading Git daemon service
11708
11709@deffn {Scheme Procedure} git-daemon-service [#:config (git-daemon-configuration)]
11710
11711Return a service that runs @command{git daemon}, a simple TCP server to
11712expose repositiories over the Git protocol for annoymous access.
11713
11714The optional @var{config} argument should be a
11715@code{<git-daemon-configuration>} object, by default it allows read-only
11716access to exported@footnote{By creating the magic file
11717"git-daemon-export-ok" in the repository directory.} repositories under
11718@file{/srv/git}.
11719
11720@end deffn
11721
11722@deftp {Data Type} git-daemon-configuration
11723Data type representing the configuration for @code{git-daemon-service}.
11724
11725@table @asis
11726@item @code{package} (default: @var{git})
11727Package object of the Git distributed version control system.
11728
11729@item @code{export-all?} (default: @var{#f})
11730Whether to allow access for all Git repositories, even if they do not
11731have the @file{git-daemon-export-ok} file.
11732
11733@item @code{base-path} (default: @file{/srv/git})
11734Whether to remap all the path requests as relative to the given path.
11735If you run git daemon with @var{(base-path "/srv/git")} on example.com,
11736then if you later try to pull @code{git://example.com/hello.git}, git
11737daemon will interpret the path as @code{/srv/git/hello.git}.
11738
11739@item @code{user-path} (default: @var{#f})
11740Whether to allow @code{~user} notation to be used in requests. When
11741specified with empty string, requests to @code{git://host/~alice/foo} is
11742taken as a request to access @code{foo} repository in the home directory
11743of user @code{alice}. If @var{(user-path "path")} is specified, the
11744same request is taken as a request to access @code{path/foo} repository
11745in the home directory of user @code{alice}.
11746
11747@item @code{listen} (default: @var{'()})
11748Whether to listen on specific IP addresses or hostnames, defaults to
11749all.
11750
11751@item @code{port} (default: @var{#f})
11752Whether to listen on an alternative port, which defaults to 9418.
11753
11754@item @code{whitelist} (default: @var{'()})
11755If not empty, only allow access to this list of directories.
11756
11757@item @code{extra-options} (default: @var{'()})
11758Extra options will be passed to @code{git daemon}, please run
11759@command{man git-daemon} for more information.
11760
11761@end table
11762@end deftp
11763
0ae8c15a
LC
11764@node Setuid Programs
11765@subsection Setuid Programs
11766
11767@cindex setuid programs
11768Some programs need to run with ``root'' privileges, even when they are
11769launched by unprivileged users. A notorious example is the
4d40227c
LC
11770@command{passwd} program, which users can run to change their
11771password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
11772@file{/etc/shadow} files---something normally restricted to root, for
11773obvious security reasons. To address that, these executables are
11774@dfn{setuid-root}, meaning that they always run with root privileges
11775(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 11776for more info about the setuid mechanism.)
0ae8c15a
LC
11777
11778The store itself @emph{cannot} contain setuid programs: that would be a
11779security issue since any user on the system can write derivations that
11780populate the store (@pxref{The Store}). Thus, a different mechanism is
11781used: instead of changing the setuid bit directly on files that are in
11782the store, we let the system administrator @emph{declare} which programs
11783should be setuid root.
11784
11785The @code{setuid-programs} field of an @code{operating-system}
11786declaration contains a list of G-expressions denoting the names of
11787programs to be setuid-root (@pxref{Using the Configuration System}).
11788For instance, the @command{passwd} program, which is part of the Shadow
11789package, can be designated by this G-expression (@pxref{G-Expressions}):
11790
11791@example
11792#~(string-append #$shadow "/bin/passwd")
11793@end example
11794
11795A default set of setuid programs is defined by the
11796@code{%setuid-programs} variable of the @code{(gnu system)} module.
11797
11798@defvr {Scheme Variable} %setuid-programs
11799A list of G-expressions denoting common programs that are setuid-root.
11800
11801The list includes commands such as @command{passwd}, @command{ping},
11802@command{su}, and @command{sudo}.
11803@end defvr
11804
11805Under the hood, the actual setuid programs are created in the
11806@file{/run/setuid-programs} directory at system activation time. The
11807files in this directory refer to the ``real'' binaries, which are in the
11808store.
11809
efb5e833
LC
11810@node X.509 Certificates
11811@subsection X.509 Certificates
11812
11813@cindex HTTPS, certificates
11814@cindex X.509 certificates
11815@cindex TLS
11816Web servers available over HTTPS (that is, HTTP over the transport-layer
11817security mechanism, TLS) send client programs an @dfn{X.509 certificate}
11818that the client can then use to @emph{authenticate} the server. To do
11819that, clients verify that the server's certificate is signed by a
11820so-called @dfn{certificate authority} (CA). But to verify the CA's
11821signature, clients must have first acquired the CA's certificate.
11822
11823Web browsers such as GNU@tie{}IceCat include their own set of CA
11824certificates, such that they are able to verify CA signatures
11825out-of-the-box.
11826
11827However, most other programs that can talk HTTPS---@command{wget},
11828@command{git}, @command{w3m}, etc.---need to be told where CA
11829certificates can be found.
11830
11831@cindex @code{nss-certs}
11832In GuixSD, this is done by adding a package that provides certificates
11833to the @code{packages} field of the @code{operating-system} declaration
11834(@pxref{operating-system Reference}). GuixSD includes one such package,
11835@code{nss-certs}, which is a set of CA certificates provided as part of
11836Mozilla's Network Security Services.
11837
11838Note that it is @emph{not} part of @var{%base-packages}, so you need to
11839explicitly add it. The @file{/etc/ssl/certs} directory, which is where
11840most applications and libraries look for certificates by default, points
11841to the certificates installed globally.
11842
b3129f2b
LC
11843Unprivileged users, including users of Guix on a foreign distro,
11844can also install their own certificate package in
efb5e833
LC
11845their profile. A number of environment variables need to be defined so
11846that applications and libraries know where to find them. Namely, the
11847OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
11848variables. Some applications add their own environment variables; for
11849instance, the Git version control system honors the certificate bundle
b3129f2b
LC
11850pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
11851would typically run something like:
efb5e833 11852
b3129f2b
LC
11853@example
11854$ guix package -i nss-certs
11855$ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
11856$ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
11857$ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
11858@end example
efb5e833 11859
996ed739
LC
11860@node Name Service Switch
11861@subsection Name Service Switch
11862
11863@cindex name service switch
11864@cindex NSS
11865The @code{(gnu system nss)} module provides bindings to the
1068f26b 11866configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
11867(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
11868Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
11869extended with new ``name'' lookup methods for system databases, which
11870includes host names, service names, user accounts, and more (@pxref{Name
11871Service Switch, System Databases and Name Service Switch,, libc, The GNU
11872C Library Reference Manual}).
11873
11874The NSS configuration specifies, for each system database, which lookup
11875method is to be used, and how the various methods are chained
11876together---for instance, under which circumstances NSS should try the
11877next method in the list. The NSS configuration is given in the
11878@code{name-service-switch} field of @code{operating-system} declarations
11879(@pxref{operating-system Reference, @code{name-service-switch}}).
11880
4c9050c6
LC
11881@cindex nss-mdns
11882@cindex .local, host name lookup
996ed739 11883As an example, the declaration below configures the NSS to use the
4c9050c6
LC
11884@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
11885back-end}, which supports host name lookups over multicast DNS (mDNS)
11886for host names ending in @code{.local}:
996ed739
LC
11887
11888@example
11889(name-service-switch
11890 (hosts (list %files ;first, check /etc/hosts
11891
11892 ;; If the above did not succeed, try
11893 ;; with 'mdns_minimal'.
11894 (name-service
11895 (name "mdns_minimal")
11896
11897 ;; 'mdns_minimal' is authoritative for
11898 ;; '.local'. When it returns "not found",
11899 ;; no need to try the next methods.
11900 (reaction (lookup-specification
11901 (not-found => return))))
11902
11903 ;; Then fall back to DNS.
11904 (name-service
11905 (name "dns"))
11906
11907 ;; Finally, try with the "full" 'mdns'.
11908 (name-service
11909 (name "mdns")))))
11910@end example
11911
1068f26b
AE
11912Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
11913contains this configuration, so you will not have to type it if all you
15137a29
LC
11914want is to have @code{.local} host lookup working.
11915
4c9050c6
LC
11916Note that, in this case, in addition to setting the
11917@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
11918you also need to use @code{avahi-service} (@pxref{Networking Services,
11919@code{avahi-service}}), or @var{%desktop-services}, which includes it
11920(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
11921to the name service cache daemon (@pxref{Base Services,
11922@code{nscd-service}}).
15137a29
LC
11923
11924For convenience, the following variables provide typical NSS
11925configurations.
11926
11927@defvr {Scheme Variable} %default-nss
11928This is the default name service switch configuration, a
11929@code{name-service-switch} object.
11930@end defvr
11931
11932@defvr {Scheme Variable} %mdns-host-lookup-nss
11933This is the name service switch configuration with support for host name
11934lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
11935@end defvr
4c9050c6 11936
996ed739 11937The reference for name service switch configuration is given below. It
1068f26b 11938is a direct mapping of the configuration file format of the C library , so
996ed739
LC
11939please refer to the C library manual for more information (@pxref{NSS
11940Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 11941Compared to the configuration file format of libc NSS, it has the advantage
996ed739 11942not only of adding this warm parenthetic feel that we like, but also
1068f26b 11943static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
11944run @command{guix system}.
11945
996ed739
LC
11946@deftp {Data Type} name-service-switch
11947
11948This is the data type representation the configuration of libc's name
11949service switch (NSS). Each field below represents one of the supported
11950system databases.
11951
11952@table @code
11953@item aliases
11954@itemx ethers
11955@itemx group
11956@itemx gshadow
11957@itemx hosts
11958@itemx initgroups
11959@itemx netgroup
11960@itemx networks
11961@itemx password
11962@itemx public-key
11963@itemx rpc
11964@itemx services
11965@itemx shadow
11966The system databases handled by the NSS. Each of these fields must be a
1068f26b 11967list of @code{<name-service>} objects (see below).
996ed739
LC
11968@end table
11969@end deftp
11970
11971@deftp {Data Type} name-service
11972
11973This is the data type representing an actual name service and the
11974associated lookup action.
11975
11976@table @code
11977@item name
11978A string denoting the name service (@pxref{Services in the NSS
11979configuration,,, libc, The GNU C Library Reference Manual}).
11980
4aee6e60
LC
11981Note that name services listed here must be visible to nscd. This is
11982achieved by passing the @code{#:name-services} argument to
11983@code{nscd-service} the list of packages providing the needed name
11984services (@pxref{Base Services, @code{nscd-service}}).
11985
996ed739
LC
11986@item reaction
11987An action specified using the @code{lookup-specification} macro
11988(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
11989Reference Manual}). For example:
11990
11991@example
11992(lookup-specification (unavailable => continue)
11993 (success => return))
11994@end example
11995@end table
11996@end deftp
0ae8c15a 11997
fd1b1fa2
LC
11998@node Initial RAM Disk
11999@subsection Initial RAM Disk
12000
e32171ee
JD
12001@cindex initrd
12002@cindex initial RAM disk
fd1b1fa2
LC
12003For bootstrapping purposes, the Linux-Libre kernel is passed an
12004@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 12005root file system as well as an initialization script. The latter is
fd1b1fa2
LC
12006responsible for mounting the real root file system, and for loading any
12007kernel modules that may be needed to achieve that.
12008
12009The @code{initrd} field of an @code{operating-system} declaration allows
12010you to specify which initrd you would like to use. The @code{(gnu
12011system linux-initrd)} module provides two ways to build an initrd: the
12012high-level @code{base-initrd} procedure, and the low-level
12013@code{expression->initrd} procedure.
12014
12015The @code{base-initrd} procedure is intended to cover most common uses.
12016For example, if you want to add a bunch of kernel modules to be loaded
12017at boot time, you can define the @code{initrd} field of the operating
12018system declaration like this:
12019
12020@example
52ac153e 12021(initrd (lambda (file-systems . rest)
027981d6
LC
12022 ;; Create a standard initrd that has modules "foo.ko"
12023 ;; and "bar.ko", as well as their dependencies, in
12024 ;; addition to the modules available by default.
52ac153e 12025 (apply base-initrd file-systems
027981d6 12026 #:extra-modules '("foo" "bar")
52ac153e 12027 rest)))
fd1b1fa2
LC
12028@end example
12029
52ac153e 12030The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
12031involves using the system as a QEMU guest, or as a ``live'' system with
12032volatile root file system.
fd1b1fa2 12033
e90cf6c1
LC
12034The initial RAM disk produced by @code{base-initrd} honors several
12035options passed on the Linux kernel command line (that is, arguments
1068f26b 12036passed @i{via} the @code{linux} command of GRUB, or the
4af2fafd 12037@code{-append} option of QEMU), notably:
e90cf6c1
LC
12038
12039@table @code
12040@item --load=@var{boot}
12041Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
12042program, once it has mounted the root file system.
12043
12044GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 12045service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
12046initialization system.
12047
12048@item --root=@var{root}
1068f26b 12049Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
12050device name like @code{/dev/sda1}, a partition label, or a partition
12051UUID.
12052
12053@item --system=@var{system}
12054Have @file{/run/booted-system} and @file{/run/current-system} point to
12055@var{system}.
12056
12057@item modprobe.blacklist=@var{modules}@dots{}
12058@cindex module, black-listing
12059@cindex black list, of kernel modules
12060Instruct the initial RAM disk as well as the @command{modprobe} command
12061(from the kmod package) to refuse to load @var{modules}. @var{modules}
12062must be a comma-separated list of module names---e.g.,
12063@code{usbkbd,9pnet}.
12064
12065@item --repl
12066Start a read-eval-print loop (REPL) from the initial RAM disk before it
12067tries to load kernel modules and to mount the root file system. Our
12068marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
12069love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
12070Manual}, for more information on Guile's REPL.
12071
12072@end table
12073
12074Now that you know all the features that initial RAM disks produced by
12075@code{base-initrd} provide, here is how to use it and customize it
12076further.
12077
e32171ee
JD
12078@cindex initrd
12079@cindex initial RAM disk
fd1b1fa2 12080@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 12081 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 12082 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2 12083Return a monadic derivation that builds a generic initrd. @var{file-systems} is
1068f26b 12084a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 12085the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
12086@var{mapped-devices} is a list of device mappings to realize before
12087@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
12088
12089When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
12090parameters. When @var{virtio?} is true, load additional modules so that the
12091initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
12092
12093When @var{volatile-root?} is true, the root file system is writable but any changes
12094to it are lost.
12095
12096The initrd is automatically populated with all the kernel modules necessary
12097for @var{file-systems} and for the given options. However, additional kernel
12098modules can be listed in @var{extra-modules}. They will be added to the initrd, and
12099loaded at boot time in the order in which they appear.
12100@end deffn
12101
12102Needless to say, the initrds we produce and use embed a
12103statically-linked Guile, and the initialization program is a Guile
12104program. That gives a lot of flexibility. The
12105@code{expression->initrd} procedure builds such an initrd, given the
12106program to run in that initrd.
12107
12108@deffn {Monadic Procedure} expression->initrd @var{exp} @
4ee96a79 12109 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
fd1b1fa2
LC
12110Return a derivation that builds a Linux initrd (a gzipped cpio archive)
12111containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
12112upon booting. All the derivations referenced by @var{exp} are
12113automatically copied to the initrd.
fd1b1fa2
LC
12114@end deffn
12115
88faf933
LC
12116@node GRUB Configuration
12117@subsection GRUB Configuration
12118
12119@cindex GRUB
12120@cindex boot loader
12121
12122The operating system uses GNU@tie{}GRUB as its boot loader
12123(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
12124configured using a @code{grub-configuration} declaration. This data type
12125is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
12126
12127@deftp {Data Type} grub-configuration
12128The type of a GRUB configuration declaration.
12129
12130@table @asis
12131
12132@item @code{device}
12133This is a string denoting the boot device. It must be a device name
12134understood by the @command{grub-install} command, such as
12135@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
12136GNU GRUB Manual}).
12137
12138@item @code{menu-entries} (default: @code{()})
12139A possibly empty list of @code{menu-entry} objects (see below), denoting
12140entries to appear in the GRUB boot menu, in addition to the current
12141system entry and the entry pointing to previous system generations.
12142
12143@item @code{default-entry} (default: @code{0})
1068f26b
AE
12144The index of the default boot menu entry. Index 0 is for the entry of the
12145current system.
88faf933
LC
12146
12147@item @code{timeout} (default: @code{5})
12148The number of seconds to wait for keyboard input before booting. Set to
121490 to boot immediately, and to -1 to wait indefinitely.
12150
12151@item @code{theme} (default: @var{%default-theme})
12152The @code{grub-theme} object describing the theme to use.
12153@end table
12154
12155@end deftp
12156
44d5f54e
LC
12157@cindex dual boot
12158@cindex boot menu
88faf933
LC
12159Should you want to list additional boot menu entries @i{via} the
12160@code{menu-entries} field above, you will need to create them with the
44d5f54e
LC
12161@code{menu-entry} form. For example, imagine you want to be able to
12162boot another distro (hard to imagine!), you can define a menu entry
12163along these lines:
12164
12165@example
12166(menu-entry
12167 (label "The Other Distro")
12168 (linux "/boot/old/vmlinux-2.6.32")
12169 (linux-arguments '("root=/dev/sda2"))
12170 (initrd "/boot/old/initrd"))
12171@end example
12172
12173Details below.
88faf933
LC
12174
12175@deftp {Data Type} menu-entry
12176The type of an entry in the GRUB boot menu.
12177
12178@table @asis
12179
12180@item @code{label}
35ed9306 12181The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
12182
12183@item @code{linux}
44d5f54e
LC
12184The Linux kernel image to boot, for example:
12185
12186@example
12187(file-append linux-libre "/bzImage")
12188@end example
88faf933 12189
1ef8b72a
CM
12190It is also possible to specify a device explicitly in the file path
12191using GRUB's device naming convention (@pxref{Naming convention,,, grub,
12192GNU GRUB manual}), for example:
12193
12194@example
12195"(hd0,msdos1)/boot/vmlinuz"
12196@end example
12197
12198If the device is specified explicitly as above, then the @code{device}
12199field is ignored entirely.
12200
88faf933
LC
12201@item @code{linux-arguments} (default: @code{()})
12202The list of extra Linux kernel command-line arguments---e.g.,
12203@code{("console=ttyS0")}.
12204
12205@item @code{initrd}
12206A G-Expression or string denoting the file name of the initial RAM disk
12207to use (@pxref{G-Expressions}).
12208
1ef8b72a
CM
12209@item @code{device} (default: @code{#f})
12210The device where the kernel and initrd are to be found---i.e., the GRUB
12211@dfn{root} for this menu entry (@pxref{root,,, grub, GNU GRUB manual}).
12212
12213This may be a file system label (a string), a file system UUID (a
12214bytevector, @pxref{File Systems}), or @code{#f}, in which case GRUB will
12215search the device containing the file specified by the @code{linux}
12216field (@pxref{search,,, grub, GNU GRUB manual}). It must @emph{not} be
12217an OS device name such as @file{/dev/sda1}.
12218
12219@item @code{device-mount-point} (default: @code{"/"})
12220The mount point of the above device on the system. You probably do not
12221need to change the default value. GuixSD uses it to strip the prefix of
12222store file names for systems where @file{/gnu} or @file{/gnu/store} is
12223on a separate partition.
12224
88faf933
LC
12225@end table
12226@end deftp
12227
12228@c FIXME: Write documentation once it's stable.
12229Themes are created using the @code{grub-theme} form, which is not
12230documented yet.
12231
12232@defvr {Scheme Variable} %default-theme
12233This is the default GRUB theme used by the operating system, with a
12234fancy background image displaying the GNU and Guix logos.
12235@end defvr
12236
12237
cf4a9129
LC
12238@node Invoking guix system
12239@subsection Invoking @code{guix system}
0918e64a 12240
1068f26b 12241Once you have written an operating system declaration as seen in the
cf4a9129
LC
12242previous section, it can be @dfn{instantiated} using the @command{guix
12243system} command. The synopsis is:
4af2447e 12244
cf4a9129
LC
12245@example
12246guix system @var{options}@dots{} @var{action} @var{file}
12247@end example
4af2447e 12248
cf4a9129
LC
12249@var{file} must be the name of a file containing an
12250@code{operating-system} declaration. @var{action} specifies how the
a40424bd 12251operating system is instantiated. Currently the following values are
cf4a9129 12252supported:
4af2447e 12253
cf4a9129
LC
12254@table @code
12255@item reconfigure
12256Build the operating system described in @var{file}, activate it, and
8074b330
CM
12257switch to it@footnote{This action (and the related actions
12258@code{switch-generation} and @code{roll-back}) are usable only on
12259systems already running GuixSD.}.
4af2447e 12260
cf4a9129
LC
12261This effects all the configuration specified in @var{file}: user
12262accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
12263The command starts system services specified in @var{file} that are not
12264currently running; if a service is currently running, it does not
1068f26b 12265attempt to upgrade it since this would not be possible without stopping it
240b57f0 12266first.
4af2447e 12267
cf4a9129
LC
12268It also adds a GRUB menu entry for the new OS configuration, and moves
12269entries for older configurations to a submenu---unless
12270@option{--no-grub} is passed.
4af2447e 12271
240b57f0 12272@quotation Note
bf2479c7
LC
12273@c The paragraph below refers to the problem discussed at
12274@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
12275It is highly recommended to run @command{guix pull} once before you run
12276@command{guix system reconfigure} for the first time (@pxref{Invoking
12277guix pull}). Failing to do that you would see an older version of Guix
12278once @command{reconfigure} has completed.
240b57f0 12279@end quotation
bf2479c7 12280
8074b330 12281@item switch-generation
e32171ee 12282@cindex generations
8074b330
CM
12283Switch to an existing system generation. This action atomically
12284switches the system profile to the specified system generation. It also
12285rearranges the system's existing GRUB menu entries. It makes the menu
12286entry for the specified system generation the default, and it moves the
12287entries for the other generations to a submenu. The next time the
12288system boots, it will use the specified system generation.
12289
12290The target generation can be specified explicitly by its generation
12291number. For example, the following invocation would switch to system
12292generation 7:
12293
12294@example
12295guix system switch-generation 7
12296@end example
12297
12298The target generation can also be specified relative to the current
12299generation with the form @code{+N} or @code{-N}, where @code{+3} means
12300``3 generations ahead of the current generation,'' and @code{-1} means
12301``1 generation prior to the current generation.'' When specifying a
12302negative value such as @code{-1}, you must precede it with @code{--} to
12303prevent it from being parsed as an option. For example:
12304
12305@example
12306guix system switch-generation -- -1
12307@end example
12308
12309Currently, the effect of invoking this action is @emph{only} to switch
12310the system profile to an existing generation and rearrange the GRUB menu
12311entries. To actually start using the target system generation, you must
12312reboot after running this action. In the future, it will be updated to
12313do the same things as @command{reconfigure}, like activating and
12314deactivating services.
12315
12316This action will fail if the specified generation does not exist.
12317
12318@item roll-back
e32171ee 12319@cindex rolling back
8074b330
CM
12320Switch to the preceding system generation. The next time the system
12321boots, it will use the preceding system generation. This is the inverse
12322of @command{reconfigure}, and it is exactly the same as invoking
12323@command{switch-generation} with an argument of @code{-1}.
12324
12325Currently, as with @command{switch-generation}, you must reboot after
12326running this action to actually start using the preceding system
12327generation.
12328
cf4a9129 12329@item build
1068f26b 12330Build the derivation of the operating system, which includes all the
cf4a9129
LC
12331configuration files and programs needed to boot and run the system.
12332This action does not actually install anything.
113daf62 12333
cf4a9129
LC
12334@item init
12335Populate the given directory with all the files necessary to run the
12336operating system specified in @var{file}. This is useful for first-time
4705641f 12337installations of GuixSD. For instance:
113daf62
LC
12338
12339@example
cf4a9129 12340guix system init my-os-config.scm /mnt
113daf62
LC
12341@end example
12342
cf4a9129
LC
12343copies to @file{/mnt} all the store items required by the configuration
12344specified in @file{my-os-config.scm}. This includes configuration
12345files, packages, and so on. It also creates other essential files
12346needed for the system to operate correctly---e.g., the @file{/etc},
12347@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 12348
cf4a9129
LC
12349This command also installs GRUB on the device specified in
12350@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 12351
cf4a9129
LC
12352@item vm
12353@cindex virtual machine
0276f697 12354@cindex VM
f535dcbe 12355@anchor{guix system vm}
1068f26b 12356Build a virtual machine that contains the operating system declared in
cf4a9129 12357@var{file}, and return a script to run that virtual machine (VM).
1068f26b 12358Arguments given to the script are passed to QEMU.
113daf62 12359
cf4a9129 12360The VM shares its store with the host system.
113daf62 12361
0276f697
LC
12362Additional file systems can be shared between the host and the VM using
12363the @code{--share} and @code{--expose} command-line options: the former
12364specifies a directory to be shared with write access, while the latter
12365provides read-only access to the shared directory.
12366
12367The example below creates a VM in which the user's home directory is
12368accessible read-only, and where the @file{/exchange} directory is a
1068f26b 12369read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
12370
12371@example
12372guix system vm my-config.scm \
12373 --expose=$HOME --share=$HOME/tmp=/exchange
12374@end example
12375
6aa260af
LC
12376On GNU/Linux, the default is to boot directly to the kernel; this has
12377the advantage of requiring only a very tiny root disk image since the
1068f26b 12378store of the host can then be mounted.
6aa260af
LC
12379
12380The @code{--full-boot} option forces a complete boot sequence, starting
12381with the bootloader. This requires more disk space since a root image
12382containing at least the kernel, initrd, and bootloader data files must
12383be created. The @code{--image-size} option can be used to specify the
1068f26b 12384size of the image.
ab11f0be 12385
cf4a9129
LC
12386@item vm-image
12387@itemx disk-image
12388Return a virtual machine or disk image of the operating system declared
12389in @var{file} that stands alone. Use the @option{--image-size} option
12390to specify the size of the image.
113daf62 12391
cf4a9129 12392When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
12393the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
12394for more information on how to run the image in a virtual machine.
113daf62 12395
cf4a9129
LC
12396When using @code{disk-image}, a raw disk image is produced; it can be
12397copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 12398the device corresponding to a USB stick, one can copy the image to it
cf4a9129 12399using the following command:
113daf62 12400
cf4a9129
LC
12401@example
12402# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
12403@end example
113daf62 12404
1c8a81b1
DT
12405@item container
12406Return a script to run the operating system declared in @var{file}
12407within a container. Containers are a set of lightweight isolation
12408mechanisms provided by the kernel Linux-libre. Containers are
12409substantially less resource-demanding than full virtual machines since
12410the kernel, shared objects, and other resources can be shared with the
12411host system; this also means they provide thinner isolation.
12412
12413Currently, the script must be run as root in order to support more than
12414a single user and group. The container shares its store with the host
12415system.
12416
12417As with the @code{vm} action (@pxref{guix system vm}), additional file
12418systems to be shared between the host and container can be specified
12419using the @option{--share} and @option{--expose} options:
12420
12421@example
12422guix system container my-config.scm \
12423 --expose=$HOME --share=$HOME/tmp=/exchange
12424@end example
12425
0f252e26 12426@quotation Note
cfd35b4e 12427This option requires Linux-libre 3.19 or newer.
0f252e26
DT
12428@end quotation
12429
cf4a9129 12430@end table
113daf62 12431
ccd7158d
LC
12432@var{options} can contain any of the common build options (@pxref{Common
12433Build Options}). In addition, @var{options} can contain one of the
12434following:
113daf62 12435
cf4a9129
LC
12436@table @option
12437@item --system=@var{system}
12438@itemx -s @var{system}
1068f26b 12439Attempt to build for @var{system} instead of the host system type.
cf4a9129 12440This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 12441
f3f427c2
LC
12442@item --derivation
12443@itemx -d
12444Return the derivation file name of the given operating system without
12445building anything.
12446
cf4a9129
LC
12447@item --image-size=@var{size}
12448For the @code{vm-image} and @code{disk-image} actions, create an image
12449of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
12450include a unit as a suffix (@pxref{Block size, size specifications,,
12451coreutils, GNU Coreutils}).
db030303
LC
12452
12453@item --on-error=@var{strategy}
12454Apply @var{strategy} when an error occurs when reading @var{file}.
12455@var{strategy} may be one of the following:
12456
12457@table @code
12458@item nothing-special
12459Report the error concisely and exit. This is the default strategy.
12460
12461@item backtrace
12462Likewise, but also display a backtrace.
12463
12464@item debug
12465Report the error and enter Guile's debugger. From there, you can run
12466commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
12467display local variable values, and more generally inspect the state of the
12468program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
12469a list of available debugging commands.
12470@end table
113daf62 12471@end table
113daf62 12472
eca69fc0
LC
12473@quotation Note
12474All the actions above, except @code{build} and @code{init},
12475can use KVM support in the Linux-libre kernel. Specifically, if the
12476machine has hardware virtualization support, the corresponding
cf4a9129 12477KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b 12478must exist and be readable and writable by the user and by the
eca69fc0
LC
12479build users of the daemon (@pxref{Build Environment Setup}).
12480@end quotation
8451a568 12481
65797bff
LC
12482Once you have built, configured, re-configured, and re-re-configured
12483your GuixSD installation, you may find it useful to list the operating
12484system generations available on disk---and that you can choose from the
12485GRUB boot menu:
12486
12487@table @code
12488
12489@item list-generations
12490List a summary of each generation of the operating system available on
12491disk, in a human-readable way. This is similar to the
12492@option{--list-generations} option of @command{guix package}
12493(@pxref{Invoking guix package}).
12494
12495Optionally, one can specify a pattern, with the same syntax that is used
12496in @command{guix package --list-generations}, to restrict the list of
12497generations displayed. For instance, the following command displays
1068f26b 12498generations that are up to 10 days old:
65797bff
LC
12499
12500@example
12501$ guix system list-generations 10d
12502@end example
12503
12504@end table
12505
d6c3267a
LC
12506The @command{guix system} command has even more to offer! The following
12507sub-commands allow you to visualize how your system services relate to
12508each other:
12509
12510@anchor{system-extension-graph}
12511@table @code
12512
12513@item extension-graph
12514Emit in Dot/Graphviz format to standard output the @dfn{service
12515extension graph} of the operating system defined in @var{file}
12516(@pxref{Service Composition}, for more information on service
12517extensions.)
12518
12519The command:
12520
12521@example
12522$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
12523@end example
12524
12525produces a PDF file showing the extension relations among services.
12526
710fa231
AK
12527@anchor{system-shepherd-graph}
12528@item shepherd-graph
6f305ea5 12529Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
12530graph} of shepherd services of the operating system defined in
12531@var{file}. @xref{Shepherd Services}, for more information and for an
12532example graph.
6f305ea5 12533
d6c3267a
LC
12534@end table
12535
97d76250 12536@node Running GuixSD in a VM
70ac09a5 12537@subsection Running GuixSD in a Virtual Machine
97d76250 12538
e32171ee 12539@cindex virtual machine
97d76250
LF
12540One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
12541virtual machine image using @command{guix system vm-image}
12542(@pxref{Invoking guix system}). The returned image is in qcow2 format,
12543which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
12544
e32171ee 12545@cindex QEMU
97d76250
LF
12546To run the image in QEMU, copy it out of the store (@pxref{The Store})
12547and give yourself permission to write to the copy. When invoking QEMU,
12548you must choose a system emulator that is suitable for your hardware
12549platform. Here is a minimal QEMU invocation that will boot the result
12550of @command{guix system vm-image} on x86_64 hardware:
12551
12552@example
12553$ qemu-system-x86_64 \
12554 -net user -net nic,model=virtio \
12555 -enable-kvm -m 256 /tmp/qemu-image
12556@end example
12557
12558Here is what each of these options means:
12559
12560@table @code
12561@item qemu-system-x86_64
12562This specifies the hardware platform to emulate. This should match the
12563host.
12564
12565@item -net user
12566Enable the unprivileged user-mode network stack. The guest OS can
12567access the host but not vice versa. This is the simplest way to get the
1068f26b 12568guest OS online. If you do not choose a network stack, the boot will
97d76250
LF
12569fail.
12570
12571@item -net nic,model=virtio
1068f26b 12572You must create a network interface of a given model. If you do not
97d76250
LF
12573create a NIC, the boot will fail. Assuming your hardware platform is
12574x86_64, you can get a list of available NIC models by running
12575@command{qemu-system-x86_64 -net nic,model=help}.
12576
12577@item -enable-kvm
12578If your system has hardware virtualization extensions, enabling the
1068f26b 12579virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
12580faster.
12581
12582@item -m 256
12583RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
7414de0a 12584which may be insufficient for some operations.
97d76250
LF
12585
12586@item /tmp/qemu-image
12587The file name of the qcow2 image.
12588@end table
d6c3267a 12589
3ddc50db
DC
12590The default @command{run-vm.sh} script that is returned by an invokation of
12591@command{guix system vm} does not add a @command{-net user} flag by default.
12592To get network access from within the vm add the @code{(dhcp-client-service)}
12593to your system definition and start the VM using
12594@command{`guix system vm config.scm` -net user}. An important caveat of using
12595@command{-net user} for networking is that @command{ping} will not work, because
12596it uses the ICMP protocol. You'll have to use a different command to check for
12597network connectivity, like for example @command{curl}.
12598
12599@subsubsection Connecting Through SSH
12600
e32171ee
JD
12601@cindex SSH
12602@cindex SSH server
3ddc50db
DC
12603To enable SSH inside a VM you need to add a SSH server like @code{(dropbear-service)}
12604or @code{(lsh-service)} to your VM. The @code{(lsh-service}) doesn't currently
12605boot unsupervised. It requires you to type some characters to initialize the
12606randomness generator. In addition you need to forward the SSH port, 22 by
12607default, to the host. You can do this with
12608
12609@example
12610`guix system vm config.scm` -net user,hostfwd=tcp::10022-:22
12611@end example
12612
12613To connect to the VM you can run
12614
12615@example
12616ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022
12617@end example
12618
12619The @command{-p} tells @command{ssh} the port you want to connect to.
12620@command{-o UserKnownHostsFile=/dev/null} prevents @command{ssh} from complaining
12621every time you modify your @command{config.scm} file and the
12622@command{-o StrictHostKeyChecking=no} prevents you from having to allow a
12623connection to an unknown host every time you connect.
12624
12625@subsubsection Using @command{virt-viewer} with Spice
12626
12627As an alternative to the default @command{qemu} graphical client you can
12628use the @command{remote-viewer} from the @command{virt-viewer} package. To
12629connect pass the @command{-spice port=5930,disable-ticketing} flag to
12630@command{qemu}. See previous section for further information on how to do this.
12631
12632Spice also allows you to do some nice stuff like share your clipboard with your
12633VM. To enable that you'll also have to pass the following flags to @command{qemu}:
12634
12635@example
12636-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5
12637-chardev spicevmc,name=vdagent,id=vdagent
12638-device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,
12639name=com.redhat.spice.0
12640@end example
12641
12642You'll also need to add the @pxref{Miscellaneous Services, Spice service}.
12643
cf4a9129
LC
12644@node Defining Services
12645@subsection Defining Services
8451a568 12646
eb524192 12647The previous sections show the available services and how one can combine
0adfe95a
LC
12648them in an @code{operating-system} declaration. But how do we define
12649them in the first place? And what is a service anyway?
8451a568 12650
0adfe95a
LC
12651@menu
12652* Service Composition:: The model for composing services.
12653* Service Types and Services:: Types and services.
12654* Service Reference:: API reference.
dd17bc38 12655* Shepherd Services:: A particular type of service.
0adfe95a
LC
12656@end menu
12657
12658@node Service Composition
12659@subsubsection Service Composition
12660
12661@cindex services
12662@cindex daemons
12663Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 12664functionality of the operating system. Often a service is a process---a
0adfe95a
LC
12665@dfn{daemon}---started when the system boots: a secure shell server, a
12666Web server, the Guix build daemon, etc. Sometimes a service is a daemon
12667whose execution can be triggered by another daemon---e.g., an FTP server
12668started by @command{inetd} or a D-Bus service activated by
12669@command{dbus-daemon}. Occasionally, a service does not map to a
12670daemon. For instance, the ``account'' service collects user accounts
12671and makes sure they exist when the system runs; the ``udev'' service
12672collects device management rules and makes them available to the eudev
1068f26b
AE
12673daemon; the @file{/etc} service populates the @file{/etc} directory
12674of the system.
0adfe95a 12675
d6c3267a 12676@cindex service extensions
0adfe95a 12677GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 12678secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
12679initialization system, running as PID@tie{}1---by giving it the command
12680lines to start and stop the secure shell daemon (@pxref{Networking
12681Services, @code{lsh-service}}); the UPower service extends the D-Bus
12682service by passing it its @file{.service} specification, and extends the
12683udev service by passing it device management rules (@pxref{Desktop
12684Services, @code{upower-service}}); the Guix daemon service extends the
12685Shepherd by passing it the command lines to start and stop the daemon,
12686and extends the account service by passing it a list of required build
12687user accounts (@pxref{Base Services}).
0adfe95a
LC
12688
12689All in all, services and their ``extends'' relations form a directed
12690acyclic graph (DAG). If we represent services as boxes and extensions
12691as arrows, a typical system might provide something like this:
12692
12693@image{images/service-graph,,5in,Typical service extension graph.}
12694
d62e201c
LC
12695@cindex system service
12696At the bottom, we see the @dfn{system service}, which produces the
12697directory containing everything to run and boot the system, as returned
12698by the @command{guix system build} command. @xref{Service Reference},
12699to learn about the other service types shown here.
d6c3267a
LC
12700@xref{system-extension-graph, the @command{guix system extension-graph}
12701command}, for information on how to generate this representation for a
12702particular operating system definition.
0adfe95a
LC
12703
12704@cindex service types
12705Technically, developers can define @dfn{service types} to express these
12706relations. There can be any number of services of a given type on the
12707system---for instance, a system running two instances of the GNU secure
12708shell server (lsh) has two instances of @var{lsh-service-type}, with
12709different parameters.
12710
12711The following section describes the programming interface for service
12712types and services.
12713
12714@node Service Types and Services
12715@subsubsection Service Types and Services
12716
12717A @dfn{service type} is a node in the DAG described above. Let us start
12718with a simple example, the service type for the Guix build daemon
12719(@pxref{Invoking guix-daemon}):
12720
12721@example
12722(define guix-service-type
12723 (service-type
12724 (name 'guix)
12725 (extensions
d4053c71 12726 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
12727 (service-extension account-service-type guix-accounts)
12728 (service-extension activation-service-type guix-activation)))))
12729@end example
8451a568 12730
cf4a9129 12731@noindent
1068f26b 12732It defines two things:
0adfe95a
LC
12733
12734@enumerate
12735@item
12736A name, whose sole purpose is to make inspection and debugging easier.
12737
12738@item
12739A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
12740target service type and a procedure that, given the parameters of the
12741service, returns a list of objects to extend the service of that type.
0adfe95a
LC
12742
12743Every service type has at least one service extension. The only
12744exception is the @dfn{boot service type}, which is the ultimate service.
12745@end enumerate
12746
12747In this example, @var{guix-service-type} extends three services:
12748
12749@table @var
d4053c71
AK
12750@item shepherd-root-service-type
12751The @var{guix-shepherd-service} procedure defines how the Shepherd
12752service is extended. Namely, it returns a @code{<shepherd-service>}
12753object that defines how @command{guix-daemon} is started and stopped
12754(@pxref{Shepherd Services}).
0adfe95a
LC
12755
12756@item account-service-type
12757This extension for this service is computed by @var{guix-accounts},
12758which returns a list of @code{user-group} and @code{user-account}
12759objects representing the build user accounts (@pxref{Invoking
12760guix-daemon}).
12761
12762@item activation-service-type
12763Here @var{guix-activation} is a procedure that returns a gexp, which is
12764a code snippet to run at ``activation time''---e.g., when the service is
12765booted.
12766@end table
12767
12768A service of this type is instantiated like this:
12769
12770@example
12771(service guix-service-type
12772 (guix-configuration
12773 (build-accounts 5)
12774 (use-substitutes? #f)))
12775@end example
12776
12777The second argument to the @code{service} form is a value representing
12778the parameters of this specific service instance.
12779@xref{guix-configuration-type, @code{guix-configuration}}, for
12780information about the @code{guix-configuration} data type.
12781
12782@var{guix-service-type} is quite simple because it extends other
12783services but is not extensible itself.
12784
12785@c @subsubsubsection Extensible Service Types
12786
12787The service type for an @emph{extensible} service looks like this:
12788
12789@example
12790(define udev-service-type
12791 (service-type (name 'udev)
12792 (extensions
d4053c71
AK
12793 (list (service-extension shepherd-root-service-type
12794 udev-shepherd-service)))
0adfe95a
LC
12795
12796 (compose concatenate) ;concatenate the list of rules
12797 (extend (lambda (config rules)
12798 (match config
12799 (($ <udev-configuration> udev initial-rules)
12800 (udev-configuration
12801 (udev udev) ;the udev package to use
12802 (rules (append initial-rules rules)))))))))
12803@end example
12804
12805This is the service type for the
12806@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
12807management daemon}. Compared to the previous example, in addition to an
d4053c71 12808extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
12809
12810@table @code
12811@item compose
12812This is the procedure to @dfn{compose} the list of extensions to
12813services of this type.
12814
12815Services can extend the udev service by passing it lists of rules; we
12816compose those extensions simply by concatenating them.
12817
12818@item extend
1068f26b 12819This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
12820the composition of the extensions.
12821
12822Udev extensions are composed into a list of rules, but the udev service
12823value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 12824extend that record by appending the list of rules it contains to the
0adfe95a
LC
12825list of contributed rules.
12826@end table
12827
12828There can be only one instance of an extensible service type such as
12829@var{udev-service-type}. If there were more, the
12830@code{service-extension} specifications would be ambiguous.
12831
12832Still here? The next section provides a reference of the programming
12833interface for services.
12834
12835@node Service Reference
12836@subsubsection Service Reference
12837
12838We have seen an overview of service types (@pxref{Service Types and
12839Services}). This section provides a reference on how to manipulate
12840services and service types. This interface is provided by the
12841@code{(gnu services)} module.
12842
12843@deffn {Scheme Procedure} service @var{type} @var{value}
12844Return a new service of @var{type}, a @code{<service-type>} object (see
12845below.) @var{value} can be any object; it represents the parameters of
12846this particular service instance.
12847@end deffn
12848
12849@deffn {Scheme Procedure} service? @var{obj}
12850Return true if @var{obj} is a service.
12851@end deffn
8451a568 12852
0adfe95a
LC
12853@deffn {Scheme Procedure} service-kind @var{service}
12854Return the type of @var{service}---i.e., a @code{<service-type>} object.
12855@end deffn
12856
12857@deffn {Scheme Procedure} service-parameters @var{service}
12858Return the value associated with @var{service}. It represents its
12859parameters.
12860@end deffn
12861
12862Here is an example of how a service is created and manipulated:
12863
12864@example
12865(define s
12866 (service nginx-service-type
12867 (nginx-configuration
12868 (nginx nginx)
12869 (log-directory log-directory)
12870 (run-directory run-directory)
12871 (file config-file))))
12872
12873(service? s)
12874@result{} #t
12875
12876(eq? (service-kind s) nginx-service-type)
12877@result{} #t
12878@end example
12879
cd6f6c22
LC
12880The @code{modify-services} form provides a handy way to change the
12881parameters of some of the services of a list such as
4d343a14 12882@var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
7414de0a 12883evaluates to a list of services. Of course, you could always use
4d343a14
CM
12884standard list combinators such as @code{map} and @code{fold} to do that
12885(@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
12886@code{modify-services} simply provides a more concise form for this
12887common pattern.
cd6f6c22
LC
12888
12889@deffn {Scheme Syntax} modify-services @var{services} @
12890 (@var{type} @var{variable} => @var{body}) @dots{}
12891
12892Modify the services listed in @var{services} according to the given
12893clauses. Each clause has the form:
12894
12895@example
12896(@var{type} @var{variable} => @var{body})
12897@end example
12898
4d343a14
CM
12899where @var{type} is a service type---e.g.,
12900@code{guix-service-type}---and @var{variable} is an identifier that is
12901bound within the @var{body} to the service parameters---e.g., a
12902@code{guix-configuration} instance---of the original service of that
12903@var{type}.
cd6f6c22 12904
4d343a14
CM
12905The @var{body} should evaluate to the new service parameters, which will
12906be used to configure the new service. This new service will replace the
12907original in the resulting list. Because a service's service parameters
7414de0a 12908are created using @code{define-record-type*}, you can write a succinct
4d343a14
CM
12909@var{body} that evaluates to the new service parameters by using the
12910@code{inherit} feature that @code{define-record-type*} provides.
12911
b53daad0 12912@xref{Using the Configuration System}, for example usage.
cd6f6c22 12913
cd6f6c22
LC
12914@end deffn
12915
12916Next comes the programming interface for service types. This is
12917something you want to know when writing new service definitions, but not
12918necessarily when simply looking for ways to customize your
12919@code{operating-system} declaration.
12920
0adfe95a
LC
12921@deftp {Data Type} service-type
12922@cindex service type
12923This is the representation of a @dfn{service type} (@pxref{Service Types
12924and Services}).
12925
12926@table @asis
12927@item @code{name}
12928This is a symbol, used only to simplify inspection and debugging.
12929
12930@item @code{extensions}
1068f26b 12931A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
12932
12933@item @code{compose} (default: @code{#f})
12934If this is @code{#f}, then the service type denotes services that cannot
12935be extended---i.e., services that do not receive ``values'' from other
12936services.
12937
12938Otherwise, it must be a one-argument procedure. The procedure is called
12939by @code{fold-services} and is passed a list of values collected from
12940extensions. It must return a value that is a valid parameter value for
12941the service instance.
12942
12943@item @code{extend} (default: @code{#f})
12944If this is @code{#f}, services of this type cannot be extended.
12945
12946Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 12947calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
12948and the result of applying @code{compose} to the extension values as the
12949second argument.
12950@end table
12951
12952@xref{Service Types and Services}, for examples.
12953@end deftp
12954
12955@deffn {Scheme Procedure} service-extension @var{target-type} @
12956 @var{compute}
12957Return a new extension for services of type @var{target-type}.
12958@var{compute} must be a one-argument procedure: @code{fold-services}
12959calls it, passing it the value associated with the service that provides
12960the extension; it must return a valid value for the target service.
12961@end deffn
12962
12963@deffn {Scheme Procedure} service-extension? @var{obj}
12964Return true if @var{obj} is a service extension.
12965@end deffn
12966
71654dfd
LC
12967Occasionally, you might want to simply extend an existing service. This
12968involves creating a new service type and specifying the extension of
12969interest, which can be verbose; the @code{simple-service} procedure
12970provides a shorthand for this.
12971
12972@deffn {Scheme Procedure} simple-service @var{name} @var{target} @var{value}
12973Return a service that extends @var{target} with @var{value}. This works
12974by creating a singleton service type @var{name}, of which the returned
12975service is an instance.
12976
12977For example, this extends mcron (@pxref{Scheduled Job Execution}) with
12978an additional job:
12979
12980@example
12981(simple-service 'my-mcron-job mcron-service-type
12982 #~(job '(next-hour (3)) "guix gc -F 2G"))
12983@end example
12984@end deffn
12985
0adfe95a
LC
12986At the core of the service abstraction lies the @code{fold-services}
12987procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
12988down to a single directory that contains everything needed to boot and
12989run the system---the directory shown by the @command{guix system build}
12990command (@pxref{Invoking guix system}). In essence, it propagates
12991service extensions down the service graph, updating each node parameters
12992on the way, until it reaches the root node.
0adfe95a
LC
12993
12994@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 12995 [#:target-type @var{system-service-type}]
0adfe95a
LC
12996Fold @var{services} by propagating their extensions down to the root of
12997type @var{target-type}; return the root service adjusted accordingly.
12998@end deffn
12999
13000Lastly, the @code{(gnu services)} module also defines several essential
13001service types, some of which are listed below.
13002
d62e201c
LC
13003@defvr {Scheme Variable} system-service-type
13004This is the root of the service graph. It produces the system directory
13005as returned by the @command{guix system build} command.
13006@end defvr
13007
0adfe95a 13008@defvr {Scheme Variable} boot-service-type
d62e201c
LC
13009The type of the ``boot service'', which produces the @dfn{boot script}.
13010The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
13011@end defvr
13012
13013@defvr {Scheme Variable} etc-service-type
13014The type of the @file{/etc} service. This service can be extended by
13015passing it name/file tuples such as:
13016
13017@example
13018(list `("issue" ,(plain-file "issue" "Welcome!\n")))
13019@end example
13020
13021In this example, the effect would be to add an @file{/etc/issue} file
13022pointing to the given file.
13023@end defvr
13024
13025@defvr {Scheme Variable} setuid-program-service-type
13026Type for the ``setuid-program service''. This service collects lists of
13027executable file names, passed as gexps, and adds them to the set of
13028setuid-root programs on the system (@pxref{Setuid Programs}).
13029@end defvr
13030
af4c3fd5
LC
13031@defvr {Scheme Variable} profile-service-type
13032Type of the service that populates the @dfn{system profile}---i.e., the
13033programs under @file{/run/current-system/profile}. Other services can
13034extend it by passing it lists of packages to add to the system profile.
13035@end defvr
13036
0adfe95a 13037
dd17bc38
AK
13038@node Shepherd Services
13039@subsubsection Shepherd Services
0adfe95a 13040
e32171ee 13041@cindex shepherd services
0adfe95a
LC
13042@cindex PID 1
13043@cindex init system
a40424bd
CM
13044The @code{(gnu services shepherd)} module provides a way to define
13045services managed by the GNU@tie{}Shepherd, which is the GuixSD
13046initialization system---the first process that is started when the
1068f26b
AE
13047system boots, also known as PID@tie{}1
13048(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 13049
dd17bc38
AK
13050Services in the Shepherd can depend on each other. For instance, the
13051SSH daemon may need to be started after the syslog daemon has been
13052started, which in turn can only happen once all the file systems have
13053been mounted. The simple operating system defined earlier (@pxref{Using
13054the Configuration System}) results in a service graph like this:
6f305ea5 13055
710fa231 13056@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
13057
13058You can actually generate such a graph for any operating system
710fa231
AK
13059definition using the @command{guix system shepherd-graph} command
13060(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 13061
d4053c71
AK
13062The @var{%shepherd-root-service} is a service object representing
13063PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
13064by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 13065
d4053c71 13066@deftp {Data Type} shepherd-service
dd17bc38 13067The data type representing a service managed by the Shepherd.
0adfe95a
LC
13068
13069@table @asis
13070@item @code{provision}
13071This is a list of symbols denoting what the service provides.
13072
dd17bc38
AK
13073These are the names that may be passed to @command{herd start},
13074@command{herd status}, and similar commands (@pxref{Invoking herd,,,
13075shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
13076@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
13077
13078@item @code{requirements} (default: @code{'()})
dd17bc38 13079List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
13080
13081@item @code{respawn?} (default: @code{#t})
13082Whether to restart the service when it stops, for instance when the
13083underlying process dies.
13084
13085@item @code{start}
13086@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
13087The @code{start} and @code{stop} fields refer to the Shepherd's
13088facilities to start and stop processes (@pxref{Service De- and
13089Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
13090G-expressions that get expanded in the Shepherd configuration file
13091(@pxref{G-Expressions}).
0adfe95a
LC
13092
13093@item @code{documentation}
13094A documentation string, as shown when running:
13095
13096@example
dd17bc38 13097herd doc @var{service-name}
0adfe95a
LC
13098@end example
13099
13100where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 13101(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
13102
13103@item @code{modules} (default: @var{%default-modules})
13104This is the list of modules that must be in scope when @code{start} and
13105@code{stop} are evaluated.
13106
0adfe95a
LC
13107@end table
13108@end deftp
13109
d4053c71 13110@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 13111The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
13112
13113This is the service type that extensions target when they want to create
dd17bc38 13114shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 13115Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
13116@end defvr
13117
d4053c71 13118@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
13119This service represents PID@tie{}1.
13120@end defvr
8451a568 13121
8451a568 13122
cf4a9129
LC
13123@node Installing Debugging Files
13124@section Installing Debugging Files
8451a568 13125
cf4a9129
LC
13126@cindex debugging files
13127Program binaries, as produced by the GCC compilers for instance, are
13128typically written in the ELF format, with a section containing
13129@dfn{debugging information}. Debugging information is what allows the
13130debugger, GDB, to map binary code to source code; it is required to
13131debug a compiled program in good conditions.
8451a568 13132
cf4a9129
LC
13133The problem with debugging information is that is takes up a fair amount
13134of disk space. For example, debugging information for the GNU C Library
13135weighs in at more than 60 MiB. Thus, as a user, keeping all the
13136debugging info of all the installed programs is usually not an option.
13137Yet, space savings should not come at the cost of an impediment to
13138debugging---especially in the GNU system, which should make it easier
13139for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 13140
cf4a9129
LC
13141Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
13142mechanism that allows users to get the best of both worlds: debugging
13143information can be stripped from the binaries and stored in separate
13144files. GDB is then able to load debugging information from those files,
13145when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
13146with GDB}).
8451a568 13147
cf4a9129
LC
13148The GNU distribution takes advantage of this by storing debugging
13149information in the @code{lib/debug} sub-directory of a separate package
13150output unimaginatively called @code{debug} (@pxref{Packages with
13151Multiple Outputs}). Users can choose to install the @code{debug} output
13152of a package when they need it. For instance, the following command
13153installs the debugging information for the GNU C Library and for GNU
13154Guile:
8451a568
LC
13155
13156@example
cf4a9129 13157guix package -i glibc:debug guile:debug
8451a568
LC
13158@end example
13159
cf4a9129
LC
13160GDB must then be told to look for debug files in the user's profile, by
13161setting the @code{debug-file-directory} variable (consider setting it
13162from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
13163GDB}):
8451a568 13164
cf4a9129
LC
13165@example
13166(gdb) set debug-file-directory ~/.guix-profile/lib/debug
13167@end example
8451a568 13168
cf4a9129
LC
13169From there on, GDB will pick up debugging information from the
13170@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 13171
cf4a9129
LC
13172In addition, you will most likely want GDB to be able to show the source
13173code being debugged. To do that, you will have to unpack the source
13174code of the package of interest (obtained with @code{guix build
13175--source}, @pxref{Invoking guix build}), and to point GDB to that source
13176directory using the @code{directory} command (@pxref{Source Path,
13177@code{directory},, gdb, Debugging with GDB}).
8451a568 13178
cf4a9129
LC
13179@c XXX: keep me up-to-date
13180The @code{debug} output mechanism in Guix is implemented by the
13181@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
13182opt-in---debugging information is available only for the packages
13183with definitions explicitly declaring a @code{debug} output. This may be
13184changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
13185the load. To check whether a package has a @code{debug} output, use
13186@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 13187
8451a568 13188
05962f29
LC
13189@node Security Updates
13190@section Security Updates
13191
09866b39
LC
13192@cindex security updates
13193@cindex security vulnerabilities
13194Occasionally, important security vulnerabilities are discovered in software
13195packages and must be patched. Guix developers try hard to keep track of
13196known vulnerabilities and to apply fixes as soon as possible in the
13197@code{master} branch of Guix (we do not yet provide a ``stable'' branch
13198containing only security updates.) The @command{guix lint} tool helps
13199developers find out about vulnerable versions of software packages in the
13200distribution:
13201
13202@smallexample
13203$ guix lint -c cve
13204gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
13205gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
13206gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
13207@dots{}
13208@end smallexample
13209
13210@xref{Invoking guix lint}, for more information.
13211
843858b8 13212@quotation Note
09866b39
LC
13213As of version @value{VERSION}, the feature described below is considered
13214``beta''.
843858b8 13215@end quotation
05962f29 13216
09866b39 13217Guix follows a functional
05962f29
LC
13218package management discipline (@pxref{Introduction}), which implies
13219that, when a package is changed, @emph{every package that depends on it}
13220must be rebuilt. This can significantly slow down the deployment of
13221fixes in core packages such as libc or Bash, since basically the whole
13222distribution would need to be rebuilt. Using pre-built binaries helps
13223(@pxref{Substitutes}), but deployment may still take more time than
13224desired.
13225
13226@cindex grafts
1068f26b 13227To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
13228for fast deployment of critical updates without the costs associated
13229with a whole-distribution rebuild. The idea is to rebuild only the
13230package that needs to be patched, and then to ``graft'' it onto packages
13231explicitly installed by the user and that were previously referring to
13232the original package. The cost of grafting is typically very low, and
13233order of magnitudes lower than a full rebuild of the dependency chain.
13234
13235@cindex replacements of packages, for grafts
13236For instance, suppose a security update needs to be applied to Bash.
13237Guix developers will provide a package definition for the ``fixed''
13238Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
13239Packages}). Then, the original package definition is augmented with a
13240@code{replacement} field pointing to the package containing the bug fix:
13241
13242@example
13243(define bash
13244 (package
13245 (name "bash")
13246 ;; @dots{}
13247 (replacement bash-fixed)))
13248@end example
13249
c22a1324
LC
13250From there on, any package depending directly or indirectly on Bash---as
13251reported by @command{guix gc --requisites} (@pxref{Invoking guix
13252gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 13253@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 13254time proportional to the size of the package, usually less than a
c22a1324
LC
13255minute for an ``average'' package on a recent machine. Grafting is
13256recursive: when an indirect dependency requires grafting, then grafting
13257``propagates'' up to the package that the user is installing.
05962f29 13258
57bdd79e
LC
13259Currently, the length of the name and version of the graft and that of
13260the package it replaces (@var{bash-fixed} and @var{bash} in the example
13261above) must be equal. This restriction mostly comes from the fact that
13262grafting works by patching files, including binary files, directly.
05962f29
LC
13263Other restrictions may apply: for instance, when adding a graft to a
13264package providing a shared library, the original shared library and its
13265replacement must have the same @code{SONAME} and be binary-compatible.
13266
59a4dd50
LC
13267The @option{--no-grafts} command-line option allows you to forcefully
13268avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
13269Thus, the command:
13270
13271@example
13272guix build bash --no-grafts
13273@end example
13274
13275@noindent
13276returns the store file name of the original Bash, whereas:
13277
13278@example
13279guix build bash
13280@end example
13281
13282@noindent
13283returns the store file name of the ``fixed'', replacement Bash. This
13284allows you to distinguish between the two variants of Bash.
13285
13286To verify which Bash your whole profile refers to, you can run
13287(@pxref{Invoking guix gc}):
13288
13289@example
13290guix gc -R `readlink -f ~/.guix-profile` | grep bash
13291@end example
13292
13293@noindent
13294@dots{} and compare the store file names that you get with those above.
13295Likewise for a complete GuixSD system generation:
13296
13297@example
13298guix gc -R `guix system build my-config.scm` | grep bash
13299@end example
13300
13301Lastly, to check which Bash running processes are using, you can use the
13302@command{lsof} command:
13303
13304@example
13305lsof | grep /gnu/store/.*bash
13306@end example
13307
05962f29 13308
cf4a9129
LC
13309@node Package Modules
13310@section Package Modules
8451a568 13311
cf4a9129
LC
13312From a programming viewpoint, the package definitions of the
13313GNU distribution are provided by Guile modules in the @code{(gnu packages
13314@dots{})} name space@footnote{Note that packages under the @code{(gnu
13315packages @dots{})} module name space are not necessarily ``GNU
13316packages''. This module naming scheme follows the usual Guile module
13317naming convention: @code{gnu} means that these modules are distributed
13318as part of the GNU system, and @code{packages} identifies modules that
13319define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
13320Reference Manual}). For instance, the @code{(gnu packages emacs)}
13321module exports a variable named @code{emacs}, which is bound to a
13322@code{<package>} object (@pxref{Defining Packages}).
113daf62 13323
300868ba 13324The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
13325automatically scanned for packages by the command-line tools. For
13326instance, when running @code{guix package -i emacs}, all the @code{(gnu
13327packages @dots{})} modules are scanned until one that exports a package
13328object whose name is @code{emacs} is found. This package search
13329facility is implemented in the @code{(gnu packages)} module.
113daf62 13330
300868ba 13331@cindex customization, of packages
8689901f 13332@cindex package module search path
cf4a9129 13333Users can store package definitions in modules with different
60142854 13334names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
13335name and module name must match. For instance, the @code{(my-packages
13336emacs)} module must be stored in a @file{my-packages/emacs.scm} file
13337relative to the load path specified with @option{--load-path} or
13338@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
13339guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
13340will not be visible by default. Users can invoke commands such as
13341@command{guix package} and @command{guix build} with the
c95ded7e
LC
13342@code{-e} option so that they know where to find the package. Better
13343yet, they can use the
300868ba 13344@code{-L} option of these commands to make those modules visible
8689901f
LC
13345(@pxref{Invoking guix build, @code{--load-path}}), or define the
13346@code{GUIX_PACKAGE_PATH} environment variable. This environment
13347variable makes it easy to extend or customize the distribution and is
13348honored by all the user interfaces.
13349
13350@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
13351This is a colon-separated list of directories to search for additional
13352package modules. Directories listed in this variable take precedence
13353over the own modules of the distribution.
8689901f 13354@end defvr
ef5dd60a 13355
cf4a9129
LC
13356The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
13357each package is built based solely on other packages in the
13358distribution. The root of this dependency graph is a small set of
13359@dfn{bootstrap binaries}, provided by the @code{(gnu packages
13360bootstrap)} module. For more information on bootstrapping,
081145cf 13361@pxref{Bootstrapping}.
ef5dd60a 13362
cf4a9129
LC
13363@node Packaging Guidelines
13364@section Packaging Guidelines
ef5dd60a 13365
e32171ee 13366@cindex packages, creating
cf4a9129
LC
13367The GNU distribution is nascent and may well lack some of your favorite
13368packages. This section describes how you can help make the distribution
13369grow. @xref{Contributing}, for additional information on how you can
13370help.
ef5dd60a 13371
cf4a9129
LC
13372Free software packages are usually distributed in the form of
13373@dfn{source code tarballs}---typically @file{tar.gz} files that contain
13374all the source files. Adding a package to the distribution means
13375essentially two things: adding a @dfn{recipe} that describes how to
13376build the package, including a list of other packages required to build
f97c9175 13377it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 13378description and licensing information.
ef5dd60a 13379
cf4a9129
LC
13380In Guix all this information is embodied in @dfn{package definitions}.
13381Package definitions provide a high-level view of the package. They are
13382written using the syntax of the Scheme programming language; in fact,
13383for each package we define a variable bound to the package definition,
13384and export that variable from a module (@pxref{Package Modules}).
13385However, in-depth Scheme knowledge is @emph{not} a prerequisite for
13386creating packages. For more information on package definitions,
081145cf 13387@pxref{Defining Packages}.
ef5dd60a 13388
cf4a9129
LC
13389Once a package definition is in place, stored in a file in the Guix
13390source tree, it can be tested using the @command{guix build} command
13391(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
13392called @code{gnew}, you may run this command from the Guix build tree
13393(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
13394
13395@example
cf4a9129 13396./pre-inst-env guix build gnew --keep-failed
ef5dd60a 13397@end example
ef5dd60a 13398
cf4a9129
LC
13399Using @code{--keep-failed} makes it easier to debug build failures since
13400it provides access to the failed build tree. Another useful
13401command-line option when debugging is @code{--log-file}, to access the
13402build log.
ef5dd60a 13403
cf4a9129
LC
13404If the package is unknown to the @command{guix} command, it may be that
13405the source file contains a syntax error, or lacks a @code{define-public}
13406clause to export the package variable. To figure it out, you may load
13407the module from Guile to get more information about the actual error:
ef5dd60a 13408
cf4a9129
LC
13409@example
13410./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
13411@end example
ef5dd60a 13412
cf4a9129
LC
13413Once your package builds correctly, please send us a patch
13414(@pxref{Contributing}). Well, if you need help, we will be happy to
13415help you too. Once the patch is committed in the Guix repository, the
13416new package automatically gets built on the supported platforms by
2b1cee21 13417@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 13418system}.
ef5dd60a 13419
cf4a9129
LC
13420@cindex substituter
13421Users can obtain the new package definition simply by running
13422@command{guix pull} (@pxref{Invoking guix pull}). When
13423@code{hydra.gnu.org} is done building the package, installing the
13424package automatically downloads binaries from there
13425(@pxref{Substitutes}). The only place where human intervention is
13426needed is to review and apply the patch.
ef5dd60a 13427
ef5dd60a 13428
cf4a9129 13429@menu
ec0339cd
LC
13430* Software Freedom:: What may go into the distribution.
13431* Package Naming:: What's in a name?
13432* Version Numbers:: When the name is not enough.
cbd02397 13433* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
13434* Python Modules:: Taming the snake.
13435* Perl Modules:: Little pearls.
e1c963bf 13436* Java Packages:: Coffee break.
ec0339cd 13437* Fonts:: Fond of fonts.
cf4a9129 13438@end menu
ef5dd60a 13439
cf4a9129
LC
13440@node Software Freedom
13441@subsection Software Freedom
ef5dd60a 13442
cf4a9129 13443@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
e32171ee 13444@cindex free software
cf4a9129
LC
13445The GNU operating system has been developed so that users can have
13446freedom in their computing. GNU is @dfn{free software}, meaning that
13447users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
13448essential freedoms}: to run the program, to study and change the program
13449in source code form, to redistribute exact copies, and to distribute
13450modified versions. Packages found in the GNU distribution provide only
13451software that conveys these four freedoms.
c11a6eb1 13452
cf4a9129
LC
13453In addition, the GNU distribution follow the
13454@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
13455software distribution guidelines}. Among other things, these guidelines
13456reject non-free firmware, recommendations of non-free software, and
13457discuss ways to deal with trademarks and patents.
ef5dd60a 13458
1068f26b
AE
13459Some otherwise free upstream package sources contain a small and optional
13460subset that violates the above guidelines, for instance because this subset
13461is itself non-free code. When that happens, the offending items are removed
13462with appropriate patches or code snippets in the @code{origin} form of the
13463package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
13464build --source} returns the ``freed'' source rather than the unmodified
13465upstream source.
ef5dd60a 13466
ef5dd60a 13467
cf4a9129
LC
13468@node Package Naming
13469@subsection Package Naming
ef5dd60a 13470
e32171ee 13471@cindex package name
cf4a9129
LC
13472A package has actually two names associated with it:
13473First, there is the name of the @emph{Scheme variable}, the one following
13474@code{define-public}. By this name, the package can be made known in the
13475Scheme code, for instance as input to another package. Second, there is
13476the string in the @code{name} field of a package definition. This name
13477is used by package management commands such as
13478@command{guix package} and @command{guix build}.
ef5dd60a 13479
cf4a9129
LC
13480Both are usually the same and correspond to the lowercase conversion of
13481the project name chosen upstream, with underscores replaced with
13482hyphens. For instance, GNUnet is available as @code{gnunet}, and
13483SDL_net as @code{sdl-net}.
927097ef 13484
cf4a9129 13485We do not add @code{lib} prefixes for library packages, unless these are
081145cf 13486already part of the official project name. But @pxref{Python
cf4a9129
LC
13487Modules} and @ref{Perl Modules} for special rules concerning modules for
13488the Python and Perl languages.
927097ef 13489
1b366ee4 13490Font package names are handled differently, @pxref{Fonts}.
7fec52b7 13491
ef5dd60a 13492
cf4a9129
LC
13493@node Version Numbers
13494@subsection Version Numbers
ef5dd60a 13495
e32171ee 13496@cindex package version
cf4a9129
LC
13497We usually package only the latest version of a given free software
13498project. But sometimes, for instance for incompatible library versions,
13499two (or more) versions of the same package are needed. These require
13500different Scheme variable names. We use the name as defined
13501in @ref{Package Naming}
13502for the most recent version; previous versions use the same name, suffixed
13503by @code{-} and the smallest prefix of the version number that may
13504distinguish the two versions.
ef5dd60a 13505
cf4a9129
LC
13506The name inside the package definition is the same for all versions of a
13507package and does not contain any version number.
ef5dd60a 13508
cf4a9129 13509For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 13510
cf4a9129
LC
13511@example
13512(define-public gtk+
13513 (package
17d8e33f
ML
13514 (name "gtk+")
13515 (version "3.9.12")
13516 ...))
cf4a9129
LC
13517(define-public gtk+-2
13518 (package
17d8e33f
ML
13519 (name "gtk+")
13520 (version "2.24.20")
13521 ...))
cf4a9129
LC
13522@end example
13523If we also wanted GTK+ 3.8.2, this would be packaged as
13524@example
13525(define-public gtk+-3.8
13526 (package
17d8e33f
ML
13527 (name "gtk+")
13528 (version "3.8.2")
13529 ...))
cf4a9129 13530@end example
ef5dd60a 13531
880d647d
LC
13532@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
13533@c for a discussion of what follows.
13534@cindex version number, for VCS snapshots
13535Occasionally, we package snapshots of upstream's version control system
13536(VCS) instead of formal releases. This should remain exceptional,
13537because it is up to upstream developers to clarify what the stable
13538release is. Yet, it is sometimes necessary. So, what should we put in
13539the @code{version} field?
13540
13541Clearly, we need to make the commit identifier of the VCS snapshot
13542visible in the version string, but we also need to make sure that the
13543version string is monotonically increasing so that @command{guix package
13544--upgrade} can determine which version is newer. Since commit
13545identifiers, notably with Git, are not monotonically increasing, we add
13546a revision number that we increase each time we upgrade to a newer
13547snapshot. The resulting version string looks like this:
13548
13549@example
135502.0.11-3.cabba9e
13551 ^ ^ ^
13552 | | `-- upstream commit ID
13553 | |
13554 | `--- Guix package revision
13555 |
13556latest upstream version
13557@end example
13558
13559It is a good idea to strip commit identifiers in the @code{version}
13560field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
13561aesthetics have a role to play here) as well as problems related to OS
13562limits such as the maximum shebang length (127 bytes for the Linux
13563kernel.) It is best to use the full commit identifiers in
561360a5
LC
13564@code{origin}s, though, to avoid ambiguities. A typical package
13565definition may look like this:
13566
13567@example
13568(define my-package
6e42660b 13569 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
13570 (revision "1")) ;Guix package revision
561360a5 13571 (package
6e42660b 13572 (version (string-append "0.9-" revision "."
561360a5
LC
13573 (string-take commit 7)))
13574 (source (origin
13575 (method git-fetch)
13576 (uri (git-reference
13577 (url "git://example.org/my-package.git")
13578 (commit commit)))
13579 (sha256 (base32 "1mbikn@dots{}"))
13580 (file-name (string-append "my-package-" version
13581 "-checkout"))))
13582 ;; @dots{}
13583 )))
13584@end example
880d647d 13585
cbd02397
LC
13586@node Synopses and Descriptions
13587@subsection Synopses and Descriptions
13588
e32171ee
JD
13589@cindex package description
13590@cindex package synopsis
cbd02397
LC
13591As we have seen before, each package in GNU@tie{}Guix includes a
13592synopsis and a description (@pxref{Defining Packages}). Synopses and
13593descriptions are important: They are what @command{guix package
13594--search} searches, and a crucial piece of information to help users
13595determine whether a given package suits their needs. Consequently,
13596packagers should pay attention to what goes into them.
13597
13598Synopses must start with a capital letter and must not end with a
13599period. They must not start with ``a'' or ``the'', which usually does
13600not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
13601tool that frobs files''. The synopsis should say what the package
13602is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
13603used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
13604matching a pattern''.
13605
13606Keep in mind that the synopsis must be meaningful for a very wide
13607audience. For example, ``Manipulate alignments in the SAM format''
13608might make sense for a seasoned bioinformatics researcher, but might be
13609fairly unhelpful or even misleading to a non-specialized audience. It
13610is a good idea to come up with a synopsis that gives an idea of the
13611application domain of the package. In this example, this might give
13612something like ``Manipulate nucleotide sequence alignments'', which
13613hopefully gives the user a better idea of whether this is what they are
13614looking for.
13615
cbd02397
LC
13616Descriptions should take between five and ten lines. Use full
13617sentences, and avoid using acronyms without first introducing them.
762e54b7
LC
13618Please avoid marketing phrases such as ``world-leading'',
13619``industrial-strength'', and ``next-generation'', and avoid superlatives
13620like ``the most advanced''---they are not helpful to users looking for a
13621package and may even sound suspicious. Instead, try to be factual,
13622mentioning use cases and features.
13623
13624@cindex Texinfo markup, in package descriptions
cbd02397
LC
13625Descriptions can include Texinfo markup, which is useful to introduce
13626ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
13627hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
13628should be careful when using some characters for example @samp{@@} and
13629curly braces which are the basic special characters in Texinfo
13630(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
13631such as @command{guix package --show} take care of rendering it
13632appropriately.
cbd02397
LC
13633
13634Synopses and descriptions are translated by volunteers
13635@uref{http://translationproject.org/domain/guix-packages.html, at the
13636Translation Project} so that as many users as possible can read them in
13637their native language. User interfaces search them and display them in
13638the language specified by the current locale.
13639
13640Translation is a lot of work so, as a packager, please pay even more
13641attention to your synopses and descriptions as every change may entail
ba7d6c76 13642additional work for translators. In order to help them, it is possible
36743e71 13643to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
13644special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
13645Gettext}):
13646
13647@example
13648;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
13649(description "ARandR is designed to provide a simple visual front end
13650for the X11 resize-and-rotate (RandR) extension. @dots{}")
13651@end example
cbd02397 13652
ef5dd60a 13653
cf4a9129
LC
13654@node Python Modules
13655@subsection Python Modules
ef5dd60a 13656
e32171ee 13657@cindex python
cf4a9129
LC
13658We currently package Python 2 and Python 3, under the Scheme variable names
13659@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
13660To avoid confusion and naming clashes with other programming languages, it
13661seems desirable that the name of a package for a Python module contains
13662the word @code{python}.
ef5dd60a 13663
cf4a9129
LC
13664Some modules are compatible with only one version of Python, others with both.
13665If the package Foo compiles only with Python 3, we name it
13666@code{python-foo}; if it compiles only with Python 2, we name it
13667@code{python2-foo}. If it is compatible with both versions, we create two
13668packages with the corresponding names.
ef5dd60a 13669
cf4a9129
LC
13670If a project already contains the word @code{python}, we drop this;
13671for instance, the module python-dateutil is packaged under the names
99c866a0
HG
13672@code{python-dateutil} and @code{python2-dateutil}. If the project name
13673starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
13674described above.
113daf62 13675
523e4896 13676
e940a271
HG
13677@subsubsection Specifying Dependencies
13678@cindex inputs, for Python packages
13679
13680Dependency information for Python packages is usually available in the
13681package source tree, with varying degrees of accuracy: in the
13682@file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
13683
13684Your mission, when writing a recipe for a Python package, is to map
13685these dependencies to the appropriate type of ``input'' (@pxref{package
13686Reference, inputs}). Although the @code{pypi} importer normally does a
13687good job (@pxref{Invoking guix import}), you may want to check the
13688following check list to determine which dependency goes where.
13689
13690@itemize
13691
13692@item
13693Python dependencies required at run time go into
13694@code{propagated-inputs}. They are typically defined with the
13695@code{install_requires} keyword in @file{setup.py}, or in the
13696@file{requirements.txt} file.
13697
13698@item
13699Python packages required only at build time---e.g., those listed with
13700the @code{setup_requires} keyword in @file{setup.py}---or only for
13701testing---e.g., those in @code{tests_require}---go into
13702@code{native-inputs}. The rationale is that (1) they do not need to be
13703propagated because they are not needed at run time, and (2) in a
13704cross-compilation context, it's the ``native'' input that we'd want.
13705
13706Examples are @code{setuptools}, which is usually needed only at build
13707time, or the @code{pytest}, @code{mock}, and @code{nose} test
13708frameworks. Of course if any of these packages is also required at
13709run-time, it needs to go to @code{propagated-inputs}.
13710
13711@item
13712Anything that does not fall in the previous categories goes to
13713@code{inputs}, for example programs or C libraries required for building
13714Python packages containing C extensions.
13715
13716@item
13717If a Python package has optional dependencies (@code{extras_require}),
13718it is up to you to decide whether to add them or not, based on their
13719usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
13720size}}).
13721
13722@end itemize
13723
13724
cf4a9129
LC
13725@node Perl Modules
13726@subsection Perl Modules
523e4896 13727
e32171ee 13728@cindex perl
cf4a9129
LC
13729Perl programs standing for themselves are named as any other package,
13730using the lowercase upstream name.
13731For Perl packages containing a single class, we use the lowercase class name,
13732replace all occurrences of @code{::} by dashes and prepend the prefix
13733@code{perl-}.
13734So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
13735Modules containing several classes keep their lowercase upstream name and
13736are also prepended by @code{perl-}. Such modules tend to have the word
13737@code{perl} somewhere in their name, which gets dropped in favor of the
13738prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 13739
523e4896 13740
e1c963bf
HG
13741@node Java Packages
13742@subsection Java Packages
13743
e32171ee 13744@cindex java
e1c963bf
HG
13745Java programs standing for themselves are named as any other package,
13746using the lowercase upstream name.
13747
13748To avoid confusion and naming clashes with other programming languages,
13749it is desirable that the name of a package for a Java package is
13750prefixed with @code{java-}. If a project already contains the word
13751@code{java}, we drop this; for instance, the package @code{ngsjava} is
13752packaged under the name @code{java-ngs}.
13753
13754For Java packages containing a single class or a small class hierarchy,
13755we use the lowercase class name, replace all occurrences of @code{.} by
13756dashes and prepend the prefix @code{java-}. So the class
13757@code{apache.commons.cli} becomes package
13758@code{java-apache-commons-cli}.
13759
13760
7fec52b7
AE
13761@node Fonts
13762@subsection Fonts
13763
e32171ee 13764@cindex fonts
7fec52b7
AE
13765For fonts that are in general not installed by a user for typesetting
13766purposes, or that are distributed as part of a larger software package,
13767we rely on the general packaging rules for software; for instance, this
13768applies to the fonts delivered as part of the X.Org system or fonts that
13769are part of TeX Live.
13770
13771To make it easier for a user to search for fonts, names for other packages
13772containing only fonts are constructed as follows, independently of the
13773upstream package name.
13774
13775The name of a package containing only one font family starts with
13776@code{font-}; it is followed by the foundry name and a dash @code{-}
13777if the foundry is known, and the font family name, in which spaces are
13778replaced by dashes (and as usual, all upper case letters are transformed
13779to lower case).
13780For example, the Gentium font family by SIL is packaged under the name
13781@code{font-sil-gentium}.
13782
13783For a package containing several font families, the name of the collection
13784is used in the place of the font family name.
13785For instance, the Liberation fonts consist of three families,
13786Liberation Sans, Liberation Serif and Liberation Mono.
13787These could be packaged separately under the names
13788@code{font-liberation-sans} and so on; but as they are distributed together
13789under a common name, we prefer to package them together as
13790@code{font-liberation}.
13791
13792In the case where several formats of the same font family or font collection
13793are packaged separately, a short form of the format, prepended by a dash,
13794is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 13795@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
13796fonts.
13797
13798
b25937e3 13799
cf4a9129
LC
13800@node Bootstrapping
13801@section Bootstrapping
b25937e3 13802
cf4a9129 13803@c Adapted from the ELS 2013 paper.
b25937e3 13804
cf4a9129 13805@cindex bootstrapping
7889394e 13806
cf4a9129
LC
13807Bootstrapping in our context refers to how the distribution gets built
13808``from nothing''. Remember that the build environment of a derivation
13809contains nothing but its declared inputs (@pxref{Introduction}). So
13810there's an obvious chicken-and-egg problem: how does the first package
13811get built? How does the first compiler get compiled? Note that this is
13812a question of interest only to the curious hacker, not to the regular
13813user, so you can shamelessly skip this section if you consider yourself
13814a ``regular user''.
72b9d60d 13815
cf4a9129
LC
13816@cindex bootstrap binaries
13817The GNU system is primarily made of C code, with libc at its core. The
13818GNU build system itself assumes the availability of a Bourne shell and
13819command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
13820`grep'. Furthermore, build programs---programs that run
13821@code{./configure}, @code{make}, etc.---are written in Guile Scheme
13822(@pxref{Derivations}). Consequently, to be able to build anything at
13823all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
13824Binutils, libc, and the other packages mentioned above---the
13825@dfn{bootstrap binaries}.
72b9d60d 13826
cf4a9129
LC
13827These bootstrap binaries are ``taken for granted'', though we can also
13828re-create them if needed (more on that later).
72b9d60d 13829
cf4a9129 13830@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 13831
cf4a9129
LC
13832@c As of Emacs 24.3, Info-mode displays the image, but since it's a
13833@c large image, it's hard to scroll. Oh well.
13834@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 13835
cf4a9129
LC
13836The figure above shows the very beginning of the dependency graph of the
13837distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
13838packages bootstrap)} module. A similar figure can be generated with
13839@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
13840
13841@example
13842guix graph -t derivation \
13843 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
13844 | dot -Tps > t.ps
13845@end example
13846
13847At this level of detail, things are
cf4a9129
LC
13848slightly complex. First, Guile itself consists of an ELF executable,
13849along with many source and compiled Scheme files that are dynamically
13850loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
13851tarball shown in this graph. This tarball is part of Guix's ``source''
13852distribution, and gets inserted into the store with @code{add-to-store}
13853(@pxref{The Store}).
2e7b5cea 13854
cf4a9129
LC
13855But how do we write a derivation that unpacks this tarball and adds it
13856to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
13857derivation---the first one that gets built---uses @code{bash} as its
13858builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
13859@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
13860@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
13861the Guix source distribution, whose sole purpose is to allow the Guile
13862tarball to be unpacked.
fb729425 13863
cf4a9129
LC
13864Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
13865Guile that can be used to run subsequent build programs. Its first task
13866is to download tarballs containing the other pre-built binaries---this
13867is what the @code{.tar.xz.drv} derivations do. Guix modules such as
13868@code{ftp-client.scm} are used for this purpose. The
13869@code{module-import.drv} derivations import those modules in a directory
13870in the store, using the original layout. The
13871@code{module-import-compiled.drv} derivations compile those modules, and
13872write them in an output directory with the right layout. This
13873corresponds to the @code{#:modules} argument of
13874@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 13875
cf4a9129
LC
13876Finally, the various tarballs are unpacked by the
13877derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
13878etc., at which point we have a working C tool chain.
fb729425 13879
fb729425 13880
cf4a9129 13881@unnumberedsubsec Building the Build Tools
523e4896 13882
cf4a9129
LC
13883Bootstrapping is complete when we have a full tool chain that does not
13884depend on the pre-built bootstrap tools discussed above. This
13885no-dependency requirement is verified by checking whether the files of
13886the final tool chain contain references to the @file{/gnu/store}
13887directories of the bootstrap inputs. The process that leads to this
13888``final'' tool chain is described by the package definitions found in
1f6f57df 13889the @code{(gnu packages commencement)} module.
df2ce343 13890
d33fa0c7
LC
13891The @command{guix graph} command allows us to ``zoom out'' compared to
13892the graph above, by looking at the level of package objects instead of
13893individual derivations---remember that a package may translate to
13894several derivations, typically one derivation to download its source,
13895one to build the Guile modules it needs, and one to actually build the
13896package from source. The command:
13897
13898@example
13899guix graph -t bag \
13900 -e '(@@@@ (gnu packages commencement)
13901 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
13902@end example
13903
13904@noindent
13905produces the dependency graph leading to the ``final'' C
13906library@footnote{You may notice the @code{glibc-intermediate} label,
13907suggesting that it is not @emph{quite} final, but as a good
13908approximation, we will consider it final.}, depicted below.
13909
13910@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
13911
cf4a9129
LC
13912@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
13913The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
13914GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
13915for all the following packages. From there Findutils and Diffutils get
13916built.
523e4896 13917
cf4a9129
LC
13918Then come the first-stage Binutils and GCC, built as pseudo cross
13919tools---i.e., with @code{--target} equal to @code{--host}. They are
13920used to build libc. Thanks to this cross-build trick, this libc is
13921guaranteed not to hold any reference to the initial tool chain.
4af2447e 13922
d33fa0c7
LC
13923From there the final Binutils and GCC (not shown above) are built.
13924GCC uses @code{ld}
cf4a9129
LC
13925from the final Binutils, and links programs against the just-built libc.
13926This tool chain is used to build the other packages used by Guix and by
13927the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 13928
cf4a9129
LC
13929And voilà! At this point we have the complete set of build tools that
13930the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
13931variable of the @code{(gnu packages commencement)} module, and are
13932implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 13933(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 13934
4af2447e 13935
cf4a9129 13936@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 13937
e32171ee 13938@cindex bootstrap binaries
cf4a9129
LC
13939Because the final tool chain does not depend on the bootstrap binaries,
13940those rarely need to be updated. Nevertheless, it is useful to have an
13941automated way to produce them, should an update occur, and this is what
13942the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 13943
cf4a9129
LC
13944The following command builds the tarballs containing the bootstrap
13945binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
13946of Coreutils and other basic command-line tools):
4b2615e1 13947
cf4a9129
LC
13948@example
13949guix build bootstrap-tarballs
13950@end example
13951
13952The generated tarballs are those that should be referred to in the
13953@code{(gnu packages bootstrap)} module mentioned at the beginning of
13954this section.
13955
13956Still here? Then perhaps by now you've started to wonder: when do we
13957reach a fixed point? That is an interesting question! The answer is
13958unknown, but if you would like to investigate further (and have
13959significant computational and storage resources to do so), then let us
13960know.
13961
13962@node Porting
13963@section Porting to a New Platform
13964
13965As discussed above, the GNU distribution is self-contained, and
13966self-containment is achieved by relying on pre-built ``bootstrap
13967binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
13968operating system kernel, CPU architecture, and application binary
13969interface (ABI). Thus, to port the distribution to a platform that is
13970not yet supported, one must build those bootstrap binaries, and update
13971the @code{(gnu packages bootstrap)} module to use them on that platform.
13972
13973Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
13974When everything goes well, and assuming the GNU tool chain supports the
13975target platform, this can be as simple as running a command like this
13976one:
13977
13978@example
13979guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
13980@end example
13981
1c0c417d
LC
13982For this to work, the @code{glibc-dynamic-linker} procedure in
13983@code{(gnu packages bootstrap)} must be augmented to return the right
13984file name for libc's dynamic linker on that platform; likewise,
13985@code{system->linux-architecture} in @code{(gnu packages linux)} must be
13986taught about the new platform.
13987
cf4a9129 13988Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
13989to be updated to refer to these binaries on the target platform. That
13990is, the hashes and URLs of the bootstrap tarballs for the new platform
13991must be added alongside those of the currently supported platforms. The
13992bootstrap Guile tarball is treated specially: it is expected to be
03d0e2d2 13993available locally, and @file{gnu/local.mk} has rules do download it for
1c0c417d
LC
13994the supported architectures; a rule for the new platform must be added
13995as well.
cf4a9129
LC
13996
13997In practice, there may be some complications. First, it may be that the
13998extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
13999above) is not recognized by all the GNU tools. Typically, glibc
14000recognizes some of these, whereas GCC uses an extra @code{--with-abi}
14001configure flag (see @code{gcc.scm} for examples of how to handle this).
14002Second, some of the required packages could fail to build for that
14003platform. Lastly, the generated binaries could be broken for some
14004reason.
4af2447e 14005
9bf3c1a7 14006@c *********************************************************************
8c01b9d0 14007@include contributing.texi
c78bd12b 14008
568717fd
LC
14009@c *********************************************************************
14010@node Acknowledgments
14011@chapter Acknowledgments
14012
136787cb
LC
14013Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
14014which was designed and
4c7ac9aa
LC
14015implemented by Eelco Dolstra, with contributions from other people (see
14016the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
14017management, and promoted unprecedented features, such as transactional
14018package upgrades and rollbacks, per-user profiles, and referentially
14019transparent build processes. Without this work, Guix would not exist.
14020
14021The Nix-based software distributions, Nixpkgs and NixOS, have also been
14022an inspiration for Guix.
14023
4c7ac9aa
LC
14024GNU@tie{}Guix itself is a collective work with contributions from a
14025number of people. See the @file{AUTHORS} file in Guix for more
14026information on these fine people. The @file{THANKS} file lists people
14027who have helped by reporting bugs, taking care of the infrastructure,
14028providing artwork and themes, making suggestions, and more---thank you!
14029
14030
568717fd
LC
14031@c *********************************************************************
14032@node GNU Free Documentation License
14033@appendix GNU Free Documentation License
e32171ee 14034@cindex license, GNU Free Documentation License
568717fd
LC
14035@include fdl-1.3.texi
14036
14037@c *********************************************************************
14038@node Concept Index
14039@unnumbered Concept Index
14040@printindex cp
14041
a85b83d2
LC
14042@node Programming Index
14043@unnumbered Programming Index
14044@syncodeindex tp fn
14045@syncodeindex vr fn
568717fd
LC
14046@printindex fn
14047
14048@bye
14049
14050@c Local Variables:
14051@c ispell-local-dictionary: "american";
14052@c End: