Commit | Line | Data |
---|---|---|
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 | |
4379c35b | 13 | Copyright @copyright{} 2012, 2013, 2014, 2015 Ludovic Courtès@* |
af8a56b8 | 14 | Copyright @copyright{} 2013, 2014 Andreas Enge@* |
87eafdbd TUBK |
15 | Copyright @copyright{} 2013 Nikita Karetnikov@* |
16 | Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer | |
7df7a74e NK |
17 | |
18 | Permission is granted to copy, distribute and/or modify this document | |
19 | under the terms of the GNU Free Documentation License, Version 1.3 or | |
20 | any later version published by the Free Software Foundation; with no | |
21 | Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A | |
22 | copy of the license is included in the section entitled ``GNU Free | |
23 | Documentation License''. | |
24 | @end copying | |
568717fd | 25 | |
eeaf4427 | 26 | @dircategory Package management |
568717fd LC |
27 | @direntry |
28 | * guix: (guix). Guix, the functional package manager. | |
e49951eb | 29 | * guix package: (guix)Invoking guix package |
eeaf4427 | 30 | Managing packages with Guix. |
e49951eb | 31 | * guix build: (guix)Invoking guix build |
568717fd | 32 | Building packages with Guix. |
054e8576 LC |
33 | * guix system: (guix)Invoking guix system |
34 | Managing the operating system configuration. | |
568717fd | 35 | @end direntry |
568717fd | 36 | |
372c4bbc DT |
37 | @dircategory Software development |
38 | @direntry | |
39 | * guix environment: (guix)Invoking guix environment | |
40 | Building development environments with Guix. | |
41 | @end direntry | |
42 | ||
568717fd | 43 | @titlepage |
7730d112 LC |
44 | @title GNU Guix Reference Manual |
45 | @subtitle Using the GNU Guix Functional Package Manager | |
568717fd | 46 | @author Ludovic Courtès |
da7cabd4 | 47 | @author Andreas Enge |
acc08466 | 48 | @author Nikita Karetnikov |
568717fd LC |
49 | |
50 | @page | |
51 | @vskip 0pt plus 1filll | |
52 | Edition @value{EDITION} @* | |
53 | @value{UPDATED} @* | |
54 | ||
7df7a74e | 55 | @insertcopying |
568717fd LC |
56 | @end titlepage |
57 | ||
568717fd LC |
58 | @contents |
59 | ||
60 | @c ********************************************************************* | |
61 | @node Top | |
f8348b91 | 62 | @top GNU Guix |
568717fd | 63 | |
f8348b91 LC |
64 | This document describes GNU Guix version @value{VERSION}, a functional |
65 | package management tool written for the GNU system. | |
568717fd LC |
66 | |
67 | @menu | |
68 | * Introduction:: What is Guix about? | |
bd5e766b | 69 | * Installation:: Installing Guix. |
eeaf4427 | 70 | * Package Management:: Package installation, upgrade, etc. |
568717fd LC |
71 | * Programming Interface:: Using Guix in Scheme. |
72 | * Utilities:: Package management commands. | |
a1ba8475 | 73 | * GNU Distribution:: Software for your friendly GNU system. |
9bf3c1a7 | 74 | * Contributing:: Your help needed! |
568717fd LC |
75 | |
76 | * Acknowledgments:: Thanks! | |
77 | * GNU Free Documentation License:: The license of this manual. | |
78 | * Concept Index:: Concepts. | |
a85b83d2 | 79 | * Programming Index:: Data types, functions, and variables. |
aaa3eaa9 LC |
80 | |
81 | @detailmenu | |
82 | --- The Detailed Node Listing --- | |
83 | ||
84 | Installation | |
85 | ||
1b2b8177 | 86 | * Binary Installation:: Getting Guix running in no time! |
aaa3eaa9 | 87 | * Requirements:: Software needed to build and run Guix. |
ec0339cd | 88 | * Running the Test Suite:: Testing Guix. |
aaa3eaa9 LC |
89 | * Setting Up the Daemon:: Preparing the build daemon's environment. |
90 | * Invoking guix-daemon:: Running the build daemon. | |
c71979f4 | 91 | * Running Guix Before It Is Installed:: Hacker tricks. |
aaa3eaa9 LC |
92 | |
93 | Setting Up the Daemon | |
94 | ||
95 | * Build Environment Setup:: Preparing the isolated build environment. | |
96 | * Daemon Offload Setup:: Offloading builds to remote machines. | |
97 | ||
98 | Package Management | |
99 | ||
100 | * Features:: How Guix will make your life brighter. | |
101 | * Invoking guix package:: Package installation, removal, etc. | |
102 | * Emacs Interface:: Package management from Emacs. | |
103 | * Substitutes:: Downloading pre-built binaries. | |
104 | * Packages with Multiple Outputs:: Single source package, multiple outputs. | |
105 | * Invoking guix gc:: Running the garbage collector. | |
106 | * Invoking guix pull:: Fetching the latest Guix and distribution. | |
107 | * Invoking guix archive:: Exporting and importing store files. | |
108 | ||
109 | Programming Interface | |
110 | ||
111 | * Defining Packages:: Defining new packages. | |
112 | * Build Systems:: Specifying how packages are built. | |
113 | * The Store:: Manipulating the package store. | |
114 | * Derivations:: Low-level interface to package derivations. | |
115 | * The Store Monad:: Purely functional interface to the store. | |
116 | * G-Expressions:: Manipulating build expressions. | |
117 | ||
92492b23 LC |
118 | Defining Packages |
119 | ||
120 | * package Reference:: The package data type. | |
121 | * origin Reference:: The origin data type. | |
122 | ||
aaa3eaa9 LC |
123 | Utilities |
124 | ||
125 | * Invoking guix build:: Building packages from the command line. | |
126 | * Invoking guix download:: Downloading a file and printing its hash. | |
127 | * Invoking guix hash:: Computing the cryptographic hash of a file. | |
128 | * Invoking guix import:: Importing package definitions. | |
129 | * Invoking guix refresh:: Updating package definitions. | |
130 | * Invoking guix lint:: Finding errors in package definitions. | |
131 | * Invoking guix environment:: Setting up development environments. | |
aff8ce7c | 132 | * Invoking guix publish:: Sharing substitutes. |
aaa3eaa9 LC |
133 | |
134 | GNU Distribution | |
135 | ||
136 | * System Installation:: Installing the whole operating system. | |
35ed9306 | 137 | * System Configuration:: Configuring the operating system. |
aaa3eaa9 LC |
138 | * Installing Debugging Files:: Feeding the debugger. |
139 | * Security Updates:: Deploying security fixes quickly. | |
140 | * Package Modules:: Packages from the programmer's viewpoint. | |
141 | * Packaging Guidelines:: Growing the distribution. | |
142 | * Bootstrapping:: GNU/Linux built from scratch. | |
143 | * Porting:: Targeting another platform or kernel. | |
144 | ||
145 | System Configuration | |
146 | ||
147 | * Using the Configuration System:: Customizing your GNU system. | |
148 | * operating-system Reference:: Detail of operating-system declarations. | |
149 | * File Systems:: Configuring file system mounts. | |
150 | * Mapped Devices:: Block device extra processing. | |
151 | * User Accounts:: Specifying user accounts. | |
598e19dc | 152 | * Locales:: Language and cultural convention settings. |
aaa3eaa9 LC |
153 | * Services:: Specifying system services. |
154 | * Setuid Programs:: Programs running with root privileges. | |
1b2b8177 | 155 | * X.509 Certificates:: Authenticating HTTPS servers. |
996ed739 | 156 | * Name Service Switch:: Configuring libc's name service switch. |
aaa3eaa9 LC |
157 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
158 | * GRUB Configuration:: Configuring the boot loader. | |
159 | * Invoking guix system:: Instantiating a system configuration. | |
160 | * Defining Services:: Adding new service definitions. | |
161 | ||
162 | Services | |
163 | ||
164 | * Base Services:: Essential system services. | |
165 | * Networking Services:: Network setup, SSH daemon, etc. | |
166 | * X Window:: Graphical display. | |
1b2b8177 LC |
167 | * Desktop Services:: D-Bus and desktop services. |
168 | * Database Services:: SQL databases. | |
aa4ed923 | 169 | * Various Services:: Other services. |
aaa3eaa9 LC |
170 | |
171 | Packaging Guidelines | |
172 | ||
ec0339cd LC |
173 | * Software Freedom:: What may go into the distribution. |
174 | * Package Naming:: What's in a name? | |
175 | * Version Numbers:: When the name is not enough. | |
176 | * Python Modules:: Taming the snake. | |
177 | * Perl Modules:: Little pearls. | |
178 | * Fonts:: Fond of fonts. | |
aaa3eaa9 LC |
179 | |
180 | @end detailmenu | |
568717fd LC |
181 | @end menu |
182 | ||
183 | @c ********************************************************************* | |
184 | @node Introduction | |
185 | @chapter Introduction | |
186 | ||
c80e7e55 LC |
187 | GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks'' |
188 | using the international phonetic alphabet (IPA).} is a functional | |
189 | package management tool for the GNU system. Package management consists | |
4bfc4ea3 NK |
190 | of all activities that relate to building packages from sources, |
191 | honoring their build-time and run-time dependencies, | |
c80e7e55 LC |
192 | installing packages in user environments, upgrading installed packages |
193 | to new versions or rolling back to a previous set, removing unused | |
194 | software packages, etc. | |
568717fd LC |
195 | |
196 | @cindex functional package management | |
197 | The term @dfn{functional} refers to a specific package management | |
198 | discipline. In Guix, the package build and installation process is seen | |
4bfc4ea3 NK |
199 | as a function, in the mathematical sense. That function takes inputs, |
200 | such as build scripts, a compiler, and libraries, and | |
201 | returns an installed package. As a pure function, its result depends | |
568717fd LC |
202 | solely on its inputs---for instance, it cannot refer to software or |
203 | scripts that were not explicitly passed as inputs. A build function | |
4bfc4ea3 NK |
204 | always produces the same result when passed a given set of inputs. It |
205 | cannot alter the system's environment in | |
568717fd LC |
206 | any way; for instance, it cannot create, modify, or delete files outside |
207 | of its build and installation directories. This is achieved by running | |
e900c503 | 208 | build processes in isolated environments (or @dfn{containers}), where only their |
4bfc4ea3 | 209 | explicit inputs are visible. |
568717fd | 210 | |
e531ac2a | 211 | @cindex store |
568717fd | 212 | The result of package build functions is @dfn{cached} in the file |
e531ac2a LC |
213 | system, in a special directory called @dfn{the store} (@pxref{The |
214 | Store}). Each package is installed in a directory of its own, in the | |
834129e0 | 215 | store---by default under @file{/gnu/store}. The directory name contains |
568717fd LC |
216 | a hash of all the inputs used to build that package; thus, changing an |
217 | input yields a different directory name. | |
218 | ||
219 | This approach is the foundation of Guix's salient features: support for | |
4bfc4ea3 | 220 | transactional package upgrade and rollback, per-user installation, and |
eeaf4427 | 221 | garbage collection of packages (@pxref{Features}). |
568717fd | 222 | |
4bfc4ea3 | 223 | Guix has a command-line interface, which allows users to build, install, |
568717fd | 224 | upgrade, and remove packages, as well as a Scheme programming interface. |
568717fd | 225 | |
3ca2731c | 226 | @cindex Guix System Distribution |
4705641f | 227 | @cindex GuixSD |
a1ba8475 | 228 | Last but not least, Guix is used to build a distribution of the GNU |
3ca2731c | 229 | system, with many GNU and non-GNU free software packages. The Guix |
4705641f LC |
230 | System Distribution, or GNU@tie{}GuixSD, takes advantage of the core |
231 | properties of Guix at the system level. With GuixSD, users | |
3ca2731c LC |
232 | @emph{declare} all aspects of the operating system configuration, and |
233 | Guix takes care of instantiating that configuration in a reproducible, | |
234 | stateless fashion. @xref{GNU Distribution}. | |
a1ba8475 | 235 | |
bd5e766b LC |
236 | @c ********************************************************************* |
237 | @node Installation | |
238 | @chapter Installation | |
239 | ||
48febeb8 LC |
240 | GNU Guix is available for download from its website at |
241 | @url{http://www.gnu.org/software/guix/}. This section describes the | |
242 | software requirements of Guix, as well as how to install it and get | |
243 | ready to use it. | |
bd5e766b | 244 | |
5af6de3e LC |
245 | Note that this section is concerned with the installation of the package |
246 | manager, which can be done on top of a running GNU/Linux system. If, | |
247 | instead, you want to install the complete GNU operating system, | |
6621cdb6 | 248 | @pxref{System Installation}. |
5af6de3e | 249 | |
bd5e766b | 250 | @menu |
09722b11 | 251 | * Binary Installation:: Getting Guix running in no time! |
bd5e766b | 252 | * Requirements:: Software needed to build and run Guix. |
ec0339cd | 253 | * Running the Test Suite:: Testing Guix. |
bd5e766b LC |
254 | * Setting Up the Daemon:: Preparing the build daemon's environment. |
255 | * Invoking guix-daemon:: Running the build daemon. | |
c71979f4 | 256 | * Running Guix Before It Is Installed:: Hacker tricks. |
bd5e766b LC |
257 | @end menu |
258 | ||
09722b11 LC |
259 | @node Binary Installation |
260 | @section Binary Installation | |
261 | ||
262 | This section describes how to install Guix on an arbitrary system from a | |
263 | self-contained tarball providing binaries for Guix and for all its | |
264 | dependencies. This is often quicker than installing from source, which | |
265 | is described in the next sections. The only requirement is to have | |
266 | GNU@tie{}tar and Xz. | |
267 | ||
268 | Installing goes along these lines: | |
269 | ||
270 | @enumerate | |
271 | @item | |
272 | Download the binary tarball from | |
ae806096 | 273 | @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz}@footnote{As |
09722b11 LC |
274 | usual, make sure to download the associated @file{.sig} file and to |
275 | verify the authenticity of the tarball against it!}, where @var{system} | |
276 | is @code{x86_64-linux} for an @code{x86_64} machine already running the | |
277 | kernel Linux, and so on. | |
278 | ||
279 | @item | |
280 | As @code{root}, run: | |
281 | ||
282 | @example | |
283 | # cd / | |
b91d7f0f | 284 | # tar xf guix-binary-@value{VERSION}.@var{system}.tar.xz |
09722b11 LC |
285 | @end example |
286 | ||
287 | This creates @file{/gnu/store} (@pxref{The Store}), @file{/var/guix}, | |
288 | and @file{/root/.guix-profile}. @file{/root/.guix-profile} is a | |
289 | ready-to-use profile for @code{root} where Guix is installed. | |
290 | ||
5dc3ce5f LC |
291 | Do @emph{not} unpack the tarball on a working Guix system since that |
292 | would overwrite its own essential files. | |
293 | ||
09722b11 | 294 | @item |
175ced41 | 295 | Run the daemon: |
09722b11 LC |
296 | |
297 | @example | |
cfc149dc | 298 | # /root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild |
09722b11 LC |
299 | @end example |
300 | ||
301 | @item | |
302 | Make the @command{guix} command available to other users on the machine, | |
303 | for instance with: | |
304 | ||
305 | @example | |
306 | # mkdir -p /usr/local/bin | |
307 | # cd /usr/local/bin | |
d72d05f9 | 308 | # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix |
09722b11 | 309 | @end example |
39f8ed14 LC |
310 | |
311 | @item | |
312 | To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}), | |
313 | authorize them: | |
314 | ||
315 | @example | |
316 | # guix archive --authorize < /root/.guix-profile/share/guix/hydra.gnu.org.pub | |
317 | @end example | |
09722b11 LC |
318 | @end enumerate |
319 | ||
320 | And that's it! | |
321 | ||
5dc3ce5f | 322 | The @code{guix} package must remain available in @code{root}'s |
09722b11 LC |
323 | profile, or it would become subject to garbage collection---in which |
324 | case you would find yourself badly handicapped by the lack of the | |
325 | @command{guix} command. | |
326 | ||
39f8ed14 LC |
327 | The tarball in question can be (re)produced and verified simply by |
328 | running the following command in the Guix source tree: | |
09722b11 LC |
329 | |
330 | @example | |
331 | make guix-binary.@var{system}.tar.xz | |
332 | @end example | |
333 | ||
334 | ||
bd5e766b LC |
335 | @node Requirements |
336 | @section Requirements | |
337 | ||
09722b11 LC |
338 | This section lists requirements when building Guix from source. The |
339 | build procedure for Guix is the same as for other GNU software, and is | |
340 | not covered here. Please see the files @file{README} and @file{INSTALL} | |
341 | in the Guix source tree for additional details. | |
342 | ||
bd5e766b LC |
343 | GNU Guix depends on the following packages: |
344 | ||
345 | @itemize | |
47c66da0 | 346 | @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later; |
288dca55 | 347 | @item @url{http://gnupg.org/, GNU libgcrypt}; |
f0b98b84 | 348 | @item @url{http://www.gnu.org/software/make/, GNU Make}. |
8a96bd4b ID |
349 | @end itemize |
350 | ||
351 | The following dependencies are optional: | |
352 | ||
353 | @itemize | |
288dca55 | 354 | @item |
8a96bd4b | 355 | Installing |
288dca55 | 356 | @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will |
2f7d2d91 LC |
357 | allow you to use the @command{guix import pypi} command (@pxref{Invoking |
358 | guix import}). It is of | |
288dca55 | 359 | interest primarily for developers and not for casual users. |
8a96bd4b ID |
360 | @item |
361 | Installing @uref{http://gnutls.org/, GnuTLS-Guile} will | |
362 | allow you to access @code{https} URLs with the @command{guix download} | |
d45dc6da EB |
363 | command (@pxref{Invoking guix download}), the @command{guix import pypi} |
364 | command, and the @command{guix import cpan} command. This is primarily | |
365 | of interest to developers. @xref{Guile Preparations, how to install the | |
366 | GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}. | |
bd5e766b LC |
367 | @end itemize |
368 | ||
369 | Unless @code{--disable-daemon} was passed to @command{configure}, the | |
370 | following packages are also needed: | |
371 | ||
372 | @itemize | |
368d08f7 LC |
373 | @item @url{http://sqlite.org, SQLite 3}; |
374 | @item @url{http://www.bzip.org, libbz2}; | |
375 | @item @url{http://gcc.gnu.org, GCC's g++}, with support for the | |
376 | C++11 standard. | |
bd5e766b LC |
377 | @end itemize |
378 | ||
4bfc4ea3 NK |
379 | When a working installation of @url{http://nixos.org/nix/, the Nix package |
380 | manager} is available, you | |
bd5e766b | 381 | can instead configure Guix with @code{--disable-daemon}. In that case, |
4bfc4ea3 | 382 | Nix replaces the three dependencies above. |
bd5e766b | 383 | |
b22a12fd LC |
384 | Guix is compatible with Nix, so it is possible to share the same store |
385 | between both. To do so, you must pass @command{configure} not only the | |
386 | same @code{--with-store-dir} value, but also the same | |
4bfc4ea3 NK |
387 | @code{--localstatedir} value. The latter is essential because it |
388 | specifies where the database that stores metadata about the store is | |
834129e0 | 389 | located, among other things. The default values for Nix are |
b22a12fd | 390 | @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}. |
4bfc4ea3 NK |
391 | Note that @code{--disable-daemon} is not required if |
392 | your goal is to share the store with Nix. | |
b22a12fd | 393 | |
ec0339cd LC |
394 | @node Running the Test Suite |
395 | @section Running the Test Suite | |
396 | ||
397 | After a successful @command{configure} and @code{make} run, it is a good | |
398 | idea to run the test suite. It can help catch issues with the setup or | |
399 | environment, or bugs in Guix itself---and really, reporting test | |
400 | failures is a good way to help improve the software. To run the test | |
401 | suite, type: | |
402 | ||
403 | @example | |
404 | make check | |
405 | @end example | |
406 | ||
407 | Test cases can run in parallel: you can use the @code{-j} option of | |
408 | GNU@tie{}make to speed things up. The first run may take a few minutes | |
409 | on a recent machine; subsequent runs will be faster because the store | |
410 | that is created for test purposes will already have various things in | |
411 | cache. | |
412 | ||
413 | Upon failure, please email @email{bug-guix@@gnu.org} and attach the | |
414 | @file{test-suite.log} file. When @file{tests/@var{something}.scm} | |
415 | fails, please also attach the @file{@var{something}.log} file available | |
416 | in the top-level build directory. Please specify the Guix version being | |
417 | used as well as version numbers of the dependencies | |
418 | (@pxref{Requirements}) in your message. | |
419 | ||
bd5e766b LC |
420 | @node Setting Up the Daemon |
421 | @section Setting Up the Daemon | |
422 | ||
423 | @cindex daemon | |
424 | Operations such as building a package or running the garbage collector | |
49e6291a | 425 | are all performed by a specialized process, the @dfn{build daemon}, on |
bd5e766b LC |
426 | behalf of clients. Only the daemon may access the store and its |
427 | associated database. Thus, any operation that manipulates the store | |
428 | goes through the daemon. For instance, command-line tools such as | |
e49951eb | 429 | @command{guix package} and @command{guix build} communicate with the |
bd5e766b LC |
430 | daemon (@i{via} remote procedure calls) to instruct it what to do. |
431 | ||
49e6291a | 432 | The following sections explain how to prepare the build daemon's |
225dafde LC |
433 | environment. Also @ref{Substitutes}, for information on how to allow |
434 | the daemon to download pre-built binaries. | |
49e6291a LC |
435 | |
436 | @menu | |
437 | * Build Environment Setup:: Preparing the isolated build environment. | |
438 | * Daemon Offload Setup:: Offloading builds to remote machines. | |
439 | @end menu | |
440 | ||
441 | @node Build Environment Setup | |
442 | @subsection Build Environment Setup | |
443 | ||
bd5e766b LC |
444 | In a standard multi-user setup, Guix and its daemon---the |
445 | @command{guix-daemon} program---are installed by the system | |
834129e0 | 446 | administrator; @file{/gnu/store} is owned by @code{root} and |
bd5e766b LC |
447 | @command{guix-daemon} runs as @code{root}. Unprivileged users may use |
448 | Guix tools to build packages or otherwise access the store, and the | |
449 | daemon will do it on their behalf, ensuring that the store is kept in a | |
450 | consistent state, and allowing built packages to be shared among users. | |
451 | ||
452 | @cindex build users | |
453 | When @command{guix-daemon} runs as @code{root}, you may not want package | |
454 | build processes themselves to run as @code{root} too, for obvious | |
455 | security reasons. To avoid that, a special pool of @dfn{build users} | |
456 | should be created for use by build processes started by the daemon. | |
457 | These build users need not have a shell and a home directory: they will | |
458 | just be used when the daemon drops @code{root} privileges in build | |
459 | processes. Having several such users allows the daemon to launch | |
460 | distinct build processes under separate UIDs, which guarantees that they | |
461 | do not interfere with each other---an essential feature since builds are | |
462 | regarded as pure functions (@pxref{Introduction}). | |
463 | ||
464 | On a GNU/Linux system, a build user pool may be created like this (using | |
465 | Bash syntax and the @code{shadow} commands): | |
466 | ||
091196b3 LC |
467 | @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html |
468 | @c for why `-G' is needed. | |
bd5e766b | 469 | @example |
cfc149dc LC |
470 | # groupadd --system guixbuild |
471 | # for i in `seq -w 1 10`; | |
bd5e766b | 472 | do |
cfc149dc LC |
473 | useradd -g guixbuild -G guixbuild \ |
474 | -d /var/empty -s `which nologin` \ | |
475 | -c "Guix build user $i" --system \ | |
476 | guixbuilder$i; | |
bd5e766b LC |
477 | done |
478 | @end example | |
479 | ||
480 | @noindent | |
481 | The @code{guix-daemon} program may then be run as @code{root} with: | |
482 | ||
483 | @example | |
cfc149dc | 484 | # guix-daemon --build-users-group=guixbuild |
bd5e766b LC |
485 | @end example |
486 | ||
e900c503 | 487 | @cindex chroot |
b095792f LC |
488 | @noindent |
489 | This way, the daemon starts build processes in a chroot, under one of | |
cfc149dc | 490 | the @code{guixbuilder} users. On GNU/Linux, by default, the chroot |
6dc99317 LC |
491 | environment contains nothing but: |
492 | ||
493 | @c Keep this list in sync with libstore/build.cc! ----------------------- | |
494 | @itemize | |
495 | @item | |
4743a4da LC |
496 | a minimal @code{/dev} directory, created mostly independently from the |
497 | host @code{/dev}@footnote{``Mostly'', because while the set of files | |
498 | that appear in the chroot's @code{/dev} is fixed, most of these files | |
499 | can only be created if the host has them.}; | |
500 | ||
501 | @item | |
502 | the @code{/proc} directory; it only shows the container's processes | |
503 | since a separate PID name space is used; | |
6dc99317 LC |
504 | |
505 | @item | |
506 | @file{/etc/passwd} with an entry for the current user and an entry for | |
507 | user @file{nobody}; | |
508 | ||
509 | @item | |
510 | @file{/etc/group} with an entry for the user's group; | |
511 | ||
512 | @item | |
513 | @file{/etc/hosts} with an entry that maps @code{localhost} to | |
514 | @code{127.0.0.1}; | |
515 | ||
516 | @item | |
517 | a writable @file{/tmp} directory. | |
518 | @end itemize | |
b095792f | 519 | |
d43eb499 | 520 | If you are installing Guix as an unprivileged user, it is still |
bd5e766b LC |
521 | possible to run @command{guix-daemon}. However, build processes will |
522 | not be isolated from one another, and not from the rest of the system. | |
523 | Thus, build processes may interfere with each other, and may access | |
524 | programs, libraries, and other files available on the system---making it | |
525 | much harder to view them as @emph{pure} functions. | |
526 | ||
49e6291a LC |
527 | |
528 | @node Daemon Offload Setup | |
529 | @subsection Using the Offload Facility | |
530 | ||
531 | @cindex offloading | |
4ec2e92d LC |
532 | @cindex build hook |
533 | When desired, the build daemon can @dfn{offload} | |
534 | derivation builds to other machines | |
49e6291a LC |
535 | running Guix, using the @code{offload} @dfn{build hook}. When that |
536 | feature is enabled, a list of user-specified build machines is read from | |
537 | @file{/etc/guix/machines.scm}; anytime a build is requested, for | |
538 | instance via @code{guix build}, the daemon attempts to offload it to one | |
539 | of the machines that satisfies the derivation's constraints, in | |
540 | particular its system type---e.g., @file{x86_64-linux}. Missing | |
541 | prerequisites for the build are copied over SSH to the target machine, | |
542 | which then proceeds with the build; upon success the output(s) of the | |
543 | build are copied back to the initial machine. | |
544 | ||
4ec2e92d | 545 | The @file{/etc/guix/machines.scm} file typically looks like this: |
49e6291a LC |
546 | |
547 | @example | |
548 | (list (build-machine | |
549 | (name "eightysix.example.org") | |
550 | (system "x86_64-linux") | |
551 | (user "bob") | |
552 | (speed 2.)) ; incredibly fast! | |
553 | ||
554 | (build-machine | |
555 | (name "meeps.example.org") | |
556 | (system "mips64el-linux") | |
557 | (user "alice") | |
558 | (private-key | |
559 | (string-append (getenv "HOME") | |
560 | "/.ssh/id-rsa-for-guix")))) | |
561 | @end example | |
562 | ||
563 | @noindent | |
564 | In the example above we specify a list of two build machines, one for | |
565 | the @code{x86_64} architecture and one for the @code{mips64el} | |
4ec2e92d LC |
566 | architecture. |
567 | ||
568 | In fact, this file is---not surprisingly!---a Scheme file that is | |
569 | evaluated when the @code{offload} hook is started. Its return value | |
570 | must be a list of @code{build-machine} objects. While this example | |
571 | shows a fixed list of build machines, one could imagine, say, using | |
572 | DNS-SD to return a list of potential build machines discovered in the | |
573 | local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using | |
c678a4ee LC |
574 | Avahi in Guile Scheme Programs}). The @code{build-machine} data type is |
575 | detailed below. | |
4ec2e92d | 576 | |
c678a4ee LC |
577 | @deftp {Data Type} build-machine |
578 | This data type represents build machines the daemon may offload builds | |
579 | to. The important fields are: | |
49e6291a LC |
580 | |
581 | @table @code | |
582 | ||
583 | @item name | |
584 | The remote machine's host name. | |
585 | ||
586 | @item system | |
c678a4ee | 587 | The remote machine's system type---e.g., @code{"x86_64-linux"}. |
49e6291a LC |
588 | |
589 | @item user | |
590 | The user account to use when connecting to the remote machine over SSH. | |
591 | Note that the SSH key pair must @emph{not} be passphrase-protected, to | |
592 | allow non-interactive logins. | |
593 | ||
594 | @end table | |
595 | ||
4ec2e92d | 596 | A number of optional fields may be specified: |
49e6291a LC |
597 | |
598 | @table @code | |
599 | ||
cecd72d5 LC |
600 | @item port |
601 | Port number of the machine's SSH server (default: 22). | |
602 | ||
49e6291a LC |
603 | @item private-key |
604 | The SSH private key file to use when connecting to the machine. | |
605 | ||
606 | @item parallel-builds | |
607 | The number of builds that may run in parallel on the machine (1 by | |
608 | default.) | |
609 | ||
610 | @item speed | |
611 | A ``relative speed factor''. The offload scheduler will tend to prefer | |
612 | machines with a higher speed factor. | |
613 | ||
614 | @item features | |
615 | A list of strings denoting specific features supported by the machine. | |
616 | An example is @code{"kvm"} for machines that have the KVM Linux modules | |
617 | and corresponding hardware support. Derivations can request features by | |
618 | name, and they will be scheduled on matching build machines. | |
619 | ||
620 | @end table | |
c678a4ee | 621 | @end deftp |
49e6291a LC |
622 | |
623 | The @code{guix} command must be in the search path on the build | |
624 | machines, since offloading works by invoking the @code{guix archive} and | |
625 | @code{guix build} commands. | |
626 | ||
627 | There's one last thing to do once @file{machines.scm} is in place. As | |
628 | explained above, when offloading, files are transferred back and forth | |
629 | between the machine stores. For this to work, you need to generate a | |
630 | key pair to allow the daemon to export signed archives of files from the | |
631 | store (@pxref{Invoking guix archive}): | |
632 | ||
633 | @example | |
634 | # guix archive --generate-key | |
635 | @end example | |
636 | ||
637 | @noindent | |
638 | Thus, when receiving files, a machine's build daemon can make sure they | |
639 | are genuine, have not been tampered with, and that they are signed by an | |
640 | authorized key. | |
641 | ||
642 | ||
bd5e766b LC |
643 | @node Invoking guix-daemon |
644 | @section Invoking @command{guix-daemon} | |
645 | ||
646 | The @command{guix-daemon} program implements all the functionality to | |
647 | access the store. This includes launching build processes, running the | |
648 | garbage collector, querying the availability of a build result, etc. It | |
649 | is normally run as @code{root} like this: | |
650 | ||
651 | @example | |
cfc149dc | 652 | # guix-daemon --build-users-group=guixbuild |
bd5e766b LC |
653 | @end example |
654 | ||
655 | @noindent | |
081145cf | 656 | For details on how to set it up, @pxref{Setting Up the Daemon}. |
bd5e766b | 657 | |
e900c503 LC |
658 | @cindex chroot |
659 | @cindex container, build environment | |
660 | @cindex build environment | |
661 | @cindex reproducible builds | |
bd5e766b LC |
662 | By default, @command{guix-daemon} launches build processes under |
663 | different UIDs, taken from the build group specified with | |
664 | @code{--build-users-group}. In addition, each build process is run in a | |
665 | chroot environment that only contains the subset of the store that the | |
666 | build process depends on, as specified by its derivation | |
667 | (@pxref{Programming Interface, derivation}), plus a set of specific | |
668 | system directories. By default, the latter contains @file{/dev} and | |
e900c503 LC |
669 | @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a |
670 | @dfn{container}: in addition to having its own file system tree, it has | |
671 | a separate mount name space, its own PID name space, network name space, | |
672 | etc. This helps achieve reproducible builds (@pxref{Features}). | |
bd5e766b | 673 | |
cbc538fe LC |
674 | When the daemon performs a build on behalf of the user, it creates a |
675 | build directory under @file{/tmp} or under the directory specified by | |
676 | its @code{TMPDIR} environment variable; this directory is shared with | |
677 | the container for the duration of the build. Be aware that using a | |
678 | directory other than @file{/tmp} can affect build results---for example, | |
679 | with a longer directory name, a build process that uses Unix-domain | |
680 | sockets might hit the name length limitation for @code{sun_path}, which | |
681 | it would otherwise not hit. | |
682 | ||
683 | The build directory is automatically deleted upon completion, unless the | |
684 | build failed and the client specified @option{--keep-failed} | |
685 | (@pxref{Invoking guix build, @option{--keep-failed}}). | |
686 | ||
bd5e766b LC |
687 | The following command-line options are supported: |
688 | ||
689 | @table @code | |
690 | @item --build-users-group=@var{group} | |
691 | Take users from @var{group} to run build processes (@pxref{Setting Up | |
692 | the Daemon, build users}). | |
693 | ||
6858f9d1 | 694 | @item --no-substitutes |
b5385b52 | 695 | @cindex substitutes |
6858f9d1 | 696 | Do not use substitutes for build products. That is, always build things |
c4202d60 LC |
697 | locally instead of allowing downloads of pre-built binaries |
698 | (@pxref{Substitutes}). | |
6858f9d1 | 699 | |
b5385b52 LC |
700 | By default substitutes are used, unless the client---such as the |
701 | @command{guix package} command---is explicitly invoked with | |
702 | @code{--no-substitutes}. | |
703 | ||
704 | When the daemon runs with @code{--no-substitutes}, clients can still | |
705 | explicitly enable substitution @i{via} the @code{set-build-options} | |
706 | remote procedure call (@pxref{The Store}). | |
707 | ||
9176607e LC |
708 | @item --substitute-urls=@var{urls} |
709 | Consider @var{urls} the default whitespace-separated list of substitute | |
ae806096 | 710 | source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org} |
9176607e LC |
711 | is used. |
712 | ||
713 | This means that substitutes may be downloaded from @var{urls}, as long | |
714 | as they are signed by a trusted signature (@pxref{Substitutes}). | |
715 | ||
4ec2e92d LC |
716 | @cindex build hook |
717 | @item --no-build-hook | |
718 | Do not use the @dfn{build hook}. | |
719 | ||
720 | The build hook is a helper program that the daemon can start and to | |
721 | which it submits build requests. This mechanism is used to offload | |
722 | builds to other machines (@pxref{Daemon Offload Setup}). | |
723 | ||
bd5e766b LC |
724 | @item --cache-failures |
725 | Cache build failures. By default, only successful builds are cached. | |
726 | ||
727 | @item --cores=@var{n} | |
728 | @itemx -c @var{n} | |
729 | Use @var{n} CPU cores to build each derivation; @code{0} means as many | |
730 | as available. | |
731 | ||
6efc160e | 732 | The default value is @code{0}, but it may be overridden by clients, such |
e49951eb MW |
733 | as the @code{--cores} option of @command{guix build} (@pxref{Invoking |
734 | guix build}). | |
bd5e766b LC |
735 | |
736 | The effect is to define the @code{NIX_BUILD_CORES} environment variable | |
737 | in the build process, which can then use it to exploit internal | |
738 | parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}. | |
739 | ||
740 | @item --max-jobs=@var{n} | |
741 | @itemx -M @var{n} | |
742 | Allow at most @var{n} build jobs in parallel. The default value is | |
f6526eb3 LC |
743 | @code{1}. Setting it to @code{0} means that no builds will be performed |
744 | locally; instead, the daemon will offload builds (@pxref{Daemon Offload | |
745 | Setup}), or simply fail. | |
bd5e766b LC |
746 | |
747 | @item --debug | |
748 | Produce debugging output. | |
749 | ||
750 | This is useful to debug daemon start-up issues, but then it may be | |
751 | overridden by clients, for example the @code{--verbosity} option of | |
e49951eb | 752 | @command{guix build} (@pxref{Invoking guix build}). |
bd5e766b LC |
753 | |
754 | @item --chroot-directory=@var{dir} | |
755 | Add @var{dir} to the build chroot. | |
756 | ||
757 | Doing this may change the result of build processes---for instance if | |
758 | they use optional dependencies found in @var{dir} when it is available, | |
759 | and not otherwise. For that reason, it is not recommended to do so. | |
760 | Instead, make sure that each derivation declares all the inputs that it | |
761 | needs. | |
762 | ||
763 | @item --disable-chroot | |
764 | Disable chroot builds. | |
765 | ||
766 | Using this option is not recommended since, again, it would allow build | |
767 | processes to gain access to undeclared dependencies. | |
768 | ||
769 | @item --disable-log-compression | |
770 | Disable compression of the build logs. | |
771 | ||
1da983b9 LC |
772 | Unless @code{--lose-logs} is used, all the build logs are kept in the |
773 | @var{localstatedir}. To save space, the daemon automatically compresses | |
774 | them with bzip2 by default. This option disables that. | |
775 | ||
ab3893d7 LC |
776 | @item --disable-deduplication |
777 | @cindex deduplication | |
bd5e766b LC |
778 | Disable automatic file ``deduplication'' in the store. |
779 | ||
1da983b9 | 780 | By default, files added to the store are automatically ``deduplicated'': |
ab3893d7 LC |
781 | if a newly added file is identical to another one found in the store, |
782 | the daemon makes the new file a hard link to the other file. This can | |
783 | noticeably reduce disk usage, at the expense of slightly increasde | |
784 | input/output load at the end of a build process. This option disables | |
785 | this optimization. | |
1da983b9 | 786 | |
6e37066e LC |
787 | @item --gc-keep-outputs[=yes|no] |
788 | Tell whether the garbage collector (GC) must keep outputs of live | |
789 | derivations. | |
790 | ||
791 | When set to ``yes'', the GC will keep the outputs of any live derivation | |
792 | available in the store---the @code{.drv} files. The default is ``no'', | |
793 | meaning that derivation outputs are kept only if they are GC roots. | |
794 | ||
795 | @item --gc-keep-derivations[=yes|no] | |
796 | Tell whether the garbage collector (GC) must keep derivations | |
797 | corresponding to live outputs. | |
798 | ||
799 | When set to ``yes'', as is the case by default, the GC keeps | |
800 | derivations---i.e., @code{.drv} files---as long as at least one of their | |
801 | outputs is live. This allows users to keep track of the origins of | |
802 | items in their store. Setting it to ``no'' saves a bit of disk space. | |
803 | ||
804 | Note that when both @code{--gc-keep-derivations} and | |
805 | @code{--gc-keep-outputs} are used, the effect is to keep all the build | |
806 | prerequisites (the sources, compiler, libraries, and other build-time | |
807 | tools) of live objects in the store, regardless of whether these | |
808 | prerequisites are live. This is convenient for developers since it | |
809 | saves rebuilds or downloads. | |
810 | ||
bd5e766b LC |
811 | @item --impersonate-linux-2.6 |
812 | On Linux-based systems, impersonate Linux 2.6. This means that the | |
813 | kernel's @code{uname} system call will report 2.6 as the release number. | |
814 | ||
815 | This might be helpful to build programs that (usually wrongfully) depend | |
816 | on the kernel version number. | |
817 | ||
818 | @item --lose-logs | |
819 | Do not keep build logs. By default they are kept under | |
ce33631f | 820 | @code{@var{localstatedir}/guix/log}. |
bd5e766b LC |
821 | |
822 | @item --system=@var{system} | |
823 | Assume @var{system} as the current system type. By default it is the | |
824 | architecture/kernel pair found at configure time, such as | |
825 | @code{x86_64-linux}. | |
b8d2aa26 LC |
826 | |
827 | @item --listen=@var{socket} | |
828 | Listen for connections on @var{socket}, the file name of a Unix-domain | |
829 | socket. The default socket is | |
830 | @file{@var{localstatedir}/daemon-socket/socket}. This option is only | |
831 | useful in exceptional circumstances, such as if you need to run several | |
832 | daemons on the same machine. | |
bd5e766b LC |
833 | @end table |
834 | ||
c71979f4 LC |
835 | @node Running Guix Before It Is Installed |
836 | @section Running Guix Before It Is Installed | |
837 | ||
838 | If you are hacking Guix itself---which is a good idea!---you will find | |
839 | it useful to test the changes made in your local source tree checkout | |
840 | without actually installing them. | |
841 | ||
842 | To that end, all the command-line tools can be used even if you have not | |
843 | run @command{make install}. To do that, prefix each command with | |
844 | @command{./pre-inst-env} (the @file{pre-inst-env} script lives in the | |
845 | top build tree of Guix), as in: | |
846 | ||
847 | @example | |
848 | $ sudo ./pre-inst-env guix-daemon --build-users-group=guixbuild | |
849 | $ ./pre-inst-env guix build hello | |
850 | @end example | |
851 | ||
852 | @noindent | |
853 | Similarly, for a Guile session using the Guix modules: | |
854 | ||
855 | @example | |
856 | $ ./pre-inst-env guile -c '(use-modules (guix utils)) (pk (%current-system))' | |
857 | @end example | |
858 | ||
859 | The @command{pre-inst-env} script sets up all the environment variables | |
860 | necessary to support this, including @code{PATH} and | |
861 | @code{GUILE_LOAD_PATH}. | |
862 | ||
863 | If you are hacking Guix from Emacs using the wonderful Geiser | |
864 | (@pxref{Introduction,,, geiser, Geiser User Manual}), make sure to | |
865 | augment Guile's load path so that it finds source files from your | |
866 | checkout: | |
867 | ||
868 | @lisp | |
869 | ;; Assuming the Guix checkout is in ~/src/guix. | |
870 | (add-to-list 'geiser-guile-load-path "~/src/guix") | |
871 | @end lisp | |
872 | ||
bd5e766b | 873 | |
eeaf4427 LC |
874 | @c ********************************************************************* |
875 | @node Package Management | |
876 | @chapter Package Management | |
877 | ||
f8348b91 | 878 | The purpose of GNU Guix is to allow users to easily install, upgrade, and |
eeaf4427 LC |
879 | remove software packages, without having to know about their build |
880 | procedure or dependencies. Guix also goes beyond this obvious set of | |
881 | features. | |
882 | ||
883 | This chapter describes the main features of Guix, as well as the package | |
c1941588 LC |
884 | management tools it provides. Two user interfaces are provided for |
885 | routine package management tasks: a command-line interface | |
886 | (@pxref{Invoking guix package, @code{guix package}}), and a visual user | |
887 | interface in Emacs (@pxref{Emacs Interface}). | |
eeaf4427 LC |
888 | |
889 | @menu | |
890 | * Features:: How Guix will make your life brighter. | |
e49951eb | 891 | * Invoking guix package:: Package installation, removal, etc. |
457f60fa | 892 | * Emacs Interface:: Package management from Emacs. |
c4202d60 | 893 | * Substitutes:: Downloading pre-built binaries. |
760c60d6 | 894 | * Packages with Multiple Outputs:: Single source package, multiple outputs. |
e49951eb | 895 | * Invoking guix gc:: Running the garbage collector. |
f651b477 | 896 | * Invoking guix pull:: Fetching the latest Guix and distribution. |
760c60d6 | 897 | * Invoking guix archive:: Exporting and importing store files. |
eeaf4427 LC |
898 | @end menu |
899 | ||
900 | @node Features | |
901 | @section Features | |
902 | ||
903 | When using Guix, each package ends up in the @dfn{package store}, in its | |
904 | own directory---something that resembles | |
9a130e19 AK |
905 | @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string |
906 | (note that Guix comes with an Emacs extension to shorten those file | |
081145cf | 907 | names, @pxref{Emacs Prettify}.) |
eeaf4427 LC |
908 | |
909 | Instead of referring to these directories, users have their own | |
910 | @dfn{profile}, which points to the packages that they actually want to | |
821b0015 LC |
911 | use. These profiles are stored within each user's home directory, at |
912 | @code{$HOME/.guix-profile}. | |
eeaf4427 | 913 | |
821b0015 | 914 | For example, @code{alice} installs GCC 4.7.2. As a result, |
eeaf4427 | 915 | @file{/home/alice/.guix-profile/bin/gcc} points to |
834129e0 | 916 | @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine, |
821b0015 LC |
917 | @code{bob} had already installed GCC 4.8.0. The profile of @code{bob} |
918 | simply continues to point to | |
834129e0 | 919 | @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC |
821b0015 | 920 | coexist on the same system without any interference. |
eeaf4427 | 921 | |
e49951eb MW |
922 | The @command{guix package} command is the central tool to manage |
923 | packages (@pxref{Invoking guix package}). It operates on those per-user | |
821b0015 | 924 | profiles, and can be used @emph{with normal user privileges}. |
eeaf4427 LC |
925 | |
926 | The command provides the obvious install, remove, and upgrade | |
927 | operations. Each invocation is actually a @emph{transaction}: either | |
ba55b1cb | 928 | the specified operation succeeds, or nothing happens. Thus, if the |
e49951eb | 929 | @command{guix package} process is terminated during the transaction, |
eeaf4427 LC |
930 | or if a power outage occurs during the transaction, then the user's |
931 | profile remains in its previous state, and remains usable. | |
932 | ||
933 | In addition, any package transaction may be @emph{rolled back}. So, if, | |
934 | for example, an upgrade installs a new version of a package that turns | |
935 | out to have a serious bug, users may roll back to the previous instance | |
4af2447e LC |
936 | of their profile, which was known to work well. Similarly, the global |
937 | system configuration is subject to transactional upgrades and roll-back | |
938 | (@pxref{Using the Configuration System}). | |
eeaf4427 LC |
939 | |
940 | All those packages in the package store may be @emph{garbage-collected}. | |
941 | Guix can determine which packages are still referenced by the user | |
fe8ff028 | 942 | profiles, and remove those that are provably no longer referenced |
e49951eb | 943 | (@pxref{Invoking guix gc}). Users may also explicitly remove old |
fe8ff028 LC |
944 | generations of their profile so that the packages they refer to can be |
945 | collected. | |
eeaf4427 | 946 | |
e900c503 LC |
947 | @cindex reproducibility |
948 | @cindex reproducible builds | |
eeaf4427 LC |
949 | Finally, Guix takes a @dfn{purely functional} approach to package |
950 | management, as described in the introduction (@pxref{Introduction}). | |
834129e0 | 951 | Each @file{/gnu/store} package directory name contains a hash of all the |
eeaf4427 LC |
952 | inputs that were used to build that package---compiler, libraries, build |
953 | scripts, etc. This direct correspondence allows users to make sure a | |
954 | given package installation matches the current state of their | |
e900c503 LC |
955 | distribution. It also helps maximize @dfn{build reproducibility}: |
956 | thanks to the isolated build environments that are used, a given build | |
957 | is likely to yield bit-identical files when performed on different | |
958 | machines (@pxref{Invoking guix-daemon, container}). | |
eeaf4427 | 959 | |
c4202d60 | 960 | @cindex substitutes |
eeaf4427 | 961 | This foundation allows Guix to support @dfn{transparent binary/source |
c4202d60 | 962 | deployment}. When a pre-built binary for a @file{/gnu/store} item is |
18f2887b | 963 | available from an external source---a @dfn{substitute}, Guix just |
c4202d60 LC |
964 | downloads it and unpacks it; |
965 | otherwise, it builds the package from source, locally | |
966 | (@pxref{Substitutes}). | |
eeaf4427 | 967 | |
f5fd4fd2 LC |
968 | Control over the build environment is a feature that is also useful for |
969 | developers. The @command{guix environment} command allows developers of | |
970 | a package to quickly set up the right development environment for their | |
971 | package, without having to manually install the package's dependencies | |
972 | in their profile (@pxref{Invoking guix environment}). | |
973 | ||
e49951eb MW |
974 | @node Invoking guix package |
975 | @section Invoking @command{guix package} | |
eeaf4427 | 976 | |
e49951eb | 977 | The @command{guix package} command is the tool that allows users to |
eeaf4427 LC |
978 | install, upgrade, and remove packages, as well as rolling back to |
979 | previous configurations. It operates only on the user's own profile, | |
980 | and works with normal user privileges (@pxref{Features}). Its syntax | |
981 | is: | |
982 | ||
983 | @example | |
e49951eb | 984 | guix package @var{options} |
eeaf4427 LC |
985 | @end example |
986 | ||
ba55b1cb | 987 | Primarily, @var{options} specifies the operations to be performed during |
eeaf4427 | 988 | the transaction. Upon completion, a new profile is created, but |
99bd74d5 | 989 | previous @dfn{generations} of the profile remain available, should the user |
eeaf4427 LC |
990 | want to roll back. |
991 | ||
6447738c MW |
992 | For example, to remove @code{lua} and install @code{guile} and |
993 | @code{guile-cairo} in a single transaction: | |
994 | ||
995 | @example | |
996 | guix package -r lua -i guile guile-cairo | |
997 | @end example | |
998 | ||
99bd74d5 LC |
999 | @command{guix package} also supports a @dfn{declarative approach} |
1000 | whereby the user specifies the exact set of packages to be available and | |
1001 | passes it @i{via} the @option{--manifest} option | |
1002 | (@pxref{profile-manifest, @option{--manifest}}). | |
1003 | ||
b9e5c0a9 | 1004 | For each user, a symlink to the user's default profile is automatically |
0ec1af59 | 1005 | created in @file{$HOME/.guix-profile}. This symlink always points to the |
b9e5c0a9 LC |
1006 | current generation of the user's default profile. Thus, users can add |
1007 | @file{$HOME/.guix-profile/bin} to their @code{PATH} environment | |
1008 | variable, and so on. | |
d664f1b4 LC |
1009 | @cindex search paths |
1010 | If you are not using the Guix System Distribution, consider adding the | |
1011 | following lines to your @file{~/.bash_profile} (@pxref{Bash Startup | |
1012 | Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned | |
1013 | shells get all the right environment variable definitions: | |
1014 | ||
1015 | @example | |
1016 | GUIX_PROFILE="$HOME/.guix-profile" \ | |
1017 | source "$HOME/.guix-profile/etc/profile" | |
1018 | @end example | |
b9e5c0a9 | 1019 | |
4379c35b LC |
1020 | In a multi-user setup, user profiles are stored in a place registered as |
1021 | a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points | |
1022 | to (@pxref{Invoking guix gc}). That directory is normally | |
0ec1af59 LC |
1023 | @code{@var{localstatedir}/profiles/per-user/@var{user}}, where |
1024 | @var{localstatedir} is the value passed to @code{configure} as | |
4379c35b LC |
1025 | @code{--localstatedir}, and @var{user} is the user name. The |
1026 | @file{per-user} directory is created when @command{guix-daemon} is | |
1027 | started, and the @var{user} sub-directory is created by @command{guix | |
1028 | package}. | |
0ec1af59 LC |
1029 | |
1030 | The @var{options} can be among the following: | |
1031 | ||
eeaf4427 LC |
1032 | @table @code |
1033 | ||
6447738c MW |
1034 | @item --install=@var{package} @dots{} |
1035 | @itemx -i @var{package} @dots{} | |
1036 | Install the specified @var{package}s. | |
eeaf4427 | 1037 | |
6447738c | 1038 | Each @var{package} may specify either a simple package name, such as |
eeaf4427 | 1039 | @code{guile}, or a package name followed by a hyphen and version number, |
724311a2 LC |
1040 | such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter |
1041 | case, the newest version prefixed by @code{1.8} is selected.) | |
1042 | ||
1043 | If no version number is specified, the | |
dc5669cd MW |
1044 | newest available version will be selected. In addition, @var{package} |
1045 | may contain a colon, followed by the name of one of the outputs of the | |
6e721c4d | 1046 | package, as in @code{gcc:doc} or @code{binutils-2.22:lib} |
e7f34eb0 LC |
1047 | (@pxref{Packages with Multiple Outputs}). Packages with a corresponding |
1048 | name (and optionally version) are searched for among the GNU | |
1049 | distribution modules (@pxref{Package Modules}). | |
eeaf4427 | 1050 | |
461572cc LC |
1051 | @cindex propagated inputs |
1052 | Sometimes packages have @dfn{propagated inputs}: these are dependencies | |
21461f27 LC |
1053 | that automatically get installed along with the required package |
1054 | (@pxref{package-propagated-inputs, @code{propagated-inputs} in | |
1055 | @code{package} objects}, for information about propagated inputs in | |
1056 | package definitions). | |
461572cc | 1057 | |
21461f27 | 1058 | @anchor{package-cmd-propagated-inputs} |
461572cc LC |
1059 | An example is the GNU MPC library: its C header files refer to those of |
1060 | the GNU MPFR library, which in turn refer to those of the GMP library. | |
1061 | Thus, when installing MPC, the MPFR and GMP libraries also get installed | |
1062 | in the profile; removing MPC also removes MPFR and GMP---unless they had | |
1063 | also been explicitly installed independently. | |
1064 | ||
ba7ea5ce | 1065 | Besides, packages sometimes rely on the definition of environment |
5924080d | 1066 | variables for their search paths (see explanation of |
ba7ea5ce | 1067 | @code{--search-paths} below). Any missing or possibly incorrect |
5924080d LC |
1068 | environment variable definitions are reported here. |
1069 | ||
ef010c0f | 1070 | @c XXX: keep me up-to-date |
5924080d | 1071 | Finally, when installing a GNU package, the tool reports the |
ef010c0f LC |
1072 | availability of a newer upstream version. In the future, it may provide |
1073 | the option of installing directly from the upstream version, even if | |
1074 | that version is not yet in the distribution. | |
1075 | ||
5d4b411f LC |
1076 | @item --install-from-expression=@var{exp} |
1077 | @itemx -e @var{exp} | |
1078 | Install the package @var{exp} evaluates to. | |
1079 | ||
1080 | @var{exp} must be a Scheme expression that evaluates to a | |
1081 | @code{<package>} object. This option is notably useful to disambiguate | |
1082 | between same-named variants of a package, with expressions such as | |
1083 | @code{(@@ (gnu packages base) guile-final)}. | |
1084 | ||
1085 | Note that this option installs the first output of the specified | |
1086 | package, which may be insufficient when needing a specific output of a | |
1087 | multiple-output package. | |
1088 | ||
6447738c MW |
1089 | @item --remove=@var{package} @dots{} |
1090 | @itemx -r @var{package} @dots{} | |
1091 | Remove the specified @var{package}s. | |
eeaf4427 | 1092 | |
6447738c | 1093 | As for @code{--install}, each @var{package} may specify a version number |
13ed095c LC |
1094 | and/or output name in addition to the package name. For instance, |
1095 | @code{-r glibc:debug} would remove the @code{debug} output of | |
1096 | @code{glibc}. | |
1097 | ||
6447738c MW |
1098 | @item --upgrade[=@var{regexp} @dots{}] |
1099 | @itemx -u [@var{regexp} @dots{}] | |
1100 | Upgrade all the installed packages. If one or more @var{regexp}s are | |
1101 | specified, upgrade only installed packages whose name matches a | |
d5f01e48 | 1102 | @var{regexp}. Also see the @code{--do-not-upgrade} option below. |
eeaf4427 | 1103 | |
f651b477 LC |
1104 | Note that this upgrades package to the latest version of packages found |
1105 | in the distribution currently installed. To update your distribution, | |
1106 | you should regularly run @command{guix pull} (@pxref{Invoking guix | |
1107 | pull}). | |
1108 | ||
d5f01e48 MW |
1109 | @item --do-not-upgrade[=@var{regexp} @dots{}] |
1110 | When used together with the @code{--upgrade} option, do @emph{not} | |
1111 | upgrade any packages whose name matches a @var{regexp}. For example, to | |
1112 | upgrade all packages in the current profile except those containing the | |
1113 | substring ``emacs'': | |
1114 | ||
1115 | @example | |
1116 | $ guix package --upgrade . --do-not-upgrade emacs | |
1117 | @end example | |
1118 | ||
99bd74d5 | 1119 | @item @anchor{profile-manifest}--manifest=@var{file} |
1b676447 | 1120 | @itemx -m @var{file} |
99bd74d5 LC |
1121 | @cindex profile declaration |
1122 | @cindex profile manifest | |
1123 | Create a new generation of the profile from the manifest object | |
1b676447 DT |
1124 | returned by the Scheme code in @var{file}. |
1125 | ||
99bd74d5 LC |
1126 | This allows you to @emph{declare} the profile's contents rather than |
1127 | constructing it through a sequence of @code{--install} and similar | |
1128 | commands. The advantage is that @var{file} can be put under version | |
1129 | control, copied to different machines to reproduce the same profile, and | |
1130 | so on. | |
1131 | ||
1132 | @c FIXME: Add reference to (guix profile) documentation when available. | |
1133 | @var{file} must return a @dfn{manifest} object, which is roughly a list | |
1134 | of packages: | |
1b676447 | 1135 | |
99bd74d5 | 1136 | @findex packages->manifest |
1b676447 | 1137 | @example |
99bd74d5 | 1138 | (use-package-modules guile emacs) |
1b676447 DT |
1139 | |
1140 | (packages->manifest | |
99bd74d5 LC |
1141 | (list emacs |
1142 | guile-2.0 | |
1b676447 | 1143 | ;; Use a specific package output. |
99bd74d5 | 1144 | (list guile-2.0 "debug"))) |
1b676447 DT |
1145 | @end example |
1146 | ||
24e262f0 LC |
1147 | @item --roll-back |
1148 | Roll back to the previous @dfn{generation} of the profile---i.e., undo | |
1149 | the last transaction. | |
1150 | ||
1151 | When combined with options such as @code{--install}, roll back occurs | |
1152 | before any other actions. | |
1153 | ||
d9307267 | 1154 | When rolling back from the first generation that actually contains |
4b2bc804 NK |
1155 | installed packages, the profile is made to point to the @dfn{zeroth |
1156 | generation}, which contains no files apart from its own meta-data. | |
d9307267 | 1157 | |
82fe08ed LC |
1158 | Installing, removing, or upgrading packages from a generation that has |
1159 | been rolled back to overwrites previous future generations. Thus, the | |
1160 | history of a profile's generations is always linear. | |
1161 | ||
b3bb82f1 AK |
1162 | @item --switch-generation=@var{pattern} |
1163 | @itemx -S @var{pattern} | |
1164 | Switch to a particular generation defined by @var{pattern}. | |
1165 | ||
1166 | @var{pattern} may be either a generation number or a number prefixed | |
1167 | with ``+'' or ``-''. The latter means: move forward/backward by a | |
1168 | specified number of generations. For example, if you want to return to | |
1169 | the latest generation after @code{--roll-back}, use | |
1170 | @code{--switch-generation=+1}. | |
1171 | ||
1172 | The difference between @code{--roll-back} and | |
1173 | @code{--switch-generation=-1} is that @code{--switch-generation} will | |
1174 | not make a zeroth generation, so if a specified generation does not | |
1175 | exist, the current generation will not be changed. | |
1176 | ||
dbc31ab2 | 1177 | @item --search-paths[=@var{kind}] |
5924080d LC |
1178 | @cindex search paths |
1179 | Report environment variable definitions, in Bash syntax, that may be | |
1180 | needed in order to use the set of installed packages. These environment | |
1181 | variables are used to specify @dfn{search paths} for files used by some | |
1182 | of the installed packages. | |
1183 | ||
1184 | For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH} | |
1185 | environment variables to be defined so it can look for headers and | |
1186 | libraries in the user's profile (@pxref{Environment Variables,,, gcc, | |
1187 | Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C | |
1188 | library are installed in the profile, then @code{--search-paths} will | |
1189 | suggest setting these variables to @code{@var{profile}/include} and | |
1190 | @code{@var{profile}/lib}, respectively. | |
1191 | ||
dbc31ab2 LC |
1192 | The typical use case is to define these environment variables in the |
1193 | shell: | |
1194 | ||
1195 | @example | |
1196 | $ eval `guix package --search-paths` | |
1197 | @end example | |
1198 | ||
1199 | @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix}, | |
1200 | meaning that the returned environment variable definitions will either | |
1201 | be exact settings, or prefixes or suffixes of the current value of these | |
1202 | variables. When omitted, @var{kind} defaults to @code{exact}. | |
1203 | ||
eeaf4427 LC |
1204 | @item --profile=@var{profile} |
1205 | @itemx -p @var{profile} | |
1206 | Use @var{profile} instead of the user's default profile. | |
1207 | ||
70915c1a LC |
1208 | @item --verbose |
1209 | Produce verbose output. In particular, emit the environment's build log | |
1210 | on the standard error port. | |
1211 | ||
eeaf4427 LC |
1212 | @item --bootstrap |
1213 | Use the bootstrap Guile to build the profile. This option is only | |
1214 | useful to distribution developers. | |
1215 | ||
1216 | @end table | |
1217 | ||
e49951eb | 1218 | In addition to these actions @command{guix package} supports the |
733b4130 LC |
1219 | following options to query the current state of a profile, or the |
1220 | availability of packages: | |
eeaf4427 | 1221 | |
733b4130 LC |
1222 | @table @option |
1223 | ||
acc08466 NK |
1224 | @item --search=@var{regexp} |
1225 | @itemx -s @var{regexp} | |
5763ad92 | 1226 | List the available packages whose name, synopsis, or description matches |
299112d3 LC |
1227 | @var{regexp}. Print all the meta-data of matching packages in |
1228 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, | |
1229 | GNU recutils manual}). | |
acc08466 | 1230 | |
299112d3 LC |
1231 | This allows specific fields to be extracted using the @command{recsel} |
1232 | command, for instance: | |
1233 | ||
1234 | @example | |
e49951eb | 1235 | $ guix package -s malloc | recsel -p name,version |
299112d3 LC |
1236 | name: glibc |
1237 | version: 2.17 | |
1238 | ||
1239 | name: libgc | |
1240 | version: 7.2alpha6 | |
1241 | @end example | |
acc08466 | 1242 | |
a12d92f5 LC |
1243 | Similarly, to show the name of all the packages available under the |
1244 | terms of the GNU@tie{}LGPL version 3: | |
1245 | ||
1246 | @example | |
1247 | $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"' | |
1248 | name: elfutils | |
1249 | ||
1250 | name: gmp | |
1251 | @dots{} | |
1252 | @end example | |
1253 | ||
2aa6efb0 CR |
1254 | @item --show=@var{package} |
1255 | Show details about @var{package}, taken from the list of available packages, in | |
1256 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU | |
1257 | recutils manual}). | |
1258 | ||
1259 | @example | |
1260 | $ guix package --show=python | recsel -p name,version | |
1261 | name: python | |
1262 | version: 2.7.6 | |
1263 | ||
1264 | name: python | |
1265 | version: 3.3.5 | |
1266 | @end example | |
1267 | ||
1268 | You may also specify the full name of a package to only get details about a | |
1269 | specific version of it: | |
1270 | @example | |
1271 | $ guix package --show=python-3.3.5 | recsel -p name,version | |
1272 | name: python | |
1273 | version: 3.3.5 | |
1274 | @end example | |
1275 | ||
1276 | ||
1277 | ||
733b4130 LC |
1278 | @item --list-installed[=@var{regexp}] |
1279 | @itemx -I [@var{regexp}] | |
bd9bde1c LC |
1280 | List the currently installed packages in the specified profile, with the |
1281 | most recently installed packages shown last. When @var{regexp} is | |
1282 | specified, list only installed packages whose name matches @var{regexp}. | |
733b4130 LC |
1283 | |
1284 | For each installed package, print the following items, separated by | |
1285 | tabs: the package name, its version string, the part of the package that | |
1286 | is installed (for instance, @code{out} for the default output, | |
1287 | @code{include} for its headers, etc.), and the path of this package in | |
1288 | the store. | |
1289 | ||
64fc89b6 LC |
1290 | @item --list-available[=@var{regexp}] |
1291 | @itemx -A [@var{regexp}] | |
5763ad92 | 1292 | List packages currently available in the distribution for this system |
a1ba8475 LC |
1293 | (@pxref{GNU Distribution}). When @var{regexp} is specified, list only |
1294 | installed packages whose name matches @var{regexp}. | |
64fc89b6 LC |
1295 | |
1296 | For each package, print the following items separated by tabs: its name, | |
6e721c4d LC |
1297 | its version string, the parts of the package (@pxref{Packages with |
1298 | Multiple Outputs}), and the source location of its definition. | |
64fc89b6 | 1299 | |
f566d765 LC |
1300 | @item --list-generations[=@var{pattern}] |
1301 | @itemx -l [@var{pattern}] | |
1302 | Return a list of generations along with their creation dates; for each | |
1303 | generation, show the installed packages, with the most recently | |
4b2bc804 NK |
1304 | installed packages shown last. Note that the zeroth generation is never |
1305 | shown. | |
f566d765 LC |
1306 | |
1307 | For each installed package, print the following items, separated by | |
1308 | tabs: the name of a package, its version string, the part of the package | |
1309 | that is installed (@pxref{Packages with Multiple Outputs}), and the | |
1310 | location of this package in the store. | |
1311 | ||
1312 | When @var{pattern} is used, the command returns only matching | |
1313 | generations. Valid patterns include: | |
1314 | ||
1315 | @itemize | |
1316 | @item @emph{Integers and comma-separated integers}. Both patterns denote | |
1317 | generation numbers. For instance, @code{--list-generations=1} returns | |
1318 | the first one. | |
1319 | ||
1320 | And @code{--list-generations=1,8,2} outputs three generations in the | |
1321 | specified order. Neither spaces nor trailing commas are allowed. | |
1322 | ||
1323 | @item @emph{Ranges}. @code{--list-generations=2..9} prints the | |
1324 | specified generations and everything in between. Note that the start of | |
1325 | a range must be lesser than its end. | |
1326 | ||
1327 | It is also possible to omit the endpoint. For example, | |
1328 | @code{--list-generations=2..}, returns all generations starting from the | |
1329 | second one. | |
1330 | ||
1331 | @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks, | |
1332 | or months by passing an integer along with the first letter of the | |
d7ddb257 LC |
1333 | duration. For example, @code{--list-generations=20d} lists generations |
1334 | that are up to 20 days old. | |
f566d765 LC |
1335 | @end itemize |
1336 | ||
b7884ca3 NK |
1337 | @item --delete-generations[=@var{pattern}] |
1338 | @itemx -d [@var{pattern}] | |
d7ddb257 LC |
1339 | When @var{pattern} is omitted, delete all generations except the current |
1340 | one. | |
b7884ca3 NK |
1341 | |
1342 | This command accepts the same patterns as @option{--list-generations}. | |
d7ddb257 LC |
1343 | When @var{pattern} is specified, delete the matching generations. When |
1344 | @var{pattern} specifies a duration, generations @emph{older} than the | |
1345 | specified duration match. For instance, @code{--delete-generations=1m} | |
1346 | deletes generations that are more than one month old. | |
1347 | ||
391bdd8f LC |
1348 | If the current generation matches, it is @emph{not} deleted. Also, the |
1349 | zeroth generation is never deleted. | |
b7884ca3 | 1350 | |
1bb9900a LC |
1351 | Note that deleting generations prevents roll-back to them. |
1352 | Consequently, this command must be used with care. | |
1353 | ||
733b4130 | 1354 | @end table |
eeaf4427 | 1355 | |
70ee5642 LC |
1356 | Finally, since @command{guix package} may actually start build |
1357 | processes, it supports all the common build options that @command{guix | |
1358 | build} supports (@pxref{Invoking guix build, common build options}). | |
1359 | ||
457f60fa AK |
1360 | @include emacs.texi |
1361 | ||
c4202d60 LC |
1362 | @node Substitutes |
1363 | @section Substitutes | |
1364 | ||
1365 | @cindex substitutes | |
1366 | @cindex pre-built binaries | |
1367 | Guix supports transparent source/binary deployment, which means that it | |
1368 | can either build things locally, or download pre-built items from a | |
1369 | server. We call these pre-built items @dfn{substitutes}---they are | |
1370 | substitutes for local build results. In many cases, downloading a | |
1371 | substitute is much faster than building things locally. | |
1372 | ||
1373 | Substitutes can be anything resulting from a derivation build | |
1374 | (@pxref{Derivations}). Of course, in the common case, they are | |
1375 | pre-built package binaries, but source tarballs, for instance, which | |
1376 | also result from derivation builds, can be available as substitutes. | |
1377 | ||
1378 | The @code{hydra.gnu.org} server is a front-end to a build farm that | |
1379 | builds packages from the GNU distribution continuously for some | |
9176607e LC |
1380 | architectures, and makes them available as substitutes. This is the |
1381 | default source of substitutes; it can be overridden by passing | |
1382 | @command{guix-daemon} the @code{--substitute-urls} option | |
1383 | (@pxref{Invoking guix-daemon}). | |
c4202d60 LC |
1384 | |
1385 | @cindex security | |
1386 | @cindex digital signatures | |
1387 | To allow Guix to download substitutes from @code{hydra.gnu.org}, you | |
1388 | must add its public key to the access control list (ACL) of archive | |
1389 | imports, using the @command{guix archive} command (@pxref{Invoking guix | |
1390 | archive}). Doing so implies that you trust @code{hydra.gnu.org} to not | |
1391 | be compromised and to serve genuine substitutes. | |
1392 | ||
1393 | This public key is installed along with Guix, in | |
1394 | @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is | |
1395 | the installation prefix of Guix. If you installed Guix from source, | |
1396 | make sure you checked the GPG signature of | |
1397 | @file{guix-@value{VERSION}.tar.gz}, which contains this public key file. | |
1398 | Then, you can run something like this: | |
1399 | ||
1400 | @example | |
1401 | # guix archive --authorize < hydra.gnu.org.pub | |
1402 | @end example | |
1403 | ||
1404 | Once this is in place, the output of a command like @code{guix build} | |
1405 | should change from something like: | |
1406 | ||
1407 | @example | |
1408 | $ guix build emacs --dry-run | |
1409 | The following derivations would be built: | |
1410 | /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv | |
1411 | /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv | |
1412 | /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv | |
1413 | /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv | |
1414 | @dots{} | |
1415 | @end example | |
1416 | ||
1417 | @noindent | |
1418 | to something like: | |
1419 | ||
1420 | @example | |
1421 | $ guix build emacs --dry-run | |
1422 | The following files would be downloaded: | |
1423 | /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3 | |
1424 | /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d | |
1425 | /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16 | |
1426 | /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7 | |
1427 | @dots{} | |
1428 | @end example | |
1429 | ||
1430 | @noindent | |
1431 | This indicates that substitutes from @code{hydra.gnu.org} are usable and | |
1432 | will be downloaded, when possible, for future builds. | |
1433 | ||
1434 | Guix ignores substitutes that are not signed, or that are not signed by | |
ef27aa9c | 1435 | one of the keys listed in the ACL. It also detects and raises an error |
c4202d60 LC |
1436 | when attempting to use a substitute that has been tampered with. |
1437 | ||
1438 | The substitute mechanism can be disabled globally by running | |
1439 | @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking | |
1440 | guix-daemon}). It can also be disabled temporarily by passing the | |
1441 | @code{--no-substitutes} option to @command{guix package}, @command{guix | |
1442 | build}, and other command-line tools. | |
1443 | ||
1444 | ||
1445 | Today, each individual's control over their own computing is at the | |
1446 | mercy of institutions, corporations, and groups with enough power and | |
1447 | determination to subvert the computing infrastructure and exploit its | |
1448 | weaknesses. While using @code{hydra.gnu.org} substitutes can be | |
1449 | convenient, we encourage users to also build on their own, or even run | |
1450 | their own build farm, such that @code{hydra.gnu.org} is less of an | |
8ce229fc LC |
1451 | interesting target. One way to help is by publishing the software you |
1452 | build using @command{guix publish} so that others have one more choice | |
1453 | of server to download substitutes from (@pxref{Invoking guix publish}). | |
c4202d60 LC |
1454 | |
1455 | Guix has the foundations to maximize build reproducibility | |
1456 | (@pxref{Features}). In most cases, independent builds of a given | |
1457 | package or derivation should yield bit-identical results. Thus, through | |
1458 | a diverse set of independent package builds, we can strengthen the | |
1459 | integrity of our systems. | |
1460 | ||
1461 | In the future, we want Guix to have support to publish and retrieve | |
1462 | binaries to/from other users, in a peer-to-peer fashion. If you would | |
1463 | like to discuss this project, join us on @email{guix-devel@@gnu.org}. | |
1464 | ||
1465 | ||
6e721c4d LC |
1466 | @node Packages with Multiple Outputs |
1467 | @section Packages with Multiple Outputs | |
1468 | ||
1469 | @cindex multiple-output packages | |
1470 | @cindex package outputs | |
1471 | ||
1472 | Often, packages defined in Guix have a single @dfn{output}---i.e., the | |
1473 | source package leads exactly one directory in the store. When running | |
1474 | @command{guix package -i glibc}, one installs the default output of the | |
1475 | GNU libc package; the default output is called @code{out}, but its name | |
1476 | can be omitted as shown in this command. In this particular case, the | |
1477 | default output of @code{glibc} contains all the C header files, shared | |
1478 | libraries, static libraries, Info documentation, and other supporting | |
1479 | files. | |
1480 | ||
1481 | Sometimes it is more appropriate to separate the various types of files | |
1482 | produced from a single source package into separate outputs. For | |
1483 | instance, the GLib C library (used by GTK+ and related packages) | |
1484 | installs more than 20 MiB of reference documentation as HTML pages. | |
1485 | To save space for users who do not need it, the documentation goes to a | |
1486 | separate output, called @code{doc}. To install the main GLib output, | |
1487 | which contains everything but the documentation, one would run: | |
1488 | ||
1489 | @example | |
1490 | guix package -i glib | |
1491 | @end example | |
1492 | ||
1493 | The command to install its documentation is: | |
1494 | ||
1495 | @example | |
1496 | guix package -i glib:doc | |
1497 | @end example | |
1498 | ||
1499 | Some packages install programs with different ``dependency footprints''. | |
1500 | For instance, the WordNet package install both command-line tools and | |
1501 | graphical user interfaces (GUIs). The former depend solely on the C | |
1502 | library, whereas the latter depend on Tcl/Tk and the underlying X | |
1503 | libraries. In this case, we leave the command-line tools in the default | |
1504 | output, whereas the GUIs are in a separate output. This allows users | |
1505 | who do not need the GUIs to save space. | |
1506 | ||
1507 | There are several such multiple-output packages in the GNU distribution. | |
91ef73d4 LC |
1508 | Other conventional output names include @code{lib} for libraries and |
1509 | possibly header files, @code{bin} for stand-alone programs, and | |
1510 | @code{debug} for debugging information (@pxref{Installing Debugging | |
1511 | Files}). The outputs of a packages are listed in the third column of | |
1512 | the output of @command{guix package --list-available} (@pxref{Invoking | |
1513 | guix package}). | |
6e721c4d | 1514 | |
eeaf4427 | 1515 | |
e49951eb MW |
1516 | @node Invoking guix gc |
1517 | @section Invoking @command{guix gc} | |
fe8ff028 LC |
1518 | |
1519 | @cindex garbage collector | |
1520 | Packages that are installed but not used may be @dfn{garbage-collected}. | |
e49951eb | 1521 | The @command{guix gc} command allows users to explicitly run the garbage |
c22eb992 LC |
1522 | collector to reclaim space from the @file{/gnu/store} directory. It is |
1523 | the @emph{only} way to remove files from @file{/gnu/store}---removing | |
1524 | files or directories manually may break it beyond repair! | |
fe8ff028 LC |
1525 | |
1526 | The garbage collector has a set of known @dfn{roots}: any file under | |
834129e0 | 1527 | @file{/gnu/store} reachable from a root is considered @dfn{live} and |
fe8ff028 LC |
1528 | cannot be deleted; any other file is considered @dfn{dead} and may be |
1529 | deleted. The set of garbage collector roots includes default user | |
e49951eb MW |
1530 | profiles, and may be augmented with @command{guix build --root}, for |
1531 | example (@pxref{Invoking guix build}). | |
fe8ff028 | 1532 | |
1bb9900a LC |
1533 | Prior to running @code{guix gc --collect-garbage} to make space, it is |
1534 | often useful to remove old generations from user profiles; that way, old | |
1535 | package builds referenced by those generations can be reclaimed. This | |
1536 | is achieved by running @code{guix package --delete-generations} | |
1537 | (@pxref{Invoking guix package}). | |
1538 | ||
e49951eb | 1539 | The @command{guix gc} command has three modes of operation: it can be |
fe8ff028 LC |
1540 | used to garbage-collect any dead files (the default), to delete specific |
1541 | files (the @code{--delete} option), or to print garbage-collector | |
1542 | information. The available options are listed below: | |
1543 | ||
1544 | @table @code | |
1545 | @item --collect-garbage[=@var{min}] | |
1546 | @itemx -C [@var{min}] | |
834129e0 | 1547 | Collect garbage---i.e., unreachable @file{/gnu/store} files and |
fe8ff028 LC |
1548 | sub-directories. This is the default operation when no option is |
1549 | specified. | |
1550 | ||
1551 | When @var{min} is given, stop once @var{min} bytes have been collected. | |
1552 | @var{min} may be a number of bytes, or it may include a unit as a | |
4a44d7bb LC |
1553 | suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes |
1554 | (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}). | |
fe8ff028 LC |
1555 | |
1556 | When @var{min} is omitted, collect all the garbage. | |
1557 | ||
1558 | @item --delete | |
1559 | @itemx -d | |
1560 | Attempt to delete all the store files and directories specified as | |
1561 | arguments. This fails if some of the files are not in the store, or if | |
1562 | they are still live. | |
1563 | ||
38d27786 LC |
1564 | @item --optimize |
1565 | @cindex deduplication | |
1566 | Optimize the store by hard-linking identical files---this is | |
1567 | @dfn{deduplication}. | |
1568 | ||
1569 | The daemon performs deduplication after each successful build or archive | |
1570 | import, unless it was started with @code{--disable-deduplication} | |
1571 | (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus, | |
1572 | this option is primarily useful when the daemon was running with | |
1573 | @code{--disable-deduplication}. | |
1574 | ||
fe8ff028 LC |
1575 | @item --list-dead |
1576 | Show the list of dead files and directories still present in the | |
1577 | store---i.e., files and directories no longer reachable from any root. | |
1578 | ||
1579 | @item --list-live | |
1580 | Show the list of live store files and directories. | |
ba8b732d LC |
1581 | |
1582 | @end table | |
1583 | ||
1584 | In addition, the references among existing store files can be queried: | |
1585 | ||
1586 | @table @code | |
1587 | ||
1588 | @item --references | |
1589 | @itemx --referrers | |
1590 | List the references (respectively, the referrers) of store files given | |
1591 | as arguments. | |
1592 | ||
8e59fdd5 LC |
1593 | @item --requisites |
1594 | @itemx -R | |
1595 | List the requisites of the store files passed as arguments. Requisites | |
1596 | include the store files themselves, their references, and the references | |
1597 | of these, recursively. In other words, the returned list is the | |
1598 | @dfn{transitive closure} of the store files. | |
1599 | ||
fe8ff028 LC |
1600 | @end table |
1601 | ||
eeaf4427 | 1602 | |
f651b477 LC |
1603 | @node Invoking guix pull |
1604 | @section Invoking @command{guix pull} | |
1605 | ||
1606 | Packages are installed or upgraded to the latest version available in | |
1607 | the distribution currently available on your local machine. To update | |
1608 | that distribution, along with the Guix tools, you must run @command{guix | |
1609 | pull}: the command downloads the latest Guix source code and package | |
1610 | descriptions, and deploys it. | |
1611 | ||
1612 | On completion, @command{guix package} will use packages and package | |
1613 | versions from this just-retrieved copy of Guix. Not only that, but all | |
1614 | the Guix commands and Scheme modules will also be taken from that latest | |
1615 | version. New @command{guix} sub-commands added by the update also | |
1616 | become available. | |
1617 | ||
1618 | The @command{guix pull} command is usually invoked with no arguments, | |
1619 | but it supports the following options: | |
1620 | ||
1621 | @table @code | |
1622 | @item --verbose | |
1623 | Produce verbose output, writing build logs to the standard error output. | |
1624 | ||
ab5d72ad LC |
1625 | @item --url=@var{url} |
1626 | Download the source tarball of Guix from @var{url}. | |
1627 | ||
1628 | By default, the tarball is taken from its canonical address at | |
1629 | @code{gnu.org}, for the stable branch of Guix. | |
1630 | ||
f651b477 LC |
1631 | @item --bootstrap |
1632 | Use the bootstrap Guile to build the latest Guix. This option is only | |
1633 | useful to Guix developers. | |
1634 | @end table | |
1635 | ||
760c60d6 LC |
1636 | |
1637 | @node Invoking guix archive | |
1638 | @section Invoking @command{guix archive} | |
1639 | ||
1640 | The @command{guix archive} command allows users to @dfn{export} files | |
1641 | from the store into a single archive, and to later @dfn{import} them. | |
1642 | In particular, it allows store files to be transferred from one machine | |
1643 | to another machine's store. For example, to transfer the @code{emacs} | |
1644 | package to a machine connected over SSH, one would run: | |
1645 | ||
1646 | @example | |
56607088 | 1647 | guix archive --export -r emacs | ssh the-machine guix archive --import |
760c60d6 LC |
1648 | @end example |
1649 | ||
87236aed | 1650 | @noindent |
56607088 LC |
1651 | Similarly, a complete user profile may be transferred from one machine |
1652 | to another like this: | |
1653 | ||
1654 | @example | |
1655 | guix archive --export -r $(readlink -f ~/.guix-profile) | \ | |
1656 | ssh the-machine guix-archive --import | |
1657 | @end example | |
1658 | ||
1659 | @noindent | |
1660 | However, note that, in both examples, all of @code{emacs} and the | |
1661 | profile as well as all of their dependencies are transferred (due to | |
1662 | @code{-r}), regardless of what is already available in the target | |
1663 | machine's store. The @code{--missing} option can help figure out which | |
1664 | items are missing from the target's store. | |
87236aed | 1665 | |
760c60d6 | 1666 | Archives are stored in the ``Nix archive'' or ``Nar'' format, which is |
0dbd88db LC |
1667 | comparable in spirit to `tar', but with a few noteworthy differences |
1668 | that make it more appropriate for our purposes. First, rather than | |
1669 | recording all Unix meta-data for each file, the Nar format only mentions | |
1670 | the file type (regular, directory, or symbolic link); Unix permissions | |
1671 | and owner/group are dismissed. Second, the order in which directory | |
1672 | entries are stored always follows the order of file names according to | |
1673 | the C locale collation order. This makes archive production fully | |
1674 | deterministic. | |
1675 | ||
1676 | When exporting, the daemon digitally signs the contents of the archive, | |
1677 | and that digital signature is appended. When importing, the daemon | |
1678 | verifies the signature and rejects the import in case of an invalid | |
1679 | signature or if the signing key is not authorized. | |
760c60d6 LC |
1680 | @c FIXME: Add xref to daemon doc about signatures. |
1681 | ||
1682 | The main options are: | |
1683 | ||
1684 | @table @code | |
1685 | @item --export | |
1686 | Export the specified store files or packages (see below.) Write the | |
1687 | resulting archive to the standard output. | |
1688 | ||
56607088 LC |
1689 | Dependencies are @emph{not} included in the output, unless |
1690 | @code{--recursive} is passed. | |
1691 | ||
1692 | @item -r | |
1693 | @itemx --recursive | |
1694 | When combined with @code{--export}, this instructs @command{guix | |
1695 | archive} to include dependencies of the given items in the archive. | |
1696 | Thus, the resulting archive is self-contained: it contains the closure | |
1697 | of the exported store items. | |
1698 | ||
760c60d6 LC |
1699 | @item --import |
1700 | Read an archive from the standard input, and import the files listed | |
1701 | therein into the store. Abort if the archive has an invalid digital | |
f82cc5fd LC |
1702 | signature, or if it is signed by a public key not among the authorized |
1703 | keys (see @code{--authorize} below.) | |
554f26ec | 1704 | |
87236aed LC |
1705 | @item --missing |
1706 | Read a list of store file names from the standard input, one per line, | |
1707 | and write on the standard output the subset of these files missing from | |
1708 | the store. | |
1709 | ||
554f26ec | 1710 | @item --generate-key[=@var{parameters}] |
f82cc5fd | 1711 | @cindex signing, archives |
554f26ec LC |
1712 | Generate a new key pair for the daemons. This is a prerequisite before |
1713 | archives can be exported with @code{--export}. Note that this operation | |
1714 | usually takes time, because it needs to gather enough entropy to | |
1715 | generate the key pair. | |
1716 | ||
1717 | The generated key pair is typically stored under @file{/etc/guix}, in | |
1718 | @file{signing-key.pub} (public key) and @file{signing-key.sec} (private | |
867d8473 LC |
1719 | key, which must be kept secret.) When @var{parameters} is omitted, |
1720 | an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt | |
1721 | versions before 1.6.0, it is a 4096-bit RSA key. | |
1722 | Alternately, @var{parameters} can specify | |
554f26ec LC |
1723 | @code{genkey} parameters suitable for Libgcrypt (@pxref{General |
1724 | public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The | |
1725 | Libgcrypt Reference Manual}). | |
f82cc5fd LC |
1726 | |
1727 | @item --authorize | |
1728 | @cindex authorizing, archives | |
1729 | Authorize imports signed by the public key passed on standard input. | |
1730 | The public key must be in ``s-expression advanced format''---i.e., the | |
1731 | same format as the @file{signing-key.pub} file. | |
1732 | ||
1733 | The list of authorized keys is kept in the human-editable file | |
1734 | @file{/etc/guix/acl}. The file contains | |
1735 | @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format | |
1736 | s-expressions''} and is structured as an access-control list in the | |
1737 | @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure | |
1738 | (SPKI)}. | |
760c60d6 LC |
1739 | @end table |
1740 | ||
1741 | To export store files as an archive to the standard output, run: | |
1742 | ||
1743 | @example | |
1744 | guix archive --export @var{options} @var{specifications}... | |
1745 | @end example | |
1746 | ||
1747 | @var{specifications} may be either store file names or package | |
1748 | specifications, as for @command{guix package} (@pxref{Invoking guix | |
1749 | package}). For instance, the following command creates an archive | |
1750 | containing the @code{gui} output of the @code{git} package and the main | |
1751 | output of @code{emacs}: | |
1752 | ||
1753 | @example | |
834129e0 | 1754 | guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar |
760c60d6 LC |
1755 | @end example |
1756 | ||
1757 | If the specified packages are not built yet, @command{guix archive} | |
1758 | automatically builds them. The build process may be controlled with the | |
1759 | same options that can be passed to the @command{guix build} command | |
70ee5642 | 1760 | (@pxref{Invoking guix build, common build options}). |
760c60d6 LC |
1761 | |
1762 | ||
568717fd LC |
1763 | @c ********************************************************************* |
1764 | @node Programming Interface | |
1765 | @chapter Programming Interface | |
1766 | ||
3dc1970d LC |
1767 | GNU Guix provides several Scheme programming interfaces (APIs) to |
1768 | define, build, and query packages. The first interface allows users to | |
1769 | write high-level package definitions. These definitions refer to | |
1770 | familiar packaging concepts, such as the name and version of a package, | |
1771 | its build system, and its dependencies. These definitions can then be | |
1772 | turned into concrete build actions. | |
1773 | ||
ba55b1cb | 1774 | Build actions are performed by the Guix daemon, on behalf of users. In a |
3dc1970d | 1775 | standard setup, the daemon has write access to the store---the |
834129e0 | 1776 | @file{/gnu/store} directory---whereas users do not. The recommended |
3dc1970d LC |
1777 | setup also has the daemon perform builds in chroots, under a specific |
1778 | build users, to minimize interference with the rest of the system. | |
1779 | ||
1780 | @cindex derivation | |
1781 | Lower-level APIs are available to interact with the daemon and the | |
1782 | store. To instruct the daemon to perform a build action, users actually | |
1783 | provide it with a @dfn{derivation}. A derivation is a low-level | |
1784 | representation of the build actions to be taken, and the environment in | |
1785 | which they should occur---derivations are to package definitions what | |
49ad317a LC |
1786 | assembly is to C programs. The term ``derivation'' comes from the fact |
1787 | that build results @emph{derive} from them. | |
3dc1970d LC |
1788 | |
1789 | This chapter describes all these APIs in turn, starting from high-level | |
1790 | package definitions. | |
1791 | ||
568717fd | 1792 | @menu |
b860f382 | 1793 | * Defining Packages:: Defining new packages. |
7458bd0a | 1794 | * Build Systems:: Specifying how packages are built. |
b860f382 LC |
1795 | * The Store:: Manipulating the package store. |
1796 | * Derivations:: Low-level interface to package derivations. | |
1797 | * The Store Monad:: Purely functional interface to the store. | |
21b679f6 | 1798 | * G-Expressions:: Manipulating build expressions. |
568717fd LC |
1799 | @end menu |
1800 | ||
1801 | @node Defining Packages | |
1802 | @section Defining Packages | |
1803 | ||
3dc1970d LC |
1804 | The high-level interface to package definitions is implemented in the |
1805 | @code{(guix packages)} and @code{(guix build-system)} modules. As an | |
1806 | example, the package definition, or @dfn{recipe}, for the GNU Hello | |
1807 | package looks like this: | |
1808 | ||
1809 | @example | |
e7f34eb0 LC |
1810 | (define-module (gnu packages hello) |
1811 | #:use-module (guix packages) | |
1812 | #:use-module (guix download) | |
1813 | #:use-module (guix build-system gnu) | |
1814 | #:use-module (guix licenses)) | |
b22a12fd | 1815 | |
79f5dd59 | 1816 | (define-public hello |
3dc1970d LC |
1817 | (package |
1818 | (name "hello") | |
1819 | (version "2.8") | |
1820 | (source (origin | |
1821 | (method url-fetch) | |
1822 | (uri (string-append "mirror://gnu/hello/hello-" version | |
1823 | ".tar.gz")) | |
1824 | (sha256 | |
1825 | (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")))) | |
1826 | (build-system gnu-build-system) | |
7458bd0a | 1827 | (arguments `(#:configure-flags '("--enable-silent-rules"))) |
3dc1970d | 1828 | (inputs `(("gawk" ,gawk))) |
7458bd0a LC |
1829 | (synopsis "Hello, GNU world: An example GNU package") |
1830 | (description "Guess what GNU Hello prints!") | |
3dc1970d | 1831 | (home-page "http://www.gnu.org/software/hello/") |
b22a12fd | 1832 | (license gpl3+))) |
3dc1970d LC |
1833 | @end example |
1834 | ||
1835 | @noindent | |
1836 | Without being a Scheme expert, the reader may have guessed the meaning | |
e7f34eb0 | 1837 | of the various fields here. This expression binds variable @code{hello} |
3dc1970d LC |
1838 | to a @code{<package>} object, which is essentially a record |
1839 | (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}). | |
1840 | This package object can be inspected using procedures found in the | |
1841 | @code{(guix packages)} module; for instance, @code{(package-name hello)} | |
1842 | returns---surprise!---@code{"hello"}. | |
1843 | ||
2f7d2d91 LC |
1844 | With luck, you may be able to import part or all of the definition of |
1845 | the package you are interested in from another repository, using the | |
1846 | @code{guix import} command (@pxref{Invoking guix import}). | |
1847 | ||
e7f34eb0 LC |
1848 | In the example above, @var{hello} is defined into a module of its own, |
1849 | @code{(gnu packages hello)}. Technically, this is not strictly | |
1850 | necessary, but it is convenient to do so: all the packages defined in | |
1851 | modules under @code{(gnu packages @dots{})} are automatically known to | |
1852 | the command-line tools (@pxref{Package Modules}). | |
1853 | ||
3dc1970d LC |
1854 | There are a few points worth noting in the above package definition: |
1855 | ||
1856 | @itemize | |
1857 | @item | |
a2bf4907 LC |
1858 | The @code{source} field of the package is an @code{<origin>} object |
1859 | (@pxref{origin Reference}, for the complete reference). | |
3dc1970d LC |
1860 | Here, the @code{url-fetch} method from @code{(guix download)} is used, |
1861 | meaning that the source is a file to be downloaded over FTP or HTTP. | |
1862 | ||
1863 | The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of | |
1864 | the GNU mirrors defined in @code{(guix download)}. | |
1865 | ||
1866 | The @code{sha256} field specifies the expected SHA256 hash of the file | |
1867 | being downloaded. It is mandatory, and allows Guix to check the | |
1868 | integrity of the file. The @code{(base32 @dots{})} form introduces the | |
6c365eca | 1869 | base32 representation of the hash. You can obtain this information with |
210cc920 LC |
1870 | @code{guix download} (@pxref{Invoking guix download}) and @code{guix |
1871 | hash} (@pxref{Invoking guix hash}). | |
3dc1970d | 1872 | |
f9cc8971 LC |
1873 | @cindex patches |
1874 | When needed, the @code{origin} form can also have a @code{patches} field | |
1875 | listing patches to be applied, and a @code{snippet} field giving a | |
1876 | Scheme expression to modify the source code. | |
1877 | ||
3dc1970d LC |
1878 | @item |
1879 | @cindex GNU Build System | |
7458bd0a LC |
1880 | The @code{build-system} field specifies the procedure to build the |
1881 | package (@pxref{Build Systems}). Here, @var{gnu-build-system} | |
1882 | represents the familiar GNU Build System, where packages may be | |
1883 | configured, built, and installed with the usual @code{./configure && | |
1884 | make && make check && make install} command sequence. | |
1885 | ||
1886 | @item | |
1887 | The @code{arguments} field specifies options for the build system | |
1888 | (@pxref{Build Systems}). Here it is interpreted by | |
1889 | @var{gnu-build-system} as a request run @file{configure} with the | |
1890 | @code{--enable-silent-rules} flag. | |
3dc1970d LC |
1891 | |
1892 | @item | |
1893 | The @code{inputs} field specifies inputs to the build process---i.e., | |
1894 | build-time or run-time dependencies of the package. Here, we define an | |
1895 | input called @code{"gawk"} whose value is that of the @var{gawk} | |
1896 | variable; @var{gawk} is itself bound to a @code{<package>} object. | |
1897 | ||
1898 | Note that GCC, Coreutils, Bash, and other essential tools do not need to | |
1899 | be specified as inputs here. Instead, @var{gnu-build-system} takes care | |
7458bd0a | 1900 | of ensuring that they are present (@pxref{Build Systems}). |
3dc1970d LC |
1901 | |
1902 | However, any other dependencies need to be specified in the | |
1903 | @code{inputs} field. Any dependency not specified here will simply be | |
1904 | unavailable to the build process, possibly leading to a build failure. | |
1905 | @end itemize | |
1906 | ||
87eafdbd TUBK |
1907 | @xref{package Reference}, for a full description of possible fields. |
1908 | ||
2f7d2d91 | 1909 | Once a package definition is in place, the |
e49951eb | 1910 | package may actually be built using the @code{guix build} command-line |
7458bd0a | 1911 | tool (@pxref{Invoking guix build}). @xref{Packaging Guidelines}, for |
b4f5e0e8 CR |
1912 | more information on how to test package definitions, and |
1913 | @ref{Invoking guix lint}, for information on how to check a definition | |
1914 | for style conformance. | |
1915 | ||
7458bd0a LC |
1916 | Eventually, updating the package definition to a new upstream version |
1917 | can be partly automated by the @command{guix refresh} command | |
1918 | (@pxref{Invoking guix refresh}). | |
3dc1970d LC |
1919 | |
1920 | Behind the scenes, a derivation corresponding to the @code{<package>} | |
1921 | object is first computed by the @code{package-derivation} procedure. | |
834129e0 | 1922 | That derivation is stored in a @code{.drv} file under @file{/gnu/store}. |
ba55b1cb | 1923 | The build actions it prescribes may then be realized by using the |
3dc1970d LC |
1924 | @code{build-derivations} procedure (@pxref{The Store}). |
1925 | ||
1926 | @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}] | |
59688fc4 LC |
1927 | Return the @code{<derivation>} object of @var{package} for @var{system} |
1928 | (@pxref{Derivations}). | |
3dc1970d LC |
1929 | |
1930 | @var{package} must be a valid @code{<package>} object, and @var{system} | |
1931 | must be a string denoting the target system type---e.g., | |
1932 | @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store} | |
1933 | must be a connection to the daemon, which operates on the store | |
1934 | (@pxref{The Store}). | |
1935 | @end deffn | |
568717fd | 1936 | |
9c1edabd LC |
1937 | @noindent |
1938 | @cindex cross-compilation | |
1939 | Similarly, it is possible to compute a derivation that cross-builds a | |
1940 | package for some other system: | |
1941 | ||
1942 | @deffn {Scheme Procedure} package-cross-derivation @var{store} @ | |
1943 | @var{package} @var{target} [@var{system}] | |
59688fc4 LC |
1944 | Return the @code{<derivation>} object of @var{package} cross-built from |
1945 | @var{system} to @var{target}. | |
9c1edabd LC |
1946 | |
1947 | @var{target} must be a valid GNU triplet denoting the target hardware | |
1948 | and operating system, such as @code{"mips64el-linux-gnu"} | |
1949 | (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU | |
1950 | Configure and Build System}). | |
1951 | @end deffn | |
1952 | ||
87eafdbd TUBK |
1953 | @menu |
1954 | * package Reference :: The package data type. | |
1955 | * origin Reference:: The origin data type. | |
1956 | @end menu | |
1957 | ||
1958 | ||
1959 | @node package Reference | |
1960 | @subsection @code{package} Reference | |
1961 | ||
1962 | This section summarizes all the options available in @code{package} | |
1963 | declarations (@pxref{Defining Packages}). | |
1964 | ||
1965 | @deftp {Data Type} package | |
1966 | This is the data type representing a package recipe. | |
1967 | ||
1968 | @table @asis | |
1969 | @item @code{name} | |
1970 | The name of the package, as a string. | |
1971 | ||
1972 | @item @code{version} | |
1973 | The version of the package, as a string. | |
1974 | ||
1975 | @item @code{source} | |
1976 | An origin object telling how the source code for the package should be | |
1977 | acquired (@pxref{origin Reference}). | |
1978 | ||
1979 | @item @code{build-system} | |
1980 | The build system that should be used to build the package (@pxref{Build | |
1981 | Systems}). | |
1982 | ||
1983 | @item @code{arguments} (default: @code{'()}) | |
1984 | The arguments that should be passed to the build system. This is a | |
1985 | list, typically containing sequential keyword-value pairs. | |
1986 | ||
1987 | @item @code{inputs} (default: @code{'()}) | |
1988 | Package or derivation inputs to the build. This is a list of lists, | |
1989 | where each list has the name of the input (a string) as its first | |
1990 | element, a package or derivation object as its second element, and | |
1991 | optionally the name of the output of the package or derivation that | |
1992 | should be used, which defaults to @code{"out"}. | |
1993 | ||
21461f27 LC |
1994 | @item @anchor{package-propagated-inputs}@code{propagated-inputs} (default: @code{'()}) |
1995 | @cindex propagated inputs | |
87eafdbd | 1996 | This field is like @code{inputs}, but the specified packages will be |
21461f27 LC |
1997 | force-installed alongside the package they belong to |
1998 | (@pxref{package-cmd-propagated-inputs, @command{guix package}}, for | |
1999 | information on how @command{guix package} deals with propagated inputs.) | |
2000 | ||
2001 | For example this is necessary when a library needs headers of another | |
2002 | library to compile, or needs another shared library to be linked | |
2003 | alongside itself when a program wants to link to it. | |
87eafdbd TUBK |
2004 | |
2005 | @item @code{native-inputs} (default: @code{'()}) | |
2006 | This field is like @code{inputs}, but in case of a cross-compilation it | |
2007 | will be ensured that packages for the architecture of the build machine | |
2008 | are present, such that executables from them can be used during the | |
21461f27 LC |
2009 | build. |
2010 | ||
2011 | This is typically where you would list tools needed at build time but | |
2012 | not at run time, such as Autoconf, Automake, pkg-config, Gettext, or | |
2013 | Bison. @command{guix lint} can report likely mistakes in this area | |
2014 | (@pxref{Invoking guix lint}). | |
87eafdbd TUBK |
2015 | |
2016 | @item @code{self-native-input?} (default: @code{#f}) | |
2017 | This is a Boolean field telling whether the package should use itself as | |
2018 | a native input when cross-compiling. | |
2019 | ||
2020 | @item @code{outputs} (default: @code{'("out")}) | |
2021 | The list of output names of the package. @xref{Packages with Multiple | |
2022 | Outputs}, for typical uses of additional outputs. | |
2023 | ||
2024 | @item @code{native-search-paths} (default: @code{'()}) | |
2025 | @itemx @code{search-paths} (default: @code{'()}) | |
2026 | A list of @code{search-path-specification} objects describing | |
2027 | search-path environment variables honored by the package. | |
2028 | ||
2029 | @item @code{replacement} (default: @code{#f}) | |
2030 | This must either @code{#f} or a package object that will be used as a | |
2031 | @dfn{replacement} for this package. @xref{Security Updates, grafts}, | |
2032 | for details. | |
2033 | ||
2034 | @item @code{synopsis} | |
2035 | A one-line description of the package. | |
2036 | ||
2037 | @item @code{description} | |
2038 | A more elaborate description of the package. | |
2039 | ||
2040 | @item @code{license} | |
2041 | The license of the package; a value from @code{(guix licenses)}. | |
2042 | ||
2043 | @item @code{home-page} | |
2044 | The URL to the home-page of the package, as a string. | |
2045 | ||
2046 | @item @code{supported-systems} (default: @var{%supported-systems}) | |
2047 | The list of systems supported by the package, as strings of the form | |
2048 | @code{architecture-kernel}, for example @code{"x86_64-linux"}. | |
2049 | ||
2050 | @item @code{maintainers} (default: @code{'()}) | |
2051 | The list of maintainers of the package, as @code{maintainer} objects. | |
2052 | ||
2053 | @item @code{location} (default: source location of the @code{package} form) | |
2054 | The source location of the package. It's useful to override this when | |
2055 | inheriting from another package, in which case this field is not | |
2056 | automatically corrected. | |
2057 | @end table | |
2058 | @end deftp | |
2059 | ||
2060 | ||
2061 | @node origin Reference | |
2062 | @subsection @code{origin} Reference | |
2063 | ||
2064 | This section summarizes all the options available in @code{origin} | |
2065 | declarations (@pxref{Defining Packages}). | |
2066 | ||
2067 | @deftp {Data Type} origin | |
2068 | This is the data type representing a source code origin. | |
2069 | ||
2070 | @table @asis | |
2071 | @item @code{uri} | |
2072 | An object containing the URI of the source. The object type depends on | |
2073 | the @code{method} (see below). For example, when using the | |
2074 | @var{url-fetch} method of @code{(guix download)}, the valid @code{uri} | |
2075 | values are: a URL represented as a string, or a list thereof. | |
2076 | ||
2077 | @item @code{method} | |
2078 | A procedure that will handle the URI. | |
2079 | ||
2080 | Examples include: | |
2081 | ||
2082 | @table @asis | |
2083 | @item @var{url-fetch} from @code{(guix download)} | |
2084 | download a file the HTTP, HTTPS, or FTP URL specified in the | |
2085 | @code{uri} field; | |
2086 | ||
2087 | @item @var{git-fetch} from @code{(guix git-download)} | |
2088 | clone the Git version control repository, and check out the revision | |
2089 | specified in the @code{uri} field as a @code{git-reference} object; a | |
2090 | @code{git-reference} looks like this: | |
2091 | ||
2092 | @example | |
2093 | (git-reference | |
2094 | (url "git://git.debian.org/git/pkg-shadow/shadow") | |
2095 | (commit "v4.1.5.1")) | |
2096 | @end example | |
2097 | @end table | |
2098 | ||
2099 | @item @code{sha256} | |
2100 | A bytevector containing the SHA-256 hash of the source. Typically the | |
2101 | @code{base32} form is used here to generate the bytevector from a | |
2102 | base-32 string. | |
2103 | ||
2104 | @item @code{file-name} (default: @code{#f}) | |
2105 | The file name under which the source code should be saved. When this is | |
2106 | @code{#f}, a sensible default value will be used in most cases. In case | |
2107 | the source is fetched from a URL, the file name from the URL will be | |
2108 | used. For version control checkouts, it's recommended to provide the | |
2109 | file name explicitly because the default is not very descriptive. | |
2110 | ||
2111 | @item @code{patches} (default: @code{'()}) | |
2112 | A list of file names containing patches to be applied to the source. | |
2113 | ||
2114 | @item @code{snippet} (default: @code{#f}) | |
2115 | A quoted piece of code that will be run in the source directory to make | |
2116 | any modifications, which is sometimes more convenient than a patch. | |
2117 | ||
2118 | @item @code{patch-flags} (default: @code{'("-p1")}) | |
2119 | A list of command-line flags that should be passed to the @code{patch} | |
2120 | command. | |
2121 | ||
2122 | @item @code{patch-inputs} (default: @code{#f}) | |
2123 | Input packages or derivations to the patching process. When this is | |
2124 | @code{#f}, the usual set of inputs necessary for patching are provided, | |
2125 | such as GNU@tie{}Patch. | |
2126 | ||
2127 | @item @code{modules} (default: @code{'()}) | |
2128 | A list of Guile modules that should be loaded during the patching | |
2129 | process and while running the code in the @code{snippet} field. | |
2130 | ||
2131 | @item @code{imported-modules} (default: @code{'()}) | |
2132 | The list of Guile modules to import in the patch derivation, for use by | |
2133 | the @code{snippet}. | |
2134 | ||
2135 | @item @code{patch-guile} (default: @code{#f}) | |
2136 | The Guile package that should be used in the patching process. When | |
2137 | this is @code{#f}, a sensible default is used. | |
2138 | @end table | |
2139 | @end deftp | |
2140 | ||
9c1edabd | 2141 | |
7458bd0a LC |
2142 | @node Build Systems |
2143 | @section Build Systems | |
2144 | ||
2145 | @cindex build system | |
2146 | Each package definition specifies a @dfn{build system} and arguments for | |
2147 | that build system (@pxref{Defining Packages}). This @code{build-system} | |
2148 | field represents the build procedure of the package, as well implicit | |
2149 | dependencies of that build procedure. | |
2150 | ||
2151 | Build systems are @code{<build-system>} objects. The interface to | |
2152 | create and manipulate them is provided by the @code{(guix build-system)} | |
2153 | module, and actual build systems are exported by specific modules. | |
2154 | ||
f5fd4fd2 | 2155 | @cindex bag (low-level package representation) |
0d5a559f LC |
2156 | Under the hood, build systems first compile package objects to |
2157 | @dfn{bags}. A @dfn{bag} is like a package, but with less | |
2158 | ornamentation---in other words, a bag is a lower-level representation of | |
2159 | a package, which includes all the inputs of that package, including some | |
2160 | that were implicitly added by the build system. This intermediate | |
2161 | representation is then compiled to a derivation (@pxref{Derivations}). | |
2162 | ||
7458bd0a LC |
2163 | Build systems accept an optional list of @dfn{arguments}. In package |
2164 | definitions, these are passed @i{via} the @code{arguments} field | |
2165 | (@pxref{Defining Packages}). They are typically keyword arguments | |
2166 | (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU | |
2167 | Guile Reference Manual}). The value of these arguments is usually | |
2168 | evaluated in the @dfn{build stratum}---i.e., by a Guile process launched | |
2169 | by the daemon (@pxref{Derivations}). | |
2170 | ||
2171 | The main build system is @var{gnu-build-system}, which implements the | |
2172 | standard build procedure for GNU packages and many other packages. It | |
2173 | is provided by the @code{(guix build-system gnu)} module. | |
2174 | ||
2175 | @defvr {Scheme Variable} gnu-build-system | |
2176 | @var{gnu-build-system} represents the GNU Build System, and variants | |
2177 | thereof (@pxref{Configuration, configuration and makefile conventions,, | |
2178 | standards, GNU Coding Standards}). | |
2179 | ||
2180 | @cindex build phases | |
2181 | In a nutshell, packages using it configured, built, and installed with | |
2182 | the usual @code{./configure && make && make check && make install} | |
2183 | command sequence. In practice, a few additional steps are often needed. | |
2184 | All these steps are split up in separate @dfn{phases}, | |
2185 | notably@footnote{Please see the @code{(guix build gnu-build-system)} | |
2186 | modules for more details about the build phases.}: | |
2187 | ||
2188 | @table @code | |
2189 | @item unpack | |
2190 | Unpack the source tarball, and change the current directory to the | |
2191 | extracted source tree. If the source is actually a directory, copy it | |
2192 | to the build tree, and enter that directory. | |
2193 | ||
2194 | @item patch-source-shebangs | |
2195 | Patch shebangs encountered in source files so they refer to the right | |
2196 | store file names. For instance, this changes @code{#!/bin/sh} to | |
2197 | @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}. | |
2198 | ||
2199 | @item configure | |
2200 | Run the @file{configure} script with a number of default options, such | |
2201 | as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified | |
2202 | by the @code{#:configure-flags} argument. | |
2203 | ||
2204 | @item build | |
2205 | Run @code{make} with the list of flags specified with | |
2206 | @code{#:make-flags}. If the @code{#:parallel-builds?} argument is true | |
2207 | (the default), build with @code{make -j}. | |
2208 | ||
2209 | @item check | |
2210 | Run @code{make check}, or some other target specified with | |
2211 | @code{#:test-target}, unless @code{#:tests? #f} is passed. If the | |
2212 | @code{#:parallel-tests?} argument is true (the default), run @code{make | |
2213 | check -j}. | |
2214 | ||
2215 | @item install | |
2216 | Run @code{make install} with the flags listed in @code{#:make-flags}. | |
2217 | ||
2218 | @item patch-shebangs | |
2219 | Patch shebangs on the installed executable files. | |
2220 | ||
2221 | @item strip | |
2222 | Strip debugging symbols from ELF files (unless @code{#:strip-binaries?} | |
2223 | is false), copying them to the @code{debug} output when available | |
2224 | (@pxref{Installing Debugging Files}). | |
2225 | @end table | |
2226 | ||
2227 | @vindex %standard-phases | |
2228 | The build-side module @code{(guix build gnu-build-system)} defines | |
2229 | @var{%standard-phases} as the default list of build phases. | |
2230 | @var{%standard-phases} is a list of symbol/procedure pairs, where the | |
2231 | procedure implements the actual phase. | |
2232 | ||
2233 | The list of phases used for a particular package can be changed with the | |
2234 | @code{#:phases} parameter. For instance, passing: | |
2235 | ||
2236 | @example | |
2237 | #:phases (alist-delete 'configure %standard-phases) | |
2238 | @end example | |
2239 | ||
9bf404e9 | 2240 | means that all the phases described above will be used, except the |
7458bd0a LC |
2241 | @code{configure} phase. |
2242 | ||
2243 | In addition, this build system ensures that the ``standard'' environment | |
2244 | for GNU packages is available. This includes tools such as GCC, libc, | |
2245 | Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix | |
2246 | build-system gnu)} module for a complete list.) We call these the | |
2247 | @dfn{implicit inputs} of a package, because package definitions don't | |
2248 | have to mention them. | |
2249 | @end defvr | |
2250 | ||
2251 | Other @code{<build-system>} objects are defined to support other | |
2252 | conventions and tools used by free software packages. They inherit most | |
2253 | of @var{gnu-build-system}, and differ mainly in the set of inputs | |
2254 | implicitly added to the build process, and in the list of phases | |
2255 | executed. Some of these build systems are listed below. | |
2256 | ||
2257 | @defvr {Scheme Variable} cmake-build-system | |
2258 | This variable is exported by @code{(guix build-system cmake)}. It | |
2259 | implements the build procedure for packages using the | |
2260 | @url{http://www.cmake.org, CMake build tool}. | |
2261 | ||
2262 | It automatically adds the @code{cmake} package to the set of inputs. | |
2263 | Which package is used can be specified with the @code{#:cmake} | |
2264 | parameter. | |
9849cfc1 LC |
2265 | |
2266 | The @code{#:configure-flags} parameter is taken as a list of flags | |
2267 | passed to the @command{cmake} command. The @code{#:build-type} | |
2268 | parameter specifies in abstract terms the flags passed to the compiler; | |
2269 | it defaults to @code{"RelWithDebInfo"} (short for ``release mode with | |
2270 | debugging information''), which roughly means that code is compiled with | |
2271 | @code{-O2 -g}, as is the case for Autoconf-based packages by default. | |
7458bd0a LC |
2272 | @end defvr |
2273 | ||
3afcf52b FB |
2274 | @defvr {Scheme Variable} glib-or-gtk-build-system |
2275 | This variable is exported by @code{(guix build-system glib-or-gtk)}. It | |
2276 | is intended for use with packages making use of GLib or GTK+. | |
2277 | ||
2278 | This build system adds the following two phases to the ones defined by | |
2279 | @var{gnu-build-system}: | |
2280 | ||
2281 | @table @code | |
2282 | @item glib-or-gtk-wrap | |
2283 | The phase @code{glib-or-gtk-wrap} ensures that programs found under | |
2284 | @file{bin/} are able to find GLib's ``schemas'' and | |
2285 | @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+ | |
2286 | modules}. This is achieved by wrapping the programs in launch scripts | |
2287 | that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH} | |
2288 | environment variables. | |
2289 | ||
73aa8ddb LC |
2290 | It is possible to exclude specific package outputs from that wrapping |
2291 | process by listing their names in the | |
2292 | @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful | |
2293 | when an output is known not to contain any GLib or GTK+ binaries, and | |
2294 | where wrapping would gratuitously add a dependency of that output on | |
2295 | GLib and GTK+. | |
2296 | ||
3afcf52b FB |
2297 | @item glib-or-gtk-compile-schemas |
2298 | The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's | |
2299 | @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html, | |
2300 | GSettings schemas} are compiled. Compilation is performed by the | |
2301 | @command{glib-compile-schemas} program. It is provided by the package | |
2302 | @code{glib:bin} which is automatically imported by the build system. | |
2303 | The @code{glib} package providing @command{glib-compile-schemas} can be | |
2304 | specified with the @code{#:glib} parameter. | |
2305 | @end table | |
2306 | ||
2307 | Both phases are executed after the @code{install} phase. | |
2308 | @end defvr | |
2309 | ||
7458bd0a LC |
2310 | @defvr {Scheme Variable} python-build-system |
2311 | This variable is exported by @code{(guix build-system python)}. It | |
2312 | implements the more or less standard build procedure used by Python | |
2313 | packages, which consists in running @code{python setup.py build} and | |
2314 | then @code{python setup.py install --prefix=/gnu/store/@dots{}}. | |
2315 | ||
2316 | For packages that install stand-alone Python programs under @code{bin/}, | |
2317 | it takes care of wrapping these programs so their @code{PYTHONPATH} | |
2318 | environment variable points to all the Python libraries they depend on. | |
2319 | ||
2320 | Which Python package is used can be specified with the @code{#:python} | |
2321 | parameter. | |
2322 | @end defvr | |
2323 | ||
2324 | @defvr {Scheme Variable} perl-build-system | |
2325 | This variable is exported by @code{(guix build-system perl)}. It | |
2d2a53fc EB |
2326 | implements the standard build procedure for Perl packages, which either |
2327 | consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}}, | |
2328 | followed by @code{Build} and @code{Build install}; or in running | |
2329 | @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by | |
2330 | @code{make} and @code{make install}; depending on which of | |
2331 | @code{Build.PL} or @code{Makefile.PL} is present in the package | |
2332 | distribution. Preference is given to the former if both @code{Build.PL} | |
2333 | and @code{Makefile.PL} exist in the package distribution. This | |
2334 | preference can be reversed by specifying @code{#t} for the | |
2335 | @code{#:make-maker?} parameter. | |
2336 | ||
2337 | The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation | |
2338 | passes flags specified by the @code{#:make-maker-flags} or | |
2339 | @code{#:module-build-flags} parameter, respectively. | |
7458bd0a LC |
2340 | |
2341 | Which Perl package is used can be specified with @code{#:perl}. | |
2342 | @end defvr | |
2343 | ||
c08f9818 DT |
2344 | @defvr {Scheme Variable} ruby-build-system |
2345 | This variable is exported by @code{(guix build-system ruby)}. It | |
2346 | implements the RubyGems build procedure used by Ruby packages, which | |
2347 | involves running @code{gem build} followed by @code{gem install}. | |
2348 | ||
2349 | Which Ruby package is used can be specified with the @code{#:ruby} | |
2350 | parameter. | |
2351 | @end defvr | |
7458bd0a | 2352 | |
a677c726 RW |
2353 | @defvr {Scheme Variable} waf-build-system |
2354 | This variable is exported by @code{(guix build-system waf)}. It | |
2355 | implements a build procedure around the @code{waf} script. The common | |
2356 | phases---@code{configure}, @code{build}, and @code{install}---are | |
2357 | implemented by passing their names as arguments to the @code{waf} | |
2358 | script. | |
2359 | ||
2360 | The @code{waf} script is executed by the Python interpreter. Which | |
2361 | Python package is used to run the script can be specified with the | |
2362 | @code{#:python} parameter. | |
2363 | @end defvr | |
2364 | ||
14dfdf2e FB |
2365 | @defvr {Scheme Variable} haskell-build-system |
2366 | This variable is exported by @code{(guix build-system haskell)}. It | |
2367 | implements the Cabal build procedure used by Haskell packages, which | |
2368 | involves running @code{runhaskell Setup.hs configure | |
2369 | --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}. | |
2370 | Instead of installing the package by running @code{runhaskell Setup.hs | |
2371 | install}, to avoid trying to register libraries in the read-only | |
2372 | compiler store directory, the build system uses @code{runhaskell | |
2373 | Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In | |
2374 | addition, the build system generates the package documentation by | |
2375 | running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f} | |
2376 | is passed. Optional Haddock parameters can be passed with the help of | |
2377 | the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is | |
2378 | not found, the build system looks for @code{Setup.lhs} instead. | |
2379 | ||
2380 | Which Haskell compiler is used can be specified with the @code{#:haskell} | |
2381 | parameter which defaults to @code{ghc}. | |
2382 | @end defvr | |
2383 | ||
7458bd0a LC |
2384 | Lastly, for packages that do not need anything as sophisticated, a |
2385 | ``trivial'' build system is provided. It is trivial in the sense that | |
2386 | it provides basically no support: it does not pull any implicit inputs, | |
2387 | and does not have a notion of build phases. | |
2388 | ||
2389 | @defvr {Scheme Variable} trivial-build-system | |
2390 | This variable is exported by @code{(guix build-system trivial)}. | |
2391 | ||
2392 | This build system requires a @code{#:builder} argument. This argument | |
2393 | must be a Scheme expression that builds the package's output(s)---as | |
2394 | with @code{build-expression->derivation} (@pxref{Derivations, | |
2395 | @code{build-expression->derivation}}). | |
2396 | @end defvr | |
2397 | ||
568717fd LC |
2398 | @node The Store |
2399 | @section The Store | |
2400 | ||
e531ac2a LC |
2401 | @cindex store |
2402 | @cindex store paths | |
2403 | ||
2404 | Conceptually, the @dfn{store} is where derivations that have been | |
834129e0 | 2405 | successfully built are stored---by default, under @file{/gnu/store}. |
e531ac2a LC |
2406 | Sub-directories in the store are referred to as @dfn{store paths}. The |
2407 | store has an associated database that contains information such has the | |
2408 | store paths referred to by each store path, and the list of @emph{valid} | |
2409 | store paths---paths that result from a successful build. | |
2410 | ||
2411 | The store is always accessed by the daemon on behalf of its clients | |
2412 | (@pxref{Invoking guix-daemon}). To manipulate the store, clients | |
2413 | connect to the daemon over a Unix-domain socket, send it requests, and | |
2414 | read the result---these are remote procedure calls, or RPCs. | |
2415 | ||
2416 | The @code{(guix store)} module provides procedures to connect to the | |
2417 | daemon, and to perform RPCs. These are described below. | |
2418 | ||
2419 | @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t] | |
2420 | Connect to the daemon over the Unix-domain socket at @var{file}. When | |
2421 | @var{reserve-space?} is true, instruct it to reserve a little bit of | |
2422 | extra space on the file system so that the garbage collector can still | |
2423 | operate, should the disk become full. Return a server object. | |
2424 | ||
2425 | @var{file} defaults to @var{%default-socket-path}, which is the normal | |
2426 | location given the options that were passed to @command{configure}. | |
2427 | @end deffn | |
2428 | ||
2429 | @deffn {Scheme Procedure} close-connection @var{server} | |
2430 | Close the connection to @var{server}. | |
2431 | @end deffn | |
2432 | ||
2433 | @defvr {Scheme Variable} current-build-output-port | |
2434 | This variable is bound to a SRFI-39 parameter, which refers to the port | |
2435 | where build and error logs sent by the daemon should be written. | |
2436 | @end defvr | |
2437 | ||
2438 | Procedures that make RPCs all take a server object as their first | |
2439 | argument. | |
2440 | ||
2441 | @deffn {Scheme Procedure} valid-path? @var{server} @var{path} | |
2442 | Return @code{#t} when @var{path} is a valid store path. | |
2443 | @end deffn | |
2444 | ||
cfbf9160 | 2445 | @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}] |
e531ac2a LC |
2446 | Add @var{text} under file @var{name} in the store, and return its store |
2447 | path. @var{references} is the list of store paths referred to by the | |
2448 | resulting store path. | |
2449 | @end deffn | |
2450 | ||
874e6874 | 2451 | @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations} |
59688fc4 LC |
2452 | Build @var{derivations} (a list of @code{<derivation>} objects or |
2453 | derivation paths), and return when the worker is done building them. | |
2454 | Return @code{#t} on success. | |
874e6874 LC |
2455 | @end deffn |
2456 | ||
b860f382 LC |
2457 | Note that the @code{(guix monads)} module provides a monad as well as |
2458 | monadic versions of the above procedures, with the goal of making it | |
2459 | more convenient to work with code that accesses the store (@pxref{The | |
2460 | Store Monad}). | |
2461 | ||
e531ac2a LC |
2462 | @c FIXME |
2463 | @i{This section is currently incomplete.} | |
568717fd LC |
2464 | |
2465 | @node Derivations | |
2466 | @section Derivations | |
2467 | ||
874e6874 LC |
2468 | @cindex derivations |
2469 | Low-level build actions and the environment in which they are performed | |
2470 | are represented by @dfn{derivations}. A derivation contain the | |
2471 | following pieces of information: | |
2472 | ||
2473 | @itemize | |
2474 | @item | |
2475 | The outputs of the derivation---derivations produce at least one file or | |
2476 | directory in the store, but may produce more. | |
2477 | ||
2478 | @item | |
2479 | The inputs of the derivations, which may be other derivations or plain | |
2480 | files in the store (patches, build scripts, etc.) | |
2481 | ||
2482 | @item | |
2483 | The system type targeted by the derivation---e.g., @code{x86_64-linux}. | |
2484 | ||
2485 | @item | |
2486 | The file name of a build script in the store, along with the arguments | |
2487 | to be passed. | |
2488 | ||
2489 | @item | |
2490 | A list of environment variables to be defined. | |
2491 | ||
2492 | @end itemize | |
2493 | ||
2494 | @cindex derivation path | |
2495 | Derivations allow clients of the daemon to communicate build actions to | |
2496 | the store. They exist in two forms: as an in-memory representation, | |
2497 | both on the client- and daemon-side, and as files in the store whose | |
2498 | name end in @code{.drv}---these files are referred to as @dfn{derivation | |
2499 | paths}. Derivations paths can be passed to the @code{build-derivations} | |
2500 | procedure to perform the build actions they prescribe (@pxref{The | |
2501 | Store}). | |
2502 | ||
2503 | The @code{(guix derivations)} module provides a representation of | |
2504 | derivations as Scheme objects, along with procedures to create and | |
2505 | otherwise manipulate derivations. The lowest-level primitive to create | |
2506 | a derivation is the @code{derivation} procedure: | |
2507 | ||
1909431c LC |
2508 | @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @ |
2509 | @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @ | |
2096ef47 | 2510 | [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @ |
1909431c | 2511 | [#:system (%current-system)] [#:references-graphs #f] @ |
c0468155 | 2512 | [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] |
59688fc4 LC |
2513 | Build a derivation with the given arguments, and return the resulting |
2514 | @code{<derivation>} object. | |
874e6874 | 2515 | |
2096ef47 | 2516 | When @var{hash} and @var{hash-algo} are given, a |
874e6874 | 2517 | @dfn{fixed-output derivation} is created---i.e., one whose result is |
36bbbbd1 LC |
2518 | known in advance, such as a file download. If, in addition, |
2519 | @var{recursive?} is true, then that fixed output may be an executable | |
2520 | file or a directory and @var{hash} must be the hash of an archive | |
2521 | containing this output. | |
5b0c9d16 | 2522 | |
858e9282 | 2523 | When @var{references-graphs} is true, it must be a list of file |
5b0c9d16 LC |
2524 | name/store path pairs. In that case, the reference graph of each store |
2525 | path is exported in the build environment in the corresponding file, in | |
2526 | a simple text format. | |
1909431c | 2527 | |
b53be755 LC |
2528 | When @var{allowed-references} is true, it must be a list of store items |
2529 | or outputs that the derivation's output may refer to. | |
2530 | ||
c0468155 LC |
2531 | When @var{leaked-env-vars} is true, it must be a list of strings |
2532 | denoting environment variables that are allowed to ``leak'' from the | |
2533 | daemon's environment to the build environment. This is only applicable | |
2534 | to fixed-output derivations---i.e., when @var{hash} is true. The main | |
2535 | use is to allow variables such as @code{http_proxy} to be passed to | |
2536 | derivations that download files. | |
2537 | ||
1909431c LC |
2538 | When @var{local-build?} is true, declare that the derivation is not a |
2539 | good candidate for offloading and should rather be built locally | |
2540 | (@pxref{Daemon Offload Setup}). This is the case for small derivations | |
2541 | where the costs of data transfers would outweigh the benefits. | |
874e6874 LC |
2542 | @end deffn |
2543 | ||
2544 | @noindent | |
2545 | Here's an example with a shell script as its builder, assuming | |
2546 | @var{store} is an open connection to the daemon, and @var{bash} points | |
2547 | to a Bash executable in the store: | |
2548 | ||
2549 | @lisp | |
2550 | (use-modules (guix utils) | |
2551 | (guix store) | |
2552 | (guix derivations)) | |
2553 | ||
59688fc4 LC |
2554 | (let ((builder ; add the Bash script to the store |
2555 | (add-text-to-store store "my-builder.sh" | |
2556 | "echo hello world > $out\n" '()))) | |
2557 | (derivation store "foo" | |
2558 | bash `("-e" ,builder) | |
21b679f6 | 2559 | #:inputs `((,bash) (,builder)) |
59688fc4 | 2560 | #:env-vars '(("HOME" . "/homeless")))) |
834129e0 | 2561 | @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo> |
874e6874 LC |
2562 | @end lisp |
2563 | ||
21b679f6 LC |
2564 | As can be guessed, this primitive is cumbersome to use directly. A |
2565 | better approach is to write build scripts in Scheme, of course! The | |
2566 | best course of action for that is to write the build code as a | |
2567 | ``G-expression'', and to pass it to @code{gexp->derivation}. For more | |
6621cdb6 | 2568 | information, @pxref{G-Expressions}. |
21b679f6 LC |
2569 | |
2570 | Once upon a time, @code{gexp->derivation} did not exist and constructing | |
2571 | derivations with build code written in Scheme was achieved with | |
2572 | @code{build-expression->derivation}, documented below. This procedure | |
2573 | is now deprecated in favor of the much nicer @code{gexp->derivation}. | |
874e6874 | 2574 | |
dd1a5a15 LC |
2575 | @deffn {Scheme Procedure} build-expression->derivation @var{store} @ |
2576 | @var{name} @var{exp} @ | |
2577 | [#:system (%current-system)] [#:inputs '()] @ | |
2578 | [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @ | |
36bbbbd1 | 2579 | [#:recursive? #f] [#:env-vars '()] [#:modules '()] @ |
63a42824 LC |
2580 | [#:references-graphs #f] [#:allowed-references #f] @ |
2581 | [#:local-build? #f] [#:guile-for-build #f] | |
874e6874 LC |
2582 | Return a derivation that executes Scheme expression @var{exp} as a |
2583 | builder for derivation @var{name}. @var{inputs} must be a list of | |
2584 | @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted, | |
2585 | @code{"out"} is assumed. @var{modules} is a list of names of Guile | |
2586 | modules from the current search path to be copied in the store, | |
2587 | compiled, and made available in the load path during the execution of | |
2588 | @var{exp}---e.g., @code{((guix build utils) (guix build | |
2589 | gnu-build-system))}. | |
2590 | ||
2591 | @var{exp} is evaluated in an environment where @code{%outputs} is bound | |
2592 | to a list of output/path pairs, and where @code{%build-inputs} is bound | |
2593 | to a list of string/output-path pairs made from @var{inputs}. | |
2594 | Optionally, @var{env-vars} is a list of string pairs specifying the name | |
2595 | and value of environment variables visible to the builder. The builder | |
2596 | terminates by passing the result of @var{exp} to @code{exit}; thus, when | |
2597 | @var{exp} returns @code{#f}, the build is considered to have failed. | |
2598 | ||
2599 | @var{exp} is built using @var{guile-for-build} (a derivation). When | |
2600 | @var{guile-for-build} is omitted or is @code{#f}, the value of the | |
2601 | @code{%guile-for-build} fluid is used instead. | |
9c629a27 | 2602 | |
63a42824 LC |
2603 | See the @code{derivation} procedure for the meaning of |
2604 | @var{references-graphs}, @var{allowed-references}, and @var{local-build?}. | |
874e6874 LC |
2605 | @end deffn |
2606 | ||
2607 | @noindent | |
2608 | Here's an example of a single-output derivation that creates a directory | |
2609 | containing one file: | |
2610 | ||
2611 | @lisp | |
2612 | (let ((builder '(let ((out (assoc-ref %outputs "out"))) | |
834129e0 | 2613 | (mkdir out) ; create /gnu/store/@dots{}-goo |
874e6874 LC |
2614 | (call-with-output-file (string-append out "/test") |
2615 | (lambda (p) | |
2616 | (display '(hello guix) p)))))) | |
dd1a5a15 | 2617 | (build-expression->derivation store "goo" builder)) |
874e6874 | 2618 | |
834129e0 | 2619 | @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}> |
874e6874 LC |
2620 | @end lisp |
2621 | ||
568717fd | 2622 | |
b860f382 LC |
2623 | @node The Store Monad |
2624 | @section The Store Monad | |
2625 | ||
2626 | @cindex monad | |
2627 | ||
2628 | The procedures that operate on the store described in the previous | |
2629 | sections all take an open connection to the build daemon as their first | |
2630 | argument. Although the underlying model is functional, they either have | |
2631 | side effects or depend on the current state of the store. | |
2632 | ||
2633 | The former is inconvenient: the connection to the build daemon has to be | |
2634 | carried around in all those functions, making it impossible to compose | |
2635 | functions that do not take that parameter with functions that do. The | |
2636 | latter can be problematic: since store operations have side effects | |
2637 | and/or depend on external state, they have to be properly sequenced. | |
2638 | ||
2639 | @cindex monadic values | |
2640 | @cindex monadic functions | |
2641 | This is where the @code{(guix monads)} module comes in. This module | |
2642 | provides a framework for working with @dfn{monads}, and a particularly | |
2643 | useful monad for our uses, the @dfn{store monad}. Monads are a | |
2644 | construct that allows two things: associating ``context'' with values | |
2645 | (in our case, the context is the store), and building sequences of | |
561fb6c3 | 2646 | computations (here computations include accesses to the store.) Values |
b860f382 LC |
2647 | in a monad---values that carry this additional context---are called |
2648 | @dfn{monadic values}; procedures that return such values are called | |
2649 | @dfn{monadic procedures}. | |
2650 | ||
2651 | Consider this ``normal'' procedure: | |
2652 | ||
2653 | @example | |
45adbd62 LC |
2654 | (define (sh-symlink store) |
2655 | ;; Return a derivation that symlinks the 'bash' executable. | |
2656 | (let* ((drv (package-derivation store bash)) | |
2657 | (out (derivation->output-path drv)) | |
2658 | (sh (string-append out "/bin/bash"))) | |
2659 | (build-expression->derivation store "sh" | |
2660 | `(symlink ,sh %output)))) | |
b860f382 LC |
2661 | @end example |
2662 | ||
c6f30b81 LC |
2663 | Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten |
2664 | as a monadic function: | |
b860f382 LC |
2665 | |
2666 | @example | |
45adbd62 | 2667 | (define (sh-symlink) |
b860f382 | 2668 | ;; Same, but return a monadic value. |
c6f30b81 LC |
2669 | (mlet %store-monad ((drv (package->derivation bash))) |
2670 | (gexp->derivation "sh" | |
2671 | #~(symlink (string-append #$drv "/bin/bash") | |
2672 | #$output)))) | |
b860f382 LC |
2673 | @end example |
2674 | ||
c6f30b81 LC |
2675 | There several things to note in the second version: the @code{store} |
2676 | parameter is now implicit and is ``threaded'' in the calls to the | |
2677 | @code{package->derivation} and @code{gexp->derivation} monadic | |
2678 | procedures, and the monadic value returned by @code{package->derivation} | |
2679 | is @dfn{bound} using @code{mlet} instead of plain @code{let}. | |
2680 | ||
2681 | As it turns out, the call to @code{package->derivation} can even be | |
2682 | omitted since it will take place implicitly, as we will see later | |
2683 | (@pxref{G-Expressions}): | |
2684 | ||
2685 | @example | |
2686 | (define (sh-symlink) | |
2687 | (gexp->derivation "sh" | |
2688 | #~(symlink (string-append #$bash "/bin/bash") | |
2689 | #$output))) | |
2690 | @end example | |
b860f382 | 2691 | |
8e9aa37f | 2692 | Calling the monadic @code{sh-symlink} has no effect. To get the desired |
b860f382 LC |
2693 | effect, one must use @code{run-with-store}: |
2694 | ||
2695 | @example | |
8e9aa37f CAW |
2696 | (run-with-store (open-connection) (sh-symlink)) |
2697 | @result{} /gnu/store/...-sh-symlink | |
b860f382 LC |
2698 | @end example |
2699 | ||
b9b86078 LC |
2700 | Note that the @code{(guix monad-repl)} module extends Guile's REPL with |
2701 | new ``meta-commands'' to make it easier to deal with monadic procedures: | |
2702 | @code{run-in-store}, and @code{enter-store-monad}. The former, is used | |
2703 | to ``run'' a single monadic value through the store: | |
2704 | ||
2705 | @example | |
2706 | scheme@@(guile-user)> ,run-in-store (package->derivation hello) | |
2707 | $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}> | |
2708 | @end example | |
2709 | ||
2710 | The latter enters a recursive REPL, where all the return values are | |
2711 | automatically run through the store: | |
2712 | ||
2713 | @example | |
2714 | scheme@@(guile-user)> ,enter-store-monad | |
2715 | store-monad@@(guile-user) [1]> (package->derivation hello) | |
2716 | $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}> | |
2717 | store-monad@@(guile-user) [1]> (text-file "foo" "Hello!") | |
2718 | $3 = "/gnu/store/@dots{}-foo" | |
2719 | store-monad@@(guile-user) [1]> ,q | |
2720 | scheme@@(guile-user)> | |
2721 | @end example | |
2722 | ||
2723 | @noindent | |
2724 | Note that non-monadic values cannot be returned in the | |
2725 | @code{store-monad} REPL. | |
2726 | ||
e87f0591 LC |
2727 | The main syntactic forms to deal with monads in general are provided by |
2728 | the @code{(guix monads)} module and are described below. | |
b860f382 LC |
2729 | |
2730 | @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ... | |
2731 | Evaluate any @code{>>=} or @code{return} forms in @var{body} as being | |
2732 | in @var{monad}. | |
2733 | @end deffn | |
2734 | ||
2735 | @deffn {Scheme Syntax} return @var{val} | |
2736 | Return a monadic value that encapsulates @var{val}. | |
2737 | @end deffn | |
2738 | ||
2739 | @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} | |
2740 | @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic | |
2741 | procedure @var{mproc}@footnote{This operation is commonly referred to as | |
2742 | ``bind'', but that name denotes an unrelated procedure in Guile. Thus | |
2743 | we use this somewhat cryptic symbol inherited from the Haskell | |
2744 | language.}. | |
2745 | @end deffn | |
2746 | ||
2747 | @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @ | |
2748 | @var{body} ... | |
2749 | @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @ | |
2750 | @var{body} ... | |
2751 | Bind the variables @var{var} to the monadic values @var{mval} in | |
2752 | @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the | |
2753 | ``normal'' value @var{val}, as per @code{let}. | |
2754 | ||
2755 | @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let} | |
2756 | (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}). | |
2757 | @end deffn | |
2758 | ||
405a9d4e LC |
2759 | @deffn {Scheme System} mbegin @var{monad} @var{mexp} ... |
2760 | Bind @var{mexp} and the following monadic expressions in sequence, | |
2761 | returning the result of the last expression. | |
2762 | ||
2763 | This is akin to @code{mlet}, except that the return values of the | |
2764 | monadic expressions are ignored. In that sense, it is analogous to | |
2765 | @code{begin}, but applied to monadic expressions. | |
2766 | @end deffn | |
2767 | ||
561fb6c3 LC |
2768 | @cindex state monad |
2769 | The @code{(guix monads)} module provides the @dfn{state monad}, which | |
2770 | allows an additional value---the state---to be @emph{threaded} through | |
2771 | monadic procedure calls. | |
2772 | ||
2773 | @defvr {Scheme Variable} %state-monad | |
2774 | The state monad. Procedures in the state monad can access and change | |
2775 | the state that is threaded. | |
2776 | ||
2777 | Consider the example below. The @code{square} procedure returns a value | |
2778 | in the state monad. It returns the square of its argument, but also | |
2779 | increments the current state value: | |
2780 | ||
2781 | @example | |
2782 | (define (square x) | |
2783 | (mlet %state-monad ((count (current-state))) | |
2784 | (mbegin %state-monad | |
2785 | (set-current-state (+ 1 count)) | |
2786 | (return (* x x))))) | |
2787 | ||
2788 | (run-with-state (sequence %state-monad (map square (iota 3))) 0) | |
2789 | @result{} (0 1 4) | |
2790 | @result{} 3 | |
2791 | @end example | |
2792 | ||
2793 | When ``run'' through @var{%state-monad}, we obtain that additional state | |
2794 | value, which is the number of @code{square} calls. | |
2795 | @end defvr | |
2796 | ||
2797 | @deffn {Monadic Procedure} current-state | |
2798 | Return the current state as a monadic value. | |
2799 | @end deffn | |
2800 | ||
2801 | @deffn {Monadic Procedure} set-current-state @var{value} | |
2802 | Set the current state to @var{value} and return the previous state as a | |
2803 | monadic value. | |
2804 | @end deffn | |
2805 | ||
2806 | @deffn {Monadic Procedure} state-push @var{value} | |
2807 | Push @var{value} to the current state, which is assumed to be a list, | |
2808 | and return the previous state as a monadic value. | |
2809 | @end deffn | |
2810 | ||
2811 | @deffn {Monadic Procedure} state-pop | |
2812 | Pop a value from the current state and return it as a monadic value. | |
2813 | The state is assumed to be a list. | |
2814 | @end deffn | |
2815 | ||
2816 | @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}] | |
2817 | Run monadic value @var{mval} starting with @var{state} as the initial | |
2818 | state. Return two values: the resulting value, and the resulting state. | |
2819 | @end deffn | |
2820 | ||
e87f0591 LC |
2821 | The main interface to the store monad, provided by the @code{(guix |
2822 | store)} module, is as follows. | |
b860f382 LC |
2823 | |
2824 | @defvr {Scheme Variable} %store-monad | |
561fb6c3 LC |
2825 | The store monad---an alias for @var{%state-monad}. |
2826 | ||
2827 | Values in the store monad encapsulate accesses to the store. When its | |
2828 | effect is needed, a value of the store monad must be ``evaluated'' by | |
2829 | passing it to the @code{run-with-store} procedure (see below.) | |
b860f382 LC |
2830 | @end defvr |
2831 | ||
2832 | @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)] | |
2833 | Run @var{mval}, a monadic value in the store monad, in @var{store}, an | |
2834 | open store connection. | |
2835 | @end deffn | |
2836 | ||
ad372953 | 2837 | @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}] |
b860f382 | 2838 | Return as a monadic value the absolute file name in the store of the file |
ad372953 LC |
2839 | containing @var{text}, a string. @var{references} is a list of store items that the |
2840 | resulting text file refers to; it defaults to the empty list. | |
45adbd62 LC |
2841 | @end deffn |
2842 | ||
0a90af15 LC |
2843 | @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @ |
2844 | [#:recursive? #t] | |
2845 | Return the name of @var{file} once interned in the store. Use | |
2846 | @var{name} as its store name, or the basename of @var{file} if | |
2847 | @var{name} is omitted. | |
2848 | ||
2849 | When @var{recursive?} is true, the contents of @var{file} are added | |
2850 | recursively; if @var{file} designates a flat file and @var{recursive?} | |
2851 | is true, its contents are added, and its permission bits are kept. | |
2852 | ||
2853 | The example below adds a file to the store, under two different names: | |
2854 | ||
2855 | @example | |
2856 | (run-with-store (open-connection) | |
2857 | (mlet %store-monad ((a (interned-file "README")) | |
2858 | (b (interned-file "README" "LEGU-MIN"))) | |
2859 | (return (list a b)))) | |
2860 | ||
2861 | @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN") | |
2862 | @end example | |
2863 | ||
2864 | @end deffn | |
2865 | ||
e87f0591 LC |
2866 | The @code{(guix packages)} module exports the following package-related |
2867 | monadic procedures: | |
2868 | ||
b860f382 | 2869 | @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @ |
4231f05b LC |
2870 | [#:system (%current-system)] [#:target #f] @ |
2871 | [#:output "out"] Return as a monadic | |
b860f382 LC |
2872 | value in the absolute file name of @var{file} within the @var{output} |
2873 | directory of @var{package}. When @var{file} is omitted, return the name | |
4231f05b LC |
2874 | of the @var{output} directory of @var{package}. When @var{target} is |
2875 | true, use it as a cross-compilation target triplet. | |
b860f382 LC |
2876 | @end deffn |
2877 | ||
b860f382 | 2878 | @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}] |
4231f05b LC |
2879 | @deffnx {Monadic Procedure} package->cross-derivation @var{package} @ |
2880 | @var{target} [@var{system}] | |
2881 | Monadic version of @code{package-derivation} and | |
2882 | @code{package-cross-derivation} (@pxref{Defining Packages}). | |
b860f382 LC |
2883 | @end deffn |
2884 | ||
2885 | ||
21b679f6 LC |
2886 | @node G-Expressions |
2887 | @section G-Expressions | |
2888 | ||
2889 | @cindex G-expression | |
2890 | @cindex build code quoting | |
2891 | So we have ``derivations'', which represent a sequence of build actions | |
2892 | to be performed to produce an item in the store (@pxref{Derivations}). | |
2893 | Those build actions are performed when asking the daemon to actually | |
2894 | build the derivations; they are run by the daemon in a container | |
2895 | (@pxref{Invoking guix-daemon}). | |
2896 | ||
2897 | @cindex strata of code | |
2898 | It should come as no surprise that we like to write those build actions | |
2899 | in Scheme. When we do that, we end up with two @dfn{strata} of Scheme | |
2900 | code@footnote{The term @dfn{stratum} in this context was coined by | |
ef4ab0a4 LC |
2901 | Manuel Serrano et al.@: in the context of their work on Hop. Oleg |
2902 | Kiselyov, who has written insightful | |
2903 | @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code | |
2904 | on this topic}, refers to this kind of code generation as | |
2905 | @dfn{staging}.}: the ``host code''---code that defines packages, talks | |
2906 | to the daemon, etc.---and the ``build code''---code that actually | |
2907 | performs build actions, such as making directories, invoking | |
2908 | @command{make}, etc. | |
21b679f6 LC |
2909 | |
2910 | To describe a derivation and its build actions, one typically needs to | |
2911 | embed build code inside host code. It boils down to manipulating build | |
2912 | code as data, and Scheme's homoiconicity---code has a direct | |
2913 | representation as data---comes in handy for that. But we need more than | |
2914 | Scheme's normal @code{quasiquote} mechanism to construct build | |
2915 | expressions. | |
2916 | ||
2917 | The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of | |
2918 | S-expressions adapted to build expressions. G-expressions, or | |
2919 | @dfn{gexps}, consist essentially in three syntactic forms: @code{gexp}, | |
2920 | @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~}, | |
2921 | @code{#$}, and @code{#$@@}), which are comparable respectively to | |
2922 | @code{quasiquote}, @code{unquote}, and @code{unquote-splicing} | |
2923 | (@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile | |
2924 | Reference Manual}). However, there are major differences: | |
2925 | ||
2926 | @itemize | |
2927 | @item | |
2928 | Gexps are meant to be written to a file and run or manipulated by other | |
2929 | processes. | |
2930 | ||
2931 | @item | |
b39fc6f7 LC |
2932 | When a high-level object such as a package or derivation is unquoted |
2933 | inside a gexp, the result is as if its output file name had been | |
2934 | introduced. | |
ff40e9b7 | 2935 | |
21b679f6 LC |
2936 | @item |
2937 | Gexps carry information about the packages or derivations they refer to, | |
2938 | and these dependencies are automatically added as inputs to the build | |
2939 | processes that use them. | |
2940 | @end itemize | |
2941 | ||
b39fc6f7 LC |
2942 | Actually this mechanism is not limited to package and derivation |
2943 | objects; @dfn{compilers} able to ``lower'' other high-level objects to | |
2944 | derivations can be defined, such that these objects can also be inserted | |
d9ae938f LC |
2945 | into gexps. Another useful type of high-level object that can be |
2946 | inserted in a gexp is @dfn{local files}, which allows files from the | |
2947 | local file system to be added to the store and referred to by | |
2948 | derivations and such (see @code{local-file} below.) | |
b39fc6f7 | 2949 | |
21b679f6 LC |
2950 | To illustrate the idea, here is an example of a gexp: |
2951 | ||
2952 | @example | |
2953 | (define build-exp | |
2954 | #~(begin | |
2955 | (mkdir #$output) | |
2956 | (chdir #$output) | |
aff8ce7c | 2957 | (symlink (string-append #$coreutils "/bin/ls") |
21b679f6 LC |
2958 | "list-files"))) |
2959 | @end example | |
2960 | ||
2961 | This gexp can be passed to @code{gexp->derivation}; we obtain a | |
2962 | derivation that builds a directory containing exactly one symlink to | |
2963 | @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}: | |
2964 | ||
2965 | @example | |
2966 | (gexp->derivation "the-thing" build-exp) | |
2967 | @end example | |
2968 | ||
e20fd1bf | 2969 | As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is |
21b679f6 LC |
2970 | substituted to the reference to the @var{coreutils} package in the |
2971 | actual build code, and @var{coreutils} is automatically made an input to | |
2972 | the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp | |
2973 | output)}) is replaced by a string containing the derivation's output | |
667b2508 LC |
2974 | directory name. |
2975 | ||
2976 | @cindex cross compilation | |
2977 | In a cross-compilation context, it is useful to distinguish between | |
2978 | references to the @emph{native} build of a package---that can run on the | |
2979 | host---versus references to cross builds of a package. To that end, the | |
2980 | @code{#+} plays the same role as @code{#$}, but is a reference to a | |
2981 | native package build: | |
2982 | ||
2983 | @example | |
2984 | (gexp->derivation "vi" | |
2985 | #~(begin | |
2986 | (mkdir #$output) | |
2987 | (system* (string-append #+coreutils "/bin/ln") | |
2988 | "-s" | |
2989 | (string-append #$emacs "/bin/emacs") | |
2990 | (string-append #$output "/bin/vi"))) | |
2991 | #:target "mips64el-linux") | |
2992 | @end example | |
2993 | ||
2994 | @noindent | |
2995 | In the example above, the native build of @var{coreutils} is used, so | |
2996 | that @command{ln} can actually run on the host; but then the | |
2997 | cross-compiled build of @var{emacs} is referenced. | |
2998 | ||
2999 | The syntactic form to construct gexps is summarized below. | |
21b679f6 LC |
3000 | |
3001 | @deffn {Scheme Syntax} #~@var{exp} | |
3002 | @deffnx {Scheme Syntax} (gexp @var{exp}) | |
3003 | Return a G-expression containing @var{exp}. @var{exp} may contain one | |
3004 | or more of the following forms: | |
3005 | ||
3006 | @table @code | |
3007 | @item #$@var{obj} | |
3008 | @itemx (ungexp @var{obj}) | |
b39fc6f7 LC |
3009 | Introduce a reference to @var{obj}. @var{obj} may have one of the |
3010 | supported types, for example a package or a | |
21b679f6 LC |
3011 | derivation, in which case the @code{ungexp} form is replaced by its |
3012 | output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}. | |
3013 | ||
b39fc6f7 LC |
3014 | If @var{obj} is a list, it is traversed and references to supported |
3015 | objects are substituted similarly. | |
21b679f6 LC |
3016 | |
3017 | If @var{obj} is another gexp, its contents are inserted and its | |
3018 | dependencies are added to those of the containing gexp. | |
3019 | ||
3020 | If @var{obj} is another kind of object, it is inserted as is. | |
3021 | ||
b39fc6f7 LC |
3022 | @item #$@var{obj}:@var{output} |
3023 | @itemx (ungexp @var{obj} @var{output}) | |
21b679f6 | 3024 | This is like the form above, but referring explicitly to the |
b39fc6f7 LC |
3025 | @var{output} of @var{obj}---this is useful when @var{obj} produces |
3026 | multiple outputs (@pxref{Packages with Multiple Outputs}). | |
21b679f6 | 3027 | |
667b2508 LC |
3028 | @item #+@var{obj} |
3029 | @itemx #+@var{obj}:output | |
3030 | @itemx (ungexp-native @var{obj}) | |
3031 | @itemx (ungexp-native @var{obj} @var{output}) | |
3032 | Same as @code{ungexp}, but produces a reference to the @emph{native} | |
3033 | build of @var{obj} when used in a cross compilation context. | |
3034 | ||
21b679f6 LC |
3035 | @item #$output[:@var{output}] |
3036 | @itemx (ungexp output [@var{output}]) | |
3037 | Insert a reference to derivation output @var{output}, or to the main | |
3038 | output when @var{output} is omitted. | |
3039 | ||
3040 | This only makes sense for gexps passed to @code{gexp->derivation}. | |
3041 | ||
3042 | @item #$@@@var{lst} | |
3043 | @itemx (ungexp-splicing @var{lst}) | |
3044 | Like the above, but splices the contents of @var{lst} inside the | |
3045 | containing list. | |
3046 | ||
667b2508 LC |
3047 | @item #+@@@var{lst} |
3048 | @itemx (ungexp-native-splicing @var{lst}) | |
3049 | Like the above, but refers to native builds of the objects listed in | |
3050 | @var{lst}. | |
3051 | ||
21b679f6 LC |
3052 | @end table |
3053 | ||
3054 | G-expressions created by @code{gexp} or @code{#~} are run-time objects | |
3055 | of the @code{gexp?} type (see below.) | |
3056 | @end deffn | |
3057 | ||
3058 | @deffn {Scheme Procedure} gexp? @var{obj} | |
3059 | Return @code{#t} if @var{obj} is a G-expression. | |
3060 | @end deffn | |
3061 | ||
3062 | G-expressions are meant to be written to disk, either as code building | |
3063 | some derivation, or as plain files in the store. The monadic procedures | |
3064 | below allow you to do that (@pxref{The Store Monad}, for more | |
3065 | information about monads.) | |
3066 | ||
3067 | @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @ | |
ce45eb4c | 3068 | [#:system (%current-system)] [#:target #f] [#:graft? #t] @ |
21b679f6 LC |
3069 | [#:hash #f] [#:hash-algo #f] @ |
3070 | [#:recursive? #f] [#:env-vars '()] [#:modules '()] @ | |
4684f301 | 3071 | [#:module-path @var{%load-path}] @ |
c8351d9a | 3072 | [#:references-graphs #f] [#:allowed-references #f] @ |
c0468155 | 3073 | [#:leaked-env-vars #f] @ |
c8351d9a | 3074 | [#:local-build? #f] [#:guile-for-build #f] |
21b679f6 | 3075 | Return a derivation @var{name} that runs @var{exp} (a gexp) with |
68a61e9f LC |
3076 | @var{guile-for-build} (a derivation) on @var{system}. When @var{target} |
3077 | is true, it is used as the cross-compilation target triplet for packages | |
3078 | referred to by @var{exp}. | |
21b679f6 | 3079 | |
ce45eb4c LC |
3080 | Make @var{modules} available in the evaluation context of @var{exp}; |
3081 | @var{modules} is a list of names of Guile modules searched in | |
3082 | @var{module-path} to be copied in the store, compiled, and made available in | |
21b679f6 LC |
3083 | the load path during the execution of @var{exp}---e.g., @code{((guix |
3084 | build utils) (guix build gnu-build-system))}. | |
3085 | ||
ce45eb4c LC |
3086 | @var{graft?} determines whether packages referred to by @var{exp} should be grafted when |
3087 | applicable. | |
3088 | ||
b53833b2 LC |
3089 | When @var{references-graphs} is true, it must be a list of tuples of one of the |
3090 | following forms: | |
3091 | ||
3092 | @example | |
3093 | (@var{file-name} @var{package}) | |
3094 | (@var{file-name} @var{package} @var{output}) | |
3095 | (@var{file-name} @var{derivation}) | |
3096 | (@var{file-name} @var{derivation} @var{output}) | |
3097 | (@var{file-name} @var{store-item}) | |
3098 | @end example | |
3099 | ||
3100 | The right-hand-side of each element of @var{references-graphs} is automatically made | |
3101 | an input of the build process of @var{exp}. In the build environment, each | |
3102 | @var{file-name} contains the reference graph of the corresponding item, in a simple | |
3103 | text format. | |
3104 | ||
c8351d9a LC |
3105 | @var{allowed-references} must be either @code{#f} or a list of output names and packages. |
3106 | In the latter case, the list denotes store items that the result is allowed to | |
3107 | refer to. Any reference to another store item will lead to a build error. | |
3108 | ||
e20fd1bf | 3109 | The other arguments are as for @code{derivation} (@pxref{Derivations}). |
21b679f6 LC |
3110 | @end deffn |
3111 | ||
d9ae938f LC |
3112 | @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @ |
3113 | [#:recursive? #t] | |
3114 | Return an object representing local file @var{file} to add to the store; this | |
3115 | object can be used in a gexp. @var{file} will be added to the store under @var{name}--by | |
3116 | default the base name of @var{file}. | |
3117 | ||
3118 | When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file} | |
3119 | designates a flat file and @var{recursive?} is true, its contents are added, and its | |
3120 | permission bits are kept. | |
3121 | ||
3122 | This is the declarative counterpart of the @code{interned-file} monadic | |
3123 | procedure (@pxref{The Store Monad, @code{interned-file}}). | |
3124 | @end deffn | |
3125 | ||
21b679f6 LC |
3126 | @deffn {Monadic Procedure} gexp->script @var{name} @var{exp} |
3127 | Return an executable script @var{name} that runs @var{exp} using | |
3128 | @var{guile} with @var{modules} in its search path. | |
3129 | ||
3130 | The example below builds a script that simply invokes the @command{ls} | |
3131 | command: | |
3132 | ||
3133 | @example | |
3134 | (use-modules (guix gexp) (gnu packages base)) | |
3135 | ||
3136 | (gexp->script "list-files" | |
3137 | #~(execl (string-append #$coreutils "/bin/ls") | |
3138 | "ls")) | |
3139 | @end example | |
3140 | ||
3141 | When ``running'' it through the store (@pxref{The Store Monad, | |
e20fd1bf | 3142 | @code{run-with-store}}), we obtain a derivation that produces an |
21b679f6 LC |
3143 | executable file @file{/gnu/store/@dots{}-list-files} along these lines: |
3144 | ||
3145 | @example | |
3146 | #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds | |
3147 | !# | |
3148 | (execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls") | |
3149 | "ls") | |
3150 | @end example | |
3151 | @end deffn | |
3152 | ||
3153 | @deffn {Monadic Procedure} gexp->file @var{name} @var{exp} | |
3154 | Return a derivation that builds a file @var{name} containing @var{exp}. | |
3155 | ||
3156 | The resulting file holds references to all the dependencies of @var{exp} | |
3157 | or a subset thereof. | |
3158 | @end deffn | |
1ed19464 LC |
3159 | |
3160 | @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{} | |
3161 | Return as a monadic value a derivation that builds a text file | |
3162 | containing all of @var{text}. @var{text} may list, in addition to | |
d9ae938f LC |
3163 | strings, objects of any type that can be used in a gexp: packages, |
3164 | derivations, local file objects, etc. The resulting store file holds | |
3165 | references to all these. | |
1ed19464 LC |
3166 | |
3167 | This variant should be preferred over @code{text-file} anytime the file | |
3168 | to create will reference items from the store. This is typically the | |
3169 | case when building a configuration file that embeds store file names, | |
3170 | like this: | |
3171 | ||
3172 | @example | |
3173 | (define (profile.sh) | |
3174 | ;; Return the name of a shell script in the store that | |
3175 | ;; initializes the 'PATH' environment variable. | |
3176 | (text-file* "profile.sh" | |
3177 | "export PATH=" coreutils "/bin:" | |
3178 | grep "/bin:" sed "/bin\n")) | |
3179 | @end example | |
3180 | ||
3181 | In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file | |
3182 | will references @var{coreutils}, @var{grep}, and @var{sed}, thereby | |
3183 | preventing them from being garbage-collected during its lifetime. | |
3184 | @end deffn | |
21b679f6 LC |
3185 | |
3186 | Of course, in addition to gexps embedded in ``host'' code, there are | |
3187 | also modules containing build tools. To make it clear that they are | |
3188 | meant to be used in the build stratum, these modules are kept in the | |
3189 | @code{(guix build @dots{})} name space. | |
3190 | ||
3191 | ||
568717fd LC |
3192 | @c ********************************************************************* |
3193 | @node Utilities | |
3194 | @chapter Utilities | |
3195 | ||
210cc920 LC |
3196 | This section describes tools primarily targeted at developers and users |
3197 | who write new package definitions. They complement the Scheme | |
3198 | programming interface of Guix in a convenient way. | |
3199 | ||
568717fd | 3200 | @menu |
37166310 | 3201 | * Invoking guix build:: Building packages from the command line. |
210cc920 | 3202 | * Invoking guix download:: Downloading a file and printing its hash. |
37166310 | 3203 | * Invoking guix hash:: Computing the cryptographic hash of a file. |
2f7d2d91 | 3204 | * Invoking guix import:: Importing package definitions. |
37166310 | 3205 | * Invoking guix refresh:: Updating package definitions. |
b4f5e0e8 | 3206 | * Invoking guix lint:: Finding errors in package definitions. |
372c4bbc | 3207 | * Invoking guix environment:: Setting up development environments. |
aff8ce7c | 3208 | * Invoking guix publish:: Sharing substitutes. |
568717fd LC |
3209 | @end menu |
3210 | ||
e49951eb MW |
3211 | @node Invoking guix build |
3212 | @section Invoking @command{guix build} | |
568717fd | 3213 | |
e49951eb | 3214 | The @command{guix build} command builds packages or derivations and |
6798a8e4 LC |
3215 | their dependencies, and prints the resulting store paths. Note that it |
3216 | does not modify the user's profile---this is the job of the | |
e49951eb | 3217 | @command{guix package} command (@pxref{Invoking guix package}). Thus, |
6798a8e4 LC |
3218 | it is mainly useful for distribution developers. |
3219 | ||
3220 | The general syntax is: | |
c78bd12b LC |
3221 | |
3222 | @example | |
e49951eb | 3223 | guix build @var{options} @var{package-or-derivation}@dots{} |
c78bd12b LC |
3224 | @end example |
3225 | ||
3226 | @var{package-or-derivation} may be either the name of a package found in | |
5401dd75 LC |
3227 | the software distribution such as @code{coreutils} or |
3228 | @code{coreutils-8.20}, or a derivation such as | |
834129e0 | 3229 | @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a |
e7f34eb0 LC |
3230 | package with the corresponding name (and optionally version) is searched |
3231 | for among the GNU distribution modules (@pxref{Package Modules}). | |
3232 | ||
3233 | Alternatively, the @code{--expression} option may be used to specify a | |
3234 | Scheme expression that evaluates to a package; this is useful when | |
3235 | disambiguation among several same-named packages or package variants is | |
3236 | needed. | |
c78bd12b LC |
3237 | |
3238 | The @var{options} may be zero or more of the following: | |
3239 | ||
3240 | @table @code | |
3241 | ||
3242 | @item --expression=@var{expr} | |
3243 | @itemx -e @var{expr} | |
ac5de156 | 3244 | Build the package or derivation @var{expr} evaluates to. |
c78bd12b | 3245 | |
5401dd75 | 3246 | For example, @var{expr} may be @code{(@@ (gnu packages guile) |
c78bd12b LC |
3247 | guile-1.8)}, which unambiguously designates this specific variant of |
3248 | version 1.8 of Guile. | |
3249 | ||
56b82106 LC |
3250 | Alternately, @var{expr} may be a G-expression, in which case it is used |
3251 | as a build program passed to @code{gexp->derivation} | |
3252 | (@pxref{G-Expressions}). | |
3253 | ||
3254 | Lastly, @var{expr} may refer to a zero-argument monadic procedure | |
ac5de156 LC |
3255 | (@pxref{The Store Monad}). The procedure must return a derivation as a |
3256 | monadic value, which is then passed through @code{run-with-store}. | |
3257 | ||
c78bd12b LC |
3258 | @item --source |
3259 | @itemx -S | |
3260 | Build the packages' source derivations, rather than the packages | |
3261 | themselves. | |
3262 | ||
e49951eb | 3263 | For instance, @code{guix build -S gcc} returns something like |
834129e0 | 3264 | @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball. |
c78bd12b | 3265 | |
f9cc8971 LC |
3266 | The returned source tarball is the result of applying any patches and |
3267 | code snippets specified in the package's @code{origin} (@pxref{Defining | |
3268 | Packages}). | |
3269 | ||
2cdfe13d EB |
3270 | @item --sources |
3271 | Fetch and return the source of @var{package-or-derivation} and all their | |
3272 | dependencies, recursively. This is a handy way to obtain a local copy | |
3273 | of all the source code needed to build @var{packages}, allowing you to | |
3274 | eventually build them even without network access. It is an extension | |
3275 | of the @code{--source} option and can accept one of the following | |
3276 | optional argument values: | |
3277 | ||
3278 | @table @code | |
3279 | @item package | |
3280 | This value causes the @code{--sources} option to behave in the same way | |
3281 | as the @code{--source} option. | |
3282 | ||
3283 | @item all | |
3284 | Build all packages' source derivations, including any source that might | |
3285 | be listed as @code{inputs}. This is the default value. | |
3286 | ||
3287 | @example | |
3288 | $ guix build --sources tzdata | |
3289 | The following derivations will be built: | |
3290 | /gnu/store/@dots{}-tzdata2015b.tar.gz.drv | |
3291 | /gnu/store/@dots{}-tzcode2015b.tar.gz.drv | |
3292 | @end example | |
3293 | ||
3294 | @item transitive | |
3295 | Build all packages' source derivations, as well as all source | |
3296 | derivations for packages' transitive inputs. This can be used e.g. to | |
3297 | prefetch package source for later offline building. | |
3298 | ||
3299 | @example | |
3300 | $ guix build --sources=transitive tzdata | |
3301 | The following derivations will be built: | |
3302 | /gnu/store/@dots{}-tzcode2015b.tar.gz.drv | |
3303 | /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv | |
3304 | /gnu/store/@dots{}-grep-2.21.tar.xz.drv | |
3305 | /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv | |
3306 | /gnu/store/@dots{}-make-4.1.tar.xz.drv | |
3307 | /gnu/store/@dots{}-bash-4.3.tar.xz.drv | |
3308 | @dots{} | |
3309 | @end example | |
3310 | ||
3311 | @end table | |
3312 | ||
c78bd12b LC |
3313 | @item --system=@var{system} |
3314 | @itemx -s @var{system} | |
3315 | Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of | |
3316 | the host's system type. | |
3317 | ||
3318 | An example use of this is on Linux-based systems, which can emulate | |
3319 | different personalities. For instance, passing | |
3320 | @code{--system=i686-linux} on an @code{x86_64-linux} system allows users | |
3321 | to build packages in a complete 32-bit environment. | |
3322 | ||
e55ec43d LC |
3323 | @item --target=@var{triplet} |
3324 | @cindex cross-compilation | |
3325 | Cross-build for @var{triplet}, which must be a valid GNU triplet, such | |
3326 | as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU | |
3327 | configuration triplets,, configure, GNU Configure and Build System}). | |
3328 | ||
7f3673f2 LC |
3329 | @item --with-source=@var{source} |
3330 | Use @var{source} as the source of the corresponding package. | |
3331 | @var{source} must be a file name or a URL, as for @command{guix | |
3332 | download} (@pxref{Invoking guix download}). | |
3333 | ||
3334 | The ``corresponding package'' is taken to be one specified on the | |
3335 | command line whose name matches the base of @var{source}---e.g., if | |
3336 | @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding | |
3337 | package is @code{guile}. Likewise, the version string is inferred from | |
3338 | @var{source}; in the previous example, it's @code{2.0.10}. | |
3339 | ||
3340 | This option allows users to try out versions of packages other than the | |
3341 | one provided by the distribution. The example below downloads | |
3342 | @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for | |
3343 | the @code{ed} package: | |
3344 | ||
3345 | @example | |
3346 | guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz | |
3347 | @end example | |
3348 | ||
3349 | As a developer, @code{--with-source} makes it easy to test release | |
3350 | candidates: | |
3351 | ||
3352 | @example | |
3353 | guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz | |
3354 | @end example | |
3355 | ||
05962f29 LC |
3356 | @item --no-grafts |
3357 | Do not ``graft'' packages. In practice, this means that package updates | |
3358 | available as grafts are not applied. @xref{Security Updates}, for more | |
3359 | information on grafts. | |
7f3673f2 | 3360 | |
c78bd12b LC |
3361 | @item --derivations |
3362 | @itemx -d | |
3363 | Return the derivation paths, not the output paths, of the given | |
3364 | packages. | |
3365 | ||
70ee5642 LC |
3366 | @item --root=@var{file} |
3367 | @itemx -r @var{file} | |
3368 | Make @var{file} a symlink to the result, and register it as a garbage | |
3369 | collector root. | |
3370 | ||
3371 | @item --log-file | |
3372 | Return the build log file names for the given | |
3373 | @var{package-or-derivation}s, or raise an error if build logs are | |
3374 | missing. | |
3375 | ||
3376 | This works regardless of how packages or derivations are specified. For | |
3377 | instance, the following invocations are equivalent: | |
3378 | ||
3379 | @example | |
3380 | guix build --log-file `guix build -d guile` | |
3381 | guix build --log-file `guix build guile` | |
3382 | guix build --log-file guile | |
3383 | guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)' | |
3384 | @end example | |
3385 | ||
3386 | ||
3387 | @end table | |
3388 | ||
3389 | @cindex common build options | |
3390 | In addition, a number of options that control the build process are | |
3391 | common to @command{guix build} and other commands that can spawn builds, | |
3392 | such as @command{guix package} or @command{guix archive}. These are the | |
3393 | following: | |
3394 | ||
3395 | @table @code | |
3396 | ||
300868ba LC |
3397 | @item --load-path=@var{directory} |
3398 | @itemx -L @var{directory} | |
3399 | Add @var{directory} to the front of the package module search path | |
3400 | (@pxref{Package Modules}). | |
3401 | ||
3402 | This allows users to define their own packages and make them visible to | |
3403 | the command-line tools. | |
3404 | ||
c78bd12b LC |
3405 | @item --keep-failed |
3406 | @itemx -K | |
3407 | Keep the build tree of failed builds. Thus, if a build fail, its build | |
3408 | tree is kept under @file{/tmp}, in a directory whose name is shown at | |
3409 | the end of the build log. This is useful when debugging build issues. | |
3410 | ||
3411 | @item --dry-run | |
3412 | @itemx -n | |
3413 | Do not build the derivations. | |
3414 | ||
56b1f4b7 LC |
3415 | @item --fallback |
3416 | When substituting a pre-built binary fails, fall back to building | |
3417 | packages locally. | |
3418 | ||
c78bd12b | 3419 | @item --no-substitutes |
b5385b52 | 3420 | Do not use substitutes for build products. That is, always build things |
c4202d60 LC |
3421 | locally instead of allowing downloads of pre-built binaries |
3422 | (@pxref{Substitutes}). | |
c78bd12b | 3423 | |
425b0bfc | 3424 | @item --no-build-hook |
4ec2e92d LC |
3425 | Do not attempt to offload builds @i{via} the daemon's ``build hook'' |
3426 | (@pxref{Daemon Offload Setup}). That is, always build things locally | |
3427 | instead of offloading builds to remote machines. | |
425b0bfc | 3428 | |
969e678e LC |
3429 | @item --max-silent-time=@var{seconds} |
3430 | When the build or substitution process remains silent for more than | |
3431 | @var{seconds}, terminate it and report a build failure. | |
3432 | ||
002622b6 LC |
3433 | @item --timeout=@var{seconds} |
3434 | Likewise, when the build or substitution process lasts for more than | |
3435 | @var{seconds}, terminate it and report a build failure. | |
3436 | ||
3437 | By default there is no timeout. This behavior can be restored with | |
3438 | @code{--timeout=0}. | |
3439 | ||
07ab4bf1 LC |
3440 | @item --verbosity=@var{level} |
3441 | Use the given verbosity level. @var{level} must be an integer between 0 | |
3442 | and 5; higher means more verbose output. Setting a level of 4 or more | |
3443 | may be helpful when debugging setup issues with the build daemon. | |
3444 | ||
70ee5642 LC |
3445 | @item --cores=@var{n} |
3446 | @itemx -c @var{n} | |
3447 | Allow the use of up to @var{n} CPU cores for the build. The special | |
3448 | value @code{0} means to use as many CPU cores as available. | |
bf421152 | 3449 | |
f6526eb3 LC |
3450 | @item --max-jobs=@var{n} |
3451 | @itemx -M @var{n} | |
3452 | Allow at most @var{n} build jobs in parallel. @xref{Invoking | |
3453 | guix-daemon, @code{--max-jobs}}, for details about this option and the | |
3454 | equivalent @command{guix-daemon} option. | |
3455 | ||
c78bd12b LC |
3456 | @end table |
3457 | ||
e49951eb | 3458 | Behind the scenes, @command{guix build} is essentially an interface to |
c78bd12b LC |
3459 | the @code{package-derivation} procedure of the @code{(guix packages)} |
3460 | module, and to the @code{build-derivations} procedure of the @code{(guix | |
01d8ac64 | 3461 | derivations)} module. |
c78bd12b | 3462 | |
16eb115e DP |
3463 | In addition to options explicitly passed on the command line, |
3464 | @command{guix build} and other @command{guix} commands that support | |
3465 | building honor the @code{GUIX_BUILD_OPTIONS} environment variable. | |
3466 | ||
3467 | @defvr {Environment Variable} GUIX_BUILD_OPTIONS | |
3468 | Users can define this variable to a list of command line options that | |
3469 | will automatically be used by @command{guix build} and other | |
3470 | @command{guix} commands that can perform builds, as in the example | |
3471 | below: | |
3472 | ||
3473 | @example | |
3474 | $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar" | |
3475 | @end example | |
3476 | ||
847391fe DP |
3477 | These options are parsed independently, and the result is appended to |
3478 | the parsed command-line options. | |
16eb115e DP |
3479 | @end defvr |
3480 | ||
3481 | ||
210cc920 LC |
3482 | @node Invoking guix download |
3483 | @section Invoking @command{guix download} | |
3484 | ||
3485 | When writing a package definition, developers typically need to download | |
3486 | the package's source tarball, compute its SHA256 hash, and write that | |
3487 | hash in the package definition (@pxref{Defining Packages}). The | |
3488 | @command{guix download} tool helps with this task: it downloads a file | |
3489 | from the given URI, adds it to the store, and prints both its file name | |
3490 | in the store and its SHA256 hash. | |
3491 | ||
3492 | The fact that the downloaded file is added to the store saves bandwidth: | |
3493 | when the developer eventually tries to build the newly defined package | |
3494 | with @command{guix build}, the source tarball will not have to be | |
3495 | downloaded again because it is already in the store. It is also a | |
3496 | convenient way to temporarily stash files, which may be deleted | |
3497 | eventually (@pxref{Invoking guix gc}). | |
3498 | ||
3499 | The @command{guix download} command supports the same URIs as used in | |
3500 | package definitions. In particular, it supports @code{mirror://} URIs. | |
3501 | @code{https} URIs (HTTP over TLS) are supported @emph{provided} the | |
3502 | Guile bindings for GnuTLS are available in the user's environment; when | |
537c8bb3 LC |
3503 | they are not available, an error is raised. @xref{Guile Preparations, |
3504 | how to install the GnuTLS bindings for Guile,, gnutls-guile, | |
3505 | GnuTLS-Guile}, for more information. | |
210cc920 LC |
3506 | |
3507 | The following option is available: | |
3508 | ||
3509 | @table @code | |
3510 | @item --format=@var{fmt} | |
3511 | @itemx -f @var{fmt} | |
3512 | Write the hash in the format specified by @var{fmt}. For more | |
081145cf | 3513 | information on the valid values for @var{fmt}, @pxref{Invoking guix hash}. |
210cc920 LC |
3514 | @end table |
3515 | ||
6c365eca NK |
3516 | @node Invoking guix hash |
3517 | @section Invoking @command{guix hash} | |
3518 | ||
210cc920 | 3519 | The @command{guix hash} command computes the SHA256 hash of a file. |
6c365eca NK |
3520 | It is primarily a convenience tool for anyone contributing to the |
3521 | distribution: it computes the cryptographic hash of a file, which can be | |
3522 | used in the definition of a package (@pxref{Defining Packages}). | |
3523 | ||
3524 | The general syntax is: | |
3525 | ||
3526 | @example | |
3527 | guix hash @var{option} @var{file} | |
3528 | @end example | |
3529 | ||
3530 | @command{guix hash} has the following option: | |
3531 | ||
3532 | @table @code | |
3533 | ||
3534 | @item --format=@var{fmt} | |
3535 | @itemx -f @var{fmt} | |
210cc920 | 3536 | Write the hash in the format specified by @var{fmt}. |
6c365eca NK |
3537 | |
3538 | Supported formats: @code{nix-base32}, @code{base32}, @code{base16} | |
3539 | (@code{hex} and @code{hexadecimal} can be used as well). | |
3540 | ||
3541 | If the @option{--format} option is not specified, @command{guix hash} | |
3542 | will output the hash in @code{nix-base32}. This representation is used | |
3543 | in the definitions of packages. | |
3544 | ||
3140f2df LC |
3545 | @item --recursive |
3546 | @itemx -r | |
3547 | Compute the hash on @var{file} recursively. | |
3548 | ||
3549 | In this case, the hash is computed on an archive containing @var{file}, | |
3550 | including its children if it is a directory. Some of @var{file}'s | |
3551 | meta-data is part of the archive; for instance, when @var{file} is a | |
3552 | regular file, the hash is different depending on whether @var{file} is | |
3553 | executable or not. Meta-data such as time stamps has no impact on the | |
3554 | hash (@pxref{Invoking guix archive}). | |
3555 | @c FIXME: Replace xref above with xref to an ``Archive'' section when | |
3556 | @c it exists. | |
3557 | ||
6c365eca NK |
3558 | @end table |
3559 | ||
2f7d2d91 LC |
3560 | @node Invoking guix import |
3561 | @section Invoking @command{guix import} | |
3562 | ||
3563 | @cindex importing packages | |
3564 | @cindex package import | |
3565 | @cindex package conversion | |
3566 | The @command{guix import} command is useful for people willing to add a | |
3567 | package to the distribution but who'd rather do as little work as | |
3568 | possible to get there---a legitimate demand. The command knows of a few | |
3569 | repositories from which it can ``import'' package meta-data. The result | |
3570 | is a package definition, or a template thereof, in the format we know | |
3571 | (@pxref{Defining Packages}). | |
3572 | ||
3573 | The general syntax is: | |
3574 | ||
3575 | @example | |
3576 | guix import @var{importer} @var{options}@dots{} | |
3577 | @end example | |
3578 | ||
3579 | @var{importer} specifies the source from which to import package | |
3580 | meta-data, and @var{options} specifies a package identifier and other | |
3581 | options specific to @var{importer}. Currently, the available | |
3582 | ``importers'' are: | |
3583 | ||
3584 | @table @code | |
3585 | @item gnu | |
3586 | Import meta-data for the given GNU package. This provides a template | |
3587 | for the latest version of that GNU package, including the hash of its | |
3588 | source tarball, and its canonical synopsis and description. | |
3589 | ||
3590 | Additional information such as the package's dependencies and its | |
3591 | license needs to be figured out manually. | |
3592 | ||
3593 | For example, the following command returns a package definition for | |
3594 | GNU@tie{}Hello: | |
3595 | ||
3596 | @example | |
3597 | guix import gnu hello | |
3598 | @end example | |
3599 | ||
3600 | Specific command-line options are: | |
3601 | ||
3602 | @table @code | |
3603 | @item --key-download=@var{policy} | |
3604 | As for @code{guix refresh}, specify the policy to handle missing OpenPGP | |
3605 | keys when verifying the package's signature. @xref{Invoking guix | |
3606 | refresh, @code{--key-download}}. | |
3607 | @end table | |
3608 | ||
3609 | @item pypi | |
3610 | @cindex pypi | |
3611 | Import meta-data from the @uref{https://pypi.python.org/, Python Package | |
3612 | Index}@footnote{This functionality requires Guile-JSON to be installed. | |
3613 | @xref{Requirements}.}. Information is taken from the JSON-formatted | |
3614 | description available at @code{pypi.python.org} and usually includes all | |
3615 | the relevant information, including package dependencies. | |
3616 | ||
3617 | The command below imports meta-data for the @code{itsdangerous} Python | |
3618 | package: | |
3619 | ||
3620 | @example | |
3621 | guix import pypi itsdangerous | |
3622 | @end example | |
3623 | ||
d45dc6da EB |
3624 | @item cpan |
3625 | @cindex CPAN | |
3626 | Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}. | |
3627 | Information is taken from the JSON-formatted meta-data provided through | |
3628 | @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most | |
66392e47 EB |
3629 | relevant information, such as module dependencies. License information |
3630 | should be checked closely. If Perl is available in the store, then the | |
3631 | @code{corelist} utility will be used to filter core modules out of the | |
3632 | list of dependencies. | |
d45dc6da EB |
3633 | |
3634 | The command command below imports meta-data for the @code{Acme::Boolean} | |
3635 | Perl module: | |
3636 | ||
3637 | @example | |
3638 | guix import cpan Acme::Boolean | |
3639 | @end example | |
3640 | ||
2f7d2d91 LC |
3641 | @item nix |
3642 | Import meta-data from a local copy of the source of the | |
3643 | @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This | |
3644 | relies on the @command{nix-instantiate} command of | |
3645 | @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are | |
3646 | typically written in a mixture of Nix-language and Bash code. This | |
3647 | command only imports the high-level package structure that is written in | |
3648 | the Nix language. It normally includes all the basic fields of a | |
3649 | package definition. | |
3650 | ||
3651 | When importing a GNU package, the synopsis and descriptions are replaced | |
3652 | by their canonical upstream variant. | |
3653 | ||
3654 | As an example, the command below imports the package definition of | |
3655 | LibreOffice (more precisely, it imports the definition of the package | |
3656 | bound to the @code{libreoffice} top-level attribute): | |
3657 | ||
3658 | @example | |
3659 | guix import nix ~/path/to/nixpkgs libreoffice | |
3660 | @end example | |
863af4e1 FB |
3661 | |
3662 | @item hackage | |
3663 | @cindex hackage | |
3664 | Import meta-data from Haskell community's central package archive | |
3665 | @uref{https://hackage.haskell.org/, Hackage}. Information is taken from | |
3666 | Cabal files and includes all the relevant information, including package | |
3667 | dependencies. | |
3668 | ||
3669 | Specific command-line options are: | |
3670 | ||
3671 | @table @code | |
3672 | @item --no-test-dependencies | |
3673 | @itemx -t | |
3674 | Do not include dependencies only required to run the test suite. | |
3675 | @end table | |
3676 | ||
3677 | The command below imports meta-data for the latest version of the | |
3678 | @code{HTTP} Haskell package without including test dependencies: | |
3679 | ||
3680 | @example | |
3681 | guix import hackage -t HTTP | |
3682 | @end example | |
3683 | ||
3684 | A specific package version may optionally be specified by following the | |
3685 | package name by a hyphen and a version number as in the following example: | |
3686 | ||
3687 | @example | |
3688 | guix import hackage mtl-2.1.3.1 | |
3689 | @end example | |
3690 | ||
3691 | Currently only indentation structured Cabal files are supported. | |
2f7d2d91 LC |
3692 | @end table |
3693 | ||
3694 | The structure of the @command{guix import} code is modular. It would be | |
3695 | useful to have more importers for other package formats, and your help | |
3696 | is welcome here (@pxref{Contributing}). | |
3697 | ||
37166310 LC |
3698 | @node Invoking guix refresh |
3699 | @section Invoking @command{guix refresh} | |
3700 | ||
3701 | The primary audience of the @command{guix refresh} command is developers | |
3702 | of the GNU software distribution. By default, it reports any packages | |
3703 | provided by the distribution that are outdated compared to the latest | |
3704 | upstream version, like this: | |
3705 | ||
3706 | @example | |
3707 | $ guix refresh | |
3708 | gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1 | |
3709 | gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0 | |
3710 | @end example | |
3711 | ||
3712 | It does so by browsing each package's FTP directory and determining the | |
3713 | highest version number of the source tarballs | |
3714 | therein@footnote{Currently, this only works for GNU packages.}. | |
3715 | ||
3716 | When passed @code{--update}, it modifies distribution source files to | |
3717 | update the version numbers and source tarball hashes of those packages' | |
3718 | recipes (@pxref{Defining Packages}). This is achieved by downloading | |
3719 | each package's latest source tarball and its associated OpenPGP | |
3720 | signature, authenticating the downloaded tarball against its signature | |
3721 | using @command{gpg}, and finally computing its hash. When the public | |
3722 | key used to sign the tarball is missing from the user's keyring, an | |
3723 | attempt is made to automatically retrieve it from a public key server; | |
3724 | when it's successful, the key is added to the user's keyring; otherwise, | |
3725 | @command{guix refresh} reports an error. | |
3726 | ||
3727 | The following options are supported: | |
3728 | ||
3729 | @table @code | |
3730 | ||
3731 | @item --update | |
3732 | @itemx -u | |
3733 | Update distribution source files (package recipes) in place. | |
081145cf | 3734 | @xref{Defining Packages}, for more information on package definitions. |
37166310 LC |
3735 | |
3736 | @item --select=[@var{subset}] | |
3737 | @itemx -s @var{subset} | |
3738 | Select all the packages in @var{subset}, one of @code{core} or | |
3739 | @code{non-core}. | |
3740 | ||
3741 | The @code{core} subset refers to all the packages at the core of the | |
3742 | distribution---i.e., packages that are used to build ``everything | |
3743 | else''. This includes GCC, libc, Binutils, Bash, etc. Usually, | |
3744 | changing one of these packages in the distribution entails a rebuild of | |
3745 | all the others. Thus, such updates are an inconvenience to users in | |
3746 | terms of build time or bandwidth used to achieve the upgrade. | |
3747 | ||
3748 | The @code{non-core} subset refers to the remaining packages. It is | |
3749 | typically useful in cases where an update of the core packages would be | |
3750 | inconvenient. | |
3751 | ||
3752 | @end table | |
3753 | ||
3754 | In addition, @command{guix refresh} can be passed one or more package | |
3755 | names, as in this example: | |
3756 | ||
3757 | @example | |
4b9b3cbb | 3758 | guix refresh -u emacs idutils gcc-4.8.4 |
37166310 LC |
3759 | @end example |
3760 | ||
3761 | @noindent | |
3762 | The command above specifically updates the @code{emacs} and | |
3763 | @code{idutils} packages. The @code{--select} option would have no | |
3764 | effect in this case. | |
3765 | ||
7d193ec3 EB |
3766 | When considering whether to upgrade a package, it is sometimes |
3767 | convenient to know which packages would be affected by the upgrade and | |
3768 | should be checked for compatibility. For this the following option may | |
3769 | be used when passing @command{guix refresh} one or more package names: | |
3770 | ||
3771 | @table @code | |
3772 | ||
3773 | @item --list-dependent | |
3774 | @itemx -l | |
3775 | List top-level dependent packages that would need to be rebuilt as a | |
3776 | result of upgrading one or more packages. | |
3777 | ||
3778 | @end table | |
3779 | ||
3780 | Be aware that the @code{--list-dependent} option only | |
3781 | @emph{approximates} the rebuilds that would be required as a result of | |
3782 | an upgrade. More rebuilds might be required under some circumstances. | |
3783 | ||
3784 | @example | |
7779ab61 LC |
3785 | $ guix refresh --list-dependent flex |
3786 | Building the following 120 packages would ensure 213 dependent packages are rebuilt: | |
3787 | hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{} | |
7d193ec3 EB |
3788 | @end example |
3789 | ||
3790 | The command above lists a set of packages that could be built to check | |
3791 | for compatibility with an upgraded @code{flex} package. | |
3792 | ||
f9230085 LC |
3793 | The following options can be used to customize GnuPG operation: |
3794 | ||
3795 | @table @code | |
3796 | ||
f9230085 LC |
3797 | @item --gpg=@var{command} |
3798 | Use @var{command} as the GnuPG 2.x command. @var{command} is searched | |
3799 | for in @code{$PATH}. | |
3800 | ||
2bc53ba9 LC |
3801 | @item --key-download=@var{policy} |
3802 | Handle missing OpenPGP keys according to @var{policy}, which may be one | |
3803 | of: | |
3804 | ||
3805 | @table @code | |
3806 | @item always | |
3807 | Always download missing OpenPGP keys from the key server, and add them | |
3808 | to the user's GnuPG keyring. | |
3809 | ||
3810 | @item never | |
3811 | Never try to download missing OpenPGP keys. Instead just bail out. | |
3812 | ||
3813 | @item interactive | |
3814 | When a package signed with an unknown OpenPGP key is encountered, ask | |
3815 | the user whether to download it or not. This is the default behavior. | |
3816 | @end table | |
3817 | ||
3818 | @item --key-server=@var{host} | |
3819 | Use @var{host} as the OpenPGP key server when importing a public key. | |
3820 | ||
f9230085 LC |
3821 | @end table |
3822 | ||
b4f5e0e8 CR |
3823 | @node Invoking guix lint |
3824 | @section Invoking @command{guix lint} | |
3825 | The @command{guix lint} is meant to help package developers avoid common | |
873c4085 LC |
3826 | errors and use a consistent style. It runs a number of checks on a |
3827 | given set of packages in order to find common mistakes in their | |
3828 | definitions. Available @dfn{checkers} include (see | |
3829 | @code{--list-checkers} for a complete list): | |
3830 | ||
3831 | @table @code | |
3832 | @item synopsis | |
3833 | @itemx description | |
3834 | Validate certain typographical and stylistic rules about package | |
3835 | descriptions and synopses. | |
3836 | ||
3837 | @item inputs-should-be-native | |
3838 | Identify inputs that should most likely be native inputs. | |
3839 | ||
3840 | @item source | |
3841 | @itemx home-page | |
3842 | Probe @code{home-page} and @code{source} URLs and report those that are | |
3843 | invalid. | |
3844 | @end table | |
b4f5e0e8 CR |
3845 | |
3846 | The general syntax is: | |
3847 | ||
3848 | @example | |
3849 | guix lint @var{options} @var{package}@dots{} | |
3850 | @end example | |
3851 | ||
3852 | If no package is given on the command line, then all packages are checked. | |
3853 | The @var{options} may be zero or more of the following: | |
3854 | ||
3855 | @table @code | |
3856 | ||
dd7c013d CR |
3857 | @item --checkers |
3858 | @itemx -c | |
3859 | Only enable the checkers specified in a comma-separated list using the | |
3860 | names returned by @code{--list-checkers}. | |
3861 | ||
b4f5e0e8 CR |
3862 | @item --list-checkers |
3863 | @itemx -l | |
3864 | List and describe all the available checkers that will be run on packages | |
3865 | and exit. | |
3866 | ||
3867 | @end table | |
37166310 | 3868 | |
372c4bbc DT |
3869 | @node Invoking guix environment |
3870 | @section Invoking @command{guix environment} | |
3871 | ||
f5fd4fd2 | 3872 | @cindex reproducible build environments |
372c4bbc DT |
3873 | The purpose of @command{guix environment} is to assist hackers in |
3874 | creating reproducible development environments without polluting their | |
3875 | package profile. The @command{guix environment} tool takes one or more | |
3876 | packages, builds all of the necessary inputs, and creates a shell | |
3877 | environment to use them. | |
3878 | ||
3879 | The general syntax is: | |
3880 | ||
3881 | @example | |
3882 | guix environment @var{options} @var{package}@dots{} | |
3883 | @end example | |
3884 | ||
3885 | The following examples spawns a new shell that is capable of building | |
3886 | the GNU Guile source code: | |
3887 | ||
3888 | @example | |
3889 | guix environment guile | |
3890 | @end example | |
3891 | ||
3892 | If the specified packages are not built yet, @command{guix environment} | |
3893 | automatically builds them. The new shell's environment is an augmented | |
3894 | version of the environment that @command{guix environment} was run in. | |
3895 | It contains the necessary search paths for building the given package | |
3896 | added to the existing environment variables. To create a ``pure'' | |
3897 | environment in which the original environment variables have been unset, | |
3898 | use the @code{--pure} option. | |
3899 | ||
3900 | Additionally, more than one package may be specified, in which case the | |
3901 | union of the inputs for the given packages are used. For example, the | |
3902 | command below spawns a shell where all of the dependencies of both Guile | |
3903 | and Emacs are available: | |
3904 | ||
3905 | @example | |
3906 | guix environment guile emacs | |
3907 | @end example | |
3908 | ||
3909 | Sometimes an interactive shell session is not desired. The | |
3910 | @code{--exec} option can be used to specify the command to run instead. | |
3911 | ||
3912 | @example | |
3913 | guix environment guile --exec=make | |
3914 | @end example | |
3915 | ||
3916 | The following options are available: | |
3917 | ||
3918 | @table @code | |
3919 | @item --expression=@var{expr} | |
3920 | @itemx -e @var{expr} | |
3921 | Create an environment for the package that @var{expr} evaluates to. | |
3922 | ||
3923 | @item --load=@var{file} | |
3924 | @itemx -l @var{file} | |
3925 | Create an environment for the package that the code within @var{file} | |
3926 | evaluates to. | |
3927 | ||
3928 | @item --exec=@var{command} | |
3929 | @item -E @var{command} | |
3930 | Execute @var{command} in the new environment. | |
3931 | ||
3932 | @item --pure | |
3933 | Unset existing environment variables when building the new environment. | |
3934 | This has the effect of creating an environment in which search paths | |
3935 | only contain package inputs. | |
3936 | ||
3937 | @item --search-paths | |
3938 | Display the environment variable definitions that make up the | |
3939 | environment. | |
3940 | @end table | |
3941 | ||
3942 | It also supports all of the common build options that @command{guix | |
3943 | build} supports (@pxref{Invoking guix build, common build options}). | |
3944 | ||
aff8ce7c DT |
3945 | @node Invoking guix publish |
3946 | @section Invoking @command{guix publish} | |
3947 | ||
3948 | The purpose of @command{guix publish} is to enable users to easily share | |
8ce229fc LC |
3949 | their store with others, which can then use it as a substitute server |
3950 | (@pxref{Substitutes}). | |
3951 | ||
3952 | When @command{guix publish} runs, it spawns an HTTP server which allows | |
3953 | anyone with network access to obtain substitutes from it. This means | |
3954 | that any machine running Guix can also act as if it were a build farm, | |
3955 | since the HTTP interface is compatible with Hydra, the software behind | |
3956 | the @code{hydra.gnu.org} build farm. | |
aff8ce7c DT |
3957 | |
3958 | For security, each substitute is signed, allowing recipients to check | |
3959 | their authenticity and integrity (@pxref{Substitutes}). Because | |
3960 | @command{guix publish} uses the system's signing key, which is only | |
5463fe51 LC |
3961 | readable by the system administrator, it must be started as root; the |
3962 | @code{--user} option makes it drop root privileges early on. | |
aff8ce7c DT |
3963 | |
3964 | The general syntax is: | |
3965 | ||
3966 | @example | |
3967 | guix publish @var{options}@dots{} | |
3968 | @end example | |
3969 | ||
3970 | Running @command{guix publish} without any additional arguments will | |
3971 | spawn an HTTP server on port 8080: | |
3972 | ||
3973 | @example | |
3974 | guix publish | |
3975 | @end example | |
3976 | ||
3977 | Once a publishing server has been authorized (@pxref{Invoking guix | |
3978 | archive}), the daemon may download substitutes from it: | |
3979 | ||
3980 | @example | |
3981 | guix-daemon --substitute-urls=http://example.org:8080 | |
3982 | @end example | |
3983 | ||
3984 | The following options are available: | |
3985 | ||
3986 | @table @code | |
3987 | @item --port=@var{port} | |
3988 | @itemx -p @var{port} | |
3989 | Listen for HTTP requests on @var{port}. | |
3990 | ||
9e2292ef LC |
3991 | @item --listen=@var{host} |
3992 | Listen on the network interface for @var{host}. The default is to | |
3993 | accept connections from any interface. | |
3994 | ||
5463fe51 LC |
3995 | @item --user=@var{user} |
3996 | @itemx -u @var{user} | |
3997 | Change privileges to @var{user} as soon as possible---i.e., once the | |
3998 | server socket is open and the signing key has been read. | |
3999 | ||
aff8ce7c DT |
4000 | @item --repl[=@var{port}] |
4001 | @itemx -r [@var{port}] | |
4002 | Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile | |
8ce229fc LC |
4003 | Reference Manual}) on @var{port} (37146 by default). This is used |
4004 | primarily for debugging a running @command{guix publish} server. | |
aff8ce7c DT |
4005 | @end table |
4006 | ||
a1ba8475 LC |
4007 | @c ********************************************************************* |
4008 | @node GNU Distribution | |
4009 | @chapter GNU Distribution | |
4010 | ||
3ca2731c | 4011 | @cindex Guix System Distribution |
4705641f | 4012 | @cindex GuixSD |
3ca2731c LC |
4013 | Guix comes with a distribution of the GNU system consisting entirely of |
4014 | free software@footnote{The term ``free'' here refers to the | |
a1ba8475 | 4015 | @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to |
3ca2731c | 4016 | users of that software}.}. The |
35ed9306 LC |
4017 | distribution can be installed on its own (@pxref{System Installation}), |
4018 | but it is also possible to install Guix as a package manager on top of | |
4019 | an installed GNU/Linux system (@pxref{Installation}). To distinguish | |
3ca2731c | 4020 | between the two, we refer to the standalone distribution as the Guix |
4705641f | 4021 | System Distribution, or GuixSD. |
35ed9306 LC |
4022 | |
4023 | The distribution provides core GNU packages such as GNU libc, GCC, and | |
4024 | Binutils, as well as many GNU and non-GNU applications. The complete | |
4025 | list of available packages can be browsed | |
d03bb653 LC |
4026 | @url{http://www.gnu.org/software/guix/package-list.html,on-line} or by |
4027 | running @command{guix package} (@pxref{Invoking guix package}): | |
a1ba8475 LC |
4028 | |
4029 | @example | |
e49951eb | 4030 | guix package --list-available |
a1ba8475 LC |
4031 | @end example |
4032 | ||
35ed9306 | 4033 | Our goal has been to provide a practical 100% free software distribution of |
401c53c4 LC |
4034 | Linux-based and other variants of GNU, with a focus on the promotion and |
4035 | tight integration of GNU components, and an emphasis on programs and | |
4036 | tools that help users exert that freedom. | |
4037 | ||
3ca2731c | 4038 | Packages are currently available on the following platforms: |
c320011d LC |
4039 | |
4040 | @table @code | |
4041 | ||
4042 | @item x86_64-linux | |
4043 | Intel/AMD @code{x86_64} architecture, Linux-Libre kernel; | |
4044 | ||
4045 | @item i686-linux | |
4046 | Intel 32-bit architecture (IA32), Linux-Libre kernel; | |
4047 | ||
aa1e1947 MW |
4048 | @item armhf-linux |
4049 | ARMv7-A architecture with hard float, Thumb-2 and VFP3D16 coprocessor, | |
4050 | using the EABI hard-float ABI, and Linux-Libre kernel. | |
4051 | ||
c320011d LC |
4052 | @item mips64el-linux |
4053 | little-endian 64-bit MIPS processors, specifically the Loongson series, | |
4054 | n32 application binary interface (ABI), and Linux-Libre kernel. | |
4055 | ||
4056 | @end table | |
4057 | ||
4705641f | 4058 | GuixSD itself is currently only available on @code{i686} and @code{x86_64}. |
3ca2731c | 4059 | |
c320011d LC |
4060 | @noindent |
4061 | For information on porting to other architectures or kernels, | |
4062 | @xref{Porting}. | |
4063 | ||
401c53c4 | 4064 | @menu |
5af6de3e | 4065 | * System Installation:: Installing the whole operating system. |
35ed9306 | 4066 | * System Configuration:: Configuring the operating system. |
91ef73d4 | 4067 | * Installing Debugging Files:: Feeding the debugger. |
05962f29 | 4068 | * Security Updates:: Deploying security fixes quickly. |
401c53c4 | 4069 | * Package Modules:: Packages from the programmer's viewpoint. |
da7cabd4 | 4070 | * Packaging Guidelines:: Growing the distribution. |
401c53c4 | 4071 | * Bootstrapping:: GNU/Linux built from scratch. |
8b315a6d | 4072 | * Porting:: Targeting another platform or kernel. |
401c53c4 LC |
4073 | @end menu |
4074 | ||
4075 | Building this distribution is a cooperative effort, and you are invited | |
081145cf | 4076 | to join! @xref{Contributing}, for information about how you can help. |
401c53c4 | 4077 | |
5af6de3e LC |
4078 | @node System Installation |
4079 | @section System Installation | |
4080 | ||
3ca2731c LC |
4081 | @cindex Guix System Distribution |
4082 | This section explains how to install the Guix System Distribution | |
4083 | on a machine. The Guix package manager can | |
35ed9306 LC |
4084 | also be installed on top of a running GNU/Linux system, |
4085 | @pxref{Installation}. | |
5af6de3e LC |
4086 | |
4087 | @ifinfo | |
4088 | @c This paragraph is for people reading this from tty2 of the | |
4089 | @c installation image. | |
4090 | You're reading this documentation with an Info reader. For details on | |
4091 | how to use it, hit the @key{RET} key (``return'' or ``enter'') on the | |
6621cdb6 | 4092 | link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit |
5af6de3e LC |
4093 | @kbd{l} afterwards to come back here. |
4094 | @end ifinfo | |
4095 | ||
8aaaae38 LC |
4096 | @subsection Limitations |
4097 | ||
4705641f | 4098 | As of version @value{VERSION}, the Guix System Distribution (GuixSD) is |
3ca2731c | 4099 | not production-ready. It may contain bugs and lack important |
8aaaae38 LC |
4100 | features. Thus, if you are looking for a stable production system that |
4101 | respects your freedom as a computer user, a good solution at this point | |
4102 | is to consider @url{http://www.gnu.org/distros/free-distros.html, one of | |
4103 | more established GNU/Linux distributions}. We hope you can soon switch | |
4705641f | 4104 | to the GuixSD without fear, of course. In the meantime, you can |
8aaaae38 LC |
4105 | also keep using your distribution and try out the package manager on top |
4106 | of it (@pxref{Installation}). | |
4107 | ||
4108 | Before you proceed with the installation, be aware of the following | |
4109 | noteworthy limitations applicable to version @value{VERSION}: | |
4110 | ||
4111 | @itemize | |
4112 | @item | |
4113 | The installation process does not include a graphical user interface and | |
4114 | requires familiarity with GNU/Linux (see the following subsections to | |
4115 | get a feel of what that means.) | |
4116 | ||
4117 | @item | |
b1e95eca LC |
4118 | The system does not yet provide GNOME and KDE; it provides Xfce, though, |
4119 | if graphical desktop environments are your thing. | |
8aaaae38 LC |
4120 | |
4121 | @item | |
dbcb0ab1 | 4122 | Support for the Logical Volume Manager (LVM) is missing. |
8aaaae38 LC |
4123 | |
4124 | @item | |
4125 | Few system services are currently supported out-of-the-box | |
4126 | (@pxref{Services}). | |
4127 | ||
4128 | @item | |
49607566 | 4129 | On the order of 1,900 packages are available, which means that you may |
8aaaae38 LC |
4130 | occasionally find that a useful package is missing. |
4131 | @end itemize | |
4132 | ||
4133 | You've been warned. But more than a disclaimer, this is an invitation | |
4134 | to report issues (and success stories!), and join us in improving it. | |
4135 | @xref{Contributing}, for more info. | |
5af6de3e LC |
4136 | |
4137 | @subsection USB Stick Installation | |
4138 | ||
4139 | An installation image for USB sticks can be downloaded from | |
4705641f | 4140 | @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz}, |
5af6de3e LC |
4141 | where @var{system} is one of: |
4142 | ||
4143 | @table @code | |
4144 | @item x86_64-linux | |
4145 | for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs; | |
4146 | ||
4147 | @item i686-linux | |
4148 | for a 32-bit GNU/Linux system on Intel-compatible CPUs. | |
4149 | @end table | |
4150 | ||
4151 | This image contains a single partition with the tools necessary for an | |
4152 | installation. It is meant to be copied @emph{as is} to a large-enough | |
4153 | USB stick. | |
4154 | ||
4155 | To copy the image to a USB stick, follow these steps: | |
4156 | ||
4157 | @enumerate | |
4158 | @item | |
4159 | Decompress the image using the @command{xz} command: | |
4160 | ||
4161 | @example | |
4705641f | 4162 | xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz |
5af6de3e LC |
4163 | @end example |
4164 | ||
4165 | @item | |
4166 | Insert a USB stick of 1@tie{}GiB or more in your machine, and determine | |
4167 | its device name. Assuming that USB stick is known as @file{/dev/sdX}, | |
4168 | copy the image with: | |
4169 | ||
4170 | @example | |
4705641f | 4171 | dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX |
5af6de3e LC |
4172 | @end example |
4173 | ||
4174 | Access to @file{/dev/sdX} usually requires root privileges. | |
4175 | @end enumerate | |
4176 | ||
4177 | Once this is done, you should be able to reboot the system and boot from | |
4178 | the USB stick. The latter usually requires you to get in the BIOS' boot | |
4179 | menu, where you can choose to boot from the USB stick. | |
4180 | ||
4181 | @subsection Preparing for Installation | |
4182 | ||
4183 | Once you have successfully booted the image on the USB stick, you should | |
4184 | end up with a root prompt. Several console TTYs are configured and can | |
4185 | be used to run commands as root. TTY2 shows this documentation, | |
4186 | browsable using the Info reader commands (@pxref{Help,,, info, Info: An | |
4187 | Introduction}). | |
4188 | ||
4189 | To install the system, you would: | |
4190 | ||
4191 | @enumerate | |
4192 | ||
4193 | @item | |
152dd61c LC |
4194 | Configure the network, by running @command{ifconfig eno1 up && dhclient |
4195 | eno1} (to get an automatically assigned IP address from the wired | |
4196 | network interface controller@footnote{ | |
95c559c1 LC |
4197 | @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20 |
4198 | The name @code{eno1} is for the first on-board Ethernet controller. The | |
4199 | interface name for an Ethernet controller that is in the first slot of | |
4200 | the first PCI bus, for instance, would be @code{enp1s0}. Use | |
4201 | @command{ifconfig -a} to list all the available network interfaces.}), | |
4202 | or using the @command{ifconfig} command. | |
5af6de3e LC |
4203 | |
4204 | The system automatically loads drivers for your network interface | |
4205 | controllers. | |
4206 | ||
4207 | Setting up network access is almost always a requirement because the | |
4208 | image does not contain all the software and tools that may be needed. | |
4209 | ||
4210 | @item | |
4211 | Unless this has already been done, you must partition and format the | |
4212 | target partitions. | |
4213 | ||
7ab44369 LC |
4214 | Preferably, assign partitions a label so that you can easily and |
4215 | reliably refer to them in @code{file-system} declarations (@pxref{File | |
4216 | Systems}). This is typically done using the @code{-L} option of | |
4217 | @command{mkfs.ext4} and related commands. | |
4218 | ||
5af6de3e | 4219 | The installation image includes Parted (@pxref{Overview,,, parted, GNU |
b419c7f5 LC |
4220 | Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk |
4221 | encryption, and e2fsprogs, the suite of tools to manipulate | |
4222 | ext2/ext3/ext4 file systems. | |
5af6de3e | 4223 | |
83a17b62 LC |
4224 | @item |
4225 | Once that is done, mount the target root partition under @file{/mnt}. | |
4226 | ||
4227 | @item | |
4228 | Lastly, run @code{deco start cow-store /mnt}. | |
4229 | ||
4230 | This will make @file{/gnu/store} copy-on-write, such that packages added | |
4231 | to it during the installation phase will be written to the target disk | |
4232 | rather than kept in memory. | |
4233 | ||
5af6de3e LC |
4234 | @end enumerate |
4235 | ||
5af6de3e LC |
4236 | |
4237 | @subsection Proceeding with the Installation | |
4238 | ||
4239 | With the target partitions ready, you now have to edit a file and | |
4240 | provide the declaration of the operating system to be installed. To | |
4241 | that end, the installation system comes with two text editors: GNU nano | |
4242 | (@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone. | |
4243 | It is better to store that file on the target root file system, say, as | |
4244 | @file{/mnt/etc/config.scm}. | |
4245 | ||
dd51caac LC |
4246 | @xref{Using the Configuration System}, for examples of operating system |
4247 | configurations. These examples are available under | |
4248 | @file{/etc/configuration} in the installation image, so you can copy | |
4249 | them and use them as a starting point for your own configuration. | |
5af6de3e | 4250 | |
dd51caac LC |
4251 | Once you are done preparing the configuration file, the new system must |
4252 | be initialized (remember that the target root file system is mounted | |
4253 | under @file{/mnt}): | |
5af6de3e LC |
4254 | |
4255 | @example | |
4256 | guix system init /mnt/etc/config.scm /mnt | |
4257 | @end example | |
4258 | ||
4259 | @noindent | |
4260 | This will copy all the necessary files, and install GRUB on | |
4261 | @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For | |
6621cdb6 | 4262 | more information, @pxref{Invoking guix system}. This command may trigger |
5af6de3e LC |
4263 | downloads or builds of missing packages, which can take some time. |
4264 | ||
4265 | Once that command has completed---and hopefully succeeded!---you can | |
ad14d9e7 | 4266 | run @command{reboot} and boot into the new system. Cross fingers, and |
5af6de3e LC |
4267 | join us on @code{#guix} on the Freenode IRC network or on |
4268 | @file{guix-devel@@gnu.org} to share your experience---good or not so | |
4269 | good. | |
4270 | ||
4271 | @subsection Building the Installation Image | |
4272 | ||
4273 | The installation image described above was built using the @command{guix | |
4274 | system} command, specifically: | |
4275 | ||
4276 | @example | |
8a225c66 | 4277 | guix system disk-image --image-size=850MiB gnu/system/install.scm |
5af6de3e LC |
4278 | @end example |
4279 | ||
4280 | @xref{Invoking guix system}, for more information. See | |
4281 | @file{gnu/system/install.scm} in the source tree for more information | |
4282 | about the installation image. | |
4283 | ||
cf4a9129 LC |
4284 | @node System Configuration |
4285 | @section System Configuration | |
b208a005 | 4286 | |
cf4a9129 | 4287 | @cindex system configuration |
3ca2731c | 4288 | The Guix System Distribution supports a consistent whole-system configuration |
cf4a9129 LC |
4289 | mechanism. By that we mean that all aspects of the global system |
4290 | configuration---such as the available system services, timezone and | |
4291 | locale settings, user accounts---are declared in a single place. Such | |
4292 | a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected. | |
91ef73d4 | 4293 | |
cf4a9129 LC |
4294 | One of the advantages of putting all the system configuration under the |
4295 | control of Guix is that it supports transactional system upgrades, and | |
4296 | makes it possible to roll-back to a previous system instantiation, | |
4297 | should something go wrong with the new one (@pxref{Features}). Another | |
4298 | one is that it makes it easy to replicate the exact same configuration | |
4299 | across different machines, or at different points in time, without | |
4300 | having to resort to additional administration tools layered on top of | |
4301 | the system's own tools. | |
4302 | @c Yes, we're talking of Puppet, Chef, & co. here. ↑ | |
91ef73d4 | 4303 | |
cf4a9129 LC |
4304 | This section describes this mechanism. First we focus on the system |
4305 | administrator's viewpoint---explaining how the system is configured and | |
4306 | instantiated. Then we show how this mechanism can be extended, for | |
4307 | instance to support new system services. | |
91ef73d4 | 4308 | |
cf4a9129 LC |
4309 | @menu |
4310 | * Using the Configuration System:: Customizing your GNU system. | |
7313a52e | 4311 | * operating-system Reference:: Detail of operating-system declarations. |
cf4a9129 | 4312 | * File Systems:: Configuring file system mounts. |
510f9d86 | 4313 | * Mapped Devices:: Block device extra processing. |
cf4a9129 | 4314 | * User Accounts:: Specifying user accounts. |
598e19dc | 4315 | * Locales:: Language and cultural convention settings. |
cf4a9129 | 4316 | * Services:: Specifying system services. |
0ae8c15a | 4317 | * Setuid Programs:: Programs running with root privileges. |
efb5e833 | 4318 | * X.509 Certificates:: Authenticating HTTPS servers. |
996ed739 | 4319 | * Name Service Switch:: Configuring libc's name service switch. |
fd1b1fa2 | 4320 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
88faf933 | 4321 | * GRUB Configuration:: Configuring the boot loader. |
cf4a9129 LC |
4322 | * Invoking guix system:: Instantiating a system configuration. |
4323 | * Defining Services:: Adding new service definitions. | |
4324 | @end menu | |
91ef73d4 | 4325 | |
cf4a9129 LC |
4326 | @node Using the Configuration System |
4327 | @subsection Using the Configuration System | |
64d76fa6 | 4328 | |
cf4a9129 LC |
4329 | The operating system is configured by providing an |
4330 | @code{operating-system} declaration in a file that can then be passed to | |
4331 | the @command{guix system} command (@pxref{Invoking guix system}). A | |
4332 | simple setup, with the default system services, the default Linux-Libre | |
4333 | kernel, initial RAM disk, and boot loader looks like this: | |
91ef73d4 | 4334 | |
cf4a9129 LC |
4335 | @findex operating-system |
4336 | @lisp | |
dd51caac | 4337 | @include os-config-bare-bones.texi |
cf4a9129 | 4338 | @end lisp |
401c53c4 | 4339 | |
cf4a9129 LC |
4340 | This example should be self-describing. Some of the fields defined |
4341 | above, such as @code{host-name} and @code{bootloader}, are mandatory. | |
4342 | Others, such as @code{packages} and @code{services}, can be omitted, in | |
4343 | which case they get a default value. | |
e7f34eb0 | 4344 | |
cf4a9129 LC |
4345 | @vindex %base-packages |
4346 | The @code{packages} field lists | |
4347 | packages that will be globally visible on the system, for all user | |
4348 | accounts---i.e., in every user's @code{PATH} environment variable---in | |
4349 | addition to the per-user profiles (@pxref{Invoking guix package}). The | |
4350 | @var{%base-packages} variable provides all the tools one would expect | |
4351 | for basic user and administrator tasks---including the GNU Core | |
4352 | Utilities, the GNU Networking Utilities, the GNU Zile lightweight text | |
4353 | editor, @command{find}, @command{grep}, etc. The example above adds | |
4354 | Emacs to those, taken from the @code{(gnu packages emacs)} module | |
4355 | (@pxref{Package Modules}). | |
e7f34eb0 | 4356 | |
cf4a9129 LC |
4357 | @vindex %base-services |
4358 | The @code{services} field lists @dfn{system services} to be made | |
4359 | available when the system starts (@pxref{Services}). | |
4360 | The @code{operating-system} declaration above specifies that, in | |
4361 | addition to the basic services, we want the @command{lshd} secure shell | |
4362 | daemon listening on port 2222, and allowing remote @code{root} logins | |
4363 | (@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood, | |
4364 | @code{lsh-service} arranges so that @code{lshd} is started with the | |
4365 | right command-line options, possibly with supporting configuration files | |
7313a52e LC |
4366 | generated as needed (@pxref{Defining Services}). @xref{operating-system |
4367 | Reference}, for details about the available @code{operating-system} | |
4368 | fields. | |
a1ba8475 | 4369 | |
dd51caac LC |
4370 | The configuration for a typical ``desktop'' usage, with the X11 display |
4371 | server, a desktop environment, network management, an SSH server, and | |
4372 | more, would look like this: | |
4373 | ||
4374 | @lisp | |
4375 | @include os-config-desktop.texi | |
4376 | @end lisp | |
4377 | ||
4378 | @xref{Desktop Services}, for the exact list of services provided by | |
efb5e833 LC |
4379 | @var{%desktop-services}. @xref{X.509 Certificates}, for background |
4380 | information about the @code{nss-certs} package that is used here. | |
dd51caac | 4381 | |
cf4a9129 LC |
4382 | Assuming the above snippet is stored in the @file{my-system-config.scm} |
4383 | file, the @command{guix system reconfigure my-system-config.scm} command | |
4384 | instantiates that configuration, and makes it the default GRUB boot | |
4385 | entry (@pxref{Invoking guix system}). The normal way to change the | |
4386 | system's configuration is by updating this file and re-running the | |
4387 | @command{guix system} command. | |
b81e1947 | 4388 | |
cf4a9129 LC |
4389 | At the Scheme level, the bulk of an @code{operating-system} declaration |
4390 | is instantiated with the following monadic procedure (@pxref{The Store | |
4391 | Monad}): | |
b81e1947 | 4392 | |
cf4a9129 LC |
4393 | @deffn {Monadic Procedure} operating-system-derivation os |
4394 | Return a derivation that builds @var{os}, an @code{operating-system} | |
4395 | object (@pxref{Derivations}). | |
b81e1947 | 4396 | |
cf4a9129 LC |
4397 | The output of the derivation is a single directory that refers to all |
4398 | the packages, configuration files, and other supporting files needed to | |
4399 | instantiate @var{os}. | |
4400 | @end deffn | |
b81e1947 | 4401 | |
7313a52e LC |
4402 | @node operating-system Reference |
4403 | @subsection @code{operating-system} Reference | |
4404 | ||
4405 | This section summarizes all the options available in | |
4406 | @code{operating-system} declarations (@pxref{Using the Configuration | |
4407 | System}). | |
4408 | ||
4409 | @deftp {Data Type} operating-system | |
4410 | This is the data type representing an operating system configuration. | |
4411 | By that, we mean all the global system configuration, not per-user | |
4412 | configuration (@pxref{Using the Configuration System}). | |
4413 | ||
4414 | @table @asis | |
4415 | @item @code{kernel} (default: @var{linux-libre}) | |
fbb25e56 | 4416 | The package object of the operating system kernel to use@footnote{Currently |
7313a52e LC |
4417 | only the Linux-libre kernel is supported. In the future, it will be |
4418 | possible to use the GNU@tie{}Hurd.}. | |
4419 | ||
4420 | @item @code{bootloader} | |
88faf933 | 4421 | The system bootloader configuration object. @xref{GRUB Configuration}. |
7313a52e LC |
4422 | |
4423 | @item @code{initrd} (default: @code{base-initrd}) | |
4424 | A two-argument monadic procedure that returns an initial RAM disk for | |
4425 | the Linux kernel. @xref{Initial RAM Disk}. | |
4426 | ||
f34c56be LC |
4427 | @item @code{firmware} (default: @var{%base-firmware}) |
4428 | @cindex firmware | |
4429 | List of firmware packages loadable by the operating system kernel. | |
4430 | ||
4431 | The default includes firmware needed for Atheros-based WiFi devices | |
4432 | (Linux-libre module @code{ath9k}.) | |
4433 | ||
7313a52e LC |
4434 | @item @code{host-name} |
4435 | The host name. | |
4436 | ||
4437 | @item @code{hosts-file} | |
4438 | @cindex hosts file | |
4439 | A zero-argument monadic procedure that returns a text file for use as | |
4440 | @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library | |
4441 | Reference Manual}). The default is to produce a file with entries for | |
4442 | @code{localhost} and @var{host-name}. | |
4443 | ||
4444 | @item @code{mapped-devices} (default: @code{'()}) | |
4445 | A list of mapped devices. @xref{Mapped Devices}. | |
4446 | ||
4447 | @item @code{file-systems} | |
4448 | A list of file systems. @xref{File Systems}. | |
4449 | ||
4450 | @item @code{swap-devices} (default: @code{'()}) | |
4451 | @cindex swap devices | |
4452 | A list of strings identifying devices to be used for ``swap space'' | |
4453 | (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}). | |
4454 | For example, @code{'("/dev/sda3")}. | |
4455 | ||
bf87f38a | 4456 | @item @code{users} (default: @code{%base-user-accounts}) |
7313a52e LC |
4457 | @itemx @code{groups} (default: @var{%base-groups}) |
4458 | List of user accounts and groups. @xref{User Accounts}. | |
4459 | ||
4460 | @item @code{skeletons} (default: @code{(default-skeletons)}) | |
4461 | A monadic list of pairs of target file name and files. These are the | |
4462 | files that will be used as skeletons as new accounts are created. | |
4463 | ||
4464 | For instance, a valid value may look like this: | |
4465 | ||
4466 | @example | |
4467 | (mlet %store-monad ((bashrc (text-file "bashrc" "\ | |
4468 | export PATH=$HOME/.guix-profile/bin"))) | |
4469 | (return `((".bashrc" ,bashrc)))) | |
4470 | @end example | |
4471 | ||
4472 | @item @code{issue} (default: @var{%default-issue}) | |
4473 | A string denoting the contents of the @file{/etc/issue} file, which is | |
4474 | what displayed when users log in on a text console. | |
4475 | ||
4476 | @item @code{packages} (default: @var{%base-packages}) | |
4477 | The set of packages installed in the global profile, which is accessible | |
4478 | at @file{/run/current-system/profile}. | |
4479 | ||
4480 | The default set includes core utilities, but it is good practice to | |
4481 | install non-core utilities in user profiles (@pxref{Invoking guix | |
4482 | package}). | |
4483 | ||
4484 | @item @code{timezone} | |
4485 | A timezone identifying string---e.g., @code{"Europe/Paris"}. | |
4486 | ||
598e19dc LC |
4487 | @item @code{locale} (default: @code{"en_US.utf8"}) |
4488 | The name of the default locale (@pxref{Locale Names,,, libc, The GNU C | |
4489 | Library Reference Manual}). @xref{Locales}, for more information. | |
4490 | ||
4491 | @item @code{locale-definitions} (default: @var{%default-locale-definitions}) | |
4492 | The list of locale definitions to be compiled and that may be used at | |
4493 | run time. @xref{Locales}. | |
7313a52e | 4494 | |
996ed739 LC |
4495 | @item @code{name-service-switch} (default: @var{%default-nss}) |
4496 | Configuration of libc's name service switch (NSS)---a | |
4497 | @code{<name-service-switch>} object. @xref{Name Service Switch}, for | |
4498 | details. | |
4499 | ||
7313a52e LC |
4500 | @item @code{services} (default: @var{%base-services}) |
4501 | A list of monadic values denoting system services. @xref{Services}. | |
4502 | ||
4503 | @item @code{pam-services} (default: @code{(base-pam-services)}) | |
4504 | @cindex PAM | |
4505 | @cindex pluggable authentication modules | |
4506 | Linux @dfn{pluggable authentication module} (PAM) services. | |
4507 | @c FIXME: Add xref to PAM services section. | |
4508 | ||
4509 | @item @code{setuid-programs} (default: @var{%setuid-programs}) | |
4510 | List of string-valued G-expressions denoting setuid programs. | |
4511 | @xref{Setuid Programs}. | |
4512 | ||
4513 | @item @code{sudoers} (default: @var{%sudoers-specification}) | |
4514 | @cindex sudoers | |
4515 | The contents of the @file{/etc/sudoers} file as a string. | |
4516 | ||
4517 | This file specifies which users can use the @command{sudo} command, what | |
4518 | they are allowed to do, and what privileges they may gain. The default | |
4519 | is that only @code{root} and members of the @code{wheel} group may use | |
4520 | @code{sudo}. | |
4521 | ||
4522 | @end table | |
4523 | @end deftp | |
4524 | ||
cf4a9129 LC |
4525 | @node File Systems |
4526 | @subsection File Systems | |
b81e1947 | 4527 | |
cf4a9129 LC |
4528 | The list of file systems to be mounted is specified in the |
4529 | @code{file-systems} field of the operating system's declaration | |
4530 | (@pxref{Using the Configuration System}). Each file system is declared | |
4531 | using the @code{file-system} form, like this: | |
b81e1947 LC |
4532 | |
4533 | @example | |
cf4a9129 LC |
4534 | (file-system |
4535 | (mount-point "/home") | |
4536 | (device "/dev/sda3") | |
4537 | (type "ext4")) | |
b81e1947 LC |
4538 | @end example |
4539 | ||
cf4a9129 LC |
4540 | As usual, some of the fields are mandatory---those shown in the example |
4541 | above---while others can be omitted. These are described below. | |
b81e1947 | 4542 | |
cf4a9129 LC |
4543 | @deftp {Data Type} file-system |
4544 | Objects of this type represent file systems to be mounted. They | |
4545 | contain the following members: | |
5ff3c4b8 | 4546 | |
cf4a9129 LC |
4547 | @table @asis |
4548 | @item @code{type} | |
4549 | This is a string specifying the type of the file system---e.g., | |
4550 | @code{"ext4"}. | |
5ff3c4b8 | 4551 | |
cf4a9129 LC |
4552 | @item @code{mount-point} |
4553 | This designates the place where the file system is to be mounted. | |
b81e1947 | 4554 | |
cf4a9129 LC |
4555 | @item @code{device} |
4556 | This names the ``source'' of the file system. By default it is the name | |
4557 | of a node under @file{/dev}, but its meaning depends on the @code{title} | |
4558 | field described below. | |
401c53c4 | 4559 | |
cf4a9129 LC |
4560 | @item @code{title} (default: @code{'device}) |
4561 | This is a symbol that specifies how the @code{device} field is to be | |
4562 | interpreted. | |
401c53c4 | 4563 | |
cf4a9129 LC |
4564 | When it is the symbol @code{device}, then the @code{device} field is |
4565 | interpreted as a file name; when it is @code{label}, then @code{device} | |
4566 | is interpreted as a partition label name; when it is @code{uuid}, | |
4567 | @code{device} is interpreted as a partition unique identifier (UUID). | |
da7cabd4 | 4568 | |
cf4a9129 LC |
4569 | The @code{label} and @code{uuid} options offer a way to refer to disk |
4570 | partitions without having to hard-code their actual device name. | |
da7cabd4 | 4571 | |
5f86a66e LC |
4572 | However, when a file system's source is a mapped device (@pxref{Mapped |
4573 | Devices}), its @code{device} field @emph{must} refer to the mapped | |
4574 | device name---e.g., @file{/dev/mapper/root-partition}---and consequently | |
4575 | @code{title} must be set to @code{'device}. This is required so that | |
4576 | the system knows that mounting the file system depends on having the | |
4577 | corresponding device mapping established. | |
4578 | ||
cf4a9129 LC |
4579 | @item @code{flags} (default: @code{'()}) |
4580 | This is a list of symbols denoting mount flags. Recognized flags | |
2c071ce9 LC |
4581 | include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow |
4582 | access to special files), @code{no-suid} (ignore setuid and setgid | |
4583 | bits), and @code{no-exec} (disallow program execution.) | |
da7cabd4 | 4584 | |
cf4a9129 LC |
4585 | @item @code{options} (default: @code{#f}) |
4586 | This is either @code{#f}, or a string denoting mount options. | |
da7cabd4 | 4587 | |
cf4a9129 LC |
4588 | @item @code{needed-for-boot?} (default: @code{#f}) |
4589 | This Boolean value indicates whether the file system is needed when | |
4590 | booting. If that is true, then the file system is mounted when the | |
4591 | initial RAM disk (initrd) is loaded. This is always the case, for | |
4592 | instance, for the root file system. | |
da7cabd4 | 4593 | |
cf4a9129 LC |
4594 | @item @code{check?} (default: @code{#t}) |
4595 | This Boolean indicates whether the file system needs to be checked for | |
4596 | errors before being mounted. | |
f9cc8971 | 4597 | |
4e469051 LC |
4598 | @item @code{create-mount-point?} (default: @code{#f}) |
4599 | When true, the mount point is created if it does not exist yet. | |
4600 | ||
cf4a9129 LC |
4601 | @end table |
4602 | @end deftp | |
da7cabd4 | 4603 | |
a69576ea LC |
4604 | The @code{(gnu system file-systems)} exports the following useful |
4605 | variables. | |
4606 | ||
4607 | @defvr {Scheme Variable} %base-file-systems | |
4608 | These are essential file systems that are required on normal systems, | |
3392ce5d LC |
4609 | such as @var{%devtmpfs-file-system} and @var{%immutable-store} (see |
4610 | below.) Operating system declarations should always contain at least | |
4611 | these. | |
a69576ea LC |
4612 | @end defvr |
4613 | ||
4614 | @defvr {Scheme Variable} %devtmpfs-file-system | |
4615 | The @code{devtmpfs} file system to be mounted on @file{/dev}. This is a | |
4616 | requirement for udev (@pxref{Base Services, @code{udev-service}}). | |
4617 | @end defvr | |
4618 | ||
7f239fd3 LC |
4619 | @defvr {Scheme Variable} %pseudo-terminal-file-system |
4620 | This is the file system to be mounted as @file{/dev/pts}. It supports | |
4621 | @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar | |
4622 | functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference | |
4623 | Manual}). Pseudo-terminals are used by terminal emulators such as | |
4624 | @command{xterm}. | |
4625 | @end defvr | |
4626 | ||
db17ae5c LC |
4627 | @defvr {Scheme Variable} %shared-memory-file-system |
4628 | This file system is mounted as @file{/dev/shm} and is used to support | |
4629 | memory sharing across processes (@pxref{Memory-mapped I/O, | |
4630 | @code{shm_open},, libc, The GNU C Library Reference Manual}). | |
4631 | @end defvr | |
4632 | ||
3392ce5d LC |
4633 | @defvr {Scheme Variable} %immutable-store |
4634 | This file system performs a read-only ``bind mount'' of | |
4635 | @file{/gnu/store}, making it read-only for all the users including | |
4636 | @code{root}. This prevents against accidental modification by software | |
4637 | running as @code{root} or by system administrators. | |
4638 | ||
4639 | The daemon itself is still able to write to the store: it remounts it | |
4640 | read-write in its own ``name space.'' | |
4641 | @end defvr | |
4642 | ||
a69576ea LC |
4643 | @defvr {Scheme Variable} %binary-format-file-system |
4644 | The @code{binfmt_misc} file system, which allows handling of arbitrary | |
4645 | executable file types to be delegated to user space. This requires the | |
4646 | @code{binfmt.ko} kernel module to be loaded. | |
4647 | @end defvr | |
4648 | ||
4649 | @defvr {Scheme Variable} %fuse-control-file-system | |
4650 | The @code{fusectl} file system, which allows unprivileged users to mount | |
4651 | and unmount user-space FUSE file systems. This requires the | |
4652 | @code{fuse.ko} kernel module to be loaded. | |
4653 | @end defvr | |
4654 | ||
510f9d86 LC |
4655 | @node Mapped Devices |
4656 | @subsection Mapped Devices | |
4657 | ||
4658 | @cindex device mapping | |
4659 | @cindex mapped devices | |
4660 | The Linux kernel has a notion of @dfn{device mapping}: a block device, | |
4661 | such as a hard disk partition, can be @dfn{mapped} into another device, | |
4662 | with additional processing over the data that flows through | |
4663 | it@footnote{Note that the GNU@tie{}Hurd makes no difference between the | |
4664 | concept of a ``mapped device'' and that of a file system: both boil down | |
4665 | to @emph{translating} input/output operations made on a file to | |
4666 | operations on its backing store. Thus, the Hurd implements mapped | |
4667 | devices, like file systems, using the generic @dfn{translator} mechanism | |
4668 | (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A | |
4669 | typical example is encryption device mapping: all writes to the mapped | |
4670 | device are encrypted, and all reads are deciphered, transparently. | |
4671 | ||
4672 | Mapped devices are declared using the @code{mapped-device} form: | |
4673 | ||
4674 | @example | |
4675 | (mapped-device | |
4676 | (source "/dev/sda3") | |
4677 | (target "home") | |
4678 | (type luks-device-mapping)) | |
4679 | @end example | |
4680 | ||
4681 | @noindent | |
4682 | @cindex disk encryption | |
4683 | @cindex LUKS | |
4684 | This example specifies a mapping from @file{/dev/sda3} to | |
4685 | @file{/dev/mapper/home} using LUKS---the | |
4686 | @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a | |
4687 | standard mechanism for disk encryption. The @file{/dev/mapper/home} | |
4688 | device can then be used as the @code{device} of a @code{file-system} | |
4689 | declaration (@pxref{File Systems}). The @code{mapped-device} form is | |
4690 | detailed below. | |
4691 | ||
4692 | @deftp {Data Type} mapped-device | |
4693 | Objects of this type represent device mappings that will be made when | |
4694 | the system boots up. | |
4695 | ||
9cb426b8 LC |
4696 | @table @code |
4697 | @item source | |
510f9d86 LC |
4698 | This string specifies the name of the block device to be mapped, such as |
4699 | @code{"/dev/sda3"}. | |
4700 | ||
9cb426b8 | 4701 | @item target |
510f9d86 LC |
4702 | This string specifies the name of the mapping to be established. For |
4703 | example, specifying @code{"my-partition"} will lead to the creation of | |
4704 | the @code{"/dev/mapper/my-partition"} device. | |
4705 | ||
9cb426b8 | 4706 | @item type |
510f9d86 LC |
4707 | This must be a @code{mapped-device-kind} object, which specifies how |
4708 | @var{source} is mapped to @var{target}. | |
4709 | @end table | |
4710 | @end deftp | |
4711 | ||
4712 | @defvr {Scheme Variable} luks-device-mapping | |
4713 | This defines LUKS block device encryption using the @command{cryptsetup} | |
4714 | command, from the same-named package. This relies on the | |
4715 | @code{dm-crypt} Linux kernel module. | |
4716 | @end defvr | |
4717 | ||
cf4a9129 LC |
4718 | @node User Accounts |
4719 | @subsection User Accounts | |
ee85f3db | 4720 | |
9bea87a5 LC |
4721 | User accounts and groups are entirely managed through the |
4722 | @code{operating-system} declaration. They are specified with the | |
4723 | @code{user-account} and @code{user-group} forms: | |
ee85f3db | 4724 | |
cf4a9129 LC |
4725 | @example |
4726 | (user-account | |
4727 | (name "alice") | |
4728 | (group "users") | |
24e752c0 LC |
4729 | (supplementary-groups '("wheel" ;allow use of sudo, etc. |
4730 | "audio" ;sound card | |
4731 | "video" ;video devices such as webcams | |
4732 | "cdrom")) ;the good ol' CD-ROM | |
cf4a9129 LC |
4733 | (comment "Bob's sister") |
4734 | (home-directory "/home/alice")) | |
4735 | @end example | |
25083588 | 4736 | |
9bea87a5 LC |
4737 | When booting or upon completion of @command{guix system reconfigure}, |
4738 | the system ensures that only the user accounts and groups specified in | |
4739 | the @code{operating-system} declaration exist, and with the specified | |
4740 | properties. Thus, account or group creations or modifications made by | |
4741 | directly invoking commands such as @command{useradd} are lost upon | |
4742 | reconfiguration or reboot. This ensures that the system remains exactly | |
4743 | as declared. | |
4744 | ||
cf4a9129 LC |
4745 | @deftp {Data Type} user-account |
4746 | Objects of this type represent user accounts. The following members may | |
4747 | be specified: | |
ee85f3db | 4748 | |
cf4a9129 LC |
4749 | @table @asis |
4750 | @item @code{name} | |
4751 | The name of the user account. | |
ee85f3db | 4752 | |
cf4a9129 LC |
4753 | @item @code{group} |
4754 | This is the name (a string) or identifier (a number) of the user group | |
4755 | this account belongs to. | |
ee85f3db | 4756 | |
cf4a9129 LC |
4757 | @item @code{supplementary-groups} (default: @code{'()}) |
4758 | Optionally, this can be defined as a list of group names that this | |
4759 | account belongs to. | |
ee85f3db | 4760 | |
cf4a9129 LC |
4761 | @item @code{uid} (default: @code{#f}) |
4762 | This is the user ID for this account (a number), or @code{#f}. In the | |
4763 | latter case, a number is automatically chosen by the system when the | |
4764 | account is created. | |
ee85f3db | 4765 | |
cf4a9129 LC |
4766 | @item @code{comment} (default: @code{""}) |
4767 | A comment about the account, such as the account's owner full name. | |
c8c871d1 | 4768 | |
cf4a9129 LC |
4769 | @item @code{home-directory} |
4770 | This is the name of the home directory for the account. | |
ee85f3db | 4771 | |
cf4a9129 LC |
4772 | @item @code{shell} (default: Bash) |
4773 | This is a G-expression denoting the file name of a program to be used as | |
4774 | the shell (@pxref{G-Expressions}). | |
ee85f3db | 4775 | |
cf4a9129 LC |
4776 | @item @code{system?} (default: @code{#f}) |
4777 | This Boolean value indicates whether the account is a ``system'' | |
4778 | account. System accounts are sometimes treated specially; for instance, | |
4779 | graphical login managers do not list them. | |
ee85f3db | 4780 | |
cf4a9129 | 4781 | @item @code{password} (default: @code{#f}) |
eb59595c LC |
4782 | You would normally leave this field to @code{#f}, initialize user |
4783 | passwords as @code{root} with the @command{passwd} command, and then let | |
9bea87a5 LC |
4784 | users change it with @command{passwd}. Passwords set with |
4785 | @command{passwd} are of course preserved across reboot and | |
4786 | reconfiguration. | |
eb59595c LC |
4787 | |
4788 | If you @emph{do} want to have a preset password for an account, then | |
4789 | this field must contain the encrypted password, as a string. | |
5d1f1177 LC |
4790 | @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information |
4791 | on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference | |
eb59595c | 4792 | Manual}, for information on Guile's @code{crypt} procedure. |
c8c871d1 | 4793 | |
cf4a9129 LC |
4794 | @end table |
4795 | @end deftp | |
ee85f3db | 4796 | |
cf4a9129 | 4797 | User group declarations are even simpler: |
ee85f3db | 4798 | |
cf4a9129 LC |
4799 | @example |
4800 | (user-group (name "students")) | |
4801 | @end example | |
ee85f3db | 4802 | |
cf4a9129 LC |
4803 | @deftp {Data Type} user-group |
4804 | This type is for, well, user groups. There are just a few fields: | |
af8a56b8 | 4805 | |
cf4a9129 LC |
4806 | @table @asis |
4807 | @item @code{name} | |
4808 | The group's name. | |
ee85f3db | 4809 | |
cf4a9129 LC |
4810 | @item @code{id} (default: @code{#f}) |
4811 | The group identifier (a number). If @code{#f}, a new number is | |
4812 | automatically allocated when the group is created. | |
ee85f3db | 4813 | |
c8fa3426 LC |
4814 | @item @code{system?} (default: @code{#f}) |
4815 | This Boolean value indicates whether the group is a ``system'' group. | |
4816 | System groups have low numerical IDs. | |
4817 | ||
cf4a9129 LC |
4818 | @item @code{password} (default: @code{#f}) |
4819 | What, user groups can have a password? Well, apparently yes. Unless | |
4820 | @code{#f}, this field specifies the group's password. | |
ee85f3db | 4821 | |
cf4a9129 LC |
4822 | @end table |
4823 | @end deftp | |
401c53c4 | 4824 | |
cf4a9129 LC |
4825 | For convenience, a variable lists all the basic user groups one may |
4826 | expect: | |
401c53c4 | 4827 | |
cf4a9129 LC |
4828 | @defvr {Scheme Variable} %base-groups |
4829 | This is the list of basic user groups that users and/or packages expect | |
4830 | to be present on the system. This includes groups such as ``root'', | |
4831 | ``wheel'', and ``users'', as well as groups used to control access to | |
4832 | specific devices such as ``audio'', ``disk'', and ``cdrom''. | |
4833 | @end defvr | |
401c53c4 | 4834 | |
bf87f38a LC |
4835 | @defvr {Scheme Variable} %base-user-accounts |
4836 | This is the list of basic system accounts that programs may expect to | |
4837 | find on a GNU/Linux system, such as the ``nobody'' account. | |
4838 | ||
4839 | Note that the ``root'' account is not included here. It is a | |
4840 | special-case and is automatically added whether or not it is specified. | |
4841 | @end defvr | |
4842 | ||
598e19dc LC |
4843 | @node Locales |
4844 | @subsection Locales | |
4845 | ||
4846 | @cindex locale | |
4847 | A @dfn{locale} defines cultural conventions for a particular language | |
4848 | and region of the world (@pxref{Locales,,, libc, The GNU C Library | |
4849 | Reference Manual}). Each locale has a name that typically has the form | |
4850 | @code{@var{language}_@var{territory}.@var{charset}}---e.g., | |
4851 | @code{fr_LU.utf8} designates the locale for the French language, with | |
4852 | cultural conventions from Luxembourg, and using the UTF-8 encoding. | |
4853 | ||
4854 | @cindex locale definition | |
4855 | Usually, you will want to specify the default locale for the machine | |
4856 | using the @code{locale} field of the @code{operating-system} declaration | |
4857 | (@pxref{operating-system Reference, @code{locale}}). | |
4858 | ||
4859 | That locale must be among the @dfn{locale definitions} that are known to | |
4860 | the system---and these are specified in the @code{locale-definitions} | |
4861 | slot of @code{operating-system}. The default value includes locale | |
4862 | definition for some widely used locales, but not for all the available | |
4863 | locales, in order to save space. | |
4864 | ||
4865 | If the locale specified in the @code{locale} field is not among the | |
4866 | definitions listed in @code{locale-definitions}, @command{guix system} | |
4867 | raises an error. In that case, you should add the locale definition to | |
4868 | the @code{locale-definitions} field. For instance, to add the North | |
4869 | Frisian locale for Germany, the value of that field may be: | |
4870 | ||
4871 | @example | |
4872 | (cons (locale-definition | |
4873 | (name "fy_DE.utf8") (source "fy_DE")) | |
4874 | %default-locale-definitions) | |
4875 | @end example | |
4876 | ||
4877 | Likewise, to save space, one might want @code{locale-definitions} to | |
4878 | list only the locales that are actually used, as in: | |
4879 | ||
4880 | @example | |
4881 | (list (locale-definition | |
4882 | (name "ja_JP.eucjp") (source "ja_JP") | |
4883 | (charset "EUC-JP"))) | |
4884 | @end example | |
4885 | ||
4886 | The @code{locale-definition} form is provided by the @code{(gnu system | |
4887 | locale)} module. Details are given below. | |
4888 | ||
4889 | @deftp {Data Type} locale-definition | |
4890 | This is the data type of a locale definition. | |
4891 | ||
4892 | @table @asis | |
4893 | ||
4894 | @item @code{name} | |
4895 | The name of the locale. @xref{Locale Names,,, libc, The GNU C Library | |
4896 | Reference Manual}, for more information on locale names. | |
4897 | ||
4898 | @item @code{source} | |
4899 | The name of the source for that locale. This is typically the | |
4900 | @code{@var{language}_@var{territory}} part of the locale name. | |
4901 | ||
4902 | @item @code{charset} (default: @code{"UTF-8"}) | |
4903 | The ``character set'' or ``code set'' for that locale, | |
4904 | @uref{http://www.iana.org/assignments/character-sets, as defined by | |
4905 | IANA}. | |
4906 | ||
4907 | @end table | |
4908 | @end deftp | |
4909 | ||
4910 | @defvr {Scheme Variable} %default-locale-definitions | |
4911 | An arbitrary list of commonly used locales, used as the default value of | |
4912 | the @code{locale-definitions} field of @code{operating-system} | |
4913 | declarations. | |
4914 | @end defvr | |
401c53c4 | 4915 | |
cf4a9129 LC |
4916 | @node Services |
4917 | @subsection Services | |
401c53c4 | 4918 | |
cf4a9129 LC |
4919 | @cindex system services |
4920 | An important part of preparing an @code{operating-system} declaration is | |
4921 | listing @dfn{system services} and their configuration (@pxref{Using the | |
4922 | Configuration System}). System services are typically daemons launched | |
4923 | when the system boots, or other actions needed at that time---e.g., | |
d8b94dbd LC |
4924 | configuring network access. |
4925 | ||
4926 | Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU | |
4927 | dmd Manual}). On a running system, the @command{deco} command allows | |
4928 | you to list the available services, show their status, start and stop | |
4929 | them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd | |
4930 | Manual}). For example: | |
4931 | ||
4932 | @example | |
4933 | # deco status dmd | |
4934 | @end example | |
4935 | ||
4936 | The above command, run as @code{root}, lists the currently defined | |
4937 | services. The @command{deco doc} command shows a synopsis of the given | |
4938 | service: | |
4939 | ||
4940 | @example | |
4941 | # deco doc nscd | |
4942 | Run libc's name service cache daemon (nscd). | |
4943 | @end example | |
4944 | ||
4945 | The @command{start}, @command{stop}, and @command{restart} sub-commands | |
4946 | have the effect you would expect. For instance, the commands below stop | |
4947 | the nscd service and restart the Xorg display server: | |
4948 | ||
4949 | @example | |
4950 | # deco stop nscd | |
4951 | Service nscd has been stopped. | |
4952 | # deco restart xorg-server | |
4953 | Service xorg-server has been stopped. | |
4954 | Service xorg-server has been started. | |
4955 | @end example | |
401c53c4 | 4956 | |
cf4a9129 | 4957 | The following sections document the available services, starting with |
d8b94dbd LC |
4958 | the core services, that may be used in an @code{operating-system} |
4959 | declaration. | |
401c53c4 | 4960 | |
cf4a9129 LC |
4961 | @menu |
4962 | * Base Services:: Essential system services. | |
4963 | * Networking Services:: Network setup, SSH daemon, etc. | |
4964 | * X Window:: Graphical display. | |
fe1a39d3 | 4965 | * Desktop Services:: D-Bus and desktop services. |
105369a4 | 4966 | * Database Services:: SQL databases. |
aa4ed923 | 4967 | * Various Services:: Other services. |
cf4a9129 | 4968 | @end menu |
401c53c4 | 4969 | |
cf4a9129 LC |
4970 | @node Base Services |
4971 | @subsubsection Base Services | |
a1ba8475 | 4972 | |
cf4a9129 LC |
4973 | The @code{(gnu services base)} module provides definitions for the basic |
4974 | services that one expects from the system. The services exported by | |
4975 | this module are listed below. | |
401c53c4 | 4976 | |
cf4a9129 LC |
4977 | @defvr {Scheme Variable} %base-services |
4978 | This variable contains a list of basic services@footnote{Technically, | |
4979 | this is a list of monadic services. @xref{The Store Monad}.} one would | |
4980 | expect from the system: a login service (mingetty) on each tty, syslogd, | |
4981 | libc's name service cache daemon (nscd), the udev device manager, and | |
4982 | more. | |
401c53c4 | 4983 | |
cf4a9129 LC |
4984 | This is the default value of the @code{services} field of |
4985 | @code{operating-system} declarations. Usually, when customizing a | |
4986 | system, you will want to append services to @var{%base-services}, like | |
4987 | this: | |
401c53c4 | 4988 | |
cf4a9129 | 4989 | @example |
fa1e31b8 | 4990 | (cons* (avahi-service) (lsh-service) %base-services) |
cf4a9129 LC |
4991 | @end example |
4992 | @end defvr | |
401c53c4 | 4993 | |
cf4a9129 LC |
4994 | @deffn {Monadic Procedure} host-name-service @var{name} |
4995 | Return a service that sets the host name to @var{name}. | |
4996 | @end deffn | |
401c53c4 | 4997 | |
cf4a9129 LC |
4998 | @deffn {Monadic Procedure} mingetty-service @var{tty} [#:motd] @ |
4999 | [#:auto-login #f] [#:login-program] [#:login-pause? #f] @ | |
5000 | [#:allow-empty-passwords? #f] | |
5001 | Return a service to run mingetty on @var{tty}. | |
401c53c4 | 5002 | |
cf4a9129 LC |
5003 | When @var{allow-empty-passwords?} is true, allow empty log-in password. When |
5004 | @var{auto-login} is true, it must be a user name under which to log-in | |
5005 | automatically. @var{login-pause?} can be set to @code{#t} in conjunction with | |
5006 | @var{auto-login}, in which case the user will have to press a key before the | |
5007 | login shell is launched. | |
401c53c4 | 5008 | |
cf4a9129 LC |
5009 | When true, @var{login-program} is a gexp or a monadic gexp denoting the name |
5010 | of the log-in program (the default is the @code{login} program from the Shadow | |
5011 | tool suite.) | |
401c53c4 | 5012 | |
cf4a9129 LC |
5013 | @var{motd} is a monadic value containing a text file to use as |
5014 | the ``message of the day''. | |
5015 | @end deffn | |
401c53c4 | 5016 | |
6454b333 LC |
5017 | @cindex name service cache daemon |
5018 | @cindex nscd | |
4aee6e60 LC |
5019 | @deffn {Monadic Procedure} nscd-service [@var{config}] [#:glibc glibc] @ |
5020 | [#:name-services '()] | |
5021 | Return a service that runs libc's name service cache daemon (nscd) with | |
5022 | the given @var{config}---an @code{<nscd-configuration>} object. | |
5023 | Optionally, @code{#:name-services} is a list of packages that provide | |
4c9050c6 LC |
5024 | name service switch (NSS) modules needed by nscd. @xref{Name Service |
5025 | Switch}, for an example. | |
cf4a9129 | 5026 | @end deffn |
401c53c4 | 5027 | |
6454b333 LC |
5028 | @defvr {Scheme Variable} %nscd-default-configuration |
5029 | This is the default @code{<nscd-configuration>} value (see below) used | |
5030 | by @code{nscd-service}. This uses the caches defined by | |
5031 | @var{%nscd-default-caches}; see below. | |
5032 | @end defvr | |
5033 | ||
5034 | @deftp {Data Type} nscd-configuration | |
5035 | This is the type representing the name service cache daemon (nscd) | |
5036 | configuration. | |
5037 | ||
5038 | @table @asis | |
5039 | ||
5040 | @item @code{log-file} (default: @code{"/var/log/nscd.log"}) | |
5041 | Name of nscd's log file. This is where debugging output goes when | |
5042 | @code{debug-level} is strictly positive. | |
5043 | ||
5044 | @item @code{debug-level} (default: @code{0}) | |
5045 | Integer denoting the debugging levels. Higher numbers mean more | |
5046 | debugging output is logged. | |
5047 | ||
5048 | @item @code{caches} (default: @var{%nscd-default-caches}) | |
5049 | List of @code{<nscd-cache>} objects denoting things to be cached; see | |
5050 | below. | |
5051 | ||
5052 | @end table | |
5053 | @end deftp | |
5054 | ||
5055 | @deftp {Data Type} nscd-cache | |
5056 | Data type representing a cache database of nscd and its parameters. | |
5057 | ||
5058 | @table @asis | |
5059 | ||
5060 | @item @code{database} | |
5061 | This is a symbol representing the name of the database to be cached. | |
5062 | Valid values are @code{passwd}, @code{group}, @code{hosts}, and | |
5063 | @code{services}, which designate the corresponding NSS database | |
5064 | (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}). | |
5065 | ||
5066 | @item @code{positive-time-to-live} | |
5067 | @itemx @code{negative-time-to-live} (default: @code{20}) | |
5068 | A number representing the number of seconds during which a positive or | |
5069 | negative lookup result remains in cache. | |
5070 | ||
5071 | @item @code{check-files?} (default: @code{#t}) | |
5072 | Whether to check for updates of the files corresponding to | |
5073 | @var{database}. | |
5074 | ||
5075 | For instance, when @var{database} is @code{hosts}, setting this flag | |
5076 | instructs nscd to check for updates in @file{/etc/hosts} and to take | |
5077 | them into account. | |
5078 | ||
5079 | @item @code{persistent?} (default: @code{#t}) | |
5080 | Whether the cache should be stored persistently on disk. | |
5081 | ||
5082 | @item @code{shared?} (default: @code{#t}) | |
5083 | Whether the cache should be shared among users. | |
5084 | ||
5085 | @item @code{max-database-size} (default: 32@tie{}MiB) | |
5086 | Maximum size in bytes of the database cache. | |
5087 | ||
5088 | @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert | |
5089 | @c settings, so leave them out. | |
5090 | ||
5091 | @end table | |
5092 | @end deftp | |
5093 | ||
5094 | @defvr {Scheme Variable} %nscd-default-caches | |
5095 | List of @code{<nscd-cache>} objects used by default by | |
5096 | @code{nscd-configuration} (see above.) | |
5097 | ||
5098 | It enables persistent and aggressive caching of service and host name | |
5099 | lookups. The latter provides better host name lookup performance, | |
5100 | resilience in the face of unreliable name servers, and also better | |
5101 | privacy---often the result of host name lookups is in local cache, so | |
5102 | external name servers do not even need to be queried. | |
5103 | @end defvr | |
5104 | ||
5105 | ||
1bb76f75 AK |
5106 | @deffn {Monadic Procedure} syslog-service [#:config-file #f] |
5107 | Return a service that runs @code{syslogd}. If configuration file name | |
5108 | @var{config-file} is not specified, use some reasonable default | |
cf4a9129 LC |
5109 | settings. |
5110 | @end deffn | |
401c53c4 | 5111 | |
cf4a9129 LC |
5112 | @deffn {Monadic Procedure} guix-service [#:guix guix] @ |
5113 | [#:builder-group "guixbuild"] [#:build-accounts 10] @ | |
02bb6b45 | 5114 | [#:authorize-hydra-key? #t] [#:use-substitutes? #t] @ |
cf4a9129 LC |
5115 | [#:extra-options '()] |
5116 | Return a service that runs the build daemon from @var{guix}, and has | |
5117 | @var{build-accounts} user accounts available under @var{builder-group}. | |
401c53c4 | 5118 | |
cf4a9129 LC |
5119 | When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key |
5120 | provided by @var{guix} is authorized upon activation, meaning that substitutes | |
5121 | from @code{hydra.gnu.org} are used by default. | |
401c53c4 | 5122 | |
cf4a9129 LC |
5123 | If @var{use-substitutes?} is false, the daemon is run with |
5124 | @option{--no-substitutes} (@pxref{Invoking guix-daemon, | |
5125 | @option{--no-substitutes}}). | |
401c53c4 | 5126 | |
cf4a9129 LC |
5127 | Finally, @var{extra-options} is a list of additional command-line options |
5128 | passed to @command{guix-daemon}. | |
5129 | @end deffn | |
a1ba8475 | 5130 | |
cf4a9129 LC |
5131 | @deffn {Monadic Procedure} udev-service [#:udev udev] |
5132 | Run @var{udev}, which populates the @file{/dev} directory dynamically. | |
5133 | @end deffn | |
401c53c4 | 5134 | |
5eca9459 AK |
5135 | @deffn {Monadic Procedure} console-keymap-service @var{file} |
5136 | Return a service to load console keymap from @var{file} using | |
5137 | @command{loadkeys} command. | |
5138 | @end deffn | |
5139 | ||
a69576ea | 5140 | |
cf4a9129 LC |
5141 | @node Networking Services |
5142 | @subsubsection Networking Services | |
401c53c4 | 5143 | |
fa1e31b8 | 5144 | The @code{(gnu services networking)} module provides services to configure |
cf4a9129 | 5145 | the network interface. |
a1ba8475 | 5146 | |
a023cca8 LC |
5147 | @cindex DHCP, networking service |
5148 | @deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}] | |
5149 | Return a service that runs @var{dhcp}, a Dynamic Host Configuration | |
5150 | Protocol (DHCP) client, on all the non-loopback network interfaces. | |
5151 | @end deffn | |
5152 | ||
cf4a9129 LC |
5153 | @deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @ |
5154 | [#:gateway #f] [#:name-services @code{'()}] | |
5155 | Return a service that starts @var{interface} with address @var{ip}. If | |
5156 | @var{gateway} is true, it must be a string specifying the default network | |
5157 | gateway. | |
5158 | @end deffn | |
8b315a6d | 5159 | |
b7d0c494 MW |
5160 | @cindex wicd |
5161 | @deffn {Monadic Procedure} wicd-service [#:wicd @var{wicd}] | |
5162 | Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a | |
5163 | network manager that aims to simplify wired and wireless networking. | |
5164 | @end deffn | |
5165 | ||
63854bcb LC |
5166 | @deffn {Monadic Procedure} ntp-service [#:ntp @var{ntp}] @ |
5167 | [#:name-service @var{%ntp-servers}] | |
5168 | Return a service that runs the daemon from @var{ntp}, the | |
5169 | @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will | |
5170 | keep the system clock synchronized with that of @var{servers}. | |
5171 | @end deffn | |
5172 | ||
5173 | @defvr {Scheme Variable} %ntp-servers | |
5174 | List of host names used as the default NTP servers. | |
5175 | @end defvr | |
5176 | ||
cf4a9129 LC |
5177 | @deffn {Monadic Procedure} tor-service [#:tor tor] |
5178 | Return a service to run the @uref{https://torproject.org,Tor} daemon. | |
8b315a6d | 5179 | |
cf4a9129 LC |
5180 | The daemon runs with the default settings (in particular the default exit |
5181 | policy) as the @code{tor} unprivileged user. | |
5182 | @end deffn | |
8b315a6d | 5183 | |
4627a464 LC |
5184 | @deffn {Monadic Procedure} bitlbee-service [#:bitlbee bitlbee] @ |
5185 | [#:interface "127.0.0.1"] [#:port 6667] @ | |
5186 | [#:extra-settings ""] | |
5187 | Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that | |
5188 | acts as a gateway between IRC and chat networks. | |
5189 | ||
5190 | The daemon will listen to the interface corresponding to the IP address | |
5191 | specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only | |
5192 | local clients can connect, whereas @code{0.0.0.0} means that connections can | |
5193 | come from any networking interface. | |
5194 | ||
5195 | In addition, @var{extra-settings} specifies a string to append to the | |
5196 | configuration file. | |
5197 | @end deffn | |
5198 | ||
f4391bec | 5199 | Furthermore, @code{(gnu services ssh)} provides the following service. |
8b315a6d | 5200 | |
cf4a9129 | 5201 | @deffn {Monadic Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @ |
5833bf33 | 5202 | [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @ |
cf4a9129 LC |
5203 | [#:allow-empty-passwords? #f] [#:root-login? #f] @ |
5204 | [#:syslog-output? #t] [#:x11-forwarding? #t] @ | |
5205 | [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @ | |
21cc905a | 5206 | [#:public-key-authentication? #t] [#:initialize? #t] |
cf4a9129 LC |
5207 | Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}. |
5208 | @var{host-key} must designate a file containing the host key, and readable | |
5209 | only by root. | |
72e25e35 | 5210 | |
5833bf33 DP |
5211 | When @var{daemonic?} is true, @command{lshd} will detach from the |
5212 | controlling terminal and log its output to syslogd, unless one sets | |
5213 | @var{syslog-output?} to false. Obviously, it also makes lsh-service | |
5214 | depend on existence of syslogd service. When @var{pid-file?} is true, | |
5215 | @command{lshd} writes its PID to the file called @var{pid-file}. | |
5216 | ||
cf4a9129 LC |
5217 | When @var{initialize?} is true, automatically create the seed and host key |
5218 | upon service activation if they do not exist yet. This may take long and | |
5219 | require interaction. | |
8b315a6d | 5220 | |
20dd519c LC |
5221 | When @var{initialize?} is false, it is up to the user to initialize the |
5222 | randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create | |
5223 | a key pair with the private key stored in file @var{host-key} (@pxref{lshd | |
5224 | basics,,, lsh, LSH Manual}). | |
5225 | ||
cf4a9129 LC |
5226 | When @var{interfaces} is empty, lshd listens for connections on all the |
5227 | network interfaces; otherwise, @var{interfaces} must be a list of host names | |
5228 | or addresses. | |
9bf3c1a7 | 5229 | |
20dd519c LC |
5230 | @var{allow-empty-passwords?} specifies whether to accept log-ins with empty |
5231 | passwords, and @var{root-login?} specifies whether to accept log-ins as | |
cf4a9129 | 5232 | root. |
4af2447e | 5233 | |
cf4a9129 LC |
5234 | The other options should be self-descriptive. |
5235 | @end deffn | |
4af2447e | 5236 | |
fa0c1d61 LC |
5237 | @defvr {Scheme Variable} %facebook-host-aliases |
5238 | This variable contains a string for use in @file{/etc/hosts} | |
5239 | (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each | |
5240 | line contains a entry that maps a known server name of the Facebook | |
5241 | on-line service---e.g., @code{www.facebook.com}---to the local | |
5242 | host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. | |
5243 | ||
5244 | This variable is typically used in the @code{hosts-file} field of an | |
7313a52e LC |
5245 | @code{operating-system} declaration (@pxref{operating-system Reference, |
5246 | @file{/etc/hosts}}): | |
fa0c1d61 LC |
5247 | |
5248 | @example | |
5249 | (use-modules (gnu) (guix)) | |
5250 | ||
5251 | (operating-system | |
5252 | (host-name "mymachine") | |
5253 | ;; ... | |
5254 | (hosts-file | |
5255 | ;; Create a /etc/hosts file with aliases for "localhost" | |
5256 | ;; and "mymachine", as well as for Facebook servers. | |
5257 | (text-file "hosts" | |
5258 | (string-append (local-host-aliases host-name) | |
5259 | %facebook-host-aliases)))) | |
5260 | @end example | |
5261 | ||
5262 | This mechanism can prevent programs running locally, such as Web | |
5263 | browsers, from accessing Facebook. | |
5264 | @end defvr | |
5265 | ||
965a7332 LC |
5266 | The @code{(gnu services avahi)} provides the following definition. |
5267 | ||
5268 | @deffn {Monadic Procedure} avahi-service [#:avahi @var{avahi}] @ | |
5269 | [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @ | |
5270 | [#:ipv6? #t] [#:wide-area? #f] @ | |
5271 | [#:domains-to-browse '()] | |
5272 | Return a service that runs @command{avahi-daemon}, a system-wide | |
5273 | mDNS/DNS-SD responder that allows for service discovery and | |
5274 | "zero-configuration" host name lookups (see @uref{http://avahi.org/}). | |
5275 | ||
5276 | If @var{host-name} is different from @code{#f}, use that as the host name to | |
5277 | publish for this machine; otherwise, use the machine's actual host name. | |
5278 | ||
5279 | When @var{publish?} is true, publishing of host names and services is allowed; | |
5280 | in particular, avahi-daemon will publish the machine's host name and IP | |
5281 | address via mDNS on the local network. | |
5282 | ||
5283 | When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled. | |
5284 | ||
5285 | Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6 | |
5286 | sockets. | |
5287 | @end deffn | |
5288 | ||
5289 | ||
cf4a9129 LC |
5290 | @node X Window |
5291 | @subsubsection X Window | |
68ad877c | 5292 | |
cf4a9129 LC |
5293 | Support for the X Window graphical display system---specifically |
5294 | Xorg---is provided by the @code{(gnu services xorg)} module. Note that | |
5295 | there is no @code{xorg-service} procedure. Instead, the X server is | |
5296 | started by the @dfn{login manager}, currently SLiM. | |
4af2447e | 5297 | |
cf4a9129 | 5298 | @deffn {Monadic Procedure} slim-service [#:allow-empty-passwords? #f] @ |
0ecc3bf3 LC |
5299 | [#:auto-login? #f] [#:default-user ""] [#:startx] @ |
5300 | [#:theme @var{%default-slim-theme}] @ | |
4bd43bbe | 5301 | [#:theme-name @var{%default-slim-theme-name}] |
cf4a9129 LC |
5302 | Return a service that spawns the SLiM graphical login manager, which in |
5303 | turn starts the X display server with @var{startx}, a command as returned by | |
5304 | @code{xorg-start-command}. | |
4af2447e | 5305 | |
04e4e6ab LC |
5306 | @cindex X session |
5307 | ||
5308 | SLiM automatically looks for session types described by the @file{.desktop} | |
5309 | files in @file{/run/current-system/profile/share/xsessions} and allows users | |
5310 | to choose a session from the log-in screen using @kbd{F1}. Packages such as | |
5311 | @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files; | |
5312 | adding them to the system-wide set of packages automatically makes them | |
5313 | available at the log-in screen. | |
5314 | ||
5315 | In addition, @file{~/.xsession} files are honored. When available, | |
5316 | @file{~/.xsession} must be an executable that starts a window manager | |
5317 | and/or other X clients. | |
5318 | ||
cf4a9129 LC |
5319 | When @var{allow-empty-passwords?} is true, allow logins with an empty |
5320 | password. When @var{auto-login?} is true, log in automatically as | |
5321 | @var{default-user}. | |
0ecc3bf3 LC |
5322 | |
5323 | If @var{theme} is @code{#f}, the use the default log-in theme; otherwise | |
5324 | @var{theme} must be a gexp denoting the name of a directory containing the | |
5325 | theme to use. In that case, @var{theme-name} specifies the name of the | |
5326 | theme. | |
cf4a9129 | 5327 | @end deffn |
4af2447e | 5328 | |
0ecc3bf3 LC |
5329 | @defvr {Scheme Variable} %default-theme |
5330 | @defvrx {Scheme Variable} %default-theme-name | |
5331 | The G-Expression denoting the default SLiM theme and its name. | |
5332 | @end defvr | |
5333 | ||
f703413e | 5334 | @deffn {Monadic Procedure} xorg-start-command [#:guile] @ |
d1cdd7ba | 5335 | [#:configuration-file #f] [#:xorg-server @var{xorg-server}] |
f703413e | 5336 | Return a derivation that builds a @var{guile} script to start the X server |
d1cdd7ba LC |
5337 | from @var{xorg-server}. @var{configuration-file} is the server configuration |
5338 | file or a derivation that builds it; when omitted, the result of | |
5339 | @code{xorg-configuration-file} is used. | |
5340 | ||
5341 | Usually the X server is started by a login manager. | |
5342 | @end deffn | |
5343 | ||
5344 | @deffn {Monadic Procedure} xorg-configuration-file @ | |
12422c9d | 5345 | [#:drivers '()] [#:resolutions '()] [#:extra-config '()] |
d1cdd7ba LC |
5346 | Return a configuration file for the Xorg server containing search paths for |
5347 | all the common drivers. | |
f703413e LC |
5348 | |
5349 | @var{drivers} must be either the empty list, in which case Xorg chooses a | |
5350 | graphics driver automatically, or a list of driver names that will be tried in | |
d1cdd7ba | 5351 | this order---e.g., @code{(\"modesetting\" \"vesa\")}. |
d2e59637 LC |
5352 | |
5353 | Likewise, when @var{resolutions} is the empty list, Xorg chooses an | |
5354 | appropriate screen resolution; otherwise, it must be a list of | |
5355 | resolutions---e.g., @code{((1024 768) (640 480))}. | |
12422c9d LC |
5356 | |
5357 | Last, @var{extra-config} is a list of strings or objects appended to the | |
5358 | @code{text-file*} argument list. It is used to pass extra text to be added | |
5359 | verbatim to the configuration file. | |
f703413e | 5360 | @end deffn |
4af2447e | 5361 | |
fe1a39d3 LC |
5362 | @node Desktop Services |
5363 | @subsubsection Desktop Services | |
aa4ed923 | 5364 | |
fe1a39d3 LC |
5365 | The @code{(gnu services desktop)} module provides services that are |
5366 | usually useful in the context of a ``desktop'' setup---that is, on a | |
5367 | machine running a graphical display server, possibly with graphical user | |
5368 | interfaces, etc. | |
aa4ed923 | 5369 | |
4467be21 LC |
5370 | To simplify things, the module defines a variable containing the set of |
5371 | services that users typically expect on a machine with a graphical | |
5372 | environment and networking: | |
5373 | ||
5374 | @defvr {Scheme Variable} %desktop-services | |
5375 | This is a list of services that builds upon @var{%base-services} and | |
5376 | adds or adjust services for a typical ``desktop'' setup. | |
5377 | ||
5378 | In particular, it adds a graphical login manager (@pxref{X Window, | |
5379 | @code{slim-service}}), a network management tool (@pxref{Networking | |
5380 | Services, @code{wicd-service}}), energy and color management services, | |
5381 | an NTP client and an SSH server (@pxref{Networking Services}), the Avahi | |
5382 | daemon, and has the name service switch service configured to be able to | |
5383 | use @code{nss-mdns} (@pxref{Name Service Switch, mDNS}). | |
5384 | @end defvr | |
5385 | ||
5386 | The @var{%desktop-services} variable can be used as the @code{services} | |
5387 | field of an @code{operating-system} declaration (@pxref{operating-system | |
5388 | Reference, @code{services}}). | |
5389 | ||
5390 | The actual service definitions provided by @code{(gnu services desktop)} | |
5391 | are described below. | |
5392 | ||
fe1a39d3 LC |
5393 | @deffn {Monadic Procedure} dbus-service @var{services} @ |
5394 | [#:dbus @var{dbus}] | |
5395 | Return a service that runs the ``system bus'', using @var{dbus}, with | |
5396 | support for @var{services}. | |
aa4ed923 | 5397 | |
fe1a39d3 LC |
5398 | @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication |
5399 | facility. Its system bus is used to allow system services to communicate | |
5400 | and be notified of system-wide events. | |
aa4ed923 | 5401 | |
fe1a39d3 LC |
5402 | @var{services} must be a list of packages that provide an |
5403 | @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration | |
5404 | and policy files. For example, to allow avahi-daemon to use the system bus, | |
5405 | @var{services} must be equal to @code{(list avahi)}. | |
aa4ed923 AK |
5406 | @end deffn |
5407 | ||
be234128 AW |
5408 | @deffn {Monadic Procedure} upower-service [#:upower @var{upower}] @ |
5409 | [#:watts-up-pro? #f] @ | |
5410 | [#:poll-batteries? #t] @ | |
5411 | [#:ignore-lid? #f] @ | |
5412 | [#:use-percentage-for-policy? #f] @ | |
5413 | [#:percentage-low 10] @ | |
5414 | [#:percentage-critical 3] @ | |
5415 | [#:percentage-action 2] @ | |
5416 | [#:time-low 1200] @ | |
5417 | [#:time-critical 300] @ | |
5418 | [#:time-action 120] @ | |
5419 | [#:critical-power-action 'hybrid-sleep] | |
5420 | Return a service that runs @uref{http://upower.freedesktop.org/, | |
5421 | @command{upowerd}}, a system-wide monitor for power consumption and battery | |
5422 | levels, with the given configuration settings. It implements the | |
5423 | @code{org.freedesktop.UPower} D-Bus interface, and is notably used by | |
5424 | GNOME. | |
5425 | @end deffn | |
5426 | ||
7ce597ff AW |
5427 | @deffn {Monadic Procedure} colord-service [#:colord @var{colord}] |
5428 | Return a service that runs @command{colord}, a system service with a D-Bus | |
5429 | interface to manage the color profiles of input and output devices such as | |
5430 | screens and scanners. It is notably used by the GNOME Color Manager graphical | |
5431 | tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web | |
5432 | site} for more information. | |
5433 | @end deffn | |
5434 | ||
105369a4 DT |
5435 | @node Database Services |
5436 | @subsubsection Database Services | |
5437 | ||
5438 | The @code{(gnu services databases)} module provides the following service. | |
5439 | ||
5440 | @deffn {Monadic Procedure} postgresql-service [#:postgresql postgresql] @ | |
5441 | [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] | |
5442 | Return a service that runs @var{postgresql}, the PostgreSQL database | |
5443 | server. | |
5444 | ||
5445 | The PostgreSQL daemon loads its runtime configuration from | |
5446 | @var{config-file} and stores the database cluster in | |
5447 | @var{data-directory}. | |
5448 | @end deffn | |
fe1a39d3 LC |
5449 | |
5450 | @node Various Services | |
5451 | @subsubsection Various Services | |
5452 | ||
5453 | The @code{(gnu services lirc)} module provides the following service. | |
5454 | ||
5455 | @deffn {Monadic Procedure} lirc-service [#:lirc lirc] @ | |
5456 | [#:device #f] [#:driver #f] [#:config-file #f] @ | |
5457 | [#:extra-options '()] | |
5458 | Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that | |
5459 | decodes infrared signals from remote controls. | |
5460 | ||
5461 | Optionally, @var{device}, @var{driver} and @var{config-file} | |
5462 | (configuration file name) may be specified. See @command{lircd} manual | |
5463 | for details. | |
5464 | ||
5465 | Finally, @var{extra-options} is a list of additional command-line options | |
5466 | passed to @command{lircd}. | |
5467 | @end deffn | |
5468 | ||
5469 | ||
0ae8c15a LC |
5470 | @node Setuid Programs |
5471 | @subsection Setuid Programs | |
5472 | ||
5473 | @cindex setuid programs | |
5474 | Some programs need to run with ``root'' privileges, even when they are | |
5475 | launched by unprivileged users. A notorious example is the | |
5476 | @command{passwd} programs, which can users can run to change their | |
5477 | password, and which requires write access to the @file{/etc/passwd} and | |
5478 | @file{/etc/shadow} files---something normally restricted to root, for | |
5479 | obvious security reasons. To address that, these executables are | |
5480 | @dfn{setuid-root}, meaning that they always run with root privileges | |
5481 | (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual}, | |
5482 | for more info about the setuid mechanisms.) | |
5483 | ||
5484 | The store itself @emph{cannot} contain setuid programs: that would be a | |
5485 | security issue since any user on the system can write derivations that | |
5486 | populate the store (@pxref{The Store}). Thus, a different mechanism is | |
5487 | used: instead of changing the setuid bit directly on files that are in | |
5488 | the store, we let the system administrator @emph{declare} which programs | |
5489 | should be setuid root. | |
5490 | ||
5491 | The @code{setuid-programs} field of an @code{operating-system} | |
5492 | declaration contains a list of G-expressions denoting the names of | |
5493 | programs to be setuid-root (@pxref{Using the Configuration System}). | |
5494 | For instance, the @command{passwd} program, which is part of the Shadow | |
5495 | package, can be designated by this G-expression (@pxref{G-Expressions}): | |
5496 | ||
5497 | @example | |
5498 | #~(string-append #$shadow "/bin/passwd") | |
5499 | @end example | |
5500 | ||
5501 | A default set of setuid programs is defined by the | |
5502 | @code{%setuid-programs} variable of the @code{(gnu system)} module. | |
5503 | ||
5504 | @defvr {Scheme Variable} %setuid-programs | |
5505 | A list of G-expressions denoting common programs that are setuid-root. | |
5506 | ||
5507 | The list includes commands such as @command{passwd}, @command{ping}, | |
5508 | @command{su}, and @command{sudo}. | |
5509 | @end defvr | |
5510 | ||
5511 | Under the hood, the actual setuid programs are created in the | |
5512 | @file{/run/setuid-programs} directory at system activation time. The | |
5513 | files in this directory refer to the ``real'' binaries, which are in the | |
5514 | store. | |
5515 | ||
efb5e833 LC |
5516 | @node X.509 Certificates |
5517 | @subsection X.509 Certificates | |
5518 | ||
5519 | @cindex HTTPS, certificates | |
5520 | @cindex X.509 certificates | |
5521 | @cindex TLS | |
5522 | Web servers available over HTTPS (that is, HTTP over the transport-layer | |
5523 | security mechanism, TLS) send client programs an @dfn{X.509 certificate} | |
5524 | that the client can then use to @emph{authenticate} the server. To do | |
5525 | that, clients verify that the server's certificate is signed by a | |
5526 | so-called @dfn{certificate authority} (CA). But to verify the CA's | |
5527 | signature, clients must have first acquired the CA's certificate. | |
5528 | ||
5529 | Web browsers such as GNU@tie{}IceCat include their own set of CA | |
5530 | certificates, such that they are able to verify CA signatures | |
5531 | out-of-the-box. | |
5532 | ||
5533 | However, most other programs that can talk HTTPS---@command{wget}, | |
5534 | @command{git}, @command{w3m}, etc.---need to be told where CA | |
5535 | certificates can be found. | |
5536 | ||
5537 | @cindex @code{nss-certs} | |
5538 | In GuixSD, this is done by adding a package that provides certificates | |
5539 | to the @code{packages} field of the @code{operating-system} declaration | |
5540 | (@pxref{operating-system Reference}). GuixSD includes one such package, | |
5541 | @code{nss-certs}, which is a set of CA certificates provided as part of | |
5542 | Mozilla's Network Security Services. | |
5543 | ||
5544 | Note that it is @emph{not} part of @var{%base-packages}, so you need to | |
5545 | explicitly add it. The @file{/etc/ssl/certs} directory, which is where | |
5546 | most applications and libraries look for certificates by default, points | |
5547 | to the certificates installed globally. | |
5548 | ||
5549 | Unprivileged users can also install their own certificate package in | |
5550 | their profile. A number of environment variables need to be defined so | |
5551 | that applications and libraries know where to find them. Namely, the | |
5552 | OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE} | |
5553 | variables. Some applications add their own environment variables; for | |
5554 | instance, the Git version control system honors the certificate bundle | |
5555 | pointed to by the @code{GIT_SSL_CAINFO} environment variable. | |
5556 | ||
5557 | ||
996ed739 LC |
5558 | @node Name Service Switch |
5559 | @subsection Name Service Switch | |
5560 | ||
5561 | @cindex name service switch | |
5562 | @cindex NSS | |
5563 | The @code{(gnu system nss)} module provides bindings to the | |
5564 | configuration file of libc's @dfn{name service switch} or @dfn{NSS} | |
5565 | (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference | |
5566 | Manual}). In a nutshell, the NSS is a mechanism that allows libc to be | |
5567 | extended with new ``name'' lookup methods for system databases, which | |
5568 | includes host names, service names, user accounts, and more (@pxref{Name | |
5569 | Service Switch, System Databases and Name Service Switch,, libc, The GNU | |
5570 | C Library Reference Manual}). | |
5571 | ||
5572 | The NSS configuration specifies, for each system database, which lookup | |
5573 | method is to be used, and how the various methods are chained | |
5574 | together---for instance, under which circumstances NSS should try the | |
5575 | next method in the list. The NSS configuration is given in the | |
5576 | @code{name-service-switch} field of @code{operating-system} declarations | |
5577 | (@pxref{operating-system Reference, @code{name-service-switch}}). | |
5578 | ||
4c9050c6 LC |
5579 | @cindex nss-mdns |
5580 | @cindex .local, host name lookup | |
996ed739 | 5581 | As an example, the declaration below configures the NSS to use the |
4c9050c6 LC |
5582 | @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns} |
5583 | back-end}, which supports host name lookups over multicast DNS (mDNS) | |
5584 | for host names ending in @code{.local}: | |
996ed739 LC |
5585 | |
5586 | @example | |
5587 | (name-service-switch | |
5588 | (hosts (list %files ;first, check /etc/hosts | |
5589 | ||
5590 | ;; If the above did not succeed, try | |
5591 | ;; with 'mdns_minimal'. | |
5592 | (name-service | |
5593 | (name "mdns_minimal") | |
5594 | ||
5595 | ;; 'mdns_minimal' is authoritative for | |
5596 | ;; '.local'. When it returns "not found", | |
5597 | ;; no need to try the next methods. | |
5598 | (reaction (lookup-specification | |
5599 | (not-found => return)))) | |
5600 | ||
5601 | ;; Then fall back to DNS. | |
5602 | (name-service | |
5603 | (name "dns")) | |
5604 | ||
5605 | ;; Finally, try with the "full" 'mdns'. | |
5606 | (name-service | |
5607 | (name "mdns"))))) | |
5608 | @end example | |
5609 | ||
15137a29 LC |
5610 | Don't worry: the @code{%mdns-host-lookup-nss} variable (see below) |
5611 | contains this configuration, so you won't have to type it if all you | |
5612 | want is to have @code{.local} host lookup working. | |
5613 | ||
4c9050c6 LC |
5614 | Note that, in this case, in addition to setting the |
5615 | @code{name-service-switch} of the @code{operating-system} declaration, | |
5616 | @code{nscd-service} must be told where to find the @code{nss-mdns} | |
5617 | shared library (@pxref{Base Services, @code{nscd-service}}). Since the | |
5618 | @code{nscd} service is part of @var{%base-services}, you may want to | |
5619 | customize it by adding this snippet in the operating system | |
5620 | configuration file: | |
5621 | ||
5622 | @example | |
5623 | (use-modules (guix) (gnu)) | |
5624 | ||
5625 | (define %my-base-services | |
5626 | ;; Replace the default nscd service with one that knows | |
5627 | ;; about nss-mdns. | |
5628 | (map (lambda (mservice) | |
5629 | ;; "Bind" the MSERVICE monadic value to inspect it. | |
5630 | (mlet %store-monad ((service mservice)) | |
5631 | (if (member 'nscd (service-provision service)) | |
5632 | (nscd-service (nscd-configuration) | |
5633 | #:name-services (list nss-mdns)) | |
5634 | mservice))) | |
5635 | %base-services)) | |
5636 | @end example | |
5637 | ||
5638 | @noindent | |
5639 | @dots{} and then refer to @var{%my-base-services} instead of | |
5640 | @var{%base-services} in the @code{operating-system} declaration. | |
15137a29 | 5641 | Lastly, this relies on the availability of the Avahi service |
965a7332 | 5642 | (@pxref{Networking Services, @code{avahi-service}}). |
15137a29 LC |
5643 | |
5644 | For convenience, the following variables provide typical NSS | |
5645 | configurations. | |
5646 | ||
5647 | @defvr {Scheme Variable} %default-nss | |
5648 | This is the default name service switch configuration, a | |
5649 | @code{name-service-switch} object. | |
5650 | @end defvr | |
5651 | ||
5652 | @defvr {Scheme Variable} %mdns-host-lookup-nss | |
5653 | This is the name service switch configuration with support for host name | |
5654 | lookup over multicast DNS (mDNS) for host names ending in @code{.local}. | |
5655 | @end defvr | |
4c9050c6 | 5656 | |
996ed739 LC |
5657 | The reference for name service switch configuration is given below. It |
5658 | is a direct mapping of the C library's configuration file format, so | |
5659 | please refer to the C library manual for more information (@pxref{NSS | |
5660 | Configuration File,,, libc, The GNU C Library Reference Manual}). | |
5661 | Compared to libc's NSS configuration file format, it has the advantage | |
5662 | not only of adding this warm parenthetic feel that we like, but also | |
5663 | static checks: you'll know about syntax errors and typos as soon as you | |
5664 | run @command{guix system}. | |
5665 | ||
996ed739 LC |
5666 | @deftp {Data Type} name-service-switch |
5667 | ||
5668 | This is the data type representation the configuration of libc's name | |
5669 | service switch (NSS). Each field below represents one of the supported | |
5670 | system databases. | |
5671 | ||
5672 | @table @code | |
5673 | @item aliases | |
5674 | @itemx ethers | |
5675 | @itemx group | |
5676 | @itemx gshadow | |
5677 | @itemx hosts | |
5678 | @itemx initgroups | |
5679 | @itemx netgroup | |
5680 | @itemx networks | |
5681 | @itemx password | |
5682 | @itemx public-key | |
5683 | @itemx rpc | |
5684 | @itemx services | |
5685 | @itemx shadow | |
5686 | The system databases handled by the NSS. Each of these fields must be a | |
5687 | list of @code{<name-service>} objects (see below.) | |
5688 | @end table | |
5689 | @end deftp | |
5690 | ||
5691 | @deftp {Data Type} name-service | |
5692 | ||
5693 | This is the data type representing an actual name service and the | |
5694 | associated lookup action. | |
5695 | ||
5696 | @table @code | |
5697 | @item name | |
5698 | A string denoting the name service (@pxref{Services in the NSS | |
5699 | configuration,,, libc, The GNU C Library Reference Manual}). | |
5700 | ||
4aee6e60 LC |
5701 | Note that name services listed here must be visible to nscd. This is |
5702 | achieved by passing the @code{#:name-services} argument to | |
5703 | @code{nscd-service} the list of packages providing the needed name | |
5704 | services (@pxref{Base Services, @code{nscd-service}}). | |
5705 | ||
996ed739 LC |
5706 | @item reaction |
5707 | An action specified using the @code{lookup-specification} macro | |
5708 | (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library | |
5709 | Reference Manual}). For example: | |
5710 | ||
5711 | @example | |
5712 | (lookup-specification (unavailable => continue) | |
5713 | (success => return)) | |
5714 | @end example | |
5715 | @end table | |
5716 | @end deftp | |
0ae8c15a | 5717 | |
fd1b1fa2 LC |
5718 | @node Initial RAM Disk |
5719 | @subsection Initial RAM Disk | |
5720 | ||
5721 | @cindex initial RAM disk (initrd) | |
5722 | @cindex initrd (initial RAM disk) | |
5723 | For bootstrapping purposes, the Linux-Libre kernel is passed an | |
5724 | @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary | |
5725 | root file system, as well as an initialization script. The latter is | |
5726 | responsible for mounting the real root file system, and for loading any | |
5727 | kernel modules that may be needed to achieve that. | |
5728 | ||
5729 | The @code{initrd} field of an @code{operating-system} declaration allows | |
5730 | you to specify which initrd you would like to use. The @code{(gnu | |
5731 | system linux-initrd)} module provides two ways to build an initrd: the | |
5732 | high-level @code{base-initrd} procedure, and the low-level | |
5733 | @code{expression->initrd} procedure. | |
5734 | ||
5735 | The @code{base-initrd} procedure is intended to cover most common uses. | |
5736 | For example, if you want to add a bunch of kernel modules to be loaded | |
5737 | at boot time, you can define the @code{initrd} field of the operating | |
5738 | system declaration like this: | |
5739 | ||
5740 | @example | |
52ac153e | 5741 | (initrd (lambda (file-systems . rest) |
027981d6 LC |
5742 | ;; Create a standard initrd that has modules "foo.ko" |
5743 | ;; and "bar.ko", as well as their dependencies, in | |
5744 | ;; addition to the modules available by default. | |
52ac153e | 5745 | (apply base-initrd file-systems |
027981d6 | 5746 | #:extra-modules '("foo" "bar") |
52ac153e | 5747 | rest))) |
fd1b1fa2 LC |
5748 | @end example |
5749 | ||
52ac153e LC |
5750 | The @code{base-initrd} procedure also handles common use cases that |
5751 | involves using the system as a QEMU guest, or as a ``live'' system whose | |
5752 | root file system is volatile. | |
fd1b1fa2 LC |
5753 | |
5754 | @deffn {Monadic Procedure} base-initrd @var{file-systems} @ | |
5755 | [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @ | |
52ac153e | 5756 | [#:extra-modules '()] [#:mapped-devices '()] |
fd1b1fa2 LC |
5757 | Return a monadic derivation that builds a generic initrd. @var{file-systems} is |
5758 | a list of file-systems to be mounted by the initrd, possibly in addition to | |
5759 | the root file system specified on the kernel command line via @code{--root}. | |
52ac153e LC |
5760 | @var{mapped-devices} is a list of device mappings to realize before |
5761 | @var{file-systems} are mounted (@pxref{Mapped Devices}). | |
fd1b1fa2 LC |
5762 | |
5763 | When @var{qemu-networking?} is true, set up networking with the standard QEMU | |
5764 | parameters. When @var{virtio?} is true, load additional modules so the initrd can | |
5765 | be used as a QEMU guest with para-virtualized I/O drivers. | |
5766 | ||
5767 | When @var{volatile-root?} is true, the root file system is writable but any changes | |
5768 | to it are lost. | |
5769 | ||
5770 | The initrd is automatically populated with all the kernel modules necessary | |
5771 | for @var{file-systems} and for the given options. However, additional kernel | |
5772 | modules can be listed in @var{extra-modules}. They will be added to the initrd, and | |
5773 | loaded at boot time in the order in which they appear. | |
5774 | @end deffn | |
5775 | ||
5776 | Needless to say, the initrds we produce and use embed a | |
5777 | statically-linked Guile, and the initialization program is a Guile | |
5778 | program. That gives a lot of flexibility. The | |
5779 | @code{expression->initrd} procedure builds such an initrd, given the | |
5780 | program to run in that initrd. | |
5781 | ||
5782 | @deffn {Monadic Procedure} expression->initrd @var{exp} @ | |
5783 | [#:guile %guile-static-stripped] [#:name "guile-initrd"] @ | |
42d10464 | 5784 | [#:modules '()] |
fd1b1fa2 LC |
5785 | Return a derivation that builds a Linux initrd (a gzipped cpio archive) |
5786 | containing @var{guile} and that evaluates @var{exp}, a G-expression, | |
df650fa8 LC |
5787 | upon booting. All the derivations referenced by @var{exp} are |
5788 | automatically copied to the initrd. | |
fd1b1fa2 | 5789 | |
42d10464 LC |
5790 | @var{modules} is a list of Guile module names to be embedded in the |
5791 | initrd. | |
fd1b1fa2 LC |
5792 | @end deffn |
5793 | ||
88faf933 LC |
5794 | @node GRUB Configuration |
5795 | @subsection GRUB Configuration | |
5796 | ||
5797 | @cindex GRUB | |
5798 | @cindex boot loader | |
5799 | ||
5800 | The operating system uses GNU@tie{}GRUB as its boot loader | |
5801 | (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is | |
5802 | configured using @code{grub-configuration} declarations. This data type | |
5803 | is exported by the @code{(gnu system grub)} module, and described below. | |
5804 | ||
5805 | @deftp {Data Type} grub-configuration | |
5806 | The type of a GRUB configuration declaration. | |
5807 | ||
5808 | @table @asis | |
5809 | ||
5810 | @item @code{device} | |
5811 | This is a string denoting the boot device. It must be a device name | |
5812 | understood by the @command{grub-install} command, such as | |
5813 | @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub, | |
5814 | GNU GRUB Manual}). | |
5815 | ||
5816 | @item @code{menu-entries} (default: @code{()}) | |
5817 | A possibly empty list of @code{menu-entry} objects (see below), denoting | |
5818 | entries to appear in the GRUB boot menu, in addition to the current | |
5819 | system entry and the entry pointing to previous system generations. | |
5820 | ||
5821 | @item @code{default-entry} (default: @code{0}) | |
5822 | The index of the default boot menu entry. Index 0 is for the current | |
5823 | system's entry. | |
5824 | ||
5825 | @item @code{timeout} (default: @code{5}) | |
5826 | The number of seconds to wait for keyboard input before booting. Set to | |
5827 | 0 to boot immediately, and to -1 to wait indefinitely. | |
5828 | ||
5829 | @item @code{theme} (default: @var{%default-theme}) | |
5830 | The @code{grub-theme} object describing the theme to use. | |
5831 | @end table | |
5832 | ||
5833 | @end deftp | |
5834 | ||
5835 | Should you want to list additional boot menu entries @i{via} the | |
5836 | @code{menu-entries} field above, you will need to create them with the | |
5837 | @code{menu-entry} form: | |
5838 | ||
5839 | @deftp {Data Type} menu-entry | |
5840 | The type of an entry in the GRUB boot menu. | |
5841 | ||
5842 | @table @asis | |
5843 | ||
5844 | @item @code{label} | |
35ed9306 | 5845 | The label to show in the menu---e.g., @code{"GNU"}. |
88faf933 LC |
5846 | |
5847 | @item @code{linux} | |
5848 | The Linux kernel to boot. | |
5849 | ||
5850 | @item @code{linux-arguments} (default: @code{()}) | |
5851 | The list of extra Linux kernel command-line arguments---e.g., | |
5852 | @code{("console=ttyS0")}. | |
5853 | ||
5854 | @item @code{initrd} | |
5855 | A G-Expression or string denoting the file name of the initial RAM disk | |
5856 | to use (@pxref{G-Expressions}). | |
5857 | ||
5858 | @end table | |
5859 | @end deftp | |
5860 | ||
5861 | @c FIXME: Write documentation once it's stable. | |
5862 | Themes are created using the @code{grub-theme} form, which is not | |
5863 | documented yet. | |
5864 | ||
5865 | @defvr {Scheme Variable} %default-theme | |
5866 | This is the default GRUB theme used by the operating system, with a | |
5867 | fancy background image displaying the GNU and Guix logos. | |
5868 | @end defvr | |
5869 | ||
5870 | ||
cf4a9129 LC |
5871 | @node Invoking guix system |
5872 | @subsection Invoking @code{guix system} | |
0918e64a | 5873 | |
cf4a9129 LC |
5874 | Once you have written an operating system declaration, as seen in the |
5875 | previous section, it can be @dfn{instantiated} using the @command{guix | |
5876 | system} command. The synopsis is: | |
4af2447e | 5877 | |
cf4a9129 LC |
5878 | @example |
5879 | guix system @var{options}@dots{} @var{action} @var{file} | |
5880 | @end example | |
4af2447e | 5881 | |
cf4a9129 LC |
5882 | @var{file} must be the name of a file containing an |
5883 | @code{operating-system} declaration. @var{action} specifies how the | |
5884 | operating system is instantiate. Currently the following values are | |
5885 | supported: | |
4af2447e | 5886 | |
cf4a9129 LC |
5887 | @table @code |
5888 | @item reconfigure | |
5889 | Build the operating system described in @var{file}, activate it, and | |
5890 | switch to it@footnote{This action is usable only on systems already | |
5891 | running GNU.}. | |
4af2447e | 5892 | |
cf4a9129 LC |
5893 | This effects all the configuration specified in @var{file}: user |
5894 | accounts, system services, global package list, setuid programs, etc. | |
4af2447e | 5895 | |
cf4a9129 LC |
5896 | It also adds a GRUB menu entry for the new OS configuration, and moves |
5897 | entries for older configurations to a submenu---unless | |
5898 | @option{--no-grub} is passed. | |
4af2447e | 5899 | |
bf2479c7 LC |
5900 | @c The paragraph below refers to the problem discussed at |
5901 | @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>. | |
5902 | It is highly recommended to run @command{guix pull} once before you run | |
5903 | @command{guix system reconfigure} for the first time (@pxref{Invoking | |
5904 | guix pull}). Failing to do that you would see an older version of Guix | |
5905 | once @command{reconfigure} has completed. | |
5906 | ||
cf4a9129 LC |
5907 | @item build |
5908 | Build the operating system's derivation, which includes all the | |
5909 | configuration files and programs needed to boot and run the system. | |
5910 | This action does not actually install anything. | |
113daf62 | 5911 | |
cf4a9129 LC |
5912 | @item init |
5913 | Populate the given directory with all the files necessary to run the | |
5914 | operating system specified in @var{file}. This is useful for first-time | |
4705641f | 5915 | installations of GuixSD. For instance: |
113daf62 LC |
5916 | |
5917 | @example | |
cf4a9129 | 5918 | guix system init my-os-config.scm /mnt |
113daf62 LC |
5919 | @end example |
5920 | ||
cf4a9129 LC |
5921 | copies to @file{/mnt} all the store items required by the configuration |
5922 | specified in @file{my-os-config.scm}. This includes configuration | |
5923 | files, packages, and so on. It also creates other essential files | |
5924 | needed for the system to operate correctly---e.g., the @file{/etc}, | |
5925 | @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file. | |
113daf62 | 5926 | |
cf4a9129 LC |
5927 | This command also installs GRUB on the device specified in |
5928 | @file{my-os-config}, unless the @option{--no-grub} option was passed. | |
113daf62 | 5929 | |
cf4a9129 LC |
5930 | @item vm |
5931 | @cindex virtual machine | |
0276f697 | 5932 | @cindex VM |
cf4a9129 LC |
5933 | Build a virtual machine that contain the operating system declared in |
5934 | @var{file}, and return a script to run that virtual machine (VM). | |
810568b3 | 5935 | Arguments given to the script are passed as is to QEMU. |
113daf62 | 5936 | |
cf4a9129 | 5937 | The VM shares its store with the host system. |
113daf62 | 5938 | |
0276f697 LC |
5939 | Additional file systems can be shared between the host and the VM using |
5940 | the @code{--share} and @code{--expose} command-line options: the former | |
5941 | specifies a directory to be shared with write access, while the latter | |
5942 | provides read-only access to the shared directory. | |
5943 | ||
5944 | The example below creates a VM in which the user's home directory is | |
5945 | accessible read-only, and where the @file{/exchange} directory is a | |
5946 | read-write mapping of the host's @file{$HOME/tmp}: | |
5947 | ||
5948 | @example | |
5949 | guix system vm my-config.scm \ | |
5950 | --expose=$HOME --share=$HOME/tmp=/exchange | |
5951 | @end example | |
5952 | ||
6aa260af LC |
5953 | On GNU/Linux, the default is to boot directly to the kernel; this has |
5954 | the advantage of requiring only a very tiny root disk image since the | |
5955 | host's store can then be mounted. | |
5956 | ||
5957 | The @code{--full-boot} option forces a complete boot sequence, starting | |
5958 | with the bootloader. This requires more disk space since a root image | |
5959 | containing at least the kernel, initrd, and bootloader data files must | |
5960 | be created. The @code{--image-size} option can be used to specify the | |
5961 | image's size. | |
ab11f0be | 5962 | |
cf4a9129 LC |
5963 | @item vm-image |
5964 | @itemx disk-image | |
5965 | Return a virtual machine or disk image of the operating system declared | |
5966 | in @var{file} that stands alone. Use the @option{--image-size} option | |
5967 | to specify the size of the image. | |
113daf62 | 5968 | |
cf4a9129 LC |
5969 | When using @code{vm-image}, the returned image is in qcow2 format, which |
5970 | the QEMU emulator can efficiently use. | |
113daf62 | 5971 | |
cf4a9129 LC |
5972 | When using @code{disk-image}, a raw disk image is produced; it can be |
5973 | copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is | |
5974 | the device corresponding to a USB stick, one can copy the image on it | |
5975 | using the following command: | |
113daf62 | 5976 | |
cf4a9129 LC |
5977 | @example |
5978 | # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc | |
5979 | @end example | |
113daf62 | 5980 | |
cf4a9129 | 5981 | @end table |
113daf62 | 5982 | |
cf4a9129 LC |
5983 | @var{options} can contain any of the common build options provided by |
5984 | @command{guix build} (@pxref{Invoking guix build}). In addition, | |
5985 | @var{options} can contain one of the following: | |
113daf62 | 5986 | |
cf4a9129 LC |
5987 | @table @option |
5988 | @item --system=@var{system} | |
5989 | @itemx -s @var{system} | |
5990 | Attempt to build for @var{system} instead of the host's system type. | |
5991 | This works as per @command{guix build} (@pxref{Invoking guix build}). | |
113daf62 | 5992 | |
cf4a9129 LC |
5993 | @item --image-size=@var{size} |
5994 | For the @code{vm-image} and @code{disk-image} actions, create an image | |
5995 | of the given @var{size}. @var{size} may be a number of bytes, or it may | |
4a44d7bb LC |
5996 | include a unit as a suffix (@pxref{Block size, size specifications,, |
5997 | coreutils, GNU Coreutils}). | |
db030303 LC |
5998 | |
5999 | @item --on-error=@var{strategy} | |
6000 | Apply @var{strategy} when an error occurs when reading @var{file}. | |
6001 | @var{strategy} may be one of the following: | |
6002 | ||
6003 | @table @code | |
6004 | @item nothing-special | |
6005 | Report the error concisely and exit. This is the default strategy. | |
6006 | ||
6007 | @item backtrace | |
6008 | Likewise, but also display a backtrace. | |
6009 | ||
6010 | @item debug | |
6011 | Report the error and enter Guile's debugger. From there, you can run | |
6012 | commands such as @code{,bt} to get a backtrace, @code{,locals} to | |
6013 | display local variable values, and more generally inspect the program's | |
6014 | state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for | |
6015 | a list of available debugging commands. | |
6016 | @end table | |
113daf62 | 6017 | @end table |
113daf62 | 6018 | |
cf4a9129 LC |
6019 | Note that all the actions above, except @code{build} and @code{init}, |
6020 | rely on KVM support in the Linux-Libre kernel. Specifically, the | |
6021 | machine should have hardware virtualization support, the corresponding | |
6022 | KVM kernel module should be loaded, and the @file{/dev/kvm} device node | |
6023 | must exist and be readable and writable by the user and by the daemon's | |
6024 | build users. | |
8451a568 | 6025 | |
cf4a9129 LC |
6026 | @node Defining Services |
6027 | @subsection Defining Services | |
8451a568 | 6028 | |
cf4a9129 LC |
6029 | The @code{(gnu services @dots{})} modules define several procedures that allow |
6030 | users to declare the operating system's services (@pxref{Using the | |
6031 | Configuration System}). These procedures are @emph{monadic | |
6032 | procedures}---i.e., procedures that return a monadic value in the store | |
6033 | monad (@pxref{The Store Monad}). For examples of such procedures, | |
6034 | @xref{Services}. | |
8451a568 | 6035 | |
cf4a9129 LC |
6036 | @cindex service definition |
6037 | The monadic value returned by those procedures is a @dfn{service | |
6038 | definition}---a structure as returned by the @code{service} form. | |
6039 | Service definitions specifies the inputs the service depends on, and an | |
6040 | expression to start and stop the service. Behind the scenes, service | |
6041 | definitions are ``translated'' into the form suitable for the | |
6042 | configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU | |
6043 | dmd Manual}). | |
8451a568 | 6044 | |
cf4a9129 LC |
6045 | As an example, here is what the @code{nscd-service} procedure looks |
6046 | like: | |
8451a568 | 6047 | |
cf4a9129 LC |
6048 | @lisp |
6049 | (define (nscd-service) | |
6050 | (with-monad %store-monad | |
6051 | (return (service | |
6052 | (documentation "Run libc's name service cache daemon.") | |
6053 | (provision '(nscd)) | |
6054 | (activate #~(begin | |
6055 | (use-modules (guix build utils)) | |
6056 | (mkdir-p "/var/run/nscd"))) | |
6057 | (start #~(make-forkexec-constructor | |
6058 | (string-append #$glibc "/sbin/nscd") | |
6059 | "-f" "/dev/null" "--foreground")) | |
6060 | (stop #~(make-kill-destructor)) | |
6061 | (respawn? #f))))) | |
6062 | @end lisp | |
8451a568 | 6063 | |
cf4a9129 LC |
6064 | @noindent |
6065 | The @code{activate}, @code{start}, and @code{stop} fields are G-expressions | |
6066 | (@pxref{G-Expressions}). The @code{activate} field contains a script to | |
6067 | run at ``activation'' time; it makes sure that the @file{/var/run/nscd} | |
6068 | directory exists before @command{nscd} is started. | |
8451a568 | 6069 | |
cf4a9129 LC |
6070 | The @code{start} and @code{stop} fields refer to dmd's facilities to |
6071 | start and stop processes (@pxref{Service De- and Constructors,,, dmd, | |
6072 | GNU dmd Manual}). The @code{provision} field specifies the name under | |
6073 | which this service is known to dmd, and @code{documentation} specifies | |
6074 | on-line documentation. Thus, the commands @command{deco start ncsd}, | |
6075 | @command{deco stop nscd}, and @command{deco doc nscd} will do what you | |
6076 | would expect (@pxref{Invoking deco,,, dmd, GNU dmd Manual}). | |
8451a568 | 6077 | |
8451a568 | 6078 | |
cf4a9129 LC |
6079 | @node Installing Debugging Files |
6080 | @section Installing Debugging Files | |
8451a568 | 6081 | |
cf4a9129 LC |
6082 | @cindex debugging files |
6083 | Program binaries, as produced by the GCC compilers for instance, are | |
6084 | typically written in the ELF format, with a section containing | |
6085 | @dfn{debugging information}. Debugging information is what allows the | |
6086 | debugger, GDB, to map binary code to source code; it is required to | |
6087 | debug a compiled program in good conditions. | |
8451a568 | 6088 | |
cf4a9129 LC |
6089 | The problem with debugging information is that is takes up a fair amount |
6090 | of disk space. For example, debugging information for the GNU C Library | |
6091 | weighs in at more than 60 MiB. Thus, as a user, keeping all the | |
6092 | debugging info of all the installed programs is usually not an option. | |
6093 | Yet, space savings should not come at the cost of an impediment to | |
6094 | debugging---especially in the GNU system, which should make it easier | |
6095 | for users to exert their computing freedom (@pxref{GNU Distribution}). | |
8451a568 | 6096 | |
cf4a9129 LC |
6097 | Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a |
6098 | mechanism that allows users to get the best of both worlds: debugging | |
6099 | information can be stripped from the binaries and stored in separate | |
6100 | files. GDB is then able to load debugging information from those files, | |
6101 | when they are available (@pxref{Separate Debug Files,,, gdb, Debugging | |
6102 | with GDB}). | |
8451a568 | 6103 | |
cf4a9129 LC |
6104 | The GNU distribution takes advantage of this by storing debugging |
6105 | information in the @code{lib/debug} sub-directory of a separate package | |
6106 | output unimaginatively called @code{debug} (@pxref{Packages with | |
6107 | Multiple Outputs}). Users can choose to install the @code{debug} output | |
6108 | of a package when they need it. For instance, the following command | |
6109 | installs the debugging information for the GNU C Library and for GNU | |
6110 | Guile: | |
8451a568 LC |
6111 | |
6112 | @example | |
cf4a9129 | 6113 | guix package -i glibc:debug guile:debug |
8451a568 LC |
6114 | @end example |
6115 | ||
cf4a9129 LC |
6116 | GDB must then be told to look for debug files in the user's profile, by |
6117 | setting the @code{debug-file-directory} variable (consider setting it | |
6118 | from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with | |
6119 | GDB}): | |
8451a568 | 6120 | |
cf4a9129 LC |
6121 | @example |
6122 | (gdb) set debug-file-directory ~/.guix-profile/lib/debug | |
6123 | @end example | |
8451a568 | 6124 | |
cf4a9129 LC |
6125 | From there on, GDB will pick up debugging information from the |
6126 | @code{.debug} files under @file{~/.guix-profile/lib/debug}. | |
8451a568 | 6127 | |
cf4a9129 LC |
6128 | In addition, you will most likely want GDB to be able to show the source |
6129 | code being debugged. To do that, you will have to unpack the source | |
6130 | code of the package of interest (obtained with @code{guix build | |
6131 | --source}, @pxref{Invoking guix build}), and to point GDB to that source | |
6132 | directory using the @code{directory} command (@pxref{Source Path, | |
6133 | @code{directory},, gdb, Debugging with GDB}). | |
8451a568 | 6134 | |
cf4a9129 LC |
6135 | @c XXX: keep me up-to-date |
6136 | The @code{debug} output mechanism in Guix is implemented by the | |
6137 | @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is | |
6138 | opt-in---debugging information is available only for those packages | |
6139 | whose definition explicitly declares a @code{debug} output. This may be | |
6140 | changed to opt-out in the future, if our build farm servers can handle | |
6141 | the load. To check whether a package has a @code{debug} output, use | |
6142 | @command{guix package --list-available} (@pxref{Invoking guix package}). | |
8451a568 | 6143 | |
8451a568 | 6144 | |
05962f29 LC |
6145 | @node Security Updates |
6146 | @section Security Updates | |
6147 | ||
843858b8 LC |
6148 | @quotation Note |
6149 | As of version @value{VERSION}, the feature described in this section is | |
6150 | experimental. | |
6151 | @end quotation | |
05962f29 LC |
6152 | |
6153 | @cindex security updates | |
6154 | Occasionally, important security vulnerabilities are discovered in core | |
6155 | software packages and must be patched. Guix follows a functional | |
6156 | package management discipline (@pxref{Introduction}), which implies | |
6157 | that, when a package is changed, @emph{every package that depends on it} | |
6158 | must be rebuilt. This can significantly slow down the deployment of | |
6159 | fixes in core packages such as libc or Bash, since basically the whole | |
6160 | distribution would need to be rebuilt. Using pre-built binaries helps | |
6161 | (@pxref{Substitutes}), but deployment may still take more time than | |
6162 | desired. | |
6163 | ||
6164 | @cindex grafts | |
6165 | To address that, Guix implements @dfn{grafts}, a mechanism that allows | |
6166 | for fast deployment of critical updates without the costs associated | |
6167 | with a whole-distribution rebuild. The idea is to rebuild only the | |
6168 | package that needs to be patched, and then to ``graft'' it onto packages | |
6169 | explicitly installed by the user and that were previously referring to | |
6170 | the original package. The cost of grafting is typically very low, and | |
6171 | order of magnitudes lower than a full rebuild of the dependency chain. | |
6172 | ||
6173 | @cindex replacements of packages, for grafts | |
6174 | For instance, suppose a security update needs to be applied to Bash. | |
6175 | Guix developers will provide a package definition for the ``fixed'' | |
6176 | Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining | |
6177 | Packages}). Then, the original package definition is augmented with a | |
6178 | @code{replacement} field pointing to the package containing the bug fix: | |
6179 | ||
6180 | @example | |
6181 | (define bash | |
6182 | (package | |
6183 | (name "bash") | |
6184 | ;; @dots{} | |
6185 | (replacement bash-fixed))) | |
6186 | @end example | |
6187 | ||
6188 | From there on, any package depending directly or indirectly on Bash that | |
6189 | is installed will automatically be ``rewritten'' to refer to | |
6190 | @var{bash-fixed} instead of @var{bash}. This grafting process takes | |
6191 | time proportional to the size of the package, but expect less than a | |
6192 | minute for an ``average'' package on a recent machine. | |
6193 | ||
6194 | Currently, the graft and the package it replaces (@var{bash-fixed} and | |
6195 | @var{bash} in the example above) must have the exact same @code{name} | |
6196 | and @code{version} fields. This restriction mostly comes from the fact | |
6197 | that grafting works by patching files, including binary files, directly. | |
6198 | Other restrictions may apply: for instance, when adding a graft to a | |
6199 | package providing a shared library, the original shared library and its | |
6200 | replacement must have the same @code{SONAME} and be binary-compatible. | |
6201 | ||
6202 | ||
cf4a9129 LC |
6203 | @node Package Modules |
6204 | @section Package Modules | |
8451a568 | 6205 | |
cf4a9129 LC |
6206 | From a programming viewpoint, the package definitions of the |
6207 | GNU distribution are provided by Guile modules in the @code{(gnu packages | |
6208 | @dots{})} name space@footnote{Note that packages under the @code{(gnu | |
6209 | packages @dots{})} module name space are not necessarily ``GNU | |
6210 | packages''. This module naming scheme follows the usual Guile module | |
6211 | naming convention: @code{gnu} means that these modules are distributed | |
6212 | as part of the GNU system, and @code{packages} identifies modules that | |
6213 | define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile | |
6214 | Reference Manual}). For instance, the @code{(gnu packages emacs)} | |
6215 | module exports a variable named @code{emacs}, which is bound to a | |
6216 | @code{<package>} object (@pxref{Defining Packages}). | |
113daf62 | 6217 | |
300868ba | 6218 | The @code{(gnu packages @dots{})} module name space is |
cf4a9129 LC |
6219 | automatically scanned for packages by the command-line tools. For |
6220 | instance, when running @code{guix package -i emacs}, all the @code{(gnu | |
6221 | packages @dots{})} modules are scanned until one that exports a package | |
6222 | object whose name is @code{emacs} is found. This package search | |
6223 | facility is implemented in the @code{(gnu packages)} module. | |
113daf62 | 6224 | |
300868ba | 6225 | @cindex customization, of packages |
8689901f | 6226 | @cindex package module search path |
cf4a9129 | 6227 | Users can store package definitions in modules with different |
60142854 | 6228 | names---e.g., @code{(my-packages emacs)}@footnote{Note that the file |
c95ded7e LC |
6229 | name and module name must match. For instance, the @code{(my-packages |
6230 | emacs)} module must be stored in a @file{my-packages/emacs.scm} file | |
6231 | relative to the load path specified with @option{--load-path} or | |
6232 | @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,, | |
6233 | guile, GNU Guile Reference Manual}, for details.}. These package definitions | |
300868ba LC |
6234 | will not be visible by default. Thus, users can invoke commands such as |
6235 | @command{guix package} and @command{guix build} have to be used with the | |
c95ded7e LC |
6236 | @code{-e} option so that they know where to find the package. Better |
6237 | yet, they can use the | |
300868ba | 6238 | @code{-L} option of these commands to make those modules visible |
8689901f LC |
6239 | (@pxref{Invoking guix build, @code{--load-path}}), or define the |
6240 | @code{GUIX_PACKAGE_PATH} environment variable. This environment | |
6241 | variable makes it easy to extend or customize the distribution and is | |
6242 | honored by all the user interfaces. | |
6243 | ||
6244 | @defvr {Environment Variable} GUIX_PACKAGE_PATH | |
6245 | This is a colon-separated list of directories to search for package | |
6246 | modules. Directories listed in this variable take precedence over the | |
6247 | distribution's own modules. | |
6248 | @end defvr | |
ef5dd60a | 6249 | |
cf4a9129 LC |
6250 | The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}: |
6251 | each package is built based solely on other packages in the | |
6252 | distribution. The root of this dependency graph is a small set of | |
6253 | @dfn{bootstrap binaries}, provided by the @code{(gnu packages | |
6254 | bootstrap)} module. For more information on bootstrapping, | |
081145cf | 6255 | @pxref{Bootstrapping}. |
ef5dd60a | 6256 | |
cf4a9129 LC |
6257 | @node Packaging Guidelines |
6258 | @section Packaging Guidelines | |
ef5dd60a | 6259 | |
cf4a9129 LC |
6260 | The GNU distribution is nascent and may well lack some of your favorite |
6261 | packages. This section describes how you can help make the distribution | |
6262 | grow. @xref{Contributing}, for additional information on how you can | |
6263 | help. | |
ef5dd60a | 6264 | |
cf4a9129 LC |
6265 | Free software packages are usually distributed in the form of |
6266 | @dfn{source code tarballs}---typically @file{tar.gz} files that contain | |
6267 | all the source files. Adding a package to the distribution means | |
6268 | essentially two things: adding a @dfn{recipe} that describes how to | |
6269 | build the package, including a list of other packages required to build | |
6270 | it, and adding @dfn{package meta-data} along with that recipe, such as a | |
6271 | description and licensing information. | |
ef5dd60a | 6272 | |
cf4a9129 LC |
6273 | In Guix all this information is embodied in @dfn{package definitions}. |
6274 | Package definitions provide a high-level view of the package. They are | |
6275 | written using the syntax of the Scheme programming language; in fact, | |
6276 | for each package we define a variable bound to the package definition, | |
6277 | and export that variable from a module (@pxref{Package Modules}). | |
6278 | However, in-depth Scheme knowledge is @emph{not} a prerequisite for | |
6279 | creating packages. For more information on package definitions, | |
081145cf | 6280 | @pxref{Defining Packages}. |
ef5dd60a | 6281 | |
cf4a9129 LC |
6282 | Once a package definition is in place, stored in a file in the Guix |
6283 | source tree, it can be tested using the @command{guix build} command | |
6284 | (@pxref{Invoking guix build}). For example, assuming the new package is | |
c71979f4 LC |
6285 | called @code{gnew}, you may run this command from the Guix build tree |
6286 | (@pxref{Running Guix Before It Is Installed}): | |
ef5dd60a LC |
6287 | |
6288 | @example | |
cf4a9129 | 6289 | ./pre-inst-env guix build gnew --keep-failed |
ef5dd60a | 6290 | @end example |
ef5dd60a | 6291 | |
cf4a9129 LC |
6292 | Using @code{--keep-failed} makes it easier to debug build failures since |
6293 | it provides access to the failed build tree. Another useful | |
6294 | command-line option when debugging is @code{--log-file}, to access the | |
6295 | build log. | |
ef5dd60a | 6296 | |
cf4a9129 LC |
6297 | If the package is unknown to the @command{guix} command, it may be that |
6298 | the source file contains a syntax error, or lacks a @code{define-public} | |
6299 | clause to export the package variable. To figure it out, you may load | |
6300 | the module from Guile to get more information about the actual error: | |
ef5dd60a | 6301 | |
cf4a9129 LC |
6302 | @example |
6303 | ./pre-inst-env guile -c '(use-modules (gnu packages gnew))' | |
6304 | @end example | |
ef5dd60a | 6305 | |
cf4a9129 LC |
6306 | Once your package builds correctly, please send us a patch |
6307 | (@pxref{Contributing}). Well, if you need help, we will be happy to | |
6308 | help you too. Once the patch is committed in the Guix repository, the | |
6309 | new package automatically gets built on the supported platforms by | |
2b1cee21 | 6310 | @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration |
cf4a9129 | 6311 | system}. |
ef5dd60a | 6312 | |
cf4a9129 LC |
6313 | @cindex substituter |
6314 | Users can obtain the new package definition simply by running | |
6315 | @command{guix pull} (@pxref{Invoking guix pull}). When | |
6316 | @code{hydra.gnu.org} is done building the package, installing the | |
6317 | package automatically downloads binaries from there | |
6318 | (@pxref{Substitutes}). The only place where human intervention is | |
6319 | needed is to review and apply the patch. | |
ef5dd60a | 6320 | |
ef5dd60a | 6321 | |
cf4a9129 | 6322 | @menu |
ec0339cd LC |
6323 | * Software Freedom:: What may go into the distribution. |
6324 | * Package Naming:: What's in a name? | |
6325 | * Version Numbers:: When the name is not enough. | |
6326 | * Python Modules:: Taming the snake. | |
6327 | * Perl Modules:: Little pearls. | |
6328 | * Fonts:: Fond of fonts. | |
cf4a9129 | 6329 | @end menu |
ef5dd60a | 6330 | |
cf4a9129 LC |
6331 | @node Software Freedom |
6332 | @subsection Software Freedom | |
ef5dd60a | 6333 | |
cf4a9129 | 6334 | @c Adapted from http://www.gnu.org/philosophy/philosophy.html. |
c11a6eb1 | 6335 | |
cf4a9129 LC |
6336 | The GNU operating system has been developed so that users can have |
6337 | freedom in their computing. GNU is @dfn{free software}, meaning that | |
6338 | users have the @url{http://www.gnu.org/philosophy/free-sw.html,four | |
6339 | essential freedoms}: to run the program, to study and change the program | |
6340 | in source code form, to redistribute exact copies, and to distribute | |
6341 | modified versions. Packages found in the GNU distribution provide only | |
6342 | software that conveys these four freedoms. | |
c11a6eb1 | 6343 | |
cf4a9129 LC |
6344 | In addition, the GNU distribution follow the |
6345 | @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free | |
6346 | software distribution guidelines}. Among other things, these guidelines | |
6347 | reject non-free firmware, recommendations of non-free software, and | |
6348 | discuss ways to deal with trademarks and patents. | |
ef5dd60a | 6349 | |
cf4a9129 LC |
6350 | Some packages contain a small and optional subset that violates the |
6351 | above guidelines, for instance because this subset is itself non-free | |
6352 | code. When that happens, the offending items are removed with | |
6353 | appropriate patches or code snippets in the package definition's | |
6354 | @code{origin} form (@pxref{Defining Packages}). That way, @code{guix | |
6355 | build --source} returns the ``freed'' source rather than the unmodified | |
6356 | upstream source. | |
ef5dd60a | 6357 | |
ef5dd60a | 6358 | |
cf4a9129 LC |
6359 | @node Package Naming |
6360 | @subsection Package Naming | |
ef5dd60a | 6361 | |
cf4a9129 LC |
6362 | A package has actually two names associated with it: |
6363 | First, there is the name of the @emph{Scheme variable}, the one following | |
6364 | @code{define-public}. By this name, the package can be made known in the | |
6365 | Scheme code, for instance as input to another package. Second, there is | |
6366 | the string in the @code{name} field of a package definition. This name | |
6367 | is used by package management commands such as | |
6368 | @command{guix package} and @command{guix build}. | |
ef5dd60a | 6369 | |
cf4a9129 LC |
6370 | Both are usually the same and correspond to the lowercase conversion of |
6371 | the project name chosen upstream, with underscores replaced with | |
6372 | hyphens. For instance, GNUnet is available as @code{gnunet}, and | |
6373 | SDL_net as @code{sdl-net}. | |
927097ef | 6374 | |
cf4a9129 | 6375 | We do not add @code{lib} prefixes for library packages, unless these are |
081145cf | 6376 | already part of the official project name. But @pxref{Python |
cf4a9129 LC |
6377 | Modules} and @ref{Perl Modules} for special rules concerning modules for |
6378 | the Python and Perl languages. | |
927097ef | 6379 | |
1b366ee4 | 6380 | Font package names are handled differently, @pxref{Fonts}. |
7fec52b7 | 6381 | |
ef5dd60a | 6382 | |
cf4a9129 LC |
6383 | @node Version Numbers |
6384 | @subsection Version Numbers | |
ef5dd60a | 6385 | |
cf4a9129 LC |
6386 | We usually package only the latest version of a given free software |
6387 | project. But sometimes, for instance for incompatible library versions, | |
6388 | two (or more) versions of the same package are needed. These require | |
6389 | different Scheme variable names. We use the name as defined | |
6390 | in @ref{Package Naming} | |
6391 | for the most recent version; previous versions use the same name, suffixed | |
6392 | by @code{-} and the smallest prefix of the version number that may | |
6393 | distinguish the two versions. | |
ef5dd60a | 6394 | |
cf4a9129 LC |
6395 | The name inside the package definition is the same for all versions of a |
6396 | package and does not contain any version number. | |
ef5dd60a | 6397 | |
cf4a9129 | 6398 | For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows: |
ef5dd60a | 6399 | |
cf4a9129 LC |
6400 | @example |
6401 | (define-public gtk+ | |
6402 | (package | |
6403 | (name "gtk+") | |
6404 | (version "3.9.12") | |
6405 | ...)) | |
6406 | (define-public gtk+-2 | |
6407 | (package | |
6408 | (name "gtk+") | |
6409 | (version "2.24.20") | |
6410 | ...)) | |
6411 | @end example | |
6412 | If we also wanted GTK+ 3.8.2, this would be packaged as | |
6413 | @example | |
6414 | (define-public gtk+-3.8 | |
6415 | (package | |
6416 | (name "gtk+") | |
6417 | (version "3.8.2") | |
6418 | ...)) | |
6419 | @end example | |
ef5dd60a | 6420 | |
ef5dd60a | 6421 | |
cf4a9129 LC |
6422 | @node Python Modules |
6423 | @subsection Python Modules | |
ef5dd60a | 6424 | |
cf4a9129 LC |
6425 | We currently package Python 2 and Python 3, under the Scheme variable names |
6426 | @code{python-2} and @code{python} as explained in @ref{Version Numbers}. | |
6427 | To avoid confusion and naming clashes with other programming languages, it | |
6428 | seems desirable that the name of a package for a Python module contains | |
6429 | the word @code{python}. | |
ef5dd60a | 6430 | |
cf4a9129 LC |
6431 | Some modules are compatible with only one version of Python, others with both. |
6432 | If the package Foo compiles only with Python 3, we name it | |
6433 | @code{python-foo}; if it compiles only with Python 2, we name it | |
6434 | @code{python2-foo}. If it is compatible with both versions, we create two | |
6435 | packages with the corresponding names. | |
ef5dd60a | 6436 | |
cf4a9129 LC |
6437 | If a project already contains the word @code{python}, we drop this; |
6438 | for instance, the module python-dateutil is packaged under the names | |
6439 | @code{python-dateutil} and @code{python2-dateutil}. | |
113daf62 | 6440 | |
523e4896 | 6441 | |
cf4a9129 LC |
6442 | @node Perl Modules |
6443 | @subsection Perl Modules | |
523e4896 | 6444 | |
cf4a9129 LC |
6445 | Perl programs standing for themselves are named as any other package, |
6446 | using the lowercase upstream name. | |
6447 | For Perl packages containing a single class, we use the lowercase class name, | |
6448 | replace all occurrences of @code{::} by dashes and prepend the prefix | |
6449 | @code{perl-}. | |
6450 | So the class @code{XML::Parser} becomes @code{perl-xml-parser}. | |
6451 | Modules containing several classes keep their lowercase upstream name and | |
6452 | are also prepended by @code{perl-}. Such modules tend to have the word | |
6453 | @code{perl} somewhere in their name, which gets dropped in favor of the | |
6454 | prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}. | |
523e4896 | 6455 | |
523e4896 | 6456 | |
7fec52b7 AE |
6457 | @node Fonts |
6458 | @subsection Fonts | |
6459 | ||
6460 | For fonts that are in general not installed by a user for typesetting | |
6461 | purposes, or that are distributed as part of a larger software package, | |
6462 | we rely on the general packaging rules for software; for instance, this | |
6463 | applies to the fonts delivered as part of the X.Org system or fonts that | |
6464 | are part of TeX Live. | |
6465 | ||
6466 | To make it easier for a user to search for fonts, names for other packages | |
6467 | containing only fonts are constructed as follows, independently of the | |
6468 | upstream package name. | |
6469 | ||
6470 | The name of a package containing only one font family starts with | |
6471 | @code{font-}; it is followed by the foundry name and a dash @code{-} | |
6472 | if the foundry is known, and the font family name, in which spaces are | |
6473 | replaced by dashes (and as usual, all upper case letters are transformed | |
6474 | to lower case). | |
6475 | For example, the Gentium font family by SIL is packaged under the name | |
6476 | @code{font-sil-gentium}. | |
6477 | ||
6478 | For a package containing several font families, the name of the collection | |
6479 | is used in the place of the font family name. | |
6480 | For instance, the Liberation fonts consist of three families, | |
6481 | Liberation Sans, Liberation Serif and Liberation Mono. | |
6482 | These could be packaged separately under the names | |
6483 | @code{font-liberation-sans} and so on; but as they are distributed together | |
6484 | under a common name, we prefer to package them together as | |
6485 | @code{font-liberation}. | |
6486 | ||
6487 | In the case where several formats of the same font family or font collection | |
6488 | are packaged separately, a short form of the format, prepended by a dash, | |
6489 | is added to the package name. We use @code{-ttf} for TrueType fonts, | |
1b366ee4 | 6490 | @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1 |
7fec52b7 AE |
6491 | fonts. |
6492 | ||
6493 | ||
b25937e3 | 6494 | |
cf4a9129 LC |
6495 | @node Bootstrapping |
6496 | @section Bootstrapping | |
b25937e3 | 6497 | |
cf4a9129 | 6498 | @c Adapted from the ELS 2013 paper. |
b25937e3 | 6499 | |
cf4a9129 | 6500 | @cindex bootstrapping |
7889394e | 6501 | |
cf4a9129 LC |
6502 | Bootstrapping in our context refers to how the distribution gets built |
6503 | ``from nothing''. Remember that the build environment of a derivation | |
6504 | contains nothing but its declared inputs (@pxref{Introduction}). So | |
6505 | there's an obvious chicken-and-egg problem: how does the first package | |
6506 | get built? How does the first compiler get compiled? Note that this is | |
6507 | a question of interest only to the curious hacker, not to the regular | |
6508 | user, so you can shamelessly skip this section if you consider yourself | |
6509 | a ``regular user''. | |
72b9d60d | 6510 | |
cf4a9129 LC |
6511 | @cindex bootstrap binaries |
6512 | The GNU system is primarily made of C code, with libc at its core. The | |
6513 | GNU build system itself assumes the availability of a Bourne shell and | |
6514 | command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and | |
6515 | `grep'. Furthermore, build programs---programs that run | |
6516 | @code{./configure}, @code{make}, etc.---are written in Guile Scheme | |
6517 | (@pxref{Derivations}). Consequently, to be able to build anything at | |
6518 | all, from scratch, Guix relies on pre-built binaries of Guile, GCC, | |
6519 | Binutils, libc, and the other packages mentioned above---the | |
6520 | @dfn{bootstrap binaries}. | |
72b9d60d | 6521 | |
cf4a9129 LC |
6522 | These bootstrap binaries are ``taken for granted'', though we can also |
6523 | re-create them if needed (more on that later). | |
72b9d60d | 6524 | |
cf4a9129 | 6525 | @unnumberedsubsec Preparing to Use the Bootstrap Binaries |
c79d54fe | 6526 | |
cf4a9129 LC |
6527 | @c As of Emacs 24.3, Info-mode displays the image, but since it's a |
6528 | @c large image, it's hard to scroll. Oh well. | |
6529 | @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations} | |
523e4896 | 6530 | |
cf4a9129 LC |
6531 | The figure above shows the very beginning of the dependency graph of the |
6532 | distribution, corresponding to the package definitions of the @code{(gnu | |
6533 | packages bootstrap)} module. At this level of detail, things are | |
6534 | slightly complex. First, Guile itself consists of an ELF executable, | |
6535 | along with many source and compiled Scheme files that are dynamically | |
6536 | loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz} | |
6537 | tarball shown in this graph. This tarball is part of Guix's ``source'' | |
6538 | distribution, and gets inserted into the store with @code{add-to-store} | |
6539 | (@pxref{The Store}). | |
2e7b5cea | 6540 | |
cf4a9129 LC |
6541 | But how do we write a derivation that unpacks this tarball and adds it |
6542 | to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv} | |
6543 | derivation---the first one that gets built---uses @code{bash} as its | |
6544 | builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls | |
6545 | @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar}, | |
6546 | @file{xz}, and @file{mkdir} are statically-linked binaries, also part of | |
6547 | the Guix source distribution, whose sole purpose is to allow the Guile | |
6548 | tarball to be unpacked. | |
fb729425 | 6549 | |
cf4a9129 LC |
6550 | Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning |
6551 | Guile that can be used to run subsequent build programs. Its first task | |
6552 | is to download tarballs containing the other pre-built binaries---this | |
6553 | is what the @code{.tar.xz.drv} derivations do. Guix modules such as | |
6554 | @code{ftp-client.scm} are used for this purpose. The | |
6555 | @code{module-import.drv} derivations import those modules in a directory | |
6556 | in the store, using the original layout. The | |
6557 | @code{module-import-compiled.drv} derivations compile those modules, and | |
6558 | write them in an output directory with the right layout. This | |
6559 | corresponds to the @code{#:modules} argument of | |
6560 | @code{build-expression->derivation} (@pxref{Derivations}). | |
fb729425 | 6561 | |
cf4a9129 LC |
6562 | Finally, the various tarballs are unpacked by the |
6563 | derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv}, | |
6564 | etc., at which point we have a working C tool chain. | |
fb729425 | 6565 | |
fb729425 | 6566 | |
cf4a9129 | 6567 | @unnumberedsubsec Building the Build Tools |
523e4896 | 6568 | |
cf4a9129 LC |
6569 | @c TODO: Add a package-level dependency graph generated from (gnu |
6570 | @c packages base). | |
df2ce343 | 6571 | |
cf4a9129 LC |
6572 | Bootstrapping is complete when we have a full tool chain that does not |
6573 | depend on the pre-built bootstrap tools discussed above. This | |
6574 | no-dependency requirement is verified by checking whether the files of | |
6575 | the final tool chain contain references to the @file{/gnu/store} | |
6576 | directories of the bootstrap inputs. The process that leads to this | |
6577 | ``final'' tool chain is described by the package definitions found in | |
1f6f57df | 6578 | the @code{(gnu packages commencement)} module. |
df2ce343 | 6579 | |
cf4a9129 LC |
6580 | @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>. |
6581 | The first tool that gets built with the bootstrap binaries is | |
6582 | GNU Make, which is a prerequisite for all the following packages. | |
6583 | From there Findutils and Diffutils get built. | |
523e4896 | 6584 | |
cf4a9129 LC |
6585 | Then come the first-stage Binutils and GCC, built as pseudo cross |
6586 | tools---i.e., with @code{--target} equal to @code{--host}. They are | |
6587 | used to build libc. Thanks to this cross-build trick, this libc is | |
6588 | guaranteed not to hold any reference to the initial tool chain. | |
4af2447e | 6589 | |
cf4a9129 LC |
6590 | From there the final Binutils and GCC are built. GCC uses @code{ld} |
6591 | from the final Binutils, and links programs against the just-built libc. | |
6592 | This tool chain is used to build the other packages used by Guix and by | |
6593 | the GNU Build System: Guile, Bash, Coreutils, etc. | |
4af2447e | 6594 | |
cf4a9129 LC |
6595 | And voilà! At this point we have the complete set of build tools that |
6596 | the GNU Build System expects. These are in the @code{%final-inputs} | |
dd164244 MW |
6597 | variable of the @code{(gnu packages commencement)} module, and are |
6598 | implicitly used by any package that uses @code{gnu-build-system} | |
1f6f57df | 6599 | (@pxref{Build Systems, @code{gnu-build-system}}). |
4af2447e | 6600 | |
4af2447e | 6601 | |
cf4a9129 | 6602 | @unnumberedsubsec Building the Bootstrap Binaries |
4af2447e | 6603 | |
cf4a9129 LC |
6604 | Because the final tool chain does not depend on the bootstrap binaries, |
6605 | those rarely need to be updated. Nevertheless, it is useful to have an | |
6606 | automated way to produce them, should an update occur, and this is what | |
6607 | the @code{(gnu packages make-bootstrap)} module provides. | |
4af2447e | 6608 | |
cf4a9129 LC |
6609 | The following command builds the tarballs containing the bootstrap |
6610 | binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture | |
6611 | of Coreutils and other basic command-line tools): | |
4b2615e1 | 6612 | |
cf4a9129 LC |
6613 | @example |
6614 | guix build bootstrap-tarballs | |
6615 | @end example | |
6616 | ||
6617 | The generated tarballs are those that should be referred to in the | |
6618 | @code{(gnu packages bootstrap)} module mentioned at the beginning of | |
6619 | this section. | |
6620 | ||
6621 | Still here? Then perhaps by now you've started to wonder: when do we | |
6622 | reach a fixed point? That is an interesting question! The answer is | |
6623 | unknown, but if you would like to investigate further (and have | |
6624 | significant computational and storage resources to do so), then let us | |
6625 | know. | |
6626 | ||
6627 | @node Porting | |
6628 | @section Porting to a New Platform | |
6629 | ||
6630 | As discussed above, the GNU distribution is self-contained, and | |
6631 | self-containment is achieved by relying on pre-built ``bootstrap | |
6632 | binaries'' (@pxref{Bootstrapping}). These binaries are specific to an | |
6633 | operating system kernel, CPU architecture, and application binary | |
6634 | interface (ABI). Thus, to port the distribution to a platform that is | |
6635 | not yet supported, one must build those bootstrap binaries, and update | |
6636 | the @code{(gnu packages bootstrap)} module to use them on that platform. | |
6637 | ||
6638 | Fortunately, Guix can @emph{cross compile} those bootstrap binaries. | |
6639 | When everything goes well, and assuming the GNU tool chain supports the | |
6640 | target platform, this can be as simple as running a command like this | |
6641 | one: | |
6642 | ||
6643 | @example | |
6644 | guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs | |
6645 | @end example | |
6646 | ||
1c0c417d LC |
6647 | For this to work, the @code{glibc-dynamic-linker} procedure in |
6648 | @code{(gnu packages bootstrap)} must be augmented to return the right | |
6649 | file name for libc's dynamic linker on that platform; likewise, | |
6650 | @code{system->linux-architecture} in @code{(gnu packages linux)} must be | |
6651 | taught about the new platform. | |
6652 | ||
cf4a9129 | 6653 | Once these are built, the @code{(gnu packages bootstrap)} module needs |
1c0c417d LC |
6654 | to be updated to refer to these binaries on the target platform. That |
6655 | is, the hashes and URLs of the bootstrap tarballs for the new platform | |
6656 | must be added alongside those of the currently supported platforms. The | |
6657 | bootstrap Guile tarball is treated specially: it is expected to be | |
6658 | available locally, and @file{gnu-system.am} has rules do download it for | |
6659 | the supported architectures; a rule for the new platform must be added | |
6660 | as well. | |
cf4a9129 LC |
6661 | |
6662 | In practice, there may be some complications. First, it may be that the | |
6663 | extended GNU triplet that specifies an ABI (like the @code{eabi} suffix | |
6664 | above) is not recognized by all the GNU tools. Typically, glibc | |
6665 | recognizes some of these, whereas GCC uses an extra @code{--with-abi} | |
6666 | configure flag (see @code{gcc.scm} for examples of how to handle this). | |
6667 | Second, some of the required packages could fail to build for that | |
6668 | platform. Lastly, the generated binaries could be broken for some | |
6669 | reason. | |
4af2447e LC |
6670 | |
6671 | ||
9bf3c1a7 LC |
6672 | @c ********************************************************************* |
6673 | @node Contributing | |
6674 | @chapter Contributing | |
6675 | ||
6676 | This project is a cooperative effort, and we need your help to make it | |
5ff3c4b8 PAR |
6677 | grow! Please get in touch with us on @email{guix-devel@@gnu.org} and |
6678 | @code{#guix} on the Freenode IRC network. We welcome ideas, bug | |
6679 | reports, patches, and anything that may be helpful to the project. We | |
6680 | particularly welcome help on packaging (@pxref{Packaging Guidelines}). | |
a1ba8475 | 6681 | |
9bf3c1a7 LC |
6682 | Please see the |
6683 | @url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING, | |
6684 | @file{HACKING} file} that comes with the Guix source code for practical | |
6685 | details about contributions. | |
6686 | ||
c78bd12b | 6687 | |
568717fd LC |
6688 | @c ********************************************************************* |
6689 | @node Acknowledgments | |
6690 | @chapter Acknowledgments | |
6691 | ||
6692 | Guix is based on the Nix package manager, which was designed and | |
4c7ac9aa LC |
6693 | implemented by Eelco Dolstra, with contributions from other people (see |
6694 | the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package | |
568717fd LC |
6695 | management, and promoted unprecedented features, such as transactional |
6696 | package upgrades and rollbacks, per-user profiles, and referentially | |
6697 | transparent build processes. Without this work, Guix would not exist. | |
6698 | ||
6699 | The Nix-based software distributions, Nixpkgs and NixOS, have also been | |
6700 | an inspiration for Guix. | |
6701 | ||
4c7ac9aa LC |
6702 | GNU@tie{}Guix itself is a collective work with contributions from a |
6703 | number of people. See the @file{AUTHORS} file in Guix for more | |
6704 | information on these fine people. The @file{THANKS} file lists people | |
6705 | who have helped by reporting bugs, taking care of the infrastructure, | |
6706 | providing artwork and themes, making suggestions, and more---thank you! | |
6707 | ||
6708 | ||
568717fd LC |
6709 | @c ********************************************************************* |
6710 | @node GNU Free Documentation License | |
6711 | @appendix GNU Free Documentation License | |
6712 | ||
6713 | @include fdl-1.3.texi | |
6714 | ||
6715 | @c ********************************************************************* | |
6716 | @node Concept Index | |
6717 | @unnumbered Concept Index | |
6718 | @printindex cp | |
6719 | ||
a85b83d2 LC |
6720 | @node Programming Index |
6721 | @unnumbered Programming Index | |
6722 | @syncodeindex tp fn | |
6723 | @syncodeindex vr fn | |
568717fd LC |
6724 | @printindex fn |
6725 | ||
6726 | @bye | |
6727 | ||
6728 | @c Local Variables: | |
6729 | @c ispell-local-dictionary: "american"; | |
6730 | @c End: |