gnu: ucommon: Update to 6.3.1.
[jackhill/guix/guix.git] / doc / guix.texi
CommitLineData
568717fd
LC
1\input texinfo
2@c -*-texinfo-*-
3
4@c %**start of header
5@setfilename guix.info
6@documentencoding UTF-8
f8348b91 7@settitle GNU Guix Reference Manual
568717fd
LC
8@c %**end of header
9
10@include version.texi
7df7a74e
NK
11
12@copying
4379c35b 13Copyright @copyright{} 2012, 2013, 2014, 2015 Ludovic Courtès@*
af8a56b8 14Copyright @copyright{} 2013, 2014 Andreas Enge@*
7df7a74e
NK
15Copyright @copyright{} 2013 Nikita Karetnikov
16
17Permission is granted to copy, distribute and/or modify this document
18under the terms of the GNU Free Documentation License, Version 1.3 or
19any later version published by the Free Software Foundation; with no
20Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
21copy of the license is included in the section entitled ``GNU Free
22Documentation License''.
23@end copying
568717fd 24
eeaf4427 25@dircategory Package management
568717fd
LC
26@direntry
27* guix: (guix). Guix, the functional package manager.
e49951eb 28* guix package: (guix)Invoking guix package
eeaf4427 29 Managing packages with Guix.
e49951eb 30* guix build: (guix)Invoking guix build
568717fd 31 Building packages with Guix.
054e8576
LC
32* guix system: (guix)Invoking guix system
33 Managing the operating system configuration.
568717fd 34@end direntry
568717fd 35
372c4bbc
DT
36@dircategory Software development
37@direntry
38* guix environment: (guix)Invoking guix environment
39 Building development environments with Guix.
40@end direntry
41
568717fd 42@titlepage
7730d112
LC
43@title GNU Guix Reference Manual
44@subtitle Using the GNU Guix Functional Package Manager
568717fd 45@author Ludovic Courtès
da7cabd4 46@author Andreas Enge
acc08466 47@author Nikita Karetnikov
568717fd
LC
48
49@page
50@vskip 0pt plus 1filll
51Edition @value{EDITION} @*
52@value{UPDATED} @*
53
7df7a74e 54@insertcopying
568717fd
LC
55@end titlepage
56
568717fd
LC
57@contents
58
59@c *********************************************************************
60@node Top
f8348b91 61@top GNU Guix
568717fd 62
f8348b91
LC
63This document describes GNU Guix version @value{VERSION}, a functional
64package management tool written for the GNU system.
568717fd
LC
65
66@menu
67* Introduction:: What is Guix about?
bd5e766b 68* Installation:: Installing Guix.
eeaf4427 69* Package Management:: Package installation, upgrade, etc.
568717fd
LC
70* Programming Interface:: Using Guix in Scheme.
71* Utilities:: Package management commands.
a1ba8475 72* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 73* Contributing:: Your help needed!
568717fd
LC
74
75* Acknowledgments:: Thanks!
76* GNU Free Documentation License:: The license of this manual.
77* Concept Index:: Concepts.
a85b83d2 78* Programming Index:: Data types, functions, and variables.
aaa3eaa9
LC
79
80@detailmenu
81 --- The Detailed Node Listing ---
82
83Installation
84
85* Requirements:: Software needed to build and run Guix.
ec0339cd 86* Running the Test Suite:: Testing Guix.
aaa3eaa9
LC
87* Setting Up the Daemon:: Preparing the build daemon's environment.
88* Invoking guix-daemon:: Running the build daemon.
89
90Setting Up the Daemon
91
92* Build Environment Setup:: Preparing the isolated build environment.
93* Daemon Offload Setup:: Offloading builds to remote machines.
94
95Package Management
96
97* Features:: How Guix will make your life brighter.
98* Invoking guix package:: Package installation, removal, etc.
99* Emacs Interface:: Package management from Emacs.
100* Substitutes:: Downloading pre-built binaries.
101* Packages with Multiple Outputs:: Single source package, multiple outputs.
102* Invoking guix gc:: Running the garbage collector.
103* Invoking guix pull:: Fetching the latest Guix and distribution.
104* Invoking guix archive:: Exporting and importing store files.
105
106Programming Interface
107
108* Defining Packages:: Defining new packages.
109* Build Systems:: Specifying how packages are built.
110* The Store:: Manipulating the package store.
111* Derivations:: Low-level interface to package derivations.
112* The Store Monad:: Purely functional interface to the store.
113* G-Expressions:: Manipulating build expressions.
114
115Utilities
116
117* Invoking guix build:: Building packages from the command line.
118* Invoking guix download:: Downloading a file and printing its hash.
119* Invoking guix hash:: Computing the cryptographic hash of a file.
120* Invoking guix import:: Importing package definitions.
121* Invoking guix refresh:: Updating package definitions.
122* Invoking guix lint:: Finding errors in package definitions.
123* Invoking guix environment:: Setting up development environments.
aff8ce7c 124* Invoking guix publish:: Sharing substitutes.
aaa3eaa9
LC
125
126GNU Distribution
127
128* System Installation:: Installing the whole operating system.
35ed9306 129* System Configuration:: Configuring the operating system.
aaa3eaa9
LC
130* Installing Debugging Files:: Feeding the debugger.
131* Security Updates:: Deploying security fixes quickly.
132* Package Modules:: Packages from the programmer's viewpoint.
133* Packaging Guidelines:: Growing the distribution.
134* Bootstrapping:: GNU/Linux built from scratch.
135* Porting:: Targeting another platform or kernel.
136
137System Configuration
138
139* Using the Configuration System:: Customizing your GNU system.
140* operating-system Reference:: Detail of operating-system declarations.
141* File Systems:: Configuring file system mounts.
142* Mapped Devices:: Block device extra processing.
143* User Accounts:: Specifying user accounts.
598e19dc 144* Locales:: Language and cultural convention settings.
aaa3eaa9
LC
145* Services:: Specifying system services.
146* Setuid Programs:: Programs running with root privileges.
996ed739 147* Name Service Switch:: Configuring libc's name service switch.
aaa3eaa9
LC
148* Initial RAM Disk:: Linux-Libre bootstrapping.
149* GRUB Configuration:: Configuring the boot loader.
150* Invoking guix system:: Instantiating a system configuration.
151* Defining Services:: Adding new service definitions.
152
153Services
154
155* Base Services:: Essential system services.
156* Networking Services:: Network setup, SSH daemon, etc.
157* X Window:: Graphical display.
aa4ed923 158* Various Services:: Other services.
aaa3eaa9
LC
159
160Packaging Guidelines
161
ec0339cd
LC
162* Software Freedom:: What may go into the distribution.
163* Package Naming:: What's in a name?
164* Version Numbers:: When the name is not enough.
165* Python Modules:: Taming the snake.
166* Perl Modules:: Little pearls.
167* Fonts:: Fond of fonts.
aaa3eaa9
LC
168
169@end detailmenu
568717fd
LC
170@end menu
171
172@c *********************************************************************
173@node Introduction
174@chapter Introduction
175
c80e7e55
LC
176GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
177using the international phonetic alphabet (IPA).} is a functional
178package management tool for the GNU system. Package management consists
4bfc4ea3
NK
179of all activities that relate to building packages from sources,
180honoring their build-time and run-time dependencies,
c80e7e55
LC
181installing packages in user environments, upgrading installed packages
182to new versions or rolling back to a previous set, removing unused
183software packages, etc.
568717fd
LC
184
185@cindex functional package management
186The term @dfn{functional} refers to a specific package management
187discipline. In Guix, the package build and installation process is seen
4bfc4ea3
NK
188as a function, in the mathematical sense. That function takes inputs,
189such as build scripts, a compiler, and libraries, and
190returns an installed package. As a pure function, its result depends
568717fd
LC
191solely on its inputs---for instance, it cannot refer to software or
192scripts that were not explicitly passed as inputs. A build function
4bfc4ea3
NK
193always produces the same result when passed a given set of inputs. It
194cannot alter the system's environment in
568717fd
LC
195any way; for instance, it cannot create, modify, or delete files outside
196of its build and installation directories. This is achieved by running
e900c503 197build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 198explicit inputs are visible.
568717fd 199
e531ac2a 200@cindex store
568717fd 201The result of package build functions is @dfn{cached} in the file
e531ac2a
LC
202system, in a special directory called @dfn{the store} (@pxref{The
203Store}). Each package is installed in a directory of its own, in the
834129e0 204store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
205a hash of all the inputs used to build that package; thus, changing an
206input yields a different directory name.
207
208This approach is the foundation of Guix's salient features: support for
4bfc4ea3 209transactional package upgrade and rollback, per-user installation, and
eeaf4427 210garbage collection of packages (@pxref{Features}).
568717fd 211
4bfc4ea3 212Guix has a command-line interface, which allows users to build, install,
568717fd 213upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 214
3ca2731c
LC
215@cindex Guix System Distribution
216@cindex GSD
a1ba8475 217Last but not least, Guix is used to build a distribution of the GNU
3ca2731c
LC
218system, with many GNU and non-GNU free software packages. The Guix
219System Distribution, or GNU@tie{}GSD, takes advantage of the core
220properties of Guix at the system level. With GNU@tie{}GSD, users
221@emph{declare} all aspects of the operating system configuration, and
222Guix takes care of instantiating that configuration in a reproducible,
223stateless fashion. @xref{GNU Distribution}.
a1ba8475 224
bd5e766b
LC
225@c *********************************************************************
226@node Installation
227@chapter Installation
228
48febeb8
LC
229GNU Guix is available for download from its website at
230@url{http://www.gnu.org/software/guix/}. This section describes the
231software requirements of Guix, as well as how to install it and get
232ready to use it.
bd5e766b 233
5af6de3e
LC
234Note that this section is concerned with the installation of the package
235manager, which can be done on top of a running GNU/Linux system. If,
236instead, you want to install the complete GNU operating system,
6621cdb6 237@pxref{System Installation}.
5af6de3e 238
bd5e766b 239@menu
09722b11 240* Binary Installation:: Getting Guix running in no time!
bd5e766b 241* Requirements:: Software needed to build and run Guix.
ec0339cd 242* Running the Test Suite:: Testing Guix.
bd5e766b
LC
243* Setting Up the Daemon:: Preparing the build daemon's environment.
244* Invoking guix-daemon:: Running the build daemon.
245@end menu
246
09722b11
LC
247@node Binary Installation
248@section Binary Installation
249
250This section describes how to install Guix on an arbitrary system from a
251self-contained tarball providing binaries for Guix and for all its
252dependencies. This is often quicker than installing from source, which
253is described in the next sections. The only requirement is to have
254GNU@tie{}tar and Xz.
255
256Installing goes along these lines:
257
258@enumerate
259@item
260Download the binary tarball from
261@code{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz}@footnote{As
262usual, make sure to download the associated @file{.sig} file and to
263verify the authenticity of the tarball against it!}, where @var{system}
264is @code{x86_64-linux} for an @code{x86_64} machine already running the
265kernel Linux, and so on.
266
267@item
268As @code{root}, run:
269
270@example
271# cd /
272# tar xf guix-binary-@value{VERSION}.@var{system}.tar.xz
273@end example
274
275This creates @file{/gnu/store} (@pxref{The Store}), @file{/var/guix},
276and @file{/root/.guix-profile}. @file{/root/.guix-profile} is a
277ready-to-use profile for @code{root} where Guix is installed.
278
279@item
280Setup the daemon as explained below (@pxref{Setting Up the Daemon}), and
281run it:
282
283@example
284# /root/.guix-profile/bin/guix-daemon --build-users-group=guix-builder
285@end example
286
287@item
288Make the @command{guix} command available to other users on the machine,
289for instance with:
290
291@example
292# mkdir -p /usr/local/bin
293# cd /usr/local/bin
294# ln -s /root/.guix-profile/bin/guix
295@end example
296@end enumerate
297
298And that's it!
299
300There are two things to note. First, don't unpack the tarball on a
301working Guix system since that would overwrite its own essential files.
302Second, the @code{guix} package must remain available in @code{root}'s
303profile, or it would become subject to garbage collection---in which
304case you would find yourself badly handicapped by the lack of the
305@command{guix} command.
306
307The tarball in question can be (re)produced simply by running the
308following command in the Guix source tree:
309
310@example
311make guix-binary.@var{system}.tar.xz
312@end example
313
314
bd5e766b
LC
315@node Requirements
316@section Requirements
317
09722b11
LC
318This section lists requirements when building Guix from source. The
319build procedure for Guix is the same as for other GNU software, and is
320not covered here. Please see the files @file{README} and @file{INSTALL}
321in the Guix source tree for additional details.
322
bd5e766b
LC
323GNU Guix depends on the following packages:
324
325@itemize
4a328f73 326@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.5 or later;
288dca55 327@item @url{http://gnupg.org/, GNU libgcrypt};
8a96bd4b
ID
328@end itemize
329
330The following dependencies are optional:
331
332@itemize
288dca55 333@item
8a96bd4b 334Installing
288dca55 335@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
2f7d2d91
LC
336allow you to use the @command{guix import pypi} command (@pxref{Invoking
337guix import}). It is of
288dca55 338interest primarily for developers and not for casual users.
8a96bd4b
ID
339@item
340Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
341allow you to access @code{https} URLs with the @command{guix download}
d45dc6da
EB
342command (@pxref{Invoking guix download}), the @command{guix import pypi}
343command, and the @command{guix import cpan} command. This is primarily
344of interest to developers. @xref{Guile Preparations, how to install the
345GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}.
bd5e766b
LC
346@end itemize
347
348Unless @code{--disable-daemon} was passed to @command{configure}, the
349following packages are also needed:
350
351@itemize
352@item @url{http://sqlite.org, SQLite 3}
353@item @url{http://www.bzip.org, libbz2}
354@item @url{http://gcc.gnu.org, GCC's g++}
355@end itemize
356
4bfc4ea3
NK
357When a working installation of @url{http://nixos.org/nix/, the Nix package
358manager} is available, you
bd5e766b 359can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 360Nix replaces the three dependencies above.
bd5e766b 361
b22a12fd
LC
362Guix is compatible with Nix, so it is possible to share the same store
363between both. To do so, you must pass @command{configure} not only the
364same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
365@code{--localstatedir} value. The latter is essential because it
366specifies where the database that stores metadata about the store is
834129e0 367located, among other things. The default values for Nix are
b22a12fd 368@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
369Note that @code{--disable-daemon} is not required if
370your goal is to share the store with Nix.
b22a12fd 371
ec0339cd
LC
372@node Running the Test Suite
373@section Running the Test Suite
374
375After a successful @command{configure} and @code{make} run, it is a good
376idea to run the test suite. It can help catch issues with the setup or
377environment, or bugs in Guix itself---and really, reporting test
378failures is a good way to help improve the software. To run the test
379suite, type:
380
381@example
382make check
383@end example
384
385Test cases can run in parallel: you can use the @code{-j} option of
386GNU@tie{}make to speed things up. The first run may take a few minutes
387on a recent machine; subsequent runs will be faster because the store
388that is created for test purposes will already have various things in
389cache.
390
391Upon failure, please email @email{bug-guix@@gnu.org} and attach the
392@file{test-suite.log} file. When @file{tests/@var{something}.scm}
393fails, please also attach the @file{@var{something}.log} file available
394in the top-level build directory. Please specify the Guix version being
395used as well as version numbers of the dependencies
396(@pxref{Requirements}) in your message.
397
bd5e766b
LC
398@node Setting Up the Daemon
399@section Setting Up the Daemon
400
401@cindex daemon
402Operations such as building a package or running the garbage collector
49e6291a 403are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
404behalf of clients. Only the daemon may access the store and its
405associated database. Thus, any operation that manipulates the store
406goes through the daemon. For instance, command-line tools such as
e49951eb 407@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
408daemon (@i{via} remote procedure calls) to instruct it what to do.
409
49e6291a 410The following sections explain how to prepare the build daemon's
225dafde
LC
411environment. Also @ref{Substitutes}, for information on how to allow
412the daemon to download pre-built binaries.
49e6291a
LC
413
414@menu
415* Build Environment Setup:: Preparing the isolated build environment.
416* Daemon Offload Setup:: Offloading builds to remote machines.
417@end menu
418
419@node Build Environment Setup
420@subsection Build Environment Setup
421
bd5e766b
LC
422In a standard multi-user setup, Guix and its daemon---the
423@command{guix-daemon} program---are installed by the system
834129e0 424administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
425@command{guix-daemon} runs as @code{root}. Unprivileged users may use
426Guix tools to build packages or otherwise access the store, and the
427daemon will do it on their behalf, ensuring that the store is kept in a
428consistent state, and allowing built packages to be shared among users.
429
430@cindex build users
431When @command{guix-daemon} runs as @code{root}, you may not want package
432build processes themselves to run as @code{root} too, for obvious
433security reasons. To avoid that, a special pool of @dfn{build users}
434should be created for use by build processes started by the daemon.
435These build users need not have a shell and a home directory: they will
436just be used when the daemon drops @code{root} privileges in build
437processes. Having several such users allows the daemon to launch
438distinct build processes under separate UIDs, which guarantees that they
439do not interfere with each other---an essential feature since builds are
440regarded as pure functions (@pxref{Introduction}).
441
442On a GNU/Linux system, a build user pool may be created like this (using
443Bash syntax and the @code{shadow} commands):
444
091196b3
LC
445@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
446@c for why `-G' is needed.
bd5e766b
LC
447@example
448# groupadd guix-builder
449# for i in `seq 1 10`;
450 do
091196b3
LC
451 useradd -g guix-builder -G guix-builder \
452 -d /var/empty -s `which nologin` \
4d1a2b50
LC
453 -c "Guix build user $i" --system \
454 guix-builder$i;
bd5e766b
LC
455 done
456@end example
457
458@noindent
459The @code{guix-daemon} program may then be run as @code{root} with:
460
461@example
462# guix-daemon --build-users-group=guix-builder
463@end example
464
e900c503 465@cindex chroot
b095792f
LC
466@noindent
467This way, the daemon starts build processes in a chroot, under one of
468the @code{guix-builder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
469environment contains nothing but:
470
471@c Keep this list in sync with libstore/build.cc! -----------------------
472@itemize
473@item
4743a4da
LC
474a minimal @code{/dev} directory, created mostly independently from the
475host @code{/dev}@footnote{``Mostly'', because while the set of files
476that appear in the chroot's @code{/dev} is fixed, most of these files
477can only be created if the host has them.};
478
479@item
480the @code{/proc} directory; it only shows the container's processes
481since a separate PID name space is used;
6dc99317
LC
482
483@item
484@file{/etc/passwd} with an entry for the current user and an entry for
485user @file{nobody};
486
487@item
488@file{/etc/group} with an entry for the user's group;
489
490@item
491@file{/etc/hosts} with an entry that maps @code{localhost} to
492@code{127.0.0.1};
493
494@item
495a writable @file{/tmp} directory.
496@end itemize
b095792f 497
d43eb499 498If you are installing Guix as an unprivileged user, it is still
bd5e766b
LC
499possible to run @command{guix-daemon}. However, build processes will
500not be isolated from one another, and not from the rest of the system.
501Thus, build processes may interfere with each other, and may access
502programs, libraries, and other files available on the system---making it
503much harder to view them as @emph{pure} functions.
504
49e6291a
LC
505
506@node Daemon Offload Setup
507@subsection Using the Offload Facility
508
509@cindex offloading
4ec2e92d
LC
510@cindex build hook
511When desired, the build daemon can @dfn{offload}
512derivation builds to other machines
49e6291a
LC
513running Guix, using the @code{offload} @dfn{build hook}. When that
514feature is enabled, a list of user-specified build machines is read from
515@file{/etc/guix/machines.scm}; anytime a build is requested, for
516instance via @code{guix build}, the daemon attempts to offload it to one
517of the machines that satisfies the derivation's constraints, in
518particular its system type---e.g., @file{x86_64-linux}. Missing
519prerequisites for the build are copied over SSH to the target machine,
520which then proceeds with the build; upon success the output(s) of the
521build are copied back to the initial machine.
522
4ec2e92d 523The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
524
525@example
526(list (build-machine
527 (name "eightysix.example.org")
528 (system "x86_64-linux")
529 (user "bob")
530 (speed 2.)) ; incredibly fast!
531
532 (build-machine
533 (name "meeps.example.org")
534 (system "mips64el-linux")
535 (user "alice")
536 (private-key
537 (string-append (getenv "HOME")
538 "/.ssh/id-rsa-for-guix"))))
539@end example
540
541@noindent
542In the example above we specify a list of two build machines, one for
543the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
544architecture.
545
546In fact, this file is---not surprisingly!---a Scheme file that is
547evaluated when the @code{offload} hook is started. Its return value
548must be a list of @code{build-machine} objects. While this example
549shows a fixed list of build machines, one could imagine, say, using
550DNS-SD to return a list of potential build machines discovered in the
551local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
552Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
553detailed below.
4ec2e92d 554
c678a4ee
LC
555@deftp {Data Type} build-machine
556This data type represents build machines the daemon may offload builds
557to. The important fields are:
49e6291a
LC
558
559@table @code
560
561@item name
562The remote machine's host name.
563
564@item system
c678a4ee 565The remote machine's system type---e.g., @code{"x86_64-linux"}.
49e6291a
LC
566
567@item user
568The user account to use when connecting to the remote machine over SSH.
569Note that the SSH key pair must @emph{not} be passphrase-protected, to
570allow non-interactive logins.
571
572@end table
573
4ec2e92d 574A number of optional fields may be specified:
49e6291a
LC
575
576@table @code
577
cecd72d5
LC
578@item port
579Port number of the machine's SSH server (default: 22).
580
49e6291a
LC
581@item private-key
582The SSH private key file to use when connecting to the machine.
583
584@item parallel-builds
585The number of builds that may run in parallel on the machine (1 by
586default.)
587
588@item speed
589A ``relative speed factor''. The offload scheduler will tend to prefer
590machines with a higher speed factor.
591
592@item features
593A list of strings denoting specific features supported by the machine.
594An example is @code{"kvm"} for machines that have the KVM Linux modules
595and corresponding hardware support. Derivations can request features by
596name, and they will be scheduled on matching build machines.
597
598@end table
c678a4ee 599@end deftp
49e6291a
LC
600
601The @code{guix} command must be in the search path on the build
602machines, since offloading works by invoking the @code{guix archive} and
603@code{guix build} commands.
604
605There's one last thing to do once @file{machines.scm} is in place. As
606explained above, when offloading, files are transferred back and forth
607between the machine stores. For this to work, you need to generate a
608key pair to allow the daemon to export signed archives of files from the
609store (@pxref{Invoking guix archive}):
610
611@example
612# guix archive --generate-key
613@end example
614
615@noindent
616Thus, when receiving files, a machine's build daemon can make sure they
617are genuine, have not been tampered with, and that they are signed by an
618authorized key.
619
620
bd5e766b
LC
621@node Invoking guix-daemon
622@section Invoking @command{guix-daemon}
623
624The @command{guix-daemon} program implements all the functionality to
625access the store. This includes launching build processes, running the
626garbage collector, querying the availability of a build result, etc. It
627is normally run as @code{root} like this:
628
629@example
630# guix-daemon --build-users-group=guix-builder
631@end example
632
633@noindent
081145cf 634For details on how to set it up, @pxref{Setting Up the Daemon}.
bd5e766b 635
e900c503
LC
636@cindex chroot
637@cindex container, build environment
638@cindex build environment
639@cindex reproducible builds
bd5e766b
LC
640By default, @command{guix-daemon} launches build processes under
641different UIDs, taken from the build group specified with
642@code{--build-users-group}. In addition, each build process is run in a
643chroot environment that only contains the subset of the store that the
644build process depends on, as specified by its derivation
645(@pxref{Programming Interface, derivation}), plus a set of specific
646system directories. By default, the latter contains @file{/dev} and
e900c503
LC
647@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
648@dfn{container}: in addition to having its own file system tree, it has
649a separate mount name space, its own PID name space, network name space,
650etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b 651
cbc538fe
LC
652When the daemon performs a build on behalf of the user, it creates a
653build directory under @file{/tmp} or under the directory specified by
654its @code{TMPDIR} environment variable; this directory is shared with
655the container for the duration of the build. Be aware that using a
656directory other than @file{/tmp} can affect build results---for example,
657with a longer directory name, a build process that uses Unix-domain
658sockets might hit the name length limitation for @code{sun_path}, which
659it would otherwise not hit.
660
661The build directory is automatically deleted upon completion, unless the
662build failed and the client specified @option{--keep-failed}
663(@pxref{Invoking guix build, @option{--keep-failed}}).
664
bd5e766b
LC
665The following command-line options are supported:
666
667@table @code
668@item --build-users-group=@var{group}
669Take users from @var{group} to run build processes (@pxref{Setting Up
670the Daemon, build users}).
671
6858f9d1 672@item --no-substitutes
b5385b52 673@cindex substitutes
6858f9d1 674Do not use substitutes for build products. That is, always build things
c4202d60
LC
675locally instead of allowing downloads of pre-built binaries
676(@pxref{Substitutes}).
6858f9d1 677
b5385b52
LC
678By default substitutes are used, unless the client---such as the
679@command{guix package} command---is explicitly invoked with
680@code{--no-substitutes}.
681
682When the daemon runs with @code{--no-substitutes}, clients can still
683explicitly enable substitution @i{via} the @code{set-build-options}
684remote procedure call (@pxref{The Store}).
685
9176607e
LC
686@item --substitute-urls=@var{urls}
687Consider @var{urls} the default whitespace-separated list of substitute
688source URLs. When this option is omitted, @code{http://hydra.gnu.org}
689is used.
690
691This means that substitutes may be downloaded from @var{urls}, as long
692as they are signed by a trusted signature (@pxref{Substitutes}).
693
4ec2e92d
LC
694@cindex build hook
695@item --no-build-hook
696Do not use the @dfn{build hook}.
697
698The build hook is a helper program that the daemon can start and to
699which it submits build requests. This mechanism is used to offload
700builds to other machines (@pxref{Daemon Offload Setup}).
701
bd5e766b
LC
702@item --cache-failures
703Cache build failures. By default, only successful builds are cached.
704
705@item --cores=@var{n}
706@itemx -c @var{n}
707Use @var{n} CPU cores to build each derivation; @code{0} means as many
708as available.
709
6efc160e 710The default value is @code{0}, but it may be overridden by clients, such
e49951eb
MW
711as the @code{--cores} option of @command{guix build} (@pxref{Invoking
712guix build}).
bd5e766b
LC
713
714The effect is to define the @code{NIX_BUILD_CORES} environment variable
715in the build process, which can then use it to exploit internal
716parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
717
718@item --max-jobs=@var{n}
719@itemx -M @var{n}
720Allow at most @var{n} build jobs in parallel. The default value is
f6526eb3
LC
721@code{1}. Setting it to @code{0} means that no builds will be performed
722locally; instead, the daemon will offload builds (@pxref{Daemon Offload
723Setup}), or simply fail.
bd5e766b
LC
724
725@item --debug
726Produce debugging output.
727
728This is useful to debug daemon start-up issues, but then it may be
729overridden by clients, for example the @code{--verbosity} option of
e49951eb 730@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
731
732@item --chroot-directory=@var{dir}
733Add @var{dir} to the build chroot.
734
735Doing this may change the result of build processes---for instance if
736they use optional dependencies found in @var{dir} when it is available,
737and not otherwise. For that reason, it is not recommended to do so.
738Instead, make sure that each derivation declares all the inputs that it
739needs.
740
741@item --disable-chroot
742Disable chroot builds.
743
744Using this option is not recommended since, again, it would allow build
745processes to gain access to undeclared dependencies.
746
747@item --disable-log-compression
748Disable compression of the build logs.
749
1da983b9
LC
750Unless @code{--lose-logs} is used, all the build logs are kept in the
751@var{localstatedir}. To save space, the daemon automatically compresses
752them with bzip2 by default. This option disables that.
753
ab3893d7
LC
754@item --disable-deduplication
755@cindex deduplication
bd5e766b
LC
756Disable automatic file ``deduplication'' in the store.
757
1da983b9 758By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
759if a newly added file is identical to another one found in the store,
760the daemon makes the new file a hard link to the other file. This can
761noticeably reduce disk usage, at the expense of slightly increasde
762input/output load at the end of a build process. This option disables
763this optimization.
1da983b9 764
6e37066e
LC
765@item --gc-keep-outputs[=yes|no]
766Tell whether the garbage collector (GC) must keep outputs of live
767derivations.
768
769When set to ``yes'', the GC will keep the outputs of any live derivation
770available in the store---the @code{.drv} files. The default is ``no'',
771meaning that derivation outputs are kept only if they are GC roots.
772
773@item --gc-keep-derivations[=yes|no]
774Tell whether the garbage collector (GC) must keep derivations
775corresponding to live outputs.
776
777When set to ``yes'', as is the case by default, the GC keeps
778derivations---i.e., @code{.drv} files---as long as at least one of their
779outputs is live. This allows users to keep track of the origins of
780items in their store. Setting it to ``no'' saves a bit of disk space.
781
782Note that when both @code{--gc-keep-derivations} and
783@code{--gc-keep-outputs} are used, the effect is to keep all the build
784prerequisites (the sources, compiler, libraries, and other build-time
785tools) of live objects in the store, regardless of whether these
786prerequisites are live. This is convenient for developers since it
787saves rebuilds or downloads.
788
bd5e766b
LC
789@item --impersonate-linux-2.6
790On Linux-based systems, impersonate Linux 2.6. This means that the
791kernel's @code{uname} system call will report 2.6 as the release number.
792
793This might be helpful to build programs that (usually wrongfully) depend
794on the kernel version number.
795
796@item --lose-logs
797Do not keep build logs. By default they are kept under
ce33631f 798@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
799
800@item --system=@var{system}
801Assume @var{system} as the current system type. By default it is the
802architecture/kernel pair found at configure time, such as
803@code{x86_64-linux}.
b8d2aa26
LC
804
805@item --listen=@var{socket}
806Listen for connections on @var{socket}, the file name of a Unix-domain
807socket. The default socket is
808@file{@var{localstatedir}/daemon-socket/socket}. This option is only
809useful in exceptional circumstances, such as if you need to run several
810daemons on the same machine.
bd5e766b
LC
811@end table
812
813
eeaf4427
LC
814@c *********************************************************************
815@node Package Management
816@chapter Package Management
817
f8348b91 818The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
819remove software packages, without having to know about their build
820procedure or dependencies. Guix also goes beyond this obvious set of
821features.
822
823This chapter describes the main features of Guix, as well as the package
c1941588
LC
824management tools it provides. Two user interfaces are provided for
825routine package management tasks: a command-line interface
826(@pxref{Invoking guix package, @code{guix package}}), and a visual user
827interface in Emacs (@pxref{Emacs Interface}).
eeaf4427
LC
828
829@menu
830* Features:: How Guix will make your life brighter.
e49951eb 831* Invoking guix package:: Package installation, removal, etc.
457f60fa 832* Emacs Interface:: Package management from Emacs.
c4202d60 833* Substitutes:: Downloading pre-built binaries.
760c60d6 834* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 835* Invoking guix gc:: Running the garbage collector.
f651b477 836* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 837* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
838@end menu
839
840@node Features
841@section Features
842
843When using Guix, each package ends up in the @dfn{package store}, in its
844own directory---something that resembles
9a130e19
AK
845@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
846(note that Guix comes with an Emacs extension to shorten those file
081145cf 847names, @pxref{Emacs Prettify}.)
eeaf4427
LC
848
849Instead of referring to these directories, users have their own
850@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
851use. These profiles are stored within each user's home directory, at
852@code{$HOME/.guix-profile}.
eeaf4427 853
821b0015 854For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 855@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 856@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
857@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
858simply continues to point to
834129e0 859@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 860coexist on the same system without any interference.
eeaf4427 861
e49951eb
MW
862The @command{guix package} command is the central tool to manage
863packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 864profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
865
866The command provides the obvious install, remove, and upgrade
867operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 868the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 869@command{guix package} process is terminated during the transaction,
eeaf4427
LC
870or if a power outage occurs during the transaction, then the user's
871profile remains in its previous state, and remains usable.
872
873In addition, any package transaction may be @emph{rolled back}. So, if,
874for example, an upgrade installs a new version of a package that turns
875out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
876of their profile, which was known to work well. Similarly, the global
877system configuration is subject to transactional upgrades and roll-back
878(@pxref{Using the Configuration System}).
eeaf4427
LC
879
880All those packages in the package store may be @emph{garbage-collected}.
881Guix can determine which packages are still referenced by the user
fe8ff028 882profiles, and remove those that are provably no longer referenced
e49951eb 883(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
884generations of their profile so that the packages they refer to can be
885collected.
eeaf4427 886
e900c503
LC
887@cindex reproducibility
888@cindex reproducible builds
eeaf4427
LC
889Finally, Guix takes a @dfn{purely functional} approach to package
890management, as described in the introduction (@pxref{Introduction}).
834129e0 891Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
892inputs that were used to build that package---compiler, libraries, build
893scripts, etc. This direct correspondence allows users to make sure a
894given package installation matches the current state of their
e900c503
LC
895distribution. It also helps maximize @dfn{build reproducibility}:
896thanks to the isolated build environments that are used, a given build
897is likely to yield bit-identical files when performed on different
898machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 899
c4202d60 900@cindex substitutes
eeaf4427 901This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 902deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 903available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
904downloads it and unpacks it;
905otherwise, it builds the package from source, locally
906(@pxref{Substitutes}).
eeaf4427 907
f5fd4fd2
LC
908Control over the build environment is a feature that is also useful for
909developers. The @command{guix environment} command allows developers of
910a package to quickly set up the right development environment for their
911package, without having to manually install the package's dependencies
912in their profile (@pxref{Invoking guix environment}).
913
e49951eb
MW
914@node Invoking guix package
915@section Invoking @command{guix package}
eeaf4427 916
e49951eb 917The @command{guix package} command is the tool that allows users to
eeaf4427
LC
918install, upgrade, and remove packages, as well as rolling back to
919previous configurations. It operates only on the user's own profile,
920and works with normal user privileges (@pxref{Features}). Its syntax
921is:
922
923@example
e49951eb 924guix package @var{options}
eeaf4427
LC
925@end example
926
ba55b1cb 927Primarily, @var{options} specifies the operations to be performed during
eeaf4427
LC
928the transaction. Upon completion, a new profile is created, but
929previous generations of the profile remain available, should the user
930want to roll back.
931
6447738c
MW
932For example, to remove @code{lua} and install @code{guile} and
933@code{guile-cairo} in a single transaction:
934
935@example
936guix package -r lua -i guile guile-cairo
937@end example
938
b9e5c0a9 939For each user, a symlink to the user's default profile is automatically
0ec1af59 940created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
941current generation of the user's default profile. Thus, users can add
942@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
943variable, and so on.
944
4379c35b
LC
945In a multi-user setup, user profiles are stored in a place registered as
946a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points
947to (@pxref{Invoking guix gc}). That directory is normally
0ec1af59
LC
948@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
949@var{localstatedir} is the value passed to @code{configure} as
4379c35b
LC
950@code{--localstatedir}, and @var{user} is the user name. The
951@file{per-user} directory is created when @command{guix-daemon} is
952started, and the @var{user} sub-directory is created by @command{guix
953package}.
0ec1af59
LC
954
955The @var{options} can be among the following:
956
eeaf4427
LC
957@table @code
958
6447738c
MW
959@item --install=@var{package} @dots{}
960@itemx -i @var{package} @dots{}
961Install the specified @var{package}s.
eeaf4427 962
6447738c 963Each @var{package} may specify either a simple package name, such as
eeaf4427 964@code{guile}, or a package name followed by a hyphen and version number,
dc5669cd
MW
965such as @code{guile-1.8.8}. If no version number is specified, the
966newest available version will be selected. In addition, @var{package}
967may contain a colon, followed by the name of one of the outputs of the
6e721c4d 968package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
e7f34eb0
LC
969(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
970name (and optionally version) are searched for among the GNU
971distribution modules (@pxref{Package Modules}).
eeaf4427 972
461572cc
LC
973@cindex propagated inputs
974Sometimes packages have @dfn{propagated inputs}: these are dependencies
975that automatically get installed along with the required package.
976
977An example is the GNU MPC library: its C header files refer to those of
978the GNU MPFR library, which in turn refer to those of the GMP library.
979Thus, when installing MPC, the MPFR and GMP libraries also get installed
980in the profile; removing MPC also removes MPFR and GMP---unless they had
981also been explicitly installed independently.
982
ba7ea5ce 983Besides, packages sometimes rely on the definition of environment
5924080d 984variables for their search paths (see explanation of
ba7ea5ce 985@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
986environment variable definitions are reported here.
987
ef010c0f 988@c XXX: keep me up-to-date
5924080d 989Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
990availability of a newer upstream version. In the future, it may provide
991the option of installing directly from the upstream version, even if
992that version is not yet in the distribution.
993
5d4b411f
LC
994@item --install-from-expression=@var{exp}
995@itemx -e @var{exp}
996Install the package @var{exp} evaluates to.
997
998@var{exp} must be a Scheme expression that evaluates to a
999@code{<package>} object. This option is notably useful to disambiguate
1000between same-named variants of a package, with expressions such as
1001@code{(@@ (gnu packages base) guile-final)}.
1002
1003Note that this option installs the first output of the specified
1004package, which may be insufficient when needing a specific output of a
1005multiple-output package.
1006
6447738c
MW
1007@item --remove=@var{package} @dots{}
1008@itemx -r @var{package} @dots{}
1009Remove the specified @var{package}s.
eeaf4427 1010
6447738c 1011As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
1012and/or output name in addition to the package name. For instance,
1013@code{-r glibc:debug} would remove the @code{debug} output of
1014@code{glibc}.
1015
6447738c
MW
1016@item --upgrade[=@var{regexp} @dots{}]
1017@itemx -u [@var{regexp} @dots{}]
1018Upgrade all the installed packages. If one or more @var{regexp}s are
1019specified, upgrade only installed packages whose name matches a
d5f01e48 1020@var{regexp}. Also see the @code{--do-not-upgrade} option below.
eeaf4427 1021
f651b477
LC
1022Note that this upgrades package to the latest version of packages found
1023in the distribution currently installed. To update your distribution,
1024you should regularly run @command{guix pull} (@pxref{Invoking guix
1025pull}).
1026
d5f01e48
MW
1027@item --do-not-upgrade[=@var{regexp} @dots{}]
1028When used together with the @code{--upgrade} option, do @emph{not}
1029upgrade any packages whose name matches a @var{regexp}. For example, to
1030upgrade all packages in the current profile except those containing the
1031substring ``emacs'':
1032
1033@example
1034$ guix package --upgrade . --do-not-upgrade emacs
1035@end example
1036
24e262f0
LC
1037@item --roll-back
1038Roll back to the previous @dfn{generation} of the profile---i.e., undo
1039the last transaction.
1040
1041When combined with options such as @code{--install}, roll back occurs
1042before any other actions.
1043
d9307267 1044When rolling back from the first generation that actually contains
4b2bc804
NK
1045installed packages, the profile is made to point to the @dfn{zeroth
1046generation}, which contains no files apart from its own meta-data.
d9307267 1047
82fe08ed
LC
1048Installing, removing, or upgrading packages from a generation that has
1049been rolled back to overwrites previous future generations. Thus, the
1050history of a profile's generations is always linear.
1051
b3bb82f1
AK
1052@item --switch-generation=@var{pattern}
1053@itemx -S @var{pattern}
1054Switch to a particular generation defined by @var{pattern}.
1055
1056@var{pattern} may be either a generation number or a number prefixed
1057with ``+'' or ``-''. The latter means: move forward/backward by a
1058specified number of generations. For example, if you want to return to
1059the latest generation after @code{--roll-back}, use
1060@code{--switch-generation=+1}.
1061
1062The difference between @code{--roll-back} and
1063@code{--switch-generation=-1} is that @code{--switch-generation} will
1064not make a zeroth generation, so if a specified generation does not
1065exist, the current generation will not be changed.
1066
5924080d
LC
1067@item --search-paths
1068@cindex search paths
1069Report environment variable definitions, in Bash syntax, that may be
1070needed in order to use the set of installed packages. These environment
1071variables are used to specify @dfn{search paths} for files used by some
1072of the installed packages.
1073
1074For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
1075environment variables to be defined so it can look for headers and
1076libraries in the user's profile (@pxref{Environment Variables,,, gcc,
1077Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
1078library are installed in the profile, then @code{--search-paths} will
1079suggest setting these variables to @code{@var{profile}/include} and
1080@code{@var{profile}/lib}, respectively.
1081
eeaf4427
LC
1082@item --profile=@var{profile}
1083@itemx -p @var{profile}
1084Use @var{profile} instead of the user's default profile.
1085
70915c1a
LC
1086@item --verbose
1087Produce verbose output. In particular, emit the environment's build log
1088on the standard error port.
1089
eeaf4427
LC
1090@item --bootstrap
1091Use the bootstrap Guile to build the profile. This option is only
1092useful to distribution developers.
1093
1094@end table
1095
e49951eb 1096In addition to these actions @command{guix package} supports the
733b4130
LC
1097following options to query the current state of a profile, or the
1098availability of packages:
eeaf4427 1099
733b4130
LC
1100@table @option
1101
acc08466
NK
1102@item --search=@var{regexp}
1103@itemx -s @var{regexp}
1104List the available packages whose synopsis or description matches
299112d3
LC
1105@var{regexp}. Print all the meta-data of matching packages in
1106@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
1107GNU recutils manual}).
acc08466 1108
299112d3
LC
1109This allows specific fields to be extracted using the @command{recsel}
1110command, for instance:
1111
1112@example
e49951eb 1113$ guix package -s malloc | recsel -p name,version
299112d3
LC
1114name: glibc
1115version: 2.17
1116
1117name: libgc
1118version: 7.2alpha6
1119@end example
acc08466 1120
a12d92f5
LC
1121Similarly, to show the name of all the packages available under the
1122terms of the GNU@tie{}LGPL version 3:
1123
1124@example
1125$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
1126name: elfutils
1127
1128name: gmp
1129@dots{}
1130@end example
1131
2aa6efb0
CR
1132@item --show=@var{package}
1133Show details about @var{package}, taken from the list of available packages, in
1134@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
1135recutils manual}).
1136
1137@example
1138$ guix package --show=python | recsel -p name,version
1139name: python
1140version: 2.7.6
1141
1142name: python
1143version: 3.3.5
1144@end example
1145
1146You may also specify the full name of a package to only get details about a
1147specific version of it:
1148@example
1149$ guix package --show=python-3.3.5 | recsel -p name,version
1150name: python
1151version: 3.3.5
1152@end example
1153
1154
1155
733b4130
LC
1156@item --list-installed[=@var{regexp}]
1157@itemx -I [@var{regexp}]
bd9bde1c
LC
1158List the currently installed packages in the specified profile, with the
1159most recently installed packages shown last. When @var{regexp} is
1160specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
1161
1162For each installed package, print the following items, separated by
1163tabs: the package name, its version string, the part of the package that
1164is installed (for instance, @code{out} for the default output,
1165@code{include} for its headers, etc.), and the path of this package in
1166the store.
1167
64fc89b6
LC
1168@item --list-available[=@var{regexp}]
1169@itemx -A [@var{regexp}]
a1ba8475
LC
1170List packages currently available in the software distribution
1171(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
1172installed packages whose name matches @var{regexp}.
64fc89b6
LC
1173
1174For each package, print the following items separated by tabs: its name,
6e721c4d
LC
1175its version string, the parts of the package (@pxref{Packages with
1176Multiple Outputs}), and the source location of its definition.
64fc89b6 1177
f566d765
LC
1178@item --list-generations[=@var{pattern}]
1179@itemx -l [@var{pattern}]
1180Return a list of generations along with their creation dates; for each
1181generation, show the installed packages, with the most recently
4b2bc804
NK
1182installed packages shown last. Note that the zeroth generation is never
1183shown.
f566d765
LC
1184
1185For each installed package, print the following items, separated by
1186tabs: the name of a package, its version string, the part of the package
1187that is installed (@pxref{Packages with Multiple Outputs}), and the
1188location of this package in the store.
1189
1190When @var{pattern} is used, the command returns only matching
1191generations. Valid patterns include:
1192
1193@itemize
1194@item @emph{Integers and comma-separated integers}. Both patterns denote
1195generation numbers. For instance, @code{--list-generations=1} returns
1196the first one.
1197
1198And @code{--list-generations=1,8,2} outputs three generations in the
1199specified order. Neither spaces nor trailing commas are allowed.
1200
1201@item @emph{Ranges}. @code{--list-generations=2..9} prints the
1202specified generations and everything in between. Note that the start of
1203a range must be lesser than its end.
1204
1205It is also possible to omit the endpoint. For example,
1206@code{--list-generations=2..}, returns all generations starting from the
1207second one.
1208
1209@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
1210or months by passing an integer along with the first letter of the
d7ddb257
LC
1211duration. For example, @code{--list-generations=20d} lists generations
1212that are up to 20 days old.
f566d765
LC
1213@end itemize
1214
b7884ca3
NK
1215@item --delete-generations[=@var{pattern}]
1216@itemx -d [@var{pattern}]
d7ddb257
LC
1217When @var{pattern} is omitted, delete all generations except the current
1218one.
b7884ca3
NK
1219
1220This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
1221When @var{pattern} is specified, delete the matching generations. When
1222@var{pattern} specifies a duration, generations @emph{older} than the
1223specified duration match. For instance, @code{--delete-generations=1m}
1224deletes generations that are more than one month old.
1225
391bdd8f
LC
1226If the current generation matches, it is @emph{not} deleted. Also, the
1227zeroth generation is never deleted.
b7884ca3 1228
1bb9900a
LC
1229Note that deleting generations prevents roll-back to them.
1230Consequently, this command must be used with care.
1231
733b4130 1232@end table
eeaf4427 1233
70ee5642
LC
1234Finally, since @command{guix package} may actually start build
1235processes, it supports all the common build options that @command{guix
1236build} supports (@pxref{Invoking guix build, common build options}).
1237
457f60fa
AK
1238@include emacs.texi
1239
c4202d60
LC
1240@node Substitutes
1241@section Substitutes
1242
1243@cindex substitutes
1244@cindex pre-built binaries
1245Guix supports transparent source/binary deployment, which means that it
1246can either build things locally, or download pre-built items from a
1247server. We call these pre-built items @dfn{substitutes}---they are
1248substitutes for local build results. In many cases, downloading a
1249substitute is much faster than building things locally.
1250
1251Substitutes can be anything resulting from a derivation build
1252(@pxref{Derivations}). Of course, in the common case, they are
1253pre-built package binaries, but source tarballs, for instance, which
1254also result from derivation builds, can be available as substitutes.
1255
1256The @code{hydra.gnu.org} server is a front-end to a build farm that
1257builds packages from the GNU distribution continuously for some
9176607e
LC
1258architectures, and makes them available as substitutes. This is the
1259default source of substitutes; it can be overridden by passing
1260@command{guix-daemon} the @code{--substitute-urls} option
1261(@pxref{Invoking guix-daemon}).
c4202d60
LC
1262
1263@cindex security
1264@cindex digital signatures
1265To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1266must add its public key to the access control list (ACL) of archive
1267imports, using the @command{guix archive} command (@pxref{Invoking guix
1268archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1269be compromised and to serve genuine substitutes.
1270
1271This public key is installed along with Guix, in
1272@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1273the installation prefix of Guix. If you installed Guix from source,
1274make sure you checked the GPG signature of
1275@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1276Then, you can run something like this:
1277
1278@example
1279# guix archive --authorize < hydra.gnu.org.pub
1280@end example
1281
1282Once this is in place, the output of a command like @code{guix build}
1283should change from something like:
1284
1285@example
1286$ guix build emacs --dry-run
1287The following derivations would be built:
1288 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1289 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1290 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1291 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1292@dots{}
1293@end example
1294
1295@noindent
1296to something like:
1297
1298@example
1299$ guix build emacs --dry-run
1300The following files would be downloaded:
1301 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1302 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1303 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1304 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1305@dots{}
1306@end example
1307
1308@noindent
1309This indicates that substitutes from @code{hydra.gnu.org} are usable and
1310will be downloaded, when possible, for future builds.
1311
1312Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1313one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1314when attempting to use a substitute that has been tampered with.
1315
1316The substitute mechanism can be disabled globally by running
1317@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1318guix-daemon}). It can also be disabled temporarily by passing the
1319@code{--no-substitutes} option to @command{guix package}, @command{guix
1320build}, and other command-line tools.
1321
1322
1323Today, each individual's control over their own computing is at the
1324mercy of institutions, corporations, and groups with enough power and
1325determination to subvert the computing infrastructure and exploit its
1326weaknesses. While using @code{hydra.gnu.org} substitutes can be
1327convenient, we encourage users to also build on their own, or even run
1328their own build farm, such that @code{hydra.gnu.org} is less of an
1329interesting target.
1330
1331Guix has the foundations to maximize build reproducibility
1332(@pxref{Features}). In most cases, independent builds of a given
1333package or derivation should yield bit-identical results. Thus, through
1334a diverse set of independent package builds, we can strengthen the
1335integrity of our systems.
1336
1337In the future, we want Guix to have support to publish and retrieve
1338binaries to/from other users, in a peer-to-peer fashion. If you would
1339like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1340
1341
6e721c4d
LC
1342@node Packages with Multiple Outputs
1343@section Packages with Multiple Outputs
1344
1345@cindex multiple-output packages
1346@cindex package outputs
1347
1348Often, packages defined in Guix have a single @dfn{output}---i.e., the
1349source package leads exactly one directory in the store. When running
1350@command{guix package -i glibc}, one installs the default output of the
1351GNU libc package; the default output is called @code{out}, but its name
1352can be omitted as shown in this command. In this particular case, the
1353default output of @code{glibc} contains all the C header files, shared
1354libraries, static libraries, Info documentation, and other supporting
1355files.
1356
1357Sometimes it is more appropriate to separate the various types of files
1358produced from a single source package into separate outputs. For
1359instance, the GLib C library (used by GTK+ and related packages)
1360installs more than 20 MiB of reference documentation as HTML pages.
1361To save space for users who do not need it, the documentation goes to a
1362separate output, called @code{doc}. To install the main GLib output,
1363which contains everything but the documentation, one would run:
1364
1365@example
1366guix package -i glib
1367@end example
1368
1369The command to install its documentation is:
1370
1371@example
1372guix package -i glib:doc
1373@end example
1374
1375Some packages install programs with different ``dependency footprints''.
1376For instance, the WordNet package install both command-line tools and
1377graphical user interfaces (GUIs). The former depend solely on the C
1378library, whereas the latter depend on Tcl/Tk and the underlying X
1379libraries. In this case, we leave the command-line tools in the default
1380output, whereas the GUIs are in a separate output. This allows users
1381who do not need the GUIs to save space.
1382
1383There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1384Other conventional output names include @code{lib} for libraries and
1385possibly header files, @code{bin} for stand-alone programs, and
1386@code{debug} for debugging information (@pxref{Installing Debugging
1387Files}). The outputs of a packages are listed in the third column of
1388the output of @command{guix package --list-available} (@pxref{Invoking
1389guix package}).
6e721c4d 1390
eeaf4427 1391
e49951eb
MW
1392@node Invoking guix gc
1393@section Invoking @command{guix gc}
fe8ff028
LC
1394
1395@cindex garbage collector
1396Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 1397The @command{guix gc} command allows users to explicitly run the garbage
c22eb992
LC
1398collector to reclaim space from the @file{/gnu/store} directory. It is
1399the @emph{only} way to remove files from @file{/gnu/store}---removing
1400files or directories manually may break it beyond repair!
fe8ff028
LC
1401
1402The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1403@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1404cannot be deleted; any other file is considered @dfn{dead} and may be
1405deleted. The set of garbage collector roots includes default user
e49951eb
MW
1406profiles, and may be augmented with @command{guix build --root}, for
1407example (@pxref{Invoking guix build}).
fe8ff028 1408
1bb9900a
LC
1409Prior to running @code{guix gc --collect-garbage} to make space, it is
1410often useful to remove old generations from user profiles; that way, old
1411package builds referenced by those generations can be reclaimed. This
1412is achieved by running @code{guix package --delete-generations}
1413(@pxref{Invoking guix package}).
1414
e49951eb 1415The @command{guix gc} command has three modes of operation: it can be
fe8ff028
LC
1416used to garbage-collect any dead files (the default), to delete specific
1417files (the @code{--delete} option), or to print garbage-collector
1418information. The available options are listed below:
1419
1420@table @code
1421@item --collect-garbage[=@var{min}]
1422@itemx -C [@var{min}]
834129e0 1423Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1424sub-directories. This is the default operation when no option is
1425specified.
1426
1427When @var{min} is given, stop once @var{min} bytes have been collected.
1428@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1429suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1430(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1431
1432When @var{min} is omitted, collect all the garbage.
1433
1434@item --delete
1435@itemx -d
1436Attempt to delete all the store files and directories specified as
1437arguments. This fails if some of the files are not in the store, or if
1438they are still live.
1439
1440@item --list-dead
1441Show the list of dead files and directories still present in the
1442store---i.e., files and directories no longer reachable from any root.
1443
1444@item --list-live
1445Show the list of live store files and directories.
ba8b732d
LC
1446
1447@end table
1448
1449In addition, the references among existing store files can be queried:
1450
1451@table @code
1452
1453@item --references
1454@itemx --referrers
1455List the references (respectively, the referrers) of store files given
1456as arguments.
1457
8e59fdd5
LC
1458@item --requisites
1459@itemx -R
1460List the requisites of the store files passed as arguments. Requisites
1461include the store files themselves, their references, and the references
1462of these, recursively. In other words, the returned list is the
1463@dfn{transitive closure} of the store files.
1464
fe8ff028
LC
1465@end table
1466
eeaf4427 1467
f651b477
LC
1468@node Invoking guix pull
1469@section Invoking @command{guix pull}
1470
1471Packages are installed or upgraded to the latest version available in
1472the distribution currently available on your local machine. To update
1473that distribution, along with the Guix tools, you must run @command{guix
1474pull}: the command downloads the latest Guix source code and package
1475descriptions, and deploys it.
1476
1477On completion, @command{guix package} will use packages and package
1478versions from this just-retrieved copy of Guix. Not only that, but all
1479the Guix commands and Scheme modules will also be taken from that latest
1480version. New @command{guix} sub-commands added by the update also
1481become available.
1482
1483The @command{guix pull} command is usually invoked with no arguments,
1484but it supports the following options:
1485
1486@table @code
1487@item --verbose
1488Produce verbose output, writing build logs to the standard error output.
1489
ab5d72ad
LC
1490@item --url=@var{url}
1491Download the source tarball of Guix from @var{url}.
1492
1493By default, the tarball is taken from its canonical address at
1494@code{gnu.org}, for the stable branch of Guix.
1495
f651b477
LC
1496@item --bootstrap
1497Use the bootstrap Guile to build the latest Guix. This option is only
1498useful to Guix developers.
1499@end table
1500
760c60d6
LC
1501
1502@node Invoking guix archive
1503@section Invoking @command{guix archive}
1504
1505The @command{guix archive} command allows users to @dfn{export} files
1506from the store into a single archive, and to later @dfn{import} them.
1507In particular, it allows store files to be transferred from one machine
1508to another machine's store. For example, to transfer the @code{emacs}
1509package to a machine connected over SSH, one would run:
1510
1511@example
56607088 1512guix archive --export -r emacs | ssh the-machine guix archive --import
760c60d6
LC
1513@end example
1514
87236aed 1515@noindent
56607088
LC
1516Similarly, a complete user profile may be transferred from one machine
1517to another like this:
1518
1519@example
1520guix archive --export -r $(readlink -f ~/.guix-profile) | \
1521 ssh the-machine guix-archive --import
1522@end example
1523
1524@noindent
1525However, note that, in both examples, all of @code{emacs} and the
1526profile as well as all of their dependencies are transferred (due to
1527@code{-r}), regardless of what is already available in the target
1528machine's store. The @code{--missing} option can help figure out which
1529items are missing from the target's store.
87236aed 1530
760c60d6 1531Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
1532comparable in spirit to `tar', but with a few noteworthy differences
1533that make it more appropriate for our purposes. First, rather than
1534recording all Unix meta-data for each file, the Nar format only mentions
1535the file type (regular, directory, or symbolic link); Unix permissions
1536and owner/group are dismissed. Second, the order in which directory
1537entries are stored always follows the order of file names according to
1538the C locale collation order. This makes archive production fully
1539deterministic.
1540
1541When exporting, the daemon digitally signs the contents of the archive,
1542and that digital signature is appended. When importing, the daemon
1543verifies the signature and rejects the import in case of an invalid
1544signature or if the signing key is not authorized.
760c60d6
LC
1545@c FIXME: Add xref to daemon doc about signatures.
1546
1547The main options are:
1548
1549@table @code
1550@item --export
1551Export the specified store files or packages (see below.) Write the
1552resulting archive to the standard output.
1553
56607088
LC
1554Dependencies are @emph{not} included in the output, unless
1555@code{--recursive} is passed.
1556
1557@item -r
1558@itemx --recursive
1559When combined with @code{--export}, this instructs @command{guix
1560archive} to include dependencies of the given items in the archive.
1561Thus, the resulting archive is self-contained: it contains the closure
1562of the exported store items.
1563
760c60d6
LC
1564@item --import
1565Read an archive from the standard input, and import the files listed
1566therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
1567signature, or if it is signed by a public key not among the authorized
1568keys (see @code{--authorize} below.)
554f26ec 1569
87236aed
LC
1570@item --missing
1571Read a list of store file names from the standard input, one per line,
1572and write on the standard output the subset of these files missing from
1573the store.
1574
554f26ec 1575@item --generate-key[=@var{parameters}]
f82cc5fd 1576@cindex signing, archives
554f26ec
LC
1577Generate a new key pair for the daemons. This is a prerequisite before
1578archives can be exported with @code{--export}. Note that this operation
1579usually takes time, because it needs to gather enough entropy to
1580generate the key pair.
1581
1582The generated key pair is typically stored under @file{/etc/guix}, in
1583@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
867d8473
LC
1584key, which must be kept secret.) When @var{parameters} is omitted,
1585an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
1586versions before 1.6.0, it is a 4096-bit RSA key.
1587Alternately, @var{parameters} can specify
554f26ec
LC
1588@code{genkey} parameters suitable for Libgcrypt (@pxref{General
1589public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
1590Libgcrypt Reference Manual}).
f82cc5fd
LC
1591
1592@item --authorize
1593@cindex authorizing, archives
1594Authorize imports signed by the public key passed on standard input.
1595The public key must be in ``s-expression advanced format''---i.e., the
1596same format as the @file{signing-key.pub} file.
1597
1598The list of authorized keys is kept in the human-editable file
1599@file{/etc/guix/acl}. The file contains
1600@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
1601s-expressions''} and is structured as an access-control list in the
1602@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
1603(SPKI)}.
760c60d6
LC
1604@end table
1605
1606To export store files as an archive to the standard output, run:
1607
1608@example
1609guix archive --export @var{options} @var{specifications}...
1610@end example
1611
1612@var{specifications} may be either store file names or package
1613specifications, as for @command{guix package} (@pxref{Invoking guix
1614package}). For instance, the following command creates an archive
1615containing the @code{gui} output of the @code{git} package and the main
1616output of @code{emacs}:
1617
1618@example
834129e0 1619guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
760c60d6
LC
1620@end example
1621
1622If the specified packages are not built yet, @command{guix archive}
1623automatically builds them. The build process may be controlled with the
1624same options that can be passed to the @command{guix build} command
70ee5642 1625(@pxref{Invoking guix build, common build options}).
760c60d6
LC
1626
1627
568717fd
LC
1628@c *********************************************************************
1629@node Programming Interface
1630@chapter Programming Interface
1631
3dc1970d
LC
1632GNU Guix provides several Scheme programming interfaces (APIs) to
1633define, build, and query packages. The first interface allows users to
1634write high-level package definitions. These definitions refer to
1635familiar packaging concepts, such as the name and version of a package,
1636its build system, and its dependencies. These definitions can then be
1637turned into concrete build actions.
1638
ba55b1cb 1639Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 1640standard setup, the daemon has write access to the store---the
834129e0 1641@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
1642setup also has the daemon perform builds in chroots, under a specific
1643build users, to minimize interference with the rest of the system.
1644
1645@cindex derivation
1646Lower-level APIs are available to interact with the daemon and the
1647store. To instruct the daemon to perform a build action, users actually
1648provide it with a @dfn{derivation}. A derivation is a low-level
1649representation of the build actions to be taken, and the environment in
1650which they should occur---derivations are to package definitions what
49ad317a
LC
1651assembly is to C programs. The term ``derivation'' comes from the fact
1652that build results @emph{derive} from them.
3dc1970d
LC
1653
1654This chapter describes all these APIs in turn, starting from high-level
1655package definitions.
1656
568717fd 1657@menu
b860f382 1658* Defining Packages:: Defining new packages.
7458bd0a 1659* Build Systems:: Specifying how packages are built.
b860f382
LC
1660* The Store:: Manipulating the package store.
1661* Derivations:: Low-level interface to package derivations.
1662* The Store Monad:: Purely functional interface to the store.
21b679f6 1663* G-Expressions:: Manipulating build expressions.
568717fd
LC
1664@end menu
1665
1666@node Defining Packages
1667@section Defining Packages
1668
3dc1970d
LC
1669The high-level interface to package definitions is implemented in the
1670@code{(guix packages)} and @code{(guix build-system)} modules. As an
1671example, the package definition, or @dfn{recipe}, for the GNU Hello
1672package looks like this:
1673
1674@example
e7f34eb0
LC
1675(define-module (gnu packages hello)
1676 #:use-module (guix packages)
1677 #:use-module (guix download)
1678 #:use-module (guix build-system gnu)
1679 #:use-module (guix licenses))
b22a12fd 1680
79f5dd59 1681(define-public hello
3dc1970d
LC
1682 (package
1683 (name "hello")
1684 (version "2.8")
1685 (source (origin
1686 (method url-fetch)
1687 (uri (string-append "mirror://gnu/hello/hello-" version
1688 ".tar.gz"))
1689 (sha256
1690 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
1691 (build-system gnu-build-system)
7458bd0a 1692 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 1693 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
1694 (synopsis "Hello, GNU world: An example GNU package")
1695 (description "Guess what GNU Hello prints!")
3dc1970d 1696 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 1697 (license gpl3+)))
3dc1970d
LC
1698@end example
1699
1700@noindent
1701Without being a Scheme expert, the reader may have guessed the meaning
e7f34eb0 1702of the various fields here. This expression binds variable @code{hello}
3dc1970d
LC
1703to a @code{<package>} object, which is essentially a record
1704(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
1705This package object can be inspected using procedures found in the
1706@code{(guix packages)} module; for instance, @code{(package-name hello)}
1707returns---surprise!---@code{"hello"}.
1708
2f7d2d91
LC
1709With luck, you may be able to import part or all of the definition of
1710the package you are interested in from another repository, using the
1711@code{guix import} command (@pxref{Invoking guix import}).
1712
e7f34eb0
LC
1713In the example above, @var{hello} is defined into a module of its own,
1714@code{(gnu packages hello)}. Technically, this is not strictly
1715necessary, but it is convenient to do so: all the packages defined in
1716modules under @code{(gnu packages @dots{})} are automatically known to
1717the command-line tools (@pxref{Package Modules}).
1718
3dc1970d
LC
1719There are a few points worth noting in the above package definition:
1720
1721@itemize
1722@item
1723The @code{source} field of the package is an @code{<origin>} object.
1724Here, the @code{url-fetch} method from @code{(guix download)} is used,
1725meaning that the source is a file to be downloaded over FTP or HTTP.
1726
1727The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
1728the GNU mirrors defined in @code{(guix download)}.
1729
1730The @code{sha256} field specifies the expected SHA256 hash of the file
1731being downloaded. It is mandatory, and allows Guix to check the
1732integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 1733base32 representation of the hash. You can obtain this information with
210cc920
LC
1734@code{guix download} (@pxref{Invoking guix download}) and @code{guix
1735hash} (@pxref{Invoking guix hash}).
3dc1970d 1736
f9cc8971
LC
1737@cindex patches
1738When needed, the @code{origin} form can also have a @code{patches} field
1739listing patches to be applied, and a @code{snippet} field giving a
1740Scheme expression to modify the source code.
1741
3dc1970d
LC
1742@item
1743@cindex GNU Build System
7458bd0a
LC
1744The @code{build-system} field specifies the procedure to build the
1745package (@pxref{Build Systems}). Here, @var{gnu-build-system}
1746represents the familiar GNU Build System, where packages may be
1747configured, built, and installed with the usual @code{./configure &&
1748make && make check && make install} command sequence.
1749
1750@item
1751The @code{arguments} field specifies options for the build system
1752(@pxref{Build Systems}). Here it is interpreted by
1753@var{gnu-build-system} as a request run @file{configure} with the
1754@code{--enable-silent-rules} flag.
3dc1970d
LC
1755
1756@item
1757The @code{inputs} field specifies inputs to the build process---i.e.,
1758build-time or run-time dependencies of the package. Here, we define an
1759input called @code{"gawk"} whose value is that of the @var{gawk}
1760variable; @var{gawk} is itself bound to a @code{<package>} object.
1761
1762Note that GCC, Coreutils, Bash, and other essential tools do not need to
1763be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 1764of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
1765
1766However, any other dependencies need to be specified in the
1767@code{inputs} field. Any dependency not specified here will simply be
1768unavailable to the build process, possibly leading to a build failure.
1769@end itemize
1770
2f7d2d91 1771Once a package definition is in place, the
e49951eb 1772package may actually be built using the @code{guix build} command-line
7458bd0a 1773tool (@pxref{Invoking guix build}). @xref{Packaging Guidelines}, for
b4f5e0e8
CR
1774more information on how to test package definitions, and
1775@ref{Invoking guix lint}, for information on how to check a definition
1776for style conformance.
1777
7458bd0a
LC
1778Eventually, updating the package definition to a new upstream version
1779can be partly automated by the @command{guix refresh} command
1780(@pxref{Invoking guix refresh}).
3dc1970d
LC
1781
1782Behind the scenes, a derivation corresponding to the @code{<package>}
1783object is first computed by the @code{package-derivation} procedure.
834129e0 1784That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 1785The build actions it prescribes may then be realized by using the
3dc1970d
LC
1786@code{build-derivations} procedure (@pxref{The Store}).
1787
1788@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
1789Return the @code{<derivation>} object of @var{package} for @var{system}
1790(@pxref{Derivations}).
3dc1970d
LC
1791
1792@var{package} must be a valid @code{<package>} object, and @var{system}
1793must be a string denoting the target system type---e.g.,
1794@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
1795must be a connection to the daemon, which operates on the store
1796(@pxref{The Store}).
1797@end deffn
568717fd 1798
9c1edabd
LC
1799@noindent
1800@cindex cross-compilation
1801Similarly, it is possible to compute a derivation that cross-builds a
1802package for some other system:
1803
1804@deffn {Scheme Procedure} package-cross-derivation @var{store} @
1805 @var{package} @var{target} [@var{system}]
59688fc4
LC
1806Return the @code{<derivation>} object of @var{package} cross-built from
1807@var{system} to @var{target}.
9c1edabd
LC
1808
1809@var{target} must be a valid GNU triplet denoting the target hardware
1810and operating system, such as @code{"mips64el-linux-gnu"}
1811(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
1812Configure and Build System}).
1813@end deffn
1814
1815
7458bd0a
LC
1816@node Build Systems
1817@section Build Systems
1818
1819@cindex build system
1820Each package definition specifies a @dfn{build system} and arguments for
1821that build system (@pxref{Defining Packages}). This @code{build-system}
1822field represents the build procedure of the package, as well implicit
1823dependencies of that build procedure.
1824
1825Build systems are @code{<build-system>} objects. The interface to
1826create and manipulate them is provided by the @code{(guix build-system)}
1827module, and actual build systems are exported by specific modules.
1828
f5fd4fd2 1829@cindex bag (low-level package representation)
0d5a559f
LC
1830Under the hood, build systems first compile package objects to
1831@dfn{bags}. A @dfn{bag} is like a package, but with less
1832ornamentation---in other words, a bag is a lower-level representation of
1833a package, which includes all the inputs of that package, including some
1834that were implicitly added by the build system. This intermediate
1835representation is then compiled to a derivation (@pxref{Derivations}).
1836
7458bd0a
LC
1837Build systems accept an optional list of @dfn{arguments}. In package
1838definitions, these are passed @i{via} the @code{arguments} field
1839(@pxref{Defining Packages}). They are typically keyword arguments
1840(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
1841Guile Reference Manual}). The value of these arguments is usually
1842evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
1843by the daemon (@pxref{Derivations}).
1844
1845The main build system is @var{gnu-build-system}, which implements the
1846standard build procedure for GNU packages and many other packages. It
1847is provided by the @code{(guix build-system gnu)} module.
1848
1849@defvr {Scheme Variable} gnu-build-system
1850@var{gnu-build-system} represents the GNU Build System, and variants
1851thereof (@pxref{Configuration, configuration and makefile conventions,,
1852standards, GNU Coding Standards}).
1853
1854@cindex build phases
1855In a nutshell, packages using it configured, built, and installed with
1856the usual @code{./configure && make && make check && make install}
1857command sequence. In practice, a few additional steps are often needed.
1858All these steps are split up in separate @dfn{phases},
1859notably@footnote{Please see the @code{(guix build gnu-build-system)}
1860modules for more details about the build phases.}:
1861
1862@table @code
1863@item unpack
1864Unpack the source tarball, and change the current directory to the
1865extracted source tree. If the source is actually a directory, copy it
1866to the build tree, and enter that directory.
1867
1868@item patch-source-shebangs
1869Patch shebangs encountered in source files so they refer to the right
1870store file names. For instance, this changes @code{#!/bin/sh} to
1871@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
1872
1873@item configure
1874Run the @file{configure} script with a number of default options, such
1875as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
1876by the @code{#:configure-flags} argument.
1877
1878@item build
1879Run @code{make} with the list of flags specified with
1880@code{#:make-flags}. If the @code{#:parallel-builds?} argument is true
1881(the default), build with @code{make -j}.
1882
1883@item check
1884Run @code{make check}, or some other target specified with
1885@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
1886@code{#:parallel-tests?} argument is true (the default), run @code{make
1887check -j}.
1888
1889@item install
1890Run @code{make install} with the flags listed in @code{#:make-flags}.
1891
1892@item patch-shebangs
1893Patch shebangs on the installed executable files.
1894
1895@item strip
1896Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
1897is false), copying them to the @code{debug} output when available
1898(@pxref{Installing Debugging Files}).
1899@end table
1900
1901@vindex %standard-phases
1902The build-side module @code{(guix build gnu-build-system)} defines
1903@var{%standard-phases} as the default list of build phases.
1904@var{%standard-phases} is a list of symbol/procedure pairs, where the
1905procedure implements the actual phase.
1906
1907The list of phases used for a particular package can be changed with the
1908@code{#:phases} parameter. For instance, passing:
1909
1910@example
1911#:phases (alist-delete 'configure %standard-phases)
1912@end example
1913
9bf404e9 1914means that all the phases described above will be used, except the
7458bd0a
LC
1915@code{configure} phase.
1916
1917In addition, this build system ensures that the ``standard'' environment
1918for GNU packages is available. This includes tools such as GCC, libc,
1919Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
1920build-system gnu)} module for a complete list.) We call these the
1921@dfn{implicit inputs} of a package, because package definitions don't
1922have to mention them.
1923@end defvr
1924
1925Other @code{<build-system>} objects are defined to support other
1926conventions and tools used by free software packages. They inherit most
1927of @var{gnu-build-system}, and differ mainly in the set of inputs
1928implicitly added to the build process, and in the list of phases
1929executed. Some of these build systems are listed below.
1930
1931@defvr {Scheme Variable} cmake-build-system
1932This variable is exported by @code{(guix build-system cmake)}. It
1933implements the build procedure for packages using the
1934@url{http://www.cmake.org, CMake build tool}.
1935
1936It automatically adds the @code{cmake} package to the set of inputs.
1937Which package is used can be specified with the @code{#:cmake}
1938parameter.
9849cfc1
LC
1939
1940The @code{#:configure-flags} parameter is taken as a list of flags
1941passed to the @command{cmake} command. The @code{#:build-type}
1942parameter specifies in abstract terms the flags passed to the compiler;
1943it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
1944debugging information''), which roughly means that code is compiled with
1945@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
1946@end defvr
1947
3afcf52b
FB
1948@defvr {Scheme Variable} glib-or-gtk-build-system
1949This variable is exported by @code{(guix build-system glib-or-gtk)}. It
1950is intended for use with packages making use of GLib or GTK+.
1951
1952This build system adds the following two phases to the ones defined by
1953@var{gnu-build-system}:
1954
1955@table @code
1956@item glib-or-gtk-wrap
1957The phase @code{glib-or-gtk-wrap} ensures that programs found under
1958@file{bin/} are able to find GLib's ``schemas'' and
1959@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
1960modules}. This is achieved by wrapping the programs in launch scripts
1961that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
1962environment variables.
1963
73aa8ddb
LC
1964It is possible to exclude specific package outputs from that wrapping
1965process by listing their names in the
1966@code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful
1967when an output is known not to contain any GLib or GTK+ binaries, and
1968where wrapping would gratuitously add a dependency of that output on
1969GLib and GTK+.
1970
3afcf52b
FB
1971@item glib-or-gtk-compile-schemas
1972The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's
1973@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
1974GSettings schemas} are compiled. Compilation is performed by the
1975@command{glib-compile-schemas} program. It is provided by the package
1976@code{glib:bin} which is automatically imported by the build system.
1977The @code{glib} package providing @command{glib-compile-schemas} can be
1978specified with the @code{#:glib} parameter.
1979@end table
1980
1981Both phases are executed after the @code{install} phase.
1982@end defvr
1983
7458bd0a
LC
1984@defvr {Scheme Variable} python-build-system
1985This variable is exported by @code{(guix build-system python)}. It
1986implements the more or less standard build procedure used by Python
1987packages, which consists in running @code{python setup.py build} and
1988then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
1989
1990For packages that install stand-alone Python programs under @code{bin/},
1991it takes care of wrapping these programs so their @code{PYTHONPATH}
1992environment variable points to all the Python libraries they depend on.
1993
1994Which Python package is used can be specified with the @code{#:python}
1995parameter.
1996@end defvr
1997
1998@defvr {Scheme Variable} perl-build-system
1999This variable is exported by @code{(guix build-system perl)}. It
2d2a53fc
EB
2000implements the standard build procedure for Perl packages, which either
2001consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}},
2002followed by @code{Build} and @code{Build install}; or in running
2003@code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by
2004@code{make} and @code{make install}; depending on which of
2005@code{Build.PL} or @code{Makefile.PL} is present in the package
2006distribution. Preference is given to the former if both @code{Build.PL}
2007and @code{Makefile.PL} exist in the package distribution. This
2008preference can be reversed by specifying @code{#t} for the
2009@code{#:make-maker?} parameter.
2010
2011The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation
2012passes flags specified by the @code{#:make-maker-flags} or
2013@code{#:module-build-flags} parameter, respectively.
7458bd0a
LC
2014
2015Which Perl package is used can be specified with @code{#:perl}.
2016@end defvr
2017
c08f9818
DT
2018@defvr {Scheme Variable} ruby-build-system
2019This variable is exported by @code{(guix build-system ruby)}. It
2020implements the RubyGems build procedure used by Ruby packages, which
2021involves running @code{gem build} followed by @code{gem install}.
2022
2023Which Ruby package is used can be specified with the @code{#:ruby}
2024parameter.
2025@end defvr
7458bd0a 2026
a677c726
RW
2027@defvr {Scheme Variable} waf-build-system
2028This variable is exported by @code{(guix build-system waf)}. It
2029implements a build procedure around the @code{waf} script. The common
2030phases---@code{configure}, @code{build}, and @code{install}---are
2031implemented by passing their names as arguments to the @code{waf}
2032script.
2033
2034The @code{waf} script is executed by the Python interpreter. Which
2035Python package is used to run the script can be specified with the
2036@code{#:python} parameter.
2037@end defvr
2038
14dfdf2e
FB
2039@defvr {Scheme Variable} haskell-build-system
2040This variable is exported by @code{(guix build-system haskell)}. It
2041implements the Cabal build procedure used by Haskell packages, which
2042involves running @code{runhaskell Setup.hs configure
2043--prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}.
2044Instead of installing the package by running @code{runhaskell Setup.hs
2045install}, to avoid trying to register libraries in the read-only
2046compiler store directory, the build system uses @code{runhaskell
2047Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In
2048addition, the build system generates the package documentation by
2049running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f}
2050is passed. Optional Haddock parameters can be passed with the help of
2051the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is
2052not found, the build system looks for @code{Setup.lhs} instead.
2053
2054Which Haskell compiler is used can be specified with the @code{#:haskell}
2055parameter which defaults to @code{ghc}.
2056@end defvr
2057
7458bd0a
LC
2058Lastly, for packages that do not need anything as sophisticated, a
2059``trivial'' build system is provided. It is trivial in the sense that
2060it provides basically no support: it does not pull any implicit inputs,
2061and does not have a notion of build phases.
2062
2063@defvr {Scheme Variable} trivial-build-system
2064This variable is exported by @code{(guix build-system trivial)}.
2065
2066This build system requires a @code{#:builder} argument. This argument
2067must be a Scheme expression that builds the package's output(s)---as
2068with @code{build-expression->derivation} (@pxref{Derivations,
2069@code{build-expression->derivation}}).
2070@end defvr
2071
568717fd
LC
2072@node The Store
2073@section The Store
2074
e531ac2a
LC
2075@cindex store
2076@cindex store paths
2077
2078Conceptually, the @dfn{store} is where derivations that have been
834129e0 2079successfully built are stored---by default, under @file{/gnu/store}.
e531ac2a
LC
2080Sub-directories in the store are referred to as @dfn{store paths}. The
2081store has an associated database that contains information such has the
2082store paths referred to by each store path, and the list of @emph{valid}
2083store paths---paths that result from a successful build.
2084
2085The store is always accessed by the daemon on behalf of its clients
2086(@pxref{Invoking guix-daemon}). To manipulate the store, clients
2087connect to the daemon over a Unix-domain socket, send it requests, and
2088read the result---these are remote procedure calls, or RPCs.
2089
2090The @code{(guix store)} module provides procedures to connect to the
2091daemon, and to perform RPCs. These are described below.
2092
2093@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
2094Connect to the daemon over the Unix-domain socket at @var{file}. When
2095@var{reserve-space?} is true, instruct it to reserve a little bit of
2096extra space on the file system so that the garbage collector can still
2097operate, should the disk become full. Return a server object.
2098
2099@var{file} defaults to @var{%default-socket-path}, which is the normal
2100location given the options that were passed to @command{configure}.
2101@end deffn
2102
2103@deffn {Scheme Procedure} close-connection @var{server}
2104Close the connection to @var{server}.
2105@end deffn
2106
2107@defvr {Scheme Variable} current-build-output-port
2108This variable is bound to a SRFI-39 parameter, which refers to the port
2109where build and error logs sent by the daemon should be written.
2110@end defvr
2111
2112Procedures that make RPCs all take a server object as their first
2113argument.
2114
2115@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
2116Return @code{#t} when @var{path} is a valid store path.
2117@end deffn
2118
cfbf9160 2119@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
2120Add @var{text} under file @var{name} in the store, and return its store
2121path. @var{references} is the list of store paths referred to by the
2122resulting store path.
2123@end deffn
2124
874e6874 2125@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
2126Build @var{derivations} (a list of @code{<derivation>} objects or
2127derivation paths), and return when the worker is done building them.
2128Return @code{#t} on success.
874e6874
LC
2129@end deffn
2130
b860f382
LC
2131Note that the @code{(guix monads)} module provides a monad as well as
2132monadic versions of the above procedures, with the goal of making it
2133more convenient to work with code that accesses the store (@pxref{The
2134Store Monad}).
2135
e531ac2a
LC
2136@c FIXME
2137@i{This section is currently incomplete.}
568717fd
LC
2138
2139@node Derivations
2140@section Derivations
2141
874e6874
LC
2142@cindex derivations
2143Low-level build actions and the environment in which they are performed
2144are represented by @dfn{derivations}. A derivation contain the
2145following pieces of information:
2146
2147@itemize
2148@item
2149The outputs of the derivation---derivations produce at least one file or
2150directory in the store, but may produce more.
2151
2152@item
2153The inputs of the derivations, which may be other derivations or plain
2154files in the store (patches, build scripts, etc.)
2155
2156@item
2157The system type targeted by the derivation---e.g., @code{x86_64-linux}.
2158
2159@item
2160The file name of a build script in the store, along with the arguments
2161to be passed.
2162
2163@item
2164A list of environment variables to be defined.
2165
2166@end itemize
2167
2168@cindex derivation path
2169Derivations allow clients of the daemon to communicate build actions to
2170the store. They exist in two forms: as an in-memory representation,
2171both on the client- and daemon-side, and as files in the store whose
2172name end in @code{.drv}---these files are referred to as @dfn{derivation
2173paths}. Derivations paths can be passed to the @code{build-derivations}
2174procedure to perform the build actions they prescribe (@pxref{The
2175Store}).
2176
2177The @code{(guix derivations)} module provides a representation of
2178derivations as Scheme objects, along with procedures to create and
2179otherwise manipulate derivations. The lowest-level primitive to create
2180a derivation is the @code{derivation} procedure:
2181
1909431c
LC
2182@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
2183 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 2184 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 2185 [#:system (%current-system)] [#:references-graphs #f] @
b53be755 2186 [#:allowed-references #f] [#:local-build? #f]
59688fc4
LC
2187Build a derivation with the given arguments, and return the resulting
2188@code{<derivation>} object.
874e6874 2189
2096ef47 2190When @var{hash} and @var{hash-algo} are given, a
874e6874 2191@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
2192known in advance, such as a file download. If, in addition,
2193@var{recursive?} is true, then that fixed output may be an executable
2194file or a directory and @var{hash} must be the hash of an archive
2195containing this output.
5b0c9d16 2196
858e9282 2197When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
2198name/store path pairs. In that case, the reference graph of each store
2199path is exported in the build environment in the corresponding file, in
2200a simple text format.
1909431c 2201
b53be755
LC
2202When @var{allowed-references} is true, it must be a list of store items
2203or outputs that the derivation's output may refer to.
2204
1909431c
LC
2205When @var{local-build?} is true, declare that the derivation is not a
2206good candidate for offloading and should rather be built locally
2207(@pxref{Daemon Offload Setup}). This is the case for small derivations
2208where the costs of data transfers would outweigh the benefits.
874e6874
LC
2209@end deffn
2210
2211@noindent
2212Here's an example with a shell script as its builder, assuming
2213@var{store} is an open connection to the daemon, and @var{bash} points
2214to a Bash executable in the store:
2215
2216@lisp
2217(use-modules (guix utils)
2218 (guix store)
2219 (guix derivations))
2220
59688fc4
LC
2221(let ((builder ; add the Bash script to the store
2222 (add-text-to-store store "my-builder.sh"
2223 "echo hello world > $out\n" '())))
2224 (derivation store "foo"
2225 bash `("-e" ,builder)
21b679f6 2226 #:inputs `((,bash) (,builder))
59688fc4 2227 #:env-vars '(("HOME" . "/homeless"))))
834129e0 2228@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
2229@end lisp
2230
21b679f6
LC
2231As can be guessed, this primitive is cumbersome to use directly. A
2232better approach is to write build scripts in Scheme, of course! The
2233best course of action for that is to write the build code as a
2234``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 2235information, @pxref{G-Expressions}.
21b679f6
LC
2236
2237Once upon a time, @code{gexp->derivation} did not exist and constructing
2238derivations with build code written in Scheme was achieved with
2239@code{build-expression->derivation}, documented below. This procedure
2240is now deprecated in favor of the much nicer @code{gexp->derivation}.
874e6874 2241
dd1a5a15
LC
2242@deffn {Scheme Procedure} build-expression->derivation @var{store} @
2243 @var{name} @var{exp} @
2244 [#:system (%current-system)] [#:inputs '()] @
2245 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
36bbbbd1 2246 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
63a42824
LC
2247 [#:references-graphs #f] [#:allowed-references #f] @
2248 [#:local-build? #f] [#:guile-for-build #f]
874e6874
LC
2249Return a derivation that executes Scheme expression @var{exp} as a
2250builder for derivation @var{name}. @var{inputs} must be a list of
2251@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
2252@code{"out"} is assumed. @var{modules} is a list of names of Guile
2253modules from the current search path to be copied in the store,
2254compiled, and made available in the load path during the execution of
2255@var{exp}---e.g., @code{((guix build utils) (guix build
2256gnu-build-system))}.
2257
2258@var{exp} is evaluated in an environment where @code{%outputs} is bound
2259to a list of output/path pairs, and where @code{%build-inputs} is bound
2260to a list of string/output-path pairs made from @var{inputs}.
2261Optionally, @var{env-vars} is a list of string pairs specifying the name
2262and value of environment variables visible to the builder. The builder
2263terminates by passing the result of @var{exp} to @code{exit}; thus, when
2264@var{exp} returns @code{#f}, the build is considered to have failed.
2265
2266@var{exp} is built using @var{guile-for-build} (a derivation). When
2267@var{guile-for-build} is omitted or is @code{#f}, the value of the
2268@code{%guile-for-build} fluid is used instead.
9c629a27 2269
63a42824
LC
2270See the @code{derivation} procedure for the meaning of
2271@var{references-graphs}, @var{allowed-references}, and @var{local-build?}.
874e6874
LC
2272@end deffn
2273
2274@noindent
2275Here's an example of a single-output derivation that creates a directory
2276containing one file:
2277
2278@lisp
2279(let ((builder '(let ((out (assoc-ref %outputs "out")))
834129e0 2280 (mkdir out) ; create /gnu/store/@dots{}-goo
874e6874
LC
2281 (call-with-output-file (string-append out "/test")
2282 (lambda (p)
2283 (display '(hello guix) p))))))
dd1a5a15 2284 (build-expression->derivation store "goo" builder))
874e6874 2285
834129e0 2286@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
2287@end lisp
2288
568717fd 2289
b860f382
LC
2290@node The Store Monad
2291@section The Store Monad
2292
2293@cindex monad
2294
2295The procedures that operate on the store described in the previous
2296sections all take an open connection to the build daemon as their first
2297argument. Although the underlying model is functional, they either have
2298side effects or depend on the current state of the store.
2299
2300The former is inconvenient: the connection to the build daemon has to be
2301carried around in all those functions, making it impossible to compose
2302functions that do not take that parameter with functions that do. The
2303latter can be problematic: since store operations have side effects
2304and/or depend on external state, they have to be properly sequenced.
2305
2306@cindex monadic values
2307@cindex monadic functions
2308This is where the @code{(guix monads)} module comes in. This module
2309provides a framework for working with @dfn{monads}, and a particularly
2310useful monad for our uses, the @dfn{store monad}. Monads are a
2311construct that allows two things: associating ``context'' with values
2312(in our case, the context is the store), and building sequences of
561fb6c3 2313computations (here computations include accesses to the store.) Values
b860f382
LC
2314in a monad---values that carry this additional context---are called
2315@dfn{monadic values}; procedures that return such values are called
2316@dfn{monadic procedures}.
2317
2318Consider this ``normal'' procedure:
2319
2320@example
45adbd62
LC
2321(define (sh-symlink store)
2322 ;; Return a derivation that symlinks the 'bash' executable.
2323 (let* ((drv (package-derivation store bash))
2324 (out (derivation->output-path drv))
2325 (sh (string-append out "/bin/bash")))
2326 (build-expression->derivation store "sh"
2327 `(symlink ,sh %output))))
b860f382
LC
2328@end example
2329
2330Using @code{(guix monads)}, it may be rewritten as a monadic function:
2331
ada3df03 2332@c FIXME: Find a better example, one that uses 'mlet'.
b860f382 2333@example
45adbd62 2334(define (sh-symlink)
b860f382 2335 ;; Same, but return a monadic value.
ada3df03
LC
2336 (gexp->derivation "sh"
2337 #~(symlink (string-append #$bash "/bin/bash") #$output)))
b860f382
LC
2338@end example
2339
2340There are two things to note in the second version: the @code{store}
2341parameter is now implicit, and the monadic value returned by
2342@code{package-file}---a wrapper around @code{package-derivation} and
2343@code{derivation->output-path}---is @dfn{bound} using @code{mlet}
2344instead of plain @code{let}.
2345
2346Calling the monadic @code{profile.sh} has no effect. To get the desired
2347effect, one must use @code{run-with-store}:
2348
2349@example
2350(run-with-store (open-connection) (profile.sh))
834129e0 2351@result{} /gnu/store/...-profile.sh
b860f382
LC
2352@end example
2353
b9b86078
LC
2354Note that the @code{(guix monad-repl)} module extends Guile's REPL with
2355new ``meta-commands'' to make it easier to deal with monadic procedures:
2356@code{run-in-store}, and @code{enter-store-monad}. The former, is used
2357to ``run'' a single monadic value through the store:
2358
2359@example
2360scheme@@(guile-user)> ,run-in-store (package->derivation hello)
2361$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
2362@end example
2363
2364The latter enters a recursive REPL, where all the return values are
2365automatically run through the store:
2366
2367@example
2368scheme@@(guile-user)> ,enter-store-monad
2369store-monad@@(guile-user) [1]> (package->derivation hello)
2370$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
2371store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
2372$3 = "/gnu/store/@dots{}-foo"
2373store-monad@@(guile-user) [1]> ,q
2374scheme@@(guile-user)>
2375@end example
2376
2377@noindent
2378Note that non-monadic values cannot be returned in the
2379@code{store-monad} REPL.
2380
e87f0591
LC
2381The main syntactic forms to deal with monads in general are provided by
2382the @code{(guix monads)} module and are described below.
b860f382
LC
2383
2384@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
2385Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
2386in @var{monad}.
2387@end deffn
2388
2389@deffn {Scheme Syntax} return @var{val}
2390Return a monadic value that encapsulates @var{val}.
2391@end deffn
2392
2393@deffn {Scheme Syntax} >>= @var{mval} @var{mproc}
2394@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
2395procedure @var{mproc}@footnote{This operation is commonly referred to as
2396``bind'', but that name denotes an unrelated procedure in Guile. Thus
2397we use this somewhat cryptic symbol inherited from the Haskell
2398language.}.
2399@end deffn
2400
2401@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
2402 @var{body} ...
2403@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
2404 @var{body} ...
2405Bind the variables @var{var} to the monadic values @var{mval} in
2406@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
2407``normal'' value @var{val}, as per @code{let}.
2408
2409@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
2410(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
2411@end deffn
2412
405a9d4e
LC
2413@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
2414Bind @var{mexp} and the following monadic expressions in sequence,
2415returning the result of the last expression.
2416
2417This is akin to @code{mlet}, except that the return values of the
2418monadic expressions are ignored. In that sense, it is analogous to
2419@code{begin}, but applied to monadic expressions.
2420@end deffn
2421
561fb6c3
LC
2422@cindex state monad
2423The @code{(guix monads)} module provides the @dfn{state monad}, which
2424allows an additional value---the state---to be @emph{threaded} through
2425monadic procedure calls.
2426
2427@defvr {Scheme Variable} %state-monad
2428The state monad. Procedures in the state monad can access and change
2429the state that is threaded.
2430
2431Consider the example below. The @code{square} procedure returns a value
2432in the state monad. It returns the square of its argument, but also
2433increments the current state value:
2434
2435@example
2436(define (square x)
2437 (mlet %state-monad ((count (current-state)))
2438 (mbegin %state-monad
2439 (set-current-state (+ 1 count))
2440 (return (* x x)))))
2441
2442(run-with-state (sequence %state-monad (map square (iota 3))) 0)
2443@result{} (0 1 4)
2444@result{} 3
2445@end example
2446
2447When ``run'' through @var{%state-monad}, we obtain that additional state
2448value, which is the number of @code{square} calls.
2449@end defvr
2450
2451@deffn {Monadic Procedure} current-state
2452Return the current state as a monadic value.
2453@end deffn
2454
2455@deffn {Monadic Procedure} set-current-state @var{value}
2456Set the current state to @var{value} and return the previous state as a
2457monadic value.
2458@end deffn
2459
2460@deffn {Monadic Procedure} state-push @var{value}
2461Push @var{value} to the current state, which is assumed to be a list,
2462and return the previous state as a monadic value.
2463@end deffn
2464
2465@deffn {Monadic Procedure} state-pop
2466Pop a value from the current state and return it as a monadic value.
2467The state is assumed to be a list.
2468@end deffn
2469
2470@deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}]
2471Run monadic value @var{mval} starting with @var{state} as the initial
2472state. Return two values: the resulting value, and the resulting state.
2473@end deffn
2474
e87f0591
LC
2475The main interface to the store monad, provided by the @code{(guix
2476store)} module, is as follows.
b860f382
LC
2477
2478@defvr {Scheme Variable} %store-monad
561fb6c3
LC
2479The store monad---an alias for @var{%state-monad}.
2480
2481Values in the store monad encapsulate accesses to the store. When its
2482effect is needed, a value of the store monad must be ``evaluated'' by
2483passing it to the @code{run-with-store} procedure (see below.)
b860f382
LC
2484@end defvr
2485
2486@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
2487Run @var{mval}, a monadic value in the store monad, in @var{store}, an
2488open store connection.
2489@end deffn
2490
ad372953 2491@deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}]
b860f382 2492Return as a monadic value the absolute file name in the store of the file
ad372953
LC
2493containing @var{text}, a string. @var{references} is a list of store items that the
2494resulting text file refers to; it defaults to the empty list.
45adbd62
LC
2495@end deffn
2496
0a90af15
LC
2497@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
2498 [#:recursive? #t]
2499Return the name of @var{file} once interned in the store. Use
2500@var{name} as its store name, or the basename of @var{file} if
2501@var{name} is omitted.
2502
2503When @var{recursive?} is true, the contents of @var{file} are added
2504recursively; if @var{file} designates a flat file and @var{recursive?}
2505is true, its contents are added, and its permission bits are kept.
2506
2507The example below adds a file to the store, under two different names:
2508
2509@example
2510(run-with-store (open-connection)
2511 (mlet %store-monad ((a (interned-file "README"))
2512 (b (interned-file "README" "LEGU-MIN")))
2513 (return (list a b))))
2514
2515@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
2516@end example
2517
2518@end deffn
2519
e87f0591
LC
2520The @code{(guix packages)} module exports the following package-related
2521monadic procedures:
2522
b860f382 2523@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b
LC
2524 [#:system (%current-system)] [#:target #f] @
2525 [#:output "out"] Return as a monadic
b860f382
LC
2526value in the absolute file name of @var{file} within the @var{output}
2527directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
2528of the @var{output} directory of @var{package}. When @var{target} is
2529true, use it as a cross-compilation target triplet.
b860f382
LC
2530@end deffn
2531
b860f382 2532@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
2533@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
2534 @var{target} [@var{system}]
2535Monadic version of @code{package-derivation} and
2536@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
2537@end deffn
2538
2539
21b679f6
LC
2540@node G-Expressions
2541@section G-Expressions
2542
2543@cindex G-expression
2544@cindex build code quoting
2545So we have ``derivations'', which represent a sequence of build actions
2546to be performed to produce an item in the store (@pxref{Derivations}).
2547Those build actions are performed when asking the daemon to actually
2548build the derivations; they are run by the daemon in a container
2549(@pxref{Invoking guix-daemon}).
2550
2551@cindex strata of code
2552It should come as no surprise that we like to write those build actions
2553in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
2554code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
2555Manuel Serrano et al.@: in the context of their work on Hop. Oleg
2556Kiselyov, who has written insightful
2557@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
2558on this topic}, refers to this kind of code generation as
2559@dfn{staging}.}: the ``host code''---code that defines packages, talks
2560to the daemon, etc.---and the ``build code''---code that actually
2561performs build actions, such as making directories, invoking
2562@command{make}, etc.
21b679f6
LC
2563
2564To describe a derivation and its build actions, one typically needs to
2565embed build code inside host code. It boils down to manipulating build
2566code as data, and Scheme's homoiconicity---code has a direct
2567representation as data---comes in handy for that. But we need more than
2568Scheme's normal @code{quasiquote} mechanism to construct build
2569expressions.
2570
2571The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
2572S-expressions adapted to build expressions. G-expressions, or
2573@dfn{gexps}, consist essentially in three syntactic forms: @code{gexp},
2574@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
2575@code{#$}, and @code{#$@@}), which are comparable respectively to
2576@code{quasiquote}, @code{unquote}, and @code{unquote-splicing}
2577(@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile
2578Reference Manual}). However, there are major differences:
2579
2580@itemize
2581@item
2582Gexps are meant to be written to a file and run or manipulated by other
2583processes.
2584
2585@item
b39fc6f7
LC
2586When a high-level object such as a package or derivation is unquoted
2587inside a gexp, the result is as if its output file name had been
2588introduced.
ff40e9b7 2589
21b679f6
LC
2590@item
2591Gexps carry information about the packages or derivations they refer to,
2592and these dependencies are automatically added as inputs to the build
2593processes that use them.
2594@end itemize
2595
b39fc6f7
LC
2596Actually this mechanism is not limited to package and derivation
2597objects; @dfn{compilers} able to ``lower'' other high-level objects to
2598derivations can be defined, such that these objects can also be inserted
d9ae938f
LC
2599into gexps. Another useful type of high-level object that can be
2600inserted in a gexp is @dfn{local files}, which allows files from the
2601local file system to be added to the store and referred to by
2602derivations and such (see @code{local-file} below.)
b39fc6f7 2603
21b679f6
LC
2604To illustrate the idea, here is an example of a gexp:
2605
2606@example
2607(define build-exp
2608 #~(begin
2609 (mkdir #$output)
2610 (chdir #$output)
aff8ce7c 2611 (symlink (string-append #$coreutils "/bin/ls")
21b679f6
LC
2612 "list-files")))
2613@end example
2614
2615This gexp can be passed to @code{gexp->derivation}; we obtain a
2616derivation that builds a directory containing exactly one symlink to
2617@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
2618
2619@example
2620(gexp->derivation "the-thing" build-exp)
2621@end example
2622
e20fd1bf 2623As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
2624substituted to the reference to the @var{coreutils} package in the
2625actual build code, and @var{coreutils} is automatically made an input to
2626the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
2627output)}) is replaced by a string containing the derivation's output
667b2508
LC
2628directory name.
2629
2630@cindex cross compilation
2631In a cross-compilation context, it is useful to distinguish between
2632references to the @emph{native} build of a package---that can run on the
2633host---versus references to cross builds of a package. To that end, the
2634@code{#+} plays the same role as @code{#$}, but is a reference to a
2635native package build:
2636
2637@example
2638(gexp->derivation "vi"
2639 #~(begin
2640 (mkdir #$output)
2641 (system* (string-append #+coreutils "/bin/ln")
2642 "-s"
2643 (string-append #$emacs "/bin/emacs")
2644 (string-append #$output "/bin/vi")))
2645 #:target "mips64el-linux")
2646@end example
2647
2648@noindent
2649In the example above, the native build of @var{coreutils} is used, so
2650that @command{ln} can actually run on the host; but then the
2651cross-compiled build of @var{emacs} is referenced.
2652
2653The syntactic form to construct gexps is summarized below.
21b679f6
LC
2654
2655@deffn {Scheme Syntax} #~@var{exp}
2656@deffnx {Scheme Syntax} (gexp @var{exp})
2657Return a G-expression containing @var{exp}. @var{exp} may contain one
2658or more of the following forms:
2659
2660@table @code
2661@item #$@var{obj}
2662@itemx (ungexp @var{obj})
b39fc6f7
LC
2663Introduce a reference to @var{obj}. @var{obj} may have one of the
2664supported types, for example a package or a
21b679f6
LC
2665derivation, in which case the @code{ungexp} form is replaced by its
2666output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
2667
b39fc6f7
LC
2668If @var{obj} is a list, it is traversed and references to supported
2669objects are substituted similarly.
21b679f6
LC
2670
2671If @var{obj} is another gexp, its contents are inserted and its
2672dependencies are added to those of the containing gexp.
2673
2674If @var{obj} is another kind of object, it is inserted as is.
2675
b39fc6f7
LC
2676@item #$@var{obj}:@var{output}
2677@itemx (ungexp @var{obj} @var{output})
21b679f6 2678This is like the form above, but referring explicitly to the
b39fc6f7
LC
2679@var{output} of @var{obj}---this is useful when @var{obj} produces
2680multiple outputs (@pxref{Packages with Multiple Outputs}).
21b679f6 2681
667b2508
LC
2682@item #+@var{obj}
2683@itemx #+@var{obj}:output
2684@itemx (ungexp-native @var{obj})
2685@itemx (ungexp-native @var{obj} @var{output})
2686Same as @code{ungexp}, but produces a reference to the @emph{native}
2687build of @var{obj} when used in a cross compilation context.
2688
21b679f6
LC
2689@item #$output[:@var{output}]
2690@itemx (ungexp output [@var{output}])
2691Insert a reference to derivation output @var{output}, or to the main
2692output when @var{output} is omitted.
2693
2694This only makes sense for gexps passed to @code{gexp->derivation}.
2695
2696@item #$@@@var{lst}
2697@itemx (ungexp-splicing @var{lst})
2698Like the above, but splices the contents of @var{lst} inside the
2699containing list.
2700
667b2508
LC
2701@item #+@@@var{lst}
2702@itemx (ungexp-native-splicing @var{lst})
2703Like the above, but refers to native builds of the objects listed in
2704@var{lst}.
2705
21b679f6
LC
2706@end table
2707
2708G-expressions created by @code{gexp} or @code{#~} are run-time objects
2709of the @code{gexp?} type (see below.)
2710@end deffn
2711
2712@deffn {Scheme Procedure} gexp? @var{obj}
2713Return @code{#t} if @var{obj} is a G-expression.
2714@end deffn
2715
2716G-expressions are meant to be written to disk, either as code building
2717some derivation, or as plain files in the store. The monadic procedures
2718below allow you to do that (@pxref{The Store Monad}, for more
2719information about monads.)
2720
2721@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
ce45eb4c 2722 [#:system (%current-system)] [#:target #f] [#:graft? #t] @
21b679f6
LC
2723 [#:hash #f] [#:hash-algo #f] @
2724 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
4684f301 2725 [#:module-path @var{%load-path}] @
c8351d9a
LC
2726 [#:references-graphs #f] [#:allowed-references #f] @
2727 [#:local-build? #f] [#:guile-for-build #f]
21b679f6 2728Return a derivation @var{name} that runs @var{exp} (a gexp) with
68a61e9f
LC
2729@var{guile-for-build} (a derivation) on @var{system}. When @var{target}
2730is true, it is used as the cross-compilation target triplet for packages
2731referred to by @var{exp}.
21b679f6 2732
ce45eb4c
LC
2733Make @var{modules} available in the evaluation context of @var{exp};
2734@var{modules} is a list of names of Guile modules searched in
2735@var{module-path} to be copied in the store, compiled, and made available in
21b679f6
LC
2736the load path during the execution of @var{exp}---e.g., @code{((guix
2737build utils) (guix build gnu-build-system))}.
2738
ce45eb4c
LC
2739@var{graft?} determines whether packages referred to by @var{exp} should be grafted when
2740applicable.
2741
b53833b2
LC
2742When @var{references-graphs} is true, it must be a list of tuples of one of the
2743following forms:
2744
2745@example
2746(@var{file-name} @var{package})
2747(@var{file-name} @var{package} @var{output})
2748(@var{file-name} @var{derivation})
2749(@var{file-name} @var{derivation} @var{output})
2750(@var{file-name} @var{store-item})
2751@end example
2752
2753The right-hand-side of each element of @var{references-graphs} is automatically made
2754an input of the build process of @var{exp}. In the build environment, each
2755@var{file-name} contains the reference graph of the corresponding item, in a simple
2756text format.
2757
c8351d9a
LC
2758@var{allowed-references} must be either @code{#f} or a list of output names and packages.
2759In the latter case, the list denotes store items that the result is allowed to
2760refer to. Any reference to another store item will lead to a build error.
2761
e20fd1bf 2762The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
2763@end deffn
2764
d9ae938f
LC
2765@deffn {Scheme Procedure} local-file @var{file} [@var{name}] @
2766 [#:recursive? #t]
2767Return an object representing local file @var{file} to add to the store; this
2768object can be used in a gexp. @var{file} will be added to the store under @var{name}--by
2769default the base name of @var{file}.
2770
2771When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file}
2772designates a flat file and @var{recursive?} is true, its contents are added, and its
2773permission bits are kept.
2774
2775This is the declarative counterpart of the @code{interned-file} monadic
2776procedure (@pxref{The Store Monad, @code{interned-file}}).
2777@end deffn
2778
21b679f6
LC
2779@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
2780Return an executable script @var{name} that runs @var{exp} using
2781@var{guile} with @var{modules} in its search path.
2782
2783The example below builds a script that simply invokes the @command{ls}
2784command:
2785
2786@example
2787(use-modules (guix gexp) (gnu packages base))
2788
2789(gexp->script "list-files"
2790 #~(execl (string-append #$coreutils "/bin/ls")
2791 "ls"))
2792@end example
2793
2794When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 2795@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
2796executable file @file{/gnu/store/@dots{}-list-files} along these lines:
2797
2798@example
2799#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
2800!#
2801(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
2802 "ls")
2803@end example
2804@end deffn
2805
2806@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
2807Return a derivation that builds a file @var{name} containing @var{exp}.
2808
2809The resulting file holds references to all the dependencies of @var{exp}
2810or a subset thereof.
2811@end deffn
1ed19464
LC
2812
2813@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
2814Return as a monadic value a derivation that builds a text file
2815containing all of @var{text}. @var{text} may list, in addition to
d9ae938f
LC
2816strings, objects of any type that can be used in a gexp: packages,
2817derivations, local file objects, etc. The resulting store file holds
2818references to all these.
1ed19464
LC
2819
2820This variant should be preferred over @code{text-file} anytime the file
2821to create will reference items from the store. This is typically the
2822case when building a configuration file that embeds store file names,
2823like this:
2824
2825@example
2826(define (profile.sh)
2827 ;; Return the name of a shell script in the store that
2828 ;; initializes the 'PATH' environment variable.
2829 (text-file* "profile.sh"
2830 "export PATH=" coreutils "/bin:"
2831 grep "/bin:" sed "/bin\n"))
2832@end example
2833
2834In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
2835will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
2836preventing them from being garbage-collected during its lifetime.
2837@end deffn
21b679f6
LC
2838
2839Of course, in addition to gexps embedded in ``host'' code, there are
2840also modules containing build tools. To make it clear that they are
2841meant to be used in the build stratum, these modules are kept in the
2842@code{(guix build @dots{})} name space.
2843
2844
568717fd
LC
2845@c *********************************************************************
2846@node Utilities
2847@chapter Utilities
2848
210cc920
LC
2849This section describes tools primarily targeted at developers and users
2850who write new package definitions. They complement the Scheme
2851programming interface of Guix in a convenient way.
2852
568717fd 2853@menu
37166310 2854* Invoking guix build:: Building packages from the command line.
210cc920 2855* Invoking guix download:: Downloading a file and printing its hash.
37166310 2856* Invoking guix hash:: Computing the cryptographic hash of a file.
2f7d2d91 2857* Invoking guix import:: Importing package definitions.
37166310 2858* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 2859* Invoking guix lint:: Finding errors in package definitions.
372c4bbc 2860* Invoking guix environment:: Setting up development environments.
aff8ce7c 2861* Invoking guix publish:: Sharing substitutes.
568717fd
LC
2862@end menu
2863
e49951eb
MW
2864@node Invoking guix build
2865@section Invoking @command{guix build}
568717fd 2866
e49951eb 2867The @command{guix build} command builds packages or derivations and
6798a8e4
LC
2868their dependencies, and prints the resulting store paths. Note that it
2869does not modify the user's profile---this is the job of the
e49951eb 2870@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
2871it is mainly useful for distribution developers.
2872
2873The general syntax is:
c78bd12b
LC
2874
2875@example
e49951eb 2876guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
2877@end example
2878
2879@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
2880the software distribution such as @code{coreutils} or
2881@code{coreutils-8.20}, or a derivation such as
834129e0 2882@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
2883package with the corresponding name (and optionally version) is searched
2884for among the GNU distribution modules (@pxref{Package Modules}).
2885
2886Alternatively, the @code{--expression} option may be used to specify a
2887Scheme expression that evaluates to a package; this is useful when
2888disambiguation among several same-named packages or package variants is
2889needed.
c78bd12b
LC
2890
2891The @var{options} may be zero or more of the following:
2892
2893@table @code
2894
2895@item --expression=@var{expr}
2896@itemx -e @var{expr}
ac5de156 2897Build the package or derivation @var{expr} evaluates to.
c78bd12b 2898
5401dd75 2899For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
2900guile-1.8)}, which unambiguously designates this specific variant of
2901version 1.8 of Guile.
2902
56b82106
LC
2903Alternately, @var{expr} may be a G-expression, in which case it is used
2904as a build program passed to @code{gexp->derivation}
2905(@pxref{G-Expressions}).
2906
2907Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
2908(@pxref{The Store Monad}). The procedure must return a derivation as a
2909monadic value, which is then passed through @code{run-with-store}.
2910
c78bd12b
LC
2911@item --source
2912@itemx -S
2913Build the packages' source derivations, rather than the packages
2914themselves.
2915
e49951eb 2916For instance, @code{guix build -S gcc} returns something like
834129e0 2917@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 2918
f9cc8971
LC
2919The returned source tarball is the result of applying any patches and
2920code snippets specified in the package's @code{origin} (@pxref{Defining
2921Packages}).
2922
c78bd12b
LC
2923@item --system=@var{system}
2924@itemx -s @var{system}
2925Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
2926the host's system type.
2927
2928An example use of this is on Linux-based systems, which can emulate
2929different personalities. For instance, passing
2930@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
2931to build packages in a complete 32-bit environment.
2932
e55ec43d
LC
2933@item --target=@var{triplet}
2934@cindex cross-compilation
2935Cross-build for @var{triplet}, which must be a valid GNU triplet, such
2936as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
2937configuration triplets,, configure, GNU Configure and Build System}).
2938
7f3673f2
LC
2939@item --with-source=@var{source}
2940Use @var{source} as the source of the corresponding package.
2941@var{source} must be a file name or a URL, as for @command{guix
2942download} (@pxref{Invoking guix download}).
2943
2944The ``corresponding package'' is taken to be one specified on the
2945command line whose name matches the base of @var{source}---e.g., if
2946@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
2947package is @code{guile}. Likewise, the version string is inferred from
2948@var{source}; in the previous example, it's @code{2.0.10}.
2949
2950This option allows users to try out versions of packages other than the
2951one provided by the distribution. The example below downloads
2952@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
2953the @code{ed} package:
2954
2955@example
2956guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
2957@end example
2958
2959As a developer, @code{--with-source} makes it easy to test release
2960candidates:
2961
2962@example
2963guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
2964@end example
2965
05962f29
LC
2966@item --no-grafts
2967Do not ``graft'' packages. In practice, this means that package updates
2968available as grafts are not applied. @xref{Security Updates}, for more
2969information on grafts.
7f3673f2 2970
c78bd12b
LC
2971@item --derivations
2972@itemx -d
2973Return the derivation paths, not the output paths, of the given
2974packages.
2975
70ee5642
LC
2976@item --root=@var{file}
2977@itemx -r @var{file}
2978Make @var{file} a symlink to the result, and register it as a garbage
2979collector root.
2980
2981@item --log-file
2982Return the build log file names for the given
2983@var{package-or-derivation}s, or raise an error if build logs are
2984missing.
2985
2986This works regardless of how packages or derivations are specified. For
2987instance, the following invocations are equivalent:
2988
2989@example
2990guix build --log-file `guix build -d guile`
2991guix build --log-file `guix build guile`
2992guix build --log-file guile
2993guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
2994@end example
2995
2996
2997@end table
2998
2999@cindex common build options
3000In addition, a number of options that control the build process are
3001common to @command{guix build} and other commands that can spawn builds,
3002such as @command{guix package} or @command{guix archive}. These are the
3003following:
3004
3005@table @code
3006
300868ba
LC
3007@item --load-path=@var{directory}
3008@itemx -L @var{directory}
3009Add @var{directory} to the front of the package module search path
3010(@pxref{Package Modules}).
3011
3012This allows users to define their own packages and make them visible to
3013the command-line tools.
3014
c78bd12b
LC
3015@item --keep-failed
3016@itemx -K
3017Keep the build tree of failed builds. Thus, if a build fail, its build
3018tree is kept under @file{/tmp}, in a directory whose name is shown at
3019the end of the build log. This is useful when debugging build issues.
3020
3021@item --dry-run
3022@itemx -n
3023Do not build the derivations.
3024
56b1f4b7
LC
3025@item --fallback
3026When substituting a pre-built binary fails, fall back to building
3027packages locally.
3028
c78bd12b 3029@item --no-substitutes
b5385b52 3030Do not use substitutes for build products. That is, always build things
c4202d60
LC
3031locally instead of allowing downloads of pre-built binaries
3032(@pxref{Substitutes}).
c78bd12b 3033
425b0bfc 3034@item --no-build-hook
4ec2e92d
LC
3035Do not attempt to offload builds @i{via} the daemon's ``build hook''
3036(@pxref{Daemon Offload Setup}). That is, always build things locally
3037instead of offloading builds to remote machines.
425b0bfc 3038
969e678e
LC
3039@item --max-silent-time=@var{seconds}
3040When the build or substitution process remains silent for more than
3041@var{seconds}, terminate it and report a build failure.
3042
002622b6
LC
3043@item --timeout=@var{seconds}
3044Likewise, when the build or substitution process lasts for more than
3045@var{seconds}, terminate it and report a build failure.
3046
3047By default there is no timeout. This behavior can be restored with
3048@code{--timeout=0}.
3049
07ab4bf1
LC
3050@item --verbosity=@var{level}
3051Use the given verbosity level. @var{level} must be an integer between 0
3052and 5; higher means more verbose output. Setting a level of 4 or more
3053may be helpful when debugging setup issues with the build daemon.
3054
70ee5642
LC
3055@item --cores=@var{n}
3056@itemx -c @var{n}
3057Allow the use of up to @var{n} CPU cores for the build. The special
3058value @code{0} means to use as many CPU cores as available.
bf421152 3059
f6526eb3
LC
3060@item --max-jobs=@var{n}
3061@itemx -M @var{n}
3062Allow at most @var{n} build jobs in parallel. @xref{Invoking
3063guix-daemon, @code{--max-jobs}}, for details about this option and the
3064equivalent @command{guix-daemon} option.
3065
c78bd12b
LC
3066@end table
3067
e49951eb 3068Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
3069the @code{package-derivation} procedure of the @code{(guix packages)}
3070module, and to the @code{build-derivations} procedure of the @code{(guix
01d8ac64 3071derivations)} module.
c78bd12b 3072
16eb115e
DP
3073In addition to options explicitly passed on the command line,
3074@command{guix build} and other @command{guix} commands that support
3075building honor the @code{GUIX_BUILD_OPTIONS} environment variable.
3076
3077@defvr {Environment Variable} GUIX_BUILD_OPTIONS
3078Users can define this variable to a list of command line options that
3079will automatically be used by @command{guix build} and other
3080@command{guix} commands that can perform builds, as in the example
3081below:
3082
3083@example
3084$ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar"
3085@end example
3086
847391fe
DP
3087These options are parsed independently, and the result is appended to
3088the parsed command-line options.
16eb115e
DP
3089@end defvr
3090
3091
210cc920
LC
3092@node Invoking guix download
3093@section Invoking @command{guix download}
3094
3095When writing a package definition, developers typically need to download
3096the package's source tarball, compute its SHA256 hash, and write that
3097hash in the package definition (@pxref{Defining Packages}). The
3098@command{guix download} tool helps with this task: it downloads a file
3099from the given URI, adds it to the store, and prints both its file name
3100in the store and its SHA256 hash.
3101
3102The fact that the downloaded file is added to the store saves bandwidth:
3103when the developer eventually tries to build the newly defined package
3104with @command{guix build}, the source tarball will not have to be
3105downloaded again because it is already in the store. It is also a
3106convenient way to temporarily stash files, which may be deleted
3107eventually (@pxref{Invoking guix gc}).
3108
3109The @command{guix download} command supports the same URIs as used in
3110package definitions. In particular, it supports @code{mirror://} URIs.
3111@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
3112Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
3113they are not available, an error is raised. @xref{Guile Preparations,
3114how to install the GnuTLS bindings for Guile,, gnutls-guile,
3115GnuTLS-Guile}, for more information.
210cc920
LC
3116
3117The following option is available:
3118
3119@table @code
3120@item --format=@var{fmt}
3121@itemx -f @var{fmt}
3122Write the hash in the format specified by @var{fmt}. For more
081145cf 3123information on the valid values for @var{fmt}, @pxref{Invoking guix hash}.
210cc920
LC
3124@end table
3125
6c365eca
NK
3126@node Invoking guix hash
3127@section Invoking @command{guix hash}
3128
210cc920 3129The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
3130It is primarily a convenience tool for anyone contributing to the
3131distribution: it computes the cryptographic hash of a file, which can be
3132used in the definition of a package (@pxref{Defining Packages}).
3133
3134The general syntax is:
3135
3136@example
3137guix hash @var{option} @var{file}
3138@end example
3139
3140@command{guix hash} has the following option:
3141
3142@table @code
3143
3144@item --format=@var{fmt}
3145@itemx -f @var{fmt}
210cc920 3146Write the hash in the format specified by @var{fmt}.
6c365eca
NK
3147
3148Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
3149(@code{hex} and @code{hexadecimal} can be used as well).
3150
3151If the @option{--format} option is not specified, @command{guix hash}
3152will output the hash in @code{nix-base32}. This representation is used
3153in the definitions of packages.
3154
3140f2df
LC
3155@item --recursive
3156@itemx -r
3157Compute the hash on @var{file} recursively.
3158
3159In this case, the hash is computed on an archive containing @var{file},
3160including its children if it is a directory. Some of @var{file}'s
3161meta-data is part of the archive; for instance, when @var{file} is a
3162regular file, the hash is different depending on whether @var{file} is
3163executable or not. Meta-data such as time stamps has no impact on the
3164hash (@pxref{Invoking guix archive}).
3165@c FIXME: Replace xref above with xref to an ``Archive'' section when
3166@c it exists.
3167
6c365eca
NK
3168@end table
3169
2f7d2d91
LC
3170@node Invoking guix import
3171@section Invoking @command{guix import}
3172
3173@cindex importing packages
3174@cindex package import
3175@cindex package conversion
3176The @command{guix import} command is useful for people willing to add a
3177package to the distribution but who'd rather do as little work as
3178possible to get there---a legitimate demand. The command knows of a few
3179repositories from which it can ``import'' package meta-data. The result
3180is a package definition, or a template thereof, in the format we know
3181(@pxref{Defining Packages}).
3182
3183The general syntax is:
3184
3185@example
3186guix import @var{importer} @var{options}@dots{}
3187@end example
3188
3189@var{importer} specifies the source from which to import package
3190meta-data, and @var{options} specifies a package identifier and other
3191options specific to @var{importer}. Currently, the available
3192``importers'' are:
3193
3194@table @code
3195@item gnu
3196Import meta-data for the given GNU package. This provides a template
3197for the latest version of that GNU package, including the hash of its
3198source tarball, and its canonical synopsis and description.
3199
3200Additional information such as the package's dependencies and its
3201license needs to be figured out manually.
3202
3203For example, the following command returns a package definition for
3204GNU@tie{}Hello:
3205
3206@example
3207guix import gnu hello
3208@end example
3209
3210Specific command-line options are:
3211
3212@table @code
3213@item --key-download=@var{policy}
3214As for @code{guix refresh}, specify the policy to handle missing OpenPGP
3215keys when verifying the package's signature. @xref{Invoking guix
3216refresh, @code{--key-download}}.
3217@end table
3218
3219@item pypi
3220@cindex pypi
3221Import meta-data from the @uref{https://pypi.python.org/, Python Package
3222Index}@footnote{This functionality requires Guile-JSON to be installed.
3223@xref{Requirements}.}. Information is taken from the JSON-formatted
3224description available at @code{pypi.python.org} and usually includes all
3225the relevant information, including package dependencies.
3226
3227The command below imports meta-data for the @code{itsdangerous} Python
3228package:
3229
3230@example
3231guix import pypi itsdangerous
3232@end example
3233
d45dc6da
EB
3234@item cpan
3235@cindex CPAN
3236Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}.
3237Information is taken from the JSON-formatted meta-data provided through
3238@uref{https://api.metacpan.org/, MetaCPAN's API} and includes most
66392e47
EB
3239relevant information, such as module dependencies. License information
3240should be checked closely. If Perl is available in the store, then the
3241@code{corelist} utility will be used to filter core modules out of the
3242list of dependencies.
d45dc6da
EB
3243
3244The command command below imports meta-data for the @code{Acme::Boolean}
3245Perl module:
3246
3247@example
3248guix import cpan Acme::Boolean
3249@end example
3250
2f7d2d91
LC
3251@item nix
3252Import meta-data from a local copy of the source of the
3253@uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This
3254relies on the @command{nix-instantiate} command of
3255@uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are
3256typically written in a mixture of Nix-language and Bash code. This
3257command only imports the high-level package structure that is written in
3258the Nix language. It normally includes all the basic fields of a
3259package definition.
3260
3261When importing a GNU package, the synopsis and descriptions are replaced
3262by their canonical upstream variant.
3263
3264As an example, the command below imports the package definition of
3265LibreOffice (more precisely, it imports the definition of the package
3266bound to the @code{libreoffice} top-level attribute):
3267
3268@example
3269guix import nix ~/path/to/nixpkgs libreoffice
3270@end example
863af4e1
FB
3271
3272@item hackage
3273@cindex hackage
3274Import meta-data from Haskell community's central package archive
3275@uref{https://hackage.haskell.org/, Hackage}. Information is taken from
3276Cabal files and includes all the relevant information, including package
3277dependencies.
3278
3279Specific command-line options are:
3280
3281@table @code
3282@item --no-test-dependencies
3283@itemx -t
3284Do not include dependencies only required to run the test suite.
3285@end table
3286
3287The command below imports meta-data for the latest version of the
3288@code{HTTP} Haskell package without including test dependencies:
3289
3290@example
3291guix import hackage -t HTTP
3292@end example
3293
3294A specific package version may optionally be specified by following the
3295package name by a hyphen and a version number as in the following example:
3296
3297@example
3298guix import hackage mtl-2.1.3.1
3299@end example
3300
3301Currently only indentation structured Cabal files are supported.
2f7d2d91
LC
3302@end table
3303
3304The structure of the @command{guix import} code is modular. It would be
3305useful to have more importers for other package formats, and your help
3306is welcome here (@pxref{Contributing}).
3307
37166310
LC
3308@node Invoking guix refresh
3309@section Invoking @command{guix refresh}
3310
3311The primary audience of the @command{guix refresh} command is developers
3312of the GNU software distribution. By default, it reports any packages
3313provided by the distribution that are outdated compared to the latest
3314upstream version, like this:
3315
3316@example
3317$ guix refresh
3318gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
3319gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
3320@end example
3321
3322It does so by browsing each package's FTP directory and determining the
3323highest version number of the source tarballs
3324therein@footnote{Currently, this only works for GNU packages.}.
3325
3326When passed @code{--update}, it modifies distribution source files to
3327update the version numbers and source tarball hashes of those packages'
3328recipes (@pxref{Defining Packages}). This is achieved by downloading
3329each package's latest source tarball and its associated OpenPGP
3330signature, authenticating the downloaded tarball against its signature
3331using @command{gpg}, and finally computing its hash. When the public
3332key used to sign the tarball is missing from the user's keyring, an
3333attempt is made to automatically retrieve it from a public key server;
3334when it's successful, the key is added to the user's keyring; otherwise,
3335@command{guix refresh} reports an error.
3336
3337The following options are supported:
3338
3339@table @code
3340
3341@item --update
3342@itemx -u
3343Update distribution source files (package recipes) in place.
081145cf 3344@xref{Defining Packages}, for more information on package definitions.
37166310
LC
3345
3346@item --select=[@var{subset}]
3347@itemx -s @var{subset}
3348Select all the packages in @var{subset}, one of @code{core} or
3349@code{non-core}.
3350
3351The @code{core} subset refers to all the packages at the core of the
3352distribution---i.e., packages that are used to build ``everything
3353else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
3354changing one of these packages in the distribution entails a rebuild of
3355all the others. Thus, such updates are an inconvenience to users in
3356terms of build time or bandwidth used to achieve the upgrade.
3357
3358The @code{non-core} subset refers to the remaining packages. It is
3359typically useful in cases where an update of the core packages would be
3360inconvenient.
3361
3362@end table
3363
3364In addition, @command{guix refresh} can be passed one or more package
3365names, as in this example:
3366
3367@example
4b9b3cbb 3368guix refresh -u emacs idutils gcc-4.8.4
37166310
LC
3369@end example
3370
3371@noindent
3372The command above specifically updates the @code{emacs} and
3373@code{idutils} packages. The @code{--select} option would have no
3374effect in this case.
3375
7d193ec3
EB
3376When considering whether to upgrade a package, it is sometimes
3377convenient to know which packages would be affected by the upgrade and
3378should be checked for compatibility. For this the following option may
3379be used when passing @command{guix refresh} one or more package names:
3380
3381@table @code
3382
3383@item --list-dependent
3384@itemx -l
3385List top-level dependent packages that would need to be rebuilt as a
3386result of upgrading one or more packages.
3387
3388@end table
3389
3390Be aware that the @code{--list-dependent} option only
3391@emph{approximates} the rebuilds that would be required as a result of
3392an upgrade. More rebuilds might be required under some circumstances.
3393
3394@example
7779ab61
LC
3395$ guix refresh --list-dependent flex
3396Building the following 120 packages would ensure 213 dependent packages are rebuilt:
3397hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
3398@end example
3399
3400The command above lists a set of packages that could be built to check
3401for compatibility with an upgraded @code{flex} package.
3402
f9230085
LC
3403The following options can be used to customize GnuPG operation:
3404
3405@table @code
3406
f9230085
LC
3407@item --gpg=@var{command}
3408Use @var{command} as the GnuPG 2.x command. @var{command} is searched
3409for in @code{$PATH}.
3410
2bc53ba9
LC
3411@item --key-download=@var{policy}
3412Handle missing OpenPGP keys according to @var{policy}, which may be one
3413of:
3414
3415@table @code
3416@item always
3417Always download missing OpenPGP keys from the key server, and add them
3418to the user's GnuPG keyring.
3419
3420@item never
3421Never try to download missing OpenPGP keys. Instead just bail out.
3422
3423@item interactive
3424When a package signed with an unknown OpenPGP key is encountered, ask
3425the user whether to download it or not. This is the default behavior.
3426@end table
3427
3428@item --key-server=@var{host}
3429Use @var{host} as the OpenPGP key server when importing a public key.
3430
f9230085
LC
3431@end table
3432
b4f5e0e8
CR
3433@node Invoking guix lint
3434@section Invoking @command{guix lint}
3435The @command{guix lint} is meant to help package developers avoid common
873c4085
LC
3436errors and use a consistent style. It runs a number of checks on a
3437given set of packages in order to find common mistakes in their
3438definitions. Available @dfn{checkers} include (see
3439@code{--list-checkers} for a complete list):
3440
3441@table @code
3442@item synopsis
3443@itemx description
3444Validate certain typographical and stylistic rules about package
3445descriptions and synopses.
3446
3447@item inputs-should-be-native
3448Identify inputs that should most likely be native inputs.
3449
3450@item source
3451@itemx home-page
3452Probe @code{home-page} and @code{source} URLs and report those that are
3453invalid.
3454@end table
b4f5e0e8
CR
3455
3456The general syntax is:
3457
3458@example
3459guix lint @var{options} @var{package}@dots{}
3460@end example
3461
3462If no package is given on the command line, then all packages are checked.
3463The @var{options} may be zero or more of the following:
3464
3465@table @code
3466
dd7c013d
CR
3467@item --checkers
3468@itemx -c
3469Only enable the checkers specified in a comma-separated list using the
3470names returned by @code{--list-checkers}.
3471
b4f5e0e8
CR
3472@item --list-checkers
3473@itemx -l
3474List and describe all the available checkers that will be run on packages
3475and exit.
3476
3477@end table
37166310 3478
372c4bbc
DT
3479@node Invoking guix environment
3480@section Invoking @command{guix environment}
3481
f5fd4fd2 3482@cindex reproducible build environments
372c4bbc
DT
3483The purpose of @command{guix environment} is to assist hackers in
3484creating reproducible development environments without polluting their
3485package profile. The @command{guix environment} tool takes one or more
3486packages, builds all of the necessary inputs, and creates a shell
3487environment to use them.
3488
3489The general syntax is:
3490
3491@example
3492guix environment @var{options} @var{package}@dots{}
3493@end example
3494
3495The following examples spawns a new shell that is capable of building
3496the GNU Guile source code:
3497
3498@example
3499guix environment guile
3500@end example
3501
3502If the specified packages are not built yet, @command{guix environment}
3503automatically builds them. The new shell's environment is an augmented
3504version of the environment that @command{guix environment} was run in.
3505It contains the necessary search paths for building the given package
3506added to the existing environment variables. To create a ``pure''
3507environment in which the original environment variables have been unset,
3508use the @code{--pure} option.
3509
3510Additionally, more than one package may be specified, in which case the
3511union of the inputs for the given packages are used. For example, the
3512command below spawns a shell where all of the dependencies of both Guile
3513and Emacs are available:
3514
3515@example
3516guix environment guile emacs
3517@end example
3518
3519Sometimes an interactive shell session is not desired. The
3520@code{--exec} option can be used to specify the command to run instead.
3521
3522@example
3523guix environment guile --exec=make
3524@end example
3525
3526The following options are available:
3527
3528@table @code
3529@item --expression=@var{expr}
3530@itemx -e @var{expr}
3531Create an environment for the package that @var{expr} evaluates to.
3532
3533@item --load=@var{file}
3534@itemx -l @var{file}
3535Create an environment for the package that the code within @var{file}
3536evaluates to.
3537
3538@item --exec=@var{command}
3539@item -E @var{command}
3540Execute @var{command} in the new environment.
3541
3542@item --pure
3543Unset existing environment variables when building the new environment.
3544This has the effect of creating an environment in which search paths
3545only contain package inputs.
3546
3547@item --search-paths
3548Display the environment variable definitions that make up the
3549environment.
3550@end table
3551
3552It also supports all of the common build options that @command{guix
3553build} supports (@pxref{Invoking guix build, common build options}).
3554
aff8ce7c
DT
3555@node Invoking guix publish
3556@section Invoking @command{guix publish}
3557
3558The purpose of @command{guix publish} is to enable users to easily share
3559their store with others. When @command{guix publish} runs, it spawns an
3560HTTP server which allows anyone with network access to obtain
3561substitutes from it. This means that any machine running Guix can also
3562act as if it were a build farm, since the HTTP interface is
3563Hydra-compatible.
3564
3565For security, each substitute is signed, allowing recipients to check
3566their authenticity and integrity (@pxref{Substitutes}). Because
3567@command{guix publish} uses the system's signing key, which is only
3568readable by the system administrator, it must run as root.
3569
3570The general syntax is:
3571
3572@example
3573guix publish @var{options}@dots{}
3574@end example
3575
3576Running @command{guix publish} without any additional arguments will
3577spawn an HTTP server on port 8080:
3578
3579@example
3580guix publish
3581@end example
3582
3583Once a publishing server has been authorized (@pxref{Invoking guix
3584archive}), the daemon may download substitutes from it:
3585
3586@example
3587guix-daemon --substitute-urls=http://example.org:8080
3588@end example
3589
3590The following options are available:
3591
3592@table @code
3593@item --port=@var{port}
3594@itemx -p @var{port}
3595Listen for HTTP requests on @var{port}.
3596
3597@item --repl[=@var{port}]
3598@itemx -r [@var{port}]
3599Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile
3600Reference Manual}) on @var{port} (37146 by default).
3601@end table
3602
a1ba8475
LC
3603@c *********************************************************************
3604@node GNU Distribution
3605@chapter GNU Distribution
3606
3ca2731c
LC
3607@cindex Guix System Distribution
3608@cindex GSD
3609Guix comes with a distribution of the GNU system consisting entirely of
3610free software@footnote{The term ``free'' here refers to the
a1ba8475 3611@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
3ca2731c 3612users of that software}.}. The
35ed9306
LC
3613distribution can be installed on its own (@pxref{System Installation}),
3614but it is also possible to install Guix as a package manager on top of
3615an installed GNU/Linux system (@pxref{Installation}). To distinguish
3ca2731c
LC
3616between the two, we refer to the standalone distribution as the Guix
3617System Distribution, or GNU@tie{}GSD.
35ed9306
LC
3618
3619The distribution provides core GNU packages such as GNU libc, GCC, and
3620Binutils, as well as many GNU and non-GNU applications. The complete
3621list of available packages can be browsed
d03bb653
LC
3622@url{http://www.gnu.org/software/guix/package-list.html,on-line} or by
3623running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
3624
3625@example
e49951eb 3626guix package --list-available
a1ba8475
LC
3627@end example
3628
35ed9306 3629Our goal has been to provide a practical 100% free software distribution of
401c53c4
LC
3630Linux-based and other variants of GNU, with a focus on the promotion and
3631tight integration of GNU components, and an emphasis on programs and
3632tools that help users exert that freedom.
3633
3ca2731c 3634Packages are currently available on the following platforms:
c320011d
LC
3635
3636@table @code
3637
3638@item x86_64-linux
3639Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
3640
3641@item i686-linux
3642Intel 32-bit architecture (IA32), Linux-Libre kernel;
3643
aa1e1947
MW
3644@item armhf-linux
3645ARMv7-A architecture with hard float, Thumb-2 and VFP3D16 coprocessor,
3646using the EABI hard-float ABI, and Linux-Libre kernel.
3647
c320011d
LC
3648@item mips64el-linux
3649little-endian 64-bit MIPS processors, specifically the Loongson series,
3650n32 application binary interface (ABI), and Linux-Libre kernel.
3651
3652@end table
3653
3ca2731c
LC
3654GSD itself is currently only available on @code{i686} and @code{x86_64}.
3655
c320011d
LC
3656@noindent
3657For information on porting to other architectures or kernels,
3658@xref{Porting}.
3659
401c53c4 3660@menu
5af6de3e 3661* System Installation:: Installing the whole operating system.
35ed9306 3662* System Configuration:: Configuring the operating system.
91ef73d4 3663* Installing Debugging Files:: Feeding the debugger.
05962f29 3664* Security Updates:: Deploying security fixes quickly.
401c53c4 3665* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 3666* Packaging Guidelines:: Growing the distribution.
401c53c4 3667* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 3668* Porting:: Targeting another platform or kernel.
401c53c4
LC
3669@end menu
3670
3671Building this distribution is a cooperative effort, and you are invited
081145cf 3672to join! @xref{Contributing}, for information about how you can help.
401c53c4 3673
5af6de3e
LC
3674@node System Installation
3675@section System Installation
3676
3ca2731c
LC
3677@cindex Guix System Distribution
3678This section explains how to install the Guix System Distribution
3679on a machine. The Guix package manager can
35ed9306
LC
3680also be installed on top of a running GNU/Linux system,
3681@pxref{Installation}.
5af6de3e
LC
3682
3683@ifinfo
3684@c This paragraph is for people reading this from tty2 of the
3685@c installation image.
3686You're reading this documentation with an Info reader. For details on
3687how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 3688link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
3689@kbd{l} afterwards to come back here.
3690@end ifinfo
3691
8aaaae38
LC
3692@subsection Limitations
3693
3ca2731c
LC
3694As of version @value{VERSION}, the Guix System Distribution (GSD) is
3695not production-ready. It may contain bugs and lack important
8aaaae38
LC
3696features. Thus, if you are looking for a stable production system that
3697respects your freedom as a computer user, a good solution at this point
3698is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
3699more established GNU/Linux distributions}. We hope you can soon switch
3ca2731c 3700to the GSD without fear, of course. In the meantime, you can
8aaaae38
LC
3701also keep using your distribution and try out the package manager on top
3702of it (@pxref{Installation}).
3703
3704Before you proceed with the installation, be aware of the following
3705noteworthy limitations applicable to version @value{VERSION}:
3706
3707@itemize
3708@item
3709The installation process does not include a graphical user interface and
3710requires familiarity with GNU/Linux (see the following subsections to
3711get a feel of what that means.)
3712
3713@item
b1e95eca
LC
3714The system does not yet provide GNOME and KDE; it provides Xfce, though,
3715if graphical desktop environments are your thing.
8aaaae38
LC
3716
3717@item
dbcb0ab1 3718Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
3719
3720@item
3721Few system services are currently supported out-of-the-box
3722(@pxref{Services}).
3723
3724@item
b1e95eca 3725On the order of 1,200 packages are available, which means that you may
8aaaae38
LC
3726occasionally find that a useful package is missing.
3727@end itemize
3728
3729You've been warned. But more than a disclaimer, this is an invitation
3730to report issues (and success stories!), and join us in improving it.
3731@xref{Contributing}, for more info.
5af6de3e
LC
3732
3733@subsection USB Stick Installation
3734
3735An installation image for USB sticks can be downloaded from
ab3872de 3736@code{ftp://alpha.gnu.org/gnu/guix/gsd-usb-install-@value{VERSION}.@var{system}.xz},
5af6de3e
LC
3737where @var{system} is one of:
3738
3739@table @code
3740@item x86_64-linux
3741for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
3742
3743@item i686-linux
3744for a 32-bit GNU/Linux system on Intel-compatible CPUs.
3745@end table
3746
3747This image contains a single partition with the tools necessary for an
3748installation. It is meant to be copied @emph{as is} to a large-enough
3749USB stick.
3750
3751To copy the image to a USB stick, follow these steps:
3752
3753@enumerate
3754@item
3755Decompress the image using the @command{xz} command:
3756
3757@example
3a5d914b 3758xz -d gsd-usb-install-@value{VERSION}.@var{system}.xz
5af6de3e
LC
3759@end example
3760
3761@item
3762Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
3763its device name. Assuming that USB stick is known as @file{/dev/sdX},
3764copy the image with:
3765
3766@example
3a5d914b 3767dd if=gsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
3768@end example
3769
3770Access to @file{/dev/sdX} usually requires root privileges.
3771@end enumerate
3772
3773Once this is done, you should be able to reboot the system and boot from
3774the USB stick. The latter usually requires you to get in the BIOS' boot
3775menu, where you can choose to boot from the USB stick.
3776
3777@subsection Preparing for Installation
3778
3779Once you have successfully booted the image on the USB stick, you should
3780end up with a root prompt. Several console TTYs are configured and can
3781be used to run commands as root. TTY2 shows this documentation,
3782browsable using the Info reader commands (@pxref{Help,,, info, Info: An
3783Introduction}).
3784
3785To install the system, you would:
3786
3787@enumerate
3788
3789@item
95c559c1 3790Configure the network, by running @command{dhclient eno1} (to get an
5af6de3e 3791automatically assigned IP address from the wired network interface
95c559c1
LC
3792controller@footnote{
3793@c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20
3794The name @code{eno1} is for the first on-board Ethernet controller. The
3795interface name for an Ethernet controller that is in the first slot of
3796the first PCI bus, for instance, would be @code{enp1s0}. Use
3797@command{ifconfig -a} to list all the available network interfaces.}),
3798or using the @command{ifconfig} command.
5af6de3e
LC
3799
3800The system automatically loads drivers for your network interface
3801controllers.
3802
3803Setting up network access is almost always a requirement because the
3804image does not contain all the software and tools that may be needed.
3805
3806@item
3807Unless this has already been done, you must partition and format the
3808target partitions.
3809
7ab44369
LC
3810Preferably, assign partitions a label so that you can easily and
3811reliably refer to them in @code{file-system} declarations (@pxref{File
3812Systems}). This is typically done using the @code{-L} option of
3813@command{mkfs.ext4} and related commands.
3814
5af6de3e 3815The installation image includes Parted (@pxref{Overview,,, parted, GNU
b419c7f5
LC
3816Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk
3817encryption, and e2fsprogs, the suite of tools to manipulate
3818ext2/ext3/ext4 file systems.
5af6de3e 3819
83a17b62
LC
3820@item
3821Once that is done, mount the target root partition under @file{/mnt}.
3822
3823@item
3824Lastly, run @code{deco start cow-store /mnt}.
3825
3826This will make @file{/gnu/store} copy-on-write, such that packages added
3827to it during the installation phase will be written to the target disk
3828rather than kept in memory.
3829
5af6de3e
LC
3830@end enumerate
3831
5af6de3e
LC
3832
3833@subsection Proceeding with the Installation
3834
3835With the target partitions ready, you now have to edit a file and
3836provide the declaration of the operating system to be installed. To
3837that end, the installation system comes with two text editors: GNU nano
3838(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
3839It is better to store that file on the target root file system, say, as
3840@file{/mnt/etc/config.scm}.
3841
3842A minimal operating system configuration, with just the bare minimum and
1dac8566
LC
3843only a root account would look like this (on the installation system,
3844this example is available as @file{/etc/configuration-template.scm}):
5af6de3e
LC
3845
3846@example
931c132a 3847@include os-config.texi
5af6de3e
LC
3848@end example
3849
3850@noindent
3851For more information on @code{operating-system} declarations,
6621cdb6 3852@pxref{Using the Configuration System}.
5af6de3e
LC
3853
3854Once that is done, the new system must be initialized (remember that the
3855target root file system is mounted under @file{/mnt}):
3856
3857@example
3858guix system init /mnt/etc/config.scm /mnt
3859@end example
3860
3861@noindent
3862This will copy all the necessary files, and install GRUB on
3863@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 3864more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
3865downloads or builds of missing packages, which can take some time.
3866
3867Once that command has completed---and hopefully succeeded!---you can
ad14d9e7 3868run @command{reboot} and boot into the new system. Cross fingers, and
5af6de3e
LC
3869join us on @code{#guix} on the Freenode IRC network or on
3870@file{guix-devel@@gnu.org} to share your experience---good or not so
3871good.
3872
3873@subsection Building the Installation Image
3874
3875The installation image described above was built using the @command{guix
3876system} command, specifically:
3877
3878@example
8a225c66 3879guix system disk-image --image-size=850MiB gnu/system/install.scm
5af6de3e
LC
3880@end example
3881
3882@xref{Invoking guix system}, for more information. See
3883@file{gnu/system/install.scm} in the source tree for more information
3884about the installation image.
3885
cf4a9129
LC
3886@node System Configuration
3887@section System Configuration
b208a005 3888
cf4a9129 3889@cindex system configuration
3ca2731c 3890The Guix System Distribution supports a consistent whole-system configuration
cf4a9129
LC
3891mechanism. By that we mean that all aspects of the global system
3892configuration---such as the available system services, timezone and
3893locale settings, user accounts---are declared in a single place. Such
3894a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 3895
cf4a9129
LC
3896One of the advantages of putting all the system configuration under the
3897control of Guix is that it supports transactional system upgrades, and
3898makes it possible to roll-back to a previous system instantiation,
3899should something go wrong with the new one (@pxref{Features}). Another
3900one is that it makes it easy to replicate the exact same configuration
3901across different machines, or at different points in time, without
3902having to resort to additional administration tools layered on top of
3903the system's own tools.
3904@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 3905
cf4a9129
LC
3906This section describes this mechanism. First we focus on the system
3907administrator's viewpoint---explaining how the system is configured and
3908instantiated. Then we show how this mechanism can be extended, for
3909instance to support new system services.
91ef73d4 3910
cf4a9129
LC
3911@menu
3912* Using the Configuration System:: Customizing your GNU system.
7313a52e 3913* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 3914* File Systems:: Configuring file system mounts.
510f9d86 3915* Mapped Devices:: Block device extra processing.
cf4a9129 3916* User Accounts:: Specifying user accounts.
598e19dc 3917* Locales:: Language and cultural convention settings.
cf4a9129 3918* Services:: Specifying system services.
0ae8c15a 3919* Setuid Programs:: Programs running with root privileges.
996ed739 3920* Name Service Switch:: Configuring libc's name service switch.
fd1b1fa2 3921* Initial RAM Disk:: Linux-Libre bootstrapping.
88faf933 3922* GRUB Configuration:: Configuring the boot loader.
cf4a9129
LC
3923* Invoking guix system:: Instantiating a system configuration.
3924* Defining Services:: Adding new service definitions.
3925@end menu
91ef73d4 3926
cf4a9129
LC
3927@node Using the Configuration System
3928@subsection Using the Configuration System
64d76fa6 3929
cf4a9129
LC
3930The operating system is configured by providing an
3931@code{operating-system} declaration in a file that can then be passed to
3932the @command{guix system} command (@pxref{Invoking guix system}). A
3933simple setup, with the default system services, the default Linux-Libre
3934kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 3935
cf4a9129
LC
3936@findex operating-system
3937@lisp
3938(use-modules (gnu) ; for 'user-account', '%base-services', etc.
3939 (gnu packages emacs) ; for 'emacs'
3940 (gnu services ssh)) ; for 'lsh-service'
91ef73d4 3941
cf4a9129
LC
3942(operating-system
3943 (host-name "komputilo")
3944 (timezone "Europe/Paris")
598e19dc 3945 (locale "fr_FR.utf8")
cf4a9129
LC
3946 (bootloader (grub-configuration
3947 (device "/dev/sda")))
a69576ea 3948 (file-systems (cons (file-system
cf4a9129
LC
3949 (device "/dev/sda1") ; or partition label
3950 (mount-point "/")
a69576ea
LC
3951 (type "ext3"))
3952 %base-file-systems))
cf4a9129
LC
3953 (users (list (user-account
3954 (name "alice")
bc73aa43 3955 (group "users")
cf4a9129
LC
3956 (comment "Bob's sister")
3957 (home-directory "/home/alice"))))
3958 (packages (cons emacs %base-packages))
21cc905a 3959 (services (cons (lsh-service #:port 2222 #:root-login? #t)
cf4a9129
LC
3960 %base-services)))
3961@end lisp
401c53c4 3962
cf4a9129
LC
3963This example should be self-describing. Some of the fields defined
3964above, such as @code{host-name} and @code{bootloader}, are mandatory.
3965Others, such as @code{packages} and @code{services}, can be omitted, in
3966which case they get a default value.
e7f34eb0 3967
cf4a9129
LC
3968@vindex %base-packages
3969The @code{packages} field lists
3970packages that will be globally visible on the system, for all user
3971accounts---i.e., in every user's @code{PATH} environment variable---in
3972addition to the per-user profiles (@pxref{Invoking guix package}). The
3973@var{%base-packages} variable provides all the tools one would expect
3974for basic user and administrator tasks---including the GNU Core
3975Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
3976editor, @command{find}, @command{grep}, etc. The example above adds
3977Emacs to those, taken from the @code{(gnu packages emacs)} module
3978(@pxref{Package Modules}).
e7f34eb0 3979
cf4a9129
LC
3980@vindex %base-services
3981The @code{services} field lists @dfn{system services} to be made
3982available when the system starts (@pxref{Services}).
3983The @code{operating-system} declaration above specifies that, in
3984addition to the basic services, we want the @command{lshd} secure shell
3985daemon listening on port 2222, and allowing remote @code{root} logins
3986(@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
3987@code{lsh-service} arranges so that @code{lshd} is started with the
3988right command-line options, possibly with supporting configuration files
7313a52e
LC
3989generated as needed (@pxref{Defining Services}). @xref{operating-system
3990Reference}, for details about the available @code{operating-system}
3991fields.
a1ba8475 3992
cf4a9129
LC
3993Assuming the above snippet is stored in the @file{my-system-config.scm}
3994file, the @command{guix system reconfigure my-system-config.scm} command
3995instantiates that configuration, and makes it the default GRUB boot
3996entry (@pxref{Invoking guix system}). The normal way to change the
3997system's configuration is by updating this file and re-running the
3998@command{guix system} command.
b81e1947 3999
cf4a9129
LC
4000At the Scheme level, the bulk of an @code{operating-system} declaration
4001is instantiated with the following monadic procedure (@pxref{The Store
4002Monad}):
b81e1947 4003
cf4a9129
LC
4004@deffn {Monadic Procedure} operating-system-derivation os
4005Return a derivation that builds @var{os}, an @code{operating-system}
4006object (@pxref{Derivations}).
b81e1947 4007
cf4a9129
LC
4008The output of the derivation is a single directory that refers to all
4009the packages, configuration files, and other supporting files needed to
4010instantiate @var{os}.
4011@end deffn
b81e1947 4012
7313a52e
LC
4013@node operating-system Reference
4014@subsection @code{operating-system} Reference
4015
4016This section summarizes all the options available in
4017@code{operating-system} declarations (@pxref{Using the Configuration
4018System}).
4019
4020@deftp {Data Type} operating-system
4021This is the data type representing an operating system configuration.
4022By that, we mean all the global system configuration, not per-user
4023configuration (@pxref{Using the Configuration System}).
4024
4025@table @asis
4026@item @code{kernel} (default: @var{linux-libre})
4027The package object of the operating system to use@footnote{Currently
4028only the Linux-libre kernel is supported. In the future, it will be
4029possible to use the GNU@tie{}Hurd.}.
4030
4031@item @code{bootloader}
88faf933 4032The system bootloader configuration object. @xref{GRUB Configuration}.
7313a52e
LC
4033
4034@item @code{initrd} (default: @code{base-initrd})
4035A two-argument monadic procedure that returns an initial RAM disk for
4036the Linux kernel. @xref{Initial RAM Disk}.
4037
f34c56be
LC
4038@item @code{firmware} (default: @var{%base-firmware})
4039@cindex firmware
4040List of firmware packages loadable by the operating system kernel.
4041
4042The default includes firmware needed for Atheros-based WiFi devices
4043(Linux-libre module @code{ath9k}.)
4044
7313a52e
LC
4045@item @code{host-name}
4046The host name.
4047
4048@item @code{hosts-file}
4049@cindex hosts file
4050A zero-argument monadic procedure that returns a text file for use as
4051@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
4052Reference Manual}). The default is to produce a file with entries for
4053@code{localhost} and @var{host-name}.
4054
4055@item @code{mapped-devices} (default: @code{'()})
4056A list of mapped devices. @xref{Mapped Devices}.
4057
4058@item @code{file-systems}
4059A list of file systems. @xref{File Systems}.
4060
4061@item @code{swap-devices} (default: @code{'()})
4062@cindex swap devices
4063A list of strings identifying devices to be used for ``swap space''
4064(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
4065For example, @code{'("/dev/sda3")}.
4066
4067@item @code{users} (default: @code{'()})
4068@itemx @code{groups} (default: @var{%base-groups})
4069List of user accounts and groups. @xref{User Accounts}.
4070
4071@item @code{skeletons} (default: @code{(default-skeletons)})
4072A monadic list of pairs of target file name and files. These are the
4073files that will be used as skeletons as new accounts are created.
4074
4075For instance, a valid value may look like this:
4076
4077@example
4078(mlet %store-monad ((bashrc (text-file "bashrc" "\
4079 export PATH=$HOME/.guix-profile/bin")))
4080 (return `((".bashrc" ,bashrc))))
4081@end example
4082
4083@item @code{issue} (default: @var{%default-issue})
4084A string denoting the contents of the @file{/etc/issue} file, which is
4085what displayed when users log in on a text console.
4086
4087@item @code{packages} (default: @var{%base-packages})
4088The set of packages installed in the global profile, which is accessible
4089at @file{/run/current-system/profile}.
4090
4091The default set includes core utilities, but it is good practice to
4092install non-core utilities in user profiles (@pxref{Invoking guix
4093package}).
4094
4095@item @code{timezone}
4096A timezone identifying string---e.g., @code{"Europe/Paris"}.
4097
598e19dc
LC
4098@item @code{locale} (default: @code{"en_US.utf8"})
4099The name of the default locale (@pxref{Locale Names,,, libc, The GNU C
4100Library Reference Manual}). @xref{Locales}, for more information.
4101
4102@item @code{locale-definitions} (default: @var{%default-locale-definitions})
4103The list of locale definitions to be compiled and that may be used at
4104run time. @xref{Locales}.
7313a52e 4105
996ed739
LC
4106@item @code{name-service-switch} (default: @var{%default-nss})
4107Configuration of libc's name service switch (NSS)---a
4108@code{<name-service-switch>} object. @xref{Name Service Switch}, for
4109details.
4110
7313a52e
LC
4111@item @code{services} (default: @var{%base-services})
4112A list of monadic values denoting system services. @xref{Services}.
4113
4114@item @code{pam-services} (default: @code{(base-pam-services)})
4115@cindex PAM
4116@cindex pluggable authentication modules
4117Linux @dfn{pluggable authentication module} (PAM) services.
4118@c FIXME: Add xref to PAM services section.
4119
4120@item @code{setuid-programs} (default: @var{%setuid-programs})
4121List of string-valued G-expressions denoting setuid programs.
4122@xref{Setuid Programs}.
4123
4124@item @code{sudoers} (default: @var{%sudoers-specification})
4125@cindex sudoers
4126The contents of the @file{/etc/sudoers} file as a string.
4127
4128This file specifies which users can use the @command{sudo} command, what
4129they are allowed to do, and what privileges they may gain. The default
4130is that only @code{root} and members of the @code{wheel} group may use
4131@code{sudo}.
4132
4133@end table
4134@end deftp
4135
cf4a9129
LC
4136@node File Systems
4137@subsection File Systems
b81e1947 4138
cf4a9129
LC
4139The list of file systems to be mounted is specified in the
4140@code{file-systems} field of the operating system's declaration
4141(@pxref{Using the Configuration System}). Each file system is declared
4142using the @code{file-system} form, like this:
b81e1947
LC
4143
4144@example
cf4a9129
LC
4145(file-system
4146 (mount-point "/home")
4147 (device "/dev/sda3")
4148 (type "ext4"))
b81e1947
LC
4149@end example
4150
cf4a9129
LC
4151As usual, some of the fields are mandatory---those shown in the example
4152above---while others can be omitted. These are described below.
b81e1947 4153
cf4a9129
LC
4154@deftp {Data Type} file-system
4155Objects of this type represent file systems to be mounted. They
4156contain the following members:
5ff3c4b8 4157
cf4a9129
LC
4158@table @asis
4159@item @code{type}
4160This is a string specifying the type of the file system---e.g.,
4161@code{"ext4"}.
5ff3c4b8 4162
cf4a9129
LC
4163@item @code{mount-point}
4164This designates the place where the file system is to be mounted.
b81e1947 4165
cf4a9129
LC
4166@item @code{device}
4167This names the ``source'' of the file system. By default it is the name
4168of a node under @file{/dev}, but its meaning depends on the @code{title}
4169field described below.
401c53c4 4170
cf4a9129
LC
4171@item @code{title} (default: @code{'device})
4172This is a symbol that specifies how the @code{device} field is to be
4173interpreted.
401c53c4 4174
cf4a9129
LC
4175When it is the symbol @code{device}, then the @code{device} field is
4176interpreted as a file name; when it is @code{label}, then @code{device}
4177is interpreted as a partition label name; when it is @code{uuid},
4178@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 4179
cf4a9129
LC
4180The @code{label} and @code{uuid} options offer a way to refer to disk
4181partitions without having to hard-code their actual device name.
da7cabd4 4182
5f86a66e
LC
4183However, when a file system's source is a mapped device (@pxref{Mapped
4184Devices}), its @code{device} field @emph{must} refer to the mapped
4185device name---e.g., @file{/dev/mapper/root-partition}---and consequently
4186@code{title} must be set to @code{'device}. This is required so that
4187the system knows that mounting the file system depends on having the
4188corresponding device mapping established.
4189
cf4a9129
LC
4190@item @code{flags} (default: @code{'()})
4191This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
4192include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
4193access to special files), @code{no-suid} (ignore setuid and setgid
4194bits), and @code{no-exec} (disallow program execution.)
da7cabd4 4195
cf4a9129
LC
4196@item @code{options} (default: @code{#f})
4197This is either @code{#f}, or a string denoting mount options.
da7cabd4 4198
cf4a9129
LC
4199@item @code{needed-for-boot?} (default: @code{#f})
4200This Boolean value indicates whether the file system is needed when
4201booting. If that is true, then the file system is mounted when the
4202initial RAM disk (initrd) is loaded. This is always the case, for
4203instance, for the root file system.
da7cabd4 4204
cf4a9129
LC
4205@item @code{check?} (default: @code{#t})
4206This Boolean indicates whether the file system needs to be checked for
4207errors before being mounted.
f9cc8971 4208
4e469051
LC
4209@item @code{create-mount-point?} (default: @code{#f})
4210When true, the mount point is created if it does not exist yet.
4211
cf4a9129
LC
4212@end table
4213@end deftp
da7cabd4 4214
a69576ea
LC
4215The @code{(gnu system file-systems)} exports the following useful
4216variables.
4217
4218@defvr {Scheme Variable} %base-file-systems
4219These are essential file systems that are required on normal systems,
4220such as @var{%devtmpfs-file-system} (see below.) Operating system
4221declarations should always contain at least these.
4222@end defvr
4223
4224@defvr {Scheme Variable} %devtmpfs-file-system
4225The @code{devtmpfs} file system to be mounted on @file{/dev}. This is a
4226requirement for udev (@pxref{Base Services, @code{udev-service}}).
4227@end defvr
4228
7f239fd3
LC
4229@defvr {Scheme Variable} %pseudo-terminal-file-system
4230This is the file system to be mounted as @file{/dev/pts}. It supports
4231@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
4232functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
4233Manual}). Pseudo-terminals are used by terminal emulators such as
4234@command{xterm}.
4235@end defvr
4236
db17ae5c
LC
4237@defvr {Scheme Variable} %shared-memory-file-system
4238This file system is mounted as @file{/dev/shm} and is used to support
4239memory sharing across processes (@pxref{Memory-mapped I/O,
4240@code{shm_open},, libc, The GNU C Library Reference Manual}).
4241@end defvr
4242
a69576ea
LC
4243@defvr {Scheme Variable} %binary-format-file-system
4244The @code{binfmt_misc} file system, which allows handling of arbitrary
4245executable file types to be delegated to user space. This requires the
4246@code{binfmt.ko} kernel module to be loaded.
4247@end defvr
4248
4249@defvr {Scheme Variable} %fuse-control-file-system
4250The @code{fusectl} file system, which allows unprivileged users to mount
4251and unmount user-space FUSE file systems. This requires the
4252@code{fuse.ko} kernel module to be loaded.
4253@end defvr
4254
510f9d86
LC
4255@node Mapped Devices
4256@subsection Mapped Devices
4257
4258@cindex device mapping
4259@cindex mapped devices
4260The Linux kernel has a notion of @dfn{device mapping}: a block device,
4261such as a hard disk partition, can be @dfn{mapped} into another device,
4262with additional processing over the data that flows through
4263it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
4264concept of a ``mapped device'' and that of a file system: both boil down
4265to @emph{translating} input/output operations made on a file to
4266operations on its backing store. Thus, the Hurd implements mapped
4267devices, like file systems, using the generic @dfn{translator} mechanism
4268(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
4269typical example is encryption device mapping: all writes to the mapped
4270device are encrypted, and all reads are deciphered, transparently.
4271
4272Mapped devices are declared using the @code{mapped-device} form:
4273
4274@example
4275(mapped-device
4276 (source "/dev/sda3")
4277 (target "home")
4278 (type luks-device-mapping))
4279@end example
4280
4281@noindent
4282@cindex disk encryption
4283@cindex LUKS
4284This example specifies a mapping from @file{/dev/sda3} to
4285@file{/dev/mapper/home} using LUKS---the
4286@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
4287standard mechanism for disk encryption. The @file{/dev/mapper/home}
4288device can then be used as the @code{device} of a @code{file-system}
4289declaration (@pxref{File Systems}). The @code{mapped-device} form is
4290detailed below.
4291
4292@deftp {Data Type} mapped-device
4293Objects of this type represent device mappings that will be made when
4294the system boots up.
4295
9cb426b8
LC
4296@table @code
4297@item source
510f9d86
LC
4298This string specifies the name of the block device to be mapped, such as
4299@code{"/dev/sda3"}.
4300
9cb426b8 4301@item target
510f9d86
LC
4302This string specifies the name of the mapping to be established. For
4303example, specifying @code{"my-partition"} will lead to the creation of
4304the @code{"/dev/mapper/my-partition"} device.
4305
9cb426b8 4306@item type
510f9d86
LC
4307This must be a @code{mapped-device-kind} object, which specifies how
4308@var{source} is mapped to @var{target}.
4309@end table
4310@end deftp
4311
4312@defvr {Scheme Variable} luks-device-mapping
4313This defines LUKS block device encryption using the @command{cryptsetup}
4314command, from the same-named package. This relies on the
4315@code{dm-crypt} Linux kernel module.
4316@end defvr
4317
cf4a9129
LC
4318@node User Accounts
4319@subsection User Accounts
ee85f3db 4320
9bea87a5
LC
4321User accounts and groups are entirely managed through the
4322@code{operating-system} declaration. They are specified with the
4323@code{user-account} and @code{user-group} forms:
ee85f3db 4324
cf4a9129
LC
4325@example
4326(user-account
4327 (name "alice")
4328 (group "users")
24e752c0
LC
4329 (supplementary-groups '("wheel" ;allow use of sudo, etc.
4330 "audio" ;sound card
4331 "video" ;video devices such as webcams
4332 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
4333 (comment "Bob's sister")
4334 (home-directory "/home/alice"))
4335@end example
25083588 4336
9bea87a5
LC
4337When booting or upon completion of @command{guix system reconfigure},
4338the system ensures that only the user accounts and groups specified in
4339the @code{operating-system} declaration exist, and with the specified
4340properties. Thus, account or group creations or modifications made by
4341directly invoking commands such as @command{useradd} are lost upon
4342reconfiguration or reboot. This ensures that the system remains exactly
4343as declared.
4344
cf4a9129
LC
4345@deftp {Data Type} user-account
4346Objects of this type represent user accounts. The following members may
4347be specified:
ee85f3db 4348
cf4a9129
LC
4349@table @asis
4350@item @code{name}
4351The name of the user account.
ee85f3db 4352
cf4a9129
LC
4353@item @code{group}
4354This is the name (a string) or identifier (a number) of the user group
4355this account belongs to.
ee85f3db 4356
cf4a9129
LC
4357@item @code{supplementary-groups} (default: @code{'()})
4358Optionally, this can be defined as a list of group names that this
4359account belongs to.
ee85f3db 4360
cf4a9129
LC
4361@item @code{uid} (default: @code{#f})
4362This is the user ID for this account (a number), or @code{#f}. In the
4363latter case, a number is automatically chosen by the system when the
4364account is created.
ee85f3db 4365
cf4a9129
LC
4366@item @code{comment} (default: @code{""})
4367A comment about the account, such as the account's owner full name.
c8c871d1 4368
cf4a9129
LC
4369@item @code{home-directory}
4370This is the name of the home directory for the account.
ee85f3db 4371
cf4a9129
LC
4372@item @code{shell} (default: Bash)
4373This is a G-expression denoting the file name of a program to be used as
4374the shell (@pxref{G-Expressions}).
ee85f3db 4375
cf4a9129
LC
4376@item @code{system?} (default: @code{#f})
4377This Boolean value indicates whether the account is a ``system''
4378account. System accounts are sometimes treated specially; for instance,
4379graphical login managers do not list them.
ee85f3db 4380
cf4a9129 4381@item @code{password} (default: @code{#f})
eb59595c
LC
4382You would normally leave this field to @code{#f}, initialize user
4383passwords as @code{root} with the @command{passwd} command, and then let
9bea87a5
LC
4384users change it with @command{passwd}. Passwords set with
4385@command{passwd} are of course preserved across reboot and
4386reconfiguration.
eb59595c
LC
4387
4388If you @emph{do} want to have a preset password for an account, then
4389this field must contain the encrypted password, as a string.
5d1f1177
LC
4390@xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information
4391on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference
eb59595c 4392Manual}, for information on Guile's @code{crypt} procedure.
c8c871d1 4393
cf4a9129
LC
4394@end table
4395@end deftp
ee85f3db 4396
cf4a9129 4397User group declarations are even simpler:
ee85f3db 4398
cf4a9129
LC
4399@example
4400(user-group (name "students"))
4401@end example
ee85f3db 4402
cf4a9129
LC
4403@deftp {Data Type} user-group
4404This type is for, well, user groups. There are just a few fields:
af8a56b8 4405
cf4a9129
LC
4406@table @asis
4407@item @code{name}
4408The group's name.
ee85f3db 4409
cf4a9129
LC
4410@item @code{id} (default: @code{#f})
4411The group identifier (a number). If @code{#f}, a new number is
4412automatically allocated when the group is created.
ee85f3db 4413
c8fa3426
LC
4414@item @code{system?} (default: @code{#f})
4415This Boolean value indicates whether the group is a ``system'' group.
4416System groups have low numerical IDs.
4417
cf4a9129
LC
4418@item @code{password} (default: @code{#f})
4419What, user groups can have a password? Well, apparently yes. Unless
4420@code{#f}, this field specifies the group's password.
ee85f3db 4421
cf4a9129
LC
4422@end table
4423@end deftp
401c53c4 4424
cf4a9129
LC
4425For convenience, a variable lists all the basic user groups one may
4426expect:
401c53c4 4427
cf4a9129
LC
4428@defvr {Scheme Variable} %base-groups
4429This is the list of basic user groups that users and/or packages expect
4430to be present on the system. This includes groups such as ``root'',
4431``wheel'', and ``users'', as well as groups used to control access to
4432specific devices such as ``audio'', ``disk'', and ``cdrom''.
4433@end defvr
401c53c4 4434
598e19dc
LC
4435@node Locales
4436@subsection Locales
4437
4438@cindex locale
4439A @dfn{locale} defines cultural conventions for a particular language
4440and region of the world (@pxref{Locales,,, libc, The GNU C Library
4441Reference Manual}). Each locale has a name that typically has the form
4442@code{@var{language}_@var{territory}.@var{charset}}---e.g.,
4443@code{fr_LU.utf8} designates the locale for the French language, with
4444cultural conventions from Luxembourg, and using the UTF-8 encoding.
4445
4446@cindex locale definition
4447Usually, you will want to specify the default locale for the machine
4448using the @code{locale} field of the @code{operating-system} declaration
4449(@pxref{operating-system Reference, @code{locale}}).
4450
4451That locale must be among the @dfn{locale definitions} that are known to
4452the system---and these are specified in the @code{locale-definitions}
4453slot of @code{operating-system}. The default value includes locale
4454definition for some widely used locales, but not for all the available
4455locales, in order to save space.
4456
4457If the locale specified in the @code{locale} field is not among the
4458definitions listed in @code{locale-definitions}, @command{guix system}
4459raises an error. In that case, you should add the locale definition to
4460the @code{locale-definitions} field. For instance, to add the North
4461Frisian locale for Germany, the value of that field may be:
4462
4463@example
4464(cons (locale-definition
4465 (name "fy_DE.utf8") (source "fy_DE"))
4466 %default-locale-definitions)
4467@end example
4468
4469Likewise, to save space, one might want @code{locale-definitions} to
4470list only the locales that are actually used, as in:
4471
4472@example
4473(list (locale-definition
4474 (name "ja_JP.eucjp") (source "ja_JP")
4475 (charset "EUC-JP")))
4476@end example
4477
4478The @code{locale-definition} form is provided by the @code{(gnu system
4479locale)} module. Details are given below.
4480
4481@deftp {Data Type} locale-definition
4482This is the data type of a locale definition.
4483
4484@table @asis
4485
4486@item @code{name}
4487The name of the locale. @xref{Locale Names,,, libc, The GNU C Library
4488Reference Manual}, for more information on locale names.
4489
4490@item @code{source}
4491The name of the source for that locale. This is typically the
4492@code{@var{language}_@var{territory}} part of the locale name.
4493
4494@item @code{charset} (default: @code{"UTF-8"})
4495The ``character set'' or ``code set'' for that locale,
4496@uref{http://www.iana.org/assignments/character-sets, as defined by
4497IANA}.
4498
4499@end table
4500@end deftp
4501
4502@defvr {Scheme Variable} %default-locale-definitions
4503An arbitrary list of commonly used locales, used as the default value of
4504the @code{locale-definitions} field of @code{operating-system}
4505declarations.
4506@end defvr
401c53c4 4507
cf4a9129
LC
4508@node Services
4509@subsection Services
401c53c4 4510
cf4a9129
LC
4511@cindex system services
4512An important part of preparing an @code{operating-system} declaration is
4513listing @dfn{system services} and their configuration (@pxref{Using the
4514Configuration System}). System services are typically daemons launched
4515when the system boots, or other actions needed at that time---e.g.,
d8b94dbd
LC
4516configuring network access.
4517
4518Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU
4519dmd Manual}). On a running system, the @command{deco} command allows
4520you to list the available services, show their status, start and stop
4521them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd
4522Manual}). For example:
4523
4524@example
4525# deco status dmd
4526@end example
4527
4528The above command, run as @code{root}, lists the currently defined
4529services. The @command{deco doc} command shows a synopsis of the given
4530service:
4531
4532@example
4533# deco doc nscd
4534Run libc's name service cache daemon (nscd).
4535@end example
4536
4537The @command{start}, @command{stop}, and @command{restart} sub-commands
4538have the effect you would expect. For instance, the commands below stop
4539the nscd service and restart the Xorg display server:
4540
4541@example
4542# deco stop nscd
4543Service nscd has been stopped.
4544# deco restart xorg-server
4545Service xorg-server has been stopped.
4546Service xorg-server has been started.
4547@end example
401c53c4 4548
cf4a9129 4549The following sections document the available services, starting with
d8b94dbd
LC
4550the core services, that may be used in an @code{operating-system}
4551declaration.
401c53c4 4552
cf4a9129
LC
4553@menu
4554* Base Services:: Essential system services.
4555* Networking Services:: Network setup, SSH daemon, etc.
4556* X Window:: Graphical display.
aa4ed923 4557* Various Services:: Other services.
cf4a9129 4558@end menu
401c53c4 4559
cf4a9129
LC
4560@node Base Services
4561@subsubsection Base Services
a1ba8475 4562
cf4a9129
LC
4563The @code{(gnu services base)} module provides definitions for the basic
4564services that one expects from the system. The services exported by
4565this module are listed below.
401c53c4 4566
cf4a9129
LC
4567@defvr {Scheme Variable} %base-services
4568This variable contains a list of basic services@footnote{Technically,
4569this is a list of monadic services. @xref{The Store Monad}.} one would
4570expect from the system: a login service (mingetty) on each tty, syslogd,
4571libc's name service cache daemon (nscd), the udev device manager, and
4572more.
401c53c4 4573
cf4a9129
LC
4574This is the default value of the @code{services} field of
4575@code{operating-system} declarations. Usually, when customizing a
4576system, you will want to append services to @var{%base-services}, like
4577this:
401c53c4 4578
cf4a9129 4579@example
fa1e31b8 4580(cons* (avahi-service) (lsh-service) %base-services)
cf4a9129
LC
4581@end example
4582@end defvr
401c53c4 4583
cf4a9129
LC
4584@deffn {Monadic Procedure} host-name-service @var{name}
4585Return a service that sets the host name to @var{name}.
4586@end deffn
401c53c4 4587
cf4a9129
LC
4588@deffn {Monadic Procedure} mingetty-service @var{tty} [#:motd] @
4589 [#:auto-login #f] [#:login-program] [#:login-pause? #f] @
4590 [#:allow-empty-passwords? #f]
4591Return a service to run mingetty on @var{tty}.
401c53c4 4592
cf4a9129
LC
4593When @var{allow-empty-passwords?} is true, allow empty log-in password. When
4594@var{auto-login} is true, it must be a user name under which to log-in
4595automatically. @var{login-pause?} can be set to @code{#t} in conjunction with
4596@var{auto-login}, in which case the user will have to press a key before the
4597login shell is launched.
401c53c4 4598
cf4a9129
LC
4599When true, @var{login-program} is a gexp or a monadic gexp denoting the name
4600of the log-in program (the default is the @code{login} program from the Shadow
4601tool suite.)
401c53c4 4602
cf4a9129
LC
4603@var{motd} is a monadic value containing a text file to use as
4604the ``message of the day''.
4605@end deffn
401c53c4 4606
6454b333
LC
4607@cindex name service cache daemon
4608@cindex nscd
4aee6e60
LC
4609@deffn {Monadic Procedure} nscd-service [@var{config}] [#:glibc glibc] @
4610 [#:name-services '()]
4611Return a service that runs libc's name service cache daemon (nscd) with
4612the given @var{config}---an @code{<nscd-configuration>} object.
4613Optionally, @code{#:name-services} is a list of packages that provide
4c9050c6
LC
4614name service switch (NSS) modules needed by nscd. @xref{Name Service
4615Switch}, for an example.
cf4a9129 4616@end deffn
401c53c4 4617
6454b333
LC
4618@defvr {Scheme Variable} %nscd-default-configuration
4619This is the default @code{<nscd-configuration>} value (see below) used
4620by @code{nscd-service}. This uses the caches defined by
4621@var{%nscd-default-caches}; see below.
4622@end defvr
4623
4624@deftp {Data Type} nscd-configuration
4625This is the type representing the name service cache daemon (nscd)
4626configuration.
4627
4628@table @asis
4629
4630@item @code{log-file} (default: @code{"/var/log/nscd.log"})
4631Name of nscd's log file. This is where debugging output goes when
4632@code{debug-level} is strictly positive.
4633
4634@item @code{debug-level} (default: @code{0})
4635Integer denoting the debugging levels. Higher numbers mean more
4636debugging output is logged.
4637
4638@item @code{caches} (default: @var{%nscd-default-caches})
4639List of @code{<nscd-cache>} objects denoting things to be cached; see
4640below.
4641
4642@end table
4643@end deftp
4644
4645@deftp {Data Type} nscd-cache
4646Data type representing a cache database of nscd and its parameters.
4647
4648@table @asis
4649
4650@item @code{database}
4651This is a symbol representing the name of the database to be cached.
4652Valid values are @code{passwd}, @code{group}, @code{hosts}, and
4653@code{services}, which designate the corresponding NSS database
4654(@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}).
4655
4656@item @code{positive-time-to-live}
4657@itemx @code{negative-time-to-live} (default: @code{20})
4658A number representing the number of seconds during which a positive or
4659negative lookup result remains in cache.
4660
4661@item @code{check-files?} (default: @code{#t})
4662Whether to check for updates of the files corresponding to
4663@var{database}.
4664
4665For instance, when @var{database} is @code{hosts}, setting this flag
4666instructs nscd to check for updates in @file{/etc/hosts} and to take
4667them into account.
4668
4669@item @code{persistent?} (default: @code{#t})
4670Whether the cache should be stored persistently on disk.
4671
4672@item @code{shared?} (default: @code{#t})
4673Whether the cache should be shared among users.
4674
4675@item @code{max-database-size} (default: 32@tie{}MiB)
4676Maximum size in bytes of the database cache.
4677
4678@c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert
4679@c settings, so leave them out.
4680
4681@end table
4682@end deftp
4683
4684@defvr {Scheme Variable} %nscd-default-caches
4685List of @code{<nscd-cache>} objects used by default by
4686@code{nscd-configuration} (see above.)
4687
4688It enables persistent and aggressive caching of service and host name
4689lookups. The latter provides better host name lookup performance,
4690resilience in the face of unreliable name servers, and also better
4691privacy---often the result of host name lookups is in local cache, so
4692external name servers do not even need to be queried.
4693@end defvr
4694
4695
1bb76f75
AK
4696@deffn {Monadic Procedure} syslog-service [#:config-file #f]
4697Return a service that runs @code{syslogd}. If configuration file name
4698@var{config-file} is not specified, use some reasonable default
cf4a9129
LC
4699settings.
4700@end deffn
401c53c4 4701
cf4a9129
LC
4702@deffn {Monadic Procedure} guix-service [#:guix guix] @
4703 [#:builder-group "guixbuild"] [#:build-accounts 10] @
02bb6b45 4704 [#:authorize-hydra-key? #t] [#:use-substitutes? #t] @
cf4a9129
LC
4705 [#:extra-options '()]
4706Return a service that runs the build daemon from @var{guix}, and has
4707@var{build-accounts} user accounts available under @var{builder-group}.
401c53c4 4708
cf4a9129
LC
4709When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key
4710provided by @var{guix} is authorized upon activation, meaning that substitutes
4711from @code{hydra.gnu.org} are used by default.
401c53c4 4712
cf4a9129
LC
4713If @var{use-substitutes?} is false, the daemon is run with
4714@option{--no-substitutes} (@pxref{Invoking guix-daemon,
4715@option{--no-substitutes}}).
401c53c4 4716
cf4a9129
LC
4717Finally, @var{extra-options} is a list of additional command-line options
4718passed to @command{guix-daemon}.
4719@end deffn
a1ba8475 4720
cf4a9129
LC
4721@deffn {Monadic Procedure} udev-service [#:udev udev]
4722Run @var{udev}, which populates the @file{/dev} directory dynamically.
4723@end deffn
401c53c4 4724
a69576ea 4725
cf4a9129
LC
4726@node Networking Services
4727@subsubsection Networking Services
401c53c4 4728
fa1e31b8 4729The @code{(gnu services networking)} module provides services to configure
cf4a9129 4730the network interface.
a1ba8475 4731
a023cca8
LC
4732@cindex DHCP, networking service
4733@deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
4734Return a service that runs @var{dhcp}, a Dynamic Host Configuration
4735Protocol (DHCP) client, on all the non-loopback network interfaces.
4736@end deffn
4737
cf4a9129
LC
4738@deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @
4739 [#:gateway #f] [#:name-services @code{'()}]
4740Return a service that starts @var{interface} with address @var{ip}. If
4741@var{gateway} is true, it must be a string specifying the default network
4742gateway.
4743@end deffn
8b315a6d 4744
b7d0c494
MW
4745@cindex wicd
4746@deffn {Monadic Procedure} wicd-service [#:wicd @var{wicd}]
4747Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a
4748network manager that aims to simplify wired and wireless networking.
4749@end deffn
4750
63854bcb
LC
4751@deffn {Monadic Procedure} ntp-service [#:ntp @var{ntp}] @
4752 [#:name-service @var{%ntp-servers}]
4753Return a service that runs the daemon from @var{ntp}, the
4754@uref{http://www.ntp.org, Network Time Protocol package}. The daemon will
4755keep the system clock synchronized with that of @var{servers}.
4756@end deffn
4757
4758@defvr {Scheme Variable} %ntp-servers
4759List of host names used as the default NTP servers.
4760@end defvr
4761
cf4a9129
LC
4762@deffn {Monadic Procedure} tor-service [#:tor tor]
4763Return a service to run the @uref{https://torproject.org,Tor} daemon.
8b315a6d 4764
cf4a9129
LC
4765The daemon runs with the default settings (in particular the default exit
4766policy) as the @code{tor} unprivileged user.
4767@end deffn
8b315a6d 4768
4627a464
LC
4769@deffn {Monadic Procedure} bitlbee-service [#:bitlbee bitlbee] @
4770 [#:interface "127.0.0.1"] [#:port 6667] @
4771 [#:extra-settings ""]
4772Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
4773acts as a gateway between IRC and chat networks.
4774
4775The daemon will listen to the interface corresponding to the IP address
4776specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
4777local clients can connect, whereas @code{0.0.0.0} means that connections can
4778come from any networking interface.
4779
4780In addition, @var{extra-settings} specifies a string to append to the
4781configuration file.
4782@end deffn
4783
f4391bec 4784Furthermore, @code{(gnu services ssh)} provides the following service.
8b315a6d 4785
cf4a9129 4786@deffn {Monadic Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
5833bf33 4787 [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
cf4a9129
LC
4788 [#:allow-empty-passwords? #f] [#:root-login? #f] @
4789 [#:syslog-output? #t] [#:x11-forwarding? #t] @
4790 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
21cc905a 4791 [#:public-key-authentication? #t] [#:initialize? #t]
cf4a9129
LC
4792Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
4793@var{host-key} must designate a file containing the host key, and readable
4794only by root.
72e25e35 4795
5833bf33
DP
4796When @var{daemonic?} is true, @command{lshd} will detach from the
4797controlling terminal and log its output to syslogd, unless one sets
4798@var{syslog-output?} to false. Obviously, it also makes lsh-service
4799depend on existence of syslogd service. When @var{pid-file?} is true,
4800@command{lshd} writes its PID to the file called @var{pid-file}.
4801
cf4a9129
LC
4802When @var{initialize?} is true, automatically create the seed and host key
4803upon service activation if they do not exist yet. This may take long and
4804require interaction.
8b315a6d 4805
20dd519c
LC
4806When @var{initialize?} is false, it is up to the user to initialize the
4807randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
4808a key pair with the private key stored in file @var{host-key} (@pxref{lshd
4809basics,,, lsh, LSH Manual}).
4810
cf4a9129
LC
4811When @var{interfaces} is empty, lshd listens for connections on all the
4812network interfaces; otherwise, @var{interfaces} must be a list of host names
4813or addresses.
9bf3c1a7 4814
20dd519c
LC
4815@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
4816passwords, and @var{root-login?} specifies whether to accept log-ins as
cf4a9129 4817root.
4af2447e 4818
cf4a9129
LC
4819The other options should be self-descriptive.
4820@end deffn
4af2447e 4821
fa0c1d61
LC
4822@defvr {Scheme Variable} %facebook-host-aliases
4823This variable contains a string for use in @file{/etc/hosts}
4824(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
4825line contains a entry that maps a known server name of the Facebook
4826on-line service---e.g., @code{www.facebook.com}---to the local
4827host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
4828
4829This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
4830@code{operating-system} declaration (@pxref{operating-system Reference,
4831@file{/etc/hosts}}):
fa0c1d61
LC
4832
4833@example
4834(use-modules (gnu) (guix))
4835
4836(operating-system
4837 (host-name "mymachine")
4838 ;; ...
4839 (hosts-file
4840 ;; Create a /etc/hosts file with aliases for "localhost"
4841 ;; and "mymachine", as well as for Facebook servers.
4842 (text-file "hosts"
4843 (string-append (local-host-aliases host-name)
4844 %facebook-host-aliases))))
4845@end example
4846
4847This mechanism can prevent programs running locally, such as Web
4848browsers, from accessing Facebook.
4849@end defvr
4850
cf4a9129
LC
4851@node X Window
4852@subsubsection X Window
68ad877c 4853
cf4a9129
LC
4854Support for the X Window graphical display system---specifically
4855Xorg---is provided by the @code{(gnu services xorg)} module. Note that
4856there is no @code{xorg-service} procedure. Instead, the X server is
4857started by the @dfn{login manager}, currently SLiM.
4af2447e 4858
cf4a9129 4859@deffn {Monadic Procedure} slim-service [#:allow-empty-passwords? #f] @
0ecc3bf3
LC
4860 [#:auto-login? #f] [#:default-user ""] [#:startx] @
4861 [#:theme @var{%default-slim-theme}] @
4bd43bbe 4862 [#:theme-name @var{%default-slim-theme-name}]
cf4a9129
LC
4863Return a service that spawns the SLiM graphical login manager, which in
4864turn starts the X display server with @var{startx}, a command as returned by
4865@code{xorg-start-command}.
4af2447e 4866
cf4a9129
LC
4867When @var{allow-empty-passwords?} is true, allow logins with an empty
4868password. When @var{auto-login?} is true, log in automatically as
4869@var{default-user}.
0ecc3bf3
LC
4870
4871If @var{theme} is @code{#f}, the use the default log-in theme; otherwise
4872@var{theme} must be a gexp denoting the name of a directory containing the
4873theme to use. In that case, @var{theme-name} specifies the name of the
4874theme.
cf4a9129 4875@end deffn
4af2447e 4876
0ecc3bf3
LC
4877@defvr {Scheme Variable} %default-theme
4878@defvrx {Scheme Variable} %default-theme-name
4879The G-Expression denoting the default SLiM theme and its name.
4880@end defvr
4881
f703413e 4882@deffn {Monadic Procedure} xorg-start-command [#:guile] @
d2e59637 4883 [#:drivers '()] [#:resolutions '()] [#:xorg-server @var{xorg-server}]
f703413e
LC
4884Return a derivation that builds a @var{guile} script to start the X server
4885from @var{xorg-server}. Usually the X server is started by a login manager.
4886
4887@var{drivers} must be either the empty list, in which case Xorg chooses a
4888graphics driver automatically, or a list of driver names that will be tried in
4889this order---e.g., @code{("modesetting" "vesa")}.
d2e59637
LC
4890
4891Likewise, when @var{resolutions} is the empty list, Xorg chooses an
4892appropriate screen resolution; otherwise, it must be a list of
4893resolutions---e.g., @code{((1024 768) (640 480))}.
f703413e 4894@end deffn
4af2447e 4895
aa4ed923
AK
4896@node Various Services
4897@subsubsection Various Services
4898
4899The @code{(gnu services lirc)} module provides the following service.
4900
4901@deffn {Monadic Procedure} lirc-service [#:lirc lirc] @
4902 [#:device #f] [#:driver #f] [#:config-file #f] @
4903 [#:extra-options '()]
4904Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that
4905decodes infrared signals from remote controls.
4906
4907Optionally, @var{device}, @var{driver} and @var{config-file}
4908(configuration file name) may be specified. See @command{lircd} manual
4909for details.
4910
4911Finally, @var{extra-options} is a list of additional command-line options
4912passed to @command{lircd}.
4913@end deffn
4914
be234128
AW
4915@code{(gnu services upower)} provides a power-management daemon:
4916
4917@deffn {Monadic Procedure} upower-service [#:upower @var{upower}] @
4918 [#:watts-up-pro? #f] @
4919 [#:poll-batteries? #t] @
4920 [#:ignore-lid? #f] @
4921 [#:use-percentage-for-policy? #f] @
4922 [#:percentage-low 10] @
4923 [#:percentage-critical 3] @
4924 [#:percentage-action 2] @
4925 [#:time-low 1200] @
4926 [#:time-critical 300] @
4927 [#:time-action 120] @
4928 [#:critical-power-action 'hybrid-sleep]
4929Return a service that runs @uref{http://upower.freedesktop.org/,
4930@command{upowerd}}, a system-wide monitor for power consumption and battery
4931levels, with the given configuration settings. It implements the
4932@code{org.freedesktop.UPower} D-Bus interface, and is notably used by
4933GNOME.
4934@end deffn
4935
7ce597ff
AW
4936@code{(gnu services colord)} provides a color management service:
4937
4938@deffn {Monadic Procedure} colord-service [#:colord @var{colord}]
4939Return a service that runs @command{colord}, a system service with a D-Bus
4940interface to manage the color profiles of input and output devices such as
4941screens and scanners. It is notably used by the GNOME Color Manager graphical
4942tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web
4943site} for more information.
4944@end deffn
4945
0ae8c15a
LC
4946@node Setuid Programs
4947@subsection Setuid Programs
4948
4949@cindex setuid programs
4950Some programs need to run with ``root'' privileges, even when they are
4951launched by unprivileged users. A notorious example is the
4952@command{passwd} programs, which can users can run to change their
4953password, and which requires write access to the @file{/etc/passwd} and
4954@file{/etc/shadow} files---something normally restricted to root, for
4955obvious security reasons. To address that, these executables are
4956@dfn{setuid-root}, meaning that they always run with root privileges
4957(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
4958for more info about the setuid mechanisms.)
4959
4960The store itself @emph{cannot} contain setuid programs: that would be a
4961security issue since any user on the system can write derivations that
4962populate the store (@pxref{The Store}). Thus, a different mechanism is
4963used: instead of changing the setuid bit directly on files that are in
4964the store, we let the system administrator @emph{declare} which programs
4965should be setuid root.
4966
4967The @code{setuid-programs} field of an @code{operating-system}
4968declaration contains a list of G-expressions denoting the names of
4969programs to be setuid-root (@pxref{Using the Configuration System}).
4970For instance, the @command{passwd} program, which is part of the Shadow
4971package, can be designated by this G-expression (@pxref{G-Expressions}):
4972
4973@example
4974#~(string-append #$shadow "/bin/passwd")
4975@end example
4976
4977A default set of setuid programs is defined by the
4978@code{%setuid-programs} variable of the @code{(gnu system)} module.
4979
4980@defvr {Scheme Variable} %setuid-programs
4981A list of G-expressions denoting common programs that are setuid-root.
4982
4983The list includes commands such as @command{passwd}, @command{ping},
4984@command{su}, and @command{sudo}.
4985@end defvr
4986
4987Under the hood, the actual setuid programs are created in the
4988@file{/run/setuid-programs} directory at system activation time. The
4989files in this directory refer to the ``real'' binaries, which are in the
4990store.
4991
996ed739
LC
4992@node Name Service Switch
4993@subsection Name Service Switch
4994
4995@cindex name service switch
4996@cindex NSS
4997The @code{(gnu system nss)} module provides bindings to the
4998configuration file of libc's @dfn{name service switch} or @dfn{NSS}
4999(@pxref{NSS Configuration File,,, libc, The GNU C Library Reference
5000Manual}). In a nutshell, the NSS is a mechanism that allows libc to be
5001extended with new ``name'' lookup methods for system databases, which
5002includes host names, service names, user accounts, and more (@pxref{Name
5003Service Switch, System Databases and Name Service Switch,, libc, The GNU
5004C Library Reference Manual}).
5005
5006The NSS configuration specifies, for each system database, which lookup
5007method is to be used, and how the various methods are chained
5008together---for instance, under which circumstances NSS should try the
5009next method in the list. The NSS configuration is given in the
5010@code{name-service-switch} field of @code{operating-system} declarations
5011(@pxref{operating-system Reference, @code{name-service-switch}}).
5012
4c9050c6
LC
5013@cindex nss-mdns
5014@cindex .local, host name lookup
996ed739 5015As an example, the declaration below configures the NSS to use the
4c9050c6
LC
5016@uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns}
5017back-end}, which supports host name lookups over multicast DNS (mDNS)
5018for host names ending in @code{.local}:
996ed739
LC
5019
5020@example
5021(name-service-switch
5022 (hosts (list %files ;first, check /etc/hosts
5023
5024 ;; If the above did not succeed, try
5025 ;; with 'mdns_minimal'.
5026 (name-service
5027 (name "mdns_minimal")
5028
5029 ;; 'mdns_minimal' is authoritative for
5030 ;; '.local'. When it returns "not found",
5031 ;; no need to try the next methods.
5032 (reaction (lookup-specification
5033 (not-found => return))))
5034
5035 ;; Then fall back to DNS.
5036 (name-service
5037 (name "dns"))
5038
5039 ;; Finally, try with the "full" 'mdns'.
5040 (name-service
5041 (name "mdns")))))
5042@end example
5043
4c9050c6
LC
5044Note that, in this case, in addition to setting the
5045@code{name-service-switch} of the @code{operating-system} declaration,
5046@code{nscd-service} must be told where to find the @code{nss-mdns}
5047shared library (@pxref{Base Services, @code{nscd-service}}). Since the
5048@code{nscd} service is part of @var{%base-services}, you may want to
5049customize it by adding this snippet in the operating system
5050configuration file:
5051
5052@example
5053(use-modules (guix) (gnu))
5054
5055(define %my-base-services
5056 ;; Replace the default nscd service with one that knows
5057 ;; about nss-mdns.
5058 (map (lambda (mservice)
5059 ;; "Bind" the MSERVICE monadic value to inspect it.
5060 (mlet %store-monad ((service mservice))
5061 (if (member 'nscd (service-provision service))
5062 (nscd-service (nscd-configuration)
5063 #:name-services (list nss-mdns))
5064 mservice)))
5065 %base-services))
5066@end example
5067
5068@noindent
5069@dots{} and then refer to @var{%my-base-services} instead of
5070@var{%base-services} in the @code{operating-system} declaration.
5071
996ed739
LC
5072The reference for name service switch configuration is given below. It
5073is a direct mapping of the C library's configuration file format, so
5074please refer to the C library manual for more information (@pxref{NSS
5075Configuration File,,, libc, The GNU C Library Reference Manual}).
5076Compared to libc's NSS configuration file format, it has the advantage
5077not only of adding this warm parenthetic feel that we like, but also
5078static checks: you'll know about syntax errors and typos as soon as you
5079run @command{guix system}.
5080
5081@defvr {Scheme Variable} %default-nss
5082This is the default name service switch configuration, a
5083@code{name-service-switch} object.
5084@end defvr
5085
5086@deftp {Data Type} name-service-switch
5087
5088This is the data type representation the configuration of libc's name
5089service switch (NSS). Each field below represents one of the supported
5090system databases.
5091
5092@table @code
5093@item aliases
5094@itemx ethers
5095@itemx group
5096@itemx gshadow
5097@itemx hosts
5098@itemx initgroups
5099@itemx netgroup
5100@itemx networks
5101@itemx password
5102@itemx public-key
5103@itemx rpc
5104@itemx services
5105@itemx shadow
5106The system databases handled by the NSS. Each of these fields must be a
5107list of @code{<name-service>} objects (see below.)
5108@end table
5109@end deftp
5110
5111@deftp {Data Type} name-service
5112
5113This is the data type representing an actual name service and the
5114associated lookup action.
5115
5116@table @code
5117@item name
5118A string denoting the name service (@pxref{Services in the NSS
5119configuration,,, libc, The GNU C Library Reference Manual}).
5120
4aee6e60
LC
5121Note that name services listed here must be visible to nscd. This is
5122achieved by passing the @code{#:name-services} argument to
5123@code{nscd-service} the list of packages providing the needed name
5124services (@pxref{Base Services, @code{nscd-service}}).
5125
996ed739
LC
5126@item reaction
5127An action specified using the @code{lookup-specification} macro
5128(@pxref{Actions in the NSS configuration,,, libc, The GNU C Library
5129Reference Manual}). For example:
5130
5131@example
5132(lookup-specification (unavailable => continue)
5133 (success => return))
5134@end example
5135@end table
5136@end deftp
0ae8c15a 5137
fd1b1fa2
LC
5138@node Initial RAM Disk
5139@subsection Initial RAM Disk
5140
5141@cindex initial RAM disk (initrd)
5142@cindex initrd (initial RAM disk)
5143For bootstrapping purposes, the Linux-Libre kernel is passed an
5144@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
5145root file system, as well as an initialization script. The latter is
5146responsible for mounting the real root file system, and for loading any
5147kernel modules that may be needed to achieve that.
5148
5149The @code{initrd} field of an @code{operating-system} declaration allows
5150you to specify which initrd you would like to use. The @code{(gnu
5151system linux-initrd)} module provides two ways to build an initrd: the
5152high-level @code{base-initrd} procedure, and the low-level
5153@code{expression->initrd} procedure.
5154
5155The @code{base-initrd} procedure is intended to cover most common uses.
5156For example, if you want to add a bunch of kernel modules to be loaded
5157at boot time, you can define the @code{initrd} field of the operating
5158system declaration like this:
5159
5160@example
52ac153e 5161(initrd (lambda (file-systems . rest)
027981d6
LC
5162 ;; Create a standard initrd that has modules "foo.ko"
5163 ;; and "bar.ko", as well as their dependencies, in
5164 ;; addition to the modules available by default.
52ac153e 5165 (apply base-initrd file-systems
027981d6 5166 #:extra-modules '("foo" "bar")
52ac153e 5167 rest)))
fd1b1fa2
LC
5168@end example
5169
52ac153e
LC
5170The @code{base-initrd} procedure also handles common use cases that
5171involves using the system as a QEMU guest, or as a ``live'' system whose
5172root file system is volatile.
fd1b1fa2
LC
5173
5174@deffn {Monadic Procedure} base-initrd @var{file-systems} @
5175 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
52ac153e 5176 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
5177Return a monadic derivation that builds a generic initrd. @var{file-systems} is
5178a list of file-systems to be mounted by the initrd, possibly in addition to
5179the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
5180@var{mapped-devices} is a list of device mappings to realize before
5181@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
5182
5183When @var{qemu-networking?} is true, set up networking with the standard QEMU
5184parameters. When @var{virtio?} is true, load additional modules so the initrd can
5185be used as a QEMU guest with para-virtualized I/O drivers.
5186
5187When @var{volatile-root?} is true, the root file system is writable but any changes
5188to it are lost.
5189
5190The initrd is automatically populated with all the kernel modules necessary
5191for @var{file-systems} and for the given options. However, additional kernel
5192modules can be listed in @var{extra-modules}. They will be added to the initrd, and
5193loaded at boot time in the order in which they appear.
5194@end deffn
5195
5196Needless to say, the initrds we produce and use embed a
5197statically-linked Guile, and the initialization program is a Guile
5198program. That gives a lot of flexibility. The
5199@code{expression->initrd} procedure builds such an initrd, given the
5200program to run in that initrd.
5201
5202@deffn {Monadic Procedure} expression->initrd @var{exp} @
5203 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 5204 [#:modules '()]
fd1b1fa2
LC
5205Return a derivation that builds a Linux initrd (a gzipped cpio archive)
5206containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
5207upon booting. All the derivations referenced by @var{exp} are
5208automatically copied to the initrd.
fd1b1fa2 5209
42d10464
LC
5210@var{modules} is a list of Guile module names to be embedded in the
5211initrd.
fd1b1fa2
LC
5212@end deffn
5213
88faf933
LC
5214@node GRUB Configuration
5215@subsection GRUB Configuration
5216
5217@cindex GRUB
5218@cindex boot loader
5219
5220The operating system uses GNU@tie{}GRUB as its boot loader
5221(@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is
5222configured using @code{grub-configuration} declarations. This data type
5223is exported by the @code{(gnu system grub)} module, and described below.
5224
5225@deftp {Data Type} grub-configuration
5226The type of a GRUB configuration declaration.
5227
5228@table @asis
5229
5230@item @code{device}
5231This is a string denoting the boot device. It must be a device name
5232understood by the @command{grub-install} command, such as
5233@code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub,
5234GNU GRUB Manual}).
5235
5236@item @code{menu-entries} (default: @code{()})
5237A possibly empty list of @code{menu-entry} objects (see below), denoting
5238entries to appear in the GRUB boot menu, in addition to the current
5239system entry and the entry pointing to previous system generations.
5240
5241@item @code{default-entry} (default: @code{0})
5242The index of the default boot menu entry. Index 0 is for the current
5243system's entry.
5244
5245@item @code{timeout} (default: @code{5})
5246The number of seconds to wait for keyboard input before booting. Set to
52470 to boot immediately, and to -1 to wait indefinitely.
5248
5249@item @code{theme} (default: @var{%default-theme})
5250The @code{grub-theme} object describing the theme to use.
5251@end table
5252
5253@end deftp
5254
5255Should you want to list additional boot menu entries @i{via} the
5256@code{menu-entries} field above, you will need to create them with the
5257@code{menu-entry} form:
5258
5259@deftp {Data Type} menu-entry
5260The type of an entry in the GRUB boot menu.
5261
5262@table @asis
5263
5264@item @code{label}
35ed9306 5265The label to show in the menu---e.g., @code{"GNU"}.
88faf933
LC
5266
5267@item @code{linux}
5268The Linux kernel to boot.
5269
5270@item @code{linux-arguments} (default: @code{()})
5271The list of extra Linux kernel command-line arguments---e.g.,
5272@code{("console=ttyS0")}.
5273
5274@item @code{initrd}
5275A G-Expression or string denoting the file name of the initial RAM disk
5276to use (@pxref{G-Expressions}).
5277
5278@end table
5279@end deftp
5280
5281@c FIXME: Write documentation once it's stable.
5282Themes are created using the @code{grub-theme} form, which is not
5283documented yet.
5284
5285@defvr {Scheme Variable} %default-theme
5286This is the default GRUB theme used by the operating system, with a
5287fancy background image displaying the GNU and Guix logos.
5288@end defvr
5289
5290
cf4a9129
LC
5291@node Invoking guix system
5292@subsection Invoking @code{guix system}
0918e64a 5293
cf4a9129
LC
5294Once you have written an operating system declaration, as seen in the
5295previous section, it can be @dfn{instantiated} using the @command{guix
5296system} command. The synopsis is:
4af2447e 5297
cf4a9129
LC
5298@example
5299guix system @var{options}@dots{} @var{action} @var{file}
5300@end example
4af2447e 5301
cf4a9129
LC
5302@var{file} must be the name of a file containing an
5303@code{operating-system} declaration. @var{action} specifies how the
5304operating system is instantiate. Currently the following values are
5305supported:
4af2447e 5306
cf4a9129
LC
5307@table @code
5308@item reconfigure
5309Build the operating system described in @var{file}, activate it, and
5310switch to it@footnote{This action is usable only on systems already
5311running GNU.}.
4af2447e 5312
cf4a9129
LC
5313This effects all the configuration specified in @var{file}: user
5314accounts, system services, global package list, setuid programs, etc.
4af2447e 5315
cf4a9129
LC
5316It also adds a GRUB menu entry for the new OS configuration, and moves
5317entries for older configurations to a submenu---unless
5318@option{--no-grub} is passed.
4af2447e 5319
bf2479c7
LC
5320@c The paragraph below refers to the problem discussed at
5321@c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
5322It is highly recommended to run @command{guix pull} once before you run
5323@command{guix system reconfigure} for the first time (@pxref{Invoking
5324guix pull}). Failing to do that you would see an older version of Guix
5325once @command{reconfigure} has completed.
5326
cf4a9129
LC
5327@item build
5328Build the operating system's derivation, which includes all the
5329configuration files and programs needed to boot and run the system.
5330This action does not actually install anything.
113daf62 5331
cf4a9129
LC
5332@item init
5333Populate the given directory with all the files necessary to run the
5334operating system specified in @var{file}. This is useful for first-time
3ca2731c 5335installations of GSD. For instance:
113daf62
LC
5336
5337@example
cf4a9129 5338guix system init my-os-config.scm /mnt
113daf62
LC
5339@end example
5340
cf4a9129
LC
5341copies to @file{/mnt} all the store items required by the configuration
5342specified in @file{my-os-config.scm}. This includes configuration
5343files, packages, and so on. It also creates other essential files
5344needed for the system to operate correctly---e.g., the @file{/etc},
5345@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 5346
cf4a9129
LC
5347This command also installs GRUB on the device specified in
5348@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 5349
cf4a9129
LC
5350@item vm
5351@cindex virtual machine
0276f697 5352@cindex VM
cf4a9129
LC
5353Build a virtual machine that contain the operating system declared in
5354@var{file}, and return a script to run that virtual machine (VM).
810568b3 5355Arguments given to the script are passed as is to QEMU.
113daf62 5356
cf4a9129 5357The VM shares its store with the host system.
113daf62 5358
0276f697
LC
5359Additional file systems can be shared between the host and the VM using
5360the @code{--share} and @code{--expose} command-line options: the former
5361specifies a directory to be shared with write access, while the latter
5362provides read-only access to the shared directory.
5363
5364The example below creates a VM in which the user's home directory is
5365accessible read-only, and where the @file{/exchange} directory is a
5366read-write mapping of the host's @file{$HOME/tmp}:
5367
5368@example
5369guix system vm my-config.scm \
5370 --expose=$HOME --share=$HOME/tmp=/exchange
5371@end example
5372
6aa260af
LC
5373On GNU/Linux, the default is to boot directly to the kernel; this has
5374the advantage of requiring only a very tiny root disk image since the
5375host's store can then be mounted.
5376
5377The @code{--full-boot} option forces a complete boot sequence, starting
5378with the bootloader. This requires more disk space since a root image
5379containing at least the kernel, initrd, and bootloader data files must
5380be created. The @code{--image-size} option can be used to specify the
5381image's size.
ab11f0be 5382
cf4a9129
LC
5383@item vm-image
5384@itemx disk-image
5385Return a virtual machine or disk image of the operating system declared
5386in @var{file} that stands alone. Use the @option{--image-size} option
5387to specify the size of the image.
113daf62 5388
cf4a9129
LC
5389When using @code{vm-image}, the returned image is in qcow2 format, which
5390the QEMU emulator can efficiently use.
113daf62 5391
cf4a9129
LC
5392When using @code{disk-image}, a raw disk image is produced; it can be
5393copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
5394the device corresponding to a USB stick, one can copy the image on it
5395using the following command:
113daf62 5396
cf4a9129
LC
5397@example
5398# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
5399@end example
113daf62 5400
cf4a9129 5401@end table
113daf62 5402
cf4a9129
LC
5403@var{options} can contain any of the common build options provided by
5404@command{guix build} (@pxref{Invoking guix build}). In addition,
5405@var{options} can contain one of the following:
113daf62 5406
cf4a9129
LC
5407@table @option
5408@item --system=@var{system}
5409@itemx -s @var{system}
5410Attempt to build for @var{system} instead of the host's system type.
5411This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 5412
cf4a9129
LC
5413@item --image-size=@var{size}
5414For the @code{vm-image} and @code{disk-image} actions, create an image
5415of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
5416include a unit as a suffix (@pxref{Block size, size specifications,,
5417coreutils, GNU Coreutils}).
113daf62 5418@end table
113daf62 5419
cf4a9129
LC
5420Note that all the actions above, except @code{build} and @code{init},
5421rely on KVM support in the Linux-Libre kernel. Specifically, the
5422machine should have hardware virtualization support, the corresponding
5423KVM kernel module should be loaded, and the @file{/dev/kvm} device node
5424must exist and be readable and writable by the user and by the daemon's
5425build users.
8451a568 5426
cf4a9129
LC
5427@node Defining Services
5428@subsection Defining Services
8451a568 5429
cf4a9129
LC
5430The @code{(gnu services @dots{})} modules define several procedures that allow
5431users to declare the operating system's services (@pxref{Using the
5432Configuration System}). These procedures are @emph{monadic
5433procedures}---i.e., procedures that return a monadic value in the store
5434monad (@pxref{The Store Monad}). For examples of such procedures,
5435@xref{Services}.
8451a568 5436
cf4a9129
LC
5437@cindex service definition
5438The monadic value returned by those procedures is a @dfn{service
5439definition}---a structure as returned by the @code{service} form.
5440Service definitions specifies the inputs the service depends on, and an
5441expression to start and stop the service. Behind the scenes, service
5442definitions are ``translated'' into the form suitable for the
5443configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU
5444dmd Manual}).
8451a568 5445
cf4a9129
LC
5446As an example, here is what the @code{nscd-service} procedure looks
5447like:
8451a568 5448
cf4a9129
LC
5449@lisp
5450(define (nscd-service)
5451 (with-monad %store-monad
5452 (return (service
5453 (documentation "Run libc's name service cache daemon.")
5454 (provision '(nscd))
5455 (activate #~(begin
5456 (use-modules (guix build utils))
5457 (mkdir-p "/var/run/nscd")))
5458 (start #~(make-forkexec-constructor
5459 (string-append #$glibc "/sbin/nscd")
5460 "-f" "/dev/null" "--foreground"))
5461 (stop #~(make-kill-destructor))
5462 (respawn? #f)))))
5463@end lisp
8451a568 5464
cf4a9129
LC
5465@noindent
5466The @code{activate}, @code{start}, and @code{stop} fields are G-expressions
5467(@pxref{G-Expressions}). The @code{activate} field contains a script to
5468run at ``activation'' time; it makes sure that the @file{/var/run/nscd}
5469directory exists before @command{nscd} is started.
8451a568 5470
cf4a9129
LC
5471The @code{start} and @code{stop} fields refer to dmd's facilities to
5472start and stop processes (@pxref{Service De- and Constructors,,, dmd,
5473GNU dmd Manual}). The @code{provision} field specifies the name under
5474which this service is known to dmd, and @code{documentation} specifies
5475on-line documentation. Thus, the commands @command{deco start ncsd},
5476@command{deco stop nscd}, and @command{deco doc nscd} will do what you
5477would expect (@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
8451a568 5478
8451a568 5479
cf4a9129
LC
5480@node Installing Debugging Files
5481@section Installing Debugging Files
8451a568 5482
cf4a9129
LC
5483@cindex debugging files
5484Program binaries, as produced by the GCC compilers for instance, are
5485typically written in the ELF format, with a section containing
5486@dfn{debugging information}. Debugging information is what allows the
5487debugger, GDB, to map binary code to source code; it is required to
5488debug a compiled program in good conditions.
8451a568 5489
cf4a9129
LC
5490The problem with debugging information is that is takes up a fair amount
5491of disk space. For example, debugging information for the GNU C Library
5492weighs in at more than 60 MiB. Thus, as a user, keeping all the
5493debugging info of all the installed programs is usually not an option.
5494Yet, space savings should not come at the cost of an impediment to
5495debugging---especially in the GNU system, which should make it easier
5496for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 5497
cf4a9129
LC
5498Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
5499mechanism that allows users to get the best of both worlds: debugging
5500information can be stripped from the binaries and stored in separate
5501files. GDB is then able to load debugging information from those files,
5502when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
5503with GDB}).
8451a568 5504
cf4a9129
LC
5505The GNU distribution takes advantage of this by storing debugging
5506information in the @code{lib/debug} sub-directory of a separate package
5507output unimaginatively called @code{debug} (@pxref{Packages with
5508Multiple Outputs}). Users can choose to install the @code{debug} output
5509of a package when they need it. For instance, the following command
5510installs the debugging information for the GNU C Library and for GNU
5511Guile:
8451a568
LC
5512
5513@example
cf4a9129 5514guix package -i glibc:debug guile:debug
8451a568
LC
5515@end example
5516
cf4a9129
LC
5517GDB must then be told to look for debug files in the user's profile, by
5518setting the @code{debug-file-directory} variable (consider setting it
5519from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
5520GDB}):
8451a568 5521
cf4a9129
LC
5522@example
5523(gdb) set debug-file-directory ~/.guix-profile/lib/debug
5524@end example
8451a568 5525
cf4a9129
LC
5526From there on, GDB will pick up debugging information from the
5527@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 5528
cf4a9129
LC
5529In addition, you will most likely want GDB to be able to show the source
5530code being debugged. To do that, you will have to unpack the source
5531code of the package of interest (obtained with @code{guix build
5532--source}, @pxref{Invoking guix build}), and to point GDB to that source
5533directory using the @code{directory} command (@pxref{Source Path,
5534@code{directory},, gdb, Debugging with GDB}).
8451a568 5535
cf4a9129
LC
5536@c XXX: keep me up-to-date
5537The @code{debug} output mechanism in Guix is implemented by the
5538@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
5539opt-in---debugging information is available only for those packages
5540whose definition explicitly declares a @code{debug} output. This may be
5541changed to opt-out in the future, if our build farm servers can handle
5542the load. To check whether a package has a @code{debug} output, use
5543@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 5544
8451a568 5545
05962f29
LC
5546@node Security Updates
5547@section Security Updates
5548
843858b8
LC
5549@quotation Note
5550As of version @value{VERSION}, the feature described in this section is
5551experimental.
5552@end quotation
05962f29
LC
5553
5554@cindex security updates
5555Occasionally, important security vulnerabilities are discovered in core
5556software packages and must be patched. Guix follows a functional
5557package management discipline (@pxref{Introduction}), which implies
5558that, when a package is changed, @emph{every package that depends on it}
5559must be rebuilt. This can significantly slow down the deployment of
5560fixes in core packages such as libc or Bash, since basically the whole
5561distribution would need to be rebuilt. Using pre-built binaries helps
5562(@pxref{Substitutes}), but deployment may still take more time than
5563desired.
5564
5565@cindex grafts
5566To address that, Guix implements @dfn{grafts}, a mechanism that allows
5567for fast deployment of critical updates without the costs associated
5568with a whole-distribution rebuild. The idea is to rebuild only the
5569package that needs to be patched, and then to ``graft'' it onto packages
5570explicitly installed by the user and that were previously referring to
5571the original package. The cost of grafting is typically very low, and
5572order of magnitudes lower than a full rebuild of the dependency chain.
5573
5574@cindex replacements of packages, for grafts
5575For instance, suppose a security update needs to be applied to Bash.
5576Guix developers will provide a package definition for the ``fixed''
5577Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
5578Packages}). Then, the original package definition is augmented with a
5579@code{replacement} field pointing to the package containing the bug fix:
5580
5581@example
5582(define bash
5583 (package
5584 (name "bash")
5585 ;; @dots{}
5586 (replacement bash-fixed)))
5587@end example
5588
5589From there on, any package depending directly or indirectly on Bash that
5590is installed will automatically be ``rewritten'' to refer to
5591@var{bash-fixed} instead of @var{bash}. This grafting process takes
5592time proportional to the size of the package, but expect less than a
5593minute for an ``average'' package on a recent machine.
5594
5595Currently, the graft and the package it replaces (@var{bash-fixed} and
5596@var{bash} in the example above) must have the exact same @code{name}
5597and @code{version} fields. This restriction mostly comes from the fact
5598that grafting works by patching files, including binary files, directly.
5599Other restrictions may apply: for instance, when adding a graft to a
5600package providing a shared library, the original shared library and its
5601replacement must have the same @code{SONAME} and be binary-compatible.
5602
5603
cf4a9129
LC
5604@node Package Modules
5605@section Package Modules
8451a568 5606
cf4a9129
LC
5607From a programming viewpoint, the package definitions of the
5608GNU distribution are provided by Guile modules in the @code{(gnu packages
5609@dots{})} name space@footnote{Note that packages under the @code{(gnu
5610packages @dots{})} module name space are not necessarily ``GNU
5611packages''. This module naming scheme follows the usual Guile module
5612naming convention: @code{gnu} means that these modules are distributed
5613as part of the GNU system, and @code{packages} identifies modules that
5614define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
5615Reference Manual}). For instance, the @code{(gnu packages emacs)}
5616module exports a variable named @code{emacs}, which is bound to a
5617@code{<package>} object (@pxref{Defining Packages}).
113daf62 5618
300868ba 5619The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
5620automatically scanned for packages by the command-line tools. For
5621instance, when running @code{guix package -i emacs}, all the @code{(gnu
5622packages @dots{})} modules are scanned until one that exports a package
5623object whose name is @code{emacs} is found. This package search
5624facility is implemented in the @code{(gnu packages)} module.
113daf62 5625
300868ba 5626@cindex customization, of packages
8689901f 5627@cindex package module search path
cf4a9129 5628Users can store package definitions in modules with different
60142854
LC
5629names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
5630name and module name must match. @xref{Modules and the File System,,,
5631guile, GNU Guile Reference Manual}, for details.} These package definitions
300868ba
LC
5632will not be visible by default. Thus, users can invoke commands such as
5633@command{guix package} and @command{guix build} have to be used with the
5634@code{-e} option so that they know where to find the package, or use the
5635@code{-L} option of these commands to make those modules visible
8689901f
LC
5636(@pxref{Invoking guix build, @code{--load-path}}), or define the
5637@code{GUIX_PACKAGE_PATH} environment variable. This environment
5638variable makes it easy to extend or customize the distribution and is
5639honored by all the user interfaces.
5640
5641@defvr {Environment Variable} GUIX_PACKAGE_PATH
5642This is a colon-separated list of directories to search for package
5643modules. Directories listed in this variable take precedence over the
5644distribution's own modules.
5645@end defvr
ef5dd60a 5646
cf4a9129
LC
5647The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
5648each package is built based solely on other packages in the
5649distribution. The root of this dependency graph is a small set of
5650@dfn{bootstrap binaries}, provided by the @code{(gnu packages
5651bootstrap)} module. For more information on bootstrapping,
081145cf 5652@pxref{Bootstrapping}.
ef5dd60a 5653
cf4a9129
LC
5654@node Packaging Guidelines
5655@section Packaging Guidelines
ef5dd60a 5656
cf4a9129
LC
5657The GNU distribution is nascent and may well lack some of your favorite
5658packages. This section describes how you can help make the distribution
5659grow. @xref{Contributing}, for additional information on how you can
5660help.
ef5dd60a 5661
cf4a9129
LC
5662Free software packages are usually distributed in the form of
5663@dfn{source code tarballs}---typically @file{tar.gz} files that contain
5664all the source files. Adding a package to the distribution means
5665essentially two things: adding a @dfn{recipe} that describes how to
5666build the package, including a list of other packages required to build
5667it, and adding @dfn{package meta-data} along with that recipe, such as a
5668description and licensing information.
ef5dd60a 5669
cf4a9129
LC
5670In Guix all this information is embodied in @dfn{package definitions}.
5671Package definitions provide a high-level view of the package. They are
5672written using the syntax of the Scheme programming language; in fact,
5673for each package we define a variable bound to the package definition,
5674and export that variable from a module (@pxref{Package Modules}).
5675However, in-depth Scheme knowledge is @emph{not} a prerequisite for
5676creating packages. For more information on package definitions,
081145cf 5677@pxref{Defining Packages}.
ef5dd60a 5678
cf4a9129
LC
5679Once a package definition is in place, stored in a file in the Guix
5680source tree, it can be tested using the @command{guix build} command
5681(@pxref{Invoking guix build}). For example, assuming the new package is
5682called @code{gnew}, you may run this command from the Guix build tree:
ef5dd60a
LC
5683
5684@example
cf4a9129 5685./pre-inst-env guix build gnew --keep-failed
ef5dd60a 5686@end example
ef5dd60a 5687
cf4a9129
LC
5688Using @code{--keep-failed} makes it easier to debug build failures since
5689it provides access to the failed build tree. Another useful
5690command-line option when debugging is @code{--log-file}, to access the
5691build log.
ef5dd60a 5692
cf4a9129
LC
5693If the package is unknown to the @command{guix} command, it may be that
5694the source file contains a syntax error, or lacks a @code{define-public}
5695clause to export the package variable. To figure it out, you may load
5696the module from Guile to get more information about the actual error:
ef5dd60a 5697
cf4a9129
LC
5698@example
5699./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
5700@end example
ef5dd60a 5701
cf4a9129
LC
5702Once your package builds correctly, please send us a patch
5703(@pxref{Contributing}). Well, if you need help, we will be happy to
5704help you too. Once the patch is committed in the Guix repository, the
5705new package automatically gets built on the supported platforms by
2b1cee21 5706@url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
cf4a9129 5707system}.
ef5dd60a 5708
cf4a9129
LC
5709@cindex substituter
5710Users can obtain the new package definition simply by running
5711@command{guix pull} (@pxref{Invoking guix pull}). When
5712@code{hydra.gnu.org} is done building the package, installing the
5713package automatically downloads binaries from there
5714(@pxref{Substitutes}). The only place where human intervention is
5715needed is to review and apply the patch.
ef5dd60a 5716
ef5dd60a 5717
cf4a9129 5718@menu
ec0339cd
LC
5719* Software Freedom:: What may go into the distribution.
5720* Package Naming:: What's in a name?
5721* Version Numbers:: When the name is not enough.
5722* Python Modules:: Taming the snake.
5723* Perl Modules:: Little pearls.
5724* Fonts:: Fond of fonts.
cf4a9129 5725@end menu
ef5dd60a 5726
cf4a9129
LC
5727@node Software Freedom
5728@subsection Software Freedom
ef5dd60a 5729
cf4a9129 5730@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 5731
cf4a9129
LC
5732The GNU operating system has been developed so that users can have
5733freedom in their computing. GNU is @dfn{free software}, meaning that
5734users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
5735essential freedoms}: to run the program, to study and change the program
5736in source code form, to redistribute exact copies, and to distribute
5737modified versions. Packages found in the GNU distribution provide only
5738software that conveys these four freedoms.
c11a6eb1 5739
cf4a9129
LC
5740In addition, the GNU distribution follow the
5741@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
5742software distribution guidelines}. Among other things, these guidelines
5743reject non-free firmware, recommendations of non-free software, and
5744discuss ways to deal with trademarks and patents.
ef5dd60a 5745
cf4a9129
LC
5746Some packages contain a small and optional subset that violates the
5747above guidelines, for instance because this subset is itself non-free
5748code. When that happens, the offending items are removed with
5749appropriate patches or code snippets in the package definition's
5750@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
5751build --source} returns the ``freed'' source rather than the unmodified
5752upstream source.
ef5dd60a 5753
ef5dd60a 5754
cf4a9129
LC
5755@node Package Naming
5756@subsection Package Naming
ef5dd60a 5757
cf4a9129
LC
5758A package has actually two names associated with it:
5759First, there is the name of the @emph{Scheme variable}, the one following
5760@code{define-public}. By this name, the package can be made known in the
5761Scheme code, for instance as input to another package. Second, there is
5762the string in the @code{name} field of a package definition. This name
5763is used by package management commands such as
5764@command{guix package} and @command{guix build}.
ef5dd60a 5765
cf4a9129
LC
5766Both are usually the same and correspond to the lowercase conversion of
5767the project name chosen upstream, with underscores replaced with
5768hyphens. For instance, GNUnet is available as @code{gnunet}, and
5769SDL_net as @code{sdl-net}.
927097ef 5770
cf4a9129 5771We do not add @code{lib} prefixes for library packages, unless these are
081145cf 5772already part of the official project name. But @pxref{Python
cf4a9129
LC
5773Modules} and @ref{Perl Modules} for special rules concerning modules for
5774the Python and Perl languages.
927097ef 5775
1b366ee4 5776Font package names are handled differently, @pxref{Fonts}.
7fec52b7 5777
ef5dd60a 5778
cf4a9129
LC
5779@node Version Numbers
5780@subsection Version Numbers
ef5dd60a 5781
cf4a9129
LC
5782We usually package only the latest version of a given free software
5783project. But sometimes, for instance for incompatible library versions,
5784two (or more) versions of the same package are needed. These require
5785different Scheme variable names. We use the name as defined
5786in @ref{Package Naming}
5787for the most recent version; previous versions use the same name, suffixed
5788by @code{-} and the smallest prefix of the version number that may
5789distinguish the two versions.
ef5dd60a 5790
cf4a9129
LC
5791The name inside the package definition is the same for all versions of a
5792package and does not contain any version number.
ef5dd60a 5793
cf4a9129 5794For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 5795
cf4a9129
LC
5796@example
5797(define-public gtk+
5798 (package
5799 (name "gtk+")
5800 (version "3.9.12")
5801 ...))
5802(define-public gtk+-2
5803 (package
5804 (name "gtk+")
5805 (version "2.24.20")
5806 ...))
5807@end example
5808If we also wanted GTK+ 3.8.2, this would be packaged as
5809@example
5810(define-public gtk+-3.8
5811 (package
5812 (name "gtk+")
5813 (version "3.8.2")
5814 ...))
5815@end example
ef5dd60a 5816
ef5dd60a 5817
cf4a9129
LC
5818@node Python Modules
5819@subsection Python Modules
ef5dd60a 5820
cf4a9129
LC
5821We currently package Python 2 and Python 3, under the Scheme variable names
5822@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
5823To avoid confusion and naming clashes with other programming languages, it
5824seems desirable that the name of a package for a Python module contains
5825the word @code{python}.
ef5dd60a 5826
cf4a9129
LC
5827Some modules are compatible with only one version of Python, others with both.
5828If the package Foo compiles only with Python 3, we name it
5829@code{python-foo}; if it compiles only with Python 2, we name it
5830@code{python2-foo}. If it is compatible with both versions, we create two
5831packages with the corresponding names.
ef5dd60a 5832
cf4a9129
LC
5833If a project already contains the word @code{python}, we drop this;
5834for instance, the module python-dateutil is packaged under the names
5835@code{python-dateutil} and @code{python2-dateutil}.
113daf62 5836
523e4896 5837
cf4a9129
LC
5838@node Perl Modules
5839@subsection Perl Modules
523e4896 5840
cf4a9129
LC
5841Perl programs standing for themselves are named as any other package,
5842using the lowercase upstream name.
5843For Perl packages containing a single class, we use the lowercase class name,
5844replace all occurrences of @code{::} by dashes and prepend the prefix
5845@code{perl-}.
5846So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
5847Modules containing several classes keep their lowercase upstream name and
5848are also prepended by @code{perl-}. Such modules tend to have the word
5849@code{perl} somewhere in their name, which gets dropped in favor of the
5850prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 5851
523e4896 5852
7fec52b7
AE
5853@node Fonts
5854@subsection Fonts
5855
5856For fonts that are in general not installed by a user for typesetting
5857purposes, or that are distributed as part of a larger software package,
5858we rely on the general packaging rules for software; for instance, this
5859applies to the fonts delivered as part of the X.Org system or fonts that
5860are part of TeX Live.
5861
5862To make it easier for a user to search for fonts, names for other packages
5863containing only fonts are constructed as follows, independently of the
5864upstream package name.
5865
5866The name of a package containing only one font family starts with
5867@code{font-}; it is followed by the foundry name and a dash @code{-}
5868if the foundry is known, and the font family name, in which spaces are
5869replaced by dashes (and as usual, all upper case letters are transformed
5870to lower case).
5871For example, the Gentium font family by SIL is packaged under the name
5872@code{font-sil-gentium}.
5873
5874For a package containing several font families, the name of the collection
5875is used in the place of the font family name.
5876For instance, the Liberation fonts consist of three families,
5877Liberation Sans, Liberation Serif and Liberation Mono.
5878These could be packaged separately under the names
5879@code{font-liberation-sans} and so on; but as they are distributed together
5880under a common name, we prefer to package them together as
5881@code{font-liberation}.
5882
5883In the case where several formats of the same font family or font collection
5884are packaged separately, a short form of the format, prepended by a dash,
5885is added to the package name. We use @code{-ttf} for TrueType fonts,
1b366ee4 5886@code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1
7fec52b7
AE
5887fonts.
5888
5889
b25937e3 5890
cf4a9129
LC
5891@node Bootstrapping
5892@section Bootstrapping
b25937e3 5893
cf4a9129 5894@c Adapted from the ELS 2013 paper.
b25937e3 5895
cf4a9129 5896@cindex bootstrapping
7889394e 5897
cf4a9129
LC
5898Bootstrapping in our context refers to how the distribution gets built
5899``from nothing''. Remember that the build environment of a derivation
5900contains nothing but its declared inputs (@pxref{Introduction}). So
5901there's an obvious chicken-and-egg problem: how does the first package
5902get built? How does the first compiler get compiled? Note that this is
5903a question of interest only to the curious hacker, not to the regular
5904user, so you can shamelessly skip this section if you consider yourself
5905a ``regular user''.
72b9d60d 5906
cf4a9129
LC
5907@cindex bootstrap binaries
5908The GNU system is primarily made of C code, with libc at its core. The
5909GNU build system itself assumes the availability of a Bourne shell and
5910command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
5911`grep'. Furthermore, build programs---programs that run
5912@code{./configure}, @code{make}, etc.---are written in Guile Scheme
5913(@pxref{Derivations}). Consequently, to be able to build anything at
5914all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
5915Binutils, libc, and the other packages mentioned above---the
5916@dfn{bootstrap binaries}.
72b9d60d 5917
cf4a9129
LC
5918These bootstrap binaries are ``taken for granted'', though we can also
5919re-create them if needed (more on that later).
72b9d60d 5920
cf4a9129 5921@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 5922
cf4a9129
LC
5923@c As of Emacs 24.3, Info-mode displays the image, but since it's a
5924@c large image, it's hard to scroll. Oh well.
5925@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 5926
cf4a9129
LC
5927The figure above shows the very beginning of the dependency graph of the
5928distribution, corresponding to the package definitions of the @code{(gnu
5929packages bootstrap)} module. At this level of detail, things are
5930slightly complex. First, Guile itself consists of an ELF executable,
5931along with many source and compiled Scheme files that are dynamically
5932loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
5933tarball shown in this graph. This tarball is part of Guix's ``source''
5934distribution, and gets inserted into the store with @code{add-to-store}
5935(@pxref{The Store}).
2e7b5cea 5936
cf4a9129
LC
5937But how do we write a derivation that unpacks this tarball and adds it
5938to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
5939derivation---the first one that gets built---uses @code{bash} as its
5940builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
5941@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
5942@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
5943the Guix source distribution, whose sole purpose is to allow the Guile
5944tarball to be unpacked.
fb729425 5945
cf4a9129
LC
5946Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
5947Guile that can be used to run subsequent build programs. Its first task
5948is to download tarballs containing the other pre-built binaries---this
5949is what the @code{.tar.xz.drv} derivations do. Guix modules such as
5950@code{ftp-client.scm} are used for this purpose. The
5951@code{module-import.drv} derivations import those modules in a directory
5952in the store, using the original layout. The
5953@code{module-import-compiled.drv} derivations compile those modules, and
5954write them in an output directory with the right layout. This
5955corresponds to the @code{#:modules} argument of
5956@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 5957
cf4a9129
LC
5958Finally, the various tarballs are unpacked by the
5959derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
5960etc., at which point we have a working C tool chain.
fb729425 5961
fb729425 5962
cf4a9129 5963@unnumberedsubsec Building the Build Tools
523e4896 5964
cf4a9129
LC
5965@c TODO: Add a package-level dependency graph generated from (gnu
5966@c packages base).
df2ce343 5967
cf4a9129
LC
5968Bootstrapping is complete when we have a full tool chain that does not
5969depend on the pre-built bootstrap tools discussed above. This
5970no-dependency requirement is verified by checking whether the files of
5971the final tool chain contain references to the @file{/gnu/store}
5972directories of the bootstrap inputs. The process that leads to this
5973``final'' tool chain is described by the package definitions found in
1f6f57df 5974the @code{(gnu packages commencement)} module.
df2ce343 5975
cf4a9129
LC
5976@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
5977The first tool that gets built with the bootstrap binaries is
5978GNU Make, which is a prerequisite for all the following packages.
5979From there Findutils and Diffutils get built.
523e4896 5980
cf4a9129
LC
5981Then come the first-stage Binutils and GCC, built as pseudo cross
5982tools---i.e., with @code{--target} equal to @code{--host}. They are
5983used to build libc. Thanks to this cross-build trick, this libc is
5984guaranteed not to hold any reference to the initial tool chain.
4af2447e 5985
cf4a9129
LC
5986From there the final Binutils and GCC are built. GCC uses @code{ld}
5987from the final Binutils, and links programs against the just-built libc.
5988This tool chain is used to build the other packages used by Guix and by
5989the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 5990
cf4a9129
LC
5991And voilà! At this point we have the complete set of build tools that
5992the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
5993variable of the @code{(gnu packages commencement)} module, and are
5994implicitly used by any package that uses @code{gnu-build-system}
1f6f57df 5995(@pxref{Build Systems, @code{gnu-build-system}}).
4af2447e 5996
4af2447e 5997
cf4a9129 5998@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 5999
cf4a9129
LC
6000Because the final tool chain does not depend on the bootstrap binaries,
6001those rarely need to be updated. Nevertheless, it is useful to have an
6002automated way to produce them, should an update occur, and this is what
6003the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 6004
cf4a9129
LC
6005The following command builds the tarballs containing the bootstrap
6006binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
6007of Coreutils and other basic command-line tools):
4b2615e1 6008
cf4a9129
LC
6009@example
6010guix build bootstrap-tarballs
6011@end example
6012
6013The generated tarballs are those that should be referred to in the
6014@code{(gnu packages bootstrap)} module mentioned at the beginning of
6015this section.
6016
6017Still here? Then perhaps by now you've started to wonder: when do we
6018reach a fixed point? That is an interesting question! The answer is
6019unknown, but if you would like to investigate further (and have
6020significant computational and storage resources to do so), then let us
6021know.
6022
6023@node Porting
6024@section Porting to a New Platform
6025
6026As discussed above, the GNU distribution is self-contained, and
6027self-containment is achieved by relying on pre-built ``bootstrap
6028binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
6029operating system kernel, CPU architecture, and application binary
6030interface (ABI). Thus, to port the distribution to a platform that is
6031not yet supported, one must build those bootstrap binaries, and update
6032the @code{(gnu packages bootstrap)} module to use them on that platform.
6033
6034Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
6035When everything goes well, and assuming the GNU tool chain supports the
6036target platform, this can be as simple as running a command like this
6037one:
6038
6039@example
6040guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
6041@end example
6042
1c0c417d
LC
6043For this to work, the @code{glibc-dynamic-linker} procedure in
6044@code{(gnu packages bootstrap)} must be augmented to return the right
6045file name for libc's dynamic linker on that platform; likewise,
6046@code{system->linux-architecture} in @code{(gnu packages linux)} must be
6047taught about the new platform.
6048
cf4a9129 6049Once these are built, the @code{(gnu packages bootstrap)} module needs
1c0c417d
LC
6050to be updated to refer to these binaries on the target platform. That
6051is, the hashes and URLs of the bootstrap tarballs for the new platform
6052must be added alongside those of the currently supported platforms. The
6053bootstrap Guile tarball is treated specially: it is expected to be
6054available locally, and @file{gnu-system.am} has rules do download it for
6055the supported architectures; a rule for the new platform must be added
6056as well.
cf4a9129
LC
6057
6058In practice, there may be some complications. First, it may be that the
6059extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
6060above) is not recognized by all the GNU tools. Typically, glibc
6061recognizes some of these, whereas GCC uses an extra @code{--with-abi}
6062configure flag (see @code{gcc.scm} for examples of how to handle this).
6063Second, some of the required packages could fail to build for that
6064platform. Lastly, the generated binaries could be broken for some
6065reason.
4af2447e
LC
6066
6067
9bf3c1a7
LC
6068@c *********************************************************************
6069@node Contributing
6070@chapter Contributing
6071
6072This project is a cooperative effort, and we need your help to make it
5ff3c4b8
PAR
6073grow! Please get in touch with us on @email{guix-devel@@gnu.org} and
6074@code{#guix} on the Freenode IRC network. We welcome ideas, bug
6075reports, patches, and anything that may be helpful to the project. We
6076particularly welcome help on packaging (@pxref{Packaging Guidelines}).
a1ba8475 6077
9bf3c1a7
LC
6078Please see the
6079@url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING,
6080@file{HACKING} file} that comes with the Guix source code for practical
6081details about contributions.
6082
c78bd12b 6083
568717fd
LC
6084@c *********************************************************************
6085@node Acknowledgments
6086@chapter Acknowledgments
6087
6088Guix is based on the Nix package manager, which was designed and
4c7ac9aa
LC
6089implemented by Eelco Dolstra, with contributions from other people (see
6090the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
568717fd
LC
6091management, and promoted unprecedented features, such as transactional
6092package upgrades and rollbacks, per-user profiles, and referentially
6093transparent build processes. Without this work, Guix would not exist.
6094
6095The Nix-based software distributions, Nixpkgs and NixOS, have also been
6096an inspiration for Guix.
6097
4c7ac9aa
LC
6098GNU@tie{}Guix itself is a collective work with contributions from a
6099number of people. See the @file{AUTHORS} file in Guix for more
6100information on these fine people. The @file{THANKS} file lists people
6101who have helped by reporting bugs, taking care of the infrastructure,
6102providing artwork and themes, making suggestions, and more---thank you!
6103
6104
568717fd
LC
6105@c *********************************************************************
6106@node GNU Free Documentation License
6107@appendix GNU Free Documentation License
6108
6109@include fdl-1.3.texi
6110
6111@c *********************************************************************
6112@node Concept Index
6113@unnumbered Concept Index
6114@printindex cp
6115
a85b83d2
LC
6116@node Programming Index
6117@unnumbered Programming Index
6118@syncodeindex tp fn
6119@syncodeindex vr fn
568717fd
LC
6120@printindex fn
6121
6122@bye
6123
6124@c Local Variables:
6125@c ispell-local-dictionary: "american";
6126@c End: