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