gnu: file: Upgrade to 5.16.
[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@*
7df7a74e
NK
14Copyright @copyright{} 2013 Andreas Enge@*
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
LC
31 Building packages with Guix.
32@end direntry
568717fd
LC
33
34@titlepage
7730d112
LC
35@title GNU Guix Reference Manual
36@subtitle Using the GNU Guix Functional Package Manager
568717fd 37@author Ludovic Courtès
da7cabd4 38@author Andreas Enge
acc08466 39@author Nikita Karetnikov
568717fd
LC
40
41@page
42@vskip 0pt plus 1filll
43Edition @value{EDITION} @*
44@value{UPDATED} @*
45
7df7a74e 46@insertcopying
568717fd
LC
47@end titlepage
48
568717fd
LC
49@contents
50
51@c *********************************************************************
52@node Top
f8348b91 53@top GNU Guix
568717fd 54
f8348b91
LC
55This document describes GNU Guix version @value{VERSION}, a functional
56package management tool written for the GNU system.
568717fd
LC
57
58@menu
59* Introduction:: What is Guix about?
bd5e766b 60* Installation:: Installing Guix.
eeaf4427 61* Package Management:: Package installation, upgrade, etc.
568717fd
LC
62* Programming Interface:: Using Guix in Scheme.
63* Utilities:: Package management commands.
a1ba8475 64* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 65* Contributing:: Your help needed!
568717fd
LC
66
67* Acknowledgments:: Thanks!
68* GNU Free Documentation License:: The license of this manual.
69* Concept Index:: Concepts.
70* Function Index:: Functions.
71@end menu
72
73@c *********************************************************************
74@node Introduction
75@chapter Introduction
76
c80e7e55
LC
77GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
78using the international phonetic alphabet (IPA).} is a functional
79package management tool for the GNU system. Package management consists
4bfc4ea3
NK
80of all activities that relate to building packages from sources,
81honoring their build-time and run-time dependencies,
c80e7e55
LC
82installing packages in user environments, upgrading installed packages
83to new versions or rolling back to a previous set, removing unused
84software packages, etc.
568717fd
LC
85
86@cindex functional package management
87The term @dfn{functional} refers to a specific package management
88discipline. In Guix, the package build and installation process is seen
4bfc4ea3
NK
89as a function, in the mathematical sense. That function takes inputs,
90such as build scripts, a compiler, and libraries, and
91returns an installed package. As a pure function, its result depends
568717fd
LC
92solely on its inputs---for instance, it cannot refer to software or
93scripts that were not explicitly passed as inputs. A build function
4bfc4ea3
NK
94always produces the same result when passed a given set of inputs. It
95cannot alter the system's environment in
568717fd
LC
96any way; for instance, it cannot create, modify, or delete files outside
97of its build and installation directories. This is achieved by running
e900c503 98build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 99explicit inputs are visible.
568717fd 100
e531ac2a 101@cindex store
568717fd 102The result of package build functions is @dfn{cached} in the file
e531ac2a
LC
103system, in a special directory called @dfn{the store} (@pxref{The
104Store}). Each package is installed in a directory of its own, in the
568717fd
LC
105store---by default under @file{/nix/store}. The directory name contains
106a hash of all the inputs used to build that package; thus, changing an
107input yields a different directory name.
108
109This approach is the foundation of Guix's salient features: support for
4bfc4ea3 110transactional package upgrade and rollback, per-user installation, and
eeaf4427 111garbage collection of packages (@pxref{Features}).
568717fd 112
4bfc4ea3 113Guix has a command-line interface, which allows users to build, install,
568717fd 114upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 115
a1ba8475
LC
116Last but not least, Guix is used to build a distribution of the GNU
117system, with many GNU and non-GNU free software packages. @xref{GNU
118Distribution}.
119
bd5e766b
LC
120@c *********************************************************************
121@node Installation
122@chapter Installation
123
48febeb8
LC
124GNU Guix is available for download from its website at
125@url{http://www.gnu.org/software/guix/}. This section describes the
126software requirements of Guix, as well as how to install it and get
127ready to use it.
bd5e766b 128
b22a12fd 129The build procedure for Guix is the same as for other GNU software, and
1da983b9 130is not covered here. Please see the files @file{README} and
b22a12fd
LC
131@file{INSTALL} in the Guix source tree for additional details.
132
bd5e766b
LC
133@menu
134* Requirements:: Software needed to build and run Guix.
135* Setting Up the Daemon:: Preparing the build daemon's environment.
136* Invoking guix-daemon:: Running the build daemon.
137@end menu
138
139@node Requirements
140@section Requirements
141
142GNU Guix depends on the following packages:
143
144@itemize
4a328f73 145@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.5 or later;
bd5e766b
LC
146@item @url{http://gnupg.org/, GNU libgcrypt}
147@end itemize
148
149Unless @code{--disable-daemon} was passed to @command{configure}, the
150following packages are also needed:
151
152@itemize
153@item @url{http://sqlite.org, SQLite 3}
154@item @url{http://www.bzip.org, libbz2}
155@item @url{http://gcc.gnu.org, GCC's g++}
156@end itemize
157
4bfc4ea3
NK
158When a working installation of @url{http://nixos.org/nix/, the Nix package
159manager} is available, you
bd5e766b 160can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 161Nix replaces the three dependencies above.
bd5e766b 162
b22a12fd
LC
163Guix is compatible with Nix, so it is possible to share the same store
164between both. To do so, you must pass @command{configure} not only the
165same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
166@code{--localstatedir} value. The latter is essential because it
167specifies where the database that stores metadata about the store is
168located, among other things. The default values are
b22a12fd 169@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
170Note that @code{--disable-daemon} is not required if
171your goal is to share the store with Nix.
b22a12fd 172
bd5e766b
LC
173@node Setting Up the Daemon
174@section Setting Up the Daemon
175
176@cindex daemon
177Operations such as building a package or running the garbage collector
49e6291a 178are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
179behalf of clients. Only the daemon may access the store and its
180associated database. Thus, any operation that manipulates the store
181goes through the daemon. For instance, command-line tools such as
e49951eb 182@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
183daemon (@i{via} remote procedure calls) to instruct it what to do.
184
49e6291a
LC
185The following sections explain how to prepare the build daemon's
186environment.
187
188@menu
189* Build Environment Setup:: Preparing the isolated build environment.
190* Daemon Offload Setup:: Offloading builds to remote machines.
191@end menu
192
193@node Build Environment Setup
194@subsection Build Environment Setup
195
bd5e766b
LC
196In a standard multi-user setup, Guix and its daemon---the
197@command{guix-daemon} program---are installed by the system
198administrator; @file{/nix/store} is owned by @code{root} and
199@command{guix-daemon} runs as @code{root}. Unprivileged users may use
200Guix tools to build packages or otherwise access the store, and the
201daemon will do it on their behalf, ensuring that the store is kept in a
202consistent state, and allowing built packages to be shared among users.
203
204@cindex build users
205When @command{guix-daemon} runs as @code{root}, you may not want package
206build processes themselves to run as @code{root} too, for obvious
207security reasons. To avoid that, a special pool of @dfn{build users}
208should be created for use by build processes started by the daemon.
209These build users need not have a shell and a home directory: they will
210just be used when the daemon drops @code{root} privileges in build
211processes. Having several such users allows the daemon to launch
212distinct build processes under separate UIDs, which guarantees that they
213do not interfere with each other---an essential feature since builds are
214regarded as pure functions (@pxref{Introduction}).
215
216On a GNU/Linux system, a build user pool may be created like this (using
217Bash syntax and the @code{shadow} commands):
218
091196b3
LC
219@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
220@c for why `-G' is needed.
bd5e766b
LC
221@example
222# groupadd guix-builder
223# for i in `seq 1 10`;
224 do
091196b3
LC
225 useradd -g guix-builder -G guix-builder \
226 -d /var/empty -s `which nologin` \
4d1a2b50
LC
227 -c "Guix build user $i" --system \
228 guix-builder$i;
bd5e766b
LC
229 done
230@end example
231
232@noindent
233The @code{guix-daemon} program may then be run as @code{root} with:
234
235@example
236# guix-daemon --build-users-group=guix-builder
237@end example
238
e900c503 239@cindex chroot
b095792f
LC
240@noindent
241This way, the daemon starts build processes in a chroot, under one of
242the @code{guix-builder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
243environment contains nothing but:
244
245@c Keep this list in sync with libstore/build.cc! -----------------------
246@itemize
247@item
248the @code{/dev} and @code{/proc} directories@footnote{On some systems
249@code{/dev/shm}, which supports shared memory, is a symlink to another
250directory such as @code{/run/shm}, that is @emph{not} is the chroot.
251When that is the case, shared memory support is unavailable in the
252chroot environment. The workaround is to make sure that @file{/dev/shm}
253is directly a @code{tmpfs} mount point.};
254
255@item
256@file{/etc/passwd} with an entry for the current user and an entry for
257user @file{nobody};
258
259@item
260@file{/etc/group} with an entry for the user's group;
261
262@item
263@file{/etc/hosts} with an entry that maps @code{localhost} to
264@code{127.0.0.1};
265
266@item
267a writable @file{/tmp} directory.
268@end itemize
b095792f 269
d43eb499 270If you are installing Guix as an unprivileged user, it is still
bd5e766b
LC
271possible to run @command{guix-daemon}. However, build processes will
272not be isolated from one another, and not from the rest of the system.
273Thus, build processes may interfere with each other, and may access
274programs, libraries, and other files available on the system---making it
275much harder to view them as @emph{pure} functions.
276
49e6291a
LC
277
278@node Daemon Offload Setup
279@subsection Using the Offload Facility
280
281@cindex offloading
4ec2e92d
LC
282@cindex build hook
283When desired, the build daemon can @dfn{offload}
284derivation builds to other machines
49e6291a
LC
285running Guix, using the @code{offload} @dfn{build hook}. When that
286feature is enabled, a list of user-specified build machines is read from
287@file{/etc/guix/machines.scm}; anytime a build is requested, for
288instance via @code{guix build}, the daemon attempts to offload it to one
289of the machines that satisfies the derivation's constraints, in
290particular its system type---e.g., @file{x86_64-linux}. Missing
291prerequisites for the build are copied over SSH to the target machine,
292which then proceeds with the build; upon success the output(s) of the
293build are copied back to the initial machine.
294
4ec2e92d 295The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
296
297@example
298(list (build-machine
299 (name "eightysix.example.org")
300 (system "x86_64-linux")
301 (user "bob")
302 (speed 2.)) ; incredibly fast!
303
304 (build-machine
305 (name "meeps.example.org")
306 (system "mips64el-linux")
307 (user "alice")
308 (private-key
309 (string-append (getenv "HOME")
310 "/.ssh/id-rsa-for-guix"))))
311@end example
312
313@noindent
314In the example above we specify a list of two build machines, one for
315the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
316architecture.
317
318In fact, this file is---not surprisingly!---a Scheme file that is
319evaluated when the @code{offload} hook is started. Its return value
320must be a list of @code{build-machine} objects. While this example
321shows a fixed list of build machines, one could imagine, say, using
322DNS-SD to return a list of potential build machines discovered in the
323local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
324Avahi in Guile Scheme Programs}).
325
326The compulsory fields for a @code{build-machine} declaration are:
49e6291a
LC
327
328@table @code
329
330@item name
331The remote machine's host name.
332
333@item system
334The remote machine's system type.
335
336@item user
337The user account to use when connecting to the remote machine over SSH.
338Note that the SSH key pair must @emph{not} be passphrase-protected, to
339allow non-interactive logins.
340
341@end table
342
343@noindent
4ec2e92d 344A number of optional fields may be specified:
49e6291a
LC
345
346@table @code
347
348@item private-key
349The SSH private key file to use when connecting to the machine.
350
351@item parallel-builds
352The number of builds that may run in parallel on the machine (1 by
353default.)
354
355@item speed
356A ``relative speed factor''. The offload scheduler will tend to prefer
357machines with a higher speed factor.
358
359@item features
360A list of strings denoting specific features supported by the machine.
361An example is @code{"kvm"} for machines that have the KVM Linux modules
362and corresponding hardware support. Derivations can request features by
363name, and they will be scheduled on matching build machines.
364
365@end table
366
367The @code{guix} command must be in the search path on the build
368machines, since offloading works by invoking the @code{guix archive} and
369@code{guix build} commands.
370
371There's one last thing to do once @file{machines.scm} is in place. As
372explained above, when offloading, files are transferred back and forth
373between the machine stores. For this to work, you need to generate a
374key pair to allow the daemon to export signed archives of files from the
375store (@pxref{Invoking guix archive}):
376
377@example
378# guix archive --generate-key
379@end example
380
381@noindent
382Thus, when receiving files, a machine's build daemon can make sure they
383are genuine, have not been tampered with, and that they are signed by an
384authorized key.
385
386
bd5e766b
LC
387@node Invoking guix-daemon
388@section Invoking @command{guix-daemon}
389
390The @command{guix-daemon} program implements all the functionality to
391access the store. This includes launching build processes, running the
392garbage collector, querying the availability of a build result, etc. It
393is normally run as @code{root} like this:
394
395@example
396# guix-daemon --build-users-group=guix-builder
397@end example
398
399@noindent
400For details on how to set it up, @ref{Setting Up the Daemon}.
401
e900c503
LC
402@cindex chroot
403@cindex container, build environment
404@cindex build environment
405@cindex reproducible builds
bd5e766b
LC
406By default, @command{guix-daemon} launches build processes under
407different UIDs, taken from the build group specified with
408@code{--build-users-group}. In addition, each build process is run in a
409chroot environment that only contains the subset of the store that the
410build process depends on, as specified by its derivation
411(@pxref{Programming Interface, derivation}), plus a set of specific
412system directories. By default, the latter contains @file{/dev} and
e900c503
LC
413@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
414@dfn{container}: in addition to having its own file system tree, it has
415a separate mount name space, its own PID name space, network name space,
416etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b
LC
417
418The following command-line options are supported:
419
420@table @code
421@item --build-users-group=@var{group}
422Take users from @var{group} to run build processes (@pxref{Setting Up
423the Daemon, build users}).
424
6858f9d1 425@item --no-substitutes
b5385b52 426@cindex substitutes
6858f9d1
LC
427Do not use substitutes for build products. That is, always build things
428locally instead of allowing downloads of pre-built binaries.
429
b5385b52
LC
430By default substitutes are used, unless the client---such as the
431@command{guix package} command---is explicitly invoked with
432@code{--no-substitutes}.
433
434When the daemon runs with @code{--no-substitutes}, clients can still
435explicitly enable substitution @i{via} the @code{set-build-options}
436remote procedure call (@pxref{The Store}).
437
4ec2e92d
LC
438@cindex build hook
439@item --no-build-hook
440Do not use the @dfn{build hook}.
441
442The build hook is a helper program that the daemon can start and to
443which it submits build requests. This mechanism is used to offload
444builds to other machines (@pxref{Daemon Offload Setup}).
445
bd5e766b
LC
446@item --cache-failures
447Cache build failures. By default, only successful builds are cached.
448
449@item --cores=@var{n}
450@itemx -c @var{n}
451Use @var{n} CPU cores to build each derivation; @code{0} means as many
452as available.
453
454The default value is @code{1}, but it may be overridden by clients, such
e49951eb
MW
455as the @code{--cores} option of @command{guix build} (@pxref{Invoking
456guix build}).
bd5e766b
LC
457
458The effect is to define the @code{NIX_BUILD_CORES} environment variable
459in the build process, which can then use it to exploit internal
460parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
461
462@item --max-jobs=@var{n}
463@itemx -M @var{n}
464Allow at most @var{n} build jobs in parallel. The default value is
465@code{1}.
466
467@item --debug
468Produce debugging output.
469
470This is useful to debug daemon start-up issues, but then it may be
471overridden by clients, for example the @code{--verbosity} option of
e49951eb 472@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
473
474@item --chroot-directory=@var{dir}
475Add @var{dir} to the build chroot.
476
477Doing this may change the result of build processes---for instance if
478they use optional dependencies found in @var{dir} when it is available,
479and not otherwise. For that reason, it is not recommended to do so.
480Instead, make sure that each derivation declares all the inputs that it
481needs.
482
483@item --disable-chroot
484Disable chroot builds.
485
486Using this option is not recommended since, again, it would allow build
487processes to gain access to undeclared dependencies.
488
489@item --disable-log-compression
490Disable compression of the build logs.
491
1da983b9
LC
492Unless @code{--lose-logs} is used, all the build logs are kept in the
493@var{localstatedir}. To save space, the daemon automatically compresses
494them with bzip2 by default. This option disables that.
495
bd5e766b
LC
496@item --disable-store-optimization
497Disable automatic file ``deduplication'' in the store.
498
1da983b9
LC
499By default, files added to the store are automatically ``deduplicated'':
500if a newly added file is identical as another one found in the store,
501the daemon makes the new file a hard link to the other file. This
502slightly increases the input/output load at the end of a build process.
503This option disables this.
504
bd5e766b
LC
505@item --impersonate-linux-2.6
506On Linux-based systems, impersonate Linux 2.6. This means that the
507kernel's @code{uname} system call will report 2.6 as the release number.
508
509This might be helpful to build programs that (usually wrongfully) depend
510on the kernel version number.
511
512@item --lose-logs
513Do not keep build logs. By default they are kept under
514@code{@var{localstatedir}/nix/log}.
515
516@item --system=@var{system}
517Assume @var{system} as the current system type. By default it is the
518architecture/kernel pair found at configure time, such as
519@code{x86_64-linux}.
b8d2aa26
LC
520
521@item --listen=@var{socket}
522Listen for connections on @var{socket}, the file name of a Unix-domain
523socket. The default socket is
524@file{@var{localstatedir}/daemon-socket/socket}. This option is only
525useful in exceptional circumstances, such as if you need to run several
526daemons on the same machine.
bd5e766b
LC
527@end table
528
529
eeaf4427
LC
530@c *********************************************************************
531@node Package Management
532@chapter Package Management
533
f8348b91 534The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
535remove software packages, without having to know about their build
536procedure or dependencies. Guix also goes beyond this obvious set of
537features.
538
539This chapter describes the main features of Guix, as well as the package
540management tools it provides.
541
542@menu
543* Features:: How Guix will make your life brighter.
e49951eb 544* Invoking guix package:: Package installation, removal, etc.
760c60d6 545* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 546* Invoking guix gc:: Running the garbage collector.
f651b477 547* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 548* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
549@end menu
550
551@node Features
552@section Features
553
554When using Guix, each package ends up in the @dfn{package store}, in its
555own directory---something that resembles
556@file{/nix/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
557
558Instead of referring to these directories, users have their own
559@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
560use. These profiles are stored within each user's home directory, at
561@code{$HOME/.guix-profile}.
eeaf4427 562
821b0015 563For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 564@file{/home/alice/.guix-profile/bin/gcc} points to
821b0015
LC
565@file{/nix/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
566@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
567simply continues to point to
568@file{/nix/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
569coexist on the same system without any interference.
eeaf4427 570
e49951eb
MW
571The @command{guix package} command is the central tool to manage
572packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 573profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
574
575The command provides the obvious install, remove, and upgrade
576operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 577the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 578@command{guix package} process is terminated during the transaction,
eeaf4427
LC
579or if a power outage occurs during the transaction, then the user's
580profile remains in its previous state, and remains usable.
581
582In addition, any package transaction may be @emph{rolled back}. So, if,
583for example, an upgrade installs a new version of a package that turns
584out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
585of their profile, which was known to work well. Similarly, the global
586system configuration is subject to transactional upgrades and roll-back
587(@pxref{Using the Configuration System}).
eeaf4427
LC
588
589All those packages in the package store may be @emph{garbage-collected}.
590Guix can determine which packages are still referenced by the user
fe8ff028 591profiles, and remove those that are provably no longer referenced
e49951eb 592(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
593generations of their profile so that the packages they refer to can be
594collected.
eeaf4427 595
e900c503
LC
596@cindex reproducibility
597@cindex reproducible builds
eeaf4427
LC
598Finally, Guix takes a @dfn{purely functional} approach to package
599management, as described in the introduction (@pxref{Introduction}).
600Each @file{/nix/store} package directory name contains a hash of all the
601inputs that were used to build that package---compiler, libraries, build
602scripts, etc. This direct correspondence allows users to make sure a
603given package installation matches the current state of their
e900c503
LC
604distribution. It also helps maximize @dfn{build reproducibility}:
605thanks to the isolated build environments that are used, a given build
606is likely to yield bit-identical files when performed on different
607machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 608
18f2887b 609@cindex substitute
eeaf4427 610This foundation allows Guix to support @dfn{transparent binary/source
3b78d1ea 611deployment}. When a pre-built binary for a @file{/nix/store} path is
18f2887b
LC
612available from an external source---a @dfn{substitute}, Guix just
613downloads it@footnote{@c XXX: Remove me when outdated.
614As of version @value{VERSION}, substitutes are downloaded from
615@url{http://hydra.gnu.org/} but are @emph{not} authenticated---i.e.,
616Guix cannot tell whether binaries it downloaded have been tampered with,
617nor whether they come from the genuine @code{gnu.org} build farm. This
618will be fixed in future versions. In the meantime, concerned users can
619opt for @code{--no-substitutes} (@pxref{Invoking guix-daemon}).};
620otherwise, it builds the package from source, locally.
eeaf4427 621
e49951eb
MW
622@node Invoking guix package
623@section Invoking @command{guix package}
eeaf4427 624
e49951eb 625The @command{guix package} command is the tool that allows users to
eeaf4427
LC
626install, upgrade, and remove packages, as well as rolling back to
627previous configurations. It operates only on the user's own profile,
628and works with normal user privileges (@pxref{Features}). Its syntax
629is:
630
631@example
e49951eb 632guix package @var{options}
eeaf4427
LC
633@end example
634
ba55b1cb 635Primarily, @var{options} specifies the operations to be performed during
eeaf4427
LC
636the transaction. Upon completion, a new profile is created, but
637previous generations of the profile remain available, should the user
638want to roll back.
639
6447738c
MW
640For example, to remove @code{lua} and install @code{guile} and
641@code{guile-cairo} in a single transaction:
642
643@example
644guix package -r lua -i guile guile-cairo
645@end example
646
b9e5c0a9 647For each user, a symlink to the user's default profile is automatically
0ec1af59 648created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
649current generation of the user's default profile. Thus, users can add
650@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
651variable, and so on.
652
0ec1af59
LC
653In a multi-user setup, user profiles must be stored in a place
654registered as a @dfn{garbage-collector root}, which
e49951eb 655@file{$HOME/.guix-profile} points to (@pxref{Invoking guix gc}). That
0ec1af59
LC
656directory is normally
657@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
658@var{localstatedir} is the value passed to @code{configure} as
659@code{--localstatedir}, and @var{user} is the user name. It must be
660created by @code{root}, with @var{user} as the owner. When it does not
70c43291
LC
661exist, or is not owned by @var{user}, @command{guix package} emits an
662error about it.
0ec1af59
LC
663
664The @var{options} can be among the following:
665
eeaf4427
LC
666@table @code
667
6447738c
MW
668@item --install=@var{package} @dots{}
669@itemx -i @var{package} @dots{}
670Install the specified @var{package}s.
eeaf4427 671
6447738c 672Each @var{package} may specify either a simple package name, such as
eeaf4427 673@code{guile}, or a package name followed by a hyphen and version number,
dc5669cd
MW
674such as @code{guile-1.8.8}. If no version number is specified, the
675newest available version will be selected. In addition, @var{package}
676may contain a colon, followed by the name of one of the outputs of the
6e721c4d
LC
677package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
678(@pxref{Packages with Multiple Outputs}).
eeaf4427 679
461572cc
LC
680@cindex propagated inputs
681Sometimes packages have @dfn{propagated inputs}: these are dependencies
682that automatically get installed along with the required package.
683
684An example is the GNU MPC library: its C header files refer to those of
685the GNU MPFR library, which in turn refer to those of the GMP library.
686Thus, when installing MPC, the MPFR and GMP libraries also get installed
687in the profile; removing MPC also removes MPFR and GMP---unless they had
688also been explicitly installed independently.
689
ba7ea5ce 690Besides, packages sometimes rely on the definition of environment
5924080d 691variables for their search paths (see explanation of
ba7ea5ce 692@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
693environment variable definitions are reported here.
694
ef010c0f 695@c XXX: keep me up-to-date
5924080d 696Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
697availability of a newer upstream version. In the future, it may provide
698the option of installing directly from the upstream version, even if
699that version is not yet in the distribution.
700
5d4b411f
LC
701@item --install-from-expression=@var{exp}
702@itemx -e @var{exp}
703Install the package @var{exp} evaluates to.
704
705@var{exp} must be a Scheme expression that evaluates to a
706@code{<package>} object. This option is notably useful to disambiguate
707between same-named variants of a package, with expressions such as
708@code{(@@ (gnu packages base) guile-final)}.
709
710Note that this option installs the first output of the specified
711package, which may be insufficient when needing a specific output of a
712multiple-output package.
713
6447738c
MW
714@item --remove=@var{package} @dots{}
715@itemx -r @var{package} @dots{}
716Remove the specified @var{package}s.
eeaf4427 717
6447738c 718As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
719and/or output name in addition to the package name. For instance,
720@code{-r glibc:debug} would remove the @code{debug} output of
721@code{glibc}.
722
6447738c
MW
723@item --upgrade[=@var{regexp} @dots{}]
724@itemx -u [@var{regexp} @dots{}]
725Upgrade all the installed packages. If one or more @var{regexp}s are
726specified, upgrade only installed packages whose name matches a
727@var{regexp}.
eeaf4427 728
f651b477
LC
729Note that this upgrades package to the latest version of packages found
730in the distribution currently installed. To update your distribution,
731you should regularly run @command{guix pull} (@pxref{Invoking guix
732pull}).
733
24e262f0
LC
734@item --roll-back
735Roll back to the previous @dfn{generation} of the profile---i.e., undo
736the last transaction.
737
738When combined with options such as @code{--install}, roll back occurs
739before any other actions.
740
d9307267 741When rolling back from the first generation that actually contains
4b2bc804
NK
742installed packages, the profile is made to point to the @dfn{zeroth
743generation}, which contains no files apart from its own meta-data.
d9307267 744
82fe08ed
LC
745Installing, removing, or upgrading packages from a generation that has
746been rolled back to overwrites previous future generations. Thus, the
747history of a profile's generations is always linear.
748
5924080d
LC
749@item --search-paths
750@cindex search paths
751Report environment variable definitions, in Bash syntax, that may be
752needed in order to use the set of installed packages. These environment
753variables are used to specify @dfn{search paths} for files used by some
754of the installed packages.
755
756For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
757environment variables to be defined so it can look for headers and
758libraries in the user's profile (@pxref{Environment Variables,,, gcc,
759Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
760library are installed in the profile, then @code{--search-paths} will
761suggest setting these variables to @code{@var{profile}/include} and
762@code{@var{profile}/lib}, respectively.
763
eeaf4427
LC
764@item --profile=@var{profile}
765@itemx -p @var{profile}
766Use @var{profile} instead of the user's default profile.
767
768@item --dry-run
769@itemx -n
770Show what would be done without actually doing it.
771
56b1f4b7
LC
772@item --fallback
773When substituting a pre-built binary fails, fall back to building
774packages locally.
775
3b824605 776@item --no-substitutes
b5385b52
LC
777Do not use substitutes for build products. That is, always build things
778locally instead of allowing downloads of pre-built binaries.
779
780@item --max-silent-time=@var{seconds}
969e678e 781Same as for @command{guix build} (@pxref{Invoking guix build}).
3b824605 782
70915c1a
LC
783@item --verbose
784Produce verbose output. In particular, emit the environment's build log
785on the standard error port.
786
eeaf4427
LC
787@item --bootstrap
788Use the bootstrap Guile to build the profile. This option is only
789useful to distribution developers.
790
791@end table
792
e49951eb 793In addition to these actions @command{guix package} supports the
733b4130
LC
794following options to query the current state of a profile, or the
795availability of packages:
eeaf4427 796
733b4130
LC
797@table @option
798
acc08466
NK
799@item --search=@var{regexp}
800@itemx -s @var{regexp}
801List the available packages whose synopsis or description matches
299112d3
LC
802@var{regexp}. Print all the meta-data of matching packages in
803@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
804GNU recutils manual}).
acc08466 805
299112d3
LC
806This allows specific fields to be extracted using the @command{recsel}
807command, for instance:
808
809@example
e49951eb 810$ guix package -s malloc | recsel -p name,version
299112d3
LC
811name: glibc
812version: 2.17
813
814name: libgc
815version: 7.2alpha6
816@end example
acc08466 817
733b4130
LC
818@item --list-installed[=@var{regexp}]
819@itemx -I [@var{regexp}]
bd9bde1c
LC
820List the currently installed packages in the specified profile, with the
821most recently installed packages shown last. When @var{regexp} is
822specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
823
824For each installed package, print the following items, separated by
825tabs: the package name, its version string, the part of the package that
826is installed (for instance, @code{out} for the default output,
827@code{include} for its headers, etc.), and the path of this package in
828the store.
829
64fc89b6
LC
830@item --list-available[=@var{regexp}]
831@itemx -A [@var{regexp}]
a1ba8475
LC
832List packages currently available in the software distribution
833(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
834installed packages whose name matches @var{regexp}.
64fc89b6
LC
835
836For each package, print the following items separated by tabs: its name,
6e721c4d
LC
837its version string, the parts of the package (@pxref{Packages with
838Multiple Outputs}), and the source location of its definition.
64fc89b6 839
f566d765
LC
840@item --list-generations[=@var{pattern}]
841@itemx -l [@var{pattern}]
842Return a list of generations along with their creation dates; for each
843generation, show the installed packages, with the most recently
4b2bc804
NK
844installed packages shown last. Note that the zeroth generation is never
845shown.
f566d765
LC
846
847For each installed package, print the following items, separated by
848tabs: the name of a package, its version string, the part of the package
849that is installed (@pxref{Packages with Multiple Outputs}), and the
850location of this package in the store.
851
852When @var{pattern} is used, the command returns only matching
853generations. Valid patterns include:
854
855@itemize
856@item @emph{Integers and comma-separated integers}. Both patterns denote
857generation numbers. For instance, @code{--list-generations=1} returns
858the first one.
859
860And @code{--list-generations=1,8,2} outputs three generations in the
861specified order. Neither spaces nor trailing commas are allowed.
862
863@item @emph{Ranges}. @code{--list-generations=2..9} prints the
864specified generations and everything in between. Note that the start of
865a range must be lesser than its end.
866
867It is also possible to omit the endpoint. For example,
868@code{--list-generations=2..}, returns all generations starting from the
869second one.
870
871@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
872or months by passing an integer along with the first letter of the
d7ddb257
LC
873duration. For example, @code{--list-generations=20d} lists generations
874that are up to 20 days old.
f566d765
LC
875@end itemize
876
b7884ca3
NK
877@item --delete-generations[=@var{pattern}]
878@itemx -d [@var{pattern}]
d7ddb257
LC
879When @var{pattern} is omitted, delete all generations except the current
880one.
b7884ca3
NK
881
882This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
883When @var{pattern} is specified, delete the matching generations. When
884@var{pattern} specifies a duration, generations @emph{older} than the
885specified duration match. For instance, @code{--delete-generations=1m}
886deletes generations that are more than one month old.
887
888If the current generation matches, it is deleted atomically---i.e., by
889switching to the previous available generation. Note that the zeroth
890generation is never deleted.
b7884ca3 891
1bb9900a
LC
892Note that deleting generations prevents roll-back to them.
893Consequently, this command must be used with care.
894
733b4130 895@end table
eeaf4427 896
6e721c4d
LC
897@node Packages with Multiple Outputs
898@section Packages with Multiple Outputs
899
900@cindex multiple-output packages
901@cindex package outputs
902
903Often, packages defined in Guix have a single @dfn{output}---i.e., the
904source package leads exactly one directory in the store. When running
905@command{guix package -i glibc}, one installs the default output of the
906GNU libc package; the default output is called @code{out}, but its name
907can be omitted as shown in this command. In this particular case, the
908default output of @code{glibc} contains all the C header files, shared
909libraries, static libraries, Info documentation, and other supporting
910files.
911
912Sometimes it is more appropriate to separate the various types of files
913produced from a single source package into separate outputs. For
914instance, the GLib C library (used by GTK+ and related packages)
915installs more than 20 MiB of reference documentation as HTML pages.
916To save space for users who do not need it, the documentation goes to a
917separate output, called @code{doc}. To install the main GLib output,
918which contains everything but the documentation, one would run:
919
920@example
921guix package -i glib
922@end example
923
924The command to install its documentation is:
925
926@example
927guix package -i glib:doc
928@end example
929
930Some packages install programs with different ``dependency footprints''.
931For instance, the WordNet package install both command-line tools and
932graphical user interfaces (GUIs). The former depend solely on the C
933library, whereas the latter depend on Tcl/Tk and the underlying X
934libraries. In this case, we leave the command-line tools in the default
935output, whereas the GUIs are in a separate output. This allows users
936who do not need the GUIs to save space.
937
938There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
939Other conventional output names include @code{lib} for libraries and
940possibly header files, @code{bin} for stand-alone programs, and
941@code{debug} for debugging information (@pxref{Installing Debugging
942Files}). The outputs of a packages are listed in the third column of
943the output of @command{guix package --list-available} (@pxref{Invoking
944guix package}).
6e721c4d 945
eeaf4427 946
e49951eb
MW
947@node Invoking guix gc
948@section Invoking @command{guix gc}
fe8ff028
LC
949
950@cindex garbage collector
951Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 952The @command{guix gc} command allows users to explicitly run the garbage
fe8ff028
LC
953collector to reclaim space from the @file{/nix/store} directory.
954
955The garbage collector has a set of known @dfn{roots}: any file under
956@file{/nix/store} reachable from a root is considered @dfn{live} and
957cannot be deleted; any other file is considered @dfn{dead} and may be
958deleted. The set of garbage collector roots includes default user
e49951eb
MW
959profiles, and may be augmented with @command{guix build --root}, for
960example (@pxref{Invoking guix build}).
fe8ff028 961
1bb9900a
LC
962Prior to running @code{guix gc --collect-garbage} to make space, it is
963often useful to remove old generations from user profiles; that way, old
964package builds referenced by those generations can be reclaimed. This
965is achieved by running @code{guix package --delete-generations}
966(@pxref{Invoking guix package}).
967
e49951eb 968The @command{guix gc} command has three modes of operation: it can be
fe8ff028
LC
969used to garbage-collect any dead files (the default), to delete specific
970files (the @code{--delete} option), or to print garbage-collector
971information. The available options are listed below:
972
973@table @code
974@item --collect-garbage[=@var{min}]
975@itemx -C [@var{min}]
976Collect garbage---i.e., unreachable @file{/nix/store} files and
977sub-directories. This is the default operation when no option is
978specified.
979
980When @var{min} is given, stop once @var{min} bytes have been collected.
981@var{min} may be a number of bytes, or it may include a unit as a
982suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes.
983
984When @var{min} is omitted, collect all the garbage.
985
986@item --delete
987@itemx -d
988Attempt to delete all the store files and directories specified as
989arguments. This fails if some of the files are not in the store, or if
990they are still live.
991
992@item --list-dead
993Show the list of dead files and directories still present in the
994store---i.e., files and directories no longer reachable from any root.
995
996@item --list-live
997Show the list of live store files and directories.
ba8b732d
LC
998
999@end table
1000
1001In addition, the references among existing store files can be queried:
1002
1003@table @code
1004
1005@item --references
1006@itemx --referrers
1007List the references (respectively, the referrers) of store files given
1008as arguments.
1009
8e59fdd5
LC
1010@item --requisites
1011@itemx -R
1012List the requisites of the store files passed as arguments. Requisites
1013include the store files themselves, their references, and the references
1014of these, recursively. In other words, the returned list is the
1015@dfn{transitive closure} of the store files.
1016
fe8ff028
LC
1017@end table
1018
eeaf4427 1019
f651b477
LC
1020@node Invoking guix pull
1021@section Invoking @command{guix pull}
1022
1023Packages are installed or upgraded to the latest version available in
1024the distribution currently available on your local machine. To update
1025that distribution, along with the Guix tools, you must run @command{guix
1026pull}: the command downloads the latest Guix source code and package
1027descriptions, and deploys it.
1028
1029On completion, @command{guix package} will use packages and package
1030versions from this just-retrieved copy of Guix. Not only that, but all
1031the Guix commands and Scheme modules will also be taken from that latest
1032version. New @command{guix} sub-commands added by the update also
1033become available.
1034
1035The @command{guix pull} command is usually invoked with no arguments,
1036but it supports the following options:
1037
1038@table @code
1039@item --verbose
1040Produce verbose output, writing build logs to the standard error output.
1041
ab5d72ad
LC
1042@item --url=@var{url}
1043Download the source tarball of Guix from @var{url}.
1044
1045By default, the tarball is taken from its canonical address at
1046@code{gnu.org}, for the stable branch of Guix.
1047
f651b477
LC
1048@item --bootstrap
1049Use the bootstrap Guile to build the latest Guix. This option is only
1050useful to Guix developers.
1051@end table
1052
760c60d6
LC
1053
1054@node Invoking guix archive
1055@section Invoking @command{guix archive}
1056
1057The @command{guix archive} command allows users to @dfn{export} files
1058from the store into a single archive, and to later @dfn{import} them.
1059In particular, it allows store files to be transferred from one machine
1060to another machine's store. For example, to transfer the @code{emacs}
1061package to a machine connected over SSH, one would run:
1062
1063@example
1064guix archive --export emacs | ssh the-machine guix archive --import
1065@end example
1066
87236aed
LC
1067@noindent
1068However, note that, in this example, all of @code{emacs} and its
1069dependencies are transferred, regardless of what is already available in
1070the target machine's store. The @code{--missing} option can help figure
1071out which items are missing from the target's store.
1072
760c60d6
LC
1073Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
1074comparable in spirit to `tar'. When exporting, the daemon digitally
1075signs the contents of the archive, and that digital signature is
1076appended. When importing, the daemon verifies the signature and rejects
f82cc5fd
LC
1077the import in case of an invalid signature or if the signing key is not
1078authorized.
760c60d6
LC
1079@c FIXME: Add xref to daemon doc about signatures.
1080
1081The main options are:
1082
1083@table @code
1084@item --export
1085Export the specified store files or packages (see below.) Write the
1086resulting archive to the standard output.
1087
1088@item --import
1089Read an archive from the standard input, and import the files listed
1090therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
1091signature, or if it is signed by a public key not among the authorized
1092keys (see @code{--authorize} below.)
554f26ec 1093
87236aed
LC
1094@item --missing
1095Read a list of store file names from the standard input, one per line,
1096and write on the standard output the subset of these files missing from
1097the store.
1098
554f26ec 1099@item --generate-key[=@var{parameters}]
f82cc5fd 1100@cindex signing, archives
554f26ec
LC
1101Generate a new key pair for the daemons. This is a prerequisite before
1102archives can be exported with @code{--export}. Note that this operation
1103usually takes time, because it needs to gather enough entropy to
1104generate the key pair.
1105
1106The generated key pair is typically stored under @file{/etc/guix}, in
1107@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
1108key, which must be kept secret.) When @var{parameters} is omitted, it
1109is a 4096-bit RSA key. Alternately, @var{parameters} can specify
1110@code{genkey} parameters suitable for Libgcrypt (@pxref{General
1111public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
1112Libgcrypt Reference Manual}).
f82cc5fd
LC
1113
1114@item --authorize
1115@cindex authorizing, archives
1116Authorize imports signed by the public key passed on standard input.
1117The public key must be in ``s-expression advanced format''---i.e., the
1118same format as the @file{signing-key.pub} file.
1119
1120The list of authorized keys is kept in the human-editable file
1121@file{/etc/guix/acl}. The file contains
1122@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
1123s-expressions''} and is structured as an access-control list in the
1124@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
1125(SPKI)}.
760c60d6
LC
1126@end table
1127
1128To export store files as an archive to the standard output, run:
1129
1130@example
1131guix archive --export @var{options} @var{specifications}...
1132@end example
1133
1134@var{specifications} may be either store file names or package
1135specifications, as for @command{guix package} (@pxref{Invoking guix
1136package}). For instance, the following command creates an archive
1137containing the @code{gui} output of the @code{git} package and the main
1138output of @code{emacs}:
1139
1140@example
1141guix archive --export git:gui /nix/store/...-emacs-24.3 > great.nar
1142@end example
1143
1144If the specified packages are not built yet, @command{guix archive}
1145automatically builds them. The build process may be controlled with the
1146same options that can be passed to the @command{guix build} command
1147(@pxref{Invoking guix build}).
1148
1149
568717fd
LC
1150@c *********************************************************************
1151@node Programming Interface
1152@chapter Programming Interface
1153
3dc1970d
LC
1154GNU Guix provides several Scheme programming interfaces (APIs) to
1155define, build, and query packages. The first interface allows users to
1156write high-level package definitions. These definitions refer to
1157familiar packaging concepts, such as the name and version of a package,
1158its build system, and its dependencies. These definitions can then be
1159turned into concrete build actions.
1160
ba55b1cb 1161Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d
LC
1162standard setup, the daemon has write access to the store---the
1163@file{/nix/store} directory---whereas users do not. The recommended
1164setup also has the daemon perform builds in chroots, under a specific
1165build users, to minimize interference with the rest of the system.
1166
1167@cindex derivation
1168Lower-level APIs are available to interact with the daemon and the
1169store. To instruct the daemon to perform a build action, users actually
1170provide it with a @dfn{derivation}. A derivation is a low-level
1171representation of the build actions to be taken, and the environment in
1172which they should occur---derivations are to package definitions what
1173assembly is to C programs.
1174
1175This chapter describes all these APIs in turn, starting from high-level
1176package definitions.
1177
568717fd 1178@menu
b860f382
LC
1179* Defining Packages:: Defining new packages.
1180* The Store:: Manipulating the package store.
1181* Derivations:: Low-level interface to package derivations.
1182* The Store Monad:: Purely functional interface to the store.
568717fd
LC
1183@end menu
1184
1185@node Defining Packages
1186@section Defining Packages
1187
3dc1970d
LC
1188The high-level interface to package definitions is implemented in the
1189@code{(guix packages)} and @code{(guix build-system)} modules. As an
1190example, the package definition, or @dfn{recipe}, for the GNU Hello
1191package looks like this:
1192
1193@example
b22a12fd
LC
1194(use-modules (guix packages)
1195 (guix download)
1196 (guix build-system gnu)
1197 (guix licenses))
1198
3dc1970d
LC
1199(define hello
1200 (package
1201 (name "hello")
1202 (version "2.8")
1203 (source (origin
1204 (method url-fetch)
1205 (uri (string-append "mirror://gnu/hello/hello-" version
1206 ".tar.gz"))
1207 (sha256
1208 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
1209 (build-system gnu-build-system)
1210 (inputs `(("gawk" ,gawk)))
1211 (synopsis "GNU Hello")
1212 (description "Yeah...")
1213 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 1214 (license gpl3+)))
3dc1970d
LC
1215@end example
1216
1217@noindent
1218Without being a Scheme expert, the reader may have guessed the meaning
1219of the various fields here. This expression binds variable @var{hello}
1220to a @code{<package>} object, which is essentially a record
1221(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
1222This package object can be inspected using procedures found in the
1223@code{(guix packages)} module; for instance, @code{(package-name hello)}
1224returns---surprise!---@code{"hello"}.
1225
1226There are a few points worth noting in the above package definition:
1227
1228@itemize
1229@item
1230The @code{source} field of the package is an @code{<origin>} object.
1231Here, the @code{url-fetch} method from @code{(guix download)} is used,
1232meaning that the source is a file to be downloaded over FTP or HTTP.
1233
1234The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
1235the GNU mirrors defined in @code{(guix download)}.
1236
1237The @code{sha256} field specifies the expected SHA256 hash of the file
1238being downloaded. It is mandatory, and allows Guix to check the
1239integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 1240base32 representation of the hash. You can obtain this information with
210cc920
LC
1241@code{guix download} (@pxref{Invoking guix download}) and @code{guix
1242hash} (@pxref{Invoking guix hash}).
3dc1970d 1243
f9cc8971
LC
1244@cindex patches
1245When needed, the @code{origin} form can also have a @code{patches} field
1246listing patches to be applied, and a @code{snippet} field giving a
1247Scheme expression to modify the source code.
1248
3dc1970d
LC
1249@item
1250@cindex GNU Build System
1251The @code{build-system} field is set to @var{gnu-build-system}. The
1252@var{gnu-build-system} variable is defined in the @code{(guix
1253build-system gnu)} module, and is bound to a @code{<build-system>}
1254object.
1255
1256Naturally, @var{gnu-build-system} represents the familiar GNU Build
1257System, and variants thereof (@pxref{Configuration, configuration and
1258makefile conventions,, standards, GNU Coding Standards}). In a
ba55b1cb 1259nutshell, packages using the GNU Build System may be configured, built,
3dc1970d
LC
1260and installed with the usual @code{./configure && make && make check &&
1261make install} command sequence. This is what @var{gnu-build-system}
1262does.
1263
1264In addition, @var{gnu-build-system} ensures that the ``standard''
1265environment for GNU packages is available. This includes tools such as
1266GCC, Coreutils, Bash, Make, Diffutils, and Patch.
1267
1268@item
1269The @code{inputs} field specifies inputs to the build process---i.e.,
1270build-time or run-time dependencies of the package. Here, we define an
1271input called @code{"gawk"} whose value is that of the @var{gawk}
1272variable; @var{gawk} is itself bound to a @code{<package>} object.
1273
1274Note that GCC, Coreutils, Bash, and other essential tools do not need to
1275be specified as inputs here. Instead, @var{gnu-build-system} takes care
1276of ensuring that they are present.
1277
1278However, any other dependencies need to be specified in the
1279@code{inputs} field. Any dependency not specified here will simply be
1280unavailable to the build process, possibly leading to a build failure.
1281@end itemize
1282
1283There are other fields that package definitions may provide. Of
1284particular interest is the @code{arguments} field. When specified, it
1285must be bound to a list of additional arguments to be passed to the
1286build system. For instance, the above definition could be augmented
1287with the following field initializer:
1288
1289@example
1290 (arguments `(#:tests? #f
1291 #:configure-flags '("--enable-silent-rules")))
1292@end example
1293
1294@noindent
1295These are keyword arguments (@pxref{Optional Arguments, keyword
1296arguments in Guile,, guile, GNU Guile Reference Manual}). They are
1297passed to @var{gnu-build-system}, which interprets them as meaning ``do
1298not run @code{make check}'', and ``run @file{configure} with the
874e6874
LC
1299@code{--enable-silent-rules} flag''. The value of these keyword
1300parameters is actually evaluated in the @dfn{build stratum}---i.e., by a
1301Guile process launched by the daemon (@pxref{Derivations}).
3dc1970d
LC
1302
1303Once a package definition is in place@footnote{Simple package
1304definitions like the one above may be automatically converted from the
e49951eb
MW
1305Nixpkgs distribution using the @command{guix import} command.}, the
1306package may actually be built using the @code{guix build} command-line
37166310
LC
1307tool (@pxref{Invoking guix build}). Eventually, updating the package
1308definition to a new upstream version can be partly automated by the
1309@command{guix refresh} command (@pxref{Invoking guix refresh}).
3dc1970d
LC
1310
1311Behind the scenes, a derivation corresponding to the @code{<package>}
1312object is first computed by the @code{package-derivation} procedure.
1313That derivation is stored in a @code{.drv} file under @file{/nix/store}.
ba55b1cb 1314The build actions it prescribes may then be realized by using the
3dc1970d
LC
1315@code{build-derivations} procedure (@pxref{The Store}).
1316
1317@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
1318Return the @code{<derivation>} object of @var{package} for @var{system}
1319(@pxref{Derivations}).
3dc1970d
LC
1320
1321@var{package} must be a valid @code{<package>} object, and @var{system}
1322must be a string denoting the target system type---e.g.,
1323@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
1324must be a connection to the daemon, which operates on the store
1325(@pxref{The Store}).
1326@end deffn
568717fd 1327
9c1edabd
LC
1328@noindent
1329@cindex cross-compilation
1330Similarly, it is possible to compute a derivation that cross-builds a
1331package for some other system:
1332
1333@deffn {Scheme Procedure} package-cross-derivation @var{store} @
1334 @var{package} @var{target} [@var{system}]
59688fc4
LC
1335Return the @code{<derivation>} object of @var{package} cross-built from
1336@var{system} to @var{target}.
9c1edabd
LC
1337
1338@var{target} must be a valid GNU triplet denoting the target hardware
1339and operating system, such as @code{"mips64el-linux-gnu"}
1340(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
1341Configure and Build System}).
1342@end deffn
1343
1344
568717fd
LC
1345@node The Store
1346@section The Store
1347
e531ac2a
LC
1348@cindex store
1349@cindex store paths
1350
1351Conceptually, the @dfn{store} is where derivations that have been
1352successfully built are stored---by default, under @file{/nix/store}.
1353Sub-directories in the store are referred to as @dfn{store paths}. The
1354store has an associated database that contains information such has the
1355store paths referred to by each store path, and the list of @emph{valid}
1356store paths---paths that result from a successful build.
1357
1358The store is always accessed by the daemon on behalf of its clients
1359(@pxref{Invoking guix-daemon}). To manipulate the store, clients
1360connect to the daemon over a Unix-domain socket, send it requests, and
1361read the result---these are remote procedure calls, or RPCs.
1362
1363The @code{(guix store)} module provides procedures to connect to the
1364daemon, and to perform RPCs. These are described below.
1365
1366@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
1367Connect to the daemon over the Unix-domain socket at @var{file}. When
1368@var{reserve-space?} is true, instruct it to reserve a little bit of
1369extra space on the file system so that the garbage collector can still
1370operate, should the disk become full. Return a server object.
1371
1372@var{file} defaults to @var{%default-socket-path}, which is the normal
1373location given the options that were passed to @command{configure}.
1374@end deffn
1375
1376@deffn {Scheme Procedure} close-connection @var{server}
1377Close the connection to @var{server}.
1378@end deffn
1379
1380@defvr {Scheme Variable} current-build-output-port
1381This variable is bound to a SRFI-39 parameter, which refers to the port
1382where build and error logs sent by the daemon should be written.
1383@end defvr
1384
1385Procedures that make RPCs all take a server object as their first
1386argument.
1387
1388@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
1389Return @code{#t} when @var{path} is a valid store path.
1390@end deffn
1391
cfbf9160 1392@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
1393Add @var{text} under file @var{name} in the store, and return its store
1394path. @var{references} is the list of store paths referred to by the
1395resulting store path.
1396@end deffn
1397
874e6874 1398@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
1399Build @var{derivations} (a list of @code{<derivation>} objects or
1400derivation paths), and return when the worker is done building them.
1401Return @code{#t} on success.
874e6874
LC
1402@end deffn
1403
b860f382
LC
1404Note that the @code{(guix monads)} module provides a monad as well as
1405monadic versions of the above procedures, with the goal of making it
1406more convenient to work with code that accesses the store (@pxref{The
1407Store Monad}).
1408
e531ac2a
LC
1409@c FIXME
1410@i{This section is currently incomplete.}
568717fd
LC
1411
1412@node Derivations
1413@section Derivations
1414
874e6874
LC
1415@cindex derivations
1416Low-level build actions and the environment in which they are performed
1417are represented by @dfn{derivations}. A derivation contain the
1418following pieces of information:
1419
1420@itemize
1421@item
1422The outputs of the derivation---derivations produce at least one file or
1423directory in the store, but may produce more.
1424
1425@item
1426The inputs of the derivations, which may be other derivations or plain
1427files in the store (patches, build scripts, etc.)
1428
1429@item
1430The system type targeted by the derivation---e.g., @code{x86_64-linux}.
1431
1432@item
1433The file name of a build script in the store, along with the arguments
1434to be passed.
1435
1436@item
1437A list of environment variables to be defined.
1438
1439@end itemize
1440
1441@cindex derivation path
1442Derivations allow clients of the daemon to communicate build actions to
1443the store. They exist in two forms: as an in-memory representation,
1444both on the client- and daemon-side, and as files in the store whose
1445name end in @code{.drv}---these files are referred to as @dfn{derivation
1446paths}. Derivations paths can be passed to the @code{build-derivations}
1447procedure to perform the build actions they prescribe (@pxref{The
1448Store}).
1449
1450The @code{(guix derivations)} module provides a representation of
1451derivations as Scheme objects, along with procedures to create and
1452otherwise manipulate derivations. The lowest-level primitive to create
1453a derivation is the @code{derivation} procedure:
1454
1909431c
LC
1455@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
1456 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
1457 [#:hash-mode #f] [#:inputs '()] [#:env-vars '()] @
1458 [#:system (%current-system)] [#:references-graphs #f] @
1459 [#:local-build? #f]
59688fc4
LC
1460Build a derivation with the given arguments, and return the resulting
1461@code{<derivation>} object.
874e6874
LC
1462
1463When @var{hash}, @var{hash-algo}, and @var{hash-mode} are given, a
1464@dfn{fixed-output derivation} is created---i.e., one whose result is
1465known in advance, such as a file download.
5b0c9d16 1466
858e9282 1467When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
1468name/store path pairs. In that case, the reference graph of each store
1469path is exported in the build environment in the corresponding file, in
1470a simple text format.
1909431c
LC
1471
1472When @var{local-build?} is true, declare that the derivation is not a
1473good candidate for offloading and should rather be built locally
1474(@pxref{Daemon Offload Setup}). This is the case for small derivations
1475where the costs of data transfers would outweigh the benefits.
874e6874
LC
1476@end deffn
1477
1478@noindent
1479Here's an example with a shell script as its builder, assuming
1480@var{store} is an open connection to the daemon, and @var{bash} points
1481to a Bash executable in the store:
1482
1483@lisp
1484(use-modules (guix utils)
1485 (guix store)
1486 (guix derivations))
1487
59688fc4
LC
1488(let ((builder ; add the Bash script to the store
1489 (add-text-to-store store "my-builder.sh"
1490 "echo hello world > $out\n" '())))
1491 (derivation store "foo"
1492 bash `("-e" ,builder)
1493 #:env-vars '(("HOME" . "/homeless"))))
1494@result{} #<derivation /nix/store/@dots{}-foo.drv => /nix/store/@dots{}-foo>
874e6874
LC
1495@end lisp
1496
1497As can be guessed, this primitive is cumbersome to use directly. An
1498improved variant is @code{build-expression->derivation}, which allows
1499the caller to directly pass a Guile expression as the build script:
1500
dd1a5a15
LC
1501@deffn {Scheme Procedure} build-expression->derivation @var{store} @
1502 @var{name} @var{exp} @
1503 [#:system (%current-system)] [#:inputs '()] @
1504 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
1505 [#:env-vars '()] [#:modules '()] @
1909431c 1506 [#:references-graphs #f] [#:local-build? #f] [#:guile-for-build #f]
874e6874
LC
1507Return a derivation that executes Scheme expression @var{exp} as a
1508builder for derivation @var{name}. @var{inputs} must be a list of
1509@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
1510@code{"out"} is assumed. @var{modules} is a list of names of Guile
1511modules from the current search path to be copied in the store,
1512compiled, and made available in the load path during the execution of
1513@var{exp}---e.g., @code{((guix build utils) (guix build
1514gnu-build-system))}.
1515
1516@var{exp} is evaluated in an environment where @code{%outputs} is bound
1517to a list of output/path pairs, and where @code{%build-inputs} is bound
1518to a list of string/output-path pairs made from @var{inputs}.
1519Optionally, @var{env-vars} is a list of string pairs specifying the name
1520and value of environment variables visible to the builder. The builder
1521terminates by passing the result of @var{exp} to @code{exit}; thus, when
1522@var{exp} returns @code{#f}, the build is considered to have failed.
1523
1524@var{exp} is built using @var{guile-for-build} (a derivation). When
1525@var{guile-for-build} is omitted or is @code{#f}, the value of the
1526@code{%guile-for-build} fluid is used instead.
9c629a27 1527
1909431c
LC
1528See the @code{derivation} procedure for the meaning of @var{references-graphs}
1529and @var{local-build?}.
874e6874
LC
1530@end deffn
1531
1532@noindent
1533Here's an example of a single-output derivation that creates a directory
1534containing one file:
1535
1536@lisp
1537(let ((builder '(let ((out (assoc-ref %outputs "out")))
1538 (mkdir out) ; create /nix/store/@dots{}-goo
1539 (call-with-output-file (string-append out "/test")
1540 (lambda (p)
1541 (display '(hello guix) p))))))
dd1a5a15 1542 (build-expression->derivation store "goo" builder))
874e6874 1543
59688fc4 1544@result{} #<derivation /nix/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
1545@end lisp
1546
1547@cindex strata of code
1548Remember that the build expression passed to
1549@code{build-expression->derivation} is run by a separate Guile process
1550than the one that calls @code{build-expression->derivation}: it is run
1551by a Guile process launched by the daemon, typically in a chroot. So,
1552while there is a single language for both the @dfn{host} and the build
1553side, there are really two @dfn{strata} of code: the host-side, and the
1554build-side code@footnote{The term @dfn{stratum} in this context was
1555coined by Manuel Serrano et al. in the context of their work on Hop.}.
1556This distinction is important to keep in mind, notably when using
1557higher-level constructs such as @var{gnu-build-system} (@pxref{Defining
1558Packages}). For this reason, Guix modules that are meant to be used in
1559the build stratum are kept in the @code{(guix build @dots{})} name
1560space.
568717fd 1561
b860f382
LC
1562@node The Store Monad
1563@section The Store Monad
1564
1565@cindex monad
1566
1567The procedures that operate on the store described in the previous
1568sections all take an open connection to the build daemon as their first
1569argument. Although the underlying model is functional, they either have
1570side effects or depend on the current state of the store.
1571
1572The former is inconvenient: the connection to the build daemon has to be
1573carried around in all those functions, making it impossible to compose
1574functions that do not take that parameter with functions that do. The
1575latter can be problematic: since store operations have side effects
1576and/or depend on external state, they have to be properly sequenced.
1577
1578@cindex monadic values
1579@cindex monadic functions
1580This is where the @code{(guix monads)} module comes in. This module
1581provides a framework for working with @dfn{monads}, and a particularly
1582useful monad for our uses, the @dfn{store monad}. Monads are a
1583construct that allows two things: associating ``context'' with values
1584(in our case, the context is the store), and building sequences of
1585computations (here computations includes accesses to the store.) Values
1586in a monad---values that carry this additional context---are called
1587@dfn{monadic values}; procedures that return such values are called
1588@dfn{monadic procedures}.
1589
1590Consider this ``normal'' procedure:
1591
1592@example
1593(define (profile.sh store)
1594 ;; Return the name of a shell script in the store that
1595 ;; initializes the 'PATH' environment variable.
1596 (let* ((drv (package-derivation store coreutils))
1597 (out (derivation->output-path drv)))
1598 (add-text-to-store store "profile.sh"
1599 (format #f "export PATH=~a/bin" out))))
1600@end example
1601
1602Using @code{(guix monads)}, it may be rewritten as a monadic function:
1603
1604@example
1605(define (profile.sh)
1606 ;; Same, but return a monadic value.
1607 (mlet %store-monad ((bin (package-file coreutils "bin")))
1608 (text-file "profile.sh"
1609 (string-append "export PATH=" bin))))
1610@end example
1611
1612There are two things to note in the second version: the @code{store}
1613parameter is now implicit, and the monadic value returned by
1614@code{package-file}---a wrapper around @code{package-derivation} and
1615@code{derivation->output-path}---is @dfn{bound} using @code{mlet}
1616instead of plain @code{let}.
1617
1618Calling the monadic @code{profile.sh} has no effect. To get the desired
1619effect, one must use @code{run-with-store}:
1620
1621@example
1622(run-with-store (open-connection) (profile.sh))
1623@result{} /nix/store/...-profile.sh
1624@end example
1625
1626The main syntactic forms to deal with monads in general are described
1627below.
1628
1629@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
1630Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
1631in @var{monad}.
1632@end deffn
1633
1634@deffn {Scheme Syntax} return @var{val}
1635Return a monadic value that encapsulates @var{val}.
1636@end deffn
1637
1638@deffn {Scheme Syntax} >>= @var{mval} @var{mproc}
1639@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
1640procedure @var{mproc}@footnote{This operation is commonly referred to as
1641``bind'', but that name denotes an unrelated procedure in Guile. Thus
1642we use this somewhat cryptic symbol inherited from the Haskell
1643language.}.
1644@end deffn
1645
1646@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
1647 @var{body} ...
1648@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
1649 @var{body} ...
1650Bind the variables @var{var} to the monadic values @var{mval} in
1651@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
1652``normal'' value @var{val}, as per @code{let}.
1653
1654@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
1655(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
1656@end deffn
1657
1658The interface to the store monad provided by @code{(guix monads)} is as
1659follows.
1660
1661@defvr {Scheme Variable} %store-monad
1662The store monad. Values in the store monad encapsulate accesses to the
1663store. When its effect is needed, a value of the store monad must be
1664``evaluated'' by passing it to the @code{run-with-store} procedure (see
1665below.)
1666@end defvr
1667
1668@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
1669Run @var{mval}, a monadic value in the store monad, in @var{store}, an
1670open store connection.
1671@end deffn
1672
1673@deffn {Monadic Procedure} text-file @var{name} @var{text}
1674Return as a monadic value the absolute file name in the store of the file
1675containing @var{text}.
1676@end deffn
1677
1678@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
1679 [#:system (%current-system)] [#:output "out"] Return as a monadic
1680value in the absolute file name of @var{file} within the @var{output}
1681directory of @var{package}. When @var{file} is omitted, return the name
1682of the @var{output} directory of @var{package}.
1683@end deffn
1684
dd1a5a15
LC
1685@deffn {Monadic Procedure} derivation-expression @var{name} @var{exp} @
1686 [#:system (%current-system)] [#:inputs '()] @
1687 [#:outputs '("out")] [#:hash #f] @
b860f382
LC
1688 [#:hash-algo #f] [#:env-vars '()] [#:modules '()] @
1689 [#:references-graphs #f] [#:guile-for-build #f]
1690Monadic version of @code{build-expression->derivation}
1691(@pxref{Derivations}).
1692@end deffn
1693
1694@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
1695Monadic version of @code{package-derivation} (@pxref{Defining
1696Packages}).
1697@end deffn
1698
1699
568717fd
LC
1700@c *********************************************************************
1701@node Utilities
1702@chapter Utilities
1703
210cc920
LC
1704This section describes tools primarily targeted at developers and users
1705who write new package definitions. They complement the Scheme
1706programming interface of Guix in a convenient way.
1707
568717fd 1708@menu
37166310 1709* Invoking guix build:: Building packages from the command line.
210cc920 1710* Invoking guix download:: Downloading a file and printing its hash.
37166310
LC
1711* Invoking guix hash:: Computing the cryptographic hash of a file.
1712* Invoking guix refresh:: Updating package definitions.
568717fd
LC
1713@end menu
1714
e49951eb
MW
1715@node Invoking guix build
1716@section Invoking @command{guix build}
568717fd 1717
e49951eb 1718The @command{guix build} command builds packages or derivations and
6798a8e4
LC
1719their dependencies, and prints the resulting store paths. Note that it
1720does not modify the user's profile---this is the job of the
e49951eb 1721@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
1722it is mainly useful for distribution developers.
1723
1724The general syntax is:
c78bd12b
LC
1725
1726@example
e49951eb 1727guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
1728@end example
1729
1730@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
1731the software distribution such as @code{coreutils} or
1732@code{coreutils-8.20}, or a derivation such as
1733@file{/nix/store/@dots{}-coreutils-8.19.drv}. Alternatively, the
c78bd12b
LC
1734@code{--expression} option may be used to specify a Scheme expression
1735that evaluates to a package; this is useful when disambiguation among
1736several same-named packages or package variants is needed.
1737
1738The @var{options} may be zero or more of the following:
1739
1740@table @code
1741
1742@item --expression=@var{expr}
1743@itemx -e @var{expr}
ac5de156 1744Build the package or derivation @var{expr} evaluates to.
c78bd12b 1745
5401dd75 1746For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
1747guile-1.8)}, which unambiguously designates this specific variant of
1748version 1.8 of Guile.
1749
ac5de156
LC
1750Alternately, @var{expr} may refer to a zero-argument monadic procedure
1751(@pxref{The Store Monad}). The procedure must return a derivation as a
1752monadic value, which is then passed through @code{run-with-store}.
1753
c78bd12b
LC
1754@item --source
1755@itemx -S
1756Build the packages' source derivations, rather than the packages
1757themselves.
1758
e49951eb 1759For instance, @code{guix build -S gcc} returns something like
6798a8e4 1760@file{/nix/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 1761
f9cc8971
LC
1762The returned source tarball is the result of applying any patches and
1763code snippets specified in the package's @code{origin} (@pxref{Defining
1764Packages}).
1765
c78bd12b
LC
1766@item --system=@var{system}
1767@itemx -s @var{system}
1768Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
1769the host's system type.
1770
1771An example use of this is on Linux-based systems, which can emulate
1772different personalities. For instance, passing
1773@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
1774to build packages in a complete 32-bit environment.
1775
e55ec43d
LC
1776@item --target=@var{triplet}
1777@cindex cross-compilation
1778Cross-build for @var{triplet}, which must be a valid GNU triplet, such
1779as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
1780configuration triplets,, configure, GNU Configure and Build System}).
1781
c78bd12b
LC
1782@item --derivations
1783@itemx -d
1784Return the derivation paths, not the output paths, of the given
1785packages.
1786
1787@item --keep-failed
1788@itemx -K
1789Keep the build tree of failed builds. Thus, if a build fail, its build
1790tree is kept under @file{/tmp}, in a directory whose name is shown at
1791the end of the build log. This is useful when debugging build issues.
1792
1793@item --dry-run
1794@itemx -n
1795Do not build the derivations.
1796
56b1f4b7
LC
1797@item --fallback
1798When substituting a pre-built binary fails, fall back to building
1799packages locally.
1800
c78bd12b 1801@item --no-substitutes
b5385b52
LC
1802Do not use substitutes for build products. That is, always build things
1803locally instead of allowing downloads of pre-built binaries.
c78bd12b 1804
425b0bfc 1805@item --no-build-hook
4ec2e92d
LC
1806Do not attempt to offload builds @i{via} the daemon's ``build hook''
1807(@pxref{Daemon Offload Setup}). That is, always build things locally
1808instead of offloading builds to remote machines.
425b0bfc 1809
969e678e
LC
1810@item --max-silent-time=@var{seconds}
1811When the build or substitution process remains silent for more than
1812@var{seconds}, terminate it and report a build failure.
1813
c78bd12b
LC
1814@item --cores=@var{n}
1815@itemx -c @var{n}
1816Allow the use of up to @var{n} CPU cores for the build. The special
1817value @code{0} means to use as many CPU cores as available.
1818
1819@item --root=@var{file}
1820@itemx -r @var{file}
1821Make @var{file} a symlink to the result, and register it as a garbage
1822collector root.
07ab4bf1
LC
1823
1824@item --verbosity=@var{level}
1825Use the given verbosity level. @var{level} must be an integer between 0
1826and 5; higher means more verbose output. Setting a level of 4 or more
1827may be helpful when debugging setup issues with the build daemon.
1828
bf421152
LC
1829@item --log-file
1830Return the build log file names for the given
1831@var{package-or-derivation}s, or raise an error if build logs are
1832missing.
1833
1834This works regardless of how packages or derivations are specified. For
1835instance, the following invocations are equivalent:
1836
1837@example
1838guix build --log-file `guix build -d guile`
1839guix build --log-file `guix build guile`
1840guix build --log-file guile
1841guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
1842@end example
1843
1844
c78bd12b
LC
1845@end table
1846
e49951eb 1847Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
1848the @code{package-derivation} procedure of the @code{(guix packages)}
1849module, and to the @code{build-derivations} procedure of the @code{(guix
1850store)} module.
1851
210cc920
LC
1852@node Invoking guix download
1853@section Invoking @command{guix download}
1854
1855When writing a package definition, developers typically need to download
1856the package's source tarball, compute its SHA256 hash, and write that
1857hash in the package definition (@pxref{Defining Packages}). The
1858@command{guix download} tool helps with this task: it downloads a file
1859from the given URI, adds it to the store, and prints both its file name
1860in the store and its SHA256 hash.
1861
1862The fact that the downloaded file is added to the store saves bandwidth:
1863when the developer eventually tries to build the newly defined package
1864with @command{guix build}, the source tarball will not have to be
1865downloaded again because it is already in the store. It is also a
1866convenient way to temporarily stash files, which may be deleted
1867eventually (@pxref{Invoking guix gc}).
1868
1869The @command{guix download} command supports the same URIs as used in
1870package definitions. In particular, it supports @code{mirror://} URIs.
1871@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
1872Guile bindings for GnuTLS are available in the user's environment; when
1873they are not available, an error is raised.
1874
1875The following option is available:
1876
1877@table @code
1878@item --format=@var{fmt}
1879@itemx -f @var{fmt}
1880Write the hash in the format specified by @var{fmt}. For more
1881information on the valid values for @var{fmt}, @ref{Invoking guix hash}.
1882@end table
1883
6c365eca
NK
1884@node Invoking guix hash
1885@section Invoking @command{guix hash}
1886
210cc920 1887The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
1888It is primarily a convenience tool for anyone contributing to the
1889distribution: it computes the cryptographic hash of a file, which can be
1890used in the definition of a package (@pxref{Defining Packages}).
1891
1892The general syntax is:
1893
1894@example
1895guix hash @var{option} @var{file}
1896@end example
1897
1898@command{guix hash} has the following option:
1899
1900@table @code
1901
1902@item --format=@var{fmt}
1903@itemx -f @var{fmt}
210cc920 1904Write the hash in the format specified by @var{fmt}.
6c365eca
NK
1905
1906Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
1907(@code{hex} and @code{hexadecimal} can be used as well).
1908
1909If the @option{--format} option is not specified, @command{guix hash}
1910will output the hash in @code{nix-base32}. This representation is used
1911in the definitions of packages.
1912
1913@end table
1914
37166310
LC
1915@node Invoking guix refresh
1916@section Invoking @command{guix refresh}
1917
1918The primary audience of the @command{guix refresh} command is developers
1919of the GNU software distribution. By default, it reports any packages
1920provided by the distribution that are outdated compared to the latest
1921upstream version, like this:
1922
1923@example
1924$ guix refresh
1925gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
1926gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
1927@end example
1928
1929It does so by browsing each package's FTP directory and determining the
1930highest version number of the source tarballs
1931therein@footnote{Currently, this only works for GNU packages.}.
1932
1933When passed @code{--update}, it modifies distribution source files to
1934update the version numbers and source tarball hashes of those packages'
1935recipes (@pxref{Defining Packages}). This is achieved by downloading
1936each package's latest source tarball and its associated OpenPGP
1937signature, authenticating the downloaded tarball against its signature
1938using @command{gpg}, and finally computing its hash. When the public
1939key used to sign the tarball is missing from the user's keyring, an
1940attempt is made to automatically retrieve it from a public key server;
1941when it's successful, the key is added to the user's keyring; otherwise,
1942@command{guix refresh} reports an error.
1943
1944The following options are supported:
1945
1946@table @code
1947
1948@item --update
1949@itemx -u
1950Update distribution source files (package recipes) in place.
1951@ref{Defining Packages}, for more information on package definitions.
1952
1953@item --select=[@var{subset}]
1954@itemx -s @var{subset}
1955Select all the packages in @var{subset}, one of @code{core} or
1956@code{non-core}.
1957
1958The @code{core} subset refers to all the packages at the core of the
1959distribution---i.e., packages that are used to build ``everything
1960else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
1961changing one of these packages in the distribution entails a rebuild of
1962all the others. Thus, such updates are an inconvenience to users in
1963terms of build time or bandwidth used to achieve the upgrade.
1964
1965The @code{non-core} subset refers to the remaining packages. It is
1966typically useful in cases where an update of the core packages would be
1967inconvenient.
1968
1969@end table
1970
1971In addition, @command{guix refresh} can be passed one or more package
1972names, as in this example:
1973
1974@example
1975guix refresh -u emacs idutils
1976@end example
1977
1978@noindent
1979The command above specifically updates the @code{emacs} and
1980@code{idutils} packages. The @code{--select} option would have no
1981effect in this case.
1982
f9230085
LC
1983The following options can be used to customize GnuPG operation:
1984
1985@table @code
1986
1987@item --key-server=@var{host}
1988Use @var{host} as the OpenPGP key server when importing a public key.
1989
1990@item --gpg=@var{command}
1991Use @var{command} as the GnuPG 2.x command. @var{command} is searched
1992for in @code{$PATH}.
1993
1994@end table
1995
37166310 1996
a1ba8475
LC
1997@c *********************************************************************
1998@node GNU Distribution
1999@chapter GNU Distribution
2000
2001Guix comes with a distribution of free software@footnote{The term
2002``free'' here refers to the
2003@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
c320011d 2004users of that software}.} that forms the basis of the GNU system. This
a1ba8475
LC
2005includes core GNU packages such as GNU libc, GCC, and Binutils, as well
2006as many GNU and non-GNU applications. The complete list of available
d03bb653
LC
2007packages can be browsed
2008@url{http://www.gnu.org/software/guix/package-list.html,on-line} or by
2009running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
2010
2011@example
e49951eb 2012guix package --list-available
a1ba8475
LC
2013@end example
2014
401c53c4
LC
2015Our goal is to build a practical 100% free software distribution of
2016Linux-based and other variants of GNU, with a focus on the promotion and
2017tight integration of GNU components, and an emphasis on programs and
2018tools that help users exert that freedom.
2019
c320011d
LC
2020The GNU distribution is currently available on the following platforms:
2021
2022@table @code
2023
2024@item x86_64-linux
2025Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
2026
2027@item i686-linux
2028Intel 32-bit architecture (IA32), Linux-Libre kernel;
2029
2030@item mips64el-linux
2031little-endian 64-bit MIPS processors, specifically the Loongson series,
2032n32 application binary interface (ABI), and Linux-Libre kernel.
2033
2034@end table
2035
2036@noindent
2037For information on porting to other architectures or kernels,
2038@xref{Porting}.
2039
401c53c4 2040@menu
91ef73d4 2041* Installing Debugging Files:: Feeding the debugger.
401c53c4 2042* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 2043* Packaging Guidelines:: Growing the distribution.
401c53c4 2044* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 2045* Porting:: Targeting another platform or kernel.
4af2447e 2046* System Configuration:: Configuring a GNU system.
401c53c4
LC
2047@end menu
2048
2049Building this distribution is a cooperative effort, and you are invited
2050to join! @ref{Contributing}, for information about how you can help.
2051
b208a005 2052
91ef73d4
LC
2053@node Installing Debugging Files
2054@section Installing Debugging Files
2055
2056Program binaries, as produced by the GCC compilers for instance, are
2057typically written in the ELF format, with a section containing
2058@dfn{debugging information}. Debugging information is what allows the
2059debugger, GDB, to map binary code to source code; it is required to
2060debug a compiled program in good conditions.
2061
2062The problem with debugging information is that is takes up a fair amount
2063of disk space. For example, debugging information for the GNU C Library
2064weighs in at more than 60 MiB. Thus, as a user, keeping all the
2065debugging info of all the installed programs is usually not an option.
2066Yet, space savings should not come at the cost of an impediment to
2067debugging---especially in the GNU system, which should make it easier
2068for users to exert their computing freedom (@pxref{GNU Distribution}).
2069
2070Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
2071mechanism that allows users to get the best of both worlds: debugging
2072information can be stripped from the binaries and stored in separate
2073files. GDB is then able to load debugging information from those files,
2074when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
2075with GDB}).
2076
2077The GNU distribution takes advantage of this by storing debugging
2078information in the @code{lib/debug} sub-directory of a separate package
2079output unimaginatively called @code{debug} (@pxref{Packages with
2080Multiple Outputs}). Users can choose to install the @code{debug} output
2081of a package when they need it. For instance, the following command
2082installs the debugging information for the GNU C Library and for GNU
2083Guile:
2084
2085@example
2086guix package -i glibc:debug -i guile:debug
2087@end example
2088
2089GDB must then be told to look for debug files in the user's profile, by
2090setting the @code{debug-file-directory} variable (consider setting it
2091from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
2092GDB}):
2093
2094@example
2095(gdb) set debug-file-directory ~/.guix-profile/lib/debug
2096@end example
2097
2098From there on, GDB will pick up debugging information from the
2099@code{.debug} files under @file{~/.guix-profile/lib/debug}.
2100
2101@c XXX: keep me up-to-date
2102The @code{debug} output mechanism in Guix is implemented by the
2103@code{gnu-build-system} (@pxref{Defining Packages}). Currently, it is
2104opt-in---debugging information is available only for those packages
2105whose definition explicitly declares a @code{debug} output. This may be
2106changed to opt-out in the future, if our build farm servers can handle
2107the load. To check whether a package has a @code{debug} output, use
2108@command{guix package --list-available} (@pxref{Invoking guix package}).
2109
2110
401c53c4
LC
2111@node Package Modules
2112@section Package Modules
2113
2114From a programming viewpoint, the package definitions of the
2115distribution are provided by Guile modules in the @code{(gnu packages
7e17f65d
LC
2116@dots{})} name space@footnote{Note that packages under the @code{(gnu
2117packages @dots{})} module name space are not necessarily ``GNU
2118packages''. This module naming scheme follows the usual Guile module
2119naming convention: @code{gnu} means that these modules are distributed
2120as part of the GNU system, and @code{packages} identifies modules that
2121define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
b81e1947
LC
2122Reference Manual}). For instance, the @code{(gnu packages emacs)}
2123module exports a variable named @code{emacs}, which is bound to a
401c53c4
LC
2124@code{<package>} object (@pxref{Defining Packages}). The @code{(gnu
2125packages)} module provides facilities for searching for packages.
a1ba8475
LC
2126
2127The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
2128each package is built based solely on other packages in the
2129distribution. The root of this dependency graph is a small set of
2130@dfn{bootstrap binaries}, provided by the @code{(gnu packages
b81e1947
LC
2131bootstrap)} module. For more information on bootstrapping,
2132@ref{Bootstrapping}.
2133
da7cabd4
AE
2134@node Packaging Guidelines
2135@section Packaging Guidelines
b81e1947
LC
2136
2137The GNU distribution is nascent and may well lack some of your favorite
2138packages. This section describes how you can help make the distribution
c8c871d1 2139grow. @xref{Contributing}, for additional information on how you can
b81e1947
LC
2140help.
2141
b81e1947
LC
2142Free software packages are usually distributed in the form of
2143@dfn{source code tarballs}---typically @file{tar.gz} files that contain
2144all the source files. Adding a package to the distribution means
2145essentially two things: adding a @dfn{recipe} that describes how to
2146build the package, including a list of other packages required to build
2147it, and adding @dfn{package meta-data} along with that recipe, such as a
2148description and licensing information.
2149
2150In Guix all this information is embodied in @dfn{package definitions}.
2151Package definitions provide a high-level view of the package. They are
2152written using the syntax of the Scheme programming language; in fact,
2153for each package we define a variable bound to the package definition,
2154and export that variable from a module (@pxref{Package Modules}).
2155However, in-depth Scheme knowledge is @emph{not} a prerequisite for
2156creating packages. For more information on package definitions,
2157@ref{Defining Packages}.
2158
2159Once a package definition is in place, stored in a file in the Guix
2160source tree, it can be tested using the @command{guix build} command
2161(@pxref{Invoking guix build}). For example, assuming the new package is
2162called @code{gnew}, you may run this command from the Guix build tree:
2163
2164@example
2165./pre-inst-env guix build gnew --keep-failed
2166@end example
2167
2168Using @code{--keep-failed} makes it easier to debug build failures since
2169it provides access to the failed build tree.
2170
2171Once your package builds correctly, please send us a patch
2172(@pxref{Contributing}). Well, if you need help, we will be happy to
2173help you too. Once the patch is committed in the Guix repository, the
2174new package automatically gets built on the supported platforms by
2175@url{http://hydra.gnu.org/gnu/master, our continuous integration
2176system}.
2177
2178@cindex substituter
2179Users can obtain the new package definition simply by running
2180@command{guix pull} (@pxref{Invoking guix pull}). When
2181@code{hydra.gnu.org} is done building the package, installing the
2182package automatically downloads binaries from there (except when using
2183@code{--no-substitutes}). The only place where human intervention is
2184needed is to review and apply the patch.
401c53c4
LC
2185
2186
da7cabd4 2187@menu
ee85f3db
AE
2188* Software Freedom:: What may go into the distribution.
2189* Package Naming:: What's in a name?
2190* Version Numbers:: When the name is not enough.
2191* Python Modules:: Taming the snake.
da7cabd4
AE
2192@end menu
2193
2194@node Software Freedom
2195@subsection Software Freedom
2196
2197@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
2198
2199The GNU operating system has been developed so that users can have
2200freedom in their computing. GNU is @dfn{free software}, meaning that
2201users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
2202essential freedoms}: to run the program, to study and change the program
2203in source code form, to redistribute exact copies, and to distribute
2204modified versions. Packages found in the GNU distribution provide only
2205software that conveys these four freedoms.
2206
2207In addition, the GNU distribution follow the
2208@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
2209software distribution guidelines}. Among other things, these guidelines
2210reject non-free firmware, recommendations of non-free software, and
2211discuss ways to deal with trademarks and patents.
2212
f9cc8971
LC
2213Some packages contain a small and optional subset that violates the
2214above guidelines, for instance because this subset is itself non-free
2215code. When that happens, the offending items are removed with
2216appropriate patches or code snippets in the package definition's
2217@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
2218build --source} returns the ``freed'' source rather than the unmodified
2219upstream source.
2220
da7cabd4 2221
ee85f3db
AE
2222@node Package Naming
2223@subsection Package Naming
2224
c8c871d1 2225A package has actually two names associated with it:
ee85f3db 2226First, there is the name of the @emph{Scheme variable}, the one following
c8c871d1
AE
2227@code{define-public}. By this name, the package can be made known in the
2228Scheme code, for instance as input to another package. Second, there is
2229the string in the @code{name} field of a package definition. This name
2230is used by package management commands such as
2231@command{guix package} and @command{guix build}.
ee85f3db
AE
2232
2233Both are usually the same and correspond to the lowercase conversion of the
c8c871d1
AE
2234project name chosen upstream. For instance, the GNUnet project is packaged
2235as @code{gnunet}. We do not add @code{lib} prefixes for library packages,
2236unless these are already part of the official project name. But see
2237@ref{Python Modules} for special rules concerning modules for
ee85f3db
AE
2238the Python language.
2239
2240
2241@node Version Numbers
2242@subsection Version Numbers
2243
2244We usually package only the latest version of a given free software
c8c871d1
AE
2245project. But sometimes, for instance for incompatible library versions,
2246two (or more) versions of the same package are needed. These require
2247different Scheme variable names. We use the name as defined
2248in @ref{Package Naming}
ee85f3db
AE
2249for the most recent version; previous versions use the same name, suffixed
2250by @code{-} and the smallest prefix of the version number that may
2251distinguish the two versions.
2252
2253The name inside the package definition is the same for all versions of a
2254package and does not contain any version number.
2255
2256For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
c8c871d1 2257
ee85f3db
AE
2258@example
2259(define-public gtk+
2260 (package
2261 (name "gtk+")
2262 (version "3.9.12")
2263 ...))
2264(define-public gtk+-2
2265 (package
2266 (name "gtk+")
2267 (version "2.24.20")
2268 ...))
2269@end example
2270If we also wanted GTK+ 3.8.2, this would be packaged as
2271@example
2272(define-public gtk+-3.8
2273 (package
2274 (name "gtk+")
2275 (version "3.8.2")
2276 ...))
2277@end example
2278
2279
2280@node Python Modules
2281@subsection Python Modules
2282
2283We currently package Python 2 and Python 3, under the Scheme variable names
2284@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
2285To avoid confusion and naming clashes with other programming languages, it
2286seems desirable that the name of a package for a Python module contains
2287the word @code{python}.
c8c871d1 2288
ee85f3db
AE
2289Some modules are compatible with only one version of Python, others with both.
2290If the package Foo compiles only with Python 3, we name it
2291@code{python-foo}; if it compiles only with Python 2, we name it
2292@code{python2-foo}. If it is compatible with both versions, we create two
2293packages with the corresponding names.
2294
2295If a project already contains the word @code{python}, we drop this;
2296for instance, the module python-dateutil is packaged under the names
2297@code{python-dateutil} and @code{python2-dateutil}.
2298
2299
2300
2301
2302
401c53c4
LC
2303@node Bootstrapping
2304@section Bootstrapping
2305
2306@c Adapted from the ELS 2013 paper.
2307
2308@cindex bootstrapping
2309
2310Bootstrapping in our context refers to how the distribution gets built
2311``from nothing''. Remember that the build environment of a derivation
2312contains nothing but its declared inputs (@pxref{Introduction}). So
2313there's an obvious chicken-and-egg problem: how does the first package
2314get built? How does the first compiler get compiled? Note that this is
2315a question of interest only to the curious hacker, not to the regular
2316user, so you can shamelessly skip this section if you consider yourself
2317a ``regular user''.
2318
2319@cindex bootstrap binaries
2320The GNU system is primarily made of C code, with libc at its core. The
2321GNU build system itself assumes the availability of a Bourne shell and
2322command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
2323`grep'. Furthermore, build programs---programs that run
2324@code{./configure}, @code{make}, etc.---are written in Guile Scheme
2325(@pxref{Derivations}). Consequently, to be able to build anything at
2326all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
2327Binutils, libc, and the other packages mentioned above---the
2328@dfn{bootstrap binaries}.
2329
2330These bootstrap binaries are ``taken for granted'', though we can also
ba7ea5ce 2331re-create them if needed (more on that later).
401c53c4
LC
2332
2333@unnumberedsubsec Preparing to Use the Bootstrap Binaries
2334
2335@c As of Emacs 24.3, Info-mode displays the image, but since it's a
2336@c large image, it's hard to scroll. Oh well.
29f66ddd 2337@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
401c53c4
LC
2338
2339The figure above shows the very beginning of the dependency graph of the
2340distribution, corresponding to the package definitions of the @code{(gnu
2341packages bootstrap)} module. At this level of detail, things are
2342slightly complex. First, Guile itself consists of an ELF executable,
2343along with many source and compiled Scheme files that are dynamically
2344loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
2345tarball shown in this graph. This tarball is part of Guix's ``source''
2346distribution, and gets inserted into the store with @code{add-to-store}
2347(@pxref{The Store}).
a1ba8475 2348
401c53c4
LC
2349But how do we write a derivation that unpacks this tarball and adds it
2350to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
2351derivation---the first one that gets built---uses @code{bash} as its
2352builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
2353@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
2354@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
2355the Guix source distribution, whose sole purpose is to allow the Guile
2356tarball to be unpacked.
2357
2358Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
2359Guile that can be used to run subsequent build programs. Its first task
2360is to download tarballs containing the other pre-built binaries---this
2361is what the @code{.tar.xz.drv} derivations do. Guix modules such as
2362@code{ftp-client.scm} are used for this purpose. The
2363@code{module-import.drv} derivations import those modules in a directory
2364in the store, using the original layout. The
2365@code{module-import-compiled.drv} derivations compile those modules, and
2366write them in an output directory with the right layout. This
2367corresponds to the @code{#:modules} argument of
2368@code{build-expression->derivation} (@pxref{Derivations}).
2369
2370Finally, the various tarballs are unpacked by the
2371derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
2372etc., at which point we have a working C tool chain.
2373
2374
2375@unnumberedsubsec Building the Build Tools
2376
2377@c TODO: Add a package-level dependency graph generated from (gnu
2378@c packages base).
2379
2380Bootstrapping is complete when we have a full tool chain that does not
2381depend on the pre-built bootstrap tools discussed above. This
2382no-dependency requirement is verified by checking whether the files of
2383the final tool chain contain references to the @file{/nix/store}
2384directories of the bootstrap inputs. The process that leads to this
2385``final'' tool chain is described by the package definitions found in
2386the @code{(gnu packages base)} module.
2387
2388@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
2389The first tool that gets built with the bootstrap binaries is
2390GNU Make, which is a prerequisite for all the following packages.
2391From there Findutils and Diffutils get built.
2392
2393Then come the first-stage Binutils and GCC, built as pseudo cross
2394tools---i.e., with @code{--target} equal to @code{--host}. They are
2395used to build libc. Thanks to this cross-build trick, this libc is
2396guaranteed not to hold any reference to the initial tool chain.
2397
2398From there the final Binutils and GCC are built. GCC uses @code{ld}
2399from the final Binutils, and links programs against the just-built libc.
2400This tool chain is used to build the other packages used by Guix and by
2401the GNU Build System: Guile, Bash, Coreutils, etc.
2402
2403And voilà! At this point we have the complete set of build tools that
2404the GNU Build System expects. These are in the @code{%final-inputs}
2405variables of the @code{(gnu packages base)} module, and are implicitly
2406used by any package that uses @code{gnu-build-system} (@pxref{Defining
2407Packages}).
2408
2409
2410@unnumberedsubsec Building the Bootstrap Binaries
2411
2412Because the final tool chain does not depend on the bootstrap binaries,
2413those rarely need to be updated. Nevertheless, it is useful to have an
2414automated way to produce them, should an update occur, and this is what
2415the @code{(gnu packages make-bootstrap)} module provides.
2416
2417The following command builds the tarballs containing the bootstrap
2418binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
2419of Coreutils and other basic command-line tools):
a1ba8475 2420
401c53c4
LC
2421@example
2422guix build bootstrap-tarballs
2423@end example
2424
2425The generated tarballs are those that should be referred to in the
2426@code{(gnu packages bootstrap)} module mentioned at the beginning of
2427this section.
2428
2429Still here? Then perhaps by now you've started to wonder: when do we
2430reach a fixed point? That is an interesting question! The answer is
2431unknown, but if you would like to investigate further (and have
2432significant computational and storage resources to do so), then let us
2433know.
a1ba8475 2434
8b315a6d
LC
2435@node Porting
2436@section Porting to a New Platform
2437
2438As discussed above, the GNU distribution is self-contained, and
2439self-containment is achieved by relying on pre-built ``bootstrap
2440binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
2441operating system kernel, CPU architecture, and application binary
2442interface (ABI). Thus, to port the distribution to a platform that is
2443not yet supported, one must build those bootstrap binaries, and update
2444the @code{(gnu packages bootstrap)} module to use them on that platform.
2445
2446Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
2447When everything goes well, and assuming the GNU tool chain supports the
2448target platform, this can be as simple as running a command like this
2449one:
2450
2451@example
2452guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
2453@end example
2454
72e25e35
LC
2455Once these are built, the @code{(gnu packages bootstrap)} module needs
2456to be updated to refer to these binaries on the target platform. In
2457addition, the @code{glibc-dynamic-linker} procedure in that module must
2458be augmented to return the right file name for libc's dynamic linker on
2459that platform; likewise, @code{system->linux-architecture} in @code{(gnu
2460packages linux)} must be taught about the new platform.
2461
8b315a6d
LC
2462In practice, there may be some complications. First, it may be that the
2463extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
2464above) is not recognized by all the GNU tools. Typically, glibc
2465recognizes some of these, whereas GCC uses an extra @code{--with-abi}
ba7ea5ce 2466configure flag (see @code{gcc.scm} for examples of how to handle this).
8b315a6d
LC
2467Second, some of the required packages could fail to build for that
2468platform. Lastly, the generated binaries could be broken for some
2469reason.
2470
9bf3c1a7 2471
4af2447e
LC
2472@node System Configuration
2473@section System Configuration
2474
2475@emph{This section documents work-in-progress. As such it may be
2476incomplete, outdated, or open to discussions. Please discuss it on
2477@email{guix-devel@@gnu.org}.}
2478
2479@cindex system configuration
2480The GNU system supports a consistent whole-system configuration
2481mechanism. By that we mean that all aspects of the global system
2482configuration---such as the available system services, timezone and
68ad877c 2483locale settings, user accounts---are declared in a single place. Such
4af2447e
LC
2484a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
2485
68ad877c
LC
2486One of the advantages of putting all the system configuration under the
2487control of Guix is that it supports transactional system upgrades, and
2488makes it possible to roll-back to a previous system instantiation,
2489should something go wrong with the new one (@pxref{Features}). Another
2490one is that it makes it easy to replicate the exact same configuration
2491across different machines, or at different points in time, without
2492having to resort to additional administration tools layered on top of
2493the system's own tools.
2494@c Yes, we're talking of Puppet, Chef, & co. here. ↑
2495
4af2447e
LC
2496This section describes this mechanism. First we focus on the system
2497administrator's viewpoint---explaining how the system is configured and
2498instantiated. Then we show how this mechanism can be extended, for
2499instance to support new system services.
2500
2501@menu
2502* Using the Configuration System:: Customizing your GNU system.
2503* Defining Services:: Adding new service definitions.
2504@end menu
2505
2506@node Using the Configuration System
2507@subsection Using the Configuration System
2508
2509The operating system is configured by filling in an
2510@code{operating-system} structure, as defined by the @code{(gnu system)}
2511module. A simple setup, with the default system services, the default
2512Linux-Libre kernel, initial RAM disk, and boot loader looks like this:
2513
2514@findex operating-system
2515@lisp
2516(use-modules (gnu system)
2517 (gnu system shadow) ; for 'user-account'
2518 (gnu system service) ; for 'lsh-service'
2519 (gnu packages base) ; Coreutils, grep, etc.
2520 (gnu packages bash) ; Bash
4eaad71d 2521 (gnu packages admin) ; dmd, Inetutils
4af2447e
LC
2522 (gnu packages zile) ; Zile
2523 (gnu packages less) ; less
2524 (gnu packages guile) ; Guile
2525 (gnu packages linux)) ; procps, psmisc
2526
68ad877c 2527(define komputilo
4af2447e
LC
2528 (operating-system
2529 (host-name "komputilo")
2530 (timezone "Europe/Paris")
2531 (locale "fr_FR.UTF-8")
2532 (users (list (user-account
2533 (name "alice")
2534 (password "")
2535 (uid 1000) (gid 100)
2536 (comment "Bob's sister")
2537 (home-directory "/home/alice"))))
2538 (packages (list coreutils bash guile-2.0
2539 guix dmd
2540 inetutils
2541 findutils grep sed
2542 procps psmisc
2543 zile less))
2544 (services (cons (lsh-service #:port 2222 #:allow-root-login? #t)
2545 %standard-services))))
2546@end lisp
2547
2548This example should be self-describing. The @code{packages} field lists
68ad877c
LC
2549packages provided by the various @code{(gnu packages ...)} modules above
2550(@pxref{Package Modules}). These are the packages that will be globally
2551visible on the system, for all user accounts---i.e., in every user's
2552@code{PATH} environment variable---in addition to the per-user profiles
2553(@pxref{Invoking guix package}).
4af2447e
LC
2554
2555The @code{services} field lists @dfn{system services} to be made
2556available when the system starts. The @var{%standard-services} list,
2557from the @code{(gnu system)} module, provides the basic services one
2558would expect from a GNU system: a login service (mingetty) on each tty,
2559syslogd, libc's name service cache daemon (nscd), etc.
2560
2561The @code{operating-system} declaration above specifies that, in
2562addition to those services, we want the @command{lshd} secure shell
2563daemon listening on port 2222, and allowing remote @code{root} logins
2564(@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
2565@code{lsh-service} arranges so that @code{lshd} is started with the
2566right command-line options, possibly with supporting configuration files
2567generated as needed (@pxref{Defining Services}).
2568
2569@c TODO: update when that command exists
2570Assuming the above snippet is stored in the @file{my-system-config.scm}
2571file, the (yet unwritten!) @command{guix system --boot
2572my-system-config.scm} command instantiates that configuration, and makes
2573it the default GRUB boot entry. The normal way to change the system's
2574configuration is by updating this file and re-running the @command{guix
2575system} command.
2576
2577At the Scheme level, the bulk of an @code{operating-system} declaration
2578is instantiated with the following monadic procedure (@pxref{The Store
2579Monad}):
2580
2581@deffn {Monadic Procedure} operating-system-derivation os
2582Return a derivation that builds @var{os}, an @code{operating-system}
2583object (@pxref{Derivations}).
2584
2585The output of the derivation is a single directory that refers to all
2586the packages, configuration files, and other supporting files needed to
2587instantiate @var{os}.
2588@end deffn
2589
4af2447e
LC
2590
2591@node Defining Services
2592@subsection Defining Services
2593
2594The @code{(gnu system dmd)} module defines several procedures that allow
2595users to declare the operating system's services (@pxref{Using the
2596Configuration System}). These procedures are @emph{monadic
2597procedures}---i.e., procedures that return a monadic value in the store
2598monad (@pxref{The Store Monad}). Examples of such procedures include:
2599
2600@table @code
2601@item mingetty-service
2602return the definition of a service that runs @command{mingetty} to
2603offer a login service on the given console tty;
2604
2605@item nscd-service
2606return a definition for libc's name service cache daemon (nscd);
2607
2608@item guix-service
2609return a definition for a service that runs @command{guix-daemon}
2610(@pxref{Invoking guix-daemon}).
2611@end table
2612
2613@cindex service definition
2614The monadic value returned by those procedures is a @dfn{service
2615definition}---a structure as returned by the @code{service} form.
2616Service definitions specifies the inputs the service depends on, and an
2617expression to start and stop the service. Behind the scenes, service
2618definitions are ``translated'' into the form suitable for the
2619configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU
2620dmd Manual}).
2621
2622As an example, here is what the @code{nscd-service} procedure looks
2623like:
2624
2625@lisp
2626(define (nscd-service)
2627 (mlet %store-monad ((nscd (package-file glibc "sbin/nscd")))
2628 (return (service
2629 (documentation "Run libc's name service cache daemon.")
2630 (provision '(nscd))
2631 (start `(make-forkexec-constructor ,nscd "-f" "/dev/null"
2632 "--foreground"))
2633 (stop `(make-kill-destructor))
2634
2635 (respawn? #f)
2636 (inputs `(("glibc" ,glibc)))))))
2637@end lisp
2638
2639@noindent
2640The @code{inputs} field specifies that this service depends on the
2641@var{glibc} package---the package that contains the @command{nscd}
2642program. The @code{start} and @code{stop} fields are expressions that
2643make use of dmd's facilities to start and stop processes (@pxref{Service
2644De- and Constructors,,, dmd, GNU dmd Manual}). The @code{provision}
2645field specifies the name under which this service is known to dmd, and
2646@code{documentation} specifies on-line documentation. Thus, the
2647commands @command{deco start ncsd}, @command{deco stop nscd}, and
2648@command{deco doc nscd} will do what you would expect (@pxref{Invoking
2649deco,,, dmd, GNU dmd Manual}).
2650
2651
9bf3c1a7
LC
2652@c *********************************************************************
2653@node Contributing
2654@chapter Contributing
2655
2656This project is a cooperative effort, and we need your help to make it
63f6004b 2657grow! Please get in touch with us on @email{guix-devel@@gnu.org}. We
a1ba8475 2658welcome ideas, bug reports, patches, and anything that may be helpful to
da7cabd4
AE
2659the project. We particularly welcome help on packaging
2660(@pxref{Packaging Guidelines}).
a1ba8475 2661
9bf3c1a7
LC
2662Please see the
2663@url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING,
2664@file{HACKING} file} that comes with the Guix source code for practical
2665details about contributions.
2666
c78bd12b 2667
568717fd
LC
2668@c *********************************************************************
2669@node Acknowledgments
2670@chapter Acknowledgments
2671
2672Guix is based on the Nix package manager, which was designed and
2673implemented by Eelco Dolstra. Nix pioneered functional package
2674management, and promoted unprecedented features, such as transactional
2675package upgrades and rollbacks, per-user profiles, and referentially
2676transparent build processes. Without this work, Guix would not exist.
2677
2678The Nix-based software distributions, Nixpkgs and NixOS, have also been
2679an inspiration for Guix.
2680
2681@c *********************************************************************
2682@node GNU Free Documentation License
2683@appendix GNU Free Documentation License
2684
2685@include fdl-1.3.texi
2686
2687@c *********************************************************************
2688@node Concept Index
2689@unnumbered Concept Index
2690@printindex cp
2691
2692@node Function Index
2693@unnumbered Function Index
2694@printindex fn
2695
2696@bye
2697
2698@c Local Variables:
2699@c ispell-local-dictionary: "american";
2700@c End: