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