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 | 25 | @author Ludovic Courtès |
acc08466 | 26 | @author Nikita Karetnikov |
568717fd LC |
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. | |
a1ba8475 | 84 | * GNU Distribution:: Software for your friendly GNU system. |
568717fd LC |
85 | |
86 | * Acknowledgments:: Thanks! | |
87 | * GNU Free Documentation License:: The license of this manual. | |
88 | * Concept Index:: Concepts. | |
89 | * Function Index:: Functions. | |
90 | @end menu | |
91 | ||
92 | @c ********************************************************************* | |
93 | @node Introduction | |
94 | @chapter Introduction | |
95 | ||
c80e7e55 LC |
96 | GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks'' |
97 | using the international phonetic alphabet (IPA).} is a functional | |
98 | package management tool for the GNU system. Package management consists | |
99 | in all the activities that relate to building packages from source, | |
100 | honoring the build-time and run-time dependencies on packages, | |
101 | installing packages in user environments, upgrading installed packages | |
102 | to new versions or rolling back to a previous set, removing unused | |
103 | software packages, etc. | |
568717fd LC |
104 | |
105 | @cindex functional package management | |
106 | The term @dfn{functional} refers to a specific package management | |
107 | discipline. In Guix, the package build and installation process is seen | |
108 | as a function, in the mathematical sense: that function takes inputs, | |
109 | such as build scripts, a compiler, and libraries depended on, and | |
110 | returns the installed package. As a pure function, its result depends | |
111 | solely on its inputs---for instance, it cannot refer to software or | |
112 | scripts that were not explicitly passed as inputs. A build function | |
113 | always produces the same result when passed a given set of inputs. Last | |
114 | but not least, a build function cannot alter the system's environment in | |
115 | any way; for instance, it cannot create, modify, or delete files outside | |
116 | of its build and installation directories. This is achieved by running | |
117 | build processes in dedicated ``chroots'', where only their explicit | |
118 | inputs are visible. | |
119 | ||
e531ac2a | 120 | @cindex store |
568717fd | 121 | The result of package build functions is @dfn{cached} in the file |
e531ac2a LC |
122 | system, in a special directory called @dfn{the store} (@pxref{The |
123 | Store}). Each package is installed in a directory of its own, in the | |
568717fd LC |
124 | store---by default under @file{/nix/store}. The directory name contains |
125 | a hash of all the inputs used to build that package; thus, changing an | |
126 | input yields a different directory name. | |
127 | ||
128 | This approach is the foundation of Guix's salient features: support for | |
129 | transactional package upgrades and rollback, per-user installation, and | |
eeaf4427 | 130 | garbage collection of packages (@pxref{Features}). |
568717fd LC |
131 | |
132 | Guix has a command-line interface allowing users to build, install, | |
133 | upgrade, and remove packages, as well as a Scheme programming interface. | |
134 | The remainder of this manual describes them. | |
135 | ||
a1ba8475 LC |
136 | Last but not least, Guix is used to build a distribution of the GNU |
137 | system, with many GNU and non-GNU free software packages. @xref{GNU | |
138 | Distribution}. | |
139 | ||
bd5e766b LC |
140 | @c ********************************************************************* |
141 | @node Installation | |
142 | @chapter Installation | |
143 | ||
144 | This section describes the software requirements of Guix, as well as how | |
145 | to install it and get ready to use it. | |
146 | ||
b22a12fd | 147 | The build procedure for Guix is the same as for other GNU software, and |
1da983b9 | 148 | is not covered here. Please see the files @file{README} and |
b22a12fd LC |
149 | @file{INSTALL} in the Guix source tree for additional details. |
150 | ||
bd5e766b LC |
151 | @menu |
152 | * Requirements:: Software needed to build and run Guix. | |
153 | * Setting Up the Daemon:: Preparing the build daemon's environment. | |
154 | * Invoking guix-daemon:: Running the build daemon. | |
155 | @end menu | |
156 | ||
157 | @node Requirements | |
158 | @section Requirements | |
159 | ||
160 | GNU Guix depends on the following packages: | |
161 | ||
162 | @itemize | |
163 | @item @url{http://gnu.org/software/guile/, GNU Guile 2.0.x}; | |
164 | @item @url{http://gnupg.org/, GNU libgcrypt} | |
165 | @end itemize | |
166 | ||
167 | Unless @code{--disable-daemon} was passed to @command{configure}, the | |
168 | following packages are also needed: | |
169 | ||
170 | @itemize | |
171 | @item @url{http://sqlite.org, SQLite 3} | |
172 | @item @url{http://www.bzip.org, libbz2} | |
173 | @item @url{http://gcc.gnu.org, GCC's g++} | |
174 | @end itemize | |
175 | ||
176 | When a working installation of the Nix package manager is available, you | |
177 | can instead configure Guix with @code{--disable-daemon}. In that case, | |
178 | @url{http://nixos.org/nix/, Nix} replaces the three dependencies above. | |
179 | ||
b22a12fd LC |
180 | Guix is compatible with Nix, so it is possible to share the same store |
181 | between both. To do so, you must pass @command{configure} not only the | |
182 | same @code{--with-store-dir} value, but also the same | |
183 | @code{--localstatedir} value (the latter is essential because it | |
184 | specifies where the database that store meta-data about the store is | |
185 | located, among other things.) The default values are | |
186 | @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}. | |
187 | Note that @code{--disable-daemon} is orthogonal and is not required if | |
188 | your goal is to share the same store as Nix. | |
189 | ||
bd5e766b LC |
190 | @node Setting Up the Daemon |
191 | @section Setting Up the Daemon | |
192 | ||
193 | @cindex daemon | |
194 | Operations such as building a package or running the garbage collector | |
195 | are all performed by a specialized process, the @dfn{Guix daemon}, on | |
196 | behalf of clients. Only the daemon may access the store and its | |
197 | associated database. Thus, any operation that manipulates the store | |
198 | goes through the daemon. For instance, command-line tools such as | |
199 | @command{guix-package} and @command{guix-build} communicate with the | |
200 | daemon (@i{via} remote procedure calls) to instruct it what to do. | |
201 | ||
202 | In a standard multi-user setup, Guix and its daemon---the | |
203 | @command{guix-daemon} program---are installed by the system | |
204 | administrator; @file{/nix/store} is owned by @code{root} and | |
205 | @command{guix-daemon} runs as @code{root}. Unprivileged users may use | |
206 | Guix tools to build packages or otherwise access the store, and the | |
207 | daemon will do it on their behalf, ensuring that the store is kept in a | |
208 | consistent state, and allowing built packages to be shared among users. | |
209 | ||
210 | @cindex build users | |
211 | When @command{guix-daemon} runs as @code{root}, you may not want package | |
212 | build processes themselves to run as @code{root} too, for obvious | |
213 | security reasons. To avoid that, a special pool of @dfn{build users} | |
214 | should be created for use by build processes started by the daemon. | |
215 | These build users need not have a shell and a home directory: they will | |
216 | just be used when the daemon drops @code{root} privileges in build | |
217 | processes. Having several such users allows the daemon to launch | |
218 | distinct build processes under separate UIDs, which guarantees that they | |
219 | do not interfere with each other---an essential feature since builds are | |
220 | regarded as pure functions (@pxref{Introduction}). | |
221 | ||
222 | On a GNU/Linux system, a build user pool may be created like this (using | |
223 | Bash syntax and the @code{shadow} commands): | |
224 | ||
091196b3 LC |
225 | @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html |
226 | @c for why `-G' is needed. | |
bd5e766b LC |
227 | @example |
228 | # groupadd guix-builder | |
229 | # for i in `seq 1 10`; | |
230 | do | |
091196b3 LC |
231 | useradd -g guix-builder -G guix-builder \ |
232 | -d /var/empty -s `which nologin` \ | |
80ba8cc0 | 233 | -c "Guix build user $i" guix-builder$i; |
bd5e766b LC |
234 | done |
235 | @end example | |
236 | ||
237 | @noindent | |
238 | The @code{guix-daemon} program may then be run as @code{root} with: | |
239 | ||
240 | @example | |
241 | # guix-daemon --build-users-group=guix-builder | |
242 | @end example | |
243 | ||
244 | Guix may also be used in a single-user setup, with @command{guix-daemon} | |
1da983b9 | 245 | running as an unprivileged user. However, to maximize non-interference |
bd5e766b LC |
246 | of build processes, the daemon still needs to perform certain operations |
247 | that are restricted to @code{root} on GNU/Linux: it should be able to | |
248 | run build processes in a chroot, and to run them under different UIDs. | |
249 | To that end, the @command{nix-setuid-helper} program is provided; it is | |
250 | a small C program (less than 300 lines) that, if it is made setuid | |
251 | @code{root}, can be executed by the daemon to perform these operations | |
252 | on its behalf. The @code{root}-owned @file{/etc/nix-setuid.conf} file | |
253 | is read by @command{nix-setuid-helper}; it should contain exactly two | |
254 | words: the user name under which the authorized @command{guix-daemon} | |
255 | runs, and the name of the build users group. | |
256 | ||
257 | If you are installing Guix as an unprivileged user and do not have the | |
258 | ability to make @file{nix-setuid-helper} setuid-@code{root}, it is still | |
259 | possible to run @command{guix-daemon}. However, build processes will | |
260 | not be isolated from one another, and not from the rest of the system. | |
261 | Thus, build processes may interfere with each other, and may access | |
262 | programs, libraries, and other files available on the system---making it | |
263 | much harder to view them as @emph{pure} functions. | |
264 | ||
265 | @node Invoking guix-daemon | |
266 | @section Invoking @command{guix-daemon} | |
267 | ||
268 | The @command{guix-daemon} program implements all the functionality to | |
269 | access the store. This includes launching build processes, running the | |
270 | garbage collector, querying the availability of a build result, etc. It | |
271 | is normally run as @code{root} like this: | |
272 | ||
273 | @example | |
274 | # guix-daemon --build-users-group=guix-builder | |
275 | @end example | |
276 | ||
277 | @noindent | |
278 | For details on how to set it up, @ref{Setting Up the Daemon}. | |
279 | ||
280 | By default, @command{guix-daemon} launches build processes under | |
281 | different UIDs, taken from the build group specified with | |
282 | @code{--build-users-group}. In addition, each build process is run in a | |
283 | chroot environment that only contains the subset of the store that the | |
284 | build process depends on, as specified by its derivation | |
285 | (@pxref{Programming Interface, derivation}), plus a set of specific | |
286 | system directories. By default, the latter contains @file{/dev} and | |
287 | @file{/dev/pts}. | |
288 | ||
289 | The following command-line options are supported: | |
290 | ||
291 | @table @code | |
292 | @item --build-users-group=@var{group} | |
293 | Take users from @var{group} to run build processes (@pxref{Setting Up | |
294 | the Daemon, build users}). | |
295 | ||
296 | @item --cache-failures | |
297 | Cache build failures. By default, only successful builds are cached. | |
298 | ||
299 | @item --cores=@var{n} | |
300 | @itemx -c @var{n} | |
301 | Use @var{n} CPU cores to build each derivation; @code{0} means as many | |
302 | as available. | |
303 | ||
304 | The default value is @code{1}, but it may be overridden by clients, such | |
305 | as the @code{--cores} option of @command{guix-build} (@pxref{Invoking | |
306 | guix-build}). | |
307 | ||
308 | The effect is to define the @code{NIX_BUILD_CORES} environment variable | |
309 | in the build process, which can then use it to exploit internal | |
310 | parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}. | |
311 | ||
312 | @item --max-jobs=@var{n} | |
313 | @itemx -M @var{n} | |
314 | Allow at most @var{n} build jobs in parallel. The default value is | |
315 | @code{1}. | |
316 | ||
317 | @item --debug | |
318 | Produce debugging output. | |
319 | ||
320 | This is useful to debug daemon start-up issues, but then it may be | |
321 | overridden by clients, for example the @code{--verbosity} option of | |
322 | @command{guix-build} (@pxref{Invoking guix-build}). | |
323 | ||
324 | @item --chroot-directory=@var{dir} | |
325 | Add @var{dir} to the build chroot. | |
326 | ||
327 | Doing this may change the result of build processes---for instance if | |
328 | they use optional dependencies found in @var{dir} when it is available, | |
329 | and not otherwise. For that reason, it is not recommended to do so. | |
330 | Instead, make sure that each derivation declares all the inputs that it | |
331 | needs. | |
332 | ||
333 | @item --disable-chroot | |
334 | Disable chroot builds. | |
335 | ||
336 | Using this option is not recommended since, again, it would allow build | |
337 | processes to gain access to undeclared dependencies. | |
338 | ||
339 | @item --disable-log-compression | |
340 | Disable compression of the build logs. | |
341 | ||
1da983b9 LC |
342 | Unless @code{--lose-logs} is used, all the build logs are kept in the |
343 | @var{localstatedir}. To save space, the daemon automatically compresses | |
344 | them with bzip2 by default. This option disables that. | |
345 | ||
bd5e766b LC |
346 | @item --disable-store-optimization |
347 | Disable automatic file ``deduplication'' in the store. | |
348 | ||
1da983b9 LC |
349 | By default, files added to the store are automatically ``deduplicated'': |
350 | if a newly added file is identical as another one found in the store, | |
351 | the daemon makes the new file a hard link to the other file. This | |
352 | slightly increases the input/output load at the end of a build process. | |
353 | This option disables this. | |
354 | ||
bd5e766b LC |
355 | @item --impersonate-linux-2.6 |
356 | On Linux-based systems, impersonate Linux 2.6. This means that the | |
357 | kernel's @code{uname} system call will report 2.6 as the release number. | |
358 | ||
359 | This might be helpful to build programs that (usually wrongfully) depend | |
360 | on the kernel version number. | |
361 | ||
362 | @item --lose-logs | |
363 | Do not keep build logs. By default they are kept under | |
364 | @code{@var{localstatedir}/nix/log}. | |
365 | ||
366 | @item --system=@var{system} | |
367 | Assume @var{system} as the current system type. By default it is the | |
368 | architecture/kernel pair found at configure time, such as | |
369 | @code{x86_64-linux}. | |
370 | @end table | |
371 | ||
372 | ||
eeaf4427 LC |
373 | @c ********************************************************************* |
374 | @node Package Management | |
375 | @chapter Package Management | |
376 | ||
f8348b91 | 377 | The purpose of GNU Guix is to allow users to easily install, upgrade, and |
eeaf4427 LC |
378 | remove software packages, without having to know about their build |
379 | procedure or dependencies. Guix also goes beyond this obvious set of | |
380 | features. | |
381 | ||
382 | This chapter describes the main features of Guix, as well as the package | |
383 | management tools it provides. | |
384 | ||
385 | @menu | |
386 | * Features:: How Guix will make your life brighter. | |
387 | * Invoking guix-package:: Package installation, removal, etc. | |
fe8ff028 | 388 | * Invoking guix-gc:: Running the garbage collector. |
eeaf4427 LC |
389 | @end menu |
390 | ||
391 | @node Features | |
392 | @section Features | |
393 | ||
394 | When using Guix, each package ends up in the @dfn{package store}, in its | |
395 | own directory---something that resembles | |
396 | @file{/nix/store/xxx-package-1.2}, where @code{xxx} is a base32 string. | |
397 | ||
398 | Instead of referring to these directories, users have their own | |
399 | @dfn{profile}, which points to the packages that they actually want to | |
821b0015 LC |
400 | use. These profiles are stored within each user's home directory, at |
401 | @code{$HOME/.guix-profile}. | |
eeaf4427 | 402 | |
821b0015 | 403 | For example, @code{alice} installs GCC 4.7.2. As a result, |
eeaf4427 | 404 | @file{/home/alice/.guix-profile/bin/gcc} points to |
821b0015 LC |
405 | @file{/nix/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine, |
406 | @code{bob} had already installed GCC 4.8.0. The profile of @code{bob} | |
407 | simply continues to point to | |
408 | @file{/nix/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC | |
409 | coexist on the same system without any interference. | |
eeaf4427 LC |
410 | |
411 | The @command{guix-package} command is the central tool to manage | |
821b0015 LC |
412 | packages (@pxref{Invoking guix-package}). It operates on those per-user |
413 | profiles, and can be used @emph{with normal user privileges}. | |
eeaf4427 LC |
414 | |
415 | The command provides the obvious install, remove, and upgrade | |
416 | operations. Each invocation is actually a @emph{transaction}: either | |
ba55b1cb | 417 | the specified operation succeeds, or nothing happens. Thus, if the |
821b0015 | 418 | @command{guix-package} process is terminated during the transaction, |
eeaf4427 LC |
419 | or if a power outage occurs during the transaction, then the user's |
420 | profile remains in its previous state, and remains usable. | |
421 | ||
422 | In addition, any package transaction may be @emph{rolled back}. So, if, | |
423 | for example, an upgrade installs a new version of a package that turns | |
424 | out to have a serious bug, users may roll back to the previous instance | |
425 | of their profile, which was known to work well. | |
426 | ||
427 | All those packages in the package store may be @emph{garbage-collected}. | |
428 | Guix can determine which packages are still referenced by the user | |
fe8ff028 LC |
429 | profiles, and remove those that are provably no longer referenced |
430 | (@pxref{Invoking guix-gc}). Users may also explicitly remove old | |
431 | generations of their profile so that the packages they refer to can be | |
432 | collected. | |
eeaf4427 LC |
433 | |
434 | Finally, Guix takes a @dfn{purely functional} approach to package | |
435 | management, as described in the introduction (@pxref{Introduction}). | |
436 | Each @file{/nix/store} package directory name contains a hash of all the | |
437 | inputs that were used to build that package---compiler, libraries, build | |
438 | scripts, etc. This direct correspondence allows users to make sure a | |
439 | given package installation matches the current state of their | |
a1ba8475 | 440 | distribution, and helps maximize @dfn{reproducibility}. |
eeaf4427 | 441 | |
75f1e8f7 | 442 | @c FIXME: Remove footnote when it's implemented. |
eeaf4427 | 443 | This foundation allows Guix to support @dfn{transparent binary/source |
75f1e8f7 LC |
444 | deployment}@footnote{This feature is not implemented as of version |
445 | @value{VERSION}. Please contact @email{bug-guix@@gnu.org} for more | |
446 | details.}. When a pre-built binary for a @file{/nix/store} path is | |
eeaf4427 LC |
447 | available from an external source, Guix just downloads it; otherwise, it |
448 | builds the package from source, locally. | |
449 | ||
450 | @node Invoking guix-package | |
451 | @section Invoking @command{guix-package} | |
452 | ||
ba55b1cb | 453 | The @command{guix-package} command is the tool that allows users to |
eeaf4427 LC |
454 | install, upgrade, and remove packages, as well as rolling back to |
455 | previous configurations. It operates only on the user's own profile, | |
456 | and works with normal user privileges (@pxref{Features}). Its syntax | |
457 | is: | |
458 | ||
459 | @example | |
460 | guix-package @var{options} | |
461 | @end example | |
462 | ||
ba55b1cb | 463 | Primarily, @var{options} specifies the operations to be performed during |
eeaf4427 LC |
464 | the transaction. Upon completion, a new profile is created, but |
465 | previous generations of the profile remain available, should the user | |
466 | want to roll back. | |
467 | ||
b9e5c0a9 | 468 | For each user, a symlink to the user's default profile is automatically |
0ec1af59 | 469 | created in @file{$HOME/.guix-profile}. This symlink always points to the |
b9e5c0a9 LC |
470 | current generation of the user's default profile. Thus, users can add |
471 | @file{$HOME/.guix-profile/bin} to their @code{PATH} environment | |
472 | variable, and so on. | |
473 | ||
0ec1af59 LC |
474 | In a multi-user setup, user profiles must be stored in a place |
475 | registered as a @dfn{garbage-collector root}, which | |
476 | @file{$HOME/.guix-profile} points to (@pxref{Invoking guix-gc}). That | |
477 | directory is normally | |
478 | @code{@var{localstatedir}/profiles/per-user/@var{user}}, where | |
479 | @var{localstatedir} is the value passed to @code{configure} as | |
480 | @code{--localstatedir}, and @var{user} is the user name. It must be | |
481 | created by @code{root}, with @var{user} as the owner. When it does not | |
482 | exist, @command{guix-package} emits an error about it. | |
483 | ||
484 | The @var{options} can be among the following: | |
485 | ||
eeaf4427 LC |
486 | @table @code |
487 | ||
488 | @item --install=@var{package} | |
51c8d790 | 489 | @itemx -i @var{package} |
eeaf4427 LC |
490 | Install @var{package}. |
491 | ||
492 | @var{package} may specify either a simple package name, such as | |
493 | @code{guile}, or a package name followed by a hyphen and version number, | |
bfe384cc | 494 | such as @code{guile-1.8.8}. In addition, @var{package} may contain a |
eeaf4427 | 495 | colon, followed by the name of one of the outputs of the package, as in |
f03e7115 | 496 | @code{gcc:doc} or @code{binutils-2.22:lib}. |
eeaf4427 LC |
497 | |
498 | @item --remove=@var{package} | |
499 | @itemx -r @var{package} | |
500 | Remove @var{package}. | |
501 | ||
ba55b1cb LC |
502 | @item --upgrade=@var{regexp} |
503 | @itemx -u @var{regexp} | |
eeaf4427 LC |
504 | Upgrade all the installed packages matching @var{regexp}. |
505 | ||
24e262f0 LC |
506 | @item --roll-back |
507 | Roll back to the previous @dfn{generation} of the profile---i.e., undo | |
508 | the last transaction. | |
509 | ||
510 | When combined with options such as @code{--install}, roll back occurs | |
511 | before any other actions. | |
512 | ||
d9307267 LC |
513 | When rolling back from the first generation that actually contains |
514 | installed packages, the profile is made to point to the @dfn{empty | |
515 | profile}, also known as @dfn{profile zero}---i.e., it contains no files | |
516 | apart from its own meta-data. | |
517 | ||
82fe08ed LC |
518 | Installing, removing, or upgrading packages from a generation that has |
519 | been rolled back to overwrites previous future generations. Thus, the | |
520 | history of a profile's generations is always linear. | |
521 | ||
eeaf4427 LC |
522 | @item --profile=@var{profile} |
523 | @itemx -p @var{profile} | |
524 | Use @var{profile} instead of the user's default profile. | |
525 | ||
526 | @item --dry-run | |
527 | @itemx -n | |
528 | Show what would be done without actually doing it. | |
529 | ||
70915c1a LC |
530 | @item --verbose |
531 | Produce verbose output. In particular, emit the environment's build log | |
532 | on the standard error port. | |
533 | ||
eeaf4427 LC |
534 | @item --bootstrap |
535 | Use the bootstrap Guile to build the profile. This option is only | |
536 | useful to distribution developers. | |
537 | ||
538 | @end table | |
539 | ||
733b4130 LC |
540 | In addition to these actions @command{guix-package} supports the |
541 | following options to query the current state of a profile, or the | |
542 | availability of packages: | |
eeaf4427 | 543 | |
733b4130 LC |
544 | @table @option |
545 | ||
acc08466 NK |
546 | @item --search=@var{regexp} |
547 | @itemx -s @var{regexp} | |
548 | List the available packages whose synopsis or description matches | |
299112d3 LC |
549 | @var{regexp}. Print all the meta-data of matching packages in |
550 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, | |
551 | GNU recutils manual}). | |
acc08466 | 552 | |
299112d3 LC |
553 | This allows specific fields to be extracted using the @command{recsel} |
554 | command, for instance: | |
555 | ||
556 | @example | |
557 | $ guix-package -s malloc | recsel -p name,version | |
558 | name: glibc | |
559 | version: 2.17 | |
560 | ||
561 | name: libgc | |
562 | version: 7.2alpha6 | |
563 | @end example | |
acc08466 | 564 | |
733b4130 LC |
565 | @item --list-installed[=@var{regexp}] |
566 | @itemx -I [@var{regexp}] | |
567 | List currently installed packages in the specified profile. When | |
568 | @var{regexp} is specified, list only installed packages whose name | |
569 | matches @var{regexp}. | |
570 | ||
571 | For each installed package, print the following items, separated by | |
572 | tabs: the package name, its version string, the part of the package that | |
573 | is installed (for instance, @code{out} for the default output, | |
574 | @code{include} for its headers, etc.), and the path of this package in | |
575 | the store. | |
576 | ||
64fc89b6 LC |
577 | @item --list-available[=@var{regexp}] |
578 | @itemx -A [@var{regexp}] | |
a1ba8475 LC |
579 | List packages currently available in the software distribution |
580 | (@pxref{GNU Distribution}). When @var{regexp} is specified, list only | |
581 | installed packages whose name matches @var{regexp}. | |
64fc89b6 LC |
582 | |
583 | For each package, print the following items separated by tabs: its name, | |
44b6be77 LC |
584 | its version string, the parts of the package (@code{out} for the main |
585 | files, @code{lib} for libraries and possibly headers, etc.), and the | |
586 | source location of its definition. | |
64fc89b6 | 587 | |
733b4130 | 588 | @end table |
eeaf4427 LC |
589 | |
590 | ||
fe8ff028 LC |
591 | @node Invoking guix-gc |
592 | @section Invoking @command{guix-gc} | |
593 | ||
594 | @cindex garbage collector | |
595 | Packages that are installed but not used may be @dfn{garbage-collected}. | |
596 | The @command{guix-gc} command allows users to explicitly run the garbage | |
597 | collector to reclaim space from the @file{/nix/store} directory. | |
598 | ||
599 | The garbage collector has a set of known @dfn{roots}: any file under | |
600 | @file{/nix/store} reachable from a root is considered @dfn{live} and | |
601 | cannot be deleted; any other file is considered @dfn{dead} and may be | |
602 | deleted. The set of garbage collector roots includes default user | |
603 | profiles, and may be augmented with @command{guix-build --root}, for | |
604 | example (@pxref{Invoking guix-build}). | |
605 | ||
1da983b9 | 606 | The @command{guix-gc} command has three modes of operation: it can be |
fe8ff028 LC |
607 | used to garbage-collect any dead files (the default), to delete specific |
608 | files (the @code{--delete} option), or to print garbage-collector | |
609 | information. The available options are listed below: | |
610 | ||
611 | @table @code | |
612 | @item --collect-garbage[=@var{min}] | |
613 | @itemx -C [@var{min}] | |
614 | Collect garbage---i.e., unreachable @file{/nix/store} files and | |
615 | sub-directories. This is the default operation when no option is | |
616 | specified. | |
617 | ||
618 | When @var{min} is given, stop once @var{min} bytes have been collected. | |
619 | @var{min} may be a number of bytes, or it may include a unit as a | |
620 | suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes. | |
621 | ||
622 | When @var{min} is omitted, collect all the garbage. | |
623 | ||
624 | @item --delete | |
625 | @itemx -d | |
626 | Attempt to delete all the store files and directories specified as | |
627 | arguments. This fails if some of the files are not in the store, or if | |
628 | they are still live. | |
629 | ||
630 | @item --list-dead | |
631 | Show the list of dead files and directories still present in the | |
632 | store---i.e., files and directories no longer reachable from any root. | |
633 | ||
634 | @item --list-live | |
635 | Show the list of live store files and directories. | |
636 | @end table | |
637 | ||
eeaf4427 | 638 | |
568717fd LC |
639 | @c ********************************************************************* |
640 | @node Programming Interface | |
641 | @chapter Programming Interface | |
642 | ||
3dc1970d LC |
643 | GNU Guix provides several Scheme programming interfaces (APIs) to |
644 | define, build, and query packages. The first interface allows users to | |
645 | write high-level package definitions. These definitions refer to | |
646 | familiar packaging concepts, such as the name and version of a package, | |
647 | its build system, and its dependencies. These definitions can then be | |
648 | turned into concrete build actions. | |
649 | ||
ba55b1cb | 650 | Build actions are performed by the Guix daemon, on behalf of users. In a |
3dc1970d LC |
651 | standard setup, the daemon has write access to the store---the |
652 | @file{/nix/store} directory---whereas users do not. The recommended | |
653 | setup also has the daemon perform builds in chroots, under a specific | |
654 | build users, to minimize interference with the rest of the system. | |
655 | ||
656 | @cindex derivation | |
657 | Lower-level APIs are available to interact with the daemon and the | |
658 | store. To instruct the daemon to perform a build action, users actually | |
659 | provide it with a @dfn{derivation}. A derivation is a low-level | |
660 | representation of the build actions to be taken, and the environment in | |
661 | which they should occur---derivations are to package definitions what | |
662 | assembly is to C programs. | |
663 | ||
664 | This chapter describes all these APIs in turn, starting from high-level | |
665 | package definitions. | |
666 | ||
568717fd LC |
667 | @menu |
668 | * Defining Packages:: Defining new packages. | |
669 | * The Store:: Manipulating the package store. | |
670 | * Derivations:: Low-level interface to package derivations. | |
671 | @end menu | |
672 | ||
673 | @node Defining Packages | |
674 | @section Defining Packages | |
675 | ||
3dc1970d LC |
676 | The high-level interface to package definitions is implemented in the |
677 | @code{(guix packages)} and @code{(guix build-system)} modules. As an | |
678 | example, the package definition, or @dfn{recipe}, for the GNU Hello | |
679 | package looks like this: | |
680 | ||
681 | @example | |
b22a12fd LC |
682 | (use-modules (guix packages) |
683 | (guix download) | |
684 | (guix build-system gnu) | |
685 | (guix licenses)) | |
686 | ||
3dc1970d LC |
687 | (define hello |
688 | (package | |
689 | (name "hello") | |
690 | (version "2.8") | |
691 | (source (origin | |
692 | (method url-fetch) | |
693 | (uri (string-append "mirror://gnu/hello/hello-" version | |
694 | ".tar.gz")) | |
695 | (sha256 | |
696 | (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")))) | |
697 | (build-system gnu-build-system) | |
698 | (inputs `(("gawk" ,gawk))) | |
699 | (synopsis "GNU Hello") | |
700 | (description "Yeah...") | |
701 | (home-page "http://www.gnu.org/software/hello/") | |
b22a12fd | 702 | (license gpl3+))) |
3dc1970d LC |
703 | @end example |
704 | ||
705 | @noindent | |
706 | Without being a Scheme expert, the reader may have guessed the meaning | |
707 | of the various fields here. This expression binds variable @var{hello} | |
708 | to a @code{<package>} object, which is essentially a record | |
709 | (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}). | |
710 | This package object can be inspected using procedures found in the | |
711 | @code{(guix packages)} module; for instance, @code{(package-name hello)} | |
712 | returns---surprise!---@code{"hello"}. | |
713 | ||
714 | There are a few points worth noting in the above package definition: | |
715 | ||
716 | @itemize | |
717 | @item | |
718 | The @code{source} field of the package is an @code{<origin>} object. | |
719 | Here, the @code{url-fetch} method from @code{(guix download)} is used, | |
720 | meaning that the source is a file to be downloaded over FTP or HTTP. | |
721 | ||
722 | The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of | |
723 | the GNU mirrors defined in @code{(guix download)}. | |
724 | ||
725 | The @code{sha256} field specifies the expected SHA256 hash of the file | |
726 | being downloaded. It is mandatory, and allows Guix to check the | |
727 | integrity of the file. The @code{(base32 @dots{})} form introduces the | |
728 | base32 representation of the hash. A convenient way to obtain this | |
729 | information is with the @code{guix-download} tool. | |
730 | ||
731 | @item | |
732 | @cindex GNU Build System | |
733 | The @code{build-system} field is set to @var{gnu-build-system}. The | |
734 | @var{gnu-build-system} variable is defined in the @code{(guix | |
735 | build-system gnu)} module, and is bound to a @code{<build-system>} | |
736 | object. | |
737 | ||
738 | Naturally, @var{gnu-build-system} represents the familiar GNU Build | |
739 | System, and variants thereof (@pxref{Configuration, configuration and | |
740 | makefile conventions,, standards, GNU Coding Standards}). In a | |
ba55b1cb | 741 | nutshell, packages using the GNU Build System may be configured, built, |
3dc1970d LC |
742 | and installed with the usual @code{./configure && make && make check && |
743 | make install} command sequence. This is what @var{gnu-build-system} | |
744 | does. | |
745 | ||
746 | In addition, @var{gnu-build-system} ensures that the ``standard'' | |
747 | environment for GNU packages is available. This includes tools such as | |
748 | GCC, Coreutils, Bash, Make, Diffutils, and Patch. | |
749 | ||
750 | @item | |
751 | The @code{inputs} field specifies inputs to the build process---i.e., | |
752 | build-time or run-time dependencies of the package. Here, we define an | |
753 | input called @code{"gawk"} whose value is that of the @var{gawk} | |
754 | variable; @var{gawk} is itself bound to a @code{<package>} object. | |
755 | ||
756 | Note that GCC, Coreutils, Bash, and other essential tools do not need to | |
757 | be specified as inputs here. Instead, @var{gnu-build-system} takes care | |
758 | of ensuring that they are present. | |
759 | ||
760 | However, any other dependencies need to be specified in the | |
761 | @code{inputs} field. Any dependency not specified here will simply be | |
762 | unavailable to the build process, possibly leading to a build failure. | |
763 | @end itemize | |
764 | ||
765 | There are other fields that package definitions may provide. Of | |
766 | particular interest is the @code{arguments} field. When specified, it | |
767 | must be bound to a list of additional arguments to be passed to the | |
768 | build system. For instance, the above definition could be augmented | |
769 | with the following field initializer: | |
770 | ||
771 | @example | |
772 | (arguments `(#:tests? #f | |
773 | #:configure-flags '("--enable-silent-rules"))) | |
774 | @end example | |
775 | ||
776 | @noindent | |
777 | These are keyword arguments (@pxref{Optional Arguments, keyword | |
778 | arguments in Guile,, guile, GNU Guile Reference Manual}). They are | |
779 | passed to @var{gnu-build-system}, which interprets them as meaning ``do | |
780 | not run @code{make check}'', and ``run @file{configure} with the | |
874e6874 LC |
781 | @code{--enable-silent-rules} flag''. The value of these keyword |
782 | parameters is actually evaluated in the @dfn{build stratum}---i.e., by a | |
783 | Guile process launched by the daemon (@pxref{Derivations}). | |
3dc1970d LC |
784 | |
785 | Once a package definition is in place@footnote{Simple package | |
786 | definitions like the one above may be automatically converted from the | |
787 | Nixpkgs distribution using the @command{guix-import} command.}, the | |
788 | package may actually be built using the @code{guix-build} command-line | |
789 | tool (@pxref{Invoking guix-build}). | |
790 | ||
791 | Behind the scenes, a derivation corresponding to the @code{<package>} | |
792 | object is first computed by the @code{package-derivation} procedure. | |
793 | That derivation is stored in a @code{.drv} file under @file{/nix/store}. | |
ba55b1cb | 794 | The build actions it prescribes may then be realized by using the |
3dc1970d LC |
795 | @code{build-derivations} procedure (@pxref{The Store}). |
796 | ||
797 | @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}] | |
e509d152 LC |
798 | Return the derivation path and corresponding @code{<derivation>} object |
799 | of @var{package} for @var{system} (@pxref{Derivations}). | |
3dc1970d LC |
800 | |
801 | @var{package} must be a valid @code{<package>} object, and @var{system} | |
802 | must be a string denoting the target system type---e.g., | |
803 | @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store} | |
804 | must be a connection to the daemon, which operates on the store | |
805 | (@pxref{The Store}). | |
806 | @end deffn | |
568717fd LC |
807 | |
808 | @node The Store | |
809 | @section The Store | |
810 | ||
e531ac2a LC |
811 | @cindex store |
812 | @cindex store paths | |
813 | ||
814 | Conceptually, the @dfn{store} is where derivations that have been | |
815 | successfully built are stored---by default, under @file{/nix/store}. | |
816 | Sub-directories in the store are referred to as @dfn{store paths}. The | |
817 | store has an associated database that contains information such has the | |
818 | store paths referred to by each store path, and the list of @emph{valid} | |
819 | store paths---paths that result from a successful build. | |
820 | ||
821 | The store is always accessed by the daemon on behalf of its clients | |
822 | (@pxref{Invoking guix-daemon}). To manipulate the store, clients | |
823 | connect to the daemon over a Unix-domain socket, send it requests, and | |
824 | read the result---these are remote procedure calls, or RPCs. | |
825 | ||
826 | The @code{(guix store)} module provides procedures to connect to the | |
827 | daemon, and to perform RPCs. These are described below. | |
828 | ||
829 | @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t] | |
830 | Connect to the daemon over the Unix-domain socket at @var{file}. When | |
831 | @var{reserve-space?} is true, instruct it to reserve a little bit of | |
832 | extra space on the file system so that the garbage collector can still | |
833 | operate, should the disk become full. Return a server object. | |
834 | ||
835 | @var{file} defaults to @var{%default-socket-path}, which is the normal | |
836 | location given the options that were passed to @command{configure}. | |
837 | @end deffn | |
838 | ||
839 | @deffn {Scheme Procedure} close-connection @var{server} | |
840 | Close the connection to @var{server}. | |
841 | @end deffn | |
842 | ||
843 | @defvr {Scheme Variable} current-build-output-port | |
844 | This variable is bound to a SRFI-39 parameter, which refers to the port | |
845 | where build and error logs sent by the daemon should be written. | |
846 | @end defvr | |
847 | ||
848 | Procedures that make RPCs all take a server object as their first | |
849 | argument. | |
850 | ||
851 | @deffn {Scheme Procedure} valid-path? @var{server} @var{path} | |
852 | Return @code{#t} when @var{path} is a valid store path. | |
853 | @end deffn | |
854 | ||
855 | @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} @var{references} | |
856 | Add @var{text} under file @var{name} in the store, and return its store | |
857 | path. @var{references} is the list of store paths referred to by the | |
858 | resulting store path. | |
859 | @end deffn | |
860 | ||
874e6874 LC |
861 | @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations} |
862 | Build @var{derivations} (a list of derivation paths), and return when | |
863 | the worker is done building them. Return @code{#t} on success. | |
864 | @end deffn | |
865 | ||
e531ac2a LC |
866 | @c FIXME |
867 | @i{This section is currently incomplete.} | |
568717fd LC |
868 | |
869 | @node Derivations | |
870 | @section Derivations | |
871 | ||
874e6874 LC |
872 | @cindex derivations |
873 | Low-level build actions and the environment in which they are performed | |
874 | are represented by @dfn{derivations}. A derivation contain the | |
875 | following pieces of information: | |
876 | ||
877 | @itemize | |
878 | @item | |
879 | The outputs of the derivation---derivations produce at least one file or | |
880 | directory in the store, but may produce more. | |
881 | ||
882 | @item | |
883 | The inputs of the derivations, which may be other derivations or plain | |
884 | files in the store (patches, build scripts, etc.) | |
885 | ||
886 | @item | |
887 | The system type targeted by the derivation---e.g., @code{x86_64-linux}. | |
888 | ||
889 | @item | |
890 | The file name of a build script in the store, along with the arguments | |
891 | to be passed. | |
892 | ||
893 | @item | |
894 | A list of environment variables to be defined. | |
895 | ||
896 | @end itemize | |
897 | ||
898 | @cindex derivation path | |
899 | Derivations allow clients of the daemon to communicate build actions to | |
900 | the store. They exist in two forms: as an in-memory representation, | |
901 | both on the client- and daemon-side, and as files in the store whose | |
902 | name end in @code{.drv}---these files are referred to as @dfn{derivation | |
903 | paths}. Derivations paths can be passed to the @code{build-derivations} | |
904 | procedure to perform the build actions they prescribe (@pxref{The | |
905 | Store}). | |
906 | ||
907 | The @code{(guix derivations)} module provides a representation of | |
908 | derivations as Scheme objects, along with procedures to create and | |
909 | otherwise manipulate derivations. The lowest-level primitive to create | |
910 | a derivation is the @code{derivation} procedure: | |
911 | ||
912 | @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{system} @var{builder} @var{args} @var{env-vars} @var{inputs} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] [#:hash-mode #f] | |
913 | Build a derivation with the given arguments. Return the resulting store | |
914 | path and @code{<derivation>} object. | |
915 | ||
916 | When @var{hash}, @var{hash-algo}, and @var{hash-mode} are given, a | |
917 | @dfn{fixed-output derivation} is created---i.e., one whose result is | |
918 | known in advance, such as a file download. | |
919 | @end deffn | |
920 | ||
921 | @noindent | |
922 | Here's an example with a shell script as its builder, assuming | |
923 | @var{store} is an open connection to the daemon, and @var{bash} points | |
924 | to a Bash executable in the store: | |
925 | ||
926 | @lisp | |
927 | (use-modules (guix utils) | |
928 | (guix store) | |
929 | (guix derivations)) | |
930 | ||
931 | (call-with-values | |
932 | (lambda () | |
933 | (let ((builder ; add the Bash script to the store | |
934 | (add-text-to-store store "my-builder.sh" | |
935 | "echo hello world > $out\n" '()))) | |
936 | (derivation store "foo" (%current-system) | |
937 | bash `("-e" ,builder) | |
938 | '(("HOME" . "/homeless")) '()))) | |
939 | list) | |
940 | @result{} ("/nix/store/@dots{}-foo.drv" #<<derivation> @dots{}>) | |
941 | @end lisp | |
942 | ||
943 | As can be guessed, this primitive is cumbersome to use directly. An | |
944 | improved variant is @code{build-expression->derivation}, which allows | |
945 | the caller to directly pass a Guile expression as the build script: | |
946 | ||
947 | @deffn {Scheme Procedure} build-expression->derivation @var{store} @var{name} @var{system} @var{exp} @var{inputs} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] [#:env-vars '()] [#:modules '()] [#:guile-for-build #f] | |
948 | Return a derivation that executes Scheme expression @var{exp} as a | |
949 | builder for derivation @var{name}. @var{inputs} must be a list of | |
950 | @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted, | |
951 | @code{"out"} is assumed. @var{modules} is a list of names of Guile | |
952 | modules from the current search path to be copied in the store, | |
953 | compiled, and made available in the load path during the execution of | |
954 | @var{exp}---e.g., @code{((guix build utils) (guix build | |
955 | gnu-build-system))}. | |
956 | ||
957 | @var{exp} is evaluated in an environment where @code{%outputs} is bound | |
958 | to a list of output/path pairs, and where @code{%build-inputs} is bound | |
959 | to a list of string/output-path pairs made from @var{inputs}. | |
960 | Optionally, @var{env-vars} is a list of string pairs specifying the name | |
961 | and value of environment variables visible to the builder. The builder | |
962 | terminates by passing the result of @var{exp} to @code{exit}; thus, when | |
963 | @var{exp} returns @code{#f}, the build is considered to have failed. | |
964 | ||
965 | @var{exp} is built using @var{guile-for-build} (a derivation). When | |
966 | @var{guile-for-build} is omitted or is @code{#f}, the value of the | |
967 | @code{%guile-for-build} fluid is used instead. | |
968 | @end deffn | |
969 | ||
970 | @noindent | |
971 | Here's an example of a single-output derivation that creates a directory | |
972 | containing one file: | |
973 | ||
974 | @lisp | |
975 | (let ((builder '(let ((out (assoc-ref %outputs "out"))) | |
976 | (mkdir out) ; create /nix/store/@dots{}-goo | |
977 | (call-with-output-file (string-append out "/test") | |
978 | (lambda (p) | |
979 | (display '(hello guix) p)))))) | |
980 | (build-expression->derivation store "goo" (%current-system) | |
981 | builder '())) | |
982 | ||
983 | @result{} "/nix/store/@dots{}-goo.drv" | |
984 | @result{} #<<derivation> @dots{}> | |
985 | @end lisp | |
986 | ||
987 | @cindex strata of code | |
988 | Remember that the build expression passed to | |
989 | @code{build-expression->derivation} is run by a separate Guile process | |
990 | than the one that calls @code{build-expression->derivation}: it is run | |
991 | by a Guile process launched by the daemon, typically in a chroot. So, | |
992 | while there is a single language for both the @dfn{host} and the build | |
993 | side, there are really two @dfn{strata} of code: the host-side, and the | |
994 | build-side code@footnote{The term @dfn{stratum} in this context was | |
995 | coined by Manuel Serrano et al. in the context of their work on Hop.}. | |
996 | This distinction is important to keep in mind, notably when using | |
997 | higher-level constructs such as @var{gnu-build-system} (@pxref{Defining | |
998 | Packages}). For this reason, Guix modules that are meant to be used in | |
999 | the build stratum are kept in the @code{(guix build @dots{})} name | |
1000 | space. | |
568717fd LC |
1001 | |
1002 | @c ********************************************************************* | |
1003 | @node Utilities | |
1004 | @chapter Utilities | |
1005 | ||
1006 | @menu | |
1007 | * Invoking guix-build:: Building packages from the command line. | |
1008 | @end menu | |
1009 | ||
1010 | @node Invoking guix-build | |
1011 | @section Invoking @command{guix-build} | |
1012 | ||
c78bd12b | 1013 | The @command{guix-build} command builds packages or derivations and |
6798a8e4 LC |
1014 | their dependencies, and prints the resulting store paths. Note that it |
1015 | does not modify the user's profile---this is the job of the | |
1016 | @command{guix-package} command (@pxref{Invoking guix-package}). Thus, | |
1017 | it is mainly useful for distribution developers. | |
1018 | ||
1019 | The general syntax is: | |
c78bd12b LC |
1020 | |
1021 | @example | |
1022 | guix-build @var{options} @var{package-or-derivation}@dots{} | |
1023 | @end example | |
1024 | ||
1025 | @var{package-or-derivation} may be either the name of a package found in | |
5401dd75 LC |
1026 | the software distribution such as @code{coreutils} or |
1027 | @code{coreutils-8.20}, or a derivation such as | |
1028 | @file{/nix/store/@dots{}-coreutils-8.19.drv}. Alternatively, the | |
c78bd12b LC |
1029 | @code{--expression} option may be used to specify a Scheme expression |
1030 | that evaluates to a package; this is useful when disambiguation among | |
1031 | several same-named packages or package variants is needed. | |
1032 | ||
1033 | The @var{options} may be zero or more of the following: | |
1034 | ||
1035 | @table @code | |
1036 | ||
1037 | @item --expression=@var{expr} | |
1038 | @itemx -e @var{expr} | |
1039 | Build the package @var{expr} evaluates to. | |
1040 | ||
5401dd75 | 1041 | For example, @var{expr} may be @code{(@@ (gnu packages guile) |
c78bd12b LC |
1042 | guile-1.8)}, which unambiguously designates this specific variant of |
1043 | version 1.8 of Guile. | |
1044 | ||
1045 | @item --source | |
1046 | @itemx -S | |
1047 | Build the packages' source derivations, rather than the packages | |
1048 | themselves. | |
1049 | ||
1050 | For instance, @code{guix-build -S gcc} returns something like | |
6798a8e4 | 1051 | @file{/nix/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball. |
c78bd12b LC |
1052 | |
1053 | @item --system=@var{system} | |
1054 | @itemx -s @var{system} | |
1055 | Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of | |
1056 | the host's system type. | |
1057 | ||
1058 | An example use of this is on Linux-based systems, which can emulate | |
1059 | different personalities. For instance, passing | |
1060 | @code{--system=i686-linux} on an @code{x86_64-linux} system allows users | |
1061 | to build packages in a complete 32-bit environment. | |
1062 | ||
1063 | @item --derivations | |
1064 | @itemx -d | |
1065 | Return the derivation paths, not the output paths, of the given | |
1066 | packages. | |
1067 | ||
1068 | @item --keep-failed | |
1069 | @itemx -K | |
1070 | Keep the build tree of failed builds. Thus, if a build fail, its build | |
1071 | tree is kept under @file{/tmp}, in a directory whose name is shown at | |
1072 | the end of the build log. This is useful when debugging build issues. | |
1073 | ||
1074 | @item --dry-run | |
1075 | @itemx -n | |
1076 | Do not build the derivations. | |
1077 | ||
1078 | @item --no-substitutes | |
1079 | Build instead of resorting to pre-built substitutes. | |
1080 | ||
1081 | @item --cores=@var{n} | |
1082 | @itemx -c @var{n} | |
1083 | Allow the use of up to @var{n} CPU cores for the build. The special | |
1084 | value @code{0} means to use as many CPU cores as available. | |
1085 | ||
1086 | @item --root=@var{file} | |
1087 | @itemx -r @var{file} | |
1088 | Make @var{file} a symlink to the result, and register it as a garbage | |
1089 | collector root. | |
07ab4bf1 LC |
1090 | |
1091 | @item --verbosity=@var{level} | |
1092 | Use the given verbosity level. @var{level} must be an integer between 0 | |
1093 | and 5; higher means more verbose output. Setting a level of 4 or more | |
1094 | may be helpful when debugging setup issues with the build daemon. | |
1095 | ||
c78bd12b LC |
1096 | @end table |
1097 | ||
1098 | Behind the scenes, @command{guix-build} is essentially an interface to | |
1099 | the @code{package-derivation} procedure of the @code{(guix packages)} | |
1100 | module, and to the @code{build-derivations} procedure of the @code{(guix | |
1101 | store)} module. | |
1102 | ||
a1ba8475 LC |
1103 | @c ********************************************************************* |
1104 | @node GNU Distribution | |
1105 | @chapter GNU Distribution | |
1106 | ||
1107 | Guix comes with a distribution of free software@footnote{The term | |
1108 | ``free'' here refers to the | |
1109 | @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to | |
1110 | users of that software}.} that form the basis of the GNU system. This | |
1111 | includes core GNU packages such as GNU libc, GCC, and Binutils, as well | |
1112 | as many GNU and non-GNU applications. The complete list of available | |
1113 | packages can be seen by running @command{guix-package} (@pxref{Invoking | |
1114 | guix-package}): | |
1115 | ||
1116 | @example | |
1117 | guix-package --list-available | |
1118 | @end example | |
1119 | ||
1120 | The package definitions of the distribution may are provided by Guile | |
1121 | modules in the @code{(gnu packages ...)} name space---for instance, the | |
1122 | @code{(gnu packages emacs)} module exports a variable named | |
1123 | @code{emacs}, which is bound to a @code{<package>} object | |
1124 | (@pxref{Defining Packages}). The @code{(gnu packages)} module provides | |
1125 | facilities for searching for packages. | |
1126 | ||
1127 | The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}: | |
1128 | each package is built based solely on other packages in the | |
1129 | distribution. The root of this dependency graph is a small set of | |
1130 | @dfn{bootstrap binaries}, provided by the @code{(gnu packages | |
1131 | bootstrap)} module. These are statically-linked binaries of the core | |
1132 | tools without which building anything at all would be impossible. | |
1133 | ||
1134 | ||
1135 | Our goal is to build a practical 100% free software distribution of | |
1136 | Linux-based and other variants of GNU, with a focus on the promotion and | |
1137 | tight integration of GNU components, and an emphasis on programs and | |
1138 | tools that help users exert that freedom. | |
1139 | ||
1140 | Building this distribution is a cooperative effort, and you are invited | |
1141 | to join! Please get in touch with us on @email{bug-guix@@gnu.org}. We | |
1142 | welcome ideas, bug reports, patches, and anything that may be helpful to | |
1143 | the project. | |
1144 | ||
c78bd12b | 1145 | |
568717fd LC |
1146 | @c ********************************************************************* |
1147 | @node Acknowledgments | |
1148 | @chapter Acknowledgments | |
1149 | ||
1150 | Guix is based on the Nix package manager, which was designed and | |
1151 | implemented by Eelco Dolstra. Nix pioneered functional package | |
1152 | management, and promoted unprecedented features, such as transactional | |
1153 | package upgrades and rollbacks, per-user profiles, and referentially | |
1154 | transparent build processes. Without this work, Guix would not exist. | |
1155 | ||
1156 | The Nix-based software distributions, Nixpkgs and NixOS, have also been | |
1157 | an inspiration for Guix. | |
1158 | ||
1159 | @c ********************************************************************* | |
1160 | @node GNU Free Documentation License | |
1161 | @appendix GNU Free Documentation License | |
1162 | ||
1163 | @include fdl-1.3.texi | |
1164 | ||
1165 | @c ********************************************************************* | |
1166 | @node Concept Index | |
1167 | @unnumbered Concept Index | |
1168 | @printindex cp | |
1169 | ||
1170 | @node Function Index | |
1171 | @unnumbered Function Index | |
1172 | @printindex fn | |
1173 | ||
1174 | @bye | |
1175 | ||
1176 | @c Local Variables: | |
1177 | @c ispell-local-dictionary: "american"; | |
1178 | @c End: |