tests: Use "binutils:lib" as the `guix-package' example.
[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
b22a12fd 7@documentlanguage en
f8348b91 8@settitle GNU Guix Reference Manual
568717fd
LC
9@c %**end of header
10
11@include version.texi
58db733e 12@set YEARS 2012, 2013
568717fd 13
eeaf4427 14@dircategory Package management
568717fd
LC
15@direntry
16* guix: (guix). Guix, the functional package manager.
eeaf4427
LC
17* guix-package: (guix)Invoking guix-package
18 Managing packages with Guix.
568717fd
LC
19* guix-build: (guix)Invoking guix-build
20 Building packages with Guix.
21@end direntry
568717fd
LC
22
23@titlepage
f8348b91
LC
24@title{GNU Guix Reference Manual}
25@subtitle{Using the GNU Guix Functional Package Manager}
568717fd
LC
26@author Ludovic Courtès
27
28@page
29@vskip 0pt plus 1filll
30Edition @value{EDITION} @*
31@value{UPDATED} @*
32
58db733e 33Copyright @copyright{} @value{YEARS} Ludovic Court@`es
568717fd
LC
34
35@quotation
36Permission is granted to copy, distribute and/or modify this document
37under the terms of the GNU Free Documentation License, Version 1.3 or
38any later version published by the Free Software Foundation; with no
39Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
40copy of the license is included in the section entitled ``GNU Free
41Documentation License''.
42@end quotation
43@end titlepage
44
45@copying
f8348b91 46This manual documents GNU Guix version @value{VERSION}.
568717fd 47
58db733e 48Copyright @copyright{} @value{YEARS} Ludovic Courtès
568717fd
LC
49
50Permission is granted to copy, distribute and/or modify this document
51under the terms of the GNU Free Documentation License, Version 1.3 or
52any later version published by the Free Software Foundation; with no
53Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
54copy of the license is included in the section entitled ``GNU Free
55Documentation License.''
56@end copying
57
58@contents
59
60@c *********************************************************************
61@node Top
f8348b91 62@top GNU Guix
568717fd 63
f8348b91
LC
64This document describes GNU Guix version @value{VERSION}, a functional
65package management tool written for the GNU system.
568717fd 66
58db733e
LC
67@quotation
68Copyright @copyright{} @value{YEARS} Ludovic Courtès
69
70Permission is granted to copy, distribute and/or modify this document
71under the terms of the GNU Free Documentation License, Version 1.3 or
72any later version published by the Free Software Foundation; with no
73Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
74copy of the license is included in the section entitled ``GNU Free
75Documentation License.''
76@end quotation
77
568717fd
LC
78@menu
79* Introduction:: What is Guix about?
bd5e766b 80* Installation:: Installing Guix.
eeaf4427 81* Package Management:: Package installation, upgrade, etc.
568717fd
LC
82* Programming Interface:: Using Guix in Scheme.
83* Utilities:: Package management commands.
84
85* Acknowledgments:: Thanks!
86* GNU Free Documentation License:: The license of this manual.
87* Concept Index:: Concepts.
88* Function Index:: Functions.
89@end menu
90
91@c *********************************************************************
92@node Introduction
93@chapter Introduction
94
c80e7e55
LC
95GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
96using the international phonetic alphabet (IPA).} is a functional
97package management tool for the GNU system. Package management consists
98in all the activities that relate to building packages from source,
99honoring the build-time and run-time dependencies on packages,
100installing packages in user environments, upgrading installed packages
101to new versions or rolling back to a previous set, removing unused
102software packages, etc.
568717fd
LC
103
104@cindex functional package management
105The term @dfn{functional} refers to a specific package management
106discipline. In Guix, the package build and installation process is seen
107as a function, in the mathematical sense: that function takes inputs,
108such as build scripts, a compiler, and libraries depended on, and
109returns the installed package. As a pure function, its result depends
110solely on its inputs---for instance, it cannot refer to software or
111scripts that were not explicitly passed as inputs. A build function
112always produces the same result when passed a given set of inputs. Last
113but not least, a build function cannot alter the system's environment in
114any way; for instance, it cannot create, modify, or delete files outside
115of its build and installation directories. This is achieved by running
116build processes in dedicated ``chroots'', where only their explicit
117inputs are visible.
118
119@cindex package store
120The result of package build functions is @dfn{cached} in the file
121system, in a special directory called the @dfn{package store}. In
122practice, each package is installed in a directory of its own, in the
123store---by default under @file{/nix/store}. The directory name contains
124a hash of all the inputs used to build that package; thus, changing an
125input yields a different directory name.
126
127This approach is the foundation of Guix's salient features: support for
128transactional package upgrades and rollback, per-user installation, and
eeaf4427 129garbage collection of packages (@pxref{Features}).
568717fd
LC
130
131Guix has a command-line interface allowing users to build, install,
132upgrade, and remove packages, as well as a Scheme programming interface.
133The remainder of this manual describes them.
134
bd5e766b
LC
135@c *********************************************************************
136@node Installation
137@chapter Installation
138
139This section describes the software requirements of Guix, as well as how
140to install it and get ready to use it.
141
b22a12fd
LC
142The build procedure for Guix is the same as for other GNU software, and
143are not covered here. Please see the files @file{README} and
144@file{INSTALL} in the Guix source tree for additional details.
145
bd5e766b
LC
146@menu
147* Requirements:: Software needed to build and run Guix.
148* Setting Up the Daemon:: Preparing the build daemon's environment.
149* Invoking guix-daemon:: Running the build daemon.
150@end menu
151
152@node Requirements
153@section Requirements
154
155GNU Guix depends on the following packages:
156
157@itemize
158@item @url{http://gnu.org/software/guile/, GNU Guile 2.0.x};
159@item @url{http://gnupg.org/, GNU libgcrypt}
160@end itemize
161
162Unless @code{--disable-daemon} was passed to @command{configure}, the
163following packages are also needed:
164
165@itemize
166@item @url{http://sqlite.org, SQLite 3}
167@item @url{http://www.bzip.org, libbz2}
168@item @url{http://gcc.gnu.org, GCC's g++}
169@end itemize
170
171When a working installation of the Nix package manager is available, you
172can instead configure Guix with @code{--disable-daemon}. In that case,
173@url{http://nixos.org/nix/, Nix} replaces the three dependencies above.
174
b22a12fd
LC
175Guix is compatible with Nix, so it is possible to share the same store
176between both. To do so, you must pass @command{configure} not only the
177same @code{--with-store-dir} value, but also the same
178@code{--localstatedir} value (the latter is essential because it
179specifies where the database that store meta-data about the store is
180located, among other things.) The default values are
181@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
182Note that @code{--disable-daemon} is orthogonal and is not required if
183your goal is to share the same store as Nix.
184
bd5e766b
LC
185@node Setting Up the Daemon
186@section Setting Up the Daemon
187
188@cindex daemon
189Operations such as building a package or running the garbage collector
190are all performed by a specialized process, the @dfn{Guix daemon}, on
191behalf of clients. Only the daemon may access the store and its
192associated database. Thus, any operation that manipulates the store
193goes through the daemon. For instance, command-line tools such as
194@command{guix-package} and @command{guix-build} communicate with the
195daemon (@i{via} remote procedure calls) to instruct it what to do.
196
197In a standard multi-user setup, Guix and its daemon---the
198@command{guix-daemon} program---are installed by the system
199administrator; @file{/nix/store} is owned by @code{root} and
200@command{guix-daemon} runs as @code{root}. Unprivileged users may use
201Guix tools to build packages or otherwise access the store, and the
202daemon will do it on their behalf, ensuring that the store is kept in a
203consistent state, and allowing built packages to be shared among users.
204
205@cindex build users
206When @command{guix-daemon} runs as @code{root}, you may not want package
207build processes themselves to run as @code{root} too, for obvious
208security reasons. To avoid that, a special pool of @dfn{build users}
209should be created for use by build processes started by the daemon.
210These build users need not have a shell and a home directory: they will
211just be used when the daemon drops @code{root} privileges in build
212processes. Having several such users allows the daemon to launch
213distinct build processes under separate UIDs, which guarantees that they
214do not interfere with each other---an essential feature since builds are
215regarded as pure functions (@pxref{Introduction}).
216
217On a GNU/Linux system, a build user pool may be created like this (using
218Bash syntax and the @code{shadow} commands):
219
220@example
221# groupadd guix-builder
222# for i in `seq 1 10`;
223 do
224 useradd -g guix-builder -d /var/empty -s `which nologin` \
80ba8cc0 225 -c "Guix build user $i" guix-builder$i;
bd5e766b
LC
226 done
227@end example
228
229@noindent
230The @code{guix-daemon} program may then be run as @code{root} with:
231
232@example
233# guix-daemon --build-users-group=guix-builder
234@end example
235
236Guix may also be used in a single-user setup, with @command{guix-daemon}
237running as a unprivileged user. However, to maximize non-interference
238of build processes, the daemon still needs to perform certain operations
239that are restricted to @code{root} on GNU/Linux: it should be able to
240run build processes in a chroot, and to run them under different UIDs.
241To that end, the @command{nix-setuid-helper} program is provided; it is
242a small C program (less than 300 lines) that, if it is made setuid
243@code{root}, can be executed by the daemon to perform these operations
244on its behalf. The @code{root}-owned @file{/etc/nix-setuid.conf} file
245is read by @command{nix-setuid-helper}; it should contain exactly two
246words: the user name under which the authorized @command{guix-daemon}
247runs, and the name of the build users group.
248
249If you are installing Guix as an unprivileged user and do not have the
250ability to make @file{nix-setuid-helper} setuid-@code{root}, it is still
251possible to run @command{guix-daemon}. However, build processes will
252not be isolated from one another, and not from the rest of the system.
253Thus, build processes may interfere with each other, and may access
254programs, libraries, and other files available on the system---making it
255much harder to view them as @emph{pure} functions.
256
257@node Invoking guix-daemon
258@section Invoking @command{guix-daemon}
259
260The @command{guix-daemon} program implements all the functionality to
261access the store. This includes launching build processes, running the
262garbage collector, querying the availability of a build result, etc. It
263is normally run as @code{root} like this:
264
265@example
266# guix-daemon --build-users-group=guix-builder
267@end example
268
269@noindent
270For details on how to set it up, @ref{Setting Up the Daemon}.
271
272By default, @command{guix-daemon} launches build processes under
273different UIDs, taken from the build group specified with
274@code{--build-users-group}. In addition, each build process is run in a
275chroot environment that only contains the subset of the store that the
276build process depends on, as specified by its derivation
277(@pxref{Programming Interface, derivation}), plus a set of specific
278system directories. By default, the latter contains @file{/dev} and
279@file{/dev/pts}.
280
281The following command-line options are supported:
282
283@table @code
284@item --build-users-group=@var{group}
285Take users from @var{group} to run build processes (@pxref{Setting Up
286the Daemon, build users}).
287
288@item --cache-failures
289Cache build failures. By default, only successful builds are cached.
290
291@item --cores=@var{n}
292@itemx -c @var{n}
293Use @var{n} CPU cores to build each derivation; @code{0} means as many
294as available.
295
296The default value is @code{1}, but it may be overridden by clients, such
297as the @code{--cores} option of @command{guix-build} (@pxref{Invoking
298guix-build}).
299
300The effect is to define the @code{NIX_BUILD_CORES} environment variable
301in the build process, which can then use it to exploit internal
302parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
303
304@item --max-jobs=@var{n}
305@itemx -M @var{n}
306Allow at most @var{n} build jobs in parallel. The default value is
307@code{1}.
308
309@item --debug
310Produce debugging output.
311
312This is useful to debug daemon start-up issues, but then it may be
313overridden by clients, for example the @code{--verbosity} option of
314@command{guix-build} (@pxref{Invoking guix-build}).
315
316@item --chroot-directory=@var{dir}
317Add @var{dir} to the build chroot.
318
319Doing this may change the result of build processes---for instance if
320they use optional dependencies found in @var{dir} when it is available,
321and not otherwise. For that reason, it is not recommended to do so.
322Instead, make sure that each derivation declares all the inputs that it
323needs.
324
325@item --disable-chroot
326Disable chroot builds.
327
328Using this option is not recommended since, again, it would allow build
329processes to gain access to undeclared dependencies.
330
331@item --disable-log-compression
332Disable compression of the build logs.
333
334@item --disable-store-optimization
335Disable automatic file ``deduplication'' in the store.
336
337@item --impersonate-linux-2.6
338On Linux-based systems, impersonate Linux 2.6. This means that the
339kernel's @code{uname} system call will report 2.6 as the release number.
340
341This might be helpful to build programs that (usually wrongfully) depend
342on the kernel version number.
343
344@item --lose-logs
345Do not keep build logs. By default they are kept under
346@code{@var{localstatedir}/nix/log}.
347
348@item --system=@var{system}
349Assume @var{system} as the current system type. By default it is the
350architecture/kernel pair found at configure time, such as
351@code{x86_64-linux}.
352@end table
353
354
eeaf4427
LC
355@c *********************************************************************
356@node Package Management
357@chapter Package Management
358
f8348b91 359The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
360remove software packages, without having to know about their build
361procedure or dependencies. Guix also goes beyond this obvious set of
362features.
363
364This chapter describes the main features of Guix, as well as the package
365management tools it provides.
366
367@menu
368* Features:: How Guix will make your life brighter.
369* Invoking guix-package:: Package installation, removal, etc.
fe8ff028 370* Invoking guix-gc:: Running the garbage collector.
eeaf4427
LC
371@end menu
372
373@node Features
374@section Features
375
376When using Guix, each package ends up in the @dfn{package store}, in its
377own directory---something that resembles
378@file{/nix/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
379
380Instead of referring to these directories, users have their own
381@dfn{profile}, which points to the packages that they actually want to
382use. That profile is normally stored in @code{$HOME/.guix-profile}, and
383each user has its own profile.
384
385For example, if @code{alice} installed GCC 4.7.2, then
386@file{/home/alice/.guix-profile/bin/gcc} points to
387@file{/nix/store/xxx-gcc-4.7.2/bin/gcc}; on the same machine, @code{bob}
388may have installed GCC 4.8.0, in which case its profile refers to these
389particular package installation. Both coexist, without any
390interference.
391
392The @command{guix-package} command is the central tool to manage
393packages. It operates on those per-user profiles, and can be used
394@emph{with normal user privileges}.
395
396The command provides the obvious install, remove, and upgrade
397operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 398the specified operation succeeds, or nothing happens. Thus, if the
eeaf4427
LC
399@command{guix-package} processed is terminated during the transaction,
400or if a power outage occurs during the transaction, then the user's
401profile remains in its previous state, and remains usable.
402
403In addition, any package transaction may be @emph{rolled back}. So, if,
404for example, an upgrade installs a new version of a package that turns
405out to have a serious bug, users may roll back to the previous instance
406of their profile, which was known to work well.
407
408All those packages in the package store may be @emph{garbage-collected}.
409Guix can determine which packages are still referenced by the user
fe8ff028
LC
410profiles, and remove those that are provably no longer referenced
411(@pxref{Invoking guix-gc}). Users may also explicitly remove old
412generations of their profile so that the packages they refer to can be
413collected.
eeaf4427
LC
414
415Finally, Guix takes a @dfn{purely functional} approach to package
416management, as described in the introduction (@pxref{Introduction}).
417Each @file{/nix/store} package directory name contains a hash of all the
418inputs that were used to build that package---compiler, libraries, build
419scripts, etc. This direct correspondence allows users to make sure a
420given package installation matches the current state of their
421distribution.
422
423This foundation allows Guix to support @dfn{transparent binary/source
424deployment}. When a pre-built binary for a @file{/nix/store} path is
425available from an external source, Guix just downloads it; otherwise, it
426builds the package from source, locally.
427
428@node Invoking guix-package
429@section Invoking @command{guix-package}
430
ba55b1cb 431The @command{guix-package} command is the tool that allows users to
eeaf4427
LC
432install, upgrade, and remove packages, as well as rolling back to
433previous configurations. It operates only on the user's own profile,
434and works with normal user privileges (@pxref{Features}). Its syntax
435is:
436
437@example
438guix-package @var{options}
439@end example
440
ba55b1cb 441Primarily, @var{options} specifies the operations to be performed during
eeaf4427
LC
442the transaction. Upon completion, a new profile is created, but
443previous generations of the profile remain available, should the user
444want to roll back.
445
b9e5c0a9
LC
446For each user, a symlink to the user's default profile is automatically
447created in @file{$HOME/.guix-profile}. This symlink always point to the
448current generation of the user's default profile. Thus, users can add
449@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
450variable, and so on.
451
eeaf4427
LC
452@table @code
453
454@item --install=@var{package}
51c8d790 455@itemx -i @var{package}
eeaf4427
LC
456Install @var{package}.
457
458@var{package} may specify either a simple package name, such as
459@code{guile}, or a package name followed by a hyphen and version number,
bfe384cc 460such as @code{guile-1.8.8}. In addition, @var{package} may contain a
eeaf4427 461colon, followed by the name of one of the outputs of the package, as in
f03e7115 462@code{gcc:doc} or @code{binutils-2.22:lib}.
eeaf4427
LC
463
464@item --remove=@var{package}
465@itemx -r @var{package}
466Remove @var{package}.
467
ba55b1cb
LC
468@item --upgrade=@var{regexp}
469@itemx -u @var{regexp}
eeaf4427
LC
470Upgrade all the installed packages matching @var{regexp}.
471
472@item --profile=@var{profile}
473@itemx -p @var{profile}
474Use @var{profile} instead of the user's default profile.
475
476@item --dry-run
477@itemx -n
478Show what would be done without actually doing it.
479
70915c1a
LC
480@item --verbose
481Produce verbose output. In particular, emit the environment's build log
482on the standard error port.
483
eeaf4427
LC
484@item --bootstrap
485Use the bootstrap Guile to build the profile. This option is only
486useful to distribution developers.
487
488@end table
489
733b4130
LC
490In addition to these actions @command{guix-package} supports the
491following options to query the current state of a profile, or the
492availability of packages:
eeaf4427 493
733b4130
LC
494@table @option
495
496@item --list-installed[=@var{regexp}]
497@itemx -I [@var{regexp}]
498List currently installed packages in the specified profile. When
499@var{regexp} is specified, list only installed packages whose name
500matches @var{regexp}.
501
502For each installed package, print the following items, separated by
503tabs: the package name, its version string, the part of the package that
504is installed (for instance, @code{out} for the default output,
505@code{include} for its headers, etc.), and the path of this package in
506the store.
507
64fc89b6
LC
508@item --list-available[=@var{regexp}]
509@itemx -A [@var{regexp}]
510List packages currently available in the software distribution. When
511@var{regexp} is specified, list only installed packages whose name
512matches @var{regexp}.
513
514For each package, print the following items separated by tabs: its name,
44b6be77
LC
515its version string, the parts of the package (@code{out} for the main
516files, @code{lib} for libraries and possibly headers, etc.), and the
517source location of its definition.
64fc89b6 518
733b4130 519@end table
eeaf4427
LC
520
521
fe8ff028
LC
522@node Invoking guix-gc
523@section Invoking @command{guix-gc}
524
525@cindex garbage collector
526Packages that are installed but not used may be @dfn{garbage-collected}.
527The @command{guix-gc} command allows users to explicitly run the garbage
528collector to reclaim space from the @file{/nix/store} directory.
529
530The garbage collector has a set of known @dfn{roots}: any file under
531@file{/nix/store} reachable from a root is considered @dfn{live} and
532cannot be deleted; any other file is considered @dfn{dead} and may be
533deleted. The set of garbage collector roots includes default user
534profiles, and may be augmented with @command{guix-build --root}, for
535example (@pxref{Invoking guix-build}).
536
80ba8cc0 537The @command{guix-gc} command has three modes of operations: it can be
fe8ff028
LC
538used to garbage-collect any dead files (the default), to delete specific
539files (the @code{--delete} option), or to print garbage-collector
540information. The available options are listed below:
541
542@table @code
543@item --collect-garbage[=@var{min}]
544@itemx -C [@var{min}]
545Collect garbage---i.e., unreachable @file{/nix/store} files and
546sub-directories. This is the default operation when no option is
547specified.
548
549When @var{min} is given, stop once @var{min} bytes have been collected.
550@var{min} may be a number of bytes, or it may include a unit as a
551suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes.
552
553When @var{min} is omitted, collect all the garbage.
554
555@item --delete
556@itemx -d
557Attempt to delete all the store files and directories specified as
558arguments. This fails if some of the files are not in the store, or if
559they are still live.
560
561@item --list-dead
562Show the list of dead files and directories still present in the
563store---i.e., files and directories no longer reachable from any root.
564
565@item --list-live
566Show the list of live store files and directories.
567@end table
568
eeaf4427 569
568717fd
LC
570@c *********************************************************************
571@node Programming Interface
572@chapter Programming Interface
573
3dc1970d
LC
574GNU Guix provides several Scheme programming interfaces (APIs) to
575define, build, and query packages. The first interface allows users to
576write high-level package definitions. These definitions refer to
577familiar packaging concepts, such as the name and version of a package,
578its build system, and its dependencies. These definitions can then be
579turned into concrete build actions.
580
ba55b1cb 581Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d
LC
582standard setup, the daemon has write access to the store---the
583@file{/nix/store} directory---whereas users do not. The recommended
584setup also has the daemon perform builds in chroots, under a specific
585build users, to minimize interference with the rest of the system.
586
587@cindex derivation
588Lower-level APIs are available to interact with the daemon and the
589store. To instruct the daemon to perform a build action, users actually
590provide it with a @dfn{derivation}. A derivation is a low-level
591representation of the build actions to be taken, and the environment in
592which they should occur---derivations are to package definitions what
593assembly is to C programs.
594
595This chapter describes all these APIs in turn, starting from high-level
596package definitions.
597
568717fd
LC
598@menu
599* Defining Packages:: Defining new packages.
600* The Store:: Manipulating the package store.
601* Derivations:: Low-level interface to package derivations.
602@end menu
603
604@node Defining Packages
605@section Defining Packages
606
3dc1970d
LC
607The high-level interface to package definitions is implemented in the
608@code{(guix packages)} and @code{(guix build-system)} modules. As an
609example, the package definition, or @dfn{recipe}, for the GNU Hello
610package looks like this:
611
612@example
b22a12fd
LC
613(use-modules (guix packages)
614 (guix download)
615 (guix build-system gnu)
616 (guix licenses))
617
3dc1970d
LC
618(define hello
619 (package
620 (name "hello")
621 (version "2.8")
622 (source (origin
623 (method url-fetch)
624 (uri (string-append "mirror://gnu/hello/hello-" version
625 ".tar.gz"))
626 (sha256
627 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
628 (build-system gnu-build-system)
629 (inputs `(("gawk" ,gawk)))
630 (synopsis "GNU Hello")
631 (description "Yeah...")
632 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 633 (license gpl3+)))
3dc1970d
LC
634@end example
635
636@noindent
637Without being a Scheme expert, the reader may have guessed the meaning
638of the various fields here. This expression binds variable @var{hello}
639to a @code{<package>} object, which is essentially a record
640(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
641This package object can be inspected using procedures found in the
642@code{(guix packages)} module; for instance, @code{(package-name hello)}
643returns---surprise!---@code{"hello"}.
644
645There are a few points worth noting in the above package definition:
646
647@itemize
648@item
649The @code{source} field of the package is an @code{<origin>} object.
650Here, the @code{url-fetch} method from @code{(guix download)} is used,
651meaning that the source is a file to be downloaded over FTP or HTTP.
652
653The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
654the GNU mirrors defined in @code{(guix download)}.
655
656The @code{sha256} field specifies the expected SHA256 hash of the file
657being downloaded. It is mandatory, and allows Guix to check the
658integrity of the file. The @code{(base32 @dots{})} form introduces the
659base32 representation of the hash. A convenient way to obtain this
660information is with the @code{guix-download} tool.
661
662@item
663@cindex GNU Build System
664The @code{build-system} field is set to @var{gnu-build-system}. The
665@var{gnu-build-system} variable is defined in the @code{(guix
666build-system gnu)} module, and is bound to a @code{<build-system>}
667object.
668
669Naturally, @var{gnu-build-system} represents the familiar GNU Build
670System, and variants thereof (@pxref{Configuration, configuration and
671makefile conventions,, standards, GNU Coding Standards}). In a
ba55b1cb 672nutshell, packages using the GNU Build System may be configured, built,
3dc1970d
LC
673and installed with the usual @code{./configure && make && make check &&
674make install} command sequence. This is what @var{gnu-build-system}
675does.
676
677In addition, @var{gnu-build-system} ensures that the ``standard''
678environment for GNU packages is available. This includes tools such as
679GCC, Coreutils, Bash, Make, Diffutils, and Patch.
680
681@item
682The @code{inputs} field specifies inputs to the build process---i.e.,
683build-time or run-time dependencies of the package. Here, we define an
684input called @code{"gawk"} whose value is that of the @var{gawk}
685variable; @var{gawk} is itself bound to a @code{<package>} object.
686
687Note that GCC, Coreutils, Bash, and other essential tools do not need to
688be specified as inputs here. Instead, @var{gnu-build-system} takes care
689of ensuring that they are present.
690
691However, any other dependencies need to be specified in the
692@code{inputs} field. Any dependency not specified here will simply be
693unavailable to the build process, possibly leading to a build failure.
694@end itemize
695
696There are other fields that package definitions may provide. Of
697particular interest is the @code{arguments} field. When specified, it
698must be bound to a list of additional arguments to be passed to the
699build system. For instance, the above definition could be augmented
700with the following field initializer:
701
702@example
703 (arguments `(#:tests? #f
704 #:configure-flags '("--enable-silent-rules")))
705@end example
706
707@noindent
708These are keyword arguments (@pxref{Optional Arguments, keyword
709arguments in Guile,, guile, GNU Guile Reference Manual}). They are
710passed to @var{gnu-build-system}, which interprets them as meaning ``do
711not run @code{make check}'', and ``run @file{configure} with the
712@code{--enable-silent-rules} flag''.
713
714Once a package definition is in place@footnote{Simple package
715definitions like the one above may be automatically converted from the
716Nixpkgs distribution using the @command{guix-import} command.}, the
717package may actually be built using the @code{guix-build} command-line
718tool (@pxref{Invoking guix-build}).
719
720Behind the scenes, a derivation corresponding to the @code{<package>}
721object is first computed by the @code{package-derivation} procedure.
722That derivation is stored in a @code{.drv} file under @file{/nix/store}.
ba55b1cb 723The build actions it prescribes may then be realized by using the
3dc1970d
LC
724@code{build-derivations} procedure (@pxref{The Store}).
725
726@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
727Return the derivation of @var{package} for @var{system}. The result is
728the file name of the derivation---i.e., a @code{.drv} file under
729@code{/nix/store}.
730
731@var{package} must be a valid @code{<package>} object, and @var{system}
732must be a string denoting the target system type---e.g.,
733@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
734must be a connection to the daemon, which operates on the store
735(@pxref{The Store}).
736@end deffn
568717fd
LC
737
738@node The Store
739@section The Store
740
741@code{(guix store)}
742
743@node Derivations
744@section Derivations
745
746@code{(guix derivations)}
747
748@c *********************************************************************
749@node Utilities
750@chapter Utilities
751
752@menu
753* Invoking guix-build:: Building packages from the command line.
754@end menu
755
756@node Invoking guix-build
757@section Invoking @command{guix-build}
758
c78bd12b
LC
759The @command{guix-build} command builds packages or derivations and
760their dependencies, and prints the resulting store paths. It is mainly
761useful for distribution developers. The general syntax is:
762
763@example
764guix-build @var{options} @var{package-or-derivation}@dots{}
765@end example
766
767@var{package-or-derivation} may be either the name of a package found in
768the software distribution such as @code{coreutils}, or a derivation such
769as @file{/nix/store/xxx-coreutils-8.19.drv}. Alternatively, the
770@code{--expression} option may be used to specify a Scheme expression
771that evaluates to a package; this is useful when disambiguation among
772several same-named packages or package variants is needed.
773
774The @var{options} may be zero or more of the following:
775
776@table @code
777
778@item --expression=@var{expr}
779@itemx -e @var{expr}
780Build the package @var{expr} evaluates to.
781
782For example, @var{expr} may be @code{(@@ (distro packages guile)
783guile-1.8)}, which unambiguously designates this specific variant of
784version 1.8 of Guile.
785
786@item --source
787@itemx -S
788Build the packages' source derivations, rather than the packages
789themselves.
790
791For instance, @code{guix-build -S gcc} returns something like
792@file{/nix/store/xxx-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
793
794@item --system=@var{system}
795@itemx -s @var{system}
796Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
797the host's system type.
798
799An example use of this is on Linux-based systems, which can emulate
800different personalities. For instance, passing
801@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
802to build packages in a complete 32-bit environment.
803
804@item --derivations
805@itemx -d
806Return the derivation paths, not the output paths, of the given
807packages.
808
809@item --keep-failed
810@itemx -K
811Keep the build tree of failed builds. Thus, if a build fail, its build
812tree is kept under @file{/tmp}, in a directory whose name is shown at
813the end of the build log. This is useful when debugging build issues.
814
815@item --dry-run
816@itemx -n
817Do not build the derivations.
818
819@item --no-substitutes
820Build instead of resorting to pre-built substitutes.
821
822@item --cores=@var{n}
823@itemx -c @var{n}
824Allow the use of up to @var{n} CPU cores for the build. The special
825value @code{0} means to use as many CPU cores as available.
826
827@item --root=@var{file}
828@itemx -r @var{file}
829Make @var{file} a symlink to the result, and register it as a garbage
830collector root.
07ab4bf1
LC
831
832@item --verbosity=@var{level}
833Use the given verbosity level. @var{level} must be an integer between 0
834and 5; higher means more verbose output. Setting a level of 4 or more
835may be helpful when debugging setup issues with the build daemon.
836
c78bd12b
LC
837@end table
838
839Behind the scenes, @command{guix-build} is essentially an interface to
840the @code{package-derivation} procedure of the @code{(guix packages)}
841module, and to the @code{build-derivations} procedure of the @code{(guix
842store)} module.
843
844
568717fd
LC
845@c *********************************************************************
846@node Acknowledgments
847@chapter Acknowledgments
848
849Guix is based on the Nix package manager, which was designed and
850implemented by Eelco Dolstra. Nix pioneered functional package
851management, and promoted unprecedented features, such as transactional
852package upgrades and rollbacks, per-user profiles, and referentially
853transparent build processes. Without this work, Guix would not exist.
854
855The Nix-based software distributions, Nixpkgs and NixOS, have also been
856an inspiration for Guix.
857
858@c *********************************************************************
859@node GNU Free Documentation License
860@appendix GNU Free Documentation License
861
862@include fdl-1.3.texi
863
864@c *********************************************************************
865@node Concept Index
866@unnumbered Concept Index
867@printindex cp
868
869@node Function Index
870@unnumbered Function Index
871@printindex fn
872
873@bye
874
875@c Local Variables:
876@c ispell-local-dictionary: "american";
877@c End: