gnu: r-plotrix: Update to 3.6-4.
[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.
cccbc639 13@set OPENPGP-SIGNING-KEY-ID BCA689B636553801C3C62150197A5888235FACAC
debc6360 14
7df7a74e 15@copying
8de938d5 16Copyright @copyright{} 2012, 2013, 2014, 2015, 2016, 2017 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 30Copyright @copyright{} 2016 Jan Nieuwenhuizen@*
9747d189
AW
31Copyright @copyright{} 2016 Julien Lepiller@*
32Copyright @copyright{} 2016 Alex ter Weele
7df7a74e
NK
33
34Permission is granted to copy, distribute and/or modify this document
35under the terms of the GNU Free Documentation License, Version 1.3 or
36any later version published by the Free Software Foundation; with no
37Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
38copy of the license is included in the section entitled ``GNU Free
39Documentation License''.
40@end copying
568717fd 41
abd67856 42@dircategory System administration
568717fd 43@direntry
abd67856
LC
44* Guix: (guix). Manage installed software and system configuration.
45* guix package: (guix)Invoking guix package. Installing, removing, and upgrading packages.
46* guix build: (guix)Invoking guix build. Building packages.
47* guix gc: (guix)Invoking guix gc. Reclaiming unused disk space.
48* guix pull: (guix)Invoking guix pull. Update the list of available packages.
49* guix system: (guix)Invoking guix system. Manage the operating system configuration.
568717fd 50@end direntry
568717fd 51
372c4bbc
DT
52@dircategory Software development
53@direntry
abd67856 54* guix environment: (guix)Invoking guix environment. Building development environments with Guix.
372c4bbc
DT
55@end direntry
56
568717fd 57@titlepage
7730d112
LC
58@title GNU Guix Reference Manual
59@subtitle Using the GNU Guix Functional Package Manager
2cbed07e 60@author The GNU Guix Developers
568717fd
LC
61
62@page
63@vskip 0pt plus 1filll
64Edition @value{EDITION} @*
65@value{UPDATED} @*
66
7df7a74e 67@insertcopying
568717fd
LC
68@end titlepage
69
568717fd
LC
70@contents
71
72@c *********************************************************************
73@node Top
f8348b91 74@top GNU Guix
568717fd 75
f8348b91
LC
76This document describes GNU Guix version @value{VERSION}, a functional
77package management tool written for the GNU system.
568717fd
LC
78
79@menu
80* Introduction:: What is Guix about?
bd5e766b 81* Installation:: Installing Guix.
eeaf4427 82* Package Management:: Package installation, upgrade, etc.
568717fd
LC
83* Programming Interface:: Using Guix in Scheme.
84* Utilities:: Package management commands.
a1ba8475 85* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 86* Contributing:: Your help needed!
568717fd
LC
87
88* Acknowledgments:: Thanks!
89* GNU Free Documentation License:: The license of this manual.
90* Concept Index:: Concepts.
a85b83d2 91* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
92
93@detailmenu
94 --- The Detailed Node Listing ---
95
96Installation
97
1b2b8177 98* Binary Installation:: Getting Guix running in no time!
aaa3eaa9 99* Requirements:: Software needed to build and run Guix.
ec0339cd 100* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
101* Setting Up the Daemon:: Preparing the build daemon's environment.
102* Invoking guix-daemon:: Running the build daemon.
0e2d0213 103* Application Setup:: Application-specific setup.
aaa3eaa9
LC
104
105Setting Up the Daemon
106
107* Build Environment Setup:: Preparing the isolated build environment.
108* Daemon Offload Setup:: Offloading builds to remote machines.
109
110Package Management
111
112* Features:: How Guix will make your life brighter.
113* Invoking guix package:: Package installation, removal, etc.
aaa3eaa9
LC
114* Substitutes:: Downloading pre-built binaries.
115* Packages with Multiple Outputs:: Single source package, multiple outputs.
116* Invoking guix gc:: Running the garbage collector.
117* Invoking guix pull:: Fetching the latest Guix and distribution.
118* Invoking guix archive:: Exporting and importing store files.
119
120Programming Interface
121
122* Defining Packages:: Defining new packages.
123* Build Systems:: Specifying how packages are built.
124* The Store:: Manipulating the package store.
125* Derivations:: Low-level interface to package derivations.
126* The Store Monad:: Purely functional interface to the store.
127* G-Expressions:: Manipulating build expressions.
128
92492b23
LC
129Defining Packages
130
131* package Reference:: The package data type.
132* origin Reference:: The origin data type.
133
aaa3eaa9
LC
134Utilities
135
136* Invoking guix build:: Building packages from the command line.
fcc58db6 137* Invoking guix edit:: Editing package definitions.
aaa3eaa9
LC
138* Invoking guix download:: Downloading a file and printing its hash.
139* Invoking guix hash:: Computing the cryptographic hash of a file.
140* Invoking guix import:: Importing package definitions.
141* Invoking guix refresh:: Updating package definitions.
142* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 143* Invoking guix size:: Profiling disk usage.
88856916 144* Invoking guix graph:: Visualizing the graph of packages.
aaa3eaa9 145* Invoking guix environment:: Setting up development environments.
aff8ce7c 146* Invoking guix publish:: Sharing substitutes.
d23c20f1 147* Invoking guix challenge:: Challenging substitute servers.
f11c444d 148* Invoking guix copy:: Copying to and from a remote store.
32efa254 149* Invoking guix container:: Process isolation.
aaa3eaa9 150
e3009f60
LC
151Invoking @command{guix build}
152
153* Common Build Options:: Build options for most commands.
f11c444d 154* Package Transformation Options:: Creating variants of packages.
e3009f60
LC
155* Additional Build Options:: Options specific to 'guix build'.
156
aaa3eaa9
LC
157GNU Distribution
158
159* System Installation:: Installing the whole operating system.
35ed9306 160* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
161* Installing Debugging Files:: Feeding the debugger.
162* Security Updates:: Deploying security fixes quickly.
163* Package Modules:: Packages from the programmer's viewpoint.
164* Packaging Guidelines:: Growing the distribution.
165* Bootstrapping:: GNU/Linux built from scratch.
166* Porting:: Targeting another platform or kernel.
167
e3009f60
LC
168System Installation
169
170* Limitations:: What you can expect.
171* Hardware Considerations:: Supported hardware.
172* USB Stick Installation:: Preparing the installation medium.
173* Preparing for Installation:: Networking, partitioning, etc.
174* Proceeding with the Installation:: The real thing.
c8b54374 175* Installing GuixSD in a VM:: GuixSD playground.
e3009f60
LC
176* Building the Installation Image:: How this comes to be.
177
aaa3eaa9
LC
178System Configuration
179
180* Using the Configuration System:: Customizing your GNU system.
181* operating-system Reference:: Detail of operating-system declarations.
182* File Systems:: Configuring file system mounts.
183* Mapped Devices:: Block device extra processing.
184* User Accounts:: Specifying user accounts.
598e19dc 185* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
186* Services:: Specifying system services.
187* Setuid Programs:: Programs running with root privileges.
1b2b8177 188* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 189* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
190* Initial RAM Disk:: Linux-Libre bootstrapping.
191* GRUB Configuration:: Configuring the boot loader.
192* Invoking guix system:: Instantiating a system configuration.
97d76250 193* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
aaa3eaa9
LC
194* Defining Services:: Adding new service definitions.
195
196Services
197
198* Base Services:: Essential system services.
c311089b 199* Scheduled Job Execution:: The mcron service.
92c03a87 200* Log Rotation:: The rottlog service.
aaa3eaa9
LC
201* Networking Services:: Network setup, SSH daemon, etc.
202* X Window:: Graphical display.
f11c444d 203* Printing Services:: Local and remote printer support.
1b2b8177
LC
204* Desktop Services:: D-Bus and desktop services.
205* Database Services:: SQL databases.
d8c18af8 206* Mail Services:: IMAP, POP3, SMTP, and all that.
859e367d 207* Kerberos Services:: Kerberos services.
cbd02397 208* Web Services:: Web servers.
eb419bc9 209* Network File System:: NFS related services.
f11c444d 210* Continuous Integration:: The Cuirass service.
dbc6d370 211* Miscellaneous Services:: Other services.
aaa3eaa9 212
0adfe95a
LC
213Defining Services
214
215* Service Composition:: The model for composing services.
216* Service Types and Services:: Types and services.
217* Service Reference:: API reference.
dd17bc38 218* Shepherd Services:: A particular type of service.
0adfe95a 219
aaa3eaa9
LC
220Packaging Guidelines
221
ec0339cd
LC
222* Software Freedom:: What may go into the distribution.
223* Package Naming:: What's in a name?
224* Version Numbers:: When the name is not enough.
cbd02397 225* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
226* Python Modules:: Taming the snake.
227* Perl Modules:: Little pearls.
e1c963bf 228* Java Packages:: Coffee break.
ec0339cd 229* Fonts:: Fond of fonts.
aaa3eaa9 230
8c01b9d0
ML
231Contributing
232
233* Building from Git:: The latest and greatest.
234* Running Guix Before It Is Installed:: Hacker tricks.
235* The Perfect Setup:: The right tools.
236* Coding Style:: Hygiene of the contributor.
237* Submitting Patches:: Share your work.
238
239Coding Style
240
241* Programming Paradigm:: How to compose your elements.
242* Modules:: Where to store your code?
243* Data Types and Pattern Matching:: Implementing data structures.
244* Formatting Code:: Writing conventions.
245
aaa3eaa9 246@end detailmenu
568717fd
LC
247@end menu
248
249@c *********************************************************************
250@node Introduction
251@chapter Introduction
252
6f773606 253@cindex purpose
c80e7e55 254GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
6f773606
LC
255using the international phonetic alphabet (IPA).} is a package
256management tool for the GNU system. Guix makes it easy for unprivileged
257users to install, upgrade, or remove packages, to roll back to a
258previous package set, to build packages from source, and generally
259assists with the creation and maintenance of software environments.
260
261@cindex user interfaces
262Guix provides a command-line package management interface
263(@pxref{Invoking guix package}), a set of command-line utilities
deb6276d 264(@pxref{Utilities}), as well as Scheme programming interfaces
6f773606
LC
265(@pxref{Programming Interface}).
266@cindex build daemon
267Its @dfn{build daemon} is responsible for building packages on behalf of
268users (@pxref{Setting Up the Daemon}) and for downloading pre-built
269binaries from authorized sources (@pxref{Substitutes}).
270
271@cindex extensibility of the distribution
e32171ee 272@cindex customization, of packages
6f773606
LC
273Guix includes package definitions for many GNU and non-GNU packages, all
274of which @uref{https://www.gnu.org/philosophy/free-sw.html, respect the
275user's computing freedom}. It is @emph{extensible}: users can write
276their own package definitions (@pxref{Defining Packages}) and make them
277available as independent package modules (@pxref{Package Modules}). It
278is also @emph{customizable}: users can @emph{derive} specialized package
279definitions from existing ones, including from the command line
280(@pxref{Package Transformation Options}).
281
282@cindex Guix System Distribution
283@cindex GuixSD
284You can install GNU@tie{}Guix on top of an existing GNU/Linux system
285where it complements the available tools without interference
286(@pxref{Installation}), or you can use it as part of the standalone
287@dfn{Guix System Distribution} or GuixSD (@pxref{GNU Distribution}).
288With GNU@tie{}GuixSD, you @emph{declare} all aspects of the operating
289system configuration and Guix takes care of instantiating the
290configuration in a transactional, reproducible, and stateless fashion
291(@pxref{System Configuration}).
568717fd
LC
292
293@cindex functional package management
6f773606 294Under the hood, Guix implements the @dfn{functional package management}
136787cb
LC
295discipline pioneered by Nix (@pxref{Acknowledgments}).
296In Guix, the package build and installation process is seen
6f773606 297as a @emph{function}, in the mathematical sense. That function takes inputs,
4bfc4ea3
NK
298such as build scripts, a compiler, and libraries, and
299returns an installed package. As a pure function, its result depends
568717fd
LC
300solely on its inputs---for instance, it cannot refer to software or
301scripts that were not explicitly passed as inputs. A build function
4bfc4ea3 302always produces the same result when passed a given set of inputs. It
f97c9175 303cannot alter the environment of the running system in
568717fd
LC
304any way; for instance, it cannot create, modify, or delete files outside
305of its build and installation directories. This is achieved by running
e900c503 306build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 307explicit inputs are visible.
568717fd 308
e531ac2a 309@cindex store
568717fd 310The result of package build functions is @dfn{cached} in the file
e531ac2a 311system, in a special directory called @dfn{the store} (@pxref{The
f97c9175 312Store}). Each package is installed in a directory of its own in the
834129e0 313store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
314a hash of all the inputs used to build that package; thus, changing an
315input yields a different directory name.
316
f97c9175
AE
317This approach is the foundation for the salient features of Guix: support
318for transactional package upgrade and rollback, per-user installation, and
eeaf4427 319garbage collection of packages (@pxref{Features}).
568717fd 320
a1ba8475 321
bd5e766b
LC
322@c *********************************************************************
323@node Installation
324@chapter Installation
325
e32171ee 326@cindex installing Guix
48febeb8
LC
327GNU Guix is available for download from its website at
328@url{http://www.gnu.org/software/guix/}. This section describes the
329software requirements of Guix, as well as how to install it and get
330ready to use it.
bd5e766b 331
5af6de3e
LC
332Note that this section is concerned with the installation of the package
333manager, which can be done on top of a running GNU/Linux system. If,
334instead, you want to install the complete GNU operating system,
6621cdb6 335@pxref{System Installation}.
5af6de3e 336
d23ef788
LC
337@cindex foreign distro
338When installed on a running GNU/Linux system---thereafter called a
339@dfn{foreign distro}---GNU@tie{}Guix complements the available tools
340without interference. Its data lives exclusively in two directories,
341usually @file{/gnu/store} and @file{/var/guix}; other files on your
342system, such as @file{/etc}, are left untouched.
343
7fcf2a0b
LC
344Once installed, Guix can be updated by running @command{guix pull}
345(@pxref{Invoking guix pull}).
346
bd5e766b 347@menu
09722b11 348* Binary Installation:: Getting Guix running in no time!
bd5e766b 349* Requirements:: Software needed to build and run Guix.
ec0339cd 350* Running the Test Suite:: Testing Guix.
bd5e766b
LC
351* Setting Up the Daemon:: Preparing the build daemon's environment.
352* Invoking guix-daemon:: Running the build daemon.
0e2d0213 353* Application Setup:: Application-specific setup.
bd5e766b
LC
354@end menu
355
09722b11
LC
356@node Binary Installation
357@section Binary Installation
358
e32171ee 359@cindex installing Guix from binaries
09722b11
LC
360This section describes how to install Guix on an arbitrary system from a
361self-contained tarball providing binaries for Guix and for all its
362dependencies. This is often quicker than installing from source, which
363is described in the next sections. The only requirement is to have
364GNU@tie{}tar and Xz.
365
366Installing goes along these lines:
367
368@enumerate
369@item
e32171ee 370@cindex downloading Guix binary
09722b11 371Download the binary tarball from
daa8922a
LC
372@indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz},
373where @var{system} is @code{x86_64-linux} for an @code{x86_64} machine
374already running the kernel Linux, and so on.
375
debc6360 376@c The following is somewhat duplicated in ``System Installation''.
daa8922a
LC
377Make sure to download the associated @file{.sig} file and to verify the
378authenticity of the tarball against it, along these lines:
379
380@example
381$ wget ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
382$ gpg --verify guix-binary-@value{VERSION}.@var{system}.tar.xz.sig
383@end example
384
f97c9175 385If that command fails because you do not have the required public key,
daa8922a
LC
386then run this command to import it:
387
388@example
debc6360 389$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
daa8922a
LC
390@end example
391
392@noindent
393and rerun the @code{gpg --verify} command.
debc6360 394@c end authentication part
09722b11
LC
395
396@item
397As @code{root}, run:
398
399@example
5dc42964 400# cd /tmp
254b1c2e
LC
401# tar --warning=no-timestamp -xf \
402 guix-binary-@value{VERSION}.@var{system}.tar.xz
5dc42964 403# mv var/guix /var/ && mv gnu /
09722b11
LC
404@end example
405
7acd3439
LC
406This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}.
407The latter contains a ready-to-use profile for @code{root} (see next
408step.)
09722b11 409
5dc3ce5f
LC
410Do @emph{not} unpack the tarball on a working Guix system since that
411would overwrite its own essential files.
412
254b1c2e 413The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does
e9ba6357
LC
414not emit warnings about ``implausibly old time stamps'' (such
415warnings were triggered by GNU@tie{}tar 1.26 and older; recent
416versions are fine.)
417They stem from the fact that all the
254b1c2e
LC
418files in the archive have their modification time set to zero (which
419means January 1st, 1970.) This is done on purpose to make sure the
420archive content is independent of its creation time, thus making it
421reproducible.
422
7acd3439
LC
423@item
424Make @code{root}'s profile available under @file{~/.guix-profile}:
425
426@example
427# ln -sf /var/guix/profiles/per-user/root/guix-profile \
428 ~root/.guix-profile
429@end example
430
43c33047
LC
431@item
432Create the group and user accounts for build users as explained below
433(@pxref{Build Environment Setup}).
434
09722b11 435@item
bf98aea9 436Run the daemon, and set it to automatically start on boot.
c8e26887 437
bf98aea9
LC
438If your host distro uses the systemd init system, this can be achieved
439with these commands:
c8e26887
GC
440
441@example
b7230de5 442# ln -s ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
c8e26887
GC
443 /etc/systemd/system/
444# systemctl start guix-daemon && systemctl enable guix-daemon
445@end example
446
447If your host distro uses the Upstart init system:
09722b11
LC
448
449@example
b7230de5 450# ln -s ~root/.guix-profile/lib/upstart/system/guix-daemon.conf /etc/init/
bf98aea9 451# start guix-daemon
09722b11
LC
452@end example
453
c8e26887
GC
454Otherwise, you can still start the daemon manually with:
455
456@example
457# ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild
458@end example
d2825c96 459
09722b11
LC
460@item
461Make the @command{guix} command available to other users on the machine,
462for instance with:
463
464@example
465# mkdir -p /usr/local/bin
466# cd /usr/local/bin
d72d05f9 467# ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
09722b11 468@end example
39f8ed14 469
aca738f3
LC
470It is also a good idea to make the Info version of this manual available
471there:
472
473@example
474# mkdir -p /usr/local/share/info
475# cd /usr/local/share/info
476# for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
477 do ln -s $i ; done
478@end example
479
480That way, assuming @file{/usr/local/share/info} is in the search path,
481running @command{info guix} will open this manual (@pxref{Other Info
482Directories,,, texinfo, GNU Texinfo}, for more details on changing the
483Info search path.)
484
39f8ed14 485@item
e32171ee 486@cindex substitutes, authorization thereof
df061d07
LC
487To use substitutes from @code{hydra.gnu.org} or one of its mirrors
488(@pxref{Substitutes}), authorize them:
39f8ed14
LC
489
490@example
7acd3439 491# guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
39f8ed14 492@end example
09722b11
LC
493@end enumerate
494
bf98aea9 495This completes root-level install of Guix. Each user will need to
7414de0a 496perform additional steps to make their Guix environment ready for use,
c8e26887 497@pxref{Application Setup}.
09722b11 498
c8e26887
GC
499You can confirm that Guix is working by installing a sample package into
500the root profile:
09722b11
LC
501
502@example
c8e26887 503# guix package -i hello
09722b11
LC
504@end example
505
c8e26887
GC
506The @code{guix} package must remain available in @code{root}'s profile,
507or it would become subject to garbage collection---in which case you
508would find yourself badly handicapped by the lack of the @command{guix}
bf98aea9
LC
509command. In other words, do not remove @code{guix} by running
510@code{guix package -r guix}.
511
512The binary installation tarball can be (re)produced and verified simply
513by running the following command in the Guix source tree:
514
515@example
516make guix-binary.@var{system}.tar.xz
517@end example
c8e26887 518
09722b11 519
bd5e766b
LC
520@node Requirements
521@section Requirements
522
09722b11
LC
523This section lists requirements when building Guix from source. The
524build procedure for Guix is the same as for other GNU software, and is
525not covered here. Please see the files @file{README} and @file{INSTALL}
526in the Guix source tree for additional details.
527
bd5e766b
LC
528GNU Guix depends on the following packages:
529
530@itemize
47c66da0 531@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later;
288dca55 532@item @url{http://gnupg.org/, GNU libgcrypt};
f0b98b84 533@item @url{http://www.gnu.org/software/make/, GNU Make}.
8a96bd4b
ID
534@end itemize
535
536The following dependencies are optional:
537
538@itemize
9b7bd1b1
LC
539@item
540Installing @uref{http://gnutls.org/, GnuTLS-Guile} will allow you to
541access @code{https} URLs for substitutes, which is highly recommended
542(@pxref{Substitutes}). It also allows you to access HTTPS URLs with the
543@command{guix download} command (@pxref{Invoking guix download}), the
544@command{guix import pypi} command, and the @command{guix import cpan}
545command. @xref{Guile Preparations, how to install the GnuTLS bindings
546for Guile,, gnutls-guile, GnuTLS-Guile}.
547
288dca55 548@item
8a96bd4b 549Installing
288dca55 550@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
551allow you to use the @command{guix import pypi} command (@pxref{Invoking
552guix import}). It is of
288dca55 553interest primarily for developers and not for casual users.
4591c02e 554
21531add
LC
555@item
556@c Note: We need at least 0.10.2 for 'channel-send-eof'.
f11c444d
LC
557Support for build offloading (@pxref{Daemon Offload Setup}) and
558@command{guix copy} (@pxref{Invoking guix copy}) depends on
21531add
LC
559@uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH},
560version 0.10.2 or later.
561
4591c02e
LC
562@item
563When @url{http://zlib.net, zlib} is available, @command{guix publish}
564can compress build byproducts (@pxref{Invoking guix publish}).
bd5e766b
LC
565@end itemize
566
567Unless @code{--disable-daemon} was passed to @command{configure}, the
568following packages are also needed:
569
570@itemize
368d08f7
LC
571@item @url{http://sqlite.org, SQLite 3};
572@item @url{http://www.bzip.org, libbz2};
573@item @url{http://gcc.gnu.org, GCC's g++}, with support for the
574C++11 standard.
bd5e766b
LC
575@end itemize
576
e32171ee 577@cindex state directory
ef5f5c86
LC
578When configuring Guix on a system that already has a Guix installation,
579be sure to specify the same state directory as the existing installation
580using the @code{--localstatedir} option of the @command{configure}
581script (@pxref{Directory Variables, @code{localstatedir},, standards,
582GNU Coding Standards}). The @command{configure} script protects against
583unintended misconfiguration of @var{localstatedir} so you do not
584inadvertently corrupt your store (@pxref{The Store}).
585
e32171ee 586@cindex Nix, compatibility
4bfc4ea3
NK
587When a working installation of @url{http://nixos.org/nix/, the Nix package
588manager} is available, you
bd5e766b 589can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 590Nix replaces the three dependencies above.
bd5e766b 591
b22a12fd
LC
592Guix is compatible with Nix, so it is possible to share the same store
593between both. To do so, you must pass @command{configure} not only the
594same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
595@code{--localstatedir} value. The latter is essential because it
596specifies where the database that stores metadata about the store is
834129e0 597located, among other things. The default values for Nix are
b22a12fd 598@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
599Note that @code{--disable-daemon} is not required if
600your goal is to share the store with Nix.
b22a12fd 601
ec0339cd
LC
602@node Running the Test Suite
603@section Running the Test Suite
604
e32171ee 605@cindex test suite
ec0339cd
LC
606After a successful @command{configure} and @code{make} run, it is a good
607idea to run the test suite. It can help catch issues with the setup or
608environment, or bugs in Guix itself---and really, reporting test
609failures is a good way to help improve the software. To run the test
610suite, type:
611
612@example
613make check
614@end example
615
616Test cases can run in parallel: you can use the @code{-j} option of
617GNU@tie{}make to speed things up. The first run may take a few minutes
618on a recent machine; subsequent runs will be faster because the store
619that is created for test purposes will already have various things in
620cache.
621
a887fd8d
LC
622It is also possible to run a subset of the tests by defining the
623@code{TESTS} makefile variable as in this example:
624
625@example
626make check TESTS="tests/store.scm tests/cpio.scm"
627@end example
628
a9edb211
ML
629By default, tests results are displayed at a file level. In order to
630see the details of every individual test cases, it is possible to define
631the @code{SCM_LOG_DRIVER_FLAGS} makefile variable as in this example:
632
633@example
634make check TESTS="tests/base64.scm" SCM_LOG_DRIVER_FLAGS="--brief=no"
635@end example
636
ec0339cd 637Upon failure, please email @email{bug-guix@@gnu.org} and attach the
a9edb211
ML
638@file{test-suite.log} file. Please specify the Guix version being used
639as well as version numbers of the dependencies (@pxref{Requirements}) in
640your message.
ec0339cd 641
0a2f2848
LC
642Guix also comes with a whole-system test suite that tests complete
643GuixSD operating system instances. It can only run on systems where
644Guix is already installed, using:
645
646@example
647make check-system
648@end example
649
650@noindent
651or, again, by defining @code{TESTS} to select a subset of tests to run:
652
653@example
654make check-system TESTS="basic mcron"
655@end example
656
657These system tests are defined in the @code{(gnu tests @dots{})}
658modules. They work by running the operating systems under test with
659lightweight instrumentation in a virtual machine (VM). They can be
660computationally intensive or rather cheap, depending on whether
661substitutes are available for their dependencies (@pxref{Substitutes}).
662Some of them require a lot of storage space to hold VM images.
663
664Again in case of test failures, please send @email{bug-guix@@gnu.org}
665all the details.
666
bd5e766b
LC
667@node Setting Up the Daemon
668@section Setting Up the Daemon
669
670@cindex daemon
671Operations such as building a package or running the garbage collector
49e6291a 672are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
673behalf of clients. Only the daemon may access the store and its
674associated database. Thus, any operation that manipulates the store
675goes through the daemon. For instance, command-line tools such as
e49951eb 676@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
677daemon (@i{via} remote procedure calls) to instruct it what to do.
678
49e6291a 679The following sections explain how to prepare the build daemon's
f97c9175 680environment. See also @ref{Substitutes}, for information on how to allow
225dafde 681the daemon to download pre-built binaries.
49e6291a
LC
682
683@menu
684* Build Environment Setup:: Preparing the isolated build environment.
685* Daemon Offload Setup:: Offloading builds to remote machines.
686@end menu
687
688@node Build Environment Setup
689@subsection Build Environment Setup
690
e32171ee 691@cindex build environment
bd5e766b
LC
692In a standard multi-user setup, Guix and its daemon---the
693@command{guix-daemon} program---are installed by the system
834129e0 694administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
695@command{guix-daemon} runs as @code{root}. Unprivileged users may use
696Guix tools to build packages or otherwise access the store, and the
697daemon will do it on their behalf, ensuring that the store is kept in a
698consistent state, and allowing built packages to be shared among users.
699
700@cindex build users
701When @command{guix-daemon} runs as @code{root}, you may not want package
702build processes themselves to run as @code{root} too, for obvious
703security reasons. To avoid that, a special pool of @dfn{build users}
704should be created for use by build processes started by the daemon.
705These build users need not have a shell and a home directory: they will
706just be used when the daemon drops @code{root} privileges in build
707processes. Having several such users allows the daemon to launch
708distinct build processes under separate UIDs, which guarantees that they
709do not interfere with each other---an essential feature since builds are
710regarded as pure functions (@pxref{Introduction}).
711
712On a GNU/Linux system, a build user pool may be created like this (using
713Bash syntax and the @code{shadow} commands):
714
091196b3
LC
715@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
716@c for why `-G' is needed.
bd5e766b 717@example
cfc149dc
LC
718# groupadd --system guixbuild
719# for i in `seq -w 1 10`;
bd5e766b 720 do
cfc149dc
LC
721 useradd -g guixbuild -G guixbuild \
722 -d /var/empty -s `which nologin` \
723 -c "Guix build user $i" --system \
724 guixbuilder$i;
bd5e766b
LC
725 done
726@end example
727
728@noindent
54eb03ab
LC
729The number of build users determines how many build jobs may run in
730parallel, as specified by the @option{--max-jobs} option
eca69fc0
LC
731(@pxref{Invoking guix-daemon, @option{--max-jobs}}). To use
732@command{guix system vm} and related commands, you may need to add the
733build users to the @code{kvm} group so they can access @file{/dev/kvm},
734using @code{-G guixbuild,kvm} instead of @code{-G guixbuild}
735(@pxref{Invoking guix system}).
736
737The @code{guix-daemon} program may then be run as @code{root} with the
d2825c96
LC
738following command@footnote{If your machine uses the systemd init system,
739dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service}
740file in @file{/etc/systemd/system} will ensure that
ad227484
MDRS
741@command{guix-daemon} is automatically started. Similarly, if your
742machine uses the Upstart init system, drop the
743@file{@var{prefix}/lib/upstart/system/guix-daemon.conf}
744file in @file{/etc/init}.}:
bd5e766b
LC
745
746@example
cfc149dc 747# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
748@end example
749
e900c503 750@cindex chroot
b095792f
LC
751@noindent
752This way, the daemon starts build processes in a chroot, under one of
cfc149dc 753the @code{guixbuilder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
754environment contains nothing but:
755
756@c Keep this list in sync with libstore/build.cc! -----------------------
757@itemize
758@item
4743a4da
LC
759a minimal @code{/dev} directory, created mostly independently from the
760host @code{/dev}@footnote{``Mostly'', because while the set of files
761that appear in the chroot's @code{/dev} is fixed, most of these files
762can only be created if the host has them.};
763
764@item
f97c9175 765the @code{/proc} directory; it only shows the processes of the container
4743a4da 766since a separate PID name space is used;
6dc99317
LC
767
768@item
769@file{/etc/passwd} with an entry for the current user and an entry for
770user @file{nobody};
771
772@item
773@file{/etc/group} with an entry for the user's group;
774
775@item
776@file{/etc/hosts} with an entry that maps @code{localhost} to
777@code{127.0.0.1};
778
779@item
780a writable @file{/tmp} directory.
781@end itemize
b095792f 782
cb960102
ED
783You can influence the directory where the daemon stores build trees
784@i{via} the @code{TMPDIR} environment variable. However, the build tree
f97c9175 785within the chroot is always called @file{/tmp/guix-build-@var{name}.drv-0},
cb960102
ED
786where @var{name} is the derivation name---e.g., @code{coreutils-8.24}.
787This way, the value of @code{TMPDIR} does not leak inside build
788environments, which avoids discrepancies in cases where build processes
789capture the name of their build tree.
790
e0c941fe
LC
791@vindex http_proxy
792The daemon also honors the @code{http_proxy} environment variable for
793HTTP downloads it performs, be it for fixed-output derivations
794(@pxref{Derivations}) or for substitutes (@pxref{Substitutes}).
795
1e2644bb
LC
796If you are installing Guix as an unprivileged user, it is still possible
797to run @command{guix-daemon} provided you pass @code{--disable-chroot}.
798However, build processes will not be isolated from one another, and not
799from the rest of the system. Thus, build processes may interfere with
800each other, and may access programs, libraries, and other files
801available on the system---making it much harder to view them as
802@emph{pure} functions.
bd5e766b 803
49e6291a
LC
804
805@node Daemon Offload Setup
806@subsection Using the Offload Facility
807
808@cindex offloading
4ec2e92d 809@cindex build hook
21531add
LC
810When desired, the build daemon can @dfn{offload} derivation builds to
811other machines running Guix, using the @code{offload} @dfn{build
812hook}@footnote{This feature is available only when
813@uref{https://github.com/artyom-poptsov/guile-ssh, Guile-SSH} is
814present.}. When that
49e6291a 815feature is enabled, a list of user-specified build machines is read from
f97c9175 816@file{/etc/guix/machines.scm}; every time a build is requested, for
49e6291a 817instance via @code{guix build}, the daemon attempts to offload it to one
f97c9175 818of the machines that satisfy the constraints of the derivation, in
49e6291a
LC
819particular its system type---e.g., @file{x86_64-linux}. Missing
820prerequisites for the build are copied over SSH to the target machine,
821which then proceeds with the build; upon success the output(s) of the
822build are copied back to the initial machine.
823
4ec2e92d 824The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
825
826@example
827(list (build-machine
828 (name "eightysix.example.org")
829 (system "x86_64-linux")
21531add 830 (host-key "ssh-ed25519 AAAAC3Nza@dots{}")
49e6291a 831 (user "bob")
21531add 832 (speed 2.)) ;incredibly fast!
49e6291a
LC
833
834 (build-machine
835 (name "meeps.example.org")
836 (system "mips64el-linux")
21531add 837 (host-key "ssh-rsa AAAAB3Nza@dots{}")
49e6291a
LC
838 (user "alice")
839 (private-key
840 (string-append (getenv "HOME")
21531add 841 "/.ssh/identity-for-guix"))))
49e6291a
LC
842@end example
843
844@noindent
845In the example above we specify a list of two build machines, one for
846the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
847architecture.
848
849In fact, this file is---not surprisingly!---a Scheme file that is
850evaluated when the @code{offload} hook is started. Its return value
851must be a list of @code{build-machine} objects. While this example
852shows a fixed list of build machines, one could imagine, say, using
853DNS-SD to return a list of potential build machines discovered in the
854local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
855Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
856detailed below.
4ec2e92d 857
c678a4ee 858@deftp {Data Type} build-machine
f97c9175
AE
859This data type represents build machines to which the daemon may offload
860builds. The important fields are:
49e6291a
LC
861
862@table @code
863
864@item name
f97c9175 865The host name of the remote machine.
49e6291a
LC
866
867@item system
f97c9175 868The system type of the remote machine---e.g., @code{"x86_64-linux"}.
49e6291a
LC
869
870@item user
871The user account to use when connecting to the remote machine over SSH.
872Note that the SSH key pair must @emph{not} be passphrase-protected, to
873allow non-interactive logins.
874
21531add
LC
875@item host-key
876This must be the machine's SSH @dfn{public host key} in OpenSSH format.
877This is used to authenticate the machine when we connect to it. It is a
878long string that looks like this:
879
880@example
881ssh-ed25519 AAAAC3NzaC@dots{}mde+UhL hint@@example.org
882@end example
883
884If the machine is running the OpenSSH daemon, @command{sshd}, the host
885key can be found in a file such as
886@file{/etc/ssh/ssh_host_ed25519_key.pub}.
887
888If the machine is running the SSH daemon of GNU@tie{}lsh,
889@command{lshd}, the host key is in @file{/etc/lsh/host-key.pub} or a
890similar file. It can be converted to the OpenSSH format using
891@command{lsh-export-key} (@pxref{Converting keys,,, lsh, LSH Manual}):
892
893@example
894$ lsh-export-key --openssh < /etc/lsh/host-key.pub
895ssh-rsa AAAAB3NzaC1yc2EAAAAEOp8FoQAAAQEAs1eB46LV@dots{}
896@end example
897
49e6291a
LC
898@end table
899
4ec2e92d 900A number of optional fields may be specified:
49e6291a 901
21531add 902@table @asis
49e6291a 903
21531add
LC
904@item @code{port} (default: @code{22})
905Port number of SSH server on the machine.
cecd72d5 906
21531add
LC
907@item @code{private-key} (default: @file{~/.ssh/id_rsa})
908The SSH private key file to use when connecting to the machine, in
909OpenSSH format.
49e6291a 910
1d48cf94
LC
911@item @code{compression} (default: @code{"zlib@@openssh.com,zlib"})
912@itemx @code{compression-level} (default: @code{3})
913The SSH-level compression methods and compression level requested.
914
915Note that offloading relies on SSH compression to reduce bandwidth usage
916when transferring files to and from build machines.
917
cf283dd9
LC
918@item @code{daemon-socket} (default: @code{"/var/guix/daemon-socket/socket"})
919File name of the Unix-domain socket @command{guix-daemon} is listening
920to on that machine.
c4fdfd6f 921
21531add
LC
922@item @code{parallel-builds} (default: @code{1})
923The number of builds that may run in parallel on the machine.
49e6291a 924
21531add 925@item @code{speed} (default: @code{1.0})
49e6291a
LC
926A ``relative speed factor''. The offload scheduler will tend to prefer
927machines with a higher speed factor.
928
21531add 929@item @code{features} (default: @code{'()})
49e6291a
LC
930A list of strings denoting specific features supported by the machine.
931An example is @code{"kvm"} for machines that have the KVM Linux modules
932and corresponding hardware support. Derivations can request features by
933name, and they will be scheduled on matching build machines.
934
935@end table
c678a4ee 936@end deftp
49e6291a 937
aebaee95
LC
938The @code{guile} command must be in the search path on the build
939machines. In addition, the Guix modules must be in
c4fdfd6f
LC
940@code{$GUILE_LOAD_PATH} on the build machine---you can check whether
941this is the case by running:
942
943@example
21531add 944ssh build-machine guile -c "'(use-modules (guix config))'"
c4fdfd6f 945@end example
49e6291a 946
f97c9175 947There is one last thing to do once @file{machines.scm} is in place. As
49e6291a 948explained above, when offloading, files are transferred back and forth
c4fdfd6f
LC
949between the machine stores. For this to work, you first need to
950generate a key pair on each machine to allow the daemon to export signed
951archives of files from the store (@pxref{Invoking guix archive}):
49e6291a
LC
952
953@example
954# guix archive --generate-key
955@end example
956
957@noindent
c4fdfd6f
LC
958Each build machine must authorize the key of the master machine so that
959it accepts store items it receives from the master:
960
961@example
962# guix archive --authorize < master-public-key.txt
963@end example
964
965@noindent
966Likewise, the master machine must authorize the key of each build machine.
967
968All the fuss with keys is here to express pairwise mutual trust
969relations between the master and the build machines. Concretely, when
970the master receives files from a build machine (and @i{vice versa}), its
971build daemon can make sure they are genuine, have not been tampered
972with, and that they are signed by an authorized key.
49e6291a 973
aebaee95
LC
974@cindex offload test
975To test whether your setup is operational, run this command on the
976master node:
977
978@example
979# guix offload test
980@end example
981
982This will attempt to connect to each of the build machines specified in
983@file{/etc/guix/machines.scm}, make sure Guile and the Guix modules are
984available on each machine, attempt to export to the machine and import
985from it, and report any error in the process.
986
987If you want to test a different machine file, just specify it on the
988command line:
989
990@example
991# guix offload test machines-qualif.scm
992@end example
993
27991c97
LC
994Last, you can test the subset of the machines whose name matches a
995regular expression like this:
996
997@example
998# guix offload test machines.scm '\.gnu\.org$'
999@end example
49e6291a 1000
bd5e766b
LC
1001@node Invoking guix-daemon
1002@section Invoking @command{guix-daemon}
1003
1004The @command{guix-daemon} program implements all the functionality to
1005access the store. This includes launching build processes, running the
1006garbage collector, querying the availability of a build result, etc. It
1007is normally run as @code{root} like this:
1008
1009@example
cfc149dc 1010# guix-daemon --build-users-group=guixbuild
bd5e766b
LC
1011@end example
1012
1013@noindent
081145cf 1014For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 1015
e900c503
LC
1016@cindex chroot
1017@cindex container, build environment
1018@cindex build environment
1019@cindex reproducible builds
bd5e766b
LC
1020By default, @command{guix-daemon} launches build processes under
1021different UIDs, taken from the build group specified with
1022@code{--build-users-group}. In addition, each build process is run in a
1023chroot environment that only contains the subset of the store that the
1024build process depends on, as specified by its derivation
1025(@pxref{Programming Interface, derivation}), plus a set of specific
1026system directories. By default, the latter contains @file{/dev} and
e900c503
LC
1027@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
1028@dfn{container}: in addition to having its own file system tree, it has
1029a separate mount name space, its own PID name space, network name space,
1030etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 1031
cbc538fe
LC
1032When the daemon performs a build on behalf of the user, it creates a
1033build directory under @file{/tmp} or under the directory specified by
1034its @code{TMPDIR} environment variable; this directory is shared with
1035the container for the duration of the build. Be aware that using a
1036directory other than @file{/tmp} can affect build results---for example,
1037with a longer directory name, a build process that uses Unix-domain
1038sockets might hit the name length limitation for @code{sun_path}, which
1039it would otherwise not hit.
1040
1041The build directory is automatically deleted upon completion, unless the
1042build failed and the client specified @option{--keep-failed}
1043(@pxref{Invoking guix build, @option{--keep-failed}}).
1044
bd5e766b
LC
1045The following command-line options are supported:
1046
1047@table @code
1048@item --build-users-group=@var{group}
1049Take users from @var{group} to run build processes (@pxref{Setting Up
1050the Daemon, build users}).
1051
6858f9d1 1052@item --no-substitutes
b5385b52 1053@cindex substitutes
6858f9d1 1054Do not use substitutes for build products. That is, always build things
c4202d60
LC
1055locally instead of allowing downloads of pre-built binaries
1056(@pxref{Substitutes}).
6858f9d1 1057
b5385b52
LC
1058By default substitutes are used, unless the client---such as the
1059@command{guix package} command---is explicitly invoked with
1060@code{--no-substitutes}.
1061
1062When the daemon runs with @code{--no-substitutes}, clients can still
1063explicitly enable substitution @i{via} the @code{set-build-options}
1064remote procedure call (@pxref{The Store}).
1065
9176607e 1066@item --substitute-urls=@var{urls}
f8a8e0fe 1067@anchor{daemon-substitute-urls}
9176607e 1068Consider @var{urls} the default whitespace-separated list of substitute
df061d07
LC
1069source URLs. When this option is omitted,
1070@indicateurl{https://mirror.hydra.gnu.org https://hydra.gnu.org} is used
1071(@code{mirror.hydra.gnu.org} is a mirror of @code{hydra.gnu.org}).
9176607e
LC
1072
1073This means that substitutes may be downloaded from @var{urls}, as long
1074as they are signed by a trusted signature (@pxref{Substitutes}).
1075
4ec2e92d
LC
1076@cindex build hook
1077@item --no-build-hook
1078Do not use the @dfn{build hook}.
1079
1080The build hook is a helper program that the daemon can start and to
1081which it submits build requests. This mechanism is used to offload
1082builds to other machines (@pxref{Daemon Offload Setup}).
1083
bd5e766b
LC
1084@item --cache-failures
1085Cache build failures. By default, only successful builds are cached.
1086
30d9aa54
LC
1087When this option is used, @command{guix gc --list-failures} can be used
1088to query the set of store items marked as failed; @command{guix gc
1089--clear-failures} removes store items from the set of cached failures.
1090@xref{Invoking guix gc}.
1091
bd5e766b
LC
1092@item --cores=@var{n}
1093@itemx -c @var{n}
1094Use @var{n} CPU cores to build each derivation; @code{0} means as many
1095as available.
1096
6efc160e 1097The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
1098as the @code{--cores} option of @command{guix build} (@pxref{Invoking
1099guix build}).
bd5e766b
LC
1100
1101The effect is to define the @code{NIX_BUILD_CORES} environment variable
1102in the build process, which can then use it to exploit internal
1103parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
1104
1105@item --max-jobs=@var{n}
1106@itemx -M @var{n}
1107Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
1108@code{1}. Setting it to @code{0} means that no builds will be performed
1109locally; instead, the daemon will offload builds (@pxref{Daemon Offload
1110Setup}), or simply fail.
bd5e766b 1111
ecf84b7c
LC
1112@item --rounds=@var{N}
1113Build each derivation @var{n} times in a row, and raise an error if
1114consecutive build results are not bit-for-bit identical. Note that this
1115setting can be overridden by clients such as @command{guix build}
1116(@pxref{Invoking guix build}).
1117
b4528110
ED
1118When used in conjunction with @option{--keep-failed}, the differing
1119output is kept in the store, under @file{/gnu/store/@dots{}-check}.
1120This makes it easy to look for differences between the two results.
1121
bd5e766b
LC
1122@item --debug
1123Produce debugging output.
1124
1125This is useful to debug daemon start-up issues, but then it may be
1126overridden by clients, for example the @code{--verbosity} option of
e49951eb 1127@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
1128
1129@item --chroot-directory=@var{dir}
1130Add @var{dir} to the build chroot.
1131
1132Doing this may change the result of build processes---for instance if
1133they use optional dependencies found in @var{dir} when it is available,
1134and not otherwise. For that reason, it is not recommended to do so.
1135Instead, make sure that each derivation declares all the inputs that it
1136needs.
1137
1138@item --disable-chroot
1139Disable chroot builds.
1140
1141Using this option is not recommended since, again, it would allow build
1e2644bb
LC
1142processes to gain access to undeclared dependencies. It is necessary,
1143though, when @command{guix-daemon} is running under an unprivileged user
1144account.
bd5e766b
LC
1145
1146@item --disable-log-compression
1147Disable compression of the build logs.
1148
1da983b9
LC
1149Unless @code{--lose-logs} is used, all the build logs are kept in the
1150@var{localstatedir}. To save space, the daemon automatically compresses
1151them with bzip2 by default. This option disables that.
1152
ab3893d7
LC
1153@item --disable-deduplication
1154@cindex deduplication
bd5e766b
LC
1155Disable automatic file ``deduplication'' in the store.
1156
1da983b9 1157By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
1158if a newly added file is identical to another one found in the store,
1159the daemon makes the new file a hard link to the other file. This can
4988dd40 1160noticeably reduce disk usage, at the expense of slightly increased
ab3893d7
LC
1161input/output load at the end of a build process. This option disables
1162this optimization.
1da983b9 1163
6e37066e
LC
1164@item --gc-keep-outputs[=yes|no]
1165Tell whether the garbage collector (GC) must keep outputs of live
1166derivations.
1167
1168When set to ``yes'', the GC will keep the outputs of any live derivation
1169available in the store---the @code{.drv} files. The default is ``no'',
1170meaning that derivation outputs are kept only if they are GC roots.
1171
1172@item --gc-keep-derivations[=yes|no]
1173Tell whether the garbage collector (GC) must keep derivations
1174corresponding to live outputs.
1175
1176When set to ``yes'', as is the case by default, the GC keeps
1177derivations---i.e., @code{.drv} files---as long as at least one of their
1178outputs is live. This allows users to keep track of the origins of
1179items in their store. Setting it to ``no'' saves a bit of disk space.
1180
1181Note that when both @code{--gc-keep-derivations} and
1182@code{--gc-keep-outputs} are used, the effect is to keep all the build
1183prerequisites (the sources, compiler, libraries, and other build-time
1184tools) of live objects in the store, regardless of whether these
1185prerequisites are live. This is convenient for developers since it
1186saves rebuilds or downloads.
1187
bd5e766b
LC
1188@item --impersonate-linux-2.6
1189On Linux-based systems, impersonate Linux 2.6. This means that the
1190kernel's @code{uname} system call will report 2.6 as the release number.
1191
1192This might be helpful to build programs that (usually wrongfully) depend
1193on the kernel version number.
1194
1195@item --lose-logs
1196Do not keep build logs. By default they are kept under
ce33631f 1197@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
1198
1199@item --system=@var{system}
1200Assume @var{system} as the current system type. By default it is the
1201architecture/kernel pair found at configure time, such as
1202@code{x86_64-linux}.
b8d2aa26
LC
1203
1204@item --listen=@var{socket}
1205Listen for connections on @var{socket}, the file name of a Unix-domain
1206socket. The default socket is
1207@file{@var{localstatedir}/daemon-socket/socket}. This option is only
1208useful in exceptional circumstances, such as if you need to run several
1209daemons on the same machine.
bd5e766b
LC
1210@end table
1211
1212
0e2d0213
LC
1213@node Application Setup
1214@section Application Setup
1215
d23ef788 1216@cindex foreign distro
85e57214
LC
1217When using Guix on top of GNU/Linux distribution other than GuixSD---a
1218so-called @dfn{foreign distro}---a few additional steps are needed to
1219get everything in place. Here are some of them.
0e2d0213
LC
1220
1221@subsection Locales
1222
5c3c1427 1223@anchor{locales-and-locpath}
0e2d0213 1224@cindex locales, when not on GuixSD
5c3c1427 1225@vindex LOCPATH
85e57214 1226@vindex GUIX_LOCPATH
f97c9175
AE
1227Packages installed @i{via} Guix will not use the locale data of the
1228host system. Instead, you must first install one of the locale packages
85e57214
LC
1229available with Guix and then define the @code{GUIX_LOCPATH} environment
1230variable:
0e2d0213
LC
1231
1232@example
1233$ guix package -i glibc-locales
85e57214 1234$ export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
0e2d0213
LC
1235@end example
1236
1237Note that the @code{glibc-locales} package contains data for all the
1238locales supported by the GNU@tie{}libc and weighs in at around
f97c9175 1239110@tie{}MiB. Alternatively, the @code{glibc-utf8-locales} is smaller but
0e2d0213
LC
1240limited to a few UTF-8 locales.
1241
85e57214
LC
1242The @code{GUIX_LOCPATH} variable plays a role similar to @code{LOCPATH}
1243(@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library Reference
1244Manual}). There are two important differences though:
1245
1246@enumerate
1247@item
f97c9175 1248@code{GUIX_LOCPATH} is honored only by the libc in Guix, and not by the libc
85e57214 1249provided by foreign distros. Thus, using @code{GUIX_LOCPATH} allows you
f97c9175 1250to make sure the programs of the foreign distro will not end up loading
85e57214
LC
1251incompatible locale data.
1252
1253@item
1254libc suffixes each entry of @code{GUIX_LOCPATH} with @code{/X.Y}, where
1255@code{X.Y} is the libc version---e.g., @code{2.22}. This means that,
1256should your Guix profile contain a mixture of programs linked against
1257different libc version, each libc version will only try to load locale
1258data in the right format.
1259@end enumerate
1260
1261This is important because the locale data format used by different libc
1262versions may be incompatible.
1263
9a5187b6
LC
1264@subsection Name Service Switch
1265
1266@cindex name service switch, glibc
1267@cindex NSS (name service switch), glibc
1268@cindex nscd (name service caching daemon)
1269@cindex name service caching daemon (nscd)
1270When using Guix on a foreign distro, we @emph{strongly recommend} that
1271the system run the GNU C library's @dfn{name service cache daemon},
1272@command{nscd}, which should be listening on the
1273@file{/var/run/nscd/socket} socket. Failing to do that, applications
1274installed with Guix may fail to look up host names or user accounts, or
1275may even crash. The next paragraphs explain why.
1276
1277@cindex @file{nsswitch.conf}
1278The GNU C library implements a @dfn{name service switch} (NSS), which is
1279an extensible mechanism for ``name lookups'' in general: host name
1280resolution, user accounts, and more (@pxref{Name Service Switch,,, libc,
1281The GNU C Library Reference Manual}).
1282
1283@cindex Network information service (NIS)
1284@cindex NIS (Network information service)
1285Being extensible, the NSS supports @dfn{plugins}, which provide new name
1286lookup implementations: for example, the @code{nss-mdns} plugin allow
1287resolution of @code{.local} host names, the @code{nis} plugin allows
1288user account lookup using the Network information service (NIS), and so
1289on. These extra ``lookup services'' are configured system-wide in
1290@file{/etc/nsswitch.conf}, and all the programs running on the system
1291honor those settings (@pxref{NSS Configuration File,,, libc, The GNU C
1292Reference Manual}).
1293
1294When they perform a name lookup---for instance by calling the
1295@code{getaddrinfo} function in C---applications first try to connect to
1296the nscd; on success, nscd performs name lookups on their behalf. If
1297the nscd is not running, then they perform the name lookup by
1298themselves, by loading the name lookup services into their own address
1299space and running it. These name lookup services---the
1300@file{libnss_*.so} files---are @code{dlopen}'d, but they may come from
1301the host system's C library, rather than from the C library the
1302application is linked against (the C library coming from Guix).
1303
1304And this is where the problem is: if your application is linked against
1305Guix's C library (say, glibc 2.24) and tries to load NSS plugins from
1306another C library (say, @code{libnss_mdns.so} for glibc 2.22), it will
1307likely crash or have its name lookups fail unexpectedly.
1308
1309Running @command{nscd} on the system, among other advantages, eliminates
1310this binary incompatibility problem because those @code{libnss_*.so}
1311files are loaded in the @command{nscd} process, not in applications
1312themselves.
1313
0e2d0213
LC
1314@subsection X11 Fonts
1315
e32171ee 1316@cindex fonts
4988dd40 1317The majority of graphical applications use Fontconfig to locate and
f97c9175
AE
1318load fonts and perform X11-client-side rendering. The @code{fontconfig}
1319package in Guix looks for fonts in @file{$HOME/.guix-profile}
0e2d0213 1320by default. Thus, to allow graphical applications installed with Guix
f97c9175 1321to display fonts, you have to install fonts with Guix as well.
0e2d0213 1322Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and
8fe5b1d1 1323@code{font-gnu-freefont-ttf}.
0e2d0213 1324
5c36edc8
LC
1325To display text written in Chinese languages, Japanese, or Korean in
1326graphical applications, consider installing
1327@code{font-adobe-source-han-sans} or @code{font-wqy-zenhei}. The former
1328has multiple outputs, one per language family (@pxref{Packages with
1329Multiple Outputs}). For instance, the following command installs fonts
1330for Chinese languages:
1331
1332@example
1333guix package -i font-adobe-source-han-sans:cn
1334@end example
1335
e32171ee 1336@cindex @code{xterm}
1a3e6b15
AK
1337Older programs such as @command{xterm} do not use Fontconfig and instead
1338rely on server-side font rendering. Such programs require to specify a
1339full name of a font using XLFD (X Logical Font Description), like this:
1340
1341@example
1342-*-dejavu sans-medium-r-normal-*-*-100-*-*-*-*-*-1
1343@end example
1344
1345To be able to use such full names for the TrueType fonts installed in
1346your Guix profile, you need to extend the font path of the X server:
1347
1348@example
1349xset +fp ~/.guix-profile/share/fonts/truetype
1350@end example
1351
e32171ee 1352@cindex @code{xlsfonts}
1a3e6b15
AK
1353After that, you can run @code{xlsfonts} (from @code{xlsfonts} package)
1354to make sure your TrueType fonts are listed there.
1355
b3129f2b
LC
1356@subsection X.509 Certificates
1357
e32171ee 1358@cindex @code{nss-certs}
b3129f2b
LC
1359The @code{nss-certs} package provides X.509 certificates, which allow
1360programs to authenticate Web servers accessed over HTTPS.
1361
1362When using Guix on a foreign distro, you can install this package and
1363define the relevant environment variables so that packages know where to
80d944b7 1364look for certificates. @xref{X.509 Certificates}, for detailed
b3129f2b
LC
1365information.
1366
6d97319c
AK
1367@subsection Emacs Packages
1368
e32171ee 1369@cindex @code{emacs}
6d97319c
AK
1370When you install Emacs packages with Guix, the elisp files may be placed
1371either in @file{$HOME/.guix-profile/share/emacs/site-lisp/} or in
1372sub-directories of
1373@file{$HOME/.guix-profile/share/emacs/site-lisp/guix.d/}. The latter
1374directory exists because potentially there may exist thousands of Emacs
1375packages and storing all their files in a single directory may be not
1376reliable (because of name conflicts). So we think using a separate
1377directory for each package is a good idea. It is very similar to how
1378the Emacs package system organizes the file structure (@pxref{Package
1379Files,,, emacs, The GNU Emacs Manual}).
1380
1381By default, Emacs (installed with Guix) ``knows'' where these packages
f97c9175 1382are placed, so you do not need to perform any configuration. If, for
6d97319c 1383some reason, you want to avoid auto-loading Emacs packages installed
f97c9175 1384with Guix, you can do so by running Emacs with @code{--no-site-file}
6d97319c
AK
1385option (@pxref{Init File,,, emacs, The GNU Emacs Manual}).
1386
0e2d0213
LC
1387@c TODO What else?
1388
eeaf4427
LC
1389@c *********************************************************************
1390@node Package Management
1391@chapter Package Management
1392
e32171ee 1393@cindex packages
f8348b91 1394The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427 1395remove software packages, without having to know about their build
f97c9175 1396procedures or dependencies. Guix also goes beyond this obvious set of
eeaf4427
LC
1397features.
1398
1399This chapter describes the main features of Guix, as well as the package
deb6276d
AK
1400management tools it provides. Along with the command-line interface
1401described below (@pxref{Invoking guix package, @code{guix package}}),
1402you may also use Emacs Interface, after installing @code{emacs-guix}
1403package (run @kbd{M-x guix-help} command to start with it):
1404
1405@example
1406guix package -i emacs-guix
1407@end example
eeaf4427
LC
1408
1409@menu
1410* Features:: How Guix will make your life brighter.
e49951eb 1411* Invoking guix package:: Package installation, removal, etc.
c4202d60 1412* Substitutes:: Downloading pre-built binaries.
760c60d6 1413* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 1414* Invoking guix gc:: Running the garbage collector.
f651b477 1415* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 1416* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
1417@end menu
1418
1419@node Features
1420@section Features
1421
1422When using Guix, each package ends up in the @dfn{package store}, in its
1423own directory---something that resembles
deb6276d 1424@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
eeaf4427
LC
1425
1426Instead of referring to these directories, users have their own
1427@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
1428use. These profiles are stored within each user's home directory, at
1429@code{$HOME/.guix-profile}.
eeaf4427 1430
821b0015 1431For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 1432@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 1433@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
1434@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
1435simply continues to point to
834129e0 1436@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 1437coexist on the same system without any interference.
eeaf4427 1438
e49951eb 1439The @command{guix package} command is the central tool to manage
f97c9175 1440packages (@pxref{Invoking guix package}). It operates on the per-user
821b0015 1441profiles, and can be used @emph{with normal user privileges}.
eeaf4427 1442
e32171ee 1443@cindex transactions
eeaf4427
LC
1444The command provides the obvious install, remove, and upgrade
1445operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 1446the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 1447@command{guix package} process is terminated during the transaction,
eeaf4427
LC
1448or if a power outage occurs during the transaction, then the user's
1449profile remains in its previous state, and remains usable.
1450
1451In addition, any package transaction may be @emph{rolled back}. So, if,
1452for example, an upgrade installs a new version of a package that turns
1453out to have a serious bug, users may roll back to the previous instance
4af2447e 1454of their profile, which was known to work well. Similarly, the global
6f773606
LC
1455system configuration on GuixSD is subject to
1456transactional upgrades and roll-back
4af2447e 1457(@pxref{Using the Configuration System}).
eeaf4427 1458
f97c9175
AE
1459All packages in the package store may be @emph{garbage-collected}.
1460Guix can determine which packages are still referenced by user
fe8ff028 1461profiles, and remove those that are provably no longer referenced
e49951eb 1462(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
1463generations of their profile so that the packages they refer to can be
1464collected.
eeaf4427 1465
e900c503
LC
1466@cindex reproducibility
1467@cindex reproducible builds
eeaf4427
LC
1468Finally, Guix takes a @dfn{purely functional} approach to package
1469management, as described in the introduction (@pxref{Introduction}).
834129e0 1470Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
1471inputs that were used to build that package---compiler, libraries, build
1472scripts, etc. This direct correspondence allows users to make sure a
1473given package installation matches the current state of their
e900c503
LC
1474distribution. It also helps maximize @dfn{build reproducibility}:
1475thanks to the isolated build environments that are used, a given build
1476is likely to yield bit-identical files when performed on different
1477machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 1478
c4202d60 1479@cindex substitutes
eeaf4427 1480This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 1481deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 1482available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
1483downloads it and unpacks it;
1484otherwise, it builds the package from source, locally
bf9eacd2
LC
1485(@pxref{Substitutes}). Because build results are usually bit-for-bit
1486reproducible, users do not have to trust servers that provide
1487substitutes: they can force a local build and @emph{challenge} providers
1488(@pxref{Invoking guix challenge}).
eeaf4427 1489
f5fd4fd2
LC
1490Control over the build environment is a feature that is also useful for
1491developers. The @command{guix environment} command allows developers of
1492a package to quickly set up the right development environment for their
f97c9175
AE
1493package, without having to manually install the dependencies of the
1494package into their profile (@pxref{Invoking guix environment}).
f5fd4fd2 1495
e49951eb
MW
1496@node Invoking guix package
1497@section Invoking @command{guix package}
eeaf4427 1498
e32171ee
JD
1499@cindex installing packages
1500@cindex removing packages
1501@cindex package installation
1502@cindex package removal
e49951eb 1503The @command{guix package} command is the tool that allows users to
eeaf4427
LC
1504install, upgrade, and remove packages, as well as rolling back to
1505previous configurations. It operates only on the user's own profile,
1506and works with normal user privileges (@pxref{Features}). Its syntax
1507is:
1508
1509@example
e49951eb 1510guix package @var{options}
eeaf4427 1511@end example
e32171ee 1512@cindex transactions
ba55b1cb 1513Primarily, @var{options} specifies the operations to be performed during
eeaf4427 1514the transaction. Upon completion, a new profile is created, but
99bd74d5 1515previous @dfn{generations} of the profile remain available, should the user
eeaf4427
LC
1516want to roll back.
1517
6447738c
MW
1518For example, to remove @code{lua} and install @code{guile} and
1519@code{guile-cairo} in a single transaction:
1520
1521@example
1522guix package -r lua -i guile guile-cairo
1523@end example
1524
99bd74d5
LC
1525@command{guix package} also supports a @dfn{declarative approach}
1526whereby the user specifies the exact set of packages to be available and
1527passes it @i{via} the @option{--manifest} option
1528(@pxref{profile-manifest, @option{--manifest}}).
1529
e32171ee 1530@cindex profile
b9e5c0a9 1531For each user, a symlink to the user's default profile is automatically
0ec1af59 1532created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
1533current generation of the user's default profile. Thus, users can add
1534@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
1535variable, and so on.
d664f1b4
LC
1536@cindex search paths
1537If you are not using the Guix System Distribution, consider adding the
1538following lines to your @file{~/.bash_profile} (@pxref{Bash Startup
1539Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned
1540shells get all the right environment variable definitions:
1541
1542@example
1543GUIX_PROFILE="$HOME/.guix-profile" \
1544source "$HOME/.guix-profile/etc/profile"
1545@end example
b9e5c0a9 1546
4379c35b
LC
1547In a multi-user setup, user profiles are stored in a place registered as
1548a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
1549to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
1550@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
1551@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
1552@code{--localstatedir}, and @var{user} is the user name. The
1553@file{per-user} directory is created when @command{guix-daemon} is
1554started, and the @var{user} sub-directory is created by @command{guix
1555package}.
0ec1af59
LC
1556
1557The @var{options} can be among the following:
1558
eeaf4427
LC
1559@table @code
1560
6447738c
MW
1561@item --install=@var{package} @dots{}
1562@itemx -i @var{package} @dots{}
1563Install the specified @var{package}s.
eeaf4427 1564
6447738c 1565Each @var{package} may specify either a simple package name, such as
1b846da8
ML
1566@code{guile}, or a package name followed by an at-sign and version number,
1567such as @code{guile@@1.8.8} or simply @code{guile@@1.8} (in the latter
724311a2
LC
1568case, the newest version prefixed by @code{1.8} is selected.)
1569
1570If no version number is specified, the
dc5669cd
MW
1571newest available version will be selected. In addition, @var{package}
1572may contain a colon, followed by the name of one of the outputs of the
1b846da8 1573package, as in @code{gcc:doc} or @code{binutils@@2.22:lib}
e7f34eb0
LC
1574(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
1575name (and optionally version) are searched for among the GNU
1576distribution modules (@pxref{Package Modules}).
eeaf4427 1577
461572cc
LC
1578@cindex propagated inputs
1579Sometimes packages have @dfn{propagated inputs}: these are dependencies
21461f27
LC
1580that automatically get installed along with the required package
1581(@pxref{package-propagated-inputs, @code{propagated-inputs} in
1582@code{package} objects}, for information about propagated inputs in
1583package definitions).
461572cc 1584
21461f27 1585@anchor{package-cmd-propagated-inputs}
461572cc
LC
1586An example is the GNU MPC library: its C header files refer to those of
1587the GNU MPFR library, which in turn refer to those of the GMP library.
1588Thus, when installing MPC, the MPFR and GMP libraries also get installed
1589in the profile; removing MPC also removes MPFR and GMP---unless they had
f97c9175 1590also been explicitly installed by the user.
461572cc 1591
ba7ea5ce 1592Besides, packages sometimes rely on the definition of environment
5924080d 1593variables for their search paths (see explanation of
ba7ea5ce 1594@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
1595environment variable definitions are reported here.
1596
5d4b411f
LC
1597@item --install-from-expression=@var{exp}
1598@itemx -e @var{exp}
1599Install the package @var{exp} evaluates to.
1600
1601@var{exp} must be a Scheme expression that evaluates to a
1602@code{<package>} object. This option is notably useful to disambiguate
1603between same-named variants of a package, with expressions such as
1604@code{(@@ (gnu packages base) guile-final)}.
1605
1606Note that this option installs the first output of the specified
1607package, which may be insufficient when needing a specific output of a
1608multiple-output package.
1609
0d279400
DT
1610@item --install-from-file=@var{file}
1611@itemx -f @var{file}
1612Install the package that the code within @var{file} evaluates to.
1613
1614As an example, @var{file} might contain a definition like this
1615(@pxref{Defining Packages}):
1616
1617@example
1618@verbatiminclude package-hello.scm
1619@end example
1620
baacf042 1621Developers may find it useful to include such a @file{guix.scm} file
f97c9175 1622in the root of their project source tree that can be used to test
0d279400
DT
1623development snapshots and create reproducible development environments
1624(@pxref{Invoking guix environment}).
1625
6447738c
MW
1626@item --remove=@var{package} @dots{}
1627@itemx -r @var{package} @dots{}
1628Remove the specified @var{package}s.
eeaf4427 1629
6447738c 1630As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1631and/or output name in addition to the package name. For instance,
1632@code{-r glibc:debug} would remove the @code{debug} output of
1633@code{glibc}.
1634
6447738c
MW
1635@item --upgrade[=@var{regexp} @dots{}]
1636@itemx -u [@var{regexp} @dots{}]
e32171ee 1637@cindex upgrading packages
6447738c
MW
1638Upgrade all the installed packages. If one or more @var{regexp}s are
1639specified, upgrade only installed packages whose name matches a
d5f01e48 1640@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1641
f651b477
LC
1642Note that this upgrades package to the latest version of packages found
1643in the distribution currently installed. To update your distribution,
1644you should regularly run @command{guix pull} (@pxref{Invoking guix
1645pull}).
1646
d5f01e48
MW
1647@item --do-not-upgrade[=@var{regexp} @dots{}]
1648When used together with the @code{--upgrade} option, do @emph{not}
1649upgrade any packages whose name matches a @var{regexp}. For example, to
1650upgrade all packages in the current profile except those containing the
1651substring ``emacs'':
1652
1653@example
1654$ guix package --upgrade . --do-not-upgrade emacs
1655@end example
1656
99bd74d5 1657@item @anchor{profile-manifest}--manifest=@var{file}
1b676447 1658@itemx -m @var{file}
99bd74d5
LC
1659@cindex profile declaration
1660@cindex profile manifest
1661Create a new generation of the profile from the manifest object
1b676447
DT
1662returned by the Scheme code in @var{file}.
1663
99bd74d5
LC
1664This allows you to @emph{declare} the profile's contents rather than
1665constructing it through a sequence of @code{--install} and similar
1666commands. The advantage is that @var{file} can be put under version
1667control, copied to different machines to reproduce the same profile, and
1668so on.
1669
1670@c FIXME: Add reference to (guix profile) documentation when available.
1671@var{file} must return a @dfn{manifest} object, which is roughly a list
1672of packages:
1b676447 1673
99bd74d5 1674@findex packages->manifest
1b676447 1675@example
99bd74d5 1676(use-package-modules guile emacs)
1b676447
DT
1677
1678(packages->manifest
99bd74d5
LC
1679 (list emacs
1680 guile-2.0
1b676447 1681 ;; Use a specific package output.
99bd74d5 1682 (list guile-2.0 "debug")))
1b676447
DT
1683@end example
1684
24e262f0 1685@item --roll-back
e32171ee
JD
1686@cindex rolling back
1687@cindex undoing transactions
1688@cindex transactions, undoing
24e262f0
LC
1689Roll back to the previous @dfn{generation} of the profile---i.e., undo
1690the last transaction.
1691
1692When combined with options such as @code{--install}, roll back occurs
1693before any other actions.
1694
d9307267 1695When rolling back from the first generation that actually contains
4b2bc804 1696installed packages, the profile is made to point to the @dfn{zeroth
f97c9175 1697generation}, which contains no files apart from its own metadata.
d9307267 1698
f97c9175
AE
1699After having rolled back, installing, removing, or upgrading packages
1700overwrites previous future generations. Thus, the history of the
1701generations in a profile is always linear.
82fe08ed 1702
b3bb82f1
AK
1703@item --switch-generation=@var{pattern}
1704@itemx -S @var{pattern}
e32171ee 1705@cindex generations
b3bb82f1
AK
1706Switch to a particular generation defined by @var{pattern}.
1707
1708@var{pattern} may be either a generation number or a number prefixed
1709with ``+'' or ``-''. The latter means: move forward/backward by a
1710specified number of generations. For example, if you want to return to
1711the latest generation after @code{--roll-back}, use
1712@code{--switch-generation=+1}.
1713
1714The difference between @code{--roll-back} and
1715@code{--switch-generation=-1} is that @code{--switch-generation} will
1716not make a zeroth generation, so if a specified generation does not
1717exist, the current generation will not be changed.
1718
dbc31ab2 1719@item --search-paths[=@var{kind}]
5924080d
LC
1720@cindex search paths
1721Report environment variable definitions, in Bash syntax, that may be
1722needed in order to use the set of installed packages. These environment
1723variables are used to specify @dfn{search paths} for files used by some
1724of the installed packages.
1725
1726For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1727environment variables to be defined so it can look for headers and
1728libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1729Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1730library are installed in the profile, then @code{--search-paths} will
1731suggest setting these variables to @code{@var{profile}/include} and
1732@code{@var{profile}/lib}, respectively.
1733
dbc31ab2
LC
1734The typical use case is to define these environment variables in the
1735shell:
1736
1737@example
1738$ eval `guix package --search-paths`
1739@end example
1740
1741@var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix},
1742meaning that the returned environment variable definitions will either
1743be exact settings, or prefixes or suffixes of the current value of these
1744variables. When omitted, @var{kind} defaults to @code{exact}.
1745
fc2d2339
LC
1746This option can also be used to compute the @emph{combined} search paths
1747of several profiles. Consider this example:
1748
1749@example
1750$ guix package -p foo -i guile
1751$ guix package -p bar -i guile-json
1752$ guix package -p foo -p bar --search-paths
1753@end example
1754
1755The last command above reports about the @code{GUILE_LOAD_PATH}
1756variable, even though, taken individually, neither @file{foo} nor
1757@file{bar} would lead to that recommendation.
1758
1759
eeaf4427
LC
1760@item --profile=@var{profile}
1761@itemx -p @var{profile}
1762Use @var{profile} instead of the user's default profile.
1763
70915c1a 1764@item --verbose
f97c9175
AE
1765Produce verbose output. In particular, emit the build log of the
1766environment on the standard error port.
70915c1a 1767
eeaf4427
LC
1768@item --bootstrap
1769Use the bootstrap Guile to build the profile. This option is only
1770useful to distribution developers.
1771
1772@end table
1773
f97c9175 1774In addition to these actions, @command{guix package} supports the
733b4130
LC
1775following options to query the current state of a profile, or the
1776availability of packages:
eeaf4427 1777
733b4130
LC
1778@table @option
1779
acc08466
NK
1780@item --search=@var{regexp}
1781@itemx -s @var{regexp}
b110869d 1782@cindex searching for packages
5763ad92 1783List the available packages whose name, synopsis, or description matches
f97c9175 1784@var{regexp}. Print all the metadata of matching packages in
299112d3
LC
1785@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1786GNU recutils manual}).
acc08466 1787
299112d3
LC
1788This allows specific fields to be extracted using the @command{recsel}
1789command, for instance:
1790
1791@example
e49951eb 1792$ guix package -s malloc | recsel -p name,version
299112d3
LC
1793name: glibc
1794version: 2.17
1795
1796name: libgc
1797version: 7.2alpha6
1798@end example
acc08466 1799
a12d92f5
LC
1800Similarly, to show the name of all the packages available under the
1801terms of the GNU@tie{}LGPL version 3:
1802
1803@example
1804$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1805name: elfutils
1806
1807name: gmp
1808@dots{}
1809@end example
1810
db5a9444
LC
1811It is also possible to refine search results using several @code{-s}
1812flags. For example, the following command returns a list of board
1813games:
1814
1815@example
1816$ guix package -s '\<board\>' -s game | recsel -p name
1817name: gnubg
1818@dots{}
1819@end example
1820
1821If we were to omit @code{-s game}, we would also get software packages
1822that deal with printed circuit boards; removing the angle brackets
1823around @code{board} would further add packages that have to do with
1824keyboards.
1825
b110869d
LC
1826And now for a more elaborate example. The following command searches
1827for cryptographic libraries, filters out Haskell, Perl, Python, and Ruby
1828libraries, and prints the name and synopsis of the matching packages:
1829
1830@example
1831$ guix package -s crypto -s library | \
1832 recsel -e '! (name ~ "^(ghc|perl|python|ruby)")' -p name,synopsis
1833@end example
1834
1835@noindent
1836@xref{Selection Expressions,,, recutils, GNU recutils manual}, for more
1837information on @dfn{selection expressions} for @code{recsel -e}.
1838
2aa6efb0
CR
1839@item --show=@var{package}
1840Show details about @var{package}, taken from the list of available packages, in
1841@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1842recutils manual}).
1843
1844@example
1845$ guix package --show=python | recsel -p name,version
1846name: python
1847version: 2.7.6
1848
1849name: python
1850version: 3.3.5
1851@end example
1852
1853You may also specify the full name of a package to only get details about a
1854specific version of it:
1855@example
ea206df4 1856$ guix package --show=python@@3.4 | recsel -p name,version
2aa6efb0 1857name: python
ea206df4 1858version: 3.4.3
2aa6efb0
CR
1859@end example
1860
1861
1862
733b4130
LC
1863@item --list-installed[=@var{regexp}]
1864@itemx -I [@var{regexp}]
bd9bde1c
LC
1865List the currently installed packages in the specified profile, with the
1866most recently installed packages shown last. When @var{regexp} is
1867specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1868
1869For each installed package, print the following items, separated by
1870tabs: the package name, its version string, the part of the package that
1871is installed (for instance, @code{out} for the default output,
1872@code{include} for its headers, etc.), and the path of this package in
1873the store.
1874
64fc89b6
LC
1875@item --list-available[=@var{regexp}]
1876@itemx -A [@var{regexp}]
5763ad92 1877List packages currently available in the distribution for this system
a1ba8475
LC
1878(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1879installed packages whose name matches @var{regexp}.
64fc89b6
LC
1880
1881For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1882its version string, the parts of the package (@pxref{Packages with
1883Multiple Outputs}), and the source location of its definition.
64fc89b6 1884
f566d765
LC
1885@item --list-generations[=@var{pattern}]
1886@itemx -l [@var{pattern}]
e32171ee 1887@cindex generations
f566d765
LC
1888Return a list of generations along with their creation dates; for each
1889generation, show the installed packages, with the most recently
4b2bc804
NK
1890installed packages shown last. Note that the zeroth generation is never
1891shown.
f566d765
LC
1892
1893For each installed package, print the following items, separated by
1894tabs: the name of a package, its version string, the part of the package
1895that is installed (@pxref{Packages with Multiple Outputs}), and the
1896location of this package in the store.
1897
1898When @var{pattern} is used, the command returns only matching
1899generations. Valid patterns include:
1900
1901@itemize
1902@item @emph{Integers and comma-separated integers}. Both patterns denote
1903generation numbers. For instance, @code{--list-generations=1} returns
1904the first one.
1905
1906And @code{--list-generations=1,8,2} outputs three generations in the
1907specified order. Neither spaces nor trailing commas are allowed.
1908
1909@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1910specified generations and everything in between. Note that the start of
f97c9175 1911a range must be smaller than its end.
f566d765
LC
1912
1913It is also possible to omit the endpoint. For example,
1914@code{--list-generations=2..}, returns all generations starting from the
1915second one.
1916
1917@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1918or months by passing an integer along with the first letter of the
d7ddb257
LC
1919duration. For example, @code{--list-generations=20d} lists generations
1920that are up to 20 days old.
f566d765
LC
1921@end itemize
1922
b7884ca3
NK
1923@item --delete-generations[=@var{pattern}]
1924@itemx -d [@var{pattern}]
d7ddb257
LC
1925When @var{pattern} is omitted, delete all generations except the current
1926one.
b7884ca3
NK
1927
1928This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1929When @var{pattern} is specified, delete the matching generations. When
1930@var{pattern} specifies a duration, generations @emph{older} than the
1931specified duration match. For instance, @code{--delete-generations=1m}
1932deletes generations that are more than one month old.
1933
391bdd8f
LC
1934If the current generation matches, it is @emph{not} deleted. Also, the
1935zeroth generation is never deleted.
b7884ca3 1936
f97c9175 1937Note that deleting generations prevents rolling back to them.
1bb9900a
LC
1938Consequently, this command must be used with care.
1939
733b4130 1940@end table
eeaf4427 1941
70ee5642 1942Finally, since @command{guix package} may actually start build
ccd7158d 1943processes, it supports all the common build options (@pxref{Common Build
f97c9175 1944Options}). It also supports package transformation options, such as
b8638f03
LC
1945@option{--with-source} (@pxref{Package Transformation Options}).
1946However, note that package transformations are lost when upgrading; to
f97c9175 1947preserve transformations across upgrades, you should define your own
b8638f03
LC
1948package variant in a Guile module and add it to @code{GUIX_PACKAGE_PATH}
1949(@pxref{Defining Packages}).
1950
70ee5642 1951
c4202d60
LC
1952@node Substitutes
1953@section Substitutes
1954
1955@cindex substitutes
1956@cindex pre-built binaries
1957Guix supports transparent source/binary deployment, which means that it
1958can either build things locally, or download pre-built items from a
1959server. We call these pre-built items @dfn{substitutes}---they are
1960substitutes for local build results. In many cases, downloading a
1961substitute is much faster than building things locally.
1962
1963Substitutes can be anything resulting from a derivation build
1964(@pxref{Derivations}). Of course, in the common case, they are
1965pre-built package binaries, but source tarballs, for instance, which
1966also result from derivation builds, can be available as substitutes.
1967
1968The @code{hydra.gnu.org} server is a front-end to a build farm that
1969builds packages from the GNU distribution continuously for some
deb6276d 1970architectures, and makes them available as substitutes. This is the
f8a8e0fe
LC
1971default source of substitutes; it can be overridden by passing the
1972@option{--substitute-urls} option either to @command{guix-daemon}
1973(@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}})
1974or to client tools such as @command{guix package}
1975(@pxref{client-substitute-urls,, client @option{--substitute-urls}
1976option}).
c4202d60 1977
9b7bd1b1
LC
1978Substitute URLs can be either HTTP or HTTPS@footnote{For HTTPS access,
1979the Guile bindings of GnuTLS must be installed. @xref{Requirements}.}
1980HTTPS is recommended because communications are encrypted; conversely,
1981using HTTP makes all communications visible to an eavesdropper, who
1982could use the information gathered to determine, for instance, whether
1983your system has unpatched security vulnerabilities.
1984
c4202d60
LC
1985@cindex security
1986@cindex digital signatures
e32171ee 1987@cindex substitutes, authorization thereof
df061d07
LC
1988To allow Guix to download substitutes from @code{hydra.gnu.org} or a
1989mirror thereof, you
c4202d60
LC
1990must add its public key to the access control list (ACL) of archive
1991imports, using the @command{guix archive} command (@pxref{Invoking guix
1992archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1993be compromised and to serve genuine substitutes.
1994
1995This public key is installed along with Guix, in
1996@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1997the installation prefix of Guix. If you installed Guix from source,
1998make sure you checked the GPG signature of
1999@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
2000Then, you can run something like this:
2001
2002@example
2003# guix archive --authorize < hydra.gnu.org.pub
2004@end example
2005
2006Once this is in place, the output of a command like @code{guix build}
2007should change from something like:
2008
2009@example
2010$ guix build emacs --dry-run
2011The following derivations would be built:
2012 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
2013 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
2014 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
2015 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
2016@dots{}
2017@end example
2018
2019@noindent
2020to something like:
2021
2022@example
2023$ guix build emacs --dry-run
2024The following files would be downloaded:
2025 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
2026 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
2027 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
2028 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
2029@dots{}
2030@end example
2031
2032@noindent
2033This indicates that substitutes from @code{hydra.gnu.org} are usable and
2034will be downloaded, when possible, for future builds.
2035
2036Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 2037one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
2038when attempting to use a substitute that has been tampered with.
2039
e0c941fe 2040@vindex http_proxy
9b7bd1b1
LC
2041Substitutes are downloaded over HTTP or HTTPS.
2042The @code{http_proxy} environment
e0c941fe
LC
2043variable can be set in the environment of @command{guix-daemon} and is
2044honored for downloads of substitutes. Note that the value of
2045@code{http_proxy} in the environment where @command{guix build},
2046@command{guix package}, and other client commands are run has
2047@emph{absolutely no effect}.
2048
9b7bd1b1
LC
2049When using HTTPS, the server's X.509 certificate is @emph{not} validated
2050(in other words, the server is not authenticated), contrary to what
2051HTTPS clients such as Web browsers usually do. This is because Guix
2052authenticates substitute information itself, as explained above, which
2053is what we care about (whereas X.509 certificates are about
2054authenticating bindings between domain names and public keys.)
2055
c4202d60
LC
2056The substitute mechanism can be disabled globally by running
2057@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
2058guix-daemon}). It can also be disabled temporarily by passing the
2059@code{--no-substitutes} option to @command{guix package}, @command{guix
2060build}, and other command-line tools.
2061
2062
9b7bd1b1
LC
2063@unnumberedsubsec On Trusting Binaries
2064
c4202d60
LC
2065Today, each individual's control over their own computing is at the
2066mercy of institutions, corporations, and groups with enough power and
2067determination to subvert the computing infrastructure and exploit its
2068weaknesses. While using @code{hydra.gnu.org} substitutes can be
2069convenient, we encourage users to also build on their own, or even run
2070their own build farm, such that @code{hydra.gnu.org} is less of an
8ce229fc
LC
2071interesting target. One way to help is by publishing the software you
2072build using @command{guix publish} so that others have one more choice
2073of server to download substitutes from (@pxref{Invoking guix publish}).
c4202d60
LC
2074
2075Guix has the foundations to maximize build reproducibility
2076(@pxref{Features}). In most cases, independent builds of a given
2077package or derivation should yield bit-identical results. Thus, through
2078a diverse set of independent package builds, we can strengthen the
d23c20f1
LC
2079integrity of our systems. The @command{guix challenge} command aims to
2080help users assess substitute servers, and to assist developers in
2081finding out about non-deterministic package builds (@pxref{Invoking guix
a8d65643
LC
2082challenge}). Similarly, the @option{--check} option of @command{guix
2083build} allows users to check whether previously-installed substitutes
2084are genuine by rebuilding them locally (@pxref{build-check,
2085@command{guix build --check}}).
c4202d60
LC
2086
2087In the future, we want Guix to have support to publish and retrieve
2088binaries to/from other users, in a peer-to-peer fashion. If you would
2089like to discuss this project, join us on @email{guix-devel@@gnu.org}.
2090
2091
6e721c4d
LC
2092@node Packages with Multiple Outputs
2093@section Packages with Multiple Outputs
2094
2095@cindex multiple-output packages
2096@cindex package outputs
e32171ee 2097@cindex outputs
6e721c4d
LC
2098
2099Often, packages defined in Guix have a single @dfn{output}---i.e., the
f97c9175 2100source package leads to exactly one directory in the store. When running
6e721c4d
LC
2101@command{guix package -i glibc}, one installs the default output of the
2102GNU libc package; the default output is called @code{out}, but its name
2103can be omitted as shown in this command. In this particular case, the
2104default output of @code{glibc} contains all the C header files, shared
2105libraries, static libraries, Info documentation, and other supporting
2106files.
2107
2108Sometimes it is more appropriate to separate the various types of files
2109produced from a single source package into separate outputs. For
2110instance, the GLib C library (used by GTK+ and related packages)
2111installs more than 20 MiB of reference documentation as HTML pages.
2112To save space for users who do not need it, the documentation goes to a
2113separate output, called @code{doc}. To install the main GLib output,
2114which contains everything but the documentation, one would run:
2115
2116@example
2117guix package -i glib
2118@end example
2119
e32171ee 2120@cindex documentation
6e721c4d
LC
2121The command to install its documentation is:
2122
2123@example
2124guix package -i glib:doc
2125@end example
2126
2127Some packages install programs with different ``dependency footprints''.
f97c9175 2128For instance, the WordNet package installs both command-line tools and
6e721c4d
LC
2129graphical user interfaces (GUIs). The former depend solely on the C
2130library, whereas the latter depend on Tcl/Tk and the underlying X
2131libraries. In this case, we leave the command-line tools in the default
2132output, whereas the GUIs are in a separate output. This allows users
fcc58db6
LC
2133who do not need the GUIs to save space. The @command{guix size} command
2134can help find out about such situations (@pxref{Invoking guix size}).
88856916 2135@command{guix graph} can also be helpful (@pxref{Invoking guix graph}).
6e721c4d
LC
2136
2137There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
2138Other conventional output names include @code{lib} for libraries and
2139possibly header files, @code{bin} for stand-alone programs, and
2140@code{debug} for debugging information (@pxref{Installing Debugging
2141Files}). The outputs of a packages are listed in the third column of
2142the output of @command{guix package --list-available} (@pxref{Invoking
2143guix package}).
6e721c4d 2144
eeaf4427 2145
e49951eb
MW
2146@node Invoking guix gc
2147@section Invoking @command{guix gc}
fe8ff028
LC
2148
2149@cindex garbage collector
e32171ee 2150@cindex disk space
f97c9175 2151Packages that are installed, but not used, may be @dfn{garbage-collected}.
e49951eb 2152The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
2153collector to reclaim space from the @file{/gnu/store} directory. It is
2154the @emph{only} way to remove files from @file{/gnu/store}---removing
2155files or directories manually may break it beyond repair!
fe8ff028
LC
2156
2157The garbage collector has a set of known @dfn{roots}: any file under
834129e0 2158@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
2159cannot be deleted; any other file is considered @dfn{dead} and may be
2160deleted. The set of garbage collector roots includes default user
e49951eb
MW
2161profiles, and may be augmented with @command{guix build --root}, for
2162example (@pxref{Invoking guix build}).
fe8ff028 2163
1bb9900a
LC
2164Prior to running @code{guix gc --collect-garbage} to make space, it is
2165often useful to remove old generations from user profiles; that way, old
2166package builds referenced by those generations can be reclaimed. This
2167is achieved by running @code{guix package --delete-generations}
2168(@pxref{Invoking guix package}).
2169
e49951eb 2170The @command{guix gc} command has three modes of operation: it can be
fe8ff028 2171used to garbage-collect any dead files (the default), to delete specific
7770aafc
LC
2172files (the @code{--delete} option), to print garbage-collector
2173information, or for more advanced queries. The garbage collection
2174options are as follows:
fe8ff028
LC
2175
2176@table @code
2177@item --collect-garbage[=@var{min}]
2178@itemx -C [@var{min}]
834129e0 2179Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
2180sub-directories. This is the default operation when no option is
2181specified.
2182
2183When @var{min} is given, stop once @var{min} bytes have been collected.
2184@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
2185suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
2186(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
2187
2188When @var{min} is omitted, collect all the garbage.
2189
0054e470
LC
2190@item --free-space=@var{free}
2191@itemx -F @var{free}
2192Collect garbage until @var{free} space is available under
2193@file{/gnu/store}, if possible; @var{free} denotes storage space, such
2194as @code{500MiB}, as described above.
2195
2196When @var{free} or more is already available in @file{/gnu/store}, do
2197nothing and exit immediately.
2198
fe8ff028
LC
2199@item --delete
2200@itemx -d
2201Attempt to delete all the store files and directories specified as
2202arguments. This fails if some of the files are not in the store, or if
2203they are still live.
2204
30d9aa54
LC
2205@item --list-failures
2206List store items corresponding to cached build failures.
2207
2208This prints nothing unless the daemon was started with
2209@option{--cache-failures} (@pxref{Invoking guix-daemon,
2210@option{--cache-failures}}).
2211
2212@item --clear-failures
2213Remove the specified store items from the failed-build cache.
2214
2215Again, this option only makes sense when the daemon is started with
2216@option{--cache-failures}. Otherwise, it does nothing.
2217
fe8ff028
LC
2218@item --list-dead
2219Show the list of dead files and directories still present in the
2220store---i.e., files and directories no longer reachable from any root.
2221
2222@item --list-live
2223Show the list of live store files and directories.
ba8b732d
LC
2224
2225@end table
2226
2227In addition, the references among existing store files can be queried:
2228
2229@table @code
2230
2231@item --references
2232@itemx --referrers
e32171ee 2233@cindex package dependencies
ba8b732d
LC
2234List the references (respectively, the referrers) of store files given
2235as arguments.
2236
8e59fdd5
LC
2237@item --requisites
2238@itemx -R
fcc58db6 2239@cindex closure
8e59fdd5
LC
2240List the requisites of the store files passed as arguments. Requisites
2241include the store files themselves, their references, and the references
2242of these, recursively. In other words, the returned list is the
2243@dfn{transitive closure} of the store files.
2244
f97c9175
AE
2245@xref{Invoking guix size}, for a tool to profile the size of the closure
2246of an element. @xref{Invoking guix graph}, for a tool to visualize
88856916 2247the graph of references.
fcc58db6 2248
fe8ff028
LC
2249@end table
2250
7770aafc
LC
2251Lastly, the following options allow you to check the integrity of the
2252store and to control disk usage.
2253
2254@table @option
2255
2256@item --verify[=@var{options}]
2257@cindex integrity, of the store
2258@cindex integrity checking
2259Verify the integrity of the store.
2260
2261By default, make sure that all the store items marked as valid in the
f97c9175 2262database of the daemon actually exist in @file{/gnu/store}.
7770aafc 2263
f97c9175 2264When provided, @var{options} must be a comma-separated list containing one
7770aafc
LC
2265or more of @code{contents} and @code{repair}.
2266
7414de0a 2267When passing @option{--verify=contents}, the daemon computes the
f97c9175 2268content hash of each store item and compares it against its hash in the
7770aafc
LC
2269database. Hash mismatches are reported as data corruptions. Because it
2270traverses @emph{all the files in the store}, this command can take a
2271long time, especially on systems with a slow disk drive.
2272
2273@cindex repairing the store
2274Using @option{--verify=repair} or @option{--verify=contents,repair}
2275causes the daemon to try to repair corrupt store items by fetching
2276substitutes for them (@pxref{Substitutes}). Because repairing is not
2277atomic, and thus potentially dangerous, it is available only to the
2278system administrator.
2279
2280@item --optimize
2281@cindex deduplication
2282Optimize the store by hard-linking identical files---this is
2283@dfn{deduplication}.
2284
2285The daemon performs deduplication after each successful build or archive
2286import, unless it was started with @code{--disable-deduplication}
2287(@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus,
2288this option is primarily useful when the daemon was running with
2289@code{--disable-deduplication}.
2290
2291@end table
eeaf4427 2292
f651b477
LC
2293@node Invoking guix pull
2294@section Invoking @command{guix pull}
2295
e32171ee 2296@cindex upgrading Guix
7fcf2a0b 2297@cindex updating Guix
e32171ee
JD
2298@cindex @command{guix pull}
2299@cindex pull
f651b477
LC
2300Packages are installed or upgraded to the latest version available in
2301the distribution currently available on your local machine. To update
2302that distribution, along with the Guix tools, you must run @command{guix
2303pull}: the command downloads the latest Guix source code and package
2304descriptions, and deploys it.
2305
2306On completion, @command{guix package} will use packages and package
2307versions from this just-retrieved copy of Guix. Not only that, but all
2308the Guix commands and Scheme modules will also be taken from that latest
2309version. New @command{guix} sub-commands added by the update also
cb05108a
LC
2310become available.
2311
2312Any user can update their Guix copy using @command{guix pull}, and the
2313effect is limited to the user who run @command{guix pull}. For
2314instance, when user @code{root} runs @command{guix pull}, this has no
2315effect on the version of Guix that user @code{alice} sees, and vice
2316versa@footnote{Under the hood, @command{guix pull} updates the
2317@file{~/.config/guix/latest} symbolic link to point to the latest Guix,
2318and the @command{guix} command loads code from there.}.
f651b477
LC
2319
2320The @command{guix pull} command is usually invoked with no arguments,
2321but it supports the following options:
2322
2323@table @code
2324@item --verbose
2325Produce verbose output, writing build logs to the standard error output.
2326
ab5d72ad
LC
2327@item --url=@var{url}
2328Download the source tarball of Guix from @var{url}.
2329
2330By default, the tarball is taken from its canonical address at
2331@code{gnu.org}, for the stable branch of Guix.
2332
f651b477
LC
2333@item --bootstrap
2334Use the bootstrap Guile to build the latest Guix. This option is only
2335useful to Guix developers.
2336@end table
2337
760c60d6
LC
2338
2339@node Invoking guix archive
2340@section Invoking @command{guix archive}
2341
e32171ee
JD
2342@cindex @command{guix archive}
2343@cindex archive
760c60d6
LC
2344The @command{guix archive} command allows users to @dfn{export} files
2345from the store into a single archive, and to later @dfn{import} them.
2346In particular, it allows store files to be transferred from one machine
4d4c4816
AE
2347to the store on another machine.
2348
e32171ee 2349@cindex exporting store items
4d4c4816
AE
2350To export store files as an archive to standard output, run:
2351
2352@example
2353guix archive --export @var{options} @var{specifications}...
2354@end example
2355
2356@var{specifications} may be either store file names or package
2357specifications, as for @command{guix package} (@pxref{Invoking guix
2358package}). For instance, the following command creates an archive
2359containing the @code{gui} output of the @code{git} package and the main
2360output of @code{emacs}:
2361
2362@example
2363guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
2364@end example
2365
2366If the specified packages are not built yet, @command{guix archive}
2367automatically builds them. The build process may be controlled with the
2368common build options (@pxref{Common Build Options}).
2369
2370To transfer the @code{emacs} package to a machine connected over SSH,
2371one would run:
760c60d6
LC
2372
2373@example
56607088 2374guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
2375@end example
2376
87236aed 2377@noindent
56607088
LC
2378Similarly, a complete user profile may be transferred from one machine
2379to another like this:
2380
2381@example
2382guix archive --export -r $(readlink -f ~/.guix-profile) | \
2383 ssh the-machine guix-archive --import
2384@end example
2385
2386@noindent
2387However, note that, in both examples, all of @code{emacs} and the
2388profile as well as all of their dependencies are transferred (due to
f97c9175
AE
2389@code{-r}), regardless of what is already available in the store on the
2390target machine. The @code{--missing} option can help figure out which
f11c444d
LC
2391items are missing from the target store. The @command{guix copy}
2392command simplifies and optimizes this whole process, so this is probably
2393what you should use in this case (@pxref{Invoking guix copy}).
87236aed 2394
5597b3ae
LC
2395@cindex nar, archive format
2396@cindex normalized archive (nar)
2397Archives are stored in the ``normalized archive'' or ``nar'' format, which is
2398comparable in spirit to `tar', but with differences
0dbd88db 2399that make it more appropriate for our purposes. First, rather than
5597b3ae 2400recording all Unix metadata for each file, the nar format only mentions
0dbd88db
LC
2401the file type (regular, directory, or symbolic link); Unix permissions
2402and owner/group are dismissed. Second, the order in which directory
2403entries are stored always follows the order of file names according to
2404the C locale collation order. This makes archive production fully
2405deterministic.
2406
2407When exporting, the daemon digitally signs the contents of the archive,
2408and that digital signature is appended. When importing, the daemon
2409verifies the signature and rejects the import in case of an invalid
2410signature or if the signing key is not authorized.
760c60d6
LC
2411@c FIXME: Add xref to daemon doc about signatures.
2412
2413The main options are:
2414
2415@table @code
2416@item --export
2417Export the specified store files or packages (see below.) Write the
2418resulting archive to the standard output.
2419
56607088
LC
2420Dependencies are @emph{not} included in the output, unless
2421@code{--recursive} is passed.
2422
2423@item -r
2424@itemx --recursive
2425When combined with @code{--export}, this instructs @command{guix
2426archive} to include dependencies of the given items in the archive.
2427Thus, the resulting archive is self-contained: it contains the closure
2428of the exported store items.
2429
760c60d6
LC
2430@item --import
2431Read an archive from the standard input, and import the files listed
2432therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
2433signature, or if it is signed by a public key not among the authorized
2434keys (see @code{--authorize} below.)
554f26ec 2435
87236aed
LC
2436@item --missing
2437Read a list of store file names from the standard input, one per line,
2438and write on the standard output the subset of these files missing from
2439the store.
2440
554f26ec 2441@item --generate-key[=@var{parameters}]
f82cc5fd 2442@cindex signing, archives
f97c9175 2443Generate a new key pair for the daemon. This is a prerequisite before
554f26ec
LC
2444archives can be exported with @code{--export}. Note that this operation
2445usually takes time, because it needs to gather enough entropy to
2446generate the key pair.
2447
2448The generated key pair is typically stored under @file{/etc/guix}, in
2449@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
2450key, which must be kept secret.) When @var{parameters} is omitted,
2451an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
2452versions before 1.6.0, it is a 4096-bit RSA key.
f97c9175 2453Alternatively, @var{parameters} can specify
554f26ec
LC
2454@code{genkey} parameters suitable for Libgcrypt (@pxref{General
2455public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
2456Libgcrypt Reference Manual}).
f82cc5fd
LC
2457
2458@item --authorize
2459@cindex authorizing, archives
2460Authorize imports signed by the public key passed on standard input.
2461The public key must be in ``s-expression advanced format''---i.e., the
2462same format as the @file{signing-key.pub} file.
2463
2464The list of authorized keys is kept in the human-editable file
2465@file{/etc/guix/acl}. The file contains
2466@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
2467s-expressions''} and is structured as an access-control list in the
2468@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
2469(SPKI)}.
c6f8e9dd
LC
2470
2471@item --extract=@var{directory}
2472@itemx -x @var{directory}
2473Read a single-item archive as served by substitute servers
2474(@pxref{Substitutes}) and extract it to @var{directory}. This is a
2475low-level operation needed in only very narrow use cases; see below.
2476
2477For example, the following command extracts the substitute for Emacs
2478served by @code{hydra.gnu.org} to @file{/tmp/emacs}:
2479
2480@example
2481$ wget -O - \
df061d07 2482 https://hydra.gnu.org/nar/@dots{}-emacs-24.5 \
c6f8e9dd
LC
2483 | bunzip2 | guix archive -x /tmp/emacs
2484@end example
2485
2486Single-item archives are different from multiple-item archives produced
2487by @command{guix archive --export}; they contain a single store item,
2488and they do @emph{not} embed a signature. Thus this operation does
2489@emph{no} signature verification and its output should be considered
2490unsafe.
2491
2492The primary purpose of this operation is to facilitate inspection of
2493archive contents coming from possibly untrusted substitute servers.
2494
760c60d6
LC
2495@end table
2496
568717fd
LC
2497@c *********************************************************************
2498@node Programming Interface
2499@chapter Programming Interface
2500
3dc1970d
LC
2501GNU Guix provides several Scheme programming interfaces (APIs) to
2502define, build, and query packages. The first interface allows users to
2503write high-level package definitions. These definitions refer to
2504familiar packaging concepts, such as the name and version of a package,
2505its build system, and its dependencies. These definitions can then be
2506turned into concrete build actions.
2507
ba55b1cb 2508Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 2509standard setup, the daemon has write access to the store---the
834129e0 2510@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
2511setup also has the daemon perform builds in chroots, under a specific
2512build users, to minimize interference with the rest of the system.
2513
2514@cindex derivation
2515Lower-level APIs are available to interact with the daemon and the
2516store. To instruct the daemon to perform a build action, users actually
2517provide it with a @dfn{derivation}. A derivation is a low-level
2518representation of the build actions to be taken, and the environment in
2519which they should occur---derivations are to package definitions what
49ad317a
LC
2520assembly is to C programs. The term ``derivation'' comes from the fact
2521that build results @emph{derive} from them.
3dc1970d
LC
2522
2523This chapter describes all these APIs in turn, starting from high-level
2524package definitions.
2525
568717fd 2526@menu
b860f382 2527* Defining Packages:: Defining new packages.
7458bd0a 2528* Build Systems:: Specifying how packages are built.
b860f382
LC
2529* The Store:: Manipulating the package store.
2530* Derivations:: Low-level interface to package derivations.
2531* The Store Monad:: Purely functional interface to the store.
21b679f6 2532* G-Expressions:: Manipulating build expressions.
568717fd
LC
2533@end menu
2534
2535@node Defining Packages
2536@section Defining Packages
2537
3dc1970d
LC
2538The high-level interface to package definitions is implemented in the
2539@code{(guix packages)} and @code{(guix build-system)} modules. As an
2540example, the package definition, or @dfn{recipe}, for the GNU Hello
2541package looks like this:
2542
2543@example
e7f34eb0
LC
2544(define-module (gnu packages hello)
2545 #:use-module (guix packages)
2546 #:use-module (guix download)
2547 #:use-module (guix build-system gnu)
a6dcdcac
SB
2548 #:use-module (guix licenses)
2549 #:use-module (gnu packages gawk))
b22a12fd 2550
79f5dd59 2551(define-public hello
3dc1970d
LC
2552 (package
2553 (name "hello")
17d8e33f 2554 (version "2.10")
3dc1970d 2555 (source (origin
17d8e33f
ML
2556 (method url-fetch)
2557 (uri (string-append "mirror://gnu/hello/hello-" version
2558 ".tar.gz"))
2559 (sha256
2560 (base32
2561 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
3dc1970d 2562 (build-system gnu-build-system)
654c0d97 2563 (arguments '(#:configure-flags '("--enable-silent-rules")))
3dc1970d 2564 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
2565 (synopsis "Hello, GNU world: An example GNU package")
2566 (description "Guess what GNU Hello prints!")
3dc1970d 2567 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 2568 (license gpl3+)))
3dc1970d
LC
2569@end example
2570
2571@noindent
2572Without being a Scheme expert, the reader may have guessed the meaning
f97c9175
AE
2573of the various fields here. This expression binds the variable
2574@code{hello} to a @code{<package>} object, which is essentially a record
3dc1970d
LC
2575(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
2576This package object can be inspected using procedures found in the
2577@code{(guix packages)} module; for instance, @code{(package-name hello)}
2578returns---surprise!---@code{"hello"}.
2579
2f7d2d91
LC
2580With luck, you may be able to import part or all of the definition of
2581the package you are interested in from another repository, using the
2582@code{guix import} command (@pxref{Invoking guix import}).
2583
f97c9175 2584In the example above, @var{hello} is defined in a module of its own,
e7f34eb0
LC
2585@code{(gnu packages hello)}. Technically, this is not strictly
2586necessary, but it is convenient to do so: all the packages defined in
2587modules under @code{(gnu packages @dots{})} are automatically known to
2588the command-line tools (@pxref{Package Modules}).
2589
3dc1970d
LC
2590There are a few points worth noting in the above package definition:
2591
2592@itemize
2593@item
a2bf4907
LC
2594The @code{source} field of the package is an @code{<origin>} object
2595(@pxref{origin Reference}, for the complete reference).
3dc1970d
LC
2596Here, the @code{url-fetch} method from @code{(guix download)} is used,
2597meaning that the source is a file to be downloaded over FTP or HTTP.
2598
2599The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
2600the GNU mirrors defined in @code{(guix download)}.
2601
2602The @code{sha256} field specifies the expected SHA256 hash of the file
2603being downloaded. It is mandatory, and allows Guix to check the
2604integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 2605base32 representation of the hash. You can obtain this information with
210cc920
LC
2606@code{guix download} (@pxref{Invoking guix download}) and @code{guix
2607hash} (@pxref{Invoking guix hash}).
3dc1970d 2608
f9cc8971
LC
2609@cindex patches
2610When needed, the @code{origin} form can also have a @code{patches} field
2611listing patches to be applied, and a @code{snippet} field giving a
2612Scheme expression to modify the source code.
2613
3dc1970d
LC
2614@item
2615@cindex GNU Build System
7458bd0a
LC
2616The @code{build-system} field specifies the procedure to build the
2617package (@pxref{Build Systems}). Here, @var{gnu-build-system}
2618represents the familiar GNU Build System, where packages may be
2619configured, built, and installed with the usual @code{./configure &&
2620make && make check && make install} command sequence.
2621
2622@item
2623The @code{arguments} field specifies options for the build system
2624(@pxref{Build Systems}). Here it is interpreted by
2625@var{gnu-build-system} as a request run @file{configure} with the
2626@code{--enable-silent-rules} flag.
3dc1970d 2627
654c0d97
LC
2628@cindex quote
2629@cindex quoting
2630@findex '
2631@findex quote
2632What about these quote (@code{'}) characters? They are Scheme syntax to
2633introduce a literal list; @code{'} is synonymous with @code{quote}.
2634@xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
2635for details. Here the value of the @code{arguments} field is a list of
2636arguments passed to the build system down the road, as with @code{apply}
2637(@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
2638Manual}).
2639
2640The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
2641(@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
2642@code{#:configure-flags} is a keyword used to pass a keyword argument
2643to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
2644Reference Manual}).
2645
3dc1970d
LC
2646@item
2647The @code{inputs} field specifies inputs to the build process---i.e.,
2648build-time or run-time dependencies of the package. Here, we define an
2649input called @code{"gawk"} whose value is that of the @var{gawk}
2650variable; @var{gawk} is itself bound to a @code{<package>} object.
2651
654c0d97
LC
2652@cindex backquote (quasiquote)
2653@findex `
2654@findex quasiquote
2655@cindex comma (unquote)
2656@findex ,
2657@findex unquote
2658@findex ,@@
2659@findex unquote-splicing
2660Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
2661us to introduce a literal list in the @code{inputs} field, while
2662@code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
2663value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
2664Reference Manual}).
2665
3dc1970d
LC
2666Note that GCC, Coreutils, Bash, and other essential tools do not need to
2667be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 2668of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
2669
2670However, any other dependencies need to be specified in the
2671@code{inputs} field. Any dependency not specified here will simply be
2672unavailable to the build process, possibly leading to a build failure.
2673@end itemize
2674
87eafdbd
TUBK
2675@xref{package Reference}, for a full description of possible fields.
2676
2f7d2d91 2677Once a package definition is in place, the
e49951eb 2678package may actually be built using the @code{guix build} command-line
39bee8a2
LC
2679tool (@pxref{Invoking guix build}). You can easily jump back to the
2680package definition using the @command{guix edit} command
2681(@pxref{Invoking guix edit}).
2682@xref{Packaging Guidelines}, for
b4f5e0e8
CR
2683more information on how to test package definitions, and
2684@ref{Invoking guix lint}, for information on how to check a definition
2685for style conformance.
2686
f97c9175 2687Finally, updating the package definition to a new upstream version
7458bd0a
LC
2688can be partly automated by the @command{guix refresh} command
2689(@pxref{Invoking guix refresh}).
3dc1970d
LC
2690
2691Behind the scenes, a derivation corresponding to the @code{<package>}
2692object is first computed by the @code{package-derivation} procedure.
834129e0 2693That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 2694The build actions it prescribes may then be realized by using the
3dc1970d
LC
2695@code{build-derivations} procedure (@pxref{The Store}).
2696
2697@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
2698Return the @code{<derivation>} object of @var{package} for @var{system}
2699(@pxref{Derivations}).
3dc1970d
LC
2700
2701@var{package} must be a valid @code{<package>} object, and @var{system}
2702must be a string denoting the target system type---e.g.,
2703@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
2704must be a connection to the daemon, which operates on the store
2705(@pxref{The Store}).
2706@end deffn
568717fd 2707
9c1edabd
LC
2708@noindent
2709@cindex cross-compilation
2710Similarly, it is possible to compute a derivation that cross-builds a
2711package for some other system:
2712
2713@deffn {Scheme Procedure} package-cross-derivation @var{store} @
2714 @var{package} @var{target} [@var{system}]
59688fc4
LC
2715Return the @code{<derivation>} object of @var{package} cross-built from
2716@var{system} to @var{target}.
9c1edabd
LC
2717
2718@var{target} must be a valid GNU triplet denoting the target hardware
2719and operating system, such as @code{"mips64el-linux-gnu"}
2720(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
2721Configure and Build System}).
2722@end deffn
2723
2a75b0b6
LC
2724@cindex package transformations
2725@cindex input rewriting
2726@cindex dependency tree rewriting
2727Packages can be manipulated in arbitrary ways. An example of a useful
2728transformation is @dfn{input rewriting}, whereby the dependency tree of
2729a package is rewritten by replacing specific inputs by others:
2730
2731@deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
2732 [@var{rewrite-name}]
2733Return a procedure that, when passed a package, replaces its direct and
2734indirect dependencies (but not its implicit inputs) according to
2735@var{replacements}. @var{replacements} is a list of package pairs; the
2736first element of each pair is the package to replace, and the second one
2737is the replacement.
2738
2739Optionally, @var{rewrite-name} is a one-argument procedure that takes
2740the name of a package and returns its new name after rewrite.
2741@end deffn
2742
2743@noindent
2744Consider this example:
2745
2746@example
2747(define libressl-instead-of-openssl
2748 ;; This is a procedure to replace OPENSSL by LIBRESSL,
2749 ;; recursively.
2750 (package-input-rewriting `((,openssl . ,libressl))))
2751
2752(define git-with-libressl
2753 (libressl-instead-of-openssl git))
2754@end example
2755
2756@noindent
2757Here we first define a rewriting procedure that replaces @var{openssl}
2758with @var{libressl}. Then we use it to define a @dfn{variant} of the
2759@var{git} package that uses @var{libressl} instead of @var{openssl}.
2760This is exactly what the @option{--with-input} command-line option does
2761(@pxref{Package Transformation Options, @option{--with-input}}).
2762
87eafdbd
TUBK
2763@menu
2764* package Reference :: The package data type.
2765* origin Reference:: The origin data type.
2766@end menu
2767
2768
2769@node package Reference
2770@subsection @code{package} Reference
2771
2772This section summarizes all the options available in @code{package}
2773declarations (@pxref{Defining Packages}).
2774
2775@deftp {Data Type} package
2776This is the data type representing a package recipe.
2777
2778@table @asis
2779@item @code{name}
2780The name of the package, as a string.
2781
2782@item @code{version}
2783The version of the package, as a string.
2784
2785@item @code{source}
da675305
LC
2786An object telling how the source code for the package should be
2787acquired. Most of the time, this is an @code{origin} object, which
2788denotes a file fetched from the Internet (@pxref{origin Reference}). It
2789can also be any other ``file-like'' object such as a @code{local-file},
2790which denotes a file from the local file system (@pxref{G-Expressions,
2791@code{local-file}}).
87eafdbd
TUBK
2792
2793@item @code{build-system}
2794The build system that should be used to build the package (@pxref{Build
2795Systems}).
2796
2797@item @code{arguments} (default: @code{'()})
2798The arguments that should be passed to the build system. This is a
2799list, typically containing sequential keyword-value pairs.
2800
2801@item @code{inputs} (default: @code{'()})
70650c68
LC
2802@itemx @code{native-inputs} (default: @code{'()})
2803@itemx @code{propagated-inputs} (default: @code{'()})
2804@cindex inputs, of packages
2805These fields list dependencies of the package. Each one is a list of
2806tuples, where each tuple has a label for the input (a string) as its
2807first element, a package, origin, or derivation as its second element,
2808and optionally the name of the output thereof that should be used, which
2809defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
f97c9175 2810more on package outputs). For example, the list below specifies three
70650c68 2811inputs:
87eafdbd 2812
70650c68
LC
2813@example
2814`(("libffi" ,libffi)
2815 ("libunistring" ,libunistring)
2816 ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
2817@end example
2818
2819@cindex cross compilation, package dependencies
2820The distinction between @code{native-inputs} and @code{inputs} is
2821necessary when considering cross-compilation. When cross-compiling,
2822dependencies listed in @code{inputs} are built for the @emph{target}
2823architecture; conversely, dependencies listed in @code{native-inputs}
2824are built for the architecture of the @emph{build} machine.
2825
f97c9175
AE
2826@code{native-inputs} is typically used to list tools needed at
2827build time, but not at run time, such as Autoconf, Automake, pkg-config,
70650c68
LC
2828Gettext, or Bison. @command{guix lint} can report likely mistakes in
2829this area (@pxref{Invoking guix lint}).
2830
2831@anchor{package-propagated-inputs}
2832Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
f97c9175
AE
2833specified packages will be automatically installed alongside the package
2834they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
70650c68
LC
2835package}}, for information on how @command{guix package} deals with
2836propagated inputs.)
21461f27 2837
e0508b6b
LC
2838For example this is necessary when a C/C++ library needs headers of
2839another library to compile, or when a pkg-config file refers to another
2840one @i{via} its @code{Requires} field.
2841
f97c9175
AE
2842Another example where @code{propagated-inputs} is useful is for languages
2843that lack a facility to record the run-time search path akin to the
c8ebb4c4 2844@code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
e0508b6b
LC
2845more. To ensure that libraries written in those languages can find
2846library code they depend on at run time, run-time dependencies must be
2847listed in @code{propagated-inputs} rather than @code{inputs}.
87eafdbd 2848
87eafdbd
TUBK
2849@item @code{self-native-input?} (default: @code{#f})
2850This is a Boolean field telling whether the package should use itself as
2851a native input when cross-compiling.
2852
2853@item @code{outputs} (default: @code{'("out")})
2854The list of output names of the package. @xref{Packages with Multiple
2855Outputs}, for typical uses of additional outputs.
2856
2857@item @code{native-search-paths} (default: @code{'()})
2858@itemx @code{search-paths} (default: @code{'()})
2859A list of @code{search-path-specification} objects describing
2860search-path environment variables honored by the package.
2861
2862@item @code{replacement} (default: @code{#f})
f97c9175 2863This must be either @code{#f} or a package object that will be used as a
87eafdbd
TUBK
2864@dfn{replacement} for this package. @xref{Security Updates, grafts},
2865for details.
2866
2867@item @code{synopsis}
2868A one-line description of the package.
2869
2870@item @code{description}
2871A more elaborate description of the package.
2872
2873@item @code{license}
e32171ee 2874@cindex license, of packages
f97c9175
AE
2875The license of the package; a value from @code{(guix licenses)},
2876or a list of such values.
87eafdbd
TUBK
2877
2878@item @code{home-page}
2879The URL to the home-page of the package, as a string.
2880
2881@item @code{supported-systems} (default: @var{%supported-systems})
2882The list of systems supported by the package, as strings of the form
2883@code{architecture-kernel}, for example @code{"x86_64-linux"}.
2884
2885@item @code{maintainers} (default: @code{'()})
2886The list of maintainers of the package, as @code{maintainer} objects.
2887
2888@item @code{location} (default: source location of the @code{package} form)
f97c9175 2889The source location of the package. It is useful to override this when
87eafdbd
TUBK
2890inheriting from another package, in which case this field is not
2891automatically corrected.
2892@end table
2893@end deftp
2894
2895
2896@node origin Reference
2897@subsection @code{origin} Reference
2898
2899This section summarizes all the options available in @code{origin}
2900declarations (@pxref{Defining Packages}).
2901
2902@deftp {Data Type} origin
2903This is the data type representing a source code origin.
2904
2905@table @asis
2906@item @code{uri}
2907An object containing the URI of the source. The object type depends on
2908the @code{method} (see below). For example, when using the
2909@var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
2910values are: a URL represented as a string, or a list thereof.
2911
2912@item @code{method}
f97c9175 2913A procedure that handles the URI.
87eafdbd
TUBK
2914
2915Examples include:
2916
2917@table @asis
2918@item @var{url-fetch} from @code{(guix download)}
f97c9175 2919download a file from the HTTP, HTTPS, or FTP URL specified in the
87eafdbd
TUBK
2920@code{uri} field;
2921
db97a03a 2922@vindex git-fetch
87eafdbd
TUBK
2923@item @var{git-fetch} from @code{(guix git-download)}
2924clone the Git version control repository, and check out the revision
2925specified in the @code{uri} field as a @code{git-reference} object; a
2926@code{git-reference} looks like this:
2927
2928@example
2929(git-reference
2930 (url "git://git.debian.org/git/pkg-shadow/shadow")
2931 (commit "v4.1.5.1"))
2932@end example
2933@end table
2934
2935@item @code{sha256}
2936A bytevector containing the SHA-256 hash of the source. Typically the
2937@code{base32} form is used here to generate the bytevector from a
2938base-32 string.
2939
db97a03a
LC
2940You can obtain this information using @code{guix download}
2941(@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
2942guix hash}).
2943
87eafdbd
TUBK
2944@item @code{file-name} (default: @code{#f})
2945The file name under which the source code should be saved. When this is
2946@code{#f}, a sensible default value will be used in most cases. In case
2947the source is fetched from a URL, the file name from the URL will be
f97c9175 2948used. For version control checkouts, it is recommended to provide the
87eafdbd
TUBK
2949file name explicitly because the default is not very descriptive.
2950
2951@item @code{patches} (default: @code{'()})
2952A list of file names containing patches to be applied to the source.
2953
0dfebdaa
LC
2954This list of patches must be unconditional. In particular, it cannot
2955depend on the value of @code{%current-system} or
2956@code{%current-target-system}.
2957
87eafdbd 2958@item @code{snippet} (default: @code{#f})
1929fdba
LC
2959A G-expression (@pxref{G-Expressions}) or S-expression that will be run
2960in the source directory. This is a convenient way to modify the source,
2961sometimes more convenient than a patch.
87eafdbd
TUBK
2962
2963@item @code{patch-flags} (default: @code{'("-p1")})
2964A list of command-line flags that should be passed to the @code{patch}
2965command.
2966
2967@item @code{patch-inputs} (default: @code{#f})
2968Input packages or derivations to the patching process. When this is
2969@code{#f}, the usual set of inputs necessary for patching are provided,
2970such as GNU@tie{}Patch.
2971
2972@item @code{modules} (default: @code{'()})
2973A list of Guile modules that should be loaded during the patching
2974process and while running the code in the @code{snippet} field.
2975
87eafdbd
TUBK
2976@item @code{patch-guile} (default: @code{#f})
2977The Guile package that should be used in the patching process. When
2978this is @code{#f}, a sensible default is used.
2979@end table
2980@end deftp
2981
9c1edabd 2982
7458bd0a
LC
2983@node Build Systems
2984@section Build Systems
2985
2986@cindex build system
2987Each package definition specifies a @dfn{build system} and arguments for
2988that build system (@pxref{Defining Packages}). This @code{build-system}
f97c9175 2989field represents the build procedure of the package, as well as implicit
7458bd0a
LC
2990dependencies of that build procedure.
2991
2992Build systems are @code{<build-system>} objects. The interface to
2993create and manipulate them is provided by the @code{(guix build-system)}
2994module, and actual build systems are exported by specific modules.
2995
f5fd4fd2 2996@cindex bag (low-level package representation)
0d5a559f
LC
2997Under the hood, build systems first compile package objects to
2998@dfn{bags}. A @dfn{bag} is like a package, but with less
2999ornamentation---in other words, a bag is a lower-level representation of
3000a package, which includes all the inputs of that package, including some
3001that were implicitly added by the build system. This intermediate
3002representation is then compiled to a derivation (@pxref{Derivations}).
3003
7458bd0a
LC
3004Build systems accept an optional list of @dfn{arguments}. In package
3005definitions, these are passed @i{via} the @code{arguments} field
3006(@pxref{Defining Packages}). They are typically keyword arguments
3007(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
3008Guile Reference Manual}). The value of these arguments is usually
3009evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
3010by the daemon (@pxref{Derivations}).
3011
3012The main build system is @var{gnu-build-system}, which implements the
f97c9175 3013standard build procedure for GNU and many other packages. It
7458bd0a
LC
3014is provided by the @code{(guix build-system gnu)} module.
3015
3016@defvr {Scheme Variable} gnu-build-system
3017@var{gnu-build-system} represents the GNU Build System, and variants
3018thereof (@pxref{Configuration, configuration and makefile conventions,,
3019standards, GNU Coding Standards}).
3020
3021@cindex build phases
f97c9175 3022In a nutshell, packages using it are configured, built, and installed with
7458bd0a
LC
3023the usual @code{./configure && make && make check && make install}
3024command sequence. In practice, a few additional steps are often needed.
3025All these steps are split up in separate @dfn{phases},
3026notably@footnote{Please see the @code{(guix build gnu-build-system)}
3027modules for more details about the build phases.}:
3028
3029@table @code
3030@item unpack
3031Unpack the source tarball, and change the current directory to the
3032extracted source tree. If the source is actually a directory, copy it
3033to the build tree, and enter that directory.
3034
3035@item patch-source-shebangs
3036Patch shebangs encountered in source files so they refer to the right
3037store file names. For instance, this changes @code{#!/bin/sh} to
3038@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
3039
3040@item configure
3041Run the @file{configure} script with a number of default options, such
3042as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
3043by the @code{#:configure-flags} argument.
3044
3045@item build
3046Run @code{make} with the list of flags specified with
0917e80e 3047@code{#:make-flags}. If the @code{#:parallel-build?} argument is true
7458bd0a
LC
3048(the default), build with @code{make -j}.
3049
3050@item check
3051Run @code{make check}, or some other target specified with
3052@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
3053@code{#:parallel-tests?} argument is true (the default), run @code{make
3054check -j}.
3055
3056@item install
3057Run @code{make install} with the flags listed in @code{#:make-flags}.
3058
3059@item patch-shebangs
3060Patch shebangs on the installed executable files.
3061
3062@item strip
3063Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
3064is false), copying them to the @code{debug} output when available
3065(@pxref{Installing Debugging Files}).
3066@end table
3067
3068@vindex %standard-phases
3069The build-side module @code{(guix build gnu-build-system)} defines
3070@var{%standard-phases} as the default list of build phases.
3071@var{%standard-phases} is a list of symbol/procedure pairs, where the
3072procedure implements the actual phase.
3073
3074The list of phases used for a particular package can be changed with the
3075@code{#:phases} parameter. For instance, passing:
3076
3077@example
c2c5dc79 3078#:phases (modify-phases %standard-phases (delete 'configure))
7458bd0a
LC
3079@end example
3080
9bf404e9 3081means that all the phases described above will be used, except the
7458bd0a
LC
3082@code{configure} phase.
3083
3084In addition, this build system ensures that the ``standard'' environment
3085for GNU packages is available. This includes tools such as GCC, libc,
3086Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
f97c9175
AE
3087build-system gnu)} module for a complete list). We call these the
3088@dfn{implicit inputs} of a package, because package definitions do not
7458bd0a
LC
3089have to mention them.
3090@end defvr
3091
3092Other @code{<build-system>} objects are defined to support other
3093conventions and tools used by free software packages. They inherit most
3094of @var{gnu-build-system}, and differ mainly in the set of inputs
3095implicitly added to the build process, and in the list of phases
3096executed. Some of these build systems are listed below.
3097
5f7a1a4d
RW
3098@defvr {Scheme Variable} ant-build-system
3099This variable is exported by @code{(guix build-system ant)}. It
3100implements the build procedure for Java packages that can be built with
3101@url{http://ant.apache.org/, Ant build tool}.
3102
3103It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
3104provided by the @code{icedtea} package to the set of inputs. Different
3105packages can be specified with the @code{#:ant} and @code{#:jdk}
3106parameters, respectively.
3107
3108When the original package does not provide a suitable Ant build file,
3109the parameter @code{#:jar-name} can be used to generate a minimal Ant
3110build file @file{build.xml} with tasks to build the specified jar
3111archive.
3112
3113The parameter @code{#:build-target} can be used to specify the Ant task
3114that should be run during the @code{build} phase. By default the
3115``jar'' task will be run.
3116
3117@end defvr
3118
a1b30f99
AP
3119@defvr {Scheme Variable} asdf-build-system/source
3120@defvrx {Scheme Variable} asdf-build-system/sbcl
3121@defvrx {Scheme Variable} asdf-build-system/ecl
3122
3123These variables, exported by @code{(guix build-system asdf)}, implement
3124build procedures for Common Lisp packages using
3125@url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
3126definition facility for Common Lisp programs and libraries.
3127
3128The @code{asdf-build-system/source} system installs the packages in
3129source form, and can be loaded using any common lisp implementation, via
3130ASDF. The others, such as @code{asdf-build-system/sbcl}, install binary
3131systems in the format which a particular implementation understands.
3132These build systems can also be used to produce executable programs, or
3133lisp images which contain a set of packages pre-loaded.
3134
3135The build system uses naming conventions. For binary packages, the
3136package itself as well as its run-time dependencies should begin their
3137name with the lisp implementation, such as @code{sbcl-} for
3138@code{asdf-build-system/sbcl}. Beginning the input name with this
3139prefix will allow the build system to encode its location into the
3140resulting library, so that the input can be found at run-time.
3141
3142If dependencies are used only for tests, it is convenient to use a
3143different prefix in order to avoid having a run-time dependency on such
3144systems. For example,
3145
3146@example
3147(define-public sbcl-bordeaux-threads
3148 (package
3149 ...
3150 (native-inputs `(("tests:cl-fiveam" ,sbcl-fiveam)))
3151 ...))
3152@end example
3153
3154Additionally, the corresponding source package should be labeled using
3155the same convention as python packages (see @ref{Python Modules}), using
3156the @code{cl-} prefix.
3157
3158For binary packages, each system should be defined as a Guix package.
3159If one package @code{origin} contains several systems, package variants
3160can be created in order to build all the systems. Source packages,
3161which use @code{asdf-build-system/source}, may contain several systems.
3162
3163In order to create executable programs and images, the build-side
3164procedures @code{build-program} and @code{build-image} can be used.
3165They should be called in a build phase after the @code{create-symlinks}
3166phase, so that the system which was just built can be used within the
3167resulting image. @code{build-program} requires a list of Common Lisp
3168expressions to be passed as the @code{#:entry-program} argument.
3169
3170If the system is not defined within its own @code{.asd} file of the same
3171name, then the @code{#:asd-file} parameter should be used to specify
3172which file the system is defined in.
3173
3174@end defvr
3175
1ec34dd7
LC
3176@defvr {Scheme Variable} cargo-build-system
3177@cindex Rust programming language
3178@cindex Cargo (Rust build system)
3179This variable is exported by @code{(guix build-system cargo)}. It
3180supports builds of packages using Cargo, the build tool of the
3181@uref{https://www.rust-lang.org, Rust programming language}.
3182
3183In its @code{configure} phase, this build system replaces dependencies
3184specified in the @file{Carto.toml} file with inputs to the Guix package.
3185The @code{install} phase installs the binaries, and it also installs the
3186source code and @file{Cargo.toml} file.
3187@end defvr
3188
7458bd0a
LC
3189@defvr {Scheme Variable} cmake-build-system
3190This variable is exported by @code{(guix build-system cmake)}. It
3191implements the build procedure for packages using the
3192@url{http://www.cmake.org, CMake build tool}.
3193
3194It automatically adds the @code{cmake} package to the set of inputs.
3195Which package is used can be specified with the @code{#:cmake}
3196parameter.
9849cfc1
LC
3197
3198The @code{#:configure-flags} parameter is taken as a list of flags
3199passed to the @command{cmake} command. The @code{#:build-type}
3200parameter specifies in abstract terms the flags passed to the compiler;
3201it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
3202debugging information''), which roughly means that code is compiled with
3203@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
3204@end defvr
3205
3afcf52b
FB
3206@defvr {Scheme Variable} glib-or-gtk-build-system
3207This variable is exported by @code{(guix build-system glib-or-gtk)}. It
3208is intended for use with packages making use of GLib or GTK+.
3209
3210This build system adds the following two phases to the ones defined by
3211@var{gnu-build-system}:
3212
3213@table @code
3214@item glib-or-gtk-wrap
f97c9175
AE
3215The phase @code{glib-or-gtk-wrap} ensures that programs in
3216@file{bin/} are able to find GLib ``schemas'' and
3afcf52b
FB
3217@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
3218modules}. This is achieved by wrapping the programs in launch scripts
3219that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
3220environment variables.
3221
73aa8ddb
LC
3222It is possible to exclude specific package outputs from that wrapping
3223process by listing their names in the
3224@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
3225when an output is known not to contain any GLib or GTK+ binaries, and
3226where wrapping would gratuitously add a dependency of that output on
3227GLib and GTK+.
3228
3afcf52b 3229@item glib-or-gtk-compile-schemas
f97c9175 3230The phase @code{glib-or-gtk-compile-schemas} makes sure that all
3afcf52b 3231@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
f97c9175 3232GSettings schemas} of GLib are compiled. Compilation is performed by the
3afcf52b
FB
3233@command{glib-compile-schemas} program. It is provided by the package
3234@code{glib:bin} which is automatically imported by the build system.
3235The @code{glib} package providing @command{glib-compile-schemas} can be
3236specified with the @code{#:glib} parameter.
3237@end table
3238
3239Both phases are executed after the @code{install} phase.
3240@end defvr
3241
7458bd0a
LC
3242@defvr {Scheme Variable} python-build-system
3243This variable is exported by @code{(guix build-system python)}. It
3244implements the more or less standard build procedure used by Python
3245packages, which consists in running @code{python setup.py build} and
3246then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
3247
3248For packages that install stand-alone Python programs under @code{bin/},
f97c9175 3249it takes care of wrapping these programs so that their @code{PYTHONPATH}
7458bd0a
LC
3250environment variable points to all the Python libraries they depend on.
3251
8a46205b
CM
3252Which Python package is used to perform the build can be specified with
3253the @code{#:python} parameter. This is a useful way to force a package
3254to be built for a specific version of the Python interpreter, which
3255might be necessary if the package is only compatible with a single
3256interpreter version.
5f7565d1
HG
3257
3258By default guix calls @code{setup.py} under control of
3259@code{setuptools}, much like @command{pip} does. Some packages are not
3260compatible with setuptools (and pip), thus you can disable this by
3261setting the @code{#:use-setuptools} parameter to @code{#f}.
7458bd0a
LC
3262@end defvr
3263
3264@defvr {Scheme Variable} perl-build-system
3265This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
3266implements the standard build procedure for Perl packages, which either
3267consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
3268followed by @code{Build} and @code{Build install}; or in running
3269@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
f97c9175 3270@code{make} and @code{make install}, depending on which of
2d2a53fc
EB
3271@code{Build.PL} or @code{Makefile.PL} is present in the package
3272distribution. Preference is given to the former if both @code{Build.PL}
3273and @code{Makefile.PL} exist in the package distribution. This
3274preference can be reversed by specifying @code{#t} for the
3275@code{#:make-maker?} parameter.
3276
3277The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
3278passes flags specified by the @code{#:make-maker-flags} or
3279@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
3280
3281Which Perl package is used can be specified with @code{#:perl}.
3282@end defvr
3283
f8f3bef6
RW
3284@defvr {Scheme Variable} r-build-system
3285This variable is exported by @code{(guix build-system r)}. It
3286implements the build procedure used by @uref{http://r-project.org, R}
3287packages, which essentially is little more than running @code{R CMD
3288INSTALL --library=/gnu/store/@dots{}} in an environment where
3289@code{R_LIBS_SITE} contains the paths to all R package inputs. Tests
3290are run after installation using the R function
3291@code{tools::testInstalledPackage}.
3292@end defvr
3293
c08f9818
DT
3294@defvr {Scheme Variable} ruby-build-system
3295This variable is exported by @code{(guix build-system ruby)}. It
3296implements the RubyGems build procedure used by Ruby packages, which
3297involves running @code{gem build} followed by @code{gem install}.
3298
5dc87623
DT
3299The @code{source} field of a package that uses this build system
3300typically references a gem archive, since this is the format that Ruby
3301developers use when releasing their software. The build system unpacks
3302the gem archive, potentially patches the source, runs the test suite,
3303repackages the gem, and installs it. Additionally, directories and
3304tarballs may be referenced to allow building unreleased gems from Git or
3305a traditional source release tarball.
e83c6d00 3306
c08f9818 3307Which Ruby package is used can be specified with the @code{#:ruby}
6e9f2913
PP
3308parameter. A list of additional flags to be passed to the @command{gem}
3309command can be specified with the @code{#:gem-flags} parameter.
c08f9818 3310@end defvr
7458bd0a 3311
a677c726
RW
3312@defvr {Scheme Variable} waf-build-system
3313This variable is exported by @code{(guix build-system waf)}. It
3314implements a build procedure around the @code{waf} script. The common
3315phases---@code{configure}, @code{build}, and @code{install}---are
3316implemented by passing their names as arguments to the @code{waf}
3317script.
3318
3319The @code{waf} script is executed by the Python interpreter. Which
3320Python package is used to run the script can be specified with the
3321@code{#:python} parameter.
3322@end defvr
3323
14dfdf2e
FB
3324@defvr {Scheme Variable} haskell-build-system
3325This variable is exported by @code{(guix build-system haskell)}. It
3326implements the Cabal build procedure used by Haskell packages, which
3327involves running @code{runhaskell Setup.hs configure
3328--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
3329Instead of installing the package by running @code{runhaskell Setup.hs
3330install}, to avoid trying to register libraries in the read-only
3331compiler store directory, the build system uses @code{runhaskell
3332Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
3333addition, the build system generates the package documentation by
3334running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
3335is passed. Optional Haddock parameters can be passed with the help of
3336the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
3337not found, the build system looks for @code{Setup.lhs} instead.
3338
3339Which Haskell compiler is used can be specified with the @code{#:haskell}
a54bd6d7 3340parameter which defaults to @code{ghc}.
14dfdf2e
FB
3341@end defvr
3342
e9137a53
FB
3343@defvr {Scheme Variable} emacs-build-system
3344This variable is exported by @code{(guix build-system emacs)}. It
f97c9175
AE
3345implements an installation procedure similar to the packaging system
3346of Emacs itself (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
e9137a53
FB
3347
3348It first creates the @code{@var{package}-autoloads.el} file, then it
3349byte compiles all Emacs Lisp files. Differently from the Emacs
3350packaging system, the Info documentation files are moved to the standard
3351documentation directory and the @file{dir} file is deleted. Each
3352package is installed in its own directory under
3353@file{share/emacs/site-lisp/guix.d}.
3354@end defvr
3355
7458bd0a
LC
3356Lastly, for packages that do not need anything as sophisticated, a
3357``trivial'' build system is provided. It is trivial in the sense that
3358it provides basically no support: it does not pull any implicit inputs,
3359and does not have a notion of build phases.
3360
3361@defvr {Scheme Variable} trivial-build-system
3362This variable is exported by @code{(guix build-system trivial)}.
3363
3364This build system requires a @code{#:builder} argument. This argument
f97c9175 3365must be a Scheme expression that builds the package output(s)---as
7458bd0a
LC
3366with @code{build-expression->derivation} (@pxref{Derivations,
3367@code{build-expression->derivation}}).
3368@end defvr
3369
568717fd
LC
3370@node The Store
3371@section The Store
3372
e531ac2a 3373@cindex store
1ddee424 3374@cindex store items
e531ac2a
LC
3375@cindex store paths
3376
f97c9175
AE
3377Conceptually, the @dfn{store} is the place where derivations that have
3378been built successfully are stored---by default, @file{/gnu/store}.
1ddee424
LC
3379Sub-directories in the store are referred to as @dfn{store items} or
3380sometimes @dfn{store paths}. The store has an associated database that
3381contains information such as the store paths referred to by each store
3382path, and the list of @emph{valid} store items---results of successful
ef5f5c86
LC
3383builds. This database resides in @file{@var{localstatedir}/guix/db},
3384where @var{localstatedir} is the state directory specified @i{via}
3385@option{--localstatedir} at configure time, usually @file{/var}.
1ddee424
LC
3386
3387The store is @emph{always} accessed by the daemon on behalf of its clients
e531ac2a 3388(@pxref{Invoking guix-daemon}). To manipulate the store, clients
f97c9175
AE
3389connect to the daemon over a Unix-domain socket, send requests to it,
3390and read the result---these are remote procedure calls, or RPCs.
e531ac2a 3391
1ddee424
LC
3392@quotation Note
3393Users must @emph{never} modify files under @file{/gnu/store} directly.
3394This would lead to inconsistencies and break the immutability
3395assumptions of Guix's functional model (@pxref{Introduction}).
3396
3397@xref{Invoking guix gc, @command{guix gc --verify}}, for information on
3398how to check the integrity of the store and attempt recovery from
3399accidental modifications.
3400@end quotation
3401
e531ac2a
LC
3402The @code{(guix store)} module provides procedures to connect to the
3403daemon, and to perform RPCs. These are described below.
3404
3405@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
3406Connect to the daemon over the Unix-domain socket at @var{file}. When
3407@var{reserve-space?} is true, instruct it to reserve a little bit of
3408extra space on the file system so that the garbage collector can still
f97c9175 3409operate should the disk become full. Return a server object.
e531ac2a
LC
3410
3411@var{file} defaults to @var{%default-socket-path}, which is the normal
3412location given the options that were passed to @command{configure}.
3413@end deffn
3414
3415@deffn {Scheme Procedure} close-connection @var{server}
3416Close the connection to @var{server}.
3417@end deffn
3418
3419@defvr {Scheme Variable} current-build-output-port
3420This variable is bound to a SRFI-39 parameter, which refers to the port
3421where build and error logs sent by the daemon should be written.
3422@end defvr
3423
3424Procedures that make RPCs all take a server object as their first
3425argument.
3426
3427@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
06b76acc
LC
3428@cindex invalid store items
3429Return @code{#t} when @var{path} designates a valid store item and
3430@code{#f} otherwise (an invalid item may exist on disk but still be
3431invalid, for instance because it is the result of an aborted or failed
3432build.)
3433
3434A @code{&nix-protocol-error} condition is raised if @var{path} is not
3435prefixed by the store directory (@file{/gnu/store}).
e531ac2a
LC
3436@end deffn
3437
cfbf9160 3438@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
3439Add @var{text} under file @var{name} in the store, and return its store
3440path. @var{references} is the list of store paths referred to by the
3441resulting store path.
3442@end deffn
3443
874e6874 3444@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
3445Build @var{derivations} (a list of @code{<derivation>} objects or
3446derivation paths), and return when the worker is done building them.
3447Return @code{#t} on success.
874e6874
LC
3448@end deffn
3449
b860f382
LC
3450Note that the @code{(guix monads)} module provides a monad as well as
3451monadic versions of the above procedures, with the goal of making it
3452more convenient to work with code that accesses the store (@pxref{The
3453Store Monad}).
3454
e531ac2a
LC
3455@c FIXME
3456@i{This section is currently incomplete.}
568717fd
LC
3457
3458@node Derivations
3459@section Derivations
3460
874e6874
LC
3461@cindex derivations
3462Low-level build actions and the environment in which they are performed
70458ed5 3463are represented by @dfn{derivations}. A derivation contains the
874e6874
LC
3464following pieces of information:
3465
3466@itemize
3467@item
3468The outputs of the derivation---derivations produce at least one file or
3469directory in the store, but may produce more.
3470
3471@item
3472The inputs of the derivations, which may be other derivations or plain
3473files in the store (patches, build scripts, etc.)
3474
3475@item
3476The system type targeted by the derivation---e.g., @code{x86_64-linux}.
3477
3478@item
3479The file name of a build script in the store, along with the arguments
3480to be passed.
3481
3482@item
3483A list of environment variables to be defined.
3484
3485@end itemize
3486
3487@cindex derivation path
3488Derivations allow clients of the daemon to communicate build actions to
3489the store. They exist in two forms: as an in-memory representation,
3490both on the client- and daemon-side, and as files in the store whose
3491name end in @code{.drv}---these files are referred to as @dfn{derivation
3492paths}. Derivations paths can be passed to the @code{build-derivations}
3493procedure to perform the build actions they prescribe (@pxref{The
3494Store}).
3495
3496The @code{(guix derivations)} module provides a representation of
3497derivations as Scheme objects, along with procedures to create and
3498otherwise manipulate derivations. The lowest-level primitive to create
3499a derivation is the @code{derivation} procedure:
3500
1909431c
LC
3501@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
3502 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 3503 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 3504 [#:system (%current-system)] [#:references-graphs #f] @
35b5ca78
LC
3505 [#:allowed-references #f] [#:disallowed-references #f] @
3506 [#:leaked-env-vars #f] [#:local-build? #f] @
4a6aeb67 3507 [#:substitutable? #t]
59688fc4
LC
3508Build a derivation with the given arguments, and return the resulting
3509@code{<derivation>} object.
874e6874 3510
2096ef47 3511When @var{hash} and @var{hash-algo} are given, a
874e6874 3512@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
3513known in advance, such as a file download. If, in addition,
3514@var{recursive?} is true, then that fixed output may be an executable
3515file or a directory and @var{hash} must be the hash of an archive
3516containing this output.
5b0c9d16 3517
858e9282 3518When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
3519name/store path pairs. In that case, the reference graph of each store
3520path is exported in the build environment in the corresponding file, in
3521a simple text format.
1909431c 3522
b53be755 3523When @var{allowed-references} is true, it must be a list of store items
35b5ca78
LC
3524or outputs that the derivation's output may refer to. Likewise,
3525@var{disallowed-references}, if true, must be a list of things the
3526outputs may @emph{not} refer to.
b53be755 3527
c0468155
LC
3528When @var{leaked-env-vars} is true, it must be a list of strings
3529denoting environment variables that are allowed to ``leak'' from the
3530daemon's environment to the build environment. This is only applicable
3531to fixed-output derivations---i.e., when @var{hash} is true. The main
3532use is to allow variables such as @code{http_proxy} to be passed to
3533derivations that download files.
3534
1909431c
LC
3535When @var{local-build?} is true, declare that the derivation is not a
3536good candidate for offloading and should rather be built locally
3537(@pxref{Daemon Offload Setup}). This is the case for small derivations
3538where the costs of data transfers would outweigh the benefits.
4a6aeb67
LC
3539
3540When @var{substitutable?} is false, declare that substitutes of the
3541derivation's output should not be used (@pxref{Substitutes}). This is
3542useful, for instance, when building packages that capture details of the
3543host CPU instruction set.
874e6874
LC
3544@end deffn
3545
3546@noindent
3547Here's an example with a shell script as its builder, assuming
3548@var{store} is an open connection to the daemon, and @var{bash} points
3549to a Bash executable in the store:
3550
3551@lisp
3552(use-modules (guix utils)
3553 (guix store)
3554 (guix derivations))
3555
59688fc4
LC
3556(let ((builder ; add the Bash script to the store
3557 (add-text-to-store store "my-builder.sh"
3558 "echo hello world > $out\n" '())))
3559 (derivation store "foo"
3560 bash `("-e" ,builder)
21b679f6 3561 #:inputs `((,bash) (,builder))
59688fc4 3562 #:env-vars '(("HOME" . "/homeless"))))
834129e0 3563@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
3564@end lisp
3565
21b679f6
LC
3566As can be guessed, this primitive is cumbersome to use directly. A
3567better approach is to write build scripts in Scheme, of course! The
3568best course of action for that is to write the build code as a
3569``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 3570information, @pxref{G-Expressions}.
21b679f6 3571
f2fadbc1
AE
3572Once upon a time, @code{gexp->derivation} did not exist and constructing
3573derivations with build code written in Scheme was achieved with
3574@code{build-expression->derivation}, documented below. This procedure
3575is now deprecated in favor of the much nicer @code{gexp->derivation}.
3576
3577@deffn {Scheme Procedure} build-expression->derivation @var{store} @
3578 @var{name} @var{exp} @
3579 [#:system (%current-system)] [#:inputs '()] @
3580 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
3581 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
3582 [#:references-graphs #f] [#:allowed-references #f] @
35b5ca78 3583 [#:disallowed-references #f] @
f2fadbc1
AE
3584 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
3585Return a derivation that executes Scheme expression @var{exp} as a
3586builder for derivation @var{name}. @var{inputs} must be a list of
3587@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
3588@code{"out"} is assumed. @var{modules} is a list of names of Guile
3589modules from the current search path to be copied in the store,
3590compiled, and made available in the load path during the execution of
3591@var{exp}---e.g., @code{((guix build utils) (guix build
3592gnu-build-system))}.
3593
3594@var{exp} is evaluated in an environment where @code{%outputs} is bound
3595to a list of output/path pairs, and where @code{%build-inputs} is bound
3596to a list of string/output-path pairs made from @var{inputs}.
3597Optionally, @var{env-vars} is a list of string pairs specifying the name
3598and value of environment variables visible to the builder. The builder
3599terminates by passing the result of @var{exp} to @code{exit}; thus, when
3600@var{exp} returns @code{#f}, the build is considered to have failed.
3601
3602@var{exp} is built using @var{guile-for-build} (a derivation). When
3603@var{guile-for-build} is omitted or is @code{#f}, the value of the
3604@code{%guile-for-build} fluid is used instead.
3605
3606See the @code{derivation} procedure for the meaning of
35b5ca78
LC
3607@var{references-graphs}, @var{allowed-references},
3608@var{disallowed-references}, @var{local-build?}, and
3609@var{substitutable?}.
f2fadbc1
AE
3610@end deffn
3611
3612@noindent
3613Here's an example of a single-output derivation that creates a directory
3614containing one file:
3615
3616@lisp
3617(let ((builder '(let ((out (assoc-ref %outputs "out")))
3618 (mkdir out) ; create /gnu/store/@dots{}-goo
3619 (call-with-output-file (string-append out "/test")
3620 (lambda (p)
3621 (display '(hello guix) p))))))
3622 (build-expression->derivation store "goo" builder))
3623
3624@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
3625@end lisp
3626
568717fd 3627
b860f382
LC
3628@node The Store Monad
3629@section The Store Monad
3630
3631@cindex monad
3632
3633The procedures that operate on the store described in the previous
3634sections all take an open connection to the build daemon as their first
3635argument. Although the underlying model is functional, they either have
3636side effects or depend on the current state of the store.
3637
3638The former is inconvenient: the connection to the build daemon has to be
3639carried around in all those functions, making it impossible to compose
3640functions that do not take that parameter with functions that do. The
3641latter can be problematic: since store operations have side effects
3642and/or depend on external state, they have to be properly sequenced.
3643
3644@cindex monadic values
3645@cindex monadic functions
3646This is where the @code{(guix monads)} module comes in. This module
3647provides a framework for working with @dfn{monads}, and a particularly
3648useful monad for our uses, the @dfn{store monad}. Monads are a
3649construct that allows two things: associating ``context'' with values
3650(in our case, the context is the store), and building sequences of
4827b36d 3651computations (here computations include accesses to the store). Values
b860f382
LC
3652in a monad---values that carry this additional context---are called
3653@dfn{monadic values}; procedures that return such values are called
3654@dfn{monadic procedures}.
3655
3656Consider this ``normal'' procedure:
3657
3658@example
45adbd62
LC
3659(define (sh-symlink store)
3660 ;; Return a derivation that symlinks the 'bash' executable.
3661 (let* ((drv (package-derivation store bash))
3662 (out (derivation->output-path drv))
3663 (sh (string-append out "/bin/bash")))
3664 (build-expression->derivation store "sh"
3665 `(symlink ,sh %output))))
b860f382
LC
3666@end example
3667
c6f30b81
LC
3668Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten
3669as a monadic function:
b860f382
LC
3670
3671@example
45adbd62 3672(define (sh-symlink)
b860f382 3673 ;; Same, but return a monadic value.
c6f30b81
LC
3674 (mlet %store-monad ((drv (package->derivation bash)))
3675 (gexp->derivation "sh"
3676 #~(symlink (string-append #$drv "/bin/bash")
3677 #$output))))
b860f382
LC
3678@end example
3679
4827b36d 3680There are several things to note in the second version: the @code{store}
c6f30b81
LC
3681parameter is now implicit and is ``threaded'' in the calls to the
3682@code{package->derivation} and @code{gexp->derivation} monadic
3683procedures, and the monadic value returned by @code{package->derivation}
3684is @dfn{bound} using @code{mlet} instead of plain @code{let}.
3685
3686As it turns out, the call to @code{package->derivation} can even be
3687omitted since it will take place implicitly, as we will see later
3688(@pxref{G-Expressions}):
3689
3690@example
3691(define (sh-symlink)
3692 (gexp->derivation "sh"
3693 #~(symlink (string-append #$bash "/bin/bash")
3694 #$output)))
3695@end example
b860f382 3696
7ce21611 3697@c See
a01ad638 3698@c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/>
7ce21611
LC
3699@c for the funny quote.
3700Calling the monadic @code{sh-symlink} has no effect. As someone once
3701said, ``you exit a monad like you exit a building on fire: by running''.
3702So, to exit the monad and get the desired effect, one must use
3703@code{run-with-store}:
b860f382
LC
3704
3705@example
8e9aa37f
CAW
3706(run-with-store (open-connection) (sh-symlink))
3707@result{} /gnu/store/...-sh-symlink
b860f382
LC
3708@end example
3709
f97c9175 3710Note that the @code{(guix monad-repl)} module extends the Guile REPL with
b9b86078 3711new ``meta-commands'' to make it easier to deal with monadic procedures:
f97c9175 3712@code{run-in-store}, and @code{enter-store-monad}. The former is used
b9b86078
LC
3713to ``run'' a single monadic value through the store:
3714
3715@example
3716scheme@@(guile-user)> ,run-in-store (package->derivation hello)
3717$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3718@end example
3719
3720The latter enters a recursive REPL, where all the return values are
3721automatically run through the store:
3722
3723@example
3724scheme@@(guile-user)> ,enter-store-monad
3725store-monad@@(guile-user) [1]> (package->derivation hello)
3726$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
3727store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
3728$3 = "/gnu/store/@dots{}-foo"
3729store-monad@@(guile-user) [1]> ,q
3730scheme@@(guile-user)>
3731@end example
3732
3733@noindent
3734Note that non-monadic values cannot be returned in the
3735@code{store-monad} REPL.
3736
e87f0591
LC
3737The main syntactic forms to deal with monads in general are provided by
3738the @code{(guix monads)} module and are described below.
b860f382
LC
3739
3740@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
3741Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
3742in @var{monad}.
3743@end deffn
3744
3745@deffn {Scheme Syntax} return @var{val}
3746Return a monadic value that encapsulates @var{val}.
3747@end deffn
3748
751630c9 3749@deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ...
b860f382 3750@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
751630c9
LC
3751procedures @var{mproc}@dots{}@footnote{This operation is commonly
3752referred to as ``bind'', but that name denotes an unrelated procedure in
3753Guile. Thus we use this somewhat cryptic symbol inherited from the
3754Haskell language.}. There can be one @var{mproc} or several of them, as
3755in this example:
3756
3757@example
3758(run-with-state
3759 (with-monad %state-monad
3760 (>>= (return 1)
3761 (lambda (x) (return (+ 1 x)))
3762 (lambda (x) (return (* 2 x)))))
3763 'some-state)
3764
3765@result{} 4
3766@result{} some-state
3767@end example
b860f382
LC
3768@end deffn
3769
3770@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
3771 @var{body} ...
3772@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
3773 @var{body} ...
3774Bind the variables @var{var} to the monadic values @var{mval} in
3775@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
3776``normal'' value @var{val}, as per @code{let}.
3777
3778@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
3779(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
3780@end deffn
3781
405a9d4e
LC
3782@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
3783Bind @var{mexp} and the following monadic expressions in sequence,
3784returning the result of the last expression.
3785
3786This is akin to @code{mlet}, except that the return values of the
3787monadic expressions are ignored. In that sense, it is analogous to
3788@code{begin}, but applied to monadic expressions.
3789@end deffn
3790
561fb6c3
LC
3791@cindex state monad
3792The @code{(guix monads)} module provides the @dfn{state monad}, which
3793allows an additional value---the state---to be @emph{threaded} through
3794monadic procedure calls.
3795
3796@defvr {Scheme Variable} %state-monad
3797The state monad. Procedures in the state monad can access and change
3798the state that is threaded.
3799
3800Consider the example below. The @code{square} procedure returns a value
3801in the state monad. It returns the square of its argument, but also
3802increments the current state value:
3803
3804@example
3805(define (square x)
3806 (mlet %state-monad ((count (current-state)))
3807 (mbegin %state-monad
3808 (set-current-state (+ 1 count))
3809 (return (* x x)))))
3810
3811(run-with-state (sequence %state-monad (map square (iota 3))) 0)
3812@result{} (0 1 4)
3813@result{} 3
3814@end example
3815
3816When ``run'' through @var{%state-monad}, we obtain that additional state
3817value, which is the number of @code{square} calls.
3818@end defvr
3819
3820@deffn {Monadic Procedure} current-state
3821Return the current state as a monadic value.
3822@end deffn
3823
3824@deffn {Monadic Procedure} set-current-state @var{value}
3825Set the current state to @var{value} and return the previous state as a
3826monadic value.
3827@end deffn
3828
3829@deffn {Monadic Procedure} state-push @var{value}
3830Push @var{value} to the current state, which is assumed to be a list,
3831and return the previous state as a monadic value.
3832@end deffn
3833
3834@deffn {Monadic Procedure} state-pop
3835Pop a value from the current state and return it as a monadic value.
3836The state is assumed to be a list.
3837@end deffn
3838
3839@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
3840Run monadic value @var{mval} starting with @var{state} as the initial
3841state. Return two values: the resulting value, and the resulting state.
3842@end deffn
3843
e87f0591
LC
3844The main interface to the store monad, provided by the @code{(guix
3845store)} module, is as follows.
b860f382
LC
3846
3847@defvr {Scheme Variable} %store-monad
561fb6c3
LC
3848The store monad---an alias for @var{%state-monad}.
3849
3850Values in the store monad encapsulate accesses to the store. When its
3851effect is needed, a value of the store monad must be ``evaluated'' by
3852passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
3853@end defvr
3854
3855@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
3856Run @var{mval}, a monadic value in the store monad, in @var{store}, an
3857open store connection.
3858@end deffn
3859
ad372953 3860@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 3861Return as a monadic value the absolute file name in the store of the file
ad372953
LC
3862containing @var{text}, a string. @var{references} is a list of store items that the
3863resulting text file refers to; it defaults to the empty list.
45adbd62
LC
3864@end deffn
3865
0a90af15 3866@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
1ec32f4a 3867 [#:recursive? #t] [#:select? (const #t)]
0a90af15
LC
3868Return the name of @var{file} once interned in the store. Use
3869@var{name} as its store name, or the basename of @var{file} if
3870@var{name} is omitted.
3871
3872When @var{recursive?} is true, the contents of @var{file} are added
3873recursively; if @var{file} designates a flat file and @var{recursive?}
3874is true, its contents are added, and its permission bits are kept.
3875
1ec32f4a
LC
3876When @var{recursive?} is true, call @code{(@var{select?} @var{file}
3877@var{stat})} for each directory entry, where @var{file} is the entry's
3878absolute file name and @var{stat} is the result of @code{lstat}; exclude
3879entries for which @var{select?} does not return true.
3880
0a90af15
LC
3881The example below adds a file to the store, under two different names:
3882
3883@example
3884(run-with-store (open-connection)
3885 (mlet %store-monad ((a (interned-file "README"))
3886 (b (interned-file "README" "LEGU-MIN")))
3887 (return (list a b))))
3888
3889@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
3890@end example
3891
3892@end deffn
3893
e87f0591
LC
3894The @code{(guix packages)} module exports the following package-related
3895monadic procedures:
3896
b860f382 3897@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b 3898 [#:system (%current-system)] [#:target #f] @
f97c9175
AE
3899 [#:output "out"]
3900Return as a monadic
b860f382
LC
3901value in the absolute file name of @var{file} within the @var{output}
3902directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
3903of the @var{output} directory of @var{package}. When @var{target} is
3904true, use it as a cross-compilation target triplet.
b860f382
LC
3905@end deffn
3906
b860f382 3907@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
3908@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
3909 @var{target} [@var{system}]
3910Monadic version of @code{package-derivation} and
3911@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
3912@end deffn
3913
3914
21b679f6
LC
3915@node G-Expressions
3916@section G-Expressions
3917
3918@cindex G-expression
3919@cindex build code quoting
3920So we have ``derivations'', which represent a sequence of build actions
3921to be performed to produce an item in the store (@pxref{Derivations}).
f97c9175 3922These build actions are performed when asking the daemon to actually
21b679f6
LC
3923build the derivations; they are run by the daemon in a container
3924(@pxref{Invoking guix-daemon}).
3925
3926@cindex strata of code
f97c9175 3927It should come as no surprise that we like to write these build actions
21b679f6
LC
3928in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
3929code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
3930Manuel Serrano et al.@: in the context of their work on Hop. Oleg
3931Kiselyov, who has written insightful
3932@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
3933on this topic}, refers to this kind of code generation as
3934@dfn{staging}.}: the ``host code''---code that defines packages, talks
3935to the daemon, etc.---and the ``build code''---code that actually
3936performs build actions, such as making directories, invoking
3937@command{make}, etc.
21b679f6
LC
3938
3939To describe a derivation and its build actions, one typically needs to
3940embed build code inside host code. It boils down to manipulating build
f97c9175 3941code as data, and the homoiconicity of Scheme---code has a direct
21b679f6 3942representation as data---comes in handy for that. But we need more than
f97c9175 3943the normal @code{quasiquote} mechanism in Scheme to construct build
21b679f6
LC
3944expressions.
3945
3946The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
3947S-expressions adapted to build expressions. G-expressions, or
f97c9175 3948@dfn{gexps}, consist essentially of three syntactic forms: @code{gexp},
21b679f6 3949@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
f97c9175
AE
3950@code{#$}, and @code{#$@@}), which are comparable to
3951@code{quasiquote}, @code{unquote}, and @code{unquote-splicing},
4827b36d 3952respectively (@pxref{Expression Syntax, @code{quasiquote},, guile,
f97c9175 3953GNU Guile Reference Manual}). However, there are major differences:
21b679f6
LC
3954
3955@itemize
3956@item
3957Gexps are meant to be written to a file and run or manipulated by other
3958processes.
3959
3960@item
b39fc6f7
LC
3961When a high-level object such as a package or derivation is unquoted
3962inside a gexp, the result is as if its output file name had been
3963introduced.
ff40e9b7 3964
21b679f6
LC
3965@item
3966Gexps carry information about the packages or derivations they refer to,
3967and these dependencies are automatically added as inputs to the build
3968processes that use them.
3969@end itemize
3970
c2b84676 3971@cindex lowering, of high-level objects in gexps
343eacbe
LC
3972This mechanism is not limited to package and derivation
3973objects: @dfn{compilers} able to ``lower'' other high-level objects to
c2b84676
LC
3974derivations or files in the store can be defined,
3975such that these objects can also be inserted
f97c9175 3976into gexps. For example, a useful type of high-level objects that can be
343eacbe 3977inserted in a gexp is ``file-like objects'', which make it easy to
f97c9175 3978add files to the store and to refer to them in
558e8b11
LC
3979derivations and such (see @code{local-file} and @code{plain-file}
3980below.)
b39fc6f7 3981
21b679f6
LC
3982To illustrate the idea, here is an example of a gexp:
3983
3984@example
3985(define build-exp
3986 #~(begin
3987 (mkdir #$output)
3988 (chdir #$output)
aff8ce7c 3989 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
3990 "list-files")))
3991@end example
3992
3993This gexp can be passed to @code{gexp->derivation}; we obtain a
3994derivation that builds a directory containing exactly one symlink to
3995@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
3996
3997@example
3998(gexp->derivation "the-thing" build-exp)
3999@end example
4000
e20fd1bf 4001As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
4002substituted to the reference to the @var{coreutils} package in the
4003actual build code, and @var{coreutils} is automatically made an input to
4004the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
f97c9175
AE
4005output)}) is replaced by a string containing the directory name of the
4006output of the derivation.
667b2508
LC
4007
4008@cindex cross compilation
4009In a cross-compilation context, it is useful to distinguish between
4010references to the @emph{native} build of a package---that can run on the
4011host---versus references to cross builds of a package. To that end, the
4012@code{#+} plays the same role as @code{#$}, but is a reference to a
4013native package build:
4014
4015@example
4016(gexp->derivation "vi"
4017 #~(begin
4018 (mkdir #$output)
4019 (system* (string-append #+coreutils "/bin/ln")
4020 "-s"
4021 (string-append #$emacs "/bin/emacs")
4022 (string-append #$output "/bin/vi")))
4a3b6aa5 4023 #:target "mips64el-linux-gnu")
667b2508
LC
4024@end example
4025
4026@noindent
4027In the example above, the native build of @var{coreutils} is used, so
4028that @command{ln} can actually run on the host; but then the
4029cross-compiled build of @var{emacs} is referenced.
4030
0bb9929e
LC
4031@cindex imported modules, for gexps
4032@findex with-imported-modules
4033Another gexp feature is @dfn{imported modules}: sometimes you want to be
4034able to use certain Guile modules from the ``host environment'' in the
4035gexp, so those modules should be imported in the ``build environment''.
4036The @code{with-imported-modules} form allows you to express that:
4037
4038@example
4039(let ((build (with-imported-modules '((guix build utils))
4040 #~(begin
4041 (use-modules (guix build utils))
4042 (mkdir-p (string-append #$output "/bin"))))))
4043 (gexp->derivation "empty-dir"
4044 #~(begin
4045 #$build
4046 (display "success!\n")
4047 #t)))
4048@end example
4049
4050@noindent
4051In this example, the @code{(guix build utils)} module is automatically
4052pulled into the isolated build environment of our gexp, such that
4053@code{(use-modules (guix build utils))} works as expected.
4054
7ca87354
LC
4055@cindex module closure
4056@findex source-module-closure
4057Usually you want the @emph{closure} of the module to be imported---i.e.,
4058the module itself and all the modules it depends on---rather than just
4059the module; failing to do that, attempts to use the module will fail
4060because of missing dependent modules. The @code{source-module-closure}
4061procedure computes the closure of a module by looking at its source file
4062headers, which comes in handy in this case:
4063
4064@example
4065(use-modules (guix modules)) ;for 'source-module-closure'
4066
4067(with-imported-modules (source-module-closure
4068 '((guix build utils)
4069 (gnu build vm)))
4070 (gexp->derivation "something-with-vms"
4071 #~(begin
4072 (use-modules (guix build utils)
4073 (gnu build vm))
4074 @dots{})))
4075@end example
4076
667b2508 4077The syntactic form to construct gexps is summarized below.
21b679f6
LC
4078
4079@deffn {Scheme Syntax} #~@var{exp}
4080@deffnx {Scheme Syntax} (gexp @var{exp})
4081Return a G-expression containing @var{exp}. @var{exp} may contain one
4082or more of the following forms:
4083
4084@table @code
4085@item #$@var{obj}
4086@itemx (ungexp @var{obj})
b39fc6f7
LC
4087Introduce a reference to @var{obj}. @var{obj} may have one of the
4088supported types, for example a package or a
21b679f6
LC
4089derivation, in which case the @code{ungexp} form is replaced by its
4090output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
4091
b39fc6f7
LC
4092If @var{obj} is a list, it is traversed and references to supported
4093objects are substituted similarly.
21b679f6
LC
4094
4095If @var{obj} is another gexp, its contents are inserted and its
4096dependencies are added to those of the containing gexp.
4097
4098If @var{obj} is another kind of object, it is inserted as is.
4099
b39fc6f7
LC
4100@item #$@var{obj}:@var{output}
4101@itemx (ungexp @var{obj} @var{output})
21b679f6 4102This is like the form above, but referring explicitly to the
b39fc6f7
LC
4103@var{output} of @var{obj}---this is useful when @var{obj} produces
4104multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 4105
667b2508
LC
4106@item #+@var{obj}
4107@itemx #+@var{obj}:output
4108@itemx (ungexp-native @var{obj})
4109@itemx (ungexp-native @var{obj} @var{output})
4110Same as @code{ungexp}, but produces a reference to the @emph{native}
4111build of @var{obj} when used in a cross compilation context.
4112
21b679f6
LC
4113@item #$output[:@var{output}]
4114@itemx (ungexp output [@var{output}])
4115Insert a reference to derivation output @var{output}, or to the main
4116output when @var{output} is omitted.
4117
4118This only makes sense for gexps passed to @code{gexp->derivation}.
4119
4120@item #$@@@var{lst}
4121@itemx (ungexp-splicing @var{lst})
4122Like the above, but splices the contents of @var{lst} inside the
4123containing list.
4124
667b2508
LC
4125@item #+@@@var{lst}
4126@itemx (ungexp-native-splicing @var{lst})
4127Like the above, but refers to native builds of the objects listed in
4128@var{lst}.
4129
21b679f6
LC
4130@end table
4131
4132G-expressions created by @code{gexp} or @code{#~} are run-time objects
4133of the @code{gexp?} type (see below.)
4134@end deffn
4135
0bb9929e
LC
4136@deffn {Scheme Syntax} with-imported-modules @var{modules} @var{body}@dots{}
4137Mark the gexps defined in @var{body}@dots{} as requiring @var{modules}
4138in their execution environment. @var{modules} must be a list of Guile
4139module names, such as @code{'((guix build utils) (guix build gremlin))}.
4140
4141This form has @emph{lexical} scope: it has an effect on the gexps
4142directly defined in @var{body}@dots{}, but not on those defined, say, in
4143procedures called from @var{body}@dots{}.
4144@end deffn
4145
21b679f6
LC
4146@deffn {Scheme Procedure} gexp? @var{obj}
4147Return @code{#t} if @var{obj} is a G-expression.
4148@end deffn
4149
4150G-expressions are meant to be written to disk, either as code building
4151some derivation, or as plain files in the store. The monadic procedures
4152below allow you to do that (@pxref{The Store Monad}, for more
4153information about monads.)
4154
4155@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 4156 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
4157 [#:hash #f] [#:hash-algo #f] @
4158 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 4159 [#:module-path @var{%load-path}] @
c8351d9a 4160 [#:references-graphs #f] [#:allowed-references #f] @
3f4ecf32 4161 [#:disallowed-references #f] @
c0468155 4162 [#:leaked-env-vars #f] @
0309e1b0 4163 [#:script-name (string-append @var{name} "-builder")] @
4a6aeb67 4164 [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f]
21b679f6 4165Return a derivation @var{name} that runs @var{exp} (a gexp) with
0309e1b0
LC
4166@var{guile-for-build} (a derivation) on @var{system}; @var{exp} is
4167stored in a file called @var{script-name}. When @var{target} is true,
4168it is used as the cross-compilation target triplet for packages referred
4169to by @var{exp}.
21b679f6 4170
0bb9929e
LC
4171@var{modules} is deprecated in favor of @code{with-imported-modules}.
4172Its meaning is to
4173make @var{modules} available in the evaluation context of @var{exp};
ce45eb4c
LC
4174@var{modules} is a list of names of Guile modules searched in
4175@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
4176the load path during the execution of @var{exp}---e.g., @code{((guix
4177build utils) (guix build gnu-build-system))}.
4178
ce45eb4c
LC
4179@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
4180applicable.
4181
b53833b2
LC
4182When @var{references-graphs} is true, it must be a list of tuples of one of the
4183following forms:
4184
4185@example
4186(@var{file-name} @var{package})
4187(@var{file-name} @var{package} @var{output})
4188(@var{file-name} @var{derivation})
4189(@var{file-name} @var{derivation} @var{output})
4190(@var{file-name} @var{store-item})
4191@end example
4192
4193The right-hand-side of each element of @var{references-graphs} is automatically made
4194an input of the build process of @var{exp}. In the build environment, each
4195@var{file-name} contains the reference graph of the corresponding item, in a simple
4196text format.
4197
c8351d9a
LC
4198@var{allowed-references} must be either @code{#f} or a list of output names and packages.
4199In the latter case, the list denotes store items that the result is allowed to
4200refer to. Any reference to another store item will lead to a build error.
3f4ecf32
LC
4201Similarly for @var{disallowed-references}, which can list items that must not be
4202referenced by the outputs.
c8351d9a 4203
e20fd1bf 4204The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
4205@end deffn
4206
343eacbe 4207@cindex file-like objects
e1c153e0
LC
4208The @code{local-file}, @code{plain-file}, @code{computed-file},
4209@code{program-file}, and @code{scheme-file} procedures below return
4210@dfn{file-like objects}. That is, when unquoted in a G-expression,
4211these objects lead to a file in the store. Consider this G-expression:
343eacbe
LC
4212
4213@example
a9e5e92f 4214#~(system* #$(file-append glibc "/sbin/nscd") "-f"
343eacbe
LC
4215 #$(local-file "/tmp/my-nscd.conf"))
4216@end example
4217
4218The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it
4219to the store. Once expanded, for instance @i{via}
4220@code{gexp->derivation}, the G-expression refers to that copy under
4221@file{/gnu/store}; thus, modifying or removing the file in @file{/tmp}
4222does not have any effect on what the G-expression does.
4223@code{plain-file} can be used similarly; it differs in that the file
4224content is directly passed as a string.
4225
d9ae938f 4226@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
0687fc9c 4227 [#:recursive? #f] [#:select? (const #t)]
d9ae938f 4228Return an object representing local file @var{file} to add to the store; this
9d3994f7
LC
4229object can be used in a gexp. If @var{file} is a relative file name, it is looked
4230up relative to the source file where this form appears. @var{file} will be added to
4231the store under @var{name}--by default the base name of @var{file}.
d9ae938f
LC
4232
4233When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
4234designates a flat file and @var{recursive?} is true, its contents are added, and its
4235permission bits are kept.
4236
0687fc9c
LC
4237When @var{recursive?} is true, call @code{(@var{select?} @var{file}
4238@var{stat})} for each directory entry, where @var{file} is the entry's
4239absolute file name and @var{stat} is the result of @code{lstat}; exclude
4240entries for which @var{select?} does not return true.
4241
d9ae938f
LC
4242This is the declarative counterpart of the @code{interned-file} monadic
4243procedure (@pxref{The Store Monad, @code{interned-file}}).
4244@end deffn
4245
558e8b11
LC
4246@deffn {Scheme Procedure} plain-file @var{name} @var{content}
4247Return an object representing a text file called @var{name} with the given
4248@var{content} (a string) to be added to the store.
4249
4250This is the declarative counterpart of @code{text-file}.
4251@end deffn
4252
91937029 4253@deffn {Scheme Procedure} computed-file @var{name} @var{gexp} @
a769bffb 4254 [#:options '(#:local-build? #t)]
91937029 4255Return an object representing the store item @var{name}, a file or
a769bffb 4256directory computed by @var{gexp}. @var{options}
91937029
LC
4257is a list of additional arguments to pass to @code{gexp->derivation}.
4258
4259This is the declarative counterpart of @code{gexp->derivation}.
4260@end deffn
4261
21b679f6
LC
4262@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
4263Return an executable script @var{name} that runs @var{exp} using
9c14a487 4264@var{guile}, with @var{exp}'s imported modules in its search path.
21b679f6
LC
4265
4266The example below builds a script that simply invokes the @command{ls}
4267command:
4268
4269@example
4270(use-modules (guix gexp) (gnu packages base))
4271
4272(gexp->script "list-files"
a9e5e92f 4273 #~(execl #$(file-append coreutils "/bin/ls")
21b679f6
LC
4274 "ls"))
4275@end example
4276
4277When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 4278@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
4279executable file @file{/gnu/store/@dots{}-list-files} along these lines:
4280
4281@example
4282#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
4283!#
a9e5e92f 4284(execl "/gnu/store/@dots{}-coreutils-8.22"/bin/ls" "ls")
21b679f6
LC
4285@end example
4286@end deffn
4287
15a01c72 4288@deffn {Scheme Procedure} program-file @var{name} @var{exp} @
9c14a487 4289 [#:guile #f]
15a01c72
LC
4290Return an object representing the executable store item @var{name} that
4291runs @var{gexp}. @var{guile} is the Guile package used to execute that
9c14a487 4292script.
15a01c72
LC
4293
4294This is the declarative counterpart of @code{gexp->script}.
4295@end deffn
4296
2b418579
LC
4297@deffn {Monadic Procedure} gexp->file @var{name} @var{exp} @
4298 [#:set-load-path? #t]
21b679f6 4299Return a derivation that builds a file @var{name} containing @var{exp}.
2b418579
LC
4300When @var{set-load-path?} is true, emit code in the resulting file to
4301set @code{%load-path} and @code{%load-compiled-path} to honor
4302@var{exp}'s imported modules.
21b679f6
LC
4303
4304The resulting file holds references to all the dependencies of @var{exp}
4305or a subset thereof.
4306@end deffn
1ed19464 4307
e1c153e0
LC
4308@deffn {Scheme Procedure} scheme-file @var{name} @var{exp}
4309Return an object representing the Scheme file @var{name} that contains
4310@var{exp}.
4311
4312This is the declarative counterpart of @code{gexp->file}.
4313@end deffn
4314
1ed19464
LC
4315@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
4316Return as a monadic value a derivation that builds a text file
4317containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
4318strings, objects of any type that can be used in a gexp: packages,
4319derivations, local file objects, etc. The resulting store file holds
4320references to all these.
1ed19464
LC
4321
4322This variant should be preferred over @code{text-file} anytime the file
4323to create will reference items from the store. This is typically the
4324case when building a configuration file that embeds store file names,
4325like this:
4326
4327@example
4328(define (profile.sh)
4329 ;; Return the name of a shell script in the store that
4330 ;; initializes the 'PATH' environment variable.
4331 (text-file* "profile.sh"
4332 "export PATH=" coreutils "/bin:"
4333 grep "/bin:" sed "/bin\n"))
4334@end example
4335
4336In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
b7899749 4337will reference @var{coreutils}, @var{grep}, and @var{sed}, thereby
1ed19464
LC
4338preventing them from being garbage-collected during its lifetime.
4339@end deffn
21b679f6 4340
b751cde3
LC
4341@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
4342Return an object representing store file @var{name} containing
4343@var{text}. @var{text} is a sequence of strings and file-like objects,
4344as in:
4345
4346@example
4347(mixed-text-file "profile"
4348 "export PATH=" coreutils "/bin:" grep "/bin")
4349@end example
4350
4351This is the declarative counterpart of @code{text-file*}.
4352@end deffn
4353
a9e5e92f
LC
4354@deffn {Scheme Procedure} file-append @var{obj} @var{suffix} @dots{}
4355Return a file-like object that expands to the concatenation of @var{obj}
4356and @var{suffix}, where @var{obj} is a lowerable object and each
4357@var{suffix} is a string.
4358
4359As an example, consider this gexp:
4360
4361@example
4362(gexp->script "run-uname"
4363 #~(system* #$(file-append coreutils
4364 "/bin/uname")))
4365@end example
4366
4367The same effect could be achieved with:
4368
4369@example
4370(gexp->script "run-uname"
4371 #~(system* (string-append #$coreutils
4372 "/bin/uname")))
4373@end example
4374
4375There is one difference though: in the @code{file-append} case, the
4376resulting script contains the absolute file name as a string, whereas in
4377the second case, the resulting script contains a @code{(string-append
4378@dots{})} expression to construct the file name @emph{at run time}.
4379@end deffn
4380
4381
21b679f6
LC
4382Of course, in addition to gexps embedded in ``host'' code, there are
4383also modules containing build tools. To make it clear that they are
4384meant to be used in the build stratum, these modules are kept in the
4385@code{(guix build @dots{})} name space.
4386
c2b84676
LC
4387@cindex lowering, of high-level objects in gexps
4388Internally, high-level objects are @dfn{lowered}, using their compiler,
4389to either derivations or store items. For instance, lowering a package
4390yields a derivation, and lowering a @code{plain-file} yields a store
4391item. This is achieved using the @code{lower-object} monadic procedure.
4392
4393@deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @
4394 [#:target #f]
4395Return as a value in @var{%store-monad} the derivation or store item
4396corresponding to @var{obj} for @var{system}, cross-compiling for
4397@var{target} if @var{target} is true. @var{obj} must be an object that
4398has an associated gexp compiler, such as a @code{<package>}.
4399@end deffn
4400
21b679f6 4401
568717fd
LC
4402@c *********************************************************************
4403@node Utilities
4404@chapter Utilities
4405
6f773606
LC
4406This section describes Guix command-line utilities. Some of them are
4407primarily targeted at developers and users who write new package
4408definitions, while others are more generally useful. They complement
4409the Scheme programming interface of Guix in a convenient way.
210cc920 4410
568717fd 4411@menu
37166310 4412* Invoking guix build:: Building packages from the command line.
39bee8a2 4413* Invoking guix edit:: Editing package definitions.
210cc920 4414* Invoking guix download:: Downloading a file and printing its hash.
37166310 4415* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 4416* Invoking guix import:: Importing package definitions.
37166310 4417* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 4418* Invoking guix lint:: Finding errors in package definitions.
fcc58db6 4419* Invoking guix size:: Profiling disk usage.
88856916 4420* Invoking guix graph:: Visualizing the graph of packages.
372c4bbc 4421* Invoking guix environment:: Setting up development environments.
aff8ce7c 4422* Invoking guix publish:: Sharing substitutes.
d23c20f1 4423* Invoking guix challenge:: Challenging substitute servers.
f11c444d 4424* Invoking guix copy:: Copying to and from a remote store.
32efa254 4425* Invoking guix container:: Process isolation.
568717fd
LC
4426@end menu
4427
e49951eb
MW
4428@node Invoking guix build
4429@section Invoking @command{guix build}
568717fd 4430
e32171ee
JD
4431@cindex package building
4432@cindex @command{guix build}
e49951eb 4433The @command{guix build} command builds packages or derivations and
6798a8e4
LC
4434their dependencies, and prints the resulting store paths. Note that it
4435does not modify the user's profile---this is the job of the
e49951eb 4436@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
4437it is mainly useful for distribution developers.
4438
4439The general syntax is:
c78bd12b
LC
4440
4441@example
e49951eb 4442guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
4443@end example
4444
f97c9175 4445As an example, the following command builds the latest versions of Emacs
ccd7158d
LC
4446and of Guile, displays their build logs, and finally displays the
4447resulting directories:
4448
4449@example
4450guix build emacs guile
4451@end example
4452
4453Similarly, the following command builds all the available packages:
4454
4455@example
5284339d 4456guix build --quiet --keep-going \
ccd7158d
LC
4457 `guix package -A | cut -f1,2 --output-delimiter=@@`
4458@end example
4459
c78bd12b 4460@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
4461the software distribution such as @code{coreutils} or
4462@code{coreutils-8.20}, or a derivation such as
834129e0 4463@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
4464package with the corresponding name (and optionally version) is searched
4465for among the GNU distribution modules (@pxref{Package Modules}).
4466
4467Alternatively, the @code{--expression} option may be used to specify a
4468Scheme expression that evaluates to a package; this is useful when
b7899749 4469disambiguating among several same-named packages or package variants is
e7f34eb0 4470needed.
c78bd12b 4471
ccd7158d
LC
4472There may be zero or more @var{options}. The available options are
4473described in the subsections below.
4474
4475@menu
4476* Common Build Options:: Build options for most commands.
f11c444d 4477* Package Transformation Options:: Creating variants of packages.
ccd7158d
LC
4478* Additional Build Options:: Options specific to 'guix build'.
4479@end menu
4480
4481@node Common Build Options
4482@subsection Common Build Options
4483
4484A number of options that control the build process are common to
4485@command{guix build} and other commands that can spawn builds, such as
4486@command{guix package} or @command{guix archive}. These are the
4487following:
4488
4489@table @code
4490
4491@item --load-path=@var{directory}
4492@itemx -L @var{directory}
4493Add @var{directory} to the front of the package module search path
4494(@pxref{Package Modules}).
4495
4496This allows users to define their own packages and make them visible to
4497the command-line tools.
4498
4499@item --keep-failed
4500@itemx -K
b7899749 4501Keep the build tree of failed builds. Thus, if a build fails, its build
ccd7158d
LC
4502tree is kept under @file{/tmp}, in a directory whose name is shown at
4503the end of the build log. This is useful when debugging build issues.
4504
4505@item --keep-going
4506@itemx -k
4507Keep going when some of the derivations fail to build; return only once
4508all the builds have either completed or failed.
4509
4510The default behavior is to stop as soon as one of the specified
4511derivations has failed.
4512
4513@item --dry-run
4514@itemx -n
4515Do not build the derivations.
4516
4517@item --fallback
4518When substituting a pre-built binary fails, fall back to building
4519packages locally.
4520
4521@item --substitute-urls=@var{urls}
4522@anchor{client-substitute-urls}
4523Consider @var{urls} the whitespace-separated list of substitute source
4524URLs, overriding the default list of URLs of @command{guix-daemon}
4525(@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}).
4526
4527This means that substitutes may be downloaded from @var{urls}, provided
4528they are signed by a key authorized by the system administrator
4529(@pxref{Substitutes}).
4530
71e2065a
LC
4531When @var{urls} is the empty string, substitutes are effectively
4532disabled.
4533
ccd7158d
LC
4534@item --no-substitutes
4535Do not use substitutes for build products. That is, always build things
4536locally instead of allowing downloads of pre-built binaries
4537(@pxref{Substitutes}).
4538
7573d30f
LC
4539@item --no-grafts
4540Do not ``graft'' packages. In practice, this means that package updates
4541available as grafts are not applied. @xref{Security Updates}, for more
4542information on grafts.
4543
ccd7158d
LC
4544@item --rounds=@var{n}
4545Build each derivation @var{n} times in a row, and raise an error if
4546consecutive build results are not bit-for-bit identical.
4547
4548This is a useful way to detect non-deterministic builds processes.
4549Non-deterministic build processes are a problem because they make it
4550practically impossible for users to @emph{verify} whether third-party
4551binaries are genuine. @xref{Invoking guix challenge}, for more.
4552
4553Note that, currently, the differing build results are not kept around,
4554so you will have to manually investigate in case of an error---e.g., by
e66d1f59
ML
4555stashing one of the build results with @code{guix archive --export}
4556(@pxref{Invoking guix archive}), then rebuilding, and finally comparing
4557the two results.
ccd7158d
LC
4558
4559@item --no-build-hook
f97c9175 4560Do not attempt to offload builds @i{via} the ``build hook'' of the daemon
ccd7158d
LC
4561(@pxref{Daemon Offload Setup}). That is, always build things locally
4562instead of offloading builds to remote machines.
4563
4564@item --max-silent-time=@var{seconds}
4565When the build or substitution process remains silent for more than
4566@var{seconds}, terminate it and report a build failure.
4567
4568@item --timeout=@var{seconds}
4569Likewise, when the build or substitution process lasts for more than
4570@var{seconds}, terminate it and report a build failure.
4571
4572By default there is no timeout. This behavior can be restored with
4573@code{--timeout=0}.
4574
4575@item --verbosity=@var{level}
4576Use the given verbosity level. @var{level} must be an integer between 0
4577and 5; higher means more verbose output. Setting a level of 4 or more
4578may be helpful when debugging setup issues with the build daemon.
4579
4580@item --cores=@var{n}
4581@itemx -c @var{n}
4582Allow the use of up to @var{n} CPU cores for the build. The special
4583value @code{0} means to use as many CPU cores as available.
4584
4585@item --max-jobs=@var{n}
4586@itemx -M @var{n}
4587Allow at most @var{n} build jobs in parallel. @xref{Invoking
4588guix-daemon, @code{--max-jobs}}, for details about this option and the
4589equivalent @command{guix-daemon} option.
4590
4591@end table
4592
4593Behind the scenes, @command{guix build} is essentially an interface to
4594the @code{package-derivation} procedure of the @code{(guix packages)}
4595module, and to the @code{build-derivations} procedure of the @code{(guix
4596derivations)} module.
4597
4598In addition to options explicitly passed on the command line,
4599@command{guix build} and other @command{guix} commands that support
4600building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
4601
4602@defvr {Environment Variable} GUIX_BUILD_OPTIONS
4603Users can define this variable to a list of command line options that
4604will automatically be used by @command{guix build} and other
4605@command{guix} commands that can perform builds, as in the example
4606below:
4607
4608@example
4609$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
4610@end example
4611
4612These options are parsed independently, and the result is appended to
4613the parsed command-line options.
4614@end defvr
4615
88ad6ded
LC
4616
4617@node Package Transformation Options
4618@subsection Package Transformation Options
4619
4620@cindex package variants
4621Another set of command-line options supported by @command{guix build}
b8638f03 4622and also @command{guix package} are @dfn{package transformation
f97c9175 4623options}. These are options that make it possible to define @dfn{package
b8638f03
LC
4624variants}---for instance, packages built from different source code.
4625This is a convenient way to create customized packages on the fly
4626without having to type in the definitions of package variants
4627(@pxref{Defining Packages}).
88ad6ded
LC
4628
4629@table @code
4630
4631@item --with-source=@var{source}
4632Use @var{source} as the source of the corresponding package.
4633@var{source} must be a file name or a URL, as for @command{guix
4634download} (@pxref{Invoking guix download}).
4635
f97c9175
AE
4636The ``corresponding package'' is taken to be the one specified on the
4637command line the name of which matches the base of @var{source}---e.g.,
4638if @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
88ad6ded 4639package is @code{guile}. Likewise, the version string is inferred from
f97c9175 4640@var{source}; in the previous example, it is @code{2.0.10}.
88ad6ded
LC
4641
4642This option allows users to try out versions of packages other than the
4643one provided by the distribution. The example below downloads
4644@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
4645the @code{ed} package:
4646
4647@example
4648guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
4649@end example
4650
4651As a developer, @code{--with-source} makes it easy to test release
4652candidates:
4653
4654@example
4655guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
4656@end example
4657
4658@dots{} or to build from a checkout in a pristine environment:
4659
4660@example
4661$ git clone git://git.sv.gnu.org/guix.git
4662$ guix build guix --with-source=./guix
4663@end example
4664
47c0f92c
LC
4665@item --with-input=@var{package}=@var{replacement}
4666Replace dependency on @var{package} by a dependency on
4667@var{replacement}. @var{package} must be a package name, and
4668@var{replacement} must be a package specification such as @code{guile}
4669or @code{guile@@1.8}.
4670
f97c9175 4671For instance, the following command builds Guix, but replaces its
47c0f92c
LC
4672dependency on the current stable version of Guile with a dependency on
4673the development version of Guile, @code{guile-next}:
4674
4675@example
4676guix build --with-input=guile=guile-next guix
4677@end example
4678
4679This is a recursive, deep replacement. So in this example, both
4680@code{guix} and its dependency @code{guile-json} (which also depends on
4681@code{guile}) get rebuilt against @code{guile-next}.
4682
2a75b0b6
LC
4683This is implemented using the @code{package-input-rewriting} Scheme
4684procedure (@pxref{Defining Packages, @code{package-input-rewriting}}).
645b9df8
LC
4685
4686@item --with-graft=@var{package}=@var{replacement}
4687This is similar to @code{--with-input} but with an important difference:
4688instead of rebuilding all the dependency chain, @var{replacement} is
4689built and then @dfn{grafted} onto the binaries that were initially
4690referring to @var{package}. @xref{Security Updates}, for more
4691information on grafts.
4692
4693For example, the command below grafts version 3.5.4 of GnuTLS onto Wget
4694and all its dependencies, replacing references to the version of GnuTLS
4695they currently refer to:
4696
4697@example
4698guix build --with-graft=gnutls=gnutls@@3.5.4 wget
4699@end example
4700
4701This has the advantage of being much faster than rebuilding everything.
4702But there is a caveat: it works if and only if @var{package} and
4703@var{replacement} are strictly compatible---for example, if they provide
4704a library, the application binary interface (ABI) of those libraries
4705must be compatible. If @var{replacement} is somehow incompatible with
4706@var{package}, then the resulting package may be unusable. Use with
4707care!
4708
88ad6ded
LC
4709@end table
4710
ccd7158d
LC
4711@node Additional Build Options
4712@subsection Additional Build Options
4713
4714The command-line options presented below are specific to @command{guix
4715build}.
c78bd12b
LC
4716
4717@table @code
4718
5284339d
LC
4719@item --quiet
4720@itemx -q
4721Build quietly, without displaying the build log. Upon completion, the
4722build log is kept in @file{/var} (or similar) and can always be
4723retrieved using the @option{--log-file} option.
4724
34a1783f
DT
4725@item --file=@var{file}
4726@itemx -f @var{file}
4727
4728Build the package or derivation that the code within @var{file}
4729evaluates to.
4730
4731As an example, @var{file} might contain a package definition like this
4732(@pxref{Defining Packages}):
4733
4734@example
4735@verbatiminclude package-hello.scm
4736@end example
4737
c78bd12b
LC
4738@item --expression=@var{expr}
4739@itemx -e @var{expr}
ac5de156 4740Build the package or derivation @var{expr} evaluates to.
c78bd12b 4741
5401dd75 4742For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
4743guile-1.8)}, which unambiguously designates this specific variant of
4744version 1.8 of Guile.
4745
f97c9175 4746Alternatively, @var{expr} may be a G-expression, in which case it is used
56b82106
LC
4747as a build program passed to @code{gexp->derivation}
4748(@pxref{G-Expressions}).
4749
4750Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
4751(@pxref{The Store Monad}). The procedure must return a derivation as a
4752monadic value, which is then passed through @code{run-with-store}.
4753
c78bd12b
LC
4754@item --source
4755@itemx -S
f97c9175 4756Build the source derivations of the packages, rather than the packages
c78bd12b
LC
4757themselves.
4758
e49951eb 4759For instance, @code{guix build -S gcc} returns something like
f97c9175
AE
4760@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is the GCC
4761source tarball.
c78bd12b 4762
f9cc8971 4763The returned source tarball is the result of applying any patches and
f97c9175 4764code snippets specified in the package @code{origin} (@pxref{Defining
f9cc8971
LC
4765Packages}).
4766
2cdfe13d
EB
4767@item --sources
4768Fetch and return the source of @var{package-or-derivation} and all their
4769dependencies, recursively. This is a handy way to obtain a local copy
4770of all the source code needed to build @var{packages}, allowing you to
4771eventually build them even without network access. It is an extension
4772of the @code{--source} option and can accept one of the following
4773optional argument values:
4774
4775@table @code
4776@item package
4777This value causes the @code{--sources} option to behave in the same way
4778as the @code{--source} option.
4779
4780@item all
f97c9175
AE
4781Build the source derivations of all packages, including any source that
4782might be listed as @code{inputs}. This is the default value.
2cdfe13d
EB
4783
4784@example
4785$ guix build --sources tzdata
4786The following derivations will be built:
4787 /gnu/store/@dots{}-tzdata2015b.tar.gz.drv
4788 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4789@end example
4790
4791@item transitive
f97c9175
AE
4792Build the source derivations of all packages, as well of all transitive
4793inputs to the packages. This can be used e.g. to
2cdfe13d
EB
4794prefetch package source for later offline building.
4795
4796@example
4797$ guix build --sources=transitive tzdata
4798The following derivations will be built:
4799 /gnu/store/@dots{}-tzcode2015b.tar.gz.drv
4800 /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv
4801 /gnu/store/@dots{}-grep-2.21.tar.xz.drv
4802 /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv
4803 /gnu/store/@dots{}-make-4.1.tar.xz.drv
4804 /gnu/store/@dots{}-bash-4.3.tar.xz.drv
4805@dots{}
4806@end example
4807
4808@end table
4809
c78bd12b
LC
4810@item --system=@var{system}
4811@itemx -s @var{system}
4812Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
f97c9175 4813the system type of the build host.
c78bd12b
LC
4814
4815An example use of this is on Linux-based systems, which can emulate
4816different personalities. For instance, passing
4817@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
4818to build packages in a complete 32-bit environment.
4819
e55ec43d
LC
4820@item --target=@var{triplet}
4821@cindex cross-compilation
4822Cross-build for @var{triplet}, which must be a valid GNU triplet, such
4823as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
4824configuration triplets,, configure, GNU Configure and Build System}).
4825
a8d65643
LC
4826@anchor{build-check}
4827@item --check
4828@cindex determinism, checking
4829@cindex reproducibility, checking
4830Rebuild @var{package-or-derivation}, which are already available in the
4831store, and raise an error if the build results are not bit-for-bit
4832identical.
4833
f97c9175
AE
4834This mechanism allows you to check whether previously installed
4835substitutes are genuine (@pxref{Substitutes}), or whether the build result
4836of a package is deterministic. @xref{Invoking guix challenge}, for more
a8d65643
LC
4837background information and tools.
4838
7f3b2510
ED
4839When used in conjunction with @option{--keep-failed}, the differing
4840output is kept in the store, under @file{/gnu/store/@dots{}-check}.
4841This makes it easy to look for differences between the two results.
4842
c78bd12b
LC
4843@item --derivations
4844@itemx -d
4845Return the derivation paths, not the output paths, of the given
4846packages.
4847
70ee5642
LC
4848@item --root=@var{file}
4849@itemx -r @var{file}
4850Make @var{file} a symlink to the result, and register it as a garbage
4851collector root.
4852
4853@item --log-file
3f208ad7 4854Return the build log file names or URLs for the given
f97c9175 4855@var{package-or-derivation}, or raise an error if build logs are
70ee5642
LC
4856missing.
4857
4858This works regardless of how packages or derivations are specified. For
4859instance, the following invocations are equivalent:
4860
4861@example
4862guix build --log-file `guix build -d guile`
4863guix build --log-file `guix build guile`
4864guix build --log-file guile
4865guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
4866@end example
4867
3f208ad7
LC
4868If a log is unavailable locally, and unless @code{--no-substitutes} is
4869passed, the command looks for a corresponding log on one of the
4870substitute servers (as specified with @code{--substitute-urls}.)
70ee5642 4871
f97c9175
AE
4872So for instance, imagine you want to see the build log of GDB on MIPS,
4873but you are actually on an @code{x86_64} machine:
3f208ad7
LC
4874
4875@example
a01ad638 4876$ guix build --log-file gdb -s mips64el-linux
df061d07 4877https://hydra.gnu.org/log/@dots{}-gdb-7.10
3f208ad7
LC
4878@end example
4879
4880You can freely access a huge library of build logs!
70ee5642
LC
4881@end table
4882
16eb115e 4883
39bee8a2
LC
4884@node Invoking guix edit
4885@section Invoking @command{guix edit}
4886
e32171ee 4887@cindex @command{guix edit}
39bee8a2
LC
4888@cindex package definition, editing
4889So many packages, so many source files! The @command{guix edit} command
424a323e
GC
4890facilitates the life of users and packagers by pointing their editor at
4891the source file containing the definition of the specified packages.
4892For instance:
39bee8a2
LC
4893
4894@example
7b9a66e5 4895guix edit gcc@@4.9 vim
39bee8a2
LC
4896@end example
4897
4898@noindent
6237b9fa 4899launches the program specified in the @code{VISUAL} or in the
424a323e 4900@code{EDITOR} environment variable to view the recipe of GCC@tie{}4.9.3
6237b9fa 4901and that of Vim.
39bee8a2 4902
424a323e
GC
4903If you are using a Guix Git checkout (@pxref{Building from Git}), or
4904have created your own packages on @code{GUIX_PACKAGE_PATH}
4905(@pxref{Defining Packages}), you will be able to edit the package
4906recipes. Otherwise, you will be able to examine the read-only recipes
4907for packages currently in the store.
4908
39bee8a2 4909
210cc920
LC
4910@node Invoking guix download
4911@section Invoking @command{guix download}
4912
e32171ee
JD
4913@cindex @command{guix download}
4914@cindex downloading package sources
210cc920 4915When writing a package definition, developers typically need to download
f97c9175 4916a source tarball, compute its SHA256 hash, and write that
210cc920
LC
4917hash in the package definition (@pxref{Defining Packages}). The
4918@command{guix download} tool helps with this task: it downloads a file
4919from the given URI, adds it to the store, and prints both its file name
4920in the store and its SHA256 hash.
4921
4922The fact that the downloaded file is added to the store saves bandwidth:
4923when the developer eventually tries to build the newly defined package
4924with @command{guix build}, the source tarball will not have to be
4925downloaded again because it is already in the store. It is also a
4926convenient way to temporarily stash files, which may be deleted
4927eventually (@pxref{Invoking guix gc}).
4928
4929The @command{guix download} command supports the same URIs as used in
4930package definitions. In particular, it supports @code{mirror://} URIs.
4931@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
4932Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
4933they are not available, an error is raised. @xref{Guile Preparations,
4934how to install the GnuTLS bindings for Guile,, gnutls-guile,
4935GnuTLS-Guile}, for more information.
210cc920 4936
bc3c41ce
LC
4937@command{guix download} verifies HTTPS server certificates by loading
4938the certificates of X.509 authorities from the directory pointed to by
4939the @code{SSL_CERT_DIR} environment variable (@pxref{X.509
64b8695c 4940Certificates}), unless @option{--no-check-certificate} is used.
bc3c41ce 4941
64b8695c 4942The following options are available:
210cc920
LC
4943
4944@table @code
4945@item --format=@var{fmt}
4946@itemx -f @var{fmt}
4947Write the hash in the format specified by @var{fmt}. For more
081145cf 4948information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
64b8695c
LC
4949
4950@item --no-check-certificate
4951Do not validate the X.509 certificates of HTTPS servers.
4952
4953When using this option, you have @emph{absolutely no guarantee} that you
4954are communicating with the authentic server responsible for the given
4955URL, which makes you vulnerable to ``man-in-the-middle'' attacks.
4956
1bcc87bb
LC
4957@item --output=@var{file}
4958@itemx -o @var{file}
4959Save the downloaded file to @var{file} instead of adding it to the
4960store.
210cc920
LC
4961@end table
4962
6c365eca
NK
4963@node Invoking guix hash
4964@section Invoking @command{guix hash}
4965
e32171ee 4966@cindex @command{guix hash}
210cc920 4967The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
4968It is primarily a convenience tool for anyone contributing to the
4969distribution: it computes the cryptographic hash of a file, which can be
4970used in the definition of a package (@pxref{Defining Packages}).
4971
4972The general syntax is:
4973
4974@example
4975guix hash @var{option} @var{file}
4976@end example
4977
343dc117
LC
4978When @var{file} is @code{-} (a hyphen), @command{guix hash} computes the
4979hash of data read from standard input. @command{guix hash} has the
4980following options:
6c365eca
NK
4981
4982@table @code
4983
4984@item --format=@var{fmt}
4985@itemx -f @var{fmt}
210cc920 4986Write the hash in the format specified by @var{fmt}.
6c365eca
NK
4987
4988Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
4989(@code{hex} and @code{hexadecimal} can be used as well).
4990
4991If the @option{--format} option is not specified, @command{guix hash}
4992will output the hash in @code{nix-base32}. This representation is used
4993in the definitions of packages.
4994
3140f2df
LC
4995@item --recursive
4996@itemx -r
4997Compute the hash on @var{file} recursively.
4998
4999In this case, the hash is computed on an archive containing @var{file},
f97c9175
AE
5000including its children if it is a directory. Some of the metadata of
5001@var{file} is part of the archive; for instance, when @var{file} is a
3140f2df 5002regular file, the hash is different depending on whether @var{file} is
f97c9175 5003executable or not. Metadata such as time stamps has no impact on the
3140f2df
LC
5004hash (@pxref{Invoking guix archive}).
5005@c FIXME: Replace xref above with xref to an ``Archive'' section when
5006@c it exists.
5007
392a4e12
JN
5008@item --exclude-vcs
5009@itemx -x
5010When combined with @option{--recursive}, exclude version control system
5011directories (@file{.bzr}, @file{.git}, @file{.hg}, etc.)
5012
db97a03a
LC
5013@vindex git-fetch
5014As an example, here is how you would compute the hash of a Git checkout,
5015which is useful when using the @code{git-fetch} method (@pxref{origin
5016Reference}):
5017
5018@example
5019$ git clone http://example.org/foo.git
5020$ cd foo
392a4e12 5021$ guix hash -rx .
db97a03a 5022@end example
6c365eca
NK
5023@end table
5024
2f7d2d91
LC
5025@node Invoking guix import
5026@section Invoking @command{guix import}
5027
5028@cindex importing packages
5029@cindex package import
5030@cindex package conversion
e32171ee 5031@cindex Invoking @command{guix import}
f97c9175
AE
5032The @command{guix import} command is useful for people who would like to
5033add a package to the distribution with as little work as
5034possible---a legitimate demand. The command knows of a few
5035repositories from which it can ``import'' package metadata. The result
2f7d2d91
LC
5036is a package definition, or a template thereof, in the format we know
5037(@pxref{Defining Packages}).
5038
5039The general syntax is:
5040
5041@example
5042guix import @var{importer} @var{options}@dots{}
5043@end example
5044
5045@var{importer} specifies the source from which to import package
f97c9175 5046metadata, and @var{options} specifies a package identifier and other
2f7d2d91
LC
5047options specific to @var{importer}. Currently, the available
5048``importers'' are:
5049
5050@table @code
5051@item gnu
f97c9175 5052Import metadata for the given GNU package. This provides a template
2f7d2d91
LC
5053for the latest version of that GNU package, including the hash of its
5054source tarball, and its canonical synopsis and description.
5055
f97c9175 5056Additional information such as the package dependencies and its
2f7d2d91
LC
5057license needs to be figured out manually.
5058
5059For example, the following command returns a package definition for
5060GNU@tie{}Hello:
5061
5062@example
5063guix import gnu hello
5064@end example
5065
5066Specific command-line options are:
5067
5068@table @code
5069@item --key-download=@var{policy}
5070As for @code{guix refresh}, specify the policy to handle missing OpenPGP
f97c9175 5071keys when verifying the package signature. @xref{Invoking guix
2f7d2d91
LC
5072refresh, @code{--key-download}}.
5073@end table
5074
5075@item pypi
5076@cindex pypi
f97c9175 5077Import metadata from the @uref{https://pypi.python.org/, Python Package
2f7d2d91
LC
5078Index}@footnote{This functionality requires Guile-JSON to be installed.
5079@xref{Requirements}.}. Information is taken from the JSON-formatted
5080description available at @code{pypi.python.org} and usually includes all
266785d2
CR
5081the relevant information, including package dependencies. For maximum
5082efficiency, it is recommended to install the @command{unzip} utility, so
5083that the importer can unzip Python wheels and gather data from them.
2f7d2d91 5084
f97c9175 5085The command below imports metadata for the @code{itsdangerous} Python
2f7d2d91
LC
5086package:
5087
5088@example
5089guix import pypi itsdangerous
5090@end example
5091
3aae8145
DT
5092@item gem
5093@cindex gem
f97c9175 5094Import metadata from @uref{https://rubygems.org/,
3aae8145
DT
5095RubyGems}@footnote{This functionality requires Guile-JSON to be
5096installed. @xref{Requirements}.}. Information is taken from the
5097JSON-formatted description available at @code{rubygems.org} and includes
5098most relevant information, including runtime dependencies. There are
f97c9175 5099some caveats, however. The metadata doesn't distinguish between
3aae8145
DT
5100synopses and descriptions, so the same string is used for both fields.
5101Additionally, the details of non-Ruby dependencies required to build
5102native extensions is unavailable and left as an exercise to the
5103packager.
5104
f97c9175 5105The command below imports metadata for the @code{rails} Ruby package:
3aae8145
DT
5106
5107@example
5108guix import gem rails
5109@end example
5110
d45dc6da
EB
5111@item cpan
5112@cindex CPAN
3c192e4e
AE
5113Import metadata from @uref{https://www.metacpan.org/, MetaCPAN}@footnote{This
5114functionality requires Guile-JSON to be installed.
5115@xref{Requirements}.}.
f97c9175 5116Information is taken from the JSON-formatted metadata provided through
d45dc6da 5117@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
5118relevant information, such as module dependencies. License information
5119should be checked closely. If Perl is available in the store, then the
5120@code{corelist} utility will be used to filter core modules out of the
5121list of dependencies.
d45dc6da 5122
f97c9175 5123The command command below imports metadata for the @code{Acme::Boolean}
d45dc6da
EB
5124Perl module:
5125
5126@example
5127guix import cpan Acme::Boolean
5128@end example
5129
e1248602
RW
5130@item cran
5131@cindex CRAN
d0bd632f 5132@cindex Bioconductor
f97c9175 5133Import metadata from @uref{http://cran.r-project.org/, CRAN}, the
e1248602
RW
5134central repository for the @uref{http://r-project.org, GNU@tie{}R
5135statistical and graphical environment}.
5136
f97c9175 5137Information is extracted from the @code{DESCRIPTION} file of the package.
e1248602 5138
f97c9175 5139The command command below imports metadata for the @code{Cairo}
e1248602
RW
5140R package:
5141
5142@example
5143guix import cran Cairo
5144@end example
5145
64ce53eb
RW
5146When @code{--recursive} is added, the importer will traverse the
5147dependency graph of the given upstream package recursively and generate
5148package expressions for all those packages that are not yet in Guix.
5149
f97c9175 5150When @code{--archive=bioconductor} is added, metadata is imported from
d0bd632f
RW
5151@uref{http://www.bioconductor.org/, Bioconductor}, a repository of R
5152packages for for the analysis and comprehension of high-throughput
5153genomic data in bioinformatics.
5154
f97c9175 5155Information is extracted from the @code{DESCRIPTION} file of a package
d0bd632f
RW
5156published on the web interface of the Bioconductor SVN repository.
5157
f97c9175 5158The command below imports metadata for the @code{GenomicRanges}
d0bd632f
RW
5159R package:
5160
5161@example
5162guix import cran --archive=bioconductor GenomicRanges
5163@end example
5164
2f7d2d91 5165@item nix
f97c9175 5166Import metadata from a local copy of the source of the
2f7d2d91
LC
5167@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
5168relies on the @command{nix-instantiate} command of
5169@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
5170typically written in a mixture of Nix-language and Bash code. This
5171command only imports the high-level package structure that is written in
5172the Nix language. It normally includes all the basic fields of a
5173package definition.
5174
5175When importing a GNU package, the synopsis and descriptions are replaced
5176by their canonical upstream variant.
5177
961d0d2d
LC
5178Usually, you will first need to do:
5179
5180@example
5181export NIX_REMOTE=daemon
5182@end example
5183
5184@noindent
5185so that @command{nix-instantiate} does not try to open the Nix database.
5186
2f7d2d91
LC
5187As an example, the command below imports the package definition of
5188LibreOffice (more precisely, it imports the definition of the package
5189bound to the @code{libreoffice} top-level attribute):
5190
5191@example
5192guix import nix ~/path/to/nixpkgs libreoffice
5193@end example
863af4e1
FB
5194
5195@item hackage
5196@cindex hackage
f97c9175 5197Import metadata from the Haskell community's central package archive
863af4e1
FB
5198@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
5199Cabal files and includes all the relevant information, including package
5200dependencies.
5201
5202Specific command-line options are:
5203
5204@table @code
a4154748
FB
5205@item --stdin
5206@itemx -s
f97c9175 5207Read a Cabal file from standard input.
863af4e1
FB
5208@item --no-test-dependencies
5209@itemx -t
f97c9175 5210Do not include dependencies required only by the test suites.
a4154748
FB
5211@item --cabal-environment=@var{alist}
5212@itemx -e @var{alist}
5213@var{alist} is a Scheme alist defining the environment in which the
5214Cabal conditionals are evaluated. The accepted keys are: @code{os},
5215@code{arch}, @code{impl} and a string representing the name of a flag.
5216The value associated with a flag has to be either the symbol
5217@code{true} or @code{false}. The value associated with other keys
5218has to conform to the Cabal file format definition. The default value
5219associated with the keys @code{os}, @code{arch} and @code{impl} is
f97c9175 5220@samp{linux}, @samp{x86_64} and @samp{ghc}, respectively.
863af4e1
FB
5221@end table
5222
f97c9175 5223The command below imports metadata for the latest version of the
a4154748
FB
5224@code{HTTP} Haskell package without including test dependencies and
5225specifying the value of the flag @samp{network-uri} as @code{false}:
863af4e1
FB
5226
5227@example
a4154748 5228guix import hackage -t -e "'((\"network-uri\" . false))" HTTP
863af4e1
FB
5229@end example
5230
5231A specific package version may optionally be specified by following the
1b846da8 5232package name by an at-sign and a version number as in the following example:
863af4e1
FB
5233
5234@example
1b846da8 5235guix import hackage mtl@@2.1.3.1
863af4e1 5236@end example
7f74a931
FB
5237
5238@item elpa
5239@cindex elpa
f97c9175 5240Import metadata from an Emacs Lisp Package Archive (ELPA) package
7f74a931
FB
5241repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}).
5242
5243Specific command-line options are:
5244
5245@table @code
5246@item --archive=@var{repo}
5247@itemx -a @var{repo}
5248@var{repo} identifies the archive repository from which to retrieve the
5249information. Currently the supported repositories and their identifiers
5250are:
5251@itemize -
5252@item
840bd1d3 5253@uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu}
7f74a931
FB
5254identifier. This is the default.
5255
624144e0
LC
5256Packages from @code{elpa.gnu.org} are signed with one of the keys
5257contained in the GnuPG keyring at
5258@file{share/emacs/25.1/etc/package-keyring.gpg} (or similar) in the
5259@code{emacs} package (@pxref{Package Installation, ELPA package
5260signatures,, emacs, The GNU Emacs Manual}).
5261
7f74a931 5262@item
840bd1d3 5263@uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the
7f74a931
FB
5264@code{melpa-stable} identifier.
5265
5266@item
840bd1d3 5267@uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa}
7f74a931
FB
5268identifier.
5269@end itemize
5270@end table
3e0c0365
DC
5271
5272@item crate
5273@cindex crate
5274Import metadata from the crates.io Rust package repository
5275@uref{https://crates.io, crates.io}.
2f7d2d91
LC
5276@end table
5277
5278The structure of the @command{guix import} code is modular. It would be
5279useful to have more importers for other package formats, and your help
5280is welcome here (@pxref{Contributing}).
5281
37166310
LC
5282@node Invoking guix refresh
5283@section Invoking @command{guix refresh}
5284
e32171ee 5285@cindex @command {guix refresh}
37166310
LC
5286The primary audience of the @command{guix refresh} command is developers
5287of the GNU software distribution. By default, it reports any packages
5288provided by the distribution that are outdated compared to the latest
5289upstream version, like this:
5290
5291@example
5292$ guix refresh
5293gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
5294gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
5295@end example
5296
e9c72306
LC
5297Alternately, one can specify packages to consider, in which case a
5298warning is emitted for packages that lack an updater:
5299
5300@example
5301$ guix refresh coreutils guile guile-ssh
5302gnu/packages/ssh.scm:205:2: warning: no updater for guile-ssh
5303gnu/packages/guile.scm:136:12: guile would be upgraded from 2.0.12 to 2.0.13
5304@end example
5305
5306@command{guix refresh} browses the upstream repository of each package and determines
5307the highest version number of the releases therein. The command
bcb571cb 5308knows how to update specific types of packages: GNU packages, ELPA
e9c72306 5309packages, etc.---see the documentation for @option{--type} below. There
bcb571cb
LC
5310are many packages, though, for which it lacks a method to determine
5311whether a new upstream release is available. However, the mechanism is
5312extensible, so feel free to get in touch with us to add a new method!
37166310
LC
5313
5314When passed @code{--update}, it modifies distribution source files to
f97c9175 5315update the version numbers and source tarball hashes of those package
37166310
LC
5316recipes (@pxref{Defining Packages}). This is achieved by downloading
5317each package's latest source tarball and its associated OpenPGP
5318signature, authenticating the downloaded tarball against its signature
5319using @command{gpg}, and finally computing its hash. When the public
5320key used to sign the tarball is missing from the user's keyring, an
5321attempt is made to automatically retrieve it from a public key server;
f97c9175 5322when this is successful, the key is added to the user's keyring; otherwise,
37166310
LC
5323@command{guix refresh} reports an error.
5324
5325The following options are supported:
5326
5327@table @code
5328
2d7fc7da
LC
5329@item --expression=@var{expr}
5330@itemx -e @var{expr}
5331Consider the package @var{expr} evaluates to.
5332
5333This is useful to precisely refer to a package, as in this example:
5334
5335@example
5336guix refresh -l -e '(@@@@ (gnu packages commencement) glibc-final)'
5337@end example
5338
5339This command lists the dependents of the ``final'' libc (essentially all
5340the packages.)
5341
37166310
LC
5342@item --update
5343@itemx -u
38e16b49
LC
5344Update distribution source files (package recipes) in place. This is
5345usually run from a checkout of the Guix source tree (@pxref{Running
5346Guix Before It Is Installed}):
5347
5348@example
e9c72306 5349$ ./pre-inst-env guix refresh -s non-core -u
38e16b49
LC
5350@end example
5351
081145cf 5352@xref{Defining Packages}, for more information on package definitions.
37166310
LC
5353
5354@item --select=[@var{subset}]
5355@itemx -s @var{subset}
5356Select all the packages in @var{subset}, one of @code{core} or
5357@code{non-core}.
5358
5359The @code{core} subset refers to all the packages at the core of the
5360distribution---i.e., packages that are used to build ``everything
5361else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
5362changing one of these packages in the distribution entails a rebuild of
5363all the others. Thus, such updates are an inconvenience to users in
5364terms of build time or bandwidth used to achieve the upgrade.
5365
5366The @code{non-core} subset refers to the remaining packages. It is
5367typically useful in cases where an update of the core packages would be
5368inconvenient.
5369
bcb571cb
LC
5370@item --type=@var{updater}
5371@itemx -t @var{updater}
7191adc5
AK
5372Select only packages handled by @var{updater} (may be a comma-separated
5373list of updaters). Currently, @var{updater} may be one of:
bcb571cb
LC
5374
5375@table @code
5376@item gnu
5377the updater for GNU packages;
e80c0f85
LC
5378@item gnome
5379the updater for GNOME packages;
9c97afe8
DC
5380@item kde
5381the updater for KDE packages;
62061d6b
AW
5382@item xorg
5383the updater for X.org packages;
2fd370e8
LC
5384@item kernel.org
5385the updater for packages hosted on kernel.org;
bcb571cb 5386@item elpa
d882c235
LC
5387the updater for @uref{http://elpa.gnu.org/, ELPA} packages;
5388@item cran
b9d044ef 5389the updater for @uref{http://cran.r-project.org/, CRAN} packages;
d0bd632f
RW
5390@item bioconductor
5391the updater for @uref{http://www.bioconductor.org/, Bioconductor} R packages;
200cdf81
EB
5392@item cpan
5393the updater for @uref{http://www.cpan.org/, CPAN} packages;
bab020d7 5394@item pypi
b9d044ef 5395the updater for @uref{https://pypi.python.org, PyPI} packages.
fbc5b815
BW
5396@item gem
5397the updater for @uref{https://rubygems.org, RubyGems} packages.
917a2a58
BW
5398@item github
5399the updater for @uref{https://github.com, GitHub} packages.
42efe27a
EB
5400@item hackage
5401the updater for @uref{https://hackage.haskell.org, Hackage} packages.
8ac52987
DC
5402@item crate
5403the updater for @uref{https://crates.io, Crates} packages.
bcb571cb
LC
5404@end table
5405
f97c9175
AE
5406For instance, the following command only checks for updates of Emacs
5407packages hosted at @code{elpa.gnu.org} and for updates of CRAN packages:
bcb571cb
LC
5408
5409@example
7191adc5 5410$ guix refresh --type=elpa,cran
d882c235 5411gnu/packages/statistics.scm:819:13: r-testthat would be upgraded from 0.10.0 to 0.11.0
bcb571cb
LC
5412gnu/packages/emacs.scm:856:13: emacs-auctex would be upgraded from 11.88.6 to 11.88.9
5413@end example
5414
37166310
LC
5415@end table
5416
5417In addition, @command{guix refresh} can be passed one or more package
5418names, as in this example:
5419
5420@example
e9c72306 5421$ ./pre-inst-env guix refresh -u emacs idutils gcc@@4.8
37166310
LC
5422@end example
5423
5424@noindent
5425The command above specifically updates the @code{emacs} and
5426@code{idutils} packages. The @code{--select} option would have no
5427effect in this case.
5428
7d193ec3
EB
5429When considering whether to upgrade a package, it is sometimes
5430convenient to know which packages would be affected by the upgrade and
5431should be checked for compatibility. For this the following option may
5432be used when passing @command{guix refresh} one or more package names:
5433
5434@table @code
5435
6ffa706b
AK
5436@item --list-updaters
5437@itemx -L
5438List available updaters and exit (see @option{--type} above.)
5439
3676f892
LC
5440For each updater, display the fraction of packages it covers; at the
5441end, display the fraction of packages covered by all these updaters.
5442
7d193ec3
EB
5443@item --list-dependent
5444@itemx -l
5445List top-level dependent packages that would need to be rebuilt as a
5446result of upgrading one or more packages.
5447
5448@end table
5449
5450Be aware that the @code{--list-dependent} option only
5451@emph{approximates} the rebuilds that would be required as a result of
5452an upgrade. More rebuilds might be required under some circumstances.
5453
5454@example
7779ab61
LC
5455$ guix refresh --list-dependent flex
5456Building the following 120 packages would ensure 213 dependent packages are rebuilt:
5457hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
5458@end example
5459
5460The command above lists a set of packages that could be built to check
5461for compatibility with an upgraded @code{flex} package.
5462
f9230085
LC
5463The following options can be used to customize GnuPG operation:
5464
5465@table @code
5466
f9230085
LC
5467@item --gpg=@var{command}
5468Use @var{command} as the GnuPG 2.x command. @var{command} is searched
5469for in @code{$PATH}.
5470
2bc53ba9
LC
5471@item --key-download=@var{policy}
5472Handle missing OpenPGP keys according to @var{policy}, which may be one
5473of:
5474
5475@table @code
5476@item always
5477Always download missing OpenPGP keys from the key server, and add them
5478to the user's GnuPG keyring.
5479
5480@item never
5481Never try to download missing OpenPGP keys. Instead just bail out.
5482
5483@item interactive
5484When a package signed with an unknown OpenPGP key is encountered, ask
5485the user whether to download it or not. This is the default behavior.
5486@end table
5487
5488@item --key-server=@var{host}
5489Use @var{host} as the OpenPGP key server when importing a public key.
5490
f9230085
LC
5491@end table
5492
917a2a58
BW
5493The @code{github} updater uses the
5494@uref{https://developer.github.com/v3/, GitHub API} to query for new
5495releases. When used repeatedly e.g. when refreshing all packages,
5496GitHub will eventually refuse to answer any further API requests. By
5497default 60 API requests per hour are allowed, and a full refresh on all
5498GitHub packages in Guix requires more than this. Authentication with
5499GitHub through the use of an API token alleviates these limits. To use
5500an API token, set the environment variable @code{GUIX_GITHUB_TOKEN} to a
5501token procured from @uref{https://github.com/settings/tokens} or
5502otherwise.
5503
5504
b4f5e0e8
CR
5505@node Invoking guix lint
5506@section Invoking @command{guix lint}
e32171ee
JD
5507
5508@cindex @command{guix lint}
5509@cindex package, checking for errors
f97c9175
AE
5510The @command{guix lint} command is meant to help package developers avoid
5511common errors and use a consistent style. It runs a number of checks on
5512a given set of packages in order to find common mistakes in their
873c4085
LC
5513definitions. Available @dfn{checkers} include (see
5514@code{--list-checkers} for a complete list):
5515
5516@table @code
5517@item synopsis
5518@itemx description
5519Validate certain typographical and stylistic rules about package
5520descriptions and synopses.
5521
5522@item inputs-should-be-native
5523Identify inputs that should most likely be native inputs.
5524
5525@item source
5526@itemx home-page
fac46e3f 5527@itemx mirror-url
50f5c46d 5528@itemx source-file-name
873c4085 5529Probe @code{home-page} and @code{source} URLs and report those that are
fac46e3f
LC
5530invalid. Suggest a @code{mirror://} URL when applicable. Check that
5531the source file name is meaningful, e.g. is not
f97c9175
AE
5532just a version number or ``git-checkout'', without a declared
5533@code{file-name} (@pxref{origin Reference}).
40a7d4e5 5534
5432734b 5535@item cve
09866b39
LC
5536@cindex security vulnerabilities
5537@cindex CVE, Common Vulnerabilities and Exposures
5432734b 5538Report known vulnerabilities found in the Common Vulnerabilities and
09866b39 5539Exposures (CVE) databases of the current and past year
5432734b
LC
5540@uref{https://nvd.nist.gov/download.cfm#CVE_FEED, published by the US
5541NIST}.
5542
09866b39
LC
5543To view information about a particular vulnerability, visit pages such as:
5544
5545@itemize
5546@item
5547@indicateurl{https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-YYYY-ABCD}
5548@item
5549@indicateurl{https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-YYYY-ABCD}
5550@end itemize
5551
5552@noindent
5553where @code{CVE-YYYY-ABCD} is the CVE identifier---e.g.,
5554@code{CVE-2015-7554}.
5555
99effc8f
LC
5556Package developers can specify in package recipes the
5557@uref{https://nvd.nist.gov/cpe.cfm,Common Platform Enumeration (CPE)}
5558name and version of the package when they differ from the name that Guix
5559uses, as in this example:
5560
5561@example
5562(package
5563 (name "grub")
5564 ;; @dots{}
5565 ;; CPE calls this package "grub2".
5566 (properties '((cpe-name . "grub2"))))
5567@end example
5568
40a7d4e5
LC
5569@item formatting
5570Warn about obvious source code formatting issues: trailing white space,
5571use of tabulations, etc.
873c4085 5572@end table
b4f5e0e8
CR
5573
5574The general syntax is:
5575
5576@example
5577guix lint @var{options} @var{package}@dots{}
5578@end example
5579
5580If no package is given on the command line, then all packages are checked.
5581The @var{options} may be zero or more of the following:
5582
5583@table @code
f97c9175
AE
5584@item --list-checkers
5585@itemx -l
5586List and describe all the available checkers that will be run on packages
5587and exit.
b4f5e0e8 5588
dd7c013d
CR
5589@item --checkers
5590@itemx -c
5591Only enable the checkers specified in a comma-separated list using the
5592names returned by @code{--list-checkers}.
5593
b4f5e0e8 5594@end table
37166310 5595
fcc58db6
LC
5596@node Invoking guix size
5597@section Invoking @command{guix size}
5598
e32171ee
JD
5599@cindex size
5600@cindex package size
5601@cindex closure
5602@cindex @command{guix size}
fcc58db6
LC
5603The @command{guix size} command helps package developers profile the
5604disk usage of packages. It is easy to overlook the impact of an
5605additional dependency added to a package, or the impact of using a
5606single output for a package that could easily be split (@pxref{Packages
f97c9175 5607with Multiple Outputs}). Such are the typical issues that
fcc58db6
LC
5608@command{guix size} can highlight.
5609
5610The command can be passed a package specification such as @code{gcc-4.8}
5611or @code{guile:debug}, or a file name in the store. Consider this
5612example:
5613
5614@example
5615$ guix size coreutils
5616store item total self
5617/gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8%
5618/gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6%
5619/gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7%
5620/gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5%
5621/gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4%
5622/gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1%
5623@end example
5624
5625@cindex closure
5626The store items listed here constitute the @dfn{transitive closure} of
5627Coreutils---i.e., Coreutils and all its dependencies, recursively---as
5628would be returned by:
5629
5630@example
5631$ guix gc -R /gnu/store/@dots{}-coreutils-8.23
5632@end example
5633
f97c9175 5634Here the output shows three columns next to store items. The first column,
fcc58db6
LC
5635labeled ``total'', shows the size in mebibytes (MiB) of the closure of
5636the store item---that is, its own size plus the size of all its
5637dependencies. The next column, labeled ``self'', shows the size of the
f97c9175
AE
5638item itself. The last column shows the ratio of the size of the item
5639itself to the space occupied by all the items listed here.
fcc58db6
LC
5640
5641In this example, we see that the closure of Coreutils weighs in at
564270@tie{}MiB, half of which is taken by libc. (That libc represents a
5643large fraction of the closure is not a problem @i{per se} because it is
5644always available on the system anyway.)
5645
5646When the package passed to @command{guix size} is available in the
5647store, @command{guix size} queries the daemon to determine its
5648dependencies, and measures its size in the store, similar to @command{du
5649-ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU
5650Coreutils}).
5651
5652When the given package is @emph{not} in the store, @command{guix size}
f97c9175
AE
5653reports information based on the available substitutes
5654(@pxref{Substitutes}). This makes it possible it to profile disk usage of
5655store items that are not even on disk, only available remotely.
fcc58db6 5656
db761534
LC
5657You can also specify several package names:
5658
5659@example
5660$ guix size coreutils grep sed bash
5661store item total self
5662/gnu/store/@dots{}-coreutils-8.24 77.8 13.8 13.4%
5663/gnu/store/@dots{}-grep-2.22 73.1 0.8 0.8%
5664/gnu/store/@dots{}-bash-4.3.42 72.3 4.7 4.6%
5665/gnu/store/@dots{}-readline-6.3 67.6 1.2 1.2%
5666@dots{}
5667total: 102.3 MiB
5668@end example
5669
5670@noindent
5671In this example we see that the combination of the four packages takes
5672102.3@tie{}MiB in total, which is much less than the sum of each closure
5673since they have a lot of dependencies in common.
5674
a8f996c6 5675The available options are:
fcc58db6
LC
5676
5677@table @option
5678
d490d06e
LC
5679@item --substitute-urls=@var{urls}
5680Use substitute information from @var{urls}.
5681@xref{client-substitute-urls, the same option for @code{guix build}}.
5682
a8f996c6 5683@item --map-file=@var{file}
f97c9175 5684Write a graphical map of disk usage in PNG format to @var{file}.
a8f996c6
LC
5685
5686For the example above, the map looks like this:
5687
5688@image{images/coreutils-size-map,5in,, map of Coreutils disk usage
5689produced by @command{guix size}}
5690
5691This option requires that
5692@uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be
5693installed and visible in Guile's module search path. When that is not
5694the case, @command{guix size} fails as it tries to load it.
5695
fcc58db6
LC
5696@item --system=@var{system}
5697@itemx -s @var{system}
5698Consider packages for @var{system}---e.g., @code{x86_64-linux}.
5699
5700@end table
5701
88856916
LC
5702@node Invoking guix graph
5703@section Invoking @command{guix graph}
5704
5705@cindex DAG
e32171ee
JD
5706@cindex @command{guix graph}
5707@cindex package dependencies
88856916
LC
5708Packages and their dependencies form a @dfn{graph}, specifically a
5709directed acyclic graph (DAG). It can quickly become difficult to have a
f97c9175 5710mental model of the package DAG, so the @command{guix graph} command
9ea36197
LC
5711provides a visual representation of the DAG. By default,
5712@command{guix graph} emits a DAG representation in the input format of
88856916 5713@uref{http://www.graphviz.org/, Graphviz}, so its output can be passed
9ea36197
LC
5714directly to the @command{dot} command of Graphviz. It can also emit an
5715HTML page with embedded JavaScript code to display a ``chord diagram''
5716in a Web browser, using the @uref{https://d3js.org/, d3.js} library.
5717The general syntax is:
88856916
LC
5718
5719@example
5720guix graph @var{options} @var{package}@dots{}
5721@end example
5722
5723For example, the following command generates a PDF file representing the
5724package DAG for the GNU@tie{}Core Utilities, showing its build-time
5725dependencies:
5726
5727@example
5728guix graph coreutils | dot -Tpdf > dag.pdf
5729@end example
5730
5731The output looks like this:
5732
5733@image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils}
5734
5735Nice little graph, no?
5736
f97c9175 5737But there is more than one graph! The one above is concise: it is the
88856916 5738graph of package objects, omitting implicit inputs such as GCC, libc,
f97c9175
AE
5739grep, etc. It is often useful to have such a concise graph, but
5740sometimes one may want to see more details. @command{guix graph} supports
5741several types of graphs, allowing you to choose the level of detail:
88856916
LC
5742
5743@table @code
5744@item package
f97c9175 5745This is the default type used in the example above. It shows the DAG of
88856916
LC
5746package objects, excluding implicit dependencies. It is concise, but
5747filters out many details.
5748
5749@item bag-emerged
5750This is the package DAG, @emph{including} implicit inputs.
5751
5752For instance, the following command:
5753
5754@example
5755guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf
5756@end example
5757
5758... yields this bigger graph:
5759
5760@image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils}
5761
5762At the bottom of the graph, we see all the implicit inputs of
5763@var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}).
5764
f97c9175 5765Now, note that the dependencies of these implicit inputs---that is, the
88856916
LC
5766@dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown
5767here, for conciseness.
5768
5769@item bag
5770Similar to @code{bag-emerged}, but this time including all the bootstrap
5771dependencies.
5772
38b92daa
LC
5773@item bag-with-origins
5774Similar to @code{bag}, but also showing origins and their dependencies.
5775
88856916
LC
5776@item derivations
5777This is the most detailed representation: It shows the DAG of
5778derivations (@pxref{Derivations}) and plain store items. Compared to
5779the above representation, many additional nodes are visible, including
f97c9175 5780build scripts, patches, Guile modules, etc.
88856916 5781
a773c314
LC
5782For this type of graph, it is also possible to pass a @file{.drv} file
5783name instead of a package name, as in:
5784
5785@example
5786guix graph -t derivation `guix system build -d my-config.scm`
5787@end example
88856916
LC
5788@end table
5789
f97c9175 5790All the types above correspond to @emph{build-time dependencies}. The
88856916
LC
5791following graph type represents the @emph{run-time dependencies}:
5792
5793@table @code
5794@item references
5795This is the graph of @dfn{references} of a package output, as returned
5796by @command{guix gc --references} (@pxref{Invoking guix gc}).
5797
5798If the given package output is not available in the store, @command{guix
5799graph} attempts to obtain dependency information from substitutes.
a773c314
LC
5800
5801Here you can also pass a store file name instead of a package name. For
5802example, the command below produces the reference graph of your profile
5803(which can be big!):
5804
5805@example
5806guix graph -t references `readlink -f ~/.guix-profile`
5807@end example
7f8fec0f
LC
5808
5809@item referrers
5810This is the graph of the @dfn{referrers} of a store item, as returned by
5811@command{guix gc --referrers} (@pxref{Invoking guix gc}).
5812
5813This relies exclusively on local information from your store. For
5814instance, let us suppose that the current Inkscape is available in 10
5815profiles on your machine; @command{guix graph -t referrers inkscape}
5816will show a graph rooted at Inkscape and with those 10 profiles linked
5817to it.
5818
5819It can help determine what is preventing a store item from being garbage
5820collected.
5821
88856916
LC
5822@end table
5823
5824The available options are the following:
5825
5826@table @option
5827@item --type=@var{type}
5828@itemx -t @var{type}
5829Produce a graph output of @var{type}, where @var{type} must be one of
5830the values listed above.
5831
5832@item --list-types
5833List the supported graph types.
4c8f997a 5834
642339dc
RW
5835@item --backend=@var{backend}
5836@itemx -b @var{backend}
5837Produce a graph using the selected @var{backend}.
5838
5839@item --list-backends
5840List the supported graph backends.
5841
9ea36197
LC
5842Currently, the available backends are Graphviz and d3.js.
5843
4c8f997a
LC
5844@item --expression=@var{expr}
5845@itemx -e @var{expr}
5846Consider the package @var{expr} evaluates to.
5847
5848This is useful to precisely refer to a package, as in this example:
5849
5850@example
5851guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
5852@end example
88856916
LC
5853@end table
5854
5855
372c4bbc
DT
5856@node Invoking guix environment
5857@section Invoking @command{guix environment}
5858
f5fd4fd2 5859@cindex reproducible build environments
fe36d84e 5860@cindex development environments
e32171ee
JD
5861@cindex @command{guix environment}
5862@cindex environment, package build environment
372c4bbc
DT
5863The purpose of @command{guix environment} is to assist hackers in
5864creating reproducible development environments without polluting their
5865package profile. The @command{guix environment} tool takes one or more
f97c9175 5866packages, builds all of their inputs, and creates a shell
372c4bbc
DT
5867environment to use them.
5868
5869The general syntax is:
5870
5871@example
5872guix environment @var{options} @var{package}@dots{}
5873@end example
5874
fe36d84e
LC
5875The following example spawns a new shell set up for the development of
5876GNU@tie{}Guile:
372c4bbc
DT
5877
5878@example
5879guix environment guile
5880@end example
5881
f97c9175
AE
5882If the needed dependencies are not built yet, @command{guix environment}
5883automatically builds them. The environment of the new shell is an augmented
372c4bbc
DT
5884version of the environment that @command{guix environment} was run in.
5885It contains the necessary search paths for building the given package
5886added to the existing environment variables. To create a ``pure''
f97c9175 5887environment, in which the original environment variables have been unset,
50500f7c
LC
5888use the @code{--pure} option@footnote{Users sometimes wrongfully augment
5889environment variables such as @code{PATH} in their @file{~/.bashrc}
5890file. As a consequence, when @code{guix environment} launches it, Bash
5891may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
5892environment variables. It is an error to define such environment
5893variables in @file{.bashrc}; instead, they should be defined in
5894@file{.bash_profile}, which is sourced only by log-in shells.
5895@xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
5896details on Bash start-up files.}.
372c4bbc 5897
28de8d25
LC
5898@vindex GUIX_ENVIRONMENT
5899@command{guix environment} defines the @code{GUIX_ENVIRONMENT}
20185522
LC
5900variable in the shell it spawns; its value is the file name of the
5901profile of this environment. This allows users to, say, define a
28de8d25
LC
5902specific prompt for development environments in their @file{.bashrc}
5903(@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
5904
5905@example
5906if [ -n "$GUIX_ENVIRONMENT" ]
5907then
5908 export PS1="\u@@\h \w [dev]\$ "
5909fi
5910@end example
5911
20185522
LC
5912@noindent
5913... or to browse the profile:
5914
5915@example
5916$ ls "$GUIX_ENVIRONMENT/bin"
5917@end example
5918
372c4bbc
DT
5919Additionally, more than one package may be specified, in which case the
5920union of the inputs for the given packages are used. For example, the
5921command below spawns a shell where all of the dependencies of both Guile
5922and Emacs are available:
5923
5924@example
5925guix environment guile emacs
5926@end example
5927
1de2fe95
DT
5928Sometimes an interactive shell session is not desired. An arbitrary
5929command may be invoked by placing the @code{--} token to separate the
5930command from the rest of the arguments:
372c4bbc
DT
5931
5932@example
1de2fe95 5933guix environment guile -- make -j4
372c4bbc
DT
5934@end example
5935
fe36d84e
LC
5936In other situations, it is more convenient to specify the list of
5937packages needed in the environment. For example, the following command
5938runs @command{python} from an environment containing Python@tie{}2.7 and
5939NumPy:
5940
5941@example
1de2fe95 5942guix environment --ad-hoc python2-numpy python-2.7 -- python
fe36d84e
LC
5943@end example
5944
cc90fbbf
DT
5945Furthermore, one might want the dependencies of a package and also some
5946additional packages that are not build-time or runtime dependencies, but
5947are useful when developing nonetheless. Because of this, the
5948@code{--ad-hoc} flag is positional. Packages appearing before
5949@code{--ad-hoc} are interpreted as packages whose dependencies will be
5950added to the environment. Packages appearing after are interpreted as
5951packages that will be added to the environment directly. For example,
5952the following command creates a Guix development environment that
5953additionally includes Git and strace:
5954
5955@example
5956guix environment guix --ad-hoc git strace
5957@end example
5958
f535dcbe
DT
5959Sometimes it is desirable to isolate the environment as much as
5960possible, for maximal purity and reproducibility. In particular, when
5961using Guix on a host distro that is not GuixSD, it is desirable to
5962prevent access to @file{/usr/bin} and other system-wide resources from
5963the development environment. For example, the following command spawns
5964a Guile REPL in a ``container'' where only the store and the current
5965working directory are mounted:
5966
5967@example
5968guix environment --ad-hoc --container guile -- guile
5969@end example
5970
0f252e26 5971@quotation Note
cfd35b4e 5972The @code{--container} option requires Linux-libre 3.19 or newer.
0f252e26
DT
5973@end quotation
5974
fe36d84e 5975The available options are summarized below.
372c4bbc
DT
5976
5977@table @code
f943c317
LC
5978@item --root=@var{file}
5979@itemx -r @var{file}
5980@cindex persistent environment
5981@cindex garbage collector root, for environments
5982Make @var{file} a symlink to the profile for this environment, and
5983register it as a garbage collector root.
5984
5985This is useful if you want to protect your environment from garbage
5986collection, to make it ``persistent''.
5987
5988When this option is omitted, the environment is protected from garbage
5989collection only for the duration of the @command{guix environment}
5990session. This means that next time you recreate the same environment,
5991you could have to rebuild or re-download packages.
5992
372c4bbc
DT
5993@item --expression=@var{expr}
5994@itemx -e @var{expr}
c9c282ce
DT
5995Create an environment for the package or list of packages that
5996@var{expr} evaluates to.
372c4bbc 5997
fe36d84e
LC
5998For example, running:
5999
6000@example
6001guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
6002@end example
6003
6004starts a shell with the environment for this specific variant of the
6005PETSc package.
6006
c9c282ce
DT
6007Running:
6008
6009@example
5c2b2f00 6010guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
c9c282ce
DT
6011@end example
6012
6013starts a shell with all the GuixSD base packages available.
6014
779aa003
DT
6015The above commands only the use default output of the given packages.
6016To select other outputs, two element tuples can be specified:
6017
6018@example
6019guix environment --ad-hoc -e '(list (@ (gnu packages bash) bash) "include")'
6020@end example
6021
372c4bbc
DT
6022@item --load=@var{file}
6023@itemx -l @var{file}
c9c282ce
DT
6024Create an environment for the package or list of packages that the code
6025within @var{file} evaluates to.
372c4bbc 6026
fe36d84e
LC
6027As an example, @var{file} might contain a definition like this
6028(@pxref{Defining Packages}):
6029
6030@example
6031@verbatiminclude environment-gdb.scm
6032@end example
6033
a54bd6d7
DT
6034@item --ad-hoc
6035Include all specified packages in the resulting environment, as if an
6036@i{ad hoc} package were defined with them as inputs. This option is
6037useful for quickly creating an environment without having to write a
6038package expression to contain the desired inputs.
6039
6040For instance, the command:
6041
6042@example
1de2fe95 6043guix environment --ad-hoc guile guile-sdl -- guile
a54bd6d7
DT
6044@end example
6045
6046runs @command{guile} in an environment where Guile and Guile-SDL are
6047available.
6048
417c39f1 6049Note that this example implicitly asks for the default output of
f97c9175 6050@code{guile} and @code{guile-sdl}, but it is possible to ask for a
417c39f1
LC
6051specific output---e.g., @code{glib:bin} asks for the @code{bin} output
6052of @code{glib} (@pxref{Packages with Multiple Outputs}).
6053
cc90fbbf
DT
6054This option may be composed with the default behavior of @command{guix
6055environment}. Packages appearing before @code{--ad-hoc} are interpreted
6056as packages whose dependencies will be added to the environment, the
6057default behavior. Packages appearing after are interpreted as packages
6058that will be added to the environment directly.
6059
372c4bbc
DT
6060@item --pure
6061Unset existing environment variables when building the new environment.
6062This has the effect of creating an environment in which search paths
6063only contain package inputs.
6064
6065@item --search-paths
6066Display the environment variable definitions that make up the
6067environment.
ce367ef3
LC
6068
6069@item --system=@var{system}
6070@itemx -s @var{system}
6071Attempt to build for @var{system}---e.g., @code{i686-linux}.
f535dcbe
DT
6072
6073@item --container
6074@itemx -C
6075@cindex container
6076Run @var{command} within an isolated container. The current working
a01ad638
DT
6077directory outside the container is mapped inside the container.
6078Additionally, a dummy home directory is created that matches the current
6079user's home directory, and @file{/etc/passwd} is configured accordingly.
6080The spawned process runs as the current user outside the container, but
6081has root privileges in the context of the container.
f535dcbe
DT
6082
6083@item --network
6084@itemx -N
6085For containers, share the network namespace with the host system.
6086Containers created without this flag only have access to the loopback
6087device.
6088
6089@item --expose=@var{source}[=@var{target}]
6090For containers, expose the file system @var{source} from the host system
6091as the read-only file system @var{target} within the container. If
6092@var{target} is not specified, @var{source} is used as the target mount
6093point in the container.
6094
6095The example below spawns a Guile REPL in a container in which the user's
6096home directory is accessible read-only via the @file{/exchange}
6097directory:
6098
6099@example
6100guix environment --container --expose=$HOME=/exchange guile -- guile
6101@end example
6102
5c2b2f00 6103@item --share=@var{source}[=@var{target}]
f535dcbe
DT
6104For containers, share the file system @var{source} from the host system
6105as the writable file system @var{target} within the container. If
6106@var{target} is not specified, @var{source} is used as the target mount
6107point in the container.
6108
6109The example below spawns a Guile REPL in a container in which the user's
6110home directory is accessible for both reading and writing via the
6111@file{/exchange} directory:
6112
6113@example
6114guix environment --container --share=$HOME=/exchange guile -- guile
6115@end example
372c4bbc
DT
6116@end table
6117
6118It also supports all of the common build options that @command{guix
ccd7158d 6119build} supports (@pxref{Common Build Options}).
372c4bbc 6120
aff8ce7c
DT
6121@node Invoking guix publish
6122@section Invoking @command{guix publish}
6123
e32171ee 6124@cindex @command{guix publish}
aff8ce7c 6125The purpose of @command{guix publish} is to enable users to easily share
f97c9175 6126their store with others, who can then use it as a substitute server
8ce229fc
LC
6127(@pxref{Substitutes}).
6128
6129When @command{guix publish} runs, it spawns an HTTP server which allows
6130anyone with network access to obtain substitutes from it. This means
6131that any machine running Guix can also act as if it were a build farm,
6132since the HTTP interface is compatible with Hydra, the software behind
6133the @code{hydra.gnu.org} build farm.
aff8ce7c
DT
6134
6135For security, each substitute is signed, allowing recipients to check
6136their authenticity and integrity (@pxref{Substitutes}). Because
f97c9175 6137@command{guix publish} uses the signing key of the system, which is only
5463fe51
LC
6138readable by the system administrator, it must be started as root; the
6139@code{--user} option makes it drop root privileges early on.
aff8ce7c 6140
b18812b6
LC
6141The signing key pair must be generated before @command{guix publish} is
6142launched, using @command{guix archive --generate-key} (@pxref{Invoking
6143guix archive}).
6144
aff8ce7c
DT
6145The general syntax is:
6146
6147@example
6148guix publish @var{options}@dots{}
6149@end example
6150
6151Running @command{guix publish} without any additional arguments will
6152spawn an HTTP server on port 8080:
6153
6154@example
6155guix publish
6156@end example
6157
6158Once a publishing server has been authorized (@pxref{Invoking guix
6159archive}), the daemon may download substitutes from it:
6160
6161@example
6162guix-daemon --substitute-urls=http://example.org:8080
6163@end example
6164
ff6638d1
LC
6165As a bonus, @command{guix publish} also serves as a content-addressed
6166mirror for source files referenced in @code{origin} records
6167(@pxref{origin Reference}). For instance, assuming @command{guix
6168publish} is running on @code{example.org}, the following URL returns the
6169raw @file{hello-2.10.tar.gz} file with the given SHA256 hash
6170(represented in @code{nix-base32} format, @pxref{Invoking guix hash}):
6171
6172@example
6173http://example.org/file/hello-2.10.tar.gz/sha256/0ssi1@dots{}ndq1i
6174@end example
6175
6176Obviously, these URLs only work for files that are in the store; in
6177other cases, they return 404 (``Not Found'').
6178
aff8ce7c
DT
6179The following options are available:
6180
6181@table @code
6182@item --port=@var{port}
6183@itemx -p @var{port}
6184Listen for HTTP requests on @var{port}.
6185
9e2292ef
LC
6186@item --listen=@var{host}
6187Listen on the network interface for @var{host}. The default is to
6188accept connections from any interface.
6189
5463fe51
LC
6190@item --user=@var{user}
6191@itemx -u @var{user}
6192Change privileges to @var{user} as soon as possible---i.e., once the
6193server socket is open and the signing key has been read.
6194
4a1fc562
LC
6195@item --compression[=@var{level}]
6196@itemx -C [@var{level}]
6197Compress data using the given @var{level}. When @var{level} is zero,
6198disable compression. The range 1 to 9 corresponds to different gzip
6199compression levels: 1 is the fastest, and 9 is the best (CPU-intensive).
6200The default is 3.
6201
4591c02e 6202Compression occurs on the fly and the compressed streams are not
4a1fc562
LC
6203cached. Thus, to reduce load on the machine that runs @command{guix
6204publish}, it may be a good idea to choose a low compression level, or to
6205run @command{guix publish} behind a caching proxy.
6206
e4c7a5f7
LC
6207@item --ttl=@var{ttl}
6208Produce @code{Cache-Control} HTTP headers that advertise a time-to-live
6209(TTL) of @var{ttl}. @var{ttl} must denote a duration: @code{5d} means 5
6210days, @code{1m} means 1 month, and so on.
6211
6212This allows the user's Guix to keep substitute information in cache for
6213@var{ttl}. However, note that @code{guix publish} does not itself
6214guarantee that the store items it provides will indeed remain available
6215for as long as @var{ttl}.
6216
aff8ce7c
DT
6217@item --repl[=@var{port}]
6218@itemx -r [@var{port}]
6219Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
8ce229fc
LC
6220Reference Manual}) on @var{port} (37146 by default). This is used
6221primarily for debugging a running @command{guix publish} server.
aff8ce7c
DT
6222@end table
6223
1c52181f
LC
6224Enabling @command{guix publish} on a GuixSD system is a one-liner: just
6225add a call to @code{guix-publish-service} in the @code{services} field
6226of the @code{operating-system} declaration (@pxref{guix-publish-service,
6227@code{guix-publish-service}}).
6228
332d7903
HG
6229If you are instead running Guix on a ``foreign distro'', follow these
6230instructions:”
6231
6232@itemize
6233@item
6234If your host distro uses the systemd init system:
6235
6236@example
6237# ln -s ~root/.guix-profile/lib/systemd/system/guix-publish.service \
6238 /etc/systemd/system/
6239# systemctl start guix-publish && systemctl enable guix-publish
6240@end example
6241
6242@item
6243If your host distro uses the Upstart init system:
6244
6245@example
6246# ln -s ~root/.guix-profile/lib/upstart/system/guix-publish.conf /etc/init/
6247# start guix-publish
6248@end example
6249
6250@item
6251Otherwise, proceed similarly with your distro's init system.
6252@end itemize
d23c20f1
LC
6253
6254@node Invoking guix challenge
6255@section Invoking @command{guix challenge}
6256
6257@cindex reproducible builds
6258@cindex verifiable builds
e32171ee
JD
6259@cindex @command{guix challenge}
6260@cindex challenge
d23c20f1 6261Do the binaries provided by this server really correspond to the source
f97c9175 6262code it claims to build? Is a package build process deterministic?
d23c20f1
LC
6263These are the questions the @command{guix challenge} command attempts to
6264answer.
6265
6266The former is obviously an important question: Before using a substitute
f97c9175 6267server (@pxref{Substitutes}), one had better @emph{verify} that it
d23c20f1
LC
6268provides the right binaries, and thus @emph{challenge} it. The latter
6269is what enables the former: If package builds are deterministic, then
6270independent builds of the package should yield the exact same result,
6271bit for bit; if a server provides a binary different from the one
6272obtained locally, it may be either corrupt or malicious.
6273
6274We know that the hash that shows up in @file{/gnu/store} file names is
6275the hash of all the inputs of the process that built the file or
6276directory---compilers, libraries, build scripts,
6277etc. (@pxref{Introduction}). Assuming deterministic build processes,
6278one store file name should map to exactly one build output.
6279@command{guix challenge} checks whether there is, indeed, a single
6280mapping by comparing the build outputs of several independent builds of
6281any given store item.
6282
f97c9175 6283The command output looks like this:
d23c20f1
LC
6284
6285@smallexample
ddbc7f7d
LC
6286$ guix challenge --substitute-urls="https://hydra.gnu.org https://guix.example.org"
6287updating list of substitutes from 'https://hydra.gnu.org'... 100.0%
6288updating list of substitutes from 'https://guix.example.org'... 100.0%
d23c20f1
LC
6289/gnu/store/@dots{}-openssl-1.0.2d contents differ:
6290 local hash: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
ddbc7f7d
LC
6291 https://hydra.gnu.org/nar/@dots{}-openssl-1.0.2d: 0725l22r5jnzazaacncwsvp9kgf42266ayyp814v7djxs7nk963q
6292 https://guix.example.org/nar/@dots{}-openssl-1.0.2d: 1zy4fmaaqcnjrzzajkdn3f5gmjk754b43qkq47llbyak9z0qjyim
d23c20f1
LC
6293/gnu/store/@dots{}-git-2.5.0 contents differ:
6294 local hash: 00p3bmryhjxrhpn2gxs2fy0a15lnip05l97205pgbk5ra395hyha
ddbc7f7d
LC
6295 https://hydra.gnu.org/nar/@dots{}-git-2.5.0: 069nb85bv4d4a6slrwjdy8v1cn4cwspm3kdbmyb81d6zckj3nq9f
6296 https://guix.example.org/nar/@dots{}-git-2.5.0: 0mdqa9w1p6cmli6976v4wi0sw9r4p5prkj7lzfd1877wk11c9c73
d23c20f1
LC
6297/gnu/store/@dots{}-pius-2.1.1 contents differ:
6298 local hash: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
ddbc7f7d
LC
6299 https://hydra.gnu.org/nar/@dots{}-pius-2.1.1: 0k4v3m9z1zp8xzzizb7d8kjj72f9172xv078sq4wl73vnq9ig3ax
6300 https://guix.example.org/nar/@dots{}-pius-2.1.1: 1cy25x1a4fzq5rk0pmvc8xhwyffnqz95h2bpvqsz2mpvlbccy0gs
d23c20f1
LC
6301@end smallexample
6302
6303@noindent
6304In this example, @command{guix challenge} first scans the store to
6305determine the set of locally-built derivations---as opposed to store
6306items that were downloaded from a substitute server---and then queries
6307all the substitute servers. It then reports those store items for which
6308the servers obtained a result different from the local build.
6309
6310@cindex non-determinism, in package builds
6311As an example, @code{guix.example.org} always gets a different answer.
6312Conversely, @code{hydra.gnu.org} agrees with local builds, except in the
6313case of Git. This might indicate that the build process of Git is
6314non-deterministic, meaning that its output varies as a function of
6315various things that Guix does not fully control, in spite of building
6316packages in isolated environments (@pxref{Features}). Most common
6317sources of non-determinism include the addition of timestamps in build
6318results, the inclusion of random numbers, and directory listings sorted
a70a5004 6319by inode number. See @uref{https://reproducible-builds.org/docs/}, for
d23c20f1
LC
6320more information.
6321
f97c9175 6322To find out what is wrong with this Git binary, we can do something along
d23c20f1
LC
6323these lines (@pxref{Invoking guix archive}):
6324
6325@example
ddbc7f7d 6326$ wget -q -O - https://hydra.gnu.org/nar/@dots{}-git-2.5.0 \
d23c20f1 6327 | guix archive -x /tmp/git
043f4698 6328$ diff -ur --no-dereference /gnu/store/@dots{}-git.2.5.0 /tmp/git
d23c20f1
LC
6329@end example
6330
6331This command shows the difference between the files resulting from the
6332local build, and the files resulting from the build on
6333@code{hydra.gnu.org} (@pxref{Overview, Comparing and Merging Files,,
6334diffutils, Comparing and Merging Files}). The @command{diff} command
6335works great for text files. When binary files differ, a better option
ddbc7f7d 6336is @uref{https://diffoscope.org/, Diffoscope}, a tool that helps
d23c20f1
LC
6337visualize differences for all kinds of files.
6338
f97c9175 6339Once you have done that work, you can tell whether the differences are due
d23c20f1
LC
6340to a non-deterministic build process or to a malicious server. We try
6341hard to remove sources of non-determinism in packages to make it easier
f97c9175
AE
6342to verify substitutes, but of course, this is a process that
6343involves not just Guix, but a large part of the free software community.
d23c20f1
LC
6344In the meantime, @command{guix challenge} is one tool to help address
6345the problem.
6346
6347If you are writing packages for Guix, you are encouraged to check
6348whether @code{hydra.gnu.org} and other substitute servers obtain the
6349same build result as you did with:
6350
6351@example
6352$ guix challenge @var{package}
6353@end example
6354
6355@noindent
f97c9175 6356where @var{package} is a package specification such as
7cffaeb6 6357@code{guile@@2.0} or @code{glibc:debug}.
d23c20f1
LC
6358
6359The general syntax is:
6360
6361@example
6362guix challenge @var{options} [@var{packages}@dots{}]
6363@end example
6364
7cffaeb6
LC
6365When a difference is found between the hash of a locally-built item and
6366that of a server-provided substitute, or among substitutes provided by
6367different servers, the command displays it as in the example above and
a17417a8
LC
6368its exit code is 2 (other non-zero exit codes denote other kinds of
6369errors.)
7cffaeb6 6370
d23c20f1
LC
6371The one option that matters is:
6372
6373@table @code
6374
6375@item --substitute-urls=@var{urls}
6376Consider @var{urls} the whitespace-separated list of substitute source
6377URLs to compare to.
6378
6379@end table
6380
f11c444d
LC
6381@node Invoking guix copy
6382@section Invoking @command{guix copy}
6383
6384@cindex copy, of store items, over SSH
6385@cindex SSH, copy of store items
6386@cindex sharing store items across machines
6387@cindex transferring store items across machines
6388The @command{guix copy} command copies items from the store of one
6389machine to that of another machine over a secure shell (SSH)
6390connection@footnote{This command is available only when Guile-SSH was
6391found. @xref{Requirements}, for details.}. For example, the following
6392command copies the @code{coreutils} package, the user's profile, and all
6393their dependencies over to @var{host}, logged in as @var{user}:
6394
6395@example
6396guix copy --to=@var{user}@@@var{host} \
6397 coreutils `readlink -f ~/.guix-profile`
6398@end example
6399
6400If some of the items to be copied are already present on @var{host},
6401they are not actually sent.
6402
6403The command below retrieves @code{libreoffice} and @code{gimp} from
6404@var{host}, assuming they are available there:
6405
6406@example
6407guix copy --from=@var{host} libreoffice gimp
6408@end example
6409
6410The SSH connection is established using the Guile-SSH client, which is
6411compatible with OpenSSH: it honors @file{~/.ssh/known_hosts} and
6412@file{~/.ssh/config}, and uses the SSH agent for authentication.
6413
6414The key used to sign items that are sent must be accepted by the remote
6415machine. Likewise, the key used by the remote machine to sign items you
6416are retrieving must be in @file{/etc/guix/acl} so it is accepted by your
6417own daemon. @xref{Invoking guix archive}, for more information about
6418store item authentication.
6419
6420The general syntax is:
6421
6422@example
6423guix copy [--to=@var{spec}|--from=@var{spec}] @var{items}@dots{}
6424@end example
6425
6426You must always specify one of the following options:
6427
6428@table @code
6429@item --to=@var{spec}
6430@itemx --from=@var{spec}
6431Specify the host to send to or receive from. @var{spec} must be an SSH
6432spec such as @code{example.org}, @code{charlie@@example.org}, or
6433@code{charlie@@example.org:2222}.
6434@end table
6435
6436The @var{items} can be either package names, such as @code{gimp}, or
6437store items, such as @file{/gnu/store/@dots{}-idutils-4.6}.
6438
6439When specifying the name of a package to send, it is first built if
6440needed, unless @option{--dry-run} was specified. Common build options
6441are supported (@pxref{Common Build Options}).
6442
d23c20f1 6443
32efa254
DT
6444@node Invoking guix container
6445@section Invoking @command{guix container}
6446@cindex container
e32171ee 6447@cindex @command{guix container}
32efa254
DT
6448@quotation Note
6449As of version @value{VERSION}, this tool is experimental. The interface
6450is subject to radical change in the future.
6451@end quotation
6452
6453The purpose of @command{guix container} is to manipulate processes
6454running within an isolated environment, commonly known as a
46c36586 6455``container'', typically created by the @command{guix environment}
32efa254
DT
6456(@pxref{Invoking guix environment}) and @command{guix system container}
6457(@pxref{Invoking guix system}) commands.
6458
6459The general syntax is:
6460
6461@example
6462guix container @var{action} @var{options}@dots{}
6463@end example
6464
6465@var{action} specifies the operation to perform with a container, and
6466@var{options} specifies the context-specific arguments for the action.
6467
6468The following actions are available:
6469
6470@table @code
6471@item exec
6472Execute a command within the context of a running container.
6473
6474The syntax is:
6475
6476@example
6477guix container exec @var{pid} @var{program} @var{arguments}@dots{}
6478@end example
6479
6480@var{pid} specifies the process ID of the running container.
f97c9175
AE
6481@var{program} specifies an executable file name within the root file
6482system of the container. @var{arguments} are the additional options that
6483will be passed to @var{program}.
32efa254
DT
6484
6485The following command launches an interactive login shell inside a
6486GuixSD container, started by @command{guix system container}, and whose
6487process ID is 9001:
6488
6489@example
6490guix container exec 9001 /run/current-system/profile/bin/bash --login
6491@end example
6492
6493Note that the @var{pid} cannot be the parent process of a container. It
f97c9175 6494must be PID 1 of the container or one of its child processes.
32efa254
DT
6495
6496@end table
6497
a1ba8475
LC
6498@c *********************************************************************
6499@node GNU Distribution
6500@chapter GNU Distribution
6501
3ca2731c 6502@cindex Guix System Distribution
4705641f 6503@cindex GuixSD
3ca2731c
LC
6504Guix comes with a distribution of the GNU system consisting entirely of
6505free software@footnote{The term ``free'' here refers to the
a1ba8475 6506@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 6507users of that software}.}. The
35ed9306
LC
6508distribution can be installed on its own (@pxref{System Installation}),
6509but it is also possible to install Guix as a package manager on top of
6510an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c 6511between the two, we refer to the standalone distribution as the Guix
4705641f 6512System Distribution, or GuixSD.
35ed9306
LC
6513
6514The distribution provides core GNU packages such as GNU libc, GCC, and
6515Binutils, as well as many GNU and non-GNU applications. The complete
6516list of available packages can be browsed
093ae1be 6517@url{http://www.gnu.org/software/guix/packages,on-line} or by
d03bb653 6518running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
6519
6520@example
e49951eb 6521guix package --list-available
a1ba8475
LC
6522@end example
6523
f97c9175 6524Our goal is to provide a practical 100% free software distribution of
401c53c4
LC
6525Linux-based and other variants of GNU, with a focus on the promotion and
6526tight integration of GNU components, and an emphasis on programs and
6527tools that help users exert that freedom.
6528
3ca2731c 6529Packages are currently available on the following platforms:
c320011d
LC
6530
6531@table @code
6532
6533@item x86_64-linux
6534Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
6535
6536@item i686-linux
6537Intel 32-bit architecture (IA32), Linux-Libre kernel;
6538
aa1e1947 6539@item armhf-linux
aa725117 6540ARMv7-A architecture with hard float, Thumb-2 and NEON,
f97c9175
AE
6541using the EABI hard-float application binary interface (ABI),
6542and Linux-Libre kernel.
aa1e1947 6543
c320011d
LC
6544@item mips64el-linux
6545little-endian 64-bit MIPS processors, specifically the Loongson series,
f97c9175 6546n32 ABI, and Linux-Libre kernel.
c320011d
LC
6547
6548@end table
6549
4705641f 6550GuixSD itself is currently only available on @code{i686} and @code{x86_64}.
3ca2731c 6551
c320011d
LC
6552@noindent
6553For information on porting to other architectures or kernels,
f97c9175 6554@pxref{Porting}.
c320011d 6555
401c53c4 6556@menu
5af6de3e 6557* System Installation:: Installing the whole operating system.
35ed9306 6558* System Configuration:: Configuring the operating system.
91ef73d4 6559* Installing Debugging Files:: Feeding the debugger.
05962f29 6560* Security Updates:: Deploying security fixes quickly.
401c53c4 6561* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 6562* Packaging Guidelines:: Growing the distribution.
401c53c4 6563* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 6564* Porting:: Targeting another platform or kernel.
401c53c4
LC
6565@end menu
6566
6567Building this distribution is a cooperative effort, and you are invited
081145cf 6568to join! @xref{Contributing}, for information about how you can help.
401c53c4 6569
5af6de3e
LC
6570@node System Installation
6571@section System Installation
6572
e32171ee 6573@cindex installing GuixSD
3ca2731c 6574@cindex Guix System Distribution
c8b54374 6575This section explains how to install the Guix System Distribution (GuixSD)
3ca2731c 6576on a machine. The Guix package manager can
35ed9306
LC
6577also be installed on top of a running GNU/Linux system,
6578@pxref{Installation}.
5af6de3e
LC
6579
6580@ifinfo
9c18cf9b 6581@quotation Note
5af6de3e
LC
6582@c This paragraph is for people reading this from tty2 of the
6583@c installation image.
1068f26b 6584You are reading this documentation with an Info reader. For details on
5af6de3e 6585how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
de341e7c
LC
6586link that follows: @pxref{Top, Info reader,, info-stnd, Stand-alone GNU
6587Info}. Hit @kbd{l} afterwards to come back here.
9c18cf9b
LC
6588
6589Alternately, run @command{info info} in another tty to keep the manual
6590available.
6591@end quotation
5af6de3e
LC
6592@end ifinfo
6593
dedb8d5e 6594@menu
e3009f60
LC
6595* Limitations:: What you can expect.
6596* Hardware Considerations:: Supported hardware.
6597* USB Stick Installation:: Preparing the installation medium.
6598* Preparing for Installation:: Networking, partitioning, etc.
6599* Proceeding with the Installation:: The real thing.
c8b54374 6600* Installing GuixSD in a VM:: GuixSD playground.
e3009f60 6601* Building the Installation Image:: How this comes to be.
dedb8d5e
LC
6602@end menu
6603
6604@node Limitations
8aaaae38
LC
6605@subsection Limitations
6606
4705641f 6607As of version @value{VERSION}, the Guix System Distribution (GuixSD) is
3ca2731c 6608not production-ready. It may contain bugs and lack important
8aaaae38
LC
6609features. Thus, if you are looking for a stable production system that
6610respects your freedom as a computer user, a good solution at this point
6611is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
f97c9175 6612the more established GNU/Linux distributions}. We hope you can soon switch
4705641f 6613to the GuixSD without fear, of course. In the meantime, you can
8aaaae38
LC
6614also keep using your distribution and try out the package manager on top
6615of it (@pxref{Installation}).
6616
6617Before you proceed with the installation, be aware of the following
6618noteworthy limitations applicable to version @value{VERSION}:
6619
6620@itemize
6621@item
6622The installation process does not include a graphical user interface and
6623requires familiarity with GNU/Linux (see the following subsections to
6624get a feel of what that means.)
6625
8aaaae38 6626@item
dbcb0ab1 6627Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
6628
6629@item
6630Few system services are currently supported out-of-the-box
6631(@pxref{Services}).
6632
6633@item
29e53b95 6634More than 4,000 packages are available, but you may
8aaaae38 6635occasionally find that a useful package is missing.
5fe01c2d
LC
6636
6637@item
6638GNOME, Xfce, and Enlightenment are available (@pxref{Desktop Services}),
6639as well as a number of X11 window managers. However, some graphical
6640applications may be missing, as well as KDE.
8aaaae38
LC
6641@end itemize
6642
f97c9175
AE
6643You have been warned! But more than a disclaimer, this is an invitation
6644to report issues (and success stories!), and to join us in improving it.
8aaaae38 6645@xref{Contributing}, for more info.
5af6de3e 6646
e3009f60
LC
6647
6648@node Hardware Considerations
6649@subsection Hardware Considerations
6650
6651@cindex hardware support on GuixSD
6652GNU@tie{}GuixSD focuses on respecting the user's computing freedom. It
6653builds around the kernel Linux-libre, which means that only hardware for
e0b3f97e 6654which free software drivers and firmware exist is supported. Nowadays,
e3009f60
LC
6655a wide range of off-the-shelf hardware is supported on
6656GNU/Linux-libre---from keyboards to graphics cards to scanners and
6657Ethernet controllers. Unfortunately, there are still areas where
6658hardware vendors deny users control over their own computing, and such
6659hardware is not supported on GuixSD.
6660
6661@cindex WiFi, hardware support
e0b3f97e 6662One of the main areas where free drivers or firmware are lacking is WiFi
e3009f60
LC
6663devices. WiFi devices known to work include those using Atheros chips
6664(AR9271 and AR7010), which corresponds to the @code{ath9k} Linux-libre
52db41af
EB
6665driver, and those using Broadcom/AirForce chips (BCM43xx with
6666Wireless-Core Revision 5), which corresponds to the @code{b43-open}
6667Linux-libre driver. Free firmware exists for both and is available
e3009f60
LC
6668out-of-the-box on GuixSD, as part of @var{%base-firmware}
6669(@pxref{operating-system Reference, @code{firmware}}).
6670
6671@cindex RYF, Respects Your Freedom
6672The @uref{https://www.fsf.org/, Free Software Foundation} runs
e0b3f97e 6673@uref{https://www.fsf.org/ryf, @dfn{Respects Your Freedom}} (RYF), a
e3009f60
LC
6674certification program for hardware products that respect your freedom
6675and your privacy and ensure that you have control over your device. We
e0b3f97e 6676encourage you to check the list of RYF-certified devices.
e3009f60
LC
6677
6678Another useful resource is the @uref{https://www.h-node.org/, H-Node}
6679web site. It contains a catalog of hardware devices with information
6680about their support in GNU/Linux.
6681
6682
dedb8d5e 6683@node USB Stick Installation
5af6de3e
LC
6684@subsection USB Stick Installation
6685
6686An installation image for USB sticks can be downloaded from
4705641f 6687@indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
6688where @var{system} is one of:
6689
6690@table @code
6691@item x86_64-linux
6692for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
6693
6694@item i686-linux
6695for a 32-bit GNU/Linux system on Intel-compatible CPUs.
6696@end table
6697
debc6360
LC
6698@c start duplication of authentication part from ``Binary Installation''
6699Make sure to download the associated @file{.sig} file and to verify the
6700authenticity of the image against it, along these lines:
6701
6702@example
6703$ wget ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6704$ gpg --verify guixsd-usb-install-@value{VERSION}.@var{system}.xz.sig
6705@end example
6706
6707If that command fails because you do not have the required public key,
6708then run this command to import it:
6709
6710@example
6711$ gpg --keyserver pgp.mit.edu --recv-keys @value{OPENPGP-SIGNING-KEY-ID}
6712@end example
6713
6714@noindent
6715and rerun the @code{gpg --verify} command.
6716@c end duplication
6717
5af6de3e
LC
6718This image contains a single partition with the tools necessary for an
6719installation. It is meant to be copied @emph{as is} to a large-enough
6720USB stick.
6721
6722To copy the image to a USB stick, follow these steps:
6723
6724@enumerate
6725@item
6726Decompress the image using the @command{xz} command:
6727
6728@example
4705641f 6729xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
6730@end example
6731
6732@item
f97c9175
AE
6733Insert a USB stick of 1@tie{}GiB or more into your machine, and determine
6734its device name. Assuming that the USB stick is known as @file{/dev/sdX},
5af6de3e
LC
6735copy the image with:
6736
6737@example
4705641f 6738dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
6739@end example
6740
6741Access to @file{/dev/sdX} usually requires root privileges.
6742@end enumerate
6743
6744Once this is done, you should be able to reboot the system and boot from
6745the USB stick. The latter usually requires you to get in the BIOS' boot
6746menu, where you can choose to boot from the USB stick.
6747
c8b54374
VL
6748@xref{Installing GuixSD in a VM}, if, instead, you would like to install
6749GuixSD in a virtual machine (VM).
6750
dedb8d5e 6751@node Preparing for Installation
5af6de3e
LC
6752@subsection Preparing for Installation
6753
6754Once you have successfully booted the image on the USB stick, you should
6755end up with a root prompt. Several console TTYs are configured and can
6756be used to run commands as root. TTY2 shows this documentation,
de341e7c
LC
6757browsable using the Info reader commands (@pxref{Top,,, info-stnd,
6758Stand-alone GNU Info}). The installation system runs the GPM mouse
6759daemon, which allows you to select text with the left mouse button and
6760to paste it with the middle button.
5af6de3e 6761
ff925d37
LC
6762@quotation Note
6763Installation requires access to the Internet so that any missing
6764dependencies of your system configuration can be downloaded. See the
6765``Networking'' section below.
6766@end quotation
6767
0e69cf67
LC
6768The installation system includes many common tools needed for this task.
6769But it is also a full-blown GuixSD system, which means that you can
6770install additional packages, should you need it, using @command{guix
6771package} (@pxref{Invoking guix package}).
6772
dedb8d5e 6773@subsubsection Keyboard Layout
5af6de3e 6774
dedb8d5e
LC
6775@cindex keyboard layout
6776The installation image uses the US qwerty keyboard layout. If you want
6777to change it, you can use the @command{loadkeys} command. For example,
6778the following command selects the Dvorak keyboard layout:
5af6de3e 6779
dedb8d5e
LC
6780@example
6781loadkeys dvorak
6782@end example
6783
6784See the files under @file{/run/current-system/profile/share/keymaps} for
6785a list of available keyboard layouts. Run @command{man loadkeys} for
6786more information.
6787
6788@subsubsection Networking
6789
6790Run the following command see what your network interfaces are called:
235cba85
LC
6791
6792@example
dedb8d5e 6793ifconfig -a
235cba85
LC
6794@end example
6795
1713c37f
LC
6796@noindent
6797@dots{} or, using the GNU/Linux-specific @command{ip} command:
6798
6799@example
6800ip a
6801@end example
6802
95c559c1 6803@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
dedb8d5e
LC
6804Wired interfaces have a name starting with @samp{e}; for example, the
6805interface corresponding to the first on-board Ethernet controller is
6806called @samp{eno1}. Wireless interfaces have a name starting with
6807@samp{w}, like @samp{w1p2s0}.
6808
6809@table @asis
6810@item Wired connection
6811To configure a wired network run the following command, substituting
6812@var{interface} with the name of the wired interface you want to use.
6813
6814@example
6815ifconfig @var{interface} up
6816@end example
6817
6818@item Wireless connection
e32171ee
JD
6819@cindex wireless
6820@cindex WiFi
dedb8d5e
LC
6821To configure wireless networking, you can create a configuration file
6822for the @command{wpa_supplicant} configuration tool (its location is not
6823important) using one of the available text editors such as
6824@command{zile}:
6825
6826@example
6827zile wpa_supplicant.conf
6828@end example
6829
6830As an example, the following stanza can go to this file and will work
6831for many wireless networks, provided you give the actual SSID and
6832passphrase for the network you are connecting to:
6833
6834@example
6835network=@{
ae768308 6836 ssid="@var{my-ssid}"
dedb8d5e
LC
6837 key_mgmt=WPA-PSK
6838 psk="the network's secret passphrase"
6839@}
6840@end example
6841
6842Start the wireless service and run it in the background with the
6843following command (substitute @var{interface} with the name of the
6844network interface you want to use):
6845
6846@example
6847wpa_supplicant -c wpa_supplicant.conf -i @var{interface} -B
6848@end example
6849
641d0518 6850Run @command{man wpa_supplicant} for more information.
dedb8d5e
LC
6851@end table
6852
e32171ee 6853@cindex DHCP
dedb8d5e
LC
6854At this point, you need to acquire an IP address. On a network where IP
6855addresses are automatically assigned @i{via} DHCP, you can run:
6856
6857@example
15650ac2 6858dhclient -v @var{interface}
dedb8d5e 6859@end example
5af6de3e 6860
dedb8d5e
LC
6861Try to ping a server to see if networking is up and running:
6862
6863@example
6864ping -c 3 gnu.org
6865@end example
5af6de3e
LC
6866
6867Setting up network access is almost always a requirement because the
6868image does not contain all the software and tools that may be needed.
6869
dedb8d5e
LC
6870@subsubsection Disk Partitioning
6871
6872Unless this has already been done, the next step is to partition, and
6873then format the target partition(s).
6874
6875The installation image includes several partitioning tools, including
6876Parted (@pxref{Overview,,, parted, GNU Parted User Manual}),
6877@command{fdisk}, and @command{cfdisk}. Run it and set up your disk with
6878the partition layout you want:
6879
6880@example
6881cfdisk
6882@end example
6883
6884Once you are done partitioning the target hard disk drive, you have to
6885create a file system on the relevant partition(s)@footnote{Currently
6886GuixSD pretty much assumes an ext4 file system. In particular, code
6887that reads partition UUIDs and labels only works with ext4. This will
6888be fixed in the future.}.
5af6de3e 6889
7ab44369
LC
6890Preferably, assign partitions a label so that you can easily and
6891reliably refer to them in @code{file-system} declarations (@pxref{File
6892Systems}). This is typically done using the @code{-L} option of
dedb8d5e
LC
6893@command{mkfs.ext4} and related commands. So, assuming the target root
6894partition lives at @file{/dev/sda1}, a file system with the label
6895@code{my-root} can be created with:
7ab44369 6896
dedb8d5e
LC
6897@example
6898mkfs.ext4 -L my-root /dev/sda1
6899@end example
dd816355 6900
13fb1bd9
LC
6901@cindex encrypted disk
6902If you are instead planning to encrypt the root partition, you can use
6903the Cryptsetup/LUKS utilities to do that (see @inlinefmtifelse{html,
6904@uref{https://linux.die.net/man/8/cryptsetup, @code{man cryptsetup}},
6905@code{man cryptsetup}} for more information.) Assuming you want to
6906store the root partition on @file{/dev/sda1}, the command sequence would
6907be along these lines:
6d6e6281 6908
13fb1bd9
LC
6909@example
6910cryptsetup luksFormat /dev/sda1
6911cryptsetup open --type luks /dev/sda1 my-partition
6912mkfs.ext4 -L my-root /dev/mapper/my-partition
6913@end example
5af6de3e 6914
dedb8d5e 6915Once that is done, mount the target root partition under @file{/mnt}
13fb1bd9
LC
6916with a command like (again, assuming @code{my-root} is the label of the
6917root partition):
83a17b62 6918
dedb8d5e 6919@example
13fb1bd9 6920mount LABEL=my-root /mnt
dedb8d5e 6921@end example
83a17b62 6922
31b6cdf8
LC
6923Finally, if you plan to use one or more swap partitions (@pxref{Memory
6924Concepts, swap space,, libc, The GNU C Library Reference Manual}), make
6925sure to initialize them with @command{mkswap}. Assuming you have one
6926swap partition on @file{/dev/sda2}, you would run:
6927
6928@example
6929mkswap /dev/sda2
b2ff76a0 6930swapon /dev/sda2
31b6cdf8
LC
6931@end example
6932
dedb8d5e
LC
6933@node Proceeding with the Installation
6934@subsection Proceeding with the Installation
83a17b62 6935
dedb8d5e
LC
6936With the target partitions ready and the target root mounted on
6937@file{/mnt}, we're ready to go. First, run:
5af6de3e 6938
dedb8d5e
LC
6939@example
6940herd start cow-store /mnt
6941@end example
5af6de3e 6942
b397c0d5
LC
6943This makes @file{/gnu/store} copy-on-write, such that packages added to it
6944during the installation phase are written to the target disk on @file{/mnt}
6945rather than kept in memory. This is necessary because the first phase of
6946the @command{guix system init} command (see below) entails downloads or
6947builds to @file{/gnu/store} which, initially, is an in-memory file system.
5af6de3e 6948
dedb8d5e 6949Next, you have to edit a file and
5af6de3e 6950provide the declaration of the operating system to be installed. To
a8cb87ab
LC
6951that end, the installation system comes with three text editors: GNU nano
6952(@pxref{Top,,, nano, GNU nano Manual}), GNU Zile (an Emacs clone), and
6953nvi (a clone of the original BSD @command{vi} editor).
efa77c6c
LC
6954We strongly recommend storing that file on the target root file system, say,
6955as @file{/mnt/etc/config.scm}. Failing to do that, you will have lost your
6956configuration file once you have rebooted into the newly-installed system.
5af6de3e 6957
dedb8d5e
LC
6958@xref{Using the Configuration System}, for an overview of the
6959configuration file. The example configurations discussed in that
6960section are available under @file{/etc/configuration} in the
6961installation image. Thus, to get started with a system configuration
6962providing a graphical display server (a ``desktop'' system), you can run
6963something along these lines:
6964
6965@example
6966# mkdir /mnt/etc
6967# cp /etc/configuration/desktop.scm /mnt/etc/config.scm
6968# zile /mnt/etc/config.scm
6969@end example
6970
6971You should pay attention to what your configuration file contains, and
6972in particular:
6973
6974@itemize
6975@item
6976Make sure the @code{grub-configuration} form refers to the device you
6977want to install GRUB on.
6978
6979@item
6980Be sure that your partition labels match the value of their respective
6981@code{device} fields in your @code{file-system} configuration, assuming
6982your @code{file-system} configuration sets the value of @code{title} to
6983@code{'label}.
13fb1bd9
LC
6984
6985@item
6986If there are encrypted or RAID partitions, make sure to add a
6987@code{mapped-devices} field to describe them (@pxref{Mapped Devices}).
dedb8d5e 6988@end itemize
5af6de3e 6989
dd51caac
LC
6990Once you are done preparing the configuration file, the new system must
6991be initialized (remember that the target root file system is mounted
6992under @file{/mnt}):
5af6de3e
LC
6993
6994@example
6995guix system init /mnt/etc/config.scm /mnt
6996@end example
6997
6998@noindent
dedb8d5e 6999This copies all the necessary files and installs GRUB on
5af6de3e 7000@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 7001more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
7002downloads or builds of missing packages, which can take some time.
7003
1bd4e6db
LC
7004Once that command has completed---and hopefully succeeded!---you can run
7005@command{reboot} and boot into the new system. The @code{root} password
7006in the new system is initially empty; other users' passwords need to be
7007initialized by running the @command{passwd} command as @code{root},
7008unless your configuration specifies otherwise
7009(@pxref{user-account-password, user account passwords}).
7010
7fcf2a0b
LC
7011@cindex upgrading GuixSD
7012From then on, you can update GuixSD whenever you want by running
7013@command{guix pull} as @code{root} (@pxref{Invoking guix pull}), and
7014then running @command{guix system reconfigure} to build a new system
7015generation with the latest packages and services (@pxref{Invoking guix
7016system}). We recommend doing that regularly so that your system
7017includes the latest security updates (@pxref{Security Updates}).
7018
1bd4e6db 7019Join us on @code{#guix} on the Freenode IRC network or on
5af6de3e
LC
7020@file{guix-devel@@gnu.org} to share your experience---good or not so
7021good.
7022
c8b54374
VL
7023@node Installing GuixSD in a VM
7024@subsection Installing GuixSD in a Virtual Machine
7025
7026@cindex virtual machine, GuixSD installation
7027If you'd like to install GuixSD in a virtual machine (VM) rather than on
7028your beloved machine, this section is for you.
7029
7030To boot a @uref{http://qemu.org/,QEMU} VM for installing GuixSD in a
7031disk image, follow these steps:
7032
7033@enumerate
7034@item
7035First, retrieve the GuixSD installation image as described previously
7036(@pxref{USB Stick Installation}).
7037
7038@item
7039Create a disk image that will hold the installed system. To make a
7040qcow2-formatted disk image, use the @command{qemu-img} command:
7041
7042@example
7043qemu-img create -f qcow2 guixsd.img 5G
7044@end example
7045
7046This will create a 5GB file.
7047
7048@item
7049Boot the USB installation image in an VM:
7050
7051@example
7052qemu-system-x86_64 -m 1024 -smp 1 \
7053 -net default -net nic,model=virtio -boot menu=on \
7054 -drive file=guixsd.img \
7055 -drive file=guixsd-usb-install-@value{VERSION}.@var{system}
7056@end example
7057
7058In the VM console, quickly press the @kbd{F12} key to enter the boot
7059menu. Then press the @kbd{2} key and the @kbd{RET} key to validate your
7060selection.
7061
7062@item
7063You're now root in the VM, proceed with the installation process.
7064@xref{Preparing for Installation}, and follow the instructions.
7065@end enumerate
7066
7067Once installation is complete, you can boot the system that's on your
7068@file{guixsd.img} image. @xref{Running GuixSD in a VM}, for how to do
7069that.
7070
dedb8d5e 7071@node Building the Installation Image
5af6de3e
LC
7072@subsection Building the Installation Image
7073
e32171ee 7074@cindex installation image
5af6de3e
LC
7075The installation image described above was built using the @command{guix
7076system} command, specifically:
7077
622b2304 7078@c FIXME: 1G is too much; see <http://bugs.gnu.org/23077>.
5af6de3e 7079@example
622b2304 7080guix system disk-image --image-size=1G gnu/system/install.scm
5af6de3e
LC
7081@end example
7082
6e6a0401
AE
7083Have a look at @file{gnu/system/install.scm} in the source tree,
7084and see also @ref{Invoking guix system} for more information
5af6de3e
LC
7085about the installation image.
7086
cf4a9129
LC
7087@node System Configuration
7088@section System Configuration
b208a005 7089
cf4a9129 7090@cindex system configuration
3ca2731c 7091The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
7092mechanism. By that we mean that all aspects of the global system
7093configuration---such as the available system services, timezone and
7094locale settings, user accounts---are declared in a single place. Such
7095a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 7096
cf4a9129
LC
7097One of the advantages of putting all the system configuration under the
7098control of Guix is that it supports transactional system upgrades, and
1068f26b 7099makes it possible to roll back to a previous system instantiation,
cf4a9129 7100should something go wrong with the new one (@pxref{Features}). Another
1068f26b 7101advantage is that it makes it easy to replicate the exact same configuration
cf4a9129
LC
7102across different machines, or at different points in time, without
7103having to resort to additional administration tools layered on top of
1068f26b 7104the own tools of the system.
cf4a9129 7105@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 7106
cf4a9129
LC
7107This section describes this mechanism. First we focus on the system
7108administrator's viewpoint---explaining how the system is configured and
7109instantiated. Then we show how this mechanism can be extended, for
7110instance to support new system services.
91ef73d4 7111
cf4a9129
LC
7112@menu
7113* Using the Configuration System:: Customizing your GNU system.
7313a52e 7114* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 7115* File Systems:: Configuring file system mounts.
510f9d86 7116* Mapped Devices:: Block device extra processing.
cf4a9129 7117* User Accounts:: Specifying user accounts.
598e19dc 7118* Locales:: Language and cultural convention settings.
cf4a9129 7119* Services:: Specifying system services.
0ae8c15a 7120* Setuid Programs:: Programs running with root privileges.
efb5e833 7121* X.509 Certificates:: Authenticating HTTPS servers.
996ed739 7122* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 7123* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 7124* GRUB Configuration:: Configuring the boot loader.
cf4a9129 7125* Invoking guix system:: Instantiating a system configuration.
97d76250 7126* Running GuixSD in a VM:: How to run GuixSD in a virtual machine.
cf4a9129
LC
7127* Defining Services:: Adding new service definitions.
7128@end menu
91ef73d4 7129
cf4a9129
LC
7130@node Using the Configuration System
7131@subsection Using the Configuration System
64d76fa6 7132
cf4a9129
LC
7133The operating system is configured by providing an
7134@code{operating-system} declaration in a file that can then be passed to
7135the @command{guix system} command (@pxref{Invoking guix system}). A
7136simple setup, with the default system services, the default Linux-Libre
7137kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 7138
cf4a9129
LC
7139@findex operating-system
7140@lisp
dd51caac 7141@include os-config-bare-bones.texi
cf4a9129 7142@end lisp
401c53c4 7143
cf4a9129
LC
7144This example should be self-describing. Some of the fields defined
7145above, such as @code{host-name} and @code{bootloader}, are mandatory.
7146Others, such as @code{packages} and @code{services}, can be omitted, in
7147which case they get a default value.
e7f34eb0 7148
5d94ac51
LC
7149Below we discuss the effect of some of the most important fields
7150(@pxref{operating-system Reference}, for details about all the available
7151fields), and how to @dfn{instantiate} the operating system using
7152@command{guix system}.
7153
7154@unnumberedsubsubsec Globally-Visible Packages
7155
cf4a9129 7156@vindex %base-packages
5d94ac51
LC
7157The @code{packages} field lists packages that will be globally visible
7158on the system, for all user accounts---i.e., in every user's @code{PATH}
7159environment variable---in addition to the per-user profiles
7160(@pxref{Invoking guix package}). The @var{%base-packages} variable
7161provides all the tools one would expect for basic user and administrator
7162tasks---including the GNU Core Utilities, the GNU Networking Utilities,
7163the GNU Zile lightweight text editor, @command{find}, @command{grep},
7164etc. The example above adds tcpdump to those, taken from the @code{(gnu
7165packages admin)} module (@pxref{Package Modules}).
e7f34eb0 7166
f6c9fb1b
LC
7167@findex specification->package
7168Referring to packages by variable name, like @var{tcpdump} above, has
7169the advantage of being unambiguous; it also allows typos and such to be
7170diagnosed right away as ``unbound variables''. The downside is that one
7171needs to know which module defines which package, and to augment the
7172@code{use-package-modules} line accordingly. To avoid that, one can use
7173the @code{specification->package} procedure of the @code{(gnu packages)}
7174module, which returns the best package for a given name or name and
7175version:
7176
7177@lisp
7178(use-modules (gnu packages))
7179
7180(operating-system
7181 ;; ...
7182 (packages (append (map specification->package
d5e59248 7183 '("tcpdump" "htop" "gnupg@@2.0"))
f6c9fb1b
LC
7184 %base-packages)))
7185@end lisp
7186
5d94ac51
LC
7187@unnumberedsubsubsec System Services
7188
e32171ee 7189@cindex services
cf4a9129
LC
7190@vindex %base-services
7191The @code{services} field lists @dfn{system services} to be made
7192available when the system starts (@pxref{Services}).
7193The @code{operating-system} declaration above specifies that, in
7194addition to the basic services, we want the @command{lshd} secure shell
cd6f6c22
LC
7195daemon listening on port 2222 (@pxref{Networking Services,
7196@code{lsh-service}}). Under the hood,
cf4a9129
LC
7197@code{lsh-service} arranges so that @code{lshd} is started with the
7198right command-line options, possibly with supporting configuration files
cd6f6c22
LC
7199generated as needed (@pxref{Defining Services}).
7200
7201@cindex customization, of services
7202@findex modify-services
7203Occasionally, instead of using the base services as is, you will want to
4d343a14
CM
7204customize them. To do this, use @code{modify-services} (@pxref{Service
7205Reference, @code{modify-services}}) to modify the list.
7206
7207For example, suppose you want to modify @code{guix-daemon} and Mingetty
7208(the console log-in) in the @var{%base-services} list (@pxref{Base
7209Services, @code{%base-services}}). To do that, you can write the
7210following in your operating system declaration:
cd6f6c22
LC
7211
7212@lisp
4d343a14
CM
7213(define %my-services
7214 ;; My very own list of services.
7215 (modify-services %base-services
7216 (guix-service-type config =>
7217 (guix-configuration
7218 (inherit config)
7219 (use-substitutes? #f)
7220 (extra-options '("--gc-keep-derivations"))))
7221 (mingetty-service-type config =>
7222 (mingetty-configuration
317d3b47 7223 (inherit config)))))
4d343a14
CM
7224
7225(operating-system
7226 ;; @dots{}
7227 (services %my-services))
cd6f6c22
LC
7228@end lisp
7229
4d343a14
CM
7230This changes the configuration---i.e., the service parameters---of the
7231@code{guix-service-type} instance, and that of all the
7232@code{mingetty-service-type} instances in the @var{%base-services} list.
7233Observe how this is accomplished: first, we arrange for the original
7234configuration to be bound to the identifier @code{config} in the
7235@var{body}, and then we write the @var{body} so that it evaluates to the
7236desired configuration. In particular, notice how we use @code{inherit}
7237to create a new configuration which has the same values as the old
7238configuration, but with a few modifications.
a1ba8475 7239
13fb1bd9
LC
7240@cindex encrypted disk
7241The configuration for a typical ``desktop'' usage, with an encrypted
7242root partition, the X11 display
d038b674
LC
7243server, GNOME and Xfce (users can choose which of these desktop
7244environments to use at the log-in screen by pressing @kbd{F1}), network
7245management, power management, and more, would look like this:
dd51caac
LC
7246
7247@lisp
7248@include os-config-desktop.texi
7249@end lisp
7250
d038b674
LC
7251A graphical environment with a choice of lightweight window managers
7252instead of full-blown desktop environments would look like this:
7253
7254@lisp
7255@include os-config-lightweight-desktop.texi
7256@end lisp
7257
dd51caac 7258@xref{Desktop Services}, for the exact list of services provided by
efb5e833
LC
7259@var{%desktop-services}. @xref{X.509 Certificates}, for background
7260information about the @code{nss-certs} package that is used here.
dd51caac 7261
5d94ac51
LC
7262Again, @var{%desktop-services} is just a list of service objects. If
7263you want to remove services from there, you can do so using the
7264procedures for list filtering (@pxref{SRFI-1 Filtering and
7265Partitioning,,, guile, GNU Guile Reference Manual}). For instance, the
7266following expression returns a list that contains all the services in
7267@var{%desktop-services} minus the Avahi service:
7268
7269@example
7270(remove (lambda (service)
7271 (eq? (service-kind service) avahi-service-type))
7272 %desktop-services)
7273@end example
7274
7275@unnumberedsubsubsec Instantiating the System
7276
7277Assuming the @code{operating-system} declaration
7278is stored in the @file{my-system-config.scm}
cf4a9129
LC
7279file, the @command{guix system reconfigure my-system-config.scm} command
7280instantiates that configuration, and makes it the default GRUB boot
65797bff
LC
7281entry (@pxref{Invoking guix system}).
7282
1068f26b 7283The normal way to change the system configuration is by updating this
65797bff 7284file and re-running @command{guix system reconfigure}. One should never
8b499030 7285have to touch files in @file{/etc} or to run commands that modify the
65797bff
LC
7286system state such as @command{useradd} or @command{grub-install}. In
7287fact, you must avoid that since that would not only void your warranty
7288but also prevent you from rolling back to previous versions of your
7289system, should you ever need to.
7290
7291@cindex roll-back, of the operating system
7292Speaking of roll-back, each time you run @command{guix system
7293reconfigure}, a new @dfn{generation} of the system is created---without
7294modifying or deleting previous generations. Old system generations get
7295an entry in the GRUB boot menu, allowing you to boot them in case
7296something went wrong with the latest generation. Reassuring, no? The
7297@command{guix system list-generations} command lists the system
067a2e2d
CM
7298generations available on disk. It is also possible to roll back the
7299system via the commands @command{guix system roll-back} and
7300@command{guix system switch-generation}.
7301
7302Although the command @command{guix system reconfigure} will not modify
7303previous generations, must take care when the current generation is not
7304the latest (e.g., after invoking @command{guix system roll-back}), since
7305the operation might overwrite a later generation (@pxref{Invoking guix
7306system}).
b81e1947 7307
5d94ac51
LC
7308@unnumberedsubsubsec The Programming Interface
7309
cf4a9129
LC
7310At the Scheme level, the bulk of an @code{operating-system} declaration
7311is instantiated with the following monadic procedure (@pxref{The Store
7312Monad}):
b81e1947 7313
cf4a9129
LC
7314@deffn {Monadic Procedure} operating-system-derivation os
7315Return a derivation that builds @var{os}, an @code{operating-system}
7316object (@pxref{Derivations}).
b81e1947 7317
cf4a9129
LC
7318The output of the derivation is a single directory that refers to all
7319the packages, configuration files, and other supporting files needed to
7320instantiate @var{os}.
7321@end deffn
b81e1947 7322
5d94ac51
LC
7323This procedure is provided by the @code{(gnu system)} module. Along
7324with @code{(gnu services)} (@pxref{Services}), this module contains the
7325guts of GuixSD. Make sure to visit it!
7326
7327
7313a52e
LC
7328@node operating-system Reference
7329@subsection @code{operating-system} Reference
7330
7331This section summarizes all the options available in
7332@code{operating-system} declarations (@pxref{Using the Configuration
7333System}).
7334
7335@deftp {Data Type} operating-system
7336This is the data type representing an operating system configuration.
7337By that, we mean all the global system configuration, not per-user
7338configuration (@pxref{Using the Configuration System}).
7339
7340@table @asis
7341@item @code{kernel} (default: @var{linux-libre})
fbb25e56 7342The package object of the operating system kernel to use@footnote{Currently
7313a52e
LC
7343only the Linux-libre kernel is supported. In the future, it will be
7344possible to use the GNU@tie{}Hurd.}.
7345
ee2a6304
LC
7346@item @code{kernel-arguments} (default: @code{'()})
7347List of strings or gexps representing additional arguments to pass on
1068f26b 7348the command-line of the kernel---e.g., @code{("console=ttyS0")}.
ee2a6304 7349
7313a52e 7350@item @code{bootloader}
88faf933 7351The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
7352
7353@item @code{initrd} (default: @code{base-initrd})
e32171ee
JD
7354@cindex initrd
7355@cindex initial RAM disk
7313a52e
LC
7356A two-argument monadic procedure that returns an initial RAM disk for
7357the Linux kernel. @xref{Initial RAM Disk}.
7358
f34c56be
LC
7359@item @code{firmware} (default: @var{%base-firmware})
7360@cindex firmware
7361List of firmware packages loadable by the operating system kernel.
7362
52db41af
EB
7363The default includes firmware needed for Atheros- and Broadcom-based
7364WiFi devices (Linux-libre modules @code{ath9k} and @code{b43-open},
7365respectively). @xref{Hardware Considerations}, for more info on
7366supported hardware.
f34c56be 7367
7313a52e
LC
7368@item @code{host-name}
7369The host name.
7370
7371@item @code{hosts-file}
7372@cindex hosts file
24e02c28 7373A file-like object (@pxref{G-Expressions, file-like objects}) for use as
7313a52e 7374@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
24e02c28 7375Reference Manual}). The default is a file with entries for
7313a52e
LC
7376@code{localhost} and @var{host-name}.
7377
7378@item @code{mapped-devices} (default: @code{'()})
7379A list of mapped devices. @xref{Mapped Devices}.
7380
7381@item @code{file-systems}
7382A list of file systems. @xref{File Systems}.
7383
7384@item @code{swap-devices} (default: @code{'()})
7385@cindex swap devices
7386A list of strings identifying devices to be used for ``swap space''
7387(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
7388For example, @code{'("/dev/sda3")}.
7389
bf87f38a 7390@item @code{users} (default: @code{%base-user-accounts})
7313a52e
LC
7391@itemx @code{groups} (default: @var{%base-groups})
7392List of user accounts and groups. @xref{User Accounts}.
7393
7394@item @code{skeletons} (default: @code{(default-skeletons)})
e9dffec1
LC
7395A list target file name/file-like object tuples (@pxref{G-Expressions,
7396file-like objects}). These are the skeleton files that will be added to
7397the home directory of newly-created user accounts.
7313a52e
LC
7398
7399For instance, a valid value may look like this:
7400
7401@example
e9dffec1
LC
7402`((".bashrc" ,(plain-file "bashrc" "echo Hello\n"))
7403 (".guile" ,(plain-file "guile"
7404 "(use-modules (ice-9 readline))
7405 (activate-readline)")))
7313a52e
LC
7406@end example
7407
7408@item @code{issue} (default: @var{%default-issue})
7409A string denoting the contents of the @file{/etc/issue} file, which is
1068f26b 7410displayed when users log in on a text console.
7313a52e
LC
7411
7412@item @code{packages} (default: @var{%base-packages})
7413The set of packages installed in the global profile, which is accessible
7414at @file{/run/current-system/profile}.
7415
1068f26b 7416The default set includes core utilities and it is good practice to
7313a52e
LC
7417install non-core utilities in user profiles (@pxref{Invoking guix
7418package}).
7419
7420@item @code{timezone}
7421A timezone identifying string---e.g., @code{"Europe/Paris"}.
7422
17c20385
LC
7423You can run the @command{tzselect} command to find out which timezone
7424string corresponds to your region. Choosing an invalid timezone name
7425causes @command{guix system} to fail.
7426
598e19dc
LC
7427@item @code{locale} (default: @code{"en_US.utf8"})
7428The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
7429Library Reference Manual}). @xref{Locales}, for more information.
7430
7431@item @code{locale-definitions} (default: @var{%default-locale-definitions})
7432The list of locale definitions to be compiled and that may be used at
7433run time. @xref{Locales}.
7313a52e 7434
34760ae7
LC
7435@item @code{locale-libcs} (default: @code{(list @var{glibc})})
7436The list of GNU@tie{}libc packages whose locale data and tools are used
7437to build the locale definitions. @xref{Locales}, for compatibility
7438considerations that justify this option.
7439
996ed739 7440@item @code{name-service-switch} (default: @var{%default-nss})
1068f26b 7441Configuration of the libc name service switch (NSS)---a
996ed739
LC
7442@code{<name-service-switch>} object. @xref{Name Service Switch}, for
7443details.
7444
7313a52e 7445@item @code{services} (default: @var{%base-services})
28d939af 7446A list of service objects denoting system services. @xref{Services}.
7313a52e
LC
7447
7448@item @code{pam-services} (default: @code{(base-pam-services)})
7449@cindex PAM
7450@cindex pluggable authentication modules
7451Linux @dfn{pluggable authentication module} (PAM) services.
7452@c FIXME: Add xref to PAM services section.
7453
7454@item @code{setuid-programs} (default: @var{%setuid-programs})
7455List of string-valued G-expressions denoting setuid programs.
7456@xref{Setuid Programs}.
7457
f5a9ffa0
AK
7458@item @code{sudoers-file} (default: @var{%sudoers-specification})
7459@cindex sudoers file
84765839
LC
7460The contents of the @file{/etc/sudoers} file as a file-like object
7461(@pxref{G-Expressions, @code{local-file} and @code{plain-file}}).
7313a52e
LC
7462
7463This file specifies which users can use the @command{sudo} command, what
7464they are allowed to do, and what privileges they may gain. The default
7465is that only @code{root} and members of the @code{wheel} group may use
7466@code{sudo}.
7467
7468@end table
7469@end deftp
7470
cf4a9129
LC
7471@node File Systems
7472@subsection File Systems
b81e1947 7473
cf4a9129 7474The list of file systems to be mounted is specified in the
1068f26b 7475@code{file-systems} field of the operating system declaration
cf4a9129
LC
7476(@pxref{Using the Configuration System}). Each file system is declared
7477using the @code{file-system} form, like this:
b81e1947
LC
7478
7479@example
cf4a9129
LC
7480(file-system
7481 (mount-point "/home")
7482 (device "/dev/sda3")
7483 (type "ext4"))
b81e1947
LC
7484@end example
7485
cf4a9129
LC
7486As usual, some of the fields are mandatory---those shown in the example
7487above---while others can be omitted. These are described below.
b81e1947 7488
cf4a9129
LC
7489@deftp {Data Type} file-system
7490Objects of this type represent file systems to be mounted. They
7491contain the following members:
5ff3c4b8 7492
cf4a9129
LC
7493@table @asis
7494@item @code{type}
7495This is a string specifying the type of the file system---e.g.,
7496@code{"ext4"}.
5ff3c4b8 7497
cf4a9129
LC
7498@item @code{mount-point}
7499This designates the place where the file system is to be mounted.
b81e1947 7500
cf4a9129
LC
7501@item @code{device}
7502This names the ``source'' of the file system. By default it is the name
7503of a node under @file{/dev}, but its meaning depends on the @code{title}
7504field described below.
401c53c4 7505
cf4a9129
LC
7506@item @code{title} (default: @code{'device})
7507This is a symbol that specifies how the @code{device} field is to be
7508interpreted.
401c53c4 7509
cf4a9129
LC
7510When it is the symbol @code{device}, then the @code{device} field is
7511interpreted as a file name; when it is @code{label}, then @code{device}
7512is interpreted as a partition label name; when it is @code{uuid},
7513@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 7514
661a1d79 7515UUIDs may be converted from their string representation (as shown by the
0767f6a6
LC
7516@command{tune2fs -l} command) using the @code{uuid} form@footnote{The
7517@code{uuid} form expects 16-byte UUIDs as defined in
7518@uref{https://tools.ietf.org/html/rfc4122, RFC@tie{}4122}. This is the
7519form of UUID used by the ext2 family of file systems and others, but it
7520is different from ``UUIDs'' found in FAT file systems, for instance.},
7521like this:
661a1d79
LC
7522
7523@example
7524(file-system
7525 (mount-point "/home")
7526 (type "ext4")
7527 (title 'uuid)
7528 (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")))
7529@end example
7530
cf4a9129 7531The @code{label} and @code{uuid} options offer a way to refer to disk
661a1d79
LC
7532partitions without having to hard-code their actual device
7533name@footnote{Note that, while it is tempting to use
7534@file{/dev/disk/by-uuid} and similar device names to achieve the same
7535result, this is not recommended: These special device nodes are created
7536by the udev daemon and may be unavailable at the time the device is
7537mounted.}.
da7cabd4 7538
1068f26b 7539However, when the source of a file system is a mapped device (@pxref{Mapped
5f86a66e
LC
7540Devices}), its @code{device} field @emph{must} refer to the mapped
7541device name---e.g., @file{/dev/mapper/root-partition}---and consequently
7542@code{title} must be set to @code{'device}. This is required so that
7543the system knows that mounting the file system depends on having the
7544corresponding device mapping established.
7545
cf4a9129
LC
7546@item @code{flags} (default: @code{'()})
7547This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
7548include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
7549access to special files), @code{no-suid} (ignore setuid and setgid
7550bits), and @code{no-exec} (disallow program execution.)
da7cabd4 7551
cf4a9129
LC
7552@item @code{options} (default: @code{#f})
7553This is either @code{#f}, or a string denoting mount options.
da7cabd4 7554
be21979d
LC
7555@item @code{mount?} (default: @code{#t})
7556This value indicates whether to automatically mount the file system when
7557the system is brought up. When set to @code{#f}, the file system gets
7558an entry in @file{/etc/fstab} (read by the @command{mount} command) but
7559is not automatically mounted.
7560
cf4a9129
LC
7561@item @code{needed-for-boot?} (default: @code{#f})
7562This Boolean value indicates whether the file system is needed when
7563booting. If that is true, then the file system is mounted when the
7564initial RAM disk (initrd) is loaded. This is always the case, for
7565instance, for the root file system.
da7cabd4 7566
cf4a9129
LC
7567@item @code{check?} (default: @code{#t})
7568This Boolean indicates whether the file system needs to be checked for
7569errors before being mounted.
f9cc8971 7570
4e469051
LC
7571@item @code{create-mount-point?} (default: @code{#f})
7572When true, the mount point is created if it does not exist yet.
7573
e51710d1 7574@item @code{dependencies} (default: @code{'()})
13fb1bd9
LC
7575This is a list of @code{<file-system>} or @code{<mapped-device>} objects
7576representing file systems that must be mounted or mapped devices that
7577must be opened before (and unmounted or closed after) this one.
e51710d1
LC
7578
7579As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is
7580a dependency of @file{/sys/fs/cgroup/cpu} and
7581@file{/sys/fs/cgroup/memory}.
7582
13fb1bd9
LC
7583Another example is a file system that depends on a mapped device, for
7584example for an encrypted partition (@pxref{Mapped Devices}).
cf4a9129
LC
7585@end table
7586@end deftp
da7cabd4 7587
a69576ea
LC
7588The @code{(gnu system file-systems)} exports the following useful
7589variables.
7590
7591@defvr {Scheme Variable} %base-file-systems
7592These are essential file systems that are required on normal systems,
cc0e575a 7593such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see
3392ce5d
LC
7594below.) Operating system declarations should always contain at least
7595these.
a69576ea
LC
7596@end defvr
7597
7f239fd3
LC
7598@defvr {Scheme Variable} %pseudo-terminal-file-system
7599This is the file system to be mounted as @file{/dev/pts}. It supports
7600@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
7601functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
7602Manual}). Pseudo-terminals are used by terminal emulators such as
7603@command{xterm}.
7604@end defvr
7605
db17ae5c
LC
7606@defvr {Scheme Variable} %shared-memory-file-system
7607This file system is mounted as @file{/dev/shm} and is used to support
7608memory sharing across processes (@pxref{Memory-mapped I/O,
7609@code{shm_open},, libc, The GNU C Library Reference Manual}).
7610@end defvr
7611
3392ce5d
LC
7612@defvr {Scheme Variable} %immutable-store
7613This file system performs a read-only ``bind mount'' of
7614@file{/gnu/store}, making it read-only for all the users including
7615@code{root}. This prevents against accidental modification by software
7616running as @code{root} or by system administrators.
7617
7618The daemon itself is still able to write to the store: it remounts it
7619read-write in its own ``name space.''
7620@end defvr
7621
a69576ea
LC
7622@defvr {Scheme Variable} %binary-format-file-system
7623The @code{binfmt_misc} file system, which allows handling of arbitrary
7624executable file types to be delegated to user space. This requires the
7625@code{binfmt.ko} kernel module to be loaded.
7626@end defvr
7627
7628@defvr {Scheme Variable} %fuse-control-file-system
7629The @code{fusectl} file system, which allows unprivileged users to mount
7630and unmount user-space FUSE file systems. This requires the
7631@code{fuse.ko} kernel module to be loaded.
7632@end defvr
7633
510f9d86
LC
7634@node Mapped Devices
7635@subsection Mapped Devices
7636
7637@cindex device mapping
7638@cindex mapped devices
7639The Linux kernel has a notion of @dfn{device mapping}: a block device,
7640such as a hard disk partition, can be @dfn{mapped} into another device,
97c8aef1 7641usually in @code{/dev/mapper/},
510f9d86
LC
7642with additional processing over the data that flows through
7643it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
7644concept of a ``mapped device'' and that of a file system: both boil down
7645to @emph{translating} input/output operations made on a file to
7646operations on its backing store. Thus, the Hurd implements mapped
7647devices, like file systems, using the generic @dfn{translator} mechanism
7648(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
7649typical example is encryption device mapping: all writes to the mapped
7650device are encrypted, and all reads are deciphered, transparently.
97c8aef1
AE
7651Guix extends this notion by considering any device or set of devices that
7652are @dfn{transformed} in some way to create a new device; for instance,
7653RAID devices are obtained by @dfn{assembling} several other devices, such
7654as hard disks or partitions, into a new one that behaves as one partition.
7655Other examples, not yet implemented, are LVM logical volumes.
510f9d86 7656
97c8aef1
AE
7657Mapped devices are declared using the @code{mapped-device} form,
7658defined as follows; for examples, see below.
510f9d86
LC
7659
7660@deftp {Data Type} mapped-device
7661Objects of this type represent device mappings that will be made when
7662the system boots up.
7663
9cb426b8
LC
7664@table @code
7665@item source
97c8aef1
AE
7666This is either a string specifying the name of the block device to be mapped,
7667such as @code{"/dev/sda3"}, or a list of such strings when several devices
7668need to be assembled for creating a new one.
510f9d86 7669
9cb426b8 7670@item target
97c8aef1
AE
7671This string specifies the name of the resulting mapped device. For
7672kernel mappers such as encrypted devices of type @code{luks-device-mapping},
7673specifying @code{"my-partition"} leads to the creation of
510f9d86 7674the @code{"/dev/mapper/my-partition"} device.
97c8aef1
AE
7675For RAID devices of type @code{raid-device-mapping}, the full device name
7676such as @code{"/dev/md0"} needs to be given.
510f9d86 7677
9cb426b8 7678@item type
510f9d86
LC
7679This must be a @code{mapped-device-kind} object, which specifies how
7680@var{source} is mapped to @var{target}.
7681@end table
7682@end deftp
7683
7684@defvr {Scheme Variable} luks-device-mapping
7685This defines LUKS block device encryption using the @command{cryptsetup}
1068f26b 7686command from the package with the same name. It relies on the
510f9d86
LC
7687@code{dm-crypt} Linux kernel module.
7688@end defvr
7689
97c8aef1
AE
7690@defvr {Scheme Variable} raid-device-mapping
7691This defines a RAID device, which is assembled using the @code{mdadm}
7692command from the package with the same name. It requires a Linux kernel
7693module for the appropriate RAID level to be loaded, such as @code{raid456}
7694for RAID-4, RAID-5 or RAID-6, or @code{raid10} for RAID-10.
7695@end defvr
7696
7697@cindex disk encryption
7698@cindex LUKS
7699The following example specifies a mapping from @file{/dev/sda3} to
7700@file{/dev/mapper/home} using LUKS---the
ddf1cd51 7701@url{https://gitlab.com/cryptsetup/cryptsetup,Linux Unified Key Setup}, a
97c8aef1
AE
7702standard mechanism for disk encryption.
7703The @file{/dev/mapper/home}
7704device can then be used as the @code{device} of a @code{file-system}
7705declaration (@pxref{File Systems}).
7706
7707@example
7708(mapped-device
7709 (source "/dev/sda3")
7710 (target "home")
7711 (type luks-device-mapping))
7712@end example
7713
7714Alternatively, to become independent of device numbering, one may obtain
7715the LUKS UUID (@dfn{unique identifier}) of the source device by a
7716command like:
7717
7718@example
7719cryptsetup luksUUID /dev/sda3
7720@end example
7721
7722and use it as follows:
7723
7724@example
7725(mapped-device
7726 (source (uuid "cb67fc72-0d54-4c88-9d4b-b225f30b0f44"))
7727 (target "home")
7728 (type luks-device-mapping))
7729@end example
7730
7731A RAID device formed of the partitions @file{/dev/sda1} and @file{/dev/sdb1}
7732may be declared as follows:
7733
7734@example
7735(mapped-device
7736 (source (list "/dev/sda1" "/dev/sdb1"))
7737 (target "/dev/md0")
7738 (type raid-device-mapping))
7739@end example
7740
7741The @file{/dev/md0} device can then be used as the @code{device} of a
7742@code{file-system} declaration (@pxref{File Systems}).
7743Note that the RAID level need not be given; it is chosen during the
7744initial creation and formatting of the RAID device and is determined
7745automatically later.
7746
7747
cf4a9129
LC
7748@node User Accounts
7749@subsection User Accounts
ee85f3db 7750
e32171ee
JD
7751@cindex users
7752@cindex accounts
7753@cindex user accounts
9bea87a5
LC
7754User accounts and groups are entirely managed through the
7755@code{operating-system} declaration. They are specified with the
7756@code{user-account} and @code{user-group} forms:
ee85f3db 7757
cf4a9129
LC
7758@example
7759(user-account
7760 (name "alice")
7761 (group "users")
24e752c0
LC
7762 (supplementary-groups '("wheel" ;allow use of sudo, etc.
7763 "audio" ;sound card
7764 "video" ;video devices such as webcams
7765 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
7766 (comment "Bob's sister")
7767 (home-directory "/home/alice"))
7768@end example
25083588 7769
9bea87a5
LC
7770When booting or upon completion of @command{guix system reconfigure},
7771the system ensures that only the user accounts and groups specified in
7772the @code{operating-system} declaration exist, and with the specified
7773properties. Thus, account or group creations or modifications made by
7774directly invoking commands such as @command{useradd} are lost upon
7775reconfiguration or reboot. This ensures that the system remains exactly
7776as declared.
7777
cf4a9129
LC
7778@deftp {Data Type} user-account
7779Objects of this type represent user accounts. The following members may
7780be specified:
ee85f3db 7781
cf4a9129
LC
7782@table @asis
7783@item @code{name}
7784The name of the user account.
ee85f3db 7785
cf4a9129 7786@item @code{group}
e32171ee 7787@cindex groups
cf4a9129
LC
7788This is the name (a string) or identifier (a number) of the user group
7789this account belongs to.
ee85f3db 7790
cf4a9129
LC
7791@item @code{supplementary-groups} (default: @code{'()})
7792Optionally, this can be defined as a list of group names that this
7793account belongs to.
ee85f3db 7794
cf4a9129
LC
7795@item @code{uid} (default: @code{#f})
7796This is the user ID for this account (a number), or @code{#f}. In the
7797latter case, a number is automatically chosen by the system when the
7798account is created.
ee85f3db 7799
cf4a9129 7800@item @code{comment} (default: @code{""})
1068f26b 7801A comment about the account, such as the account owner's full name.
c8c871d1 7802
cf4a9129
LC
7803@item @code{home-directory}
7804This is the name of the home directory for the account.
ee85f3db 7805
eb56ee02
LC
7806@item @code{create-home-directory?} (default: @code{#t})
7807Indicates whether the home directory of this account should be created
7808if it does not exist yet.
7809
cf4a9129
LC
7810@item @code{shell} (default: Bash)
7811This is a G-expression denoting the file name of a program to be used as
7812the shell (@pxref{G-Expressions}).
ee85f3db 7813
cf4a9129
LC
7814@item @code{system?} (default: @code{#f})
7815This Boolean value indicates whether the account is a ``system''
7816account. System accounts are sometimes treated specially; for instance,
7817graphical login managers do not list them.
ee85f3db 7818
1bd4e6db 7819@anchor{user-account-password}
cf4a9129 7820@item @code{password} (default: @code{#f})
eb59595c
LC
7821You would normally leave this field to @code{#f}, initialize user
7822passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
7823users change it with @command{passwd}. Passwords set with
7824@command{passwd} are of course preserved across reboot and
7825reconfiguration.
eb59595c
LC
7826
7827If you @emph{do} want to have a preset password for an account, then
7828this field must contain the encrypted password, as a string.
5d1f1177
LC
7829@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
7830on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 7831Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 7832
cf4a9129
LC
7833@end table
7834@end deftp
ee85f3db 7835
e32171ee 7836@cindex groups
cf4a9129 7837User group declarations are even simpler:
ee85f3db 7838
cf4a9129
LC
7839@example
7840(user-group (name "students"))
7841@end example
ee85f3db 7842
cf4a9129
LC
7843@deftp {Data Type} user-group
7844This type is for, well, user groups. There are just a few fields:
af8a56b8 7845
cf4a9129
LC
7846@table @asis
7847@item @code{name}
1068f26b 7848The name of the group.
ee85f3db 7849
cf4a9129
LC
7850@item @code{id} (default: @code{#f})
7851The group identifier (a number). If @code{#f}, a new number is
7852automatically allocated when the group is created.
ee85f3db 7853
c8fa3426
LC
7854@item @code{system?} (default: @code{#f})
7855This Boolean value indicates whether the group is a ``system'' group.
7856System groups have low numerical IDs.
7857
cf4a9129
LC
7858@item @code{password} (default: @code{#f})
7859What, user groups can have a password? Well, apparently yes. Unless
1068f26b 7860@code{#f}, this field specifies the password of the group.
ee85f3db 7861
cf4a9129
LC
7862@end table
7863@end deftp
401c53c4 7864
cf4a9129
LC
7865For convenience, a variable lists all the basic user groups one may
7866expect:
401c53c4 7867
cf4a9129
LC
7868@defvr {Scheme Variable} %base-groups
7869This is the list of basic user groups that users and/or packages expect
7870to be present on the system. This includes groups such as ``root'',
7871``wheel'', and ``users'', as well as groups used to control access to
7872specific devices such as ``audio'', ``disk'', and ``cdrom''.
7873@end defvr
401c53c4 7874
bf87f38a
LC
7875@defvr {Scheme Variable} %base-user-accounts
7876This is the list of basic system accounts that programs may expect to
7877find on a GNU/Linux system, such as the ``nobody'' account.
7878
7879Note that the ``root'' account is not included here. It is a
7880special-case and is automatically added whether or not it is specified.
7881@end defvr
7882
598e19dc
LC
7883@node Locales
7884@subsection Locales
7885
7886@cindex locale
7887A @dfn{locale} defines cultural conventions for a particular language
7888and region of the world (@pxref{Locales,,, libc, The GNU C Library
7889Reference Manual}). Each locale has a name that typically has the form
b2636518 7890@code{@var{language}_@var{territory}.@var{codeset}}---e.g.,
598e19dc
LC
7891@code{fr_LU.utf8} designates the locale for the French language, with
7892cultural conventions from Luxembourg, and using the UTF-8 encoding.
7893
7894@cindex locale definition
7895Usually, you will want to specify the default locale for the machine
7896using the @code{locale} field of the @code{operating-system} declaration
7897(@pxref{operating-system Reference, @code{locale}}).
7898
f5582b2c
LC
7899The selected locale is automatically added to the @dfn{locale
7900definitions} known to the system if needed, with its codeset inferred
7901from its name---e.g., @code{bo_CN.utf8} will be assumed to use the
7902@code{UTF-8} codeset. Additional locale definitions can be specified in
7903the @code{locale-definitions} slot of @code{operating-system}---this is
7904useful, for instance, if the codeset could not be inferred from the
7905locale name. The default set of locale definitions includes some widely
7906used locales, but not all the available locales, in order to save space.
7907
7908For instance, to add the North Frisian locale for Germany, the value of
7909that field may be:
598e19dc
LC
7910
7911@example
7912(cons (locale-definition
7913 (name "fy_DE.utf8") (source "fy_DE"))
7914 %default-locale-definitions)
7915@end example
7916
7917Likewise, to save space, one might want @code{locale-definitions} to
7918list only the locales that are actually used, as in:
7919
7920@example
7921(list (locale-definition
7922 (name "ja_JP.eucjp") (source "ja_JP")
7923 (charset "EUC-JP")))
7924@end example
7925
5c3c1427
LC
7926@vindex LOCPATH
7927The compiled locale definitions are available at
46bd6edd
LC
7928@file{/run/current-system/locale/X.Y}, where @code{X.Y} is the libc
7929version, which is the default location where the GNU@tie{}libc provided
7930by Guix looks for locale data. This can be overridden using the
7931@code{LOCPATH} environment variable (@pxref{locales-and-locpath,
5c3c1427
LC
7932@code{LOCPATH} and locale packages}).
7933
598e19dc
LC
7934The @code{locale-definition} form is provided by the @code{(gnu system
7935locale)} module. Details are given below.
7936
7937@deftp {Data Type} locale-definition
7938This is the data type of a locale definition.
7939
7940@table @asis
7941
7942@item @code{name}
7943The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
7944Reference Manual}, for more information on locale names.
7945
7946@item @code{source}
7947The name of the source for that locale. This is typically the
7948@code{@var{language}_@var{territory}} part of the locale name.
7949
7950@item @code{charset} (default: @code{"UTF-8"})
7951The ``character set'' or ``code set'' for that locale,
7952@uref{http://www.iana.org/assignments/character-sets, as defined by
7953IANA}.
7954
7955@end table
7956@end deftp
7957
7958@defvr {Scheme Variable} %default-locale-definitions
1068f26b 7959A list of commonly used UTF-8 locales, used as the default
b2636518 7960value of the @code{locale-definitions} field of @code{operating-system}
598e19dc 7961declarations.
b2636518
LC
7962
7963@cindex locale name
7964@cindex normalized codeset in locale names
7965These locale definitions use the @dfn{normalized codeset} for the part
7966that follows the dot in the name (@pxref{Using gettextized software,
7967normalized codeset,, libc, The GNU C Library Reference Manual}). So for
7968instance it has @code{uk_UA.utf8} but @emph{not}, say,
7969@code{uk_UA.UTF-8}.
598e19dc 7970@end defvr
401c53c4 7971
34760ae7
LC
7972@subsubsection Locale Data Compatibility Considerations
7973
7974@cindex incompatibility, of locale data
7975@code{operating-system} declarations provide a @code{locale-libcs} field
7976to specify the GNU@tie{}libc packages that are used to compile locale
7977declarations (@pxref{operating-system Reference}). ``Why would I
7978care?'', you may ask. Well, it turns out that the binary format of
7979locale data is occasionally incompatible from one libc version to
7980another.
7981
7982@c See <https://sourceware.org/ml/libc-alpha/2015-09/msg00575.html>
7983@c and <https://lists.gnu.org/archive/html/guix-devel/2015-08/msg00737.html>.
7984For instance, a program linked against libc version 2.21 is unable to
7985read locale data produced with libc 2.22; worse, that program
7986@emph{aborts} instead of simply ignoring the incompatible locale
7987data@footnote{Versions 2.23 and later of GNU@tie{}libc will simply skip
7988the incompatible locale data, which is already an improvement.}.
7989Similarly, a program linked against libc 2.22 can read most, but not
201fff9e 7990all, of the locale data from libc 2.21 (specifically, @code{LC_COLLATE}
34760ae7
LC
7991data is incompatible); thus calls to @code{setlocale} may fail, but
7992programs will not abort.
7993
7994The ``problem'' in GuixSD is that users have a lot of freedom: They can
7995choose whether and when to upgrade software in their profiles, and might
7996be using a libc version different from the one the system administrator
7997used to build the system-wide locale data.
7998
7999Fortunately, unprivileged users can also install their own locale data
8000and define @var{GUIX_LOCPATH} accordingly (@pxref{locales-and-locpath,
8001@code{GUIX_LOCPATH} and locale packages}).
8002
8003Still, it is best if the system-wide locale data at
8004@file{/run/current-system/locale} is built for all the libc versions
8005actually in use on the system, so that all the programs can access
8006it---this is especially crucial on a multi-user system. To do that, the
8007administrator can specify several libc packages in the
8008@code{locale-libcs} field of @code{operating-system}:
8009
8010@example
8011(use-package-modules base)
8012
8013(operating-system
8014 ;; @dots{}
8015 (locale-libcs (list glibc-2.21 (canonical-package glibc))))
8016@end example
8017
8018This example would lead to a system containing locale definitions for
8019both libc 2.21 and the current version of libc in
8020@file{/run/current-system/locale}.
8021
8022
cf4a9129
LC
8023@node Services
8024@subsection Services
401c53c4 8025
cf4a9129
LC
8026@cindex system services
8027An important part of preparing an @code{operating-system} declaration is
8028listing @dfn{system services} and their configuration (@pxref{Using the
8029Configuration System}). System services are typically daemons launched
8030when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
8031configuring network access.
8032
e8b652d4
LC
8033GuixSD has a broad definition of ``service'' (@pxref{Service
8034Composition}), but many services are managed by the GNU@tie{}Shepherd
8035(@pxref{Shepherd Services}). On a running system, the @command{herd}
8036command allows you to list the available services, show their status,
8037start and stop them, or do other specific operations (@pxref{Jump
8038Start,,, shepherd, The GNU Shepherd Manual}). For example:
d8b94dbd
LC
8039
8040@example
dd17bc38 8041# herd status
d8b94dbd
LC
8042@end example
8043
8044The above command, run as @code{root}, lists the currently defined
dd17bc38 8045services. The @command{herd doc} command shows a synopsis of the given
d8b94dbd
LC
8046service:
8047
8048@example
dd17bc38 8049# herd doc nscd
d8b94dbd
LC
8050Run libc's name service cache daemon (nscd).
8051@end example
8052
8053The @command{start}, @command{stop}, and @command{restart} sub-commands
8054have the effect you would expect. For instance, the commands below stop
8055the nscd service and restart the Xorg display server:
8056
8057@example
dd17bc38 8058# herd stop nscd
d8b94dbd 8059Service nscd has been stopped.
dd17bc38 8060# herd restart xorg-server
d8b94dbd
LC
8061Service xorg-server has been stopped.
8062Service xorg-server has been started.
8063@end example
401c53c4 8064
cf4a9129 8065The following sections document the available services, starting with
d8b94dbd
LC
8066the core services, that may be used in an @code{operating-system}
8067declaration.
401c53c4 8068
cf4a9129
LC
8069@menu
8070* Base Services:: Essential system services.
c311089b 8071* Scheduled Job Execution:: The mcron service.
92c03a87 8072* Log Rotation:: The rottlog service.
cf4a9129
LC
8073* Networking Services:: Network setup, SSH daemon, etc.
8074* X Window:: Graphical display.
f2ec23d1 8075* Printing Services:: Local and remote printer support.
fe1a39d3 8076* Desktop Services:: D-Bus and desktop services.
105369a4 8077* Database Services:: SQL databases.
d8c18af8 8078* Mail Services:: IMAP, POP3, SMTP, and all that.
859e367d 8079* Kerberos Services:: Kerberos services.
58724c48 8080* Web Services:: Web servers.
eb419bc9 8081* Network File System:: NFS related services.
a7cf4eb6 8082* Continuous Integration:: The Cuirass service.
dbc6d370 8083* Miscellaneous Services:: Other services.
cf4a9129 8084@end menu
401c53c4 8085
cf4a9129
LC
8086@node Base Services
8087@subsubsection Base Services
a1ba8475 8088
cf4a9129
LC
8089The @code{(gnu services base)} module provides definitions for the basic
8090services that one expects from the system. The services exported by
8091this module are listed below.
401c53c4 8092
cf4a9129 8093@defvr {Scheme Variable} %base-services
31771497
LC
8094This variable contains a list of basic services (@pxref{Service Types
8095and Services}, for more information on service objects) one would
cf4a9129 8096expect from the system: a login service (mingetty) on each tty, syslogd,
1068f26b 8097the libc name service cache daemon (nscd), the udev device manager, and
cf4a9129 8098more.
401c53c4 8099
cf4a9129
LC
8100This is the default value of the @code{services} field of
8101@code{operating-system} declarations. Usually, when customizing a
8102system, you will want to append services to @var{%base-services}, like
8103this:
401c53c4 8104
cf4a9129 8105@example
fa1e31b8 8106(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
8107@end example
8108@end defvr
401c53c4 8109
be1c2c54 8110@deffn {Scheme Procedure} host-name-service @var{name}
cf4a9129
LC
8111Return a service that sets the host name to @var{name}.
8112@end deffn
401c53c4 8113
317d3b47
DC
8114@deffn {Scheme Procedure} login-service @var{config}
8115Return a service to run login according to @var{config}, a
8116@code{<login-configuration>} object, which specifies the message of the day,
8117among other things.
8118@end deffn
8119
8120@deftp {Data Type} login-configuration
8121This is the data type representing the configuration of login.
8122
8123@table @asis
8124
8125@item @code{motd}
e32171ee 8126@cindex message of the day
317d3b47
DC
8127A file-like object containing the ``message of the day''.
8128
8129@item @code{allow-empty-passwords?} (default: @code{#t})
8130Allow empty passwords by default so that first-time users can log in when
8131the 'root' account has just been created.
8132
8133@end table
8134@end deftp
8135
66e4f01c
LC
8136@deffn {Scheme Procedure} mingetty-service @var{config}
8137Return a service to run mingetty according to @var{config}, a
8138@code{<mingetty-configuration>} object, which specifies the tty to run, among
8139other things.
cf4a9129 8140@end deffn
401c53c4 8141
66e4f01c
LC
8142@deftp {Data Type} mingetty-configuration
8143This is the data type representing the configuration of Mingetty, which
8144implements console log-in.
8145
8146@table @asis
8147
8148@item @code{tty}
8149The name of the console this Mingetty runs on---e.g., @code{"tty1"}.
8150
66e4f01c
LC
8151@item @code{auto-login} (default: @code{#f})
8152When true, this field must be a string denoting the user name under
f9b9a033 8153which the system automatically logs in. When it is @code{#f}, a
66e4f01c
LC
8154user name and password must be entered to log in.
8155
8156@item @code{login-program} (default: @code{#f})
8157This must be either @code{#f}, in which case the default log-in program
8158is used (@command{login} from the Shadow tool suite), or a gexp denoting
8159the name of the log-in program.
8160
8161@item @code{login-pause?} (default: @code{#f})
8162When set to @code{#t} in conjunction with @var{auto-login}, the user
8163will have to press a key before the log-in shell is launched.
8164
8165@item @code{mingetty} (default: @var{mingetty})
8166The Mingetty package to use.
8167
8168@end table
8169@end deftp
8170
46ec2707
DC
8171@deffn {Scheme Procedure} kmscon-service-type @var{config}
8172Return a service to run @uref{https://www.freedesktop.org/wiki/Software/kmscon,kmscon}
8173according to @var{config}, a @code{<kmscon-configuration>} object, which
8174specifies the tty to run, among other things.
8175@end deffn
8176
8177@deftp {Data Type} kmscon-configuration
8178This is the data type representing the configuration of Kmscon, which
8179implements console log-in.
8180
8181@table @asis
8182
8183@item @code{virtual-terminal}
8184The name of the console this Kmscon runs on---e.g., @code{"tty1"}.
8185
8186@item @code{login-program} (default: @code{#~(string-append #$shadow "/bin/login")})
8187A gexp denoting the name of the log-in program. The default log-in program is
8188@command{login} from the Shadow tool suite.
8189
8190@item @code{login-arguments} (default: @code{'("-p")})
8191A list of arguments to pass to @command{login}.
8192
8193@item @code{hardware-acceleration?} (default: #f)
8194Whether to use hardware acceleration.
8195
8196@item @code{kmscon} (default: @var{kmscon})
8197The Kmscon package to use.
8198
8199@end table
8200@end deftp
8201
6454b333
LC
8202@cindex name service cache daemon
8203@cindex nscd
be1c2c54 8204@deffn {Scheme Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4aee6e60 8205 [#:name-services '()]
1068f26b 8206Return a service that runs the libc name service cache daemon (nscd) with the
b893f1ae
LC
8207given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
8208Service Switch}, for an example.
cf4a9129 8209@end deffn
401c53c4 8210
6454b333
LC
8211@defvr {Scheme Variable} %nscd-default-configuration
8212This is the default @code{<nscd-configuration>} value (see below) used
1068f26b 8213by @code{nscd-service}. It uses the caches defined by
6454b333
LC
8214@var{%nscd-default-caches}; see below.
8215@end defvr
8216
8217@deftp {Data Type} nscd-configuration
1068f26b 8218This is the data type representing the name service cache daemon (nscd)
6454b333
LC
8219configuration.
8220
8221@table @asis
8222
b893f1ae
LC
8223@item @code{name-services} (default: @code{'()})
8224List of packages denoting @dfn{name services} that must be visible to
8225the nscd---e.g., @code{(list @var{nss-mdns})}.
8226
8227@item @code{glibc} (default: @var{glibc})
8228Package object denoting the GNU C Library providing the @command{nscd}
8229command.
8230
6454b333 8231@item @code{log-file} (default: @code{"/var/log/nscd.log"})
1068f26b 8232Name of the nscd log file. This is where debugging output goes when
6454b333
LC
8233@code{debug-level} is strictly positive.
8234
8235@item @code{debug-level} (default: @code{0})
1068f26b 8236Integer denoting the debugging levels. Higher numbers mean that more
6454b333
LC
8237debugging output is logged.
8238
8239@item @code{caches} (default: @var{%nscd-default-caches})
8240List of @code{<nscd-cache>} objects denoting things to be cached; see
8241below.
8242
8243@end table
8244@end deftp
8245
8246@deftp {Data Type} nscd-cache
8247Data type representing a cache database of nscd and its parameters.
8248
8249@table @asis
8250
8251@item @code{database}
8252This is a symbol representing the name of the database to be cached.
8253Valid values are @code{passwd}, @code{group}, @code{hosts}, and
8254@code{services}, which designate the corresponding NSS database
8255(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
8256
8257@item @code{positive-time-to-live}
8258@itemx @code{negative-time-to-live} (default: @code{20})
8259A number representing the number of seconds during which a positive or
8260negative lookup result remains in cache.
8261
8262@item @code{check-files?} (default: @code{#t})
8263Whether to check for updates of the files corresponding to
8264@var{database}.
8265
8266For instance, when @var{database} is @code{hosts}, setting this flag
8267instructs nscd to check for updates in @file{/etc/hosts} and to take
8268them into account.
8269
8270@item @code{persistent?} (default: @code{#t})
8271Whether the cache should be stored persistently on disk.
8272
8273@item @code{shared?} (default: @code{#t})
8274Whether the cache should be shared among users.
8275
8276@item @code{max-database-size} (default: 32@tie{}MiB)
8277Maximum size in bytes of the database cache.
8278
8279@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
8280@c settings, so leave them out.
8281
8282@end table
8283@end deftp
8284
8285@defvr {Scheme Variable} %nscd-default-caches
8286List of @code{<nscd-cache>} objects used by default by
1068f26b 8287@code{nscd-configuration} (see above).
6454b333
LC
8288
8289It enables persistent and aggressive caching of service and host name
8290lookups. The latter provides better host name lookup performance,
8291resilience in the face of unreliable name servers, and also better
8292privacy---often the result of host name lookups is in local cache, so
8293external name servers do not even need to be queried.
8294@end defvr
8295
ec2e2f6c 8296@anchor{syslog-configuration-type}
e32171ee
JD
8297@cindex syslog
8298@cindex logging
ec2e2f6c
DC
8299@deftp {Data Type} syslog-configuration
8300This data type represents the configuration of the syslog daemon.
6454b333 8301
ec2e2f6c
DC
8302@table @asis
8303@item @code{syslogd} (default: @code{#~(string-append #$inetutils "/libexec/syslogd")})
8304The syslog daemon to use.
8305
8306@item @code{config-file} (default: @code{%default-syslog.conf})
8307The syslog configuration file to use.
8308
8309@end table
8310@end deftp
8311
8312@anchor{syslog-service}
e32171ee 8313@cindex syslog
ec2e2f6c
DC
8314@deffn {Scheme Procedure} syslog-service @var{config}
8315Return a service that runs a syslog daemon according to @var{config}.
44abcb28
LC
8316
8317@xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
8318information on the configuration file syntax.
cf4a9129 8319@end deffn
401c53c4 8320
0adfe95a
LC
8321@anchor{guix-configuration-type}
8322@deftp {Data Type} guix-configuration
8323This data type represents the configuration of the Guix build daemon.
8324@xref{Invoking guix-daemon}, for more information.
8325
8326@table @asis
8327@item @code{guix} (default: @var{guix})
8328The Guix package to use.
401c53c4 8329
0adfe95a
LC
8330@item @code{build-group} (default: @code{"guixbuild"})
8331Name of the group for build user accounts.
401c53c4 8332
0adfe95a
LC
8333@item @code{build-accounts} (default: @code{10})
8334Number of build user accounts to create.
401c53c4 8335
0adfe95a 8336@item @code{authorize-key?} (default: @code{#t})
e32171ee 8337@cindex substitutes, authorization thereof
5b58c28b
LC
8338Whether to authorize the substitute keys listed in
8339@code{authorized-keys}---by default that of @code{hydra.gnu.org}
0adfe95a
LC
8340(@pxref{Substitutes}).
8341
5b58c28b
LC
8342@vindex %default-authorized-guix-keys
8343@item @code{authorized-keys} (default: @var{%default-authorized-guix-keys})
8344The list of authorized key files for archive imports, as a list of
8345string-valued gexps (@pxref{Invoking guix archive}). By default, it
8346contains that of @code{hydra.gnu.org} (@pxref{Substitutes}).
8347
0adfe95a
LC
8348@item @code{use-substitutes?} (default: @code{#t})
8349Whether to use substitutes.
8350
b0b9f6e0
LC
8351@item @code{substitute-urls} (default: @var{%default-substitute-urls})
8352The list of URLs where to look for substitutes by default.
8353
0adfe95a
LC
8354@item @code{extra-options} (default: @code{'()})
8355List of extra command-line options for @command{guix-daemon}.
8356
dc0ef095
LC
8357@item @code{log-file} (default: @code{"/var/log/guix-daemon.log"})
8358File where @command{guix-daemon}'s standard output and standard error
8359are written.
8360
0adfe95a 8361@item @code{lsof} (default: @var{lsof})
f78903f3 8362The lsof package to use.
0adfe95a
LC
8363
8364@end table
8365@end deftp
8366
8367@deffn {Scheme Procedure} guix-service @var{config}
8368Return a service that runs the Guix build daemon according to
8369@var{config}.
cf4a9129 8370@end deffn
a1ba8475 8371
be1c2c54 8372@deffn {Scheme Procedure} udev-service [#:udev udev]
cf4a9129
LC
8373Run @var{udev}, which populates the @file{/dev} directory dynamically.
8374@end deffn
401c53c4 8375
a535e122
LF
8376@deffn {Scheme Procedure} urandom-seed-service @var{#f}
8377Save some entropy in @var{%random-seed-file} to seed @file{/dev/urandom}
8378when rebooting.
8379@end deffn
8380
8381@defvr {Scheme Variable} %random-seed-file
8382This is the name of the file where some random bytes are saved by
8383@var{urandom-seed-service} to seed @file{/dev/urandom} when rebooting.
8384It defaults to @file{/var/lib/random-seed}.
8385@end defvr
8386
e32171ee
JD
8387@cindex keymap
8388@cindex keyboard
b3d05f48 8389@deffn {Scheme Procedure} console-keymap-service @var{files} ...
dedb8d5e 8390@cindex keyboard layout
b3d05f48
AK
8391Return a service to load console keymaps from @var{files} using
8392@command{loadkeys} command. Most likely, you want to load some default
8393keymap, which can be done like this:
8394
8395@example
8396(console-keymap-service "dvorak")
8397@end example
8398
8399Or, for example, for a Swedish keyboard, you may need to combine
8400the following keymaps:
8401@example
8402(console-keymap-service "se-lat6" "se-fi-lat6")
8403@end example
8404
8405Also you can specify a full file name (or file names) of your keymap(s).
8406See @code{man loadkeys} for details.
8407
5eca9459
AK
8408@end deffn
8409
e32171ee
JD
8410@cindex mouse
8411@cindex gpm
1aaf116d 8412@deffn {Scheme Procedure} gpm-service [#:gpm @var{gpm}] @
8664cc88
LC
8413 [#:options]
8414Run @var{gpm}, the general-purpose mouse daemon, with the given
8415command-line @var{options}. GPM allows users to use the mouse in the console,
8416notably to select, copy, and paste text. The default value of @var{options}
8417uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
8418
8419This service is not part of @var{%base-services}.
8420@end deffn
8421
1c52181f
LC
8422@anchor{guix-publish-service}
8423@deffn {Scheme Procedure} guix-publish-service [#:guix @var{guix}] @
8424 [#:port 80] [#:host "localhost"]
8425Return a service that runs @command{guix publish} listening on @var{host}
8426and @var{port} (@pxref{Invoking guix publish}).
8427
8428This assumes that @file{/etc/guix} already contains a signing key pair as
8429created by @command{guix archive --generate-key} (@pxref{Invoking guix
8430archive}). If that is not the case, the service will fail to start.
8431@end deffn
8432
b58cbf9a
DC
8433@anchor{rngd-service}
8434@deffn {Scheme Procedure} rngd-service [#:rng-tools @var{rng-tools}] @
8435 [#:device "/dev/hwrng"]
8436Return a service that runs the @command{rngd} program from @var{rng-tools}
8437to add @var{device} to the kernel's entropy pool. The service will fail if
8438@var{device} does not exist.
8439@end deffn
a69576ea 8440
909147e4
RW
8441@anchor{pam-limits-service}
8442@cindex session limits
8443@cindex ulimit
8444@cindex priority
8445@deffn {Scheme Procedure} pam-limits-service [#:limits @var{limits}]
8446
8447Return a service that installs a configuration file for the
8448@uref{http://linux-pam.org/Linux-PAM-html/sag-pam_limits.html,
8449@code{pam_limits} module}. The procedure optionally takes a list of
8450@code{pam-limits-entry} values, which can be used to specify
8451@code{ulimit} limits and nice priority limits to user sessions.
8452
8453The following limits definition sets two hard and soft limits for all
8454login sessions of users in the @code{realtime} group:
8455
8456@example
8457(pam-limits-service
8458 (list
8459 (pam-limits-entry "@@realtime" 'both 'rtprio 99)
8460 (pam-limits-entry "@@realtime" 'both 'memlock 'unlimited)))
8461@end example
8462
8463The first entry increases the maximum realtime priority for
8464non-privileged processes; the second entry lifts any restriction of the
8465maximum address space that can be locked in memory. These settings are
8466commonly used for real-time audio systems.
8467@end deffn
8468
c311089b
LC
8469@node Scheduled Job Execution
8470@subsubsection Scheduled Job Execution
8471
8472@cindex cron
e32171ee 8473@cindex mcron
c311089b
LC
8474@cindex scheduling jobs
8475The @code{(gnu services mcron)} module provides an interface to
8476GNU@tie{}mcron, a daemon to run jobs at scheduled times (@pxref{Top,,,
8477mcron, GNU@tie{}mcron}). GNU@tie{}mcron is similar to the traditional
8478Unix @command{cron} daemon; the main difference is that it is
8479implemented in Guile Scheme, which provides a lot of flexibility when
8480specifying the scheduling of jobs and their actions.
8481
8ac6282c 8482The example below defines an operating system that runs the
c311089b 8483@command{updatedb} (@pxref{Invoking updatedb,,, find, Finding Files})
8ac6282c
LC
8484and the @command{guix gc} commands (@pxref{Invoking guix gc}) daily, as
8485well as the @command{mkid} command on behalf of an unprivileged user
8486(@pxref{mkid invocation,,, idutils, ID Database Utilities}). It uses
8487gexps to introduce job definitions that are passed to mcron
8488(@pxref{G-Expressions}).
c311089b
LC
8489
8490@lisp
8491(use-modules (guix) (gnu) (gnu services mcron))
8ac6282c 8492(use-package-modules base idutils)
c311089b
LC
8493
8494(define updatedb-job
8ac6282c
LC
8495 ;; Run 'updatedb' at 3AM every day. Here we write the
8496 ;; job's action as a Scheme procedure.
c311089b 8497 #~(job '(next-hour '(3))
8ac6282c
LC
8498 (lambda ()
8499 (execl (string-append #$findutils "/bin/updatedb")
8500 "updatedb"
8501 "--prunepaths=/tmp /var/tmp /gnu/store"))))
c311089b
LC
8502
8503(define garbage-collector-job
8504 ;; Collect garbage 5 minutes after midnight every day.
8ac6282c 8505 ;; The job's action is a shell command.
c311089b
LC
8506 #~(job "5 0 * * *" ;Vixie cron syntax
8507 "guix gc -F 1G"))
8508
80d944b7 8509(define idutils-job
8ac6282c
LC
8510 ;; Update the index database as user "charlie" at 12:15PM
8511 ;; and 19:15PM. This runs from the user's home directory.
8512 #~(job '(next-minute-from (next-hour '(12 19)) '(15))
8513 (string-append #$idutils "/bin/mkid src")
8514 #:user "charlie"))
8515
c311089b
LC
8516(operating-system
8517 ;; @dots{}
8518 (services (cons (mcron-service (list garbage-collector-job
8ac6282c
LC
8519 updatedb-job
8520 idutils-job))
c311089b
LC
8521 %base-services)))
8522@end lisp
8523
8524@xref{Guile Syntax, mcron job specifications,, mcron, GNU@tie{}mcron},
8525for more information on mcron job specifications. Below is the
8526reference of the mcron service.
8527
8528@deffn {Scheme Procedure} mcron-service @var{jobs} [#:mcron @var{mcron2}]
8529Return an mcron service running @var{mcron} that schedules @var{jobs}, a
8530list of gexps denoting mcron job specifications.
8531
8532This is a shorthand for:
8533@example
80d944b7
LC
8534(service mcron-service-type
8535 (mcron-configuration (mcron mcron) (jobs jobs)))
c311089b
LC
8536@end example
8537@end deffn
8538
8539@defvr {Scheme Variable} mcron-service-type
8540This is the type of the @code{mcron} service, whose value is an
8541@code{mcron-configuration} object.
8542
8543This service type can be the target of a service extension that provides
8544it additional job specifications (@pxref{Service Composition}). In
80d944b7 8545other words, it is possible to define services that provide additional
c311089b
LC
8546mcron jobs to run.
8547@end defvr
8548
8549@deftp {Data Type} mcron-configuration
8550Data type representing the configuration of mcron.
8551
8552@table @asis
8553@item @code{mcron} (default: @var{mcron2})
8554The mcron package to use.
8555
8556@item @code{jobs}
8557This is a list of gexps (@pxref{G-Expressions}), where each gexp
8558corresponds to an mcron job specification (@pxref{Syntax, mcron job
8559specifications,, mcron, GNU@tie{}mcron}).
8560@end table
8561@end deftp
8562
8563
92c03a87
JN
8564@node Log Rotation
8565@subsubsection Log Rotation
8566
8567@cindex rottlog
8568@cindex log rotation
e32171ee 8569@cindex logging
92c03a87
JN
8570Log files such as those found in @file{/var/log} tend to grow endlessly,
8571so it's a good idea to @dfn{rotate} them once in a while---i.e., archive
8572their contents in separate files, possibly compressed. The @code{(gnu
8573services admin)} module provides an interface to GNU@tie{}Rot[t]log, a
8574log rotation tool (@pxref{Top,,, rottlog, GNU Rot[t]log Manual}).
8575
8576The example below defines an operating system that provides log rotation
8577with the default settings.
8578
8579@lisp
8580(use-modules (guix) (gnu))
8581(use-service-modules admin mcron)
8582(use-package-modules base idutils)
8583
8584(operating-system
8585 ;; @dots{}
8586 (services (cons* (mcron-service)
8587 (service rottlog-service-type (rottlog-configuration))
8588 %base-services)))
8589@end lisp
8590
8591@defvr {Scheme Variable} rottlog-service-type
8592This is the type of the Rottlog service, whose value is a
8593@code{rottlog-configuration} object.
8594
8595This service type can define mcron jobs (@pxref{Scheduled Job
8596Execution}) to run the rottlog service.
8597@end defvr
8598
8599@deftp {Data Type} rottlog-configuration
8600Data type representing the configuration of rottlog.
8601
8602@table @asis
8603@item @code{rottlog} (default: @code{rottlog})
8604The Rottlog package to use.
8605
8606@item @code{rc-file} (default: @code{(file-append rottlog "/etc/rc")})
8607The Rottlog configuration file to use (@pxref{Mandatory RC Variables,,,
8608rottlog, GNU Rot[t]log Manual}).
8609
8610@item @code{periodic-rotations} (default: @code{`(("weekly" %default-rotatations))})
8611A list of Rottlog period-name/period-config tuples.
8612
8613For example, taking an example from the Rottlog manual (@pxref{Period
8614Related File Examples,,, rottlog, GNU Rot[t]log Manual}), a valid tuple
8615might be:
8616
8617@example
8618("daily" ,(plain-file "daily"
8619 "\
8620 /var/log/apache/* @{
8621 storedir apache-archives
8622 rotate 6
8623 notifempty
8624 nocompress
8625 @}"))
8626@end example
8627
8628@item @code{jobs}
8629This is a list of gexps where each gexp corresponds to an mcron job
8630specification (@pxref{Scheduled Job Execution}).
8631@end table
8632@end deftp
8633
8634@defvr {Scheme Variable} %default-rotations
8635Specifies weekly rotation of @var{%rotated-files} and
8636@code{"/var/log/shepherd.log"}.
8637@end defvr
8638
8639@defvr {Scheme Variable} %rotated-files
8640The list of syslog-controlled files to be rotated. By default it is:
8641@code{'("/var/log/messages" "/var/log/secure")}.
8642@end defvr
8643
cf4a9129
LC
8644@node Networking Services
8645@subsubsection Networking Services
401c53c4 8646
fa1e31b8 8647The @code{(gnu services networking)} module provides services to configure
cf4a9129 8648the network interface.
a1ba8475 8649
a023cca8 8650@cindex DHCP, networking service
be1c2c54 8651@deffn {Scheme Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
a023cca8
LC
8652Return a service that runs @var{dhcp}, a Dynamic Host Configuration
8653Protocol (DHCP) client, on all the non-loopback network interfaces.
8654@end deffn
8655
be1c2c54 8656@deffn {Scheme Procedure} static-networking-service @var{interface} @var{ip} @
1f9803c2 8657 [#:netmask #f] [#:gateway #f] [#:name-servers @code{'()}]
cf4a9129 8658Return a service that starts @var{interface} with address @var{ip}. If
1f9803c2
LC
8659@var{netmask} is true, use it as the network mask. If @var{gateway} is true,
8660it must be a string specifying the default network gateway.
cf4a9129 8661@end deffn
8b315a6d 8662
b7d0c494 8663@cindex wicd
e32171ee
JD
8664@cindex wireless
8665@cindex WiFi
87f40011 8666@cindex network management
be1c2c54 8667@deffn {Scheme Procedure} wicd-service [#:wicd @var{wicd}]
87f40011
LC
8668Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a network
8669management daemon that aims to simplify wired and wireless networking.
8670
8671This service adds the @var{wicd} package to the global profile, providing
8672several commands to interact with the daemon and configure networking:
8673@command{wicd-client}, a graphical user interface, and the @command{wicd-cli}
8674and @command{wicd-curses} user interfaces.
b7d0c494
MW
8675@end deffn
8676
c0a9589d
SB
8677@cindex NetworkManager
8678@deffn {Scheme Procedure} network-manager-service @
8679 [#:network-manager @var{network-manager}]
8680Return a service that runs NetworkManager, a network connection manager
1068f26b 8681attempting to keep network connectivity active when available.
c0a9589d
SB
8682@end deffn
8683
76192896
EF
8684@cindex Connman
8685@deffn {Scheme Procedure} connman-service @
8686 [#:connman @var{connman}]
8687Return a service that runs @url{https://01.org/connman,Connman}, a network
8688connection manager.
8689
8690This service adds the @var{connman} package to the global profile, providing
8691several the @command{connmanctl} command to interact with the daemon and
8692configure networking."
8693@end deffn
8694
2cccbc2a 8695@cindex WPA Supplicant
cbf1024e
LC
8696@defvr {Scheme Variable} wpa-supplicant-service-type
8697This is the service type to run @url{https://w1.fi/wpa_supplicant/,WPA
2cccbc2a 8698supplicant}, an authentication daemon required to authenticate against
cbf1024e 8699encrypted WiFi or ethernet networks. It is configured to listen for
2cccbc2a 8700requests on D-Bus.
cbf1024e
LC
8701
8702The value of this service is the @code{wpa-supplicant} package to use.
8703Thus, it can be instantiated like this:
8704
8705@lisp
8706(use-modules (gnu services networking)
8707 (gnu packages admin))
8708
9747d189 8709(service wpa-supplicant-service-type wpa-supplicant)
cbf1024e
LC
8710@end lisp
8711@end defvr
2cccbc2a 8712
e32171ee
JD
8713@cindex NTP
8714@cindex real time clock
be1c2c54 8715@deffn {Scheme Procedure} ntp-service [#:ntp @var{ntp}] @
dc0322b5
LC
8716 [#:servers @var{%ntp-servers}] @
8717 [#:allow-large-adjustment? #f]
63854bcb
LC
8718Return a service that runs the daemon from @var{ntp}, the
8719@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
8720keep the system clock synchronized with that of @var{servers}.
dc0322b5
LC
8721@var{allow-large-adjustment?} determines whether @command{ntpd} is allowed to
8722make an initial adjustment of more than 1,000 seconds.
63854bcb
LC
8723@end deffn
8724
8725@defvr {Scheme Variable} %ntp-servers
8726List of host names used as the default NTP servers.
8727@end defvr
8728
e32171ee 8729@cindex Tor
375c6108
LC
8730@deffn {Scheme Procedure} tor-service [@var{config-file}] [#:tor @var{tor}]
8731Return a service to run the @uref{https://torproject.org, Tor} anonymous
8732networking daemon.
8b315a6d 8733
375c6108 8734The daemon runs as the @code{tor} unprivileged user. It is passed
6331bde7
LC
8735@var{config-file}, a file-like object, with an additional @code{User tor} line
8736and lines for hidden services added via @code{tor-hidden-service}. Run
8737@command{man tor} for information about the configuration file.
8738@end deffn
8739
24a8ef3b 8740@cindex hidden service
6331bde7
LC
8741@deffn {Scheme Procedure} tor-hidden-service @var{name} @var{mapping}
8742Define a new Tor @dfn{hidden service} called @var{name} and implementing
8743@var{mapping}. @var{mapping} is a list of port/host tuples, such as:
8744
8745@example
24a8ef3b
LC
8746 '((22 "127.0.0.1:22")
8747 (80 "127.0.0.1:8080"))
6331bde7
LC
8748@end example
8749
8750In this example, port 22 of the hidden service is mapped to local port 22, and
8751port 80 is mapped to local port 8080.
8752
6629099a
LC
8753This creates a @file{/var/lib/tor/hidden-services/@var{name}} directory, where
8754the @file{hostname} file contains the @code{.onion} host name for the hidden
6331bde7
LC
8755service.
8756
8757See @uref{https://www.torproject.org/docs/tor-hidden-service.html.en, the Tor
8758project's documentation} for more information.
cf4a9129 8759@end deffn
8b315a6d 8760
be1c2c54 8761@deffn {Scheme Procedure} bitlbee-service [#:bitlbee bitlbee] @
4627a464
LC
8762 [#:interface "127.0.0.1"] [#:port 6667] @
8763 [#:extra-settings ""]
8764Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
8765acts as a gateway between IRC and chat networks.
8766
8767The daemon will listen to the interface corresponding to the IP address
8768specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
8769local clients can connect, whereas @code{0.0.0.0} means that connections can
8770come from any networking interface.
8771
8772In addition, @var{extra-settings} specifies a string to append to the
8773configuration file.
8774@end deffn
8775
71b0601a 8776Furthermore, @code{(gnu services ssh)} provides the following services.
e32171ee
JD
8777@cindex SSH
8778@cindex SSH server
8b315a6d 8779
be1c2c54 8780@deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 8781 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
8782 [#:allow-empty-passwords? #f] [#:root-login? #f] @
8783 [#:syslog-output? #t] [#:x11-forwarding? #t] @
8784 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 8785 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
8786Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
8787@var{host-key} must designate a file containing the host key, and readable
8788only by root.
72e25e35 8789
5833bf33
DP
8790When @var{daemonic?} is true, @command{lshd} will detach from the
8791controlling terminal and log its output to syslogd, unless one sets
8792@var{syslog-output?} to false. Obviously, it also makes lsh-service
8793depend on existence of syslogd service. When @var{pid-file?} is true,
8794@command{lshd} writes its PID to the file called @var{pid-file}.
8795
cf4a9129
LC
8796When @var{initialize?} is true, automatically create the seed and host key
8797upon service activation if they do not exist yet. This may take long and
8798require interaction.
8b315a6d 8799
20dd519c
LC
8800When @var{initialize?} is false, it is up to the user to initialize the
8801randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
8802a key pair with the private key stored in file @var{host-key} (@pxref{lshd
8803basics,,, lsh, LSH Manual}).
8804
cf4a9129
LC
8805When @var{interfaces} is empty, lshd listens for connections on all the
8806network interfaces; otherwise, @var{interfaces} must be a list of host names
8807or addresses.
9bf3c1a7 8808
20dd519c
LC
8809@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
8810passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 8811root.
4af2447e 8812
cf4a9129
LC
8813The other options should be self-descriptive.
8814@end deffn
4af2447e 8815
e32171ee
JD
8816@cindex SSH
8817@cindex SSH server
d8f31281
LC
8818@deffn {Scheme Variable} openssh-service-type
8819This is the type for the @uref{http://www.openssh.org, OpenSSH} secure
8820shell daemon, @command{sshd}. Its value must be an
8821@code{openssh-configuration} record as in this example:
8822
8823@example
8824(service openssh-service-type
8825 (openssh-configuration
8826 (x11-forwarding? #t)
8827 (permit-root-login 'without-password)))
8828@end example
8829
8830See below for details about @code{openssh-configuration}.
86d8f6d3
JL
8831@end deffn
8832
d8f31281
LC
8833@deftp {Data Type} openssh-configuration
8834This is the configuration record for OpenSSH's @command{sshd}.
8835
8836@table @asis
8837@item @code{pid-file} (default: @code{"/var/run/sshd.pid"})
8838Name of the file where @command{sshd} writes its PID.
8839
8840@item @code{port-number} (default: @code{22})
8841TCP port on which @command{sshd} listens for incoming connections.
8842
8843@item @code{permit-root-login} (default: @code{#f})
8844This field determines whether and when to allow logins as root. If
8845@code{#f}, root logins are disallowed; if @code{#t}, they are allowed.
8846If it's the symbol @code{'without-password}, then root logins are
8847permitted but not with password-based authentication.
8848
8849@item @code{allow-empty-passwords?} (default: @code{#f})
8850When true, users with empty passwords may log in. When false, they may
8851not.
8852
8853@item @code{password-authentication?} (default: @code{#t})
8854When true, users may log in with their password. When false, they have
8855other authentication methods.
8856
8857@item @code{public-key-authentication?} (default: @code{#t})
8858When true, users may log in using public key authentication. When
8859false, users have to use other authentication method.
8860
8861Authorized public keys are stored in @file{~/.ssh/authorized_keys}.
8862This is used only by protocol version 2.
8863
8864@item @code{rsa-authentication?} (default: @code{#t})
8865When true, users may log in using pure RSA authentication. When false,
8866users have to use other means of authentication. This is used only by
8867protocol 1.
8868
8869@item @code{x11-forwarding?} (default: @code{#f})
8870When true, forwarding of X11 graphical client connections is
8871enabled---in other words, @command{ssh} options @option{-X} and
8872@option{-Y} will work.
8873
8874@item @code{protocol-number} (default: @code{2})
8875The SSH protocol number to use.
8876@end table
8877@end deftp
8878
71b0601a
DC
8879@deffn {Scheme Procedure} dropbear-service [@var{config}]
8880Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
8881daemon} with the given @var{config}, a @code{<dropbear-configuration>}
8882object.
8883
8884For example, to specify a Dropbear service listening on port 1234, add
8885this call to the operating system's @code{services} field:
8886
8887@example
8888(dropbear-service (dropbear-configuration
8889 (port-number 1234)))
8890@end example
8891@end deffn
8892
8893@deftp {Data Type} dropbear-configuration
8894This data type represents the configuration of a Dropbear SSH daemon.
8895
8896@table @asis
8897@item @code{dropbear} (default: @var{dropbear})
8898The Dropbear package to use.
8899
8900@item @code{port-number} (default: 22)
8901The TCP port where the daemon waits for incoming connections.
8902
8903@item @code{syslog-output?} (default: @code{#t})
8904Whether to enable syslog output.
8905
8906@item @code{pid-file} (default: @code{"/var/run/dropbear.pid"})
8907File name of the daemon's PID file.
8908
8909@item @code{root-login?} (default: @code{#f})
8910Whether to allow @code{root} logins.
8911
8912@item @code{allow-empty-passwords?} (default: @code{#f})
8913Whether to allow empty passwords.
8914
8915@item @code{password-authentication?} (default: @code{#t})
8916Whether to enable password-based authentication.
8917@end table
8918@end deftp
8919
fa0c1d61
LC
8920@defvr {Scheme Variable} %facebook-host-aliases
8921This variable contains a string for use in @file{/etc/hosts}
8922(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
8923line contains a entry that maps a known server name of the Facebook
8924on-line service---e.g., @code{www.facebook.com}---to the local
8925host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
8926
8927This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
8928@code{operating-system} declaration (@pxref{operating-system Reference,
8929@file{/etc/hosts}}):
fa0c1d61
LC
8930
8931@example
8932(use-modules (gnu) (guix))
8933
8934(operating-system
8935 (host-name "mymachine")
8936 ;; ...
8937 (hosts-file
8938 ;; Create a /etc/hosts file with aliases for "localhost"
8939 ;; and "mymachine", as well as for Facebook servers.
24e02c28
LC
8940 (plain-file "hosts"
8941 (string-append (local-host-aliases host-name)
8942 %facebook-host-aliases))))
fa0c1d61
LC
8943@end example
8944
8945This mechanism can prevent programs running locally, such as Web
8946browsers, from accessing Facebook.
8947@end defvr
8948
965a7332
LC
8949The @code{(gnu services avahi)} provides the following definition.
8950
be1c2c54 8951@deffn {Scheme Procedure} avahi-service [#:avahi @var{avahi}] @
965a7332
LC
8952 [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @
8953 [#:ipv6? #t] [#:wide-area? #f] @
c8695f32 8954 [#:domains-to-browse '()] [#:debug? #f]
965a7332
LC
8955Return a service that runs @command{avahi-daemon}, a system-wide
8956mDNS/DNS-SD responder that allows for service discovery and
cc9c1f39
LC
8957"zero-configuration" host name lookups (see @uref{http://avahi.org/}), and
8958extends the name service cache daemon (nscd) so that it can resolve
8959@code{.local} host names using
1065bed9
LC
8960@uref{http://0pointer.de/lennart/projects/nss-mdns/, nss-mdns}. Additionally,
8961add the @var{avahi} package to the system profile so that commands such as
8962@command{avahi-browse} are directly usable.
965a7332
LC
8963
8964If @var{host-name} is different from @code{#f}, use that as the host name to
8965publish for this machine; otherwise, use the machine's actual host name.
8966
8967When @var{publish?} is true, publishing of host names and services is allowed;
8968in particular, avahi-daemon will publish the machine's host name and IP
8969address via mDNS on the local network.
8970
8971When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled.
8972
8973Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6
8974sockets.
8975@end deffn
8976
8977
cf4a9129
LC
8978@node X Window
8979@subsubsection X Window
68ad877c 8980
e32171ee
JD
8981@cindex X11
8982@cindex X Window System
cf4a9129
LC
8983Support for the X Window graphical display system---specifically
8984Xorg---is provided by the @code{(gnu services xorg)} module. Note that
8985there is no @code{xorg-service} procedure. Instead, the X server is
8986started by the @dfn{login manager}, currently SLiM.
4af2447e 8987
935644c0
DC
8988@deftp {Data Type} sddm-configuration
8989This is the data type representing the sddm service configuration.
8990
8991@table @asis
8992@item @code{display-server} (default: "x11")
8993Select display server to use for the greeter. Valid values are "x11"
8994or "wayland".
8995
8996@item @code{numlock} (default: "on")
8997Valid values are "on", "off" or "none".
8998
8999@item @code{halt-command} (default @code{#~(string-apppend #$shepherd "/sbin/halt")})
9000Command to run when halting.
9001
9002@item @code{reboot-command} (default @code{#~(string-append #$shepherd "/sbin/reboot")})
9003Command to run when rebooting.
9004
9005@item @code{theme} (default "maldives")
9006Theme to use. Default themes provided by SDDM are "elarun" or "maldives".
9007
9008@item @code{themes-directory} (default "/run/current-system/profile/share/sddm/themes")
9009Directory to look for themes.
9010
9011@item @code{faces-directory} (default "/run/current-system/profile/share/sddm/faces")
9012Directory to look for faces.
9013
9014@item @code{default-path} (default "/run/current-system/profile/bin")
9015Default PATH to use.
9016
9017@item @code{minimum-uid} (default 1000)
9018Minimum UID to display in SDDM.
9019
9020@item @code{maximum-uid} (default 2000)
9021Maximum UID to display in SDDM
9022
9023@item @code{remember-last-user?} (default #t)
9024Remember last user.
9025
9026@item @code{remember-last-session?} (default #t)
9027Remember last session.
9028
9029@item @code{hide-users} (default "")
9030Usernames to hide from SDDM greeter.
9031
9032@item @code{hide-shells} (default @code{#~(string-append #$shadow "/sbin/nologin")})
9033Users with shells listed will be hidden from the SDDM greeter.
9034
9035@item @code{session-command} (default @code{#~(string-append #$sddm "/share/sddm/scripts/wayland-session")})
9036Script to run before starting a wayland session.
9037
9038@item @code{sessions-directory} (default "/run/current-system/profile/share/wayland-sessions")
9039Directory to look for desktop files starting wayland sessions.
9040
9041@item @code{xorg-server-path} (default @code{xorg-start-command})
9042Path to xorg-server.
9043
9044@item @code{xauth-path} (default @code{#~(string-append #$xauth "/bin/xauth")})
9045Path to xauth.
9046
9047@item @code{xephyr-path} (default @code{#~(string-append #$xorg-server "/bin/Xephyr")})
9048Path to Xephyr.
9049
9050@item @code{xdisplay-start} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xsetup")})
9051Script to run after starting xorg-server.
9052
9053@item @code{xdisplay-stop} (default @code{#~(string-append #$sddm "/share/sddm/scripts/Xstop")})
9054Script to run before stopping xorg-server.
9055
9056@item @code{xsession-command} (default: @code{xinitr })
9057Script to run before starting a X session.
9058
9059@item @code{xsessions-directory} (default: "/run/current-system/profile/share/xsessions")
9060Directory to look for desktop files starting X sessions.
9061
9062@item @code{minimum-vt} (default: 7)
9063Minimum VT to use.
9064
9065@item @code{xserver-arguments} (default "-nolisten tcp")
9066Arguments to pass to xorg-server.
9067
9068@item @code{auto-login-user} (default "")
9069User to use for auto-login.
9070
9071@item @code{auto-login-session} (default "")
9072Desktop file to use for auto-login.
9073
9074@item @code{relogin?} (default #f)
9075Relogin after logout.
9076
9077@end table
9078@end deftp
9079
e32171ee 9080@cindex login manager
935644c0
DC
9081@deffn {Scheme Procedure} sddm-service config
9082Return a service that spawns the SDDM graphical login manager for config of
9083type @code{<sddm-configuration>}.
9084
9085@example
9086 (sddm-service (sddm-configuration
9087 (auto-login-user "Alice")
9088 (auto-login-session "xfce.desktop")))
9089@end example
9090@end deffn
9091
be1c2c54 9092@deffn {Scheme Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
9093 [#:auto-login? #f] [#:default-user ""] [#:startx] @
9094 [#:theme @var{%default-slim-theme}] @
4bd43bbe 9095 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
9096Return a service that spawns the SLiM graphical login manager, which in
9097turn starts the X display server with @var{startx}, a command as returned by
9098@code{xorg-start-command}.
4af2447e 9099
04e4e6ab
LC
9100@cindex X session
9101
9102SLiM automatically looks for session types described by the @file{.desktop}
9103files in @file{/run/current-system/profile/share/xsessions} and allows users
9104to choose a session from the log-in screen using @kbd{F1}. Packages such as
9105@var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files;
9106adding them to the system-wide set of packages automatically makes them
9107available at the log-in screen.
9108
9109In addition, @file{~/.xsession} files are honored. When available,
9110@file{~/.xsession} must be an executable that starts a window manager
9111and/or other X clients.
9112
cf4a9129
LC
9113When @var{allow-empty-passwords?} is true, allow logins with an empty
9114password. When @var{auto-login?} is true, log in automatically as
9115@var{default-user}.
0ecc3bf3 9116
1068f26b 9117If @var{theme} is @code{#f}, use the default log-in theme; otherwise
0ecc3bf3
LC
9118@var{theme} must be a gexp denoting the name of a directory containing the
9119theme to use. In that case, @var{theme-name} specifies the name of the
9120theme.
cf4a9129 9121@end deffn
4af2447e 9122
0ecc3bf3
LC
9123@defvr {Scheme Variable} %default-theme
9124@defvrx {Scheme Variable} %default-theme-name
9125The G-Expression denoting the default SLiM theme and its name.
9126@end defvr
9127
be1c2c54 9128@deffn {Scheme Procedure} xorg-start-command [#:guile] @
d1cdd7ba 9129 [#:configuration-file #f] [#:xorg-server @var{xorg-server}]
f703413e 9130Return a derivation that builds a @var{guile} script to start the X server
d1cdd7ba
LC
9131from @var{xorg-server}. @var{configuration-file} is the server configuration
9132file or a derivation that builds it; when omitted, the result of
9133@code{xorg-configuration-file} is used.
9134
9135Usually the X server is started by a login manager.
9136@end deffn
9137
be1c2c54 9138@deffn {Scheme Procedure} xorg-configuration-file @
12422c9d 9139 [#:drivers '()] [#:resolutions '()] [#:extra-config '()]
d1cdd7ba
LC
9140Return a configuration file for the Xorg server containing search paths for
9141all the common drivers.
f703413e
LC
9142
9143@var{drivers} must be either the empty list, in which case Xorg chooses a
9144graphics driver automatically, or a list of driver names that will be tried in
d1cdd7ba 9145this order---e.g., @code{(\"modesetting\" \"vesa\")}.
d2e59637
LC
9146
9147Likewise, when @var{resolutions} is the empty list, Xorg chooses an
9148appropriate screen resolution; otherwise, it must be a list of
9149resolutions---e.g., @code{((1024 768) (640 480))}.
12422c9d
LC
9150
9151Last, @var{extra-config} is a list of strings or objects appended to the
9152@code{text-file*} argument list. It is used to pass extra text to be added
9153verbatim to the configuration file.
f703413e 9154@end deffn
4af2447e 9155
6726282b
LC
9156@deffn {Scheme Procedure} screen-locker-service @var{package} [@var{name}]
9157Add @var{package}, a package for a screen-locker or screen-saver whose
9158command is @var{program}, to the set of setuid programs and add a PAM entry
9159for it. For example:
9160
9161@lisp
9162(screen-locker-service xlockmore "xlock")
9163@end lisp
9164
9165makes the good ol' XlockMore usable.
9166@end deffn
9167
9168
f2ec23d1
AW
9169@node Printing Services
9170@subsubsection Printing Services
9171
9172The @code{(gnu services cups)} module provides a Guix service definition
9173for the CUPS printing service. To add printer support to a GuixSD
9174system, add a @code{cups-service} to the operating system definition:
9175
9176@deffn {Scheme Variable} cups-service-type
9177The service type for the CUPS print server. Its value should be a valid
9178CUPS configuration (see below). For example:
9179@example
9180(service cups-service-type (cups-configuration))
9181@end example
9182@end deffn
9183
9184The CUPS configuration controls the basic things about your CUPS
9185installation: what interfaces it listens on, what to do if a print job
9186fails, how much logging to do, and so on. To actually add a printer,
9187you have to visit the @url{http://localhost:631} URL, or use a tool such
9188as GNOME's printer configuration services. By default, configuring a
9189CUPS service will generate a self-signed certificate if needed, for
9190secure connections to the print server.
9191
9192One way you might want to customize CUPS is to enable or disable the web
9193interface. You can do that directly, like this:
9194
9195@example
9196(service cups-service-type
9197 (cups-configuration
9198 (web-interface? #f)))
9199@end example
9200
9201The available configuration parameters follow. Each parameter
9202definition is preceded by its type; for example, @samp{string-list foo}
9203indicates that the @code{foo} parameter should be specified as a list of
9204strings. There is also a way to specify the configuration as a string,
9205if you have an old @code{cupsd.conf} file that you want to port over
9206from some other system; see the end for more details.
9207
9208@c The following documentation was initially generated by
9209@c (generate-documentation) in (gnu services cups). Manually maintained
9210@c documentation is better, so we shouldn't hesitate to edit below as
9211@c needed. However if the change you want to make to this documentation
9212@c can be done in an automated way, it's probably easier to change
9213@c (generate-documentation) than to make it below and have to deal with
9214@c the churn as CUPS updates.
9215
9216
9217Available @code{cups-configuration} fields are:
9218
9219@deftypevr {@code{cups-configuration} parameter} package cups
9220The CUPS package.
9221@end deftypevr
9222
9223@deftypevr {@code{cups-configuration} parameter} package-list extensions
9224Drivers and other extensions to the CUPS package.
9225@end deftypevr
9226
9227@deftypevr {@code{cups-configuration} parameter} files-configuration files-configuration
9228Configuration of where to write logs, what directories to use for print
9229spools, and related privileged configuration parameters.
9230
9231Available @code{files-configuration} fields are:
9232
9233@deftypevr {@code{files-configuration} parameter} log-location access-log
9234Defines the access log filename. Specifying a blank filename disables
9235access log generation. The value @code{stderr} causes log entries to be
9236sent to the standard error file when the scheduler is running in the
9237foreground, or to the system log daemon when run in the background. The
9238value @code{syslog} causes log entries to be sent to the system log
9239daemon. The server name may be included in filenames using the string
9240@code{%s}, as in @code{/var/log/cups/%s-access_log}.
9241
9242Defaults to @samp{"/var/log/cups/access_log"}.
9243@end deftypevr
9244
9245@deftypevr {@code{files-configuration} parameter} file-name cache-dir
9246Where CUPS should cache data.
9247
9248Defaults to @samp{"/var/cache/cups"}.
9249@end deftypevr
9250
9251@deftypevr {@code{files-configuration} parameter} string config-file-perm
9252Specifies the permissions for all configuration files that the scheduler
9253writes.
9254
9255Note that the permissions for the printers.conf file are currently
9256masked to only allow access from the scheduler user (typically root).
9257This is done because printer device URIs sometimes contain sensitive
9258authentication information that should not be generally known on the
9259system. There is no way to disable this security feature.
9260
9261Defaults to @samp{"0640"}.
9262@end deftypevr
9263
9264@deftypevr {@code{files-configuration} parameter} log-location error-log
9265Defines the error log filename. Specifying a blank filename disables
9266access log generation. The value @code{stderr} causes log entries to be
9267sent to the standard error file when the scheduler is running in the
9268foreground, or to the system log daemon when run in the background. The
9269value @code{syslog} causes log entries to be sent to the system log
9270daemon. The server name may be included in filenames using the string
9271@code{%s}, as in @code{/var/log/cups/%s-error_log}.
9272
9273Defaults to @samp{"/var/log/cups/error_log"}.
9274@end deftypevr
9275
9276@deftypevr {@code{files-configuration} parameter} string fatal-errors
9277Specifies which errors are fatal, causing the scheduler to exit. The
9278kind strings are:
9279
9280@table @code
9281@item none
9282No errors are fatal.
9283
9284@item all
9285All of the errors below are fatal.
9286
9287@item browse
9288Browsing initialization errors are fatal, for example failed connections
9289to the DNS-SD daemon.
9290
9291@item config
9292Configuration file syntax errors are fatal.
9293
9294@item listen
9295Listen or Port errors are fatal, except for IPv6 failures on the
9296loopback or @code{any} addresses.
9297
9298@item log
9299Log file creation or write errors are fatal.
9300
9301@item permissions
9302Bad startup file permissions are fatal, for example shared TLS
9303certificate and key files with world-read permissions.
9304@end table
9305
9306Defaults to @samp{"all -browse"}.
9307@end deftypevr
9308
9309@deftypevr {@code{files-configuration} parameter} boolean file-device?
9310Specifies whether the file pseudo-device can be used for new printer
9311queues. The URI @uref{file:///dev/null} is always allowed.
9312
9313Defaults to @samp{#f}.
9314@end deftypevr
9315
9316@deftypevr {@code{files-configuration} parameter} string group
9317Specifies the group name or ID that will be used when executing external
9318programs.
9319
9320Defaults to @samp{"lp"}.
9321@end deftypevr
9322
9323@deftypevr {@code{files-configuration} parameter} string log-file-perm
9324Specifies the permissions for all log files that the scheduler writes.
9325
9326Defaults to @samp{"0644"}.
9327@end deftypevr
9328
9329@deftypevr {@code{files-configuration} parameter} log-location page-log
9330Defines the page log filename. Specifying a blank filename disables
9331access log generation. The value @code{stderr} causes log entries to be
9332sent to the standard error file when the scheduler is running in the
9333foreground, or to the system log daemon when run in the background. The
9334value @code{syslog} causes log entries to be sent to the system log
9335daemon. The server name may be included in filenames using the string
9336@code{%s}, as in @code{/var/log/cups/%s-page_log}.
9337
9338Defaults to @samp{"/var/log/cups/page_log"}.
9339@end deftypevr
9340
9341@deftypevr {@code{files-configuration} parameter} string remote-root
9342Specifies the username that is associated with unauthenticated accesses
9343by clients claiming to be the root user. The default is @code{remroot}.
9344
9345Defaults to @samp{"remroot"}.
9346@end deftypevr
9347
9348@deftypevr {@code{files-configuration} parameter} file-name request-root
9349Specifies the directory that contains print jobs and other HTTP request
9350data.
9351
9352Defaults to @samp{"/var/spool/cups"}.
9353@end deftypevr
9354
9355@deftypevr {@code{files-configuration} parameter} sandboxing sandboxing
9356Specifies the level of security sandboxing that is applied to print
9357filters, backends, and other child processes of the scheduler; either
9358@code{relaxed} or @code{strict}. This directive is currently only
9359used/supported on macOS.
9360
9361Defaults to @samp{strict}.
9362@end deftypevr
9363
9364@deftypevr {@code{files-configuration} parameter} file-name server-keychain
9365Specifies the location of TLS certificates and private keys. CUPS will
9366look for public and private keys in this directory: a @code{.crt} files
9367for PEM-encoded certificates and corresponding @code{.key} files for
9368PEM-encoded private keys.
9369
9370Defaults to @samp{"/etc/cups/ssl"}.
9371@end deftypevr
9372
9373@deftypevr {@code{files-configuration} parameter} file-name server-root
9374Specifies the directory containing the server configuration files.
9375
9376Defaults to @samp{"/etc/cups"}.
9377@end deftypevr
9378
9379@deftypevr {@code{files-configuration} parameter} boolean sync-on-close?
9380Specifies whether the scheduler calls fsync(2) after writing
9381configuration or state files.
9382
9383Defaults to @samp{#f}.
9384@end deftypevr
9385
9386@deftypevr {@code{files-configuration} parameter} space-separated-string-list system-group
9387Specifies the group(s) to use for @code{@@SYSTEM} group authentication.
9388@end deftypevr
9389
9390@deftypevr {@code{files-configuration} parameter} file-name temp-dir
9391Specifies the directory where temporary files are stored.
9392
9393Defaults to @samp{"/var/spool/cups/tmp"}.
9394@end deftypevr
9395
9396@deftypevr {@code{files-configuration} parameter} string user
9397Specifies the user name or ID that is used when running external
9398programs.
9399
9400Defaults to @samp{"lp"}.
9401@end deftypevr
9402@end deftypevr
9403
9404@deftypevr {@code{cups-configuration} parameter} access-log-level access-log-level
9405Specifies the logging level for the AccessLog file. The @code{config}
9406level logs when printers and classes are added, deleted, or modified and
9407when configuration files are accessed or updated. The @code{actions}
9408level logs when print jobs are submitted, held, released, modified, or
9409canceled, and any of the conditions for @code{config}. The @code{all}
9410level logs all requests.
9411
9412Defaults to @samp{actions}.
9413@end deftypevr
9414
9415@deftypevr {@code{cups-configuration} parameter} boolean auto-purge-jobs?
9416Specifies whether to purge job history data automatically when it is no
9417longer required for quotas.
9418
9419Defaults to @samp{#f}.
9420@end deftypevr
9421
9422@deftypevr {@code{cups-configuration} parameter} browse-local-protocols browse-local-protocols
9423Specifies which protocols to use for local printer sharing.
9424
9425Defaults to @samp{dnssd}.
9426@end deftypevr
9427
9428@deftypevr {@code{cups-configuration} parameter} boolean browse-web-if?
9429Specifies whether the CUPS web interface is advertised.
9430
9431Defaults to @samp{#f}.
9432@end deftypevr
9433
9434@deftypevr {@code{cups-configuration} parameter} boolean browsing?
9435Specifies whether shared printers are advertised.
9436
9437Defaults to @samp{#f}.
9438@end deftypevr
9439
9440@deftypevr {@code{cups-configuration} parameter} string classification
9441Specifies the security classification of the server. Any valid banner
9442name can be used, including "classified", "confidential", "secret",
9443"topsecret", and "unclassified", or the banner can be omitted to disable
9444secure printing functions.
9445
9446Defaults to @samp{""}.
9447@end deftypevr
9448
9449@deftypevr {@code{cups-configuration} parameter} boolean classify-override?
9450Specifies whether users may override the classification (cover page) of
9451individual print jobs using the @code{job-sheets} option.
9452
9453Defaults to @samp{#f}.
9454@end deftypevr
9455
9456@deftypevr {@code{cups-configuration} parameter} default-auth-type default-auth-type
9457Specifies the default type of authentication to use.
9458
9459Defaults to @samp{Basic}.
9460@end deftypevr
9461
9462@deftypevr {@code{cups-configuration} parameter} default-encryption default-encryption
9463Specifies whether encryption will be used for authenticated requests.
9464
9465Defaults to @samp{Required}.
9466@end deftypevr
9467
9468@deftypevr {@code{cups-configuration} parameter} string default-language
9469Specifies the default language to use for text and web content.
9470
9471Defaults to @samp{"en"}.
9472@end deftypevr
9473
9474@deftypevr {@code{cups-configuration} parameter} string default-paper-size
9475Specifies the default paper size for new print queues. @samp{"Auto"}
9476uses a locale-specific default, while @samp{"None"} specifies there is
9477no default paper size. Specific size names are typically
9478@samp{"Letter"} or @samp{"A4"}.
9479
9480Defaults to @samp{"Auto"}.
9481@end deftypevr
9482
9483@deftypevr {@code{cups-configuration} parameter} string default-policy
9484Specifies the default access policy to use.
9485
9486Defaults to @samp{"default"}.
9487@end deftypevr
9488
9489@deftypevr {@code{cups-configuration} parameter} boolean default-shared?
9490Specifies whether local printers are shared by default.
9491
9492Defaults to @samp{#t}.
9493@end deftypevr
9494
9495@deftypevr {@code{cups-configuration} parameter} non-negative-integer dirty-clean-interval
9496Specifies the delay for updating of configuration and state files, in
9497seconds. A value of 0 causes the update to happen as soon as possible,
9498typically within a few milliseconds.
9499
9500Defaults to @samp{30}.
9501@end deftypevr
9502
9503@deftypevr {@code{cups-configuration} parameter} error-policy error-policy
9504Specifies what to do when an error occurs. Possible values are
9505@code{abort-job}, which will discard the failed print job;
9506@code{retry-job}, which will retry the job at a later time;
9507@code{retry-this-job}, which retries the failed job immediately; and
9508@code{stop-printer}, which stops the printer.
9509
9510Defaults to @samp{stop-printer}.
9511@end deftypevr
9512
9513@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-limit
9514Specifies the maximum cost of filters that are run concurrently, which
9515can be used to minimize disk, memory, and CPU resource problems. A
9516limit of 0 disables filter limiting. An average print to a
9517non-PostScript printer needs a filter limit of about 200. A PostScript
9518printer needs about half that (100). Setting the limit below these
9519thresholds will effectively limit the scheduler to printing a single job
9520at any time.
9521
9522Defaults to @samp{0}.
9523@end deftypevr
9524
9525@deftypevr {@code{cups-configuration} parameter} non-negative-integer filter-nice
9526Specifies the scheduling priority of filters that are run to print a
9527job. The nice value ranges from 0, the highest priority, to 19, the
9528lowest priority.
9529
9530Defaults to @samp{0}.
9531@end deftypevr
9532
9533@deftypevr {@code{cups-configuration} parameter} host-name-lookups host-name-lookups
9534Specifies whether to do reverse lookups on connecting clients. The
9535@code{double} setting causes @code{cupsd} to verify that the hostname
9536resolved from the address matches one of the addresses returned for that
9537hostname. Double lookups also prevent clients with unregistered
9538addresses from connecting to your server. Only set this option to
9539@code{#t} or @code{double} if absolutely required.
9540
9541Defaults to @samp{#f}.
9542@end deftypevr
9543
9544@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-kill-delay
9545Specifies the number of seconds to wait before killing the filters and
9546backend associated with a canceled or held job.
9547
9548Defaults to @samp{30}.
9549@end deftypevr
9550
9551@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-interval
9552Specifies the interval between retries of jobs in seconds. This is
9553typically used for fax queues but can also be used with normal print
9554queues whose error policy is @code{retry-job} or
9555@code{retry-current-job}.
9556
9557Defaults to @samp{30}.
9558@end deftypevr
9559
9560@deftypevr {@code{cups-configuration} parameter} non-negative-integer job-retry-limit
9561Specifies the number of retries that are done for jobs. This is
9562typically used for fax queues but can also be used with normal print
9563queues whose error policy is @code{retry-job} or
9564@code{retry-current-job}.
9565
9566Defaults to @samp{5}.
9567@end deftypevr
9568
9569@deftypevr {@code{cups-configuration} parameter} boolean keep-alive?
9570Specifies whether to support HTTP keep-alive connections.
9571
9572Defaults to @samp{#t}.
9573@end deftypevr
9574
9575@deftypevr {@code{cups-configuration} parameter} non-negative-integer keep-alive-timeout
9576Specifies how long an idle client connection remains open, in seconds.
9577
9578Defaults to @samp{30}.
9579@end deftypevr
9580
9581@deftypevr {@code{cups-configuration} parameter} non-negative-integer limit-request-body
9582Specifies the maximum size of print files, IPP requests, and HTML form
9583data. A limit of 0 disables the limit check.
9584
9585Defaults to @samp{0}.
9586@end deftypevr
9587
9588@deftypevr {@code{cups-configuration} parameter} multiline-string-list listen
9589Listens on the specified interfaces for connections. Valid values are
9590of the form @var{address}:@var{port}, where @var{address} is either an
9591IPv6 address enclosed in brackets, an IPv4 address, or @code{*} to
9592indicate all addresses. Values can also be file names of local UNIX
9593domain sockets. The Listen directive is similar to the Port directive
9594but allows you to restrict access to specific interfaces or networks.
9595@end deftypevr
9596
9597@deftypevr {@code{cups-configuration} parameter} non-negative-integer listen-back-log
9598Specifies the number of pending connections that will be allowed. This
9599normally only affects very busy servers that have reached the MaxClients
9600limit, but can also be triggered by large numbers of simultaneous
9601connections. When the limit is reached, the operating system will
9602refuse additional connections until the scheduler can accept the pending
9603ones.
9604
9605Defaults to @samp{128}.
9606@end deftypevr
9607
9608@deftypevr {@code{cups-configuration} parameter} location-access-control-list location-access-controls
9609Specifies a set of additional access controls.
9610
9611Available @code{location-access-controls} fields are:
9612
9613@deftypevr {@code{location-access-controls} parameter} file-name path
9614Specifies the URI path to which the access control applies.
9615@end deftypevr
9616
9617@deftypevr {@code{location-access-controls} parameter} access-control-list access-controls
9618Access controls for all access to this path, in the same format as the
9619@code{access-controls} of @code{operation-access-control}.
9620
9621Defaults to @samp{()}.
9622@end deftypevr
9623
9624@deftypevr {@code{location-access-controls} parameter} method-access-control-list method-access-controls
9625Access controls for method-specific access to this path.
9626
9627Defaults to @samp{()}.
9628
9629Available @code{method-access-controls} fields are:
9630
9631@deftypevr {@code{method-access-controls} parameter} boolean reverse?
9632If @code{#t}, apply access controls to all methods except the listed
9633methods. Otherwise apply to only the listed methods.
9634
9635Defaults to @samp{#f}.
9636@end deftypevr
9637
9638@deftypevr {@code{method-access-controls} parameter} method-list methods
9639Methods to which this access control applies.
9640
9641Defaults to @samp{()}.
9642@end deftypevr
9643
9644@deftypevr {@code{method-access-controls} parameter} access-control-list access-controls
9645Access control directives, as a list of strings. Each string should be
9646one directive, such as "Order allow,deny".
9647
9648Defaults to @samp{()}.
9649@end deftypevr
9650@end deftypevr
9651@end deftypevr
9652
9653@deftypevr {@code{cups-configuration} parameter} non-negative-integer log-debug-history
9654Specifies the number of debugging messages that are retained for logging
9655if an error occurs in a print job. Debug messages are logged regardless
9656of the LogLevel setting.
9657
9658Defaults to @samp{100}.
9659@end deftypevr
9660
9661@deftypevr {@code{cups-configuration} parameter} log-level log-level
9662Specifies the level of logging for the ErrorLog file. The value
9663@code{none} stops all logging while @code{debug2} logs everything.
9664
9665Defaults to @samp{info}.
9666@end deftypevr
9667
9668@deftypevr {@code{cups-configuration} parameter} log-time-format log-time-format
9669Specifies the format of the date and time in the log files. The value
9670@code{standard} logs whole seconds while @code{usecs} logs microseconds.
9671
9672Defaults to @samp{standard}.
9673@end deftypevr
9674
9675@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients
9676Specifies the maximum number of simultaneous clients that are allowed by
9677the scheduler.
9678
9679Defaults to @samp{100}.
9680@end deftypevr
9681
9682@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-clients-per-host
9683Specifies the maximum number of simultaneous clients that are allowed
9684from a single address.
9685
9686Defaults to @samp{100}.
9687@end deftypevr
9688
9689@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-copies
9690Specifies the maximum number of copies that a user can print of each
9691job.
9692
9693Defaults to @samp{9999}.
9694@end deftypevr
9695
9696@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-hold-time
9697Specifies the maximum time a job may remain in the @code{indefinite}
9698hold state before it is canceled. A value of 0 disables cancellation of
9699held jobs.
9700
9701Defaults to @samp{0}.
9702@end deftypevr
9703
9704@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs
9705Specifies the maximum number of simultaneous jobs that are allowed. Set
9706to 0 to allow an unlimited number of jobs.
9707
9708Defaults to @samp{500}.
9709@end deftypevr
9710
9711@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-printer
9712Specifies the maximum number of simultaneous jobs that are allowed per
9713printer. A value of 0 allows up to MaxJobs jobs per printer.
9714
9715Defaults to @samp{0}.
9716@end deftypevr
9717
9718@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-jobs-per-user
9719Specifies the maximum number of simultaneous jobs that are allowed per
9720user. A value of 0 allows up to MaxJobs jobs per user.
9721
9722Defaults to @samp{0}.
9723@end deftypevr
9724
9725@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-job-time
9726Specifies the maximum time a job may take to print before it is
9727canceled, in seconds. Set to 0 to disable cancellation of "stuck" jobs.
9728
9729Defaults to @samp{10800}.
9730@end deftypevr
9731
9732@deftypevr {@code{cups-configuration} parameter} non-negative-integer max-log-size
9733Specifies the maximum size of the log files before they are rotated, in
9734bytes. The value 0 disables log rotation.
9735
9736Defaults to @samp{1048576}.
9737@end deftypevr
9738
9739@deftypevr {@code{cups-configuration} parameter} non-negative-integer multiple-operation-timeout
9740Specifies the maximum amount of time to allow between files in a
9741multiple file print job, in seconds.
9742
9743Defaults to @samp{300}.
9744@end deftypevr
9745
9746@deftypevr {@code{cups-configuration} parameter} string page-log-format
9747Specifies the format of PageLog lines. Sequences beginning with percent
9748(@samp{%}) characters are replaced with the corresponding information,
9749while all other characters are copied literally. The following percent
9750sequences are recognized:
9751
9752@table @samp
9753@item %%
9754insert a single percent character
9755
9756@item %@{name@}
9757insert the value of the specified IPP attribute
9758
9759@item %C
9760insert the number of copies for the current page
9761
9762@item %P
9763insert the current page number
9764
9765@item %T
9766insert the current date and time in common log format
9767
9768@item %j
9769insert the job ID
9770
9771@item %p
9772insert the printer name
9773
9774@item %u
9775insert the username
9776@end table
9777
9778A value of the empty string disables page logging. The string @code{%p
9779%u %j %T %P %C %@{job-billing@} %@{job-originating-host-name@}
9780%@{job-name@} %@{media@} %@{sides@}} creates a page log with the
9781standard items.
9782
9783Defaults to @samp{""}.
9784@end deftypevr
9785
9786@deftypevr {@code{cups-configuration} parameter} environment-variables environment-variables
9787Passes the specified environment variable(s) to child processes; a list
9788of strings.
9789
9790Defaults to @samp{()}.
9791@end deftypevr
9792
9793@deftypevr {@code{cups-configuration} parameter} policy-configuration-list policies
9794Specifies named access control policies.
9795
9796Available @code{policy-configuration} fields are:
9797
9798@deftypevr {@code{policy-configuration} parameter} string name
9799Name of the policy.
9800@end deftypevr
9801
9802@deftypevr {@code{policy-configuration} parameter} string job-private-access
9803Specifies an access list for a job's private values. @code{@@ACL} maps
9804to the printer's requesting-user-name-allowed or
9805requesting-user-name-denied values. @code{@@OWNER} maps to the job's
9806owner. @code{@@SYSTEM} maps to the groups listed for the
9807@code{system-group} field of the @code{files-config} configuration,
9808which is reified into the @code{cups-files.conf(5)} file. Other
9809possible elements of the access list include specific user names, and
9810@code{@@@var{group}} to indicate members of a specific group. The
9811access list may also be simply @code{all} or @code{default}.
9812
9813Defaults to @samp{"@@OWNER @@SYSTEM"}.
9814@end deftypevr
9815
9816@deftypevr {@code{policy-configuration} parameter} string job-private-values
9817Specifies the list of job values to make private, or @code{all},
9818@code{default}, or @code{none}.
9819
9820Defaults to @samp{"job-name job-originating-host-name
9821job-originating-user-name phone"}.
9822@end deftypevr
9823
9824@deftypevr {@code{policy-configuration} parameter} string subscription-private-access
9825Specifies an access list for a subscription's private values.
9826@code{@@ACL} maps to the printer's requesting-user-name-allowed or
9827requesting-user-name-denied values. @code{@@OWNER} maps to the job's
9828owner. @code{@@SYSTEM} maps to the groups listed for the
9829@code{system-group} field of the @code{files-config} configuration,
9830which is reified into the @code{cups-files.conf(5)} file. Other
9831possible elements of the access list include specific user names, and
9832@code{@@@var{group}} to indicate members of a specific group. The
9833access list may also be simply @code{all} or @code{default}.
9834
9835Defaults to @samp{"@@OWNER @@SYSTEM"}.
9836@end deftypevr
9837
9838@deftypevr {@code{policy-configuration} parameter} string subscription-private-values
9839Specifies the list of job values to make private, or @code{all},
9840@code{default}, or @code{none}.
9841
9842Defaults to @samp{"notify-events notify-pull-method notify-recipient-uri
9843notify-subscriber-user-name notify-user-data"}.
9844@end deftypevr
9845
9846@deftypevr {@code{policy-configuration} parameter} operation-access-control-list access-controls
9847Access control by IPP operation.
9848
9849Defaults to @samp{()}.
9850@end deftypevr
9851@end deftypevr
9852
9853@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-files
9854Specifies whether job files (documents) are preserved after a job is
9855printed. If a numeric value is specified, job files are preserved for
9856the indicated number of seconds after printing. Otherwise a boolean
9857value applies indefinitely.
9858
9859Defaults to @samp{86400}.
9860@end deftypevr
9861
9862@deftypevr {@code{cups-configuration} parameter} boolean-or-non-negative-integer preserve-job-history
9863Specifies whether the job history is preserved after a job is printed.
9864If a numeric value is specified, the job history is preserved for the
9865indicated number of seconds after printing. If @code{#t}, the job
9866history is preserved until the MaxJobs limit is reached.
9867
9868Defaults to @samp{#t}.
9869@end deftypevr
9870
9871@deftypevr {@code{cups-configuration} parameter} non-negative-integer reload-timeout
9872Specifies the amount of time to wait for job completion before
9873restarting the scheduler.
9874
9875Defaults to @samp{30}.
9876@end deftypevr
9877
9878@deftypevr {@code{cups-configuration} parameter} string rip-cache
9879Specifies the maximum amount of memory to use when converting documents
9880into bitmaps for a printer.
9881
9882Defaults to @samp{"128m"}.
9883@end deftypevr
9884
9885@deftypevr {@code{cups-configuration} parameter} string server-admin
9886Specifies the email address of the server administrator.
9887
9888Defaults to @samp{"root@@localhost.localdomain"}.
9889@end deftypevr
9890
9891@deftypevr {@code{cups-configuration} parameter} host-name-list-or-* server-alias
9892The ServerAlias directive is used for HTTP Host header validation when
9893clients connect to the scheduler from external interfaces. Using the
9894special name @code{*} can expose your system to known browser-based DNS
9895rebinding attacks, even when accessing sites through a firewall. If the
9896auto-discovery of alternate names does not work, we recommend listing
9897each alternate name with a ServerAlias directive instead of using
9898@code{*}.
9899
9900Defaults to @samp{*}.
9901@end deftypevr
9902
9903@deftypevr {@code{cups-configuration} parameter} string server-name
9904Specifies the fully-qualified host name of the server.
9905
9906Defaults to @samp{"localhost"}.
9907@end deftypevr
9908
9909@deftypevr {@code{cups-configuration} parameter} server-tokens server-tokens
9910Specifies what information is included in the Server header of HTTP
9911responses. @code{None} disables the Server header. @code{ProductOnly}
9912reports @code{CUPS}. @code{Major} reports @code{CUPS 2}. @code{Minor}
9913reports @code{CUPS 2.0}. @code{Minimal} reports @code{CUPS 2.0.0}.
9914@code{OS} reports @code{CUPS 2.0.0 (@var{uname})} where @var{uname} is
9915the output of the @code{uname} command. @code{Full} reports @code{CUPS
99162.0.0 (@var{uname}) IPP/2.0}.
9917
9918Defaults to @samp{Minimal}.
9919@end deftypevr
9920
9921@deftypevr {@code{cups-configuration} parameter} string set-env
9922Set the specified environment variable to be passed to child processes.
9923
9924Defaults to @samp{"variable value"}.
9925@end deftypevr
9926
9927@deftypevr {@code{cups-configuration} parameter} multiline-string-list ssl-listen
9928Listens on the specified interfaces for encrypted connections. Valid
9929values are of the form @var{address}:@var{port}, where @var{address} is
9930either an IPv6 address enclosed in brackets, an IPv4 address, or
9931@code{*} to indicate all addresses.
9932
9933Defaults to @samp{()}.
9934@end deftypevr
9935
9936@deftypevr {@code{cups-configuration} parameter} ssl-options ssl-options
9937Sets encryption options. By default, CUPS only supports encryption
9938using TLS v1.0 or higher using known secure cipher suites. The
9939@code{AllowRC4} option enables the 128-bit RC4 cipher suites, which are
9940required for some older clients that do not implement newer ones. The
9941@code{AllowSSL3} option enables SSL v3.0, which is required for some
9942older clients that do not support TLS v1.0.
9943
9944Defaults to @samp{()}.
9945@end deftypevr
9946
9947@deftypevr {@code{cups-configuration} parameter} boolean strict-conformance?
9948Specifies whether the scheduler requires clients to strictly adhere to
9949the IPP specifications.
9950
9951Defaults to @samp{#f}.
9952@end deftypevr
9953
9954@deftypevr {@code{cups-configuration} parameter} non-negative-integer timeout
9955Specifies the HTTP request timeout, in seconds.
9956
9957Defaults to @samp{300}.
9958
9959@end deftypevr
9960
9961@deftypevr {@code{cups-configuration} parameter} boolean web-interface?
9962Specifies whether the web interface is enabled.
9963
9964Defaults to @samp{#f}.
9965@end deftypevr
9966
9967At this point you're probably thinking ``oh dear, Guix manual, I like
9968you but you can stop already with the configuration options''. Indeed.
9969However, one more point: it could be that you have an existing
9970@code{cupsd.conf} that you want to use. In that case, you can pass an
9971@code{opaque-cups-configuration} as the configuration of a
9972@code{cups-service-type}.
9973
9974Available @code{opaque-cups-configuration} fields are:
9975
9976@deftypevr {@code{opaque-cups-configuration} parameter} package cups
9977The CUPS package.
9978@end deftypevr
9979
9980@deftypevr {@code{opaque-cups-configuration} parameter} string cupsd.conf
9981The contents of the @code{cupsd.conf}, as a string.
9982@end deftypevr
9983
9984@deftypevr {@code{opaque-cups-configuration} parameter} string cups-files.conf
9985The contents of the @code{cups-files.conf} file, as a string.
9986@end deftypevr
9987
9988For example, if your @code{cupsd.conf} and @code{cups-files.conf} are in
9989strings of the same name, you could instantiate a CUPS service like
9990this:
9991
9992@example
9993(service cups-service-type
9994 (opaque-cups-configuration
9995 (cupsd.conf cupsd.conf)
9996 (cups-files.conf cups-files.conf)))
9997@end example
9998
9999
fe1a39d3
LC
10000@node Desktop Services
10001@subsubsection Desktop Services
aa4ed923 10002
fe1a39d3
LC
10003The @code{(gnu services desktop)} module provides services that are
10004usually useful in the context of a ``desktop'' setup---that is, on a
10005machine running a graphical display server, possibly with graphical user
7a2413e4
AW
10006interfaces, etc. It also defines services that provide specific desktop
10007environments like GNOME and XFCE.
aa4ed923 10008
4467be21
LC
10009To simplify things, the module defines a variable containing the set of
10010services that users typically expect on a machine with a graphical
10011environment and networking:
10012
10013@defvr {Scheme Variable} %desktop-services
10014This is a list of services that builds upon @var{%base-services} and
1068f26b 10015adds or adjusts services for a typical ``desktop'' setup.
4467be21
LC
10016
10017In particular, it adds a graphical login manager (@pxref{X Window,
6726282b
LC
10018@code{slim-service}}), screen lockers,
10019a network management tool (@pxref{Networking
4467be21 10020Services, @code{wicd-service}}), energy and color management services,
4650a77e 10021the @code{elogind} login and seat manager, the Polkit privilege service,
cee32ee4
AW
10022the GeoClue location service, an NTP client (@pxref{Networking
10023Services}), the Avahi daemon, and has the name service switch service
10024configured to be able to use @code{nss-mdns} (@pxref{Name Service
10025Switch, mDNS}).
4467be21
LC
10026@end defvr
10027
10028The @var{%desktop-services} variable can be used as the @code{services}
10029field of an @code{operating-system} declaration (@pxref{operating-system
10030Reference, @code{services}}).
10031
7a2413e4
AW
10032Additionally, the @code{gnome-desktop-service} and
10033@code{xfce-desktop-service} procedures can add GNOME and/or XFCE to a
10034system. To ``add GNOME'' means that system-level services like the
10035backlight adjustment helpers and the power management utilities are
10036added to the system, extending @code{polkit} and @code{dbus}
10037appropriately, allowing GNOME to operate with elevated privileges on a
10038limited number of special-purpose system interfaces. Additionally,
10039adding a service made by @code{gnome-desktop-service} adds the GNOME
10040metapackage to the system profile. Likewise, adding the XFCE service
10041not only adds the @code{xfce} metapackage to the system profile, but it
10042also gives the Thunar file manager the ability to open a ``root-mode''
10043file management window, if the user authenticates using the
10044administrator's password via the standard polkit graphical interface.
10045
10046@deffn {Scheme Procedure} gnome-desktop-service
10047Return a service that adds the @code{gnome} package to the system
10048profile, and extends polkit with the actions from
10049@code{gnome-settings-daemon}.
10050@end deffn
10051
10052@deffn {Scheme Procedure} xfce-desktop-service
10053Return a service that adds the @code{xfce} package to the system profile,
5741e3e5 10054and extends polkit with the ability for @code{thunar} to manipulate the
7a2413e4
AW
10055file system as root from within a user session, after the user has
10056authenticated with the administrator's password.
10057@end deffn
10058
10059Because the GNOME and XFCE desktop services pull in so many packages,
10060the default @code{%desktop-services} variable doesn't include either of
10061them by default. To add GNOME or XFCE, just @code{cons} them onto
10062@code{%desktop-services} in the @code{services} field of your
10063@code{operating-system}:
10064
10065@example
10066(use-modules (gnu))
10067(use-service-modules desktop)
10068(operating-system
10069 ...
10070 ;; cons* adds items to the list given as its last argument.
10071 (services (cons* (gnome-desktop-service)
10072 (xfce-desktop-service)
10073 %desktop-services))
10074 ...)
10075@end example
10076
10077These desktop environments will then be available as options in the
10078graphical login window.
10079
10080The actual service definitions included in @code{%desktop-services} and
10081provided by @code{(gnu services dbus)} and @code{(gnu services desktop)}
10082are described below.
4467be21 10083
0adfe95a 10084@deffn {Scheme Procedure} dbus-service [#:dbus @var{dbus}] [#:services '()]
fe1a39d3
LC
10085Return a service that runs the ``system bus'', using @var{dbus}, with
10086support for @var{services}.
aa4ed923 10087
fe1a39d3
LC
10088@uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication
10089facility. Its system bus is used to allow system services to communicate
1068f26b 10090and to be notified of system-wide events.
aa4ed923 10091
fe1a39d3
LC
10092@var{services} must be a list of packages that provide an
10093@file{etc/dbus-1/system.d} directory containing additional D-Bus configuration
10094and policy files. For example, to allow avahi-daemon to use the system bus,
10095@var{services} must be equal to @code{(list avahi)}.
aa4ed923
AK
10096@end deffn
10097
0adfe95a 10098@deffn {Scheme Procedure} elogind-service [#:config @var{config}]
4650a77e
AW
10099Return a service that runs the @code{elogind} login and
10100seat management daemon. @uref{https://github.com/andywingo/elogind,
10101Elogind} exposes a D-Bus interface that can be used to know which users
10102are logged in, know what kind of sessions they have open, suspend the
10103system, inhibit system suspend, reboot the system, and other tasks.
10104
10105Elogind handles most system-level power events for a computer, for
10106example suspending the system when a lid is closed, or shutting it down
10107when the power button is pressed.
10108
10109The @var{config} keyword argument specifies the configuration for
1068f26b 10110elogind, and should be the result of an @code{(elogind-configuration
4650a77e
AW
10111(@var{parameter} @var{value})...)} invocation. Available parameters and
10112their default values are:
10113
10114@table @code
10115@item kill-user-processes?
10116@code{#f}
10117@item kill-only-users
10118@code{()}
10119@item kill-exclude-users
10120@code{("root")}
10121@item inhibit-delay-max-seconds
10122@code{5}
10123@item handle-power-key
10124@code{poweroff}
10125@item handle-suspend-key
10126@code{suspend}
10127@item handle-hibernate-key
10128@code{hibernate}
10129@item handle-lid-switch
10130@code{suspend}
10131@item handle-lid-switch-docked
10132@code{ignore}
10133@item power-key-ignore-inhibited?
10134@code{#f}
10135@item suspend-key-ignore-inhibited?
10136@code{#f}
10137@item hibernate-key-ignore-inhibited?
10138@code{#f}
10139@item lid-switch-ignore-inhibited?
10140@code{#t}
10141@item holdoff-timeout-seconds
10142@code{30}
10143@item idle-action
10144@code{ignore}
10145@item idle-action-seconds
10146@code{(* 30 60)}
10147@item runtime-directory-size-percent
10148@code{10}
10149@item runtime-directory-size
10150@code{#f}
10151@item remove-ipc?
10152@code{#t}
10153@item suspend-state
10154@code{("mem" "standby" "freeze")}
10155@item suspend-mode
10156@code{()}
10157@item hibernate-state
10158@code{("disk")}
10159@item hibernate-mode
10160@code{("platform" "shutdown")}
10161@item hybrid-sleep-state
10162@code{("disk")}
10163@item hybrid-sleep-mode
10164@code{("suspend" "platform" "shutdown")}
10165@end table
10166@end deffn
10167
be1c2c54 10168@deffn {Scheme Procedure} polkit-service @
4650a77e 10169 [#:polkit @var{polkit}]
222e3319
LC
10170Return a service that runs the
10171@uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit privilege
10172management service}, which allows system administrators to grant access to
10173privileged operations in a structured way. By querying the Polkit service, a
10174privileged system component can know when it should grant additional
10175capabilities to ordinary users. For example, an ordinary user can be granted
10176the capability to suspend the system if the user is logged in locally.
4650a77e
AW
10177@end deffn
10178
be1c2c54 10179@deffn {Scheme Procedure} upower-service [#:upower @var{upower}] @
be234128
AW
10180 [#:watts-up-pro? #f] @
10181 [#:poll-batteries? #t] @
10182 [#:ignore-lid? #f] @
10183 [#:use-percentage-for-policy? #f] @
10184 [#:percentage-low 10] @
10185 [#:percentage-critical 3] @
10186 [#:percentage-action 2] @
10187 [#:time-low 1200] @
10188 [#:time-critical 300] @
10189 [#:time-action 120] @
10190 [#:critical-power-action 'hybrid-sleep]
10191Return a service that runs @uref{http://upower.freedesktop.org/,
10192@command{upowerd}}, a system-wide monitor for power consumption and battery
10193levels, with the given configuration settings. It implements the
10194@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
10195GNOME.
10196@end deffn
10197
2b9e0a94
LC
10198@deffn {Scheme Procedure} udisks-service [#:udisks @var{udisks}]
10199Return a service for @uref{http://udisks.freedesktop.org/docs/latest/,
10200UDisks}, a @dfn{disk management} daemon that provides user interfaces with
10201notifications and ways to mount/unmount disks. Programs that talk to UDisks
10202include the @command{udisksctl} command, part of UDisks, and GNOME Disks.
10203@end deffn
10204
be1c2c54 10205@deffn {Scheme Procedure} colord-service [#:colord @var{colord}]
7ce597ff
AW
10206Return a service that runs @command{colord}, a system service with a D-Bus
10207interface to manage the color profiles of input and output devices such as
10208screens and scanners. It is notably used by the GNOME Color Manager graphical
10209tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
10210site} for more information.
10211@end deffn
10212
cee32ee4 10213@deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()]
1068f26b 10214Return a configuration allowing an application to access GeoClue
cee32ee4
AW
10215location data. @var{name} is the Desktop ID of the application, without
10216the @code{.desktop} part. If @var{allowed?} is true, the application
10217will have access to location information by default. The boolean
1068f26b 10218@var{system?} value indicates whether an application is a system component
cee32ee4
AW
10219or not. Finally @var{users} is a list of UIDs of all users for which
10220this application is allowed location info access. An empty users list
10221means that all users are allowed.
10222@end deffn
10223
10224@defvr {Scheme Variable} %standard-geoclue-applications
10225The standard list of well-known GeoClue application configurations,
1068f26b
AE
10226granting authority to the GNOME date-and-time utility to ask for the
10227current location in order to set the time zone, and allowing the
10228IceCat and Epiphany web browsers to request location information.
10229IceCat and Epiphany both query the user before allowing a web page to
cee32ee4
AW
10230know the user's location.
10231@end defvr
10232
be1c2c54 10233@deffn {Scheme Procedure} geoclue-service [#:colord @var{colord}] @
cee32ee4
AW
10234 [#:whitelist '()] @
10235 [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @
10236 [#:submit-data? #f]
10237 [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @
10238 [#:submission-nick "geoclue"] @
10239 [#:applications %standard-geoclue-applications]
10240Return a service that runs the GeoClue location service. This service
10241provides a D-Bus interface to allow applications to request access to a
10242user's physical location, and optionally to add information to online
10243location databases. See
10244@uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue
10245web site} for more information.
10246@end deffn
10247
922e21f4
SB
10248@deffn {Scheme Procedure} bluetooth-service [#:bluez @var{bluez}]
10249Return a service that runs the @command{bluetoothd} daemon, which manages
10250all the Bluetooth devices and provides a number of D-Bus interfaces.
10251
10252Users need to be in the @code{lp} group to access the D-Bus service.
10253@end deffn
10254
105369a4
DT
10255@node Database Services
10256@subsubsection Database Services
10257
e32171ee
JD
10258@cindex database
10259@cindex SQL
6575183b 10260The @code{(gnu services databases)} module provides the following services.
105369a4 10261
be1c2c54 10262@deffn {Scheme Procedure} postgresql-service [#:postgresql postgresql] @
2d3d5cc5 10263 [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] @
e05b780a 10264 [#:port 5432] [#:locale ``en_US.utf8'']
105369a4
DT
10265Return a service that runs @var{postgresql}, the PostgreSQL database
10266server.
10267
e05b780a
CB
10268The PostgreSQL daemon loads its runtime configuration from @var{config-file},
10269creates a database cluster with @var{locale} as the default
10270locale, stored in @var{data-directory}. It then listens on @var{port}.
105369a4 10271@end deffn
fe1a39d3 10272
6575183b
SB
10273@deffn {Scheme Procedure} mysql-service [#:config (mysql-configuration)]
10274Return a service that runs @command{mysqld}, the MySQL or MariaDB
10275database server.
10276
10277The optional @var{config} argument specifies the configuration for
c940b8e6 10278@command{mysqld}, which should be a @code{<mysql-configuration>} object.
6575183b
SB
10279@end deffn
10280
10281@deftp {Data Type} mysql-configuration
10282Data type representing the configuration of @var{mysql-service}.
10283
10284@table @asis
10285@item @code{mysql} (default: @var{mariadb})
10286Package object of the MySQL database server, can be either @var{mariadb}
10287or @var{mysql}.
10288
7414de0a 10289For MySQL, a temporary root password will be displayed at activation time.
6575183b 10290For MariaDB, the root password is empty.
4b41febf
CB
10291
10292@item @code{port} (default: @code{3306})
10293TCP port on which the database server listens for incoming connections.
6575183b
SB
10294@end table
10295@end deftp
10296
d8c18af8
AW
10297@node Mail Services
10298@subsubsection Mail Services
10299
e32171ee
JD
10300@cindex mail
10301@cindex email
d8c18af8 10302The @code{(gnu services mail)} module provides Guix service definitions
f88371e8
SB
10303for email services: IMAP, POP3, and LMTP servers, as well as mail
10304transport agents (MTAs). Lots of acronyms! These services are detailed
10305in the subsections below.
d8c18af8 10306
f88371e8 10307@subsubheading Dovecot Service
d8c18af8
AW
10308
10309@deffn {Scheme Procedure} dovecot-service [#:config (dovecot-configuration)]
10310Return a service that runs the Dovecot IMAP/POP3/LMTP mail server.
10311@end deffn
10312
1068f26b 10313By default, Dovecot does not need much configuration; the default
d8c18af8
AW
10314configuration object created by @code{(dovecot-configuration)} will
10315suffice if your mail is delivered to @code{~/Maildir}. A self-signed
10316certificate will be generated for TLS-protected connections, though
10317Dovecot will also listen on cleartext ports by default. There are a
1068f26b 10318number of options, though, which mail administrators might need to change,
d8c18af8
AW
10319and as is the case with other services, Guix allows the system
10320administrator to specify these parameters via a uniform Scheme interface.
10321
10322For example, to specify that mail is located at @code{maildir~/.mail},
10323one would instantiate the Dovecot service like this:
10324
10325@example
10326(dovecot-service #:config
10327 (dovecot-configuration
10328 (mail-location "maildir:~/.mail")))
10329@end example
10330
10331The available configuration parameters follow. Each parameter
10332definition is preceded by its type; for example, @samp{string-list foo}
10333indicates that the @code{foo} parameter should be specified as a list of
10334strings. There is also a way to specify the configuration as a string,
10335if you have an old @code{dovecot.conf} file that you want to port over
10336from some other system; see the end for more details.
10337
10338@c The following documentation was initially generated by
10339@c (generate-documentation) in (gnu services mail). Manually maintained
10340@c documentation is better, so we shouldn't hesitate to edit below as
10341@c needed. However if the change you want to make to this documentation
10342@c can be done in an automated way, it's probably easier to change
10343@c (generate-documentation) than to make it below and have to deal with
10344@c the churn as dovecot updates.
10345
10346Available @code{dovecot-configuration} fields are:
10347
10348@deftypevr {@code{dovecot-configuration} parameter} package dovecot
10349The dovecot package.
10350@end deftypevr
10351
10352@deftypevr {@code{dovecot-configuration} parameter} comma-separated-string-list listen
1068f26b
AE
10353A list of IPs or hosts where to listen for connections. @samp{*}
10354listens on all IPv4 interfaces, @samp{::} listens on all IPv6
d8c18af8
AW
10355interfaces. If you want to specify non-default ports or anything more
10356complex, customize the address and port fields of the
10357@samp{inet-listener} of the specific services you are interested in.
10358@end deftypevr
10359
10360@deftypevr {@code{dovecot-configuration} parameter} protocol-configuration-list protocols
10361List of protocols we want to serve. Available protocols include
10362@samp{imap}, @samp{pop3}, and @samp{lmtp}.
10363
10364Available @code{protocol-configuration} fields are:
10365
10366@deftypevr {@code{protocol-configuration} parameter} string name
10367The name of the protocol.
10368@end deftypevr
10369
10370@deftypevr {@code{protocol-configuration} parameter} string auth-socket-path
1068f26b 10371UNIX socket path to the master authentication server to find users.
d8c18af8 10372This is used by imap (for shared users) and lda.
1068f26b 10373It defaults to @samp{"/var/run/dovecot/auth-userdb"}.
d8c18af8
AW
10374@end deftypevr
10375
10376@deftypevr {@code{protocol-configuration} parameter} space-separated-string-list mail-plugins
10377Space separated list of plugins to load.
10378@end deftypevr
10379
10380@deftypevr {@code{protocol-configuration} parameter} non-negative-integer mail-max-userip-connections
10381Maximum number of IMAP connections allowed for a user from each IP
10382address. NOTE: The username is compared case-sensitively.
10383Defaults to @samp{10}.
10384@end deftypevr
10385
10386@end deftypevr
10387
10388@deftypevr {@code{dovecot-configuration} parameter} service-configuration-list services
10389List of services to enable. Available services include @samp{imap},
10390@samp{imap-login}, @samp{pop3}, @samp{pop3-login}, @samp{auth}, and
10391@samp{lmtp}.
10392
10393Available @code{service-configuration} fields are:
10394
10395@deftypevr {@code{service-configuration} parameter} string kind
10396The service kind. Valid values include @code{director},
10397@code{imap-login}, @code{pop3-login}, @code{lmtp}, @code{imap},
10398@code{pop3}, @code{auth}, @code{auth-worker}, @code{dict},
10399@code{tcpwrap}, @code{quota-warning}, or anything else.
10400@end deftypevr
10401
10402@deftypevr {@code{service-configuration} parameter} listener-configuration-list listeners
1068f26b 10403Listeners for the service. A listener is either a
d8c18af8
AW
10404@code{unix-listener-configuration}, a @code{fifo-listener-configuration}, or
10405an @code{inet-listener-configuration}.
10406Defaults to @samp{()}.
10407
10408Available @code{unix-listener-configuration} fields are:
10409
10410@deftypevr {@code{unix-listener-configuration} parameter} file-name path
10411The file name on which to listen.
10412@end deftypevr
10413
10414@deftypevr {@code{unix-listener-configuration} parameter} string mode
10415The access mode for the socket.
10416Defaults to @samp{"0600"}.
10417@end deftypevr
10418
10419@deftypevr {@code{unix-listener-configuration} parameter} string user
f9b9a033 10420The user to own the socket.
d8c18af8
AW
10421Defaults to @samp{""}.
10422@end deftypevr
10423
10424@deftypevr {@code{unix-listener-configuration} parameter} string group
10425The group to own the socket.
10426Defaults to @samp{""}.
10427@end deftypevr
10428
10429
10430Available @code{fifo-listener-configuration} fields are:
10431
10432@deftypevr {@code{fifo-listener-configuration} parameter} file-name path
10433The file name on which to listen.
10434@end deftypevr
10435
10436@deftypevr {@code{fifo-listener-configuration} parameter} string mode
10437The access mode for the socket.
10438Defaults to @samp{"0600"}.
10439@end deftypevr
10440
10441@deftypevr {@code{fifo-listener-configuration} parameter} string user
f9b9a033 10442The user to own the socket.
d8c18af8
AW
10443Defaults to @samp{""}.
10444@end deftypevr
10445
10446@deftypevr {@code{fifo-listener-configuration} parameter} string group
10447The group to own the socket.
10448Defaults to @samp{""}.
10449@end deftypevr
10450
10451
10452Available @code{inet-listener-configuration} fields are:
10453
10454@deftypevr {@code{inet-listener-configuration} parameter} string protocol
10455The protocol to listen for.
10456@end deftypevr
10457
10458@deftypevr {@code{inet-listener-configuration} parameter} string address
10459The address on which to listen, or empty for all addresses.
10460Defaults to @samp{""}.
10461@end deftypevr
10462
10463@deftypevr {@code{inet-listener-configuration} parameter} non-negative-integer port
10464The port on which to listen.
10465@end deftypevr
10466
10467@deftypevr {@code{inet-listener-configuration} parameter} boolean ssl?
10468Whether to use SSL for this service; @samp{yes}, @samp{no}, or
10469@samp{required}.
10470Defaults to @samp{#t}.
10471@end deftypevr
10472
10473@end deftypevr
10474
10475@deftypevr {@code{service-configuration} parameter} non-negative-integer service-count
10476Number of connections to handle before starting a new process.
10477Typically the only useful values are 0 (unlimited) or 1. 1 is more
10478secure, but 0 is faster. <doc/wiki/LoginProcess.txt>.
10479Defaults to @samp{1}.
10480@end deftypevr
10481
10482@deftypevr {@code{service-configuration} parameter} non-negative-integer process-min-avail
10483Number of processes to always keep waiting for more connections.
10484Defaults to @samp{0}.
10485@end deftypevr
10486
10487@deftypevr {@code{service-configuration} parameter} non-negative-integer vsz-limit
10488If you set @samp{service-count 0}, you probably need to grow
10489this.
10490Defaults to @samp{256000000}.
10491@end deftypevr
10492
10493@end deftypevr
10494
10495@deftypevr {@code{dovecot-configuration} parameter} dict-configuration dict
10496Dict configuration, as created by the @code{dict-configuration}
10497constructor.
10498
10499Available @code{dict-configuration} fields are:
10500
10501@deftypevr {@code{dict-configuration} parameter} free-form-fields entries
10502A list of key-value pairs that this dict should hold.
10503Defaults to @samp{()}.
10504@end deftypevr
10505
10506@end deftypevr
10507
10508@deftypevr {@code{dovecot-configuration} parameter} passdb-configuration-list passdbs
1068f26b 10509A list of passdb configurations, each one created by the
d8c18af8
AW
10510@code{passdb-configuration} constructor.
10511
10512Available @code{passdb-configuration} fields are:
10513
10514@deftypevr {@code{passdb-configuration} parameter} string driver
10515The driver that the passdb should use. Valid values include
10516@samp{pam}, @samp{passwd}, @samp{shadow}, @samp{bsdauth}, and
10517@samp{static}.
10518Defaults to @samp{"pam"}.
10519@end deftypevr
10520
10521@deftypevr {@code{passdb-configuration} parameter} free-form-args args
10522A list of key-value args to the passdb driver.
10523Defaults to @samp{()}.
10524@end deftypevr
10525
10526@end deftypevr
10527
10528@deftypevr {@code{dovecot-configuration} parameter} userdb-configuration-list userdbs
10529List of userdb configurations, each one created by the
10530@code{userdb-configuration} constructor.
10531
10532Available @code{userdb-configuration} fields are:
10533
10534@deftypevr {@code{userdb-configuration} parameter} string driver
10535The driver that the userdb should use. Valid values include
10536@samp{passwd} and @samp{static}.
10537Defaults to @samp{"passwd"}.
10538@end deftypevr
10539
10540@deftypevr {@code{userdb-configuration} parameter} free-form-args args
10541A list of key-value args to the userdb driver.
10542Defaults to @samp{()}.
10543@end deftypevr
10544
10545@deftypevr {@code{userdb-configuration} parameter} free-form-args override-fields
10546Override fields from passwd.
10547Defaults to @samp{()}.
10548@end deftypevr
10549
10550@end deftypevr
10551
10552@deftypevr {@code{dovecot-configuration} parameter} plugin-configuration plugin-configuration
10553Plug-in configuration, created by the @code{plugin-configuration}
10554constructor.
10555@end deftypevr
10556
10557@deftypevr {@code{dovecot-configuration} parameter} list-of-namespace-configuration namespaces
10558List of namespaces. Each item in the list is created by the
10559@code{namespace-configuration} constructor.
10560
10561Available @code{namespace-configuration} fields are:
10562
10563@deftypevr {@code{namespace-configuration} parameter} string name
10564Name for this namespace.
10565@end deftypevr
10566
10567@deftypevr {@code{namespace-configuration} parameter} string type
10568Namespace type: @samp{private}, @samp{shared} or @samp{public}.
10569Defaults to @samp{"private"}.
10570@end deftypevr
10571
10572@deftypevr {@code{namespace-configuration} parameter} string separator
10573Hierarchy separator to use. You should use the same separator for
10574all namespaces or some clients get confused. @samp{/} is usually a good
10575one. The default however depends on the underlying mail storage
10576format.
10577Defaults to @samp{""}.
10578@end deftypevr
10579
10580@deftypevr {@code{namespace-configuration} parameter} string prefix
10581Prefix required to access this namespace. This needs to be
10582different for all namespaces. For example @samp{Public/}.
10583Defaults to @samp{""}.
10584@end deftypevr
10585
10586@deftypevr {@code{namespace-configuration} parameter} string location
1068f26b 10587Physical location of the mailbox. This is in the same format as
d8c18af8
AW
10588mail_location, which is also the default for it.
10589Defaults to @samp{""}.
10590@end deftypevr
10591
10592@deftypevr {@code{namespace-configuration} parameter} boolean inbox?
10593There can be only one INBOX, and this setting defines which
10594namespace has it.
10595Defaults to @samp{#f}.
10596@end deftypevr
10597
10598@deftypevr {@code{namespace-configuration} parameter} boolean hidden?
10599If namespace is hidden, it's not advertised to clients via NAMESPACE
10600extension. You'll most likely also want to set @samp{list? #f}. This is mostly
10601useful when converting from another server with different namespaces
10602which you want to deprecate but still keep working. For example you can
10603create hidden namespaces with prefixes @samp{~/mail/}, @samp{~%u/mail/}
10604and @samp{mail/}.
10605Defaults to @samp{#f}.
10606@end deftypevr
10607
10608@deftypevr {@code{namespace-configuration} parameter} boolean list?
1068f26b
AE
10609Show the mailboxes under this namespace with the LIST command. This
10610makes the namespace visible for clients that do not support the NAMESPACE
d8c18af8
AW
10611extension. The special @code{children} value lists child mailboxes, but
10612hides the namespace prefix.
10613Defaults to @samp{#t}.
10614@end deftypevr
10615
10616@deftypevr {@code{namespace-configuration} parameter} boolean subscriptions?
10617Namespace handles its own subscriptions. If set to @code{#f}, the
10618parent namespace handles them. The empty prefix should always have this
1068f26b 10619as @code{#t}).
d8c18af8
AW
10620Defaults to @samp{#t}.
10621@end deftypevr
10622
10623@deftypevr {@code{namespace-configuration} parameter} mailbox-configuration-list mailboxes
10624List of predefined mailboxes in this namespace.
10625Defaults to @samp{()}.
10626
10627Available @code{mailbox-configuration} fields are:
10628
10629@deftypevr {@code{mailbox-configuration} parameter} string name
10630Name for this mailbox.
10631@end deftypevr
10632
10633@deftypevr {@code{mailbox-configuration} parameter} string auto
10634@samp{create} will automatically create this mailbox.
10635@samp{subscribe} will both create and subscribe to the mailbox.
10636Defaults to @samp{"no"}.
10637@end deftypevr
10638
10639@deftypevr {@code{mailbox-configuration} parameter} space-separated-string-list special-use
10640List of IMAP @code{SPECIAL-USE} attributes as specified by RFC 6154.
10641Valid values are @code{\All}, @code{\Archive}, @code{\Drafts},
10642@code{\Flagged}, @code{\Junk}, @code{\Sent}, and @code{\Trash}.
10643Defaults to @samp{()}.
10644@end deftypevr
10645
10646@end deftypevr
10647
10648@end deftypevr
10649
10650@deftypevr {@code{dovecot-configuration} parameter} file-name base-dir
10651Base directory where to store runtime data.
10652Defaults to @samp{"/var/run/dovecot/"}.
10653@end deftypevr
10654
10655@deftypevr {@code{dovecot-configuration} parameter} string login-greeting
10656Greeting message for clients.
10657Defaults to @samp{"Dovecot ready."}.
10658@end deftypevr
10659
10660@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-trusted-networks
10661List of trusted network ranges. Connections from these IPs are
10662allowed to override their IP addresses and ports (for logging and for
10663authentication checks). @samp{disable-plaintext-auth} is also ignored
1068f26b 10664for these networks. Typically you would specify your IMAP proxy servers
d8c18af8
AW
10665here.
10666Defaults to @samp{()}.
10667@end deftypevr
10668
10669@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-access-sockets
10670List of login access check sockets (e.g. tcpwrap).
10671Defaults to @samp{()}.
10672@end deftypevr
10673
10674@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-proctitle?
10675Show more verbose process titles (in ps). Currently shows user name
1068f26b
AE
10676and IP address. Useful for seeing who is actually using the IMAP
10677processes (e.g. shared mailboxes or if the same uid is used for multiple
d8c18af8
AW
10678accounts).
10679Defaults to @samp{#f}.
10680@end deftypevr
10681
10682@deftypevr {@code{dovecot-configuration} parameter} boolean shutdown-clients?
10683Should all processes be killed when Dovecot master process shuts down.
10684Setting this to @code{#f} means that Dovecot can be upgraded without
10685forcing existing client connections to close (although that could also
1068f26b 10686be a problem if the upgrade is e.g. due to a security fix).
d8c18af8
AW
10687Defaults to @samp{#t}.
10688@end deftypevr
10689
10690@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer doveadm-worker-count
10691If non-zero, run mail commands via this many connections to doveadm
10692server, instead of running them directly in the same process.
10693Defaults to @samp{0}.
10694@end deftypevr
10695
10696@deftypevr {@code{dovecot-configuration} parameter} string doveadm-socket-path
10697UNIX socket or host:port used for connecting to doveadm server.
10698Defaults to @samp{"doveadm-server"}.
10699@end deftypevr
10700
10701@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list import-environment
10702List of environment variables that are preserved on Dovecot startup
10703and passed down to all of its child processes. You can also give
10704key=value pairs to always set specific settings.
10705@end deftypevr
10706
10707@deftypevr {@code{dovecot-configuration} parameter} boolean disable-plaintext-auth?
10708Disable LOGIN command and all other plaintext authentications unless
10709SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
10710matches the local IP (i.e. you're connecting from the same computer),
10711the connection is considered secure and plaintext authentication is
10712allowed. See also ssl=required setting.
10713Defaults to @samp{#t}.
10714@end deftypevr
10715
10716@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-cache-size
10717Authentication cache size (e.g. @samp{#e10e6}). 0 means it's disabled.
10718Note that bsdauth, PAM and vpopmail require @samp{cache-key} to be set
10719for caching to be used.
10720Defaults to @samp{0}.
10721@end deftypevr
10722
10723@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-ttl
10724Time to live for cached data. After TTL expires the cached record
10725is no longer used, *except* if the main database lookup returns internal
10726failure. We also try to handle password changes automatically: If
10727user's previous authentication was successful, but this one wasn't, the
10728cache isn't used. For now this works only with plaintext
10729authentication.
10730Defaults to @samp{"1 hour"}.
10731@end deftypevr
10732
10733@deftypevr {@code{dovecot-configuration} parameter} string auth-cache-negative-ttl
10734TTL for negative hits (user not found, password mismatch).
107350 disables caching them completely.
10736Defaults to @samp{"1 hour"}.
10737@end deftypevr
10738
10739@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-realms
10740List of realms for SASL authentication mechanisms that need them.
10741You can leave it empty if you don't want to support multiple realms.
10742Many clients simply use the first one listed here, so keep the default
10743realm first.
10744Defaults to @samp{()}.
10745@end deftypevr
10746
10747@deftypevr {@code{dovecot-configuration} parameter} string auth-default-realm
10748Default realm/domain to use if none was specified. This is used for
10749both SASL realms and appending @@domain to username in plaintext
10750logins.
10751Defaults to @samp{""}.
10752@end deftypevr
10753
10754@deftypevr {@code{dovecot-configuration} parameter} string auth-username-chars
10755List of allowed characters in username. If the user-given username
10756contains a character not listed in here, the login automatically fails.
10757This is just an extra check to make sure user can't exploit any
10758potential quote escaping vulnerabilities with SQL/LDAP databases. If
10759you want to allow all characters, set this value to empty.
10760Defaults to @samp{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@@"}.
10761@end deftypevr
10762
10763@deftypevr {@code{dovecot-configuration} parameter} string auth-username-translation
10764Username character translations before it's looked up from
10765databases. The value contains series of from -> to characters. For
10766example @samp{#@@/@@} means that @samp{#} and @samp{/} characters are
10767translated to @samp{@@}.
10768Defaults to @samp{""}.
10769@end deftypevr
10770
10771@deftypevr {@code{dovecot-configuration} parameter} string auth-username-format
10772Username formatting before it's looked up from databases. You can
10773use the standard variables here, e.g. %Lu would lowercase the username,
10774%n would drop away the domain if it was given, or @samp{%n-AT-%d} would
10775change the @samp{@@} into @samp{-AT-}. This translation is done after
10776@samp{auth-username-translation} changes.
10777Defaults to @samp{"%Lu"}.
10778@end deftypevr
10779
10780@deftypevr {@code{dovecot-configuration} parameter} string auth-master-user-separator
10781If you want to allow master users to log in by specifying the master
10782username within the normal username string (i.e. not using SASL
10783mechanism's support for it), you can specify the separator character
10784here. The format is then <username><separator><master username>.
10785UW-IMAP uses @samp{*} as the separator, so that could be a good
10786choice.
10787Defaults to @samp{""}.
10788@end deftypevr
10789
10790@deftypevr {@code{dovecot-configuration} parameter} string auth-anonymous-username
10791Username to use for users logging in with ANONYMOUS SASL
10792mechanism.
10793Defaults to @samp{"anonymous"}.
10794@end deftypevr
10795
10796@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer auth-worker-max-count
10797Maximum number of dovecot-auth worker processes. They're used to
10798execute blocking passdb and userdb queries (e.g. MySQL and PAM).
10799They're automatically created and destroyed as needed.
10800Defaults to @samp{30}.
10801@end deftypevr
10802
10803@deftypevr {@code{dovecot-configuration} parameter} string auth-gssapi-hostname
10804Host name to use in GSSAPI principal names. The default is to use
10805the name returned by gethostname(). Use @samp{$ALL} (with quotes) to
10806allow all keytab entries.
10807Defaults to @samp{""}.
10808@end deftypevr
10809
10810@deftypevr {@code{dovecot-configuration} parameter} string auth-krb5-keytab
10811Kerberos keytab to use for the GSSAPI mechanism. Will use the
8b499030 10812system default (usually @file{/etc/krb5.keytab}) if not specified. You may
d8c18af8
AW
10813need to change the auth service to run as root to be able to read this
10814file.
10815Defaults to @samp{""}.
10816@end deftypevr
10817
10818@deftypevr {@code{dovecot-configuration} parameter} boolean auth-use-winbind?
10819Do NTLM and GSS-SPNEGO authentication using Samba's winbind daemon
10820and @samp{ntlm-auth} helper.
10821<doc/wiki/Authentication/Mechanisms/Winbind.txt>.
10822Defaults to @samp{#f}.
10823@end deftypevr
10824
10825@deftypevr {@code{dovecot-configuration} parameter} file-name auth-winbind-helper-path
10826Path for Samba's @samp{ntlm-auth} helper binary.
10827Defaults to @samp{"/usr/bin/ntlm_auth"}.
10828@end deftypevr
10829
10830@deftypevr {@code{dovecot-configuration} parameter} string auth-failure-delay
10831Time to delay before replying to failed authentications.
10832Defaults to @samp{"2 secs"}.
10833@end deftypevr
10834
10835@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-require-client-cert?
10836Require a valid SSL client certificate or the authentication
10837fails.
10838Defaults to @samp{#f}.
10839@end deftypevr
10840
10841@deftypevr {@code{dovecot-configuration} parameter} boolean auth-ssl-username-from-cert?
10842Take the username from client's SSL certificate, using
10843@code{X509_NAME_get_text_by_NID()} which returns the subject's DN's
10844CommonName.
10845Defaults to @samp{#f}.
10846@end deftypevr
10847
10848@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list auth-mechanisms
10849List of wanted authentication mechanisms. Supported mechanisms are:
10850@samp{plain}, @samp{login}, @samp{digest-md5}, @samp{cram-md5},
10851@samp{ntlm}, @samp{rpa}, @samp{apop}, @samp{anonymous}, @samp{gssapi},
10852@samp{otp}, @samp{skey}, and @samp{gss-spnego}. NOTE: See also
10853@samp{disable-plaintext-auth} setting.
10854@end deftypevr
10855
10856@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-servers
10857List of IPs or hostnames to all director servers, including ourself.
10858Ports can be specified as ip:port. The default port is the same as what
10859director service's @samp{inet-listener} is using.
10860Defaults to @samp{()}.
10861@end deftypevr
10862
10863@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list director-mail-servers
10864List of IPs or hostnames to all backend mail servers. Ranges are
10865allowed too, like 10.0.0.10-10.0.0.30.
10866Defaults to @samp{()}.
10867@end deftypevr
10868
10869@deftypevr {@code{dovecot-configuration} parameter} string director-user-expire
10870How long to redirect users to a specific server after it no longer
10871has any connections.
10872Defaults to @samp{"15 min"}.
10873@end deftypevr
10874
10875@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer director-doveadm-port
10876TCP/IP port that accepts doveadm connections (instead of director
10877connections) If you enable this, you'll also need to add
10878@samp{inet-listener} for the port.
10879Defaults to @samp{0}.
10880@end deftypevr
10881
10882@deftypevr {@code{dovecot-configuration} parameter} string director-username-hash
10883How the username is translated before being hashed. Useful values
10884include %Ln if user can log in with or without @@domain, %Ld if mailboxes
10885are shared within domain.
10886Defaults to @samp{"%Lu"}.
10887@end deftypevr
10888
10889@deftypevr {@code{dovecot-configuration} parameter} string log-path
10890Log file to use for error messages. @samp{syslog} logs to syslog,
10891@samp{/dev/stderr} logs to stderr.
10892Defaults to @samp{"syslog"}.
10893@end deftypevr
10894
10895@deftypevr {@code{dovecot-configuration} parameter} string info-log-path
10896Log file to use for informational messages. Defaults to
10897@samp{log-path}.
10898Defaults to @samp{""}.
10899@end deftypevr
10900
10901@deftypevr {@code{dovecot-configuration} parameter} string debug-log-path
10902Log file to use for debug messages. Defaults to
10903@samp{info-log-path}.
10904Defaults to @samp{""}.
10905@end deftypevr
10906
10907@deftypevr {@code{dovecot-configuration} parameter} string syslog-facility
10908Syslog facility to use if you're logging to syslog. Usually if you
10909don't want to use @samp{mail}, you'll use local0..local7. Also other
10910standard facilities are supported.
10911Defaults to @samp{"mail"}.
10912@end deftypevr
10913
10914@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose?
10915Log unsuccessful authentication attempts and the reasons why they
10916failed.
10917Defaults to @samp{#f}.
10918@end deftypevr
10919
10920@deftypevr {@code{dovecot-configuration} parameter} boolean auth-verbose-passwords?
10921In case of password mismatches, log the attempted password. Valid
10922values are no, plain and sha1. sha1 can be useful for detecting brute
10923force password attempts vs. user simply trying the same password over
10924and over again. You can also truncate the value to n chars by appending
10925":n" (e.g. sha1:6).
10926Defaults to @samp{#f}.
10927@end deftypevr
10928
10929@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug?
10930Even more verbose logging for debugging purposes. Shows for example
10931SQL queries.
10932Defaults to @samp{#f}.
10933@end deftypevr
10934
10935@deftypevr {@code{dovecot-configuration} parameter} boolean auth-debug-passwords?
10936In case of password mismatches, log the passwords and used scheme so
10937the problem can be debugged. Enabling this also enables
10938@samp{auth-debug}.
10939Defaults to @samp{#f}.
10940@end deftypevr
10941
10942@deftypevr {@code{dovecot-configuration} parameter} boolean mail-debug?
10943Enable mail process debugging. This can help you figure out why
10944Dovecot isn't finding your mails.
10945Defaults to @samp{#f}.
10946@end deftypevr
10947
10948@deftypevr {@code{dovecot-configuration} parameter} boolean verbose-ssl?
10949Show protocol level SSL errors.
10950Defaults to @samp{#f}.
10951@end deftypevr
10952
10953@deftypevr {@code{dovecot-configuration} parameter} string log-timestamp
10954Prefix for each line written to log file. % codes are in
10955strftime(3) format.
10956Defaults to @samp{"\"%b %d %H:%M:%S \""}.
10957@end deftypevr
10958
10959@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list login-log-format-elements
10960List of elements we want to log. The elements which have a
10961non-empty variable value are joined together to form a comma-separated
10962string.
10963@end deftypevr
10964
10965@deftypevr {@code{dovecot-configuration} parameter} string login-log-format
10966Login log format. %s contains @samp{login-log-format-elements}
10967string, %$ contains the data we want to log.
10968Defaults to @samp{"%$: %s"}.
10969@end deftypevr
10970
10971@deftypevr {@code{dovecot-configuration} parameter} string mail-log-prefix
10972Log prefix for mail processes. See doc/wiki/Variables.txt for list
10973of possible variables you can use.
10974Defaults to @samp{"\"%s(%u): \""}.
10975@end deftypevr
10976
10977@deftypevr {@code{dovecot-configuration} parameter} string deliver-log-format
10978Format to use for logging mail deliveries. You can use variables:
10979@table @code
10980@item %$
10981Delivery status message (e.g. @samp{saved to INBOX})
10982@item %m
10983Message-ID
10984@item %s
10985Subject
10986@item %f
10987From address
10988@item %p
10989Physical size
10990@item %w
10991Virtual size.
10992@end table
10993Defaults to @samp{"msgid=%m: %$"}.
10994@end deftypevr
10995
10996@deftypevr {@code{dovecot-configuration} parameter} string mail-location
10997Location for users' mailboxes. The default is empty, which means
10998that Dovecot tries to find the mailboxes automatically. This won't work
10999if the user doesn't yet have any mail, so you should explicitly tell
11000Dovecot the full location.
11001
11002If you're using mbox, giving a path to the INBOX
11003file (e.g. /var/mail/%u) isn't enough. You'll also need to tell Dovecot
11004where the other mailboxes are kept. This is called the "root mail
11005directory", and it must be the first path given in the
11006@samp{mail-location} setting.
11007
11008There are a few special variables you can use, eg.:
11009
11010@table @samp
11011@item %u
11012username
11013@item %n
11014user part in user@@domain, same as %u if there's no domain
11015@item %d
11016domain part in user@@domain, empty if there's no domain
11017@item %h
11018home director
11019@end table
11020
11021See doc/wiki/Variables.txt for full list. Some examples:
11022@table @samp
11023@item maildir:~/Maildir
11024@item mbox:~/mail:INBOX=/var/mail/%u
11025@item mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%
11026@end table
11027Defaults to @samp{""}.
11028@end deftypevr
11029
11030@deftypevr {@code{dovecot-configuration} parameter} string mail-uid
11031System user and group used to access mails. If you use multiple,
11032userdb can override these by returning uid or gid fields. You can use
11033either numbers or names. <doc/wiki/UserIds.txt>.
11034Defaults to @samp{""}.
11035@end deftypevr
11036
11037@deftypevr {@code{dovecot-configuration} parameter} string mail-gid
11038
11039Defaults to @samp{""}.
11040@end deftypevr
11041
11042@deftypevr {@code{dovecot-configuration} parameter} string mail-privileged-group
11043Group to enable temporarily for privileged operations. Currently
11044this is used only with INBOX when either its initial creation or
11045dotlocking fails. Typically this is set to "mail" to give access to
11046/var/mail.
11047Defaults to @samp{""}.
11048@end deftypevr
11049
11050@deftypevr {@code{dovecot-configuration} parameter} string mail-access-groups
11051Grant access to these supplementary groups for mail processes.
11052Typically these are used to set up access to shared mailboxes. Note
11053that it may be dangerous to set these if users can create
11054symlinks (e.g. if "mail" group is set here, ln -s /var/mail ~/mail/var
11055could allow a user to delete others' mailboxes, or ln -s
11056/secret/shared/box ~/mail/mybox would allow reading it).
11057Defaults to @samp{""}.
11058@end deftypevr
11059
11060@deftypevr {@code{dovecot-configuration} parameter} boolean mail-full-filesystem-access?
8f65585b 11061Allow full file system access to clients. There's no access checks
d8c18af8
AW
11062other than what the operating system does for the active UID/GID. It
11063works with both maildir and mboxes, allowing you to prefix mailboxes
11064names with e.g. /path/ or ~user/.
11065Defaults to @samp{#f}.
11066@end deftypevr
11067
11068@deftypevr {@code{dovecot-configuration} parameter} boolean mmap-disable?
11069Don't use mmap() at all. This is required if you store indexes to
8f65585b 11070shared file systems (NFS or clustered file system).
d8c18af8
AW
11071Defaults to @samp{#f}.
11072@end deftypevr
11073
11074@deftypevr {@code{dovecot-configuration} parameter} boolean dotlock-use-excl?
11075Rely on @samp{O_EXCL} to work when creating dotlock files. NFS
11076supports @samp{O_EXCL} since version 3, so this should be safe to use
11077nowadays by default.
11078Defaults to @samp{#t}.
11079@end deftypevr
11080
11081@deftypevr {@code{dovecot-configuration} parameter} string mail-fsync
11082When to use fsync() or fdatasync() calls:
11083@table @code
11084@item optimized
11085Whenever necessary to avoid losing important data
11086@item always
11087Useful with e.g. NFS when write()s are delayed
11088@item never
11089Never use it (best performance, but crashes can lose data).
11090@end table
11091Defaults to @samp{"optimized"}.
11092@end deftypevr
11093
11094@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-storage?
11095Mail storage exists in NFS. Set this to yes to make Dovecot flush
11096NFS caches whenever needed. If you're using only a single mail server
11097this isn't needed.
11098Defaults to @samp{#f}.
11099@end deftypevr
11100
11101@deftypevr {@code{dovecot-configuration} parameter} boolean mail-nfs-index?
11102Mail index files also exist in NFS. Setting this to yes requires
11103@samp{mmap-disable? #t} and @samp{fsync-disable? #f}.
11104Defaults to @samp{#f}.
11105@end deftypevr
11106
11107@deftypevr {@code{dovecot-configuration} parameter} string lock-method
11108Locking method for index files. Alternatives are fcntl, flock and
11109dotlock. Dotlocking uses some tricks which may create more disk I/O
11110than other locking methods. NFS users: flock doesn't work, remember to
11111change @samp{mmap-disable}.
11112Defaults to @samp{"fcntl"}.
11113@end deftypevr
11114
11115@deftypevr {@code{dovecot-configuration} parameter} file-name mail-temp-dir
11116Directory in which LDA/LMTP temporarily stores incoming mails >128
11117kB.
11118Defaults to @samp{"/tmp"}.
11119@end deftypevr
11120
11121@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-uid
11122Valid UID range for users. This is mostly to make sure that users can't
11123log in as daemons or other system users. Note that denying root logins is
11124hardcoded to dovecot binary and can't be done even if @samp{first-valid-uid}
11125is set to 0.
11126Defaults to @samp{500}.
11127@end deftypevr
11128
11129@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-uid
11130
11131Defaults to @samp{0}.
11132@end deftypevr
11133
11134@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer first-valid-gid
11135Valid GID range for users. Users having non-valid GID as primary group ID
11136aren't allowed to log in. If user belongs to supplementary groups with
11137non-valid GIDs, those groups are not set.
11138Defaults to @samp{1}.
11139@end deftypevr
11140
11141@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer last-valid-gid
11142
11143Defaults to @samp{0}.
11144@end deftypevr
11145
11146@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-max-keyword-length
11147Maximum allowed length for mail keyword name. It's only forced when
11148trying to create new keywords.
11149Defaults to @samp{50}.
11150@end deftypevr
11151
11152@deftypevr {@code{dovecot-configuration} parameter} colon-separated-file-name-list valid-chroot-dirs
11153List of directories under which chrooting is allowed for mail
11154processes (i.e. /var/mail will allow chrooting to /var/mail/foo/bar
11155too). This setting doesn't affect @samp{login-chroot}
11156@samp{mail-chroot} or auth chroot settings. If this setting is empty,
11157"/./" in home dirs are ignored. WARNING: Never add directories here
11158which local users can modify, that may lead to root exploit. Usually
11159this should be done only if you don't allow shell access for users.
11160<doc/wiki/Chrooting.txt>.
11161Defaults to @samp{()}.
11162@end deftypevr
11163
11164@deftypevr {@code{dovecot-configuration} parameter} string mail-chroot
11165Default chroot directory for mail processes. This can be overridden
11166for specific users in user database by giving /./ in user's home
11167directory (e.g. /home/./user chroots into /home). Note that usually
11168there is no real need to do chrooting, Dovecot doesn't allow users to
11169access files outside their mail directory anyway. If your home
11170directories are prefixed with the chroot directory, append "/." to
11171@samp{mail-chroot}. <doc/wiki/Chrooting.txt>.
11172Defaults to @samp{""}.
11173@end deftypevr
11174
11175@deftypevr {@code{dovecot-configuration} parameter} file-name auth-socket-path
11176UNIX socket path to master authentication server to find users.
11177This is used by imap (for shared users) and lda.
11178Defaults to @samp{"/var/run/dovecot/auth-userdb"}.
11179@end deftypevr
11180
11181@deftypevr {@code{dovecot-configuration} parameter} file-name mail-plugin-dir
11182Directory where to look up mail plugins.
11183Defaults to @samp{"/usr/lib/dovecot"}.
11184@end deftypevr
11185
11186@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mail-plugins
11187List of plugins to load for all services. Plugins specific to IMAP,
11188LDA, etc. are added to this list in their own .conf files.
11189Defaults to @samp{()}.
11190@end deftypevr
11191
11192@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-cache-min-mail-count
11193The minimum number of mails in a mailbox before updates are done to
11194cache file. This allows optimizing Dovecot's behavior to do less disk
11195writes at the cost of more disk reads.
11196Defaults to @samp{0}.
11197@end deftypevr
11198
11199@deftypevr {@code{dovecot-configuration} parameter} string mailbox-idle-check-interval
11200When IDLE command is running, mailbox is checked once in a while to
11201see if there are any new mails or other changes. This setting defines
11202the minimum time to wait between those checks. Dovecot can also use
11203dnotify, inotify and kqueue to find out immediately when changes
11204occur.
11205Defaults to @samp{"30 secs"}.
11206@end deftypevr
11207
11208@deftypevr {@code{dovecot-configuration} parameter} boolean mail-save-crlf?
11209Save mails with CR+LF instead of plain LF. This makes sending those
11210mails take less CPU, especially with sendfile() syscall with Linux and
11211FreeBSD. But it also creates a bit more disk I/O which may just make it
11212slower. Also note that if other software reads the mboxes/maildirs,
11213they may handle the extra CRs wrong and cause problems.
11214Defaults to @samp{#f}.
11215@end deftypevr
11216
11217@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-stat-dirs?
11218By default LIST command returns all entries in maildir beginning
11219with a dot. Enabling this option makes Dovecot return only entries
11220which are directories. This is done by stat()ing each entry, so it
11221causes more disk I/O.
11222 (For systems setting struct @samp{dirent->d_type} this check is free
11223and it's done always regardless of this setting).
11224Defaults to @samp{#f}.
11225@end deftypevr
11226
11227@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-copy-with-hardlinks?
11228When copying a message, do it with hard links whenever possible.
11229This makes the performance much better, and it's unlikely to have any
11230side effects.
11231Defaults to @samp{#t}.
11232@end deftypevr
11233
11234@deftypevr {@code{dovecot-configuration} parameter} boolean maildir-very-dirty-syncs?
11235Assume Dovecot is the only MUA accessing Maildir: Scan cur/
11236directory only when its mtime changes unexpectedly or when we can't find
11237the mail otherwise.
11238Defaults to @samp{#f}.
11239@end deftypevr
11240
11241@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-read-locks
11242Which locking methods to use for locking mbox. There are four
11243available:
11244
11245@table @code
11246@item dotlock
11247Create <mailbox>.lock file. This is the oldest and most NFS-safe
11248solution. If you want to use /var/mail/ like directory, the users will
11249need write access to that directory.
11250@item dotlock-try
11251Same as dotlock, but if it fails because of permissions or because there
11252isn't enough disk space, just skip it.
11253@item fcntl
11254Use this if possible. Works with NFS too if lockd is used.
11255@item flock
a01ad638 11256May not exist in all systems. Doesn't work with NFS.
d8c18af8
AW
11257@item lockf
11258May not exist in all systems. Doesn't work with NFS.
11259@end table
11260
11261You can use multiple locking methods; if you do the order they're declared
11262in is important to avoid deadlocks if other MTAs/MUAs are using multiple
11263locking methods as well. Some operating systems don't allow using some of
11264them simultaneously.
11265@end deftypevr
11266
11267@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list mbox-write-locks
11268
11269@end deftypevr
11270
11271@deftypevr {@code{dovecot-configuration} parameter} string mbox-lock-timeout
11272Maximum time to wait for lock (all of them) before aborting.
11273Defaults to @samp{"5 mins"}.
11274@end deftypevr
11275
11276@deftypevr {@code{dovecot-configuration} parameter} string mbox-dotlock-change-timeout
11277If dotlock exists but the mailbox isn't modified in any way,
11278override the lock file after this much time.
11279Defaults to @samp{"2 mins"}.
11280@end deftypevr
11281
11282@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-dirty-syncs?
11283When mbox changes unexpectedly we have to fully read it to find out
11284what changed. If the mbox is large this can take a long time. Since
11285the change is usually just a newly appended mail, it'd be faster to
11286simply read the new mails. If this setting is enabled, Dovecot does
11287this but still safely fallbacks to re-reading the whole mbox file
11288whenever something in mbox isn't how it's expected to be. The only real
11289downside to this setting is that if some other MUA changes message
11290flags, Dovecot doesn't notice it immediately. Note that a full sync is
11291done with SELECT, EXAMINE, EXPUNGE and CHECK commands.
11292Defaults to @samp{#t}.
11293@end deftypevr
11294
11295@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-very-dirty-syncs?
11296Like @samp{mbox-dirty-syncs}, but don't do full syncs even with SELECT,
11297EXAMINE, EXPUNGE or CHECK commands. If this is set,
11298@samp{mbox-dirty-syncs} is ignored.
11299Defaults to @samp{#f}.
11300@end deftypevr
11301
11302@deftypevr {@code{dovecot-configuration} parameter} boolean mbox-lazy-writes?
11303Delay writing mbox headers until doing a full write sync (EXPUNGE
11304and CHECK commands and when closing the mailbox). This is especially
11305useful for POP3 where clients often delete all mails. The downside is
11306that our changes aren't immediately visible to other MUAs.
11307Defaults to @samp{#t}.
11308@end deftypevr
11309
11310@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mbox-min-index-size
11311If mbox size is smaller than this (e.g. 100k), don't write index
11312files. If an index file already exists it's still read, just not
11313updated.
11314Defaults to @samp{0}.
11315@end deftypevr
11316
11317@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mdbox-rotate-size
11318Maximum dbox file size until it's rotated.
11319Defaults to @samp{2000000}.
11320@end deftypevr
11321
11322@deftypevr {@code{dovecot-configuration} parameter} string mdbox-rotate-interval
11323Maximum dbox file age until it's rotated. Typically in days. Day
11324begins from midnight, so 1d = today, 2d = yesterday, etc. 0 = check
11325disabled.
11326Defaults to @samp{"1d"}.
11327@end deftypevr
11328
11329@deftypevr {@code{dovecot-configuration} parameter} boolean mdbox-preallocate-space?
11330When creating new mdbox files, immediately preallocate their size to
11331@samp{mdbox-rotate-size}. This setting currently works only in Linux
8f65585b 11332with some file systems (ext4, xfs).
d8c18af8
AW
11333Defaults to @samp{#f}.
11334@end deftypevr
11335
11336@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-dir
11337sdbox and mdbox support saving mail attachments to external files,
11338which also allows single instance storage for them. Other backends
11339don't support this for now.
11340
11341WARNING: This feature hasn't been tested much yet. Use at your own risk.
11342
11343Directory root where to store mail attachments. Disabled, if empty.
11344Defaults to @samp{""}.
11345@end deftypevr
11346
11347@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer mail-attachment-min-size
11348Attachments smaller than this aren't saved externally. It's also
11349possible to write a plugin to disable saving specific attachments
11350externally.
11351Defaults to @samp{128000}.
11352@end deftypevr
11353
11354@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-fs
8f65585b 11355File system backend to use for saving attachments:
d8c18af8
AW
11356@table @code
11357@item posix
11358No SiS done by Dovecot (but this might help FS's own deduplication)
11359@item sis posix
11360SiS with immediate byte-by-byte comparison during saving
11361@item sis-queue posix
11362SiS with delayed comparison and deduplication.
11363@end table
11364Defaults to @samp{"sis posix"}.
11365@end deftypevr
11366
11367@deftypevr {@code{dovecot-configuration} parameter} string mail-attachment-hash
11368Hash format to use in attachment filenames. You can add any text and
11369variables: @code{%@{md4@}}, @code{%@{md5@}}, @code{%@{sha1@}},
11370@code{%@{sha256@}}, @code{%@{sha512@}}, @code{%@{size@}}. Variables can be
11371truncated, e.g. @code{%@{sha256:80@}} returns only first 80 bits.
11372Defaults to @samp{"%@{sha1@}"}.
11373@end deftypevr
11374
11375@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-process-limit
11376
11377Defaults to @samp{100}.
11378@end deftypevr
11379
11380@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-client-limit
11381
11382Defaults to @samp{1000}.
11383@end deftypevr
11384
11385@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer default-vsz-limit
11386Default VSZ (virtual memory size) limit for service processes.
11387This is mainly intended to catch and kill processes that leak memory
11388before they eat up everything.
11389Defaults to @samp{256000000}.
11390@end deftypevr
11391
11392@deftypevr {@code{dovecot-configuration} parameter} string default-login-user
11393Login user is internally used by login processes. This is the most
11394untrusted user in Dovecot system. It shouldn't have access to anything
11395at all.
11396Defaults to @samp{"dovenull"}.
11397@end deftypevr
11398
11399@deftypevr {@code{dovecot-configuration} parameter} string default-internal-user
11400Internal user is used by unprivileged processes. It should be
11401separate from login user, so that login processes can't disturb other
11402processes.
11403Defaults to @samp{"dovecot"}.
11404@end deftypevr
11405
11406@deftypevr {@code{dovecot-configuration} parameter} string ssl?
11407SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>.
11408Defaults to @samp{"required"}.
11409@end deftypevr
11410
11411@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert
11412PEM encoded X.509 SSL/TLS certificate (public key).
11413Defaults to @samp{"</etc/dovecot/default.pem"}.
11414@end deftypevr
11415
11416@deftypevr {@code{dovecot-configuration} parameter} string ssl-key
11417PEM encoded SSL/TLS private key. The key is opened before
11418dropping root privileges, so keep the key file unreadable by anyone but
11419root.
11420Defaults to @samp{"</etc/dovecot/private/default.pem"}.
11421@end deftypevr
11422
11423@deftypevr {@code{dovecot-configuration} parameter} string ssl-key-password
11424If key file is password protected, give the password here.
11425Alternatively give it when starting dovecot with -p parameter. Since
11426this file is often world-readable, you may want to place this setting
11427instead to a different.
11428Defaults to @samp{""}.
11429@end deftypevr
11430
11431@deftypevr {@code{dovecot-configuration} parameter} string ssl-ca
11432PEM encoded trusted certificate authority. Set this only if you
11433intend to use @samp{ssl-verify-client-cert? #t}. The file should
11434contain the CA certificate(s) followed by the matching
11435CRL(s). (e.g. @samp{ssl-ca </etc/ssl/certs/ca.pem}).
11436Defaults to @samp{""}.
11437@end deftypevr
11438
11439@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-require-crl?
11440Require that CRL check succeeds for client certificates.
11441Defaults to @samp{#t}.
11442@end deftypevr
11443
11444@deftypevr {@code{dovecot-configuration} parameter} boolean ssl-verify-client-cert?
11445Request client to send a certificate. If you also want to require
11446it, set @samp{auth-ssl-require-client-cert? #t} in auth section.
11447Defaults to @samp{#f}.
11448@end deftypevr
11449
11450@deftypevr {@code{dovecot-configuration} parameter} string ssl-cert-username-field
11451Which field from certificate to use for username. commonName and
11452x500UniqueIdentifier are the usual choices. You'll also need to set
11453@samp{auth-ssl-username-from-cert? #t}.
11454Defaults to @samp{"commonName"}.
11455@end deftypevr
11456
11457@deftypevr {@code{dovecot-configuration} parameter} hours ssl-parameters-regenerate
11458How often to regenerate the SSL parameters file. Generation is
11459quite CPU intensive operation. The value is in hours, 0 disables
11460regeneration entirely.
11461Defaults to @samp{168}.
11462@end deftypevr
11463
11464@deftypevr {@code{dovecot-configuration} parameter} string ssl-protocols
11465SSL protocols to use.
11466Defaults to @samp{"!SSLv2"}.
11467@end deftypevr
11468
11469@deftypevr {@code{dovecot-configuration} parameter} string ssl-cipher-list
11470SSL ciphers to use.
11471Defaults to @samp{"ALL:!LOW:!SSLv2:!EXP:!aNULL"}.
11472@end deftypevr
11473
11474@deftypevr {@code{dovecot-configuration} parameter} string ssl-crypto-device
11475SSL crypto device to use, for valid values run "openssl engine".
11476Defaults to @samp{""}.
11477@end deftypevr
11478
11479@deftypevr {@code{dovecot-configuration} parameter} string postmaster-address
11480Address to use when sending rejection mails.
66329c23
AW
11481%d expands to recipient domain.
11482Defaults to @samp{"postmaster@@%d"}.
d8c18af8
AW
11483@end deftypevr
11484
11485@deftypevr {@code{dovecot-configuration} parameter} string hostname
11486Hostname to use in various parts of sent mails (e.g. in Message-Id)
11487and in LMTP replies. Default is the system's real hostname@@domain.
11488Defaults to @samp{""}.
11489@end deftypevr
11490
11491@deftypevr {@code{dovecot-configuration} parameter} boolean quota-full-tempfail?
11492If user is over quota, return with temporary failure instead of
11493bouncing the mail.
11494Defaults to @samp{#f}.
11495@end deftypevr
11496
11497@deftypevr {@code{dovecot-configuration} parameter} file-name sendmail-path
11498Binary to use for sending mails.
11499Defaults to @samp{"/usr/sbin/sendmail"}.
11500@end deftypevr
11501
11502@deftypevr {@code{dovecot-configuration} parameter} string submission-host
11503If non-empty, send mails via this SMTP host[:port] instead of
11504sendmail.
11505Defaults to @samp{""}.
11506@end deftypevr
11507
11508@deftypevr {@code{dovecot-configuration} parameter} string rejection-subject
11509Subject: header to use for rejection mails. You can use the same
11510variables as for @samp{rejection-reason} below.
11511Defaults to @samp{"Rejected: %s"}.
11512@end deftypevr
11513
11514@deftypevr {@code{dovecot-configuration} parameter} string rejection-reason
11515Human readable error message for rejection mails. You can use
11516variables:
11517
11518@table @code
11519@item %n
11520CRLF
11521@item %r
11522reason
11523@item %s
11524original subject
11525@item %t
11526recipient
11527@end table
11528Defaults to @samp{"Your message to <%t> was automatically rejected:%n%r"}.
11529@end deftypevr
11530
11531@deftypevr {@code{dovecot-configuration} parameter} string recipient-delimiter
11532Delimiter character between local-part and detail in email
11533address.
11534Defaults to @samp{"+"}.
11535@end deftypevr
11536
11537@deftypevr {@code{dovecot-configuration} parameter} string lda-original-recipient-header
11538Header where the original recipient address (SMTP's RCPT TO:
11539address) is taken from if not available elsewhere. With dovecot-lda -a
11540parameter overrides this. A commonly used header for this is
11541X-Original-To.
11542Defaults to @samp{""}.
11543@end deftypevr
11544
11545@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autocreate?
11546Should saving a mail to a nonexistent mailbox automatically create
11547it?.
11548Defaults to @samp{#f}.
11549@end deftypevr
11550
11551@deftypevr {@code{dovecot-configuration} parameter} boolean lda-mailbox-autosubscribe?
11552Should automatically created mailboxes be also automatically
11553subscribed?.
11554Defaults to @samp{#f}.
11555@end deftypevr
11556
11557@deftypevr {@code{dovecot-configuration} parameter} non-negative-integer imap-max-line-length
11558Maximum IMAP command line length. Some clients generate very long
11559command lines with huge mailboxes, so you may need to raise this if you
11560get "Too long argument" or "IMAP command line too large" errors
11561often.
11562Defaults to @samp{64000}.
11563@end deftypevr
11564
11565@deftypevr {@code{dovecot-configuration} parameter} string imap-logout-format
11566IMAP logout format string:
11567@table @code
11568@item %i
11569total number of bytes read from client
11570@item %o
11571total number of bytes sent to client.
11572@end table
11573Defaults to @samp{"in=%i out=%o"}.
11574@end deftypevr
11575
11576@deftypevr {@code{dovecot-configuration} parameter} string imap-capability
11577Override the IMAP CAPABILITY response. If the value begins with '+',
11578add the given capabilities on top of the defaults (e.g. +XFOO XBAR).
11579Defaults to @samp{""}.
11580@end deftypevr
11581
11582@deftypevr {@code{dovecot-configuration} parameter} string imap-idle-notify-interval
11583How long to wait between "OK Still here" notifications when client
11584is IDLEing.
11585Defaults to @samp{"2 mins"}.
11586@end deftypevr
11587
11588@deftypevr {@code{dovecot-configuration} parameter} string imap-id-send
11589ID field names and values to send to clients. Using * as the value
11590makes Dovecot use the default value. The following fields have default
11591values currently: name, version, os, os-version, support-url,
11592support-email.
11593Defaults to @samp{""}.
11594@end deftypevr
11595
11596@deftypevr {@code{dovecot-configuration} parameter} string imap-id-log
11597ID fields sent by client to log. * means everything.
11598Defaults to @samp{""}.
11599@end deftypevr
11600
11601@deftypevr {@code{dovecot-configuration} parameter} space-separated-string-list imap-client-workarounds
11602Workarounds for various client bugs:
11603
11604@table @code
11605@item delay-newmail
11606Send EXISTS/RECENT new mail notifications only when replying to NOOP and
11607CHECK commands. Some clients ignore them otherwise, for example OSX
11608Mail (<v2.1). Outlook Express breaks more badly though, without this it
11609may show user "Message no longer in server" errors. Note that OE6
11610still breaks even with this workaround if synchronization is set to
11611"Headers Only".
11612
11613@item tb-extra-mailbox-sep
11614Thunderbird gets somehow confused with LAYOUT=fs (mbox and dbox) and
11615adds extra @samp{/} suffixes to mailbox names. This option causes Dovecot to
11616ignore the extra @samp{/} instead of treating it as invalid mailbox name.
11617
11618@item tb-lsub-flags
11619Show \Noselect flags for LSUB replies with LAYOUT=fs (e.g. mbox).
11620This makes Thunderbird realize they aren't selectable and show them
11621greyed out, instead of only later giving "not selectable" popup error.
11622@end table
11623Defaults to @samp{()}.
11624@end deftypevr
11625
11626@deftypevr {@code{dovecot-configuration} parameter} string imap-urlauth-host
11627Host allowed in URLAUTH URLs sent by client. "*" allows all.
11628Defaults to @samp{""}.
11629@end deftypevr
11630
11631
11632Whew! Lots of configuration options. The nice thing about it though is
11633that GuixSD has a complete interface to Dovecot's configuration
11634language. This allows not only a nice way to declare configurations,
11635but also offers reflective capabilities as well: users can write code to
11636inspect and transform configurations from within Scheme.
11637
11638However, it could be that you just want to get a @code{dovecot.conf} up
11639and running. In that case, you can pass an
7414de0a 11640@code{opaque-dovecot-configuration} as the @code{#:config} parameter to
d8c18af8
AW
11641@code{dovecot-service}. As its name indicates, an opaque configuration
11642does not have easy reflective capabilities.
11643
11644Available @code{opaque-dovecot-configuration} fields are:
11645
11646@deftypevr {@code{opaque-dovecot-configuration} parameter} package dovecot
11647The dovecot package.
11648@end deftypevr
11649
11650@deftypevr {@code{opaque-dovecot-configuration} parameter} string string
11651The contents of the @code{dovecot.conf}, as a string.
11652@end deftypevr
11653
11654For example, if your @code{dovecot.conf} is just the empty string, you
11655could instantiate a dovecot service like this:
11656
11657@example
11658(dovecot-service #:config
11659 (opaque-dovecot-configuration
11660 (string "")))
11661@end example
11662
f88371e8
SB
11663@subsubheading OpenSMTPD Service
11664
11665@deffn {Scheme Variable} opensmtpd-service-type
11666This is the type of the @uref{https://www.opensmtpd.org, OpenSMTPD}
11667service, whose value should be an @code{opensmtpd-configuration} object
11668as in this example:
11669
11670@example
11671(service opensmtpd-service-type
11672 (opensmtpd-configuration
11673 (config-file (local-file "./my-smtpd.conf"))))
11674@end example
11675@end deffn
11676
11677@deftp {Data Type} opensmtpd-configuration
11678Data type regresenting the configuration of opensmtpd.
11679
11680@table @asis
11681@item @code{package} (default: @var{opensmtpd})
11682Package object of the OpenSMTPD SMTP server.
11683
11684@item @code{config-file} (default: @var{%default-opensmtpd-file})
11685File-like object of the OpenSMTPD configuration file to use. By default
11686it listens on the loopback network interface, and allows for mail from
11687users and daemons on the local machine, as well as permitting email to
11688remote servers. Run @command{man smtpd.conf} for more information.
11689
11690@end table
11691@end deftp
859e367d
JD
11692
11693@node Kerberos Services
11694@subsubsection Kerberos Services
11695@cindex Kerberos
11696
df31e36a 11697The @code{(gnu services kerberos)} module provides services relating to
859e367d
JD
11698the authentication protocol @dfn{Kerberos}.
11699
8e3f813f
JD
11700@subsubheading Krb5 Service
11701
11702Programs using a Kerberos client library normally
11703expect a configuration file in @file{/etc/krb5.conf}.
11704This service generates such a file from a definition provided in the
11705operating system declaration.
11706It does not cause any daemon to be started.
11707
11708No ``keytab'' files are provided by this service---you must explicitly create them.
11709This service is known to work with the MIT client library, @code{mit-krb5}.
11710Other implementations have not been tested.
11711
11712@defvr {Scheme Variable} krb5-service-type
11713A service type for Kerberos 5 clients.
11714@end defvr
11715
11716@noindent
11717Here is an example of its use:
11718@lisp
11719(service krb5-service-type
11720 (krb5-configuration
11721 (default-realm "EXAMPLE.COM")
11722 (allow-weak-crypto? #t)
11723 (realms (list
11724 (krb5-realm
11725 (name "EXAMPLE.COM")
11726 (admin-server "groucho.example.com")
11727 (kdc "karl.example.com"))
11728 (krb5-realm
11729 (name "ARGRX.EDU")
11730 (admin-server "kerb-admin.argrx.edu")
11731 (kdc "keys.argrx.edu"))))))
11732@end lisp
11733
11734@noindent
11735This example provides a Kerberos@tie{}5 client configuration which:
11736@itemize
11737@item Recognizes two realms, @i{viz:} ``EXAMPLE.COM'' and ``ARGRX.EDU'', both
11738of which have distinct administration servers and key distribution centers;
11739@item Will default to the realm ``EXAMPLE.COM'' if the realm is not explicitly
11740specified by clients;
11741@item Accepts services which only support encryption types known to be weak.
11742@end itemize
11743
11744The @code{krb5-realm} and @code{krb5-configuration} types have many fields.
11745Only the most commonly used ones are described here.
11746For a full list, and more detailed explanation of each, see the MIT
11747@uref{http://web.mit.edu/kerberos/krb5-devel/doc/admin/conf_files/krb5_conf.html,,krb5.conf}
11748documentation.
11749
11750
11751@deftp {Data Type} krb5-realm
11752@cindex realm, kerberos
11753@table @asis
11754@item @code{name}
11755This field is a string identifying the name of the realm.
11756A common convention is to use the fully qualified DNS name of your organization,
11757converted to upper case.
11758
11759@item @code{admin-server}
11760This field is a string identifying the host where the administration server is
11761running.
11762
11763@item @code{kdc}
11764This field is a string identifying the key distribution center
11765for the realm.
11766@end table
11767@end deftp
11768
11769@deftp {Data Type} krb5-configuration
11770
11771@table @asis
11772@item @code{allow-weak-crypto?} (default: @code{#f})
11773If this flag is @code{#t} then services which only offer encryption algorithms
11774known to be weak will be accepted.
11775
11776@item @code{default-realm} (default: @code{#f})
11777This field should be a string identifying the default Kerberos
11778realm for the client.
11779You should set this field to the name of your Kerberos realm.
11780If this value is @code{#f}
11781then a realm must be specified with every Kerberos principal when invoking programs
11782such as @command{kinit}.
11783
11784@item @code{realms}
11785This should be a non-empty list of @code{krb5-realm} objects, which clients may
11786access.
11787Normally, one of them will have a @code{name} field matching the @code{default-realm}
11788field.
11789@end table
11790@end deftp
11791
11792
859e367d
JD
11793@subsubheading PAM krb5 Service
11794@cindex pam-krb5
11795
df31e36a 11796The @code{pam-krb5} service allows for login authentication and password
859e367d
JD
11797management via Kerberos.
11798You will need this service if you want PAM enabled applications to authenticate
11799users using Kerberos.
11800
11801@defvr {Scheme Variable} pam-krb5-service-type
11802A service type for the Kerberos 5 PAM module.
11803@end defvr
11804
11805@deftp {Data Type} pam-krb5-configuration
11806Data type representing the configuration of the Kerberos 5 PAM module
11807This type has the following parameters:
11808@table @asis
11809@item @code{pam-krb5} (default: @code{pam-krb5})
11810The pam-krb5 package to use.
11811
11812@item @code{minimum-uid} (default: @code{1000})
11813The smallest user ID for which Kerberos authentications should be attempted.
11814Local accounts with lower values will silently fail to authenticate.
11815@end table
11816@end deftp
11817
11818
58724c48
DT
11819@node Web Services
11820@subsubsection Web Services
11821
e32171ee
JD
11822@cindex web
11823@cindex www
11824@cindex HTTP
58724c48
DT
11825The @code{(gnu services web)} module provides the following service:
11826
be1c2c54 11827@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
58724c48
DT
11828 [#:log-directory ``/var/log/nginx''] @
11829 [#:run-directory ``/var/run/nginx''] @
8c00b838 11830 [#:vhost-list (list (nginx-vhost-configuration))] @
58724c48
DT
11831 [#:config-file]
11832
11833Return a service that runs @var{nginx}, the nginx web server.
11834
11835The nginx daemon loads its runtime configuration from @var{config-file}.
11836Log files are written to @var{log-directory} and temporary runtime data
11837files are written to @var{run-directory}. For proper operation, these
11838arguments should match what is in @var{config-file} to ensure that the
11839directories are created when the service is activated.
11840
8c00b838
JL
11841As an alternative to using a @var{config-file}, @var{vhost-list} can be
11842used to specify the list of @dfn{virtual hosts} required on the host. For
11843this to work, use the default value for @var{config-file}.
11844
58724c48
DT
11845@end deffn
11846
8c00b838
JL
11847@deftp {Data Type} nginx-vhost-configuration
11848Data type representing the configuration of an nginx virtual host.
11849This type has the following parameters:
11850
11851@table @asis
11852@item @code{http-port} (default: @code{80})
11853Nginx will listen for HTTP connection on this port. Set it at @code{#f} if
11854nginx should not listen for HTTP (non secure) connection for this
11855@dfn{virtual host}.
11856
11857@item @code{https-port} (default: @code{443})
11858Nginx will listen for HTTPS connection on this port. Set it at @code{#f} if
11859nginx should not listen for HTTPS (secure) connection for this @dfn{virtual host}.
11860
11861Note that nginx can listen for HTTP and HTTPS connections in the same
11862@dfn{virtual host}.
11863
11864@item @code{server-name} (default: @code{(list 'default)})
11865A list of server names this vhost represents. @code{'default} represents the
11866default vhost for connections matching no other vhost.
11867
11868@item @code{root} (default: @code{"/srv/http"})
11869Root of the website nginx will serve.
11870
11871@item @code{index} (default: @code{(list "index.html")})
11872Index files to look for when clients ask for a directory. If it cannot be found,
11873Nginx will send the list of files in the directory.
11874
11875@item @code{ssl-certificate} (default: @code{"/etc/nginx/cert.pem"})
11876Where to find the certificate for secure connections. Set it to @code{#f} if
11877you don't have a certificate or you don't want to use HTTPS.
11878
11879@item @code{ssl-certificate-key} (default: @code{"/etc/nginx/key.pem"})
11880Where to find the private key for secure connections. Set it to @code{#f} if
11881you don't have a key or you don't want to use HTTPS.
11882
11883@item @code{server-tokens?} (default: @code{#f})
11884Whether the server should add its configuration to response.
11885
11886@end table
11887@end deftp
11888
eb419bc9
JD
11889@node Network File System
11890@subsubsection Network File System
11891@cindex NFS
fe1a39d3 11892
eb419bc9
JD
11893The @code{(gnu services nfs)} module provides the following services,
11894which are most commonly used in relation to mounting or exporting
11895directory trees as @dfn{network file systems} (NFS).
d6a07ee6
JD
11896
11897@subsubheading RPC Bind Service
11898@cindex rpcbind
11899
eb419bc9
JD
11900The RPC Bind service provides a facility to map program numbers into
11901universal addresses.
11902Many NFS related services use this facility. Hence it is automatically
11903started when a dependent service starts.
d6a07ee6
JD
11904
11905@defvr {Scheme Variable} rpcbind-service-type
11906A service type for the RPC portmapper daemon.
11907@end defvr
11908
11909
11910@deftp {Data Type} rpcbind-configuration
11911Data type representing the configuration of the RPC Bind Service.
11912This type has the following parameters:
11913@table @asis
11914@item @code{rpcbind} (default: @code{rpcbind})
11915The rpcbind package to use.
11916
11917@item @code{warm-start?} (default: @code{#t})
11918If this parameter is @code{#t}, then the daemon will read a
11919state file on startup thus reloading state information saved by a previous
11920instance.
11921@end table
11922@end deftp
11923
eb419bc9
JD
11924
11925@subsubheading Pipefs Pseudo File System
11926@cindex pipefs
11927@cindex rpc_pipefs
11928
11929The pipefs file system is used to transfer NFS related data
11930between the kernel and user space programs.
11931
11932@defvr {Scheme Variable} pipefs-service-type
11933A service type for the pipefs pseudo file system.
11934@end defvr
11935
11936@deftp {Data Type} pipefs-configuration
11937Data type representing the configuration of the pipefs pseudo file system service.
11938This type has the following parameters:
11939@table @asis
11940@item @code{mount-point} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11941The directory to which the file system is to be attached.
11942@end table
11943@end deftp
11944
11945
11946@subsubheading GSS Daemon Service
11947@cindex GSSD
11948@cindex GSS
11949@cindex global security system
11950
11951The @dfn{global security system} (GSS) daemon provides strong security for RPC
11952based protocols.
11953Before exchanging RPC requests an RPC client must establish a security
11954context. Typically this is done using the Kerberos command @command{kinit}
859e367d 11955or automatically at login time using PAM services (@pxref{Kerberos Services}).
eb419bc9
JD
11956
11957@defvr {Scheme Variable} gss-service-type
11958A service type for the Global Security System (GSS) daemon.
11959@end defvr
11960
11961@deftp {Data Type} gss-configuration
11962Data type representing the configuration of the GSS daemon service.
11963This type has the following parameters:
11964@table @asis
11965@item @code{nfs-utils} (default: @code{nfs-utils})
11966The package in which the @command{rpc.gssd} command is to be found.
11967
11968@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11969The directory where the pipefs file system is mounted.
11970
11971@end table
11972@end deftp
11973
11974
11975@subsubheading IDMAP Daemon Service
11976@cindex idmapd
11977@cindex name mapper
11978
11979The idmap daemon service provides mapping between user IDs and user names.
11980Typically it is required in order to access file systems mounted via NFSv4.
11981
11982@defvr {Scheme Variable} idmap-service-type
11983A service type for the Identity Mapper (IDMAP) daemon.
11984@end defvr
11985
11986@deftp {Data Type} idmap-configuration
11987Data type representing the configuration of the IDMAP daemon service.
11988This type has the following parameters:
11989@table @asis
11990@item @code{nfs-utils} (default: @code{nfs-utils})
11991The package in which the @command{rpc.idmapd} command is to be found.
11992
11993@item @code{pipefs-directory} (default: @code{"/var/lib/nfs/rpc_pipefs"})
11994The directory where the pipefs file system is mounted.
11995
11996@item @code{domain} (default: @code{#f})
11997The local NFSv4 domain name.
11998This must be a string or @code{#f}.
11999If it is @code{#f} then the daemon will use the host's fully qualified domain name.
12000
12001@end table
12002@end deftp
12003
a7cf4eb6
ML
12004@node Continuous Integration
12005@subsubsection Continuous Integration
12006
12007@cindex continuous integration
12008@uref{https://notabug.org/mthl/cuirass, Cuirass} is a continuous
12009integration tool for Guix. It can be used both for development and for
12010providing substitutes to others (@pxref{Substitutes}).
12011
12012The @code{(gnu services cuirass)} module provides the following service.
12013
231eddc8
LC
12014@defvr {Scheme Procedure} cuirass-service-type
12015The type of the Cuirass service. Its value must be a
12016@code{cuirass-configuration} object, as described below.
12017@end defvr
a7cf4eb6 12018
231eddc8
LC
12019To add build jobs, you have to set the @code{specifications} field of
12020the configuration. Here is an example of a service defining a build job
12021based on a specification that can be found in Cuirass source tree. This
12022service polls the Guix repository and builds a subset of the Guix
12023packages, as prescribed in the @file{gnu-system.scm} example spec:
a7cf4eb6
ML
12024
12025@example
8de938d5
LC
12026(let ((spec #~((#:name . "guix")
12027 (#:url . "git://git.savannah.gnu.org/guix.git")
12028 (#:load-path . ".")
12029
12030 ;; Here we must provide an absolute file name.
12031 ;; We take jobs from one of the examples provided
12032 ;; by Cuirass.
12033 (#:file . #$(file-append
12034 cuirass
12035 "/tests/gnu-system.scm"))
12036
12037 (#:proc . hydra-jobs)
12038 (#:arguments (subset . "hello"))
12039 (#:branch . "master"))))
231eddc8
LC
12040 (service cuirass-service-type
12041 (cuirass-configuration
12042 (specifications #~(list #$spec)))))
a7cf4eb6
ML
12043@end example
12044
231eddc8 12045While information related to build jobs is located directly in the
a7cf4eb6
ML
12046specifications, global settings for the @command{cuirass} process are
12047accessible in other @code{cuirass-configuration} fields.
12048
12049@deftp {Data Type} cuirass-configuration
12050Data type representing the configuration of Cuirass.
12051
12052@table @asis
b17e326f
LC
12053@item @code{log-file} (default: @code{"/var/log/cuirass.log"})
12054Location of the log file.
12055
463995da 12056@item @code{cache-directory} (default: @code{"/var/cache/cuirass"})
a7cf4eb6
ML
12057Location of the repository cache.
12058
12059@item @code{user} (default: @code{"cuirass"})
12060Owner of the @code{cuirass} process.
12061
12062@item @code{group} (default: @code{"cuirass"})
12063Owner's group of the @code{cuirass} process.
12064
12065@item @code{interval} (default: @code{60})
12066Number of seconds between the poll of the repositories followed by the
12067Cuirass jobs.
12068
12069@item @code{database} (default: @code{"/var/run/cuirass/cuirass.db"})
12070Location of sqlite database which contains the build results and previously
12071added specifications.
12072
8de938d5
LC
12073@item @code{specifications} (default: @code{#~'()})
12074A gexp (@pxref{G-Expressions}) that evaluates to a list of specifications,
12075where a specification is an association list
a7cf4eb6
ML
12076(@pxref{Associations Lists,,, guile, GNU Guile Reference Manual}) whose
12077keys are keywords (@code{#:keyword-example}) as shown in the example
12078above.
12079
12080@item @code{use-substitutes?} (default: @code{#f})
12081This allows using substitutes to avoid building every dependencies of a job
12082from source.
12083
12084@item @code{one-shot?} (default: @code{#f})
12085Only evaluate specifications and build derivations once.
379b6ba5
LC
12086
12087@item @code{cuirass} (default: @code{cuirass})
12088The Cuirass package to use.
a7cf4eb6
ML
12089@end table
12090@end deftp
eb419bc9
JD
12091
12092@node Miscellaneous Services
12093@subsubsection Miscellaneous Services
12094
12095
8ff4dcbe
DC
12096@cindex lirc
12097@subsubheading Lirc Service
12098
fe1a39d3
LC
12099The @code{(gnu services lirc)} module provides the following service.
12100
be1c2c54 12101@deffn {Scheme Procedure} lirc-service [#:lirc lirc] @
fe1a39d3
LC
12102 [#:device #f] [#:driver #f] [#:config-file #f] @
12103 [#:extra-options '()]
12104Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
12105decodes infrared signals from remote controls.
12106
12107Optionally, @var{device}, @var{driver} and @var{config-file}
12108(configuration file name) may be specified. See @command{lircd} manual
12109for details.
12110
12111Finally, @var{extra-options} is a list of additional command-line options
12112passed to @command{lircd}.
12113@end deffn
12114
00f46905
DC
12115@cindex spice
12116@subsubheading Spice Service
12117
12118The @code{(gnu services spice)} module provides the following service.
12119
12120@deffn {Scheme Procedure} spice-vdagent-service [#:spice-vdagent]
12121Returns a service that runs @url{http://www.spice-space.org,VDAGENT}, a daemon
12122that enables sharing the clipboard with a vm and setting the guest display
12123resolution when the graphical console window resizes.
12124@end deffn
12125
c3d38b2b 12126@subsubsection Dictionary Services
e32171ee 12127@cindex dictionary
c3d38b2b
SB
12128The @code{(gnu services dict)} module provides the following service:
12129
12130@deffn {Scheme Procedure} dicod-service [#:config (dicod-configuration)]
12131Return a service that runs the @command{dicod} daemon, an implementation
12132of DICT server (@pxref{Dicod,,, dico, GNU Dico Manual}).
12133
12134The optional @var{config} argument specifies the configuration for
12135@command{dicod}, which should be a @code{<dicod-configuration>} object, by
12136default it serves the GNU Collaborative International Dictonary of English.
12137
12138You can add @command{open localhost} to your @file{~/.dico} file to make
12139@code{localhost} the default server for @command{dico} client
12140(@pxref{Initialization File,,, dico, GNU Dico Manual}).
12141@end deffn
12142
12143@deftp {Data Type} dicod-configuration
12144Data type representing the configuration of dicod.
12145
12146@table @asis
12147@item @code{dico} (default: @var{dico})
12148Package object of the GNU Dico dictionary server.
12149
a1b48465
LC
12150@item @code{interfaces} (default: @var{'("localhost")})
12151This is the list of IP addresses and ports and possibly socket file
12152names to listen to (@pxref{Server Settings, @code{listen} directive,,
12153dico, GNU Dico Manual}).
12154
c3d38b2b
SB
12155@item @code{databases} (default: @var{(list %dicod-database:gcide)})
12156List of @code{<dicod-database>} objects denoting dictionaries to be served.
12157@end table
12158@end deftp
12159
12160@deftp {Data Type} dicod-database
12161Data type representing a dictionary database.
12162
12163@table @asis
12164@item @code{name}
12165Name of the database, will be used in DICT commands.
12166
12167@item @code{module}
12168Name of the dicod module used by this database
12169(@pxref{Modules,,, dico, GNU Dico Manual}).
12170
12171@item @code{options}
12172List of strings or gexps representing the arguments for the module handler
12173(@pxref{Handlers,,, dico, GNU Dico Manual}).
12174@end table
12175@end deftp
12176
12177@defvr {Scheme Variable} %dicod-database:gcide
12178A @code{<dicod-database>} object serving the GNU Collaborative International
12179Dictonary of English using the @code{gcide} package.
12180@end defvr
fe1a39d3 12181
e01e2c6c 12182@subsubsection Version Control
12183
12184The @code{(gnu services version-control)} module provides the following services:
12185
12186@subsubheading Git daemon service
12187
12188@deffn {Scheme Procedure} git-daemon-service [#:config (git-daemon-configuration)]
12189
12190Return a service that runs @command{git daemon}, a simple TCP server to
12191expose repositiories over the Git protocol for annoymous access.
12192
12193The optional @var{config} argument should be a
12194@code{<git-daemon-configuration>} object, by default it allows read-only
12195access to exported@footnote{By creating the magic file
12196"git-daemon-export-ok" in the repository directory.} repositories under
12197@file{/srv/git}.
12198
12199@end deffn
12200
12201@deftp {Data Type} git-daemon-configuration
12202Data type representing the configuration for @code{git-daemon-service}.
12203
12204@table @asis
12205@item @code{package} (default: @var{git})
12206Package object of the Git distributed version control system.
12207
12208@item @code{export-all?} (default: @var{#f})
12209Whether to allow access for all Git repositories, even if they do not
12210have the @file{git-daemon-export-ok} file.
12211
12212@item @code{base-path} (default: @file{/srv/git})
12213Whether to remap all the path requests as relative to the given path.
12214If you run git daemon with @var{(base-path "/srv/git")} on example.com,
12215then if you later try to pull @code{git://example.com/hello.git}, git
12216daemon will interpret the path as @code{/srv/git/hello.git}.
12217
12218@item @code{user-path} (default: @var{#f})
12219Whether to allow @code{~user} notation to be used in requests. When
12220specified with empty string, requests to @code{git://host/~alice/foo} is
12221taken as a request to access @code{foo} repository in the home directory
12222of user @code{alice}. If @var{(user-path "path")} is specified, the
12223same request is taken as a request to access @code{path/foo} repository
12224in the home directory of user @code{alice}.
12225
12226@item @code{listen} (default: @var{'()})
12227Whether to listen on specific IP addresses or hostnames, defaults to
12228all.
12229
12230@item @code{port} (default: @var{#f})
12231Whether to listen on an alternative port, which defaults to 9418.
12232
12233@item @code{whitelist} (default: @var{'()})
12234If not empty, only allow access to this list of directories.
12235
12236@item @code{extra-options} (default: @var{'()})
12237Extra options will be passed to @code{git daemon}, please run
12238@command{man git-daemon} for more information.
12239
12240@end table
12241@end deftp
12242
0ae8c15a
LC
12243@node Setuid Programs
12244@subsection Setuid Programs
12245
12246@cindex setuid programs
12247Some programs need to run with ``root'' privileges, even when they are
12248launched by unprivileged users. A notorious example is the
4d40227c
LC
12249@command{passwd} program, which users can run to change their
12250password, and which needs to access the @file{/etc/passwd} and
0ae8c15a
LC
12251@file{/etc/shadow} files---something normally restricted to root, for
12252obvious security reasons. To address that, these executables are
12253@dfn{setuid-root}, meaning that they always run with root privileges
12254(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
f7e4ae7f 12255for more info about the setuid mechanism.)
0ae8c15a
LC
12256
12257The store itself @emph{cannot} contain setuid programs: that would be a
12258security issue since any user on the system can write derivations that
12259populate the store (@pxref{The Store}). Thus, a different mechanism is
12260used: instead of changing the setuid bit directly on files that are in
12261the store, we let the system administrator @emph{declare} which programs
12262should be setuid root.
12263
12264The @code{setuid-programs} field of an @code{operating-system}
12265declaration contains a list of G-expressions denoting the names of
12266programs to be setuid-root (@pxref{Using the Configuration System}).
12267For instance, the @command{passwd} program, which is part of the Shadow
12268package, can be designated by this G-expression (@pxref{G-Expressions}):
12269
12270@example
12271#~(string-append #$shadow "/bin/passwd")
12272@end example
12273
12274A default set of setuid programs is defined by the
12275@code{%setuid-programs} variable of the @code{(gnu system)} module.
12276
12277@defvr {Scheme Variable} %setuid-programs
12278A list of G-expressions denoting common programs that are setuid-root.
12279
12280The list includes commands such as @command{passwd}, @command{ping},
12281@command{su}, and @command{sudo}.
12282@end defvr
12283
12284Under the hood, the actual setuid programs are created in the
12285@file{/run/setuid-programs} directory at system activation time. The
12286files in this directory refer to the ``real'' binaries, which are in the
12287store.
12288
efb5e833
LC
12289@node X.509 Certificates
12290@subsection X.509 Certificates
12291
12292@cindex HTTPS, certificates
12293@cindex X.509 certificates
12294@cindex TLS
12295Web servers available over HTTPS (that is, HTTP over the transport-layer
12296security mechanism, TLS) send client programs an @dfn{X.509 certificate}
12297that the client can then use to @emph{authenticate} the server. To do
12298that, clients verify that the server's certificate is signed by a
12299so-called @dfn{certificate authority} (CA). But to verify the CA's
12300signature, clients must have first acquired the CA's certificate.
12301
12302Web browsers such as GNU@tie{}IceCat include their own set of CA
12303certificates, such that they are able to verify CA signatures
12304out-of-the-box.
12305
12306However, most other programs that can talk HTTPS---@command{wget},
12307@command{git}, @command{w3m}, etc.---need to be told where CA
12308certificates can be found.
12309
12310@cindex @code{nss-certs}
12311In GuixSD, this is done by adding a package that provides certificates
12312to the @code{packages} field of the @code{operating-system} declaration
12313(@pxref{operating-system Reference}). GuixSD includes one such package,
12314@code{nss-certs}, which is a set of CA certificates provided as part of
12315Mozilla's Network Security Services.
12316
12317Note that it is @emph{not} part of @var{%base-packages}, so you need to
12318explicitly add it. The @file{/etc/ssl/certs} directory, which is where
12319most applications and libraries look for certificates by default, points
12320to the certificates installed globally.
12321
b3129f2b
LC
12322Unprivileged users, including users of Guix on a foreign distro,
12323can also install their own certificate package in
efb5e833
LC
12324their profile. A number of environment variables need to be defined so
12325that applications and libraries know where to find them. Namely, the
12326OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE}
12327variables. Some applications add their own environment variables; for
12328instance, the Git version control system honors the certificate bundle
b3129f2b
LC
12329pointed to by the @code{GIT_SSL_CAINFO} environment variable. Thus, you
12330would typically run something like:
efb5e833 12331
b3129f2b
LC
12332@example
12333$ guix package -i nss-certs
12334$ export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
12335$ export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
12336$ export GIT_SSL_CAINFO="$SSL_CERT_FILE"
12337@end example
efb5e833 12338
996ed739
LC
12339@node Name Service Switch
12340@subsection Name Service Switch
12341
12342@cindex name service switch
12343@cindex NSS
12344The @code{(gnu system nss)} module provides bindings to the
1068f26b 12345configuration file of the libc @dfn{name service switch} or @dfn{NSS}
996ed739
LC
12346(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
12347Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
12348extended with new ``name'' lookup methods for system databases, which
12349includes host names, service names, user accounts, and more (@pxref{Name
12350Service Switch, System Databases and Name Service Switch,, libc, The GNU
12351C Library Reference Manual}).
12352
12353The NSS configuration specifies, for each system database, which lookup
12354method is to be used, and how the various methods are chained
12355together---for instance, under which circumstances NSS should try the
12356next method in the list. The NSS configuration is given in the
12357@code{name-service-switch} field of @code{operating-system} declarations
12358(@pxref{operating-system Reference, @code{name-service-switch}}).
12359
4c9050c6
LC
12360@cindex nss-mdns
12361@cindex .local, host name lookup
996ed739 12362As an example, the declaration below configures the NSS to use the
4c9050c6
LC
12363@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
12364back-end}, which supports host name lookups over multicast DNS (mDNS)
12365for host names ending in @code{.local}:
996ed739
LC
12366
12367@example
12368(name-service-switch
12369 (hosts (list %files ;first, check /etc/hosts
12370
12371 ;; If the above did not succeed, try
12372 ;; with 'mdns_minimal'.
12373 (name-service
12374 (name "mdns_minimal")
12375
12376 ;; 'mdns_minimal' is authoritative for
12377 ;; '.local'. When it returns "not found",
12378 ;; no need to try the next methods.
12379 (reaction (lookup-specification
12380 (not-found => return))))
12381
12382 ;; Then fall back to DNS.
12383 (name-service
12384 (name "dns"))
12385
12386 ;; Finally, try with the "full" 'mdns'.
12387 (name-service
12388 (name "mdns")))))
12389@end example
12390
1068f26b
AE
12391Do not worry: the @code{%mdns-host-lookup-nss} variable (see below)
12392contains this configuration, so you will not have to type it if all you
15137a29
LC
12393want is to have @code{.local} host lookup working.
12394
4c9050c6
LC
12395Note that, in this case, in addition to setting the
12396@code{name-service-switch} of the @code{operating-system} declaration,
cc9c1f39
LC
12397you also need to use @code{avahi-service} (@pxref{Networking Services,
12398@code{avahi-service}}), or @var{%desktop-services}, which includes it
12399(@pxref{Desktop Services}). Doing this makes @code{nss-mdns} accessible
12400to the name service cache daemon (@pxref{Base Services,
12401@code{nscd-service}}).
15137a29
LC
12402
12403For convenience, the following variables provide typical NSS
12404configurations.
12405
12406@defvr {Scheme Variable} %default-nss
12407This is the default name service switch configuration, a
12408@code{name-service-switch} object.
12409@end defvr
12410
12411@defvr {Scheme Variable} %mdns-host-lookup-nss
12412This is the name service switch configuration with support for host name
12413lookup over multicast DNS (mDNS) for host names ending in @code{.local}.
12414@end defvr
4c9050c6 12415
996ed739 12416The reference for name service switch configuration is given below. It
1068f26b 12417is a direct mapping of the configuration file format of the C library , so
996ed739
LC
12418please refer to the C library manual for more information (@pxref{NSS
12419Configuration File,,, libc, The GNU C Library Reference Manual}).
1068f26b 12420Compared to the configuration file format of libc NSS, it has the advantage
996ed739 12421not only of adding this warm parenthetic feel that we like, but also
1068f26b 12422static checks: you will know about syntax errors and typos as soon as you
996ed739
LC
12423run @command{guix system}.
12424
996ed739
LC
12425@deftp {Data Type} name-service-switch
12426
12427This is the data type representation the configuration of libc's name
12428service switch (NSS). Each field below represents one of the supported
12429system databases.
12430
12431@table @code
12432@item aliases
12433@itemx ethers
12434@itemx group
12435@itemx gshadow
12436@itemx hosts
12437@itemx initgroups
12438@itemx netgroup
12439@itemx networks
12440@itemx password
12441@itemx public-key
12442@itemx rpc
12443@itemx services
12444@itemx shadow
12445The system databases handled by the NSS. Each of these fields must be a
1068f26b 12446list of @code{<name-service>} objects (see below).
996ed739
LC
12447@end table
12448@end deftp
12449
12450@deftp {Data Type} name-service
12451
12452This is the data type representing an actual name service and the
12453associated lookup action.
12454
12455@table @code
12456@item name
12457A string denoting the name service (@pxref{Services in the NSS
12458configuration,,, libc, The GNU C Library Reference Manual}).
12459
4aee6e60
LC
12460Note that name services listed here must be visible to nscd. This is
12461achieved by passing the @code{#:name-services} argument to
12462@code{nscd-service} the list of packages providing the needed name
12463services (@pxref{Base Services, @code{nscd-service}}).
12464
996ed739
LC
12465@item reaction
12466An action specified using the @code{lookup-specification} macro
12467(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
12468Reference Manual}). For example:
12469
12470@example
12471(lookup-specification (unavailable => continue)
12472 (success => return))
12473@end example
12474@end table
12475@end deftp
0ae8c15a 12476
fd1b1fa2
LC
12477@node Initial RAM Disk
12478@subsection Initial RAM Disk
12479
e32171ee
JD
12480@cindex initrd
12481@cindex initial RAM disk
fd1b1fa2
LC
12482For bootstrapping purposes, the Linux-Libre kernel is passed an
12483@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
1068f26b 12484root file system as well as an initialization script. The latter is
fd1b1fa2
LC
12485responsible for mounting the real root file system, and for loading any
12486kernel modules that may be needed to achieve that.
12487
12488The @code{initrd} field of an @code{operating-system} declaration allows
12489you to specify which initrd you would like to use. The @code{(gnu
12490system linux-initrd)} module provides two ways to build an initrd: the
12491high-level @code{base-initrd} procedure, and the low-level
12492@code{expression->initrd} procedure.
12493
12494The @code{base-initrd} procedure is intended to cover most common uses.
12495For example, if you want to add a bunch of kernel modules to be loaded
12496at boot time, you can define the @code{initrd} field of the operating
12497system declaration like this:
12498
12499@example
52ac153e 12500(initrd (lambda (file-systems . rest)
027981d6
LC
12501 ;; Create a standard initrd that has modules "foo.ko"
12502 ;; and "bar.ko", as well as their dependencies, in
12503 ;; addition to the modules available by default.
52ac153e 12504 (apply base-initrd file-systems
027981d6 12505 #:extra-modules '("foo" "bar")
52ac153e 12506 rest)))
fd1b1fa2
LC
12507@end example
12508
52ac153e 12509The @code{base-initrd} procedure also handles common use cases that
1068f26b
AE
12510involves using the system as a QEMU guest, or as a ``live'' system with
12511volatile root file system.
fd1b1fa2 12512
e90cf6c1
LC
12513The initial RAM disk produced by @code{base-initrd} honors several
12514options passed on the Linux kernel command line (that is, arguments
1068f26b 12515passed @i{via} the @code{linux} command of GRUB, or the
4af2fafd 12516@code{-append} option of QEMU), notably:
e90cf6c1
LC
12517
12518@table @code
12519@item --load=@var{boot}
12520Tell the initial RAM disk to load @var{boot}, a file containing a Scheme
12521program, once it has mounted the root file system.
12522
12523GuixSD uses this option to yield control to a boot program that runs the
dd17bc38 12524service activation programs and then spawns the GNU@tie{}Shepherd, the
e90cf6c1
LC
12525initialization system.
12526
12527@item --root=@var{root}
1068f26b 12528Mount @var{root} as the root file system. @var{root} can be a
e90cf6c1
LC
12529device name like @code{/dev/sda1}, a partition label, or a partition
12530UUID.
12531
12532@item --system=@var{system}
12533Have @file{/run/booted-system} and @file{/run/current-system} point to
12534@var{system}.
12535
12536@item modprobe.blacklist=@var{modules}@dots{}
12537@cindex module, black-listing
12538@cindex black list, of kernel modules
12539Instruct the initial RAM disk as well as the @command{modprobe} command
12540(from the kmod package) to refuse to load @var{modules}. @var{modules}
12541must be a comma-separated list of module names---e.g.,
12542@code{usbkbd,9pnet}.
12543
12544@item --repl
12545Start a read-eval-print loop (REPL) from the initial RAM disk before it
12546tries to load kernel modules and to mount the root file system. Our
12547marketing team calls it @dfn{boot-to-Guile}. The Schemer in you will
12548love it. @xref{Using Guile Interactively,,, guile, GNU Guile Reference
12549Manual}, for more information on Guile's REPL.
12550
12551@end table
12552
12553Now that you know all the features that initial RAM disks produced by
12554@code{base-initrd} provide, here is how to use it and customize it
12555further.
12556
e32171ee
JD
12557@cindex initrd
12558@cindex initial RAM disk
fd1b1fa2 12559@deffn {Monadic Procedure} base-initrd @var{file-systems} @
9059b97d 12560 [#:qemu-networking? #f] [#:virtio? #t] [#:volatile-root? #f] @
52ac153e 12561 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2 12562Return a monadic derivation that builds a generic initrd. @var{file-systems} is
1068f26b 12563a list of file systems to be mounted by the initrd, possibly in addition to
fd1b1fa2 12564the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
12565@var{mapped-devices} is a list of device mappings to realize before
12566@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
12567
12568When @var{qemu-networking?} is true, set up networking with the standard QEMU
1068f26b
AE
12569parameters. When @var{virtio?} is true, load additional modules so that the
12570initrd can be used as a QEMU guest with para-virtualized I/O drivers.
fd1b1fa2
LC
12571
12572When @var{volatile-root?} is true, the root file system is writable but any changes
12573to it are lost.
12574
12575The initrd is automatically populated with all the kernel modules necessary
12576for @var{file-systems} and for the given options. However, additional kernel
12577modules can be listed in @var{extra-modules}. They will be added to the initrd, and
12578loaded at boot time in the order in which they appear.
12579@end deffn
12580
12581Needless to say, the initrds we produce and use embed a
12582statically-linked Guile, and the initialization program is a Guile
12583program. That gives a lot of flexibility. The
12584@code{expression->initrd} procedure builds such an initrd, given the
12585program to run in that initrd.
12586
12587@deffn {Monadic Procedure} expression->initrd @var{exp} @
4ee96a79 12588 [#:guile %guile-static-stripped] [#:name "guile-initrd"]
fd1b1fa2
LC
12589Return a derivation that builds a Linux initrd (a gzipped cpio archive)
12590containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
12591upon booting. All the derivations referenced by @var{exp} are
12592automatically copied to the initrd.
fd1b1fa2
LC
12593@end deffn
12594
88faf933
LC
12595@node GRUB Configuration
12596@subsection GRUB Configuration
12597
12598@cindex GRUB
12599@cindex boot loader
12600
12601The operating system uses GNU@tie{}GRUB as its boot loader
12602(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
1068f26b
AE
12603configured using a @code{grub-configuration} declaration. This data type
12604is exported by the @code{(gnu system grub)} module and described below.
88faf933
LC
12605
12606@deftp {Data Type} grub-configuration
12607The type of a GRUB configuration declaration.
12608
12609@table @asis
12610
12611@item @code{device}
12612This is a string denoting the boot device. It must be a device name
12613understood by the @command{grub-install} command, such as
12614@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
12615GNU GRUB Manual}).
12616
12617@item @code{menu-entries} (default: @code{()})
12618A possibly empty list of @code{menu-entry} objects (see below), denoting
12619entries to appear in the GRUB boot menu, in addition to the current
12620system entry and the entry pointing to previous system generations.
12621
12622@item @code{default-entry} (default: @code{0})
1068f26b
AE
12623The index of the default boot menu entry. Index 0 is for the entry of the
12624current system.
88faf933
LC
12625
12626@item @code{timeout} (default: @code{5})
12627The number of seconds to wait for keyboard input before booting. Set to
126280 to boot immediately, and to -1 to wait indefinitely.
12629
12630@item @code{theme} (default: @var{%default-theme})
12631The @code{grub-theme} object describing the theme to use.
9b06f503
LC
12632
12633@item @code{grub} (default: @code{grub})
12634The GRUB package to use.
88faf933
LC
12635@end table
12636
12637@end deftp
12638
44d5f54e
LC
12639@cindex dual boot
12640@cindex boot menu
88faf933
LC
12641Should you want to list additional boot menu entries @i{via} the
12642@code{menu-entries} field above, you will need to create them with the
44d5f54e
LC
12643@code{menu-entry} form. For example, imagine you want to be able to
12644boot another distro (hard to imagine!), you can define a menu entry
12645along these lines:
12646
12647@example
12648(menu-entry
12649 (label "The Other Distro")
12650 (linux "/boot/old/vmlinux-2.6.32")
12651 (linux-arguments '("root=/dev/sda2"))
12652 (initrd "/boot/old/initrd"))
12653@end example
12654
12655Details below.
88faf933
LC
12656
12657@deftp {Data Type} menu-entry
12658The type of an entry in the GRUB boot menu.
12659
12660@table @asis
12661
12662@item @code{label}
35ed9306 12663The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
12664
12665@item @code{linux}
44d5f54e
LC
12666The Linux kernel image to boot, for example:
12667
12668@example
12669(file-append linux-libre "/bzImage")
12670@end example
88faf933 12671
1ef8b72a
CM
12672It is also possible to specify a device explicitly in the file path
12673using GRUB's device naming convention (@pxref{Naming convention,,, grub,
12674GNU GRUB manual}), for example:
12675
12676@example
12677"(hd0,msdos1)/boot/vmlinuz"
12678@end example
12679
12680If the device is specified explicitly as above, then the @code{device}
12681field is ignored entirely.
12682
88faf933
LC
12683@item @code{linux-arguments} (default: @code{()})
12684The list of extra Linux kernel command-line arguments---e.g.,
12685@code{("console=ttyS0")}.
12686
12687@item @code{initrd}
12688A G-Expression or string denoting the file name of the initial RAM disk
12689to use (@pxref{G-Expressions}).
12690
1ef8b72a
CM
12691@item @code{device} (default: @code{#f})
12692The device where the kernel and initrd are to be found---i.e., the GRUB
12693@dfn{root} for this menu entry (@pxref{root,,, grub, GNU GRUB manual}).
12694
12695This may be a file system label (a string), a file system UUID (a
12696bytevector, @pxref{File Systems}), or @code{#f}, in which case GRUB will
12697search the device containing the file specified by the @code{linux}
12698field (@pxref{search,,, grub, GNU GRUB manual}). It must @emph{not} be
12699an OS device name such as @file{/dev/sda1}.
12700
12701@item @code{device-mount-point} (default: @code{"/"})
12702The mount point of the above device on the system. You probably do not
12703need to change the default value. GuixSD uses it to strip the prefix of
12704store file names for systems where @file{/gnu} or @file{/gnu/store} is
12705on a separate partition.
12706
88faf933
LC
12707@end table
12708@end deftp
12709
12710@c FIXME: Write documentation once it's stable.
12711Themes are created using the @code{grub-theme} form, which is not
12712documented yet.
12713
12714@defvr {Scheme Variable} %default-theme
12715This is the default GRUB theme used by the operating system, with a
12716fancy background image displaying the GNU and Guix logos.
12717@end defvr
12718
12719
cf4a9129
LC
12720@node Invoking guix system
12721@subsection Invoking @code{guix system}
0918e64a 12722
1068f26b 12723Once you have written an operating system declaration as seen in the
cf4a9129
LC
12724previous section, it can be @dfn{instantiated} using the @command{guix
12725system} command. The synopsis is:
4af2447e 12726
cf4a9129
LC
12727@example
12728guix system @var{options}@dots{} @var{action} @var{file}
12729@end example
4af2447e 12730
cf4a9129
LC
12731@var{file} must be the name of a file containing an
12732@code{operating-system} declaration. @var{action} specifies how the
a40424bd 12733operating system is instantiated. Currently the following values are
cf4a9129 12734supported:
4af2447e 12735
cf4a9129
LC
12736@table @code
12737@item reconfigure
12738Build the operating system described in @var{file}, activate it, and
8074b330
CM
12739switch to it@footnote{This action (and the related actions
12740@code{switch-generation} and @code{roll-back}) are usable only on
12741systems already running GuixSD.}.
4af2447e 12742
cf4a9129
LC
12743This effects all the configuration specified in @var{file}: user
12744accounts, system services, global package list, setuid programs, etc.
240b57f0
LC
12745The command starts system services specified in @var{file} that are not
12746currently running; if a service is currently running, it does not
1068f26b 12747attempt to upgrade it since this would not be possible without stopping it
240b57f0 12748first.
4af2447e 12749
067a2e2d
CM
12750This command creates a new generation whose number is one greater than
12751the current generation (as reported by @command{guix system
12752list-generations}). If that generation already exists, it will be
12753overwritten. This behavior mirrors that of @command{guix package}
12754(@pxref{Invoking guix package}).
12755
cf4a9129
LC
12756It also adds a GRUB menu entry for the new OS configuration, and moves
12757entries for older configurations to a submenu---unless
12758@option{--no-grub} is passed.
4af2447e 12759
240b57f0 12760@quotation Note
bf2479c7
LC
12761@c The paragraph below refers to the problem discussed at
12762@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
12763It is highly recommended to run @command{guix pull} once before you run
12764@command{guix system reconfigure} for the first time (@pxref{Invoking
12765guix pull}). Failing to do that you would see an older version of Guix
12766once @command{reconfigure} has completed.
240b57f0 12767@end quotation
bf2479c7 12768
8074b330 12769@item switch-generation
e32171ee 12770@cindex generations
8074b330
CM
12771Switch to an existing system generation. This action atomically
12772switches the system profile to the specified system generation. It also
12773rearranges the system's existing GRUB menu entries. It makes the menu
12774entry for the specified system generation the default, and it moves the
12775entries for the other generations to a submenu. The next time the
12776system boots, it will use the specified system generation.
12777
12778The target generation can be specified explicitly by its generation
12779number. For example, the following invocation would switch to system
12780generation 7:
12781
12782@example
12783guix system switch-generation 7
12784@end example
12785
12786The target generation can also be specified relative to the current
12787generation with the form @code{+N} or @code{-N}, where @code{+3} means
12788``3 generations ahead of the current generation,'' and @code{-1} means
12789``1 generation prior to the current generation.'' When specifying a
12790negative value such as @code{-1}, you must precede it with @code{--} to
12791prevent it from being parsed as an option. For example:
12792
12793@example
12794guix system switch-generation -- -1
12795@end example
12796
12797Currently, the effect of invoking this action is @emph{only} to switch
12798the system profile to an existing generation and rearrange the GRUB menu
12799entries. To actually start using the target system generation, you must
12800reboot after running this action. In the future, it will be updated to
12801do the same things as @command{reconfigure}, like activating and
12802deactivating services.
12803
12804This action will fail if the specified generation does not exist.
12805
12806@item roll-back
e32171ee 12807@cindex rolling back
8074b330
CM
12808Switch to the preceding system generation. The next time the system
12809boots, it will use the preceding system generation. This is the inverse
12810of @command{reconfigure}, and it is exactly the same as invoking
12811@command{switch-generation} with an argument of @code{-1}.
12812
12813Currently, as with @command{switch-generation}, you must reboot after
12814running this action to actually start using the preceding system
12815generation.
12816
cf4a9129 12817@item build
1068f26b 12818Build the derivation of the operating system, which includes all the
cf4a9129
LC
12819configuration files and programs needed to boot and run the system.
12820This action does not actually install anything.
113daf62 12821
cf4a9129
LC
12822@item init
12823Populate the given directory with all the files necessary to run the
12824operating system specified in @var{file}. This is useful for first-time
4705641f 12825installations of GuixSD. For instance:
113daf62
LC
12826
12827@example
cf4a9129 12828guix system init my-os-config.scm /mnt
113daf62
LC
12829@end example
12830
cf4a9129
LC
12831copies to @file{/mnt} all the store items required by the configuration
12832specified in @file{my-os-config.scm}. This includes configuration
12833files, packages, and so on. It also creates other essential files
12834needed for the system to operate correctly---e.g., the @file{/etc},
12835@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 12836
cf4a9129
LC
12837This command also installs GRUB on the device specified in
12838@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 12839
cf4a9129
LC
12840@item vm
12841@cindex virtual machine
0276f697 12842@cindex VM
f535dcbe 12843@anchor{guix system vm}
1068f26b 12844Build a virtual machine that contains the operating system declared in
cf4a9129 12845@var{file}, and return a script to run that virtual machine (VM).
1068f26b 12846Arguments given to the script are passed to QEMU.
113daf62 12847
cf4a9129 12848The VM shares its store with the host system.
113daf62 12849
0276f697
LC
12850Additional file systems can be shared between the host and the VM using
12851the @code{--share} and @code{--expose} command-line options: the former
12852specifies a directory to be shared with write access, while the latter
12853provides read-only access to the shared directory.
12854
12855The example below creates a VM in which the user's home directory is
12856accessible read-only, and where the @file{/exchange} directory is a
1068f26b 12857read-write mapping of @file{$HOME/tmp} on the host:
0276f697
LC
12858
12859@example
12860guix system vm my-config.scm \
12861 --expose=$HOME --share=$HOME/tmp=/exchange
12862@end example
12863
6aa260af
LC
12864On GNU/Linux, the default is to boot directly to the kernel; this has
12865the advantage of requiring only a very tiny root disk image since the
1068f26b 12866store of the host can then be mounted.
6aa260af
LC
12867
12868The @code{--full-boot} option forces a complete boot sequence, starting
12869with the bootloader. This requires more disk space since a root image
12870containing at least the kernel, initrd, and bootloader data files must
12871be created. The @code{--image-size} option can be used to specify the
1068f26b 12872size of the image.
ab11f0be 12873
cf4a9129
LC
12874@item vm-image
12875@itemx disk-image
12876Return a virtual machine or disk image of the operating system declared
12877in @var{file} that stands alone. Use the @option{--image-size} option
12878to specify the size of the image.
113daf62 12879
cf4a9129 12880When using @code{vm-image}, the returned image is in qcow2 format, which
97d76250
LF
12881the QEMU emulator can efficiently use. @xref{Running GuixSD in a VM},
12882for more information on how to run the image in a virtual machine.
113daf62 12883
cf4a9129
LC
12884When using @code{disk-image}, a raw disk image is produced; it can be
12885copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
1068f26b 12886the device corresponding to a USB stick, one can copy the image to it
cf4a9129 12887using the following command:
113daf62 12888
cf4a9129
LC
12889@example
12890# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
12891@end example
113daf62 12892
1c8a81b1
DT
12893@item container
12894Return a script to run the operating system declared in @var{file}
12895within a container. Containers are a set of lightweight isolation
12896mechanisms provided by the kernel Linux-libre. Containers are
12897substantially less resource-demanding than full virtual machines since
12898the kernel, shared objects, and other resources can be shared with the
12899host system; this also means they provide thinner isolation.
12900
12901Currently, the script must be run as root in order to support more than
12902a single user and group. The container shares its store with the host
12903system.
12904
12905As with the @code{vm} action (@pxref{guix system vm}), additional file
12906systems to be shared between the host and container can be specified
12907using the @option{--share} and @option{--expose} options:
12908
12909@example
12910guix system container my-config.scm \
12911 --expose=$HOME --share=$HOME/tmp=/exchange
12912@end example
12913
0f252e26 12914@quotation Note
cfd35b4e 12915This option requires Linux-libre 3.19 or newer.
0f252e26
DT
12916@end quotation
12917
cf4a9129 12918@end table
113daf62 12919
ccd7158d
LC
12920@var{options} can contain any of the common build options (@pxref{Common
12921Build Options}). In addition, @var{options} can contain one of the
12922following:
113daf62 12923
cf4a9129
LC
12924@table @option
12925@item --system=@var{system}
12926@itemx -s @var{system}
1068f26b 12927Attempt to build for @var{system} instead of the host system type.
cf4a9129 12928This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 12929
f3f427c2
LC
12930@item --derivation
12931@itemx -d
12932Return the derivation file name of the given operating system without
12933building anything.
12934
cf4a9129
LC
12935@item --image-size=@var{size}
12936For the @code{vm-image} and @code{disk-image} actions, create an image
12937of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
12938include a unit as a suffix (@pxref{Block size, size specifications,,
12939coreutils, GNU Coreutils}).
db030303
LC
12940
12941@item --on-error=@var{strategy}
12942Apply @var{strategy} when an error occurs when reading @var{file}.
12943@var{strategy} may be one of the following:
12944
12945@table @code
12946@item nothing-special
12947Report the error concisely and exit. This is the default strategy.
12948
12949@item backtrace
12950Likewise, but also display a backtrace.
12951
12952@item debug
12953Report the error and enter Guile's debugger. From there, you can run
12954commands such as @code{,bt} to get a backtrace, @code{,locals} to
1068f26b
AE
12955display local variable values, and more generally inspect the state of the
12956program. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
db030303
LC
12957a list of available debugging commands.
12958@end table
113daf62 12959@end table
113daf62 12960
eca69fc0
LC
12961@quotation Note
12962All the actions above, except @code{build} and @code{init},
12963can use KVM support in the Linux-libre kernel. Specifically, if the
12964machine has hardware virtualization support, the corresponding
cf4a9129 12965KVM kernel module should be loaded, and the @file{/dev/kvm} device node
1068f26b 12966must exist and be readable and writable by the user and by the
eca69fc0
LC
12967build users of the daemon (@pxref{Build Environment Setup}).
12968@end quotation
8451a568 12969
65797bff
LC
12970Once you have built, configured, re-configured, and re-re-configured
12971your GuixSD installation, you may find it useful to list the operating
12972system generations available on disk---and that you can choose from the
12973GRUB boot menu:
12974
12975@table @code
12976
12977@item list-generations
12978List a summary of each generation of the operating system available on
12979disk, in a human-readable way. This is similar to the
12980@option{--list-generations} option of @command{guix package}
12981(@pxref{Invoking guix package}).
12982
12983Optionally, one can specify a pattern, with the same syntax that is used
12984in @command{guix package --list-generations}, to restrict the list of
12985generations displayed. For instance, the following command displays
1068f26b 12986generations that are up to 10 days old:
65797bff
LC
12987
12988@example
12989$ guix system list-generations 10d
12990@end example
12991
12992@end table
12993
d6c3267a
LC
12994The @command{guix system} command has even more to offer! The following
12995sub-commands allow you to visualize how your system services relate to
12996each other:
12997
12998@anchor{system-extension-graph}
12999@table @code
13000
13001@item extension-graph
13002Emit in Dot/Graphviz format to standard output the @dfn{service
13003extension graph} of the operating system defined in @var{file}
13004(@pxref{Service Composition}, for more information on service
13005extensions.)
13006
13007The command:
13008
13009@example
13010$ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
13011@end example
13012
13013produces a PDF file showing the extension relations among services.
13014
710fa231
AK
13015@anchor{system-shepherd-graph}
13016@item shepherd-graph
6f305ea5 13017Emit in Dot/Graphviz format to standard output the @dfn{dependency
dd17bc38
AK
13018graph} of shepherd services of the operating system defined in
13019@var{file}. @xref{Shepherd Services}, for more information and for an
13020example graph.
6f305ea5 13021
d6c3267a
LC
13022@end table
13023
97d76250 13024@node Running GuixSD in a VM
70ac09a5 13025@subsection Running GuixSD in a Virtual Machine
97d76250 13026
e32171ee 13027@cindex virtual machine
97d76250
LF
13028One way to run GuixSD in a virtual machine (VM) is to build a GuixSD
13029virtual machine image using @command{guix system vm-image}
13030(@pxref{Invoking guix system}). The returned image is in qcow2 format,
13031which the @uref{http://qemu.org/, QEMU emulator} can efficiently use.
13032
e32171ee 13033@cindex QEMU
97d76250
LF
13034To run the image in QEMU, copy it out of the store (@pxref{The Store})
13035and give yourself permission to write to the copy. When invoking QEMU,
13036you must choose a system emulator that is suitable for your hardware
13037platform. Here is a minimal QEMU invocation that will boot the result
13038of @command{guix system vm-image} on x86_64 hardware:
13039
13040@example
13041$ qemu-system-x86_64 \
13042 -net user -net nic,model=virtio \
13043 -enable-kvm -m 256 /tmp/qemu-image
13044@end example
13045
13046Here is what each of these options means:
13047
13048@table @code
13049@item qemu-system-x86_64
13050This specifies the hardware platform to emulate. This should match the
13051host.
13052
13053@item -net user
13054Enable the unprivileged user-mode network stack. The guest OS can
13055access the host but not vice versa. This is the simplest way to get the
58806e6f 13056guest OS online.
97d76250
LF
13057
13058@item -net nic,model=virtio
1068f26b 13059You must create a network interface of a given model. If you do not
97d76250
LF
13060create a NIC, the boot will fail. Assuming your hardware platform is
13061x86_64, you can get a list of available NIC models by running
13062@command{qemu-system-x86_64 -net nic,model=help}.
13063
13064@item -enable-kvm
13065If your system has hardware virtualization extensions, enabling the
1068f26b 13066virtual machine support (KVM) of the Linux kernel will make things run
97d76250
LF
13067faster.
13068
13069@item -m 256
13070RAM available to the guest OS, in mebibytes. Defaults to 128@tie{}MiB,
7414de0a 13071which may be insufficient for some operations.
97d76250
LF
13072
13073@item /tmp/qemu-image
13074The file name of the qcow2 image.
13075@end table
d6c3267a 13076
3ddc50db
DC
13077The default @command{run-vm.sh} script that is returned by an invokation of
13078@command{guix system vm} does not add a @command{-net user} flag by default.
13079To get network access from within the vm add the @code{(dhcp-client-service)}
13080to your system definition and start the VM using
13081@command{`guix system vm config.scm` -net user}. An important caveat of using
13082@command{-net user} for networking is that @command{ping} will not work, because
13083it uses the ICMP protocol. You'll have to use a different command to check for
13084network connectivity, like for example @command{curl}.
13085
13086@subsubsection Connecting Through SSH
13087
e32171ee
JD
13088@cindex SSH
13089@cindex SSH server
3ddc50db
DC
13090To enable SSH inside a VM you need to add a SSH server like @code{(dropbear-service)}
13091or @code{(lsh-service)} to your VM. The @code{(lsh-service}) doesn't currently
13092boot unsupervised. It requires you to type some characters to initialize the
13093randomness generator. In addition you need to forward the SSH port, 22 by
13094default, to the host. You can do this with
13095
13096@example
13097`guix system vm config.scm` -net user,hostfwd=tcp::10022-:22
13098@end example
13099
13100To connect to the VM you can run
13101
13102@example
13103ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022
13104@end example
13105
13106The @command{-p} tells @command{ssh} the port you want to connect to.
13107@command{-o UserKnownHostsFile=/dev/null} prevents @command{ssh} from complaining
13108every time you modify your @command{config.scm} file and the
13109@command{-o StrictHostKeyChecking=no} prevents you from having to allow a
13110connection to an unknown host every time you connect.
13111
13112@subsubsection Using @command{virt-viewer} with Spice
13113
13114As an alternative to the default @command{qemu} graphical client you can
13115use the @command{remote-viewer} from the @command{virt-viewer} package. To
13116connect pass the @command{-spice port=5930,disable-ticketing} flag to
13117@command{qemu}. See previous section for further information on how to do this.
13118
13119Spice also allows you to do some nice stuff like share your clipboard with your
13120VM. To enable that you'll also have to pass the following flags to @command{qemu}:
13121
13122@example
13123-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5
13124-chardev spicevmc,name=vdagent,id=vdagent
13125-device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,
13126name=com.redhat.spice.0
13127@end example
13128
13129You'll also need to add the @pxref{Miscellaneous Services, Spice service}.
13130
cf4a9129
LC
13131@node Defining Services
13132@subsection Defining Services
8451a568 13133
eb524192 13134The previous sections show the available services and how one can combine
0adfe95a
LC
13135them in an @code{operating-system} declaration. But how do we define
13136them in the first place? And what is a service anyway?
8451a568 13137
0adfe95a
LC
13138@menu
13139* Service Composition:: The model for composing services.
13140* Service Types and Services:: Types and services.
13141* Service Reference:: API reference.
dd17bc38 13142* Shepherd Services:: A particular type of service.
0adfe95a
LC
13143@end menu
13144
13145@node Service Composition
13146@subsubsection Service Composition
13147
13148@cindex services
13149@cindex daemons
13150Here we define a @dfn{service} as, broadly, something that extends the
1068f26b 13151functionality of the operating system. Often a service is a process---a
0adfe95a
LC
13152@dfn{daemon}---started when the system boots: a secure shell server, a
13153Web server, the Guix build daemon, etc. Sometimes a service is a daemon
13154whose execution can be triggered by another daemon---e.g., an FTP server
13155started by @command{inetd} or a D-Bus service activated by
13156@command{dbus-daemon}. Occasionally, a service does not map to a
13157daemon. For instance, the ``account'' service collects user accounts
13158and makes sure they exist when the system runs; the ``udev'' service
13159collects device management rules and makes them available to the eudev
1068f26b
AE
13160daemon; the @file{/etc} service populates the @file{/etc} directory
13161of the system.
0adfe95a 13162
d6c3267a 13163@cindex service extensions
0adfe95a 13164GuixSD services are connected by @dfn{extensions}. For instance, the
1068f26b 13165secure shell service @emph{extends} the Shepherd---the GuixSD
dd17bc38
AK
13166initialization system, running as PID@tie{}1---by giving it the command
13167lines to start and stop the secure shell daemon (@pxref{Networking
13168Services, @code{lsh-service}}); the UPower service extends the D-Bus
13169service by passing it its @file{.service} specification, and extends the
13170udev service by passing it device management rules (@pxref{Desktop
13171Services, @code{upower-service}}); the Guix daemon service extends the
13172Shepherd by passing it the command lines to start and stop the daemon,
13173and extends the account service by passing it a list of required build
13174user accounts (@pxref{Base Services}).
0adfe95a
LC
13175
13176All in all, services and their ``extends'' relations form a directed
13177acyclic graph (DAG). If we represent services as boxes and extensions
13178as arrows, a typical system might provide something like this:
13179
13180@image{images/service-graph,,5in,Typical service extension graph.}
13181
d62e201c
LC
13182@cindex system service
13183At the bottom, we see the @dfn{system service}, which produces the
13184directory containing everything to run and boot the system, as returned
13185by the @command{guix system build} command. @xref{Service Reference},
13186to learn about the other service types shown here.
d6c3267a
LC
13187@xref{system-extension-graph, the @command{guix system extension-graph}
13188command}, for information on how to generate this representation for a
13189particular operating system definition.
0adfe95a
LC
13190
13191@cindex service types
13192Technically, developers can define @dfn{service types} to express these
13193relations. There can be any number of services of a given type on the
13194system---for instance, a system running two instances of the GNU secure
13195shell server (lsh) has two instances of @var{lsh-service-type}, with
13196different parameters.
13197
13198The following section describes the programming interface for service
13199types and services.
13200
13201@node Service Types and Services
13202@subsubsection Service Types and Services
13203
13204A @dfn{service type} is a node in the DAG described above. Let us start
13205with a simple example, the service type for the Guix build daemon
13206(@pxref{Invoking guix-daemon}):
13207
13208@example
13209(define guix-service-type
13210 (service-type
13211 (name 'guix)
13212 (extensions
d4053c71 13213 (list (service-extension shepherd-root-service-type guix-shepherd-service)
0adfe95a
LC
13214 (service-extension account-service-type guix-accounts)
13215 (service-extension activation-service-type guix-activation)))))
13216@end example
8451a568 13217
cf4a9129 13218@noindent
1068f26b 13219It defines two things:
0adfe95a
LC
13220
13221@enumerate
13222@item
13223A name, whose sole purpose is to make inspection and debugging easier.
13224
13225@item
13226A list of @dfn{service extensions}, where each extension designates the
1068f26b
AE
13227target service type and a procedure that, given the parameters of the
13228service, returns a list of objects to extend the service of that type.
0adfe95a
LC
13229
13230Every service type has at least one service extension. The only
13231exception is the @dfn{boot service type}, which is the ultimate service.
13232@end enumerate
13233
13234In this example, @var{guix-service-type} extends three services:
13235
13236@table @var
d4053c71
AK
13237@item shepherd-root-service-type
13238The @var{guix-shepherd-service} procedure defines how the Shepherd
13239service is extended. Namely, it returns a @code{<shepherd-service>}
13240object that defines how @command{guix-daemon} is started and stopped
13241(@pxref{Shepherd Services}).
0adfe95a
LC
13242
13243@item account-service-type
13244This extension for this service is computed by @var{guix-accounts},
13245which returns a list of @code{user-group} and @code{user-account}
13246objects representing the build user accounts (@pxref{Invoking
13247guix-daemon}).
13248
13249@item activation-service-type
13250Here @var{guix-activation} is a procedure that returns a gexp, which is
13251a code snippet to run at ``activation time''---e.g., when the service is
13252booted.
13253@end table
13254
13255A service of this type is instantiated like this:
13256
13257@example
13258(service guix-service-type
13259 (guix-configuration
13260 (build-accounts 5)
13261 (use-substitutes? #f)))
13262@end example
13263
13264The second argument to the @code{service} form is a value representing
13265the parameters of this specific service instance.
13266@xref{guix-configuration-type, @code{guix-configuration}}, for
13267information about the @code{guix-configuration} data type.
13268
13269@var{guix-service-type} is quite simple because it extends other
13270services but is not extensible itself.
13271
13272@c @subsubsubsection Extensible Service Types
13273
13274The service type for an @emph{extensible} service looks like this:
13275
13276@example
13277(define udev-service-type
13278 (service-type (name 'udev)
13279 (extensions
d4053c71
AK
13280 (list (service-extension shepherd-root-service-type
13281 udev-shepherd-service)))
0adfe95a
LC
13282
13283 (compose concatenate) ;concatenate the list of rules
13284 (extend (lambda (config rules)
13285 (match config
13286 (($ <udev-configuration> udev initial-rules)
13287 (udev-configuration
13288 (udev udev) ;the udev package to use
13289 (rules (append initial-rules rules)))))))))
13290@end example
13291
13292This is the service type for the
13293@uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
13294management daemon}. Compared to the previous example, in addition to an
d4053c71 13295extension of @var{shepherd-root-service-type}, we see two new fields:
0adfe95a
LC
13296
13297@table @code
13298@item compose
13299This is the procedure to @dfn{compose} the list of extensions to
13300services of this type.
13301
13302Services can extend the udev service by passing it lists of rules; we
13303compose those extensions simply by concatenating them.
13304
13305@item extend
1068f26b 13306This procedure defines how the value of the service is @dfn{extended} with
0adfe95a
LC
13307the composition of the extensions.
13308
13309Udev extensions are composed into a list of rules, but the udev service
13310value is itself a @code{<udev-configuration>} record. So here, we
a40424bd 13311extend that record by appending the list of rules it contains to the
0adfe95a
LC
13312list of contributed rules.
13313@end table
13314
13315There can be only one instance of an extensible service type such as
13316@var{udev-service-type}. If there were more, the
13317@code{service-extension} specifications would be ambiguous.
13318
13319Still here? The next section provides a reference of the programming
13320interface for services.
13321
13322@node Service Reference
13323@subsubsection Service Reference
13324
13325We have seen an overview of service types (@pxref{Service Types and
13326Services}). This section provides a reference on how to manipulate
13327services and service types. This interface is provided by the
13328@code{(gnu services)} module.
13329
13330@deffn {Scheme Procedure} service @var{type} @var{value}
13331Return a new service of @var{type}, a @code{<service-type>} object (see
13332below.) @var{value} can be any object; it represents the parameters of
13333this particular service instance.
13334@end deffn
13335
13336@deffn {Scheme Procedure} service? @var{obj}
13337Return true if @var{obj} is a service.
13338@end deffn
8451a568 13339
0adfe95a
LC
13340@deffn {Scheme Procedure} service-kind @var{service}
13341Return the type of @var{service}---i.e., a @code{<service-type>} object.
13342@end deffn
13343
13344@deffn {Scheme Procedure} service-parameters @var{service}
13345Return the value associated with @var{service}. It represents its
13346parameters.
13347@end deffn
13348
13349Here is an example of how a service is created and manipulated:
13350
13351@example
13352(define s
13353 (service nginx-service-type
13354 (nginx-configuration
13355 (nginx nginx)
13356 (log-directory log-directory)
13357 (run-directory run-directory)
13358 (file config-file))))
13359
13360(service? s)
13361@result{} #t
13362
13363(eq? (service-kind s) nginx-service-type)
13364@result{} #t
13365@end example
13366
cd6f6c22
LC
13367The @code{modify-services} form provides a handy way to change the
13368parameters of some of the services of a list such as
4d343a14 13369@var{%base-services} (@pxref{Base Services, @code{%base-services}}). It
7414de0a 13370evaluates to a list of services. Of course, you could always use
4d343a14
CM
13371standard list combinators such as @code{map} and @code{fold} to do that
13372(@pxref{SRFI-1, List Library,, guile, GNU Guile Reference Manual});
13373@code{modify-services} simply provides a more concise form for this
13374common pattern.
cd6f6c22
LC
13375
13376@deffn {Scheme Syntax} modify-services @var{services} @
13377 (@var{type} @var{variable} => @var{body}) @dots{}
13378
13379Modify the services listed in @var{services} according to the given
13380clauses. Each clause has the form:
13381
13382@example
13383(@var{type} @var{variable} => @var{body})
13384@end example
13385
4d343a14
CM
13386where @var{type} is a service type---e.g.,
13387@code{guix-service-type}---and @var{variable} is an identifier that is
13388bound within the @var{body} to the service parameters---e.g., a
13389@code{guix-configuration} instance---of the original service of that
13390@var{type}.
cd6f6c22 13391
4d343a14
CM
13392The @var{body} should evaluate to the new service parameters, which will
13393be used to configure the new service. This new service will replace the
13394original in the resulting list. Because a service's service parameters
7414de0a 13395are created using @code{define-record-type*}, you can write a succinct
4d343a14
CM
13396@var{body} that evaluates to the new service parameters by using the
13397@code{inherit} feature that @code{define-record-type*} provides.
13398
b53daad0 13399@xref{Using the Configuration System}, for example usage.
cd6f6c22 13400
cd6f6c22
LC
13401@end deffn
13402
13403Next comes the programming interface for service types. This is
13404something you want to know when writing new service definitions, but not
13405necessarily when simply looking for ways to customize your
13406@code{operating-system} declaration.
13407
0adfe95a
LC
13408@deftp {Data Type} service-type
13409@cindex service type
13410This is the representation of a @dfn{service type} (@pxref{Service Types
13411and Services}).
13412
13413@table @asis
13414@item @code{name}
13415This is a symbol, used only to simplify inspection and debugging.
13416
13417@item @code{extensions}
1068f26b 13418A non-empty list of @code{<service-extension>} objects (see below).
0adfe95a
LC
13419
13420@item @code{compose} (default: @code{#f})
13421If this is @code{#f}, then the service type denotes services that cannot
13422be extended---i.e., services that do not receive ``values'' from other
13423services.
13424
13425Otherwise, it must be a one-argument procedure. The procedure is called
13426by @code{fold-services} and is passed a list of values collected from
13427extensions. It must return a value that is a valid parameter value for
13428the service instance.
13429
13430@item @code{extend} (default: @code{#f})
13431If this is @code{#f}, services of this type cannot be extended.
13432
13433Otherwise, it must be a two-argument procedure: @code{fold-services}
1068f26b 13434calls it, passing it the initial value of the service as the first argument
0adfe95a
LC
13435and the result of applying @code{compose} to the extension values as the
13436second argument.
13437@end table
13438
13439@xref{Service Types and Services}, for examples.
13440@end deftp
13441
13442@deffn {Scheme Procedure} service-extension @var{target-type} @
13443 @var{compute}
13444Return a new extension for services of type @var{target-type}.
13445@var{compute} must be a one-argument procedure: @code{fold-services}
13446calls it, passing it the value associated with the service that provides
13447the extension; it must return a valid value for the target service.
13448@end deffn
13449
13450@deffn {Scheme Procedure} service-extension? @var{obj}
13451Return true if @var{obj} is a service extension.
13452@end deffn
13453
71654dfd
LC
13454Occasionally, you might want to simply extend an existing service. This
13455involves creating a new service type and specifying the extension of
13456interest, which can be verbose; the @code{simple-service} procedure
13457provides a shorthand for this.
13458
13459@deffn {Scheme Procedure} simple-service @var{name} @var{target} @var{value}
13460Return a service that extends @var{target} with @var{value}. This works
13461by creating a singleton service type @var{name}, of which the returned
13462service is an instance.
13463
13464For example, this extends mcron (@pxref{Scheduled Job Execution}) with
13465an additional job:
13466
13467@example
13468(simple-service 'my-mcron-job mcron-service-type
13469 #~(job '(next-hour (3)) "guix gc -F 2G"))
13470@end example
13471@end deffn
13472
0adfe95a
LC
13473At the core of the service abstraction lies the @code{fold-services}
13474procedure, which is responsible for ``compiling'' a list of services
d62e201c
LC
13475down to a single directory that contains everything needed to boot and
13476run the system---the directory shown by the @command{guix system build}
13477command (@pxref{Invoking guix system}). In essence, it propagates
13478service extensions down the service graph, updating each node parameters
13479on the way, until it reaches the root node.
0adfe95a
LC
13480
13481@deffn {Scheme Procedure} fold-services @var{services} @
d62e201c 13482 [#:target-type @var{system-service-type}]
0adfe95a
LC
13483Fold @var{services} by propagating their extensions down to the root of
13484type @var{target-type}; return the root service adjusted accordingly.
13485@end deffn
13486
13487Lastly, the @code{(gnu services)} module also defines several essential
13488service types, some of which are listed below.
13489
d62e201c
LC
13490@defvr {Scheme Variable} system-service-type
13491This is the root of the service graph. It produces the system directory
13492as returned by the @command{guix system build} command.
13493@end defvr
13494
0adfe95a 13495@defvr {Scheme Variable} boot-service-type
d62e201c
LC
13496The type of the ``boot service'', which produces the @dfn{boot script}.
13497The boot script is what the initial RAM disk runs when booting.
0adfe95a
LC
13498@end defvr
13499
13500@defvr {Scheme Variable} etc-service-type
13501The type of the @file{/etc} service. This service can be extended by
13502passing it name/file tuples such as:
13503
13504@example
13505(list `("issue" ,(plain-file "issue" "Welcome!\n")))
13506@end example
13507
13508In this example, the effect would be to add an @file{/etc/issue} file
13509pointing to the given file.
13510@end defvr
13511
13512@defvr {Scheme Variable} setuid-program-service-type
13513Type for the ``setuid-program service''. This service collects lists of
13514executable file names, passed as gexps, and adds them to the set of
13515setuid-root programs on the system (@pxref{Setuid Programs}).
13516@end defvr
13517
af4c3fd5
LC
13518@defvr {Scheme Variable} profile-service-type
13519Type of the service that populates the @dfn{system profile}---i.e., the
13520programs under @file{/run/current-system/profile}. Other services can
13521extend it by passing it lists of packages to add to the system profile.
13522@end defvr
13523
0adfe95a 13524
dd17bc38
AK
13525@node Shepherd Services
13526@subsubsection Shepherd Services
0adfe95a 13527
e32171ee 13528@cindex shepherd services
0adfe95a
LC
13529@cindex PID 1
13530@cindex init system
a40424bd
CM
13531The @code{(gnu services shepherd)} module provides a way to define
13532services managed by the GNU@tie{}Shepherd, which is the GuixSD
13533initialization system---the first process that is started when the
1068f26b
AE
13534system boots, also known as PID@tie{}1
13535(@pxref{Introduction,,, shepherd, The GNU Shepherd Manual}).
6f305ea5 13536
dd17bc38
AK
13537Services in the Shepherd can depend on each other. For instance, the
13538SSH daemon may need to be started after the syslog daemon has been
13539started, which in turn can only happen once all the file systems have
13540been mounted. The simple operating system defined earlier (@pxref{Using
13541the Configuration System}) results in a service graph like this:
6f305ea5 13542
710fa231 13543@image{images/shepherd-graph,,5in,Typical shepherd service graph.}
6f305ea5
LC
13544
13545You can actually generate such a graph for any operating system
710fa231
AK
13546definition using the @command{guix system shepherd-graph} command
13547(@pxref{system-shepherd-graph, @command{guix system shepherd-graph}}).
6f305ea5 13548
d4053c71
AK
13549The @var{%shepherd-root-service} is a service object representing
13550PID@tie{}1, of type @var{shepherd-root-service-type}; it can be extended
13551by passing it lists of @code{<shepherd-service>} objects.
0adfe95a 13552
d4053c71 13553@deftp {Data Type} shepherd-service
dd17bc38 13554The data type representing a service managed by the Shepherd.
0adfe95a
LC
13555
13556@table @asis
13557@item @code{provision}
13558This is a list of symbols denoting what the service provides.
13559
dd17bc38
AK
13560These are the names that may be passed to @command{herd start},
13561@command{herd status}, and similar commands (@pxref{Invoking herd,,,
13562shepherd, The GNU Shepherd Manual}). @xref{Slots of services, the
13563@code{provides} slot,, shepherd, The GNU Shepherd Manual}, for details.
0adfe95a
LC
13564
13565@item @code{requirements} (default: @code{'()})
dd17bc38 13566List of symbols denoting the Shepherd services this one depends on.
0adfe95a
LC
13567
13568@item @code{respawn?} (default: @code{#t})
13569Whether to restart the service when it stops, for instance when the
13570underlying process dies.
13571
13572@item @code{start}
13573@itemx @code{stop} (default: @code{#~(const #f)})
dd17bc38
AK
13574The @code{start} and @code{stop} fields refer to the Shepherd's
13575facilities to start and stop processes (@pxref{Service De- and
13576Constructors,,, shepherd, The GNU Shepherd Manual}). They are given as
13577G-expressions that get expanded in the Shepherd configuration file
13578(@pxref{G-Expressions}).
0adfe95a
LC
13579
13580@item @code{documentation}
13581A documentation string, as shown when running:
13582
13583@example
dd17bc38 13584herd doc @var{service-name}
0adfe95a
LC
13585@end example
13586
13587where @var{service-name} is one of the symbols in @var{provision}
dd17bc38 13588(@pxref{Invoking herd,,, shepherd, The GNU Shepherd Manual}).
fae685b9
LC
13589
13590@item @code{modules} (default: @var{%default-modules})
13591This is the list of modules that must be in scope when @code{start} and
13592@code{stop} are evaluated.
13593
0adfe95a
LC
13594@end table
13595@end deftp
13596
d4053c71 13597@defvr {Scheme Variable} shepherd-root-service-type
dd17bc38 13598The service type for the Shepherd ``root service''---i.e., PID@tie{}1.
0adfe95a
LC
13599
13600This is the service type that extensions target when they want to create
dd17bc38 13601shepherd services (@pxref{Service Types and Services}, for an example).
d4053c71 13602Each extension must pass a list of @code{<shepherd-service>}.
0adfe95a
LC
13603@end defvr
13604
d4053c71 13605@defvr {Scheme Variable} %shepherd-root-service
0adfe95a
LC
13606This service represents PID@tie{}1.
13607@end defvr
8451a568 13608
8451a568 13609
cf4a9129
LC
13610@node Installing Debugging Files
13611@section Installing Debugging Files
8451a568 13612
cf4a9129
LC
13613@cindex debugging files
13614Program binaries, as produced by the GCC compilers for instance, are
13615typically written in the ELF format, with a section containing
13616@dfn{debugging information}. Debugging information is what allows the
13617debugger, GDB, to map binary code to source code; it is required to
13618debug a compiled program in good conditions.
8451a568 13619
cf4a9129
LC
13620The problem with debugging information is that is takes up a fair amount
13621of disk space. For example, debugging information for the GNU C Library
13622weighs in at more than 60 MiB. Thus, as a user, keeping all the
13623debugging info of all the installed programs is usually not an option.
13624Yet, space savings should not come at the cost of an impediment to
13625debugging---especially in the GNU system, which should make it easier
13626for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 13627
cf4a9129
LC
13628Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
13629mechanism that allows users to get the best of both worlds: debugging
13630information can be stripped from the binaries and stored in separate
13631files. GDB is then able to load debugging information from those files,
13632when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
13633with GDB}).
8451a568 13634
cf4a9129
LC
13635The GNU distribution takes advantage of this by storing debugging
13636information in the @code{lib/debug} sub-directory of a separate package
13637output unimaginatively called @code{debug} (@pxref{Packages with
13638Multiple Outputs}). Users can choose to install the @code{debug} output
13639of a package when they need it. For instance, the following command
13640installs the debugging information for the GNU C Library and for GNU
13641Guile:
8451a568
LC
13642
13643@example
cf4a9129 13644guix package -i glibc:debug guile:debug
8451a568
LC
13645@end example
13646
cf4a9129
LC
13647GDB must then be told to look for debug files in the user's profile, by
13648setting the @code{debug-file-directory} variable (consider setting it
13649from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
13650GDB}):
8451a568 13651
cf4a9129
LC
13652@example
13653(gdb) set debug-file-directory ~/.guix-profile/lib/debug
13654@end example
8451a568 13655
cf4a9129
LC
13656From there on, GDB will pick up debugging information from the
13657@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 13658
cf4a9129
LC
13659In addition, you will most likely want GDB to be able to show the source
13660code being debugged. To do that, you will have to unpack the source
13661code of the package of interest (obtained with @code{guix build
13662--source}, @pxref{Invoking guix build}), and to point GDB to that source
13663directory using the @code{directory} command (@pxref{Source Path,
13664@code{directory},, gdb, Debugging with GDB}).
8451a568 13665
cf4a9129
LC
13666@c XXX: keep me up-to-date
13667The @code{debug} output mechanism in Guix is implemented by the
13668@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
1068f26b
AE
13669opt-in---debugging information is available only for the packages
13670with definitions explicitly declaring a @code{debug} output. This may be
13671changed to opt-out in the future if our build farm servers can handle
cf4a9129
LC
13672the load. To check whether a package has a @code{debug} output, use
13673@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 13674
8451a568 13675
05962f29
LC
13676@node Security Updates
13677@section Security Updates
13678
09866b39
LC
13679@cindex security updates
13680@cindex security vulnerabilities
13681Occasionally, important security vulnerabilities are discovered in software
13682packages and must be patched. Guix developers try hard to keep track of
13683known vulnerabilities and to apply fixes as soon as possible in the
13684@code{master} branch of Guix (we do not yet provide a ``stable'' branch
13685containing only security updates.) The @command{guix lint} tool helps
13686developers find out about vulnerable versions of software packages in the
13687distribution:
13688
13689@smallexample
13690$ guix lint -c cve
13691gnu/packages/base.scm:652:2: glibc-2.21: probably vulnerable to CVE-2015-1781, CVE-2015-7547
13692gnu/packages/gcc.scm:334:2: gcc-4.9.3: probably vulnerable to CVE-2015-5276
13693gnu/packages/image.scm:312:2: openjpeg-2.1.0: probably vulnerable to CVE-2016-1923, CVE-2016-1924
13694@dots{}
13695@end smallexample
13696
13697@xref{Invoking guix lint}, for more information.
13698
843858b8 13699@quotation Note
09866b39
LC
13700As of version @value{VERSION}, the feature described below is considered
13701``beta''.
843858b8 13702@end quotation
05962f29 13703
09866b39 13704Guix follows a functional
05962f29
LC
13705package management discipline (@pxref{Introduction}), which implies
13706that, when a package is changed, @emph{every package that depends on it}
13707must be rebuilt. This can significantly slow down the deployment of
13708fixes in core packages such as libc or Bash, since basically the whole
13709distribution would need to be rebuilt. Using pre-built binaries helps
13710(@pxref{Substitutes}), but deployment may still take more time than
13711desired.
13712
13713@cindex grafts
1068f26b 13714To address this, Guix implements @dfn{grafts}, a mechanism that allows
05962f29
LC
13715for fast deployment of critical updates without the costs associated
13716with a whole-distribution rebuild. The idea is to rebuild only the
13717package that needs to be patched, and then to ``graft'' it onto packages
13718explicitly installed by the user and that were previously referring to
13719the original package. The cost of grafting is typically very low, and
13720order of magnitudes lower than a full rebuild of the dependency chain.
13721
13722@cindex replacements of packages, for grafts
13723For instance, suppose a security update needs to be applied to Bash.
13724Guix developers will provide a package definition for the ``fixed''
13725Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
13726Packages}). Then, the original package definition is augmented with a
13727@code{replacement} field pointing to the package containing the bug fix:
13728
13729@example
13730(define bash
13731 (package
13732 (name "bash")
13733 ;; @dots{}
13734 (replacement bash-fixed)))
13735@end example
13736
c22a1324
LC
13737From there on, any package depending directly or indirectly on Bash---as
13738reported by @command{guix gc --requisites} (@pxref{Invoking guix
13739gc})---that is installed is automatically ``rewritten'' to refer to
05962f29 13740@var{bash-fixed} instead of @var{bash}. This grafting process takes
1068f26b 13741time proportional to the size of the package, usually less than a
c22a1324
LC
13742minute for an ``average'' package on a recent machine. Grafting is
13743recursive: when an indirect dependency requires grafting, then grafting
13744``propagates'' up to the package that the user is installing.
05962f29 13745
57bdd79e
LC
13746Currently, the length of the name and version of the graft and that of
13747the package it replaces (@var{bash-fixed} and @var{bash} in the example
13748above) must be equal. This restriction mostly comes from the fact that
13749grafting works by patching files, including binary files, directly.
05962f29
LC
13750Other restrictions may apply: for instance, when adding a graft to a
13751package providing a shared library, the original shared library and its
13752replacement must have the same @code{SONAME} and be binary-compatible.
13753
59a4dd50
LC
13754The @option{--no-grafts} command-line option allows you to forcefully
13755avoid grafting (@pxref{Common Build Options, @option{--no-grafts}}).
13756Thus, the command:
13757
13758@example
13759guix build bash --no-grafts
13760@end example
13761
13762@noindent
13763returns the store file name of the original Bash, whereas:
13764
13765@example
13766guix build bash
13767@end example
13768
13769@noindent
13770returns the store file name of the ``fixed'', replacement Bash. This
13771allows you to distinguish between the two variants of Bash.
13772
13773To verify which Bash your whole profile refers to, you can run
13774(@pxref{Invoking guix gc}):
13775
13776@example
13777guix gc -R `readlink -f ~/.guix-profile` | grep bash
13778@end example
13779
13780@noindent
13781@dots{} and compare the store file names that you get with those above.
13782Likewise for a complete GuixSD system generation:
13783
13784@example
13785guix gc -R `guix system build my-config.scm` | grep bash
13786@end example
13787
13788Lastly, to check which Bash running processes are using, you can use the
13789@command{lsof} command:
13790
13791@example
13792lsof | grep /gnu/store/.*bash
13793@end example
13794
05962f29 13795
cf4a9129
LC
13796@node Package Modules
13797@section Package Modules
8451a568 13798
cf4a9129
LC
13799From a programming viewpoint, the package definitions of the
13800GNU distribution are provided by Guile modules in the @code{(gnu packages
13801@dots{})} name space@footnote{Note that packages under the @code{(gnu
13802packages @dots{})} module name space are not necessarily ``GNU
13803packages''. This module naming scheme follows the usual Guile module
13804naming convention: @code{gnu} means that these modules are distributed
13805as part of the GNU system, and @code{packages} identifies modules that
13806define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
13807Reference Manual}). For instance, the @code{(gnu packages emacs)}
13808module exports a variable named @code{emacs}, which is bound to a
13809@code{<package>} object (@pxref{Defining Packages}).
113daf62 13810
300868ba 13811The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
13812automatically scanned for packages by the command-line tools. For
13813instance, when running @code{guix package -i emacs}, all the @code{(gnu
13814packages @dots{})} modules are scanned until one that exports a package
13815object whose name is @code{emacs} is found. This package search
13816facility is implemented in the @code{(gnu packages)} module.
113daf62 13817
300868ba 13818@cindex customization, of packages
8689901f 13819@cindex package module search path
cf4a9129 13820Users can store package definitions in modules with different
60142854 13821names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
c95ded7e
LC
13822name and module name must match. For instance, the @code{(my-packages
13823emacs)} module must be stored in a @file{my-packages/emacs.scm} file
13824relative to the load path specified with @option{--load-path} or
13825@code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,,
13826guile, GNU Guile Reference Manual}, for details.}. These package definitions
1068f26b
AE
13827will not be visible by default. Users can invoke commands such as
13828@command{guix package} and @command{guix build} with the
c95ded7e
LC
13829@code{-e} option so that they know where to find the package. Better
13830yet, they can use the
300868ba 13831@code{-L} option of these commands to make those modules visible
8689901f
LC
13832(@pxref{Invoking guix build, @code{--load-path}}), or define the
13833@code{GUIX_PACKAGE_PATH} environment variable. This environment
13834variable makes it easy to extend or customize the distribution and is
13835honored by all the user interfaces.
13836
13837@defvr {Environment Variable} GUIX_PACKAGE_PATH
1068f26b
AE
13838This is a colon-separated list of directories to search for additional
13839package modules. Directories listed in this variable take precedence
13840over the own modules of the distribution.
8689901f 13841@end defvr
ef5dd60a 13842
cf4a9129
LC
13843The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
13844each package is built based solely on other packages in the
13845distribution. The root of this dependency graph is a small set of
13846@dfn{bootstrap binaries}, provided by the @code{(gnu packages
13847bootstrap)} module. For more information on bootstrapping,
081145cf 13848@pxref{Bootstrapping}.
ef5dd60a 13849
cf4a9129
LC
13850@node Packaging Guidelines
13851@section Packaging Guidelines
ef5dd60a 13852
e32171ee 13853@cindex packages, creating
cf4a9129
LC
13854The GNU distribution is nascent and may well lack some of your favorite
13855packages. This section describes how you can help make the distribution
13856grow. @xref{Contributing}, for additional information on how you can
13857help.
ef5dd60a 13858
cf4a9129
LC
13859Free software packages are usually distributed in the form of
13860@dfn{source code tarballs}---typically @file{tar.gz} files that contain
13861all the source files. Adding a package to the distribution means
13862essentially two things: adding a @dfn{recipe} that describes how to
13863build the package, including a list of other packages required to build
f97c9175 13864it, and adding @dfn{package metadata} along with that recipe, such as a
cf4a9129 13865description and licensing information.
ef5dd60a 13866
cf4a9129
LC
13867In Guix all this information is embodied in @dfn{package definitions}.
13868Package definitions provide a high-level view of the package. They are
13869written using the syntax of the Scheme programming language; in fact,
13870for each package we define a variable bound to the package definition,
13871and export that variable from a module (@pxref{Package Modules}).
13872However, in-depth Scheme knowledge is @emph{not} a prerequisite for
13873creating packages. For more information on package definitions,
081145cf 13874@pxref{Defining Packages}.
ef5dd60a 13875
cf4a9129
LC
13876Once a package definition is in place, stored in a file in the Guix
13877source tree, it can be tested using the @command{guix build} command
13878(@pxref{Invoking guix build}). For example, assuming the new package is
c71979f4
LC
13879called @code{gnew}, you may run this command from the Guix build tree
13880(@pxref{Running Guix Before It Is Installed}):
ef5dd60a
LC
13881
13882@example
cf4a9129 13883./pre-inst-env guix build gnew --keep-failed
ef5dd60a 13884@end example
ef5dd60a 13885
cf4a9129
LC
13886Using @code{--keep-failed} makes it easier to debug build failures since
13887it provides access to the failed build tree. Another useful
13888command-line option when debugging is @code{--log-file}, to access the
13889build log.
ef5dd60a 13890
cf4a9129
LC
13891If the package is unknown to the @command{guix} command, it may be that
13892the source file contains a syntax error, or lacks a @code{define-public}
13893clause to export the package variable. To figure it out, you may load
13894the module from Guile to get more information about the actual error:
ef5dd60a 13895
cf4a9129
LC
13896@example
13897./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
13898@end example
ef5dd60a 13899
cf4a9129
LC
13900Once your package builds correctly, please send us a patch
13901(@pxref{Contributing}). Well, if you need help, we will be happy to
13902help you too. Once the patch is committed in the Guix repository, the
13903new package automatically gets built on the supported platforms by
2b1cee21 13904@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 13905system}.
ef5dd60a 13906
cf4a9129
LC
13907@cindex substituter
13908Users can obtain the new package definition simply by running
13909@command{guix pull} (@pxref{Invoking guix pull}). When
13910@code{hydra.gnu.org} is done building the package, installing the
13911package automatically downloads binaries from there
13912(@pxref{Substitutes}). The only place where human intervention is
13913needed is to review and apply the patch.
ef5dd60a 13914
ef5dd60a 13915
cf4a9129 13916@menu
ec0339cd
LC
13917* Software Freedom:: What may go into the distribution.
13918* Package Naming:: What's in a name?
13919* Version Numbers:: When the name is not enough.
cbd02397 13920* Synopses and Descriptions:: Helping users find the right package.
ec0339cd
LC
13921* Python Modules:: Taming the snake.
13922* Perl Modules:: Little pearls.
e1c963bf 13923* Java Packages:: Coffee break.
ec0339cd 13924* Fonts:: Fond of fonts.
cf4a9129 13925@end menu
ef5dd60a 13926
cf4a9129
LC
13927@node Software Freedom
13928@subsection Software Freedom
ef5dd60a 13929
cf4a9129 13930@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
e32171ee 13931@cindex free software
cf4a9129
LC
13932The GNU operating system has been developed so that users can have
13933freedom in their computing. GNU is @dfn{free software}, meaning that
13934users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
13935essential freedoms}: to run the program, to study and change the program
13936in source code form, to redistribute exact copies, and to distribute
13937modified versions. Packages found in the GNU distribution provide only
13938software that conveys these four freedoms.
c11a6eb1 13939
cf4a9129
LC
13940In addition, the GNU distribution follow the
13941@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
13942software distribution guidelines}. Among other things, these guidelines
13943reject non-free firmware, recommendations of non-free software, and
13944discuss ways to deal with trademarks and patents.
ef5dd60a 13945
1068f26b
AE
13946Some otherwise free upstream package sources contain a small and optional
13947subset that violates the above guidelines, for instance because this subset
13948is itself non-free code. When that happens, the offending items are removed
13949with appropriate patches or code snippets in the @code{origin} form of the
13950package (@pxref{Defining Packages}). This way, @code{guix
cf4a9129
LC
13951build --source} returns the ``freed'' source rather than the unmodified
13952upstream source.
ef5dd60a 13953
ef5dd60a 13954
cf4a9129
LC
13955@node Package Naming
13956@subsection Package Naming
ef5dd60a 13957
e32171ee 13958@cindex package name
cf4a9129
LC
13959A package has actually two names associated with it:
13960First, there is the name of the @emph{Scheme variable}, the one following
13961@code{define-public}. By this name, the package can be made known in the
13962Scheme code, for instance as input to another package. Second, there is
13963the string in the @code{name} field of a package definition. This name
13964is used by package management commands such as
13965@command{guix package} and @command{guix build}.
ef5dd60a 13966
cf4a9129
LC
13967Both are usually the same and correspond to the lowercase conversion of
13968the project name chosen upstream, with underscores replaced with
13969hyphens. For instance, GNUnet is available as @code{gnunet}, and
13970SDL_net as @code{sdl-net}.
927097ef 13971
cf4a9129 13972We do not add @code{lib} prefixes for library packages, unless these are
081145cf 13973already part of the official project name. But @pxref{Python
cf4a9129
LC
13974Modules} and @ref{Perl Modules} for special rules concerning modules for
13975the Python and Perl languages.
927097ef 13976
1b366ee4 13977Font package names are handled differently, @pxref{Fonts}.
7fec52b7 13978
ef5dd60a 13979
cf4a9129
LC
13980@node Version Numbers
13981@subsection Version Numbers
ef5dd60a 13982
e32171ee 13983@cindex package version
cf4a9129
LC
13984We usually package only the latest version of a given free software
13985project. But sometimes, for instance for incompatible library versions,
13986two (or more) versions of the same package are needed. These require
13987different Scheme variable names. We use the name as defined
13988in @ref{Package Naming}
13989for the most recent version; previous versions use the same name, suffixed
13990by @code{-} and the smallest prefix of the version number that may
13991distinguish the two versions.
ef5dd60a 13992
cf4a9129
LC
13993The name inside the package definition is the same for all versions of a
13994package and does not contain any version number.
ef5dd60a 13995
cf4a9129 13996For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 13997
cf4a9129
LC
13998@example
13999(define-public gtk+
14000 (package
17d8e33f
ML
14001 (name "gtk+")
14002 (version "3.9.12")
14003 ...))
cf4a9129
LC
14004(define-public gtk+-2
14005 (package
17d8e33f
ML
14006 (name "gtk+")
14007 (version "2.24.20")
14008 ...))
cf4a9129
LC
14009@end example
14010If we also wanted GTK+ 3.8.2, this would be packaged as
14011@example
14012(define-public gtk+-3.8
14013 (package
17d8e33f
ML
14014 (name "gtk+")
14015 (version "3.8.2")
14016 ...))
cf4a9129 14017@end example
ef5dd60a 14018
880d647d
LC
14019@c See <https://lists.gnu.org/archive/html/guix-devel/2016-01/msg00425.html>,
14020@c for a discussion of what follows.
14021@cindex version number, for VCS snapshots
14022Occasionally, we package snapshots of upstream's version control system
14023(VCS) instead of formal releases. This should remain exceptional,
14024because it is up to upstream developers to clarify what the stable
14025release is. Yet, it is sometimes necessary. So, what should we put in
14026the @code{version} field?
14027
14028Clearly, we need to make the commit identifier of the VCS snapshot
14029visible in the version string, but we also need to make sure that the
14030version string is monotonically increasing so that @command{guix package
14031--upgrade} can determine which version is newer. Since commit
14032identifiers, notably with Git, are not monotonically increasing, we add
14033a revision number that we increase each time we upgrade to a newer
14034snapshot. The resulting version string looks like this:
14035
14036@example
140372.0.11-3.cabba9e
14038 ^ ^ ^
14039 | | `-- upstream commit ID
14040 | |
14041 | `--- Guix package revision
14042 |
14043latest upstream version
14044@end example
14045
14046It is a good idea to strip commit identifiers in the @code{version}
14047field to, say, 7 digits. It avoids an aesthetic annoyance (assuming
14048aesthetics have a role to play here) as well as problems related to OS
14049limits such as the maximum shebang length (127 bytes for the Linux
14050kernel.) It is best to use the full commit identifiers in
561360a5
LC
14051@code{origin}s, though, to avoid ambiguities. A typical package
14052definition may look like this:
14053
14054@example
14055(define my-package
6e42660b 14056 (let ((commit "c3f29bc928d5900971f65965feaae59e1272a3f7")
14057 (revision "1")) ;Guix package revision
561360a5 14058 (package
6e42660b 14059 (version (string-append "0.9-" revision "."
561360a5
LC
14060 (string-take commit 7)))
14061 (source (origin
14062 (method git-fetch)
14063 (uri (git-reference
14064 (url "git://example.org/my-package.git")
14065 (commit commit)))
14066 (sha256 (base32 "1mbikn@dots{}"))
14067 (file-name (string-append "my-package-" version
14068 "-checkout"))))
14069 ;; @dots{}
14070 )))
14071@end example
880d647d 14072
cbd02397
LC
14073@node Synopses and Descriptions
14074@subsection Synopses and Descriptions
14075
e32171ee
JD
14076@cindex package description
14077@cindex package synopsis
cbd02397
LC
14078As we have seen before, each package in GNU@tie{}Guix includes a
14079synopsis and a description (@pxref{Defining Packages}). Synopses and
14080descriptions are important: They are what @command{guix package
14081--search} searches, and a crucial piece of information to help users
14082determine whether a given package suits their needs. Consequently,
14083packagers should pay attention to what goes into them.
14084
14085Synopses must start with a capital letter and must not end with a
14086period. They must not start with ``a'' or ``the'', which usually does
14087not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
14088tool that frobs files''. The synopsis should say what the package
14089is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
14090used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
14091matching a pattern''.
14092
14093Keep in mind that the synopsis must be meaningful for a very wide
14094audience. For example, ``Manipulate alignments in the SAM format''
14095might make sense for a seasoned bioinformatics researcher, but might be
14096fairly unhelpful or even misleading to a non-specialized audience. It
14097is a good idea to come up with a synopsis that gives an idea of the
14098application domain of the package. In this example, this might give
14099something like ``Manipulate nucleotide sequence alignments'', which
14100hopefully gives the user a better idea of whether this is what they are
14101looking for.
14102
cbd02397
LC
14103Descriptions should take between five and ten lines. Use full
14104sentences, and avoid using acronyms without first introducing them.
762e54b7
LC
14105Please avoid marketing phrases such as ``world-leading'',
14106``industrial-strength'', and ``next-generation'', and avoid superlatives
14107like ``the most advanced''---they are not helpful to users looking for a
14108package and may even sound suspicious. Instead, try to be factual,
14109mentioning use cases and features.
14110
14111@cindex Texinfo markup, in package descriptions
cbd02397
LC
14112Descriptions can include Texinfo markup, which is useful to introduce
14113ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
ba7d6c76
ML
14114hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you
14115should be careful when using some characters for example @samp{@@} and
14116curly braces which are the basic special characters in Texinfo
14117(@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces
14118such as @command{guix package --show} take care of rendering it
14119appropriately.
cbd02397
LC
14120
14121Synopses and descriptions are translated by volunteers
14122@uref{http://translationproject.org/domain/guix-packages.html, at the
14123Translation Project} so that as many users as possible can read them in
14124their native language. User interfaces search them and display them in
14125the language specified by the current locale.
14126
14127Translation is a lot of work so, as a packager, please pay even more
14128attention to your synopses and descriptions as every change may entail
ba7d6c76 14129additional work for translators. In order to help them, it is possible
36743e71 14130to make recommendations or instructions visible to them by inserting
ba7d6c76
ML
14131special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
14132Gettext}):
14133
14134@example
14135;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
14136(description "ARandR is designed to provide a simple visual front end
14137for the X11 resize-and-rotate (RandR) extension. @dots{}")
14138@end example
cbd02397 14139
ef5dd60a 14140
cf4a9129
LC
14141@node Python Modules
14142@subsection Python Modules
ef5dd60a 14143
e32171ee 14144@cindex python
cf4a9129
LC
14145We currently package Python 2 and Python 3, under the Scheme variable names
14146@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
14147To avoid confusion and naming clashes with other programming languages, it
14148seems desirable that the name of a package for a Python module contains
14149the word @code{python}.
ef5dd60a 14150
cf4a9129
LC
14151Some modules are compatible with only one version of Python, others with both.
14152If the package Foo compiles only with Python 3, we name it
14153@code{python-foo}; if it compiles only with Python 2, we name it
14154@code{python2-foo}. If it is compatible with both versions, we create two
14155packages with the corresponding names.
ef5dd60a 14156
cf4a9129
LC
14157If a project already contains the word @code{python}, we drop this;
14158for instance, the module python-dateutil is packaged under the names
99c866a0
HG
14159@code{python-dateutil} and @code{python2-dateutil}. If the project name
14160starts with @code{py} (e.g. @code{pytz}), we keep it and prefix it as
14161described above.
113daf62 14162
e940a271
HG
14163@subsubsection Specifying Dependencies
14164@cindex inputs, for Python packages
14165
14166Dependency information for Python packages is usually available in the
14167package source tree, with varying degrees of accuracy: in the
14168@file{setup.py} file, in @file{requirements.txt}, or in @file{tox.ini}.
14169
14170Your mission, when writing a recipe for a Python package, is to map
14171these dependencies to the appropriate type of ``input'' (@pxref{package
14172Reference, inputs}). Although the @code{pypi} importer normally does a
14173good job (@pxref{Invoking guix import}), you may want to check the
14174following check list to determine which dependency goes where.
14175
14176@itemize
14177
aaf75c89
HG
14178@item
14179We currently package Python 2 with @code{setuptools} and @code{pip}
14180installed like Python 3.4 has per default. Thus you don't need to
891a843d
HG
14181specify either of these as an input. @command{guix lint} will warn you
14182if you do.
aaf75c89 14183
e940a271
HG
14184@item
14185Python dependencies required at run time go into
14186@code{propagated-inputs}. They are typically defined with the
14187@code{install_requires} keyword in @file{setup.py}, or in the
14188@file{requirements.txt} file.
14189
14190@item
14191Python packages required only at build time---e.g., those listed with
14192the @code{setup_requires} keyword in @file{setup.py}---or only for
14193testing---e.g., those in @code{tests_require}---go into
14194@code{native-inputs}. The rationale is that (1) they do not need to be
14195propagated because they are not needed at run time, and (2) in a
14196cross-compilation context, it's the ``native'' input that we'd want.
14197
aaf75c89 14198Examples are the @code{pytest}, @code{mock}, and @code{nose} test
e940a271
HG
14199frameworks. Of course if any of these packages is also required at
14200run-time, it needs to go to @code{propagated-inputs}.
14201
14202@item
14203Anything that does not fall in the previous categories goes to
14204@code{inputs}, for example programs or C libraries required for building
14205Python packages containing C extensions.
14206
14207@item
14208If a Python package has optional dependencies (@code{extras_require}),
14209it is up to you to decide whether to add them or not, based on their
14210usefulness/overhead ratio (@pxref{Submitting Patches, @command{guix
14211size}}).
14212
14213@end itemize
14214
14215
cf4a9129
LC
14216@node Perl Modules
14217@subsection Perl Modules
523e4896 14218
e32171ee 14219@cindex perl
cf4a9129
LC
14220Perl programs standing for themselves are named as any other package,
14221using the lowercase upstream name.
14222For Perl packages containing a single class, we use the lowercase class name,
14223replace all occurrences of @code{::} by dashes and prepend the prefix
14224@code{perl-}.
14225So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
14226Modules containing several classes keep their lowercase upstream name and
14227are also prepended by @code{perl-}. Such modules tend to have the word
14228@code{perl} somewhere in their name, which gets dropped in favor of the
14229prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 14230
523e4896 14231
e1c963bf
HG
14232@node Java Packages
14233@subsection Java Packages
14234
e32171ee 14235@cindex java
e1c963bf
HG
14236Java programs standing for themselves are named as any other package,
14237using the lowercase upstream name.
14238
14239To avoid confusion and naming clashes with other programming languages,
14240it is desirable that the name of a package for a Java package is
14241prefixed with @code{java-}. If a project already contains the word
14242@code{java}, we drop this; for instance, the package @code{ngsjava} is
14243packaged under the name @code{java-ngs}.
14244
14245For Java packages containing a single class or a small class hierarchy,
14246we use the lowercase class name, replace all occurrences of @code{.} by
14247dashes and prepend the prefix @code{java-}. So the class
14248@code{apache.commons.cli} becomes package
14249@code{java-apache-commons-cli}.
14250
14251
7fec52b7
AE
14252@node Fonts
14253@subsection Fonts
14254
e32171ee 14255@cindex fonts
7fec52b7
AE
14256For fonts that are in general not installed by a user for typesetting
14257purposes, or that are distributed as part of a larger software package,
14258we rely on the general packaging rules for software; for instance, this
14259applies to the fonts delivered as part of the X.Org system or fonts that
14260are part of TeX Live.
14261
14262To make it easier for a user to search for fonts, names for other packages
14263containing only fonts are constructed as follows, independently of the
14264upstream package name.
14265
14266The name of a package containing only one font family starts with
14267@code{font-}; it is followed by the foundry name and a dash @code{-}
14268if the foundry is known, and the font family name, in which spaces are
14269replaced by dashes (and as usual, all upper case letters are transformed
14270to lower case).
14271For example, the Gentium font family by SIL is packaged under the name
14272@code{font-sil-gentium}.
14273
14274For a package containing several font families, the name of the collection
14275is used in the place of the font family name.
14276For instance, the Liberation fonts consist of three families,
14277Liberation Sans, Liberation Serif and Liberation Mono.
14278These could be packaged separately under the names
14279@code{font-liberation-sans} and so on; but as they are distributed together
14280under a common name, we prefer to package them together as
14281@code{font-liberation}.
14282
14283In the case where several formats of the same font family or font collection
14284are packaged separately, a short form of the format, prepended by a dash,
14285is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 14286@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
14287fonts.
14288
14289
b25937e3 14290
cf4a9129
LC
14291@node Bootstrapping
14292@section Bootstrapping
b25937e3 14293
cf4a9129 14294@c Adapted from the ELS 2013 paper.
b25937e3 14295
cf4a9129 14296@cindex bootstrapping
7889394e 14297
cf4a9129
LC
14298Bootstrapping in our context refers to how the distribution gets built
14299``from nothing''. Remember that the build environment of a derivation
14300contains nothing but its declared inputs (@pxref{Introduction}). So
14301there's an obvious chicken-and-egg problem: how does the first package
14302get built? How does the first compiler get compiled? Note that this is
14303a question of interest only to the curious hacker, not to the regular
14304user, so you can shamelessly skip this section if you consider yourself
14305a ``regular user''.
72b9d60d 14306
cf4a9129
LC
14307@cindex bootstrap binaries
14308The GNU system is primarily made of C code, with libc at its core. The
14309GNU build system itself assumes the availability of a Bourne shell and
14310command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
14311`grep'. Furthermore, build programs---programs that run
14312@code{./configure}, @code{make}, etc.---are written in Guile Scheme
14313(@pxref{Derivations}). Consequently, to be able to build anything at
14314all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
14315Binutils, libc, and the other packages mentioned above---the
14316@dfn{bootstrap binaries}.
72b9d60d 14317
cf4a9129
LC
14318These bootstrap binaries are ``taken for granted'', though we can also
14319re-create them if needed (more on that later).
72b9d60d 14320
cf4a9129 14321@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 14322
cf4a9129
LC
14323@c As of Emacs 24.3, Info-mode displays the image, but since it's a
14324@c large image, it's hard to scroll. Oh well.
14325@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 14326
cf4a9129
LC
14327The figure above shows the very beginning of the dependency graph of the
14328distribution, corresponding to the package definitions of the @code{(gnu
d33fa0c7
LC
14329packages bootstrap)} module. A similar figure can be generated with
14330@command{guix graph} (@pxref{Invoking guix graph}), along the lines of:
14331
14332@example
14333guix graph -t derivation \
14334 -e '(@@@@ (gnu packages bootstrap) %bootstrap-gcc)' \
14335 | dot -Tps > t.ps
14336@end example
14337
14338At this level of detail, things are
cf4a9129
LC
14339slightly complex. First, Guile itself consists of an ELF executable,
14340along with many source and compiled Scheme files that are dynamically
14341loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
14342tarball shown in this graph. This tarball is part of Guix's ``source''
14343distribution, and gets inserted into the store with @code{add-to-store}
14344(@pxref{The Store}).
2e7b5cea 14345
cf4a9129
LC
14346But how do we write a derivation that unpacks this tarball and adds it
14347to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
14348derivation---the first one that gets built---uses @code{bash} as its
14349builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
14350@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
14351@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
14352the Guix source distribution, whose sole purpose is to allow the Guile
14353tarball to be unpacked.
fb729425 14354
cf4a9129
LC
14355Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
14356Guile that can be used to run subsequent build programs. Its first task
14357is to download tarballs containing the other pre-built binaries---this
14358is what the @code{.tar.xz.drv} derivations do. Guix modules such as
14359@code{ftp-client.scm} are used for this purpose. The
14360@code{module-import.drv} derivations import those modules in a directory
14361in the store, using the original layout. The
14362@code{module-import-compiled.drv} derivations compile those modules, and
14363write them in an output directory with the right layout. This
14364corresponds to the @code{#:modules} argument of
14365@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 14366
cf4a9129
LC
14367Finally, the various tarballs are unpacked by the
14368derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
14369etc., at which point we have a working C tool chain.
fb729425 14370
fb729425 14371
cf4a9129 14372@unnumberedsubsec Building the Build Tools
523e4896 14373
cf4a9129
LC
14374Bootstrapping is complete when we have a full tool chain that does not
14375depend on the pre-built bootstrap tools discussed above. This
14376no-dependency requirement is verified by checking whether the files of
14377the final tool chain contain references to the @file{/gnu/store}
14378directories of the bootstrap inputs. The process that leads to this
14379``final'' tool chain is described by the package definitions found in
1f6f57df 14380the @code{(gnu packages commencement)} module.
df2ce343 14381
d33fa0c7
LC
14382The @command{guix graph} command allows us to ``zoom out'' compared to
14383the graph above, by looking at the level of package objects instead of
14384individual derivations---remember that a package may translate to
14385several derivations, typically one derivation to download its source,
14386one to build the Guile modules it needs, and one to actually build the
14387package from source. The command:
14388
14389@example
14390guix graph -t bag \
14391 -e '(@@@@ (gnu packages commencement)
14392 glibc-final-with-bootstrap-bash)' | dot -Tps > t.ps
14393@end example
14394
14395@noindent
14396produces the dependency graph leading to the ``final'' C
14397library@footnote{You may notice the @code{glibc-intermediate} label,
14398suggesting that it is not @emph{quite} final, but as a good
14399approximation, we will consider it final.}, depicted below.
14400
14401@image{images/bootstrap-packages,6in,,Dependency graph of the early packages}
14402
cf4a9129
LC
14403@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
14404The first tool that gets built with the bootstrap binaries is
d33fa0c7
LC
14405GNU@tie{}Make---noted @code{make-boot0} above---which is a prerequisite
14406for all the following packages. From there Findutils and Diffutils get
14407built.
523e4896 14408
cf4a9129
LC
14409Then come the first-stage Binutils and GCC, built as pseudo cross
14410tools---i.e., with @code{--target} equal to @code{--host}. They are
14411used to build libc. Thanks to this cross-build trick, this libc is
14412guaranteed not to hold any reference to the initial tool chain.
4af2447e 14413
d33fa0c7
LC
14414From there the final Binutils and GCC (not shown above) are built.
14415GCC uses @code{ld}
cf4a9129
LC
14416from the final Binutils, and links programs against the just-built libc.
14417This tool chain is used to build the other packages used by Guix and by
14418the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 14419
cf4a9129
LC
14420And voilà! At this point we have the complete set of build tools that
14421the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
14422variable of the @code{(gnu packages commencement)} module, and are
14423implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 14424(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 14425
4af2447e 14426
cf4a9129 14427@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 14428
e32171ee 14429@cindex bootstrap binaries
cf4a9129
LC
14430Because the final tool chain does not depend on the bootstrap binaries,
14431those rarely need to be updated. Nevertheless, it is useful to have an
14432automated way to produce them, should an update occur, and this is what
14433the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 14434
cf4a9129
LC
14435The following command builds the tarballs containing the bootstrap
14436binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
14437of Coreutils and other basic command-line tools):
4b2615e1 14438
cf4a9129
LC
14439@example
14440guix build bootstrap-tarballs
14441@end example
14442
14443The generated tarballs are those that should be referred to in the
14444@code{(gnu packages bootstrap)} module mentioned at the beginning of
14445this section.
14446
14447Still here? Then perhaps by now you've started to wonder: when do we
14448reach a fixed point? That is an interesting question! The answer is
14449unknown, but if you would like to investigate further (and have
14450significant computational and storage resources to do so), then let us
14451know.
14452
14453@node Porting
14454@section Porting to a New Platform
14455
14456As discussed above, the GNU distribution is self-contained, and
14457self-containment is achieved by relying on pre-built ``bootstrap
14458binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
14459operating system kernel, CPU architecture, and application binary
14460interface (ABI). Thus, to port the distribution to a platform that is
14461not yet supported, one must build those bootstrap binaries, and update
14462the @code{(gnu packages bootstrap)} module to use them on that platform.
14463
14464Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
14465When everything goes well, and assuming the GNU tool chain supports the
14466target platform, this can be as simple as running a command like this
14467one:
14468
14469@example
14470guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
14471@end example
14472
1c0c417d
LC
14473For this to work, the @code{glibc-dynamic-linker} procedure in
14474@code{(gnu packages bootstrap)} must be augmented to return the right
14475file name for libc's dynamic linker on that platform; likewise,
14476@code{system->linux-architecture} in @code{(gnu packages linux)} must be
14477taught about the new platform.
14478
cf4a9129 14479Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
14480to be updated to refer to these binaries on the target platform. That
14481is, the hashes and URLs of the bootstrap tarballs for the new platform
14482must be added alongside those of the currently supported platforms. The
14483bootstrap Guile tarball is treated specially: it is expected to be
03d0e2d2 14484available locally, and @file{gnu/local.mk} has rules do download it for
1c0c417d
LC
14485the supported architectures; a rule for the new platform must be added
14486as well.
cf4a9129
LC
14487
14488In practice, there may be some complications. First, it may be that the
14489extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
14490above) is not recognized by all the GNU tools. Typically, glibc
14491recognizes some of these, whereas GCC uses an extra @code{--with-abi}
14492configure flag (see @code{gcc.scm} for examples of how to handle this).
14493Second, some of the required packages could fail to build for that
14494platform. Lastly, the generated binaries could be broken for some
14495reason.
4af2447e 14496
9bf3c1a7 14497@c *********************************************************************
8c01b9d0 14498@include contributing.texi
c78bd12b 14499
568717fd
LC
14500@c *********************************************************************
14501@node Acknowledgments
14502@chapter Acknowledgments
14503
136787cb
LC
14504Guix is based on the @uref{http://nixos.org/nix/, Nix package manager},
14505which was designed and
4c7ac9aa
LC
14506implemented by Eelco Dolstra, with contributions from other people (see
14507the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
14508management, and promoted unprecedented features, such as transactional
14509package upgrades and rollbacks, per-user profiles, and referentially
14510transparent build processes. Without this work, Guix would not exist.
14511
14512The Nix-based software distributions, Nixpkgs and NixOS, have also been
14513an inspiration for Guix.
14514
4c7ac9aa
LC
14515GNU@tie{}Guix itself is a collective work with contributions from a
14516number of people. See the @file{AUTHORS} file in Guix for more
14517information on these fine people. The @file{THANKS} file lists people
14518who have helped by reporting bugs, taking care of the infrastructure,
14519providing artwork and themes, making suggestions, and more---thank you!
14520
14521
568717fd
LC
14522@c *********************************************************************
14523@node GNU Free Documentation License
14524@appendix GNU Free Documentation License
e32171ee 14525@cindex license, GNU Free Documentation License
568717fd
LC
14526@include fdl-1.3.texi
14527
14528@c *********************************************************************
14529@node Concept Index
14530@unnumbered Concept Index
14531@printindex cp
14532
a85b83d2
LC
14533@node Programming Index
14534@unnumbered Programming Index
14535@syncodeindex tp fn
14536@syncodeindex vr fn
568717fd
LC
14537@printindex fn
14538
14539@bye
14540
14541@c Local Variables:
14542@c ispell-local-dictionary: "american";
14543@c End: