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