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