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