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