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