Add hydra.gnu.org's narinfo signing public key.
[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
7df7a74e
NK
11
12@copying
425b0bfc 13Copyright @copyright{} 2012, 2013, 2014 Ludovic Courtès@*
7df7a74e
NK
14Copyright @copyright{} 2013 Andreas Enge@*
15Copyright @copyright{} 2013 Nikita Karetnikov
16
17Permission is granted to copy, distribute and/or modify this document
18under the terms of the GNU Free Documentation License, Version 1.3 or
19any later version published by the Free Software Foundation; with no
20Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
21copy of the license is included in the section entitled ``GNU Free
22Documentation License''.
23@end copying
568717fd 24
eeaf4427 25@dircategory Package management
568717fd
LC
26@direntry
27* guix: (guix). Guix, the functional package manager.
e49951eb 28* guix package: (guix)Invoking guix package
eeaf4427 29 Managing packages with Guix.
e49951eb 30* guix build: (guix)Invoking guix build
568717fd
LC
31 Building packages with Guix.
32@end direntry
568717fd
LC
33
34@titlepage
7730d112
LC
35@title GNU Guix Reference Manual
36@subtitle Using the GNU Guix Functional Package Manager
568717fd 37@author Ludovic Courtès
da7cabd4 38@author Andreas Enge
acc08466 39@author Nikita Karetnikov
568717fd
LC
40
41@page
42@vskip 0pt plus 1filll
43Edition @value{EDITION} @*
44@value{UPDATED} @*
45
7df7a74e 46@insertcopying
568717fd
LC
47@end titlepage
48
568717fd
LC
49@contents
50
51@c *********************************************************************
52@node Top
f8348b91 53@top GNU Guix
568717fd 54
f8348b91
LC
55This document describes GNU Guix version @value{VERSION}, a functional
56package management tool written for the GNU system.
568717fd
LC
57
58@menu
59* Introduction:: What is Guix about?
bd5e766b 60* Installation:: Installing Guix.
eeaf4427 61* Package Management:: Package installation, upgrade, etc.
568717fd
LC
62* Programming Interface:: Using Guix in Scheme.
63* Utilities:: Package management commands.
a1ba8475 64* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 65* Contributing:: Your help needed!
568717fd
LC
66
67* Acknowledgments:: Thanks!
68* GNU Free Documentation License:: The license of this manual.
69* Concept Index:: Concepts.
70* Function Index:: Functions.
71@end menu
72
73@c *********************************************************************
74@node Introduction
75@chapter Introduction
76
c80e7e55
LC
77GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
78using the international phonetic alphabet (IPA).} is a functional
79package management tool for the GNU system. Package management consists
4bfc4ea3
NK
80of all activities that relate to building packages from sources,
81honoring their build-time and run-time dependencies,
c80e7e55
LC
82installing packages in user environments, upgrading installed packages
83to new versions or rolling back to a previous set, removing unused
84software packages, etc.
568717fd
LC
85
86@cindex functional package management
87The term @dfn{functional} refers to a specific package management
88discipline. In Guix, the package build and installation process is seen
4bfc4ea3
NK
89as a function, in the mathematical sense. That function takes inputs,
90such as build scripts, a compiler, and libraries, and
91returns an installed package. As a pure function, its result depends
568717fd
LC
92solely on its inputs---for instance, it cannot refer to software or
93scripts that were not explicitly passed as inputs. A build function
4bfc4ea3
NK
94always produces the same result when passed a given set of inputs. It
95cannot alter the system's environment in
568717fd
LC
96any way; for instance, it cannot create, modify, or delete files outside
97of its build and installation directories. This is achieved by running
e900c503 98build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 99explicit inputs are visible.
568717fd 100
e531ac2a 101@cindex store
568717fd 102The result of package build functions is @dfn{cached} in the file
e531ac2a
LC
103system, in a special directory called @dfn{the store} (@pxref{The
104Store}). Each package is installed in a directory of its own, in the
834129e0 105store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
106a hash of all the inputs used to build that package; thus, changing an
107input yields a different directory name.
108
109This approach is the foundation of Guix's salient features: support for
4bfc4ea3 110transactional package upgrade and rollback, per-user installation, and
eeaf4427 111garbage collection of packages (@pxref{Features}).
568717fd 112
4bfc4ea3 113Guix has a command-line interface, which allows users to build, install,
568717fd 114upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 115
a1ba8475
LC
116Last but not least, Guix is used to build a distribution of the GNU
117system, with many GNU and non-GNU free software packages. @xref{GNU
118Distribution}.
119
bd5e766b
LC
120@c *********************************************************************
121@node Installation
122@chapter Installation
123
48febeb8
LC
124GNU Guix is available for download from its website at
125@url{http://www.gnu.org/software/guix/}. This section describes the
126software requirements of Guix, as well as how to install it and get
127ready to use it.
bd5e766b 128
b22a12fd 129The build procedure for Guix is the same as for other GNU software, and
1da983b9 130is not covered here. Please see the files @file{README} and
b22a12fd
LC
131@file{INSTALL} in the Guix source tree for additional details.
132
bd5e766b
LC
133@menu
134* Requirements:: Software needed to build and run Guix.
135* Setting Up the Daemon:: Preparing the build daemon's environment.
136* Invoking guix-daemon:: Running the build daemon.
137@end menu
138
139@node Requirements
140@section Requirements
141
142GNU Guix depends on the following packages:
143
144@itemize
4a328f73 145@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.5 or later;
bd5e766b
LC
146@item @url{http://gnupg.org/, GNU libgcrypt}
147@end itemize
148
149Unless @code{--disable-daemon} was passed to @command{configure}, the
150following packages are also needed:
151
152@itemize
153@item @url{http://sqlite.org, SQLite 3}
154@item @url{http://www.bzip.org, libbz2}
155@item @url{http://gcc.gnu.org, GCC's g++}
156@end itemize
157
4bfc4ea3
NK
158When a working installation of @url{http://nixos.org/nix/, the Nix package
159manager} is available, you
bd5e766b 160can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 161Nix replaces the three dependencies above.
bd5e766b 162
b22a12fd
LC
163Guix is compatible with Nix, so it is possible to share the same store
164between both. To do so, you must pass @command{configure} not only the
165same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
166@code{--localstatedir} value. The latter is essential because it
167specifies where the database that stores metadata about the store is
834129e0 168located, among other things. The default values for Nix are
b22a12fd 169@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
170Note that @code{--disable-daemon} is not required if
171your goal is to share the store with Nix.
b22a12fd 172
bd5e766b
LC
173@node Setting Up the Daemon
174@section Setting Up the Daemon
175
176@cindex daemon
177Operations such as building a package or running the garbage collector
49e6291a 178are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
179behalf of clients. Only the daemon may access the store and its
180associated database. Thus, any operation that manipulates the store
181goes through the daemon. For instance, command-line tools such as
e49951eb 182@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
183daemon (@i{via} remote procedure calls) to instruct it what to do.
184
49e6291a
LC
185The following sections explain how to prepare the build daemon's
186environment.
187
188@menu
189* Build Environment Setup:: Preparing the isolated build environment.
190* Daemon Offload Setup:: Offloading builds to remote machines.
191@end menu
192
193@node Build Environment Setup
194@subsection Build Environment Setup
195
bd5e766b
LC
196In a standard multi-user setup, Guix and its daemon---the
197@command{guix-daemon} program---are installed by the system
834129e0 198administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
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
091196b3
LC
219@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
220@c for why `-G' is needed.
bd5e766b
LC
221@example
222# groupadd guix-builder
223# for i in `seq 1 10`;
224 do
091196b3
LC
225 useradd -g guix-builder -G guix-builder \
226 -d /var/empty -s `which nologin` \
4d1a2b50
LC
227 -c "Guix build user $i" --system \
228 guix-builder$i;
bd5e766b
LC
229 done
230@end example
231
232@noindent
233The @code{guix-daemon} program may then be run as @code{root} with:
234
235@example
236# guix-daemon --build-users-group=guix-builder
237@end example
238
e900c503 239@cindex chroot
b095792f
LC
240@noindent
241This way, the daemon starts build processes in a chroot, under one of
242the @code{guix-builder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
243environment contains nothing but:
244
245@c Keep this list in sync with libstore/build.cc! -----------------------
246@itemize
247@item
248the @code{/dev} and @code{/proc} directories@footnote{On some systems
249@code{/dev/shm}, which supports shared memory, is a symlink to another
250directory such as @code{/run/shm}, that is @emph{not} is the chroot.
251When that is the case, shared memory support is unavailable in the
252chroot environment. The workaround is to make sure that @file{/dev/shm}
253is directly a @code{tmpfs} mount point.};
254
255@item
256@file{/etc/passwd} with an entry for the current user and an entry for
257user @file{nobody};
258
259@item
260@file{/etc/group} with an entry for the user's group;
261
262@item
263@file{/etc/hosts} with an entry that maps @code{localhost} to
264@code{127.0.0.1};
265
266@item
267a writable @file{/tmp} directory.
268@end itemize
b095792f 269
d43eb499 270If you are installing Guix as an unprivileged user, it is still
bd5e766b
LC
271possible to run @command{guix-daemon}. However, build processes will
272not be isolated from one another, and not from the rest of the system.
273Thus, build processes may interfere with each other, and may access
274programs, libraries, and other files available on the system---making it
275much harder to view them as @emph{pure} functions.
276
49e6291a
LC
277
278@node Daemon Offload Setup
279@subsection Using the Offload Facility
280
281@cindex offloading
4ec2e92d
LC
282@cindex build hook
283When desired, the build daemon can @dfn{offload}
284derivation builds to other machines
49e6291a
LC
285running Guix, using the @code{offload} @dfn{build hook}. When that
286feature is enabled, a list of user-specified build machines is read from
287@file{/etc/guix/machines.scm}; anytime a build is requested, for
288instance via @code{guix build}, the daemon attempts to offload it to one
289of the machines that satisfies the derivation's constraints, in
290particular its system type---e.g., @file{x86_64-linux}. Missing
291prerequisites for the build are copied over SSH to the target machine,
292which then proceeds with the build; upon success the output(s) of the
293build are copied back to the initial machine.
294
4ec2e92d 295The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
296
297@example
298(list (build-machine
299 (name "eightysix.example.org")
300 (system "x86_64-linux")
301 (user "bob")
302 (speed 2.)) ; incredibly fast!
303
304 (build-machine
305 (name "meeps.example.org")
306 (system "mips64el-linux")
307 (user "alice")
308 (private-key
309 (string-append (getenv "HOME")
310 "/.ssh/id-rsa-for-guix"))))
311@end example
312
313@noindent
314In the example above we specify a list of two build machines, one for
315the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
316architecture.
317
318In fact, this file is---not surprisingly!---a Scheme file that is
319evaluated when the @code{offload} hook is started. Its return value
320must be a list of @code{build-machine} objects. While this example
321shows a fixed list of build machines, one could imagine, say, using
322DNS-SD to return a list of potential build machines discovered in the
323local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
324Avahi in Guile Scheme Programs}).
325
326The compulsory fields for a @code{build-machine} declaration are:
49e6291a
LC
327
328@table @code
329
330@item name
331The remote machine's host name.
332
333@item system
334The remote machine's system type.
335
336@item user
337The user account to use when connecting to the remote machine over SSH.
338Note that the SSH key pair must @emph{not} be passphrase-protected, to
339allow non-interactive logins.
340
341@end table
342
343@noindent
4ec2e92d 344A number of optional fields may be specified:
49e6291a
LC
345
346@table @code
347
cecd72d5
LC
348@item port
349Port number of the machine's SSH server (default: 22).
350
49e6291a
LC
351@item private-key
352The SSH private key file to use when connecting to the machine.
353
354@item parallel-builds
355The number of builds that may run in parallel on the machine (1 by
356default.)
357
358@item speed
359A ``relative speed factor''. The offload scheduler will tend to prefer
360machines with a higher speed factor.
361
362@item features
363A list of strings denoting specific features supported by the machine.
364An example is @code{"kvm"} for machines that have the KVM Linux modules
365and corresponding hardware support. Derivations can request features by
366name, and they will be scheduled on matching build machines.
367
368@end table
369
370The @code{guix} command must be in the search path on the build
371machines, since offloading works by invoking the @code{guix archive} and
372@code{guix build} commands.
373
374There's one last thing to do once @file{machines.scm} is in place. As
375explained above, when offloading, files are transferred back and forth
376between the machine stores. For this to work, you need to generate a
377key pair to allow the daemon to export signed archives of files from the
378store (@pxref{Invoking guix archive}):
379
380@example
381# guix archive --generate-key
382@end example
383
384@noindent
385Thus, when receiving files, a machine's build daemon can make sure they
386are genuine, have not been tampered with, and that they are signed by an
387authorized key.
388
389
bd5e766b
LC
390@node Invoking guix-daemon
391@section Invoking @command{guix-daemon}
392
393The @command{guix-daemon} program implements all the functionality to
394access the store. This includes launching build processes, running the
395garbage collector, querying the availability of a build result, etc. It
396is normally run as @code{root} like this:
397
398@example
399# guix-daemon --build-users-group=guix-builder
400@end example
401
402@noindent
403For details on how to set it up, @ref{Setting Up the Daemon}.
404
e900c503
LC
405@cindex chroot
406@cindex container, build environment
407@cindex build environment
408@cindex reproducible builds
bd5e766b
LC
409By default, @command{guix-daemon} launches build processes under
410different UIDs, taken from the build group specified with
411@code{--build-users-group}. In addition, each build process is run in a
412chroot environment that only contains the subset of the store that the
413build process depends on, as specified by its derivation
414(@pxref{Programming Interface, derivation}), plus a set of specific
415system directories. By default, the latter contains @file{/dev} and
e900c503
LC
416@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
417@dfn{container}: in addition to having its own file system tree, it has
418a separate mount name space, its own PID name space, network name space,
419etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b
LC
420
421The following command-line options are supported:
422
423@table @code
424@item --build-users-group=@var{group}
425Take users from @var{group} to run build processes (@pxref{Setting Up
426the Daemon, build users}).
427
6858f9d1 428@item --no-substitutes
b5385b52 429@cindex substitutes
6858f9d1
LC
430Do not use substitutes for build products. That is, always build things
431locally instead of allowing downloads of pre-built binaries.
432
b5385b52
LC
433By default substitutes are used, unless the client---such as the
434@command{guix package} command---is explicitly invoked with
435@code{--no-substitutes}.
436
437When the daemon runs with @code{--no-substitutes}, clients can still
438explicitly enable substitution @i{via} the @code{set-build-options}
439remote procedure call (@pxref{The Store}).
440
4ec2e92d
LC
441@cindex build hook
442@item --no-build-hook
443Do not use the @dfn{build hook}.
444
445The build hook is a helper program that the daemon can start and to
446which it submits build requests. This mechanism is used to offload
447builds to other machines (@pxref{Daemon Offload Setup}).
448
bd5e766b
LC
449@item --cache-failures
450Cache build failures. By default, only successful builds are cached.
451
452@item --cores=@var{n}
453@itemx -c @var{n}
454Use @var{n} CPU cores to build each derivation; @code{0} means as many
455as available.
456
457The default value is @code{1}, but it may be overridden by clients, such
e49951eb
MW
458as the @code{--cores} option of @command{guix build} (@pxref{Invoking
459guix build}).
bd5e766b
LC
460
461The effect is to define the @code{NIX_BUILD_CORES} environment variable
462in the build process, which can then use it to exploit internal
463parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
464
465@item --max-jobs=@var{n}
466@itemx -M @var{n}
467Allow at most @var{n} build jobs in parallel. The default value is
468@code{1}.
469
470@item --debug
471Produce debugging output.
472
473This is useful to debug daemon start-up issues, but then it may be
474overridden by clients, for example the @code{--verbosity} option of
e49951eb 475@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
476
477@item --chroot-directory=@var{dir}
478Add @var{dir} to the build chroot.
479
480Doing this may change the result of build processes---for instance if
481they use optional dependencies found in @var{dir} when it is available,
482and not otherwise. For that reason, it is not recommended to do so.
483Instead, make sure that each derivation declares all the inputs that it
484needs.
485
486@item --disable-chroot
487Disable chroot builds.
488
489Using this option is not recommended since, again, it would allow build
490processes to gain access to undeclared dependencies.
491
492@item --disable-log-compression
493Disable compression of the build logs.
494
1da983b9
LC
495Unless @code{--lose-logs} is used, all the build logs are kept in the
496@var{localstatedir}. To save space, the daemon automatically compresses
497them with bzip2 by default. This option disables that.
498
bd5e766b
LC
499@item --disable-store-optimization
500Disable automatic file ``deduplication'' in the store.
501
1da983b9
LC
502By default, files added to the store are automatically ``deduplicated'':
503if a newly added file is identical as another one found in the store,
504the daemon makes the new file a hard link to the other file. This
505slightly increases the input/output load at the end of a build process.
506This option disables this.
507
6e37066e
LC
508@item --gc-keep-outputs[=yes|no]
509Tell whether the garbage collector (GC) must keep outputs of live
510derivations.
511
512When set to ``yes'', the GC will keep the outputs of any live derivation
513available in the store---the @code{.drv} files. The default is ``no'',
514meaning that derivation outputs are kept only if they are GC roots.
515
516@item --gc-keep-derivations[=yes|no]
517Tell whether the garbage collector (GC) must keep derivations
518corresponding to live outputs.
519
520When set to ``yes'', as is the case by default, the GC keeps
521derivations---i.e., @code{.drv} files---as long as at least one of their
522outputs is live. This allows users to keep track of the origins of
523items in their store. Setting it to ``no'' saves a bit of disk space.
524
525Note that when both @code{--gc-keep-derivations} and
526@code{--gc-keep-outputs} are used, the effect is to keep all the build
527prerequisites (the sources, compiler, libraries, and other build-time
528tools) of live objects in the store, regardless of whether these
529prerequisites are live. This is convenient for developers since it
530saves rebuilds or downloads.
531
bd5e766b
LC
532@item --impersonate-linux-2.6
533On Linux-based systems, impersonate Linux 2.6. This means that the
534kernel's @code{uname} system call will report 2.6 as the release number.
535
536This might be helpful to build programs that (usually wrongfully) depend
537on the kernel version number.
538
539@item --lose-logs
540Do not keep build logs. By default they are kept under
541@code{@var{localstatedir}/nix/log}.
542
543@item --system=@var{system}
544Assume @var{system} as the current system type. By default it is the
545architecture/kernel pair found at configure time, such as
546@code{x86_64-linux}.
b8d2aa26
LC
547
548@item --listen=@var{socket}
549Listen for connections on @var{socket}, the file name of a Unix-domain
550socket. The default socket is
551@file{@var{localstatedir}/daemon-socket/socket}. This option is only
552useful in exceptional circumstances, such as if you need to run several
553daemons on the same machine.
bd5e766b
LC
554@end table
555
556
eeaf4427
LC
557@c *********************************************************************
558@node Package Management
559@chapter Package Management
560
f8348b91 561The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
562remove software packages, without having to know about their build
563procedure or dependencies. Guix also goes beyond this obvious set of
564features.
565
566This chapter describes the main features of Guix, as well as the package
567management tools it provides.
568
569@menu
570* Features:: How Guix will make your life brighter.
e49951eb 571* Invoking guix package:: Package installation, removal, etc.
760c60d6 572* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 573* Invoking guix gc:: Running the garbage collector.
f651b477 574* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 575* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
576@end menu
577
578@node Features
579@section Features
580
581When using Guix, each package ends up in the @dfn{package store}, in its
582own directory---something that resembles
834129e0 583@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
eeaf4427
LC
584
585Instead of referring to these directories, users have their own
586@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
587use. These profiles are stored within each user's home directory, at
588@code{$HOME/.guix-profile}.
eeaf4427 589
821b0015 590For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 591@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 592@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
593@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
594simply continues to point to
834129e0 595@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 596coexist on the same system without any interference.
eeaf4427 597
e49951eb
MW
598The @command{guix package} command is the central tool to manage
599packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 600profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
601
602The command provides the obvious install, remove, and upgrade
603operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 604the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 605@command{guix package} process is terminated during the transaction,
eeaf4427
LC
606or if a power outage occurs during the transaction, then the user's
607profile remains in its previous state, and remains usable.
608
609In addition, any package transaction may be @emph{rolled back}. So, if,
610for example, an upgrade installs a new version of a package that turns
611out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
612of their profile, which was known to work well. Similarly, the global
613system configuration is subject to transactional upgrades and roll-back
614(@pxref{Using the Configuration System}).
eeaf4427
LC
615
616All those packages in the package store may be @emph{garbage-collected}.
617Guix can determine which packages are still referenced by the user
fe8ff028 618profiles, and remove those that are provably no longer referenced
e49951eb 619(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
620generations of their profile so that the packages they refer to can be
621collected.
eeaf4427 622
e900c503
LC
623@cindex reproducibility
624@cindex reproducible builds
eeaf4427
LC
625Finally, Guix takes a @dfn{purely functional} approach to package
626management, as described in the introduction (@pxref{Introduction}).
834129e0 627Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
628inputs that were used to build that package---compiler, libraries, build
629scripts, etc. This direct correspondence allows users to make sure a
630given package installation matches the current state of their
e900c503
LC
631distribution. It also helps maximize @dfn{build reproducibility}:
632thanks to the isolated build environments that are used, a given build
633is likely to yield bit-identical files when performed on different
634machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 635
18f2887b 636@cindex substitute
eeaf4427 637This foundation allows Guix to support @dfn{transparent binary/source
834129e0 638deployment}. When a pre-built binary for a @file{/gnu/store} path is
18f2887b
LC
639available from an external source---a @dfn{substitute}, Guix just
640downloads it@footnote{@c XXX: Remove me when outdated.
641As of version @value{VERSION}, substitutes are downloaded from
642@url{http://hydra.gnu.org/} but are @emph{not} authenticated---i.e.,
643Guix cannot tell whether binaries it downloaded have been tampered with,
644nor whether they come from the genuine @code{gnu.org} build farm. This
645will be fixed in future versions. In the meantime, concerned users can
646opt for @code{--no-substitutes} (@pxref{Invoking guix-daemon}).};
647otherwise, it builds the package from source, locally.
eeaf4427 648
e49951eb
MW
649@node Invoking guix package
650@section Invoking @command{guix package}
eeaf4427 651
e49951eb 652The @command{guix package} command is the tool that allows users to
eeaf4427
LC
653install, upgrade, and remove packages, as well as rolling back to
654previous configurations. It operates only on the user's own profile,
655and works with normal user privileges (@pxref{Features}). Its syntax
656is:
657
658@example
e49951eb 659guix package @var{options}
eeaf4427
LC
660@end example
661
ba55b1cb 662Primarily, @var{options} specifies the operations to be performed during
eeaf4427
LC
663the transaction. Upon completion, a new profile is created, but
664previous generations of the profile remain available, should the user
665want to roll back.
666
6447738c
MW
667For example, to remove @code{lua} and install @code{guile} and
668@code{guile-cairo} in a single transaction:
669
670@example
671guix package -r lua -i guile guile-cairo
672@end example
673
b9e5c0a9 674For each user, a symlink to the user's default profile is automatically
0ec1af59 675created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
676current generation of the user's default profile. Thus, users can add
677@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
678variable, and so on.
679
0ec1af59
LC
680In a multi-user setup, user profiles must be stored in a place
681registered as a @dfn{garbage-collector root}, which
e49951eb 682@file{$HOME/.guix-profile} points to (@pxref{Invoking guix gc}). That
0ec1af59
LC
683directory is normally
684@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
685@var{localstatedir} is the value passed to @code{configure} as
686@code{--localstatedir}, and @var{user} is the user name. It must be
687created by @code{root}, with @var{user} as the owner. When it does not
70c43291
LC
688exist, or is not owned by @var{user}, @command{guix package} emits an
689error about it.
0ec1af59
LC
690
691The @var{options} can be among the following:
692
eeaf4427
LC
693@table @code
694
6447738c
MW
695@item --install=@var{package} @dots{}
696@itemx -i @var{package} @dots{}
697Install the specified @var{package}s.
eeaf4427 698
6447738c 699Each @var{package} may specify either a simple package name, such as
eeaf4427 700@code{guile}, or a package name followed by a hyphen and version number,
dc5669cd
MW
701such as @code{guile-1.8.8}. If no version number is specified, the
702newest available version will be selected. In addition, @var{package}
703may contain a colon, followed by the name of one of the outputs of the
6e721c4d 704package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
e7f34eb0
LC
705(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
706name (and optionally version) are searched for among the GNU
707distribution modules (@pxref{Package Modules}).
eeaf4427 708
461572cc
LC
709@cindex propagated inputs
710Sometimes packages have @dfn{propagated inputs}: these are dependencies
711that automatically get installed along with the required package.
712
713An example is the GNU MPC library: its C header files refer to those of
714the GNU MPFR library, which in turn refer to those of the GMP library.
715Thus, when installing MPC, the MPFR and GMP libraries also get installed
716in the profile; removing MPC also removes MPFR and GMP---unless they had
717also been explicitly installed independently.
718
ba7ea5ce 719Besides, packages sometimes rely on the definition of environment
5924080d 720variables for their search paths (see explanation of
ba7ea5ce 721@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
722environment variable definitions are reported here.
723
ef010c0f 724@c XXX: keep me up-to-date
5924080d 725Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
726availability of a newer upstream version. In the future, it may provide
727the option of installing directly from the upstream version, even if
728that version is not yet in the distribution.
729
5d4b411f
LC
730@item --install-from-expression=@var{exp}
731@itemx -e @var{exp}
732Install the package @var{exp} evaluates to.
733
734@var{exp} must be a Scheme expression that evaluates to a
735@code{<package>} object. This option is notably useful to disambiguate
736between same-named variants of a package, with expressions such as
737@code{(@@ (gnu packages base) guile-final)}.
738
739Note that this option installs the first output of the specified
740package, which may be insufficient when needing a specific output of a
741multiple-output package.
742
6447738c
MW
743@item --remove=@var{package} @dots{}
744@itemx -r @var{package} @dots{}
745Remove the specified @var{package}s.
eeaf4427 746
6447738c 747As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
748and/or output name in addition to the package name. For instance,
749@code{-r glibc:debug} would remove the @code{debug} output of
750@code{glibc}.
751
6447738c
MW
752@item --upgrade[=@var{regexp} @dots{}]
753@itemx -u [@var{regexp} @dots{}]
754Upgrade all the installed packages. If one or more @var{regexp}s are
755specified, upgrade only installed packages whose name matches a
756@var{regexp}.
eeaf4427 757
f651b477
LC
758Note that this upgrades package to the latest version of packages found
759in the distribution currently installed. To update your distribution,
760you should regularly run @command{guix pull} (@pxref{Invoking guix
761pull}).
762
24e262f0
LC
763@item --roll-back
764Roll back to the previous @dfn{generation} of the profile---i.e., undo
765the last transaction.
766
767When combined with options such as @code{--install}, roll back occurs
768before any other actions.
769
d9307267 770When rolling back from the first generation that actually contains
4b2bc804
NK
771installed packages, the profile is made to point to the @dfn{zeroth
772generation}, which contains no files apart from its own meta-data.
d9307267 773
82fe08ed
LC
774Installing, removing, or upgrading packages from a generation that has
775been rolled back to overwrites previous future generations. Thus, the
776history of a profile's generations is always linear.
777
5924080d
LC
778@item --search-paths
779@cindex search paths
780Report environment variable definitions, in Bash syntax, that may be
781needed in order to use the set of installed packages. These environment
782variables are used to specify @dfn{search paths} for files used by some
783of the installed packages.
784
785For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
786environment variables to be defined so it can look for headers and
787libraries in the user's profile (@pxref{Environment Variables,,, gcc,
788Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
789library are installed in the profile, then @code{--search-paths} will
790suggest setting these variables to @code{@var{profile}/include} and
791@code{@var{profile}/lib}, respectively.
792
eeaf4427
LC
793@item --profile=@var{profile}
794@itemx -p @var{profile}
795Use @var{profile} instead of the user's default profile.
796
70915c1a
LC
797@item --verbose
798Produce verbose output. In particular, emit the environment's build log
799on the standard error port.
800
eeaf4427
LC
801@item --bootstrap
802Use the bootstrap Guile to build the profile. This option is only
803useful to distribution developers.
804
805@end table
806
e49951eb 807In addition to these actions @command{guix package} supports the
733b4130
LC
808following options to query the current state of a profile, or the
809availability of packages:
eeaf4427 810
733b4130
LC
811@table @option
812
acc08466
NK
813@item --search=@var{regexp}
814@itemx -s @var{regexp}
815List the available packages whose synopsis or description matches
299112d3
LC
816@var{regexp}. Print all the meta-data of matching packages in
817@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
818GNU recutils manual}).
acc08466 819
299112d3
LC
820This allows specific fields to be extracted using the @command{recsel}
821command, for instance:
822
823@example
e49951eb 824$ guix package -s malloc | recsel -p name,version
299112d3
LC
825name: glibc
826version: 2.17
827
828name: libgc
829version: 7.2alpha6
830@end example
acc08466 831
733b4130
LC
832@item --list-installed[=@var{regexp}]
833@itemx -I [@var{regexp}]
bd9bde1c
LC
834List the currently installed packages in the specified profile, with the
835most recently installed packages shown last. When @var{regexp} is
836specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
837
838For each installed package, print the following items, separated by
839tabs: the package name, its version string, the part of the package that
840is installed (for instance, @code{out} for the default output,
841@code{include} for its headers, etc.), and the path of this package in
842the store.
843
64fc89b6
LC
844@item --list-available[=@var{regexp}]
845@itemx -A [@var{regexp}]
a1ba8475
LC
846List packages currently available in the software distribution
847(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
848installed packages whose name matches @var{regexp}.
64fc89b6
LC
849
850For each package, print the following items separated by tabs: its name,
6e721c4d
LC
851its version string, the parts of the package (@pxref{Packages with
852Multiple Outputs}), and the source location of its definition.
64fc89b6 853
f566d765
LC
854@item --list-generations[=@var{pattern}]
855@itemx -l [@var{pattern}]
856Return a list of generations along with their creation dates; for each
857generation, show the installed packages, with the most recently
4b2bc804
NK
858installed packages shown last. Note that the zeroth generation is never
859shown.
f566d765
LC
860
861For each installed package, print the following items, separated by
862tabs: the name of a package, its version string, the part of the package
863that is installed (@pxref{Packages with Multiple Outputs}), and the
864location of this package in the store.
865
866When @var{pattern} is used, the command returns only matching
867generations. Valid patterns include:
868
869@itemize
870@item @emph{Integers and comma-separated integers}. Both patterns denote
871generation numbers. For instance, @code{--list-generations=1} returns
872the first one.
873
874And @code{--list-generations=1,8,2} outputs three generations in the
875specified order. Neither spaces nor trailing commas are allowed.
876
877@item @emph{Ranges}. @code{--list-generations=2..9} prints the
878specified generations and everything in between. Note that the start of
879a range must be lesser than its end.
880
881It is also possible to omit the endpoint. For example,
882@code{--list-generations=2..}, returns all generations starting from the
883second one.
884
885@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
886or months by passing an integer along with the first letter of the
d7ddb257
LC
887duration. For example, @code{--list-generations=20d} lists generations
888that are up to 20 days old.
f566d765
LC
889@end itemize
890
b7884ca3
NK
891@item --delete-generations[=@var{pattern}]
892@itemx -d [@var{pattern}]
d7ddb257
LC
893When @var{pattern} is omitted, delete all generations except the current
894one.
b7884ca3
NK
895
896This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
897When @var{pattern} is specified, delete the matching generations. When
898@var{pattern} specifies a duration, generations @emph{older} than the
899specified duration match. For instance, @code{--delete-generations=1m}
900deletes generations that are more than one month old.
901
902If the current generation matches, it is deleted atomically---i.e., by
903switching to the previous available generation. Note that the zeroth
904generation is never deleted.
b7884ca3 905
1bb9900a
LC
906Note that deleting generations prevents roll-back to them.
907Consequently, this command must be used with care.
908
733b4130 909@end table
eeaf4427 910
70ee5642
LC
911Finally, since @command{guix package} may actually start build
912processes, it supports all the common build options that @command{guix
913build} supports (@pxref{Invoking guix build, common build options}).
914
6e721c4d
LC
915@node Packages with Multiple Outputs
916@section Packages with Multiple Outputs
917
918@cindex multiple-output packages
919@cindex package outputs
920
921Often, packages defined in Guix have a single @dfn{output}---i.e., the
922source package leads exactly one directory in the store. When running
923@command{guix package -i glibc}, one installs the default output of the
924GNU libc package; the default output is called @code{out}, but its name
925can be omitted as shown in this command. In this particular case, the
926default output of @code{glibc} contains all the C header files, shared
927libraries, static libraries, Info documentation, and other supporting
928files.
929
930Sometimes it is more appropriate to separate the various types of files
931produced from a single source package into separate outputs. For
932instance, the GLib C library (used by GTK+ and related packages)
933installs more than 20 MiB of reference documentation as HTML pages.
934To save space for users who do not need it, the documentation goes to a
935separate output, called @code{doc}. To install the main GLib output,
936which contains everything but the documentation, one would run:
937
938@example
939guix package -i glib
940@end example
941
942The command to install its documentation is:
943
944@example
945guix package -i glib:doc
946@end example
947
948Some packages install programs with different ``dependency footprints''.
949For instance, the WordNet package install both command-line tools and
950graphical user interfaces (GUIs). The former depend solely on the C
951library, whereas the latter depend on Tcl/Tk and the underlying X
952libraries. In this case, we leave the command-line tools in the default
953output, whereas the GUIs are in a separate output. This allows users
954who do not need the GUIs to save space.
955
956There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
957Other conventional output names include @code{lib} for libraries and
958possibly header files, @code{bin} for stand-alone programs, and
959@code{debug} for debugging information (@pxref{Installing Debugging
960Files}). The outputs of a packages are listed in the third column of
961the output of @command{guix package --list-available} (@pxref{Invoking
962guix package}).
6e721c4d 963
eeaf4427 964
e49951eb
MW
965@node Invoking guix gc
966@section Invoking @command{guix gc}
fe8ff028
LC
967
968@cindex garbage collector
969Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 970The @command{guix gc} command allows users to explicitly run the garbage
834129e0 971collector to reclaim space from the @file{/gnu/store} directory.
fe8ff028
LC
972
973The garbage collector has a set of known @dfn{roots}: any file under
834129e0 974@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
975cannot be deleted; any other file is considered @dfn{dead} and may be
976deleted. The set of garbage collector roots includes default user
e49951eb
MW
977profiles, and may be augmented with @command{guix build --root}, for
978example (@pxref{Invoking guix build}).
fe8ff028 979
1bb9900a
LC
980Prior to running @code{guix gc --collect-garbage} to make space, it is
981often useful to remove old generations from user profiles; that way, old
982package builds referenced by those generations can be reclaimed. This
983is achieved by running @code{guix package --delete-generations}
984(@pxref{Invoking guix package}).
985
e49951eb 986The @command{guix gc} command has three modes of operation: it can be
fe8ff028
LC
987used to garbage-collect any dead files (the default), to delete specific
988files (the @code{--delete} option), or to print garbage-collector
989information. The available options are listed below:
990
991@table @code
992@item --collect-garbage[=@var{min}]
993@itemx -C [@var{min}]
834129e0 994Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
995sub-directories. This is the default operation when no option is
996specified.
997
998When @var{min} is given, stop once @var{min} bytes have been collected.
999@var{min} may be a number of bytes, or it may include a unit as a
1000suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes.
1001
1002When @var{min} is omitted, collect all the garbage.
1003
1004@item --delete
1005@itemx -d
1006Attempt to delete all the store files and directories specified as
1007arguments. This fails if some of the files are not in the store, or if
1008they are still live.
1009
1010@item --list-dead
1011Show the list of dead files and directories still present in the
1012store---i.e., files and directories no longer reachable from any root.
1013
1014@item --list-live
1015Show the list of live store files and directories.
ba8b732d
LC
1016
1017@end table
1018
1019In addition, the references among existing store files can be queried:
1020
1021@table @code
1022
1023@item --references
1024@itemx --referrers
1025List the references (respectively, the referrers) of store files given
1026as arguments.
1027
8e59fdd5
LC
1028@item --requisites
1029@itemx -R
1030List the requisites of the store files passed as arguments. Requisites
1031include the store files themselves, their references, and the references
1032of these, recursively. In other words, the returned list is the
1033@dfn{transitive closure} of the store files.
1034
fe8ff028
LC
1035@end table
1036
eeaf4427 1037
f651b477
LC
1038@node Invoking guix pull
1039@section Invoking @command{guix pull}
1040
1041Packages are installed or upgraded to the latest version available in
1042the distribution currently available on your local machine. To update
1043that distribution, along with the Guix tools, you must run @command{guix
1044pull}: the command downloads the latest Guix source code and package
1045descriptions, and deploys it.
1046
1047On completion, @command{guix package} will use packages and package
1048versions from this just-retrieved copy of Guix. Not only that, but all
1049the Guix commands and Scheme modules will also be taken from that latest
1050version. New @command{guix} sub-commands added by the update also
1051become available.
1052
1053The @command{guix pull} command is usually invoked with no arguments,
1054but it supports the following options:
1055
1056@table @code
1057@item --verbose
1058Produce verbose output, writing build logs to the standard error output.
1059
ab5d72ad
LC
1060@item --url=@var{url}
1061Download the source tarball of Guix from @var{url}.
1062
1063By default, the tarball is taken from its canonical address at
1064@code{gnu.org}, for the stable branch of Guix.
1065
f651b477
LC
1066@item --bootstrap
1067Use the bootstrap Guile to build the latest Guix. This option is only
1068useful to Guix developers.
1069@end table
1070
760c60d6
LC
1071
1072@node Invoking guix archive
1073@section Invoking @command{guix archive}
1074
1075The @command{guix archive} command allows users to @dfn{export} files
1076from the store into a single archive, and to later @dfn{import} them.
1077In particular, it allows store files to be transferred from one machine
1078to another machine's store. For example, to transfer the @code{emacs}
1079package to a machine connected over SSH, one would run:
1080
1081@example
1082guix archive --export emacs | ssh the-machine guix archive --import
1083@end example
1084
87236aed
LC
1085@noindent
1086However, note that, in this example, all of @code{emacs} and its
1087dependencies are transferred, regardless of what is already available in
1088the target machine's store. The @code{--missing} option can help figure
1089out which items are missing from the target's store.
1090
760c60d6 1091Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
1092comparable in spirit to `tar', but with a few noteworthy differences
1093that make it more appropriate for our purposes. First, rather than
1094recording all Unix meta-data for each file, the Nar format only mentions
1095the file type (regular, directory, or symbolic link); Unix permissions
1096and owner/group are dismissed. Second, the order in which directory
1097entries are stored always follows the order of file names according to
1098the C locale collation order. This makes archive production fully
1099deterministic.
1100
1101When exporting, the daemon digitally signs the contents of the archive,
1102and that digital signature is appended. When importing, the daemon
1103verifies the signature and rejects the import in case of an invalid
1104signature or if the signing key is not authorized.
760c60d6
LC
1105@c FIXME: Add xref to daemon doc about signatures.
1106
1107The main options are:
1108
1109@table @code
1110@item --export
1111Export the specified store files or packages (see below.) Write the
1112resulting archive to the standard output.
1113
1114@item --import
1115Read an archive from the standard input, and import the files listed
1116therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
1117signature, or if it is signed by a public key not among the authorized
1118keys (see @code{--authorize} below.)
554f26ec 1119
87236aed
LC
1120@item --missing
1121Read a list of store file names from the standard input, one per line,
1122and write on the standard output the subset of these files missing from
1123the store.
1124
554f26ec 1125@item --generate-key[=@var{parameters}]
f82cc5fd 1126@cindex signing, archives
554f26ec
LC
1127Generate a new key pair for the daemons. This is a prerequisite before
1128archives can be exported with @code{--export}. Note that this operation
1129usually takes time, because it needs to gather enough entropy to
1130generate the key pair.
1131
1132The generated key pair is typically stored under @file{/etc/guix}, in
1133@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
1134key, which must be kept secret.) When @var{parameters} is omitted, it
1135is a 4096-bit RSA key. Alternately, @var{parameters} can specify
1136@code{genkey} parameters suitable for Libgcrypt (@pxref{General
1137public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
1138Libgcrypt Reference Manual}).
f82cc5fd
LC
1139
1140@item --authorize
1141@cindex authorizing, archives
1142Authorize imports signed by the public key passed on standard input.
1143The public key must be in ``s-expression advanced format''---i.e., the
1144same format as the @file{signing-key.pub} file.
1145
1146The list of authorized keys is kept in the human-editable file
1147@file{/etc/guix/acl}. The file contains
1148@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
1149s-expressions''} and is structured as an access-control list in the
1150@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
1151(SPKI)}.
760c60d6
LC
1152@end table
1153
1154To export store files as an archive to the standard output, run:
1155
1156@example
1157guix archive --export @var{options} @var{specifications}...
1158@end example
1159
1160@var{specifications} may be either store file names or package
1161specifications, as for @command{guix package} (@pxref{Invoking guix
1162package}). For instance, the following command creates an archive
1163containing the @code{gui} output of the @code{git} package and the main
1164output of @code{emacs}:
1165
1166@example
834129e0 1167guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
760c60d6
LC
1168@end example
1169
1170If the specified packages are not built yet, @command{guix archive}
1171automatically builds them. The build process may be controlled with the
1172same options that can be passed to the @command{guix build} command
70ee5642 1173(@pxref{Invoking guix build, common build options}).
760c60d6
LC
1174
1175
568717fd
LC
1176@c *********************************************************************
1177@node Programming Interface
1178@chapter Programming Interface
1179
3dc1970d
LC
1180GNU Guix provides several Scheme programming interfaces (APIs) to
1181define, build, and query packages. The first interface allows users to
1182write high-level package definitions. These definitions refer to
1183familiar packaging concepts, such as the name and version of a package,
1184its build system, and its dependencies. These definitions can then be
1185turned into concrete build actions.
1186
ba55b1cb 1187Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 1188standard setup, the daemon has write access to the store---the
834129e0 1189@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
1190setup also has the daemon perform builds in chroots, under a specific
1191build users, to minimize interference with the rest of the system.
1192
1193@cindex derivation
1194Lower-level APIs are available to interact with the daemon and the
1195store. To instruct the daemon to perform a build action, users actually
1196provide it with a @dfn{derivation}. A derivation is a low-level
1197representation of the build actions to be taken, and the environment in
1198which they should occur---derivations are to package definitions what
1199assembly is to C programs.
1200
1201This chapter describes all these APIs in turn, starting from high-level
1202package definitions.
1203
568717fd 1204@menu
b860f382
LC
1205* Defining Packages:: Defining new packages.
1206* The Store:: Manipulating the package store.
1207* Derivations:: Low-level interface to package derivations.
1208* The Store Monad:: Purely functional interface to the store.
568717fd
LC
1209@end menu
1210
1211@node Defining Packages
1212@section Defining Packages
1213
3dc1970d
LC
1214The high-level interface to package definitions is implemented in the
1215@code{(guix packages)} and @code{(guix build-system)} modules. As an
1216example, the package definition, or @dfn{recipe}, for the GNU Hello
1217package looks like this:
1218
1219@example
e7f34eb0
LC
1220(define-module (gnu packages hello)
1221 #:use-module (guix packages)
1222 #:use-module (guix download)
1223 #:use-module (guix build-system gnu)
1224 #:use-module (guix licenses))
b22a12fd 1225
3dc1970d
LC
1226(define hello
1227 (package
1228 (name "hello")
1229 (version "2.8")
1230 (source (origin
1231 (method url-fetch)
1232 (uri (string-append "mirror://gnu/hello/hello-" version
1233 ".tar.gz"))
1234 (sha256
1235 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
1236 (build-system gnu-build-system)
1237 (inputs `(("gawk" ,gawk)))
1238 (synopsis "GNU Hello")
1239 (description "Yeah...")
1240 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 1241 (license gpl3+)))
3dc1970d
LC
1242@end example
1243
1244@noindent
1245Without being a Scheme expert, the reader may have guessed the meaning
e7f34eb0 1246of the various fields here. This expression binds variable @code{hello}
3dc1970d
LC
1247to a @code{<package>} object, which is essentially a record
1248(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
1249This package object can be inspected using procedures found in the
1250@code{(guix packages)} module; for instance, @code{(package-name hello)}
1251returns---surprise!---@code{"hello"}.
1252
e7f34eb0
LC
1253In the example above, @var{hello} is defined into a module of its own,
1254@code{(gnu packages hello)}. Technically, this is not strictly
1255necessary, but it is convenient to do so: all the packages defined in
1256modules under @code{(gnu packages @dots{})} are automatically known to
1257the command-line tools (@pxref{Package Modules}).
1258
3dc1970d
LC
1259There are a few points worth noting in the above package definition:
1260
1261@itemize
1262@item
1263The @code{source} field of the package is an @code{<origin>} object.
1264Here, the @code{url-fetch} method from @code{(guix download)} is used,
1265meaning that the source is a file to be downloaded over FTP or HTTP.
1266
1267The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
1268the GNU mirrors defined in @code{(guix download)}.
1269
1270The @code{sha256} field specifies the expected SHA256 hash of the file
1271being downloaded. It is mandatory, and allows Guix to check the
1272integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 1273base32 representation of the hash. You can obtain this information with
210cc920
LC
1274@code{guix download} (@pxref{Invoking guix download}) and @code{guix
1275hash} (@pxref{Invoking guix hash}).
3dc1970d 1276
f9cc8971
LC
1277@cindex patches
1278When needed, the @code{origin} form can also have a @code{patches} field
1279listing patches to be applied, and a @code{snippet} field giving a
1280Scheme expression to modify the source code.
1281
3dc1970d
LC
1282@item
1283@cindex GNU Build System
1284The @code{build-system} field is set to @var{gnu-build-system}. The
1285@var{gnu-build-system} variable is defined in the @code{(guix
1286build-system gnu)} module, and is bound to a @code{<build-system>}
1287object.
1288
1289Naturally, @var{gnu-build-system} represents the familiar GNU Build
1290System, and variants thereof (@pxref{Configuration, configuration and
1291makefile conventions,, standards, GNU Coding Standards}). In a
ba55b1cb 1292nutshell, packages using the GNU Build System may be configured, built,
3dc1970d
LC
1293and installed with the usual @code{./configure && make && make check &&
1294make install} command sequence. This is what @var{gnu-build-system}
1295does.
1296
1297In addition, @var{gnu-build-system} ensures that the ``standard''
1298environment for GNU packages is available. This includes tools such as
1299GCC, Coreutils, Bash, Make, Diffutils, and Patch.
1300
1301@item
1302The @code{inputs} field specifies inputs to the build process---i.e.,
1303build-time or run-time dependencies of the package. Here, we define an
1304input called @code{"gawk"} whose value is that of the @var{gawk}
1305variable; @var{gawk} is itself bound to a @code{<package>} object.
1306
1307Note that GCC, Coreutils, Bash, and other essential tools do not need to
1308be specified as inputs here. Instead, @var{gnu-build-system} takes care
1309of ensuring that they are present.
1310
1311However, any other dependencies need to be specified in the
1312@code{inputs} field. Any dependency not specified here will simply be
1313unavailable to the build process, possibly leading to a build failure.
1314@end itemize
1315
1316There are other fields that package definitions may provide. Of
1317particular interest is the @code{arguments} field. When specified, it
1318must be bound to a list of additional arguments to be passed to the
1319build system. For instance, the above definition could be augmented
1320with the following field initializer:
1321
1322@example
1323 (arguments `(#:tests? #f
1324 #:configure-flags '("--enable-silent-rules")))
1325@end example
1326
1327@noindent
1328These are keyword arguments (@pxref{Optional Arguments, keyword
1329arguments in Guile,, guile, GNU Guile Reference Manual}). They are
1330passed to @var{gnu-build-system}, which interprets them as meaning ``do
1331not run @code{make check}'', and ``run @file{configure} with the
874e6874
LC
1332@code{--enable-silent-rules} flag''. The value of these keyword
1333parameters is actually evaluated in the @dfn{build stratum}---i.e., by a
1334Guile process launched by the daemon (@pxref{Derivations}).
3dc1970d
LC
1335
1336Once a package definition is in place@footnote{Simple package
1337definitions like the one above may be automatically converted from the
e49951eb
MW
1338Nixpkgs distribution using the @command{guix import} command.}, the
1339package may actually be built using the @code{guix build} command-line
37166310
LC
1340tool (@pxref{Invoking guix build}). Eventually, updating the package
1341definition to a new upstream version can be partly automated by the
1342@command{guix refresh} command (@pxref{Invoking guix refresh}).
3dc1970d
LC
1343
1344Behind the scenes, a derivation corresponding to the @code{<package>}
1345object is first computed by the @code{package-derivation} procedure.
834129e0 1346That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 1347The build actions it prescribes may then be realized by using the
3dc1970d
LC
1348@code{build-derivations} procedure (@pxref{The Store}).
1349
1350@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
1351Return the @code{<derivation>} object of @var{package} for @var{system}
1352(@pxref{Derivations}).
3dc1970d
LC
1353
1354@var{package} must be a valid @code{<package>} object, and @var{system}
1355must be a string denoting the target system type---e.g.,
1356@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
1357must be a connection to the daemon, which operates on the store
1358(@pxref{The Store}).
1359@end deffn
568717fd 1360
9c1edabd
LC
1361@noindent
1362@cindex cross-compilation
1363Similarly, it is possible to compute a derivation that cross-builds a
1364package for some other system:
1365
1366@deffn {Scheme Procedure} package-cross-derivation @var{store} @
1367 @var{package} @var{target} [@var{system}]
59688fc4
LC
1368Return the @code{<derivation>} object of @var{package} cross-built from
1369@var{system} to @var{target}.
9c1edabd
LC
1370
1371@var{target} must be a valid GNU triplet denoting the target hardware
1372and operating system, such as @code{"mips64el-linux-gnu"}
1373(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
1374Configure and Build System}).
1375@end deffn
1376
1377
568717fd
LC
1378@node The Store
1379@section The Store
1380
e531ac2a
LC
1381@cindex store
1382@cindex store paths
1383
1384Conceptually, the @dfn{store} is where derivations that have been
834129e0 1385successfully built are stored---by default, under @file{/gnu/store}.
e531ac2a
LC
1386Sub-directories in the store are referred to as @dfn{store paths}. The
1387store has an associated database that contains information such has the
1388store paths referred to by each store path, and the list of @emph{valid}
1389store paths---paths that result from a successful build.
1390
1391The store is always accessed by the daemon on behalf of its clients
1392(@pxref{Invoking guix-daemon}). To manipulate the store, clients
1393connect to the daemon over a Unix-domain socket, send it requests, and
1394read the result---these are remote procedure calls, or RPCs.
1395
1396The @code{(guix store)} module provides procedures to connect to the
1397daemon, and to perform RPCs. These are described below.
1398
1399@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
1400Connect to the daemon over the Unix-domain socket at @var{file}. When
1401@var{reserve-space?} is true, instruct it to reserve a little bit of
1402extra space on the file system so that the garbage collector can still
1403operate, should the disk become full. Return a server object.
1404
1405@var{file} defaults to @var{%default-socket-path}, which is the normal
1406location given the options that were passed to @command{configure}.
1407@end deffn
1408
1409@deffn {Scheme Procedure} close-connection @var{server}
1410Close the connection to @var{server}.
1411@end deffn
1412
1413@defvr {Scheme Variable} current-build-output-port
1414This variable is bound to a SRFI-39 parameter, which refers to the port
1415where build and error logs sent by the daemon should be written.
1416@end defvr
1417
1418Procedures that make RPCs all take a server object as their first
1419argument.
1420
1421@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
1422Return @code{#t} when @var{path} is a valid store path.
1423@end deffn
1424
cfbf9160 1425@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
1426Add @var{text} under file @var{name} in the store, and return its store
1427path. @var{references} is the list of store paths referred to by the
1428resulting store path.
1429@end deffn
1430
874e6874 1431@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
1432Build @var{derivations} (a list of @code{<derivation>} objects or
1433derivation paths), and return when the worker is done building them.
1434Return @code{#t} on success.
874e6874
LC
1435@end deffn
1436
b860f382
LC
1437Note that the @code{(guix monads)} module provides a monad as well as
1438monadic versions of the above procedures, with the goal of making it
1439more convenient to work with code that accesses the store (@pxref{The
1440Store Monad}).
1441
e531ac2a
LC
1442@c FIXME
1443@i{This section is currently incomplete.}
568717fd
LC
1444
1445@node Derivations
1446@section Derivations
1447
874e6874
LC
1448@cindex derivations
1449Low-level build actions and the environment in which they are performed
1450are represented by @dfn{derivations}. A derivation contain the
1451following pieces of information:
1452
1453@itemize
1454@item
1455The outputs of the derivation---derivations produce at least one file or
1456directory in the store, but may produce more.
1457
1458@item
1459The inputs of the derivations, which may be other derivations or plain
1460files in the store (patches, build scripts, etc.)
1461
1462@item
1463The system type targeted by the derivation---e.g., @code{x86_64-linux}.
1464
1465@item
1466The file name of a build script in the store, along with the arguments
1467to be passed.
1468
1469@item
1470A list of environment variables to be defined.
1471
1472@end itemize
1473
1474@cindex derivation path
1475Derivations allow clients of the daemon to communicate build actions to
1476the store. They exist in two forms: as an in-memory representation,
1477both on the client- and daemon-side, and as files in the store whose
1478name end in @code{.drv}---these files are referred to as @dfn{derivation
1479paths}. Derivations paths can be passed to the @code{build-derivations}
1480procedure to perform the build actions they prescribe (@pxref{The
1481Store}).
1482
1483The @code{(guix derivations)} module provides a representation of
1484derivations as Scheme objects, along with procedures to create and
1485otherwise manipulate derivations. The lowest-level primitive to create
1486a derivation is the @code{derivation} procedure:
1487
1909431c
LC
1488@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
1489 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 1490 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c
LC
1491 [#:system (%current-system)] [#:references-graphs #f] @
1492 [#:local-build? #f]
59688fc4
LC
1493Build a derivation with the given arguments, and return the resulting
1494@code{<derivation>} object.
874e6874 1495
2096ef47 1496When @var{hash} and @var{hash-algo} are given, a
874e6874 1497@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
1498known in advance, such as a file download. If, in addition,
1499@var{recursive?} is true, then that fixed output may be an executable
1500file or a directory and @var{hash} must be the hash of an archive
1501containing this output.
5b0c9d16 1502
858e9282 1503When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
1504name/store path pairs. In that case, the reference graph of each store
1505path is exported in the build environment in the corresponding file, in
1506a simple text format.
1909431c
LC
1507
1508When @var{local-build?} is true, declare that the derivation is not a
1509good candidate for offloading and should rather be built locally
1510(@pxref{Daemon Offload Setup}). This is the case for small derivations
1511where the costs of data transfers would outweigh the benefits.
874e6874
LC
1512@end deffn
1513
1514@noindent
1515Here's an example with a shell script as its builder, assuming
1516@var{store} is an open connection to the daemon, and @var{bash} points
1517to a Bash executable in the store:
1518
1519@lisp
1520(use-modules (guix utils)
1521 (guix store)
1522 (guix derivations))
1523
59688fc4
LC
1524(let ((builder ; add the Bash script to the store
1525 (add-text-to-store store "my-builder.sh"
1526 "echo hello world > $out\n" '())))
1527 (derivation store "foo"
1528 bash `("-e" ,builder)
1529 #:env-vars '(("HOME" . "/homeless"))))
834129e0 1530@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
1531@end lisp
1532
1533As can be guessed, this primitive is cumbersome to use directly. An
1534improved variant is @code{build-expression->derivation}, which allows
1535the caller to directly pass a Guile expression as the build script:
1536
dd1a5a15
LC
1537@deffn {Scheme Procedure} build-expression->derivation @var{store} @
1538 @var{name} @var{exp} @
1539 [#:system (%current-system)] [#:inputs '()] @
1540 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
36bbbbd1 1541 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
1909431c 1542 [#:references-graphs #f] [#:local-build? #f] [#:guile-for-build #f]
874e6874
LC
1543Return a derivation that executes Scheme expression @var{exp} as a
1544builder for derivation @var{name}. @var{inputs} must be a list of
1545@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
1546@code{"out"} is assumed. @var{modules} is a list of names of Guile
1547modules from the current search path to be copied in the store,
1548compiled, and made available in the load path during the execution of
1549@var{exp}---e.g., @code{((guix build utils) (guix build
1550gnu-build-system))}.
1551
1552@var{exp} is evaluated in an environment where @code{%outputs} is bound
1553to a list of output/path pairs, and where @code{%build-inputs} is bound
1554to a list of string/output-path pairs made from @var{inputs}.
1555Optionally, @var{env-vars} is a list of string pairs specifying the name
1556and value of environment variables visible to the builder. The builder
1557terminates by passing the result of @var{exp} to @code{exit}; thus, when
1558@var{exp} returns @code{#f}, the build is considered to have failed.
1559
1560@var{exp} is built using @var{guile-for-build} (a derivation). When
1561@var{guile-for-build} is omitted or is @code{#f}, the value of the
1562@code{%guile-for-build} fluid is used instead.
9c629a27 1563
1909431c
LC
1564See the @code{derivation} procedure for the meaning of @var{references-graphs}
1565and @var{local-build?}.
874e6874
LC
1566@end deffn
1567
1568@noindent
1569Here's an example of a single-output derivation that creates a directory
1570containing one file:
1571
1572@lisp
1573(let ((builder '(let ((out (assoc-ref %outputs "out")))
834129e0 1574 (mkdir out) ; create /gnu/store/@dots{}-goo
874e6874
LC
1575 (call-with-output-file (string-append out "/test")
1576 (lambda (p)
1577 (display '(hello guix) p))))))
dd1a5a15 1578 (build-expression->derivation store "goo" builder))
874e6874 1579
834129e0 1580@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
1581@end lisp
1582
1583@cindex strata of code
1584Remember that the build expression passed to
1585@code{build-expression->derivation} is run by a separate Guile process
1586than the one that calls @code{build-expression->derivation}: it is run
1587by a Guile process launched by the daemon, typically in a chroot. So,
1588while there is a single language for both the @dfn{host} and the build
1589side, there are really two @dfn{strata} of code: the host-side, and the
1590build-side code@footnote{The term @dfn{stratum} in this context was
1591coined by Manuel Serrano et al. in the context of their work on Hop.}.
1592This distinction is important to keep in mind, notably when using
1593higher-level constructs such as @var{gnu-build-system} (@pxref{Defining
1594Packages}). For this reason, Guix modules that are meant to be used in
1595the build stratum are kept in the @code{(guix build @dots{})} name
1596space.
568717fd 1597
b860f382
LC
1598@node The Store Monad
1599@section The Store Monad
1600
1601@cindex monad
1602
1603The procedures that operate on the store described in the previous
1604sections all take an open connection to the build daemon as their first
1605argument. Although the underlying model is functional, they either have
1606side effects or depend on the current state of the store.
1607
1608The former is inconvenient: the connection to the build daemon has to be
1609carried around in all those functions, making it impossible to compose
1610functions that do not take that parameter with functions that do. The
1611latter can be problematic: since store operations have side effects
1612and/or depend on external state, they have to be properly sequenced.
1613
1614@cindex monadic values
1615@cindex monadic functions
1616This is where the @code{(guix monads)} module comes in. This module
1617provides a framework for working with @dfn{monads}, and a particularly
1618useful monad for our uses, the @dfn{store monad}. Monads are a
1619construct that allows two things: associating ``context'' with values
1620(in our case, the context is the store), and building sequences of
1621computations (here computations includes accesses to the store.) Values
1622in a monad---values that carry this additional context---are called
1623@dfn{monadic values}; procedures that return such values are called
1624@dfn{monadic procedures}.
1625
1626Consider this ``normal'' procedure:
1627
1628@example
45adbd62
LC
1629(define (sh-symlink store)
1630 ;; Return a derivation that symlinks the 'bash' executable.
1631 (let* ((drv (package-derivation store bash))
1632 (out (derivation->output-path drv))
1633 (sh (string-append out "/bin/bash")))
1634 (build-expression->derivation store "sh"
1635 `(symlink ,sh %output))))
b860f382
LC
1636@end example
1637
1638Using @code{(guix monads)}, it may be rewritten as a monadic function:
1639
1640@example
45adbd62 1641(define (sh-symlink)
b860f382 1642 ;; Same, but return a monadic value.
45adbd62
LC
1643 (mlet %store-monad ((sh (package-file bash "bin")))
1644 (derivation-expression "sh" `(symlink ,sh %output))))
b860f382
LC
1645@end example
1646
1647There are two things to note in the second version: the @code{store}
1648parameter is now implicit, and the monadic value returned by
1649@code{package-file}---a wrapper around @code{package-derivation} and
1650@code{derivation->output-path}---is @dfn{bound} using @code{mlet}
1651instead of plain @code{let}.
1652
1653Calling the monadic @code{profile.sh} has no effect. To get the desired
1654effect, one must use @code{run-with-store}:
1655
1656@example
1657(run-with-store (open-connection) (profile.sh))
834129e0 1658@result{} /gnu/store/...-profile.sh
b860f382
LC
1659@end example
1660
1661The main syntactic forms to deal with monads in general are described
1662below.
1663
1664@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
1665Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
1666in @var{monad}.
1667@end deffn
1668
1669@deffn {Scheme Syntax} return @var{val}
1670Return a monadic value that encapsulates @var{val}.
1671@end deffn
1672
1673@deffn {Scheme Syntax} >>= @var{mval} @var{mproc}
1674@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
1675procedure @var{mproc}@footnote{This operation is commonly referred to as
1676``bind'', but that name denotes an unrelated procedure in Guile. Thus
1677we use this somewhat cryptic symbol inherited from the Haskell
1678language.}.
1679@end deffn
1680
1681@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
1682 @var{body} ...
1683@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
1684 @var{body} ...
1685Bind the variables @var{var} to the monadic values @var{mval} in
1686@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
1687``normal'' value @var{val}, as per @code{let}.
1688
1689@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
1690(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
1691@end deffn
1692
1693The interface to the store monad provided by @code{(guix monads)} is as
1694follows.
1695
1696@defvr {Scheme Variable} %store-monad
1697The store monad. Values in the store monad encapsulate accesses to the
1698store. When its effect is needed, a value of the store monad must be
1699``evaluated'' by passing it to the @code{run-with-store} procedure (see
1700below.)
1701@end defvr
1702
1703@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
1704Run @var{mval}, a monadic value in the store monad, in @var{store}, an
1705open store connection.
1706@end deffn
1707
1708@deffn {Monadic Procedure} text-file @var{name} @var{text}
1709Return as a monadic value the absolute file name in the store of the file
45adbd62
LC
1710containing @var{text}, a string.
1711@end deffn
1712
1713@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
1714Return as a monadic value a derivation that builds a text file
1715containing all of @var{text}. @var{text} may list, in addition to
1716strings, packages, derivations, and store file names; the resulting
1717store file holds references to all these.
1718
1719This variant should be preferred over @code{text-file} anytime the file
1720to create will reference items from the store. This is typically the
1721case when building a configuration file that embeds store file names,
1722like this:
1723
1724@example
1725(define (profile.sh)
1726 ;; Return the name of a shell script in the store that
1727 ;; initializes the 'PATH' environment variable.
1728 (text-file* "profile.sh"
1729 "export PATH=" coreutils "/bin:"
1730 grep "/bin:" sed "/bin\n"))
1731@end example
1732
834129e0 1733In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
45adbd62
LC
1734will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
1735preventing them from being garbage-collected during its lifetime.
b860f382
LC
1736@end deffn
1737
1738@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
1739 [#:system (%current-system)] [#:output "out"] Return as a monadic
1740value in the absolute file name of @var{file} within the @var{output}
1741directory of @var{package}. When @var{file} is omitted, return the name
1742of the @var{output} directory of @var{package}.
1743@end deffn
1744
dd1a5a15
LC
1745@deffn {Monadic Procedure} derivation-expression @var{name} @var{exp} @
1746 [#:system (%current-system)] [#:inputs '()] @
1747 [#:outputs '("out")] [#:hash #f] @
b860f382
LC
1748 [#:hash-algo #f] [#:env-vars '()] [#:modules '()] @
1749 [#:references-graphs #f] [#:guile-for-build #f]
1750Monadic version of @code{build-expression->derivation}
1751(@pxref{Derivations}).
1752@end deffn
1753
1754@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
1755Monadic version of @code{package-derivation} (@pxref{Defining
1756Packages}).
1757@end deffn
1758
1759
568717fd
LC
1760@c *********************************************************************
1761@node Utilities
1762@chapter Utilities
1763
210cc920
LC
1764This section describes tools primarily targeted at developers and users
1765who write new package definitions. They complement the Scheme
1766programming interface of Guix in a convenient way.
1767
568717fd 1768@menu
37166310 1769* Invoking guix build:: Building packages from the command line.
210cc920 1770* Invoking guix download:: Downloading a file and printing its hash.
37166310
LC
1771* Invoking guix hash:: Computing the cryptographic hash of a file.
1772* Invoking guix refresh:: Updating package definitions.
568717fd
LC
1773@end menu
1774
e49951eb
MW
1775@node Invoking guix build
1776@section Invoking @command{guix build}
568717fd 1777
e49951eb 1778The @command{guix build} command builds packages or derivations and
6798a8e4
LC
1779their dependencies, and prints the resulting store paths. Note that it
1780does not modify the user's profile---this is the job of the
e49951eb 1781@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
1782it is mainly useful for distribution developers.
1783
1784The general syntax is:
c78bd12b
LC
1785
1786@example
e49951eb 1787guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
1788@end example
1789
1790@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
1791the software distribution such as @code{coreutils} or
1792@code{coreutils-8.20}, or a derivation such as
834129e0 1793@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
1794package with the corresponding name (and optionally version) is searched
1795for among the GNU distribution modules (@pxref{Package Modules}).
1796
1797Alternatively, the @code{--expression} option may be used to specify a
1798Scheme expression that evaluates to a package; this is useful when
1799disambiguation among several same-named packages or package variants is
1800needed.
c78bd12b
LC
1801
1802The @var{options} may be zero or more of the following:
1803
1804@table @code
1805
1806@item --expression=@var{expr}
1807@itemx -e @var{expr}
ac5de156 1808Build the package or derivation @var{expr} evaluates to.
c78bd12b 1809
5401dd75 1810For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
1811guile-1.8)}, which unambiguously designates this specific variant of
1812version 1.8 of Guile.
1813
ac5de156
LC
1814Alternately, @var{expr} may refer to a zero-argument monadic procedure
1815(@pxref{The Store Monad}). The procedure must return a derivation as a
1816monadic value, which is then passed through @code{run-with-store}.
1817
c78bd12b
LC
1818@item --source
1819@itemx -S
1820Build the packages' source derivations, rather than the packages
1821themselves.
1822
e49951eb 1823For instance, @code{guix build -S gcc} returns something like
834129e0 1824@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 1825
f9cc8971
LC
1826The returned source tarball is the result of applying any patches and
1827code snippets specified in the package's @code{origin} (@pxref{Defining
1828Packages}).
1829
c78bd12b
LC
1830@item --system=@var{system}
1831@itemx -s @var{system}
1832Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
1833the host's system type.
1834
1835An example use of this is on Linux-based systems, which can emulate
1836different personalities. For instance, passing
1837@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
1838to build packages in a complete 32-bit environment.
1839
e55ec43d
LC
1840@item --target=@var{triplet}
1841@cindex cross-compilation
1842Cross-build for @var{triplet}, which must be a valid GNU triplet, such
1843as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
1844configuration triplets,, configure, GNU Configure and Build System}).
1845
7f3673f2
LC
1846@item --with-source=@var{source}
1847Use @var{source} as the source of the corresponding package.
1848@var{source} must be a file name or a URL, as for @command{guix
1849download} (@pxref{Invoking guix download}).
1850
1851The ``corresponding package'' is taken to be one specified on the
1852command line whose name matches the base of @var{source}---e.g., if
1853@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
1854package is @code{guile}. Likewise, the version string is inferred from
1855@var{source}; in the previous example, it's @code{2.0.10}.
1856
1857This option allows users to try out versions of packages other than the
1858one provided by the distribution. The example below downloads
1859@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
1860the @code{ed} package:
1861
1862@example
1863guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
1864@end example
1865
1866As a developer, @code{--with-source} makes it easy to test release
1867candidates:
1868
1869@example
1870guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
1871@end example
1872
1873
c78bd12b
LC
1874@item --derivations
1875@itemx -d
1876Return the derivation paths, not the output paths, of the given
1877packages.
1878
70ee5642
LC
1879@item --root=@var{file}
1880@itemx -r @var{file}
1881Make @var{file} a symlink to the result, and register it as a garbage
1882collector root.
1883
1884@item --log-file
1885Return the build log file names for the given
1886@var{package-or-derivation}s, or raise an error if build logs are
1887missing.
1888
1889This works regardless of how packages or derivations are specified. For
1890instance, the following invocations are equivalent:
1891
1892@example
1893guix build --log-file `guix build -d guile`
1894guix build --log-file `guix build guile`
1895guix build --log-file guile
1896guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
1897@end example
1898
1899
1900@end table
1901
1902@cindex common build options
1903In addition, a number of options that control the build process are
1904common to @command{guix build} and other commands that can spawn builds,
1905such as @command{guix package} or @command{guix archive}. These are the
1906following:
1907
1908@table @code
1909
c78bd12b
LC
1910@item --keep-failed
1911@itemx -K
1912Keep the build tree of failed builds. Thus, if a build fail, its build
1913tree is kept under @file{/tmp}, in a directory whose name is shown at
1914the end of the build log. This is useful when debugging build issues.
1915
1916@item --dry-run
1917@itemx -n
1918Do not build the derivations.
1919
56b1f4b7
LC
1920@item --fallback
1921When substituting a pre-built binary fails, fall back to building
1922packages locally.
1923
c78bd12b 1924@item --no-substitutes
b5385b52
LC
1925Do not use substitutes for build products. That is, always build things
1926locally instead of allowing downloads of pre-built binaries.
c78bd12b 1927
425b0bfc 1928@item --no-build-hook
4ec2e92d
LC
1929Do not attempt to offload builds @i{via} the daemon's ``build hook''
1930(@pxref{Daemon Offload Setup}). That is, always build things locally
1931instead of offloading builds to remote machines.
425b0bfc 1932
969e678e
LC
1933@item --max-silent-time=@var{seconds}
1934When the build or substitution process remains silent for more than
1935@var{seconds}, terminate it and report a build failure.
1936
002622b6
LC
1937@item --timeout=@var{seconds}
1938Likewise, when the build or substitution process lasts for more than
1939@var{seconds}, terminate it and report a build failure.
1940
1941By default there is no timeout. This behavior can be restored with
1942@code{--timeout=0}.
1943
07ab4bf1
LC
1944@item --verbosity=@var{level}
1945Use the given verbosity level. @var{level} must be an integer between 0
1946and 5; higher means more verbose output. Setting a level of 4 or more
1947may be helpful when debugging setup issues with the build daemon.
1948
70ee5642
LC
1949@item --cores=@var{n}
1950@itemx -c @var{n}
1951Allow the use of up to @var{n} CPU cores for the build. The special
1952value @code{0} means to use as many CPU cores as available.
bf421152 1953
c78bd12b
LC
1954@end table
1955
e49951eb 1956Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
1957the @code{package-derivation} procedure of the @code{(guix packages)}
1958module, and to the @code{build-derivations} procedure of the @code{(guix
1959store)} module.
1960
210cc920
LC
1961@node Invoking guix download
1962@section Invoking @command{guix download}
1963
1964When writing a package definition, developers typically need to download
1965the package's source tarball, compute its SHA256 hash, and write that
1966hash in the package definition (@pxref{Defining Packages}). The
1967@command{guix download} tool helps with this task: it downloads a file
1968from the given URI, adds it to the store, and prints both its file name
1969in the store and its SHA256 hash.
1970
1971The fact that the downloaded file is added to the store saves bandwidth:
1972when the developer eventually tries to build the newly defined package
1973with @command{guix build}, the source tarball will not have to be
1974downloaded again because it is already in the store. It is also a
1975convenient way to temporarily stash files, which may be deleted
1976eventually (@pxref{Invoking guix gc}).
1977
1978The @command{guix download} command supports the same URIs as used in
1979package definitions. In particular, it supports @code{mirror://} URIs.
1980@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
1981Guile bindings for GnuTLS are available in the user's environment; when
1982they are not available, an error is raised.
1983
1984The following option is available:
1985
1986@table @code
1987@item --format=@var{fmt}
1988@itemx -f @var{fmt}
1989Write the hash in the format specified by @var{fmt}. For more
1990information on the valid values for @var{fmt}, @ref{Invoking guix hash}.
1991@end table
1992
6c365eca
NK
1993@node Invoking guix hash
1994@section Invoking @command{guix hash}
1995
210cc920 1996The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
1997It is primarily a convenience tool for anyone contributing to the
1998distribution: it computes the cryptographic hash of a file, which can be
1999used in the definition of a package (@pxref{Defining Packages}).
2000
2001The general syntax is:
2002
2003@example
2004guix hash @var{option} @var{file}
2005@end example
2006
2007@command{guix hash} has the following option:
2008
2009@table @code
2010
2011@item --format=@var{fmt}
2012@itemx -f @var{fmt}
210cc920 2013Write the hash in the format specified by @var{fmt}.
6c365eca
NK
2014
2015Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
2016(@code{hex} and @code{hexadecimal} can be used as well).
2017
2018If the @option{--format} option is not specified, @command{guix hash}
2019will output the hash in @code{nix-base32}. This representation is used
2020in the definitions of packages.
2021
3140f2df
LC
2022@item --recursive
2023@itemx -r
2024Compute the hash on @var{file} recursively.
2025
2026In this case, the hash is computed on an archive containing @var{file},
2027including its children if it is a directory. Some of @var{file}'s
2028meta-data is part of the archive; for instance, when @var{file} is a
2029regular file, the hash is different depending on whether @var{file} is
2030executable or not. Meta-data such as time stamps has no impact on the
2031hash (@pxref{Invoking guix archive}).
2032@c FIXME: Replace xref above with xref to an ``Archive'' section when
2033@c it exists.
2034
6c365eca
NK
2035@end table
2036
37166310
LC
2037@node Invoking guix refresh
2038@section Invoking @command{guix refresh}
2039
2040The primary audience of the @command{guix refresh} command is developers
2041of the GNU software distribution. By default, it reports any packages
2042provided by the distribution that are outdated compared to the latest
2043upstream version, like this:
2044
2045@example
2046$ guix refresh
2047gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
2048gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
2049@end example
2050
2051It does so by browsing each package's FTP directory and determining the
2052highest version number of the source tarballs
2053therein@footnote{Currently, this only works for GNU packages.}.
2054
2055When passed @code{--update}, it modifies distribution source files to
2056update the version numbers and source tarball hashes of those packages'
2057recipes (@pxref{Defining Packages}). This is achieved by downloading
2058each package's latest source tarball and its associated OpenPGP
2059signature, authenticating the downloaded tarball against its signature
2060using @command{gpg}, and finally computing its hash. When the public
2061key used to sign the tarball is missing from the user's keyring, an
2062attempt is made to automatically retrieve it from a public key server;
2063when it's successful, the key is added to the user's keyring; otherwise,
2064@command{guix refresh} reports an error.
2065
2066The following options are supported:
2067
2068@table @code
2069
2070@item --update
2071@itemx -u
2072Update distribution source files (package recipes) in place.
2073@ref{Defining Packages}, for more information on package definitions.
2074
2075@item --select=[@var{subset}]
2076@itemx -s @var{subset}
2077Select all the packages in @var{subset}, one of @code{core} or
2078@code{non-core}.
2079
2080The @code{core} subset refers to all the packages at the core of the
2081distribution---i.e., packages that are used to build ``everything
2082else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
2083changing one of these packages in the distribution entails a rebuild of
2084all the others. Thus, such updates are an inconvenience to users in
2085terms of build time or bandwidth used to achieve the upgrade.
2086
2087The @code{non-core} subset refers to the remaining packages. It is
2088typically useful in cases where an update of the core packages would be
2089inconvenient.
2090
2091@end table
2092
2093In addition, @command{guix refresh} can be passed one or more package
2094names, as in this example:
2095
2096@example
2097guix refresh -u emacs idutils
2098@end example
2099
2100@noindent
2101The command above specifically updates the @code{emacs} and
2102@code{idutils} packages. The @code{--select} option would have no
2103effect in this case.
2104
f9230085
LC
2105The following options can be used to customize GnuPG operation:
2106
2107@table @code
2108
2109@item --key-server=@var{host}
2110Use @var{host} as the OpenPGP key server when importing a public key.
2111
2112@item --gpg=@var{command}
2113Use @var{command} as the GnuPG 2.x command. @var{command} is searched
2114for in @code{$PATH}.
2115
2116@end table
2117
37166310 2118
a1ba8475
LC
2119@c *********************************************************************
2120@node GNU Distribution
2121@chapter GNU Distribution
2122
2123Guix comes with a distribution of free software@footnote{The term
2124``free'' here refers to the
2125@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
c320011d 2126users of that software}.} that forms the basis of the GNU system. This
a1ba8475
LC
2127includes core GNU packages such as GNU libc, GCC, and Binutils, as well
2128as many GNU and non-GNU applications. The complete list of available
d03bb653
LC
2129packages can be browsed
2130@url{http://www.gnu.org/software/guix/package-list.html,on-line} or by
2131running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
2132
2133@example
e49951eb 2134guix package --list-available
a1ba8475
LC
2135@end example
2136
401c53c4
LC
2137Our goal is to build a practical 100% free software distribution of
2138Linux-based and other variants of GNU, with a focus on the promotion and
2139tight integration of GNU components, and an emphasis on programs and
2140tools that help users exert that freedom.
2141
c320011d
LC
2142The GNU distribution is currently available on the following platforms:
2143
2144@table @code
2145
2146@item x86_64-linux
2147Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
2148
2149@item i686-linux
2150Intel 32-bit architecture (IA32), Linux-Libre kernel;
2151
2152@item mips64el-linux
2153little-endian 64-bit MIPS processors, specifically the Loongson series,
2154n32 application binary interface (ABI), and Linux-Libre kernel.
2155
2156@end table
2157
2158@noindent
2159For information on porting to other architectures or kernels,
2160@xref{Porting}.
2161
401c53c4 2162@menu
91ef73d4 2163* Installing Debugging Files:: Feeding the debugger.
401c53c4 2164* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 2165* Packaging Guidelines:: Growing the distribution.
401c53c4 2166* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 2167* Porting:: Targeting another platform or kernel.
4af2447e 2168* System Configuration:: Configuring a GNU system.
401c53c4
LC
2169@end menu
2170
2171Building this distribution is a cooperative effort, and you are invited
2172to join! @ref{Contributing}, for information about how you can help.
2173
b208a005 2174
91ef73d4
LC
2175@node Installing Debugging Files
2176@section Installing Debugging Files
2177
2178Program binaries, as produced by the GCC compilers for instance, are
2179typically written in the ELF format, with a section containing
2180@dfn{debugging information}. Debugging information is what allows the
2181debugger, GDB, to map binary code to source code; it is required to
2182debug a compiled program in good conditions.
2183
2184The problem with debugging information is that is takes up a fair amount
2185of disk space. For example, debugging information for the GNU C Library
2186weighs in at more than 60 MiB. Thus, as a user, keeping all the
2187debugging info of all the installed programs is usually not an option.
2188Yet, space savings should not come at the cost of an impediment to
2189debugging---especially in the GNU system, which should make it easier
2190for users to exert their computing freedom (@pxref{GNU Distribution}).
2191
2192Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
2193mechanism that allows users to get the best of both worlds: debugging
2194information can be stripped from the binaries and stored in separate
2195files. GDB is then able to load debugging information from those files,
2196when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
2197with GDB}).
2198
2199The GNU distribution takes advantage of this by storing debugging
2200information in the @code{lib/debug} sub-directory of a separate package
2201output unimaginatively called @code{debug} (@pxref{Packages with
2202Multiple Outputs}). Users can choose to install the @code{debug} output
2203of a package when they need it. For instance, the following command
2204installs the debugging information for the GNU C Library and for GNU
2205Guile:
2206
2207@example
2208guix package -i glibc:debug -i guile:debug
2209@end example
2210
2211GDB must then be told to look for debug files in the user's profile, by
2212setting the @code{debug-file-directory} variable (consider setting it
2213from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
2214GDB}):
2215
2216@example
2217(gdb) set debug-file-directory ~/.guix-profile/lib/debug
2218@end example
2219
2220From there on, GDB will pick up debugging information from the
2221@code{.debug} files under @file{~/.guix-profile/lib/debug}.
2222
2223@c XXX: keep me up-to-date
2224The @code{debug} output mechanism in Guix is implemented by the
2225@code{gnu-build-system} (@pxref{Defining Packages}). Currently, it is
2226opt-in---debugging information is available only for those packages
2227whose definition explicitly declares a @code{debug} output. This may be
2228changed to opt-out in the future, if our build farm servers can handle
2229the load. To check whether a package has a @code{debug} output, use
2230@command{guix package --list-available} (@pxref{Invoking guix package}).
2231
2232
401c53c4
LC
2233@node Package Modules
2234@section Package Modules
2235
2236From a programming viewpoint, the package definitions of the
e7f34eb0 2237GNU distribution are provided by Guile modules in the @code{(gnu packages
7e17f65d
LC
2238@dots{})} name space@footnote{Note that packages under the @code{(gnu
2239packages @dots{})} module name space are not necessarily ``GNU
2240packages''. This module naming scheme follows the usual Guile module
2241naming convention: @code{gnu} means that these modules are distributed
2242as part of the GNU system, and @code{packages} identifies modules that
2243define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
b81e1947
LC
2244Reference Manual}). For instance, the @code{(gnu packages emacs)}
2245module exports a variable named @code{emacs}, which is bound to a
e7f34eb0
LC
2246@code{<package>} object (@pxref{Defining Packages}).
2247
2248The @code{(gnu packages @dots{})} module name space is special: it is
2249automatically scanned for packages by the command-line tools. For
2250instance, when running @code{guix package -i emacs}, all the @code{(gnu
2251packages @dots{})} modules are scanned until one that exports a package
2252object whose name is @code{emacs} is found. This package search
2253facility is implemented in the @code{(gnu packages)} module.
2254
2255Users can store package definitions in modules with different
2256names---e.g., @code{(my-packages emacs)}. In that case, commands such
2257as @command{guix package} and @command{guix build} have to be used with
2258the @code{-e} option so that they know where to find the package.
a1ba8475
LC
2259
2260The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
2261each package is built based solely on other packages in the
2262distribution. The root of this dependency graph is a small set of
2263@dfn{bootstrap binaries}, provided by the @code{(gnu packages
b81e1947
LC
2264bootstrap)} module. For more information on bootstrapping,
2265@ref{Bootstrapping}.
2266
da7cabd4
AE
2267@node Packaging Guidelines
2268@section Packaging Guidelines
b81e1947
LC
2269
2270The GNU distribution is nascent and may well lack some of your favorite
2271packages. This section describes how you can help make the distribution
c8c871d1 2272grow. @xref{Contributing}, for additional information on how you can
b81e1947
LC
2273help.
2274
b81e1947
LC
2275Free software packages are usually distributed in the form of
2276@dfn{source code tarballs}---typically @file{tar.gz} files that contain
2277all the source files. Adding a package to the distribution means
2278essentially two things: adding a @dfn{recipe} that describes how to
2279build the package, including a list of other packages required to build
2280it, and adding @dfn{package meta-data} along with that recipe, such as a
2281description and licensing information.
2282
2283In Guix all this information is embodied in @dfn{package definitions}.
2284Package definitions provide a high-level view of the package. They are
2285written using the syntax of the Scheme programming language; in fact,
2286for each package we define a variable bound to the package definition,
2287and export that variable from a module (@pxref{Package Modules}).
2288However, in-depth Scheme knowledge is @emph{not} a prerequisite for
2289creating packages. For more information on package definitions,
2290@ref{Defining Packages}.
2291
2292Once a package definition is in place, stored in a file in the Guix
2293source tree, it can be tested using the @command{guix build} command
2294(@pxref{Invoking guix build}). For example, assuming the new package is
2295called @code{gnew}, you may run this command from the Guix build tree:
2296
2297@example
2298./pre-inst-env guix build gnew --keep-failed
2299@end example
2300
2301Using @code{--keep-failed} makes it easier to debug build failures since
2302it provides access to the failed build tree.
2303
5ff3c4b8
PAR
2304If the package is unknown to the @command{guix} command, it may be that
2305the source file contains a syntax error, or lacks a @code{define-public}
2306clause to export the package variable. To figure it out, you may load
2307the module from Guile to get more information about the actual error:
2308
2309@example
2310./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
2311@end example
2312
b81e1947
LC
2313Once your package builds correctly, please send us a patch
2314(@pxref{Contributing}). Well, if you need help, we will be happy to
2315help you too. Once the patch is committed in the Guix repository, the
2316new package automatically gets built on the supported platforms by
2317@url{http://hydra.gnu.org/gnu/master, our continuous integration
2318system}.
2319
2320@cindex substituter
2321Users can obtain the new package definition simply by running
2322@command{guix pull} (@pxref{Invoking guix pull}). When
2323@code{hydra.gnu.org} is done building the package, installing the
2324package automatically downloads binaries from there (except when using
2325@code{--no-substitutes}). The only place where human intervention is
2326needed is to review and apply the patch.
401c53c4
LC
2327
2328
da7cabd4 2329@menu
ee85f3db
AE
2330* Software Freedom:: What may go into the distribution.
2331* Package Naming:: What's in a name?
2332* Version Numbers:: When the name is not enough.
2333* Python Modules:: Taming the snake.
da7cabd4
AE
2334@end menu
2335
2336@node Software Freedom
2337@subsection Software Freedom
2338
2339@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
2340
2341The GNU operating system has been developed so that users can have
2342freedom in their computing. GNU is @dfn{free software}, meaning that
2343users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
2344essential freedoms}: to run the program, to study and change the program
2345in source code form, to redistribute exact copies, and to distribute
2346modified versions. Packages found in the GNU distribution provide only
2347software that conveys these four freedoms.
2348
2349In addition, the GNU distribution follow the
2350@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
2351software distribution guidelines}. Among other things, these guidelines
2352reject non-free firmware, recommendations of non-free software, and
2353discuss ways to deal with trademarks and patents.
2354
f9cc8971
LC
2355Some packages contain a small and optional subset that violates the
2356above guidelines, for instance because this subset is itself non-free
2357code. When that happens, the offending items are removed with
2358appropriate patches or code snippets in the package definition's
2359@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
2360build --source} returns the ``freed'' source rather than the unmodified
2361upstream source.
2362
da7cabd4 2363
ee85f3db
AE
2364@node Package Naming
2365@subsection Package Naming
2366
c8c871d1 2367A package has actually two names associated with it:
ee85f3db 2368First, there is the name of the @emph{Scheme variable}, the one following
c8c871d1
AE
2369@code{define-public}. By this name, the package can be made known in the
2370Scheme code, for instance as input to another package. Second, there is
2371the string in the @code{name} field of a package definition. This name
2372is used by package management commands such as
2373@command{guix package} and @command{guix build}.
ee85f3db
AE
2374
2375Both are usually the same and correspond to the lowercase conversion of the
c8c871d1
AE
2376project name chosen upstream. For instance, the GNUnet project is packaged
2377as @code{gnunet}. We do not add @code{lib} prefixes for library packages,
2378unless these are already part of the official project name. But see
2379@ref{Python Modules} for special rules concerning modules for
ee85f3db
AE
2380the Python language.
2381
2382
2383@node Version Numbers
2384@subsection Version Numbers
2385
2386We usually package only the latest version of a given free software
c8c871d1
AE
2387project. But sometimes, for instance for incompatible library versions,
2388two (or more) versions of the same package are needed. These require
2389different Scheme variable names. We use the name as defined
2390in @ref{Package Naming}
ee85f3db
AE
2391for the most recent version; previous versions use the same name, suffixed
2392by @code{-} and the smallest prefix of the version number that may
2393distinguish the two versions.
2394
2395The name inside the package definition is the same for all versions of a
2396package and does not contain any version number.
2397
2398For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
c8c871d1 2399
ee85f3db
AE
2400@example
2401(define-public gtk+
2402 (package
2403 (name "gtk+")
2404 (version "3.9.12")
2405 ...))
2406(define-public gtk+-2
2407 (package
2408 (name "gtk+")
2409 (version "2.24.20")
2410 ...))
2411@end example
2412If we also wanted GTK+ 3.8.2, this would be packaged as
2413@example
2414(define-public gtk+-3.8
2415 (package
2416 (name "gtk+")
2417 (version "3.8.2")
2418 ...))
2419@end example
2420
2421
2422@node Python Modules
2423@subsection Python Modules
2424
2425We currently package Python 2 and Python 3, under the Scheme variable names
2426@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
2427To avoid confusion and naming clashes with other programming languages, it
2428seems desirable that the name of a package for a Python module contains
2429the word @code{python}.
c8c871d1 2430
ee85f3db
AE
2431Some modules are compatible with only one version of Python, others with both.
2432If the package Foo compiles only with Python 3, we name it
2433@code{python-foo}; if it compiles only with Python 2, we name it
2434@code{python2-foo}. If it is compatible with both versions, we create two
2435packages with the corresponding names.
2436
2437If a project already contains the word @code{python}, we drop this;
2438for instance, the module python-dateutil is packaged under the names
2439@code{python-dateutil} and @code{python2-dateutil}.
2440
2441
2442
2443
2444
401c53c4
LC
2445@node Bootstrapping
2446@section Bootstrapping
2447
2448@c Adapted from the ELS 2013 paper.
2449
2450@cindex bootstrapping
2451
2452Bootstrapping in our context refers to how the distribution gets built
2453``from nothing''. Remember that the build environment of a derivation
2454contains nothing but its declared inputs (@pxref{Introduction}). So
2455there's an obvious chicken-and-egg problem: how does the first package
2456get built? How does the first compiler get compiled? Note that this is
2457a question of interest only to the curious hacker, not to the regular
2458user, so you can shamelessly skip this section if you consider yourself
2459a ``regular user''.
2460
2461@cindex bootstrap binaries
2462The GNU system is primarily made of C code, with libc at its core. The
2463GNU build system itself assumes the availability of a Bourne shell and
2464command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
2465`grep'. Furthermore, build programs---programs that run
2466@code{./configure}, @code{make}, etc.---are written in Guile Scheme
2467(@pxref{Derivations}). Consequently, to be able to build anything at
2468all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
2469Binutils, libc, and the other packages mentioned above---the
2470@dfn{bootstrap binaries}.
2471
2472These bootstrap binaries are ``taken for granted'', though we can also
ba7ea5ce 2473re-create them if needed (more on that later).
401c53c4
LC
2474
2475@unnumberedsubsec Preparing to Use the Bootstrap Binaries
2476
2477@c As of Emacs 24.3, Info-mode displays the image, but since it's a
2478@c large image, it's hard to scroll. Oh well.
29f66ddd 2479@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
401c53c4
LC
2480
2481The figure above shows the very beginning of the dependency graph of the
2482distribution, corresponding to the package definitions of the @code{(gnu
2483packages bootstrap)} module. At this level of detail, things are
2484slightly complex. First, Guile itself consists of an ELF executable,
2485along with many source and compiled Scheme files that are dynamically
2486loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
2487tarball shown in this graph. This tarball is part of Guix's ``source''
2488distribution, and gets inserted into the store with @code{add-to-store}
2489(@pxref{The Store}).
a1ba8475 2490
401c53c4
LC
2491But how do we write a derivation that unpacks this tarball and adds it
2492to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
2493derivation---the first one that gets built---uses @code{bash} as its
2494builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
2495@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
2496@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
2497the Guix source distribution, whose sole purpose is to allow the Guile
2498tarball to be unpacked.
2499
2500Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
2501Guile that can be used to run subsequent build programs. Its first task
2502is to download tarballs containing the other pre-built binaries---this
2503is what the @code{.tar.xz.drv} derivations do. Guix modules such as
2504@code{ftp-client.scm} are used for this purpose. The
2505@code{module-import.drv} derivations import those modules in a directory
2506in the store, using the original layout. The
2507@code{module-import-compiled.drv} derivations compile those modules, and
2508write them in an output directory with the right layout. This
2509corresponds to the @code{#:modules} argument of
2510@code{build-expression->derivation} (@pxref{Derivations}).
2511
2512Finally, the various tarballs are unpacked by the
2513derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
2514etc., at which point we have a working C tool chain.
2515
2516
2517@unnumberedsubsec Building the Build Tools
2518
2519@c TODO: Add a package-level dependency graph generated from (gnu
2520@c packages base).
2521
2522Bootstrapping is complete when we have a full tool chain that does not
2523depend on the pre-built bootstrap tools discussed above. This
2524no-dependency requirement is verified by checking whether the files of
834129e0 2525the final tool chain contain references to the @file{/gnu/store}
401c53c4
LC
2526directories of the bootstrap inputs. The process that leads to this
2527``final'' tool chain is described by the package definitions found in
2528the @code{(gnu packages base)} module.
2529
2530@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
2531The first tool that gets built with the bootstrap binaries is
2532GNU Make, which is a prerequisite for all the following packages.
2533From there Findutils and Diffutils get built.
2534
2535Then come the first-stage Binutils and GCC, built as pseudo cross
2536tools---i.e., with @code{--target} equal to @code{--host}. They are
2537used to build libc. Thanks to this cross-build trick, this libc is
2538guaranteed not to hold any reference to the initial tool chain.
2539
2540From there the final Binutils and GCC are built. GCC uses @code{ld}
2541from the final Binutils, and links programs against the just-built libc.
2542This tool chain is used to build the other packages used by Guix and by
2543the GNU Build System: Guile, Bash, Coreutils, etc.
2544
2545And voilà! At this point we have the complete set of build tools that
2546the GNU Build System expects. These are in the @code{%final-inputs}
2547variables of the @code{(gnu packages base)} module, and are implicitly
2548used by any package that uses @code{gnu-build-system} (@pxref{Defining
2549Packages}).
2550
2551
2552@unnumberedsubsec Building the Bootstrap Binaries
2553
2554Because the final tool chain does not depend on the bootstrap binaries,
2555those rarely need to be updated. Nevertheless, it is useful to have an
2556automated way to produce them, should an update occur, and this is what
2557the @code{(gnu packages make-bootstrap)} module provides.
2558
2559The following command builds the tarballs containing the bootstrap
2560binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
2561of Coreutils and other basic command-line tools):
a1ba8475 2562
401c53c4
LC
2563@example
2564guix build bootstrap-tarballs
2565@end example
2566
2567The generated tarballs are those that should be referred to in the
2568@code{(gnu packages bootstrap)} module mentioned at the beginning of
2569this section.
2570
2571Still here? Then perhaps by now you've started to wonder: when do we
2572reach a fixed point? That is an interesting question! The answer is
2573unknown, but if you would like to investigate further (and have
2574significant computational and storage resources to do so), then let us
2575know.
a1ba8475 2576
8b315a6d
LC
2577@node Porting
2578@section Porting to a New Platform
2579
2580As discussed above, the GNU distribution is self-contained, and
2581self-containment is achieved by relying on pre-built ``bootstrap
2582binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
2583operating system kernel, CPU architecture, and application binary
2584interface (ABI). Thus, to port the distribution to a platform that is
2585not yet supported, one must build those bootstrap binaries, and update
2586the @code{(gnu packages bootstrap)} module to use them on that platform.
2587
2588Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
2589When everything goes well, and assuming the GNU tool chain supports the
2590target platform, this can be as simple as running a command like this
2591one:
2592
2593@example
2594guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
2595@end example
2596
72e25e35
LC
2597Once these are built, the @code{(gnu packages bootstrap)} module needs
2598to be updated to refer to these binaries on the target platform. In
2599addition, the @code{glibc-dynamic-linker} procedure in that module must
2600be augmented to return the right file name for libc's dynamic linker on
2601that platform; likewise, @code{system->linux-architecture} in @code{(gnu
2602packages linux)} must be taught about the new platform.
2603
8b315a6d
LC
2604In practice, there may be some complications. First, it may be that the
2605extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
2606above) is not recognized by all the GNU tools. Typically, glibc
2607recognizes some of these, whereas GCC uses an extra @code{--with-abi}
ba7ea5ce 2608configure flag (see @code{gcc.scm} for examples of how to handle this).
8b315a6d
LC
2609Second, some of the required packages could fail to build for that
2610platform. Lastly, the generated binaries could be broken for some
2611reason.
2612
9bf3c1a7 2613
4af2447e
LC
2614@node System Configuration
2615@section System Configuration
2616
2617@emph{This section documents work-in-progress. As such it may be
2618incomplete, outdated, or open to discussions. Please discuss it on
2619@email{guix-devel@@gnu.org}.}
2620
2621@cindex system configuration
2622The GNU system supports a consistent whole-system configuration
2623mechanism. By that we mean that all aspects of the global system
2624configuration---such as the available system services, timezone and
68ad877c 2625locale settings, user accounts---are declared in a single place. Such
4af2447e
LC
2626a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
2627
68ad877c
LC
2628One of the advantages of putting all the system configuration under the
2629control of Guix is that it supports transactional system upgrades, and
2630makes it possible to roll-back to a previous system instantiation,
2631should something go wrong with the new one (@pxref{Features}). Another
2632one is that it makes it easy to replicate the exact same configuration
2633across different machines, or at different points in time, without
2634having to resort to additional administration tools layered on top of
2635the system's own tools.
2636@c Yes, we're talking of Puppet, Chef, & co. here. ↑
2637
4af2447e
LC
2638This section describes this mechanism. First we focus on the system
2639administrator's viewpoint---explaining how the system is configured and
2640instantiated. Then we show how this mechanism can be extended, for
2641instance to support new system services.
2642
2643@menu
523e4896
LC
2644* Using the Configuration System:: Customizing your GNU system.
2645* Invoking guix system:: Instantiating a system configuration.
2646* Defining Services:: Adding new service definitions.
4af2447e
LC
2647@end menu
2648
2649@node Using the Configuration System
2650@subsection Using the Configuration System
2651
2652The operating system is configured by filling in an
2653@code{operating-system} structure, as defined by the @code{(gnu system)}
2654module. A simple setup, with the default system services, the default
2655Linux-Libre kernel, initial RAM disk, and boot loader looks like this:
2656
2657@findex operating-system
2658@lisp
8b198abe 2659(use-modules (gnu services base) ; for '%base-services'
db4fdc04 2660 (gnu services ssh) ; for 'lsh-service'
4af2447e 2661 (gnu system shadow) ; for 'user-account'
4af2447e
LC
2662 (gnu packages base) ; Coreutils, grep, etc.
2663 (gnu packages bash) ; Bash
4eaad71d 2664 (gnu packages admin) ; dmd, Inetutils
4af2447e
LC
2665 (gnu packages zile) ; Zile
2666 (gnu packages less) ; less
2667 (gnu packages guile) ; Guile
2668 (gnu packages linux)) ; procps, psmisc
2669
68ad877c 2670(define komputilo
4af2447e
LC
2671 (operating-system
2672 (host-name "komputilo")
2673 (timezone "Europe/Paris")
2674 (locale "fr_FR.UTF-8")
2675 (users (list (user-account
2676 (name "alice")
2677 (password "")
2678 (uid 1000) (gid 100)
2679 (comment "Bob's sister")
2680 (home-directory "/home/alice"))))
2681 (packages (list coreutils bash guile-2.0
2682 guix dmd
2683 inetutils
2684 findutils grep sed
2685 procps psmisc
2686 zile less))
2687 (services (cons (lsh-service #:port 2222 #:allow-root-login? #t)
8b198abe 2688 %base-services))))
4af2447e
LC
2689@end lisp
2690
2691This example should be self-describing. The @code{packages} field lists
68ad877c
LC
2692packages provided by the various @code{(gnu packages ...)} modules above
2693(@pxref{Package Modules}). These are the packages that will be globally
2694visible on the system, for all user accounts---i.e., in every user's
2695@code{PATH} environment variable---in addition to the per-user profiles
2696(@pxref{Invoking guix package}).
4af2447e 2697
8b198abe 2698@vindex %base-services
4af2447e 2699The @code{services} field lists @dfn{system services} to be made
8b198abe 2700available when the system starts. The @var{%base-services} list,
db4fdc04 2701from the @code{(gnu services base)} module, provides the basic services one
4af2447e
LC
2702would expect from a GNU system: a login service (mingetty) on each tty,
2703syslogd, libc's name service cache daemon (nscd), etc.
2704
2705The @code{operating-system} declaration above specifies that, in
2706addition to those services, we want the @command{lshd} secure shell
2707daemon listening on port 2222, and allowing remote @code{root} logins
2708(@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
2709@code{lsh-service} arranges so that @code{lshd} is started with the
2710right command-line options, possibly with supporting configuration files
2711generated as needed (@pxref{Defining Services}).
2712
4af2447e 2713Assuming the above snippet is stored in the @file{my-system-config.scm}
523e4896
LC
2714file, the @command{guix system boot my-system-config.scm} command
2715instantiates that configuration, and makes it the default GRUB boot
2716entry (@pxref{Invoking guix system}). The normal way to change the
2717system's configuration is by updating this file and re-running the
2718@command{guix system} command.
4af2447e
LC
2719
2720At the Scheme level, the bulk of an @code{operating-system} declaration
2721is instantiated with the following monadic procedure (@pxref{The Store
2722Monad}):
2723
2724@deffn {Monadic Procedure} operating-system-derivation os
2725Return a derivation that builds @var{os}, an @code{operating-system}
2726object (@pxref{Derivations}).
2727
2728The output of the derivation is a single directory that refers to all
2729the packages, configuration files, and other supporting files needed to
2730instantiate @var{os}.
2731@end deffn
2732
523e4896
LC
2733@node Invoking guix system
2734@subsection Invoking @code{guix system}
2735
2736Once you have written an operating system declaration, as seen in the
2737previous section, it can be @dfn{instantiated} using the @command{guix
2738system} command. The synopsis is:
2739
2740@example
2741guix system @var{options}@dots{} @var{action} @var{file}
2742@end example
2743
2744@var{file} must be the name of a file containing an
2745@code{operating-system} declaration. @var{action} specifies how the
2746operating system is instantiate. Currently only one value is supported:
2747
2748@table @code
2749@item vm
2750@cindex virtual machine
2751Build a virtual machine that contain the operating system declared in
2752@var{file}, and return a script to run that virtual machine (VM).
2753
2754The VM shares its store with the host system.
2755@end table
2756
2757@var{options} can contain any of the common build options provided by
2758@command{guix build} (@pxref{Invoking guix build}).
2759
4af2447e
LC
2760
2761@node Defining Services
2762@subsection Defining Services
2763
db4fdc04 2764The @code{(gnu services @dots{})} modules define several procedures that allow
4af2447e
LC
2765users to declare the operating system's services (@pxref{Using the
2766Configuration System}). These procedures are @emph{monadic
2767procedures}---i.e., procedures that return a monadic value in the store
2768monad (@pxref{The Store Monad}). Examples of such procedures include:
2769
2770@table @code
2771@item mingetty-service
2772return the definition of a service that runs @command{mingetty} to
2773offer a login service on the given console tty;
2774
2775@item nscd-service
2776return a definition for libc's name service cache daemon (nscd);
2777
2778@item guix-service
2779return a definition for a service that runs @command{guix-daemon}
2780(@pxref{Invoking guix-daemon}).
2781@end table
2782
2783@cindex service definition
2784The monadic value returned by those procedures is a @dfn{service
2785definition}---a structure as returned by the @code{service} form.
2786Service definitions specifies the inputs the service depends on, and an
2787expression to start and stop the service. Behind the scenes, service
2788definitions are ``translated'' into the form suitable for the
2789configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU
2790dmd Manual}).
2791
2792As an example, here is what the @code{nscd-service} procedure looks
2793like:
2794
2795@lisp
2796(define (nscd-service)
2797 (mlet %store-monad ((nscd (package-file glibc "sbin/nscd")))
2798 (return (service
2799 (documentation "Run libc's name service cache daemon.")
2800 (provision '(nscd))
2801 (start `(make-forkexec-constructor ,nscd "-f" "/dev/null"
2802 "--foreground"))
2803 (stop `(make-kill-destructor))
2804
2805 (respawn? #f)
2806 (inputs `(("glibc" ,glibc)))))))
2807@end lisp
2808
2809@noindent
2810The @code{inputs} field specifies that this service depends on the
2811@var{glibc} package---the package that contains the @command{nscd}
2812program. The @code{start} and @code{stop} fields are expressions that
2813make use of dmd's facilities to start and stop processes (@pxref{Service
2814De- and Constructors,,, dmd, GNU dmd Manual}). The @code{provision}
2815field specifies the name under which this service is known to dmd, and
2816@code{documentation} specifies on-line documentation. Thus, the
2817commands @command{deco start ncsd}, @command{deco stop nscd}, and
2818@command{deco doc nscd} will do what you would expect (@pxref{Invoking
2819deco,,, dmd, GNU dmd Manual}).
2820
2821
9bf3c1a7
LC
2822@c *********************************************************************
2823@node Contributing
2824@chapter Contributing
2825
2826This project is a cooperative effort, and we need your help to make it
5ff3c4b8
PAR
2827grow! Please get in touch with us on @email{guix-devel@@gnu.org} and
2828@code{#guix} on the Freenode IRC network. We welcome ideas, bug
2829reports, patches, and anything that may be helpful to the project. We
2830particularly welcome help on packaging (@pxref{Packaging Guidelines}).
a1ba8475 2831
9bf3c1a7
LC
2832Please see the
2833@url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING,
2834@file{HACKING} file} that comes with the Guix source code for practical
2835details about contributions.
2836
c78bd12b 2837
568717fd
LC
2838@c *********************************************************************
2839@node Acknowledgments
2840@chapter Acknowledgments
2841
2842Guix is based on the Nix package manager, which was designed and
2843implemented by Eelco Dolstra. Nix pioneered functional package
2844management, and promoted unprecedented features, such as transactional
2845package upgrades and rollbacks, per-user profiles, and referentially
2846transparent build processes. Without this work, Guix would not exist.
2847
2848The Nix-based software distributions, Nixpkgs and NixOS, have also been
2849an inspiration for Guix.
2850
2851@c *********************************************************************
2852@node GNU Free Documentation License
2853@appendix GNU Free Documentation License
2854
2855@include fdl-1.3.texi
2856
2857@c *********************************************************************
2858@node Concept Index
2859@unnumbered Concept Index
2860@printindex cp
2861
2862@node Function Index
2863@unnumbered Function Index
2864@printindex fn
2865
2866@bye
2867
2868@c Local Variables:
2869@c ispell-local-dictionary: "american";
2870@c End: