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