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. | |
e49951eb | 16 | * guix package: (guix)Invoking guix package |
eeaf4427 | 17 | Managing packages with Guix. |
e49951eb | 18 | * guix build: (guix)Invoking guix build |
568717fd LC |
19 | Building packages with Guix. |
20 | @end direntry | |
568717fd LC |
21 | |
22 | @titlepage | |
7730d112 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. |
9bf3c1a7 | 85 | * Contributing:: Your help needed! |
568717fd LC |
86 | |
87 | * Acknowledgments:: Thanks! | |
88 | * GNU Free Documentation License:: The license of this manual. | |
89 | * Concept Index:: Concepts. | |
90 | * Function Index:: Functions. | |
91 | @end menu | |
92 | ||
93 | @c ********************************************************************* | |
94 | @node Introduction | |
95 | @chapter Introduction | |
96 | ||
c80e7e55 LC |
97 | GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks'' |
98 | using the international phonetic alphabet (IPA).} is a functional | |
99 | package management tool for the GNU system. Package management consists | |
4bfc4ea3 NK |
100 | of all activities that relate to building packages from sources, |
101 | honoring their build-time and run-time dependencies, | |
c80e7e55 LC |
102 | installing packages in user environments, upgrading installed packages |
103 | to new versions or rolling back to a previous set, removing unused | |
104 | software packages, etc. | |
568717fd LC |
105 | |
106 | @cindex functional package management | |
107 | The term @dfn{functional} refers to a specific package management | |
108 | discipline. In Guix, the package build and installation process is seen | |
4bfc4ea3 NK |
109 | as a function, in the mathematical sense. That function takes inputs, |
110 | such as build scripts, a compiler, and libraries, and | |
111 | returns an installed package. As a pure function, its result depends | |
568717fd LC |
112 | solely on its inputs---for instance, it cannot refer to software or |
113 | scripts that were not explicitly passed as inputs. A build function | |
4bfc4ea3 NK |
114 | always produces the same result when passed a given set of inputs. It |
115 | cannot alter the system's environment in | |
568717fd LC |
116 | any way; for instance, it cannot create, modify, or delete files outside |
117 | of its build and installation directories. This is achieved by running | |
4bfc4ea3 NK |
118 | build processes in isolated environments (or @dfn{chroots}), where only their |
119 | explicit inputs are visible. | |
568717fd | 120 | |
e531ac2a | 121 | @cindex store |
568717fd | 122 | The result of package build functions is @dfn{cached} in the file |
e531ac2a LC |
123 | system, in a special directory called @dfn{the store} (@pxref{The |
124 | Store}). Each package is installed in a directory of its own, in the | |
568717fd LC |
125 | store---by default under @file{/nix/store}. The directory name contains |
126 | a hash of all the inputs used to build that package; thus, changing an | |
127 | input yields a different directory name. | |
128 | ||
129 | This approach is the foundation of Guix's salient features: support for | |
4bfc4ea3 | 130 | transactional package upgrade and rollback, per-user installation, and |
eeaf4427 | 131 | garbage collection of packages (@pxref{Features}). |
568717fd | 132 | |
4bfc4ea3 | 133 | Guix has a command-line interface, which allows users to build, install, |
568717fd | 134 | upgrade, and remove packages, as well as a Scheme programming interface. |
568717fd | 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 | ||
48febeb8 LC |
144 | GNU Guix is available for download from its website at |
145 | @url{http://www.gnu.org/software/guix/}. This section describes the | |
146 | software requirements of Guix, as well as how to install it and get | |
147 | ready to use it. | |
bd5e766b | 148 | |
b22a12fd | 149 | The build procedure for Guix is the same as for other GNU software, and |
1da983b9 | 150 | is not covered here. Please see the files @file{README} and |
b22a12fd LC |
151 | @file{INSTALL} in the Guix source tree for additional details. |
152 | ||
bd5e766b LC |
153 | @menu |
154 | * Requirements:: Software needed to build and run Guix. | |
155 | * Setting Up the Daemon:: Preparing the build daemon's environment. | |
156 | * Invoking guix-daemon:: Running the build daemon. | |
157 | @end menu | |
158 | ||
159 | @node Requirements | |
160 | @section Requirements | |
161 | ||
162 | GNU Guix depends on the following packages: | |
163 | ||
164 | @itemize | |
4a328f73 | 165 | @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.5 or later; |
bd5e766b LC |
166 | @item @url{http://gnupg.org/, GNU libgcrypt} |
167 | @end itemize | |
168 | ||
169 | Unless @code{--disable-daemon} was passed to @command{configure}, the | |
170 | following packages are also needed: | |
171 | ||
172 | @itemize | |
173 | @item @url{http://sqlite.org, SQLite 3} | |
174 | @item @url{http://www.bzip.org, libbz2} | |
175 | @item @url{http://gcc.gnu.org, GCC's g++} | |
176 | @end itemize | |
177 | ||
4bfc4ea3 NK |
178 | When a working installation of @url{http://nixos.org/nix/, the Nix package |
179 | manager} is available, you | |
bd5e766b | 180 | can instead configure Guix with @code{--disable-daemon}. In that case, |
4bfc4ea3 | 181 | Nix replaces the three dependencies above. |
bd5e766b | 182 | |
b22a12fd LC |
183 | Guix is compatible with Nix, so it is possible to share the same store |
184 | between both. To do so, you must pass @command{configure} not only the | |
185 | same @code{--with-store-dir} value, but also the same | |
4bfc4ea3 NK |
186 | @code{--localstatedir} value. The latter is essential because it |
187 | specifies where the database that stores metadata about the store is | |
188 | located, among other things. The default values are | |
b22a12fd | 189 | @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}. |
4bfc4ea3 NK |
190 | Note that @code{--disable-daemon} is not required if |
191 | your goal is to share the store with Nix. | |
b22a12fd | 192 | |
bd5e766b LC |
193 | @node Setting Up the Daemon |
194 | @section Setting Up the Daemon | |
195 | ||
196 | @cindex daemon | |
197 | Operations such as building a package or running the garbage collector | |
198 | are all performed by a specialized process, the @dfn{Guix daemon}, on | |
199 | behalf of clients. Only the daemon may access the store and its | |
200 | associated database. Thus, any operation that manipulates the store | |
201 | goes through the daemon. For instance, command-line tools such as | |
e49951eb | 202 | @command{guix package} and @command{guix build} communicate with the |
bd5e766b LC |
203 | daemon (@i{via} remote procedure calls) to instruct it what to do. |
204 | ||
205 | In a standard multi-user setup, Guix and its daemon---the | |
206 | @command{guix-daemon} program---are installed by the system | |
207 | administrator; @file{/nix/store} is owned by @code{root} and | |
208 | @command{guix-daemon} runs as @code{root}. Unprivileged users may use | |
209 | Guix tools to build packages or otherwise access the store, and the | |
210 | daemon will do it on their behalf, ensuring that the store is kept in a | |
211 | consistent state, and allowing built packages to be shared among users. | |
212 | ||
213 | @cindex build users | |
214 | When @command{guix-daemon} runs as @code{root}, you may not want package | |
215 | build processes themselves to run as @code{root} too, for obvious | |
216 | security reasons. To avoid that, a special pool of @dfn{build users} | |
217 | should be created for use by build processes started by the daemon. | |
218 | These build users need not have a shell and a home directory: they will | |
219 | just be used when the daemon drops @code{root} privileges in build | |
220 | processes. Having several such users allows the daemon to launch | |
221 | distinct build processes under separate UIDs, which guarantees that they | |
222 | do not interfere with each other---an essential feature since builds are | |
223 | regarded as pure functions (@pxref{Introduction}). | |
224 | ||
225 | On a GNU/Linux system, a build user pool may be created like this (using | |
226 | Bash syntax and the @code{shadow} commands): | |
227 | ||
091196b3 LC |
228 | @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html |
229 | @c for why `-G' is needed. | |
bd5e766b LC |
230 | @example |
231 | # groupadd guix-builder | |
232 | # for i in `seq 1 10`; | |
233 | do | |
091196b3 LC |
234 | useradd -g guix-builder -G guix-builder \ |
235 | -d /var/empty -s `which nologin` \ | |
80ba8cc0 | 236 | -c "Guix build user $i" guix-builder$i; |
bd5e766b LC |
237 | done |
238 | @end example | |
239 | ||
240 | @noindent | |
241 | The @code{guix-daemon} program may then be run as @code{root} with: | |
242 | ||
243 | @example | |
244 | # guix-daemon --build-users-group=guix-builder | |
245 | @end example | |
246 | ||
b095792f LC |
247 | @noindent |
248 | This way, the daemon starts build processes in a chroot, under one of | |
249 | the @code{guix-builder} users. On GNU/Linux, by default, the chroot | |
250 | environment contains nothing but the @code{/dev} and @code{/proc} | |
251 | directories@footnote{On some systems @code{/dev/shm}, which supports | |
252 | shared memory, is a symlink to another directory such as | |
253 | @code{/run/shm}, that is @emph{not} is the chroot. When that is the | |
254 | case, shared memory support is unavailable in the chroot environment. | |
255 | The workaround is to make sure that @file{/dev/shm} is directly a | |
256 | @code{tmpfs} mount point.}. | |
257 | ||
bd5e766b | 258 | Guix may also be used in a single-user setup, with @command{guix-daemon} |
1da983b9 | 259 | running as an unprivileged user. However, to maximize non-interference |
bd5e766b LC |
260 | of build processes, the daemon still needs to perform certain operations |
261 | that are restricted to @code{root} on GNU/Linux: it should be able to | |
262 | run build processes in a chroot, and to run them under different UIDs. | |
263 | To that end, the @command{nix-setuid-helper} program is provided; it is | |
264 | a small C program (less than 300 lines) that, if it is made setuid | |
265 | @code{root}, can be executed by the daemon to perform these operations | |
266 | on its behalf. The @code{root}-owned @file{/etc/nix-setuid.conf} file | |
267 | is read by @command{nix-setuid-helper}; it should contain exactly two | |
268 | words: the user name under which the authorized @command{guix-daemon} | |
269 | runs, and the name of the build users group. | |
270 | ||
271 | If you are installing Guix as an unprivileged user and do not have the | |
272 | ability to make @file{nix-setuid-helper} setuid-@code{root}, it is still | |
273 | possible to run @command{guix-daemon}. However, build processes will | |
274 | not be isolated from one another, and not from the rest of the system. | |
275 | Thus, build processes may interfere with each other, and may access | |
276 | programs, libraries, and other files available on the system---making it | |
277 | much harder to view them as @emph{pure} functions. | |
278 | ||
279 | @node Invoking guix-daemon | |
280 | @section Invoking @command{guix-daemon} | |
281 | ||
282 | The @command{guix-daemon} program implements all the functionality to | |
283 | access the store. This includes launching build processes, running the | |
284 | garbage collector, querying the availability of a build result, etc. It | |
285 | is normally run as @code{root} like this: | |
286 | ||
287 | @example | |
288 | # guix-daemon --build-users-group=guix-builder | |
289 | @end example | |
290 | ||
291 | @noindent | |
292 | For details on how to set it up, @ref{Setting Up the Daemon}. | |
293 | ||
294 | By default, @command{guix-daemon} launches build processes under | |
295 | different UIDs, taken from the build group specified with | |
296 | @code{--build-users-group}. In addition, each build process is run in a | |
297 | chroot environment that only contains the subset of the store that the | |
298 | build process depends on, as specified by its derivation | |
299 | (@pxref{Programming Interface, derivation}), plus a set of specific | |
300 | system directories. By default, the latter contains @file{/dev} and | |
301 | @file{/dev/pts}. | |
302 | ||
303 | The following command-line options are supported: | |
304 | ||
305 | @table @code | |
306 | @item --build-users-group=@var{group} | |
307 | Take users from @var{group} to run build processes (@pxref{Setting Up | |
308 | the Daemon, build users}). | |
309 | ||
6858f9d1 LC |
310 | @item --no-substitutes |
311 | Do not use substitutes for build products. That is, always build things | |
312 | locally instead of allowing downloads of pre-built binaries. | |
313 | ||
bd5e766b LC |
314 | @item --cache-failures |
315 | Cache build failures. By default, only successful builds are cached. | |
316 | ||
317 | @item --cores=@var{n} | |
318 | @itemx -c @var{n} | |
319 | Use @var{n} CPU cores to build each derivation; @code{0} means as many | |
320 | as available. | |
321 | ||
322 | The default value is @code{1}, but it may be overridden by clients, such | |
e49951eb MW |
323 | as the @code{--cores} option of @command{guix build} (@pxref{Invoking |
324 | guix build}). | |
bd5e766b LC |
325 | |
326 | The effect is to define the @code{NIX_BUILD_CORES} environment variable | |
327 | in the build process, which can then use it to exploit internal | |
328 | parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}. | |
329 | ||
330 | @item --max-jobs=@var{n} | |
331 | @itemx -M @var{n} | |
332 | Allow at most @var{n} build jobs in parallel. The default value is | |
333 | @code{1}. | |
334 | ||
335 | @item --debug | |
336 | Produce debugging output. | |
337 | ||
338 | This is useful to debug daemon start-up issues, but then it may be | |
339 | overridden by clients, for example the @code{--verbosity} option of | |
e49951eb | 340 | @command{guix build} (@pxref{Invoking guix build}). |
bd5e766b LC |
341 | |
342 | @item --chroot-directory=@var{dir} | |
343 | Add @var{dir} to the build chroot. | |
344 | ||
345 | Doing this may change the result of build processes---for instance if | |
346 | they use optional dependencies found in @var{dir} when it is available, | |
347 | and not otherwise. For that reason, it is not recommended to do so. | |
348 | Instead, make sure that each derivation declares all the inputs that it | |
349 | needs. | |
350 | ||
351 | @item --disable-chroot | |
352 | Disable chroot builds. | |
353 | ||
354 | Using this option is not recommended since, again, it would allow build | |
355 | processes to gain access to undeclared dependencies. | |
356 | ||
357 | @item --disable-log-compression | |
358 | Disable compression of the build logs. | |
359 | ||
1da983b9 LC |
360 | Unless @code{--lose-logs} is used, all the build logs are kept in the |
361 | @var{localstatedir}. To save space, the daemon automatically compresses | |
362 | them with bzip2 by default. This option disables that. | |
363 | ||
bd5e766b LC |
364 | @item --disable-store-optimization |
365 | Disable automatic file ``deduplication'' in the store. | |
366 | ||
1da983b9 LC |
367 | By default, files added to the store are automatically ``deduplicated'': |
368 | if a newly added file is identical as another one found in the store, | |
369 | the daemon makes the new file a hard link to the other file. This | |
370 | slightly increases the input/output load at the end of a build process. | |
371 | This option disables this. | |
372 | ||
bd5e766b LC |
373 | @item --impersonate-linux-2.6 |
374 | On Linux-based systems, impersonate Linux 2.6. This means that the | |
375 | kernel's @code{uname} system call will report 2.6 as the release number. | |
376 | ||
377 | This might be helpful to build programs that (usually wrongfully) depend | |
378 | on the kernel version number. | |
379 | ||
380 | @item --lose-logs | |
381 | Do not keep build logs. By default they are kept under | |
382 | @code{@var{localstatedir}/nix/log}. | |
383 | ||
384 | @item --system=@var{system} | |
385 | Assume @var{system} as the current system type. By default it is the | |
386 | architecture/kernel pair found at configure time, such as | |
387 | @code{x86_64-linux}. | |
b8d2aa26 LC |
388 | |
389 | @item --listen=@var{socket} | |
390 | Listen for connections on @var{socket}, the file name of a Unix-domain | |
391 | socket. The default socket is | |
392 | @file{@var{localstatedir}/daemon-socket/socket}. This option is only | |
393 | useful in exceptional circumstances, such as if you need to run several | |
394 | daemons on the same machine. | |
bd5e766b LC |
395 | @end table |
396 | ||
397 | ||
eeaf4427 LC |
398 | @c ********************************************************************* |
399 | @node Package Management | |
400 | @chapter Package Management | |
401 | ||
f8348b91 | 402 | The purpose of GNU Guix is to allow users to easily install, upgrade, and |
eeaf4427 LC |
403 | remove software packages, without having to know about their build |
404 | procedure or dependencies. Guix also goes beyond this obvious set of | |
405 | features. | |
406 | ||
407 | This chapter describes the main features of Guix, as well as the package | |
408 | management tools it provides. | |
409 | ||
410 | @menu | |
411 | * Features:: How Guix will make your life brighter. | |
e49951eb | 412 | * Invoking guix package:: Package installation, removal, etc. |
6e721c4d | 413 | * Packages with Multiple Outputs:: Single source package, multiple outputs. |
e49951eb | 414 | * Invoking guix gc:: Running the garbage collector. |
f651b477 | 415 | * Invoking guix pull:: Fetching the latest Guix and distribution. |
eeaf4427 LC |
416 | @end menu |
417 | ||
418 | @node Features | |
419 | @section Features | |
420 | ||
421 | When using Guix, each package ends up in the @dfn{package store}, in its | |
422 | own directory---something that resembles | |
423 | @file{/nix/store/xxx-package-1.2}, where @code{xxx} is a base32 string. | |
424 | ||
425 | Instead of referring to these directories, users have their own | |
426 | @dfn{profile}, which points to the packages that they actually want to | |
821b0015 LC |
427 | use. These profiles are stored within each user's home directory, at |
428 | @code{$HOME/.guix-profile}. | |
eeaf4427 | 429 | |
821b0015 | 430 | For example, @code{alice} installs GCC 4.7.2. As a result, |
eeaf4427 | 431 | @file{/home/alice/.guix-profile/bin/gcc} points to |
821b0015 LC |
432 | @file{/nix/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine, |
433 | @code{bob} had already installed GCC 4.8.0. The profile of @code{bob} | |
434 | simply continues to point to | |
435 | @file{/nix/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC | |
436 | coexist on the same system without any interference. | |
eeaf4427 | 437 | |
e49951eb MW |
438 | The @command{guix package} command is the central tool to manage |
439 | packages (@pxref{Invoking guix package}). It operates on those per-user | |
821b0015 | 440 | profiles, and can be used @emph{with normal user privileges}. |
eeaf4427 LC |
441 | |
442 | The command provides the obvious install, remove, and upgrade | |
443 | operations. Each invocation is actually a @emph{transaction}: either | |
ba55b1cb | 444 | the specified operation succeeds, or nothing happens. Thus, if the |
e49951eb | 445 | @command{guix package} process is terminated during the transaction, |
eeaf4427 LC |
446 | or if a power outage occurs during the transaction, then the user's |
447 | profile remains in its previous state, and remains usable. | |
448 | ||
449 | In addition, any package transaction may be @emph{rolled back}. So, if, | |
450 | for example, an upgrade installs a new version of a package that turns | |
451 | out to have a serious bug, users may roll back to the previous instance | |
452 | of their profile, which was known to work well. | |
453 | ||
454 | All those packages in the package store may be @emph{garbage-collected}. | |
455 | Guix can determine which packages are still referenced by the user | |
fe8ff028 | 456 | profiles, and remove those that are provably no longer referenced |
e49951eb | 457 | (@pxref{Invoking guix gc}). Users may also explicitly remove old |
fe8ff028 LC |
458 | generations of their profile so that the packages they refer to can be |
459 | collected. | |
eeaf4427 LC |
460 | |
461 | Finally, Guix takes a @dfn{purely functional} approach to package | |
462 | management, as described in the introduction (@pxref{Introduction}). | |
463 | Each @file{/nix/store} package directory name contains a hash of all the | |
464 | inputs that were used to build that package---compiler, libraries, build | |
465 | scripts, etc. This direct correspondence allows users to make sure a | |
466 | given package installation matches the current state of their | |
a1ba8475 | 467 | distribution, and helps maximize @dfn{reproducibility}. |
eeaf4427 LC |
468 | |
469 | This foundation allows Guix to support @dfn{transparent binary/source | |
3b78d1ea | 470 | deployment}. When a pre-built binary for a @file{/nix/store} path is |
eeaf4427 LC |
471 | available from an external source, Guix just downloads it; otherwise, it |
472 | builds the package from source, locally. | |
473 | ||
e49951eb MW |
474 | @node Invoking guix package |
475 | @section Invoking @command{guix package} | |
eeaf4427 | 476 | |
e49951eb | 477 | The @command{guix package} command is the tool that allows users to |
eeaf4427 LC |
478 | install, upgrade, and remove packages, as well as rolling back to |
479 | previous configurations. It operates only on the user's own profile, | |
480 | and works with normal user privileges (@pxref{Features}). Its syntax | |
481 | is: | |
482 | ||
483 | @example | |
e49951eb | 484 | guix package @var{options} |
eeaf4427 LC |
485 | @end example |
486 | ||
ba55b1cb | 487 | Primarily, @var{options} specifies the operations to be performed during |
eeaf4427 LC |
488 | the transaction. Upon completion, a new profile is created, but |
489 | previous generations of the profile remain available, should the user | |
490 | want to roll back. | |
491 | ||
b9e5c0a9 | 492 | For each user, a symlink to the user's default profile is automatically |
0ec1af59 | 493 | created in @file{$HOME/.guix-profile}. This symlink always points to the |
b9e5c0a9 LC |
494 | current generation of the user's default profile. Thus, users can add |
495 | @file{$HOME/.guix-profile/bin} to their @code{PATH} environment | |
496 | variable, and so on. | |
497 | ||
0ec1af59 LC |
498 | In a multi-user setup, user profiles must be stored in a place |
499 | registered as a @dfn{garbage-collector root}, which | |
e49951eb | 500 | @file{$HOME/.guix-profile} points to (@pxref{Invoking guix gc}). That |
0ec1af59 LC |
501 | directory is normally |
502 | @code{@var{localstatedir}/profiles/per-user/@var{user}}, where | |
503 | @var{localstatedir} is the value passed to @code{configure} as | |
504 | @code{--localstatedir}, and @var{user} is the user name. It must be | |
505 | created by @code{root}, with @var{user} as the owner. When it does not | |
70c43291 LC |
506 | exist, or is not owned by @var{user}, @command{guix package} emits an |
507 | error about it. | |
0ec1af59 LC |
508 | |
509 | The @var{options} can be among the following: | |
510 | ||
eeaf4427 LC |
511 | @table @code |
512 | ||
513 | @item --install=@var{package} | |
51c8d790 | 514 | @itemx -i @var{package} |
eeaf4427 LC |
515 | Install @var{package}. |
516 | ||
517 | @var{package} may specify either a simple package name, such as | |
518 | @code{guile}, or a package name followed by a hyphen and version number, | |
dc5669cd MW |
519 | such as @code{guile-1.8.8}. If no version number is specified, the |
520 | newest available version will be selected. In addition, @var{package} | |
521 | may contain a colon, followed by the name of one of the outputs of the | |
6e721c4d LC |
522 | package, as in @code{gcc:doc} or @code{binutils-2.22:lib} |
523 | (@pxref{Packages with Multiple Outputs}). | |
eeaf4427 | 524 | |
461572cc LC |
525 | @cindex propagated inputs |
526 | Sometimes packages have @dfn{propagated inputs}: these are dependencies | |
527 | that automatically get installed along with the required package. | |
528 | ||
529 | An example is the GNU MPC library: its C header files refer to those of | |
530 | the GNU MPFR library, which in turn refer to those of the GMP library. | |
531 | Thus, when installing MPC, the MPFR and GMP libraries also get installed | |
532 | in the profile; removing MPC also removes MPFR and GMP---unless they had | |
533 | also been explicitly installed independently. | |
534 | ||
5924080d LC |
535 | Besides, packages sometime rely on the definition of environment |
536 | variables for their search paths (see explanation of | |
537 | @code{--search-paths} below.) Any missing or possibly incorrect | |
538 | environment variable definitions are reported here. | |
539 | ||
ef010c0f | 540 | @c XXX: keep me up-to-date |
5924080d | 541 | Finally, when installing a GNU package, the tool reports the |
ef010c0f LC |
542 | availability of a newer upstream version. In the future, it may provide |
543 | the option of installing directly from the upstream version, even if | |
544 | that version is not yet in the distribution. | |
545 | ||
5d4b411f LC |
546 | @item --install-from-expression=@var{exp} |
547 | @itemx -e @var{exp} | |
548 | Install the package @var{exp} evaluates to. | |
549 | ||
550 | @var{exp} must be a Scheme expression that evaluates to a | |
551 | @code{<package>} object. This option is notably useful to disambiguate | |
552 | between same-named variants of a package, with expressions such as | |
553 | @code{(@@ (gnu packages base) guile-final)}. | |
554 | ||
555 | Note that this option installs the first output of the specified | |
556 | package, which may be insufficient when needing a specific output of a | |
557 | multiple-output package. | |
558 | ||
eeaf4427 LC |
559 | @item --remove=@var{package} |
560 | @itemx -r @var{package} | |
561 | Remove @var{package}. | |
562 | ||
acb6ba25 CR |
563 | @item --upgrade[=@var{regexp}] |
564 | @itemx -u [@var{regexp}] | |
565 | Upgrade all the installed packages. When @var{regexp} is specified, upgrade | |
566 | only installed packages whose name matches @var{regexp}. | |
eeaf4427 | 567 | |
f651b477 LC |
568 | Note that this upgrades package to the latest version of packages found |
569 | in the distribution currently installed. To update your distribution, | |
570 | you should regularly run @command{guix pull} (@pxref{Invoking guix | |
571 | pull}). | |
572 | ||
24e262f0 LC |
573 | @item --roll-back |
574 | Roll back to the previous @dfn{generation} of the profile---i.e., undo | |
575 | the last transaction. | |
576 | ||
577 | When combined with options such as @code{--install}, roll back occurs | |
578 | before any other actions. | |
579 | ||
d9307267 LC |
580 | When rolling back from the first generation that actually contains |
581 | installed packages, the profile is made to point to the @dfn{empty | |
582 | profile}, also known as @dfn{profile zero}---i.e., it contains no files | |
583 | apart from its own meta-data. | |
584 | ||
82fe08ed LC |
585 | Installing, removing, or upgrading packages from a generation that has |
586 | been rolled back to overwrites previous future generations. Thus, the | |
587 | history of a profile's generations is always linear. | |
588 | ||
5924080d LC |
589 | @item --search-paths |
590 | @cindex search paths | |
591 | Report environment variable definitions, in Bash syntax, that may be | |
592 | needed in order to use the set of installed packages. These environment | |
593 | variables are used to specify @dfn{search paths} for files used by some | |
594 | of the installed packages. | |
595 | ||
596 | For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH} | |
597 | environment variables to be defined so it can look for headers and | |
598 | libraries in the user's profile (@pxref{Environment Variables,,, gcc, | |
599 | Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C | |
600 | library are installed in the profile, then @code{--search-paths} will | |
601 | suggest setting these variables to @code{@var{profile}/include} and | |
602 | @code{@var{profile}/lib}, respectively. | |
603 | ||
eeaf4427 LC |
604 | @item --profile=@var{profile} |
605 | @itemx -p @var{profile} | |
606 | Use @var{profile} instead of the user's default profile. | |
607 | ||
608 | @item --dry-run | |
609 | @itemx -n | |
610 | Show what would be done without actually doing it. | |
611 | ||
56b1f4b7 LC |
612 | @item --fallback |
613 | When substituting a pre-built binary fails, fall back to building | |
614 | packages locally. | |
615 | ||
3b824605 | 616 | @item --no-substitutes |
969e678e LC |
617 | @itemx --max-silent-time=@var{seconds} |
618 | Same as for @command{guix build} (@pxref{Invoking guix build}). | |
3b824605 | 619 | |
70915c1a LC |
620 | @item --verbose |
621 | Produce verbose output. In particular, emit the environment's build log | |
622 | on the standard error port. | |
623 | ||
eeaf4427 LC |
624 | @item --bootstrap |
625 | Use the bootstrap Guile to build the profile. This option is only | |
626 | useful to distribution developers. | |
627 | ||
628 | @end table | |
629 | ||
e49951eb | 630 | In addition to these actions @command{guix package} supports the |
733b4130 LC |
631 | following options to query the current state of a profile, or the |
632 | availability of packages: | |
eeaf4427 | 633 | |
733b4130 LC |
634 | @table @option |
635 | ||
acc08466 NK |
636 | @item --search=@var{regexp} |
637 | @itemx -s @var{regexp} | |
638 | List the available packages whose synopsis or description matches | |
299112d3 LC |
639 | @var{regexp}. Print all the meta-data of matching packages in |
640 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, | |
641 | GNU recutils manual}). | |
acc08466 | 642 | |
299112d3 LC |
643 | This allows specific fields to be extracted using the @command{recsel} |
644 | command, for instance: | |
645 | ||
646 | @example | |
e49951eb | 647 | $ guix package -s malloc | recsel -p name,version |
299112d3 LC |
648 | name: glibc |
649 | version: 2.17 | |
650 | ||
651 | name: libgc | |
652 | version: 7.2alpha6 | |
653 | @end example | |
acc08466 | 654 | |
733b4130 LC |
655 | @item --list-installed[=@var{regexp}] |
656 | @itemx -I [@var{regexp}] | |
657 | List currently installed packages in the specified profile. When | |
658 | @var{regexp} is specified, list only installed packages whose name | |
659 | matches @var{regexp}. | |
660 | ||
661 | For each installed package, print the following items, separated by | |
662 | tabs: the package name, its version string, the part of the package that | |
663 | is installed (for instance, @code{out} for the default output, | |
664 | @code{include} for its headers, etc.), and the path of this package in | |
665 | the store. | |
666 | ||
64fc89b6 LC |
667 | @item --list-available[=@var{regexp}] |
668 | @itemx -A [@var{regexp}] | |
a1ba8475 LC |
669 | List packages currently available in the software distribution |
670 | (@pxref{GNU Distribution}). When @var{regexp} is specified, list only | |
671 | installed packages whose name matches @var{regexp}. | |
64fc89b6 LC |
672 | |
673 | For each package, print the following items separated by tabs: its name, | |
6e721c4d LC |
674 | its version string, the parts of the package (@pxref{Packages with |
675 | Multiple Outputs}), and the source location of its definition. | |
64fc89b6 | 676 | |
733b4130 | 677 | @end table |
eeaf4427 | 678 | |
6e721c4d LC |
679 | @node Packages with Multiple Outputs |
680 | @section Packages with Multiple Outputs | |
681 | ||
682 | @cindex multiple-output packages | |
683 | @cindex package outputs | |
684 | ||
685 | Often, packages defined in Guix have a single @dfn{output}---i.e., the | |
686 | source package leads exactly one directory in the store. When running | |
687 | @command{guix package -i glibc}, one installs the default output of the | |
688 | GNU libc package; the default output is called @code{out}, but its name | |
689 | can be omitted as shown in this command. In this particular case, the | |
690 | default output of @code{glibc} contains all the C header files, shared | |
691 | libraries, static libraries, Info documentation, and other supporting | |
692 | files. | |
693 | ||
694 | Sometimes it is more appropriate to separate the various types of files | |
695 | produced from a single source package into separate outputs. For | |
696 | instance, the GLib C library (used by GTK+ and related packages) | |
697 | installs more than 20 MiB of reference documentation as HTML pages. | |
698 | To save space for users who do not need it, the documentation goes to a | |
699 | separate output, called @code{doc}. To install the main GLib output, | |
700 | which contains everything but the documentation, one would run: | |
701 | ||
702 | @example | |
703 | guix package -i glib | |
704 | @end example | |
705 | ||
706 | The command to install its documentation is: | |
707 | ||
708 | @example | |
709 | guix package -i glib:doc | |
710 | @end example | |
711 | ||
712 | Some packages install programs with different ``dependency footprints''. | |
713 | For instance, the WordNet package install both command-line tools and | |
714 | graphical user interfaces (GUIs). The former depend solely on the C | |
715 | library, whereas the latter depend on Tcl/Tk and the underlying X | |
716 | libraries. In this case, we leave the command-line tools in the default | |
717 | output, whereas the GUIs are in a separate output. This allows users | |
718 | who do not need the GUIs to save space. | |
719 | ||
720 | There are several such multiple-output packages in the GNU distribution. | |
91ef73d4 LC |
721 | Other conventional output names include @code{lib} for libraries and |
722 | possibly header files, @code{bin} for stand-alone programs, and | |
723 | @code{debug} for debugging information (@pxref{Installing Debugging | |
724 | Files}). The outputs of a packages are listed in the third column of | |
725 | the output of @command{guix package --list-available} (@pxref{Invoking | |
726 | guix package}). | |
6e721c4d | 727 | |
eeaf4427 | 728 | |
e49951eb MW |
729 | @node Invoking guix gc |
730 | @section Invoking @command{guix gc} | |
fe8ff028 LC |
731 | |
732 | @cindex garbage collector | |
733 | Packages that are installed but not used may be @dfn{garbage-collected}. | |
e49951eb | 734 | The @command{guix gc} command allows users to explicitly run the garbage |
fe8ff028 LC |
735 | collector to reclaim space from the @file{/nix/store} directory. |
736 | ||
737 | The garbage collector has a set of known @dfn{roots}: any file under | |
738 | @file{/nix/store} reachable from a root is considered @dfn{live} and | |
739 | cannot be deleted; any other file is considered @dfn{dead} and may be | |
740 | deleted. The set of garbage collector roots includes default user | |
e49951eb MW |
741 | profiles, and may be augmented with @command{guix build --root}, for |
742 | example (@pxref{Invoking guix build}). | |
fe8ff028 | 743 | |
e49951eb | 744 | The @command{guix gc} command has three modes of operation: it can be |
fe8ff028 LC |
745 | used to garbage-collect any dead files (the default), to delete specific |
746 | files (the @code{--delete} option), or to print garbage-collector | |
747 | information. The available options are listed below: | |
748 | ||
749 | @table @code | |
750 | @item --collect-garbage[=@var{min}] | |
751 | @itemx -C [@var{min}] | |
752 | Collect garbage---i.e., unreachable @file{/nix/store} files and | |
753 | sub-directories. This is the default operation when no option is | |
754 | specified. | |
755 | ||
756 | When @var{min} is given, stop once @var{min} bytes have been collected. | |
757 | @var{min} may be a number of bytes, or it may include a unit as a | |
758 | suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes. | |
759 | ||
760 | When @var{min} is omitted, collect all the garbage. | |
761 | ||
762 | @item --delete | |
763 | @itemx -d | |
764 | Attempt to delete all the store files and directories specified as | |
765 | arguments. This fails if some of the files are not in the store, or if | |
766 | they are still live. | |
767 | ||
768 | @item --list-dead | |
769 | Show the list of dead files and directories still present in the | |
770 | store---i.e., files and directories no longer reachable from any root. | |
771 | ||
772 | @item --list-live | |
773 | Show the list of live store files and directories. | |
ba8b732d LC |
774 | |
775 | @end table | |
776 | ||
777 | In addition, the references among existing store files can be queried: | |
778 | ||
779 | @table @code | |
780 | ||
781 | @item --references | |
782 | @itemx --referrers | |
783 | List the references (respectively, the referrers) of store files given | |
784 | as arguments. | |
785 | ||
8e59fdd5 LC |
786 | @item --requisites |
787 | @itemx -R | |
788 | List the requisites of the store files passed as arguments. Requisites | |
789 | include the store files themselves, their references, and the references | |
790 | of these, recursively. In other words, the returned list is the | |
791 | @dfn{transitive closure} of the store files. | |
792 | ||
fe8ff028 LC |
793 | @end table |
794 | ||
eeaf4427 | 795 | |
f651b477 LC |
796 | @node Invoking guix pull |
797 | @section Invoking @command{guix pull} | |
798 | ||
799 | Packages are installed or upgraded to the latest version available in | |
800 | the distribution currently available on your local machine. To update | |
801 | that distribution, along with the Guix tools, you must run @command{guix | |
802 | pull}: the command downloads the latest Guix source code and package | |
803 | descriptions, and deploys it. | |
804 | ||
805 | On completion, @command{guix package} will use packages and package | |
806 | versions from this just-retrieved copy of Guix. Not only that, but all | |
807 | the Guix commands and Scheme modules will also be taken from that latest | |
808 | version. New @command{guix} sub-commands added by the update also | |
809 | become available. | |
810 | ||
811 | The @command{guix pull} command is usually invoked with no arguments, | |
812 | but it supports the following options: | |
813 | ||
814 | @table @code | |
815 | @item --verbose | |
816 | Produce verbose output, writing build logs to the standard error output. | |
817 | ||
818 | @item --bootstrap | |
819 | Use the bootstrap Guile to build the latest Guix. This option is only | |
820 | useful to Guix developers. | |
821 | @end table | |
822 | ||
568717fd LC |
823 | @c ********************************************************************* |
824 | @node Programming Interface | |
825 | @chapter Programming Interface | |
826 | ||
3dc1970d LC |
827 | GNU Guix provides several Scheme programming interfaces (APIs) to |
828 | define, build, and query packages. The first interface allows users to | |
829 | write high-level package definitions. These definitions refer to | |
830 | familiar packaging concepts, such as the name and version of a package, | |
831 | its build system, and its dependencies. These definitions can then be | |
832 | turned into concrete build actions. | |
833 | ||
ba55b1cb | 834 | Build actions are performed by the Guix daemon, on behalf of users. In a |
3dc1970d LC |
835 | standard setup, the daemon has write access to the store---the |
836 | @file{/nix/store} directory---whereas users do not. The recommended | |
837 | setup also has the daemon perform builds in chroots, under a specific | |
838 | build users, to minimize interference with the rest of the system. | |
839 | ||
840 | @cindex derivation | |
841 | Lower-level APIs are available to interact with the daemon and the | |
842 | store. To instruct the daemon to perform a build action, users actually | |
843 | provide it with a @dfn{derivation}. A derivation is a low-level | |
844 | representation of the build actions to be taken, and the environment in | |
845 | which they should occur---derivations are to package definitions what | |
846 | assembly is to C programs. | |
847 | ||
848 | This chapter describes all these APIs in turn, starting from high-level | |
849 | package definitions. | |
850 | ||
568717fd LC |
851 | @menu |
852 | * Defining Packages:: Defining new packages. | |
853 | * The Store:: Manipulating the package store. | |
854 | * Derivations:: Low-level interface to package derivations. | |
855 | @end menu | |
856 | ||
857 | @node Defining Packages | |
858 | @section Defining Packages | |
859 | ||
3dc1970d LC |
860 | The high-level interface to package definitions is implemented in the |
861 | @code{(guix packages)} and @code{(guix build-system)} modules. As an | |
862 | example, the package definition, or @dfn{recipe}, for the GNU Hello | |
863 | package looks like this: | |
864 | ||
865 | @example | |
b22a12fd LC |
866 | (use-modules (guix packages) |
867 | (guix download) | |
868 | (guix build-system gnu) | |
869 | (guix licenses)) | |
870 | ||
3dc1970d LC |
871 | (define hello |
872 | (package | |
873 | (name "hello") | |
874 | (version "2.8") | |
875 | (source (origin | |
876 | (method url-fetch) | |
877 | (uri (string-append "mirror://gnu/hello/hello-" version | |
878 | ".tar.gz")) | |
879 | (sha256 | |
880 | (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")))) | |
881 | (build-system gnu-build-system) | |
882 | (inputs `(("gawk" ,gawk))) | |
883 | (synopsis "GNU Hello") | |
884 | (description "Yeah...") | |
885 | (home-page "http://www.gnu.org/software/hello/") | |
b22a12fd | 886 | (license gpl3+))) |
3dc1970d LC |
887 | @end example |
888 | ||
889 | @noindent | |
890 | Without being a Scheme expert, the reader may have guessed the meaning | |
891 | of the various fields here. This expression binds variable @var{hello} | |
892 | to a @code{<package>} object, which is essentially a record | |
893 | (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}). | |
894 | This package object can be inspected using procedures found in the | |
895 | @code{(guix packages)} module; for instance, @code{(package-name hello)} | |
896 | returns---surprise!---@code{"hello"}. | |
897 | ||
898 | There are a few points worth noting in the above package definition: | |
899 | ||
900 | @itemize | |
901 | @item | |
902 | The @code{source} field of the package is an @code{<origin>} object. | |
903 | Here, the @code{url-fetch} method from @code{(guix download)} is used, | |
904 | meaning that the source is a file to be downloaded over FTP or HTTP. | |
905 | ||
906 | The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of | |
907 | the GNU mirrors defined in @code{(guix download)}. | |
908 | ||
909 | The @code{sha256} field specifies the expected SHA256 hash of the file | |
910 | being downloaded. It is mandatory, and allows Guix to check the | |
911 | integrity of the file. The @code{(base32 @dots{})} form introduces the | |
6c365eca | 912 | base32 representation of the hash. You can obtain this information with |
210cc920 LC |
913 | @code{guix download} (@pxref{Invoking guix download}) and @code{guix |
914 | hash} (@pxref{Invoking guix hash}). | |
3dc1970d LC |
915 | |
916 | @item | |
917 | @cindex GNU Build System | |
918 | The @code{build-system} field is set to @var{gnu-build-system}. The | |
919 | @var{gnu-build-system} variable is defined in the @code{(guix | |
920 | build-system gnu)} module, and is bound to a @code{<build-system>} | |
921 | object. | |
922 | ||
923 | Naturally, @var{gnu-build-system} represents the familiar GNU Build | |
924 | System, and variants thereof (@pxref{Configuration, configuration and | |
925 | makefile conventions,, standards, GNU Coding Standards}). In a | |
ba55b1cb | 926 | nutshell, packages using the GNU Build System may be configured, built, |
3dc1970d LC |
927 | and installed with the usual @code{./configure && make && make check && |
928 | make install} command sequence. This is what @var{gnu-build-system} | |
929 | does. | |
930 | ||
931 | In addition, @var{gnu-build-system} ensures that the ``standard'' | |
932 | environment for GNU packages is available. This includes tools such as | |
933 | GCC, Coreutils, Bash, Make, Diffutils, and Patch. | |
934 | ||
935 | @item | |
936 | The @code{inputs} field specifies inputs to the build process---i.e., | |
937 | build-time or run-time dependencies of the package. Here, we define an | |
938 | input called @code{"gawk"} whose value is that of the @var{gawk} | |
939 | variable; @var{gawk} is itself bound to a @code{<package>} object. | |
940 | ||
941 | Note that GCC, Coreutils, Bash, and other essential tools do not need to | |
942 | be specified as inputs here. Instead, @var{gnu-build-system} takes care | |
943 | of ensuring that they are present. | |
944 | ||
945 | However, any other dependencies need to be specified in the | |
946 | @code{inputs} field. Any dependency not specified here will simply be | |
947 | unavailable to the build process, possibly leading to a build failure. | |
948 | @end itemize | |
949 | ||
950 | There are other fields that package definitions may provide. Of | |
951 | particular interest is the @code{arguments} field. When specified, it | |
952 | must be bound to a list of additional arguments to be passed to the | |
953 | build system. For instance, the above definition could be augmented | |
954 | with the following field initializer: | |
955 | ||
956 | @example | |
957 | (arguments `(#:tests? #f | |
958 | #:configure-flags '("--enable-silent-rules"))) | |
959 | @end example | |
960 | ||
961 | @noindent | |
962 | These are keyword arguments (@pxref{Optional Arguments, keyword | |
963 | arguments in Guile,, guile, GNU Guile Reference Manual}). They are | |
964 | passed to @var{gnu-build-system}, which interprets them as meaning ``do | |
965 | not run @code{make check}'', and ``run @file{configure} with the | |
874e6874 LC |
966 | @code{--enable-silent-rules} flag''. The value of these keyword |
967 | parameters is actually evaluated in the @dfn{build stratum}---i.e., by a | |
968 | Guile process launched by the daemon (@pxref{Derivations}). | |
3dc1970d LC |
969 | |
970 | Once a package definition is in place@footnote{Simple package | |
971 | definitions like the one above may be automatically converted from the | |
e49951eb MW |
972 | Nixpkgs distribution using the @command{guix import} command.}, the |
973 | package may actually be built using the @code{guix build} command-line | |
37166310 LC |
974 | tool (@pxref{Invoking guix build}). Eventually, updating the package |
975 | definition to a new upstream version can be partly automated by the | |
976 | @command{guix refresh} command (@pxref{Invoking guix refresh}). | |
3dc1970d LC |
977 | |
978 | Behind the scenes, a derivation corresponding to the @code{<package>} | |
979 | object is first computed by the @code{package-derivation} procedure. | |
980 | That derivation is stored in a @code{.drv} file under @file{/nix/store}. | |
ba55b1cb | 981 | The build actions it prescribes may then be realized by using the |
3dc1970d LC |
982 | @code{build-derivations} procedure (@pxref{The Store}). |
983 | ||
984 | @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}] | |
e509d152 LC |
985 | Return the derivation path and corresponding @code{<derivation>} object |
986 | of @var{package} for @var{system} (@pxref{Derivations}). | |
3dc1970d LC |
987 | |
988 | @var{package} must be a valid @code{<package>} object, and @var{system} | |
989 | must be a string denoting the target system type---e.g., | |
990 | @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store} | |
991 | must be a connection to the daemon, which operates on the store | |
992 | (@pxref{The Store}). | |
993 | @end deffn | |
568717fd | 994 | |
9c1edabd LC |
995 | @noindent |
996 | @cindex cross-compilation | |
997 | Similarly, it is possible to compute a derivation that cross-builds a | |
998 | package for some other system: | |
999 | ||
1000 | @deffn {Scheme Procedure} package-cross-derivation @var{store} @ | |
1001 | @var{package} @var{target} [@var{system}] | |
1002 | Return the derivation path and corresponding @code{<derivation>} object | |
1003 | of @var{package} cross-built from @var{system} to @var{target}. | |
1004 | ||
1005 | @var{target} must be a valid GNU triplet denoting the target hardware | |
1006 | and operating system, such as @code{"mips64el-linux-gnu"} | |
1007 | (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU | |
1008 | Configure and Build System}). | |
1009 | @end deffn | |
1010 | ||
1011 | ||
568717fd LC |
1012 | @node The Store |
1013 | @section The Store | |
1014 | ||
e531ac2a LC |
1015 | @cindex store |
1016 | @cindex store paths | |
1017 | ||
1018 | Conceptually, the @dfn{store} is where derivations that have been | |
1019 | successfully built are stored---by default, under @file{/nix/store}. | |
1020 | Sub-directories in the store are referred to as @dfn{store paths}. The | |
1021 | store has an associated database that contains information such has the | |
1022 | store paths referred to by each store path, and the list of @emph{valid} | |
1023 | store paths---paths that result from a successful build. | |
1024 | ||
1025 | The store is always accessed by the daemon on behalf of its clients | |
1026 | (@pxref{Invoking guix-daemon}). To manipulate the store, clients | |
1027 | connect to the daemon over a Unix-domain socket, send it requests, and | |
1028 | read the result---these are remote procedure calls, or RPCs. | |
1029 | ||
1030 | The @code{(guix store)} module provides procedures to connect to the | |
1031 | daemon, and to perform RPCs. These are described below. | |
1032 | ||
1033 | @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t] | |
1034 | Connect to the daemon over the Unix-domain socket at @var{file}. When | |
1035 | @var{reserve-space?} is true, instruct it to reserve a little bit of | |
1036 | extra space on the file system so that the garbage collector can still | |
1037 | operate, should the disk become full. Return a server object. | |
1038 | ||
1039 | @var{file} defaults to @var{%default-socket-path}, which is the normal | |
1040 | location given the options that were passed to @command{configure}. | |
1041 | @end deffn | |
1042 | ||
1043 | @deffn {Scheme Procedure} close-connection @var{server} | |
1044 | Close the connection to @var{server}. | |
1045 | @end deffn | |
1046 | ||
1047 | @defvr {Scheme Variable} current-build-output-port | |
1048 | This variable is bound to a SRFI-39 parameter, which refers to the port | |
1049 | where build and error logs sent by the daemon should be written. | |
1050 | @end defvr | |
1051 | ||
1052 | Procedures that make RPCs all take a server object as their first | |
1053 | argument. | |
1054 | ||
1055 | @deffn {Scheme Procedure} valid-path? @var{server} @var{path} | |
1056 | Return @code{#t} when @var{path} is a valid store path. | |
1057 | @end deffn | |
1058 | ||
1059 | @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} @var{references} | |
1060 | Add @var{text} under file @var{name} in the store, and return its store | |
1061 | path. @var{references} is the list of store paths referred to by the | |
1062 | resulting store path. | |
1063 | @end deffn | |
1064 | ||
874e6874 LC |
1065 | @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations} |
1066 | Build @var{derivations} (a list of derivation paths), and return when | |
1067 | the worker is done building them. Return @code{#t} on success. | |
1068 | @end deffn | |
1069 | ||
e531ac2a LC |
1070 | @c FIXME |
1071 | @i{This section is currently incomplete.} | |
568717fd LC |
1072 | |
1073 | @node Derivations | |
1074 | @section Derivations | |
1075 | ||
874e6874 LC |
1076 | @cindex derivations |
1077 | Low-level build actions and the environment in which they are performed | |
1078 | are represented by @dfn{derivations}. A derivation contain the | |
1079 | following pieces of information: | |
1080 | ||
1081 | @itemize | |
1082 | @item | |
1083 | The outputs of the derivation---derivations produce at least one file or | |
1084 | directory in the store, but may produce more. | |
1085 | ||
1086 | @item | |
1087 | The inputs of the derivations, which may be other derivations or plain | |
1088 | files in the store (patches, build scripts, etc.) | |
1089 | ||
1090 | @item | |
1091 | The system type targeted by the derivation---e.g., @code{x86_64-linux}. | |
1092 | ||
1093 | @item | |
1094 | The file name of a build script in the store, along with the arguments | |
1095 | to be passed. | |
1096 | ||
1097 | @item | |
1098 | A list of environment variables to be defined. | |
1099 | ||
1100 | @end itemize | |
1101 | ||
1102 | @cindex derivation path | |
1103 | Derivations allow clients of the daemon to communicate build actions to | |
1104 | the store. They exist in two forms: as an in-memory representation, | |
1105 | both on the client- and daemon-side, and as files in the store whose | |
1106 | name end in @code{.drv}---these files are referred to as @dfn{derivation | |
1107 | paths}. Derivations paths can be passed to the @code{build-derivations} | |
1108 | procedure to perform the build actions they prescribe (@pxref{The | |
1109 | Store}). | |
1110 | ||
1111 | The @code{(guix derivations)} module provides a representation of | |
1112 | derivations as Scheme objects, along with procedures to create and | |
1113 | otherwise manipulate derivations. The lowest-level primitive to create | |
1114 | a derivation is the @code{derivation} procedure: | |
1115 | ||
a987d2c0 | 1116 | @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] [#:hash-mode #f] [#:inputs '()] [#:env-vars '()] [#:system (%current-system)] |
874e6874 LC |
1117 | Build a derivation with the given arguments. Return the resulting store |
1118 | path and @code{<derivation>} object. | |
1119 | ||
1120 | When @var{hash}, @var{hash-algo}, and @var{hash-mode} are given, a | |
1121 | @dfn{fixed-output derivation} is created---i.e., one whose result is | |
1122 | known in advance, such as a file download. | |
1123 | @end deffn | |
1124 | ||
1125 | @noindent | |
1126 | Here's an example with a shell script as its builder, assuming | |
1127 | @var{store} is an open connection to the daemon, and @var{bash} points | |
1128 | to a Bash executable in the store: | |
1129 | ||
1130 | @lisp | |
1131 | (use-modules (guix utils) | |
1132 | (guix store) | |
1133 | (guix derivations)) | |
1134 | ||
1135 | (call-with-values | |
1136 | (lambda () | |
1137 | (let ((builder ; add the Bash script to the store | |
1138 | (add-text-to-store store "my-builder.sh" | |
1139 | "echo hello world > $out\n" '()))) | |
a987d2c0 | 1140 | (derivation store "foo" |
874e6874 | 1141 | bash `("-e" ,builder) |
a987d2c0 | 1142 | #:env-vars '(("HOME" . "/homeless"))))) |
874e6874 LC |
1143 | list) |
1144 | @result{} ("/nix/store/@dots{}-foo.drv" #<<derivation> @dots{}>) | |
1145 | @end lisp | |
1146 | ||
1147 | As can be guessed, this primitive is cumbersome to use directly. An | |
1148 | improved variant is @code{build-expression->derivation}, which allows | |
1149 | the caller to directly pass a Guile expression as the build script: | |
1150 | ||
1151 | @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] | |
1152 | Return a derivation that executes Scheme expression @var{exp} as a | |
1153 | builder for derivation @var{name}. @var{inputs} must be a list of | |
1154 | @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted, | |
1155 | @code{"out"} is assumed. @var{modules} is a list of names of Guile | |
1156 | modules from the current search path to be copied in the store, | |
1157 | compiled, and made available in the load path during the execution of | |
1158 | @var{exp}---e.g., @code{((guix build utils) (guix build | |
1159 | gnu-build-system))}. | |
1160 | ||
1161 | @var{exp} is evaluated in an environment where @code{%outputs} is bound | |
1162 | to a list of output/path pairs, and where @code{%build-inputs} is bound | |
1163 | to a list of string/output-path pairs made from @var{inputs}. | |
1164 | Optionally, @var{env-vars} is a list of string pairs specifying the name | |
1165 | and value of environment variables visible to the builder. The builder | |
1166 | terminates by passing the result of @var{exp} to @code{exit}; thus, when | |
1167 | @var{exp} returns @code{#f}, the build is considered to have failed. | |
1168 | ||
1169 | @var{exp} is built using @var{guile-for-build} (a derivation). When | |
1170 | @var{guile-for-build} is omitted or is @code{#f}, the value of the | |
1171 | @code{%guile-for-build} fluid is used instead. | |
1172 | @end deffn | |
1173 | ||
1174 | @noindent | |
1175 | Here's an example of a single-output derivation that creates a directory | |
1176 | containing one file: | |
1177 | ||
1178 | @lisp | |
1179 | (let ((builder '(let ((out (assoc-ref %outputs "out"))) | |
1180 | (mkdir out) ; create /nix/store/@dots{}-goo | |
1181 | (call-with-output-file (string-append out "/test") | |
1182 | (lambda (p) | |
1183 | (display '(hello guix) p)))))) | |
1184 | (build-expression->derivation store "goo" (%current-system) | |
1185 | builder '())) | |
1186 | ||
1187 | @result{} "/nix/store/@dots{}-goo.drv" | |
1188 | @result{} #<<derivation> @dots{}> | |
1189 | @end lisp | |
1190 | ||
1191 | @cindex strata of code | |
1192 | Remember that the build expression passed to | |
1193 | @code{build-expression->derivation} is run by a separate Guile process | |
1194 | than the one that calls @code{build-expression->derivation}: it is run | |
1195 | by a Guile process launched by the daemon, typically in a chroot. So, | |
1196 | while there is a single language for both the @dfn{host} and the build | |
1197 | side, there are really two @dfn{strata} of code: the host-side, and the | |
1198 | build-side code@footnote{The term @dfn{stratum} in this context was | |
1199 | coined by Manuel Serrano et al. in the context of their work on Hop.}. | |
1200 | This distinction is important to keep in mind, notably when using | |
1201 | higher-level constructs such as @var{gnu-build-system} (@pxref{Defining | |
1202 | Packages}). For this reason, Guix modules that are meant to be used in | |
1203 | the build stratum are kept in the @code{(guix build @dots{})} name | |
1204 | space. | |
568717fd LC |
1205 | |
1206 | @c ********************************************************************* | |
1207 | @node Utilities | |
1208 | @chapter Utilities | |
1209 | ||
210cc920 LC |
1210 | This section describes tools primarily targeted at developers and users |
1211 | who write new package definitions. They complement the Scheme | |
1212 | programming interface of Guix in a convenient way. | |
1213 | ||
568717fd | 1214 | @menu |
37166310 | 1215 | * Invoking guix build:: Building packages from the command line. |
210cc920 | 1216 | * Invoking guix download:: Downloading a file and printing its hash. |
37166310 LC |
1217 | * Invoking guix hash:: Computing the cryptographic hash of a file. |
1218 | * Invoking guix refresh:: Updating package definitions. | |
568717fd LC |
1219 | @end menu |
1220 | ||
e49951eb MW |
1221 | @node Invoking guix build |
1222 | @section Invoking @command{guix build} | |
568717fd | 1223 | |
e49951eb | 1224 | The @command{guix build} command builds packages or derivations and |
6798a8e4 LC |
1225 | their dependencies, and prints the resulting store paths. Note that it |
1226 | does not modify the user's profile---this is the job of the | |
e49951eb | 1227 | @command{guix package} command (@pxref{Invoking guix package}). Thus, |
6798a8e4 LC |
1228 | it is mainly useful for distribution developers. |
1229 | ||
1230 | The general syntax is: | |
c78bd12b LC |
1231 | |
1232 | @example | |
e49951eb | 1233 | guix build @var{options} @var{package-or-derivation}@dots{} |
c78bd12b LC |
1234 | @end example |
1235 | ||
1236 | @var{package-or-derivation} may be either the name of a package found in | |
5401dd75 LC |
1237 | the software distribution such as @code{coreutils} or |
1238 | @code{coreutils-8.20}, or a derivation such as | |
1239 | @file{/nix/store/@dots{}-coreutils-8.19.drv}. Alternatively, the | |
c78bd12b LC |
1240 | @code{--expression} option may be used to specify a Scheme expression |
1241 | that evaluates to a package; this is useful when disambiguation among | |
1242 | several same-named packages or package variants is needed. | |
1243 | ||
1244 | The @var{options} may be zero or more of the following: | |
1245 | ||
1246 | @table @code | |
1247 | ||
1248 | @item --expression=@var{expr} | |
1249 | @itemx -e @var{expr} | |
1250 | Build the package @var{expr} evaluates to. | |
1251 | ||
5401dd75 | 1252 | For example, @var{expr} may be @code{(@@ (gnu packages guile) |
c78bd12b LC |
1253 | guile-1.8)}, which unambiguously designates this specific variant of |
1254 | version 1.8 of Guile. | |
1255 | ||
1256 | @item --source | |
1257 | @itemx -S | |
1258 | Build the packages' source derivations, rather than the packages | |
1259 | themselves. | |
1260 | ||
e49951eb | 1261 | For instance, @code{guix build -S gcc} returns something like |
6798a8e4 | 1262 | @file{/nix/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball. |
c78bd12b LC |
1263 | |
1264 | @item --system=@var{system} | |
1265 | @itemx -s @var{system} | |
1266 | Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of | |
1267 | the host's system type. | |
1268 | ||
1269 | An example use of this is on Linux-based systems, which can emulate | |
1270 | different personalities. For instance, passing | |
1271 | @code{--system=i686-linux} on an @code{x86_64-linux} system allows users | |
1272 | to build packages in a complete 32-bit environment. | |
1273 | ||
e55ec43d LC |
1274 | @item --target=@var{triplet} |
1275 | @cindex cross-compilation | |
1276 | Cross-build for @var{triplet}, which must be a valid GNU triplet, such | |
1277 | as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU | |
1278 | configuration triplets,, configure, GNU Configure and Build System}). | |
1279 | ||
c78bd12b LC |
1280 | @item --derivations |
1281 | @itemx -d | |
1282 | Return the derivation paths, not the output paths, of the given | |
1283 | packages. | |
1284 | ||
1285 | @item --keep-failed | |
1286 | @itemx -K | |
1287 | Keep the build tree of failed builds. Thus, if a build fail, its build | |
1288 | tree is kept under @file{/tmp}, in a directory whose name is shown at | |
1289 | the end of the build log. This is useful when debugging build issues. | |
1290 | ||
1291 | @item --dry-run | |
1292 | @itemx -n | |
1293 | Do not build the derivations. | |
1294 | ||
56b1f4b7 LC |
1295 | @item --fallback |
1296 | When substituting a pre-built binary fails, fall back to building | |
1297 | packages locally. | |
1298 | ||
c78bd12b LC |
1299 | @item --no-substitutes |
1300 | Build instead of resorting to pre-built substitutes. | |
1301 | ||
969e678e LC |
1302 | @item --max-silent-time=@var{seconds} |
1303 | When the build or substitution process remains silent for more than | |
1304 | @var{seconds}, terminate it and report a build failure. | |
1305 | ||
c78bd12b LC |
1306 | @item --cores=@var{n} |
1307 | @itemx -c @var{n} | |
1308 | Allow the use of up to @var{n} CPU cores for the build. The special | |
1309 | value @code{0} means to use as many CPU cores as available. | |
1310 | ||
1311 | @item --root=@var{file} | |
1312 | @itemx -r @var{file} | |
1313 | Make @var{file} a symlink to the result, and register it as a garbage | |
1314 | collector root. | |
07ab4bf1 LC |
1315 | |
1316 | @item --verbosity=@var{level} | |
1317 | Use the given verbosity level. @var{level} must be an integer between 0 | |
1318 | and 5; higher means more verbose output. Setting a level of 4 or more | |
1319 | may be helpful when debugging setup issues with the build daemon. | |
1320 | ||
c78bd12b LC |
1321 | @end table |
1322 | ||
e49951eb | 1323 | Behind the scenes, @command{guix build} is essentially an interface to |
c78bd12b LC |
1324 | the @code{package-derivation} procedure of the @code{(guix packages)} |
1325 | module, and to the @code{build-derivations} procedure of the @code{(guix | |
1326 | store)} module. | |
1327 | ||
210cc920 LC |
1328 | @node Invoking guix download |
1329 | @section Invoking @command{guix download} | |
1330 | ||
1331 | When writing a package definition, developers typically need to download | |
1332 | the package's source tarball, compute its SHA256 hash, and write that | |
1333 | hash in the package definition (@pxref{Defining Packages}). The | |
1334 | @command{guix download} tool helps with this task: it downloads a file | |
1335 | from the given URI, adds it to the store, and prints both its file name | |
1336 | in the store and its SHA256 hash. | |
1337 | ||
1338 | The fact that the downloaded file is added to the store saves bandwidth: | |
1339 | when the developer eventually tries to build the newly defined package | |
1340 | with @command{guix build}, the source tarball will not have to be | |
1341 | downloaded again because it is already in the store. It is also a | |
1342 | convenient way to temporarily stash files, which may be deleted | |
1343 | eventually (@pxref{Invoking guix gc}). | |
1344 | ||
1345 | The @command{guix download} command supports the same URIs as used in | |
1346 | package definitions. In particular, it supports @code{mirror://} URIs. | |
1347 | @code{https} URIs (HTTP over TLS) are supported @emph{provided} the | |
1348 | Guile bindings for GnuTLS are available in the user's environment; when | |
1349 | they are not available, an error is raised. | |
1350 | ||
1351 | The following option is available: | |
1352 | ||
1353 | @table @code | |
1354 | @item --format=@var{fmt} | |
1355 | @itemx -f @var{fmt} | |
1356 | Write the hash in the format specified by @var{fmt}. For more | |
1357 | information on the valid values for @var{fmt}, @ref{Invoking guix hash}. | |
1358 | @end table | |
1359 | ||
6c365eca NK |
1360 | @node Invoking guix hash |
1361 | @section Invoking @command{guix hash} | |
1362 | ||
210cc920 | 1363 | The @command{guix hash} command computes the SHA256 hash of a file. |
6c365eca NK |
1364 | It is primarily a convenience tool for anyone contributing to the |
1365 | distribution: it computes the cryptographic hash of a file, which can be | |
1366 | used in the definition of a package (@pxref{Defining Packages}). | |
1367 | ||
1368 | The general syntax is: | |
1369 | ||
1370 | @example | |
1371 | guix hash @var{option} @var{file} | |
1372 | @end example | |
1373 | ||
1374 | @command{guix hash} has the following option: | |
1375 | ||
1376 | @table @code | |
1377 | ||
1378 | @item --format=@var{fmt} | |
1379 | @itemx -f @var{fmt} | |
210cc920 | 1380 | Write the hash in the format specified by @var{fmt}. |
6c365eca NK |
1381 | |
1382 | Supported formats: @code{nix-base32}, @code{base32}, @code{base16} | |
1383 | (@code{hex} and @code{hexadecimal} can be used as well). | |
1384 | ||
1385 | If the @option{--format} option is not specified, @command{guix hash} | |
1386 | will output the hash in @code{nix-base32}. This representation is used | |
1387 | in the definitions of packages. | |
1388 | ||
1389 | @end table | |
1390 | ||
37166310 LC |
1391 | @node Invoking guix refresh |
1392 | @section Invoking @command{guix refresh} | |
1393 | ||
1394 | The primary audience of the @command{guix refresh} command is developers | |
1395 | of the GNU software distribution. By default, it reports any packages | |
1396 | provided by the distribution that are outdated compared to the latest | |
1397 | upstream version, like this: | |
1398 | ||
1399 | @example | |
1400 | $ guix refresh | |
1401 | gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1 | |
1402 | gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0 | |
1403 | @end example | |
1404 | ||
1405 | It does so by browsing each package's FTP directory and determining the | |
1406 | highest version number of the source tarballs | |
1407 | therein@footnote{Currently, this only works for GNU packages.}. | |
1408 | ||
1409 | When passed @code{--update}, it modifies distribution source files to | |
1410 | update the version numbers and source tarball hashes of those packages' | |
1411 | recipes (@pxref{Defining Packages}). This is achieved by downloading | |
1412 | each package's latest source tarball and its associated OpenPGP | |
1413 | signature, authenticating the downloaded tarball against its signature | |
1414 | using @command{gpg}, and finally computing its hash. When the public | |
1415 | key used to sign the tarball is missing from the user's keyring, an | |
1416 | attempt is made to automatically retrieve it from a public key server; | |
1417 | when it's successful, the key is added to the user's keyring; otherwise, | |
1418 | @command{guix refresh} reports an error. | |
1419 | ||
1420 | The following options are supported: | |
1421 | ||
1422 | @table @code | |
1423 | ||
1424 | @item --update | |
1425 | @itemx -u | |
1426 | Update distribution source files (package recipes) in place. | |
1427 | @ref{Defining Packages}, for more information on package definitions. | |
1428 | ||
1429 | @item --select=[@var{subset}] | |
1430 | @itemx -s @var{subset} | |
1431 | Select all the packages in @var{subset}, one of @code{core} or | |
1432 | @code{non-core}. | |
1433 | ||
1434 | The @code{core} subset refers to all the packages at the core of the | |
1435 | distribution---i.e., packages that are used to build ``everything | |
1436 | else''. This includes GCC, libc, Binutils, Bash, etc. Usually, | |
1437 | changing one of these packages in the distribution entails a rebuild of | |
1438 | all the others. Thus, such updates are an inconvenience to users in | |
1439 | terms of build time or bandwidth used to achieve the upgrade. | |
1440 | ||
1441 | The @code{non-core} subset refers to the remaining packages. It is | |
1442 | typically useful in cases where an update of the core packages would be | |
1443 | inconvenient. | |
1444 | ||
1445 | @end table | |
1446 | ||
1447 | In addition, @command{guix refresh} can be passed one or more package | |
1448 | names, as in this example: | |
1449 | ||
1450 | @example | |
1451 | guix refresh -u emacs idutils | |
1452 | @end example | |
1453 | ||
1454 | @noindent | |
1455 | The command above specifically updates the @code{emacs} and | |
1456 | @code{idutils} packages. The @code{--select} option would have no | |
1457 | effect in this case. | |
1458 | ||
f9230085 LC |
1459 | The following options can be used to customize GnuPG operation: |
1460 | ||
1461 | @table @code | |
1462 | ||
1463 | @item --key-server=@var{host} | |
1464 | Use @var{host} as the OpenPGP key server when importing a public key. | |
1465 | ||
1466 | @item --gpg=@var{command} | |
1467 | Use @var{command} as the GnuPG 2.x command. @var{command} is searched | |
1468 | for in @code{$PATH}. | |
1469 | ||
1470 | @end table | |
1471 | ||
37166310 | 1472 | |
a1ba8475 LC |
1473 | @c ********************************************************************* |
1474 | @node GNU Distribution | |
1475 | @chapter GNU Distribution | |
1476 | ||
1477 | Guix comes with a distribution of free software@footnote{The term | |
1478 | ``free'' here refers to the | |
1479 | @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to | |
1480 | users of that software}.} that form the basis of the GNU system. This | |
1481 | includes core GNU packages such as GNU libc, GCC, and Binutils, as well | |
1482 | as many GNU and non-GNU applications. The complete list of available | |
e49951eb MW |
1483 | packages can be seen by running @command{guix package} (@pxref{Invoking |
1484 | guix package}): | |
a1ba8475 LC |
1485 | |
1486 | @example | |
e49951eb | 1487 | guix package --list-available |
a1ba8475 LC |
1488 | @end example |
1489 | ||
401c53c4 LC |
1490 | Our goal is to build a practical 100% free software distribution of |
1491 | Linux-based and other variants of GNU, with a focus on the promotion and | |
1492 | tight integration of GNU components, and an emphasis on programs and | |
1493 | tools that help users exert that freedom. | |
1494 | ||
1495 | @menu | |
91ef73d4 | 1496 | * Installing Debugging Files:: Feeding the debugger. |
401c53c4 | 1497 | * Package Modules:: Packages from the programmer's viewpoint. |
b81e1947 | 1498 | * Adding New Packages:: Growing the distribution. |
401c53c4 | 1499 | * Bootstrapping:: GNU/Linux built from scratch. |
8b315a6d | 1500 | * Porting:: Targeting another platform or kernel. |
401c53c4 LC |
1501 | @end menu |
1502 | ||
1503 | Building this distribution is a cooperative effort, and you are invited | |
1504 | to join! @ref{Contributing}, for information about how you can help. | |
1505 | ||
b208a005 | 1506 | |
91ef73d4 LC |
1507 | @node Installing Debugging Files |
1508 | @section Installing Debugging Files | |
1509 | ||
1510 | Program binaries, as produced by the GCC compilers for instance, are | |
1511 | typically written in the ELF format, with a section containing | |
1512 | @dfn{debugging information}. Debugging information is what allows the | |
1513 | debugger, GDB, to map binary code to source code; it is required to | |
1514 | debug a compiled program in good conditions. | |
1515 | ||
1516 | The problem with debugging information is that is takes up a fair amount | |
1517 | of disk space. For example, debugging information for the GNU C Library | |
1518 | weighs in at more than 60 MiB. Thus, as a user, keeping all the | |
1519 | debugging info of all the installed programs is usually not an option. | |
1520 | Yet, space savings should not come at the cost of an impediment to | |
1521 | debugging---especially in the GNU system, which should make it easier | |
1522 | for users to exert their computing freedom (@pxref{GNU Distribution}). | |
1523 | ||
1524 | Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a | |
1525 | mechanism that allows users to get the best of both worlds: debugging | |
1526 | information can be stripped from the binaries and stored in separate | |
1527 | files. GDB is then able to load debugging information from those files, | |
1528 | when they are available (@pxref{Separate Debug Files,,, gdb, Debugging | |
1529 | with GDB}). | |
1530 | ||
1531 | The GNU distribution takes advantage of this by storing debugging | |
1532 | information in the @code{lib/debug} sub-directory of a separate package | |
1533 | output unimaginatively called @code{debug} (@pxref{Packages with | |
1534 | Multiple Outputs}). Users can choose to install the @code{debug} output | |
1535 | of a package when they need it. For instance, the following command | |
1536 | installs the debugging information for the GNU C Library and for GNU | |
1537 | Guile: | |
1538 | ||
1539 | @example | |
1540 | guix package -i glibc:debug -i guile:debug | |
1541 | @end example | |
1542 | ||
1543 | GDB must then be told to look for debug files in the user's profile, by | |
1544 | setting the @code{debug-file-directory} variable (consider setting it | |
1545 | from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with | |
1546 | GDB}): | |
1547 | ||
1548 | @example | |
1549 | (gdb) set debug-file-directory ~/.guix-profile/lib/debug | |
1550 | @end example | |
1551 | ||
1552 | From there on, GDB will pick up debugging information from the | |
1553 | @code{.debug} files under @file{~/.guix-profile/lib/debug}. | |
1554 | ||
1555 | @c XXX: keep me up-to-date | |
1556 | The @code{debug} output mechanism in Guix is implemented by the | |
1557 | @code{gnu-build-system} (@pxref{Defining Packages}). Currently, it is | |
1558 | opt-in---debugging information is available only for those packages | |
1559 | whose definition explicitly declares a @code{debug} output. This may be | |
1560 | changed to opt-out in the future, if our build farm servers can handle | |
1561 | the load. To check whether a package has a @code{debug} output, use | |
1562 | @command{guix package --list-available} (@pxref{Invoking guix package}). | |
1563 | ||
1564 | ||
401c53c4 LC |
1565 | @node Package Modules |
1566 | @section Package Modules | |
1567 | ||
1568 | From a programming viewpoint, the package definitions of the | |
1569 | distribution are provided by Guile modules in the @code{(gnu packages | |
b81e1947 LC |
1570 | ...)} name space (@pxref{Modules, Guile modules,, guile, GNU Guile |
1571 | Reference Manual}). For instance, the @code{(gnu packages emacs)} | |
1572 | module exports a variable named @code{emacs}, which is bound to a | |
401c53c4 LC |
1573 | @code{<package>} object (@pxref{Defining Packages}). The @code{(gnu |
1574 | packages)} module provides facilities for searching for packages. | |
a1ba8475 LC |
1575 | |
1576 | The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}: | |
1577 | each package is built based solely on other packages in the | |
1578 | distribution. The root of this dependency graph is a small set of | |
1579 | @dfn{bootstrap binaries}, provided by the @code{(gnu packages | |
b81e1947 LC |
1580 | bootstrap)} module. For more information on bootstrapping, |
1581 | @ref{Bootstrapping}. | |
1582 | ||
1583 | @node Adding New Packages | |
1584 | @section Adding New Packages | |
1585 | ||
1586 | The GNU distribution is nascent and may well lack some of your favorite | |
1587 | packages. This section describes how you can help make the distribution | |
1588 | grow. @ref{Contributing}, for additional information on how you can | |
1589 | help. | |
1590 | ||
1591 | @menu | |
1592 | * Packaging Guidelines:: What goes into the distribution. | |
1593 | * From the Source Tarball to the Package:: The story of a package. | |
1594 | @end menu | |
1595 | ||
1596 | @node Packaging Guidelines | |
1597 | @subsection Packaging Guidelines | |
1598 | ||
1599 | @c Adapted from http://www.gnu.org/philosophy/philosophy.html. | |
1600 | ||
1601 | The GNU operating system has been developed so that users can have | |
1602 | freedom in their computing. GNU is @dfn{free software}, meaning that | |
1603 | users have the @url{http://www.gnu.org/philosophy/free-sw.html,four | |
1604 | essential freedoms}: to run the program, to study and change the program | |
1605 | in source code form, to redistribute exact copies, and to distribute | |
1606 | modified versions. Packages found in the GNU distribution provide only | |
1607 | software that conveys these four freedoms. | |
1608 | ||
1609 | In addition, the GNU distribution follow the | |
1610 | @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free | |
1611 | software distribution guidelines}. Among other things, these guidelines | |
1612 | reject non-free firmware, recommendations of non-free software, and | |
1613 | discuss ways to deal with trademarks and patents. | |
1614 | ||
1615 | @node From the Source Tarball to the Package | |
1616 | @subsection From the Source Tarball, to the Package Definition, to the Binary Package | |
1617 | ||
1618 | Free software packages are usually distributed in the form of | |
1619 | @dfn{source code tarballs}---typically @file{tar.gz} files that contain | |
1620 | all the source files. Adding a package to the distribution means | |
1621 | essentially two things: adding a @dfn{recipe} that describes how to | |
1622 | build the package, including a list of other packages required to build | |
1623 | it, and adding @dfn{package meta-data} along with that recipe, such as a | |
1624 | description and licensing information. | |
1625 | ||
1626 | In Guix all this information is embodied in @dfn{package definitions}. | |
1627 | Package definitions provide a high-level view of the package. They are | |
1628 | written using the syntax of the Scheme programming language; in fact, | |
1629 | for each package we define a variable bound to the package definition, | |
1630 | and export that variable from a module (@pxref{Package Modules}). | |
1631 | However, in-depth Scheme knowledge is @emph{not} a prerequisite for | |
1632 | creating packages. For more information on package definitions, | |
1633 | @ref{Defining Packages}. | |
1634 | ||
1635 | Once a package definition is in place, stored in a file in the Guix | |
1636 | source tree, it can be tested using the @command{guix build} command | |
1637 | (@pxref{Invoking guix build}). For example, assuming the new package is | |
1638 | called @code{gnew}, you may run this command from the Guix build tree: | |
1639 | ||
1640 | @example | |
1641 | ./pre-inst-env guix build gnew --keep-failed | |
1642 | @end example | |
1643 | ||
1644 | Using @code{--keep-failed} makes it easier to debug build failures since | |
1645 | it provides access to the failed build tree. | |
1646 | ||
1647 | Once your package builds correctly, please send us a patch | |
1648 | (@pxref{Contributing}). Well, if you need help, we will be happy to | |
1649 | help you too. Once the patch is committed in the Guix repository, the | |
1650 | new package automatically gets built on the supported platforms by | |
1651 | @url{http://hydra.gnu.org/gnu/master, our continuous integration | |
1652 | system}. | |
1653 | ||
1654 | @cindex substituter | |
1655 | Users can obtain the new package definition simply by running | |
1656 | @command{guix pull} (@pxref{Invoking guix pull}). When | |
1657 | @code{hydra.gnu.org} is done building the package, installing the | |
1658 | package automatically downloads binaries from there (except when using | |
1659 | @code{--no-substitutes}). The only place where human intervention is | |
1660 | needed is to review and apply the patch. | |
401c53c4 LC |
1661 | |
1662 | ||
1663 | @node Bootstrapping | |
1664 | @section Bootstrapping | |
1665 | ||
1666 | @c Adapted from the ELS 2013 paper. | |
1667 | ||
1668 | @cindex bootstrapping | |
1669 | ||
1670 | Bootstrapping in our context refers to how the distribution gets built | |
1671 | ``from nothing''. Remember that the build environment of a derivation | |
1672 | contains nothing but its declared inputs (@pxref{Introduction}). So | |
1673 | there's an obvious chicken-and-egg problem: how does the first package | |
1674 | get built? How does the first compiler get compiled? Note that this is | |
1675 | a question of interest only to the curious hacker, not to the regular | |
1676 | user, so you can shamelessly skip this section if you consider yourself | |
1677 | a ``regular user''. | |
1678 | ||
1679 | @cindex bootstrap binaries | |
1680 | The GNU system is primarily made of C code, with libc at its core. The | |
1681 | GNU build system itself assumes the availability of a Bourne shell and | |
1682 | command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and | |
1683 | `grep'. Furthermore, build programs---programs that run | |
1684 | @code{./configure}, @code{make}, etc.---are written in Guile Scheme | |
1685 | (@pxref{Derivations}). Consequently, to be able to build anything at | |
1686 | all, from scratch, Guix relies on pre-built binaries of Guile, GCC, | |
1687 | Binutils, libc, and the other packages mentioned above---the | |
1688 | @dfn{bootstrap binaries}. | |
1689 | ||
1690 | These bootstrap binaries are ``taken for granted'', though we can also | |
1691 | re-create them if needed (more on that later.) | |
1692 | ||
1693 | @unnumberedsubsec Preparing to Use the Bootstrap Binaries | |
1694 | ||
1695 | @c As of Emacs 24.3, Info-mode displays the image, but since it's a | |
1696 | @c large image, it's hard to scroll. Oh well. | |
1697 | @image{images/bootstrap-graph,,,Dependency graph of the early bootstrap derivations} | |
1698 | ||
1699 | The figure above shows the very beginning of the dependency graph of the | |
1700 | distribution, corresponding to the package definitions of the @code{(gnu | |
1701 | packages bootstrap)} module. At this level of detail, things are | |
1702 | slightly complex. First, Guile itself consists of an ELF executable, | |
1703 | along with many source and compiled Scheme files that are dynamically | |
1704 | loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz} | |
1705 | tarball shown in this graph. This tarball is part of Guix's ``source'' | |
1706 | distribution, and gets inserted into the store with @code{add-to-store} | |
1707 | (@pxref{The Store}). | |
a1ba8475 | 1708 | |
401c53c4 LC |
1709 | But how do we write a derivation that unpacks this tarball and adds it |
1710 | to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv} | |
1711 | derivation---the first one that gets built---uses @code{bash} as its | |
1712 | builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls | |
1713 | @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar}, | |
1714 | @file{xz}, and @file{mkdir} are statically-linked binaries, also part of | |
1715 | the Guix source distribution, whose sole purpose is to allow the Guile | |
1716 | tarball to be unpacked. | |
1717 | ||
1718 | Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning | |
1719 | Guile that can be used to run subsequent build programs. Its first task | |
1720 | is to download tarballs containing the other pre-built binaries---this | |
1721 | is what the @code{.tar.xz.drv} derivations do. Guix modules such as | |
1722 | @code{ftp-client.scm} are used for this purpose. The | |
1723 | @code{module-import.drv} derivations import those modules in a directory | |
1724 | in the store, using the original layout. The | |
1725 | @code{module-import-compiled.drv} derivations compile those modules, and | |
1726 | write them in an output directory with the right layout. This | |
1727 | corresponds to the @code{#:modules} argument of | |
1728 | @code{build-expression->derivation} (@pxref{Derivations}). | |
1729 | ||
1730 | Finally, the various tarballs are unpacked by the | |
1731 | derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv}, | |
1732 | etc., at which point we have a working C tool chain. | |
1733 | ||
1734 | ||
1735 | @unnumberedsubsec Building the Build Tools | |
1736 | ||
1737 | @c TODO: Add a package-level dependency graph generated from (gnu | |
1738 | @c packages base). | |
1739 | ||
1740 | Bootstrapping is complete when we have a full tool chain that does not | |
1741 | depend on the pre-built bootstrap tools discussed above. This | |
1742 | no-dependency requirement is verified by checking whether the files of | |
1743 | the final tool chain contain references to the @file{/nix/store} | |
1744 | directories of the bootstrap inputs. The process that leads to this | |
1745 | ``final'' tool chain is described by the package definitions found in | |
1746 | the @code{(gnu packages base)} module. | |
1747 | ||
1748 | @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>. | |
1749 | The first tool that gets built with the bootstrap binaries is | |
1750 | GNU Make, which is a prerequisite for all the following packages. | |
1751 | From there Findutils and Diffutils get built. | |
1752 | ||
1753 | Then come the first-stage Binutils and GCC, built as pseudo cross | |
1754 | tools---i.e., with @code{--target} equal to @code{--host}. They are | |
1755 | used to build libc. Thanks to this cross-build trick, this libc is | |
1756 | guaranteed not to hold any reference to the initial tool chain. | |
1757 | ||
1758 | From there the final Binutils and GCC are built. GCC uses @code{ld} | |
1759 | from the final Binutils, and links programs against the just-built libc. | |
1760 | This tool chain is used to build the other packages used by Guix and by | |
1761 | the GNU Build System: Guile, Bash, Coreutils, etc. | |
1762 | ||
1763 | And voilà! At this point we have the complete set of build tools that | |
1764 | the GNU Build System expects. These are in the @code{%final-inputs} | |
1765 | variables of the @code{(gnu packages base)} module, and are implicitly | |
1766 | used by any package that uses @code{gnu-build-system} (@pxref{Defining | |
1767 | Packages}). | |
1768 | ||
1769 | ||
1770 | @unnumberedsubsec Building the Bootstrap Binaries | |
1771 | ||
1772 | Because the final tool chain does not depend on the bootstrap binaries, | |
1773 | those rarely need to be updated. Nevertheless, it is useful to have an | |
1774 | automated way to produce them, should an update occur, and this is what | |
1775 | the @code{(gnu packages make-bootstrap)} module provides. | |
1776 | ||
1777 | The following command builds the tarballs containing the bootstrap | |
1778 | binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture | |
1779 | of Coreutils and other basic command-line tools): | |
a1ba8475 | 1780 | |
401c53c4 LC |
1781 | @example |
1782 | guix build bootstrap-tarballs | |
1783 | @end example | |
1784 | ||
1785 | The generated tarballs are those that should be referred to in the | |
1786 | @code{(gnu packages bootstrap)} module mentioned at the beginning of | |
1787 | this section. | |
1788 | ||
1789 | Still here? Then perhaps by now you've started to wonder: when do we | |
1790 | reach a fixed point? That is an interesting question! The answer is | |
1791 | unknown, but if you would like to investigate further (and have | |
1792 | significant computational and storage resources to do so), then let us | |
1793 | know. | |
a1ba8475 | 1794 | |
8b315a6d LC |
1795 | @node Porting |
1796 | @section Porting to a New Platform | |
1797 | ||
1798 | As discussed above, the GNU distribution is self-contained, and | |
1799 | self-containment is achieved by relying on pre-built ``bootstrap | |
1800 | binaries'' (@pxref{Bootstrapping}). These binaries are specific to an | |
1801 | operating system kernel, CPU architecture, and application binary | |
1802 | interface (ABI). Thus, to port the distribution to a platform that is | |
1803 | not yet supported, one must build those bootstrap binaries, and update | |
1804 | the @code{(gnu packages bootstrap)} module to use them on that platform. | |
1805 | ||
1806 | Fortunately, Guix can @emph{cross compile} those bootstrap binaries. | |
1807 | When everything goes well, and assuming the GNU tool chain supports the | |
1808 | target platform, this can be as simple as running a command like this | |
1809 | one: | |
1810 | ||
1811 | @example | |
1812 | guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs | |
1813 | @end example | |
1814 | ||
1815 | In practice, there may be some complications. First, it may be that the | |
1816 | extended GNU triplet that specifies an ABI (like the @code{eabi} suffix | |
1817 | above) is not recognized by all the GNU tools. Typically, glibc | |
1818 | recognizes some of these, whereas GCC uses an extra @code{--with-abi} | |
1819 | configure flag (see @code{gcc.scm} for examples of how to handle this.) | |
1820 | Second, some of the required packages could fail to build for that | |
1821 | platform. Lastly, the generated binaries could be broken for some | |
1822 | reason. | |
1823 | ||
9bf3c1a7 LC |
1824 | |
1825 | @c ********************************************************************* | |
1826 | @node Contributing | |
1827 | @chapter Contributing | |
1828 | ||
1829 | This project is a cooperative effort, and we need your help to make it | |
63f6004b | 1830 | grow! Please get in touch with us on @email{guix-devel@@gnu.org}. We |
a1ba8475 | 1831 | welcome ideas, bug reports, patches, and anything that may be helpful to |
b81e1947 LC |
1832 | the project. We particularly welcome help on packaging (@pxref{Adding |
1833 | New Packages}). | |
a1ba8475 | 1834 | |
9bf3c1a7 LC |
1835 | Please see the |
1836 | @url{http://git.savannah.gnu.org/cgit/guix.git/tree/HACKING, | |
1837 | @file{HACKING} file} that comes with the Guix source code for practical | |
1838 | details about contributions. | |
1839 | ||
c78bd12b | 1840 | |
568717fd LC |
1841 | @c ********************************************************************* |
1842 | @node Acknowledgments | |
1843 | @chapter Acknowledgments | |
1844 | ||
1845 | Guix is based on the Nix package manager, which was designed and | |
1846 | implemented by Eelco Dolstra. Nix pioneered functional package | |
1847 | management, and promoted unprecedented features, such as transactional | |
1848 | package upgrades and rollbacks, per-user profiles, and referentially | |
1849 | transparent build processes. Without this work, Guix would not exist. | |
1850 | ||
1851 | The Nix-based software distributions, Nixpkgs and NixOS, have also been | |
1852 | an inspiration for Guix. | |
1853 | ||
1854 | @c ********************************************************************* | |
1855 | @node GNU Free Documentation License | |
1856 | @appendix GNU Free Documentation License | |
1857 | ||
1858 | @include fdl-1.3.texi | |
1859 | ||
1860 | @c ********************************************************************* | |
1861 | @node Concept Index | |
1862 | @unnumbered Concept Index | |
1863 | @printindex cp | |
1864 | ||
1865 | @node Function Index | |
1866 | @unnumbered Function Index | |
1867 | @printindex fn | |
1868 | ||
1869 | @bye | |
1870 | ||
1871 | @c Local Variables: | |
1872 | @c ispell-local-dictionary: "american"; | |
1873 | @c End: |