packages: Add 'package->bag' test for propagated inputs.
[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
2572
c78bd12b
LC
2573@item --derivations
2574@itemx -d
2575Return the derivation paths, not the output paths, of the given
2576packages.
2577
70ee5642
LC
2578@item --root=@var{file}
2579@itemx -r @var{file}
2580Make @var{file} a symlink to the result, and register it as a garbage
2581collector root.
2582
2583@item --log-file
2584Return the build log file names for the given
2585@var{package-or-derivation}s, or raise an error if build logs are
2586missing.
2587
2588This works regardless of how packages or derivations are specified. For
2589instance, the following invocations are equivalent:
2590
2591@example
2592guix build --log-file `guix build -d guile`
2593guix build --log-file `guix build guile`
2594guix build --log-file guile
2595guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
2596@end example
2597
2598
2599@end table
2600
2601@cindex common build options
2602In addition, a number of options that control the build process are
2603common to @command{guix build} and other commands that can spawn builds,
2604such as @command{guix package} or @command{guix archive}. These are the
2605following:
2606
2607@table @code
2608
300868ba
LC
2609@item --load-path=@var{directory}
2610@itemx -L @var{directory}
2611Add @var{directory} to the front of the package module search path
2612(@pxref{Package Modules}).
2613
2614This allows users to define their own packages and make them visible to
2615the command-line tools.
2616
c78bd12b
LC
2617@item --keep-failed
2618@itemx -K
2619Keep the build tree of failed builds. Thus, if a build fail, its build
2620tree is kept under @file{/tmp}, in a directory whose name is shown at
2621the end of the build log. This is useful when debugging build issues.
2622
2623@item --dry-run
2624@itemx -n
2625Do not build the derivations.
2626
56b1f4b7
LC
2627@item --fallback
2628When substituting a pre-built binary fails, fall back to building
2629packages locally.
2630
c78bd12b 2631@item --no-substitutes
b5385b52 2632Do not use substitutes for build products. That is, always build things
c4202d60
LC
2633locally instead of allowing downloads of pre-built binaries
2634(@pxref{Substitutes}).
c78bd12b 2635
425b0bfc 2636@item --no-build-hook
4ec2e92d
LC
2637Do not attempt to offload builds @i{via} the daemon's ``build hook''
2638(@pxref{Daemon Offload Setup}). That is, always build things locally
2639instead of offloading builds to remote machines.
425b0bfc 2640
969e678e
LC
2641@item --max-silent-time=@var{seconds}
2642When the build or substitution process remains silent for more than
2643@var{seconds}, terminate it and report a build failure.
2644
002622b6
LC
2645@item --timeout=@var{seconds}
2646Likewise, when the build or substitution process lasts for more than
2647@var{seconds}, terminate it and report a build failure.
2648
2649By default there is no timeout. This behavior can be restored with
2650@code{--timeout=0}.
2651
07ab4bf1
LC
2652@item --verbosity=@var{level}
2653Use the given verbosity level. @var{level} must be an integer between 0
2654and 5; higher means more verbose output. Setting a level of 4 or more
2655may be helpful when debugging setup issues with the build daemon.
2656
70ee5642
LC
2657@item --cores=@var{n}
2658@itemx -c @var{n}
2659Allow the use of up to @var{n} CPU cores for the build. The special
2660value @code{0} means to use as many CPU cores as available.
bf421152 2661
c78bd12b
LC
2662@end table
2663
e49951eb 2664Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
2665the @code{package-derivation} procedure of the @code{(guix packages)}
2666module, and to the @code{build-derivations} procedure of the @code{(guix
2667store)} module.
2668
210cc920
LC
2669@node Invoking guix download
2670@section Invoking @command{guix download}
2671
2672When writing a package definition, developers typically need to download
2673the package's source tarball, compute its SHA256 hash, and write that
2674hash in the package definition (@pxref{Defining Packages}). The
2675@command{guix download} tool helps with this task: it downloads a file
2676from the given URI, adds it to the store, and prints both its file name
2677in the store and its SHA256 hash.
2678
2679The fact that the downloaded file is added to the store saves bandwidth:
2680when the developer eventually tries to build the newly defined package
2681with @command{guix build}, the source tarball will not have to be
2682downloaded again because it is already in the store. It is also a
2683convenient way to temporarily stash files, which may be deleted
2684eventually (@pxref{Invoking guix gc}).
2685
2686The @command{guix download} command supports the same URIs as used in
2687package definitions. In particular, it supports @code{mirror://} URIs.
2688@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
2689Guile bindings for GnuTLS are available in the user's environment; when
537c8bb3
LC
2690they are not available, an error is raised. @xref{Guile Preparations,
2691how to install the GnuTLS bindings for Guile,, gnutls-guile,
2692GnuTLS-Guile}, for more information.
210cc920
LC
2693
2694The following option is available:
2695
2696@table @code
2697@item --format=@var{fmt}
2698@itemx -f @var{fmt}
2699Write the hash in the format specified by @var{fmt}. For more
2700information on the valid values for @var{fmt}, @ref{Invoking guix hash}.
2701@end table
2702
6c365eca
NK
2703@node Invoking guix hash
2704@section Invoking @command{guix hash}
2705
210cc920 2706The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
2707It is primarily a convenience tool for anyone contributing to the
2708distribution: it computes the cryptographic hash of a file, which can be
2709used in the definition of a package (@pxref{Defining Packages}).
2710
2711The general syntax is:
2712
2713@example
2714guix hash @var{option} @var{file}
2715@end example
2716
2717@command{guix hash} has the following option:
2718
2719@table @code
2720
2721@item --format=@var{fmt}
2722@itemx -f @var{fmt}
210cc920 2723Write the hash in the format specified by @var{fmt}.
6c365eca
NK
2724
2725Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
2726(@code{hex} and @code{hexadecimal} can be used as well).
2727
2728If the @option{--format} option is not specified, @command{guix hash}
2729will output the hash in @code{nix-base32}. This representation is used
2730in the definitions of packages.
2731
3140f2df
LC
2732@item --recursive
2733@itemx -r
2734Compute the hash on @var{file} recursively.
2735
2736In this case, the hash is computed on an archive containing @var{file},
2737including its children if it is a directory. Some of @var{file}'s
2738meta-data is part of the archive; for instance, when @var{file} is a
2739regular file, the hash is different depending on whether @var{file} is
2740executable or not. Meta-data such as time stamps has no impact on the
2741hash (@pxref{Invoking guix archive}).
2742@c FIXME: Replace xref above with xref to an ``Archive'' section when
2743@c it exists.
2744
6c365eca
NK
2745@end table
2746
37166310
LC
2747@node Invoking guix refresh
2748@section Invoking @command{guix refresh}
2749
2750The primary audience of the @command{guix refresh} command is developers
2751of the GNU software distribution. By default, it reports any packages
2752provided by the distribution that are outdated compared to the latest
2753upstream version, like this:
2754
2755@example
2756$ guix refresh
2757gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
2758gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
2759@end example
2760
2761It does so by browsing each package's FTP directory and determining the
2762highest version number of the source tarballs
2763therein@footnote{Currently, this only works for GNU packages.}.
2764
2765When passed @code{--update}, it modifies distribution source files to
2766update the version numbers and source tarball hashes of those packages'
2767recipes (@pxref{Defining Packages}). This is achieved by downloading
2768each package's latest source tarball and its associated OpenPGP
2769signature, authenticating the downloaded tarball against its signature
2770using @command{gpg}, and finally computing its hash. When the public
2771key used to sign the tarball is missing from the user's keyring, an
2772attempt is made to automatically retrieve it from a public key server;
2773when it's successful, the key is added to the user's keyring; otherwise,
2774@command{guix refresh} reports an error.
2775
2776The following options are supported:
2777
2778@table @code
2779
2780@item --update
2781@itemx -u
2782Update distribution source files (package recipes) in place.
2783@ref{Defining Packages}, for more information on package definitions.
2784
2785@item --select=[@var{subset}]
2786@itemx -s @var{subset}
2787Select all the packages in @var{subset}, one of @code{core} or
2788@code{non-core}.
2789
2790The @code{core} subset refers to all the packages at the core of the
2791distribution---i.e., packages that are used to build ``everything
2792else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
2793changing one of these packages in the distribution entails a rebuild of
2794all the others. Thus, such updates are an inconvenience to users in
2795terms of build time or bandwidth used to achieve the upgrade.
2796
2797The @code{non-core} subset refers to the remaining packages. It is
2798typically useful in cases where an update of the core packages would be
2799inconvenient.
2800
2801@end table
2802
2803In addition, @command{guix refresh} can be passed one or more package
2804names, as in this example:
2805
2806@example
2807guix refresh -u emacs idutils
2808@end example
2809
2810@noindent
2811The command above specifically updates the @code{emacs} and
2812@code{idutils} packages. The @code{--select} option would have no
2813effect in this case.
2814
7d193ec3
EB
2815When considering whether to upgrade a package, it is sometimes
2816convenient to know which packages would be affected by the upgrade and
2817should be checked for compatibility. For this the following option may
2818be used when passing @command{guix refresh} one or more package names:
2819
2820@table @code
2821
2822@item --list-dependent
2823@itemx -l
2824List top-level dependent packages that would need to be rebuilt as a
2825result of upgrading one or more packages.
2826
2827@end table
2828
2829Be aware that the @code{--list-dependent} option only
2830@emph{approximates} the rebuilds that would be required as a result of
2831an upgrade. More rebuilds might be required under some circumstances.
2832
2833@example
7779ab61
LC
2834$ guix refresh --list-dependent flex
2835Building the following 120 packages would ensure 213 dependent packages are rebuilt:
2836hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
2837@end example
2838
2839The command above lists a set of packages that could be built to check
2840for compatibility with an upgraded @code{flex} package.
2841
f9230085
LC
2842The following options can be used to customize GnuPG operation:
2843
2844@table @code
2845
2846@item --key-server=@var{host}
2847Use @var{host} as the OpenPGP key server when importing a public key.
2848
2849@item --gpg=@var{command}
2850Use @var{command} as the GnuPG 2.x command. @var{command} is searched
2851for in @code{$PATH}.
2852
2853@end table
2854
b4f5e0e8
CR
2855@node Invoking guix lint
2856@section Invoking @command{guix lint}
2857The @command{guix lint} is meant to help package developers avoid common
2858errors and use a consistent style. It runs a few checks on a given set of
2859packages in order to find common mistakes in their definitions.
2860
2861The general syntax is:
2862
2863@example
2864guix lint @var{options} @var{package}@dots{}
2865@end example
2866
2867If no package is given on the command line, then all packages are checked.
2868The @var{options} may be zero or more of the following:
2869
2870@table @code
2871
dd7c013d
CR
2872@item --checkers
2873@itemx -c
2874Only enable the checkers specified in a comma-separated list using the
2875names returned by @code{--list-checkers}.
2876
b4f5e0e8
CR
2877@item --list-checkers
2878@itemx -l
2879List and describe all the available checkers that will be run on packages
2880and exit.
2881
2882@end table
37166310 2883
372c4bbc
DT
2884@node Invoking guix environment
2885@section Invoking @command{guix environment}
2886
2887The purpose of @command{guix environment} is to assist hackers in
2888creating reproducible development environments without polluting their
2889package profile. The @command{guix environment} tool takes one or more
2890packages, builds all of the necessary inputs, and creates a shell
2891environment to use them.
2892
2893The general syntax is:
2894
2895@example
2896guix environment @var{options} @var{package}@dots{}
2897@end example
2898
2899The following examples spawns a new shell that is capable of building
2900the GNU Guile source code:
2901
2902@example
2903guix environment guile
2904@end example
2905
2906If the specified packages are not built yet, @command{guix environment}
2907automatically builds them. The new shell's environment is an augmented
2908version of the environment that @command{guix environment} was run in.
2909It contains the necessary search paths for building the given package
2910added to the existing environment variables. To create a ``pure''
2911environment in which the original environment variables have been unset,
2912use the @code{--pure} option.
2913
2914Additionally, more than one package may be specified, in which case the
2915union of the inputs for the given packages are used. For example, the
2916command below spawns a shell where all of the dependencies of both Guile
2917and Emacs are available:
2918
2919@example
2920guix environment guile emacs
2921@end example
2922
2923Sometimes an interactive shell session is not desired. The
2924@code{--exec} option can be used to specify the command to run instead.
2925
2926@example
2927guix environment guile --exec=make
2928@end example
2929
2930The following options are available:
2931
2932@table @code
2933@item --expression=@var{expr}
2934@itemx -e @var{expr}
2935Create an environment for the package that @var{expr} evaluates to.
2936
2937@item --load=@var{file}
2938@itemx -l @var{file}
2939Create an environment for the package that the code within @var{file}
2940evaluates to.
2941
2942@item --exec=@var{command}
2943@item -E @var{command}
2944Execute @var{command} in the new environment.
2945
2946@item --pure
2947Unset existing environment variables when building the new environment.
2948This has the effect of creating an environment in which search paths
2949only contain package inputs.
2950
2951@item --search-paths
2952Display the environment variable definitions that make up the
2953environment.
2954@end table
2955
2956It also supports all of the common build options that @command{guix
2957build} supports (@pxref{Invoking guix build, common build options}).
2958
a1ba8475
LC
2959@c *********************************************************************
2960@node GNU Distribution
2961@chapter GNU Distribution
2962
2963Guix comes with a distribution of free software@footnote{The term
2964``free'' here refers to the
2965@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
c320011d 2966users of that software}.} that forms the basis of the GNU system. This
a1ba8475
LC
2967includes core GNU packages such as GNU libc, GCC, and Binutils, as well
2968as many GNU and non-GNU applications. The complete list of available
d03bb653
LC
2969packages can be browsed
2970@url{http://www.gnu.org/software/guix/package-list.html,on-line} or by
2971running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
2972
2973@example
e49951eb 2974guix package --list-available
a1ba8475
LC
2975@end example
2976
401c53c4
LC
2977Our goal is to build a practical 100% free software distribution of
2978Linux-based and other variants of GNU, with a focus on the promotion and
2979tight integration of GNU components, and an emphasis on programs and
2980tools that help users exert that freedom.
2981
c320011d
LC
2982The GNU distribution is currently available on the following platforms:
2983
2984@table @code
2985
2986@item x86_64-linux
2987Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
2988
2989@item i686-linux
2990Intel 32-bit architecture (IA32), Linux-Libre kernel;
2991
2992@item mips64el-linux
2993little-endian 64-bit MIPS processors, specifically the Loongson series,
2994n32 application binary interface (ABI), and Linux-Libre kernel.
2995
2996@end table
2997
2998@noindent
2999For information on porting to other architectures or kernels,
3000@xref{Porting}.
3001
401c53c4 3002@menu
5af6de3e 3003* System Installation:: Installing the whole operating system.
cf4a9129 3004* System Configuration:: Configuring a GNU system.
91ef73d4 3005* Installing Debugging Files:: Feeding the debugger.
401c53c4 3006* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 3007* Packaging Guidelines:: Growing the distribution.
401c53c4 3008* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 3009* Porting:: Targeting another platform or kernel.
401c53c4
LC
3010@end menu
3011
3012Building this distribution is a cooperative effort, and you are invited
3013to join! @ref{Contributing}, for information about how you can help.
3014
5af6de3e
LC
3015@node System Installation
3016@section System Installation
3017
3018This section explains how to install the complete GNU operating system
3019on a machine. The Guix package manager can also be installed on top of
6621cdb6 3020a running GNU/Linux system, @pxref{Installation}.
5af6de3e
LC
3021
3022@ifinfo
3023@c This paragraph is for people reading this from tty2 of the
3024@c installation image.
3025You're reading this documentation with an Info reader. For details on
3026how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 3027link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
3028@kbd{l} afterwards to come back here.
3029@end ifinfo
3030
8aaaae38
LC
3031@subsection Limitations
3032
3033As of version @value{VERSION}, GNU@tie{}Guix and the GNU system
3034distribution are alpha software. It may contain bugs and lack important
3035features. Thus, if you are looking for a stable production system that
3036respects your freedom as a computer user, a good solution at this point
3037is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
3038more established GNU/Linux distributions}. We hope you can soon switch
3039to the GNU system without fear, of course. In the meantime, you can
3040also keep using your distribution and try out the package manager on top
3041of it (@pxref{Installation}).
3042
3043Before you proceed with the installation, be aware of the following
3044noteworthy limitations applicable to version @value{VERSION}:
3045
3046@itemize
3047@item
3048The installation process does not include a graphical user interface and
3049requires familiarity with GNU/Linux (see the following subsections to
3050get a feel of what that means.)
3051
3052@item
3053The system does not yet provide graphical desktop environments such as
3054GNOME and KDE.
3055
3056@item
dbcb0ab1 3057Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
3058
3059@item
3060Few system services are currently supported out-of-the-box
3061(@pxref{Services}).
3062
3063@item
3064On the order of 1,000 packages are available, which means that you may
3065occasionally find that a useful package is missing.
3066@end itemize
3067
3068You've been warned. But more than a disclaimer, this is an invitation
3069to report issues (and success stories!), and join us in improving it.
3070@xref{Contributing}, for more info.
5af6de3e
LC
3071
3072@subsection USB Stick Installation
3073
3074An installation image for USB sticks can be downloaded from
3075@url{ftp://alpha.gnu.org/gnu/guix/gnu-usb-install-@value{VERSION}.@var{system}.xz},
3076where @var{system} is one of:
3077
3078@table @code
3079@item x86_64-linux
3080for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
3081
3082@item i686-linux
3083for a 32-bit GNU/Linux system on Intel-compatible CPUs.
3084@end table
3085
3086This image contains a single partition with the tools necessary for an
3087installation. It is meant to be copied @emph{as is} to a large-enough
3088USB stick.
3089
3090To copy the image to a USB stick, follow these steps:
3091
3092@enumerate
3093@item
3094Decompress the image using the @command{xz} command:
3095
3096@example
3097xz -d gnu-usb-install-@value{VERSION}.@var{system}.xz
3098@end example
3099
3100@item
3101Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
3102its device name. Assuming that USB stick is known as @file{/dev/sdX},
3103copy the image with:
3104
3105@example
445d6529 3106dd if=gnu-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
3107@end example
3108
3109Access to @file{/dev/sdX} usually requires root privileges.
3110@end enumerate
3111
3112Once this is done, you should be able to reboot the system and boot from
3113the USB stick. The latter usually requires you to get in the BIOS' boot
3114menu, where you can choose to boot from the USB stick.
3115
3116@subsection Preparing for Installation
3117
3118Once you have successfully booted the image on the USB stick, you should
3119end up with a root prompt. Several console TTYs are configured and can
3120be used to run commands as root. TTY2 shows this documentation,
3121browsable using the Info reader commands (@pxref{Help,,, info, Info: An
3122Introduction}).
3123
3124To install the system, you would:
3125
3126@enumerate
3127
3128@item
3129Configure the network, by running @command{dhclient eth0} (to get an
3130automatically assigned IP address from the wired network interface
3131controller), or using the @command{ifconfig} command.
3132
3133The system automatically loads drivers for your network interface
3134controllers.
3135
3136Setting up network access is almost always a requirement because the
3137image does not contain all the software and tools that may be needed.
3138
3139@item
3140Unless this has already been done, you must partition and format the
3141target partitions.
3142
7ab44369
LC
3143Preferably, assign partitions a label so that you can easily and
3144reliably refer to them in @code{file-system} declarations (@pxref{File
3145Systems}). This is typically done using the @code{-L} option of
3146@command{mkfs.ext4} and related commands.
3147
5af6de3e
LC
3148The installation image includes Parted (@pxref{Overview,,, parted, GNU
3149Parted User Manual}), @command{fdisk}, and e2fsprogs, the suite of tools
3150to manipulate ext2/ext3/ext4 file systems.
3151
83a17b62
LC
3152@item
3153Once that is done, mount the target root partition under @file{/mnt}.
3154
3155@item
3156Lastly, run @code{deco start cow-store /mnt}.
3157
3158This will make @file{/gnu/store} copy-on-write, such that packages added
3159to it during the installation phase will be written to the target disk
3160rather than kept in memory.
3161
5af6de3e
LC
3162@end enumerate
3163
5af6de3e
LC
3164
3165@subsection Proceeding with the Installation
3166
3167With the target partitions ready, you now have to edit a file and
3168provide the declaration of the operating system to be installed. To
3169that end, the installation system comes with two text editors: GNU nano
3170(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
3171It is better to store that file on the target root file system, say, as
3172@file{/mnt/etc/config.scm}.
3173
3174A minimal operating system configuration, with just the bare minimum and
1dac8566
LC
3175only a root account would look like this (on the installation system,
3176this example is available as @file{/etc/configuration-template.scm}):
5af6de3e
LC
3177
3178@example
931c132a 3179@include os-config.texi
5af6de3e
LC
3180@end example
3181
3182@noindent
3183For more information on @code{operating-system} declarations,
6621cdb6 3184@pxref{Using the Configuration System}.
5af6de3e
LC
3185
3186Once that is done, the new system must be initialized (remember that the
3187target root file system is mounted under @file{/mnt}):
3188
3189@example
3190guix system init /mnt/etc/config.scm /mnt
3191@end example
3192
3193@noindent
3194This will copy all the necessary files, and install GRUB on
3195@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 3196more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
3197downloads or builds of missing packages, which can take some time.
3198
3199Once that command has completed---and hopefully succeeded!---you can
ad14d9e7 3200run @command{reboot} and boot into the new system. Cross fingers, and
5af6de3e
LC
3201join us on @code{#guix} on the Freenode IRC network or on
3202@file{guix-devel@@gnu.org} to share your experience---good or not so
3203good.
3204
3205@subsection Building the Installation Image
3206
3207The installation image described above was built using the @command{guix
3208system} command, specifically:
3209
3210@example
3211guix system disk-image --image-size=800MiB gnu/system/install.scm
3212@end example
3213
3214@xref{Invoking guix system}, for more information. See
3215@file{gnu/system/install.scm} in the source tree for more information
3216about the installation image.
3217
cf4a9129
LC
3218@node System Configuration
3219@section System Configuration
b208a005 3220
cf4a9129
LC
3221@cindex system configuration
3222The GNU system supports a consistent whole-system configuration
3223mechanism. By that we mean that all aspects of the global system
3224configuration---such as the available system services, timezone and
3225locale settings, user accounts---are declared in a single place. Such
3226a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 3227
cf4a9129
LC
3228One of the advantages of putting all the system configuration under the
3229control of Guix is that it supports transactional system upgrades, and
3230makes it possible to roll-back to a previous system instantiation,
3231should something go wrong with the new one (@pxref{Features}). Another
3232one is that it makes it easy to replicate the exact same configuration
3233across different machines, or at different points in time, without
3234having to resort to additional administration tools layered on top of
3235the system's own tools.
3236@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 3237
cf4a9129
LC
3238This section describes this mechanism. First we focus on the system
3239administrator's viewpoint---explaining how the system is configured and
3240instantiated. Then we show how this mechanism can be extended, for
3241instance to support new system services.
91ef73d4 3242
cf4a9129
LC
3243@menu
3244* Using the Configuration System:: Customizing your GNU system.
7313a52e 3245* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 3246* File Systems:: Configuring file system mounts.
510f9d86 3247* Mapped Devices:: Block device extra processing.
cf4a9129
LC
3248* User Accounts:: Specifying user accounts.
3249* Services:: Specifying system services.
0ae8c15a 3250* Setuid Programs:: Programs running with root privileges.
fd1b1fa2 3251* Initial RAM Disk:: Linux-Libre bootstrapping.
cf4a9129
LC
3252* Invoking guix system:: Instantiating a system configuration.
3253* Defining Services:: Adding new service definitions.
3254@end menu
91ef73d4 3255
cf4a9129
LC
3256@node Using the Configuration System
3257@subsection Using the Configuration System
64d76fa6 3258
cf4a9129
LC
3259The operating system is configured by providing an
3260@code{operating-system} declaration in a file that can then be passed to
3261the @command{guix system} command (@pxref{Invoking guix system}). A
3262simple setup, with the default system services, the default Linux-Libre
3263kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 3264
cf4a9129
LC
3265@findex operating-system
3266@lisp
3267(use-modules (gnu) ; for 'user-account', '%base-services', etc.
3268 (gnu packages emacs) ; for 'emacs'
3269 (gnu services ssh)) ; for 'lsh-service'
91ef73d4 3270
cf4a9129
LC
3271(operating-system
3272 (host-name "komputilo")
3273 (timezone "Europe/Paris")
3274 (locale "fr_FR.UTF-8")
3275 (bootloader (grub-configuration
3276 (device "/dev/sda")))
a69576ea 3277 (file-systems (cons (file-system
cf4a9129
LC
3278 (device "/dev/sda1") ; or partition label
3279 (mount-point "/")
a69576ea
LC
3280 (type "ext3"))
3281 %base-file-systems))
cf4a9129
LC
3282 (users (list (user-account
3283 (name "alice")
3284 (password "")
1c00f836 3285 (uid 1000) (group 100)
cf4a9129
LC
3286 (comment "Bob's sister")
3287 (home-directory "/home/alice"))))
3288 (packages (cons emacs %base-packages))
3289 (services (cons (lsh-service #:port 2222 #:allow-root-login? #t)
3290 %base-services)))
3291@end lisp
401c53c4 3292
cf4a9129
LC
3293This example should be self-describing. Some of the fields defined
3294above, such as @code{host-name} and @code{bootloader}, are mandatory.
3295Others, such as @code{packages} and @code{services}, can be omitted, in
3296which case they get a default value.
e7f34eb0 3297
cf4a9129
LC
3298@vindex %base-packages
3299The @code{packages} field lists
3300packages that will be globally visible on the system, for all user
3301accounts---i.e., in every user's @code{PATH} environment variable---in
3302addition to the per-user profiles (@pxref{Invoking guix package}). The
3303@var{%base-packages} variable provides all the tools one would expect
3304for basic user and administrator tasks---including the GNU Core
3305Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
3306editor, @command{find}, @command{grep}, etc. The example above adds
3307Emacs to those, taken from the @code{(gnu packages emacs)} module
3308(@pxref{Package Modules}).
e7f34eb0 3309
cf4a9129
LC
3310@vindex %base-services
3311The @code{services} field lists @dfn{system services} to be made
3312available when the system starts (@pxref{Services}).
3313The @code{operating-system} declaration above specifies that, in
3314addition to the basic services, we want the @command{lshd} secure shell
3315daemon listening on port 2222, and allowing remote @code{root} logins
3316(@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
3317@code{lsh-service} arranges so that @code{lshd} is started with the
3318right command-line options, possibly with supporting configuration files
7313a52e
LC
3319generated as needed (@pxref{Defining Services}). @xref{operating-system
3320Reference}, for details about the available @code{operating-system}
3321fields.
a1ba8475 3322
cf4a9129
LC
3323Assuming the above snippet is stored in the @file{my-system-config.scm}
3324file, the @command{guix system reconfigure my-system-config.scm} command
3325instantiates that configuration, and makes it the default GRUB boot
3326entry (@pxref{Invoking guix system}). The normal way to change the
3327system's configuration is by updating this file and re-running the
3328@command{guix system} command.
b81e1947 3329
cf4a9129
LC
3330At the Scheme level, the bulk of an @code{operating-system} declaration
3331is instantiated with the following monadic procedure (@pxref{The Store
3332Monad}):
b81e1947 3333
cf4a9129
LC
3334@deffn {Monadic Procedure} operating-system-derivation os
3335Return a derivation that builds @var{os}, an @code{operating-system}
3336object (@pxref{Derivations}).
b81e1947 3337
cf4a9129
LC
3338The output of the derivation is a single directory that refers to all
3339the packages, configuration files, and other supporting files needed to
3340instantiate @var{os}.
3341@end deffn
b81e1947 3342
7313a52e
LC
3343@node operating-system Reference
3344@subsection @code{operating-system} Reference
3345
3346This section summarizes all the options available in
3347@code{operating-system} declarations (@pxref{Using the Configuration
3348System}).
3349
3350@deftp {Data Type} operating-system
3351This is the data type representing an operating system configuration.
3352By that, we mean all the global system configuration, not per-user
3353configuration (@pxref{Using the Configuration System}).
3354
3355@table @asis
3356@item @code{kernel} (default: @var{linux-libre})
3357The package object of the operating system to use@footnote{Currently
3358only the Linux-libre kernel is supported. In the future, it will be
3359possible to use the GNU@tie{}Hurd.}.
3360
3361@item @code{bootloader}
3362The system bootloader configuration object.
3363@c FIXME: Add xref to bootloader section.
3364
3365@item @code{initrd} (default: @code{base-initrd})
3366A two-argument monadic procedure that returns an initial RAM disk for
3367the Linux kernel. @xref{Initial RAM Disk}.
3368
3369@item @code{host-name}
3370The host name.
3371
3372@item @code{hosts-file}
3373@cindex hosts file
3374A zero-argument monadic procedure that returns a text file for use as
3375@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
3376Reference Manual}). The default is to produce a file with entries for
3377@code{localhost} and @var{host-name}.
3378
3379@item @code{mapped-devices} (default: @code{'()})
3380A list of mapped devices. @xref{Mapped Devices}.
3381
3382@item @code{file-systems}
3383A list of file systems. @xref{File Systems}.
3384
3385@item @code{swap-devices} (default: @code{'()})
3386@cindex swap devices
3387A list of strings identifying devices to be used for ``swap space''
3388(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
3389For example, @code{'("/dev/sda3")}.
3390
3391@item @code{users} (default: @code{'()})
3392@itemx @code{groups} (default: @var{%base-groups})
3393List of user accounts and groups. @xref{User Accounts}.
3394
3395@item @code{skeletons} (default: @code{(default-skeletons)})
3396A monadic list of pairs of target file name and files. These are the
3397files that will be used as skeletons as new accounts are created.
3398
3399For instance, a valid value may look like this:
3400
3401@example
3402(mlet %store-monad ((bashrc (text-file "bashrc" "\
3403 export PATH=$HOME/.guix-profile/bin")))
3404 (return `((".bashrc" ,bashrc))))
3405@end example
3406
3407@item @code{issue} (default: @var{%default-issue})
3408A string denoting the contents of the @file{/etc/issue} file, which is
3409what displayed when users log in on a text console.
3410
3411@item @code{packages} (default: @var{%base-packages})
3412The set of packages installed in the global profile, which is accessible
3413at @file{/run/current-system/profile}.
3414
3415The default set includes core utilities, but it is good practice to
3416install non-core utilities in user profiles (@pxref{Invoking guix
3417package}).
3418
3419@item @code{timezone}
3420A timezone identifying string---e.g., @code{"Europe/Paris"}.
3421
3422@item @code{locale} (default: @code{"en_US.UTF-8"})
3423The name of the default locale (@pxref{Locales,,, libc, The GNU C
3424Library Reference Manual}).
3425
3426@item @code{services} (default: @var{%base-services})
3427A list of monadic values denoting system services. @xref{Services}.
3428
3429@item @code{pam-services} (default: @code{(base-pam-services)})
3430@cindex PAM
3431@cindex pluggable authentication modules
3432Linux @dfn{pluggable authentication module} (PAM) services.
3433@c FIXME: Add xref to PAM services section.
3434
3435@item @code{setuid-programs} (default: @var{%setuid-programs})
3436List of string-valued G-expressions denoting setuid programs.
3437@xref{Setuid Programs}.
3438
3439@item @code{sudoers} (default: @var{%sudoers-specification})
3440@cindex sudoers
3441The contents of the @file{/etc/sudoers} file as a string.
3442
3443This file specifies which users can use the @command{sudo} command, what
3444they are allowed to do, and what privileges they may gain. The default
3445is that only @code{root} and members of the @code{wheel} group may use
3446@code{sudo}.
3447
3448@end table
3449@end deftp
3450
cf4a9129
LC
3451@node File Systems
3452@subsection File Systems
b81e1947 3453
cf4a9129
LC
3454The list of file systems to be mounted is specified in the
3455@code{file-systems} field of the operating system's declaration
3456(@pxref{Using the Configuration System}). Each file system is declared
3457using the @code{file-system} form, like this:
b81e1947
LC
3458
3459@example
cf4a9129
LC
3460(file-system
3461 (mount-point "/home")
3462 (device "/dev/sda3")
3463 (type "ext4"))
b81e1947
LC
3464@end example
3465
cf4a9129
LC
3466As usual, some of the fields are mandatory---those shown in the example
3467above---while others can be omitted. These are described below.
b81e1947 3468
cf4a9129
LC
3469@deftp {Data Type} file-system
3470Objects of this type represent file systems to be mounted. They
3471contain the following members:
5ff3c4b8 3472
cf4a9129
LC
3473@table @asis
3474@item @code{type}
3475This is a string specifying the type of the file system---e.g.,
3476@code{"ext4"}.
5ff3c4b8 3477
cf4a9129
LC
3478@item @code{mount-point}
3479This designates the place where the file system is to be mounted.
b81e1947 3480
cf4a9129
LC
3481@item @code{device}
3482This names the ``source'' of the file system. By default it is the name
3483of a node under @file{/dev}, but its meaning depends on the @code{title}
3484field described below.
401c53c4 3485
cf4a9129
LC
3486@item @code{title} (default: @code{'device})
3487This is a symbol that specifies how the @code{device} field is to be
3488interpreted.
401c53c4 3489
cf4a9129
LC
3490When it is the symbol @code{device}, then the @code{device} field is
3491interpreted as a file name; when it is @code{label}, then @code{device}
3492is interpreted as a partition label name; when it is @code{uuid},
3493@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 3494
cf4a9129
LC
3495The @code{label} and @code{uuid} options offer a way to refer to disk
3496partitions without having to hard-code their actual device name.
da7cabd4 3497
cf4a9129
LC
3498@item @code{flags} (default: @code{'()})
3499This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
3500include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
3501access to special files), @code{no-suid} (ignore setuid and setgid
3502bits), and @code{no-exec} (disallow program execution.)
da7cabd4 3503
cf4a9129
LC
3504@item @code{options} (default: @code{#f})
3505This is either @code{#f}, or a string denoting mount options.
da7cabd4 3506
cf4a9129
LC
3507@item @code{needed-for-boot?} (default: @code{#f})
3508This Boolean value indicates whether the file system is needed when
3509booting. If that is true, then the file system is mounted when the
3510initial RAM disk (initrd) is loaded. This is always the case, for
3511instance, for the root file system.
da7cabd4 3512
cf4a9129
LC
3513@item @code{check?} (default: @code{#t})
3514This Boolean indicates whether the file system needs to be checked for
3515errors before being mounted.
f9cc8971 3516
4e469051
LC
3517@item @code{create-mount-point?} (default: @code{#f})
3518When true, the mount point is created if it does not exist yet.
3519
cf4a9129
LC
3520@end table
3521@end deftp
da7cabd4 3522
a69576ea
LC
3523The @code{(gnu system file-systems)} exports the following useful
3524variables.
3525
3526@defvr {Scheme Variable} %base-file-systems
3527These are essential file systems that are required on normal systems,
3528such as @var{%devtmpfs-file-system} (see below.) Operating system
3529declarations should always contain at least these.
3530@end defvr
3531
3532@defvr {Scheme Variable} %devtmpfs-file-system
3533The @code{devtmpfs} file system to be mounted on @file{/dev}. This is a
3534requirement for udev (@pxref{Base Services, @code{udev-service}}).
3535@end defvr
3536
7f239fd3
LC
3537@defvr {Scheme Variable} %pseudo-terminal-file-system
3538This is the file system to be mounted as @file{/dev/pts}. It supports
3539@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
3540functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
3541Manual}). Pseudo-terminals are used by terminal emulators such as
3542@command{xterm}.
3543@end defvr
3544
db17ae5c
LC
3545@defvr {Scheme Variable} %shared-memory-file-system
3546This file system is mounted as @file{/dev/shm} and is used to support
3547memory sharing across processes (@pxref{Memory-mapped I/O,
3548@code{shm_open},, libc, The GNU C Library Reference Manual}).
3549@end defvr
3550
a69576ea
LC
3551@defvr {Scheme Variable} %binary-format-file-system
3552The @code{binfmt_misc} file system, which allows handling of arbitrary
3553executable file types to be delegated to user space. This requires the
3554@code{binfmt.ko} kernel module to be loaded.
3555@end defvr
3556
3557@defvr {Scheme Variable} %fuse-control-file-system
3558The @code{fusectl} file system, which allows unprivileged users to mount
3559and unmount user-space FUSE file systems. This requires the
3560@code{fuse.ko} kernel module to be loaded.
3561@end defvr
3562
510f9d86
LC
3563@node Mapped Devices
3564@subsection Mapped Devices
3565
3566@cindex device mapping
3567@cindex mapped devices
3568The Linux kernel has a notion of @dfn{device mapping}: a block device,
3569such as a hard disk partition, can be @dfn{mapped} into another device,
3570with additional processing over the data that flows through
3571it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
3572concept of a ``mapped device'' and that of a file system: both boil down
3573to @emph{translating} input/output operations made on a file to
3574operations on its backing store. Thus, the Hurd implements mapped
3575devices, like file systems, using the generic @dfn{translator} mechanism
3576(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
3577typical example is encryption device mapping: all writes to the mapped
3578device are encrypted, and all reads are deciphered, transparently.
3579
3580Mapped devices are declared using the @code{mapped-device} form:
3581
3582@example
3583(mapped-device
3584 (source "/dev/sda3")
3585 (target "home")
3586 (type luks-device-mapping))
3587@end example
3588
3589@noindent
3590@cindex disk encryption
3591@cindex LUKS
3592This example specifies a mapping from @file{/dev/sda3} to
3593@file{/dev/mapper/home} using LUKS---the
3594@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
3595standard mechanism for disk encryption. The @file{/dev/mapper/home}
3596device can then be used as the @code{device} of a @code{file-system}
3597declaration (@pxref{File Systems}). The @code{mapped-device} form is
3598detailed below.
3599
3600@deftp {Data Type} mapped-device
3601Objects of this type represent device mappings that will be made when
3602the system boots up.
3603
3604@table @code
3605@item source
3606This string specifies the name of the block device to be mapped, such as
3607@code{"/dev/sda3"}.
3608
3609@item target
3610This string specifies the name of the mapping to be established. For
3611example, specifying @code{"my-partition"} will lead to the creation of
3612the @code{"/dev/mapper/my-partition"} device.
3613
3614@item type
3615This must be a @code{mapped-device-kind} object, which specifies how
3616@var{source} is mapped to @var{target}.
3617@end table
3618@end deftp
3619
3620@defvr {Scheme Variable} luks-device-mapping
3621This defines LUKS block device encryption using the @command{cryptsetup}
3622command, from the same-named package. This relies on the
3623@code{dm-crypt} Linux kernel module.
3624@end defvr
3625
cf4a9129
LC
3626@node User Accounts
3627@subsection User Accounts
ee85f3db 3628
cf4a9129 3629User accounts are specified with the @code{user-account} form:
ee85f3db 3630
cf4a9129
LC
3631@example
3632(user-account
3633 (name "alice")
3634 (group "users")
24e752c0
LC
3635 (supplementary-groups '("wheel" ;allow use of sudo, etc.
3636 "audio" ;sound card
3637 "video" ;video devices such as webcams
3638 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
3639 (comment "Bob's sister")
3640 (home-directory "/home/alice"))
3641@end example
25083588 3642
cf4a9129
LC
3643@deftp {Data Type} user-account
3644Objects of this type represent user accounts. The following members may
3645be specified:
ee85f3db 3646
cf4a9129
LC
3647@table @asis
3648@item @code{name}
3649The name of the user account.
ee85f3db 3650
cf4a9129
LC
3651@item @code{group}
3652This is the name (a string) or identifier (a number) of the user group
3653this account belongs to.
ee85f3db 3654
cf4a9129
LC
3655@item @code{supplementary-groups} (default: @code{'()})
3656Optionally, this can be defined as a list of group names that this
3657account belongs to.
ee85f3db 3658
cf4a9129
LC
3659@item @code{uid} (default: @code{#f})
3660This is the user ID for this account (a number), or @code{#f}. In the
3661latter case, a number is automatically chosen by the system when the
3662account is created.
ee85f3db 3663
cf4a9129
LC
3664@item @code{comment} (default: @code{""})
3665A comment about the account, such as the account's owner full name.
c8c871d1 3666
cf4a9129
LC
3667@item @code{home-directory}
3668This is the name of the home directory for the account.
ee85f3db 3669
cf4a9129
LC
3670@item @code{shell} (default: Bash)
3671This is a G-expression denoting the file name of a program to be used as
3672the shell (@pxref{G-Expressions}).
ee85f3db 3673
cf4a9129
LC
3674@item @code{system?} (default: @code{#f})
3675This Boolean value indicates whether the account is a ``system''
3676account. System accounts are sometimes treated specially; for instance,
3677graphical login managers do not list them.
ee85f3db 3678
cf4a9129
LC
3679@item @code{password} (default: @code{#f})
3680Unless @code{#f}, this is the password to be used for the account.
c8c871d1 3681
cf4a9129
LC
3682@end table
3683@end deftp
ee85f3db 3684
cf4a9129 3685User group declarations are even simpler:
ee85f3db 3686
cf4a9129
LC
3687@example
3688(user-group (name "students"))
3689@end example
ee85f3db 3690
cf4a9129
LC
3691@deftp {Data Type} user-group
3692This type is for, well, user groups. There are just a few fields:
af8a56b8 3693
cf4a9129
LC
3694@table @asis
3695@item @code{name}
3696The group's name.
ee85f3db 3697
cf4a9129
LC
3698@item @code{id} (default: @code{#f})
3699The group identifier (a number). If @code{#f}, a new number is
3700automatically allocated when the group is created.
ee85f3db 3701
c8fa3426
LC
3702@item @code{system?} (default: @code{#f})
3703This Boolean value indicates whether the group is a ``system'' group.
3704System groups have low numerical IDs.
3705
cf4a9129
LC
3706@item @code{password} (default: @code{#f})
3707What, user groups can have a password? Well, apparently yes. Unless
3708@code{#f}, this field specifies the group's password.
ee85f3db 3709
cf4a9129
LC
3710@end table
3711@end deftp
401c53c4 3712
cf4a9129
LC
3713For convenience, a variable lists all the basic user groups one may
3714expect:
401c53c4 3715
cf4a9129
LC
3716@defvr {Scheme Variable} %base-groups
3717This is the list of basic user groups that users and/or packages expect
3718to be present on the system. This includes groups such as ``root'',
3719``wheel'', and ``users'', as well as groups used to control access to
3720specific devices such as ``audio'', ``disk'', and ``cdrom''.
3721@end defvr
401c53c4 3722
401c53c4 3723
cf4a9129
LC
3724@node Services
3725@subsection Services
401c53c4 3726
cf4a9129
LC
3727@cindex system services
3728An important part of preparing an @code{operating-system} declaration is
3729listing @dfn{system services} and their configuration (@pxref{Using the
3730Configuration System}). System services are typically daemons launched
3731when the system boots, or other actions needed at that time---e.g.,
3732configuring network access. They are managed by GNU@tie{}dmd
3733(@pxref{Introduction,,, dmd, GNU dmd Manual}).
401c53c4 3734
cf4a9129
LC
3735The following sections document the available services, starting with
3736the core services.
401c53c4 3737
cf4a9129
LC
3738@menu
3739* Base Services:: Essential system services.
3740* Networking Services:: Network setup, SSH daemon, etc.
3741* X Window:: Graphical display.
3742@end menu
401c53c4 3743
cf4a9129
LC
3744@node Base Services
3745@subsubsection Base Services
a1ba8475 3746
cf4a9129
LC
3747The @code{(gnu services base)} module provides definitions for the basic
3748services that one expects from the system. The services exported by
3749this module are listed below.
401c53c4 3750
cf4a9129
LC
3751@defvr {Scheme Variable} %base-services
3752This variable contains a list of basic services@footnote{Technically,
3753this is a list of monadic services. @xref{The Store Monad}.} one would
3754expect from the system: a login service (mingetty) on each tty, syslogd,
3755libc's name service cache daemon (nscd), the udev device manager, and
3756more.
401c53c4 3757
cf4a9129
LC
3758This is the default value of the @code{services} field of
3759@code{operating-system} declarations. Usually, when customizing a
3760system, you will want to append services to @var{%base-services}, like
3761this:
401c53c4 3762
cf4a9129
LC
3763@example
3764(cons* (avahi-service) (lshd-service) %base-services)
3765@end example
3766@end defvr
401c53c4 3767
cf4a9129
LC
3768@deffn {Monadic Procedure} host-name-service @var{name}
3769Return a service that sets the host name to @var{name}.
3770@end deffn
401c53c4 3771
cf4a9129
LC
3772@deffn {Monadic Procedure} mingetty-service @var{tty} [#:motd] @
3773 [#:auto-login #f] [#:login-program] [#:login-pause? #f] @
3774 [#:allow-empty-passwords? #f]
3775Return a service to run mingetty on @var{tty}.
401c53c4 3776
cf4a9129
LC
3777When @var{allow-empty-passwords?} is true, allow empty log-in password. When
3778@var{auto-login} is true, it must be a user name under which to log-in
3779automatically. @var{login-pause?} can be set to @code{#t} in conjunction with
3780@var{auto-login}, in which case the user will have to press a key before the
3781login shell is launched.
401c53c4 3782
cf4a9129
LC
3783When true, @var{login-program} is a gexp or a monadic gexp denoting the name
3784of the log-in program (the default is the @code{login} program from the Shadow
3785tool suite.)
401c53c4 3786
cf4a9129
LC
3787@var{motd} is a monadic value containing a text file to use as
3788the ``message of the day''.
3789@end deffn
401c53c4 3790
cf4a9129
LC
3791@deffn {Monadic Procedure} nscd-service [#:glibc glibc]
3792Return a service that runs libc's name service cache daemon (nscd).
3793@end deffn
401c53c4 3794
cf4a9129
LC
3795@deffn {Monadic Procedure} syslog-service
3796Return a service that runs @code{syslogd} with reasonable default
3797settings.
3798@end deffn
401c53c4 3799
cf4a9129
LC
3800@deffn {Monadic Procedure} guix-service [#:guix guix] @
3801 [#:builder-group "guixbuild"] [#:build-accounts 10] @
3802 [#:authorize-hydra-key? #f] [#:use-substitutes? #t] @
3803 [#:extra-options '()]
3804Return a service that runs the build daemon from @var{guix}, and has
3805@var{build-accounts} user accounts available under @var{builder-group}.
401c53c4 3806
cf4a9129
LC
3807When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key
3808provided by @var{guix} is authorized upon activation, meaning that substitutes
3809from @code{hydra.gnu.org} are used by default.
401c53c4 3810
cf4a9129
LC
3811If @var{use-substitutes?} is false, the daemon is run with
3812@option{--no-substitutes} (@pxref{Invoking guix-daemon,
3813@option{--no-substitutes}}).
401c53c4 3814
cf4a9129
LC
3815Finally, @var{extra-options} is a list of additional command-line options
3816passed to @command{guix-daemon}.
3817@end deffn
a1ba8475 3818
cf4a9129
LC
3819@deffn {Monadic Procedure} udev-service [#:udev udev]
3820Run @var{udev}, which populates the @file{/dev} directory dynamically.
3821@end deffn
401c53c4 3822
a69576ea 3823
cf4a9129
LC
3824@node Networking Services
3825@subsubsection Networking Services
401c53c4 3826
cf4a9129
LC
3827The @code{(gnu system networking)} module provides services to configure
3828the network interface.
a1ba8475 3829
a023cca8
LC
3830@cindex DHCP, networking service
3831@deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
3832Return a service that runs @var{dhcp}, a Dynamic Host Configuration
3833Protocol (DHCP) client, on all the non-loopback network interfaces.
3834@end deffn
3835
cf4a9129
LC
3836@deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @
3837 [#:gateway #f] [#:name-services @code{'()}]
3838Return a service that starts @var{interface} with address @var{ip}. If
3839@var{gateway} is true, it must be a string specifying the default network
3840gateway.
3841@end deffn
8b315a6d 3842
cf4a9129
LC
3843@deffn {Monadic Procedure} tor-service [#:tor tor]
3844Return a service to run the @uref{https://torproject.org,Tor} daemon.
8b315a6d 3845
cf4a9129
LC
3846The daemon runs with the default settings (in particular the default exit
3847policy) as the @code{tor} unprivileged user.
3848@end deffn
8b315a6d 3849
4627a464
LC
3850@deffn {Monadic Procedure} bitlbee-service [#:bitlbee bitlbee] @
3851 [#:interface "127.0.0.1"] [#:port 6667] @
3852 [#:extra-settings ""]
3853Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
3854acts as a gateway between IRC and chat networks.
3855
3856The daemon will listen to the interface corresponding to the IP address
3857specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
3858local clients can connect, whereas @code{0.0.0.0} means that connections can
3859come from any networking interface.
3860
3861In addition, @var{extra-settings} specifies a string to append to the
3862configuration file.
3863@end deffn
3864
3865Furthermore, @code{(gnu system ssh)} provides the following service.
8b315a6d 3866
cf4a9129
LC
3867@deffn {Monadic Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
3868 [#:interfaces '()] [#:port-number 22] @
3869 [#:allow-empty-passwords? #f] [#:root-login? #f] @
3870 [#:syslog-output? #t] [#:x11-forwarding? #t] @
3871 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
3872 [public-key-authentication? #t] [#:initialize? #f]
3873Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
3874@var{host-key} must designate a file containing the host key, and readable
3875only by root.
72e25e35 3876
cf4a9129
LC
3877When @var{initialize?} is true, automatically create the seed and host key
3878upon service activation if they do not exist yet. This may take long and
3879require interaction.
8b315a6d 3880
cf4a9129
LC
3881When @var{interfaces} is empty, lshd listens for connections on all the
3882network interfaces; otherwise, @var{interfaces} must be a list of host names
3883or addresses.
9bf3c1a7 3884
cf4a9129
LC
3885@var{allow-empty-passwords?} specifies whether to accepts log-ins with empty
3886passwords, and @var{root-login?} specifies whether to accepts log-ins as
3887root.
4af2447e 3888
cf4a9129
LC
3889The other options should be self-descriptive.
3890@end deffn
4af2447e 3891
fa0c1d61
LC
3892@defvr {Scheme Variable} %facebook-host-aliases
3893This variable contains a string for use in @file{/etc/hosts}
3894(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
3895line contains a entry that maps a known server name of the Facebook
3896on-line service---e.g., @code{www.facebook.com}---to the local
3897host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
3898
3899This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
3900@code{operating-system} declaration (@pxref{operating-system Reference,
3901@file{/etc/hosts}}):
fa0c1d61
LC
3902
3903@example
3904(use-modules (gnu) (guix))
3905
3906(operating-system
3907 (host-name "mymachine")
3908 ;; ...
3909 (hosts-file
3910 ;; Create a /etc/hosts file with aliases for "localhost"
3911 ;; and "mymachine", as well as for Facebook servers.
3912 (text-file "hosts"
3913 (string-append (local-host-aliases host-name)
3914 %facebook-host-aliases))))
3915@end example
3916
3917This mechanism can prevent programs running locally, such as Web
3918browsers, from accessing Facebook.
3919@end defvr
3920
cf4a9129
LC
3921@node X Window
3922@subsubsection X Window
68ad877c 3923
cf4a9129
LC
3924Support for the X Window graphical display system---specifically
3925Xorg---is provided by the @code{(gnu services xorg)} module. Note that
3926there is no @code{xorg-service} procedure. Instead, the X server is
3927started by the @dfn{login manager}, currently SLiM.
4af2447e 3928
cf4a9129
LC
3929@deffn {Monadic Procedure} slim-service [#:allow-empty-passwords? #f] @
3930 [#:auto-login? #f] [#:default-user ""] [#:startx]
3931Return a service that spawns the SLiM graphical login manager, which in
3932turn starts the X display server with @var{startx}, a command as returned by
3933@code{xorg-start-command}.
4af2447e 3934
cf4a9129
LC
3935When @var{allow-empty-passwords?} is true, allow logins with an empty
3936password. When @var{auto-login?} is true, log in automatically as
3937@var{default-user}.
3938@end deffn
4af2447e 3939
4af2447e 3940
0ae8c15a
LC
3941@node Setuid Programs
3942@subsection Setuid Programs
3943
3944@cindex setuid programs
3945Some programs need to run with ``root'' privileges, even when they are
3946launched by unprivileged users. A notorious example is the
3947@command{passwd} programs, which can users can run to change their
3948password, and which requires write access to the @file{/etc/passwd} and
3949@file{/etc/shadow} files---something normally restricted to root, for
3950obvious security reasons. To address that, these executables are
3951@dfn{setuid-root}, meaning that they always run with root privileges
3952(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
3953for more info about the setuid mechanisms.)
3954
3955The store itself @emph{cannot} contain setuid programs: that would be a
3956security issue since any user on the system can write derivations that
3957populate the store (@pxref{The Store}). Thus, a different mechanism is
3958used: instead of changing the setuid bit directly on files that are in
3959the store, we let the system administrator @emph{declare} which programs
3960should be setuid root.
3961
3962The @code{setuid-programs} field of an @code{operating-system}
3963declaration contains a list of G-expressions denoting the names of
3964programs to be setuid-root (@pxref{Using the Configuration System}).
3965For instance, the @command{passwd} program, which is part of the Shadow
3966package, can be designated by this G-expression (@pxref{G-Expressions}):
3967
3968@example
3969#~(string-append #$shadow "/bin/passwd")
3970@end example
3971
3972A default set of setuid programs is defined by the
3973@code{%setuid-programs} variable of the @code{(gnu system)} module.
3974
3975@defvr {Scheme Variable} %setuid-programs
3976A list of G-expressions denoting common programs that are setuid-root.
3977
3978The list includes commands such as @command{passwd}, @command{ping},
3979@command{su}, and @command{sudo}.
3980@end defvr
3981
3982Under the hood, the actual setuid programs are created in the
3983@file{/run/setuid-programs} directory at system activation time. The
3984files in this directory refer to the ``real'' binaries, which are in the
3985store.
3986
3987
fd1b1fa2
LC
3988@node Initial RAM Disk
3989@subsection Initial RAM Disk
3990
3991@cindex initial RAM disk (initrd)
3992@cindex initrd (initial RAM disk)
3993For bootstrapping purposes, the Linux-Libre kernel is passed an
3994@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
3995root file system, as well as an initialization script. The latter is
3996responsible for mounting the real root file system, and for loading any
3997kernel modules that may be needed to achieve that.
3998
3999The @code{initrd} field of an @code{operating-system} declaration allows
4000you to specify which initrd you would like to use. The @code{(gnu
4001system linux-initrd)} module provides two ways to build an initrd: the
4002high-level @code{base-initrd} procedure, and the low-level
4003@code{expression->initrd} procedure.
4004
4005The @code{base-initrd} procedure is intended to cover most common uses.
4006For example, if you want to add a bunch of kernel modules to be loaded
4007at boot time, you can define the @code{initrd} field of the operating
4008system declaration like this:
4009
4010@example
52ac153e
LC
4011(initrd (lambda (file-systems . rest)
4012 (apply base-initrd file-systems
4013 #:extra-modules '("my.ko" "modules.ko")
4014 rest)))
fd1b1fa2
LC
4015@end example
4016
52ac153e
LC
4017The @code{base-initrd} procedure also handles common use cases that
4018involves using the system as a QEMU guest, or as a ``live'' system whose
4019root file system is volatile.
fd1b1fa2
LC
4020
4021@deffn {Monadic Procedure} base-initrd @var{file-systems} @
4022 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
52ac153e 4023 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
4024Return a monadic derivation that builds a generic initrd. @var{file-systems} is
4025a list of file-systems to be mounted by the initrd, possibly in addition to
4026the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
4027@var{mapped-devices} is a list of device mappings to realize before
4028@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
4029
4030When @var{qemu-networking?} is true, set up networking with the standard QEMU
4031parameters. When @var{virtio?} is true, load additional modules so the initrd can
4032be used as a QEMU guest with para-virtualized I/O drivers.
4033
4034When @var{volatile-root?} is true, the root file system is writable but any changes
4035to it are lost.
4036
4037The initrd is automatically populated with all the kernel modules necessary
4038for @var{file-systems} and for the given options. However, additional kernel
4039modules can be listed in @var{extra-modules}. They will be added to the initrd, and
4040loaded at boot time in the order in which they appear.
4041@end deffn
4042
4043Needless to say, the initrds we produce and use embed a
4044statically-linked Guile, and the initialization program is a Guile
4045program. That gives a lot of flexibility. The
4046@code{expression->initrd} procedure builds such an initrd, given the
4047program to run in that initrd.
4048
4049@deffn {Monadic Procedure} expression->initrd @var{exp} @
4050 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 4051 [#:modules '()]
fd1b1fa2
LC
4052Return a derivation that builds a Linux initrd (a gzipped cpio archive)
4053containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
4054upon booting. All the derivations referenced by @var{exp} are
4055automatically copied to the initrd.
fd1b1fa2 4056
42d10464
LC
4057@var{modules} is a list of Guile module names to be embedded in the
4058initrd.
fd1b1fa2
LC
4059@end deffn
4060
cf4a9129
LC
4061@node Invoking guix system
4062@subsection Invoking @code{guix system}
0918e64a 4063
cf4a9129
LC
4064Once you have written an operating system declaration, as seen in the
4065previous section, it can be @dfn{instantiated} using the @command{guix
4066system} command. The synopsis is:
4af2447e 4067
cf4a9129
LC
4068@example
4069guix system @var{options}@dots{} @var{action} @var{file}
4070@end example
4af2447e 4071
cf4a9129
LC
4072@var{file} must be the name of a file containing an
4073@code{operating-system} declaration. @var{action} specifies how the
4074operating system is instantiate. Currently the following values are
4075supported:
4af2447e 4076
cf4a9129
LC
4077@table @code
4078@item reconfigure
4079Build the operating system described in @var{file}, activate it, and
4080switch to it@footnote{This action is usable only on systems already
4081running GNU.}.
4af2447e 4082
cf4a9129
LC
4083This effects all the configuration specified in @var{file}: user
4084accounts, system services, global package list, setuid programs, etc.
4af2447e 4085
cf4a9129
LC
4086It also adds a GRUB menu entry for the new OS configuration, and moves
4087entries for older configurations to a submenu---unless
4088@option{--no-grub} is passed.
4af2447e 4089
cf4a9129
LC
4090@item build
4091Build the operating system's derivation, which includes all the
4092configuration files and programs needed to boot and run the system.
4093This action does not actually install anything.
113daf62 4094
cf4a9129
LC
4095@item init
4096Populate the given directory with all the files necessary to run the
4097operating system specified in @var{file}. This is useful for first-time
4098installations of the GNU system. For instance:
113daf62
LC
4099
4100@example
cf4a9129 4101guix system init my-os-config.scm /mnt
113daf62
LC
4102@end example
4103
cf4a9129
LC
4104copies to @file{/mnt} all the store items required by the configuration
4105specified in @file{my-os-config.scm}. This includes configuration
4106files, packages, and so on. It also creates other essential files
4107needed for the system to operate correctly---e.g., the @file{/etc},
4108@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 4109
cf4a9129
LC
4110This command also installs GRUB on the device specified in
4111@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 4112
cf4a9129
LC
4113@item vm
4114@cindex virtual machine
4115Build a virtual machine that contain the operating system declared in
4116@var{file}, and return a script to run that virtual machine (VM).
113daf62 4117
cf4a9129 4118The VM shares its store with the host system.
113daf62 4119
cf4a9129
LC
4120@item vm-image
4121@itemx disk-image
4122Return a virtual machine or disk image of the operating system declared
4123in @var{file} that stands alone. Use the @option{--image-size} option
4124to specify the size of the image.
113daf62 4125
cf4a9129
LC
4126When using @code{vm-image}, the returned image is in qcow2 format, which
4127the QEMU emulator can efficiently use.
113daf62 4128
cf4a9129
LC
4129When using @code{disk-image}, a raw disk image is produced; it can be
4130copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
4131the device corresponding to a USB stick, one can copy the image on it
4132using the following command:
113daf62 4133
cf4a9129
LC
4134@example
4135# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
4136@end example
113daf62 4137
cf4a9129 4138@end table
113daf62 4139
cf4a9129
LC
4140@var{options} can contain any of the common build options provided by
4141@command{guix build} (@pxref{Invoking guix build}). In addition,
4142@var{options} can contain one of the following:
113daf62 4143
cf4a9129
LC
4144@table @option
4145@item --system=@var{system}
4146@itemx -s @var{system}
4147Attempt to build for @var{system} instead of the host's system type.
4148This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 4149
cf4a9129
LC
4150@item --image-size=@var{size}
4151For the @code{vm-image} and @code{disk-image} actions, create an image
4152of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
4153include a unit as a suffix (@pxref{Block size, size specifications,,
4154coreutils, GNU Coreutils}).
113daf62 4155@end table
113daf62 4156
cf4a9129
LC
4157Note that all the actions above, except @code{build} and @code{init},
4158rely on KVM support in the Linux-Libre kernel. Specifically, the
4159machine should have hardware virtualization support, the corresponding
4160KVM kernel module should be loaded, and the @file{/dev/kvm} device node
4161must exist and be readable and writable by the user and by the daemon's
4162build users.
8451a568 4163
cf4a9129
LC
4164@node Defining Services
4165@subsection Defining Services
8451a568 4166
cf4a9129
LC
4167The @code{(gnu services @dots{})} modules define several procedures that allow
4168users to declare the operating system's services (@pxref{Using the
4169Configuration System}). These procedures are @emph{monadic
4170procedures}---i.e., procedures that return a monadic value in the store
4171monad (@pxref{The Store Monad}). For examples of such procedures,
4172@xref{Services}.
8451a568 4173
cf4a9129
LC
4174@cindex service definition
4175The monadic value returned by those procedures is a @dfn{service
4176definition}---a structure as returned by the @code{service} form.
4177Service definitions specifies the inputs the service depends on, and an
4178expression to start and stop the service. Behind the scenes, service
4179definitions are ``translated'' into the form suitable for the
4180configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU
4181dmd Manual}).
8451a568 4182
cf4a9129
LC
4183As an example, here is what the @code{nscd-service} procedure looks
4184like:
8451a568 4185
cf4a9129
LC
4186@lisp
4187(define (nscd-service)
4188 (with-monad %store-monad
4189 (return (service
4190 (documentation "Run libc's name service cache daemon.")
4191 (provision '(nscd))
4192 (activate #~(begin
4193 (use-modules (guix build utils))
4194 (mkdir-p "/var/run/nscd")))
4195 (start #~(make-forkexec-constructor
4196 (string-append #$glibc "/sbin/nscd")
4197 "-f" "/dev/null" "--foreground"))
4198 (stop #~(make-kill-destructor))
4199 (respawn? #f)))))
4200@end lisp
8451a568 4201
cf4a9129
LC
4202@noindent
4203The @code{activate}, @code{start}, and @code{stop} fields are G-expressions
4204(@pxref{G-Expressions}). The @code{activate} field contains a script to
4205run at ``activation'' time; it makes sure that the @file{/var/run/nscd}
4206directory exists before @command{nscd} is started.
8451a568 4207
cf4a9129
LC
4208The @code{start} and @code{stop} fields refer to dmd's facilities to
4209start and stop processes (@pxref{Service De- and Constructors,,, dmd,
4210GNU dmd Manual}). The @code{provision} field specifies the name under
4211which this service is known to dmd, and @code{documentation} specifies
4212on-line documentation. Thus, the commands @command{deco start ncsd},
4213@command{deco stop nscd}, and @command{deco doc nscd} will do what you
4214would expect (@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
8451a568 4215
8451a568 4216
cf4a9129
LC
4217@node Installing Debugging Files
4218@section Installing Debugging Files
8451a568 4219
cf4a9129
LC
4220@cindex debugging files
4221Program binaries, as produced by the GCC compilers for instance, are
4222typically written in the ELF format, with a section containing
4223@dfn{debugging information}. Debugging information is what allows the
4224debugger, GDB, to map binary code to source code; it is required to
4225debug a compiled program in good conditions.
8451a568 4226
cf4a9129
LC
4227The problem with debugging information is that is takes up a fair amount
4228of disk space. For example, debugging information for the GNU C Library
4229weighs in at more than 60 MiB. Thus, as a user, keeping all the
4230debugging info of all the installed programs is usually not an option.
4231Yet, space savings should not come at the cost of an impediment to
4232debugging---especially in the GNU system, which should make it easier
4233for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 4234
cf4a9129
LC
4235Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
4236mechanism that allows users to get the best of both worlds: debugging
4237information can be stripped from the binaries and stored in separate
4238files. GDB is then able to load debugging information from those files,
4239when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
4240with GDB}).
8451a568 4241
cf4a9129
LC
4242The GNU distribution takes advantage of this by storing debugging
4243information in the @code{lib/debug} sub-directory of a separate package
4244output unimaginatively called @code{debug} (@pxref{Packages with
4245Multiple Outputs}). Users can choose to install the @code{debug} output
4246of a package when they need it. For instance, the following command
4247installs the debugging information for the GNU C Library and for GNU
4248Guile:
8451a568
LC
4249
4250@example
cf4a9129 4251guix package -i glibc:debug guile:debug
8451a568
LC
4252@end example
4253
cf4a9129
LC
4254GDB must then be told to look for debug files in the user's profile, by
4255setting the @code{debug-file-directory} variable (consider setting it
4256from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
4257GDB}):
8451a568 4258
cf4a9129
LC
4259@example
4260(gdb) set debug-file-directory ~/.guix-profile/lib/debug
4261@end example
8451a568 4262
cf4a9129
LC
4263From there on, GDB will pick up debugging information from the
4264@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 4265
cf4a9129
LC
4266In addition, you will most likely want GDB to be able to show the source
4267code being debugged. To do that, you will have to unpack the source
4268code of the package of interest (obtained with @code{guix build
4269--source}, @pxref{Invoking guix build}), and to point GDB to that source
4270directory using the @code{directory} command (@pxref{Source Path,
4271@code{directory},, gdb, Debugging with GDB}).
8451a568 4272
cf4a9129
LC
4273@c XXX: keep me up-to-date
4274The @code{debug} output mechanism in Guix is implemented by the
4275@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
4276opt-in---debugging information is available only for those packages
4277whose definition explicitly declares a @code{debug} output. This may be
4278changed to opt-out in the future, if our build farm servers can handle
4279the load. To check whether a package has a @code{debug} output, use
4280@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 4281
8451a568 4282
cf4a9129
LC
4283@node Package Modules
4284@section Package Modules
8451a568 4285
cf4a9129
LC
4286From a programming viewpoint, the package definitions of the
4287GNU distribution are provided by Guile modules in the @code{(gnu packages
4288@dots{})} name space@footnote{Note that packages under the @code{(gnu
4289packages @dots{})} module name space are not necessarily ``GNU
4290packages''. This module naming scheme follows the usual Guile module
4291naming convention: @code{gnu} means that these modules are distributed
4292as part of the GNU system, and @code{packages} identifies modules that
4293define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
4294Reference Manual}). For instance, the @code{(gnu packages emacs)}
4295module exports a variable named @code{emacs}, which is bound to a
4296@code{<package>} object (@pxref{Defining Packages}).
113daf62 4297
300868ba 4298The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
4299automatically scanned for packages by the command-line tools. For
4300instance, when running @code{guix package -i emacs}, all the @code{(gnu
4301packages @dots{})} modules are scanned until one that exports a package
4302object whose name is @code{emacs} is found. This package search
4303facility is implemented in the @code{(gnu packages)} module.
113daf62 4304
300868ba 4305@cindex customization, of packages
8689901f 4306@cindex package module search path
cf4a9129 4307Users can store package definitions in modules with different
300868ba
LC
4308names---e.g., @code{(my-packages emacs)}. These package definitions
4309will not be visible by default. Thus, users can invoke commands such as
4310@command{guix package} and @command{guix build} have to be used with the
4311@code{-e} option so that they know where to find the package, or use the
4312@code{-L} option of these commands to make those modules visible
8689901f
LC
4313(@pxref{Invoking guix build, @code{--load-path}}), or define the
4314@code{GUIX_PACKAGE_PATH} environment variable. This environment
4315variable makes it easy to extend or customize the distribution and is
4316honored by all the user interfaces.
4317
4318@defvr {Environment Variable} GUIX_PACKAGE_PATH
4319This is a colon-separated list of directories to search for package
4320modules. Directories listed in this variable take precedence over the
4321distribution's own modules.
4322@end defvr
ef5dd60a 4323
cf4a9129
LC
4324The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
4325each package is built based solely on other packages in the
4326distribution. The root of this dependency graph is a small set of
4327@dfn{bootstrap binaries}, provided by the @code{(gnu packages
4328bootstrap)} module. For more information on bootstrapping,
4329@ref{Bootstrapping}.
ef5dd60a 4330
cf4a9129
LC
4331@node Packaging Guidelines
4332@section Packaging Guidelines
ef5dd60a 4333
cf4a9129
LC
4334The GNU distribution is nascent and may well lack some of your favorite
4335packages. This section describes how you can help make the distribution
4336grow. @xref{Contributing}, for additional information on how you can
4337help.
ef5dd60a 4338
cf4a9129
LC
4339Free software packages are usually distributed in the form of
4340@dfn{source code tarballs}---typically @file{tar.gz} files that contain
4341all the source files. Adding a package to the distribution means
4342essentially two things: adding a @dfn{recipe} that describes how to
4343build the package, including a list of other packages required to build
4344it, and adding @dfn{package meta-data} along with that recipe, such as a
4345description and licensing information.
ef5dd60a 4346
cf4a9129
LC
4347In Guix all this information is embodied in @dfn{package definitions}.
4348Package definitions provide a high-level view of the package. They are
4349written using the syntax of the Scheme programming language; in fact,
4350for each package we define a variable bound to the package definition,
4351and export that variable from a module (@pxref{Package Modules}).
4352However, in-depth Scheme knowledge is @emph{not} a prerequisite for
4353creating packages. For more information on package definitions,
4354@ref{Defining Packages}.
ef5dd60a 4355
cf4a9129
LC
4356Once a package definition is in place, stored in a file in the Guix
4357source tree, it can be tested using the @command{guix build} command
4358(@pxref{Invoking guix build}). For example, assuming the new package is
4359called @code{gnew}, you may run this command from the Guix build tree:
ef5dd60a
LC
4360
4361@example
cf4a9129 4362./pre-inst-env guix build gnew --keep-failed
ef5dd60a 4363@end example
ef5dd60a 4364
cf4a9129
LC
4365Using @code{--keep-failed} makes it easier to debug build failures since
4366it provides access to the failed build tree. Another useful
4367command-line option when debugging is @code{--log-file}, to access the
4368build log.
ef5dd60a 4369
cf4a9129
LC
4370If the package is unknown to the @command{guix} command, it may be that
4371the source file contains a syntax error, or lacks a @code{define-public}
4372clause to export the package variable. To figure it out, you may load
4373the module from Guile to get more information about the actual error:
ef5dd60a 4374
cf4a9129
LC
4375@example
4376./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
4377@end example
ef5dd60a 4378
cf4a9129
LC
4379Once your package builds correctly, please send us a patch
4380(@pxref{Contributing}). Well, if you need help, we will be happy to
4381help you too. Once the patch is committed in the Guix repository, the
4382new package automatically gets built on the supported platforms by
4383@url{http://hydra.gnu.org/gnu/master, our continuous integration
4384system}.
ef5dd60a 4385
cf4a9129
LC
4386@cindex substituter
4387Users can obtain the new package definition simply by running
4388@command{guix pull} (@pxref{Invoking guix pull}). When
4389@code{hydra.gnu.org} is done building the package, installing the
4390package automatically downloads binaries from there
4391(@pxref{Substitutes}). The only place where human intervention is
4392needed is to review and apply the patch.
ef5dd60a 4393
ef5dd60a 4394
cf4a9129
LC
4395@menu
4396* Software Freedom:: What may go into the distribution.
4397* Package Naming:: What's in a name?
4398* Version Numbers:: When the name is not enough.
4399* Python Modules:: Taming the snake.
4400* Perl Modules:: Little pearls.
4401@end menu
ef5dd60a 4402
cf4a9129
LC
4403@node Software Freedom
4404@subsection Software Freedom
ef5dd60a 4405
cf4a9129 4406@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 4407
cf4a9129
LC
4408The GNU operating system has been developed so that users can have
4409freedom in their computing. GNU is @dfn{free software}, meaning that
4410users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
4411essential freedoms}: to run the program, to study and change the program
4412in source code form, to redistribute exact copies, and to distribute
4413modified versions. Packages found in the GNU distribution provide only
4414software that conveys these four freedoms.
c11a6eb1 4415
cf4a9129
LC
4416In addition, the GNU distribution follow the
4417@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
4418software distribution guidelines}. Among other things, these guidelines
4419reject non-free firmware, recommendations of non-free software, and
4420discuss ways to deal with trademarks and patents.
ef5dd60a 4421
cf4a9129
LC
4422Some packages contain a small and optional subset that violates the
4423above guidelines, for instance because this subset is itself non-free
4424code. When that happens, the offending items are removed with
4425appropriate patches or code snippets in the package definition's
4426@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
4427build --source} returns the ``freed'' source rather than the unmodified
4428upstream source.
ef5dd60a 4429
ef5dd60a 4430
cf4a9129
LC
4431@node Package Naming
4432@subsection Package Naming
ef5dd60a 4433
cf4a9129
LC
4434A package has actually two names associated with it:
4435First, there is the name of the @emph{Scheme variable}, the one following
4436@code{define-public}. By this name, the package can be made known in the
4437Scheme code, for instance as input to another package. Second, there is
4438the string in the @code{name} field of a package definition. This name
4439is used by package management commands such as
4440@command{guix package} and @command{guix build}.
ef5dd60a 4441
cf4a9129
LC
4442Both are usually the same and correspond to the lowercase conversion of
4443the project name chosen upstream, with underscores replaced with
4444hyphens. For instance, GNUnet is available as @code{gnunet}, and
4445SDL_net as @code{sdl-net}.
927097ef 4446
cf4a9129
LC
4447We do not add @code{lib} prefixes for library packages, unless these are
4448already part of the official project name. But see @pxref{Python
4449Modules} and @ref{Perl Modules} for special rules concerning modules for
4450the Python and Perl languages.
927097ef 4451
ef5dd60a 4452
cf4a9129
LC
4453@node Version Numbers
4454@subsection Version Numbers
ef5dd60a 4455
cf4a9129
LC
4456We usually package only the latest version of a given free software
4457project. But sometimes, for instance for incompatible library versions,
4458two (or more) versions of the same package are needed. These require
4459different Scheme variable names. We use the name as defined
4460in @ref{Package Naming}
4461for the most recent version; previous versions use the same name, suffixed
4462by @code{-} and the smallest prefix of the version number that may
4463distinguish the two versions.
ef5dd60a 4464
cf4a9129
LC
4465The name inside the package definition is the same for all versions of a
4466package and does not contain any version number.
ef5dd60a 4467
cf4a9129 4468For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 4469
cf4a9129
LC
4470@example
4471(define-public gtk+
4472 (package
4473 (name "gtk+")
4474 (version "3.9.12")
4475 ...))
4476(define-public gtk+-2
4477 (package
4478 (name "gtk+")
4479 (version "2.24.20")
4480 ...))
4481@end example
4482If we also wanted GTK+ 3.8.2, this would be packaged as
4483@example
4484(define-public gtk+-3.8
4485 (package
4486 (name "gtk+")
4487 (version "3.8.2")
4488 ...))
4489@end example
ef5dd60a 4490
ef5dd60a 4491
cf4a9129
LC
4492@node Python Modules
4493@subsection Python Modules
ef5dd60a 4494
cf4a9129
LC
4495We currently package Python 2 and Python 3, under the Scheme variable names
4496@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
4497To avoid confusion and naming clashes with other programming languages, it
4498seems desirable that the name of a package for a Python module contains
4499the word @code{python}.
ef5dd60a 4500
cf4a9129
LC
4501Some modules are compatible with only one version of Python, others with both.
4502If the package Foo compiles only with Python 3, we name it
4503@code{python-foo}; if it compiles only with Python 2, we name it
4504@code{python2-foo}. If it is compatible with both versions, we create two
4505packages with the corresponding names.
ef5dd60a 4506
cf4a9129
LC
4507If a project already contains the word @code{python}, we drop this;
4508for instance, the module python-dateutil is packaged under the names
4509@code{python-dateutil} and @code{python2-dateutil}.
113daf62 4510
523e4896 4511
cf4a9129
LC
4512@node Perl Modules
4513@subsection Perl Modules
523e4896 4514
cf4a9129
LC
4515Perl programs standing for themselves are named as any other package,
4516using the lowercase upstream name.
4517For Perl packages containing a single class, we use the lowercase class name,
4518replace all occurrences of @code{::} by dashes and prepend the prefix
4519@code{perl-}.
4520So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
4521Modules containing several classes keep their lowercase upstream name and
4522are also prepended by @code{perl-}. Such modules tend to have the word
4523@code{perl} somewhere in their name, which gets dropped in favor of the
4524prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 4525
523e4896 4526
b25937e3 4527
cf4a9129
LC
4528@node Bootstrapping
4529@section Bootstrapping
b25937e3 4530
cf4a9129 4531@c Adapted from the ELS 2013 paper.
b25937e3 4532
cf4a9129 4533@cindex bootstrapping
7889394e 4534
cf4a9129
LC
4535Bootstrapping in our context refers to how the distribution gets built
4536``from nothing''. Remember that the build environment of a derivation
4537contains nothing but its declared inputs (@pxref{Introduction}). So
4538there's an obvious chicken-and-egg problem: how does the first package
4539get built? How does the first compiler get compiled? Note that this is
4540a question of interest only to the curious hacker, not to the regular
4541user, so you can shamelessly skip this section if you consider yourself
4542a ``regular user''.
72b9d60d 4543
cf4a9129
LC
4544@cindex bootstrap binaries
4545The GNU system is primarily made of C code, with libc at its core. The
4546GNU build system itself assumes the availability of a Bourne shell and
4547command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
4548`grep'. Furthermore, build programs---programs that run
4549@code{./configure}, @code{make}, etc.---are written in Guile Scheme
4550(@pxref{Derivations}). Consequently, to be able to build anything at
4551all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
4552Binutils, libc, and the other packages mentioned above---the
4553@dfn{bootstrap binaries}.
72b9d60d 4554
cf4a9129
LC
4555These bootstrap binaries are ``taken for granted'', though we can also
4556re-create them if needed (more on that later).
72b9d60d 4557
cf4a9129 4558@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 4559
cf4a9129
LC
4560@c As of Emacs 24.3, Info-mode displays the image, but since it's a
4561@c large image, it's hard to scroll. Oh well.
4562@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 4563
cf4a9129
LC
4564The figure above shows the very beginning of the dependency graph of the
4565distribution, corresponding to the package definitions of the @code{(gnu
4566packages bootstrap)} module. At this level of detail, things are
4567slightly complex. First, Guile itself consists of an ELF executable,
4568along with many source and compiled Scheme files that are dynamically
4569loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
4570tarball shown in this graph. This tarball is part of Guix's ``source''
4571distribution, and gets inserted into the store with @code{add-to-store}
4572(@pxref{The Store}).
2e7b5cea 4573
cf4a9129
LC
4574But how do we write a derivation that unpacks this tarball and adds it
4575to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
4576derivation---the first one that gets built---uses @code{bash} as its
4577builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
4578@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
4579@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
4580the Guix source distribution, whose sole purpose is to allow the Guile
4581tarball to be unpacked.
fb729425 4582
cf4a9129
LC
4583Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
4584Guile that can be used to run subsequent build programs. Its first task
4585is to download tarballs containing the other pre-built binaries---this
4586is what the @code{.tar.xz.drv} derivations do. Guix modules such as
4587@code{ftp-client.scm} are used for this purpose. The
4588@code{module-import.drv} derivations import those modules in a directory
4589in the store, using the original layout. The
4590@code{module-import-compiled.drv} derivations compile those modules, and
4591write them in an output directory with the right layout. This
4592corresponds to the @code{#:modules} argument of
4593@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 4594
cf4a9129
LC
4595Finally, the various tarballs are unpacked by the
4596derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
4597etc., at which point we have a working C tool chain.
fb729425 4598
fb729425 4599
cf4a9129 4600@unnumberedsubsec Building the Build Tools
523e4896 4601
cf4a9129
LC
4602@c TODO: Add a package-level dependency graph generated from (gnu
4603@c packages base).
df2ce343 4604
cf4a9129
LC
4605Bootstrapping is complete when we have a full tool chain that does not
4606depend on the pre-built bootstrap tools discussed above. This
4607no-dependency requirement is verified by checking whether the files of
4608the final tool chain contain references to the @file{/gnu/store}
4609directories of the bootstrap inputs. The process that leads to this
4610``final'' tool chain is described by the package definitions found in
4611the @code{(gnu packages base)} module.
df2ce343 4612
cf4a9129
LC
4613@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
4614The first tool that gets built with the bootstrap binaries is
4615GNU Make, which is a prerequisite for all the following packages.
4616From there Findutils and Diffutils get built.
523e4896 4617
cf4a9129
LC
4618Then come the first-stage Binutils and GCC, built as pseudo cross
4619tools---i.e., with @code{--target} equal to @code{--host}. They are
4620used to build libc. Thanks to this cross-build trick, this libc is
4621guaranteed not to hold any reference to the initial tool chain.
4af2447e 4622
cf4a9129
LC
4623From there the final Binutils and GCC are built. GCC uses @code{ld}
4624from the final Binutils, and links programs against the just-built libc.
4625This tool chain is used to build the other packages used by Guix and by
4626the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 4627
cf4a9129
LC
4628And voilà! At this point we have the complete set of build tools that
4629the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
4630variable of the @code{(gnu packages commencement)} module, and are
4631implicitly used by any package that uses @code{gnu-build-system}
4632(@pxref{Defining Packages}).
4af2447e 4633
4af2447e 4634
cf4a9129 4635@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 4636
cf4a9129
LC
4637Because the final tool chain does not depend on the bootstrap binaries,
4638those rarely need to be updated. Nevertheless, it is useful to have an
4639automated way to produce them, should an update occur, and this is what
4640the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 4641
cf4a9129
LC
4642The following command builds the tarballs containing the bootstrap
4643binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
4644of Coreutils and other basic command-line tools):
4b2615e1 4645
cf4a9129
LC
4646@example
4647guix build bootstrap-tarballs
4648@end example
4649
4650The generated tarballs are those that should be referred to in the
4651@code{(gnu packages bootstrap)} module mentioned at the beginning of
4652this section.
4653
4654Still here? Then perhaps by now you've started to wonder: when do we
4655reach a fixed point? That is an interesting question! The answer is
4656unknown, but if you would like to investigate further (and have
4657significant computational and storage resources to do so), then let us
4658know.
4659
4660@node Porting
4661@section Porting to a New Platform
4662
4663As discussed above, the GNU distribution is self-contained, and
4664self-containment is achieved by relying on pre-built ``bootstrap
4665binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
4666operating system kernel, CPU architecture, and application binary
4667interface (ABI). Thus, to port the distribution to a platform that is
4668not yet supported, one must build those bootstrap binaries, and update
4669the @code{(gnu packages bootstrap)} module to use them on that platform.
4670
4671Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
4672When everything goes well, and assuming the GNU tool chain supports the
4673target platform, this can be as simple as running a command like this
4674one:
4675
4676@example
4677guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
4678@end example
4679
4680Once these are built, the @code{(gnu packages bootstrap)} module needs
4681to be updated to refer to these binaries on the target platform. In
4682addition, the @code{glibc-dynamic-linker} procedure in that module must
4683be augmented to return the right file name for libc's dynamic linker on
4684that platform; likewise, @code{system->linux-architecture} in @code{(gnu
4685packages linux)} must be taught about the new platform.
4686
4687In practice, there may be some complications. First, it may be that the
4688extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
4689above) is not recognized by all the GNU tools. Typically, glibc
4690recognizes some of these, whereas GCC uses an extra @code{--with-abi}
4691configure flag (see @code{gcc.scm} for examples of how to handle this).
4692Second, some of the required packages could fail to build for that
4693platform. Lastly, the generated binaries could be broken for some
4694reason.
4af2447e
LC
4695
4696
9bf3c1a7
LC
4697@c *********************************************************************
4698@node Contributing
4699@chapter Contributing
4700
4701This project is a cooperative effort, and we need your help to make it
5ff3c4b8
PAR
4702grow! Please get in touch with us on @email{guix-devel@@gnu.org} and
4703@code{#guix} on the Freenode IRC network. We welcome ideas, bug
4704reports, patches, and anything that may be helpful to the project. We
4705particularly welcome help on packaging (@pxref{Packaging Guidelines}).
a1ba8475 4706
9bf3c1a7
LC
4707Please see the
4708@url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING,
4709@file{HACKING} file} that comes with the Guix source code for practical
4710details about contributions.
4711
c78bd12b 4712
568717fd
LC
4713@c *********************************************************************
4714@node Acknowledgments
4715@chapter Acknowledgments
4716
4717Guix is based on the Nix package manager, which was designed and
4718implemented by Eelco Dolstra. Nix pioneered functional package
4719management, and promoted unprecedented features, such as transactional
4720package upgrades and rollbacks, per-user profiles, and referentially
4721transparent build processes. Without this work, Guix would not exist.
4722
4723The Nix-based software distributions, Nixpkgs and NixOS, have also been
4724an inspiration for Guix.
4725
4726@c *********************************************************************
4727@node GNU Free Documentation License
4728@appendix GNU Free Documentation License
4729
4730@include fdl-1.3.texi
4731
4732@c *********************************************************************
4733@node Concept Index
4734@unnumbered Concept Index
4735@printindex cp
4736
a85b83d2
LC
4737@node Programming Index
4738@unnumbered Programming Index
4739@syncodeindex tp fn
4740@syncodeindex vr fn
568717fd
LC
4741@printindex fn
4742
4743@bye
4744
4745@c Local Variables:
4746@c ispell-local-dictionary: "american";
4747@c End: