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 | |
b22a12fd | 7 | @documentlanguage en |
f8348b91 | 8 | @settitle GNU Guix Reference Manual |
568717fd LC |
9 | @c %**end of header |
10 | ||
11 | @include version.texi | |
58db733e | 12 | @set YEARS 2012, 2013 |
568717fd | 13 | |
eeaf4427 | 14 | @dircategory Package management |
568717fd LC |
15 | @direntry |
16 | * guix: (guix). Guix, the functional package manager. | |
eeaf4427 LC |
17 | * guix-package: (guix)Invoking guix-package |
18 | Managing packages with Guix. | |
568717fd LC |
19 | * guix-build: (guix)Invoking guix-build |
20 | Building packages with Guix. | |
21 | @end direntry | |
568717fd LC |
22 | |
23 | @titlepage | |
f8348b91 LC |
24 | @title{GNU Guix Reference Manual} |
25 | @subtitle{Using the GNU Guix Functional Package Manager} | |
568717fd LC |
26 | @author Ludovic Courtès |
27 | ||
28 | @page | |
29 | @vskip 0pt plus 1filll | |
30 | Edition @value{EDITION} @* | |
31 | @value{UPDATED} @* | |
32 | ||
58db733e | 33 | Copyright @copyright{} @value{YEARS} Ludovic Court@`es |
568717fd LC |
34 | |
35 | @quotation | |
36 | Permission is granted to copy, distribute and/or modify this document | |
37 | under the terms of the GNU Free Documentation License, Version 1.3 or | |
38 | any later version published by the Free Software Foundation; with no | |
39 | Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A | |
40 | copy of the license is included in the section entitled ``GNU Free | |
41 | Documentation License''. | |
42 | @end quotation | |
43 | @end titlepage | |
44 | ||
45 | @copying | |
f8348b91 | 46 | This manual documents GNU Guix version @value{VERSION}. |
568717fd | 47 | |
58db733e | 48 | Copyright @copyright{} @value{YEARS} Ludovic Courtès |
568717fd LC |
49 | |
50 | Permission is granted to copy, distribute and/or modify this document | |
51 | under the terms of the GNU Free Documentation License, Version 1.3 or | |
52 | any later version published by the Free Software Foundation; with no | |
53 | Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A | |
54 | copy of the license is included in the section entitled ``GNU Free | |
55 | Documentation License.'' | |
56 | @end copying | |
57 | ||
58 | @contents | |
59 | ||
60 | @c ********************************************************************* | |
61 | @node Top | |
f8348b91 | 62 | @top GNU Guix |
568717fd | 63 | |
f8348b91 LC |
64 | This document describes GNU Guix version @value{VERSION}, a functional |
65 | package management tool written for the GNU system. | |
568717fd | 66 | |
58db733e LC |
67 | @quotation |
68 | Copyright @copyright{} @value{YEARS} Ludovic Courtès | |
69 | ||
70 | Permission is granted to copy, distribute and/or modify this document | |
71 | under the terms of the GNU Free Documentation License, Version 1.3 or | |
72 | any later version published by the Free Software Foundation; with no | |
73 | Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A | |
74 | copy of the license is included in the section entitled ``GNU Free | |
75 | Documentation License.'' | |
76 | @end quotation | |
77 | ||
568717fd LC |
78 | @menu |
79 | * Introduction:: What is Guix about? | |
bd5e766b | 80 | * Installation:: Installing Guix. |
eeaf4427 | 81 | * Package Management:: Package installation, upgrade, etc. |
568717fd LC |
82 | * Programming Interface:: Using Guix in Scheme. |
83 | * Utilities:: Package management commands. | |
84 | ||
85 | * Acknowledgments:: Thanks! | |
86 | * GNU Free Documentation License:: The license of this manual. | |
87 | * Concept Index:: Concepts. | |
88 | * Function Index:: Functions. | |
89 | @end menu | |
90 | ||
91 | @c ********************************************************************* | |
92 | @node Introduction | |
93 | @chapter Introduction | |
94 | ||
c80e7e55 LC |
95 | GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks'' |
96 | using the international phonetic alphabet (IPA).} is a functional | |
97 | package management tool for the GNU system. Package management consists | |
98 | in all the activities that relate to building packages from source, | |
99 | honoring the build-time and run-time dependencies on packages, | |
100 | installing packages in user environments, upgrading installed packages | |
101 | to new versions or rolling back to a previous set, removing unused | |
102 | software packages, etc. | |
568717fd LC |
103 | |
104 | @cindex functional package management | |
105 | The term @dfn{functional} refers to a specific package management | |
106 | discipline. In Guix, the package build and installation process is seen | |
107 | as a function, in the mathematical sense: that function takes inputs, | |
108 | such as build scripts, a compiler, and libraries depended on, and | |
109 | returns the installed package. As a pure function, its result depends | |
110 | solely on its inputs---for instance, it cannot refer to software or | |
111 | scripts that were not explicitly passed as inputs. A build function | |
112 | always produces the same result when passed a given set of inputs. Last | |
113 | but not least, a build function cannot alter the system's environment in | |
114 | any way; for instance, it cannot create, modify, or delete files outside | |
115 | of its build and installation directories. This is achieved by running | |
116 | build processes in dedicated ``chroots'', where only their explicit | |
117 | inputs are visible. | |
118 | ||
119 | @cindex package store | |
120 | The result of package build functions is @dfn{cached} in the file | |
121 | system, in a special directory called the @dfn{package store}. In | |
122 | practice, each package is installed in a directory of its own, in the | |
123 | store---by default under @file{/nix/store}. The directory name contains | |
124 | a hash of all the inputs used to build that package; thus, changing an | |
125 | input yields a different directory name. | |
126 | ||
127 | This approach is the foundation of Guix's salient features: support for | |
128 | transactional package upgrades and rollback, per-user installation, and | |
eeaf4427 | 129 | garbage collection of packages (@pxref{Features}). |
568717fd LC |
130 | |
131 | Guix has a command-line interface allowing users to build, install, | |
132 | upgrade, and remove packages, as well as a Scheme programming interface. | |
133 | The remainder of this manual describes them. | |
134 | ||
bd5e766b LC |
135 | @c ********************************************************************* |
136 | @node Installation | |
137 | @chapter Installation | |
138 | ||
139 | This section describes the software requirements of Guix, as well as how | |
140 | to install it and get ready to use it. | |
141 | ||
b22a12fd LC |
142 | The build procedure for Guix is the same as for other GNU software, and |
143 | are not covered here. Please see the files @file{README} and | |
144 | @file{INSTALL} in the Guix source tree for additional details. | |
145 | ||
bd5e766b LC |
146 | @menu |
147 | * Requirements:: Software needed to build and run Guix. | |
148 | * Setting Up the Daemon:: Preparing the build daemon's environment. | |
149 | * Invoking guix-daemon:: Running the build daemon. | |
150 | @end menu | |
151 | ||
152 | @node Requirements | |
153 | @section Requirements | |
154 | ||
155 | GNU Guix depends on the following packages: | |
156 | ||
157 | @itemize | |
158 | @item @url{http://gnu.org/software/guile/, GNU Guile 2.0.x}; | |
159 | @item @url{http://gnupg.org/, GNU libgcrypt} | |
160 | @end itemize | |
161 | ||
162 | Unless @code{--disable-daemon} was passed to @command{configure}, the | |
163 | following packages are also needed: | |
164 | ||
165 | @itemize | |
166 | @item @url{http://sqlite.org, SQLite 3} | |
167 | @item @url{http://www.bzip.org, libbz2} | |
168 | @item @url{http://gcc.gnu.org, GCC's g++} | |
169 | @end itemize | |
170 | ||
171 | When a working installation of the Nix package manager is available, you | |
172 | can instead configure Guix with @code{--disable-daemon}. In that case, | |
173 | @url{http://nixos.org/nix/, Nix} replaces the three dependencies above. | |
174 | ||
b22a12fd LC |
175 | Guix is compatible with Nix, so it is possible to share the same store |
176 | between both. To do so, you must pass @command{configure} not only the | |
177 | same @code{--with-store-dir} value, but also the same | |
178 | @code{--localstatedir} value (the latter is essential because it | |
179 | specifies where the database that store meta-data about the store is | |
180 | located, among other things.) The default values are | |
181 | @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}. | |
182 | Note that @code{--disable-daemon} is orthogonal and is not required if | |
183 | your goal is to share the same store as Nix. | |
184 | ||
bd5e766b LC |
185 | @node Setting Up the Daemon |
186 | @section Setting Up the Daemon | |
187 | ||
188 | @cindex daemon | |
189 | Operations such as building a package or running the garbage collector | |
190 | are all performed by a specialized process, the @dfn{Guix daemon}, on | |
191 | behalf of clients. Only the daemon may access the store and its | |
192 | associated database. Thus, any operation that manipulates the store | |
193 | goes through the daemon. For instance, command-line tools such as | |
194 | @command{guix-package} and @command{guix-build} communicate with the | |
195 | daemon (@i{via} remote procedure calls) to instruct it what to do. | |
196 | ||
197 | In a standard multi-user setup, Guix and its daemon---the | |
198 | @command{guix-daemon} program---are installed by the system | |
199 | administrator; @file{/nix/store} is owned by @code{root} and | |
200 | @command{guix-daemon} runs as @code{root}. Unprivileged users may use | |
201 | Guix tools to build packages or otherwise access the store, and the | |
202 | daemon will do it on their behalf, ensuring that the store is kept in a | |
203 | consistent state, and allowing built packages to be shared among users. | |
204 | ||
205 | @cindex build users | |
206 | When @command{guix-daemon} runs as @code{root}, you may not want package | |
207 | build processes themselves to run as @code{root} too, for obvious | |
208 | security reasons. To avoid that, a special pool of @dfn{build users} | |
209 | should be created for use by build processes started by the daemon. | |
210 | These build users need not have a shell and a home directory: they will | |
211 | just be used when the daemon drops @code{root} privileges in build | |
212 | processes. Having several such users allows the daemon to launch | |
213 | distinct build processes under separate UIDs, which guarantees that they | |
214 | do not interfere with each other---an essential feature since builds are | |
215 | regarded as pure functions (@pxref{Introduction}). | |
216 | ||
217 | On a GNU/Linux system, a build user pool may be created like this (using | |
218 | Bash syntax and the @code{shadow} commands): | |
219 | ||
220 | @example | |
221 | # groupadd guix-builder | |
222 | # for i in `seq 1 10`; | |
223 | do | |
224 | useradd -g guix-builder -d /var/empty -s `which nologin` \ | |
80ba8cc0 | 225 | -c "Guix build user $i" guix-builder$i; |
bd5e766b LC |
226 | done |
227 | @end example | |
228 | ||
229 | @noindent | |
230 | The @code{guix-daemon} program may then be run as @code{root} with: | |
231 | ||
232 | @example | |
233 | # guix-daemon --build-users-group=guix-builder | |
234 | @end example | |
235 | ||
236 | Guix may also be used in a single-user setup, with @command{guix-daemon} | |
237 | running as a unprivileged user. However, to maximize non-interference | |
238 | of build processes, the daemon still needs to perform certain operations | |
239 | that are restricted to @code{root} on GNU/Linux: it should be able to | |
240 | run build processes in a chroot, and to run them under different UIDs. | |
241 | To that end, the @command{nix-setuid-helper} program is provided; it is | |
242 | a small C program (less than 300 lines) that, if it is made setuid | |
243 | @code{root}, can be executed by the daemon to perform these operations | |
244 | on its behalf. The @code{root}-owned @file{/etc/nix-setuid.conf} file | |
245 | is read by @command{nix-setuid-helper}; it should contain exactly two | |
246 | words: the user name under which the authorized @command{guix-daemon} | |
247 | runs, and the name of the build users group. | |
248 | ||
249 | If you are installing Guix as an unprivileged user and do not have the | |
250 | ability to make @file{nix-setuid-helper} setuid-@code{root}, it is still | |
251 | possible to run @command{guix-daemon}. However, build processes will | |
252 | not be isolated from one another, and not from the rest of the system. | |
253 | Thus, build processes may interfere with each other, and may access | |
254 | programs, libraries, and other files available on the system---making it | |
255 | much harder to view them as @emph{pure} functions. | |
256 | ||
257 | @node Invoking guix-daemon | |
258 | @section Invoking @command{guix-daemon} | |
259 | ||
260 | The @command{guix-daemon} program implements all the functionality to | |
261 | access the store. This includes launching build processes, running the | |
262 | garbage collector, querying the availability of a build result, etc. It | |
263 | is normally run as @code{root} like this: | |
264 | ||
265 | @example | |
266 | # guix-daemon --build-users-group=guix-builder | |
267 | @end example | |
268 | ||
269 | @noindent | |
270 | For details on how to set it up, @ref{Setting Up the Daemon}. | |
271 | ||
272 | By default, @command{guix-daemon} launches build processes under | |
273 | different UIDs, taken from the build group specified with | |
274 | @code{--build-users-group}. In addition, each build process is run in a | |
275 | chroot environment that only contains the subset of the store that the | |
276 | build process depends on, as specified by its derivation | |
277 | (@pxref{Programming Interface, derivation}), plus a set of specific | |
278 | system directories. By default, the latter contains @file{/dev} and | |
279 | @file{/dev/pts}. | |
280 | ||
281 | The following command-line options are supported: | |
282 | ||
283 | @table @code | |
284 | @item --build-users-group=@var{group} | |
285 | Take users from @var{group} to run build processes (@pxref{Setting Up | |
286 | the Daemon, build users}). | |
287 | ||
288 | @item --cache-failures | |
289 | Cache build failures. By default, only successful builds are cached. | |
290 | ||
291 | @item --cores=@var{n} | |
292 | @itemx -c @var{n} | |
293 | Use @var{n} CPU cores to build each derivation; @code{0} means as many | |
294 | as available. | |
295 | ||
296 | The default value is @code{1}, but it may be overridden by clients, such | |
297 | as the @code{--cores} option of @command{guix-build} (@pxref{Invoking | |
298 | guix-build}). | |
299 | ||
300 | The effect is to define the @code{NIX_BUILD_CORES} environment variable | |
301 | in the build process, which can then use it to exploit internal | |
302 | parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}. | |
303 | ||
304 | @item --max-jobs=@var{n} | |
305 | @itemx -M @var{n} | |
306 | Allow at most @var{n} build jobs in parallel. The default value is | |
307 | @code{1}. | |
308 | ||
309 | @item --debug | |
310 | Produce debugging output. | |
311 | ||
312 | This is useful to debug daemon start-up issues, but then it may be | |
313 | overridden by clients, for example the @code{--verbosity} option of | |
314 | @command{guix-build} (@pxref{Invoking guix-build}). | |
315 | ||
316 | @item --chroot-directory=@var{dir} | |
317 | Add @var{dir} to the build chroot. | |
318 | ||
319 | Doing this may change the result of build processes---for instance if | |
320 | they use optional dependencies found in @var{dir} when it is available, | |
321 | and not otherwise. For that reason, it is not recommended to do so. | |
322 | Instead, make sure that each derivation declares all the inputs that it | |
323 | needs. | |
324 | ||
325 | @item --disable-chroot | |
326 | Disable chroot builds. | |
327 | ||
328 | Using this option is not recommended since, again, it would allow build | |
329 | processes to gain access to undeclared dependencies. | |
330 | ||
331 | @item --disable-log-compression | |
332 | Disable compression of the build logs. | |
333 | ||
334 | @item --disable-store-optimization | |
335 | Disable automatic file ``deduplication'' in the store. | |
336 | ||
337 | @item --impersonate-linux-2.6 | |
338 | On Linux-based systems, impersonate Linux 2.6. This means that the | |
339 | kernel's @code{uname} system call will report 2.6 as the release number. | |
340 | ||
341 | This might be helpful to build programs that (usually wrongfully) depend | |
342 | on the kernel version number. | |
343 | ||
344 | @item --lose-logs | |
345 | Do not keep build logs. By default they are kept under | |
346 | @code{@var{localstatedir}/nix/log}. | |
347 | ||
348 | @item --system=@var{system} | |
349 | Assume @var{system} as the current system type. By default it is the | |
350 | architecture/kernel pair found at configure time, such as | |
351 | @code{x86_64-linux}. | |
352 | @end table | |
353 | ||
354 | ||
eeaf4427 LC |
355 | @c ********************************************************************* |
356 | @node Package Management | |
357 | @chapter Package Management | |
358 | ||
f8348b91 | 359 | The purpose of GNU Guix is to allow users to easily install, upgrade, and |
eeaf4427 LC |
360 | remove software packages, without having to know about their build |
361 | procedure or dependencies. Guix also goes beyond this obvious set of | |
362 | features. | |
363 | ||
364 | This chapter describes the main features of Guix, as well as the package | |
365 | management tools it provides. | |
366 | ||
367 | @menu | |
368 | * Features:: How Guix will make your life brighter. | |
369 | * Invoking guix-package:: Package installation, removal, etc. | |
fe8ff028 | 370 | * Invoking guix-gc:: Running the garbage collector. |
eeaf4427 LC |
371 | @end menu |
372 | ||
373 | @node Features | |
374 | @section Features | |
375 | ||
376 | When using Guix, each package ends up in the @dfn{package store}, in its | |
377 | own directory---something that resembles | |
378 | @file{/nix/store/xxx-package-1.2}, where @code{xxx} is a base32 string. | |
379 | ||
380 | Instead of referring to these directories, users have their own | |
381 | @dfn{profile}, which points to the packages that they actually want to | |
382 | use. That profile is normally stored in @code{$HOME/.guix-profile}, and | |
383 | each user has its own profile. | |
384 | ||
385 | For example, if @code{alice} installed GCC 4.7.2, then | |
386 | @file{/home/alice/.guix-profile/bin/gcc} points to | |
387 | @file{/nix/store/xxx-gcc-4.7.2/bin/gcc}; on the same machine, @code{bob} | |
388 | may have installed GCC 4.8.0, in which case its profile refers to these | |
389 | particular package installation. Both coexist, without any | |
390 | interference. | |
391 | ||
392 | The @command{guix-package} command is the central tool to manage | |
393 | packages. It operates on those per-user profiles, and can be used | |
394 | @emph{with normal user privileges}. | |
395 | ||
396 | The command provides the obvious install, remove, and upgrade | |
397 | operations. Each invocation is actually a @emph{transaction}: either | |
ba55b1cb | 398 | the specified operation succeeds, or nothing happens. Thus, if the |
eeaf4427 LC |
399 | @command{guix-package} processed is terminated during the transaction, |
400 | or if a power outage occurs during the transaction, then the user's | |
401 | profile remains in its previous state, and remains usable. | |
402 | ||
403 | In addition, any package transaction may be @emph{rolled back}. So, if, | |
404 | for example, an upgrade installs a new version of a package that turns | |
405 | out to have a serious bug, users may roll back to the previous instance | |
406 | of their profile, which was known to work well. | |
407 | ||
408 | All those packages in the package store may be @emph{garbage-collected}. | |
409 | Guix can determine which packages are still referenced by the user | |
fe8ff028 LC |
410 | profiles, and remove those that are provably no longer referenced |
411 | (@pxref{Invoking guix-gc}). Users may also explicitly remove old | |
412 | generations of their profile so that the packages they refer to can be | |
413 | collected. | |
eeaf4427 LC |
414 | |
415 | Finally, Guix takes a @dfn{purely functional} approach to package | |
416 | management, as described in the introduction (@pxref{Introduction}). | |
417 | Each @file{/nix/store} package directory name contains a hash of all the | |
418 | inputs that were used to build that package---compiler, libraries, build | |
419 | scripts, etc. This direct correspondence allows users to make sure a | |
420 | given package installation matches the current state of their | |
421 | distribution. | |
422 | ||
423 | This foundation allows Guix to support @dfn{transparent binary/source | |
424 | deployment}. When a pre-built binary for a @file{/nix/store} path is | |
425 | available from an external source, Guix just downloads it; otherwise, it | |
426 | builds the package from source, locally. | |
427 | ||
428 | @node Invoking guix-package | |
429 | @section Invoking @command{guix-package} | |
430 | ||
ba55b1cb | 431 | The @command{guix-package} command is the tool that allows users to |
eeaf4427 LC |
432 | install, upgrade, and remove packages, as well as rolling back to |
433 | previous configurations. It operates only on the user's own profile, | |
434 | and works with normal user privileges (@pxref{Features}). Its syntax | |
435 | is: | |
436 | ||
437 | @example | |
438 | guix-package @var{options} | |
439 | @end example | |
440 | ||
ba55b1cb | 441 | Primarily, @var{options} specifies the operations to be performed during |
eeaf4427 LC |
442 | the transaction. Upon completion, a new profile is created, but |
443 | previous generations of the profile remain available, should the user | |
444 | want to roll back. | |
445 | ||
b9e5c0a9 LC |
446 | For each user, a symlink to the user's default profile is automatically |
447 | created in @file{$HOME/.guix-profile}. This symlink always point to the | |
448 | current generation of the user's default profile. Thus, users can add | |
449 | @file{$HOME/.guix-profile/bin} to their @code{PATH} environment | |
450 | variable, and so on. | |
451 | ||
eeaf4427 LC |
452 | @table @code |
453 | ||
454 | @item --install=@var{package} | |
51c8d790 | 455 | @itemx -i @var{package} |
eeaf4427 LC |
456 | Install @var{package}. |
457 | ||
458 | @var{package} may specify either a simple package name, such as | |
459 | @code{guile}, or a package name followed by a hyphen and version number, | |
bfe384cc | 460 | such as @code{guile-1.8.8}. In addition, @var{package} may contain a |
eeaf4427 | 461 | colon, followed by the name of one of the outputs of the package, as in |
f03e7115 | 462 | @code{gcc:doc} or @code{binutils-2.22:lib}. |
eeaf4427 LC |
463 | |
464 | @item --remove=@var{package} | |
465 | @itemx -r @var{package} | |
466 | Remove @var{package}. | |
467 | ||
ba55b1cb LC |
468 | @item --upgrade=@var{regexp} |
469 | @itemx -u @var{regexp} | |
eeaf4427 LC |
470 | Upgrade all the installed packages matching @var{regexp}. |
471 | ||
472 | @item --profile=@var{profile} | |
473 | @itemx -p @var{profile} | |
474 | Use @var{profile} instead of the user's default profile. | |
475 | ||
476 | @item --dry-run | |
477 | @itemx -n | |
478 | Show what would be done without actually doing it. | |
479 | ||
70915c1a LC |
480 | @item --verbose |
481 | Produce verbose output. In particular, emit the environment's build log | |
482 | on the standard error port. | |
483 | ||
eeaf4427 LC |
484 | @item --bootstrap |
485 | Use the bootstrap Guile to build the profile. This option is only | |
486 | useful to distribution developers. | |
487 | ||
488 | @end table | |
489 | ||
733b4130 LC |
490 | In addition to these actions @command{guix-package} supports the |
491 | following options to query the current state of a profile, or the | |
492 | availability of packages: | |
eeaf4427 | 493 | |
733b4130 LC |
494 | @table @option |
495 | ||
496 | @item --list-installed[=@var{regexp}] | |
497 | @itemx -I [@var{regexp}] | |
498 | List currently installed packages in the specified profile. When | |
499 | @var{regexp} is specified, list only installed packages whose name | |
500 | matches @var{regexp}. | |
501 | ||
502 | For each installed package, print the following items, separated by | |
503 | tabs: the package name, its version string, the part of the package that | |
504 | is installed (for instance, @code{out} for the default output, | |
505 | @code{include} for its headers, etc.), and the path of this package in | |
506 | the store. | |
507 | ||
64fc89b6 LC |
508 | @item --list-available[=@var{regexp}] |
509 | @itemx -A [@var{regexp}] | |
510 | List packages currently available in the software distribution. When | |
511 | @var{regexp} is specified, list only installed packages whose name | |
512 | matches @var{regexp}. | |
513 | ||
514 | For each package, print the following items separated by tabs: its name, | |
44b6be77 LC |
515 | its version string, the parts of the package (@code{out} for the main |
516 | files, @code{lib} for libraries and possibly headers, etc.), and the | |
517 | source location of its definition. | |
64fc89b6 | 518 | |
733b4130 | 519 | @end table |
eeaf4427 LC |
520 | |
521 | ||
fe8ff028 LC |
522 | @node Invoking guix-gc |
523 | @section Invoking @command{guix-gc} | |
524 | ||
525 | @cindex garbage collector | |
526 | Packages that are installed but not used may be @dfn{garbage-collected}. | |
527 | The @command{guix-gc} command allows users to explicitly run the garbage | |
528 | collector to reclaim space from the @file{/nix/store} directory. | |
529 | ||
530 | The garbage collector has a set of known @dfn{roots}: any file under | |
531 | @file{/nix/store} reachable from a root is considered @dfn{live} and | |
532 | cannot be deleted; any other file is considered @dfn{dead} and may be | |
533 | deleted. The set of garbage collector roots includes default user | |
534 | profiles, and may be augmented with @command{guix-build --root}, for | |
535 | example (@pxref{Invoking guix-build}). | |
536 | ||
80ba8cc0 | 537 | The @command{guix-gc} command has three modes of operations: it can be |
fe8ff028 LC |
538 | used to garbage-collect any dead files (the default), to delete specific |
539 | files (the @code{--delete} option), or to print garbage-collector | |
540 | information. The available options are listed below: | |
541 | ||
542 | @table @code | |
543 | @item --collect-garbage[=@var{min}] | |
544 | @itemx -C [@var{min}] | |
545 | Collect garbage---i.e., unreachable @file{/nix/store} files and | |
546 | sub-directories. This is the default operation when no option is | |
547 | specified. | |
548 | ||
549 | When @var{min} is given, stop once @var{min} bytes have been collected. | |
550 | @var{min} may be a number of bytes, or it may include a unit as a | |
551 | suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes. | |
552 | ||
553 | When @var{min} is omitted, collect all the garbage. | |
554 | ||
555 | @item --delete | |
556 | @itemx -d | |
557 | Attempt to delete all the store files and directories specified as | |
558 | arguments. This fails if some of the files are not in the store, or if | |
559 | they are still live. | |
560 | ||
561 | @item --list-dead | |
562 | Show the list of dead files and directories still present in the | |
563 | store---i.e., files and directories no longer reachable from any root. | |
564 | ||
565 | @item --list-live | |
566 | Show the list of live store files and directories. | |
567 | @end table | |
568 | ||
eeaf4427 | 569 | |
568717fd LC |
570 | @c ********************************************************************* |
571 | @node Programming Interface | |
572 | @chapter Programming Interface | |
573 | ||
3dc1970d LC |
574 | GNU Guix provides several Scheme programming interfaces (APIs) to |
575 | define, build, and query packages. The first interface allows users to | |
576 | write high-level package definitions. These definitions refer to | |
577 | familiar packaging concepts, such as the name and version of a package, | |
578 | its build system, and its dependencies. These definitions can then be | |
579 | turned into concrete build actions. | |
580 | ||
ba55b1cb | 581 | Build actions are performed by the Guix daemon, on behalf of users. In a |
3dc1970d LC |
582 | standard setup, the daemon has write access to the store---the |
583 | @file{/nix/store} directory---whereas users do not. The recommended | |
584 | setup also has the daemon perform builds in chroots, under a specific | |
585 | build users, to minimize interference with the rest of the system. | |
586 | ||
587 | @cindex derivation | |
588 | Lower-level APIs are available to interact with the daemon and the | |
589 | store. To instruct the daemon to perform a build action, users actually | |
590 | provide it with a @dfn{derivation}. A derivation is a low-level | |
591 | representation of the build actions to be taken, and the environment in | |
592 | which they should occur---derivations are to package definitions what | |
593 | assembly is to C programs. | |
594 | ||
595 | This chapter describes all these APIs in turn, starting from high-level | |
596 | package definitions. | |
597 | ||
568717fd LC |
598 | @menu |
599 | * Defining Packages:: Defining new packages. | |
600 | * The Store:: Manipulating the package store. | |
601 | * Derivations:: Low-level interface to package derivations. | |
602 | @end menu | |
603 | ||
604 | @node Defining Packages | |
605 | @section Defining Packages | |
606 | ||
3dc1970d LC |
607 | The high-level interface to package definitions is implemented in the |
608 | @code{(guix packages)} and @code{(guix build-system)} modules. As an | |
609 | example, the package definition, or @dfn{recipe}, for the GNU Hello | |
610 | package looks like this: | |
611 | ||
612 | @example | |
b22a12fd LC |
613 | (use-modules (guix packages) |
614 | (guix download) | |
615 | (guix build-system gnu) | |
616 | (guix licenses)) | |
617 | ||
3dc1970d LC |
618 | (define hello |
619 | (package | |
620 | (name "hello") | |
621 | (version "2.8") | |
622 | (source (origin | |
623 | (method url-fetch) | |
624 | (uri (string-append "mirror://gnu/hello/hello-" version | |
625 | ".tar.gz")) | |
626 | (sha256 | |
627 | (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")))) | |
628 | (build-system gnu-build-system) | |
629 | (inputs `(("gawk" ,gawk))) | |
630 | (synopsis "GNU Hello") | |
631 | (description "Yeah...") | |
632 | (home-page "http://www.gnu.org/software/hello/") | |
b22a12fd | 633 | (license gpl3+))) |
3dc1970d LC |
634 | @end example |
635 | ||
636 | @noindent | |
637 | Without being a Scheme expert, the reader may have guessed the meaning | |
638 | of the various fields here. This expression binds variable @var{hello} | |
639 | to a @code{<package>} object, which is essentially a record | |
640 | (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}). | |
641 | This package object can be inspected using procedures found in the | |
642 | @code{(guix packages)} module; for instance, @code{(package-name hello)} | |
643 | returns---surprise!---@code{"hello"}. | |
644 | ||
645 | There are a few points worth noting in the above package definition: | |
646 | ||
647 | @itemize | |
648 | @item | |
649 | The @code{source} field of the package is an @code{<origin>} object. | |
650 | Here, the @code{url-fetch} method from @code{(guix download)} is used, | |
651 | meaning that the source is a file to be downloaded over FTP or HTTP. | |
652 | ||
653 | The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of | |
654 | the GNU mirrors defined in @code{(guix download)}. | |
655 | ||
656 | The @code{sha256} field specifies the expected SHA256 hash of the file | |
657 | being downloaded. It is mandatory, and allows Guix to check the | |
658 | integrity of the file. The @code{(base32 @dots{})} form introduces the | |
659 | base32 representation of the hash. A convenient way to obtain this | |
660 | information is with the @code{guix-download} tool. | |
661 | ||
662 | @item | |
663 | @cindex GNU Build System | |
664 | The @code{build-system} field is set to @var{gnu-build-system}. The | |
665 | @var{gnu-build-system} variable is defined in the @code{(guix | |
666 | build-system gnu)} module, and is bound to a @code{<build-system>} | |
667 | object. | |
668 | ||
669 | Naturally, @var{gnu-build-system} represents the familiar GNU Build | |
670 | System, and variants thereof (@pxref{Configuration, configuration and | |
671 | makefile conventions,, standards, GNU Coding Standards}). In a | |
ba55b1cb | 672 | nutshell, packages using the GNU Build System may be configured, built, |
3dc1970d LC |
673 | and installed with the usual @code{./configure && make && make check && |
674 | make install} command sequence. This is what @var{gnu-build-system} | |
675 | does. | |
676 | ||
677 | In addition, @var{gnu-build-system} ensures that the ``standard'' | |
678 | environment for GNU packages is available. This includes tools such as | |
679 | GCC, Coreutils, Bash, Make, Diffutils, and Patch. | |
680 | ||
681 | @item | |
682 | The @code{inputs} field specifies inputs to the build process---i.e., | |
683 | build-time or run-time dependencies of the package. Here, we define an | |
684 | input called @code{"gawk"} whose value is that of the @var{gawk} | |
685 | variable; @var{gawk} is itself bound to a @code{<package>} object. | |
686 | ||
687 | Note that GCC, Coreutils, Bash, and other essential tools do not need to | |
688 | be specified as inputs here. Instead, @var{gnu-build-system} takes care | |
689 | of ensuring that they are present. | |
690 | ||
691 | However, any other dependencies need to be specified in the | |
692 | @code{inputs} field. Any dependency not specified here will simply be | |
693 | unavailable to the build process, possibly leading to a build failure. | |
694 | @end itemize | |
695 | ||
696 | There are other fields that package definitions may provide. Of | |
697 | particular interest is the @code{arguments} field. When specified, it | |
698 | must be bound to a list of additional arguments to be passed to the | |
699 | build system. For instance, the above definition could be augmented | |
700 | with the following field initializer: | |
701 | ||
702 | @example | |
703 | (arguments `(#:tests? #f | |
704 | #:configure-flags '("--enable-silent-rules"))) | |
705 | @end example | |
706 | ||
707 | @noindent | |
708 | These are keyword arguments (@pxref{Optional Arguments, keyword | |
709 | arguments in Guile,, guile, GNU Guile Reference Manual}). They are | |
710 | passed to @var{gnu-build-system}, which interprets them as meaning ``do | |
711 | not run @code{make check}'', and ``run @file{configure} with the | |
712 | @code{--enable-silent-rules} flag''. | |
713 | ||
714 | Once a package definition is in place@footnote{Simple package | |
715 | definitions like the one above may be automatically converted from the | |
716 | Nixpkgs distribution using the @command{guix-import} command.}, the | |
717 | package may actually be built using the @code{guix-build} command-line | |
718 | tool (@pxref{Invoking guix-build}). | |
719 | ||
720 | Behind the scenes, a derivation corresponding to the @code{<package>} | |
721 | object is first computed by the @code{package-derivation} procedure. | |
722 | That derivation is stored in a @code{.drv} file under @file{/nix/store}. | |
ba55b1cb | 723 | The build actions it prescribes may then be realized by using the |
3dc1970d LC |
724 | @code{build-derivations} procedure (@pxref{The Store}). |
725 | ||
726 | @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}] | |
727 | Return the derivation of @var{package} for @var{system}. The result is | |
728 | the file name of the derivation---i.e., a @code{.drv} file under | |
729 | @code{/nix/store}. | |
730 | ||
731 | @var{package} must be a valid @code{<package>} object, and @var{system} | |
732 | must be a string denoting the target system type---e.g., | |
733 | @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store} | |
734 | must be a connection to the daemon, which operates on the store | |
735 | (@pxref{The Store}). | |
736 | @end deffn | |
568717fd LC |
737 | |
738 | @node The Store | |
739 | @section The Store | |
740 | ||
741 | @code{(guix store)} | |
742 | ||
743 | @node Derivations | |
744 | @section Derivations | |
745 | ||
746 | @code{(guix derivations)} | |
747 | ||
748 | @c ********************************************************************* | |
749 | @node Utilities | |
750 | @chapter Utilities | |
751 | ||
752 | @menu | |
753 | * Invoking guix-build:: Building packages from the command line. | |
754 | @end menu | |
755 | ||
756 | @node Invoking guix-build | |
757 | @section Invoking @command{guix-build} | |
758 | ||
c78bd12b LC |
759 | The @command{guix-build} command builds packages or derivations and |
760 | their dependencies, and prints the resulting store paths. It is mainly | |
761 | useful for distribution developers. The general syntax is: | |
762 | ||
763 | @example | |
764 | guix-build @var{options} @var{package-or-derivation}@dots{} | |
765 | @end example | |
766 | ||
767 | @var{package-or-derivation} may be either the name of a package found in | |
768 | the software distribution such as @code{coreutils}, or a derivation such | |
769 | as @file{/nix/store/xxx-coreutils-8.19.drv}. Alternatively, the | |
770 | @code{--expression} option may be used to specify a Scheme expression | |
771 | that evaluates to a package; this is useful when disambiguation among | |
772 | several same-named packages or package variants is needed. | |
773 | ||
774 | The @var{options} may be zero or more of the following: | |
775 | ||
776 | @table @code | |
777 | ||
778 | @item --expression=@var{expr} | |
779 | @itemx -e @var{expr} | |
780 | Build the package @var{expr} evaluates to. | |
781 | ||
782 | For example, @var{expr} may be @code{(@@ (distro packages guile) | |
783 | guile-1.8)}, which unambiguously designates this specific variant of | |
784 | version 1.8 of Guile. | |
785 | ||
786 | @item --source | |
787 | @itemx -S | |
788 | Build the packages' source derivations, rather than the packages | |
789 | themselves. | |
790 | ||
791 | For instance, @code{guix-build -S gcc} returns something like | |
792 | @file{/nix/store/xxx-gcc-4.7.2.tar.bz2}, which is GCC's source tarball. | |
793 | ||
794 | @item --system=@var{system} | |
795 | @itemx -s @var{system} | |
796 | Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of | |
797 | the host's system type. | |
798 | ||
799 | An example use of this is on Linux-based systems, which can emulate | |
800 | different personalities. For instance, passing | |
801 | @code{--system=i686-linux} on an @code{x86_64-linux} system allows users | |
802 | to build packages in a complete 32-bit environment. | |
803 | ||
804 | @item --derivations | |
805 | @itemx -d | |
806 | Return the derivation paths, not the output paths, of the given | |
807 | packages. | |
808 | ||
809 | @item --keep-failed | |
810 | @itemx -K | |
811 | Keep the build tree of failed builds. Thus, if a build fail, its build | |
812 | tree is kept under @file{/tmp}, in a directory whose name is shown at | |
813 | the end of the build log. This is useful when debugging build issues. | |
814 | ||
815 | @item --dry-run | |
816 | @itemx -n | |
817 | Do not build the derivations. | |
818 | ||
819 | @item --no-substitutes | |
820 | Build instead of resorting to pre-built substitutes. | |
821 | ||
822 | @item --cores=@var{n} | |
823 | @itemx -c @var{n} | |
824 | Allow the use of up to @var{n} CPU cores for the build. The special | |
825 | value @code{0} means to use as many CPU cores as available. | |
826 | ||
827 | @item --root=@var{file} | |
828 | @itemx -r @var{file} | |
829 | Make @var{file} a symlink to the result, and register it as a garbage | |
830 | collector root. | |
07ab4bf1 LC |
831 | |
832 | @item --verbosity=@var{level} | |
833 | Use the given verbosity level. @var{level} must be an integer between 0 | |
834 | and 5; higher means more verbose output. Setting a level of 4 or more | |
835 | may be helpful when debugging setup issues with the build daemon. | |
836 | ||
c78bd12b LC |
837 | @end table |
838 | ||
839 | Behind the scenes, @command{guix-build} is essentially an interface to | |
840 | the @code{package-derivation} procedure of the @code{(guix packages)} | |
841 | module, and to the @code{build-derivations} procedure of the @code{(guix | |
842 | store)} module. | |
843 | ||
844 | ||
568717fd LC |
845 | @c ********************************************************************* |
846 | @node Acknowledgments | |
847 | @chapter Acknowledgments | |
848 | ||
849 | Guix is based on the Nix package manager, which was designed and | |
850 | implemented by Eelco Dolstra. Nix pioneered functional package | |
851 | management, and promoted unprecedented features, such as transactional | |
852 | package upgrades and rollbacks, per-user profiles, and referentially | |
853 | transparent build processes. Without this work, Guix would not exist. | |
854 | ||
855 | The Nix-based software distributions, Nixpkgs and NixOS, have also been | |
856 | an inspiration for Guix. | |
857 | ||
858 | @c ********************************************************************* | |
859 | @node GNU Free Documentation License | |
860 | @appendix GNU Free Documentation License | |
861 | ||
862 | @include fdl-1.3.texi | |
863 | ||
864 | @c ********************************************************************* | |
865 | @node Concept Index | |
866 | @unnumbered Concept Index | |
867 | @printindex cp | |
868 | ||
869 | @node Function Index | |
870 | @unnumbered Function Index | |
871 | @printindex fn | |
872 | ||
873 | @bye | |
874 | ||
875 | @c Local Variables: | |
876 | @c ispell-local-dictionary: "american"; | |
877 | @c End: |