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