Update `TODO'.
[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
821b0015
LC
399use. These profiles are stored within each user's home directory, at
400@code{$HOME/.guix-profile}.
eeaf4427 401
821b0015 402For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 403@file{/home/alice/.guix-profile/bin/gcc} points to
821b0015
LC
404@file{/nix/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
405@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
406simply continues to point to
407@file{/nix/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
408coexist on the same system without any interference.
eeaf4427
LC
409
410The @command{guix-package} command is the central tool to manage
821b0015
LC
411packages (@pxref{Invoking guix-package}). It operates on those per-user
412profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
413
414The command provides the obvious install, remove, and upgrade
415operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 416the specified operation succeeds, or nothing happens. Thus, if the
821b0015 417@command{guix-package} process is terminated during the transaction,
eeaf4427
LC
418or if a power outage occurs during the transaction, then the user's
419profile remains in its previous state, and remains usable.
420
421In addition, any package transaction may be @emph{rolled back}. So, if,
422for example, an upgrade installs a new version of a package that turns
423out to have a serious bug, users may roll back to the previous instance
424of their profile, which was known to work well.
425
426All those packages in the package store may be @emph{garbage-collected}.
427Guix can determine which packages are still referenced by the user
fe8ff028
LC
428profiles, and remove those that are provably no longer referenced
429(@pxref{Invoking guix-gc}). Users may also explicitly remove old
430generations of their profile so that the packages they refer to can be
431collected.
eeaf4427
LC
432
433Finally, Guix takes a @dfn{purely functional} approach to package
434management, as described in the introduction (@pxref{Introduction}).
435Each @file{/nix/store} package directory name contains a hash of all the
436inputs that were used to build that package---compiler, libraries, build
437scripts, etc. This direct correspondence allows users to make sure a
438given package installation matches the current state of their
a1ba8475 439distribution, and helps maximize @dfn{reproducibility}.
eeaf4427 440
75f1e8f7 441@c FIXME: Remove footnote when it's implemented.
eeaf4427 442This foundation allows Guix to support @dfn{transparent binary/source
75f1e8f7
LC
443deployment}@footnote{This feature is not implemented as of version
444@value{VERSION}. Please contact @email{bug-guix@@gnu.org} for more
445details.}. When a pre-built binary for a @file{/nix/store} path is
eeaf4427
LC
446available from an external source, Guix just downloads it; otherwise, it
447builds the package from source, locally.
448
449@node Invoking guix-package
450@section Invoking @command{guix-package}
451
ba55b1cb 452The @command{guix-package} command is the tool that allows users to
eeaf4427
LC
453install, upgrade, and remove packages, as well as rolling back to
454previous configurations. It operates only on the user's own profile,
455and works with normal user privileges (@pxref{Features}). Its syntax
456is:
457
458@example
459guix-package @var{options}
460@end example
461
ba55b1cb 462Primarily, @var{options} specifies the operations to be performed during
eeaf4427
LC
463the transaction. Upon completion, a new profile is created, but
464previous generations of the profile remain available, should the user
465want to roll back.
466
b9e5c0a9 467For each user, a symlink to the user's default profile is automatically
0ec1af59 468created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
469current generation of the user's default profile. Thus, users can add
470@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
471variable, and so on.
472
0ec1af59
LC
473In a multi-user setup, user profiles must be stored in a place
474registered as a @dfn{garbage-collector root}, which
475@file{$HOME/.guix-profile} points to (@pxref{Invoking guix-gc}). That
476directory is normally
477@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
478@var{localstatedir} is the value passed to @code{configure} as
479@code{--localstatedir}, and @var{user} is the user name. It must be
480created by @code{root}, with @var{user} as the owner. When it does not
481exist, @command{guix-package} emits an error about it.
482
483The @var{options} can be among the following:
484
eeaf4427
LC
485@table @code
486
487@item --install=@var{package}
51c8d790 488@itemx -i @var{package}
eeaf4427
LC
489Install @var{package}.
490
491@var{package} may specify either a simple package name, such as
492@code{guile}, or a package name followed by a hyphen and version number,
bfe384cc 493such as @code{guile-1.8.8}. In addition, @var{package} may contain a
eeaf4427 494colon, followed by the name of one of the outputs of the package, as in
f03e7115 495@code{gcc:doc} or @code{binutils-2.22:lib}.
eeaf4427
LC
496
497@item --remove=@var{package}
498@itemx -r @var{package}
499Remove @var{package}.
500
ba55b1cb
LC
501@item --upgrade=@var{regexp}
502@itemx -u @var{regexp}
eeaf4427
LC
503Upgrade all the installed packages matching @var{regexp}.
504
24e262f0
LC
505@item --roll-back
506Roll back to the previous @dfn{generation} of the profile---i.e., undo
507the last transaction.
508
509When combined with options such as @code{--install}, roll back occurs
510before any other actions.
511
eeaf4427
LC
512@item --profile=@var{profile}
513@itemx -p @var{profile}
514Use @var{profile} instead of the user's default profile.
515
516@item --dry-run
517@itemx -n
518Show what would be done without actually doing it.
519
70915c1a
LC
520@item --verbose
521Produce verbose output. In particular, emit the environment's build log
522on the standard error port.
523
eeaf4427
LC
524@item --bootstrap
525Use the bootstrap Guile to build the profile. This option is only
526useful to distribution developers.
527
528@end table
529
733b4130
LC
530In addition to these actions @command{guix-package} supports the
531following options to query the current state of a profile, or the
532availability of packages:
eeaf4427 533
733b4130
LC
534@table @option
535
536@item --list-installed[=@var{regexp}]
537@itemx -I [@var{regexp}]
538List currently installed packages in the specified profile. When
539@var{regexp} is specified, list only installed packages whose name
540matches @var{regexp}.
541
542For each installed package, print the following items, separated by
543tabs: the package name, its version string, the part of the package that
544is installed (for instance, @code{out} for the default output,
545@code{include} for its headers, etc.), and the path of this package in
546the store.
547
64fc89b6
LC
548@item --list-available[=@var{regexp}]
549@itemx -A [@var{regexp}]
a1ba8475
LC
550List packages currently available in the software distribution
551(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
552installed packages whose name matches @var{regexp}.
64fc89b6
LC
553
554For each package, print the following items separated by tabs: its name,
44b6be77
LC
555its version string, the parts of the package (@code{out} for the main
556files, @code{lib} for libraries and possibly headers, etc.), and the
557source location of its definition.
64fc89b6 558
733b4130 559@end table
eeaf4427
LC
560
561
fe8ff028
LC
562@node Invoking guix-gc
563@section Invoking @command{guix-gc}
564
565@cindex garbage collector
566Packages that are installed but not used may be @dfn{garbage-collected}.
567The @command{guix-gc} command allows users to explicitly run the garbage
568collector to reclaim space from the @file{/nix/store} directory.
569
570The garbage collector has a set of known @dfn{roots}: any file under
571@file{/nix/store} reachable from a root is considered @dfn{live} and
572cannot be deleted; any other file is considered @dfn{dead} and may be
573deleted. The set of garbage collector roots includes default user
574profiles, and may be augmented with @command{guix-build --root}, for
575example (@pxref{Invoking guix-build}).
576
1da983b9 577The @command{guix-gc} command has three modes of operation: it can be
fe8ff028
LC
578used to garbage-collect any dead files (the default), to delete specific
579files (the @code{--delete} option), or to print garbage-collector
580information. The available options are listed below:
581
582@table @code
583@item --collect-garbage[=@var{min}]
584@itemx -C [@var{min}]
585Collect garbage---i.e., unreachable @file{/nix/store} files and
586sub-directories. This is the default operation when no option is
587specified.
588
589When @var{min} is given, stop once @var{min} bytes have been collected.
590@var{min} may be a number of bytes, or it may include a unit as a
591suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes.
592
593When @var{min} is omitted, collect all the garbage.
594
595@item --delete
596@itemx -d
597Attempt to delete all the store files and directories specified as
598arguments. This fails if some of the files are not in the store, or if
599they are still live.
600
601@item --list-dead
602Show the list of dead files and directories still present in the
603store---i.e., files and directories no longer reachable from any root.
604
605@item --list-live
606Show the list of live store files and directories.
607@end table
608
eeaf4427 609
568717fd
LC
610@c *********************************************************************
611@node Programming Interface
612@chapter Programming Interface
613
3dc1970d
LC
614GNU Guix provides several Scheme programming interfaces (APIs) to
615define, build, and query packages. The first interface allows users to
616write high-level package definitions. These definitions refer to
617familiar packaging concepts, such as the name and version of a package,
618its build system, and its dependencies. These definitions can then be
619turned into concrete build actions.
620
ba55b1cb 621Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d
LC
622standard setup, the daemon has write access to the store---the
623@file{/nix/store} directory---whereas users do not. The recommended
624setup also has the daemon perform builds in chroots, under a specific
625build users, to minimize interference with the rest of the system.
626
627@cindex derivation
628Lower-level APIs are available to interact with the daemon and the
629store. To instruct the daemon to perform a build action, users actually
630provide it with a @dfn{derivation}. A derivation is a low-level
631representation of the build actions to be taken, and the environment in
632which they should occur---derivations are to package definitions what
633assembly is to C programs.
634
635This chapter describes all these APIs in turn, starting from high-level
636package definitions.
637
568717fd
LC
638@menu
639* Defining Packages:: Defining new packages.
640* The Store:: Manipulating the package store.
641* Derivations:: Low-level interface to package derivations.
642@end menu
643
644@node Defining Packages
645@section Defining Packages
646
3dc1970d
LC
647The high-level interface to package definitions is implemented in the
648@code{(guix packages)} and @code{(guix build-system)} modules. As an
649example, the package definition, or @dfn{recipe}, for the GNU Hello
650package looks like this:
651
652@example
b22a12fd
LC
653(use-modules (guix packages)
654 (guix download)
655 (guix build-system gnu)
656 (guix licenses))
657
3dc1970d
LC
658(define hello
659 (package
660 (name "hello")
661 (version "2.8")
662 (source (origin
663 (method url-fetch)
664 (uri (string-append "mirror://gnu/hello/hello-" version
665 ".tar.gz"))
666 (sha256
667 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
668 (build-system gnu-build-system)
669 (inputs `(("gawk" ,gawk)))
670 (synopsis "GNU Hello")
671 (description "Yeah...")
672 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 673 (license gpl3+)))
3dc1970d
LC
674@end example
675
676@noindent
677Without being a Scheme expert, the reader may have guessed the meaning
678of the various fields here. This expression binds variable @var{hello}
679to a @code{<package>} object, which is essentially a record
680(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
681This package object can be inspected using procedures found in the
682@code{(guix packages)} module; for instance, @code{(package-name hello)}
683returns---surprise!---@code{"hello"}.
684
685There are a few points worth noting in the above package definition:
686
687@itemize
688@item
689The @code{source} field of the package is an @code{<origin>} object.
690Here, the @code{url-fetch} method from @code{(guix download)} is used,
691meaning that the source is a file to be downloaded over FTP or HTTP.
692
693The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
694the GNU mirrors defined in @code{(guix download)}.
695
696The @code{sha256} field specifies the expected SHA256 hash of the file
697being downloaded. It is mandatory, and allows Guix to check the
698integrity of the file. The @code{(base32 @dots{})} form introduces the
699base32 representation of the hash. A convenient way to obtain this
700information is with the @code{guix-download} tool.
701
702@item
703@cindex GNU Build System
704The @code{build-system} field is set to @var{gnu-build-system}. The
705@var{gnu-build-system} variable is defined in the @code{(guix
706build-system gnu)} module, and is bound to a @code{<build-system>}
707object.
708
709Naturally, @var{gnu-build-system} represents the familiar GNU Build
710System, and variants thereof (@pxref{Configuration, configuration and
711makefile conventions,, standards, GNU Coding Standards}). In a
ba55b1cb 712nutshell, packages using the GNU Build System may be configured, built,
3dc1970d
LC
713and installed with the usual @code{./configure && make && make check &&
714make install} command sequence. This is what @var{gnu-build-system}
715does.
716
717In addition, @var{gnu-build-system} ensures that the ``standard''
718environment for GNU packages is available. This includes tools such as
719GCC, Coreutils, Bash, Make, Diffutils, and Patch.
720
721@item
722The @code{inputs} field specifies inputs to the build process---i.e.,
723build-time or run-time dependencies of the package. Here, we define an
724input called @code{"gawk"} whose value is that of the @var{gawk}
725variable; @var{gawk} is itself bound to a @code{<package>} object.
726
727Note that GCC, Coreutils, Bash, and other essential tools do not need to
728be specified as inputs here. Instead, @var{gnu-build-system} takes care
729of ensuring that they are present.
730
731However, any other dependencies need to be specified in the
732@code{inputs} field. Any dependency not specified here will simply be
733unavailable to the build process, possibly leading to a build failure.
734@end itemize
735
736There are other fields that package definitions may provide. Of
737particular interest is the @code{arguments} field. When specified, it
738must be bound to a list of additional arguments to be passed to the
739build system. For instance, the above definition could be augmented
740with the following field initializer:
741
742@example
743 (arguments `(#:tests? #f
744 #:configure-flags '("--enable-silent-rules")))
745@end example
746
747@noindent
748These are keyword arguments (@pxref{Optional Arguments, keyword
749arguments in Guile,, guile, GNU Guile Reference Manual}). They are
750passed to @var{gnu-build-system}, which interprets them as meaning ``do
751not run @code{make check}'', and ``run @file{configure} with the
874e6874
LC
752@code{--enable-silent-rules} flag''. The value of these keyword
753parameters is actually evaluated in the @dfn{build stratum}---i.e., by a
754Guile process launched by the daemon (@pxref{Derivations}).
3dc1970d
LC
755
756Once a package definition is in place@footnote{Simple package
757definitions like the one above may be automatically converted from the
758Nixpkgs distribution using the @command{guix-import} command.}, the
759package may actually be built using the @code{guix-build} command-line
760tool (@pxref{Invoking guix-build}).
761
762Behind the scenes, a derivation corresponding to the @code{<package>}
763object is first computed by the @code{package-derivation} procedure.
764That derivation is stored in a @code{.drv} file under @file{/nix/store}.
ba55b1cb 765The build actions it prescribes may then be realized by using the
3dc1970d
LC
766@code{build-derivations} procedure (@pxref{The Store}).
767
768@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
e509d152
LC
769Return the derivation path and corresponding @code{<derivation>} object
770of @var{package} for @var{system} (@pxref{Derivations}).
3dc1970d
LC
771
772@var{package} must be a valid @code{<package>} object, and @var{system}
773must be a string denoting the target system type---e.g.,
774@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
775must be a connection to the daemon, which operates on the store
776(@pxref{The Store}).
777@end deffn
568717fd
LC
778
779@node The Store
780@section The Store
781
e531ac2a
LC
782@cindex store
783@cindex store paths
784
785Conceptually, the @dfn{store} is where derivations that have been
786successfully built are stored---by default, under @file{/nix/store}.
787Sub-directories in the store are referred to as @dfn{store paths}. The
788store has an associated database that contains information such has the
789store paths referred to by each store path, and the list of @emph{valid}
790store paths---paths that result from a successful build.
791
792The store is always accessed by the daemon on behalf of its clients
793(@pxref{Invoking guix-daemon}). To manipulate the store, clients
794connect to the daemon over a Unix-domain socket, send it requests, and
795read the result---these are remote procedure calls, or RPCs.
796
797The @code{(guix store)} module provides procedures to connect to the
798daemon, and to perform RPCs. These are described below.
799
800@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
801Connect to the daemon over the Unix-domain socket at @var{file}. When
802@var{reserve-space?} is true, instruct it to reserve a little bit of
803extra space on the file system so that the garbage collector can still
804operate, should the disk become full. Return a server object.
805
806@var{file} defaults to @var{%default-socket-path}, which is the normal
807location given the options that were passed to @command{configure}.
808@end deffn
809
810@deffn {Scheme Procedure} close-connection @var{server}
811Close the connection to @var{server}.
812@end deffn
813
814@defvr {Scheme Variable} current-build-output-port
815This variable is bound to a SRFI-39 parameter, which refers to the port
816where build and error logs sent by the daemon should be written.
817@end defvr
818
819Procedures that make RPCs all take a server object as their first
820argument.
821
822@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
823Return @code{#t} when @var{path} is a valid store path.
824@end deffn
825
826@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} @var{references}
827Add @var{text} under file @var{name} in the store, and return its store
828path. @var{references} is the list of store paths referred to by the
829resulting store path.
830@end deffn
831
874e6874
LC
832@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
833Build @var{derivations} (a list of derivation paths), and return when
834the worker is done building them. Return @code{#t} on success.
835@end deffn
836
e531ac2a
LC
837@c FIXME
838@i{This section is currently incomplete.}
568717fd
LC
839
840@node Derivations
841@section Derivations
842
874e6874
LC
843@cindex derivations
844Low-level build actions and the environment in which they are performed
845are represented by @dfn{derivations}. A derivation contain the
846following pieces of information:
847
848@itemize
849@item
850The outputs of the derivation---derivations produce at least one file or
851directory in the store, but may produce more.
852
853@item
854The inputs of the derivations, which may be other derivations or plain
855files in the store (patches, build scripts, etc.)
856
857@item
858The system type targeted by the derivation---e.g., @code{x86_64-linux}.
859
860@item
861The file name of a build script in the store, along with the arguments
862to be passed.
863
864@item
865A list of environment variables to be defined.
866
867@end itemize
868
869@cindex derivation path
870Derivations allow clients of the daemon to communicate build actions to
871the store. They exist in two forms: as an in-memory representation,
872both on the client- and daemon-side, and as files in the store whose
873name end in @code{.drv}---these files are referred to as @dfn{derivation
874paths}. Derivations paths can be passed to the @code{build-derivations}
875procedure to perform the build actions they prescribe (@pxref{The
876Store}).
877
878The @code{(guix derivations)} module provides a representation of
879derivations as Scheme objects, along with procedures to create and
880otherwise manipulate derivations. The lowest-level primitive to create
881a derivation is the @code{derivation} procedure:
882
883@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]
884Build a derivation with the given arguments. Return the resulting store
885path and @code{<derivation>} object.
886
887When @var{hash}, @var{hash-algo}, and @var{hash-mode} are given, a
888@dfn{fixed-output derivation} is created---i.e., one whose result is
889known in advance, such as a file download.
890@end deffn
891
892@noindent
893Here's an example with a shell script as its builder, assuming
894@var{store} is an open connection to the daemon, and @var{bash} points
895to a Bash executable in the store:
896
897@lisp
898(use-modules (guix utils)
899 (guix store)
900 (guix derivations))
901
902(call-with-values
903 (lambda ()
904 (let ((builder ; add the Bash script to the store
905 (add-text-to-store store "my-builder.sh"
906 "echo hello world > $out\n" '())))
907 (derivation store "foo" (%current-system)
908 bash `("-e" ,builder)
909 '(("HOME" . "/homeless")) '())))
910 list)
911@result{} ("/nix/store/@dots{}-foo.drv" #<<derivation> @dots{}>)
912@end lisp
913
914As can be guessed, this primitive is cumbersome to use directly. An
915improved variant is @code{build-expression->derivation}, which allows
916the caller to directly pass a Guile expression as the build script:
917
918@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]
919Return a derivation that executes Scheme expression @var{exp} as a
920builder for derivation @var{name}. @var{inputs} must be a list of
921@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
922@code{"out"} is assumed. @var{modules} is a list of names of Guile
923modules from the current search path to be copied in the store,
924compiled, and made available in the load path during the execution of
925@var{exp}---e.g., @code{((guix build utils) (guix build
926gnu-build-system))}.
927
928@var{exp} is evaluated in an environment where @code{%outputs} is bound
929to a list of output/path pairs, and where @code{%build-inputs} is bound
930to a list of string/output-path pairs made from @var{inputs}.
931Optionally, @var{env-vars} is a list of string pairs specifying the name
932and value of environment variables visible to the builder. The builder
933terminates by passing the result of @var{exp} to @code{exit}; thus, when
934@var{exp} returns @code{#f}, the build is considered to have failed.
935
936@var{exp} is built using @var{guile-for-build} (a derivation). When
937@var{guile-for-build} is omitted or is @code{#f}, the value of the
938@code{%guile-for-build} fluid is used instead.
939@end deffn
940
941@noindent
942Here's an example of a single-output derivation that creates a directory
943containing one file:
944
945@lisp
946(let ((builder '(let ((out (assoc-ref %outputs "out")))
947 (mkdir out) ; create /nix/store/@dots{}-goo
948 (call-with-output-file (string-append out "/test")
949 (lambda (p)
950 (display '(hello guix) p))))))
951 (build-expression->derivation store "goo" (%current-system)
952 builder '()))
953
954@result{} "/nix/store/@dots{}-goo.drv"
955@result{} #<<derivation> @dots{}>
956@end lisp
957
958@cindex strata of code
959Remember that the build expression passed to
960@code{build-expression->derivation} is run by a separate Guile process
961than the one that calls @code{build-expression->derivation}: it is run
962by a Guile process launched by the daemon, typically in a chroot. So,
963while there is a single language for both the @dfn{host} and the build
964side, there are really two @dfn{strata} of code: the host-side, and the
965build-side code@footnote{The term @dfn{stratum} in this context was
966coined by Manuel Serrano et al. in the context of their work on Hop.}.
967This distinction is important to keep in mind, notably when using
968higher-level constructs such as @var{gnu-build-system} (@pxref{Defining
969Packages}). For this reason, Guix modules that are meant to be used in
970the build stratum are kept in the @code{(guix build @dots{})} name
971space.
568717fd
LC
972
973@c *********************************************************************
974@node Utilities
975@chapter Utilities
976
977@menu
978* Invoking guix-build:: Building packages from the command line.
979@end menu
980
981@node Invoking guix-build
982@section Invoking @command{guix-build}
983
c78bd12b 984The @command{guix-build} command builds packages or derivations and
6798a8e4
LC
985their dependencies, and prints the resulting store paths. Note that it
986does not modify the user's profile---this is the job of the
987@command{guix-package} command (@pxref{Invoking guix-package}). Thus,
988it is mainly useful for distribution developers.
989
990The general syntax is:
c78bd12b
LC
991
992@example
993guix-build @var{options} @var{package-or-derivation}@dots{}
994@end example
995
996@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
997the software distribution such as @code{coreutils} or
998@code{coreutils-8.20}, or a derivation such as
999@file{/nix/store/@dots{}-coreutils-8.19.drv}. Alternatively, the
c78bd12b
LC
1000@code{--expression} option may be used to specify a Scheme expression
1001that evaluates to a package; this is useful when disambiguation among
1002several same-named packages or package variants is needed.
1003
1004The @var{options} may be zero or more of the following:
1005
1006@table @code
1007
1008@item --expression=@var{expr}
1009@itemx -e @var{expr}
1010Build the package @var{expr} evaluates to.
1011
5401dd75 1012For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
1013guile-1.8)}, which unambiguously designates this specific variant of
1014version 1.8 of Guile.
1015
1016@item --source
1017@itemx -S
1018Build the packages' source derivations, rather than the packages
1019themselves.
1020
1021For instance, @code{guix-build -S gcc} returns something like
6798a8e4 1022@file{/nix/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b
LC
1023
1024@item --system=@var{system}
1025@itemx -s @var{system}
1026Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
1027the host's system type.
1028
1029An example use of this is on Linux-based systems, which can emulate
1030different personalities. For instance, passing
1031@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
1032to build packages in a complete 32-bit environment.
1033
1034@item --derivations
1035@itemx -d
1036Return the derivation paths, not the output paths, of the given
1037packages.
1038
1039@item --keep-failed
1040@itemx -K
1041Keep the build tree of failed builds. Thus, if a build fail, its build
1042tree is kept under @file{/tmp}, in a directory whose name is shown at
1043the end of the build log. This is useful when debugging build issues.
1044
1045@item --dry-run
1046@itemx -n
1047Do not build the derivations.
1048
1049@item --no-substitutes
1050Build instead of resorting to pre-built substitutes.
1051
1052@item --cores=@var{n}
1053@itemx -c @var{n}
1054Allow the use of up to @var{n} CPU cores for the build. The special
1055value @code{0} means to use as many CPU cores as available.
1056
1057@item --root=@var{file}
1058@itemx -r @var{file}
1059Make @var{file} a symlink to the result, and register it as a garbage
1060collector root.
07ab4bf1
LC
1061
1062@item --verbosity=@var{level}
1063Use the given verbosity level. @var{level} must be an integer between 0
1064and 5; higher means more verbose output. Setting a level of 4 or more
1065may be helpful when debugging setup issues with the build daemon.
1066
c78bd12b
LC
1067@end table
1068
1069Behind the scenes, @command{guix-build} is essentially an interface to
1070the @code{package-derivation} procedure of the @code{(guix packages)}
1071module, and to the @code{build-derivations} procedure of the @code{(guix
1072store)} module.
1073
a1ba8475
LC
1074@c *********************************************************************
1075@node GNU Distribution
1076@chapter GNU Distribution
1077
1078Guix comes with a distribution of free software@footnote{The term
1079``free'' here refers to the
1080@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
1081users of that software}.} that form the basis of the GNU system. This
1082includes core GNU packages such as GNU libc, GCC, and Binutils, as well
1083as many GNU and non-GNU applications. The complete list of available
1084packages can be seen by running @command{guix-package} (@pxref{Invoking
1085guix-package}):
1086
1087@example
1088guix-package --list-available
1089@end example
1090
1091The package definitions of the distribution may are provided by Guile
1092modules in the @code{(gnu packages ...)} name space---for instance, the
1093@code{(gnu packages emacs)} module exports a variable named
1094@code{emacs}, which is bound to a @code{<package>} object
1095(@pxref{Defining Packages}). The @code{(gnu packages)} module provides
1096facilities for searching for packages.
1097
1098The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
1099each package is built based solely on other packages in the
1100distribution. The root of this dependency graph is a small set of
1101@dfn{bootstrap binaries}, provided by the @code{(gnu packages
1102bootstrap)} module. These are statically-linked binaries of the core
1103tools without which building anything at all would be impossible.
1104
1105
1106Our goal is to build a practical 100% free software distribution of
1107Linux-based and other variants of GNU, with a focus on the promotion and
1108tight integration of GNU components, and an emphasis on programs and
1109tools that help users exert that freedom.
1110
1111Building this distribution is a cooperative effort, and you are invited
1112to join! Please get in touch with us on @email{bug-guix@@gnu.org}. We
1113welcome ideas, bug reports, patches, and anything that may be helpful to
1114the project.
1115
c78bd12b 1116
568717fd
LC
1117@c *********************************************************************
1118@node Acknowledgments
1119@chapter Acknowledgments
1120
1121Guix is based on the Nix package manager, which was designed and
1122implemented by Eelco Dolstra. Nix pioneered functional package
1123management, and promoted unprecedented features, such as transactional
1124package upgrades and rollbacks, per-user profiles, and referentially
1125transparent build processes. Without this work, Guix would not exist.
1126
1127The Nix-based software distributions, Nixpkgs and NixOS, have also been
1128an inspiration for Guix.
1129
1130@c *********************************************************************
1131@node GNU Free Documentation License
1132@appendix GNU Free Documentation License
1133
1134@include fdl-1.3.texi
1135
1136@c *********************************************************************
1137@node Concept Index
1138@unnumbered Concept Index
1139@printindex cp
1140
1141@node Function Index
1142@unnumbered Function Index
1143@printindex fn
1144
1145@bye
1146
1147@c Local Variables:
1148@c ispell-local-dictionary: "american";
1149@c End: