gnu: Add miscfiles
[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@*
af8a56b8 14Copyright @copyright{} 2013, 2014 Andreas Enge@*
7df7a74e
NK
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 31 Building packages with Guix.
054e8576
LC
32* guix system: (guix)Invoking guix system
33 Managing the operating system configuration.
568717fd 34@end direntry
568717fd 35
372c4bbc
DT
36@dircategory Software development
37@direntry
38* guix environment: (guix)Invoking guix environment
39 Building development environments with Guix.
40@end direntry
41
568717fd 42@titlepage
7730d112
LC
43@title GNU Guix Reference Manual
44@subtitle Using the GNU Guix Functional Package Manager
568717fd 45@author Ludovic Courtès
da7cabd4 46@author Andreas Enge
acc08466 47@author Nikita Karetnikov
568717fd
LC
48
49@page
50@vskip 0pt plus 1filll
51Edition @value{EDITION} @*
52@value{UPDATED} @*
53
7df7a74e 54@insertcopying
568717fd
LC
55@end titlepage
56
568717fd
LC
57@contents
58
59@c *********************************************************************
60@node Top
f8348b91 61@top GNU Guix
568717fd 62
f8348b91
LC
63This document describes GNU Guix version @value{VERSION}, a functional
64package management tool written for the GNU system.
568717fd
LC
65
66@menu
67* Introduction:: What is Guix about?
bd5e766b 68* Installation:: Installing Guix.
eeaf4427 69* Package Management:: Package installation, upgrade, etc.
568717fd
LC
70* Programming Interface:: Using Guix in Scheme.
71* Utilities:: Package management commands.
a1ba8475 72* GNU Distribution:: Software for your friendly GNU system.
9bf3c1a7 73* Contributing:: Your help needed!
568717fd
LC
74
75* Acknowledgments:: Thanks!
76* GNU Free Documentation License:: The license of this manual.
77* Concept Index:: Concepts.
a85b83d2 78* Programming Index:: Data types, functions, and variables.
568717fd
LC
79@end menu
80
81@c *********************************************************************
82@node Introduction
83@chapter Introduction
84
c80e7e55
LC
85GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
86using the international phonetic alphabet (IPA).} is a functional
87package management tool for the GNU system. Package management consists
4bfc4ea3
NK
88of all activities that relate to building packages from sources,
89honoring their build-time and run-time dependencies,
c80e7e55
LC
90installing packages in user environments, upgrading installed packages
91to new versions or rolling back to a previous set, removing unused
92software packages, etc.
568717fd
LC
93
94@cindex functional package management
95The term @dfn{functional} refers to a specific package management
96discipline. In Guix, the package build and installation process is seen
4bfc4ea3
NK
97as a function, in the mathematical sense. That function takes inputs,
98such as build scripts, a compiler, and libraries, and
99returns an installed package. As a pure function, its result depends
568717fd
LC
100solely on its inputs---for instance, it cannot refer to software or
101scripts that were not explicitly passed as inputs. A build function
4bfc4ea3
NK
102always produces the same result when passed a given set of inputs. It
103cannot alter the system's environment in
568717fd
LC
104any way; for instance, it cannot create, modify, or delete files outside
105of its build and installation directories. This is achieved by running
e900c503 106build processes in isolated environments (or @dfn{containers}), where only their
4bfc4ea3 107explicit inputs are visible.
568717fd 108
e531ac2a 109@cindex store
568717fd 110The result of package build functions is @dfn{cached} in the file
e531ac2a
LC
111system, in a special directory called @dfn{the store} (@pxref{The
112Store}). Each package is installed in a directory of its own, in the
834129e0 113store---by default under @file{/gnu/store}. The directory name contains
568717fd
LC
114a hash of all the inputs used to build that package; thus, changing an
115input yields a different directory name.
116
117This approach is the foundation of Guix's salient features: support for
4bfc4ea3 118transactional package upgrade and rollback, per-user installation, and
eeaf4427 119garbage collection of packages (@pxref{Features}).
568717fd 120
4bfc4ea3 121Guix has a command-line interface, which allows users to build, install,
568717fd 122upgrade, and remove packages, as well as a Scheme programming interface.
568717fd 123
a1ba8475
LC
124Last but not least, Guix is used to build a distribution of the GNU
125system, with many GNU and non-GNU free software packages. @xref{GNU
126Distribution}.
127
bd5e766b
LC
128@c *********************************************************************
129@node Installation
130@chapter Installation
131
48febeb8
LC
132GNU Guix is available for download from its website at
133@url{http://www.gnu.org/software/guix/}. This section describes the
134software requirements of Guix, as well as how to install it and get
135ready to use it.
bd5e766b 136
5af6de3e
LC
137Note that this section is concerned with the installation of the package
138manager, which can be done on top of a running GNU/Linux system. If,
139instead, you want to install the complete GNU operating system,
6621cdb6 140@pxref{System Installation}.
5af6de3e 141
b22a12fd 142The build procedure for Guix is the same as for other GNU software, and
1da983b9 143is not covered here. Please see the files @file{README} and
b22a12fd
LC
144@file{INSTALL} in the Guix source tree for additional details.
145
bd5e766b
LC
146@menu
147* Requirements:: Software needed to build and run Guix.
148* Setting Up the Daemon:: Preparing the build daemon's environment.
149* Invoking guix-daemon:: Running the build daemon.
150@end menu
151
152@node Requirements
153@section Requirements
154
155GNU Guix depends on the following packages:
156
157@itemize
4a328f73 158@item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.5 or later;
288dca55
LC
159@item @url{http://gnupg.org/, GNU libgcrypt};
160@item
161optionally, installing
162@url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
163allow you to use the @command{guix import pypi} command; it is of
164interest primarily for developers and not for casual users.
bd5e766b
LC
165@end itemize
166
167Unless @code{--disable-daemon} was passed to @command{configure}, the
168following packages are also needed:
169
170@itemize
171@item @url{http://sqlite.org, SQLite 3}
172@item @url{http://www.bzip.org, libbz2}
173@item @url{http://gcc.gnu.org, GCC's g++}
174@end itemize
175
4bfc4ea3
NK
176When a working installation of @url{http://nixos.org/nix/, the Nix package
177manager} is available, you
bd5e766b 178can instead configure Guix with @code{--disable-daemon}. In that case,
4bfc4ea3 179Nix replaces the three dependencies above.
bd5e766b 180
b22a12fd
LC
181Guix is compatible with Nix, so it is possible to share the same store
182between both. To do so, you must pass @command{configure} not only the
183same @code{--with-store-dir} value, but also the same
4bfc4ea3
NK
184@code{--localstatedir} value. The latter is essential because it
185specifies where the database that stores metadata about the store is
834129e0 186located, among other things. The default values for Nix are
b22a12fd 187@code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
4bfc4ea3
NK
188Note that @code{--disable-daemon} is not required if
189your goal is to share the store with Nix.
b22a12fd 190
bd5e766b
LC
191@node Setting Up the Daemon
192@section Setting Up the Daemon
193
194@cindex daemon
195Operations such as building a package or running the garbage collector
49e6291a 196are all performed by a specialized process, the @dfn{build daemon}, on
bd5e766b
LC
197behalf of clients. Only the daemon may access the store and its
198associated database. Thus, any operation that manipulates the store
199goes through the daemon. For instance, command-line tools such as
e49951eb 200@command{guix package} and @command{guix build} communicate with the
bd5e766b
LC
201daemon (@i{via} remote procedure calls) to instruct it what to do.
202
49e6291a
LC
203The following sections explain how to prepare the build daemon's
204environment.
205
206@menu
207* Build Environment Setup:: Preparing the isolated build environment.
208* Daemon Offload Setup:: Offloading builds to remote machines.
209@end menu
210
211@node Build Environment Setup
212@subsection Build Environment Setup
213
bd5e766b
LC
214In a standard multi-user setup, Guix and its daemon---the
215@command{guix-daemon} program---are installed by the system
834129e0 216administrator; @file{/gnu/store} is owned by @code{root} and
bd5e766b
LC
217@command{guix-daemon} runs as @code{root}. Unprivileged users may use
218Guix tools to build packages or otherwise access the store, and the
219daemon will do it on their behalf, ensuring that the store is kept in a
220consistent state, and allowing built packages to be shared among users.
221
222@cindex build users
223When @command{guix-daemon} runs as @code{root}, you may not want package
224build processes themselves to run as @code{root} too, for obvious
225security reasons. To avoid that, a special pool of @dfn{build users}
226should be created for use by build processes started by the daemon.
227These build users need not have a shell and a home directory: they will
228just be used when the daemon drops @code{root} privileges in build
229processes. Having several such users allows the daemon to launch
230distinct build processes under separate UIDs, which guarantees that they
231do not interfere with each other---an essential feature since builds are
232regarded as pure functions (@pxref{Introduction}).
233
234On a GNU/Linux system, a build user pool may be created like this (using
235Bash syntax and the @code{shadow} commands):
236
091196b3
LC
237@c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
238@c for why `-G' is needed.
bd5e766b
LC
239@example
240# groupadd guix-builder
241# for i in `seq 1 10`;
242 do
091196b3
LC
243 useradd -g guix-builder -G guix-builder \
244 -d /var/empty -s `which nologin` \
4d1a2b50
LC
245 -c "Guix build user $i" --system \
246 guix-builder$i;
bd5e766b
LC
247 done
248@end example
249
250@noindent
251The @code{guix-daemon} program may then be run as @code{root} with:
252
253@example
254# guix-daemon --build-users-group=guix-builder
255@end example
256
e900c503 257@cindex chroot
b095792f
LC
258@noindent
259This way, the daemon starts build processes in a chroot, under one of
260the @code{guix-builder} users. On GNU/Linux, by default, the chroot
6dc99317
LC
261environment contains nothing but:
262
263@c Keep this list in sync with libstore/build.cc! -----------------------
264@itemize
265@item
4743a4da
LC
266a minimal @code{/dev} directory, created mostly independently from the
267host @code{/dev}@footnote{``Mostly'', because while the set of files
268that appear in the chroot's @code{/dev} is fixed, most of these files
269can only be created if the host has them.};
270
271@item
272the @code{/proc} directory; it only shows the container's processes
273since a separate PID name space is used;
6dc99317
LC
274
275@item
276@file{/etc/passwd} with an entry for the current user and an entry for
277user @file{nobody};
278
279@item
280@file{/etc/group} with an entry for the user's group;
281
282@item
283@file{/etc/hosts} with an entry that maps @code{localhost} to
284@code{127.0.0.1};
285
286@item
287a writable @file{/tmp} directory.
288@end itemize
b095792f 289
d43eb499 290If you are installing Guix as an unprivileged user, it is still
bd5e766b
LC
291possible to run @command{guix-daemon}. However, build processes will
292not be isolated from one another, and not from the rest of the system.
293Thus, build processes may interfere with each other, and may access
294programs, libraries, and other files available on the system---making it
295much harder to view them as @emph{pure} functions.
296
49e6291a
LC
297
298@node Daemon Offload Setup
299@subsection Using the Offload Facility
300
301@cindex offloading
4ec2e92d
LC
302@cindex build hook
303When desired, the build daemon can @dfn{offload}
304derivation builds to other machines
49e6291a
LC
305running Guix, using the @code{offload} @dfn{build hook}. When that
306feature is enabled, a list of user-specified build machines is read from
307@file{/etc/guix/machines.scm}; anytime a build is requested, for
308instance via @code{guix build}, the daemon attempts to offload it to one
309of the machines that satisfies the derivation's constraints, in
310particular its system type---e.g., @file{x86_64-linux}. Missing
311prerequisites for the build are copied over SSH to the target machine,
312which then proceeds with the build; upon success the output(s) of the
313build are copied back to the initial machine.
314
4ec2e92d 315The @file{/etc/guix/machines.scm} file typically looks like this:
49e6291a
LC
316
317@example
318(list (build-machine
319 (name "eightysix.example.org")
320 (system "x86_64-linux")
321 (user "bob")
322 (speed 2.)) ; incredibly fast!
323
324 (build-machine
325 (name "meeps.example.org")
326 (system "mips64el-linux")
327 (user "alice")
328 (private-key
329 (string-append (getenv "HOME")
330 "/.ssh/id-rsa-for-guix"))))
331@end example
332
333@noindent
334In the example above we specify a list of two build machines, one for
335the @code{x86_64} architecture and one for the @code{mips64el}
4ec2e92d
LC
336architecture.
337
338In fact, this file is---not surprisingly!---a Scheme file that is
339evaluated when the @code{offload} hook is started. Its return value
340must be a list of @code{build-machine} objects. While this example
341shows a fixed list of build machines, one could imagine, say, using
342DNS-SD to return a list of potential build machines discovered in the
343local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
c678a4ee
LC
344Avahi in Guile Scheme Programs}). The @code{build-machine} data type is
345detailed below.
4ec2e92d 346
c678a4ee
LC
347@deftp {Data Type} build-machine
348This data type represents build machines the daemon may offload builds
349to. The important fields are:
49e6291a
LC
350
351@table @code
352
353@item name
354The remote machine's host name.
355
356@item system
c678a4ee 357The remote machine's system type---e.g., @code{"x86_64-linux"}.
49e6291a
LC
358
359@item user
360The user account to use when connecting to the remote machine over SSH.
361Note that the SSH key pair must @emph{not} be passphrase-protected, to
362allow non-interactive logins.
363
364@end table
365
4ec2e92d 366A number of optional fields may be specified:
49e6291a
LC
367
368@table @code
369
cecd72d5
LC
370@item port
371Port number of the machine's SSH server (default: 22).
372
49e6291a
LC
373@item private-key
374The SSH private key file to use when connecting to the machine.
375
376@item parallel-builds
377The number of builds that may run in parallel on the machine (1 by
378default.)
379
380@item speed
381A ``relative speed factor''. The offload scheduler will tend to prefer
382machines with a higher speed factor.
383
384@item features
385A list of strings denoting specific features supported by the machine.
386An example is @code{"kvm"} for machines that have the KVM Linux modules
387and corresponding hardware support. Derivations can request features by
388name, and they will be scheduled on matching build machines.
389
390@end table
c678a4ee 391@end deftp
49e6291a
LC
392
393The @code{guix} command must be in the search path on the build
394machines, since offloading works by invoking the @code{guix archive} and
395@code{guix build} commands.
396
397There's one last thing to do once @file{machines.scm} is in place. As
398explained above, when offloading, files are transferred back and forth
399between the machine stores. For this to work, you need to generate a
400key pair to allow the daemon to export signed archives of files from the
401store (@pxref{Invoking guix archive}):
402
403@example
404# guix archive --generate-key
405@end example
406
407@noindent
408Thus, when receiving files, a machine's build daemon can make sure they
409are genuine, have not been tampered with, and that they are signed by an
410authorized key.
411
412
bd5e766b
LC
413@node Invoking guix-daemon
414@section Invoking @command{guix-daemon}
415
416The @command{guix-daemon} program implements all the functionality to
417access the store. This includes launching build processes, running the
418garbage collector, querying the availability of a build result, etc. It
419is normally run as @code{root} like this:
420
421@example
422# guix-daemon --build-users-group=guix-builder
423@end example
424
425@noindent
426For details on how to set it up, @ref{Setting Up the Daemon}.
427
e900c503
LC
428@cindex chroot
429@cindex container, build environment
430@cindex build environment
431@cindex reproducible builds
bd5e766b
LC
432By default, @command{guix-daemon} launches build processes under
433different UIDs, taken from the build group specified with
434@code{--build-users-group}. In addition, each build process is run in a
435chroot environment that only contains the subset of the store that the
436build process depends on, as specified by its derivation
437(@pxref{Programming Interface, derivation}), plus a set of specific
438system directories. By default, the latter contains @file{/dev} and
e900c503
LC
439@file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a
440@dfn{container}: in addition to having its own file system tree, it has
441a separate mount name space, its own PID name space, network name space,
442etc. This helps achieve reproducible builds (@pxref{Features}).
bd5e766b
LC
443
444The following command-line options are supported:
445
446@table @code
447@item --build-users-group=@var{group}
448Take users from @var{group} to run build processes (@pxref{Setting Up
449the Daemon, build users}).
450
6858f9d1 451@item --no-substitutes
b5385b52 452@cindex substitutes
6858f9d1 453Do not use substitutes for build products. That is, always build things
c4202d60
LC
454locally instead of allowing downloads of pre-built binaries
455(@pxref{Substitutes}).
6858f9d1 456
b5385b52
LC
457By default substitutes are used, unless the client---such as the
458@command{guix package} command---is explicitly invoked with
459@code{--no-substitutes}.
460
461When the daemon runs with @code{--no-substitutes}, clients can still
462explicitly enable substitution @i{via} the @code{set-build-options}
463remote procedure call (@pxref{The Store}).
464
9176607e
LC
465@item --substitute-urls=@var{urls}
466Consider @var{urls} the default whitespace-separated list of substitute
467source URLs. When this option is omitted, @code{http://hydra.gnu.org}
468is used.
469
470This means that substitutes may be downloaded from @var{urls}, as long
471as they are signed by a trusted signature (@pxref{Substitutes}).
472
4ec2e92d
LC
473@cindex build hook
474@item --no-build-hook
475Do not use the @dfn{build hook}.
476
477The build hook is a helper program that the daemon can start and to
478which it submits build requests. This mechanism is used to offload
479builds to other machines (@pxref{Daemon Offload Setup}).
480
bd5e766b
LC
481@item --cache-failures
482Cache build failures. By default, only successful builds are cached.
483
484@item --cores=@var{n}
485@itemx -c @var{n}
486Use @var{n} CPU cores to build each derivation; @code{0} means as many
487as available.
488
489The default value is @code{1}, but it may be overridden by clients, such
e49951eb
MW
490as the @code{--cores} option of @command{guix build} (@pxref{Invoking
491guix build}).
bd5e766b
LC
492
493The effect is to define the @code{NIX_BUILD_CORES} environment variable
494in the build process, which can then use it to exploit internal
495parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
496
497@item --max-jobs=@var{n}
498@itemx -M @var{n}
499Allow at most @var{n} build jobs in parallel. The default value is
500@code{1}.
501
502@item --debug
503Produce debugging output.
504
505This is useful to debug daemon start-up issues, but then it may be
506overridden by clients, for example the @code{--verbosity} option of
e49951eb 507@command{guix build} (@pxref{Invoking guix build}).
bd5e766b
LC
508
509@item --chroot-directory=@var{dir}
510Add @var{dir} to the build chroot.
511
512Doing this may change the result of build processes---for instance if
513they use optional dependencies found in @var{dir} when it is available,
514and not otherwise. For that reason, it is not recommended to do so.
515Instead, make sure that each derivation declares all the inputs that it
516needs.
517
518@item --disable-chroot
519Disable chroot builds.
520
521Using this option is not recommended since, again, it would allow build
522processes to gain access to undeclared dependencies.
523
524@item --disable-log-compression
525Disable compression of the build logs.
526
1da983b9
LC
527Unless @code{--lose-logs} is used, all the build logs are kept in the
528@var{localstatedir}. To save space, the daemon automatically compresses
529them with bzip2 by default. This option disables that.
530
ab3893d7
LC
531@item --disable-deduplication
532@cindex deduplication
bd5e766b
LC
533Disable automatic file ``deduplication'' in the store.
534
1da983b9 535By default, files added to the store are automatically ``deduplicated'':
ab3893d7
LC
536if a newly added file is identical to another one found in the store,
537the daemon makes the new file a hard link to the other file. This can
538noticeably reduce disk usage, at the expense of slightly increasde
539input/output load at the end of a build process. This option disables
540this optimization.
1da983b9 541
6e37066e
LC
542@item --gc-keep-outputs[=yes|no]
543Tell whether the garbage collector (GC) must keep outputs of live
544derivations.
545
546When set to ``yes'', the GC will keep the outputs of any live derivation
547available in the store---the @code{.drv} files. The default is ``no'',
548meaning that derivation outputs are kept only if they are GC roots.
549
550@item --gc-keep-derivations[=yes|no]
551Tell whether the garbage collector (GC) must keep derivations
552corresponding to live outputs.
553
554When set to ``yes'', as is the case by default, the GC keeps
555derivations---i.e., @code{.drv} files---as long as at least one of their
556outputs is live. This allows users to keep track of the origins of
557items in their store. Setting it to ``no'' saves a bit of disk space.
558
559Note that when both @code{--gc-keep-derivations} and
560@code{--gc-keep-outputs} are used, the effect is to keep all the build
561prerequisites (the sources, compiler, libraries, and other build-time
562tools) of live objects in the store, regardless of whether these
563prerequisites are live. This is convenient for developers since it
564saves rebuilds or downloads.
565
bd5e766b
LC
566@item --impersonate-linux-2.6
567On Linux-based systems, impersonate Linux 2.6. This means that the
568kernel's @code{uname} system call will report 2.6 as the release number.
569
570This might be helpful to build programs that (usually wrongfully) depend
571on the kernel version number.
572
573@item --lose-logs
574Do not keep build logs. By default they are kept under
ce33631f 575@code{@var{localstatedir}/guix/log}.
bd5e766b
LC
576
577@item --system=@var{system}
578Assume @var{system} as the current system type. By default it is the
579architecture/kernel pair found at configure time, such as
580@code{x86_64-linux}.
b8d2aa26
LC
581
582@item --listen=@var{socket}
583Listen for connections on @var{socket}, the file name of a Unix-domain
584socket. The default socket is
585@file{@var{localstatedir}/daemon-socket/socket}. This option is only
586useful in exceptional circumstances, such as if you need to run several
587daemons on the same machine.
bd5e766b
LC
588@end table
589
590
eeaf4427
LC
591@c *********************************************************************
592@node Package Management
593@chapter Package Management
594
f8348b91 595The purpose of GNU Guix is to allow users to easily install, upgrade, and
eeaf4427
LC
596remove software packages, without having to know about their build
597procedure or dependencies. Guix also goes beyond this obvious set of
598features.
599
600This chapter describes the main features of Guix, as well as the package
601management tools it provides.
602
603@menu
604* Features:: How Guix will make your life brighter.
e49951eb 605* Invoking guix package:: Package installation, removal, etc.
457f60fa 606* Emacs Interface:: Package management from Emacs.
c4202d60 607* Substitutes:: Downloading pre-built binaries.
760c60d6 608* Packages with Multiple Outputs:: Single source package, multiple outputs.
e49951eb 609* Invoking guix gc:: Running the garbage collector.
f651b477 610* Invoking guix pull:: Fetching the latest Guix and distribution.
760c60d6 611* Invoking guix archive:: Exporting and importing store files.
eeaf4427
LC
612@end menu
613
614@node Features
615@section Features
616
617When using Guix, each package ends up in the @dfn{package store}, in its
618own directory---something that resembles
834129e0 619@file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string.
eeaf4427
LC
620
621Instead of referring to these directories, users have their own
622@dfn{profile}, which points to the packages that they actually want to
821b0015
LC
623use. These profiles are stored within each user's home directory, at
624@code{$HOME/.guix-profile}.
eeaf4427 625
821b0015 626For example, @code{alice} installs GCC 4.7.2. As a result,
eeaf4427 627@file{/home/alice/.guix-profile/bin/gcc} points to
834129e0 628@file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine,
821b0015
LC
629@code{bob} had already installed GCC 4.8.0. The profile of @code{bob}
630simply continues to point to
834129e0 631@file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
821b0015 632coexist on the same system without any interference.
eeaf4427 633
e49951eb
MW
634The @command{guix package} command is the central tool to manage
635packages (@pxref{Invoking guix package}). It operates on those per-user
821b0015 636profiles, and can be used @emph{with normal user privileges}.
eeaf4427
LC
637
638The command provides the obvious install, remove, and upgrade
639operations. Each invocation is actually a @emph{transaction}: either
ba55b1cb 640the specified operation succeeds, or nothing happens. Thus, if the
e49951eb 641@command{guix package} process is terminated during the transaction,
eeaf4427
LC
642or if a power outage occurs during the transaction, then the user's
643profile remains in its previous state, and remains usable.
644
645In addition, any package transaction may be @emph{rolled back}. So, if,
646for example, an upgrade installs a new version of a package that turns
647out to have a serious bug, users may roll back to the previous instance
4af2447e
LC
648of their profile, which was known to work well. Similarly, the global
649system configuration is subject to transactional upgrades and roll-back
650(@pxref{Using the Configuration System}).
eeaf4427
LC
651
652All those packages in the package store may be @emph{garbage-collected}.
653Guix can determine which packages are still referenced by the user
fe8ff028 654profiles, and remove those that are provably no longer referenced
e49951eb 655(@pxref{Invoking guix gc}). Users may also explicitly remove old
fe8ff028
LC
656generations of their profile so that the packages they refer to can be
657collected.
eeaf4427 658
e900c503
LC
659@cindex reproducibility
660@cindex reproducible builds
eeaf4427
LC
661Finally, Guix takes a @dfn{purely functional} approach to package
662management, as described in the introduction (@pxref{Introduction}).
834129e0 663Each @file{/gnu/store} package directory name contains a hash of all the
eeaf4427
LC
664inputs that were used to build that package---compiler, libraries, build
665scripts, etc. This direct correspondence allows users to make sure a
666given package installation matches the current state of their
e900c503
LC
667distribution. It also helps maximize @dfn{build reproducibility}:
668thanks to the isolated build environments that are used, a given build
669is likely to yield bit-identical files when performed on different
670machines (@pxref{Invoking guix-daemon, container}).
eeaf4427 671
c4202d60 672@cindex substitutes
eeaf4427 673This foundation allows Guix to support @dfn{transparent binary/source
c4202d60 674deployment}. When a pre-built binary for a @file{/gnu/store} item is
18f2887b 675available from an external source---a @dfn{substitute}, Guix just
c4202d60
LC
676downloads it and unpacks it;
677otherwise, it builds the package from source, locally
678(@pxref{Substitutes}).
eeaf4427 679
e49951eb
MW
680@node Invoking guix package
681@section Invoking @command{guix package}
eeaf4427 682
e49951eb 683The @command{guix package} command is the tool that allows users to
eeaf4427
LC
684install, upgrade, and remove packages, as well as rolling back to
685previous configurations. It operates only on the user's own profile,
686and works with normal user privileges (@pxref{Features}). Its syntax
687is:
688
689@example
e49951eb 690guix package @var{options}
eeaf4427
LC
691@end example
692
ba55b1cb 693Primarily, @var{options} specifies the operations to be performed during
eeaf4427
LC
694the transaction. Upon completion, a new profile is created, but
695previous generations of the profile remain available, should the user
696want to roll back.
697
6447738c
MW
698For example, to remove @code{lua} and install @code{guile} and
699@code{guile-cairo} in a single transaction:
700
701@example
702guix package -r lua -i guile guile-cairo
703@end example
704
b9e5c0a9 705For each user, a symlink to the user's default profile is automatically
0ec1af59 706created in @file{$HOME/.guix-profile}. This symlink always points to the
b9e5c0a9
LC
707current generation of the user's default profile. Thus, users can add
708@file{$HOME/.guix-profile/bin} to their @code{PATH} environment
709variable, and so on.
710
0ec1af59
LC
711In a multi-user setup, user profiles must be stored in a place
712registered as a @dfn{garbage-collector root}, which
e49951eb 713@file{$HOME/.guix-profile} points to (@pxref{Invoking guix gc}). That
0ec1af59
LC
714directory is normally
715@code{@var{localstatedir}/profiles/per-user/@var{user}}, where
716@var{localstatedir} is the value passed to @code{configure} as
717@code{--localstatedir}, and @var{user} is the user name. It must be
718created by @code{root}, with @var{user} as the owner. When it does not
70c43291
LC
719exist, or is not owned by @var{user}, @command{guix package} emits an
720error about it.
0ec1af59
LC
721
722The @var{options} can be among the following:
723
eeaf4427
LC
724@table @code
725
6447738c
MW
726@item --install=@var{package} @dots{}
727@itemx -i @var{package} @dots{}
728Install the specified @var{package}s.
eeaf4427 729
6447738c 730Each @var{package} may specify either a simple package name, such as
eeaf4427 731@code{guile}, or a package name followed by a hyphen and version number,
dc5669cd
MW
732such as @code{guile-1.8.8}. If no version number is specified, the
733newest available version will be selected. In addition, @var{package}
734may contain a colon, followed by the name of one of the outputs of the
6e721c4d 735package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
e7f34eb0
LC
736(@pxref{Packages with Multiple Outputs}). Packages with a corresponding
737name (and optionally version) are searched for among the GNU
738distribution modules (@pxref{Package Modules}).
eeaf4427 739
461572cc
LC
740@cindex propagated inputs
741Sometimes packages have @dfn{propagated inputs}: these are dependencies
742that automatically get installed along with the required package.
743
744An example is the GNU MPC library: its C header files refer to those of
745the GNU MPFR library, which in turn refer to those of the GMP library.
746Thus, when installing MPC, the MPFR and GMP libraries also get installed
747in the profile; removing MPC also removes MPFR and GMP---unless they had
748also been explicitly installed independently.
749
ba7ea5ce 750Besides, packages sometimes rely on the definition of environment
5924080d 751variables for their search paths (see explanation of
ba7ea5ce 752@code{--search-paths} below). Any missing or possibly incorrect
5924080d
LC
753environment variable definitions are reported here.
754
ef010c0f 755@c XXX: keep me up-to-date
5924080d 756Finally, when installing a GNU package, the tool reports the
ef010c0f
LC
757availability of a newer upstream version. In the future, it may provide
758the option of installing directly from the upstream version, even if
759that version is not yet in the distribution.
760
5d4b411f
LC
761@item --install-from-expression=@var{exp}
762@itemx -e @var{exp}
763Install the package @var{exp} evaluates to.
764
765@var{exp} must be a Scheme expression that evaluates to a
766@code{<package>} object. This option is notably useful to disambiguate
767between same-named variants of a package, with expressions such as
768@code{(@@ (gnu packages base) guile-final)}.
769
770Note that this option installs the first output of the specified
771package, which may be insufficient when needing a specific output of a
772multiple-output package.
773
6447738c
MW
774@item --remove=@var{package} @dots{}
775@itemx -r @var{package} @dots{}
776Remove the specified @var{package}s.
eeaf4427 777
6447738c 778As for @code{--install}, each @var{package} may specify a version number
13ed095c
LC
779and/or output name in addition to the package name. For instance,
780@code{-r glibc:debug} would remove the @code{debug} output of
781@code{glibc}.
782
6447738c
MW
783@item --upgrade[=@var{regexp} @dots{}]
784@itemx -u [@var{regexp} @dots{}]
785Upgrade all the installed packages. If one or more @var{regexp}s are
786specified, upgrade only installed packages whose name matches a
787@var{regexp}.
eeaf4427 788
f651b477
LC
789Note that this upgrades package to the latest version of packages found
790in the distribution currently installed. To update your distribution,
791you should regularly run @command{guix pull} (@pxref{Invoking guix
792pull}).
793
24e262f0
LC
794@item --roll-back
795Roll back to the previous @dfn{generation} of the profile---i.e., undo
796the last transaction.
797
798When combined with options such as @code{--install}, roll back occurs
799before any other actions.
800
d9307267 801When rolling back from the first generation that actually contains
4b2bc804
NK
802installed packages, the profile is made to point to the @dfn{zeroth
803generation}, which contains no files apart from its own meta-data.
d9307267 804
82fe08ed
LC
805Installing, removing, or upgrading packages from a generation that has
806been rolled back to overwrites previous future generations. Thus, the
807history of a profile's generations is always linear.
808
b3bb82f1
AK
809@item --switch-generation=@var{pattern}
810@itemx -S @var{pattern}
811Switch to a particular generation defined by @var{pattern}.
812
813@var{pattern} may be either a generation number or a number prefixed
814with ``+'' or ``-''. The latter means: move forward/backward by a
815specified number of generations. For example, if you want to return to
816the latest generation after @code{--roll-back}, use
817@code{--switch-generation=+1}.
818
819The difference between @code{--roll-back} and
820@code{--switch-generation=-1} is that @code{--switch-generation} will
821not make a zeroth generation, so if a specified generation does not
822exist, the current generation will not be changed.
823
5924080d
LC
824@item --search-paths
825@cindex search paths
826Report environment variable definitions, in Bash syntax, that may be
827needed in order to use the set of installed packages. These environment
828variables are used to specify @dfn{search paths} for files used by some
829of the installed packages.
830
831For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
832environment variables to be defined so it can look for headers and
833libraries in the user's profile (@pxref{Environment Variables,,, gcc,
834Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C
835library are installed in the profile, then @code{--search-paths} will
836suggest setting these variables to @code{@var{profile}/include} and
837@code{@var{profile}/lib}, respectively.
838
eeaf4427
LC
839@item --profile=@var{profile}
840@itemx -p @var{profile}
841Use @var{profile} instead of the user's default profile.
842
70915c1a
LC
843@item --verbose
844Produce verbose output. In particular, emit the environment's build log
845on the standard error port.
846
eeaf4427
LC
847@item --bootstrap
848Use the bootstrap Guile to build the profile. This option is only
849useful to distribution developers.
850
851@end table
852
e49951eb 853In addition to these actions @command{guix package} supports the
733b4130
LC
854following options to query the current state of a profile, or the
855availability of packages:
eeaf4427 856
733b4130
LC
857@table @option
858
acc08466
NK
859@item --search=@var{regexp}
860@itemx -s @var{regexp}
861List the available packages whose synopsis or description matches
299112d3
LC
862@var{regexp}. Print all the meta-data of matching packages in
863@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
864GNU recutils manual}).
acc08466 865
299112d3
LC
866This allows specific fields to be extracted using the @command{recsel}
867command, for instance:
868
869@example
e49951eb 870$ guix package -s malloc | recsel -p name,version
299112d3
LC
871name: glibc
872version: 2.17
873
874name: libgc
875version: 7.2alpha6
876@end example
acc08466 877
a12d92f5
LC
878Similarly, to show the name of all the packages available under the
879terms of the GNU@tie{}LGPL version 3:
880
881@example
882$ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
883name: elfutils
884
885name: gmp
886@dots{}
887@end example
888
2aa6efb0
CR
889@item --show=@var{package}
890Show details about @var{package}, taken from the list of available packages, in
891@code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
892recutils manual}).
893
894@example
895$ guix package --show=python | recsel -p name,version
896name: python
897version: 2.7.6
898
899name: python
900version: 3.3.5
901@end example
902
903You may also specify the full name of a package to only get details about a
904specific version of it:
905@example
906$ guix package --show=python-3.3.5 | recsel -p name,version
907name: python
908version: 3.3.5
909@end example
910
911
912
733b4130
LC
913@item --list-installed[=@var{regexp}]
914@itemx -I [@var{regexp}]
bd9bde1c
LC
915List the currently installed packages in the specified profile, with the
916most recently installed packages shown last. When @var{regexp} is
917specified, list only installed packages whose name matches @var{regexp}.
733b4130
LC
918
919For each installed package, print the following items, separated by
920tabs: the package name, its version string, the part of the package that
921is installed (for instance, @code{out} for the default output,
922@code{include} for its headers, etc.), and the path of this package in
923the store.
924
64fc89b6
LC
925@item --list-available[=@var{regexp}]
926@itemx -A [@var{regexp}]
a1ba8475
LC
927List packages currently available in the software distribution
928(@pxref{GNU Distribution}). When @var{regexp} is specified, list only
929installed packages whose name matches @var{regexp}.
64fc89b6
LC
930
931For each package, print the following items separated by tabs: its name,
6e721c4d
LC
932its version string, the parts of the package (@pxref{Packages with
933Multiple Outputs}), and the source location of its definition.
64fc89b6 934
f566d765
LC
935@item --list-generations[=@var{pattern}]
936@itemx -l [@var{pattern}]
937Return a list of generations along with their creation dates; for each
938generation, show the installed packages, with the most recently
4b2bc804
NK
939installed packages shown last. Note that the zeroth generation is never
940shown.
f566d765
LC
941
942For each installed package, print the following items, separated by
943tabs: the name of a package, its version string, the part of the package
944that is installed (@pxref{Packages with Multiple Outputs}), and the
945location of this package in the store.
946
947When @var{pattern} is used, the command returns only matching
948generations. Valid patterns include:
949
950@itemize
951@item @emph{Integers and comma-separated integers}. Both patterns denote
952generation numbers. For instance, @code{--list-generations=1} returns
953the first one.
954
955And @code{--list-generations=1,8,2} outputs three generations in the
956specified order. Neither spaces nor trailing commas are allowed.
957
958@item @emph{Ranges}. @code{--list-generations=2..9} prints the
959specified generations and everything in between. Note that the start of
960a range must be lesser than its end.
961
962It is also possible to omit the endpoint. For example,
963@code{--list-generations=2..}, returns all generations starting from the
964second one.
965
966@item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks,
967or months by passing an integer along with the first letter of the
d7ddb257
LC
968duration. For example, @code{--list-generations=20d} lists generations
969that are up to 20 days old.
f566d765
LC
970@end itemize
971
b7884ca3
NK
972@item --delete-generations[=@var{pattern}]
973@itemx -d [@var{pattern}]
d7ddb257
LC
974When @var{pattern} is omitted, delete all generations except the current
975one.
b7884ca3
NK
976
977This command accepts the same patterns as @option{--list-generations}.
d7ddb257
LC
978When @var{pattern} is specified, delete the matching generations. When
979@var{pattern} specifies a duration, generations @emph{older} than the
980specified duration match. For instance, @code{--delete-generations=1m}
981deletes generations that are more than one month old.
982
983If the current generation matches, it is deleted atomically---i.e., by
984switching to the previous available generation. Note that the zeroth
985generation is never deleted.
b7884ca3 986
1bb9900a
LC
987Note that deleting generations prevents roll-back to them.
988Consequently, this command must be used with care.
989
733b4130 990@end table
eeaf4427 991
70ee5642
LC
992Finally, since @command{guix package} may actually start build
993processes, it supports all the common build options that @command{guix
994build} supports (@pxref{Invoking guix build, common build options}).
995
457f60fa
AK
996@include emacs.texi
997
c4202d60
LC
998@node Substitutes
999@section Substitutes
1000
1001@cindex substitutes
1002@cindex pre-built binaries
1003Guix supports transparent source/binary deployment, which means that it
1004can either build things locally, or download pre-built items from a
1005server. We call these pre-built items @dfn{substitutes}---they are
1006substitutes for local build results. In many cases, downloading a
1007substitute is much faster than building things locally.
1008
1009Substitutes can be anything resulting from a derivation build
1010(@pxref{Derivations}). Of course, in the common case, they are
1011pre-built package binaries, but source tarballs, for instance, which
1012also result from derivation builds, can be available as substitutes.
1013
1014The @code{hydra.gnu.org} server is a front-end to a build farm that
1015builds packages from the GNU distribution continuously for some
9176607e
LC
1016architectures, and makes them available as substitutes. This is the
1017default source of substitutes; it can be overridden by passing
1018@command{guix-daemon} the @code{--substitute-urls} option
1019(@pxref{Invoking guix-daemon}).
c4202d60
LC
1020
1021@cindex security
1022@cindex digital signatures
1023To allow Guix to download substitutes from @code{hydra.gnu.org}, you
1024must add its public key to the access control list (ACL) of archive
1025imports, using the @command{guix archive} command (@pxref{Invoking guix
1026archive}). Doing so implies that you trust @code{hydra.gnu.org} to not
1027be compromised and to serve genuine substitutes.
1028
1029This public key is installed along with Guix, in
1030@code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is
1031the installation prefix of Guix. If you installed Guix from source,
1032make sure you checked the GPG signature of
1033@file{guix-@value{VERSION}.tar.gz}, which contains this public key file.
1034Then, you can run something like this:
1035
1036@example
1037# guix archive --authorize < hydra.gnu.org.pub
1038@end example
1039
1040Once this is in place, the output of a command like @code{guix build}
1041should change from something like:
1042
1043@example
1044$ guix build emacs --dry-run
1045The following derivations would be built:
1046 /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv
1047 /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv
1048 /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv
1049 /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv
1050@dots{}
1051@end example
1052
1053@noindent
1054to something like:
1055
1056@example
1057$ guix build emacs --dry-run
1058The following files would be downloaded:
1059 /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3
1060 /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d
1061 /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16
1062 /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7
1063@dots{}
1064@end example
1065
1066@noindent
1067This indicates that substitutes from @code{hydra.gnu.org} are usable and
1068will be downloaded, when possible, for future builds.
1069
1070Guix ignores substitutes that are not signed, or that are not signed by
ef27aa9c 1071one of the keys listed in the ACL. It also detects and raises an error
c4202d60
LC
1072when attempting to use a substitute that has been tampered with.
1073
1074The substitute mechanism can be disabled globally by running
1075@code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking
1076guix-daemon}). It can also be disabled temporarily by passing the
1077@code{--no-substitutes} option to @command{guix package}, @command{guix
1078build}, and other command-line tools.
1079
1080
1081Today, each individual's control over their own computing is at the
1082mercy of institutions, corporations, and groups with enough power and
1083determination to subvert the computing infrastructure and exploit its
1084weaknesses. While using @code{hydra.gnu.org} substitutes can be
1085convenient, we encourage users to also build on their own, or even run
1086their own build farm, such that @code{hydra.gnu.org} is less of an
1087interesting target.
1088
1089Guix has the foundations to maximize build reproducibility
1090(@pxref{Features}). In most cases, independent builds of a given
1091package or derivation should yield bit-identical results. Thus, through
1092a diverse set of independent package builds, we can strengthen the
1093integrity of our systems.
1094
1095In the future, we want Guix to have support to publish and retrieve
1096binaries to/from other users, in a peer-to-peer fashion. If you would
1097like to discuss this project, join us on @email{guix-devel@@gnu.org}.
1098
1099
6e721c4d
LC
1100@node Packages with Multiple Outputs
1101@section Packages with Multiple Outputs
1102
1103@cindex multiple-output packages
1104@cindex package outputs
1105
1106Often, packages defined in Guix have a single @dfn{output}---i.e., the
1107source package leads exactly one directory in the store. When running
1108@command{guix package -i glibc}, one installs the default output of the
1109GNU libc package; the default output is called @code{out}, but its name
1110can be omitted as shown in this command. In this particular case, the
1111default output of @code{glibc} contains all the C header files, shared
1112libraries, static libraries, Info documentation, and other supporting
1113files.
1114
1115Sometimes it is more appropriate to separate the various types of files
1116produced from a single source package into separate outputs. For
1117instance, the GLib C library (used by GTK+ and related packages)
1118installs more than 20 MiB of reference documentation as HTML pages.
1119To save space for users who do not need it, the documentation goes to a
1120separate output, called @code{doc}. To install the main GLib output,
1121which contains everything but the documentation, one would run:
1122
1123@example
1124guix package -i glib
1125@end example
1126
1127The command to install its documentation is:
1128
1129@example
1130guix package -i glib:doc
1131@end example
1132
1133Some packages install programs with different ``dependency footprints''.
1134For instance, the WordNet package install both command-line tools and
1135graphical user interfaces (GUIs). The former depend solely on the C
1136library, whereas the latter depend on Tcl/Tk and the underlying X
1137libraries. In this case, we leave the command-line tools in the default
1138output, whereas the GUIs are in a separate output. This allows users
1139who do not need the GUIs to save space.
1140
1141There are several such multiple-output packages in the GNU distribution.
91ef73d4
LC
1142Other conventional output names include @code{lib} for libraries and
1143possibly header files, @code{bin} for stand-alone programs, and
1144@code{debug} for debugging information (@pxref{Installing Debugging
1145Files}). The outputs of a packages are listed in the third column of
1146the output of @command{guix package --list-available} (@pxref{Invoking
1147guix package}).
6e721c4d 1148
eeaf4427 1149
e49951eb
MW
1150@node Invoking guix gc
1151@section Invoking @command{guix gc}
fe8ff028
LC
1152
1153@cindex garbage collector
1154Packages that are installed but not used may be @dfn{garbage-collected}.
e49951eb 1155The @command{guix gc} command allows users to explicitly run the garbage
834129e0 1156collector to reclaim space from the @file{/gnu/store} directory.
fe8ff028
LC
1157
1158The garbage collector has a set of known @dfn{roots}: any file under
834129e0 1159@file{/gnu/store} reachable from a root is considered @dfn{live} and
fe8ff028
LC
1160cannot be deleted; any other file is considered @dfn{dead} and may be
1161deleted. The set of garbage collector roots includes default user
e49951eb
MW
1162profiles, and may be augmented with @command{guix build --root}, for
1163example (@pxref{Invoking guix build}).
fe8ff028 1164
1bb9900a
LC
1165Prior to running @code{guix gc --collect-garbage} to make space, it is
1166often useful to remove old generations from user profiles; that way, old
1167package builds referenced by those generations can be reclaimed. This
1168is achieved by running @code{guix package --delete-generations}
1169(@pxref{Invoking guix package}).
1170
e49951eb 1171The @command{guix gc} command has three modes of operation: it can be
fe8ff028
LC
1172used to garbage-collect any dead files (the default), to delete specific
1173files (the @code{--delete} option), or to print garbage-collector
1174information. The available options are listed below:
1175
1176@table @code
1177@item --collect-garbage[=@var{min}]
1178@itemx -C [@var{min}]
834129e0 1179Collect garbage---i.e., unreachable @file{/gnu/store} files and
fe8ff028
LC
1180sub-directories. This is the default operation when no option is
1181specified.
1182
1183When @var{min} is given, stop once @var{min} bytes have been collected.
1184@var{min} may be a number of bytes, or it may include a unit as a
4a44d7bb
LC
1185suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes
1186(@pxref{Block size, size specifications,, coreutils, GNU Coreutils}).
fe8ff028
LC
1187
1188When @var{min} is omitted, collect all the garbage.
1189
1190@item --delete
1191@itemx -d
1192Attempt to delete all the store files and directories specified as
1193arguments. This fails if some of the files are not in the store, or if
1194they are still live.
1195
1196@item --list-dead
1197Show the list of dead files and directories still present in the
1198store---i.e., files and directories no longer reachable from any root.
1199
1200@item --list-live
1201Show the list of live store files and directories.
ba8b732d
LC
1202
1203@end table
1204
1205In addition, the references among existing store files can be queried:
1206
1207@table @code
1208
1209@item --references
1210@itemx --referrers
1211List the references (respectively, the referrers) of store files given
1212as arguments.
1213
8e59fdd5
LC
1214@item --requisites
1215@itemx -R
1216List the requisites of the store files passed as arguments. Requisites
1217include the store files themselves, their references, and the references
1218of these, recursively. In other words, the returned list is the
1219@dfn{transitive closure} of the store files.
1220
fe8ff028
LC
1221@end table
1222
eeaf4427 1223
f651b477
LC
1224@node Invoking guix pull
1225@section Invoking @command{guix pull}
1226
1227Packages are installed or upgraded to the latest version available in
1228the distribution currently available on your local machine. To update
1229that distribution, along with the Guix tools, you must run @command{guix
1230pull}: the command downloads the latest Guix source code and package
1231descriptions, and deploys it.
1232
1233On completion, @command{guix package} will use packages and package
1234versions from this just-retrieved copy of Guix. Not only that, but all
1235the Guix commands and Scheme modules will also be taken from that latest
1236version. New @command{guix} sub-commands added by the update also
1237become available.
1238
1239The @command{guix pull} command is usually invoked with no arguments,
1240but it supports the following options:
1241
1242@table @code
1243@item --verbose
1244Produce verbose output, writing build logs to the standard error output.
1245
ab5d72ad
LC
1246@item --url=@var{url}
1247Download the source tarball of Guix from @var{url}.
1248
1249By default, the tarball is taken from its canonical address at
1250@code{gnu.org}, for the stable branch of Guix.
1251
f651b477
LC
1252@item --bootstrap
1253Use the bootstrap Guile to build the latest Guix. This option is only
1254useful to Guix developers.
1255@end table
1256
760c60d6
LC
1257
1258@node Invoking guix archive
1259@section Invoking @command{guix archive}
1260
1261The @command{guix archive} command allows users to @dfn{export} files
1262from the store into a single archive, and to later @dfn{import} them.
1263In particular, it allows store files to be transferred from one machine
1264to another machine's store. For example, to transfer the @code{emacs}
1265package to a machine connected over SSH, one would run:
1266
1267@example
1268guix archive --export emacs | ssh the-machine guix archive --import
1269@end example
1270
87236aed
LC
1271@noindent
1272However, note that, in this example, all of @code{emacs} and its
1273dependencies are transferred, regardless of what is already available in
1274the target machine's store. The @code{--missing} option can help figure
1275out which items are missing from the target's store.
1276
760c60d6 1277Archives are stored in the ``Nix archive'' or ``Nar'' format, which is
0dbd88db
LC
1278comparable in spirit to `tar', but with a few noteworthy differences
1279that make it more appropriate for our purposes. First, rather than
1280recording all Unix meta-data for each file, the Nar format only mentions
1281the file type (regular, directory, or symbolic link); Unix permissions
1282and owner/group are dismissed. Second, the order in which directory
1283entries are stored always follows the order of file names according to
1284the C locale collation order. This makes archive production fully
1285deterministic.
1286
1287When exporting, the daemon digitally signs the contents of the archive,
1288and that digital signature is appended. When importing, the daemon
1289verifies the signature and rejects the import in case of an invalid
1290signature or if the signing key is not authorized.
760c60d6
LC
1291@c FIXME: Add xref to daemon doc about signatures.
1292
1293The main options are:
1294
1295@table @code
1296@item --export
1297Export the specified store files or packages (see below.) Write the
1298resulting archive to the standard output.
1299
1300@item --import
1301Read an archive from the standard input, and import the files listed
1302therein into the store. Abort if the archive has an invalid digital
f82cc5fd
LC
1303signature, or if it is signed by a public key not among the authorized
1304keys (see @code{--authorize} below.)
554f26ec 1305
87236aed
LC
1306@item --missing
1307Read a list of store file names from the standard input, one per line,
1308and write on the standard output the subset of these files missing from
1309the store.
1310
554f26ec 1311@item --generate-key[=@var{parameters}]
f82cc5fd 1312@cindex signing, archives
554f26ec
LC
1313Generate a new key pair for the daemons. This is a prerequisite before
1314archives can be exported with @code{--export}. Note that this operation
1315usually takes time, because it needs to gather enough entropy to
1316generate the key pair.
1317
1318The generated key pair is typically stored under @file{/etc/guix}, in
1319@file{signing-key.pub} (public key) and @file{signing-key.sec} (private
1320key, which must be kept secret.) When @var{parameters} is omitted, it
1321is a 4096-bit RSA key. Alternately, @var{parameters} can specify
1322@code{genkey} parameters suitable for Libgcrypt (@pxref{General
1323public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
1324Libgcrypt Reference Manual}).
f82cc5fd
LC
1325
1326@item --authorize
1327@cindex authorizing, archives
1328Authorize imports signed by the public key passed on standard input.
1329The public key must be in ``s-expression advanced format''---i.e., the
1330same format as the @file{signing-key.pub} file.
1331
1332The list of authorized keys is kept in the human-editable file
1333@file{/etc/guix/acl}. The file contains
1334@url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
1335s-expressions''} and is structured as an access-control list in the
1336@url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
1337(SPKI)}.
760c60d6
LC
1338@end table
1339
1340To export store files as an archive to the standard output, run:
1341
1342@example
1343guix archive --export @var{options} @var{specifications}...
1344@end example
1345
1346@var{specifications} may be either store file names or package
1347specifications, as for @command{guix package} (@pxref{Invoking guix
1348package}). For instance, the following command creates an archive
1349containing the @code{gui} output of the @code{git} package and the main
1350output of @code{emacs}:
1351
1352@example
834129e0 1353guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
760c60d6
LC
1354@end example
1355
1356If the specified packages are not built yet, @command{guix archive}
1357automatically builds them. The build process may be controlled with the
1358same options that can be passed to the @command{guix build} command
70ee5642 1359(@pxref{Invoking guix build, common build options}).
760c60d6
LC
1360
1361
568717fd
LC
1362@c *********************************************************************
1363@node Programming Interface
1364@chapter Programming Interface
1365
3dc1970d
LC
1366GNU Guix provides several Scheme programming interfaces (APIs) to
1367define, build, and query packages. The first interface allows users to
1368write high-level package definitions. These definitions refer to
1369familiar packaging concepts, such as the name and version of a package,
1370its build system, and its dependencies. These definitions can then be
1371turned into concrete build actions.
1372
ba55b1cb 1373Build actions are performed by the Guix daemon, on behalf of users. In a
3dc1970d 1374standard setup, the daemon has write access to the store---the
834129e0 1375@file{/gnu/store} directory---whereas users do not. The recommended
3dc1970d
LC
1376setup also has the daemon perform builds in chroots, under a specific
1377build users, to minimize interference with the rest of the system.
1378
1379@cindex derivation
1380Lower-level APIs are available to interact with the daemon and the
1381store. To instruct the daemon to perform a build action, users actually
1382provide it with a @dfn{derivation}. A derivation is a low-level
1383representation of the build actions to be taken, and the environment in
1384which they should occur---derivations are to package definitions what
49ad317a
LC
1385assembly is to C programs. The term ``derivation'' comes from the fact
1386that build results @emph{derive} from them.
3dc1970d
LC
1387
1388This chapter describes all these APIs in turn, starting from high-level
1389package definitions.
1390
568717fd 1391@menu
b860f382 1392* Defining Packages:: Defining new packages.
7458bd0a 1393* Build Systems:: Specifying how packages are built.
b860f382
LC
1394* The Store:: Manipulating the package store.
1395* Derivations:: Low-level interface to package derivations.
1396* The Store Monad:: Purely functional interface to the store.
21b679f6 1397* G-Expressions:: Manipulating build expressions.
568717fd
LC
1398@end menu
1399
1400@node Defining Packages
1401@section Defining Packages
1402
3dc1970d
LC
1403The high-level interface to package definitions is implemented in the
1404@code{(guix packages)} and @code{(guix build-system)} modules. As an
1405example, the package definition, or @dfn{recipe}, for the GNU Hello
1406package looks like this:
1407
1408@example
e7f34eb0
LC
1409(define-module (gnu packages hello)
1410 #:use-module (guix packages)
1411 #:use-module (guix download)
1412 #:use-module (guix build-system gnu)
1413 #:use-module (guix licenses))
b22a12fd 1414
79f5dd59 1415(define-public hello
3dc1970d
LC
1416 (package
1417 (name "hello")
1418 (version "2.8")
1419 (source (origin
1420 (method url-fetch)
1421 (uri (string-append "mirror://gnu/hello/hello-" version
1422 ".tar.gz"))
1423 (sha256
1424 (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6"))))
1425 (build-system gnu-build-system)
7458bd0a 1426 (arguments `(#:configure-flags '("--enable-silent-rules")))
3dc1970d 1427 (inputs `(("gawk" ,gawk)))
7458bd0a
LC
1428 (synopsis "Hello, GNU world: An example GNU package")
1429 (description "Guess what GNU Hello prints!")
3dc1970d 1430 (home-page "http://www.gnu.org/software/hello/")
b22a12fd 1431 (license gpl3+)))
3dc1970d
LC
1432@end example
1433
1434@noindent
1435Without being a Scheme expert, the reader may have guessed the meaning
e7f34eb0 1436of the various fields here. This expression binds variable @code{hello}
3dc1970d
LC
1437to a @code{<package>} object, which is essentially a record
1438(@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
1439This package object can be inspected using procedures found in the
1440@code{(guix packages)} module; for instance, @code{(package-name hello)}
1441returns---surprise!---@code{"hello"}.
1442
e7f34eb0
LC
1443In the example above, @var{hello} is defined into a module of its own,
1444@code{(gnu packages hello)}. Technically, this is not strictly
1445necessary, but it is convenient to do so: all the packages defined in
1446modules under @code{(gnu packages @dots{})} are automatically known to
1447the command-line tools (@pxref{Package Modules}).
1448
3dc1970d
LC
1449There are a few points worth noting in the above package definition:
1450
1451@itemize
1452@item
1453The @code{source} field of the package is an @code{<origin>} object.
1454Here, the @code{url-fetch} method from @code{(guix download)} is used,
1455meaning that the source is a file to be downloaded over FTP or HTTP.
1456
1457The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
1458the GNU mirrors defined in @code{(guix download)}.
1459
1460The @code{sha256} field specifies the expected SHA256 hash of the file
1461being downloaded. It is mandatory, and allows Guix to check the
1462integrity of the file. The @code{(base32 @dots{})} form introduces the
6c365eca 1463base32 representation of the hash. You can obtain this information with
210cc920
LC
1464@code{guix download} (@pxref{Invoking guix download}) and @code{guix
1465hash} (@pxref{Invoking guix hash}).
3dc1970d 1466
f9cc8971
LC
1467@cindex patches
1468When needed, the @code{origin} form can also have a @code{patches} field
1469listing patches to be applied, and a @code{snippet} field giving a
1470Scheme expression to modify the source code.
1471
3dc1970d
LC
1472@item
1473@cindex GNU Build System
7458bd0a
LC
1474The @code{build-system} field specifies the procedure to build the
1475package (@pxref{Build Systems}). Here, @var{gnu-build-system}
1476represents the familiar GNU Build System, where packages may be
1477configured, built, and installed with the usual @code{./configure &&
1478make && make check && make install} command sequence.
1479
1480@item
1481The @code{arguments} field specifies options for the build system
1482(@pxref{Build Systems}). Here it is interpreted by
1483@var{gnu-build-system} as a request run @file{configure} with the
1484@code{--enable-silent-rules} flag.
3dc1970d
LC
1485
1486@item
1487The @code{inputs} field specifies inputs to the build process---i.e.,
1488build-time or run-time dependencies of the package. Here, we define an
1489input called @code{"gawk"} whose value is that of the @var{gawk}
1490variable; @var{gawk} is itself bound to a @code{<package>} object.
1491
1492Note that GCC, Coreutils, Bash, and other essential tools do not need to
1493be specified as inputs here. Instead, @var{gnu-build-system} takes care
7458bd0a 1494of ensuring that they are present (@pxref{Build Systems}).
3dc1970d
LC
1495
1496However, any other dependencies need to be specified in the
1497@code{inputs} field. Any dependency not specified here will simply be
1498unavailable to the build process, possibly leading to a build failure.
1499@end itemize
1500
3dc1970d
LC
1501Once a package definition is in place@footnote{Simple package
1502definitions like the one above may be automatically converted from the
e49951eb
MW
1503Nixpkgs distribution using the @command{guix import} command.}, the
1504package may actually be built using the @code{guix build} command-line
7458bd0a 1505tool (@pxref{Invoking guix build}). @xref{Packaging Guidelines}, for
b4f5e0e8
CR
1506more information on how to test package definitions, and
1507@ref{Invoking guix lint}, for information on how to check a definition
1508for style conformance.
1509
7458bd0a
LC
1510
1511Eventually, updating the package definition to a new upstream version
1512can be partly automated by the @command{guix refresh} command
1513(@pxref{Invoking guix refresh}).
3dc1970d
LC
1514
1515Behind the scenes, a derivation corresponding to the @code{<package>}
1516object is first computed by the @code{package-derivation} procedure.
834129e0 1517That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
ba55b1cb 1518The build actions it prescribes may then be realized by using the
3dc1970d
LC
1519@code{build-derivations} procedure (@pxref{The Store}).
1520
1521@deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
59688fc4
LC
1522Return the @code{<derivation>} object of @var{package} for @var{system}
1523(@pxref{Derivations}).
3dc1970d
LC
1524
1525@var{package} must be a valid @code{<package>} object, and @var{system}
1526must be a string denoting the target system type---e.g.,
1527@code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store}
1528must be a connection to the daemon, which operates on the store
1529(@pxref{The Store}).
1530@end deffn
568717fd 1531
9c1edabd
LC
1532@noindent
1533@cindex cross-compilation
1534Similarly, it is possible to compute a derivation that cross-builds a
1535package for some other system:
1536
1537@deffn {Scheme Procedure} package-cross-derivation @var{store} @
1538 @var{package} @var{target} [@var{system}]
59688fc4
LC
1539Return the @code{<derivation>} object of @var{package} cross-built from
1540@var{system} to @var{target}.
9c1edabd
LC
1541
1542@var{target} must be a valid GNU triplet denoting the target hardware
1543and operating system, such as @code{"mips64el-linux-gnu"}
1544(@pxref{Configuration Names, GNU configuration triplets,, configure, GNU
1545Configure and Build System}).
1546@end deffn
1547
1548
7458bd0a
LC
1549@node Build Systems
1550@section Build Systems
1551
1552@cindex build system
1553Each package definition specifies a @dfn{build system} and arguments for
1554that build system (@pxref{Defining Packages}). This @code{build-system}
1555field represents the build procedure of the package, as well implicit
1556dependencies of that build procedure.
1557
1558Build systems are @code{<build-system>} objects. The interface to
1559create and manipulate them is provided by the @code{(guix build-system)}
1560module, and actual build systems are exported by specific modules.
1561
0d5a559f
LC
1562Under the hood, build systems first compile package objects to
1563@dfn{bags}. A @dfn{bag} is like a package, but with less
1564ornamentation---in other words, a bag is a lower-level representation of
1565a package, which includes all the inputs of that package, including some
1566that were implicitly added by the build system. This intermediate
1567representation is then compiled to a derivation (@pxref{Derivations}).
1568
7458bd0a
LC
1569Build systems accept an optional list of @dfn{arguments}. In package
1570definitions, these are passed @i{via} the @code{arguments} field
1571(@pxref{Defining Packages}). They are typically keyword arguments
1572(@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
1573Guile Reference Manual}). The value of these arguments is usually
1574evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
1575by the daemon (@pxref{Derivations}).
1576
1577The main build system is @var{gnu-build-system}, which implements the
1578standard build procedure for GNU packages and many other packages. It
1579is provided by the @code{(guix build-system gnu)} module.
1580
1581@defvr {Scheme Variable} gnu-build-system
1582@var{gnu-build-system} represents the GNU Build System, and variants
1583thereof (@pxref{Configuration, configuration and makefile conventions,,
1584standards, GNU Coding Standards}).
1585
1586@cindex build phases
1587In a nutshell, packages using it configured, built, and installed with
1588the usual @code{./configure && make && make check && make install}
1589command sequence. In practice, a few additional steps are often needed.
1590All these steps are split up in separate @dfn{phases},
1591notably@footnote{Please see the @code{(guix build gnu-build-system)}
1592modules for more details about the build phases.}:
1593
1594@table @code
1595@item unpack
1596Unpack the source tarball, and change the current directory to the
1597extracted source tree. If the source is actually a directory, copy it
1598to the build tree, and enter that directory.
1599
1600@item patch-source-shebangs
1601Patch shebangs encountered in source files so they refer to the right
1602store file names. For instance, this changes @code{#!/bin/sh} to
1603@code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
1604
1605@item configure
1606Run the @file{configure} script with a number of default options, such
1607as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
1608by the @code{#:configure-flags} argument.
1609
1610@item build
1611Run @code{make} with the list of flags specified with
1612@code{#:make-flags}. If the @code{#:parallel-builds?} argument is true
1613(the default), build with @code{make -j}.
1614
1615@item check
1616Run @code{make check}, or some other target specified with
1617@code{#:test-target}, unless @code{#:tests? #f} is passed. If the
1618@code{#:parallel-tests?} argument is true (the default), run @code{make
1619check -j}.
1620
1621@item install
1622Run @code{make install} with the flags listed in @code{#:make-flags}.
1623
1624@item patch-shebangs
1625Patch shebangs on the installed executable files.
1626
1627@item strip
1628Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
1629is false), copying them to the @code{debug} output when available
1630(@pxref{Installing Debugging Files}).
1631@end table
1632
1633@vindex %standard-phases
1634The build-side module @code{(guix build gnu-build-system)} defines
1635@var{%standard-phases} as the default list of build phases.
1636@var{%standard-phases} is a list of symbol/procedure pairs, where the
1637procedure implements the actual phase.
1638
1639The list of phases used for a particular package can be changed with the
1640@code{#:phases} parameter. For instance, passing:
1641
1642@example
1643#:phases (alist-delete 'configure %standard-phases)
1644@end example
1645
9bf404e9 1646means that all the phases described above will be used, except the
7458bd0a
LC
1647@code{configure} phase.
1648
1649In addition, this build system ensures that the ``standard'' environment
1650for GNU packages is available. This includes tools such as GCC, libc,
1651Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
1652build-system gnu)} module for a complete list.) We call these the
1653@dfn{implicit inputs} of a package, because package definitions don't
1654have to mention them.
1655@end defvr
1656
1657Other @code{<build-system>} objects are defined to support other
1658conventions and tools used by free software packages. They inherit most
1659of @var{gnu-build-system}, and differ mainly in the set of inputs
1660implicitly added to the build process, and in the list of phases
1661executed. Some of these build systems are listed below.
1662
1663@defvr {Scheme Variable} cmake-build-system
1664This variable is exported by @code{(guix build-system cmake)}. It
1665implements the build procedure for packages using the
1666@url{http://www.cmake.org, CMake build tool}.
1667
1668It automatically adds the @code{cmake} package to the set of inputs.
1669Which package is used can be specified with the @code{#:cmake}
1670parameter.
9849cfc1
LC
1671
1672The @code{#:configure-flags} parameter is taken as a list of flags
1673passed to the @command{cmake} command. The @code{#:build-type}
1674parameter specifies in abstract terms the flags passed to the compiler;
1675it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
1676debugging information''), which roughly means that code is compiled with
1677@code{-O2 -g}, as is the case for Autoconf-based packages by default.
7458bd0a
LC
1678@end defvr
1679
3afcf52b
FB
1680@defvr {Scheme Variable} glib-or-gtk-build-system
1681This variable is exported by @code{(guix build-system glib-or-gtk)}. It
1682is intended for use with packages making use of GLib or GTK+.
1683
1684This build system adds the following two phases to the ones defined by
1685@var{gnu-build-system}:
1686
1687@table @code
1688@item glib-or-gtk-wrap
1689The phase @code{glib-or-gtk-wrap} ensures that programs found under
1690@file{bin/} are able to find GLib's ``schemas'' and
1691@uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
1692modules}. This is achieved by wrapping the programs in launch scripts
1693that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
1694environment variables.
1695
1696@item glib-or-gtk-compile-schemas
1697The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's
1698@uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
1699GSettings schemas} are compiled. Compilation is performed by the
1700@command{glib-compile-schemas} program. It is provided by the package
1701@code{glib:bin} which is automatically imported by the build system.
1702The @code{glib} package providing @command{glib-compile-schemas} can be
1703specified with the @code{#:glib} parameter.
1704@end table
1705
1706Both phases are executed after the @code{install} phase.
1707@end defvr
1708
7458bd0a
LC
1709@defvr {Scheme Variable} python-build-system
1710This variable is exported by @code{(guix build-system python)}. It
1711implements the more or less standard build procedure used by Python
1712packages, which consists in running @code{python setup.py build} and
1713then @code{python setup.py install --prefix=/gnu/store/@dots{}}.
1714
1715For packages that install stand-alone Python programs under @code{bin/},
1716it takes care of wrapping these programs so their @code{PYTHONPATH}
1717environment variable points to all the Python libraries they depend on.
1718
1719Which Python package is used can be specified with the @code{#:python}
1720parameter.
1721@end defvr
1722
1723@defvr {Scheme Variable} perl-build-system
1724This variable is exported by @code{(guix build-system perl)}. It
1725implements the standard build procedure for Perl packages, which
1726consists in running @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}},
1727followed by @code{make} and @code{make install}.
1728
1729The initial @code{perl Makefile.PL} invocation passes flags specified by
1730the @code{#:make-maker-flags} parameter.
1731
1732Which Perl package is used can be specified with @code{#:perl}.
1733@end defvr
1734
c08f9818
DT
1735@defvr {Scheme Variable} ruby-build-system
1736This variable is exported by @code{(guix build-system ruby)}. It
1737implements the RubyGems build procedure used by Ruby packages, which
1738involves running @code{gem build} followed by @code{gem install}.
1739
1740Which Ruby package is used can be specified with the @code{#:ruby}
1741parameter.
1742@end defvr
7458bd0a
LC
1743
1744Lastly, for packages that do not need anything as sophisticated, a
1745``trivial'' build system is provided. It is trivial in the sense that
1746it provides basically no support: it does not pull any implicit inputs,
1747and does not have a notion of build phases.
1748
1749@defvr {Scheme Variable} trivial-build-system
1750This variable is exported by @code{(guix build-system trivial)}.
1751
1752This build system requires a @code{#:builder} argument. This argument
1753must be a Scheme expression that builds the package's output(s)---as
1754with @code{build-expression->derivation} (@pxref{Derivations,
1755@code{build-expression->derivation}}).
1756@end defvr
1757
568717fd
LC
1758@node The Store
1759@section The Store
1760
e531ac2a
LC
1761@cindex store
1762@cindex store paths
1763
1764Conceptually, the @dfn{store} is where derivations that have been
834129e0 1765successfully built are stored---by default, under @file{/gnu/store}.
e531ac2a
LC
1766Sub-directories in the store are referred to as @dfn{store paths}. The
1767store has an associated database that contains information such has the
1768store paths referred to by each store path, and the list of @emph{valid}
1769store paths---paths that result from a successful build.
1770
1771The store is always accessed by the daemon on behalf of its clients
1772(@pxref{Invoking guix-daemon}). To manipulate the store, clients
1773connect to the daemon over a Unix-domain socket, send it requests, and
1774read the result---these are remote procedure calls, or RPCs.
1775
1776The @code{(guix store)} module provides procedures to connect to the
1777daemon, and to perform RPCs. These are described below.
1778
1779@deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t]
1780Connect to the daemon over the Unix-domain socket at @var{file}. When
1781@var{reserve-space?} is true, instruct it to reserve a little bit of
1782extra space on the file system so that the garbage collector can still
1783operate, should the disk become full. Return a server object.
1784
1785@var{file} defaults to @var{%default-socket-path}, which is the normal
1786location given the options that were passed to @command{configure}.
1787@end deffn
1788
1789@deffn {Scheme Procedure} close-connection @var{server}
1790Close the connection to @var{server}.
1791@end deffn
1792
1793@defvr {Scheme Variable} current-build-output-port
1794This variable is bound to a SRFI-39 parameter, which refers to the port
1795where build and error logs sent by the daemon should be written.
1796@end defvr
1797
1798Procedures that make RPCs all take a server object as their first
1799argument.
1800
1801@deffn {Scheme Procedure} valid-path? @var{server} @var{path}
1802Return @code{#t} when @var{path} is a valid store path.
1803@end deffn
1804
cfbf9160 1805@deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}]
e531ac2a
LC
1806Add @var{text} under file @var{name} in the store, and return its store
1807path. @var{references} is the list of store paths referred to by the
1808resulting store path.
1809@end deffn
1810
874e6874 1811@deffn {Scheme Procedure} build-derivations @var{server} @var{derivations}
59688fc4
LC
1812Build @var{derivations} (a list of @code{<derivation>} objects or
1813derivation paths), and return when the worker is done building them.
1814Return @code{#t} on success.
874e6874
LC
1815@end deffn
1816
b860f382
LC
1817Note that the @code{(guix monads)} module provides a monad as well as
1818monadic versions of the above procedures, with the goal of making it
1819more convenient to work with code that accesses the store (@pxref{The
1820Store Monad}).
1821
e531ac2a
LC
1822@c FIXME
1823@i{This section is currently incomplete.}
568717fd
LC
1824
1825@node Derivations
1826@section Derivations
1827
874e6874
LC
1828@cindex derivations
1829Low-level build actions and the environment in which they are performed
1830are represented by @dfn{derivations}. A derivation contain the
1831following pieces of information:
1832
1833@itemize
1834@item
1835The outputs of the derivation---derivations produce at least one file or
1836directory in the store, but may produce more.
1837
1838@item
1839The inputs of the derivations, which may be other derivations or plain
1840files in the store (patches, build scripts, etc.)
1841
1842@item
1843The system type targeted by the derivation---e.g., @code{x86_64-linux}.
1844
1845@item
1846The file name of a build script in the store, along with the arguments
1847to be passed.
1848
1849@item
1850A list of environment variables to be defined.
1851
1852@end itemize
1853
1854@cindex derivation path
1855Derivations allow clients of the daemon to communicate build actions to
1856the store. They exist in two forms: as an in-memory representation,
1857both on the client- and daemon-side, and as files in the store whose
1858name end in @code{.drv}---these files are referred to as @dfn{derivation
1859paths}. Derivations paths can be passed to the @code{build-derivations}
1860procedure to perform the build actions they prescribe (@pxref{The
1861Store}).
1862
1863The @code{(guix derivations)} module provides a representation of
1864derivations as Scheme objects, along with procedures to create and
1865otherwise manipulate derivations. The lowest-level primitive to create
1866a derivation is the @code{derivation} procedure:
1867
1909431c
LC
1868@deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @
1869 @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
2096ef47 1870 [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @
1909431c 1871 [#:system (%current-system)] [#:references-graphs #f] @
b53be755 1872 [#:allowed-references #f] [#:local-build? #f]
59688fc4
LC
1873Build a derivation with the given arguments, and return the resulting
1874@code{<derivation>} object.
874e6874 1875
2096ef47 1876When @var{hash} and @var{hash-algo} are given, a
874e6874 1877@dfn{fixed-output derivation} is created---i.e., one whose result is
36bbbbd1
LC
1878known in advance, such as a file download. If, in addition,
1879@var{recursive?} is true, then that fixed output may be an executable
1880file or a directory and @var{hash} must be the hash of an archive
1881containing this output.
5b0c9d16 1882
858e9282 1883When @var{references-graphs} is true, it must be a list of file
5b0c9d16
LC
1884name/store path pairs. In that case, the reference graph of each store
1885path is exported in the build environment in the corresponding file, in
1886a simple text format.
1909431c 1887
b53be755
LC
1888When @var{allowed-references} is true, it must be a list of store items
1889or outputs that the derivation's output may refer to.
1890
1909431c
LC
1891When @var{local-build?} is true, declare that the derivation is not a
1892good candidate for offloading and should rather be built locally
1893(@pxref{Daemon Offload Setup}). This is the case for small derivations
1894where the costs of data transfers would outweigh the benefits.
874e6874
LC
1895@end deffn
1896
1897@noindent
1898Here's an example with a shell script as its builder, assuming
1899@var{store} is an open connection to the daemon, and @var{bash} points
1900to a Bash executable in the store:
1901
1902@lisp
1903(use-modules (guix utils)
1904 (guix store)
1905 (guix derivations))
1906
59688fc4
LC
1907(let ((builder ; add the Bash script to the store
1908 (add-text-to-store store "my-builder.sh"
1909 "echo hello world > $out\n" '())))
1910 (derivation store "foo"
1911 bash `("-e" ,builder)
21b679f6 1912 #:inputs `((,bash) (,builder))
59688fc4 1913 #:env-vars '(("HOME" . "/homeless"))))
834129e0 1914@result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo>
874e6874
LC
1915@end lisp
1916
21b679f6
LC
1917As can be guessed, this primitive is cumbersome to use directly. A
1918better approach is to write build scripts in Scheme, of course! The
1919best course of action for that is to write the build code as a
1920``G-expression'', and to pass it to @code{gexp->derivation}. For more
6621cdb6 1921information, @pxref{G-Expressions}.
21b679f6
LC
1922
1923Once upon a time, @code{gexp->derivation} did not exist and constructing
1924derivations with build code written in Scheme was achieved with
1925@code{build-expression->derivation}, documented below. This procedure
1926is now deprecated in favor of the much nicer @code{gexp->derivation}.
874e6874 1927
dd1a5a15
LC
1928@deffn {Scheme Procedure} build-expression->derivation @var{store} @
1929 @var{name} @var{exp} @
1930 [#:system (%current-system)] [#:inputs '()] @
1931 [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @
36bbbbd1 1932 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
63a42824
LC
1933 [#:references-graphs #f] [#:allowed-references #f] @
1934 [#:local-build? #f] [#:guile-for-build #f]
874e6874
LC
1935Return a derivation that executes Scheme expression @var{exp} as a
1936builder for derivation @var{name}. @var{inputs} must be a list of
1937@code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted,
1938@code{"out"} is assumed. @var{modules} is a list of names of Guile
1939modules from the current search path to be copied in the store,
1940compiled, and made available in the load path during the execution of
1941@var{exp}---e.g., @code{((guix build utils) (guix build
1942gnu-build-system))}.
1943
1944@var{exp} is evaluated in an environment where @code{%outputs} is bound
1945to a list of output/path pairs, and where @code{%build-inputs} is bound
1946to a list of string/output-path pairs made from @var{inputs}.
1947Optionally, @var{env-vars} is a list of string pairs specifying the name
1948and value of environment variables visible to the builder. The builder
1949terminates by passing the result of @var{exp} to @code{exit}; thus, when
1950@var{exp} returns @code{#f}, the build is considered to have failed.
1951
1952@var{exp} is built using @var{guile-for-build} (a derivation). When
1953@var{guile-for-build} is omitted or is @code{#f}, the value of the
1954@code{%guile-for-build} fluid is used instead.
9c629a27 1955
63a42824
LC
1956See the @code{derivation} procedure for the meaning of
1957@var{references-graphs}, @var{allowed-references}, and @var{local-build?}.
874e6874
LC
1958@end deffn
1959
1960@noindent
1961Here's an example of a single-output derivation that creates a directory
1962containing one file:
1963
1964@lisp
1965(let ((builder '(let ((out (assoc-ref %outputs "out")))
834129e0 1966 (mkdir out) ; create /gnu/store/@dots{}-goo
874e6874
LC
1967 (call-with-output-file (string-append out "/test")
1968 (lambda (p)
1969 (display '(hello guix) p))))))
dd1a5a15 1970 (build-expression->derivation store "goo" builder))
874e6874 1971
834129e0 1972@result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}>
874e6874
LC
1973@end lisp
1974
568717fd 1975
b860f382
LC
1976@node The Store Monad
1977@section The Store Monad
1978
1979@cindex monad
1980
1981The procedures that operate on the store described in the previous
1982sections all take an open connection to the build daemon as their first
1983argument. Although the underlying model is functional, they either have
1984side effects or depend on the current state of the store.
1985
1986The former is inconvenient: the connection to the build daemon has to be
1987carried around in all those functions, making it impossible to compose
1988functions that do not take that parameter with functions that do. The
1989latter can be problematic: since store operations have side effects
1990and/or depend on external state, they have to be properly sequenced.
1991
1992@cindex monadic values
1993@cindex monadic functions
1994This is where the @code{(guix monads)} module comes in. This module
1995provides a framework for working with @dfn{monads}, and a particularly
1996useful monad for our uses, the @dfn{store monad}. Monads are a
1997construct that allows two things: associating ``context'' with values
1998(in our case, the context is the store), and building sequences of
1999computations (here computations includes accesses to the store.) Values
2000in a monad---values that carry this additional context---are called
2001@dfn{monadic values}; procedures that return such values are called
2002@dfn{monadic procedures}.
2003
2004Consider this ``normal'' procedure:
2005
2006@example
45adbd62
LC
2007(define (sh-symlink store)
2008 ;; Return a derivation that symlinks the 'bash' executable.
2009 (let* ((drv (package-derivation store bash))
2010 (out (derivation->output-path drv))
2011 (sh (string-append out "/bin/bash")))
2012 (build-expression->derivation store "sh"
2013 `(symlink ,sh %output))))
b860f382
LC
2014@end example
2015
2016Using @code{(guix monads)}, it may be rewritten as a monadic function:
2017
ada3df03 2018@c FIXME: Find a better example, one that uses 'mlet'.
b860f382 2019@example
45adbd62 2020(define (sh-symlink)
b860f382 2021 ;; Same, but return a monadic value.
ada3df03
LC
2022 (gexp->derivation "sh"
2023 #~(symlink (string-append #$bash "/bin/bash") #$output)))
b860f382
LC
2024@end example
2025
2026There are two things to note in the second version: the @code{store}
2027parameter is now implicit, and the monadic value returned by
2028@code{package-file}---a wrapper around @code{package-derivation} and
2029@code{derivation->output-path}---is @dfn{bound} using @code{mlet}
2030instead of plain @code{let}.
2031
2032Calling the monadic @code{profile.sh} has no effect. To get the desired
2033effect, one must use @code{run-with-store}:
2034
2035@example
2036(run-with-store (open-connection) (profile.sh))
834129e0 2037@result{} /gnu/store/...-profile.sh
b860f382
LC
2038@end example
2039
b9b86078
LC
2040Note that the @code{(guix monad-repl)} module extends Guile's REPL with
2041new ``meta-commands'' to make it easier to deal with monadic procedures:
2042@code{run-in-store}, and @code{enter-store-monad}. The former, is used
2043to ``run'' a single monadic value through the store:
2044
2045@example
2046scheme@@(guile-user)> ,run-in-store (package->derivation hello)
2047$1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
2048@end example
2049
2050The latter enters a recursive REPL, where all the return values are
2051automatically run through the store:
2052
2053@example
2054scheme@@(guile-user)> ,enter-store-monad
2055store-monad@@(guile-user) [1]> (package->derivation hello)
2056$2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}>
2057store-monad@@(guile-user) [1]> (text-file "foo" "Hello!")
2058$3 = "/gnu/store/@dots{}-foo"
2059store-monad@@(guile-user) [1]> ,q
2060scheme@@(guile-user)>
2061@end example
2062
2063@noindent
2064Note that non-monadic values cannot be returned in the
2065@code{store-monad} REPL.
2066
b860f382
LC
2067The main syntactic forms to deal with monads in general are described
2068below.
2069
2070@deffn {Scheme Syntax} with-monad @var{monad} @var{body} ...
2071Evaluate any @code{>>=} or @code{return} forms in @var{body} as being
2072in @var{monad}.
2073@end deffn
2074
2075@deffn {Scheme Syntax} return @var{val}
2076Return a monadic value that encapsulates @var{val}.
2077@end deffn
2078
2079@deffn {Scheme Syntax} >>= @var{mval} @var{mproc}
2080@dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic
2081procedure @var{mproc}@footnote{This operation is commonly referred to as
2082``bind'', but that name denotes an unrelated procedure in Guile. Thus
2083we use this somewhat cryptic symbol inherited from the Haskell
2084language.}.
2085@end deffn
2086
2087@deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @
2088 @var{body} ...
2089@deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @
2090 @var{body} ...
2091Bind the variables @var{var} to the monadic values @var{mval} in
2092@var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the
2093``normal'' value @var{val}, as per @code{let}.
2094
2095@code{mlet*} is to @code{mlet} what @code{let*} is to @code{let}
2096(@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}).
2097@end deffn
2098
405a9d4e
LC
2099@deffn {Scheme System} mbegin @var{monad} @var{mexp} ...
2100Bind @var{mexp} and the following monadic expressions in sequence,
2101returning the result of the last expression.
2102
2103This is akin to @code{mlet}, except that the return values of the
2104monadic expressions are ignored. In that sense, it is analogous to
2105@code{begin}, but applied to monadic expressions.
2106@end deffn
2107
b860f382
LC
2108The interface to the store monad provided by @code{(guix monads)} is as
2109follows.
2110
2111@defvr {Scheme Variable} %store-monad
2112The store monad. Values in the store monad encapsulate accesses to the
2113store. When its effect is needed, a value of the store monad must be
2114``evaluated'' by passing it to the @code{run-with-store} procedure (see
2115below.)
2116@end defvr
2117
2118@deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)]
2119Run @var{mval}, a monadic value in the store monad, in @var{store}, an
2120open store connection.
2121@end deffn
2122
2123@deffn {Monadic Procedure} text-file @var{name} @var{text}
2124Return as a monadic value the absolute file name in the store of the file
45adbd62
LC
2125containing @var{text}, a string.
2126@end deffn
2127
2128@deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{}
2129Return as a monadic value a derivation that builds a text file
2130containing all of @var{text}. @var{text} may list, in addition to
2131strings, packages, derivations, and store file names; the resulting
2132store file holds references to all these.
2133
2134This variant should be preferred over @code{text-file} anytime the file
2135to create will reference items from the store. This is typically the
2136case when building a configuration file that embeds store file names,
2137like this:
2138
2139@example
2140(define (profile.sh)
2141 ;; Return the name of a shell script in the store that
2142 ;; initializes the 'PATH' environment variable.
2143 (text-file* "profile.sh"
2144 "export PATH=" coreutils "/bin:"
2145 grep "/bin:" sed "/bin\n"))
2146@end example
2147
834129e0 2148In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file
45adbd62
LC
2149will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
2150preventing them from being garbage-collected during its lifetime.
b860f382
LC
2151@end deffn
2152
0a90af15
LC
2153@deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @
2154 [#:recursive? #t]
2155Return the name of @var{file} once interned in the store. Use
2156@var{name} as its store name, or the basename of @var{file} if
2157@var{name} is omitted.
2158
2159When @var{recursive?} is true, the contents of @var{file} are added
2160recursively; if @var{file} designates a flat file and @var{recursive?}
2161is true, its contents are added, and its permission bits are kept.
2162
2163The example below adds a file to the store, under two different names:
2164
2165@example
2166(run-with-store (open-connection)
2167 (mlet %store-monad ((a (interned-file "README"))
2168 (b (interned-file "README" "LEGU-MIN")))
2169 (return (list a b))))
2170
2171@result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN")
2172@end example
2173
2174@end deffn
2175
b860f382 2176@deffn {Monadic Procedure} package-file @var{package} [@var{file}] @
4231f05b
LC
2177 [#:system (%current-system)] [#:target #f] @
2178 [#:output "out"] Return as a monadic
b860f382
LC
2179value in the absolute file name of @var{file} within the @var{output}
2180directory of @var{package}. When @var{file} is omitted, return the name
4231f05b
LC
2181of the @var{output} directory of @var{package}. When @var{target} is
2182true, use it as a cross-compilation target triplet.
b860f382
LC
2183@end deffn
2184
b860f382 2185@deffn {Monadic Procedure} package->derivation @var{package} [@var{system}]
4231f05b
LC
2186@deffnx {Monadic Procedure} package->cross-derivation @var{package} @
2187 @var{target} [@var{system}]
2188Monadic version of @code{package-derivation} and
2189@code{package-cross-derivation} (@pxref{Defining Packages}).
b860f382
LC
2190@end deffn
2191
2192
21b679f6
LC
2193@node G-Expressions
2194@section G-Expressions
2195
2196@cindex G-expression
2197@cindex build code quoting
2198So we have ``derivations'', which represent a sequence of build actions
2199to be performed to produce an item in the store (@pxref{Derivations}).
2200Those build actions are performed when asking the daemon to actually
2201build the derivations; they are run by the daemon in a container
2202(@pxref{Invoking guix-daemon}).
2203
2204@cindex strata of code
2205It should come as no surprise that we like to write those build actions
2206in Scheme. When we do that, we end up with two @dfn{strata} of Scheme
2207code@footnote{The term @dfn{stratum} in this context was coined by
ef4ab0a4
LC
2208Manuel Serrano et al.@: in the context of their work on Hop. Oleg
2209Kiselyov, who has written insightful
2210@url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code
2211on this topic}, refers to this kind of code generation as
2212@dfn{staging}.}: the ``host code''---code that defines packages, talks
2213to the daemon, etc.---and the ``build code''---code that actually
2214performs build actions, such as making directories, invoking
2215@command{make}, etc.
21b679f6
LC
2216
2217To describe a derivation and its build actions, one typically needs to
2218embed build code inside host code. It boils down to manipulating build
2219code as data, and Scheme's homoiconicity---code has a direct
2220representation as data---comes in handy for that. But we need more than
2221Scheme's normal @code{quasiquote} mechanism to construct build
2222expressions.
2223
2224The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of
2225S-expressions adapted to build expressions. G-expressions, or
2226@dfn{gexps}, consist essentially in three syntactic forms: @code{gexp},
2227@code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~},
2228@code{#$}, and @code{#$@@}), which are comparable respectively to
2229@code{quasiquote}, @code{unquote}, and @code{unquote-splicing}
2230(@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile
2231Reference Manual}). However, there are major differences:
2232
2233@itemize
2234@item
2235Gexps are meant to be written to a file and run or manipulated by other
2236processes.
2237
2238@item
2239When a package or derivation is unquoted inside a gexp, the result is as
2240if its output file name had been introduced.
2241
2242@item
2243Gexps carry information about the packages or derivations they refer to,
2244and these dependencies are automatically added as inputs to the build
2245processes that use them.
2246@end itemize
2247
2248To illustrate the idea, here is an example of a gexp:
2249
2250@example
2251(define build-exp
2252 #~(begin
2253 (mkdir #$output)
2254 (chdir #$output)
2255 (symlink (string-append #$coreutils "/bin/ls")
2256 "list-files")))
2257@end example
2258
2259This gexp can be passed to @code{gexp->derivation}; we obtain a
2260derivation that builds a directory containing exactly one symlink to
2261@file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}:
2262
2263@example
2264(gexp->derivation "the-thing" build-exp)
2265@end example
2266
e20fd1bf 2267As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is
21b679f6
LC
2268substituted to the reference to the @var{coreutils} package in the
2269actual build code, and @var{coreutils} is automatically made an input to
2270the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp
2271output)}) is replaced by a string containing the derivation's output
667b2508
LC
2272directory name.
2273
2274@cindex cross compilation
2275In a cross-compilation context, it is useful to distinguish between
2276references to the @emph{native} build of a package---that can run on the
2277host---versus references to cross builds of a package. To that end, the
2278@code{#+} plays the same role as @code{#$}, but is a reference to a
2279native package build:
2280
2281@example
2282(gexp->derivation "vi"
2283 #~(begin
2284 (mkdir #$output)
2285 (system* (string-append #+coreutils "/bin/ln")
2286 "-s"
2287 (string-append #$emacs "/bin/emacs")
2288 (string-append #$output "/bin/vi")))
2289 #:target "mips64el-linux")
2290@end example
2291
2292@noindent
2293In the example above, the native build of @var{coreutils} is used, so
2294that @command{ln} can actually run on the host; but then the
2295cross-compiled build of @var{emacs} is referenced.
2296
2297The syntactic form to construct gexps is summarized below.
21b679f6
LC
2298
2299@deffn {Scheme Syntax} #~@var{exp}
2300@deffnx {Scheme Syntax} (gexp @var{exp})
2301Return a G-expression containing @var{exp}. @var{exp} may contain one
2302or more of the following forms:
2303
2304@table @code
2305@item #$@var{obj}
2306@itemx (ungexp @var{obj})
2307Introduce a reference to @var{obj}. @var{obj} may be a package or a
2308derivation, in which case the @code{ungexp} form is replaced by its
2309output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}.
2310
2311If @var{obj} is a list, it is traversed and any package or derivation
2312references are substituted similarly.
2313
2314If @var{obj} is another gexp, its contents are inserted and its
2315dependencies are added to those of the containing gexp.
2316
2317If @var{obj} is another kind of object, it is inserted as is.
2318
2319@item #$@var{package-or-derivation}:@var{output}
2320@itemx (ungexp @var{package-or-derivation} @var{output})
2321This is like the form above, but referring explicitly to the
2322@var{output} of @var{package-or-derivation}---this is useful when
2323@var{package-or-derivation} produces multiple outputs (@pxref{Packages
2324with Multiple Outputs}).
2325
667b2508
LC
2326@item #+@var{obj}
2327@itemx #+@var{obj}:output
2328@itemx (ungexp-native @var{obj})
2329@itemx (ungexp-native @var{obj} @var{output})
2330Same as @code{ungexp}, but produces a reference to the @emph{native}
2331build of @var{obj} when used in a cross compilation context.
2332
21b679f6
LC
2333@item #$output[:@var{output}]
2334@itemx (ungexp output [@var{output}])
2335Insert a reference to derivation output @var{output}, or to the main
2336output when @var{output} is omitted.
2337
2338This only makes sense for gexps passed to @code{gexp->derivation}.
2339
2340@item #$@@@var{lst}
2341@itemx (ungexp-splicing @var{lst})
2342Like the above, but splices the contents of @var{lst} inside the
2343containing list.
2344
667b2508
LC
2345@item #+@@@var{lst}
2346@itemx (ungexp-native-splicing @var{lst})
2347Like the above, but refers to native builds of the objects listed in
2348@var{lst}.
2349
21b679f6
LC
2350@end table
2351
2352G-expressions created by @code{gexp} or @code{#~} are run-time objects
2353of the @code{gexp?} type (see below.)
2354@end deffn
2355
2356@deffn {Scheme Procedure} gexp? @var{obj}
2357Return @code{#t} if @var{obj} is a G-expression.
2358@end deffn
2359
2360G-expressions are meant to be written to disk, either as code building
2361some derivation, or as plain files in the store. The monadic procedures
2362below allow you to do that (@pxref{The Store Monad}, for more
2363information about monads.)
2364
2365@deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @
68a61e9f 2366 [#:system (%current-system)] [#:target #f] [#:inputs '()] @
21b679f6
LC
2367 [#:hash #f] [#:hash-algo #f] @
2368 [#:recursive? #f] [#:env-vars '()] [#:modules '()] @
2369 [#:references-graphs #f] [#:local-build? #f] @
2370 [#:guile-for-build #f]
2371Return a derivation @var{name} that runs @var{exp} (a gexp) with
68a61e9f
LC
2372@var{guile-for-build} (a derivation) on @var{system}. When @var{target}
2373is true, it is used as the cross-compilation target triplet for packages
2374referred to by @var{exp}.
21b679f6
LC
2375
2376Make @var{modules} available in the evaluation context of @var{EXP};
2377@var{MODULES} is a list of names of Guile modules from the current
2378search path to be copied in the store, compiled, and made available in
2379the load path during the execution of @var{exp}---e.g., @code{((guix
2380build utils) (guix build gnu-build-system))}.
2381
b53833b2
LC
2382When @var{references-graphs} is true, it must be a list of tuples of one of the
2383following forms:
2384
2385@example
2386(@var{file-name} @var{package})
2387(@var{file-name} @var{package} @var{output})
2388(@var{file-name} @var{derivation})
2389(@var{file-name} @var{derivation} @var{output})
2390(@var{file-name} @var{store-item})
2391@end example
2392
2393The right-hand-side of each element of @var{references-graphs} is automatically made
2394an input of the build process of @var{exp}. In the build environment, each
2395@var{file-name} contains the reference graph of the corresponding item, in a simple
2396text format.
2397
e20fd1bf 2398The other arguments are as for @code{derivation} (@pxref{Derivations}).
21b679f6
LC
2399@end deffn
2400
2401@deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
2402Return an executable script @var{name} that runs @var{exp} using
2403@var{guile} with @var{modules} in its search path.
2404
2405The example below builds a script that simply invokes the @command{ls}
2406command:
2407
2408@example
2409(use-modules (guix gexp) (gnu packages base))
2410
2411(gexp->script "list-files"
2412 #~(execl (string-append #$coreutils "/bin/ls")
2413 "ls"))
2414@end example
2415
2416When ``running'' it through the store (@pxref{The Store Monad,
e20fd1bf 2417@code{run-with-store}}), we obtain a derivation that produces an
21b679f6
LC
2418executable file @file{/gnu/store/@dots{}-list-files} along these lines:
2419
2420@example
2421#!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds
2422!#
2423(execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls")
2424 "ls")
2425@end example
2426@end deffn
2427
2428@deffn {Monadic Procedure} gexp->file @var{name} @var{exp}
2429Return a derivation that builds a file @var{name} containing @var{exp}.
2430
2431The resulting file holds references to all the dependencies of @var{exp}
2432or a subset thereof.
2433@end deffn
2434
2435Of course, in addition to gexps embedded in ``host'' code, there are
2436also modules containing build tools. To make it clear that they are
2437meant to be used in the build stratum, these modules are kept in the
2438@code{(guix build @dots{})} name space.
2439
2440
568717fd
LC
2441@c *********************************************************************
2442@node Utilities
2443@chapter Utilities
2444
210cc920
LC
2445This section describes tools primarily targeted at developers and users
2446who write new package definitions. They complement the Scheme
2447programming interface of Guix in a convenient way.
2448
568717fd 2449@menu
37166310 2450* Invoking guix build:: Building packages from the command line.
210cc920 2451* Invoking guix download:: Downloading a file and printing its hash.
37166310
LC
2452* Invoking guix hash:: Computing the cryptographic hash of a file.
2453* Invoking guix refresh:: Updating package definitions.
b4f5e0e8 2454* Invoking guix lint:: Finding errors in package definitions.
372c4bbc 2455* Invoking guix environment:: Setting up development environments.
568717fd
LC
2456@end menu
2457
e49951eb
MW
2458@node Invoking guix build
2459@section Invoking @command{guix build}
568717fd 2460
e49951eb 2461The @command{guix build} command builds packages or derivations and
6798a8e4
LC
2462their dependencies, and prints the resulting store paths. Note that it
2463does not modify the user's profile---this is the job of the
e49951eb 2464@command{guix package} command (@pxref{Invoking guix package}). Thus,
6798a8e4
LC
2465it is mainly useful for distribution developers.
2466
2467The general syntax is:
c78bd12b
LC
2468
2469@example
e49951eb 2470guix build @var{options} @var{package-or-derivation}@dots{}
c78bd12b
LC
2471@end example
2472
2473@var{package-or-derivation} may be either the name of a package found in
5401dd75
LC
2474the software distribution such as @code{coreutils} or
2475@code{coreutils-8.20}, or a derivation such as
834129e0 2476@file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a
e7f34eb0
LC
2477package with the corresponding name (and optionally version) is searched
2478for among the GNU distribution modules (@pxref{Package Modules}).
2479
2480Alternatively, the @code{--expression} option may be used to specify a
2481Scheme expression that evaluates to a package; this is useful when
2482disambiguation among several same-named packages or package variants is
2483needed.
c78bd12b
LC
2484
2485The @var{options} may be zero or more of the following:
2486
2487@table @code
2488
2489@item --expression=@var{expr}
2490@itemx -e @var{expr}
ac5de156 2491Build the package or derivation @var{expr} evaluates to.
c78bd12b 2492
5401dd75 2493For example, @var{expr} may be @code{(@@ (gnu packages guile)
c78bd12b
LC
2494guile-1.8)}, which unambiguously designates this specific variant of
2495version 1.8 of Guile.
2496
56b82106
LC
2497Alternately, @var{expr} may be a G-expression, in which case it is used
2498as a build program passed to @code{gexp->derivation}
2499(@pxref{G-Expressions}).
2500
2501Lastly, @var{expr} may refer to a zero-argument monadic procedure
ac5de156
LC
2502(@pxref{The Store Monad}). The procedure must return a derivation as a
2503monadic value, which is then passed through @code{run-with-store}.
2504
c78bd12b
LC
2505@item --source
2506@itemx -S
2507Build the packages' source derivations, rather than the packages
2508themselves.
2509
e49951eb 2510For instance, @code{guix build -S gcc} returns something like
834129e0 2511@file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball.
c78bd12b 2512
f9cc8971
LC
2513The returned source tarball is the result of applying any patches and
2514code snippets specified in the package's @code{origin} (@pxref{Defining
2515Packages}).
2516
c78bd12b
LC
2517@item --system=@var{system}
2518@itemx -s @var{system}
2519Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
2520the host's system type.
2521
2522An example use of this is on Linux-based systems, which can emulate
2523different personalities. For instance, passing
2524@code{--system=i686-linux} on an @code{x86_64-linux} system allows users
2525to build packages in a complete 32-bit environment.
2526
e55ec43d
LC
2527@item --target=@var{triplet}
2528@cindex cross-compilation
2529Cross-build for @var{triplet}, which must be a valid GNU triplet, such
2530as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU
2531configuration triplets,, configure, GNU Configure and Build System}).
2532
7f3673f2
LC
2533@item --with-source=@var{source}
2534Use @var{source} as the source of the corresponding package.
2535@var{source} must be a file name or a URL, as for @command{guix
2536download} (@pxref{Invoking guix download}).
2537
2538The ``corresponding package'' is taken to be one specified on the
2539command line whose name matches the base of @var{source}---e.g., if
2540@var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding
2541package is @code{guile}. Likewise, the version string is inferred from
2542@var{source}; in the previous example, it's @code{2.0.10}.
2543
2544This option allows users to try out versions of packages other than the
2545one provided by the distribution. The example below downloads
2546@file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for
2547the @code{ed} package:
2548
2549@example
2550guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz
2551@end example
2552
2553As a developer, @code{--with-source} makes it easy to test release
2554candidates:
2555
2556@example
2557guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz
2558@end example
2559
2560
c78bd12b
LC
2561@item --derivations
2562@itemx -d
2563Return the derivation paths, not the output paths, of the given
2564packages.
2565
70ee5642
LC
2566@item --root=@var{file}
2567@itemx -r @var{file}
2568Make @var{file} a symlink to the result, and register it as a garbage
2569collector root.
2570
2571@item --log-file
2572Return the build log file names for the given
2573@var{package-or-derivation}s, or raise an error if build logs are
2574missing.
2575
2576This works regardless of how packages or derivations are specified. For
2577instance, the following invocations are equivalent:
2578
2579@example
2580guix build --log-file `guix build -d guile`
2581guix build --log-file `guix build guile`
2582guix build --log-file guile
2583guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)'
2584@end example
2585
2586
2587@end table
2588
2589@cindex common build options
2590In addition, a number of options that control the build process are
2591common to @command{guix build} and other commands that can spawn builds,
2592such as @command{guix package} or @command{guix archive}. These are the
2593following:
2594
2595@table @code
2596
300868ba
LC
2597@item --load-path=@var{directory}
2598@itemx -L @var{directory}
2599Add @var{directory} to the front of the package module search path
2600(@pxref{Package Modules}).
2601
2602This allows users to define their own packages and make them visible to
2603the command-line tools.
2604
c78bd12b
LC
2605@item --keep-failed
2606@itemx -K
2607Keep the build tree of failed builds. Thus, if a build fail, its build
2608tree is kept under @file{/tmp}, in a directory whose name is shown at
2609the end of the build log. This is useful when debugging build issues.
2610
2611@item --dry-run
2612@itemx -n
2613Do not build the derivations.
2614
56b1f4b7
LC
2615@item --fallback
2616When substituting a pre-built binary fails, fall back to building
2617packages locally.
2618
c78bd12b 2619@item --no-substitutes
b5385b52 2620Do not use substitutes for build products. That is, always build things
c4202d60
LC
2621locally instead of allowing downloads of pre-built binaries
2622(@pxref{Substitutes}).
c78bd12b 2623
425b0bfc 2624@item --no-build-hook
4ec2e92d
LC
2625Do not attempt to offload builds @i{via} the daemon's ``build hook''
2626(@pxref{Daemon Offload Setup}). That is, always build things locally
2627instead of offloading builds to remote machines.
425b0bfc 2628
969e678e
LC
2629@item --max-silent-time=@var{seconds}
2630When the build or substitution process remains silent for more than
2631@var{seconds}, terminate it and report a build failure.
2632
002622b6
LC
2633@item --timeout=@var{seconds}
2634Likewise, when the build or substitution process lasts for more than
2635@var{seconds}, terminate it and report a build failure.
2636
2637By default there is no timeout. This behavior can be restored with
2638@code{--timeout=0}.
2639
07ab4bf1
LC
2640@item --verbosity=@var{level}
2641Use the given verbosity level. @var{level} must be an integer between 0
2642and 5; higher means more verbose output. Setting a level of 4 or more
2643may be helpful when debugging setup issues with the build daemon.
2644
70ee5642
LC
2645@item --cores=@var{n}
2646@itemx -c @var{n}
2647Allow the use of up to @var{n} CPU cores for the build. The special
2648value @code{0} means to use as many CPU cores as available.
bf421152 2649
c78bd12b
LC
2650@end table
2651
e49951eb 2652Behind the scenes, @command{guix build} is essentially an interface to
c78bd12b
LC
2653the @code{package-derivation} procedure of the @code{(guix packages)}
2654module, and to the @code{build-derivations} procedure of the @code{(guix
2655store)} module.
2656
210cc920
LC
2657@node Invoking guix download
2658@section Invoking @command{guix download}
2659
2660When writing a package definition, developers typically need to download
2661the package's source tarball, compute its SHA256 hash, and write that
2662hash in the package definition (@pxref{Defining Packages}). The
2663@command{guix download} tool helps with this task: it downloads a file
2664from the given URI, adds it to the store, and prints both its file name
2665in the store and its SHA256 hash.
2666
2667The fact that the downloaded file is added to the store saves bandwidth:
2668when the developer eventually tries to build the newly defined package
2669with @command{guix build}, the source tarball will not have to be
2670downloaded again because it is already in the store. It is also a
2671convenient way to temporarily stash files, which may be deleted
2672eventually (@pxref{Invoking guix gc}).
2673
2674The @command{guix download} command supports the same URIs as used in
2675package definitions. In particular, it supports @code{mirror://} URIs.
2676@code{https} URIs (HTTP over TLS) are supported @emph{provided} the
2677Guile bindings for GnuTLS are available in the user's environment; when
2678they are not available, an error is raised.
2679
2680The following option is available:
2681
2682@table @code
2683@item --format=@var{fmt}
2684@itemx -f @var{fmt}
2685Write the hash in the format specified by @var{fmt}. For more
2686information on the valid values for @var{fmt}, @ref{Invoking guix hash}.
2687@end table
2688
6c365eca
NK
2689@node Invoking guix hash
2690@section Invoking @command{guix hash}
2691
210cc920 2692The @command{guix hash} command computes the SHA256 hash of a file.
6c365eca
NK
2693It is primarily a convenience tool for anyone contributing to the
2694distribution: it computes the cryptographic hash of a file, which can be
2695used in the definition of a package (@pxref{Defining Packages}).
2696
2697The general syntax is:
2698
2699@example
2700guix hash @var{option} @var{file}
2701@end example
2702
2703@command{guix hash} has the following option:
2704
2705@table @code
2706
2707@item --format=@var{fmt}
2708@itemx -f @var{fmt}
210cc920 2709Write the hash in the format specified by @var{fmt}.
6c365eca
NK
2710
2711Supported formats: @code{nix-base32}, @code{base32}, @code{base16}
2712(@code{hex} and @code{hexadecimal} can be used as well).
2713
2714If the @option{--format} option is not specified, @command{guix hash}
2715will output the hash in @code{nix-base32}. This representation is used
2716in the definitions of packages.
2717
3140f2df
LC
2718@item --recursive
2719@itemx -r
2720Compute the hash on @var{file} recursively.
2721
2722In this case, the hash is computed on an archive containing @var{file},
2723including its children if it is a directory. Some of @var{file}'s
2724meta-data is part of the archive; for instance, when @var{file} is a
2725regular file, the hash is different depending on whether @var{file} is
2726executable or not. Meta-data such as time stamps has no impact on the
2727hash (@pxref{Invoking guix archive}).
2728@c FIXME: Replace xref above with xref to an ``Archive'' section when
2729@c it exists.
2730
6c365eca
NK
2731@end table
2732
37166310
LC
2733@node Invoking guix refresh
2734@section Invoking @command{guix refresh}
2735
2736The primary audience of the @command{guix refresh} command is developers
2737of the GNU software distribution. By default, it reports any packages
2738provided by the distribution that are outdated compared to the latest
2739upstream version, like this:
2740
2741@example
2742$ guix refresh
2743gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1
2744gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0
2745@end example
2746
2747It does so by browsing each package's FTP directory and determining the
2748highest version number of the source tarballs
2749therein@footnote{Currently, this only works for GNU packages.}.
2750
2751When passed @code{--update}, it modifies distribution source files to
2752update the version numbers and source tarball hashes of those packages'
2753recipes (@pxref{Defining Packages}). This is achieved by downloading
2754each package's latest source tarball and its associated OpenPGP
2755signature, authenticating the downloaded tarball against its signature
2756using @command{gpg}, and finally computing its hash. When the public
2757key used to sign the tarball is missing from the user's keyring, an
2758attempt is made to automatically retrieve it from a public key server;
2759when it's successful, the key is added to the user's keyring; otherwise,
2760@command{guix refresh} reports an error.
2761
2762The following options are supported:
2763
2764@table @code
2765
2766@item --update
2767@itemx -u
2768Update distribution source files (package recipes) in place.
2769@ref{Defining Packages}, for more information on package definitions.
2770
2771@item --select=[@var{subset}]
2772@itemx -s @var{subset}
2773Select all the packages in @var{subset}, one of @code{core} or
2774@code{non-core}.
2775
2776The @code{core} subset refers to all the packages at the core of the
2777distribution---i.e., packages that are used to build ``everything
2778else''. This includes GCC, libc, Binutils, Bash, etc. Usually,
2779changing one of these packages in the distribution entails a rebuild of
2780all the others. Thus, such updates are an inconvenience to users in
2781terms of build time or bandwidth used to achieve the upgrade.
2782
2783The @code{non-core} subset refers to the remaining packages. It is
2784typically useful in cases where an update of the core packages would be
2785inconvenient.
2786
2787@end table
2788
2789In addition, @command{guix refresh} can be passed one or more package
2790names, as in this example:
2791
2792@example
2793guix refresh -u emacs idutils
2794@end example
2795
2796@noindent
2797The command above specifically updates the @code{emacs} and
2798@code{idutils} packages. The @code{--select} option would have no
2799effect in this case.
2800
7d193ec3
EB
2801When considering whether to upgrade a package, it is sometimes
2802convenient to know which packages would be affected by the upgrade and
2803should be checked for compatibility. For this the following option may
2804be used when passing @command{guix refresh} one or more package names:
2805
2806@table @code
2807
2808@item --list-dependent
2809@itemx -l
2810List top-level dependent packages that would need to be rebuilt as a
2811result of upgrading one or more packages.
2812
2813@end table
2814
2815Be aware that the @code{--list-dependent} option only
2816@emph{approximates} the rebuilds that would be required as a result of
2817an upgrade. More rebuilds might be required under some circumstances.
2818
2819@example
7779ab61
LC
2820$ guix refresh --list-dependent flex
2821Building the following 120 packages would ensure 213 dependent packages are rebuilt:
2822hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{}
7d193ec3
EB
2823@end example
2824
2825The command above lists a set of packages that could be built to check
2826for compatibility with an upgraded @code{flex} package.
2827
f9230085
LC
2828The following options can be used to customize GnuPG operation:
2829
2830@table @code
2831
2832@item --key-server=@var{host}
2833Use @var{host} as the OpenPGP key server when importing a public key.
2834
2835@item --gpg=@var{command}
2836Use @var{command} as the GnuPG 2.x command. @var{command} is searched
2837for in @code{$PATH}.
2838
2839@end table
2840
b4f5e0e8
CR
2841@node Invoking guix lint
2842@section Invoking @command{guix lint}
2843The @command{guix lint} is meant to help package developers avoid common
2844errors and use a consistent style. It runs a few checks on a given set of
2845packages in order to find common mistakes in their definitions.
2846
2847The general syntax is:
2848
2849@example
2850guix lint @var{options} @var{package}@dots{}
2851@end example
2852
2853If no package is given on the command line, then all packages are checked.
2854The @var{options} may be zero or more of the following:
2855
2856@table @code
2857
dd7c013d
CR
2858@item --checkers
2859@itemx -c
2860Only enable the checkers specified in a comma-separated list using the
2861names returned by @code{--list-checkers}.
2862
b4f5e0e8
CR
2863@item --list-checkers
2864@itemx -l
2865List and describe all the available checkers that will be run on packages
2866and exit.
2867
2868@end table
37166310 2869
372c4bbc
DT
2870@node Invoking guix environment
2871@section Invoking @command{guix environment}
2872
2873The purpose of @command{guix environment} is to assist hackers in
2874creating reproducible development environments without polluting their
2875package profile. The @command{guix environment} tool takes one or more
2876packages, builds all of the necessary inputs, and creates a shell
2877environment to use them.
2878
2879The general syntax is:
2880
2881@example
2882guix environment @var{options} @var{package}@dots{}
2883@end example
2884
2885The following examples spawns a new shell that is capable of building
2886the GNU Guile source code:
2887
2888@example
2889guix environment guile
2890@end example
2891
2892If the specified packages are not built yet, @command{guix environment}
2893automatically builds them. The new shell's environment is an augmented
2894version of the environment that @command{guix environment} was run in.
2895It contains the necessary search paths for building the given package
2896added to the existing environment variables. To create a ``pure''
2897environment in which the original environment variables have been unset,
2898use the @code{--pure} option.
2899
2900Additionally, more than one package may be specified, in which case the
2901union of the inputs for the given packages are used. For example, the
2902command below spawns a shell where all of the dependencies of both Guile
2903and Emacs are available:
2904
2905@example
2906guix environment guile emacs
2907@end example
2908
2909Sometimes an interactive shell session is not desired. The
2910@code{--exec} option can be used to specify the command to run instead.
2911
2912@example
2913guix environment guile --exec=make
2914@end example
2915
2916The following options are available:
2917
2918@table @code
2919@item --expression=@var{expr}
2920@itemx -e @var{expr}
2921Create an environment for the package that @var{expr} evaluates to.
2922
2923@item --load=@var{file}
2924@itemx -l @var{file}
2925Create an environment for the package that the code within @var{file}
2926evaluates to.
2927
2928@item --exec=@var{command}
2929@item -E @var{command}
2930Execute @var{command} in the new environment.
2931
2932@item --pure
2933Unset existing environment variables when building the new environment.
2934This has the effect of creating an environment in which search paths
2935only contain package inputs.
2936
2937@item --search-paths
2938Display the environment variable definitions that make up the
2939environment.
2940@end table
2941
2942It also supports all of the common build options that @command{guix
2943build} supports (@pxref{Invoking guix build, common build options}).
2944
a1ba8475
LC
2945@c *********************************************************************
2946@node GNU Distribution
2947@chapter GNU Distribution
2948
2949Guix comes with a distribution of free software@footnote{The term
2950``free'' here refers to the
2951@url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to
c320011d 2952users of that software}.} that forms the basis of the GNU system. This
a1ba8475
LC
2953includes core GNU packages such as GNU libc, GCC, and Binutils, as well
2954as many GNU and non-GNU applications. The complete list of available
d03bb653
LC
2955packages can be browsed
2956@url{http://www.gnu.org/software/guix/package-list.html,on-line} or by
2957running @command{guix package} (@pxref{Invoking guix package}):
a1ba8475
LC
2958
2959@example
e49951eb 2960guix package --list-available
a1ba8475
LC
2961@end example
2962
401c53c4
LC
2963Our goal is to build a practical 100% free software distribution of
2964Linux-based and other variants of GNU, with a focus on the promotion and
2965tight integration of GNU components, and an emphasis on programs and
2966tools that help users exert that freedom.
2967
c320011d
LC
2968The GNU distribution is currently available on the following platforms:
2969
2970@table @code
2971
2972@item x86_64-linux
2973Intel/AMD @code{x86_64} architecture, Linux-Libre kernel;
2974
2975@item i686-linux
2976Intel 32-bit architecture (IA32), Linux-Libre kernel;
2977
2978@item mips64el-linux
2979little-endian 64-bit MIPS processors, specifically the Loongson series,
2980n32 application binary interface (ABI), and Linux-Libre kernel.
2981
2982@end table
2983
2984@noindent
2985For information on porting to other architectures or kernels,
2986@xref{Porting}.
2987
401c53c4 2988@menu
5af6de3e 2989* System Installation:: Installing the whole operating system.
cf4a9129 2990* System Configuration:: Configuring a GNU system.
91ef73d4 2991* Installing Debugging Files:: Feeding the debugger.
401c53c4 2992* Package Modules:: Packages from the programmer's viewpoint.
da7cabd4 2993* Packaging Guidelines:: Growing the distribution.
401c53c4 2994* Bootstrapping:: GNU/Linux built from scratch.
8b315a6d 2995* Porting:: Targeting another platform or kernel.
401c53c4
LC
2996@end menu
2997
2998Building this distribution is a cooperative effort, and you are invited
2999to join! @ref{Contributing}, for information about how you can help.
3000
5af6de3e
LC
3001@node System Installation
3002@section System Installation
3003
3004This section explains how to install the complete GNU operating system
3005on a machine. The Guix package manager can also be installed on top of
6621cdb6 3006a running GNU/Linux system, @pxref{Installation}.
5af6de3e
LC
3007
3008@ifinfo
3009@c This paragraph is for people reading this from tty2 of the
3010@c installation image.
3011You're reading this documentation with an Info reader. For details on
3012how to use it, hit the @key{RET} key (``return'' or ``enter'') on the
6621cdb6 3013link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit
5af6de3e
LC
3014@kbd{l} afterwards to come back here.
3015@end ifinfo
3016
8aaaae38
LC
3017@subsection Limitations
3018
3019As of version @value{VERSION}, GNU@tie{}Guix and the GNU system
3020distribution are alpha software. It may contain bugs and lack important
3021features. Thus, if you are looking for a stable production system that
3022respects your freedom as a computer user, a good solution at this point
3023is to consider @url{http://www.gnu.org/distros/free-distros.html, one of
3024more established GNU/Linux distributions}. We hope you can soon switch
3025to the GNU system without fear, of course. In the meantime, you can
3026also keep using your distribution and try out the package manager on top
3027of it (@pxref{Installation}).
3028
3029Before you proceed with the installation, be aware of the following
3030noteworthy limitations applicable to version @value{VERSION}:
3031
3032@itemize
3033@item
3034The installation process does not include a graphical user interface and
3035requires familiarity with GNU/Linux (see the following subsections to
3036get a feel of what that means.)
3037
3038@item
3039The system does not yet provide graphical desktop environments such as
3040GNOME and KDE.
3041
3042@item
dbcb0ab1 3043Support for the Logical Volume Manager (LVM) is missing.
8aaaae38
LC
3044
3045@item
3046Few system services are currently supported out-of-the-box
3047(@pxref{Services}).
3048
3049@item
3050On the order of 1,000 packages are available, which means that you may
3051occasionally find that a useful package is missing.
3052@end itemize
3053
3054You've been warned. But more than a disclaimer, this is an invitation
3055to report issues (and success stories!), and join us in improving it.
3056@xref{Contributing}, for more info.
5af6de3e
LC
3057
3058@subsection USB Stick Installation
3059
3060An installation image for USB sticks can be downloaded from
3061@url{ftp://alpha.gnu.org/gnu/guix/gnu-usb-install-@value{VERSION}.@var{system}.xz},
3062where @var{system} is one of:
3063
3064@table @code
3065@item x86_64-linux
3066for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs;
3067
3068@item i686-linux
3069for a 32-bit GNU/Linux system on Intel-compatible CPUs.
3070@end table
3071
3072This image contains a single partition with the tools necessary for an
3073installation. It is meant to be copied @emph{as is} to a large-enough
3074USB stick.
3075
3076To copy the image to a USB stick, follow these steps:
3077
3078@enumerate
3079@item
3080Decompress the image using the @command{xz} command:
3081
3082@example
3083xz -d gnu-usb-install-@value{VERSION}.@var{system}.xz
3084@end example
3085
3086@item
3087Insert a USB stick of 1@tie{}GiB or more in your machine, and determine
3088its device name. Assuming that USB stick is known as @file{/dev/sdX},
3089copy the image with:
3090
3091@example
445d6529 3092dd if=gnu-usb-install-@value{VERSION}.x86_64 of=/dev/sdX
5af6de3e
LC
3093@end example
3094
3095Access to @file{/dev/sdX} usually requires root privileges.
3096@end enumerate
3097
3098Once this is done, you should be able to reboot the system and boot from
3099the USB stick. The latter usually requires you to get in the BIOS' boot
3100menu, where you can choose to boot from the USB stick.
3101
3102@subsection Preparing for Installation
3103
3104Once you have successfully booted the image on the USB stick, you should
3105end up with a root prompt. Several console TTYs are configured and can
3106be used to run commands as root. TTY2 shows this documentation,
3107browsable using the Info reader commands (@pxref{Help,,, info, Info: An
3108Introduction}).
3109
3110To install the system, you would:
3111
3112@enumerate
3113
3114@item
3115Configure the network, by running @command{dhclient eth0} (to get an
3116automatically assigned IP address from the wired network interface
3117controller), or using the @command{ifconfig} command.
3118
3119The system automatically loads drivers for your network interface
3120controllers.
3121
3122Setting up network access is almost always a requirement because the
3123image does not contain all the software and tools that may be needed.
3124
3125@item
3126Unless this has already been done, you must partition and format the
3127target partitions.
3128
7ab44369
LC
3129Preferably, assign partitions a label so that you can easily and
3130reliably refer to them in @code{file-system} declarations (@pxref{File
3131Systems}). This is typically done using the @code{-L} option of
3132@command{mkfs.ext4} and related commands.
3133
5af6de3e
LC
3134The installation image includes Parted (@pxref{Overview,,, parted, GNU
3135Parted User Manual}), @command{fdisk}, and e2fsprogs, the suite of tools
3136to manipulate ext2/ext3/ext4 file systems.
3137
83a17b62
LC
3138@item
3139Once that is done, mount the target root partition under @file{/mnt}.
3140
3141@item
3142Lastly, run @code{deco start cow-store /mnt}.
3143
3144This will make @file{/gnu/store} copy-on-write, such that packages added
3145to it during the installation phase will be written to the target disk
3146rather than kept in memory.
3147
5af6de3e
LC
3148@end enumerate
3149
5af6de3e
LC
3150
3151@subsection Proceeding with the Installation
3152
3153With the target partitions ready, you now have to edit a file and
3154provide the declaration of the operating system to be installed. To
3155that end, the installation system comes with two text editors: GNU nano
3156(@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone.
3157It is better to store that file on the target root file system, say, as
3158@file{/mnt/etc/config.scm}.
3159
3160A minimal operating system configuration, with just the bare minimum and
1dac8566
LC
3161only a root account would look like this (on the installation system,
3162this example is available as @file{/etc/configuration-template.scm}):
5af6de3e
LC
3163
3164@example
931c132a 3165@include os-config.texi
5af6de3e
LC
3166@end example
3167
3168@noindent
3169For more information on @code{operating-system} declarations,
6621cdb6 3170@pxref{Using the Configuration System}.
5af6de3e
LC
3171
3172Once that is done, the new system must be initialized (remember that the
3173target root file system is mounted under @file{/mnt}):
3174
3175@example
3176guix system init /mnt/etc/config.scm /mnt
3177@end example
3178
3179@noindent
3180This will copy all the necessary files, and install GRUB on
3181@file{/dev/sdX}, unless you pass the @option{--no-grub} option. For
6621cdb6 3182more information, @pxref{Invoking guix system}. This command may trigger
5af6de3e
LC
3183downloads or builds of missing packages, which can take some time.
3184
3185Once that command has completed---and hopefully succeeded!---you can
ad14d9e7 3186run @command{reboot} and boot into the new system. Cross fingers, and
5af6de3e
LC
3187join us on @code{#guix} on the Freenode IRC network or on
3188@file{guix-devel@@gnu.org} to share your experience---good or not so
3189good.
3190
3191@subsection Building the Installation Image
3192
3193The installation image described above was built using the @command{guix
3194system} command, specifically:
3195
3196@example
3197guix system disk-image --image-size=800MiB gnu/system/install.scm
3198@end example
3199
3200@xref{Invoking guix system}, for more information. See
3201@file{gnu/system/install.scm} in the source tree for more information
3202about the installation image.
3203
cf4a9129
LC
3204@node System Configuration
3205@section System Configuration
b208a005 3206
cf4a9129
LC
3207@cindex system configuration
3208The GNU system supports a consistent whole-system configuration
3209mechanism. By that we mean that all aspects of the global system
3210configuration---such as the available system services, timezone and
3211locale settings, user accounts---are declared in a single place. Such
3212a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected.
91ef73d4 3213
cf4a9129
LC
3214One of the advantages of putting all the system configuration under the
3215control of Guix is that it supports transactional system upgrades, and
3216makes it possible to roll-back to a previous system instantiation,
3217should something go wrong with the new one (@pxref{Features}). Another
3218one is that it makes it easy to replicate the exact same configuration
3219across different machines, or at different points in time, without
3220having to resort to additional administration tools layered on top of
3221the system's own tools.
3222@c Yes, we're talking of Puppet, Chef, & co. here. ↑
91ef73d4 3223
cf4a9129
LC
3224This section describes this mechanism. First we focus on the system
3225administrator's viewpoint---explaining how the system is configured and
3226instantiated. Then we show how this mechanism can be extended, for
3227instance to support new system services.
91ef73d4 3228
cf4a9129
LC
3229@menu
3230* Using the Configuration System:: Customizing your GNU system.
7313a52e 3231* operating-system Reference:: Detail of operating-system declarations.
cf4a9129 3232* File Systems:: Configuring file system mounts.
510f9d86 3233* Mapped Devices:: Block device extra processing.
cf4a9129
LC
3234* User Accounts:: Specifying user accounts.
3235* Services:: Specifying system services.
0ae8c15a 3236* Setuid Programs:: Programs running with root privileges.
fd1b1fa2 3237* Initial RAM Disk:: Linux-Libre bootstrapping.
cf4a9129
LC
3238* Invoking guix system:: Instantiating a system configuration.
3239* Defining Services:: Adding new service definitions.
3240@end menu
91ef73d4 3241
cf4a9129
LC
3242@node Using the Configuration System
3243@subsection Using the Configuration System
64d76fa6 3244
cf4a9129
LC
3245The operating system is configured by providing an
3246@code{operating-system} declaration in a file that can then be passed to
3247the @command{guix system} command (@pxref{Invoking guix system}). A
3248simple setup, with the default system services, the default Linux-Libre
3249kernel, initial RAM disk, and boot loader looks like this:
91ef73d4 3250
cf4a9129
LC
3251@findex operating-system
3252@lisp
3253(use-modules (gnu) ; for 'user-account', '%base-services', etc.
3254 (gnu packages emacs) ; for 'emacs'
3255 (gnu services ssh)) ; for 'lsh-service'
91ef73d4 3256
cf4a9129
LC
3257(operating-system
3258 (host-name "komputilo")
3259 (timezone "Europe/Paris")
3260 (locale "fr_FR.UTF-8")
3261 (bootloader (grub-configuration
3262 (device "/dev/sda")))
a69576ea 3263 (file-systems (cons (file-system
cf4a9129
LC
3264 (device "/dev/sda1") ; or partition label
3265 (mount-point "/")
a69576ea
LC
3266 (type "ext3"))
3267 %base-file-systems))
cf4a9129
LC
3268 (users (list (user-account
3269 (name "alice")
3270 (password "")
1c00f836 3271 (uid 1000) (group 100)
cf4a9129
LC
3272 (comment "Bob's sister")
3273 (home-directory "/home/alice"))))
3274 (packages (cons emacs %base-packages))
3275 (services (cons (lsh-service #:port 2222 #:allow-root-login? #t)
3276 %base-services)))
3277@end lisp
401c53c4 3278
cf4a9129
LC
3279This example should be self-describing. Some of the fields defined
3280above, such as @code{host-name} and @code{bootloader}, are mandatory.
3281Others, such as @code{packages} and @code{services}, can be omitted, in
3282which case they get a default value.
e7f34eb0 3283
cf4a9129
LC
3284@vindex %base-packages
3285The @code{packages} field lists
3286packages that will be globally visible on the system, for all user
3287accounts---i.e., in every user's @code{PATH} environment variable---in
3288addition to the per-user profiles (@pxref{Invoking guix package}). The
3289@var{%base-packages} variable provides all the tools one would expect
3290for basic user and administrator tasks---including the GNU Core
3291Utilities, the GNU Networking Utilities, the GNU Zile lightweight text
3292editor, @command{find}, @command{grep}, etc. The example above adds
3293Emacs to those, taken from the @code{(gnu packages emacs)} module
3294(@pxref{Package Modules}).
e7f34eb0 3295
cf4a9129
LC
3296@vindex %base-services
3297The @code{services} field lists @dfn{system services} to be made
3298available when the system starts (@pxref{Services}).
3299The @code{operating-system} declaration above specifies that, in
3300addition to the basic services, we want the @command{lshd} secure shell
3301daemon listening on port 2222, and allowing remote @code{root} logins
3302(@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood,
3303@code{lsh-service} arranges so that @code{lshd} is started with the
3304right command-line options, possibly with supporting configuration files
7313a52e
LC
3305generated as needed (@pxref{Defining Services}). @xref{operating-system
3306Reference}, for details about the available @code{operating-system}
3307fields.
a1ba8475 3308
cf4a9129
LC
3309Assuming the above snippet is stored in the @file{my-system-config.scm}
3310file, the @command{guix system reconfigure my-system-config.scm} command
3311instantiates that configuration, and makes it the default GRUB boot
3312entry (@pxref{Invoking guix system}). The normal way to change the
3313system's configuration is by updating this file and re-running the
3314@command{guix system} command.
b81e1947 3315
cf4a9129
LC
3316At the Scheme level, the bulk of an @code{operating-system} declaration
3317is instantiated with the following monadic procedure (@pxref{The Store
3318Monad}):
b81e1947 3319
cf4a9129
LC
3320@deffn {Monadic Procedure} operating-system-derivation os
3321Return a derivation that builds @var{os}, an @code{operating-system}
3322object (@pxref{Derivations}).
b81e1947 3323
cf4a9129
LC
3324The output of the derivation is a single directory that refers to all
3325the packages, configuration files, and other supporting files needed to
3326instantiate @var{os}.
3327@end deffn
b81e1947 3328
7313a52e
LC
3329@node operating-system Reference
3330@subsection @code{operating-system} Reference
3331
3332This section summarizes all the options available in
3333@code{operating-system} declarations (@pxref{Using the Configuration
3334System}).
3335
3336@deftp {Data Type} operating-system
3337This is the data type representing an operating system configuration.
3338By that, we mean all the global system configuration, not per-user
3339configuration (@pxref{Using the Configuration System}).
3340
3341@table @asis
3342@item @code{kernel} (default: @var{linux-libre})
3343The package object of the operating system to use@footnote{Currently
3344only the Linux-libre kernel is supported. In the future, it will be
3345possible to use the GNU@tie{}Hurd.}.
3346
3347@item @code{bootloader}
3348The system bootloader configuration object.
3349@c FIXME: Add xref to bootloader section.
3350
3351@item @code{initrd} (default: @code{base-initrd})
3352A two-argument monadic procedure that returns an initial RAM disk for
3353the Linux kernel. @xref{Initial RAM Disk}.
3354
3355@item @code{host-name}
3356The host name.
3357
3358@item @code{hosts-file}
3359@cindex hosts file
3360A zero-argument monadic procedure that returns a text file for use as
3361@file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library
3362Reference Manual}). The default is to produce a file with entries for
3363@code{localhost} and @var{host-name}.
3364
3365@item @code{mapped-devices} (default: @code{'()})
3366A list of mapped devices. @xref{Mapped Devices}.
3367
3368@item @code{file-systems}
3369A list of file systems. @xref{File Systems}.
3370
3371@item @code{swap-devices} (default: @code{'()})
3372@cindex swap devices
3373A list of strings identifying devices to be used for ``swap space''
3374(@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}).
3375For example, @code{'("/dev/sda3")}.
3376
3377@item @code{users} (default: @code{'()})
3378@itemx @code{groups} (default: @var{%base-groups})
3379List of user accounts and groups. @xref{User Accounts}.
3380
3381@item @code{skeletons} (default: @code{(default-skeletons)})
3382A monadic list of pairs of target file name and files. These are the
3383files that will be used as skeletons as new accounts are created.
3384
3385For instance, a valid value may look like this:
3386
3387@example
3388(mlet %store-monad ((bashrc (text-file "bashrc" "\
3389 export PATH=$HOME/.guix-profile/bin")))
3390 (return `((".bashrc" ,bashrc))))
3391@end example
3392
3393@item @code{issue} (default: @var{%default-issue})
3394A string denoting the contents of the @file{/etc/issue} file, which is
3395what displayed when users log in on a text console.
3396
3397@item @code{packages} (default: @var{%base-packages})
3398The set of packages installed in the global profile, which is accessible
3399at @file{/run/current-system/profile}.
3400
3401The default set includes core utilities, but it is good practice to
3402install non-core utilities in user profiles (@pxref{Invoking guix
3403package}).
3404
3405@item @code{timezone}
3406A timezone identifying string---e.g., @code{"Europe/Paris"}.
3407
3408@item @code{locale} (default: @code{"en_US.UTF-8"})
3409The name of the default locale (@pxref{Locales,,, libc, The GNU C
3410Library Reference Manual}).
3411
3412@item @code{services} (default: @var{%base-services})
3413A list of monadic values denoting system services. @xref{Services}.
3414
3415@item @code{pam-services} (default: @code{(base-pam-services)})
3416@cindex PAM
3417@cindex pluggable authentication modules
3418Linux @dfn{pluggable authentication module} (PAM) services.
3419@c FIXME: Add xref to PAM services section.
3420
3421@item @code{setuid-programs} (default: @var{%setuid-programs})
3422List of string-valued G-expressions denoting setuid programs.
3423@xref{Setuid Programs}.
3424
3425@item @code{sudoers} (default: @var{%sudoers-specification})
3426@cindex sudoers
3427The contents of the @file{/etc/sudoers} file as a string.
3428
3429This file specifies which users can use the @command{sudo} command, what
3430they are allowed to do, and what privileges they may gain. The default
3431is that only @code{root} and members of the @code{wheel} group may use
3432@code{sudo}.
3433
3434@end table
3435@end deftp
3436
cf4a9129
LC
3437@node File Systems
3438@subsection File Systems
b81e1947 3439
cf4a9129
LC
3440The list of file systems to be mounted is specified in the
3441@code{file-systems} field of the operating system's declaration
3442(@pxref{Using the Configuration System}). Each file system is declared
3443using the @code{file-system} form, like this:
b81e1947
LC
3444
3445@example
cf4a9129
LC
3446(file-system
3447 (mount-point "/home")
3448 (device "/dev/sda3")
3449 (type "ext4"))
b81e1947
LC
3450@end example
3451
cf4a9129
LC
3452As usual, some of the fields are mandatory---those shown in the example
3453above---while others can be omitted. These are described below.
b81e1947 3454
cf4a9129
LC
3455@deftp {Data Type} file-system
3456Objects of this type represent file systems to be mounted. They
3457contain the following members:
5ff3c4b8 3458
cf4a9129
LC
3459@table @asis
3460@item @code{type}
3461This is a string specifying the type of the file system---e.g.,
3462@code{"ext4"}.
5ff3c4b8 3463
cf4a9129
LC
3464@item @code{mount-point}
3465This designates the place where the file system is to be mounted.
b81e1947 3466
cf4a9129
LC
3467@item @code{device}
3468This names the ``source'' of the file system. By default it is the name
3469of a node under @file{/dev}, but its meaning depends on the @code{title}
3470field described below.
401c53c4 3471
cf4a9129
LC
3472@item @code{title} (default: @code{'device})
3473This is a symbol that specifies how the @code{device} field is to be
3474interpreted.
401c53c4 3475
cf4a9129
LC
3476When it is the symbol @code{device}, then the @code{device} field is
3477interpreted as a file name; when it is @code{label}, then @code{device}
3478is interpreted as a partition label name; when it is @code{uuid},
3479@code{device} is interpreted as a partition unique identifier (UUID).
da7cabd4 3480
cf4a9129
LC
3481The @code{label} and @code{uuid} options offer a way to refer to disk
3482partitions without having to hard-code their actual device name.
da7cabd4 3483
cf4a9129
LC
3484@item @code{flags} (default: @code{'()})
3485This is a list of symbols denoting mount flags. Recognized flags
2c071ce9
LC
3486include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow
3487access to special files), @code{no-suid} (ignore setuid and setgid
3488bits), and @code{no-exec} (disallow program execution.)
da7cabd4 3489
cf4a9129
LC
3490@item @code{options} (default: @code{#f})
3491This is either @code{#f}, or a string denoting mount options.
da7cabd4 3492
cf4a9129
LC
3493@item @code{needed-for-boot?} (default: @code{#f})
3494This Boolean value indicates whether the file system is needed when
3495booting. If that is true, then the file system is mounted when the
3496initial RAM disk (initrd) is loaded. This is always the case, for
3497instance, for the root file system.
da7cabd4 3498
cf4a9129
LC
3499@item @code{check?} (default: @code{#t})
3500This Boolean indicates whether the file system needs to be checked for
3501errors before being mounted.
f9cc8971 3502
4e469051
LC
3503@item @code{create-mount-point?} (default: @code{#f})
3504When true, the mount point is created if it does not exist yet.
3505
cf4a9129
LC
3506@end table
3507@end deftp
da7cabd4 3508
a69576ea
LC
3509The @code{(gnu system file-systems)} exports the following useful
3510variables.
3511
3512@defvr {Scheme Variable} %base-file-systems
3513These are essential file systems that are required on normal systems,
3514such as @var{%devtmpfs-file-system} (see below.) Operating system
3515declarations should always contain at least these.
3516@end defvr
3517
3518@defvr {Scheme Variable} %devtmpfs-file-system
3519The @code{devtmpfs} file system to be mounted on @file{/dev}. This is a
3520requirement for udev (@pxref{Base Services, @code{udev-service}}).
3521@end defvr
3522
7f239fd3
LC
3523@defvr {Scheme Variable} %pseudo-terminal-file-system
3524This is the file system to be mounted as @file{/dev/pts}. It supports
3525@dfn{pseudo-terminals} created @i{via} @code{openpty} and similar
3526functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference
3527Manual}). Pseudo-terminals are used by terminal emulators such as
3528@command{xterm}.
3529@end defvr
3530
db17ae5c
LC
3531@defvr {Scheme Variable} %shared-memory-file-system
3532This file system is mounted as @file{/dev/shm} and is used to support
3533memory sharing across processes (@pxref{Memory-mapped I/O,
3534@code{shm_open},, libc, The GNU C Library Reference Manual}).
3535@end defvr
3536
a69576ea
LC
3537@defvr {Scheme Variable} %binary-format-file-system
3538The @code{binfmt_misc} file system, which allows handling of arbitrary
3539executable file types to be delegated to user space. This requires the
3540@code{binfmt.ko} kernel module to be loaded.
3541@end defvr
3542
3543@defvr {Scheme Variable} %fuse-control-file-system
3544The @code{fusectl} file system, which allows unprivileged users to mount
3545and unmount user-space FUSE file systems. This requires the
3546@code{fuse.ko} kernel module to be loaded.
3547@end defvr
3548
510f9d86
LC
3549@node Mapped Devices
3550@subsection Mapped Devices
3551
3552@cindex device mapping
3553@cindex mapped devices
3554The Linux kernel has a notion of @dfn{device mapping}: a block device,
3555such as a hard disk partition, can be @dfn{mapped} into another device,
3556with additional processing over the data that flows through
3557it@footnote{Note that the GNU@tie{}Hurd makes no difference between the
3558concept of a ``mapped device'' and that of a file system: both boil down
3559to @emph{translating} input/output operations made on a file to
3560operations on its backing store. Thus, the Hurd implements mapped
3561devices, like file systems, using the generic @dfn{translator} mechanism
3562(@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A
3563typical example is encryption device mapping: all writes to the mapped
3564device are encrypted, and all reads are deciphered, transparently.
3565
3566Mapped devices are declared using the @code{mapped-device} form:
3567
3568@example
3569(mapped-device
3570 (source "/dev/sda3")
3571 (target "home")
3572 (type luks-device-mapping))
3573@end example
3574
3575@noindent
3576@cindex disk encryption
3577@cindex LUKS
3578This example specifies a mapping from @file{/dev/sda3} to
3579@file{/dev/mapper/home} using LUKS---the
3580@url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a
3581standard mechanism for disk encryption. The @file{/dev/mapper/home}
3582device can then be used as the @code{device} of a @code{file-system}
3583declaration (@pxref{File Systems}). The @code{mapped-device} form is
3584detailed below.
3585
3586@deftp {Data Type} mapped-device
3587Objects of this type represent device mappings that will be made when
3588the system boots up.
3589
3590@table @code
3591@item source
3592This string specifies the name of the block device to be mapped, such as
3593@code{"/dev/sda3"}.
3594
3595@item target
3596This string specifies the name of the mapping to be established. For
3597example, specifying @code{"my-partition"} will lead to the creation of
3598the @code{"/dev/mapper/my-partition"} device.
3599
3600@item type
3601This must be a @code{mapped-device-kind} object, which specifies how
3602@var{source} is mapped to @var{target}.
3603@end table
3604@end deftp
3605
3606@defvr {Scheme Variable} luks-device-mapping
3607This defines LUKS block device encryption using the @command{cryptsetup}
3608command, from the same-named package. This relies on the
3609@code{dm-crypt} Linux kernel module.
3610@end defvr
3611
cf4a9129
LC
3612@node User Accounts
3613@subsection User Accounts
ee85f3db 3614
cf4a9129 3615User accounts are specified with the @code{user-account} form:
ee85f3db 3616
cf4a9129
LC
3617@example
3618(user-account
3619 (name "alice")
3620 (group "users")
24e752c0
LC
3621 (supplementary-groups '("wheel" ;allow use of sudo, etc.
3622 "audio" ;sound card
3623 "video" ;video devices such as webcams
3624 "cdrom")) ;the good ol' CD-ROM
cf4a9129
LC
3625 (comment "Bob's sister")
3626 (home-directory "/home/alice"))
3627@end example
25083588 3628
cf4a9129
LC
3629@deftp {Data Type} user-account
3630Objects of this type represent user accounts. The following members may
3631be specified:
ee85f3db 3632
cf4a9129
LC
3633@table @asis
3634@item @code{name}
3635The name of the user account.
ee85f3db 3636
cf4a9129
LC
3637@item @code{group}
3638This is the name (a string) or identifier (a number) of the user group
3639this account belongs to.
ee85f3db 3640
cf4a9129
LC
3641@item @code{supplementary-groups} (default: @code{'()})
3642Optionally, this can be defined as a list of group names that this
3643account belongs to.
ee85f3db 3644
cf4a9129
LC
3645@item @code{uid} (default: @code{#f})
3646This is the user ID for this account (a number), or @code{#f}. In the
3647latter case, a number is automatically chosen by the system when the
3648account is created.
ee85f3db 3649
cf4a9129
LC
3650@item @code{comment} (default: @code{""})
3651A comment about the account, such as the account's owner full name.
c8c871d1 3652
cf4a9129
LC
3653@item @code{home-directory}
3654This is the name of the home directory for the account.
ee85f3db 3655
cf4a9129
LC
3656@item @code{shell} (default: Bash)
3657This is a G-expression denoting the file name of a program to be used as
3658the shell (@pxref{G-Expressions}).
ee85f3db 3659
cf4a9129
LC
3660@item @code{system?} (default: @code{#f})
3661This Boolean value indicates whether the account is a ``system''
3662account. System accounts are sometimes treated specially; for instance,
3663graphical login managers do not list them.
ee85f3db 3664
cf4a9129
LC
3665@item @code{password} (default: @code{#f})
3666Unless @code{#f}, this is the password to be used for the account.
c8c871d1 3667
cf4a9129
LC
3668@end table
3669@end deftp
ee85f3db 3670
cf4a9129 3671User group declarations are even simpler:
ee85f3db 3672
cf4a9129
LC
3673@example
3674(user-group (name "students"))
3675@end example
ee85f3db 3676
cf4a9129
LC
3677@deftp {Data Type} user-group
3678This type is for, well, user groups. There are just a few fields:
af8a56b8 3679
cf4a9129
LC
3680@table @asis
3681@item @code{name}
3682The group's name.
ee85f3db 3683
cf4a9129
LC
3684@item @code{id} (default: @code{#f})
3685The group identifier (a number). If @code{#f}, a new number is
3686automatically allocated when the group is created.
ee85f3db 3687
c8fa3426
LC
3688@item @code{system?} (default: @code{#f})
3689This Boolean value indicates whether the group is a ``system'' group.
3690System groups have low numerical IDs.
3691
cf4a9129
LC
3692@item @code{password} (default: @code{#f})
3693What, user groups can have a password? Well, apparently yes. Unless
3694@code{#f}, this field specifies the group's password.
ee85f3db 3695
cf4a9129
LC
3696@end table
3697@end deftp
401c53c4 3698
cf4a9129
LC
3699For convenience, a variable lists all the basic user groups one may
3700expect:
401c53c4 3701
cf4a9129
LC
3702@defvr {Scheme Variable} %base-groups
3703This is the list of basic user groups that users and/or packages expect
3704to be present on the system. This includes groups such as ``root'',
3705``wheel'', and ``users'', as well as groups used to control access to
3706specific devices such as ``audio'', ``disk'', and ``cdrom''.
3707@end defvr
401c53c4 3708
401c53c4 3709
cf4a9129
LC
3710@node Services
3711@subsection Services
401c53c4 3712
cf4a9129
LC
3713@cindex system services
3714An important part of preparing an @code{operating-system} declaration is
3715listing @dfn{system services} and their configuration (@pxref{Using the
3716Configuration System}). System services are typically daemons launched
3717when the system boots, or other actions needed at that time---e.g.,
3718configuring network access. They are managed by GNU@tie{}dmd
3719(@pxref{Introduction,,, dmd, GNU dmd Manual}).
401c53c4 3720
cf4a9129
LC
3721The following sections document the available services, starting with
3722the core services.
401c53c4 3723
cf4a9129
LC
3724@menu
3725* Base Services:: Essential system services.
3726* Networking Services:: Network setup, SSH daemon, etc.
3727* X Window:: Graphical display.
3728@end menu
401c53c4 3729
cf4a9129
LC
3730@node Base Services
3731@subsubsection Base Services
a1ba8475 3732
cf4a9129
LC
3733The @code{(gnu services base)} module provides definitions for the basic
3734services that one expects from the system. The services exported by
3735this module are listed below.
401c53c4 3736
cf4a9129
LC
3737@defvr {Scheme Variable} %base-services
3738This variable contains a list of basic services@footnote{Technically,
3739this is a list of monadic services. @xref{The Store Monad}.} one would
3740expect from the system: a login service (mingetty) on each tty, syslogd,
3741libc's name service cache daemon (nscd), the udev device manager, and
3742more.
401c53c4 3743
cf4a9129
LC
3744This is the default value of the @code{services} field of
3745@code{operating-system} declarations. Usually, when customizing a
3746system, you will want to append services to @var{%base-services}, like
3747this:
401c53c4 3748
cf4a9129
LC
3749@example
3750(cons* (avahi-service) (lshd-service) %base-services)
3751@end example
3752@end defvr
401c53c4 3753
cf4a9129
LC
3754@deffn {Monadic Procedure} host-name-service @var{name}
3755Return a service that sets the host name to @var{name}.
3756@end deffn
401c53c4 3757
cf4a9129
LC
3758@deffn {Monadic Procedure} mingetty-service @var{tty} [#:motd] @
3759 [#:auto-login #f] [#:login-program] [#:login-pause? #f] @
3760 [#:allow-empty-passwords? #f]
3761Return a service to run mingetty on @var{tty}.
401c53c4 3762
cf4a9129
LC
3763When @var{allow-empty-passwords?} is true, allow empty log-in password. When
3764@var{auto-login} is true, it must be a user name under which to log-in
3765automatically. @var{login-pause?} can be set to @code{#t} in conjunction with
3766@var{auto-login}, in which case the user will have to press a key before the
3767login shell is launched.
401c53c4 3768
cf4a9129
LC
3769When true, @var{login-program} is a gexp or a monadic gexp denoting the name
3770of the log-in program (the default is the @code{login} program from the Shadow
3771tool suite.)
401c53c4 3772
cf4a9129
LC
3773@var{motd} is a monadic value containing a text file to use as
3774the ``message of the day''.
3775@end deffn
401c53c4 3776
cf4a9129
LC
3777@deffn {Monadic Procedure} nscd-service [#:glibc glibc]
3778Return a service that runs libc's name service cache daemon (nscd).
3779@end deffn
401c53c4 3780
cf4a9129
LC
3781@deffn {Monadic Procedure} syslog-service
3782Return a service that runs @code{syslogd} with reasonable default
3783settings.
3784@end deffn
401c53c4 3785
cf4a9129
LC
3786@deffn {Monadic Procedure} guix-service [#:guix guix] @
3787 [#:builder-group "guixbuild"] [#:build-accounts 10] @
3788 [#:authorize-hydra-key? #f] [#:use-substitutes? #t] @
3789 [#:extra-options '()]
3790Return a service that runs the build daemon from @var{guix}, and has
3791@var{build-accounts} user accounts available under @var{builder-group}.
401c53c4 3792
cf4a9129
LC
3793When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key
3794provided by @var{guix} is authorized upon activation, meaning that substitutes
3795from @code{hydra.gnu.org} are used by default.
401c53c4 3796
cf4a9129
LC
3797If @var{use-substitutes?} is false, the daemon is run with
3798@option{--no-substitutes} (@pxref{Invoking guix-daemon,
3799@option{--no-substitutes}}).
401c53c4 3800
cf4a9129
LC
3801Finally, @var{extra-options} is a list of additional command-line options
3802passed to @command{guix-daemon}.
3803@end deffn
a1ba8475 3804
cf4a9129
LC
3805@deffn {Monadic Procedure} udev-service [#:udev udev]
3806Run @var{udev}, which populates the @file{/dev} directory dynamically.
3807@end deffn
401c53c4 3808
a69576ea 3809
cf4a9129
LC
3810@node Networking Services
3811@subsubsection Networking Services
401c53c4 3812
cf4a9129
LC
3813The @code{(gnu system networking)} module provides services to configure
3814the network interface.
a1ba8475 3815
a023cca8
LC
3816@cindex DHCP, networking service
3817@deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}]
3818Return a service that runs @var{dhcp}, a Dynamic Host Configuration
3819Protocol (DHCP) client, on all the non-loopback network interfaces.
3820@end deffn
3821
cf4a9129
LC
3822@deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @
3823 [#:gateway #f] [#:name-services @code{'()}]
3824Return a service that starts @var{interface} with address @var{ip}. If
3825@var{gateway} is true, it must be a string specifying the default network
3826gateway.
3827@end deffn
8b315a6d 3828
cf4a9129
LC
3829@deffn {Monadic Procedure} tor-service [#:tor tor]
3830Return a service to run the @uref{https://torproject.org,Tor} daemon.
8b315a6d 3831
cf4a9129
LC
3832The daemon runs with the default settings (in particular the default exit
3833policy) as the @code{tor} unprivileged user.
3834@end deffn
8b315a6d 3835
4627a464
LC
3836@deffn {Monadic Procedure} bitlbee-service [#:bitlbee bitlbee] @
3837 [#:interface "127.0.0.1"] [#:port 6667] @
3838 [#:extra-settings ""]
3839Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that
3840acts as a gateway between IRC and chat networks.
3841
3842The daemon will listen to the interface corresponding to the IP address
3843specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only
3844local clients can connect, whereas @code{0.0.0.0} means that connections can
3845come from any networking interface.
3846
3847In addition, @var{extra-settings} specifies a string to append to the
3848configuration file.
3849@end deffn
3850
3851Furthermore, @code{(gnu system ssh)} provides the following service.
8b315a6d 3852
cf4a9129
LC
3853@deffn {Monadic Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
3854 [#:interfaces '()] [#:port-number 22] @
3855 [#:allow-empty-passwords? #f] [#:root-login? #f] @
3856 [#:syslog-output? #t] [#:x11-forwarding? #t] @
3857 [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @
3858 [public-key-authentication? #t] [#:initialize? #f]
3859Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
3860@var{host-key} must designate a file containing the host key, and readable
3861only by root.
72e25e35 3862
cf4a9129
LC
3863When @var{initialize?} is true, automatically create the seed and host key
3864upon service activation if they do not exist yet. This may take long and
3865require interaction.
8b315a6d 3866
cf4a9129
LC
3867When @var{interfaces} is empty, lshd listens for connections on all the
3868network interfaces; otherwise, @var{interfaces} must be a list of host names
3869or addresses.
9bf3c1a7 3870
cf4a9129
LC
3871@var{allow-empty-passwords?} specifies whether to accepts log-ins with empty
3872passwords, and @var{root-login?} specifies whether to accepts log-ins as
3873root.
4af2447e 3874
cf4a9129
LC
3875The other options should be self-descriptive.
3876@end deffn
4af2447e 3877
fa0c1d61
LC
3878@defvr {Scheme Variable} %facebook-host-aliases
3879This variable contains a string for use in @file{/etc/hosts}
3880(@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each
3881line contains a entry that maps a known server name of the Facebook
3882on-line service---e.g., @code{www.facebook.com}---to the local
3883host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}.
3884
3885This variable is typically used in the @code{hosts-file} field of an
7313a52e
LC
3886@code{operating-system} declaration (@pxref{operating-system Reference,
3887@file{/etc/hosts}}):
fa0c1d61
LC
3888
3889@example
3890(use-modules (gnu) (guix))
3891
3892(operating-system
3893 (host-name "mymachine")
3894 ;; ...
3895 (hosts-file
3896 ;; Create a /etc/hosts file with aliases for "localhost"
3897 ;; and "mymachine", as well as for Facebook servers.
3898 (text-file "hosts"
3899 (string-append (local-host-aliases host-name)
3900 %facebook-host-aliases))))
3901@end example
3902
3903This mechanism can prevent programs running locally, such as Web
3904browsers, from accessing Facebook.
3905@end defvr
3906
cf4a9129
LC
3907@node X Window
3908@subsubsection X Window
68ad877c 3909
cf4a9129
LC
3910Support for the X Window graphical display system---specifically
3911Xorg---is provided by the @code{(gnu services xorg)} module. Note that
3912there is no @code{xorg-service} procedure. Instead, the X server is
3913started by the @dfn{login manager}, currently SLiM.
4af2447e 3914
cf4a9129
LC
3915@deffn {Monadic Procedure} slim-service [#:allow-empty-passwords? #f] @
3916 [#:auto-login? #f] [#:default-user ""] [#:startx]
3917Return a service that spawns the SLiM graphical login manager, which in
3918turn starts the X display server with @var{startx}, a command as returned by
3919@code{xorg-start-command}.
4af2447e 3920
cf4a9129
LC
3921When @var{allow-empty-passwords?} is true, allow logins with an empty
3922password. When @var{auto-login?} is true, log in automatically as
3923@var{default-user}.
3924@end deffn
4af2447e 3925
4af2447e 3926
0ae8c15a
LC
3927@node Setuid Programs
3928@subsection Setuid Programs
3929
3930@cindex setuid programs
3931Some programs need to run with ``root'' privileges, even when they are
3932launched by unprivileged users. A notorious example is the
3933@command{passwd} programs, which can users can run to change their
3934password, and which requires write access to the @file{/etc/passwd} and
3935@file{/etc/shadow} files---something normally restricted to root, for
3936obvious security reasons. To address that, these executables are
3937@dfn{setuid-root}, meaning that they always run with root privileges
3938(@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual},
3939for more info about the setuid mechanisms.)
3940
3941The store itself @emph{cannot} contain setuid programs: that would be a
3942security issue since any user on the system can write derivations that
3943populate the store (@pxref{The Store}). Thus, a different mechanism is
3944used: instead of changing the setuid bit directly on files that are in
3945the store, we let the system administrator @emph{declare} which programs
3946should be setuid root.
3947
3948The @code{setuid-programs} field of an @code{operating-system}
3949declaration contains a list of G-expressions denoting the names of
3950programs to be setuid-root (@pxref{Using the Configuration System}).
3951For instance, the @command{passwd} program, which is part of the Shadow
3952package, can be designated by this G-expression (@pxref{G-Expressions}):
3953
3954@example
3955#~(string-append #$shadow "/bin/passwd")
3956@end example
3957
3958A default set of setuid programs is defined by the
3959@code{%setuid-programs} variable of the @code{(gnu system)} module.
3960
3961@defvr {Scheme Variable} %setuid-programs
3962A list of G-expressions denoting common programs that are setuid-root.
3963
3964The list includes commands such as @command{passwd}, @command{ping},
3965@command{su}, and @command{sudo}.
3966@end defvr
3967
3968Under the hood, the actual setuid programs are created in the
3969@file{/run/setuid-programs} directory at system activation time. The
3970files in this directory refer to the ``real'' binaries, which are in the
3971store.
3972
3973
fd1b1fa2
LC
3974@node Initial RAM Disk
3975@subsection Initial RAM Disk
3976
3977@cindex initial RAM disk (initrd)
3978@cindex initrd (initial RAM disk)
3979For bootstrapping purposes, the Linux-Libre kernel is passed an
3980@dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary
3981root file system, as well as an initialization script. The latter is
3982responsible for mounting the real root file system, and for loading any
3983kernel modules that may be needed to achieve that.
3984
3985The @code{initrd} field of an @code{operating-system} declaration allows
3986you to specify which initrd you would like to use. The @code{(gnu
3987system linux-initrd)} module provides two ways to build an initrd: the
3988high-level @code{base-initrd} procedure, and the low-level
3989@code{expression->initrd} procedure.
3990
3991The @code{base-initrd} procedure is intended to cover most common uses.
3992For example, if you want to add a bunch of kernel modules to be loaded
3993at boot time, you can define the @code{initrd} field of the operating
3994system declaration like this:
3995
3996@example
52ac153e
LC
3997(initrd (lambda (file-systems . rest)
3998 (apply base-initrd file-systems
3999 #:extra-modules '("my.ko" "modules.ko")
4000 rest)))
fd1b1fa2
LC
4001@end example
4002
52ac153e
LC
4003The @code{base-initrd} procedure also handles common use cases that
4004involves using the system as a QEMU guest, or as a ``live'' system whose
4005root file system is volatile.
fd1b1fa2
LC
4006
4007@deffn {Monadic Procedure} base-initrd @var{file-systems} @
4008 [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @
52ac153e 4009 [#:extra-modules '()] [#:mapped-devices '()]
fd1b1fa2
LC
4010Return a monadic derivation that builds a generic initrd. @var{file-systems} is
4011a list of file-systems to be mounted by the initrd, possibly in addition to
4012the root file system specified on the kernel command line via @code{--root}.
52ac153e
LC
4013@var{mapped-devices} is a list of device mappings to realize before
4014@var{file-systems} are mounted (@pxref{Mapped Devices}).
fd1b1fa2
LC
4015
4016When @var{qemu-networking?} is true, set up networking with the standard QEMU
4017parameters. When @var{virtio?} is true, load additional modules so the initrd can
4018be used as a QEMU guest with para-virtualized I/O drivers.
4019
4020When @var{volatile-root?} is true, the root file system is writable but any changes
4021to it are lost.
4022
4023The initrd is automatically populated with all the kernel modules necessary
4024for @var{file-systems} and for the given options. However, additional kernel
4025modules can be listed in @var{extra-modules}. They will be added to the initrd, and
4026loaded at boot time in the order in which they appear.
4027@end deffn
4028
4029Needless to say, the initrds we produce and use embed a
4030statically-linked Guile, and the initialization program is a Guile
4031program. That gives a lot of flexibility. The
4032@code{expression->initrd} procedure builds such an initrd, given the
4033program to run in that initrd.
4034
4035@deffn {Monadic Procedure} expression->initrd @var{exp} @
4036 [#:guile %guile-static-stripped] [#:name "guile-initrd"] @
42d10464 4037 [#:modules '()]
fd1b1fa2
LC
4038Return a derivation that builds a Linux initrd (a gzipped cpio archive)
4039containing @var{guile} and that evaluates @var{exp}, a G-expression,
df650fa8
LC
4040upon booting. All the derivations referenced by @var{exp} are
4041automatically copied to the initrd.
fd1b1fa2 4042
42d10464
LC
4043@var{modules} is a list of Guile module names to be embedded in the
4044initrd.
fd1b1fa2
LC
4045@end deffn
4046
cf4a9129
LC
4047@node Invoking guix system
4048@subsection Invoking @code{guix system}
0918e64a 4049
cf4a9129
LC
4050Once you have written an operating system declaration, as seen in the
4051previous section, it can be @dfn{instantiated} using the @command{guix
4052system} command. The synopsis is:
4af2447e 4053
cf4a9129
LC
4054@example
4055guix system @var{options}@dots{} @var{action} @var{file}
4056@end example
4af2447e 4057
cf4a9129
LC
4058@var{file} must be the name of a file containing an
4059@code{operating-system} declaration. @var{action} specifies how the
4060operating system is instantiate. Currently the following values are
4061supported:
4af2447e 4062
cf4a9129
LC
4063@table @code
4064@item reconfigure
4065Build the operating system described in @var{file}, activate it, and
4066switch to it@footnote{This action is usable only on systems already
4067running GNU.}.
4af2447e 4068
cf4a9129
LC
4069This effects all the configuration specified in @var{file}: user
4070accounts, system services, global package list, setuid programs, etc.
4af2447e 4071
cf4a9129
LC
4072It also adds a GRUB menu entry for the new OS configuration, and moves
4073entries for older configurations to a submenu---unless
4074@option{--no-grub} is passed.
4af2447e 4075
cf4a9129
LC
4076@item build
4077Build the operating system's derivation, which includes all the
4078configuration files and programs needed to boot and run the system.
4079This action does not actually install anything.
113daf62 4080
cf4a9129
LC
4081@item init
4082Populate the given directory with all the files necessary to run the
4083operating system specified in @var{file}. This is useful for first-time
4084installations of the GNU system. For instance:
113daf62
LC
4085
4086@example
cf4a9129 4087guix system init my-os-config.scm /mnt
113daf62
LC
4088@end example
4089
cf4a9129
LC
4090copies to @file{/mnt} all the store items required by the configuration
4091specified in @file{my-os-config.scm}. This includes configuration
4092files, packages, and so on. It also creates other essential files
4093needed for the system to operate correctly---e.g., the @file{/etc},
4094@file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
113daf62 4095
cf4a9129
LC
4096This command also installs GRUB on the device specified in
4097@file{my-os-config}, unless the @option{--no-grub} option was passed.
113daf62 4098
cf4a9129
LC
4099@item vm
4100@cindex virtual machine
4101Build a virtual machine that contain the operating system declared in
4102@var{file}, and return a script to run that virtual machine (VM).
113daf62 4103
cf4a9129 4104The VM shares its store with the host system.
113daf62 4105
cf4a9129
LC
4106@item vm-image
4107@itemx disk-image
4108Return a virtual machine or disk image of the operating system declared
4109in @var{file} that stands alone. Use the @option{--image-size} option
4110to specify the size of the image.
113daf62 4111
cf4a9129
LC
4112When using @code{vm-image}, the returned image is in qcow2 format, which
4113the QEMU emulator can efficiently use.
113daf62 4114
cf4a9129
LC
4115When using @code{disk-image}, a raw disk image is produced; it can be
4116copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is
4117the device corresponding to a USB stick, one can copy the image on it
4118using the following command:
113daf62 4119
cf4a9129
LC
4120@example
4121# dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
4122@end example
113daf62 4123
cf4a9129 4124@end table
113daf62 4125
cf4a9129
LC
4126@var{options} can contain any of the common build options provided by
4127@command{guix build} (@pxref{Invoking guix build}). In addition,
4128@var{options} can contain one of the following:
113daf62 4129
cf4a9129
LC
4130@table @option
4131@item --system=@var{system}
4132@itemx -s @var{system}
4133Attempt to build for @var{system} instead of the host's system type.
4134This works as per @command{guix build} (@pxref{Invoking guix build}).
113daf62 4135
cf4a9129
LC
4136@item --image-size=@var{size}
4137For the @code{vm-image} and @code{disk-image} actions, create an image
4138of the given @var{size}. @var{size} may be a number of bytes, or it may
4a44d7bb
LC
4139include a unit as a suffix (@pxref{Block size, size specifications,,
4140coreutils, GNU Coreutils}).
113daf62 4141@end table
113daf62 4142
cf4a9129
LC
4143Note that all the actions above, except @code{build} and @code{init},
4144rely on KVM support in the Linux-Libre kernel. Specifically, the
4145machine should have hardware virtualization support, the corresponding
4146KVM kernel module should be loaded, and the @file{/dev/kvm} device node
4147must exist and be readable and writable by the user and by the daemon's
4148build users.
8451a568 4149
cf4a9129
LC
4150@node Defining Services
4151@subsection Defining Services
8451a568 4152
cf4a9129
LC
4153The @code{(gnu services @dots{})} modules define several procedures that allow
4154users to declare the operating system's services (@pxref{Using the
4155Configuration System}). These procedures are @emph{monadic
4156procedures}---i.e., procedures that return a monadic value in the store
4157monad (@pxref{The Store Monad}). For examples of such procedures,
4158@xref{Services}.
8451a568 4159
cf4a9129
LC
4160@cindex service definition
4161The monadic value returned by those procedures is a @dfn{service
4162definition}---a structure as returned by the @code{service} form.
4163Service definitions specifies the inputs the service depends on, and an
4164expression to start and stop the service. Behind the scenes, service
4165definitions are ``translated'' into the form suitable for the
4166configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU
4167dmd Manual}).
8451a568 4168
cf4a9129
LC
4169As an example, here is what the @code{nscd-service} procedure looks
4170like:
8451a568 4171
cf4a9129
LC
4172@lisp
4173(define (nscd-service)
4174 (with-monad %store-monad
4175 (return (service
4176 (documentation "Run libc's name service cache daemon.")
4177 (provision '(nscd))
4178 (activate #~(begin
4179 (use-modules (guix build utils))
4180 (mkdir-p "/var/run/nscd")))
4181 (start #~(make-forkexec-constructor
4182 (string-append #$glibc "/sbin/nscd")
4183 "-f" "/dev/null" "--foreground"))
4184 (stop #~(make-kill-destructor))
4185 (respawn? #f)))))
4186@end lisp
8451a568 4187
cf4a9129
LC
4188@noindent
4189The @code{activate}, @code{start}, and @code{stop} fields are G-expressions
4190(@pxref{G-Expressions}). The @code{activate} field contains a script to
4191run at ``activation'' time; it makes sure that the @file{/var/run/nscd}
4192directory exists before @command{nscd} is started.
8451a568 4193
cf4a9129
LC
4194The @code{start} and @code{stop} fields refer to dmd's facilities to
4195start and stop processes (@pxref{Service De- and Constructors,,, dmd,
4196GNU dmd Manual}). The @code{provision} field specifies the name under
4197which this service is known to dmd, and @code{documentation} specifies
4198on-line documentation. Thus, the commands @command{deco start ncsd},
4199@command{deco stop nscd}, and @command{deco doc nscd} will do what you
4200would expect (@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
8451a568 4201
8451a568 4202
cf4a9129
LC
4203@node Installing Debugging Files
4204@section Installing Debugging Files
8451a568 4205
cf4a9129
LC
4206@cindex debugging files
4207Program binaries, as produced by the GCC compilers for instance, are
4208typically written in the ELF format, with a section containing
4209@dfn{debugging information}. Debugging information is what allows the
4210debugger, GDB, to map binary code to source code; it is required to
4211debug a compiled program in good conditions.
8451a568 4212
cf4a9129
LC
4213The problem with debugging information is that is takes up a fair amount
4214of disk space. For example, debugging information for the GNU C Library
4215weighs in at more than 60 MiB. Thus, as a user, keeping all the
4216debugging info of all the installed programs is usually not an option.
4217Yet, space savings should not come at the cost of an impediment to
4218debugging---especially in the GNU system, which should make it easier
4219for users to exert their computing freedom (@pxref{GNU Distribution}).
8451a568 4220
cf4a9129
LC
4221Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
4222mechanism that allows users to get the best of both worlds: debugging
4223information can be stripped from the binaries and stored in separate
4224files. GDB is then able to load debugging information from those files,
4225when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
4226with GDB}).
8451a568 4227
cf4a9129
LC
4228The GNU distribution takes advantage of this by storing debugging
4229information in the @code{lib/debug} sub-directory of a separate package
4230output unimaginatively called @code{debug} (@pxref{Packages with
4231Multiple Outputs}). Users can choose to install the @code{debug} output
4232of a package when they need it. For instance, the following command
4233installs the debugging information for the GNU C Library and for GNU
4234Guile:
8451a568
LC
4235
4236@example
cf4a9129 4237guix package -i glibc:debug guile:debug
8451a568
LC
4238@end example
4239
cf4a9129
LC
4240GDB must then be told to look for debug files in the user's profile, by
4241setting the @code{debug-file-directory} variable (consider setting it
4242from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
4243GDB}):
8451a568 4244
cf4a9129
LC
4245@example
4246(gdb) set debug-file-directory ~/.guix-profile/lib/debug
4247@end example
8451a568 4248
cf4a9129
LC
4249From there on, GDB will pick up debugging information from the
4250@code{.debug} files under @file{~/.guix-profile/lib/debug}.
8451a568 4251
cf4a9129
LC
4252In addition, you will most likely want GDB to be able to show the source
4253code being debugged. To do that, you will have to unpack the source
4254code of the package of interest (obtained with @code{guix build
4255--source}, @pxref{Invoking guix build}), and to point GDB to that source
4256directory using the @code{directory} command (@pxref{Source Path,
4257@code{directory},, gdb, Debugging with GDB}).
8451a568 4258
cf4a9129
LC
4259@c XXX: keep me up-to-date
4260The @code{debug} output mechanism in Guix is implemented by the
4261@code{gnu-build-system} (@pxref{Build Systems}). Currently, it is
4262opt-in---debugging information is available only for those packages
4263whose definition explicitly declares a @code{debug} output. This may be
4264changed to opt-out in the future, if our build farm servers can handle
4265the load. To check whether a package has a @code{debug} output, use
4266@command{guix package --list-available} (@pxref{Invoking guix package}).
8451a568 4267
8451a568 4268
cf4a9129
LC
4269@node Package Modules
4270@section Package Modules
8451a568 4271
cf4a9129
LC
4272From a programming viewpoint, the package definitions of the
4273GNU distribution are provided by Guile modules in the @code{(gnu packages
4274@dots{})} name space@footnote{Note that packages under the @code{(gnu
4275packages @dots{})} module name space are not necessarily ``GNU
4276packages''. This module naming scheme follows the usual Guile module
4277naming convention: @code{gnu} means that these modules are distributed
4278as part of the GNU system, and @code{packages} identifies modules that
4279define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile
4280Reference Manual}). For instance, the @code{(gnu packages emacs)}
4281module exports a variable named @code{emacs}, which is bound to a
4282@code{<package>} object (@pxref{Defining Packages}).
113daf62 4283
300868ba 4284The @code{(gnu packages @dots{})} module name space is
cf4a9129
LC
4285automatically scanned for packages by the command-line tools. For
4286instance, when running @code{guix package -i emacs}, all the @code{(gnu
4287packages @dots{})} modules are scanned until one that exports a package
4288object whose name is @code{emacs} is found. This package search
4289facility is implemented in the @code{(gnu packages)} module.
113daf62 4290
300868ba 4291@cindex customization, of packages
8689901f 4292@cindex package module search path
cf4a9129 4293Users can store package definitions in modules with different
300868ba
LC
4294names---e.g., @code{(my-packages emacs)}. These package definitions
4295will not be visible by default. Thus, users can invoke commands such as
4296@command{guix package} and @command{guix build} have to be used with the
4297@code{-e} option so that they know where to find the package, or use the
4298@code{-L} option of these commands to make those modules visible
8689901f
LC
4299(@pxref{Invoking guix build, @code{--load-path}}), or define the
4300@code{GUIX_PACKAGE_PATH} environment variable. This environment
4301variable makes it easy to extend or customize the distribution and is
4302honored by all the user interfaces.
4303
4304@defvr {Environment Variable} GUIX_PACKAGE_PATH
4305This is a colon-separated list of directories to search for package
4306modules. Directories listed in this variable take precedence over the
4307distribution's own modules.
4308@end defvr
ef5dd60a 4309
cf4a9129
LC
4310The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
4311each package is built based solely on other packages in the
4312distribution. The root of this dependency graph is a small set of
4313@dfn{bootstrap binaries}, provided by the @code{(gnu packages
4314bootstrap)} module. For more information on bootstrapping,
4315@ref{Bootstrapping}.
ef5dd60a 4316
cf4a9129
LC
4317@node Packaging Guidelines
4318@section Packaging Guidelines
ef5dd60a 4319
cf4a9129
LC
4320The GNU distribution is nascent and may well lack some of your favorite
4321packages. This section describes how you can help make the distribution
4322grow. @xref{Contributing}, for additional information on how you can
4323help.
ef5dd60a 4324
cf4a9129
LC
4325Free software packages are usually distributed in the form of
4326@dfn{source code tarballs}---typically @file{tar.gz} files that contain
4327all the source files. Adding a package to the distribution means
4328essentially two things: adding a @dfn{recipe} that describes how to
4329build the package, including a list of other packages required to build
4330it, and adding @dfn{package meta-data} along with that recipe, such as a
4331description and licensing information.
ef5dd60a 4332
cf4a9129
LC
4333In Guix all this information is embodied in @dfn{package definitions}.
4334Package definitions provide a high-level view of the package. They are
4335written using the syntax of the Scheme programming language; in fact,
4336for each package we define a variable bound to the package definition,
4337and export that variable from a module (@pxref{Package Modules}).
4338However, in-depth Scheme knowledge is @emph{not} a prerequisite for
4339creating packages. For more information on package definitions,
4340@ref{Defining Packages}.
ef5dd60a 4341
cf4a9129
LC
4342Once a package definition is in place, stored in a file in the Guix
4343source tree, it can be tested using the @command{guix build} command
4344(@pxref{Invoking guix build}). For example, assuming the new package is
4345called @code{gnew}, you may run this command from the Guix build tree:
ef5dd60a
LC
4346
4347@example
cf4a9129 4348./pre-inst-env guix build gnew --keep-failed
ef5dd60a 4349@end example
ef5dd60a 4350
cf4a9129
LC
4351Using @code{--keep-failed} makes it easier to debug build failures since
4352it provides access to the failed build tree. Another useful
4353command-line option when debugging is @code{--log-file}, to access the
4354build log.
ef5dd60a 4355
cf4a9129
LC
4356If the package is unknown to the @command{guix} command, it may be that
4357the source file contains a syntax error, or lacks a @code{define-public}
4358clause to export the package variable. To figure it out, you may load
4359the module from Guile to get more information about the actual error:
ef5dd60a 4360
cf4a9129
LC
4361@example
4362./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
4363@end example
ef5dd60a 4364
cf4a9129
LC
4365Once your package builds correctly, please send us a patch
4366(@pxref{Contributing}). Well, if you need help, we will be happy to
4367help you too. Once the patch is committed in the Guix repository, the
4368new package automatically gets built on the supported platforms by
4369@url{http://hydra.gnu.org/gnu/master, our continuous integration
4370system}.
ef5dd60a 4371
cf4a9129
LC
4372@cindex substituter
4373Users can obtain the new package definition simply by running
4374@command{guix pull} (@pxref{Invoking guix pull}). When
4375@code{hydra.gnu.org} is done building the package, installing the
4376package automatically downloads binaries from there
4377(@pxref{Substitutes}). The only place where human intervention is
4378needed is to review and apply the patch.
ef5dd60a 4379
ef5dd60a 4380
cf4a9129
LC
4381@menu
4382* Software Freedom:: What may go into the distribution.
4383* Package Naming:: What's in a name?
4384* Version Numbers:: When the name is not enough.
4385* Python Modules:: Taming the snake.
4386* Perl Modules:: Little pearls.
4387@end menu
ef5dd60a 4388
cf4a9129
LC
4389@node Software Freedom
4390@subsection Software Freedom
ef5dd60a 4391
cf4a9129 4392@c Adapted from http://www.gnu.org/philosophy/philosophy.html.
c11a6eb1 4393
cf4a9129
LC
4394The GNU operating system has been developed so that users can have
4395freedom in their computing. GNU is @dfn{free software}, meaning that
4396users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
4397essential freedoms}: to run the program, to study and change the program
4398in source code form, to redistribute exact copies, and to distribute
4399modified versions. Packages found in the GNU distribution provide only
4400software that conveys these four freedoms.
c11a6eb1 4401
cf4a9129
LC
4402In addition, the GNU distribution follow the
4403@url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
4404software distribution guidelines}. Among other things, these guidelines
4405reject non-free firmware, recommendations of non-free software, and
4406discuss ways to deal with trademarks and patents.
ef5dd60a 4407
cf4a9129
LC
4408Some packages contain a small and optional subset that violates the
4409above guidelines, for instance because this subset is itself non-free
4410code. When that happens, the offending items are removed with
4411appropriate patches or code snippets in the package definition's
4412@code{origin} form (@pxref{Defining Packages}). That way, @code{guix
4413build --source} returns the ``freed'' source rather than the unmodified
4414upstream source.
ef5dd60a 4415
ef5dd60a 4416
cf4a9129
LC
4417@node Package Naming
4418@subsection Package Naming
ef5dd60a 4419
cf4a9129
LC
4420A package has actually two names associated with it:
4421First, there is the name of the @emph{Scheme variable}, the one following
4422@code{define-public}. By this name, the package can be made known in the
4423Scheme code, for instance as input to another package. Second, there is
4424the string in the @code{name} field of a package definition. This name
4425is used by package management commands such as
4426@command{guix package} and @command{guix build}.
ef5dd60a 4427
cf4a9129
LC
4428Both are usually the same and correspond to the lowercase conversion of
4429the project name chosen upstream, with underscores replaced with
4430hyphens. For instance, GNUnet is available as @code{gnunet}, and
4431SDL_net as @code{sdl-net}.
927097ef 4432
cf4a9129
LC
4433We do not add @code{lib} prefixes for library packages, unless these are
4434already part of the official project name. But see @pxref{Python
4435Modules} and @ref{Perl Modules} for special rules concerning modules for
4436the Python and Perl languages.
927097ef 4437
ef5dd60a 4438
cf4a9129
LC
4439@node Version Numbers
4440@subsection Version Numbers
ef5dd60a 4441
cf4a9129
LC
4442We usually package only the latest version of a given free software
4443project. But sometimes, for instance for incompatible library versions,
4444two (or more) versions of the same package are needed. These require
4445different Scheme variable names. We use the name as defined
4446in @ref{Package Naming}
4447for the most recent version; previous versions use the same name, suffixed
4448by @code{-} and the smallest prefix of the version number that may
4449distinguish the two versions.
ef5dd60a 4450
cf4a9129
LC
4451The name inside the package definition is the same for all versions of a
4452package and does not contain any version number.
ef5dd60a 4453
cf4a9129 4454For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
ef5dd60a 4455
cf4a9129
LC
4456@example
4457(define-public gtk+
4458 (package
4459 (name "gtk+")
4460 (version "3.9.12")
4461 ...))
4462(define-public gtk+-2
4463 (package
4464 (name "gtk+")
4465 (version "2.24.20")
4466 ...))
4467@end example
4468If we also wanted GTK+ 3.8.2, this would be packaged as
4469@example
4470(define-public gtk+-3.8
4471 (package
4472 (name "gtk+")
4473 (version "3.8.2")
4474 ...))
4475@end example
ef5dd60a 4476
ef5dd60a 4477
cf4a9129
LC
4478@node Python Modules
4479@subsection Python Modules
ef5dd60a 4480
cf4a9129
LC
4481We currently package Python 2 and Python 3, under the Scheme variable names
4482@code{python-2} and @code{python} as explained in @ref{Version Numbers}.
4483To avoid confusion and naming clashes with other programming languages, it
4484seems desirable that the name of a package for a Python module contains
4485the word @code{python}.
ef5dd60a 4486
cf4a9129
LC
4487Some modules are compatible with only one version of Python, others with both.
4488If the package Foo compiles only with Python 3, we name it
4489@code{python-foo}; if it compiles only with Python 2, we name it
4490@code{python2-foo}. If it is compatible with both versions, we create two
4491packages with the corresponding names.
ef5dd60a 4492
cf4a9129
LC
4493If a project already contains the word @code{python}, we drop this;
4494for instance, the module python-dateutil is packaged under the names
4495@code{python-dateutil} and @code{python2-dateutil}.
113daf62 4496
523e4896 4497
cf4a9129
LC
4498@node Perl Modules
4499@subsection Perl Modules
523e4896 4500
cf4a9129
LC
4501Perl programs standing for themselves are named as any other package,
4502using the lowercase upstream name.
4503For Perl packages containing a single class, we use the lowercase class name,
4504replace all occurrences of @code{::} by dashes and prepend the prefix
4505@code{perl-}.
4506So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
4507Modules containing several classes keep their lowercase upstream name and
4508are also prepended by @code{perl-}. Such modules tend to have the word
4509@code{perl} somewhere in their name, which gets dropped in favor of the
4510prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}.
523e4896 4511
523e4896 4512
b25937e3 4513
cf4a9129
LC
4514@node Bootstrapping
4515@section Bootstrapping
b25937e3 4516
cf4a9129 4517@c Adapted from the ELS 2013 paper.
b25937e3 4518
cf4a9129 4519@cindex bootstrapping
7889394e 4520
cf4a9129
LC
4521Bootstrapping in our context refers to how the distribution gets built
4522``from nothing''. Remember that the build environment of a derivation
4523contains nothing but its declared inputs (@pxref{Introduction}). So
4524there's an obvious chicken-and-egg problem: how does the first package
4525get built? How does the first compiler get compiled? Note that this is
4526a question of interest only to the curious hacker, not to the regular
4527user, so you can shamelessly skip this section if you consider yourself
4528a ``regular user''.
72b9d60d 4529
cf4a9129
LC
4530@cindex bootstrap binaries
4531The GNU system is primarily made of C code, with libc at its core. The
4532GNU build system itself assumes the availability of a Bourne shell and
4533command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and
4534`grep'. Furthermore, build programs---programs that run
4535@code{./configure}, @code{make}, etc.---are written in Guile Scheme
4536(@pxref{Derivations}). Consequently, to be able to build anything at
4537all, from scratch, Guix relies on pre-built binaries of Guile, GCC,
4538Binutils, libc, and the other packages mentioned above---the
4539@dfn{bootstrap binaries}.
72b9d60d 4540
cf4a9129
LC
4541These bootstrap binaries are ``taken for granted'', though we can also
4542re-create them if needed (more on that later).
72b9d60d 4543
cf4a9129 4544@unnumberedsubsec Preparing to Use the Bootstrap Binaries
c79d54fe 4545
cf4a9129
LC
4546@c As of Emacs 24.3, Info-mode displays the image, but since it's a
4547@c large image, it's hard to scroll. Oh well.
4548@image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations}
523e4896 4549
cf4a9129
LC
4550The figure above shows the very beginning of the dependency graph of the
4551distribution, corresponding to the package definitions of the @code{(gnu
4552packages bootstrap)} module. At this level of detail, things are
4553slightly complex. First, Guile itself consists of an ELF executable,
4554along with many source and compiled Scheme files that are dynamically
4555loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz}
4556tarball shown in this graph. This tarball is part of Guix's ``source''
4557distribution, and gets inserted into the store with @code{add-to-store}
4558(@pxref{The Store}).
2e7b5cea 4559
cf4a9129
LC
4560But how do we write a derivation that unpacks this tarball and adds it
4561to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv}
4562derivation---the first one that gets built---uses @code{bash} as its
4563builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls
4564@code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar},
4565@file{xz}, and @file{mkdir} are statically-linked binaries, also part of
4566the Guix source distribution, whose sole purpose is to allow the Guile
4567tarball to be unpacked.
fb729425 4568
cf4a9129
LC
4569Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning
4570Guile that can be used to run subsequent build programs. Its first task
4571is to download tarballs containing the other pre-built binaries---this
4572is what the @code{.tar.xz.drv} derivations do. Guix modules such as
4573@code{ftp-client.scm} are used for this purpose. The
4574@code{module-import.drv} derivations import those modules in a directory
4575in the store, using the original layout. The
4576@code{module-import-compiled.drv} derivations compile those modules, and
4577write them in an output directory with the right layout. This
4578corresponds to the @code{#:modules} argument of
4579@code{build-expression->derivation} (@pxref{Derivations}).
fb729425 4580
cf4a9129
LC
4581Finally, the various tarballs are unpacked by the
4582derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv},
4583etc., at which point we have a working C tool chain.
fb729425 4584
fb729425 4585
cf4a9129 4586@unnumberedsubsec Building the Build Tools
523e4896 4587
cf4a9129
LC
4588@c TODO: Add a package-level dependency graph generated from (gnu
4589@c packages base).
df2ce343 4590
cf4a9129
LC
4591Bootstrapping is complete when we have a full tool chain that does not
4592depend on the pre-built bootstrap tools discussed above. This
4593no-dependency requirement is verified by checking whether the files of
4594the final tool chain contain references to the @file{/gnu/store}
4595directories of the bootstrap inputs. The process that leads to this
4596``final'' tool chain is described by the package definitions found in
4597the @code{(gnu packages base)} module.
df2ce343 4598
cf4a9129
LC
4599@c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>.
4600The first tool that gets built with the bootstrap binaries is
4601GNU Make, which is a prerequisite for all the following packages.
4602From there Findutils and Diffutils get built.
523e4896 4603
cf4a9129
LC
4604Then come the first-stage Binutils and GCC, built as pseudo cross
4605tools---i.e., with @code{--target} equal to @code{--host}. They are
4606used to build libc. Thanks to this cross-build trick, this libc is
4607guaranteed not to hold any reference to the initial tool chain.
4af2447e 4608
cf4a9129
LC
4609From there the final Binutils and GCC are built. GCC uses @code{ld}
4610from the final Binutils, and links programs against the just-built libc.
4611This tool chain is used to build the other packages used by Guix and by
4612the GNU Build System: Guile, Bash, Coreutils, etc.
4af2447e 4613
cf4a9129
LC
4614And voilà! At this point we have the complete set of build tools that
4615the GNU Build System expects. These are in the @code{%final-inputs}
dd164244
MW
4616variable of the @code{(gnu packages commencement)} module, and are
4617implicitly used by any package that uses @code{gnu-build-system}
4618(@pxref{Defining Packages}).
4af2447e 4619
4af2447e 4620
cf4a9129 4621@unnumberedsubsec Building the Bootstrap Binaries
4af2447e 4622
cf4a9129
LC
4623Because the final tool chain does not depend on the bootstrap binaries,
4624those rarely need to be updated. Nevertheless, it is useful to have an
4625automated way to produce them, should an update occur, and this is what
4626the @code{(gnu packages make-bootstrap)} module provides.
4af2447e 4627
cf4a9129
LC
4628The following command builds the tarballs containing the bootstrap
4629binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture
4630of Coreutils and other basic command-line tools):
4b2615e1 4631
cf4a9129
LC
4632@example
4633guix build bootstrap-tarballs
4634@end example
4635
4636The generated tarballs are those that should be referred to in the
4637@code{(gnu packages bootstrap)} module mentioned at the beginning of
4638this section.
4639
4640Still here? Then perhaps by now you've started to wonder: when do we
4641reach a fixed point? That is an interesting question! The answer is
4642unknown, but if you would like to investigate further (and have
4643significant computational and storage resources to do so), then let us
4644know.
4645
4646@node Porting
4647@section Porting to a New Platform
4648
4649As discussed above, the GNU distribution is self-contained, and
4650self-containment is achieved by relying on pre-built ``bootstrap
4651binaries'' (@pxref{Bootstrapping}). These binaries are specific to an
4652operating system kernel, CPU architecture, and application binary
4653interface (ABI). Thus, to port the distribution to a platform that is
4654not yet supported, one must build those bootstrap binaries, and update
4655the @code{(gnu packages bootstrap)} module to use them on that platform.
4656
4657Fortunately, Guix can @emph{cross compile} those bootstrap binaries.
4658When everything goes well, and assuming the GNU tool chain supports the
4659target platform, this can be as simple as running a command like this
4660one:
4661
4662@example
4663guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs
4664@end example
4665
4666Once these are built, the @code{(gnu packages bootstrap)} module needs
4667to be updated to refer to these binaries on the target platform. In
4668addition, the @code{glibc-dynamic-linker} procedure in that module must
4669be augmented to return the right file name for libc's dynamic linker on
4670that platform; likewise, @code{system->linux-architecture} in @code{(gnu
4671packages linux)} must be taught about the new platform.
4672
4673In practice, there may be some complications. First, it may be that the
4674extended GNU triplet that specifies an ABI (like the @code{eabi} suffix
4675above) is not recognized by all the GNU tools. Typically, glibc
4676recognizes some of these, whereas GCC uses an extra @code{--with-abi}
4677configure flag (see @code{gcc.scm} for examples of how to handle this).
4678Second, some of the required packages could fail to build for that
4679platform. Lastly, the generated binaries could be broken for some
4680reason.
4af2447e
LC
4681
4682
9bf3c1a7
LC
4683@c *********************************************************************
4684@node Contributing
4685@chapter Contributing
4686
4687This project is a cooperative effort, and we need your help to make it
5ff3c4b8
PAR
4688grow! Please get in touch with us on @email{guix-devel@@gnu.org} and
4689@code{#guix} on the Freenode IRC network. We welcome ideas, bug
4690reports, patches, and anything that may be helpful to the project. We
4691particularly welcome help on packaging (@pxref{Packaging Guidelines}).
a1ba8475 4692
9bf3c1a7
LC
4693Please see the
4694@url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING,
4695@file{HACKING} file} that comes with the Guix source code for practical
4696details about contributions.
4697
c78bd12b 4698
568717fd
LC
4699@c *********************************************************************
4700@node Acknowledgments
4701@chapter Acknowledgments
4702
4703Guix is based on the Nix package manager, which was designed and
4704implemented by Eelco Dolstra. Nix pioneered functional package
4705management, and promoted unprecedented features, such as transactional
4706package upgrades and rollbacks, per-user profiles, and referentially
4707transparent build processes. Without this work, Guix would not exist.
4708
4709The Nix-based software distributions, Nixpkgs and NixOS, have also been
4710an inspiration for Guix.
4711
4712@c *********************************************************************
4713@node GNU Free Documentation License
4714@appendix GNU Free Documentation License
4715
4716@include fdl-1.3.texi
4717
4718@c *********************************************************************
4719@node Concept Index
4720@unnumbered Concept Index
4721@printindex cp
4722
a85b83d2
LC
4723@node Programming Index
4724@unnumbered Programming Index
4725@syncodeindex tp fn
4726@syncodeindex vr fn
568717fd
LC
4727@printindex fn
4728
4729@bye
4730
4731@c Local Variables:
4732@c ispell-local-dictionary: "american";
4733@c End: