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