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