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