Commit | Line | Data |
---|---|---|
568717fd LC |
1 | \input texinfo |
2 | @c -*-texinfo-*- | |
3 | ||
4 | @c %**start of header | |
5 | @setfilename guix.info | |
6 | @documentencoding UTF-8 | |
f8348b91 | 7 | @settitle GNU Guix Reference Manual |
568717fd LC |
8 | @c %**end of header |
9 | ||
10 | @include version.texi | |
7df7a74e NK |
11 | |
12 | @copying | |
4379c35b | 13 | Copyright @copyright{} 2012, 2013, 2014, 2015 Ludovic Courtès@* |
af8a56b8 | 14 | Copyright @copyright{} 2013, 2014 Andreas Enge@* |
87eafdbd | 15 | Copyright @copyright{} 2013 Nikita Karetnikov@* |
8c01b9d0 ML |
16 | Copyright @copyright{} 2015 Mathieu Lirzin@* |
17 | Copyright @copyright{} 2014 Pierre-Antoine Rault@* | |
87eafdbd | 18 | Copyright @copyright{} 2015 Taylan Ulrich Bayırlı/Kammer |
7df7a74e NK |
19 | |
20 | Permission is granted to copy, distribute and/or modify this document | |
21 | under the terms of the GNU Free Documentation License, Version 1.3 or | |
22 | any later version published by the Free Software Foundation; with no | |
23 | Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A | |
24 | copy of the license is included in the section entitled ``GNU Free | |
25 | Documentation License''. | |
26 | @end copying | |
568717fd | 27 | |
eeaf4427 | 28 | @dircategory Package management |
568717fd LC |
29 | @direntry |
30 | * guix: (guix). Guix, the functional package manager. | |
e49951eb | 31 | * guix package: (guix)Invoking guix package |
eeaf4427 | 32 | Managing packages with Guix. |
e49951eb | 33 | * guix build: (guix)Invoking guix build |
568717fd | 34 | Building packages with Guix. |
054e8576 LC |
35 | * guix system: (guix)Invoking guix system |
36 | Managing the operating system configuration. | |
568717fd | 37 | @end direntry |
568717fd | 38 | |
372c4bbc DT |
39 | @dircategory Software development |
40 | @direntry | |
41 | * guix environment: (guix)Invoking guix environment | |
42 | Building development environments with Guix. | |
43 | @end direntry | |
44 | ||
568717fd | 45 | @titlepage |
7730d112 LC |
46 | @title GNU Guix Reference Manual |
47 | @subtitle Using the GNU Guix Functional Package Manager | |
568717fd | 48 | @author Ludovic Courtès |
da7cabd4 | 49 | @author Andreas Enge |
acc08466 | 50 | @author Nikita Karetnikov |
568717fd LC |
51 | |
52 | @page | |
53 | @vskip 0pt plus 1filll | |
54 | Edition @value{EDITION} @* | |
55 | @value{UPDATED} @* | |
56 | ||
7df7a74e | 57 | @insertcopying |
568717fd LC |
58 | @end titlepage |
59 | ||
568717fd LC |
60 | @contents |
61 | ||
62 | @c ********************************************************************* | |
63 | @node Top | |
f8348b91 | 64 | @top GNU Guix |
568717fd | 65 | |
f8348b91 LC |
66 | This document describes GNU Guix version @value{VERSION}, a functional |
67 | package management tool written for the GNU system. | |
568717fd LC |
68 | |
69 | @menu | |
70 | * Introduction:: What is Guix about? | |
bd5e766b | 71 | * Installation:: Installing Guix. |
eeaf4427 | 72 | * Package Management:: Package installation, upgrade, etc. |
568717fd LC |
73 | * Programming Interface:: Using Guix in Scheme. |
74 | * Utilities:: Package management commands. | |
a1ba8475 | 75 | * GNU Distribution:: Software for your friendly GNU system. |
9bf3c1a7 | 76 | * Contributing:: Your help needed! |
568717fd LC |
77 | |
78 | * Acknowledgments:: Thanks! | |
79 | * GNU Free Documentation License:: The license of this manual. | |
80 | * Concept Index:: Concepts. | |
a85b83d2 | 81 | * Programming Index:: Data types, functions, and variables. |
aaa3eaa9 LC |
82 | |
83 | @detailmenu | |
84 | --- The Detailed Node Listing --- | |
85 | ||
86 | Installation | |
87 | ||
1b2b8177 | 88 | * Binary Installation:: Getting Guix running in no time! |
aaa3eaa9 | 89 | * Requirements:: Software needed to build and run Guix. |
ec0339cd | 90 | * Running the Test Suite:: Testing Guix. |
aaa3eaa9 LC |
91 | * Setting Up the Daemon:: Preparing the build daemon's environment. |
92 | * Invoking guix-daemon:: Running the build daemon. | |
0e2d0213 | 93 | * Application Setup:: Application-specific setup. |
aaa3eaa9 LC |
94 | |
95 | Setting Up the Daemon | |
96 | ||
97 | * Build Environment Setup:: Preparing the isolated build environment. | |
98 | * Daemon Offload Setup:: Offloading builds to remote machines. | |
99 | ||
100 | Package Management | |
101 | ||
102 | * Features:: How Guix will make your life brighter. | |
103 | * Invoking guix package:: Package installation, removal, etc. | |
104 | * Emacs Interface:: Package management from Emacs. | |
105 | * Substitutes:: Downloading pre-built binaries. | |
106 | * Packages with Multiple Outputs:: Single source package, multiple outputs. | |
107 | * Invoking guix gc:: Running the garbage collector. | |
108 | * Invoking guix pull:: Fetching the latest Guix and distribution. | |
109 | * Invoking guix archive:: Exporting and importing store files. | |
110 | ||
111 | Programming Interface | |
112 | ||
113 | * Defining Packages:: Defining new packages. | |
114 | * Build Systems:: Specifying how packages are built. | |
115 | * The Store:: Manipulating the package store. | |
116 | * Derivations:: Low-level interface to package derivations. | |
117 | * The Store Monad:: Purely functional interface to the store. | |
118 | * G-Expressions:: Manipulating build expressions. | |
119 | ||
92492b23 LC |
120 | Defining Packages |
121 | ||
122 | * package Reference:: The package data type. | |
123 | * origin Reference:: The origin data type. | |
124 | ||
aaa3eaa9 LC |
125 | Utilities |
126 | ||
127 | * Invoking guix build:: Building packages from the command line. | |
fcc58db6 | 128 | * Invoking guix edit:: Editing package definitions. |
aaa3eaa9 LC |
129 | * Invoking guix download:: Downloading a file and printing its hash. |
130 | * Invoking guix hash:: Computing the cryptographic hash of a file. | |
131 | * Invoking guix import:: Importing package definitions. | |
132 | * Invoking guix refresh:: Updating package definitions. | |
133 | * Invoking guix lint:: Finding errors in package definitions. | |
fcc58db6 | 134 | * Invoking guix size:: Profiling disk usage. |
aaa3eaa9 | 135 | * Invoking guix environment:: Setting up development environments. |
aff8ce7c | 136 | * Invoking guix publish:: Sharing substitutes. |
aaa3eaa9 LC |
137 | |
138 | GNU Distribution | |
139 | ||
140 | * System Installation:: Installing the whole operating system. | |
35ed9306 | 141 | * System Configuration:: Configuring the operating system. |
aaa3eaa9 LC |
142 | * Installing Debugging Files:: Feeding the debugger. |
143 | * Security Updates:: Deploying security fixes quickly. | |
144 | * Package Modules:: Packages from the programmer's viewpoint. | |
145 | * Packaging Guidelines:: Growing the distribution. | |
146 | * Bootstrapping:: GNU/Linux built from scratch. | |
147 | * Porting:: Targeting another platform or kernel. | |
148 | ||
149 | System Configuration | |
150 | ||
151 | * Using the Configuration System:: Customizing your GNU system. | |
152 | * operating-system Reference:: Detail of operating-system declarations. | |
153 | * File Systems:: Configuring file system mounts. | |
154 | * Mapped Devices:: Block device extra processing. | |
155 | * User Accounts:: Specifying user accounts. | |
598e19dc | 156 | * Locales:: Language and cultural convention settings. |
aaa3eaa9 LC |
157 | * Services:: Specifying system services. |
158 | * Setuid Programs:: Programs running with root privileges. | |
1b2b8177 | 159 | * X.509 Certificates:: Authenticating HTTPS servers. |
996ed739 | 160 | * Name Service Switch:: Configuring libc's name service switch. |
aaa3eaa9 LC |
161 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
162 | * GRUB Configuration:: Configuring the boot loader. | |
163 | * Invoking guix system:: Instantiating a system configuration. | |
164 | * Defining Services:: Adding new service definitions. | |
165 | ||
166 | Services | |
167 | ||
168 | * Base Services:: Essential system services. | |
169 | * Networking Services:: Network setup, SSH daemon, etc. | |
170 | * X Window:: Graphical display. | |
1b2b8177 LC |
171 | * Desktop Services:: D-Bus and desktop services. |
172 | * Database Services:: SQL databases. | |
aa4ed923 | 173 | * Various Services:: Other services. |
aaa3eaa9 LC |
174 | |
175 | Packaging Guidelines | |
176 | ||
ec0339cd LC |
177 | * Software Freedom:: What may go into the distribution. |
178 | * Package Naming:: What's in a name? | |
179 | * Version Numbers:: When the name is not enough. | |
180 | * Python Modules:: Taming the snake. | |
181 | * Perl Modules:: Little pearls. | |
182 | * Fonts:: Fond of fonts. | |
aaa3eaa9 | 183 | |
8c01b9d0 ML |
184 | Contributing |
185 | ||
186 | * Building from Git:: The latest and greatest. | |
187 | * Running Guix Before It Is Installed:: Hacker tricks. | |
188 | * The Perfect Setup:: The right tools. | |
189 | * Coding Style:: Hygiene of the contributor. | |
190 | * Submitting Patches:: Share your work. | |
191 | ||
192 | Coding Style | |
193 | ||
194 | * Programming Paradigm:: How to compose your elements. | |
195 | * Modules:: Where to store your code? | |
196 | * Data Types and Pattern Matching:: Implementing data structures. | |
197 | * Formatting Code:: Writing conventions. | |
198 | ||
aaa3eaa9 | 199 | @end detailmenu |
568717fd LC |
200 | @end menu |
201 | ||
202 | @c ********************************************************************* | |
203 | @node Introduction | |
204 | @chapter Introduction | |
205 | ||
c80e7e55 LC |
206 | GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks'' |
207 | using the international phonetic alphabet (IPA).} is a functional | |
208 | package management tool for the GNU system. Package management consists | |
4bfc4ea3 NK |
209 | of all activities that relate to building packages from sources, |
210 | honoring their build-time and run-time dependencies, | |
c80e7e55 LC |
211 | installing packages in user environments, upgrading installed packages |
212 | to new versions or rolling back to a previous set, removing unused | |
213 | software packages, etc. | |
568717fd LC |
214 | |
215 | @cindex functional package management | |
216 | The term @dfn{functional} refers to a specific package management | |
217 | discipline. In Guix, the package build and installation process is seen | |
4bfc4ea3 NK |
218 | as a function, in the mathematical sense. That function takes inputs, |
219 | such as build scripts, a compiler, and libraries, and | |
220 | returns an installed package. As a pure function, its result depends | |
568717fd LC |
221 | solely on its inputs---for instance, it cannot refer to software or |
222 | scripts that were not explicitly passed as inputs. A build function | |
4bfc4ea3 NK |
223 | always produces the same result when passed a given set of inputs. It |
224 | cannot alter the system's environment in | |
568717fd LC |
225 | any way; for instance, it cannot create, modify, or delete files outside |
226 | of its build and installation directories. This is achieved by running | |
e900c503 | 227 | build processes in isolated environments (or @dfn{containers}), where only their |
4bfc4ea3 | 228 | explicit inputs are visible. |
568717fd | 229 | |
e531ac2a | 230 | @cindex store |
568717fd | 231 | The result of package build functions is @dfn{cached} in the file |
e531ac2a LC |
232 | system, in a special directory called @dfn{the store} (@pxref{The |
233 | Store}). Each package is installed in a directory of its own, in the | |
834129e0 | 234 | store---by default under @file{/gnu/store}. The directory name contains |
568717fd LC |
235 | a hash of all the inputs used to build that package; thus, changing an |
236 | input yields a different directory name. | |
237 | ||
238 | This approach is the foundation of Guix's salient features: support for | |
4bfc4ea3 | 239 | transactional package upgrade and rollback, per-user installation, and |
eeaf4427 | 240 | garbage collection of packages (@pxref{Features}). |
568717fd | 241 | |
4bfc4ea3 | 242 | Guix has a command-line interface, which allows users to build, install, |
568717fd | 243 | upgrade, and remove packages, as well as a Scheme programming interface. |
568717fd | 244 | |
3ca2731c | 245 | @cindex Guix System Distribution |
4705641f | 246 | @cindex GuixSD |
a1ba8475 | 247 | Last but not least, Guix is used to build a distribution of the GNU |
3ca2731c | 248 | system, with many GNU and non-GNU free software packages. The Guix |
4705641f LC |
249 | System Distribution, or GNU@tie{}GuixSD, takes advantage of the core |
250 | properties of Guix at the system level. With GuixSD, users | |
3ca2731c LC |
251 | @emph{declare} all aspects of the operating system configuration, and |
252 | Guix takes care of instantiating that configuration in a reproducible, | |
253 | stateless fashion. @xref{GNU Distribution}. | |
a1ba8475 | 254 | |
bd5e766b LC |
255 | @c ********************************************************************* |
256 | @node Installation | |
257 | @chapter Installation | |
258 | ||
48febeb8 LC |
259 | GNU Guix is available for download from its website at |
260 | @url{http://www.gnu.org/software/guix/}. This section describes the | |
261 | software requirements of Guix, as well as how to install it and get | |
262 | ready to use it. | |
bd5e766b | 263 | |
5af6de3e LC |
264 | Note that this section is concerned with the installation of the package |
265 | manager, which can be done on top of a running GNU/Linux system. If, | |
266 | instead, you want to install the complete GNU operating system, | |
6621cdb6 | 267 | @pxref{System Installation}. |
5af6de3e | 268 | |
bd5e766b | 269 | @menu |
09722b11 | 270 | * Binary Installation:: Getting Guix running in no time! |
bd5e766b | 271 | * Requirements:: Software needed to build and run Guix. |
ec0339cd | 272 | * Running the Test Suite:: Testing Guix. |
bd5e766b LC |
273 | * Setting Up the Daemon:: Preparing the build daemon's environment. |
274 | * Invoking guix-daemon:: Running the build daemon. | |
0e2d0213 | 275 | * Application Setup:: Application-specific setup. |
bd5e766b LC |
276 | @end menu |
277 | ||
09722b11 LC |
278 | @node Binary Installation |
279 | @section Binary Installation | |
280 | ||
281 | This section describes how to install Guix on an arbitrary system from a | |
282 | self-contained tarball providing binaries for Guix and for all its | |
283 | dependencies. This is often quicker than installing from source, which | |
284 | is described in the next sections. The only requirement is to have | |
285 | GNU@tie{}tar and Xz. | |
286 | ||
287 | Installing goes along these lines: | |
288 | ||
289 | @enumerate | |
290 | @item | |
291 | Download the binary tarball from | |
ae806096 | 292 | @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz}@footnote{As |
09722b11 LC |
293 | usual, make sure to download the associated @file{.sig} file and to |
294 | verify the authenticity of the tarball against it!}, where @var{system} | |
295 | is @code{x86_64-linux} for an @code{x86_64} machine already running the | |
296 | kernel Linux, and so on. | |
297 | ||
298 | @item | |
299 | As @code{root}, run: | |
300 | ||
301 | @example | |
5dc42964 | 302 | # cd /tmp |
b91d7f0f | 303 | # tar xf guix-binary-@value{VERSION}.@var{system}.tar.xz |
5dc42964 | 304 | # mv var/guix /var/ && mv gnu / |
09722b11 LC |
305 | @end example |
306 | ||
7acd3439 LC |
307 | This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}. |
308 | The latter contains a ready-to-use profile for @code{root} (see next | |
309 | step.) | |
09722b11 | 310 | |
5dc3ce5f LC |
311 | Do @emph{not} unpack the tarball on a working Guix system since that |
312 | would overwrite its own essential files. | |
313 | ||
7acd3439 LC |
314 | @item |
315 | Make @code{root}'s profile available under @file{~/.guix-profile}: | |
316 | ||
317 | @example | |
318 | # ln -sf /var/guix/profiles/per-user/root/guix-profile \ | |
319 | ~root/.guix-profile | |
320 | @end example | |
321 | ||
09722b11 | 322 | @item |
175ced41 | 323 | Run the daemon: |
09722b11 LC |
324 | |
325 | @example | |
7acd3439 | 326 | # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild |
09722b11 LC |
327 | @end example |
328 | ||
329 | @item | |
330 | Make the @command{guix} command available to other users on the machine, | |
331 | for instance with: | |
332 | ||
333 | @example | |
334 | # mkdir -p /usr/local/bin | |
335 | # cd /usr/local/bin | |
d72d05f9 | 336 | # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix |
09722b11 | 337 | @end example |
39f8ed14 LC |
338 | |
339 | @item | |
340 | To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}), | |
341 | authorize them: | |
342 | ||
343 | @example | |
7acd3439 | 344 | # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub |
39f8ed14 | 345 | @end example |
09722b11 LC |
346 | @end enumerate |
347 | ||
348 | And that's it! | |
349 | ||
5dc3ce5f | 350 | The @code{guix} package must remain available in @code{root}'s |
09722b11 LC |
351 | profile, or it would become subject to garbage collection---in which |
352 | case you would find yourself badly handicapped by the lack of the | |
353 | @command{guix} command. | |
354 | ||
39f8ed14 LC |
355 | The tarball in question can be (re)produced and verified simply by |
356 | running the following command in the Guix source tree: | |
09722b11 LC |
357 | |
358 | @example | |
359 | make guix-binary.@var{system}.tar.xz | |
360 | @end example | |
361 | ||
362 | ||
bd5e766b LC |
363 | @node Requirements |
364 | @section Requirements | |
365 | ||
09722b11 LC |
366 | This section lists requirements when building Guix from source. The |
367 | build procedure for Guix is the same as for other GNU software, and is | |
368 | not covered here. Please see the files @file{README} and @file{INSTALL} | |
369 | in the Guix source tree for additional details. | |
370 | ||
bd5e766b LC |
371 | GNU Guix depends on the following packages: |
372 | ||
373 | @itemize | |
47c66da0 | 374 | @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later; |
288dca55 | 375 | @item @url{http://gnupg.org/, GNU libgcrypt}; |
f0b98b84 | 376 | @item @url{http://www.gnu.org/software/make/, GNU Make}. |
8a96bd4b ID |
377 | @end itemize |
378 | ||
379 | The following dependencies are optional: | |
380 | ||
381 | @itemize | |
288dca55 | 382 | @item |
8a96bd4b | 383 | Installing |
288dca55 | 384 | @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will |
2f7d2d91 LC |
385 | allow you to use the @command{guix import pypi} command (@pxref{Invoking |
386 | guix import}). It is of | |
288dca55 | 387 | interest primarily for developers and not for casual users. |
8a96bd4b ID |
388 | @item |
389 | Installing @uref{http://gnutls.org/, GnuTLS-Guile} will | |
390 | allow you to access @code{https} URLs with the @command{guix download} | |
d45dc6da EB |
391 | command (@pxref{Invoking guix download}), the @command{guix import pypi} |
392 | command, and the @command{guix import cpan} command. This is primarily | |
393 | of interest to developers. @xref{Guile Preparations, how to install the | |
394 | GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}. | |
bd5e766b LC |
395 | @end itemize |
396 | ||
397 | Unless @code{--disable-daemon} was passed to @command{configure}, the | |
398 | following packages are also needed: | |
399 | ||
400 | @itemize | |
368d08f7 LC |
401 | @item @url{http://sqlite.org, SQLite 3}; |
402 | @item @url{http://www.bzip.org, libbz2}; | |
403 | @item @url{http://gcc.gnu.org, GCC's g++}, with support for the | |
404 | C++11 standard. | |
bd5e766b LC |
405 | @end itemize |
406 | ||
4bfc4ea3 NK |
407 | When a working installation of @url{http://nixos.org/nix/, the Nix package |
408 | manager} is available, you | |
bd5e766b | 409 | can instead configure Guix with @code{--disable-daemon}. In that case, |
4bfc4ea3 | 410 | Nix replaces the three dependencies above. |
bd5e766b | 411 | |
b22a12fd LC |
412 | Guix is compatible with Nix, so it is possible to share the same store |
413 | between both. To do so, you must pass @command{configure} not only the | |
414 | same @code{--with-store-dir} value, but also the same | |
4bfc4ea3 NK |
415 | @code{--localstatedir} value. The latter is essential because it |
416 | specifies where the database that stores metadata about the store is | |
834129e0 | 417 | located, among other things. The default values for Nix are |
b22a12fd | 418 | @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}. |
4bfc4ea3 NK |
419 | Note that @code{--disable-daemon} is not required if |
420 | your goal is to share the store with Nix. | |
b22a12fd | 421 | |
ec0339cd LC |
422 | @node Running the Test Suite |
423 | @section Running the Test Suite | |
424 | ||
425 | After a successful @command{configure} and @code{make} run, it is a good | |
426 | idea to run the test suite. It can help catch issues with the setup or | |
427 | environment, or bugs in Guix itself---and really, reporting test | |
428 | failures is a good way to help improve the software. To run the test | |
429 | suite, type: | |
430 | ||
431 | @example | |
432 | make check | |
433 | @end example | |
434 | ||
435 | Test cases can run in parallel: you can use the @code{-j} option of | |
436 | GNU@tie{}make to speed things up. The first run may take a few minutes | |
437 | on a recent machine; subsequent runs will be faster because the store | |
438 | that is created for test purposes will already have various things in | |
439 | cache. | |
440 | ||
441 | Upon failure, please email @email{bug-guix@@gnu.org} and attach the | |
442 | @file{test-suite.log} file. When @file{tests/@var{something}.scm} | |
443 | fails, please also attach the @file{@var{something}.log} file available | |
444 | in the top-level build directory. Please specify the Guix version being | |
445 | used as well as version numbers of the dependencies | |
446 | (@pxref{Requirements}) in your message. | |
447 | ||
bd5e766b LC |
448 | @node Setting Up the Daemon |
449 | @section Setting Up the Daemon | |
450 | ||
451 | @cindex daemon | |
452 | Operations such as building a package or running the garbage collector | |
49e6291a | 453 | are all performed by a specialized process, the @dfn{build daemon}, on |
bd5e766b LC |
454 | behalf of clients. Only the daemon may access the store and its |
455 | associated database. Thus, any operation that manipulates the store | |
456 | goes through the daemon. For instance, command-line tools such as | |
e49951eb | 457 | @command{guix package} and @command{guix build} communicate with the |
bd5e766b LC |
458 | daemon (@i{via} remote procedure calls) to instruct it what to do. |
459 | ||
49e6291a | 460 | The following sections explain how to prepare the build daemon's |
225dafde LC |
461 | environment. Also @ref{Substitutes}, for information on how to allow |
462 | the daemon to download pre-built binaries. | |
49e6291a LC |
463 | |
464 | @menu | |
465 | * Build Environment Setup:: Preparing the isolated build environment. | |
466 | * Daemon Offload Setup:: Offloading builds to remote machines. | |
467 | @end menu | |
468 | ||
469 | @node Build Environment Setup | |
470 | @subsection Build Environment Setup | |
471 | ||
bd5e766b LC |
472 | In a standard multi-user setup, Guix and its daemon---the |
473 | @command{guix-daemon} program---are installed by the system | |
834129e0 | 474 | administrator; @file{/gnu/store} is owned by @code{root} and |
bd5e766b LC |
475 | @command{guix-daemon} runs as @code{root}. Unprivileged users may use |
476 | Guix tools to build packages or otherwise access the store, and the | |
477 | daemon will do it on their behalf, ensuring that the store is kept in a | |
478 | consistent state, and allowing built packages to be shared among users. | |
479 | ||
480 | @cindex build users | |
481 | When @command{guix-daemon} runs as @code{root}, you may not want package | |
482 | build processes themselves to run as @code{root} too, for obvious | |
483 | security reasons. To avoid that, a special pool of @dfn{build users} | |
484 | should be created for use by build processes started by the daemon. | |
485 | These build users need not have a shell and a home directory: they will | |
486 | just be used when the daemon drops @code{root} privileges in build | |
487 | processes. Having several such users allows the daemon to launch | |
488 | distinct build processes under separate UIDs, which guarantees that they | |
489 | do not interfere with each other---an essential feature since builds are | |
490 | regarded as pure functions (@pxref{Introduction}). | |
491 | ||
492 | On a GNU/Linux system, a build user pool may be created like this (using | |
493 | Bash syntax and the @code{shadow} commands): | |
494 | ||
091196b3 LC |
495 | @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html |
496 | @c for why `-G' is needed. | |
bd5e766b | 497 | @example |
cfc149dc LC |
498 | # groupadd --system guixbuild |
499 | # for i in `seq -w 1 10`; | |
bd5e766b | 500 | do |
cfc149dc LC |
501 | useradd -g guixbuild -G guixbuild \ |
502 | -d /var/empty -s `which nologin` \ | |
503 | -c "Guix build user $i" --system \ | |
504 | guixbuilder$i; | |
bd5e766b LC |
505 | done |
506 | @end example | |
507 | ||
508 | @noindent | |
54eb03ab LC |
509 | The number of build users determines how many build jobs may run in |
510 | parallel, as specified by the @option{--max-jobs} option | |
511 | (@pxref{Invoking guix-daemon, @option{--max-jobs}}). | |
bd5e766b LC |
512 | The @code{guix-daemon} program may then be run as @code{root} with: |
513 | ||
514 | @example | |
cfc149dc | 515 | # guix-daemon --build-users-group=guixbuild |
bd5e766b LC |
516 | @end example |
517 | ||
e900c503 | 518 | @cindex chroot |
b095792f LC |
519 | @noindent |
520 | This way, the daemon starts build processes in a chroot, under one of | |
cfc149dc | 521 | the @code{guixbuilder} users. On GNU/Linux, by default, the chroot |
6dc99317 LC |
522 | environment contains nothing but: |
523 | ||
524 | @c Keep this list in sync with libstore/build.cc! ----------------------- | |
525 | @itemize | |
526 | @item | |
4743a4da LC |
527 | a minimal @code{/dev} directory, created mostly independently from the |
528 | host @code{/dev}@footnote{``Mostly'', because while the set of files | |
529 | that appear in the chroot's @code{/dev} is fixed, most of these files | |
530 | can only be created if the host has them.}; | |
531 | ||
532 | @item | |
533 | the @code{/proc} directory; it only shows the container's processes | |
534 | since a separate PID name space is used; | |
6dc99317 LC |
535 | |
536 | @item | |
537 | @file{/etc/passwd} with an entry for the current user and an entry for | |
538 | user @file{nobody}; | |
539 | ||
540 | @item | |
541 | @file{/etc/group} with an entry for the user's group; | |
542 | ||
543 | @item | |
544 | @file{/etc/hosts} with an entry that maps @code{localhost} to | |
545 | @code{127.0.0.1}; | |
546 | ||
547 | @item | |
548 | a writable @file{/tmp} directory. | |
549 | @end itemize | |
b095792f | 550 | |
1e2644bb LC |
551 | If you are installing Guix as an unprivileged user, it is still possible |
552 | to run @command{guix-daemon} provided you pass @code{--disable-chroot}. | |
553 | However, build processes will not be isolated from one another, and not | |
554 | from the rest of the system. Thus, build processes may interfere with | |
555 | each other, and may access programs, libraries, and other files | |
556 | available on the system---making it much harder to view them as | |
557 | @emph{pure} functions. | |
bd5e766b | 558 | |
49e6291a LC |
559 | |
560 | @node Daemon Offload Setup | |
561 | @subsection Using the Offload Facility | |
562 | ||
563 | @cindex offloading | |
4ec2e92d LC |
564 | @cindex build hook |
565 | When desired, the build daemon can @dfn{offload} | |
566 | derivation builds to other machines | |
49e6291a LC |
567 | running Guix, using the @code{offload} @dfn{build hook}. When that |
568 | feature is enabled, a list of user-specified build machines is read from | |
569 | @file{/etc/guix/machines.scm}; anytime a build is requested, for | |
570 | instance via @code{guix build}, the daemon attempts to offload it to one | |
571 | of the machines that satisfies the derivation's constraints, in | |
572 | particular its system type---e.g., @file{x86_64-linux}. Missing | |
573 | prerequisites for the build are copied over SSH to the target machine, | |
574 | which then proceeds with the build; upon success the output(s) of the | |
575 | build are copied back to the initial machine. | |
576 | ||
4ec2e92d | 577 | The @file{/etc/guix/machines.scm} file typically looks like this: |
49e6291a LC |
578 | |
579 | @example | |
580 | (list (build-machine | |
581 | (name "eightysix.example.org") | |
582 | (system "x86_64-linux") | |
583 | (user "bob") | |
584 | (speed 2.)) ; incredibly fast! | |
585 | ||
586 | (build-machine | |
587 | (name "meeps.example.org") | |
588 | (system "mips64el-linux") | |
589 | (user "alice") | |
590 | (private-key | |
591 | (string-append (getenv "HOME") | |
c4fdfd6f | 592 | "/.lsh/identity-for-guix")))) |
49e6291a LC |
593 | @end example |
594 | ||
595 | @noindent | |
596 | In the example above we specify a list of two build machines, one for | |
597 | the @code{x86_64} architecture and one for the @code{mips64el} | |
4ec2e92d LC |
598 | architecture. |
599 | ||
600 | In fact, this file is---not surprisingly!---a Scheme file that is | |
601 | evaluated when the @code{offload} hook is started. Its return value | |
602 | must be a list of @code{build-machine} objects. While this example | |
603 | shows a fixed list of build machines, one could imagine, say, using | |
604 | DNS-SD to return a list of potential build machines discovered in the | |
605 | local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using | |
c678a4ee LC |
606 | Avahi in Guile Scheme Programs}). The @code{build-machine} data type is |
607 | detailed below. | |
4ec2e92d | 608 | |
c678a4ee LC |
609 | @deftp {Data Type} build-machine |
610 | This data type represents build machines the daemon may offload builds | |
611 | to. The important fields are: | |
49e6291a LC |
612 | |
613 | @table @code | |
614 | ||
615 | @item name | |
616 | The remote machine's host name. | |
617 | ||
618 | @item system | |
c678a4ee | 619 | The remote machine's system type---e.g., @code{"x86_64-linux"}. |
49e6291a LC |
620 | |
621 | @item user | |
622 | The user account to use when connecting to the remote machine over SSH. | |
623 | Note that the SSH key pair must @emph{not} be passphrase-protected, to | |
624 | allow non-interactive logins. | |
625 | ||
626 | @end table | |
627 | ||
4ec2e92d | 628 | A number of optional fields may be specified: |
49e6291a LC |
629 | |
630 | @table @code | |
631 | ||
cecd72d5 LC |
632 | @item port |
633 | Port number of the machine's SSH server (default: 22). | |
634 | ||
49e6291a LC |
635 | @item private-key |
636 | The SSH private key file to use when connecting to the machine. | |
637 | ||
c4fdfd6f LC |
638 | Currently offloading uses GNU@tie{}lsh as its SSH client |
639 | (@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must | |
640 | be an lsh key file. This may change in the future, though. | |
641 | ||
49e6291a LC |
642 | @item parallel-builds |
643 | The number of builds that may run in parallel on the machine (1 by | |
644 | default.) | |
645 | ||
646 | @item speed | |
647 | A ``relative speed factor''. The offload scheduler will tend to prefer | |
648 | machines with a higher speed factor. | |
649 | ||
650 | @item features | |
651 | A list of strings denoting specific features supported by the machine. | |
652 | An example is @code{"kvm"} for machines that have the KVM Linux modules | |
653 | and corresponding hardware support. Derivations can request features by | |
654 | name, and they will be scheduled on matching build machines. | |
655 | ||
656 | @end table | |
c678a4ee | 657 | @end deftp |
49e6291a LC |
658 | |
659 | The @code{guix} command must be in the search path on the build | |
660 | machines, since offloading works by invoking the @code{guix archive} and | |
c4fdfd6f LC |
661 | @code{guix build} commands. In addition, the Guix modules must be in |
662 | @code{$GUILE_LOAD_PATH} on the build machine---you can check whether | |
663 | this is the case by running: | |
664 | ||
665 | @example | |
666 | lsh build-machine guile -c '(use-modules (guix config))' | |
667 | @end example | |
49e6291a LC |
668 | |
669 | There's one last thing to do once @file{machines.scm} is in place. As | |
670 | explained above, when offloading, files are transferred back and forth | |
c4fdfd6f LC |
671 | between the machine stores. For this to work, you first need to |
672 | generate a key pair on each machine to allow the daemon to export signed | |
673 | archives of files from the store (@pxref{Invoking guix archive}): | |
49e6291a LC |
674 | |
675 | @example | |
676 | # guix archive --generate-key | |
677 | @end example | |
678 | ||
679 | @noindent | |
c4fdfd6f LC |
680 | Each build machine must authorize the key of the master machine so that |
681 | it accepts store items it receives from the master: | |
682 | ||
683 | @example | |
684 | # guix archive --authorize < master-public-key.txt | |
685 | @end example | |
686 | ||
687 | @noindent | |
688 | Likewise, the master machine must authorize the key of each build machine. | |
689 | ||
690 | All the fuss with keys is here to express pairwise mutual trust | |
691 | relations between the master and the build machines. Concretely, when | |
692 | the master receives files from a build machine (and @i{vice versa}), its | |
693 | build daemon can make sure they are genuine, have not been tampered | |
694 | with, and that they are signed by an authorized key. | |
49e6291a LC |
695 | |
696 | ||
bd5e766b LC |
697 | @node Invoking guix-daemon |
698 | @section Invoking @command{guix-daemon} | |
699 | ||
700 | The @command{guix-daemon} program implements all the functionality to | |
701 | access the store. This includes launching build processes, running the | |
702 | garbage collector, querying the availability of a build result, etc. It | |
703 | is normally run as @code{root} like this: | |
704 | ||
705 | @example | |
cfc149dc | 706 | # guix-daemon --build-users-group=guixbuild |
bd5e766b LC |
707 | @end example |
708 | ||
709 | @noindent | |
081145cf | 710 | For details on how to set it up, @pxref{Setting Up the Daemon}. |
bd5e766b | 711 | |
e900c503 LC |
712 | @cindex chroot |
713 | @cindex container, build environment | |
714 | @cindex build environment | |
715 | @cindex reproducible builds | |
bd5e766b LC |
716 | By default, @command{guix-daemon} launches build processes under |
717 | different UIDs, taken from the build group specified with | |
718 | @code{--build-users-group}. In addition, each build process is run in a | |
719 | chroot environment that only contains the subset of the store that the | |
720 | build process depends on, as specified by its derivation | |
721 | (@pxref{Programming Interface, derivation}), plus a set of specific | |
722 | system directories. By default, the latter contains @file{/dev} and | |
e900c503 LC |
723 | @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a |
724 | @dfn{container}: in addition to having its own file system tree, it has | |
725 | a separate mount name space, its own PID name space, network name space, | |
726 | etc. This helps achieve reproducible builds (@pxref{Features}). | |
bd5e766b | 727 | |
cbc538fe LC |
728 | When the daemon performs a build on behalf of the user, it creates a |
729 | build directory under @file{/tmp} or under the directory specified by | |
730 | its @code{TMPDIR} environment variable; this directory is shared with | |
731 | the container for the duration of the build. Be aware that using a | |
732 | directory other than @file{/tmp} can affect build results---for example, | |
733 | with a longer directory name, a build process that uses Unix-domain | |
734 | sockets might hit the name length limitation for @code{sun_path}, which | |
735 | it would otherwise not hit. | |
736 | ||
737 | The build directory is automatically deleted upon completion, unless the | |
738 | build failed and the client specified @option{--keep-failed} | |
739 | (@pxref{Invoking guix build, @option{--keep-failed}}). | |
740 | ||
bd5e766b LC |
741 | The following command-line options are supported: |
742 | ||
743 | @table @code | |
744 | @item --build-users-group=@var{group} | |
745 | Take users from @var{group} to run build processes (@pxref{Setting Up | |
746 | the Daemon, build users}). | |
747 | ||
6858f9d1 | 748 | @item --no-substitutes |
b5385b52 | 749 | @cindex substitutes |
6858f9d1 | 750 | Do not use substitutes for build products. That is, always build things |
c4202d60 LC |
751 | locally instead of allowing downloads of pre-built binaries |
752 | (@pxref{Substitutes}). | |
6858f9d1 | 753 | |
b5385b52 LC |
754 | By default substitutes are used, unless the client---such as the |
755 | @command{guix package} command---is explicitly invoked with | |
756 | @code{--no-substitutes}. | |
757 | ||
758 | When the daemon runs with @code{--no-substitutes}, clients can still | |
759 | explicitly enable substitution @i{via} the @code{set-build-options} | |
760 | remote procedure call (@pxref{The Store}). | |
761 | ||
9176607e | 762 | @item --substitute-urls=@var{urls} |
f8a8e0fe | 763 | @anchor{daemon-substitute-urls} |
9176607e | 764 | Consider @var{urls} the default whitespace-separated list of substitute |
ae806096 | 765 | source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org} |
9176607e LC |
766 | is used. |
767 | ||
768 | This means that substitutes may be downloaded from @var{urls}, as long | |
769 | as they are signed by a trusted signature (@pxref{Substitutes}). | |
770 | ||
4ec2e92d LC |
771 | @cindex build hook |
772 | @item --no-build-hook | |
773 | Do not use the @dfn{build hook}. | |
774 | ||
775 | The build hook is a helper program that the daemon can start and to | |
776 | which it submits build requests. This mechanism is used to offload | |
777 | builds to other machines (@pxref{Daemon Offload Setup}). | |
778 | ||
bd5e766b LC |
779 | @item --cache-failures |
780 | Cache build failures. By default, only successful builds are cached. | |
781 | ||
782 | @item --cores=@var{n} | |
783 | @itemx -c @var{n} | |
784 | Use @var{n} CPU cores to build each derivation; @code{0} means as many | |
785 | as available. | |
786 | ||
6efc160e | 787 | The default value is @code{0}, but it may be overridden by clients, such |
e49951eb MW |
788 | as the @code{--cores} option of @command{guix build} (@pxref{Invoking |
789 | guix build}). | |
bd5e766b LC |
790 | |
791 | The effect is to define the @code{NIX_BUILD_CORES} environment variable | |
792 | in the build process, which can then use it to exploit internal | |
793 | parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}. | |
794 | ||
795 | @item --max-jobs=@var{n} | |
796 | @itemx -M @var{n} | |
797 | Allow at most @var{n} build jobs in parallel. The default value is | |
f6526eb3 LC |
798 | @code{1}. Setting it to @code{0} means that no builds will be performed |
799 | locally; instead, the daemon will offload builds (@pxref{Daemon Offload | |
800 | Setup}), or simply fail. | |
bd5e766b LC |
801 | |
802 | @item --debug | |
803 | Produce debugging output. | |
804 | ||
805 | This is useful to debug daemon start-up issues, but then it may be | |
806 | overridden by clients, for example the @code{--verbosity} option of | |
e49951eb | 807 | @command{guix build} (@pxref{Invoking guix build}). |
bd5e766b LC |
808 | |
809 | @item --chroot-directory=@var{dir} | |
810 | Add @var{dir} to the build chroot. | |
811 | ||
812 | Doing this may change the result of build processes---for instance if | |
813 | they use optional dependencies found in @var{dir} when it is available, | |
814 | and not otherwise. For that reason, it is not recommended to do so. | |
815 | Instead, make sure that each derivation declares all the inputs that it | |
816 | needs. | |
817 | ||
818 | @item --disable-chroot | |
819 | Disable chroot builds. | |
820 | ||
821 | Using this option is not recommended since, again, it would allow build | |
1e2644bb LC |
822 | processes to gain access to undeclared dependencies. It is necessary, |
823 | though, when @command{guix-daemon} is running under an unprivileged user | |
824 | account. | |
bd5e766b LC |
825 | |
826 | @item --disable-log-compression | |
827 | Disable compression of the build logs. | |
828 | ||
1da983b9 LC |
829 | Unless @code{--lose-logs} is used, all the build logs are kept in the |
830 | @var{localstatedir}. To save space, the daemon automatically compresses | |
831 | them with bzip2 by default. This option disables that. | |
832 | ||
ab3893d7 LC |
833 | @item --disable-deduplication |
834 | @cindex deduplication | |
bd5e766b LC |
835 | Disable automatic file ``deduplication'' in the store. |
836 | ||
1da983b9 | 837 | By default, files added to the store are automatically ``deduplicated'': |
ab3893d7 LC |
838 | if a newly added file is identical to another one found in the store, |
839 | the daemon makes the new file a hard link to the other file. This can | |
840 | noticeably reduce disk usage, at the expense of slightly increasde | |
841 | input/output load at the end of a build process. This option disables | |
842 | this optimization. | |
1da983b9 | 843 | |
6e37066e LC |
844 | @item --gc-keep-outputs[=yes|no] |
845 | Tell whether the garbage collector (GC) must keep outputs of live | |
846 | derivations. | |
847 | ||
848 | When set to ``yes'', the GC will keep the outputs of any live derivation | |
849 | available in the store---the @code{.drv} files. The default is ``no'', | |
850 | meaning that derivation outputs are kept only if they are GC roots. | |
851 | ||
852 | @item --gc-keep-derivations[=yes|no] | |
853 | Tell whether the garbage collector (GC) must keep derivations | |
854 | corresponding to live outputs. | |
855 | ||
856 | When set to ``yes'', as is the case by default, the GC keeps | |
857 | derivations---i.e., @code{.drv} files---as long as at least one of their | |
858 | outputs is live. This allows users to keep track of the origins of | |
859 | items in their store. Setting it to ``no'' saves a bit of disk space. | |
860 | ||
861 | Note that when both @code{--gc-keep-derivations} and | |
862 | @code{--gc-keep-outputs} are used, the effect is to keep all the build | |
863 | prerequisites (the sources, compiler, libraries, and other build-time | |
864 | tools) of live objects in the store, regardless of whether these | |
865 | prerequisites are live. This is convenient for developers since it | |
866 | saves rebuilds or downloads. | |
867 | ||
bd5e766b LC |
868 | @item --impersonate-linux-2.6 |
869 | On Linux-based systems, impersonate Linux 2.6. This means that the | |
870 | kernel's @code{uname} system call will report 2.6 as the release number. | |
871 | ||
872 | This might be helpful to build programs that (usually wrongfully) depend | |
873 | on the kernel version number. | |
874 | ||
875 | @item --lose-logs | |
876 | Do not keep build logs. By default they are kept under | |
ce33631f | 877 | @code{@var{localstatedir}/guix/log}. |
bd5e766b LC |
878 | |
879 | @item --system=@var{system} | |
880 | Assume @var{system} as the current system type. By default it is the | |
881 | architecture/kernel pair found at configure time, such as | |
882 | @code{x86_64-linux}. | |
b8d2aa26 LC |
883 | |
884 | @item --listen=@var{socket} | |
885 | Listen for connections on @var{socket}, the file name of a Unix-domain | |
886 | socket. The default socket is | |
887 | @file{@var{localstatedir}/daemon-socket/socket}. This option is only | |
888 | useful in exceptional circumstances, such as if you need to run several | |
889 | daemons on the same machine. | |
bd5e766b LC |
890 | @end table |
891 | ||
892 | ||
0e2d0213 LC |
893 | @node Application Setup |
894 | @section Application Setup | |
895 | ||
896 | When using Guix on top of GNU/Linux distribution other than GuixSD, a | |
897 | few additional steps are needed to get everything in place. Here are | |
898 | some of them. | |
899 | ||
900 | @subsection Locales | |
901 | ||
902 | @cindex locales, when not on GuixSD | |
903 | Packages installed @i{via} Guix will not use the host system's locale | |
904 | data. Instead, you must first install one of the locale packages | |
905 | available with Guix and then define the @code{LOCPATH} environment | |
906 | variable (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library | |
907 | Reference Manual}): | |
908 | ||
909 | @example | |
910 | $ guix package -i glibc-locales | |
911 | $ export LOCPATH=$HOME/.guix-profile/lib/locale | |
912 | @end example | |
913 | ||
914 | Note that the @code{glibc-locales} package contains data for all the | |
915 | locales supported by the GNU@tie{}libc and weighs in at around | |
916 | 110@tie{}MiB. Alternately, the @code{glibc-utf8-locales} is smaller but | |
917 | limited to a few UTF-8 locales. | |
918 | ||
919 | @subsection X11 Fonts | |
920 | ||
921 | The majority of graphical applications uses Fontconfig to locate and | |
922 | load fonts and perform X11-client-side rendering. Guix's | |
923 | @code{fontconfig} package looks for fonts in @file{$HOME/.guix-profile} | |
924 | by default. Thus, to allow graphical applications installed with Guix | |
925 | to display fonts, you will have to install fonts with Guix as well. | |
926 | Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and | |
927 | @code{font-gnu-freefont}. | |
928 | ||
929 | @c TODO What else? | |
930 | ||
eeaf4427 LC |
931 | @c ********************************************************************* |
932 | @node Package Management | |
933 | @chapter Package Management | |
934 | ||
f8348b91 | 935 | The purpose of GNU Guix is to allow users to easily install, upgrade, and |
eeaf4427 LC |
936 | remove software packages, without having to know about their build |
937 | procedure or dependencies. Guix also goes beyond this obvious set of | |
938 | features. | |
939 | ||
940 | This chapter describes the main features of Guix, as well as the package | |
c1941588 LC |
941 | management tools it provides. Two user interfaces are provided for |
942 | routine package management tasks: a command-line interface | |
943 | (@pxref{Invoking guix package, @code{guix package}}), and a visual user | |
944 | interface in Emacs (@pxref{Emacs Interface}). | |
eeaf4427 LC |
945 | |
946 | @menu | |
947 | * Features:: How Guix will make your life brighter. | |
e49951eb | 948 | * Invoking guix package:: Package installation, removal, etc. |
457f60fa | 949 | * Emacs Interface:: Package management from Emacs. |
c4202d60 | 950 | * Substitutes:: Downloading pre-built binaries. |
760c60d6 | 951 | * Packages with Multiple Outputs:: Single source package, multiple outputs. |
e49951eb | 952 | * Invoking guix gc:: Running the garbage collector. |
f651b477 | 953 | * Invoking guix pull:: Fetching the latest Guix and distribution. |
760c60d6 | 954 | * Invoking guix archive:: Exporting and importing store files. |
eeaf4427 LC |
955 | @end menu |
956 | ||
957 | @node Features | |
958 | @section Features | |
959 | ||
960 | When using Guix, each package ends up in the @dfn{package store}, in its | |
961 | own directory---something that resembles | |
9a130e19 AK |
962 | @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string |
963 | (note that Guix comes with an Emacs extension to shorten those file | |
081145cf | 964 | names, @pxref{Emacs Prettify}.) |
eeaf4427 LC |
965 | |
966 | Instead of referring to these directories, users have their own | |
967 | @dfn{profile}, which points to the packages that they actually want to | |
821b0015 LC |
968 | use. These profiles are stored within each user's home directory, at |
969 | @code{$HOME/.guix-profile}. | |
eeaf4427 | 970 | |
821b0015 | 971 | For example, @code{alice} installs GCC 4.7.2. As a result, |
eeaf4427 | 972 | @file{/home/alice/.guix-profile/bin/gcc} points to |
834129e0 | 973 | @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine, |
821b0015 LC |
974 | @code{bob} had already installed GCC 4.8.0. The profile of @code{bob} |
975 | simply continues to point to | |
834129e0 | 976 | @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC |
821b0015 | 977 | coexist on the same system without any interference. |
eeaf4427 | 978 | |
e49951eb MW |
979 | The @command{guix package} command is the central tool to manage |
980 | packages (@pxref{Invoking guix package}). It operates on those per-user | |
821b0015 | 981 | profiles, and can be used @emph{with normal user privileges}. |
eeaf4427 LC |
982 | |
983 | The command provides the obvious install, remove, and upgrade | |
984 | operations. Each invocation is actually a @emph{transaction}: either | |
ba55b1cb | 985 | the specified operation succeeds, or nothing happens. Thus, if the |
e49951eb | 986 | @command{guix package} process is terminated during the transaction, |
eeaf4427 LC |
987 | or if a power outage occurs during the transaction, then the user's |
988 | profile remains in its previous state, and remains usable. | |
989 | ||
990 | In addition, any package transaction may be @emph{rolled back}. So, if, | |
991 | for example, an upgrade installs a new version of a package that turns | |
992 | out to have a serious bug, users may roll back to the previous instance | |
4af2447e LC |
993 | of their profile, which was known to work well. Similarly, the global |
994 | system configuration is subject to transactional upgrades and roll-back | |
995 | (@pxref{Using the Configuration System}). | |
eeaf4427 LC |
996 | |
997 | All those packages in the package store may be @emph{garbage-collected}. | |
998 | Guix can determine which packages are still referenced by the user | |
fe8ff028 | 999 | profiles, and remove those that are provably no longer referenced |
e49951eb | 1000 | (@pxref{Invoking guix gc}). Users may also explicitly remove old |
fe8ff028 LC |
1001 | generations of their profile so that the packages they refer to can be |
1002 | collected. | |
eeaf4427 | 1003 | |
e900c503 LC |
1004 | @cindex reproducibility |
1005 | @cindex reproducible builds | |
eeaf4427 LC |
1006 | Finally, Guix takes a @dfn{purely functional} approach to package |
1007 | management, as described in the introduction (@pxref{Introduction}). | |
834129e0 | 1008 | Each @file{/gnu/store} package directory name contains a hash of all the |
eeaf4427 LC |
1009 | inputs that were used to build that package---compiler, libraries, build |
1010 | scripts, etc. This direct correspondence allows users to make sure a | |
1011 | given package installation matches the current state of their | |
e900c503 LC |
1012 | distribution. It also helps maximize @dfn{build reproducibility}: |
1013 | thanks to the isolated build environments that are used, a given build | |
1014 | is likely to yield bit-identical files when performed on different | |
1015 | machines (@pxref{Invoking guix-daemon, container}). | |
eeaf4427 | 1016 | |
c4202d60 | 1017 | @cindex substitutes |
eeaf4427 | 1018 | This foundation allows Guix to support @dfn{transparent binary/source |
c4202d60 | 1019 | deployment}. When a pre-built binary for a @file{/gnu/store} item is |
18f2887b | 1020 | available from an external source---a @dfn{substitute}, Guix just |
c4202d60 LC |
1021 | downloads it and unpacks it; |
1022 | otherwise, it builds the package from source, locally | |
1023 | (@pxref{Substitutes}). | |
eeaf4427 | 1024 | |
f5fd4fd2 LC |
1025 | Control over the build environment is a feature that is also useful for |
1026 | developers. The @command{guix environment} command allows developers of | |
1027 | a package to quickly set up the right development environment for their | |
1028 | package, without having to manually install the package's dependencies | |
1029 | in their profile (@pxref{Invoking guix environment}). | |
1030 | ||
e49951eb MW |
1031 | @node Invoking guix package |
1032 | @section Invoking @command{guix package} | |
eeaf4427 | 1033 | |
e49951eb | 1034 | The @command{guix package} command is the tool that allows users to |
eeaf4427 LC |
1035 | install, upgrade, and remove packages, as well as rolling back to |
1036 | previous configurations. It operates only on the user's own profile, | |
1037 | and works with normal user privileges (@pxref{Features}). Its syntax | |
1038 | is: | |
1039 | ||
1040 | @example | |
e49951eb | 1041 | guix package @var{options} |
eeaf4427 LC |
1042 | @end example |
1043 | ||
ba55b1cb | 1044 | Primarily, @var{options} specifies the operations to be performed during |
eeaf4427 | 1045 | the transaction. Upon completion, a new profile is created, but |
99bd74d5 | 1046 | previous @dfn{generations} of the profile remain available, should the user |
eeaf4427 LC |
1047 | want to roll back. |
1048 | ||
6447738c MW |
1049 | For example, to remove @code{lua} and install @code{guile} and |
1050 | @code{guile-cairo} in a single transaction: | |
1051 | ||
1052 | @example | |
1053 | guix package -r lua -i guile guile-cairo | |
1054 | @end example | |
1055 | ||
99bd74d5 LC |
1056 | @command{guix package} also supports a @dfn{declarative approach} |
1057 | whereby the user specifies the exact set of packages to be available and | |
1058 | passes it @i{via} the @option{--manifest} option | |
1059 | (@pxref{profile-manifest, @option{--manifest}}). | |
1060 | ||
b9e5c0a9 | 1061 | For each user, a symlink to the user's default profile is automatically |
0ec1af59 | 1062 | created in @file{$HOME/.guix-profile}. This symlink always points to the |
b9e5c0a9 LC |
1063 | current generation of the user's default profile. Thus, users can add |
1064 | @file{$HOME/.guix-profile/bin} to their @code{PATH} environment | |
1065 | variable, and so on. | |
d664f1b4 LC |
1066 | @cindex search paths |
1067 | If you are not using the Guix System Distribution, consider adding the | |
1068 | following lines to your @file{~/.bash_profile} (@pxref{Bash Startup | |
1069 | Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned | |
1070 | shells get all the right environment variable definitions: | |
1071 | ||
1072 | @example | |
1073 | GUIX_PROFILE="$HOME/.guix-profile" \ | |
1074 | source "$HOME/.guix-profile/etc/profile" | |
1075 | @end example | |
b9e5c0a9 | 1076 | |
4379c35b LC |
1077 | In a multi-user setup, user profiles are stored in a place registered as |
1078 | a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points | |
1079 | to (@pxref{Invoking guix gc}). That directory is normally | |
0ec1af59 LC |
1080 | @code{@var{localstatedir}/profiles/per-user/@var{user}}, where |
1081 | @var{localstatedir} is the value passed to @code{configure} as | |
4379c35b LC |
1082 | @code{--localstatedir}, and @var{user} is the user name. The |
1083 | @file{per-user} directory is created when @command{guix-daemon} is | |
1084 | started, and the @var{user} sub-directory is created by @command{guix | |
1085 | package}. | |
0ec1af59 LC |
1086 | |
1087 | The @var{options} can be among the following: | |
1088 | ||
eeaf4427 LC |
1089 | @table @code |
1090 | ||
6447738c MW |
1091 | @item --install=@var{package} @dots{} |
1092 | @itemx -i @var{package} @dots{} | |
1093 | Install the specified @var{package}s. | |
eeaf4427 | 1094 | |
6447738c | 1095 | Each @var{package} may specify either a simple package name, such as |
eeaf4427 | 1096 | @code{guile}, or a package name followed by a hyphen and version number, |
724311a2 LC |
1097 | such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter |
1098 | case, the newest version prefixed by @code{1.8} is selected.) | |
1099 | ||
1100 | If no version number is specified, the | |
dc5669cd MW |
1101 | newest available version will be selected. In addition, @var{package} |
1102 | may contain a colon, followed by the name of one of the outputs of the | |
6e721c4d | 1103 | package, as in @code{gcc:doc} or @code{binutils-2.22:lib} |
e7f34eb0 LC |
1104 | (@pxref{Packages with Multiple Outputs}). Packages with a corresponding |
1105 | name (and optionally version) are searched for among the GNU | |
1106 | distribution modules (@pxref{Package Modules}). | |
eeaf4427 | 1107 | |
461572cc LC |
1108 | @cindex propagated inputs |
1109 | Sometimes packages have @dfn{propagated inputs}: these are dependencies | |
21461f27 LC |
1110 | that automatically get installed along with the required package |
1111 | (@pxref{package-propagated-inputs, @code{propagated-inputs} in | |
1112 | @code{package} objects}, for information about propagated inputs in | |
1113 | package definitions). | |
461572cc | 1114 | |
21461f27 | 1115 | @anchor{package-cmd-propagated-inputs} |
461572cc LC |
1116 | An example is the GNU MPC library: its C header files refer to those of |
1117 | the GNU MPFR library, which in turn refer to those of the GMP library. | |
1118 | Thus, when installing MPC, the MPFR and GMP libraries also get installed | |
1119 | in the profile; removing MPC also removes MPFR and GMP---unless they had | |
1120 | also been explicitly installed independently. | |
1121 | ||
ba7ea5ce | 1122 | Besides, packages sometimes rely on the definition of environment |
5924080d | 1123 | variables for their search paths (see explanation of |
ba7ea5ce | 1124 | @code{--search-paths} below). Any missing or possibly incorrect |
5924080d LC |
1125 | environment variable definitions are reported here. |
1126 | ||
ef010c0f | 1127 | @c XXX: keep me up-to-date |
5924080d | 1128 | Finally, when installing a GNU package, the tool reports the |
ef010c0f LC |
1129 | availability of a newer upstream version. In the future, it may provide |
1130 | the option of installing directly from the upstream version, even if | |
1131 | that version is not yet in the distribution. | |
1132 | ||
5d4b411f LC |
1133 | @item --install-from-expression=@var{exp} |
1134 | @itemx -e @var{exp} | |
1135 | Install the package @var{exp} evaluates to. | |
1136 | ||
1137 | @var{exp} must be a Scheme expression that evaluates to a | |
1138 | @code{<package>} object. This option is notably useful to disambiguate | |
1139 | between same-named variants of a package, with expressions such as | |
1140 | @code{(@@ (gnu packages base) guile-final)}. | |
1141 | ||
1142 | Note that this option installs the first output of the specified | |
1143 | package, which may be insufficient when needing a specific output of a | |
1144 | multiple-output package. | |
1145 | ||
6447738c MW |
1146 | @item --remove=@var{package} @dots{} |
1147 | @itemx -r @var{package} @dots{} | |
1148 | Remove the specified @var{package}s. | |
eeaf4427 | 1149 | |
6447738c | 1150 | As for @code{--install}, each @var{package} may specify a version number |
13ed095c LC |
1151 | and/or output name in addition to the package name. For instance, |
1152 | @code{-r glibc:debug} would remove the @code{debug} output of | |
1153 | @code{glibc}. | |
1154 | ||
6447738c MW |
1155 | @item --upgrade[=@var{regexp} @dots{}] |
1156 | @itemx -u [@var{regexp} @dots{}] | |
1157 | Upgrade all the installed packages. If one or more @var{regexp}s are | |
1158 | specified, upgrade only installed packages whose name matches a | |
d5f01e48 | 1159 | @var{regexp}. Also see the @code{--do-not-upgrade} option below. |
eeaf4427 | 1160 | |
f651b477 LC |
1161 | Note that this upgrades package to the latest version of packages found |
1162 | in the distribution currently installed. To update your distribution, | |
1163 | you should regularly run @command{guix pull} (@pxref{Invoking guix | |
1164 | pull}). | |
1165 | ||
d5f01e48 MW |
1166 | @item --do-not-upgrade[=@var{regexp} @dots{}] |
1167 | When used together with the @code{--upgrade} option, do @emph{not} | |
1168 | upgrade any packages whose name matches a @var{regexp}. For example, to | |
1169 | upgrade all packages in the current profile except those containing the | |
1170 | substring ``emacs'': | |
1171 | ||
1172 | @example | |
1173 | $ guix package --upgrade . --do-not-upgrade emacs | |
1174 | @end example | |
1175 | ||
99bd74d5 | 1176 | @item @anchor{profile-manifest}--manifest=@var{file} |
1b676447 | 1177 | @itemx -m @var{file} |
99bd74d5 LC |
1178 | @cindex profile declaration |
1179 | @cindex profile manifest | |
1180 | Create a new generation of the profile from the manifest object | |
1b676447 DT |
1181 | returned by the Scheme code in @var{file}. |
1182 | ||
99bd74d5 LC |
1183 | This allows you to @emph{declare} the profile's contents rather than |
1184 | constructing it through a sequence of @code{--install} and similar | |
1185 | commands. The advantage is that @var{file} can be put under version | |
1186 | control, copied to different machines to reproduce the same profile, and | |
1187 | so on. | |
1188 | ||
1189 | @c FIXME: Add reference to (guix profile) documentation when available. | |
1190 | @var{file} must return a @dfn{manifest} object, which is roughly a list | |
1191 | of packages: | |
1b676447 | 1192 | |
99bd74d5 | 1193 | @findex packages->manifest |
1b676447 | 1194 | @example |
99bd74d5 | 1195 | (use-package-modules guile emacs) |
1b676447 DT |
1196 | |
1197 | (packages->manifest | |
99bd74d5 LC |
1198 | (list emacs |
1199 | guile-2.0 | |
1b676447 | 1200 | ;; Use a specific package output. |
99bd74d5 | 1201 | (list guile-2.0 "debug"))) |
1b676447 DT |
1202 | @end example |
1203 | ||
24e262f0 LC |
1204 | @item --roll-back |
1205 | Roll back to the previous @dfn{generation} of the profile---i.e., undo | |
1206 | the last transaction. | |
1207 | ||
1208 | When combined with options such as @code{--install}, roll back occurs | |
1209 | before any other actions. | |
1210 | ||
d9307267 | 1211 | When rolling back from the first generation that actually contains |
4b2bc804 NK |
1212 | installed packages, the profile is made to point to the @dfn{zeroth |
1213 | generation}, which contains no files apart from its own meta-data. | |
d9307267 | 1214 | |
82fe08ed LC |
1215 | Installing, removing, or upgrading packages from a generation that has |
1216 | been rolled back to overwrites previous future generations. Thus, the | |
1217 | history of a profile's generations is always linear. | |
1218 | ||
b3bb82f1 AK |
1219 | @item --switch-generation=@var{pattern} |
1220 | @itemx -S @var{pattern} | |
1221 | Switch to a particular generation defined by @var{pattern}. | |
1222 | ||
1223 | @var{pattern} may be either a generation number or a number prefixed | |
1224 | with ``+'' or ``-''. The latter means: move forward/backward by a | |
1225 | specified number of generations. For example, if you want to return to | |
1226 | the latest generation after @code{--roll-back}, use | |
1227 | @code{--switch-generation=+1}. | |
1228 | ||
1229 | The difference between @code{--roll-back} and | |
1230 | @code{--switch-generation=-1} is that @code{--switch-generation} will | |
1231 | not make a zeroth generation, so if a specified generation does not | |
1232 | exist, the current generation will not be changed. | |
1233 | ||
dbc31ab2 | 1234 | @item --search-paths[=@var{kind}] |
5924080d LC |
1235 | @cindex search paths |
1236 | Report environment variable definitions, in Bash syntax, that may be | |
1237 | needed in order to use the set of installed packages. These environment | |
1238 | variables are used to specify @dfn{search paths} for files used by some | |
1239 | of the installed packages. | |
1240 | ||
1241 | For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH} | |
1242 | environment variables to be defined so it can look for headers and | |
1243 | libraries in the user's profile (@pxref{Environment Variables,,, gcc, | |
1244 | Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C | |
1245 | library are installed in the profile, then @code{--search-paths} will | |
1246 | suggest setting these variables to @code{@var{profile}/include} and | |
1247 | @code{@var{profile}/lib}, respectively. | |
1248 | ||
dbc31ab2 LC |
1249 | The typical use case is to define these environment variables in the |
1250 | shell: | |
1251 | ||
1252 | @example | |
1253 | $ eval `guix package --search-paths` | |
1254 | @end example | |
1255 | ||
1256 | @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix}, | |
1257 | meaning that the returned environment variable definitions will either | |
1258 | be exact settings, or prefixes or suffixes of the current value of these | |
1259 | variables. When omitted, @var{kind} defaults to @code{exact}. | |
1260 | ||
eeaf4427 LC |
1261 | @item --profile=@var{profile} |
1262 | @itemx -p @var{profile} | |
1263 | Use @var{profile} instead of the user's default profile. | |
1264 | ||
70915c1a LC |
1265 | @item --verbose |
1266 | Produce verbose output. In particular, emit the environment's build log | |
1267 | on the standard error port. | |
1268 | ||
eeaf4427 LC |
1269 | @item --bootstrap |
1270 | Use the bootstrap Guile to build the profile. This option is only | |
1271 | useful to distribution developers. | |
1272 | ||
1273 | @end table | |
1274 | ||
e49951eb | 1275 | In addition to these actions @command{guix package} supports the |
733b4130 LC |
1276 | following options to query the current state of a profile, or the |
1277 | availability of packages: | |
eeaf4427 | 1278 | |
733b4130 LC |
1279 | @table @option |
1280 | ||
acc08466 NK |
1281 | @item --search=@var{regexp} |
1282 | @itemx -s @var{regexp} | |
5763ad92 | 1283 | List the available packages whose name, synopsis, or description matches |
299112d3 LC |
1284 | @var{regexp}. Print all the meta-data of matching packages in |
1285 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, | |
1286 | GNU recutils manual}). | |
acc08466 | 1287 | |
299112d3 LC |
1288 | This allows specific fields to be extracted using the @command{recsel} |
1289 | command, for instance: | |
1290 | ||
1291 | @example | |
e49951eb | 1292 | $ guix package -s malloc | recsel -p name,version |
299112d3 LC |
1293 | name: glibc |
1294 | version: 2.17 | |
1295 | ||
1296 | name: libgc | |
1297 | version: 7.2alpha6 | |
1298 | @end example | |
acc08466 | 1299 | |
a12d92f5 LC |
1300 | Similarly, to show the name of all the packages available under the |
1301 | terms of the GNU@tie{}LGPL version 3: | |
1302 | ||
1303 | @example | |
1304 | $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"' | |
1305 | name: elfutils | |
1306 | ||
1307 | name: gmp | |
1308 | @dots{} | |
1309 | @end example | |
1310 | ||
2aa6efb0 CR |
1311 | @item --show=@var{package} |
1312 | Show details about @var{package}, taken from the list of available packages, in | |
1313 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU | |
1314 | recutils manual}). | |
1315 | ||
1316 | @example | |
1317 | $ guix package --show=python | recsel -p name,version | |
1318 | name: python | |
1319 | version: 2.7.6 | |
1320 | ||
1321 | name: python | |
1322 | version: 3.3.5 | |
1323 | @end example | |
1324 | ||
1325 | You may also specify the full name of a package to only get details about a | |
1326 | specific version of it: | |
1327 | @example | |
1328 | $ guix package --show=python-3.3.5 | recsel -p name,version | |
1329 | name: python | |
1330 | version: 3.3.5 | |
1331 | @end example | |
1332 | ||
1333 | ||
1334 | ||
733b4130 LC |
1335 | @item --list-installed[=@var{regexp}] |
1336 | @itemx -I [@var{regexp}] | |
bd9bde1c LC |
1337 | List the currently installed packages in the specified profile, with the |
1338 | most recently installed packages shown last. When @var{regexp} is | |
1339 | specified, list only installed packages whose name matches @var{regexp}. | |
733b4130 LC |
1340 | |
1341 | For each installed package, print the following items, separated by | |
1342 | tabs: the package name, its version string, the part of the package that | |
1343 | is installed (for instance, @code{out} for the default output, | |
1344 | @code{include} for its headers, etc.), and the path of this package in | |
1345 | the store. | |
1346 | ||
64fc89b6 LC |
1347 | @item --list-available[=@var{regexp}] |
1348 | @itemx -A [@var{regexp}] | |
5763ad92 | 1349 | List packages currently available in the distribution for this system |
a1ba8475 LC |
1350 | (@pxref{GNU Distribution}). When @var{regexp} is specified, list only |
1351 | installed packages whose name matches @var{regexp}. | |
64fc89b6 LC |
1352 | |
1353 | For each package, print the following items separated by tabs: its name, | |
6e721c4d LC |
1354 | its version string, the parts of the package (@pxref{Packages with |
1355 | Multiple Outputs}), and the source location of its definition. | |
64fc89b6 | 1356 | |
f566d765 LC |
1357 | @item --list-generations[=@var{pattern}] |
1358 | @itemx -l [@var{pattern}] | |
1359 | Return a list of generations along with their creation dates; for each | |
1360 | generation, show the installed packages, with the most recently | |
4b2bc804 NK |
1361 | installed packages shown last. Note that the zeroth generation is never |
1362 | shown. | |
f566d765 LC |
1363 | |
1364 | For each installed package, print the following items, separated by | |
1365 | tabs: the name of a package, its version string, the part of the package | |
1366 | that is installed (@pxref{Packages with Multiple Outputs}), and the | |
1367 | location of this package in the store. | |
1368 | ||
1369 | When @var{pattern} is used, the command returns only matching | |
1370 | generations. Valid patterns include: | |
1371 | ||
1372 | @itemize | |
1373 | @item @emph{Integers and comma-separated integers}. Both patterns denote | |
1374 | generation numbers. For instance, @code{--list-generations=1} returns | |
1375 | the first one. | |
1376 | ||
1377 | And @code{--list-generations=1,8,2} outputs three generations in the | |
1378 | specified order. Neither spaces nor trailing commas are allowed. | |
1379 | ||
1380 | @item @emph{Ranges}. @code{--list-generations=2..9} prints the | |
1381 | specified generations and everything in between. Note that the start of | |
1382 | a range must be lesser than its end. | |
1383 | ||
1384 | It is also possible to omit the endpoint. For example, | |
1385 | @code{--list-generations=2..}, returns all generations starting from the | |
1386 | second one. | |
1387 | ||
1388 | @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks, | |
1389 | or months by passing an integer along with the first letter of the | |
d7ddb257 LC |
1390 | duration. For example, @code{--list-generations=20d} lists generations |
1391 | that are up to 20 days old. | |
f566d765 LC |
1392 | @end itemize |
1393 | ||
b7884ca3 NK |
1394 | @item --delete-generations[=@var{pattern}] |
1395 | @itemx -d [@var{pattern}] | |
d7ddb257 LC |
1396 | When @var{pattern} is omitted, delete all generations except the current |
1397 | one. | |
b7884ca3 NK |
1398 | |
1399 | This command accepts the same patterns as @option{--list-generations}. | |
d7ddb257 LC |
1400 | When @var{pattern} is specified, delete the matching generations. When |
1401 | @var{pattern} specifies a duration, generations @emph{older} than the | |
1402 | specified duration match. For instance, @code{--delete-generations=1m} | |
1403 | deletes generations that are more than one month old. | |
1404 | ||
391bdd8f LC |
1405 | If the current generation matches, it is @emph{not} deleted. Also, the |
1406 | zeroth generation is never deleted. | |
b7884ca3 | 1407 | |
1bb9900a LC |
1408 | Note that deleting generations prevents roll-back to them. |
1409 | Consequently, this command must be used with care. | |
1410 | ||
733b4130 | 1411 | @end table |
eeaf4427 | 1412 | |
70ee5642 LC |
1413 | Finally, since @command{guix package} may actually start build |
1414 | processes, it supports all the common build options that @command{guix | |
1415 | build} supports (@pxref{Invoking guix build, common build options}). | |
1416 | ||
457f60fa AK |
1417 | @include emacs.texi |
1418 | ||
c4202d60 LC |
1419 | @node Substitutes |
1420 | @section Substitutes | |
1421 | ||
1422 | @cindex substitutes | |
1423 | @cindex pre-built binaries | |
1424 | Guix supports transparent source/binary deployment, which means that it | |
1425 | can either build things locally, or download pre-built items from a | |
1426 | server. We call these pre-built items @dfn{substitutes}---they are | |
1427 | substitutes for local build results. In many cases, downloading a | |
1428 | substitute is much faster than building things locally. | |
1429 | ||
1430 | Substitutes can be anything resulting from a derivation build | |
1431 | (@pxref{Derivations}). Of course, in the common case, they are | |
1432 | pre-built package binaries, but source tarballs, for instance, which | |
1433 | also result from derivation builds, can be available as substitutes. | |
1434 | ||
1435 | The @code{hydra.gnu.org} server is a front-end to a build farm that | |
1436 | builds packages from the GNU distribution continuously for some | |
9176607e | 1437 | architectures, and makes them available as substitutes. This is the |
f8a8e0fe LC |
1438 | default source of substitutes; it can be overridden by passing the |
1439 | @option{--substitute-urls} option either to @command{guix-daemon} | |
1440 | (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}}) | |
1441 | or to client tools such as @command{guix package} | |
1442 | (@pxref{client-substitute-urls,, client @option{--substitute-urls} | |
1443 | option}). | |
c4202d60 LC |
1444 | |
1445 | @cindex security | |
1446 | @cindex digital signatures | |
1447 | To allow Guix to download substitutes from @code{hydra.gnu.org}, you | |
1448 | must add its public key to the access control list (ACL) of archive | |
1449 | imports, using the @command{guix archive} command (@pxref{Invoking guix | |
1450 | archive}). Doing so implies that you trust @code{hydra.gnu.org} to not | |
1451 | be compromised and to serve genuine substitutes. | |
1452 | ||
1453 | This public key is installed along with Guix, in | |
1454 | @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is | |
1455 | the installation prefix of Guix. If you installed Guix from source, | |
1456 | make sure you checked the GPG signature of | |
1457 | @file{guix-@value{VERSION}.tar.gz}, which contains this public key file. | |
1458 | Then, you can run something like this: | |
1459 | ||
1460 | @example | |
1461 | # guix archive --authorize < hydra.gnu.org.pub | |
1462 | @end example | |
1463 | ||
1464 | Once this is in place, the output of a command like @code{guix build} | |
1465 | should change from something like: | |
1466 | ||
1467 | @example | |
1468 | $ guix build emacs --dry-run | |
1469 | The following derivations would be built: | |
1470 | /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv | |
1471 | /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv | |
1472 | /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv | |
1473 | /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv | |
1474 | @dots{} | |
1475 | @end example | |
1476 | ||
1477 | @noindent | |
1478 | to something like: | |
1479 | ||
1480 | @example | |
1481 | $ guix build emacs --dry-run | |
1482 | The following files would be downloaded: | |
1483 | /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3 | |
1484 | /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d | |
1485 | /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16 | |
1486 | /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7 | |
1487 | @dots{} | |
1488 | @end example | |
1489 | ||
1490 | @noindent | |
1491 | This indicates that substitutes from @code{hydra.gnu.org} are usable and | |
1492 | will be downloaded, when possible, for future builds. | |
1493 | ||
1494 | Guix ignores substitutes that are not signed, or that are not signed by | |
ef27aa9c | 1495 | one of the keys listed in the ACL. It also detects and raises an error |
c4202d60 LC |
1496 | when attempting to use a substitute that has been tampered with. |
1497 | ||
1498 | The substitute mechanism can be disabled globally by running | |
1499 | @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking | |
1500 | guix-daemon}). It can also be disabled temporarily by passing the | |
1501 | @code{--no-substitutes} option to @command{guix package}, @command{guix | |
1502 | build}, and other command-line tools. | |
1503 | ||
1504 | ||
1505 | Today, each individual's control over their own computing is at the | |
1506 | mercy of institutions, corporations, and groups with enough power and | |
1507 | determination to subvert the computing infrastructure and exploit its | |
1508 | weaknesses. While using @code{hydra.gnu.org} substitutes can be | |
1509 | convenient, we encourage users to also build on their own, or even run | |
1510 | their own build farm, such that @code{hydra.gnu.org} is less of an | |
8ce229fc LC |
1511 | interesting target. One way to help is by publishing the software you |
1512 | build using @command{guix publish} so that others have one more choice | |
1513 | of server to download substitutes from (@pxref{Invoking guix publish}). | |
c4202d60 LC |
1514 | |
1515 | Guix has the foundations to maximize build reproducibility | |
1516 | (@pxref{Features}). In most cases, independent builds of a given | |
1517 | package or derivation should yield bit-identical results. Thus, through | |
1518 | a diverse set of independent package builds, we can strengthen the | |
1519 | integrity of our systems. | |
1520 | ||
1521 | In the future, we want Guix to have support to publish and retrieve | |
1522 | binaries to/from other users, in a peer-to-peer fashion. If you would | |
1523 | like to discuss this project, join us on @email{guix-devel@@gnu.org}. | |
1524 | ||
1525 | ||
6e721c4d LC |
1526 | @node Packages with Multiple Outputs |
1527 | @section Packages with Multiple Outputs | |
1528 | ||
1529 | @cindex multiple-output packages | |
1530 | @cindex package outputs | |
1531 | ||
1532 | Often, packages defined in Guix have a single @dfn{output}---i.e., the | |
1533 | source package leads exactly one directory in the store. When running | |
1534 | @command{guix package -i glibc}, one installs the default output of the | |
1535 | GNU libc package; the default output is called @code{out}, but its name | |
1536 | can be omitted as shown in this command. In this particular case, the | |
1537 | default output of @code{glibc} contains all the C header files, shared | |
1538 | libraries, static libraries, Info documentation, and other supporting | |
1539 | files. | |
1540 | ||
1541 | Sometimes it is more appropriate to separate the various types of files | |
1542 | produced from a single source package into separate outputs. For | |
1543 | instance, the GLib C library (used by GTK+ and related packages) | |
1544 | installs more than 20 MiB of reference documentation as HTML pages. | |
1545 | To save space for users who do not need it, the documentation goes to a | |
1546 | separate output, called @code{doc}. To install the main GLib output, | |
1547 | which contains everything but the documentation, one would run: | |
1548 | ||
1549 | @example | |
1550 | guix package -i glib | |
1551 | @end example | |
1552 | ||
1553 | The command to install its documentation is: | |
1554 | ||
1555 | @example | |
1556 | guix package -i glib:doc | |
1557 | @end example | |
1558 | ||
1559 | Some packages install programs with different ``dependency footprints''. | |
1560 | For instance, the WordNet package install both command-line tools and | |
1561 | graphical user interfaces (GUIs). The former depend solely on the C | |
1562 | library, whereas the latter depend on Tcl/Tk and the underlying X | |
1563 | libraries. In this case, we leave the command-line tools in the default | |
1564 | output, whereas the GUIs are in a separate output. This allows users | |
fcc58db6 LC |
1565 | who do not need the GUIs to save space. The @command{guix size} command |
1566 | can help find out about such situations (@pxref{Invoking guix size}). | |
6e721c4d LC |
1567 | |
1568 | There are several such multiple-output packages in the GNU distribution. | |
91ef73d4 LC |
1569 | Other conventional output names include @code{lib} for libraries and |
1570 | possibly header files, @code{bin} for stand-alone programs, and | |
1571 | @code{debug} for debugging information (@pxref{Installing Debugging | |
1572 | Files}). The outputs of a packages are listed in the third column of | |
1573 | the output of @command{guix package --list-available} (@pxref{Invoking | |
1574 | guix package}). | |
6e721c4d | 1575 | |
eeaf4427 | 1576 | |
e49951eb MW |
1577 | @node Invoking guix gc |
1578 | @section Invoking @command{guix gc} | |
fe8ff028 LC |
1579 | |
1580 | @cindex garbage collector | |
1581 | Packages that are installed but not used may be @dfn{garbage-collected}. | |
e49951eb | 1582 | The @command{guix gc} command allows users to explicitly run the garbage |
c22eb992 LC |
1583 | collector to reclaim space from the @file{/gnu/store} directory. It is |
1584 | the @emph{only} way to remove files from @file{/gnu/store}---removing | |
1585 | files or directories manually may break it beyond repair! | |
fe8ff028 LC |
1586 | |
1587 | The garbage collector has a set of known @dfn{roots}: any file under | |
834129e0 | 1588 | @file{/gnu/store} reachable from a root is considered @dfn{live} and |
fe8ff028 LC |
1589 | cannot be deleted; any other file is considered @dfn{dead} and may be |
1590 | deleted. The set of garbage collector roots includes default user | |
e49951eb MW |
1591 | profiles, and may be augmented with @command{guix build --root}, for |
1592 | example (@pxref{Invoking guix build}). | |
fe8ff028 | 1593 | |
1bb9900a LC |
1594 | Prior to running @code{guix gc --collect-garbage} to make space, it is |
1595 | often useful to remove old generations from user profiles; that way, old | |
1596 | package builds referenced by those generations can be reclaimed. This | |
1597 | is achieved by running @code{guix package --delete-generations} | |
1598 | (@pxref{Invoking guix package}). | |
1599 | ||
e49951eb | 1600 | The @command{guix gc} command has three modes of operation: it can be |
fe8ff028 | 1601 | used to garbage-collect any dead files (the default), to delete specific |
7770aafc LC |
1602 | files (the @code{--delete} option), to print garbage-collector |
1603 | information, or for more advanced queries. The garbage collection | |
1604 | options are as follows: | |
fe8ff028 LC |
1605 | |
1606 | @table @code | |
1607 | @item --collect-garbage[=@var{min}] | |
1608 | @itemx -C [@var{min}] | |
834129e0 | 1609 | Collect garbage---i.e., unreachable @file{/gnu/store} files and |
fe8ff028 LC |
1610 | sub-directories. This is the default operation when no option is |
1611 | specified. | |
1612 | ||
1613 | When @var{min} is given, stop once @var{min} bytes have been collected. | |
1614 | @var{min} may be a number of bytes, or it may include a unit as a | |
4a44d7bb LC |
1615 | suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes |
1616 | (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}). | |
fe8ff028 LC |
1617 | |
1618 | When @var{min} is omitted, collect all the garbage. | |
1619 | ||
1620 | @item --delete | |
1621 | @itemx -d | |
1622 | Attempt to delete all the store files and directories specified as | |
1623 | arguments. This fails if some of the files are not in the store, or if | |
1624 | they are still live. | |
1625 | ||
1626 | @item --list-dead | |
1627 | Show the list of dead files and directories still present in the | |
1628 | store---i.e., files and directories no longer reachable from any root. | |
1629 | ||
1630 | @item --list-live | |
1631 | Show the list of live store files and directories. | |
ba8b732d LC |
1632 | |
1633 | @end table | |
1634 | ||
1635 | In addition, the references among existing store files can be queried: | |
1636 | ||
1637 | @table @code | |
1638 | ||
1639 | @item --references | |
1640 | @itemx --referrers | |
1641 | List the references (respectively, the referrers) of store files given | |
1642 | as arguments. | |
1643 | ||
8e59fdd5 LC |
1644 | @item --requisites |
1645 | @itemx -R | |
fcc58db6 | 1646 | @cindex closure |
8e59fdd5 LC |
1647 | List the requisites of the store files passed as arguments. Requisites |
1648 | include the store files themselves, their references, and the references | |
1649 | of these, recursively. In other words, the returned list is the | |
1650 | @dfn{transitive closure} of the store files. | |
1651 | ||
fcc58db6 LC |
1652 | @xref{Invoking guix size}, for a tool to profile the size of an |
1653 | element's closure. | |
1654 | ||
fe8ff028 LC |
1655 | @end table |
1656 | ||
7770aafc LC |
1657 | Lastly, the following options allow you to check the integrity of the |
1658 | store and to control disk usage. | |
1659 | ||
1660 | @table @option | |
1661 | ||
1662 | @item --verify[=@var{options}] | |
1663 | @cindex integrity, of the store | |
1664 | @cindex integrity checking | |
1665 | Verify the integrity of the store. | |
1666 | ||
1667 | By default, make sure that all the store items marked as valid in the | |
1668 | daemon's database actually exist in @file{/gnu/store}. | |
1669 | ||
1670 | When provided, @var{options} must a comma-separated list containing one | |
1671 | or more of @code{contents} and @code{repair}. | |
1672 | ||
1673 | When passing @option{--verify=contents}, the daemon will compute the | |
1674 | content hash of each store item and compare it against its hash in the | |
1675 | database. Hash mismatches are reported as data corruptions. Because it | |
1676 | traverses @emph{all the files in the store}, this command can take a | |
1677 | long time, especially on systems with a slow disk drive. | |
1678 | ||
1679 | @cindex repairing the store | |
1680 | Using @option{--verify=repair} or @option{--verify=contents,repair} | |
1681 | causes the daemon to try to repair corrupt store items by fetching | |
1682 | substitutes for them (@pxref{Substitutes}). Because repairing is not | |
1683 | atomic, and thus potentially dangerous, it is available only to the | |
1684 | system administrator. | |
1685 | ||
1686 | @item --optimize | |
1687 | @cindex deduplication | |
1688 | Optimize the store by hard-linking identical files---this is | |
1689 | @dfn{deduplication}. | |
1690 | ||
1691 | The daemon performs deduplication after each successful build or archive | |
1692 | import, unless it was started with @code{--disable-deduplication} | |
1693 | (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus, | |
1694 | this option is primarily useful when the daemon was running with | |
1695 | @code{--disable-deduplication}. | |
1696 | ||
1697 | @end table | |
eeaf4427 | 1698 | |
f651b477 LC |
1699 | @node Invoking guix pull |
1700 | @section Invoking @command{guix pull} | |
1701 | ||
1702 | Packages are installed or upgraded to the latest version available in | |
1703 | the distribution currently available on your local machine. To update | |
1704 | that distribution, along with the Guix tools, you must run @command{guix | |
1705 | pull}: the command downloads the latest Guix source code and package | |
1706 | descriptions, and deploys it. | |
1707 | ||
1708 | On completion, @command{guix package} will use packages and package | |
1709 | versions from this just-retrieved copy of Guix. Not only that, but all | |
1710 | the Guix commands and Scheme modules will also be taken from that latest | |
1711 | version. New @command{guix} sub-commands added by the update also | |
1712 | become available. | |
1713 | ||
1714 | The @command{guix pull} command is usually invoked with no arguments, | |
1715 | but it supports the following options: | |
1716 | ||
1717 | @table @code | |
1718 | @item --verbose | |
1719 | Produce verbose output, writing build logs to the standard error output. | |
1720 | ||
ab5d72ad LC |
1721 | @item --url=@var{url} |
1722 | Download the source tarball of Guix from @var{url}. | |
1723 | ||
1724 | By default, the tarball is taken from its canonical address at | |
1725 | @code{gnu.org}, for the stable branch of Guix. | |
1726 | ||
f651b477 LC |
1727 | @item --bootstrap |
1728 | Use the bootstrap Guile to build the latest Guix. This option is only | |
1729 | useful to Guix developers. | |
1730 | @end table | |
1731 | ||
760c60d6 LC |
1732 | |
1733 | @node Invoking guix archive | |
1734 | @section Invoking @command{guix archive} | |
1735 | ||
1736 | The @command{guix archive} command allows users to @dfn{export} files | |
1737 | from the store into a single archive, and to later @dfn{import} them. | |
1738 | In particular, it allows store files to be transferred from one machine | |
1739 | to another machine's store. For example, to transfer the @code{emacs} | |
1740 | package to a machine connected over SSH, one would run: | |
1741 | ||
1742 | @example | |
56607088 | 1743 | guix archive --export -r emacs | ssh the-machine guix archive --import |
760c60d6 LC |
1744 | @end example |
1745 | ||
87236aed | 1746 | @noindent |
56607088 LC |
1747 | Similarly, a complete user profile may be transferred from one machine |
1748 | to another like this: | |
1749 | ||
1750 | @example | |
1751 | guix archive --export -r $(readlink -f ~/.guix-profile) | \ | |
1752 | ssh the-machine guix-archive --import | |
1753 | @end example | |
1754 | ||
1755 | @noindent | |
1756 | However, note that, in both examples, all of @code{emacs} and the | |
1757 | profile as well as all of their dependencies are transferred (due to | |
1758 | @code{-r}), regardless of what is already available in the target | |
1759 | machine's store. The @code{--missing} option can help figure out which | |
1760 | items are missing from the target's store. | |
87236aed | 1761 | |
760c60d6 | 1762 | Archives are stored in the ``Nix archive'' or ``Nar'' format, which is |
0dbd88db LC |
1763 | comparable in spirit to `tar', but with a few noteworthy differences |
1764 | that make it more appropriate for our purposes. First, rather than | |
1765 | recording all Unix meta-data for each file, the Nar format only mentions | |
1766 | the file type (regular, directory, or symbolic link); Unix permissions | |
1767 | and owner/group are dismissed. Second, the order in which directory | |
1768 | entries are stored always follows the order of file names according to | |
1769 | the C locale collation order. This makes archive production fully | |
1770 | deterministic. | |
1771 | ||
1772 | When exporting, the daemon digitally signs the contents of the archive, | |
1773 | and that digital signature is appended. When importing, the daemon | |
1774 | verifies the signature and rejects the import in case of an invalid | |
1775 | signature or if the signing key is not authorized. | |
760c60d6 LC |
1776 | @c FIXME: Add xref to daemon doc about signatures. |
1777 | ||
1778 | The main options are: | |
1779 | ||
1780 | @table @code | |
1781 | @item --export | |
1782 | Export the specified store files or packages (see below.) Write the | |
1783 | resulting archive to the standard output. | |
1784 | ||
56607088 LC |
1785 | Dependencies are @emph{not} included in the output, unless |
1786 | @code{--recursive} is passed. | |
1787 | ||
1788 | @item -r | |
1789 | @itemx --recursive | |
1790 | When combined with @code{--export}, this instructs @command{guix | |
1791 | archive} to include dependencies of the given items in the archive. | |
1792 | Thus, the resulting archive is self-contained: it contains the closure | |
1793 | of the exported store items. | |
1794 | ||
760c60d6 LC |
1795 | @item --import |
1796 | Read an archive from the standard input, and import the files listed | |
1797 | therein into the store. Abort if the archive has an invalid digital | |
f82cc5fd LC |
1798 | signature, or if it is signed by a public key not among the authorized |
1799 | keys (see @code{--authorize} below.) | |
554f26ec | 1800 | |
87236aed LC |
1801 | @item --missing |
1802 | Read a list of store file names from the standard input, one per line, | |
1803 | and write on the standard output the subset of these files missing from | |
1804 | the store. | |
1805 | ||
554f26ec | 1806 | @item --generate-key[=@var{parameters}] |
f82cc5fd | 1807 | @cindex signing, archives |
554f26ec LC |
1808 | Generate a new key pair for the daemons. This is a prerequisite before |
1809 | archives can be exported with @code{--export}. Note that this operation | |
1810 | usually takes time, because it needs to gather enough entropy to | |
1811 | generate the key pair. | |
1812 | ||
1813 | The generated key pair is typically stored under @file{/etc/guix}, in | |
1814 | @file{signing-key.pub} (public key) and @file{signing-key.sec} (private | |
867d8473 LC |
1815 | key, which must be kept secret.) When @var{parameters} is omitted, |
1816 | an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt | |
1817 | versions before 1.6.0, it is a 4096-bit RSA key. | |
1818 | Alternately, @var{parameters} can specify | |
554f26ec LC |
1819 | @code{genkey} parameters suitable for Libgcrypt (@pxref{General |
1820 | public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The | |
1821 | Libgcrypt Reference Manual}). | |
f82cc5fd LC |
1822 | |
1823 | @item --authorize | |
1824 | @cindex authorizing, archives | |
1825 | Authorize imports signed by the public key passed on standard input. | |
1826 | The public key must be in ``s-expression advanced format''---i.e., the | |
1827 | same format as the @file{signing-key.pub} file. | |
1828 | ||
1829 | The list of authorized keys is kept in the human-editable file | |
1830 | @file{/etc/guix/acl}. The file contains | |
1831 | @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format | |
1832 | s-expressions''} and is structured as an access-control list in the | |
1833 | @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure | |
1834 | (SPKI)}. | |
760c60d6 LC |
1835 | @end table |
1836 | ||
1837 | To export store files as an archive to the standard output, run: | |
1838 | ||
1839 | @example | |
1840 | guix archive --export @var{options} @var{specifications}... | |
1841 | @end example | |
1842 | ||
1843 | @var{specifications} may be either store file names or package | |
1844 | specifications, as for @command{guix package} (@pxref{Invoking guix | |
1845 | package}). For instance, the following command creates an archive | |
1846 | containing the @code{gui} output of the @code{git} package and the main | |
1847 | output of @code{emacs}: | |
1848 | ||
1849 | @example | |
834129e0 | 1850 | guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar |
760c60d6 LC |
1851 | @end example |
1852 | ||
1853 | If the specified packages are not built yet, @command{guix archive} | |
1854 | automatically builds them. The build process may be controlled with the | |
1855 | same options that can be passed to the @command{guix build} command | |
70ee5642 | 1856 | (@pxref{Invoking guix build, common build options}). |
760c60d6 LC |
1857 | |
1858 | ||
568717fd LC |
1859 | @c ********************************************************************* |
1860 | @node Programming Interface | |
1861 | @chapter Programming Interface | |
1862 | ||
3dc1970d LC |
1863 | GNU Guix provides several Scheme programming interfaces (APIs) to |
1864 | define, build, and query packages. The first interface allows users to | |
1865 | write high-level package definitions. These definitions refer to | |
1866 | familiar packaging concepts, such as the name and version of a package, | |
1867 | its build system, and its dependencies. These definitions can then be | |
1868 | turned into concrete build actions. | |
1869 | ||
ba55b1cb | 1870 | Build actions are performed by the Guix daemon, on behalf of users. In a |
3dc1970d | 1871 | standard setup, the daemon has write access to the store---the |
834129e0 | 1872 | @file{/gnu/store} directory---whereas users do not. The recommended |
3dc1970d LC |
1873 | setup also has the daemon perform builds in chroots, under a specific |
1874 | build users, to minimize interference with the rest of the system. | |
1875 | ||
1876 | @cindex derivation | |
1877 | Lower-level APIs are available to interact with the daemon and the | |
1878 | store. To instruct the daemon to perform a build action, users actually | |
1879 | provide it with a @dfn{derivation}. A derivation is a low-level | |
1880 | representation of the build actions to be taken, and the environment in | |
1881 | which they should occur---derivations are to package definitions what | |
49ad317a LC |
1882 | assembly is to C programs. The term ``derivation'' comes from the fact |
1883 | that build results @emph{derive} from them. | |
3dc1970d LC |
1884 | |
1885 | This chapter describes all these APIs in turn, starting from high-level | |
1886 | package definitions. | |
1887 | ||
568717fd | 1888 | @menu |
b860f382 | 1889 | * Defining Packages:: Defining new packages. |
7458bd0a | 1890 | * Build Systems:: Specifying how packages are built. |
b860f382 LC |
1891 | * The Store:: Manipulating the package store. |
1892 | * Derivations:: Low-level interface to package derivations. | |
1893 | * The Store Monad:: Purely functional interface to the store. | |
21b679f6 | 1894 | * G-Expressions:: Manipulating build expressions. |
568717fd LC |
1895 | @end menu |
1896 | ||
1897 | @node Defining Packages | |
1898 | @section Defining Packages | |
1899 | ||
3dc1970d LC |
1900 | The high-level interface to package definitions is implemented in the |
1901 | @code{(guix packages)} and @code{(guix build-system)} modules. As an | |
1902 | example, the package definition, or @dfn{recipe}, for the GNU Hello | |
1903 | package looks like this: | |
1904 | ||
1905 | @example | |
e7f34eb0 LC |
1906 | (define-module (gnu packages hello) |
1907 | #:use-module (guix packages) | |
1908 | #:use-module (guix download) | |
1909 | #:use-module (guix build-system gnu) | |
1910 | #:use-module (guix licenses)) | |
b22a12fd | 1911 | |
79f5dd59 | 1912 | (define-public hello |
3dc1970d LC |
1913 | (package |
1914 | (name "hello") | |
1915 | (version "2.8") | |
1916 | (source (origin | |
1917 | (method url-fetch) | |
1918 | (uri (string-append "mirror://gnu/hello/hello-" version | |
1919 | ".tar.gz")) | |
1920 | (sha256 | |
1921 | (base32 "0wqd8sjmxfskrflaxywc7gqw7sfawrfvdxd9skxawzfgyy0pzdz6")))) | |
1922 | (build-system gnu-build-system) | |
7458bd0a | 1923 | (arguments `(#:configure-flags '("--enable-silent-rules"))) |
3dc1970d | 1924 | (inputs `(("gawk" ,gawk))) |
7458bd0a LC |
1925 | (synopsis "Hello, GNU world: An example GNU package") |
1926 | (description "Guess what GNU Hello prints!") | |
3dc1970d | 1927 | (home-page "http://www.gnu.org/software/hello/") |
b22a12fd | 1928 | (license gpl3+))) |
3dc1970d LC |
1929 | @end example |
1930 | ||
1931 | @noindent | |
1932 | Without being a Scheme expert, the reader may have guessed the meaning | |
e7f34eb0 | 1933 | of the various fields here. This expression binds variable @code{hello} |
3dc1970d LC |
1934 | to a @code{<package>} object, which is essentially a record |
1935 | (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}). | |
1936 | This package object can be inspected using procedures found in the | |
1937 | @code{(guix packages)} module; for instance, @code{(package-name hello)} | |
1938 | returns---surprise!---@code{"hello"}. | |
1939 | ||
2f7d2d91 LC |
1940 | With luck, you may be able to import part or all of the definition of |
1941 | the package you are interested in from another repository, using the | |
1942 | @code{guix import} command (@pxref{Invoking guix import}). | |
1943 | ||
e7f34eb0 LC |
1944 | In the example above, @var{hello} is defined into a module of its own, |
1945 | @code{(gnu packages hello)}. Technically, this is not strictly | |
1946 | necessary, but it is convenient to do so: all the packages defined in | |
1947 | modules under @code{(gnu packages @dots{})} are automatically known to | |
1948 | the command-line tools (@pxref{Package Modules}). | |
1949 | ||
3dc1970d LC |
1950 | There are a few points worth noting in the above package definition: |
1951 | ||
1952 | @itemize | |
1953 | @item | |
a2bf4907 LC |
1954 | The @code{source} field of the package is an @code{<origin>} object |
1955 | (@pxref{origin Reference}, for the complete reference). | |
3dc1970d LC |
1956 | Here, the @code{url-fetch} method from @code{(guix download)} is used, |
1957 | meaning that the source is a file to be downloaded over FTP or HTTP. | |
1958 | ||
1959 | The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of | |
1960 | the GNU mirrors defined in @code{(guix download)}. | |
1961 | ||
1962 | The @code{sha256} field specifies the expected SHA256 hash of the file | |
1963 | being downloaded. It is mandatory, and allows Guix to check the | |
1964 | integrity of the file. The @code{(base32 @dots{})} form introduces the | |
6c365eca | 1965 | base32 representation of the hash. You can obtain this information with |
210cc920 LC |
1966 | @code{guix download} (@pxref{Invoking guix download}) and @code{guix |
1967 | hash} (@pxref{Invoking guix hash}). | |
3dc1970d | 1968 | |
f9cc8971 LC |
1969 | @cindex patches |
1970 | When needed, the @code{origin} form can also have a @code{patches} field | |
1971 | listing patches to be applied, and a @code{snippet} field giving a | |
1972 | Scheme expression to modify the source code. | |
1973 | ||
3dc1970d LC |
1974 | @item |
1975 | @cindex GNU Build System | |
7458bd0a LC |
1976 | The @code{build-system} field specifies the procedure to build the |
1977 | package (@pxref{Build Systems}). Here, @var{gnu-build-system} | |
1978 | represents the familiar GNU Build System, where packages may be | |
1979 | configured, built, and installed with the usual @code{./configure && | |
1980 | make && make check && make install} command sequence. | |
1981 | ||
1982 | @item | |
1983 | The @code{arguments} field specifies options for the build system | |
1984 | (@pxref{Build Systems}). Here it is interpreted by | |
1985 | @var{gnu-build-system} as a request run @file{configure} with the | |
1986 | @code{--enable-silent-rules} flag. | |
3dc1970d LC |
1987 | |
1988 | @item | |
1989 | The @code{inputs} field specifies inputs to the build process---i.e., | |
1990 | build-time or run-time dependencies of the package. Here, we define an | |
1991 | input called @code{"gawk"} whose value is that of the @var{gawk} | |
1992 | variable; @var{gawk} is itself bound to a @code{<package>} object. | |
1993 | ||
1994 | Note that GCC, Coreutils, Bash, and other essential tools do not need to | |
1995 | be specified as inputs here. Instead, @var{gnu-build-system} takes care | |
7458bd0a | 1996 | of ensuring that they are present (@pxref{Build Systems}). |
3dc1970d LC |
1997 | |
1998 | However, any other dependencies need to be specified in the | |
1999 | @code{inputs} field. Any dependency not specified here will simply be | |
2000 | unavailable to the build process, possibly leading to a build failure. | |
2001 | @end itemize | |
2002 | ||
87eafdbd TUBK |
2003 | @xref{package Reference}, for a full description of possible fields. |
2004 | ||
2f7d2d91 | 2005 | Once a package definition is in place, the |
e49951eb | 2006 | package may actually be built using the @code{guix build} command-line |
39bee8a2 LC |
2007 | tool (@pxref{Invoking guix build}). You can easily jump back to the |
2008 | package definition using the @command{guix edit} command | |
2009 | (@pxref{Invoking guix edit}). | |
2010 | @xref{Packaging Guidelines}, for | |
b4f5e0e8 CR |
2011 | more information on how to test package definitions, and |
2012 | @ref{Invoking guix lint}, for information on how to check a definition | |
2013 | for style conformance. | |
2014 | ||
7458bd0a LC |
2015 | Eventually, updating the package definition to a new upstream version |
2016 | can be partly automated by the @command{guix refresh} command | |
2017 | (@pxref{Invoking guix refresh}). | |
3dc1970d LC |
2018 | |
2019 | Behind the scenes, a derivation corresponding to the @code{<package>} | |
2020 | object is first computed by the @code{package-derivation} procedure. | |
834129e0 | 2021 | That derivation is stored in a @code{.drv} file under @file{/gnu/store}. |
ba55b1cb | 2022 | The build actions it prescribes may then be realized by using the |
3dc1970d LC |
2023 | @code{build-derivations} procedure (@pxref{The Store}). |
2024 | ||
2025 | @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}] | |
59688fc4 LC |
2026 | Return the @code{<derivation>} object of @var{package} for @var{system} |
2027 | (@pxref{Derivations}). | |
3dc1970d LC |
2028 | |
2029 | @var{package} must be a valid @code{<package>} object, and @var{system} | |
2030 | must be a string denoting the target system type---e.g., | |
2031 | @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store} | |
2032 | must be a connection to the daemon, which operates on the store | |
2033 | (@pxref{The Store}). | |
2034 | @end deffn | |
568717fd | 2035 | |
9c1edabd LC |
2036 | @noindent |
2037 | @cindex cross-compilation | |
2038 | Similarly, it is possible to compute a derivation that cross-builds a | |
2039 | package for some other system: | |
2040 | ||
2041 | @deffn {Scheme Procedure} package-cross-derivation @var{store} @ | |
2042 | @var{package} @var{target} [@var{system}] | |
59688fc4 LC |
2043 | Return the @code{<derivation>} object of @var{package} cross-built from |
2044 | @var{system} to @var{target}. | |
9c1edabd LC |
2045 | |
2046 | @var{target} must be a valid GNU triplet denoting the target hardware | |
2047 | and operating system, such as @code{"mips64el-linux-gnu"} | |
2048 | (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU | |
2049 | Configure and Build System}). | |
2050 | @end deffn | |
2051 | ||
87eafdbd TUBK |
2052 | @menu |
2053 | * package Reference :: The package data type. | |
2054 | * origin Reference:: The origin data type. | |
2055 | @end menu | |
2056 | ||
2057 | ||
2058 | @node package Reference | |
2059 | @subsection @code{package} Reference | |
2060 | ||
2061 | This section summarizes all the options available in @code{package} | |
2062 | declarations (@pxref{Defining Packages}). | |
2063 | ||
2064 | @deftp {Data Type} package | |
2065 | This is the data type representing a package recipe. | |
2066 | ||
2067 | @table @asis | |
2068 | @item @code{name} | |
2069 | The name of the package, as a string. | |
2070 | ||
2071 | @item @code{version} | |
2072 | The version of the package, as a string. | |
2073 | ||
2074 | @item @code{source} | |
2075 | An origin object telling how the source code for the package should be | |
2076 | acquired (@pxref{origin Reference}). | |
2077 | ||
2078 | @item @code{build-system} | |
2079 | The build system that should be used to build the package (@pxref{Build | |
2080 | Systems}). | |
2081 | ||
2082 | @item @code{arguments} (default: @code{'()}) | |
2083 | The arguments that should be passed to the build system. This is a | |
2084 | list, typically containing sequential keyword-value pairs. | |
2085 | ||
2086 | @item @code{inputs} (default: @code{'()}) | |
2087 | Package or derivation inputs to the build. This is a list of lists, | |
2088 | where each list has the name of the input (a string) as its first | |
2089 | element, a package or derivation object as its second element, and | |
2090 | optionally the name of the output of the package or derivation that | |
2091 | should be used, which defaults to @code{"out"}. | |
2092 | ||
21461f27 LC |
2093 | @item @anchor{package-propagated-inputs}@code{propagated-inputs} (default: @code{'()}) |
2094 | @cindex propagated inputs | |
87eafdbd | 2095 | This field is like @code{inputs}, but the specified packages will be |
21461f27 LC |
2096 | force-installed alongside the package they belong to |
2097 | (@pxref{package-cmd-propagated-inputs, @command{guix package}}, for | |
2098 | information on how @command{guix package} deals with propagated inputs.) | |
2099 | ||
2100 | For example this is necessary when a library needs headers of another | |
2101 | library to compile, or needs another shared library to be linked | |
2102 | alongside itself when a program wants to link to it. | |
87eafdbd TUBK |
2103 | |
2104 | @item @code{native-inputs} (default: @code{'()}) | |
2105 | This field is like @code{inputs}, but in case of a cross-compilation it | |
2106 | will be ensured that packages for the architecture of the build machine | |
2107 | are present, such that executables from them can be used during the | |
21461f27 LC |
2108 | build. |
2109 | ||
2110 | This is typically where you would list tools needed at build time but | |
2111 | not at run time, such as Autoconf, Automake, pkg-config, Gettext, or | |
2112 | Bison. @command{guix lint} can report likely mistakes in this area | |
2113 | (@pxref{Invoking guix lint}). | |
87eafdbd TUBK |
2114 | |
2115 | @item @code{self-native-input?} (default: @code{#f}) | |
2116 | This is a Boolean field telling whether the package should use itself as | |
2117 | a native input when cross-compiling. | |
2118 | ||
2119 | @item @code{outputs} (default: @code{'("out")}) | |
2120 | The list of output names of the package. @xref{Packages with Multiple | |
2121 | Outputs}, for typical uses of additional outputs. | |
2122 | ||
2123 | @item @code{native-search-paths} (default: @code{'()}) | |
2124 | @itemx @code{search-paths} (default: @code{'()}) | |
2125 | A list of @code{search-path-specification} objects describing | |
2126 | search-path environment variables honored by the package. | |
2127 | ||
2128 | @item @code{replacement} (default: @code{#f}) | |
2129 | This must either @code{#f} or a package object that will be used as a | |
2130 | @dfn{replacement} for this package. @xref{Security Updates, grafts}, | |
2131 | for details. | |
2132 | ||
2133 | @item @code{synopsis} | |
2134 | A one-line description of the package. | |
2135 | ||
2136 | @item @code{description} | |
2137 | A more elaborate description of the package. | |
2138 | ||
2139 | @item @code{license} | |
2140 | The license of the package; a value from @code{(guix licenses)}. | |
2141 | ||
2142 | @item @code{home-page} | |
2143 | The URL to the home-page of the package, as a string. | |
2144 | ||
2145 | @item @code{supported-systems} (default: @var{%supported-systems}) | |
2146 | The list of systems supported by the package, as strings of the form | |
2147 | @code{architecture-kernel}, for example @code{"x86_64-linux"}. | |
2148 | ||
2149 | @item @code{maintainers} (default: @code{'()}) | |
2150 | The list of maintainers of the package, as @code{maintainer} objects. | |
2151 | ||
2152 | @item @code{location} (default: source location of the @code{package} form) | |
2153 | The source location of the package. It's useful to override this when | |
2154 | inheriting from another package, in which case this field is not | |
2155 | automatically corrected. | |
2156 | @end table | |
2157 | @end deftp | |
2158 | ||
2159 | ||
2160 | @node origin Reference | |
2161 | @subsection @code{origin} Reference | |
2162 | ||
2163 | This section summarizes all the options available in @code{origin} | |
2164 | declarations (@pxref{Defining Packages}). | |
2165 | ||
2166 | @deftp {Data Type} origin | |
2167 | This is the data type representing a source code origin. | |
2168 | ||
2169 | @table @asis | |
2170 | @item @code{uri} | |
2171 | An object containing the URI of the source. The object type depends on | |
2172 | the @code{method} (see below). For example, when using the | |
2173 | @var{url-fetch} method of @code{(guix download)}, the valid @code{uri} | |
2174 | values are: a URL represented as a string, or a list thereof. | |
2175 | ||
2176 | @item @code{method} | |
2177 | A procedure that will handle the URI. | |
2178 | ||
2179 | Examples include: | |
2180 | ||
2181 | @table @asis | |
2182 | @item @var{url-fetch} from @code{(guix download)} | |
2183 | download a file the HTTP, HTTPS, or FTP URL specified in the | |
2184 | @code{uri} field; | |
2185 | ||
2186 | @item @var{git-fetch} from @code{(guix git-download)} | |
2187 | clone the Git version control repository, and check out the revision | |
2188 | specified in the @code{uri} field as a @code{git-reference} object; a | |
2189 | @code{git-reference} looks like this: | |
2190 | ||
2191 | @example | |
2192 | (git-reference | |
2193 | (url "git://git.debian.org/git/pkg-shadow/shadow") | |
2194 | (commit "v4.1.5.1")) | |
2195 | @end example | |
2196 | @end table | |
2197 | ||
2198 | @item @code{sha256} | |
2199 | A bytevector containing the SHA-256 hash of the source. Typically the | |
2200 | @code{base32} form is used here to generate the bytevector from a | |
2201 | base-32 string. | |
2202 | ||
2203 | @item @code{file-name} (default: @code{#f}) | |
2204 | The file name under which the source code should be saved. When this is | |
2205 | @code{#f}, a sensible default value will be used in most cases. In case | |
2206 | the source is fetched from a URL, the file name from the URL will be | |
2207 | used. For version control checkouts, it's recommended to provide the | |
2208 | file name explicitly because the default is not very descriptive. | |
2209 | ||
2210 | @item @code{patches} (default: @code{'()}) | |
2211 | A list of file names containing patches to be applied to the source. | |
2212 | ||
2213 | @item @code{snippet} (default: @code{#f}) | |
2214 | A quoted piece of code that will be run in the source directory to make | |
2215 | any modifications, which is sometimes more convenient than a patch. | |
2216 | ||
2217 | @item @code{patch-flags} (default: @code{'("-p1")}) | |
2218 | A list of command-line flags that should be passed to the @code{patch} | |
2219 | command. | |
2220 | ||
2221 | @item @code{patch-inputs} (default: @code{#f}) | |
2222 | Input packages or derivations to the patching process. When this is | |
2223 | @code{#f}, the usual set of inputs necessary for patching are provided, | |
2224 | such as GNU@tie{}Patch. | |
2225 | ||
2226 | @item @code{modules} (default: @code{'()}) | |
2227 | A list of Guile modules that should be loaded during the patching | |
2228 | process and while running the code in the @code{snippet} field. | |
2229 | ||
2230 | @item @code{imported-modules} (default: @code{'()}) | |
2231 | The list of Guile modules to import in the patch derivation, for use by | |
2232 | the @code{snippet}. | |
2233 | ||
2234 | @item @code{patch-guile} (default: @code{#f}) | |
2235 | The Guile package that should be used in the patching process. When | |
2236 | this is @code{#f}, a sensible default is used. | |
2237 | @end table | |
2238 | @end deftp | |
2239 | ||
9c1edabd | 2240 | |
7458bd0a LC |
2241 | @node Build Systems |
2242 | @section Build Systems | |
2243 | ||
2244 | @cindex build system | |
2245 | Each package definition specifies a @dfn{build system} and arguments for | |
2246 | that build system (@pxref{Defining Packages}). This @code{build-system} | |
2247 | field represents the build procedure of the package, as well implicit | |
2248 | dependencies of that build procedure. | |
2249 | ||
2250 | Build systems are @code{<build-system>} objects. The interface to | |
2251 | create and manipulate them is provided by the @code{(guix build-system)} | |
2252 | module, and actual build systems are exported by specific modules. | |
2253 | ||
f5fd4fd2 | 2254 | @cindex bag (low-level package representation) |
0d5a559f LC |
2255 | Under the hood, build systems first compile package objects to |
2256 | @dfn{bags}. A @dfn{bag} is like a package, but with less | |
2257 | ornamentation---in other words, a bag is a lower-level representation of | |
2258 | a package, which includes all the inputs of that package, including some | |
2259 | that were implicitly added by the build system. This intermediate | |
2260 | representation is then compiled to a derivation (@pxref{Derivations}). | |
2261 | ||
7458bd0a LC |
2262 | Build systems accept an optional list of @dfn{arguments}. In package |
2263 | definitions, these are passed @i{via} the @code{arguments} field | |
2264 | (@pxref{Defining Packages}). They are typically keyword arguments | |
2265 | (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU | |
2266 | Guile Reference Manual}). The value of these arguments is usually | |
2267 | evaluated in the @dfn{build stratum}---i.e., by a Guile process launched | |
2268 | by the daemon (@pxref{Derivations}). | |
2269 | ||
2270 | The main build system is @var{gnu-build-system}, which implements the | |
2271 | standard build procedure for GNU packages and many other packages. It | |
2272 | is provided by the @code{(guix build-system gnu)} module. | |
2273 | ||
2274 | @defvr {Scheme Variable} gnu-build-system | |
2275 | @var{gnu-build-system} represents the GNU Build System, and variants | |
2276 | thereof (@pxref{Configuration, configuration and makefile conventions,, | |
2277 | standards, GNU Coding Standards}). | |
2278 | ||
2279 | @cindex build phases | |
2280 | In a nutshell, packages using it configured, built, and installed with | |
2281 | the usual @code{./configure && make && make check && make install} | |
2282 | command sequence. In practice, a few additional steps are often needed. | |
2283 | All these steps are split up in separate @dfn{phases}, | |
2284 | notably@footnote{Please see the @code{(guix build gnu-build-system)} | |
2285 | modules for more details about the build phases.}: | |
2286 | ||
2287 | @table @code | |
2288 | @item unpack | |
2289 | Unpack the source tarball, and change the current directory to the | |
2290 | extracted source tree. If the source is actually a directory, copy it | |
2291 | to the build tree, and enter that directory. | |
2292 | ||
2293 | @item patch-source-shebangs | |
2294 | Patch shebangs encountered in source files so they refer to the right | |
2295 | store file names. For instance, this changes @code{#!/bin/sh} to | |
2296 | @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}. | |
2297 | ||
2298 | @item configure | |
2299 | Run the @file{configure} script with a number of default options, such | |
2300 | as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified | |
2301 | by the @code{#:configure-flags} argument. | |
2302 | ||
2303 | @item build | |
2304 | Run @code{make} with the list of flags specified with | |
2305 | @code{#:make-flags}. If the @code{#:parallel-builds?} argument is true | |
2306 | (the default), build with @code{make -j}. | |
2307 | ||
2308 | @item check | |
2309 | Run @code{make check}, or some other target specified with | |
2310 | @code{#:test-target}, unless @code{#:tests? #f} is passed. If the | |
2311 | @code{#:parallel-tests?} argument is true (the default), run @code{make | |
2312 | check -j}. | |
2313 | ||
2314 | @item install | |
2315 | Run @code{make install} with the flags listed in @code{#:make-flags}. | |
2316 | ||
2317 | @item patch-shebangs | |
2318 | Patch shebangs on the installed executable files. | |
2319 | ||
2320 | @item strip | |
2321 | Strip debugging symbols from ELF files (unless @code{#:strip-binaries?} | |
2322 | is false), copying them to the @code{debug} output when available | |
2323 | (@pxref{Installing Debugging Files}). | |
2324 | @end table | |
2325 | ||
2326 | @vindex %standard-phases | |
2327 | The build-side module @code{(guix build gnu-build-system)} defines | |
2328 | @var{%standard-phases} as the default list of build phases. | |
2329 | @var{%standard-phases} is a list of symbol/procedure pairs, where the | |
2330 | procedure implements the actual phase. | |
2331 | ||
2332 | The list of phases used for a particular package can be changed with the | |
2333 | @code{#:phases} parameter. For instance, passing: | |
2334 | ||
2335 | @example | |
2336 | #:phases (alist-delete 'configure %standard-phases) | |
2337 | @end example | |
2338 | ||
9bf404e9 | 2339 | means that all the phases described above will be used, except the |
7458bd0a LC |
2340 | @code{configure} phase. |
2341 | ||
2342 | In addition, this build system ensures that the ``standard'' environment | |
2343 | for GNU packages is available. This includes tools such as GCC, libc, | |
2344 | Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix | |
2345 | build-system gnu)} module for a complete list.) We call these the | |
2346 | @dfn{implicit inputs} of a package, because package definitions don't | |
2347 | have to mention them. | |
2348 | @end defvr | |
2349 | ||
2350 | Other @code{<build-system>} objects are defined to support other | |
2351 | conventions and tools used by free software packages. They inherit most | |
2352 | of @var{gnu-build-system}, and differ mainly in the set of inputs | |
2353 | implicitly added to the build process, and in the list of phases | |
2354 | executed. Some of these build systems are listed below. | |
2355 | ||
2356 | @defvr {Scheme Variable} cmake-build-system | |
2357 | This variable is exported by @code{(guix build-system cmake)}. It | |
2358 | implements the build procedure for packages using the | |
2359 | @url{http://www.cmake.org, CMake build tool}. | |
2360 | ||
2361 | It automatically adds the @code{cmake} package to the set of inputs. | |
2362 | Which package is used can be specified with the @code{#:cmake} | |
2363 | parameter. | |
9849cfc1 LC |
2364 | |
2365 | The @code{#:configure-flags} parameter is taken as a list of flags | |
2366 | passed to the @command{cmake} command. The @code{#:build-type} | |
2367 | parameter specifies in abstract terms the flags passed to the compiler; | |
2368 | it defaults to @code{"RelWithDebInfo"} (short for ``release mode with | |
2369 | debugging information''), which roughly means that code is compiled with | |
2370 | @code{-O2 -g}, as is the case for Autoconf-based packages by default. | |
7458bd0a LC |
2371 | @end defvr |
2372 | ||
3afcf52b FB |
2373 | @defvr {Scheme Variable} glib-or-gtk-build-system |
2374 | This variable is exported by @code{(guix build-system glib-or-gtk)}. It | |
2375 | is intended for use with packages making use of GLib or GTK+. | |
2376 | ||
2377 | This build system adds the following two phases to the ones defined by | |
2378 | @var{gnu-build-system}: | |
2379 | ||
2380 | @table @code | |
2381 | @item glib-or-gtk-wrap | |
2382 | The phase @code{glib-or-gtk-wrap} ensures that programs found under | |
2383 | @file{bin/} are able to find GLib's ``schemas'' and | |
2384 | @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+ | |
2385 | modules}. This is achieved by wrapping the programs in launch scripts | |
2386 | that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH} | |
2387 | environment variables. | |
2388 | ||
73aa8ddb LC |
2389 | It is possible to exclude specific package outputs from that wrapping |
2390 | process by listing their names in the | |
2391 | @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful | |
2392 | when an output is known not to contain any GLib or GTK+ binaries, and | |
2393 | where wrapping would gratuitously add a dependency of that output on | |
2394 | GLib and GTK+. | |
2395 | ||
3afcf52b FB |
2396 | @item glib-or-gtk-compile-schemas |
2397 | The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's | |
2398 | @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html, | |
2399 | GSettings schemas} are compiled. Compilation is performed by the | |
2400 | @command{glib-compile-schemas} program. It is provided by the package | |
2401 | @code{glib:bin} which is automatically imported by the build system. | |
2402 | The @code{glib} package providing @command{glib-compile-schemas} can be | |
2403 | specified with the @code{#:glib} parameter. | |
2404 | @end table | |
2405 | ||
2406 | Both phases are executed after the @code{install} phase. | |
2407 | @end defvr | |
2408 | ||
7458bd0a LC |
2409 | @defvr {Scheme Variable} python-build-system |
2410 | This variable is exported by @code{(guix build-system python)}. It | |
2411 | implements the more or less standard build procedure used by Python | |
2412 | packages, which consists in running @code{python setup.py build} and | |
2413 | then @code{python setup.py install --prefix=/gnu/store/@dots{}}. | |
2414 | ||
2415 | For packages that install stand-alone Python programs under @code{bin/}, | |
2416 | it takes care of wrapping these programs so their @code{PYTHONPATH} | |
2417 | environment variable points to all the Python libraries they depend on. | |
2418 | ||
2419 | Which Python package is used can be specified with the @code{#:python} | |
2420 | parameter. | |
2421 | @end defvr | |
2422 | ||
2423 | @defvr {Scheme Variable} perl-build-system | |
2424 | This variable is exported by @code{(guix build-system perl)}. It | |
2d2a53fc EB |
2425 | implements the standard build procedure for Perl packages, which either |
2426 | consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}}, | |
2427 | followed by @code{Build} and @code{Build install}; or in running | |
2428 | @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by | |
2429 | @code{make} and @code{make install}; depending on which of | |
2430 | @code{Build.PL} or @code{Makefile.PL} is present in the package | |
2431 | distribution. Preference is given to the former if both @code{Build.PL} | |
2432 | and @code{Makefile.PL} exist in the package distribution. This | |
2433 | preference can be reversed by specifying @code{#t} for the | |
2434 | @code{#:make-maker?} parameter. | |
2435 | ||
2436 | The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation | |
2437 | passes flags specified by the @code{#:make-maker-flags} or | |
2438 | @code{#:module-build-flags} parameter, respectively. | |
7458bd0a LC |
2439 | |
2440 | Which Perl package is used can be specified with @code{#:perl}. | |
2441 | @end defvr | |
2442 | ||
c08f9818 DT |
2443 | @defvr {Scheme Variable} ruby-build-system |
2444 | This variable is exported by @code{(guix build-system ruby)}. It | |
2445 | implements the RubyGems build procedure used by Ruby packages, which | |
2446 | involves running @code{gem build} followed by @code{gem install}. | |
2447 | ||
2448 | Which Ruby package is used can be specified with the @code{#:ruby} | |
2449 | parameter. | |
2450 | @end defvr | |
7458bd0a | 2451 | |
a677c726 RW |
2452 | @defvr {Scheme Variable} waf-build-system |
2453 | This variable is exported by @code{(guix build-system waf)}. It | |
2454 | implements a build procedure around the @code{waf} script. The common | |
2455 | phases---@code{configure}, @code{build}, and @code{install}---are | |
2456 | implemented by passing their names as arguments to the @code{waf} | |
2457 | script. | |
2458 | ||
2459 | The @code{waf} script is executed by the Python interpreter. Which | |
2460 | Python package is used to run the script can be specified with the | |
2461 | @code{#:python} parameter. | |
2462 | @end defvr | |
2463 | ||
14dfdf2e FB |
2464 | @defvr {Scheme Variable} haskell-build-system |
2465 | This variable is exported by @code{(guix build-system haskell)}. It | |
2466 | implements the Cabal build procedure used by Haskell packages, which | |
2467 | involves running @code{runhaskell Setup.hs configure | |
2468 | --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}. | |
2469 | Instead of installing the package by running @code{runhaskell Setup.hs | |
2470 | install}, to avoid trying to register libraries in the read-only | |
2471 | compiler store directory, the build system uses @code{runhaskell | |
2472 | Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In | |
2473 | addition, the build system generates the package documentation by | |
2474 | running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f} | |
2475 | is passed. Optional Haddock parameters can be passed with the help of | |
2476 | the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is | |
2477 | not found, the build system looks for @code{Setup.lhs} instead. | |
2478 | ||
2479 | Which Haskell compiler is used can be specified with the @code{#:haskell} | |
a54bd6d7 | 2480 | parameter which defaults to @code{ghc}. |
14dfdf2e FB |
2481 | @end defvr |
2482 | ||
e9137a53 FB |
2483 | @defvr {Scheme Variable} emacs-build-system |
2484 | This variable is exported by @code{(guix build-system emacs)}. It | |
2485 | implements an installation procedure similar to the one of Emacs' own | |
2486 | packaging system (@pxref{Packages,,, emacs, The GNU Emacs Manual}). | |
2487 | ||
2488 | It first creates the @code{@var{package}-autoloads.el} file, then it | |
2489 | byte compiles all Emacs Lisp files. Differently from the Emacs | |
2490 | packaging system, the Info documentation files are moved to the standard | |
2491 | documentation directory and the @file{dir} file is deleted. Each | |
2492 | package is installed in its own directory under | |
2493 | @file{share/emacs/site-lisp/guix.d}. | |
2494 | @end defvr | |
2495 | ||
7458bd0a LC |
2496 | Lastly, for packages that do not need anything as sophisticated, a |
2497 | ``trivial'' build system is provided. It is trivial in the sense that | |
2498 | it provides basically no support: it does not pull any implicit inputs, | |
2499 | and does not have a notion of build phases. | |
2500 | ||
2501 | @defvr {Scheme Variable} trivial-build-system | |
2502 | This variable is exported by @code{(guix build-system trivial)}. | |
2503 | ||
2504 | This build system requires a @code{#:builder} argument. This argument | |
2505 | must be a Scheme expression that builds the package's output(s)---as | |
2506 | with @code{build-expression->derivation} (@pxref{Derivations, | |
2507 | @code{build-expression->derivation}}). | |
2508 | @end defvr | |
2509 | ||
568717fd LC |
2510 | @node The Store |
2511 | @section The Store | |
2512 | ||
e531ac2a LC |
2513 | @cindex store |
2514 | @cindex store paths | |
2515 | ||
2516 | Conceptually, the @dfn{store} is where derivations that have been | |
834129e0 | 2517 | successfully built are stored---by default, under @file{/gnu/store}. |
e531ac2a LC |
2518 | Sub-directories in the store are referred to as @dfn{store paths}. The |
2519 | store has an associated database that contains information such has the | |
2520 | store paths referred to by each store path, and the list of @emph{valid} | |
2521 | store paths---paths that result from a successful build. | |
2522 | ||
2523 | The store is always accessed by the daemon on behalf of its clients | |
2524 | (@pxref{Invoking guix-daemon}). To manipulate the store, clients | |
2525 | connect to the daemon over a Unix-domain socket, send it requests, and | |
2526 | read the result---these are remote procedure calls, or RPCs. | |
2527 | ||
2528 | The @code{(guix store)} module provides procedures to connect to the | |
2529 | daemon, and to perform RPCs. These are described below. | |
2530 | ||
2531 | @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t] | |
2532 | Connect to the daemon over the Unix-domain socket at @var{file}. When | |
2533 | @var{reserve-space?} is true, instruct it to reserve a little bit of | |
2534 | extra space on the file system so that the garbage collector can still | |
2535 | operate, should the disk become full. Return a server object. | |
2536 | ||
2537 | @var{file} defaults to @var{%default-socket-path}, which is the normal | |
2538 | location given the options that were passed to @command{configure}. | |
2539 | @end deffn | |
2540 | ||
2541 | @deffn {Scheme Procedure} close-connection @var{server} | |
2542 | Close the connection to @var{server}. | |
2543 | @end deffn | |
2544 | ||
2545 | @defvr {Scheme Variable} current-build-output-port | |
2546 | This variable is bound to a SRFI-39 parameter, which refers to the port | |
2547 | where build and error logs sent by the daemon should be written. | |
2548 | @end defvr | |
2549 | ||
2550 | Procedures that make RPCs all take a server object as their first | |
2551 | argument. | |
2552 | ||
2553 | @deffn {Scheme Procedure} valid-path? @var{server} @var{path} | |
2554 | Return @code{#t} when @var{path} is a valid store path. | |
2555 | @end deffn | |
2556 | ||
cfbf9160 | 2557 | @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}] |
e531ac2a LC |
2558 | Add @var{text} under file @var{name} in the store, and return its store |
2559 | path. @var{references} is the list of store paths referred to by the | |
2560 | resulting store path. | |
2561 | @end deffn | |
2562 | ||
874e6874 | 2563 | @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations} |
59688fc4 LC |
2564 | Build @var{derivations} (a list of @code{<derivation>} objects or |
2565 | derivation paths), and return when the worker is done building them. | |
2566 | Return @code{#t} on success. | |
874e6874 LC |
2567 | @end deffn |
2568 | ||
b860f382 LC |
2569 | Note that the @code{(guix monads)} module provides a monad as well as |
2570 | monadic versions of the above procedures, with the goal of making it | |
2571 | more convenient to work with code that accesses the store (@pxref{The | |
2572 | Store Monad}). | |
2573 | ||
e531ac2a LC |
2574 | @c FIXME |
2575 | @i{This section is currently incomplete.} | |
568717fd LC |
2576 | |
2577 | @node Derivations | |
2578 | @section Derivations | |
2579 | ||
874e6874 LC |
2580 | @cindex derivations |
2581 | Low-level build actions and the environment in which they are performed | |
2582 | are represented by @dfn{derivations}. A derivation contain the | |
2583 | following pieces of information: | |
2584 | ||
2585 | @itemize | |
2586 | @item | |
2587 | The outputs of the derivation---derivations produce at least one file or | |
2588 | directory in the store, but may produce more. | |
2589 | ||
2590 | @item | |
2591 | The inputs of the derivations, which may be other derivations or plain | |
2592 | files in the store (patches, build scripts, etc.) | |
2593 | ||
2594 | @item | |
2595 | The system type targeted by the derivation---e.g., @code{x86_64-linux}. | |
2596 | ||
2597 | @item | |
2598 | The file name of a build script in the store, along with the arguments | |
2599 | to be passed. | |
2600 | ||
2601 | @item | |
2602 | A list of environment variables to be defined. | |
2603 | ||
2604 | @end itemize | |
2605 | ||
2606 | @cindex derivation path | |
2607 | Derivations allow clients of the daemon to communicate build actions to | |
2608 | the store. They exist in two forms: as an in-memory representation, | |
2609 | both on the client- and daemon-side, and as files in the store whose | |
2610 | name end in @code{.drv}---these files are referred to as @dfn{derivation | |
2611 | paths}. Derivations paths can be passed to the @code{build-derivations} | |
2612 | procedure to perform the build actions they prescribe (@pxref{The | |
2613 | Store}). | |
2614 | ||
2615 | The @code{(guix derivations)} module provides a representation of | |
2616 | derivations as Scheme objects, along with procedures to create and | |
2617 | otherwise manipulate derivations. The lowest-level primitive to create | |
2618 | a derivation is the @code{derivation} procedure: | |
2619 | ||
1909431c LC |
2620 | @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @ |
2621 | @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @ | |
2096ef47 | 2622 | [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @ |
1909431c | 2623 | [#:system (%current-system)] [#:references-graphs #f] @ |
4a6aeb67 LC |
2624 | [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @ |
2625 | [#:substitutable? #t] | |
59688fc4 LC |
2626 | Build a derivation with the given arguments, and return the resulting |
2627 | @code{<derivation>} object. | |
874e6874 | 2628 | |
2096ef47 | 2629 | When @var{hash} and @var{hash-algo} are given, a |
874e6874 | 2630 | @dfn{fixed-output derivation} is created---i.e., one whose result is |
36bbbbd1 LC |
2631 | known in advance, such as a file download. If, in addition, |
2632 | @var{recursive?} is true, then that fixed output may be an executable | |
2633 | file or a directory and @var{hash} must be the hash of an archive | |
2634 | containing this output. | |
5b0c9d16 | 2635 | |
858e9282 | 2636 | When @var{references-graphs} is true, it must be a list of file |
5b0c9d16 LC |
2637 | name/store path pairs. In that case, the reference graph of each store |
2638 | path is exported in the build environment in the corresponding file, in | |
2639 | a simple text format. | |
1909431c | 2640 | |
b53be755 LC |
2641 | When @var{allowed-references} is true, it must be a list of store items |
2642 | or outputs that the derivation's output may refer to. | |
2643 | ||
c0468155 LC |
2644 | When @var{leaked-env-vars} is true, it must be a list of strings |
2645 | denoting environment variables that are allowed to ``leak'' from the | |
2646 | daemon's environment to the build environment. This is only applicable | |
2647 | to fixed-output derivations---i.e., when @var{hash} is true. The main | |
2648 | use is to allow variables such as @code{http_proxy} to be passed to | |
2649 | derivations that download files. | |
2650 | ||
1909431c LC |
2651 | When @var{local-build?} is true, declare that the derivation is not a |
2652 | good candidate for offloading and should rather be built locally | |
2653 | (@pxref{Daemon Offload Setup}). This is the case for small derivations | |
2654 | where the costs of data transfers would outweigh the benefits. | |
4a6aeb67 LC |
2655 | |
2656 | When @var{substitutable?} is false, declare that substitutes of the | |
2657 | derivation's output should not be used (@pxref{Substitutes}). This is | |
2658 | useful, for instance, when building packages that capture details of the | |
2659 | host CPU instruction set. | |
874e6874 LC |
2660 | @end deffn |
2661 | ||
2662 | @noindent | |
2663 | Here's an example with a shell script as its builder, assuming | |
2664 | @var{store} is an open connection to the daemon, and @var{bash} points | |
2665 | to a Bash executable in the store: | |
2666 | ||
2667 | @lisp | |
2668 | (use-modules (guix utils) | |
2669 | (guix store) | |
2670 | (guix derivations)) | |
2671 | ||
59688fc4 LC |
2672 | (let ((builder ; add the Bash script to the store |
2673 | (add-text-to-store store "my-builder.sh" | |
2674 | "echo hello world > $out\n" '()))) | |
2675 | (derivation store "foo" | |
2676 | bash `("-e" ,builder) | |
21b679f6 | 2677 | #:inputs `((,bash) (,builder)) |
59688fc4 | 2678 | #:env-vars '(("HOME" . "/homeless")))) |
834129e0 | 2679 | @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo> |
874e6874 LC |
2680 | @end lisp |
2681 | ||
21b679f6 LC |
2682 | As can be guessed, this primitive is cumbersome to use directly. A |
2683 | better approach is to write build scripts in Scheme, of course! The | |
2684 | best course of action for that is to write the build code as a | |
2685 | ``G-expression'', and to pass it to @code{gexp->derivation}. For more | |
6621cdb6 | 2686 | information, @pxref{G-Expressions}. |
21b679f6 LC |
2687 | |
2688 | Once upon a time, @code{gexp->derivation} did not exist and constructing | |
2689 | derivations with build code written in Scheme was achieved with | |
2690 | @code{build-expression->derivation}, documented below. This procedure | |
2691 | is now deprecated in favor of the much nicer @code{gexp->derivation}. | |
874e6874 | 2692 | |
dd1a5a15 LC |
2693 | @deffn {Scheme Procedure} build-expression->derivation @var{store} @ |
2694 | @var{name} @var{exp} @ | |
2695 | [#:system (%current-system)] [#:inputs '()] @ | |
2696 | [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @ | |
36bbbbd1 | 2697 | [#:recursive? #f] [#:env-vars '()] [#:modules '()] @ |
63a42824 | 2698 | [#:references-graphs #f] [#:allowed-references #f] @ |
4a6aeb67 | 2699 | [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f] |
874e6874 LC |
2700 | Return a derivation that executes Scheme expression @var{exp} as a |
2701 | builder for derivation @var{name}. @var{inputs} must be a list of | |
2702 | @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted, | |
2703 | @code{"out"} is assumed. @var{modules} is a list of names of Guile | |
2704 | modules from the current search path to be copied in the store, | |
2705 | compiled, and made available in the load path during the execution of | |
2706 | @var{exp}---e.g., @code{((guix build utils) (guix build | |
2707 | gnu-build-system))}. | |
2708 | ||
2709 | @var{exp} is evaluated in an environment where @code{%outputs} is bound | |
2710 | to a list of output/path pairs, and where @code{%build-inputs} is bound | |
2711 | to a list of string/output-path pairs made from @var{inputs}. | |
2712 | Optionally, @var{env-vars} is a list of string pairs specifying the name | |
2713 | and value of environment variables visible to the builder. The builder | |
2714 | terminates by passing the result of @var{exp} to @code{exit}; thus, when | |
2715 | @var{exp} returns @code{#f}, the build is considered to have failed. | |
2716 | ||
2717 | @var{exp} is built using @var{guile-for-build} (a derivation). When | |
2718 | @var{guile-for-build} is omitted or is @code{#f}, the value of the | |
2719 | @code{%guile-for-build} fluid is used instead. | |
9c629a27 | 2720 | |
63a42824 | 2721 | See the @code{derivation} procedure for the meaning of |
4a6aeb67 LC |
2722 | @var{references-graphs}, @var{allowed-references}, @var{local-build?}, |
2723 | and @var{substitutable?}. | |
874e6874 LC |
2724 | @end deffn |
2725 | ||
2726 | @noindent | |
2727 | Here's an example of a single-output derivation that creates a directory | |
2728 | containing one file: | |
2729 | ||
2730 | @lisp | |
2731 | (let ((builder '(let ((out (assoc-ref %outputs "out"))) | |
834129e0 | 2732 | (mkdir out) ; create /gnu/store/@dots{}-goo |
874e6874 LC |
2733 | (call-with-output-file (string-append out "/test") |
2734 | (lambda (p) | |
2735 | (display '(hello guix) p)))))) | |
dd1a5a15 | 2736 | (build-expression->derivation store "goo" builder)) |
874e6874 | 2737 | |
834129e0 | 2738 | @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}> |
874e6874 LC |
2739 | @end lisp |
2740 | ||
568717fd | 2741 | |
b860f382 LC |
2742 | @node The Store Monad |
2743 | @section The Store Monad | |
2744 | ||
2745 | @cindex monad | |
2746 | ||
2747 | The procedures that operate on the store described in the previous | |
2748 | sections all take an open connection to the build daemon as their first | |
2749 | argument. Although the underlying model is functional, they either have | |
2750 | side effects or depend on the current state of the store. | |
2751 | ||
2752 | The former is inconvenient: the connection to the build daemon has to be | |
2753 | carried around in all those functions, making it impossible to compose | |
2754 | functions that do not take that parameter with functions that do. The | |
2755 | latter can be problematic: since store operations have side effects | |
2756 | and/or depend on external state, they have to be properly sequenced. | |
2757 | ||
2758 | @cindex monadic values | |
2759 | @cindex monadic functions | |
2760 | This is where the @code{(guix monads)} module comes in. This module | |
2761 | provides a framework for working with @dfn{monads}, and a particularly | |
2762 | useful monad for our uses, the @dfn{store monad}. Monads are a | |
2763 | construct that allows two things: associating ``context'' with values | |
2764 | (in our case, the context is the store), and building sequences of | |
561fb6c3 | 2765 | computations (here computations include accesses to the store.) Values |
b860f382 LC |
2766 | in a monad---values that carry this additional context---are called |
2767 | @dfn{monadic values}; procedures that return such values are called | |
2768 | @dfn{monadic procedures}. | |
2769 | ||
2770 | Consider this ``normal'' procedure: | |
2771 | ||
2772 | @example | |
45adbd62 LC |
2773 | (define (sh-symlink store) |
2774 | ;; Return a derivation that symlinks the 'bash' executable. | |
2775 | (let* ((drv (package-derivation store bash)) | |
2776 | (out (derivation->output-path drv)) | |
2777 | (sh (string-append out "/bin/bash"))) | |
2778 | (build-expression->derivation store "sh" | |
2779 | `(symlink ,sh %output)))) | |
b860f382 LC |
2780 | @end example |
2781 | ||
c6f30b81 LC |
2782 | Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten |
2783 | as a monadic function: | |
b860f382 LC |
2784 | |
2785 | @example | |
45adbd62 | 2786 | (define (sh-symlink) |
b860f382 | 2787 | ;; Same, but return a monadic value. |
c6f30b81 LC |
2788 | (mlet %store-monad ((drv (package->derivation bash))) |
2789 | (gexp->derivation "sh" | |
2790 | #~(symlink (string-append #$drv "/bin/bash") | |
2791 | #$output)))) | |
b860f382 LC |
2792 | @end example |
2793 | ||
c6f30b81 LC |
2794 | There several things to note in the second version: the @code{store} |
2795 | parameter is now implicit and is ``threaded'' in the calls to the | |
2796 | @code{package->derivation} and @code{gexp->derivation} monadic | |
2797 | procedures, and the monadic value returned by @code{package->derivation} | |
2798 | is @dfn{bound} using @code{mlet} instead of plain @code{let}. | |
2799 | ||
2800 | As it turns out, the call to @code{package->derivation} can even be | |
2801 | omitted since it will take place implicitly, as we will see later | |
2802 | (@pxref{G-Expressions}): | |
2803 | ||
2804 | @example | |
2805 | (define (sh-symlink) | |
2806 | (gexp->derivation "sh" | |
2807 | #~(symlink (string-append #$bash "/bin/bash") | |
2808 | #$output))) | |
2809 | @end example | |
b860f382 | 2810 | |
7ce21611 LC |
2811 | @c See |
2812 | @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/> | |
2813 | @c for the funny quote. | |
2814 | Calling the monadic @code{sh-symlink} has no effect. As someone once | |
2815 | said, ``you exit a monad like you exit a building on fire: by running''. | |
2816 | So, to exit the monad and get the desired effect, one must use | |
2817 | @code{run-with-store}: | |
b860f382 LC |
2818 | |
2819 | @example | |
8e9aa37f CAW |
2820 | (run-with-store (open-connection) (sh-symlink)) |
2821 | @result{} /gnu/store/...-sh-symlink | |
b860f382 LC |
2822 | @end example |
2823 | ||
b9b86078 LC |
2824 | Note that the @code{(guix monad-repl)} module extends Guile's REPL with |
2825 | new ``meta-commands'' to make it easier to deal with monadic procedures: | |
2826 | @code{run-in-store}, and @code{enter-store-monad}. The former, is used | |
2827 | to ``run'' a single monadic value through the store: | |
2828 | ||
2829 | @example | |
2830 | scheme@@(guile-user)> ,run-in-store (package->derivation hello) | |
2831 | $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}> | |
2832 | @end example | |
2833 | ||
2834 | The latter enters a recursive REPL, where all the return values are | |
2835 | automatically run through the store: | |
2836 | ||
2837 | @example | |
2838 | scheme@@(guile-user)> ,enter-store-monad | |
2839 | store-monad@@(guile-user) [1]> (package->derivation hello) | |
2840 | $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}> | |
2841 | store-monad@@(guile-user) [1]> (text-file "foo" "Hello!") | |
2842 | $3 = "/gnu/store/@dots{}-foo" | |
2843 | store-monad@@(guile-user) [1]> ,q | |
2844 | scheme@@(guile-user)> | |
2845 | @end example | |
2846 | ||
2847 | @noindent | |
2848 | Note that non-monadic values cannot be returned in the | |
2849 | @code{store-monad} REPL. | |
2850 | ||
e87f0591 LC |
2851 | The main syntactic forms to deal with monads in general are provided by |
2852 | the @code{(guix monads)} module and are described below. | |
b860f382 LC |
2853 | |
2854 | @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ... | |
2855 | Evaluate any @code{>>=} or @code{return} forms in @var{body} as being | |
2856 | in @var{monad}. | |
2857 | @end deffn | |
2858 | ||
2859 | @deffn {Scheme Syntax} return @var{val} | |
2860 | Return a monadic value that encapsulates @var{val}. | |
2861 | @end deffn | |
2862 | ||
751630c9 | 2863 | @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ... |
b860f382 | 2864 | @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic |
751630c9 LC |
2865 | procedures @var{mproc}@dots{}@footnote{This operation is commonly |
2866 | referred to as ``bind'', but that name denotes an unrelated procedure in | |
2867 | Guile. Thus we use this somewhat cryptic symbol inherited from the | |
2868 | Haskell language.}. There can be one @var{mproc} or several of them, as | |
2869 | in this example: | |
2870 | ||
2871 | @example | |
2872 | (run-with-state | |
2873 | (with-monad %state-monad | |
2874 | (>>= (return 1) | |
2875 | (lambda (x) (return (+ 1 x))) | |
2876 | (lambda (x) (return (* 2 x))))) | |
2877 | 'some-state) | |
2878 | ||
2879 | @result{} 4 | |
2880 | @result{} some-state | |
2881 | @end example | |
b860f382 LC |
2882 | @end deffn |
2883 | ||
2884 | @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @ | |
2885 | @var{body} ... | |
2886 | @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @ | |
2887 | @var{body} ... | |
2888 | Bind the variables @var{var} to the monadic values @var{mval} in | |
2889 | @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the | |
2890 | ``normal'' value @var{val}, as per @code{let}. | |
2891 | ||
2892 | @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let} | |
2893 | (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}). | |
2894 | @end deffn | |
2895 | ||
405a9d4e LC |
2896 | @deffn {Scheme System} mbegin @var{monad} @var{mexp} ... |
2897 | Bind @var{mexp} and the following monadic expressions in sequence, | |
2898 | returning the result of the last expression. | |
2899 | ||
2900 | This is akin to @code{mlet}, except that the return values of the | |
2901 | monadic expressions are ignored. In that sense, it is analogous to | |
2902 | @code{begin}, but applied to monadic expressions. | |
2903 | @end deffn | |
2904 | ||
561fb6c3 LC |
2905 | @cindex state monad |
2906 | The @code{(guix monads)} module provides the @dfn{state monad}, which | |
2907 | allows an additional value---the state---to be @emph{threaded} through | |
2908 | monadic procedure calls. | |
2909 | ||
2910 | @defvr {Scheme Variable} %state-monad | |
2911 | The state monad. Procedures in the state monad can access and change | |
2912 | the state that is threaded. | |
2913 | ||
2914 | Consider the example below. The @code{square} procedure returns a value | |
2915 | in the state monad. It returns the square of its argument, but also | |
2916 | increments the current state value: | |
2917 | ||
2918 | @example | |
2919 | (define (square x) | |
2920 | (mlet %state-monad ((count (current-state))) | |
2921 | (mbegin %state-monad | |
2922 | (set-current-state (+ 1 count)) | |
2923 | (return (* x x))))) | |
2924 | ||
2925 | (run-with-state (sequence %state-monad (map square (iota 3))) 0) | |
2926 | @result{} (0 1 4) | |
2927 | @result{} 3 | |
2928 | @end example | |
2929 | ||
2930 | When ``run'' through @var{%state-monad}, we obtain that additional state | |
2931 | value, which is the number of @code{square} calls. | |
2932 | @end defvr | |
2933 | ||
2934 | @deffn {Monadic Procedure} current-state | |
2935 | Return the current state as a monadic value. | |
2936 | @end deffn | |
2937 | ||
2938 | @deffn {Monadic Procedure} set-current-state @var{value} | |
2939 | Set the current state to @var{value} and return the previous state as a | |
2940 | monadic value. | |
2941 | @end deffn | |
2942 | ||
2943 | @deffn {Monadic Procedure} state-push @var{value} | |
2944 | Push @var{value} to the current state, which is assumed to be a list, | |
2945 | and return the previous state as a monadic value. | |
2946 | @end deffn | |
2947 | ||
2948 | @deffn {Monadic Procedure} state-pop | |
2949 | Pop a value from the current state and return it as a monadic value. | |
2950 | The state is assumed to be a list. | |
2951 | @end deffn | |
2952 | ||
2953 | @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}] | |
2954 | Run monadic value @var{mval} starting with @var{state} as the initial | |
2955 | state. Return two values: the resulting value, and the resulting state. | |
2956 | @end deffn | |
2957 | ||
e87f0591 LC |
2958 | The main interface to the store monad, provided by the @code{(guix |
2959 | store)} module, is as follows. | |
b860f382 LC |
2960 | |
2961 | @defvr {Scheme Variable} %store-monad | |
561fb6c3 LC |
2962 | The store monad---an alias for @var{%state-monad}. |
2963 | ||
2964 | Values in the store monad encapsulate accesses to the store. When its | |
2965 | effect is needed, a value of the store monad must be ``evaluated'' by | |
2966 | passing it to the @code{run-with-store} procedure (see below.) | |
b860f382 LC |
2967 | @end defvr |
2968 | ||
2969 | @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)] | |
2970 | Run @var{mval}, a monadic value in the store monad, in @var{store}, an | |
2971 | open store connection. | |
2972 | @end deffn | |
2973 | ||
ad372953 | 2974 | @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}] |
b860f382 | 2975 | Return as a monadic value the absolute file name in the store of the file |
ad372953 LC |
2976 | containing @var{text}, a string. @var{references} is a list of store items that the |
2977 | resulting text file refers to; it defaults to the empty list. | |
45adbd62 LC |
2978 | @end deffn |
2979 | ||
0a90af15 LC |
2980 | @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @ |
2981 | [#:recursive? #t] | |
2982 | Return the name of @var{file} once interned in the store. Use | |
2983 | @var{name} as its store name, or the basename of @var{file} if | |
2984 | @var{name} is omitted. | |
2985 | ||
2986 | When @var{recursive?} is true, the contents of @var{file} are added | |
2987 | recursively; if @var{file} designates a flat file and @var{recursive?} | |
2988 | is true, its contents are added, and its permission bits are kept. | |
2989 | ||
2990 | The example below adds a file to the store, under two different names: | |
2991 | ||
2992 | @example | |
2993 | (run-with-store (open-connection) | |
2994 | (mlet %store-monad ((a (interned-file "README")) | |
2995 | (b (interned-file "README" "LEGU-MIN"))) | |
2996 | (return (list a b)))) | |
2997 | ||
2998 | @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN") | |
2999 | @end example | |
3000 | ||
3001 | @end deffn | |
3002 | ||
e87f0591 LC |
3003 | The @code{(guix packages)} module exports the following package-related |
3004 | monadic procedures: | |
3005 | ||
b860f382 | 3006 | @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @ |
4231f05b LC |
3007 | [#:system (%current-system)] [#:target #f] @ |
3008 | [#:output "out"] Return as a monadic | |
b860f382 LC |
3009 | value in the absolute file name of @var{file} within the @var{output} |
3010 | directory of @var{package}. When @var{file} is omitted, return the name | |
4231f05b LC |
3011 | of the @var{output} directory of @var{package}. When @var{target} is |
3012 | true, use it as a cross-compilation target triplet. | |
b860f382 LC |
3013 | @end deffn |
3014 | ||
b860f382 | 3015 | @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}] |
4231f05b LC |
3016 | @deffnx {Monadic Procedure} package->cross-derivation @var{package} @ |
3017 | @var{target} [@var{system}] | |
3018 | Monadic version of @code{package-derivation} and | |
3019 | @code{package-cross-derivation} (@pxref{Defining Packages}). | |
b860f382 LC |
3020 | @end deffn |
3021 | ||
3022 | ||
21b679f6 LC |
3023 | @node G-Expressions |
3024 | @section G-Expressions | |
3025 | ||
3026 | @cindex G-expression | |
3027 | @cindex build code quoting | |
3028 | So we have ``derivations'', which represent a sequence of build actions | |
3029 | to be performed to produce an item in the store (@pxref{Derivations}). | |
3030 | Those build actions are performed when asking the daemon to actually | |
3031 | build the derivations; they are run by the daemon in a container | |
3032 | (@pxref{Invoking guix-daemon}). | |
3033 | ||
3034 | @cindex strata of code | |
3035 | It should come as no surprise that we like to write those build actions | |
3036 | in Scheme. When we do that, we end up with two @dfn{strata} of Scheme | |
3037 | code@footnote{The term @dfn{stratum} in this context was coined by | |
ef4ab0a4 LC |
3038 | Manuel Serrano et al.@: in the context of their work on Hop. Oleg |
3039 | Kiselyov, who has written insightful | |
3040 | @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code | |
3041 | on this topic}, refers to this kind of code generation as | |
3042 | @dfn{staging}.}: the ``host code''---code that defines packages, talks | |
3043 | to the daemon, etc.---and the ``build code''---code that actually | |
3044 | performs build actions, such as making directories, invoking | |
3045 | @command{make}, etc. | |
21b679f6 LC |
3046 | |
3047 | To describe a derivation and its build actions, one typically needs to | |
3048 | embed build code inside host code. It boils down to manipulating build | |
3049 | code as data, and Scheme's homoiconicity---code has a direct | |
3050 | representation as data---comes in handy for that. But we need more than | |
3051 | Scheme's normal @code{quasiquote} mechanism to construct build | |
3052 | expressions. | |
3053 | ||
3054 | The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of | |
3055 | S-expressions adapted to build expressions. G-expressions, or | |
3056 | @dfn{gexps}, consist essentially in three syntactic forms: @code{gexp}, | |
3057 | @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~}, | |
3058 | @code{#$}, and @code{#$@@}), which are comparable respectively to | |
3059 | @code{quasiquote}, @code{unquote}, and @code{unquote-splicing} | |
3060 | (@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile | |
3061 | Reference Manual}). However, there are major differences: | |
3062 | ||
3063 | @itemize | |
3064 | @item | |
3065 | Gexps are meant to be written to a file and run or manipulated by other | |
3066 | processes. | |
3067 | ||
3068 | @item | |
b39fc6f7 LC |
3069 | When a high-level object such as a package or derivation is unquoted |
3070 | inside a gexp, the result is as if its output file name had been | |
3071 | introduced. | |
ff40e9b7 | 3072 | |
21b679f6 LC |
3073 | @item |
3074 | Gexps carry information about the packages or derivations they refer to, | |
3075 | and these dependencies are automatically added as inputs to the build | |
3076 | processes that use them. | |
3077 | @end itemize | |
3078 | ||
343eacbe LC |
3079 | This mechanism is not limited to package and derivation |
3080 | objects: @dfn{compilers} able to ``lower'' other high-level objects to | |
b39fc6f7 | 3081 | derivations can be defined, such that these objects can also be inserted |
343eacbe LC |
3082 | into gexps. For example, a useful type of high-level object that can be |
3083 | inserted in a gexp is ``file-like objects'', which make it easy to | |
3084 | add files to the store and refer to them in | |
558e8b11 LC |
3085 | derivations and such (see @code{local-file} and @code{plain-file} |
3086 | below.) | |
b39fc6f7 | 3087 | |
21b679f6 LC |
3088 | To illustrate the idea, here is an example of a gexp: |
3089 | ||
3090 | @example | |
3091 | (define build-exp | |
3092 | #~(begin | |
3093 | (mkdir #$output) | |
3094 | (chdir #$output) | |
aff8ce7c | 3095 | (symlink (string-append #$coreutils "/bin/ls") |
21b679f6 LC |
3096 | "list-files"))) |
3097 | @end example | |
3098 | ||
3099 | This gexp can be passed to @code{gexp->derivation}; we obtain a | |
3100 | derivation that builds a directory containing exactly one symlink to | |
3101 | @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}: | |
3102 | ||
3103 | @example | |
3104 | (gexp->derivation "the-thing" build-exp) | |
3105 | @end example | |
3106 | ||
e20fd1bf | 3107 | As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is |
21b679f6 LC |
3108 | substituted to the reference to the @var{coreutils} package in the |
3109 | actual build code, and @var{coreutils} is automatically made an input to | |
3110 | the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp | |
3111 | output)}) is replaced by a string containing the derivation's output | |
667b2508 LC |
3112 | directory name. |
3113 | ||
3114 | @cindex cross compilation | |
3115 | In a cross-compilation context, it is useful to distinguish between | |
3116 | references to the @emph{native} build of a package---that can run on the | |
3117 | host---versus references to cross builds of a package. To that end, the | |
3118 | @code{#+} plays the same role as @code{#$}, but is a reference to a | |
3119 | native package build: | |
3120 | ||
3121 | @example | |
3122 | (gexp->derivation "vi" | |
3123 | #~(begin | |
3124 | (mkdir #$output) | |
3125 | (system* (string-append #+coreutils "/bin/ln") | |
3126 | "-s" | |
3127 | (string-append #$emacs "/bin/emacs") | |
3128 | (string-append #$output "/bin/vi"))) | |
3129 | #:target "mips64el-linux") | |
3130 | @end example | |
3131 | ||
3132 | @noindent | |
3133 | In the example above, the native build of @var{coreutils} is used, so | |
3134 | that @command{ln} can actually run on the host; but then the | |
3135 | cross-compiled build of @var{emacs} is referenced. | |
3136 | ||
3137 | The syntactic form to construct gexps is summarized below. | |
21b679f6 LC |
3138 | |
3139 | @deffn {Scheme Syntax} #~@var{exp} | |
3140 | @deffnx {Scheme Syntax} (gexp @var{exp}) | |
3141 | Return a G-expression containing @var{exp}. @var{exp} may contain one | |
3142 | or more of the following forms: | |
3143 | ||
3144 | @table @code | |
3145 | @item #$@var{obj} | |
3146 | @itemx (ungexp @var{obj}) | |
b39fc6f7 LC |
3147 | Introduce a reference to @var{obj}. @var{obj} may have one of the |
3148 | supported types, for example a package or a | |
21b679f6 LC |
3149 | derivation, in which case the @code{ungexp} form is replaced by its |
3150 | output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}. | |
3151 | ||
b39fc6f7 LC |
3152 | If @var{obj} is a list, it is traversed and references to supported |
3153 | objects are substituted similarly. | |
21b679f6 LC |
3154 | |
3155 | If @var{obj} is another gexp, its contents are inserted and its | |
3156 | dependencies are added to those of the containing gexp. | |
3157 | ||
3158 | If @var{obj} is another kind of object, it is inserted as is. | |
3159 | ||
b39fc6f7 LC |
3160 | @item #$@var{obj}:@var{output} |
3161 | @itemx (ungexp @var{obj} @var{output}) | |
21b679f6 | 3162 | This is like the form above, but referring explicitly to the |
b39fc6f7 LC |
3163 | @var{output} of @var{obj}---this is useful when @var{obj} produces |
3164 | multiple outputs (@pxref{Packages with Multiple Outputs}). | |
21b679f6 | 3165 | |
667b2508 LC |
3166 | @item #+@var{obj} |
3167 | @itemx #+@var{obj}:output | |
3168 | @itemx (ungexp-native @var{obj}) | |
3169 | @itemx (ungexp-native @var{obj} @var{output}) | |
3170 | Same as @code{ungexp}, but produces a reference to the @emph{native} | |
3171 | build of @var{obj} when used in a cross compilation context. | |
3172 | ||
21b679f6 LC |
3173 | @item #$output[:@var{output}] |
3174 | @itemx (ungexp output [@var{output}]) | |
3175 | Insert a reference to derivation output @var{output}, or to the main | |
3176 | output when @var{output} is omitted. | |
3177 | ||
3178 | This only makes sense for gexps passed to @code{gexp->derivation}. | |
3179 | ||
3180 | @item #$@@@var{lst} | |
3181 | @itemx (ungexp-splicing @var{lst}) | |
3182 | Like the above, but splices the contents of @var{lst} inside the | |
3183 | containing list. | |
3184 | ||
667b2508 LC |
3185 | @item #+@@@var{lst} |
3186 | @itemx (ungexp-native-splicing @var{lst}) | |
3187 | Like the above, but refers to native builds of the objects listed in | |
3188 | @var{lst}. | |
3189 | ||
21b679f6 LC |
3190 | @end table |
3191 | ||
3192 | G-expressions created by @code{gexp} or @code{#~} are run-time objects | |
3193 | of the @code{gexp?} type (see below.) | |
3194 | @end deffn | |
3195 | ||
3196 | @deffn {Scheme Procedure} gexp? @var{obj} | |
3197 | Return @code{#t} if @var{obj} is a G-expression. | |
3198 | @end deffn | |
3199 | ||
3200 | G-expressions are meant to be written to disk, either as code building | |
3201 | some derivation, or as plain files in the store. The monadic procedures | |
3202 | below allow you to do that (@pxref{The Store Monad}, for more | |
3203 | information about monads.) | |
3204 | ||
3205 | @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @ | |
ce45eb4c | 3206 | [#:system (%current-system)] [#:target #f] [#:graft? #t] @ |
21b679f6 LC |
3207 | [#:hash #f] [#:hash-algo #f] @ |
3208 | [#:recursive? #f] [#:env-vars '()] [#:modules '()] @ | |
4684f301 | 3209 | [#:module-path @var{%load-path}] @ |
c8351d9a | 3210 | [#:references-graphs #f] [#:allowed-references #f] @ |
c0468155 | 3211 | [#:leaked-env-vars #f] @ |
4a6aeb67 | 3212 | [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f] |
21b679f6 | 3213 | Return a derivation @var{name} that runs @var{exp} (a gexp) with |
68a61e9f LC |
3214 | @var{guile-for-build} (a derivation) on @var{system}. When @var{target} |
3215 | is true, it is used as the cross-compilation target triplet for packages | |
3216 | referred to by @var{exp}. | |
21b679f6 | 3217 | |
ce45eb4c LC |
3218 | Make @var{modules} available in the evaluation context of @var{exp}; |
3219 | @var{modules} is a list of names of Guile modules searched in | |
3220 | @var{module-path} to be copied in the store, compiled, and made available in | |
21b679f6 LC |
3221 | the load path during the execution of @var{exp}---e.g., @code{((guix |
3222 | build utils) (guix build gnu-build-system))}. | |
3223 | ||
ce45eb4c LC |
3224 | @var{graft?} determines whether packages referred to by @var{exp} should be grafted when |
3225 | applicable. | |
3226 | ||
b53833b2 LC |
3227 | When @var{references-graphs} is true, it must be a list of tuples of one of the |
3228 | following forms: | |
3229 | ||
3230 | @example | |
3231 | (@var{file-name} @var{package}) | |
3232 | (@var{file-name} @var{package} @var{output}) | |
3233 | (@var{file-name} @var{derivation}) | |
3234 | (@var{file-name} @var{derivation} @var{output}) | |
3235 | (@var{file-name} @var{store-item}) | |
3236 | @end example | |
3237 | ||
3238 | The right-hand-side of each element of @var{references-graphs} is automatically made | |
3239 | an input of the build process of @var{exp}. In the build environment, each | |
3240 | @var{file-name} contains the reference graph of the corresponding item, in a simple | |
3241 | text format. | |
3242 | ||
c8351d9a LC |
3243 | @var{allowed-references} must be either @code{#f} or a list of output names and packages. |
3244 | In the latter case, the list denotes store items that the result is allowed to | |
3245 | refer to. Any reference to another store item will lead to a build error. | |
3246 | ||
e20fd1bf | 3247 | The other arguments are as for @code{derivation} (@pxref{Derivations}). |
21b679f6 LC |
3248 | @end deffn |
3249 | ||
343eacbe LC |
3250 | @cindex file-like objects |
3251 | The @code{local-file} and @code{plain-file} procedures below return | |
3252 | @dfn{file-like objects}. That is, when unquoted in a G-expression, | |
3253 | these objects lead to a file in the store. Consider this G-expression: | |
3254 | ||
3255 | @example | |
3256 | #~(system* (string-append #$glibc "/sbin/nscd") "-f" | |
3257 | #$(local-file "/tmp/my-nscd.conf")) | |
3258 | @end example | |
3259 | ||
3260 | The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it | |
3261 | to the store. Once expanded, for instance @i{via} | |
3262 | @code{gexp->derivation}, the G-expression refers to that copy under | |
3263 | @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp} | |
3264 | does not have any effect on what the G-expression does. | |
3265 | @code{plain-file} can be used similarly; it differs in that the file | |
3266 | content is directly passed as a string. | |
3267 | ||
d9ae938f LC |
3268 | @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @ |
3269 | [#:recursive? #t] | |
3270 | Return an object representing local file @var{file} to add to the store; this | |
3271 | object can be used in a gexp. @var{file} will be added to the store under @var{name}--by | |
3272 | default the base name of @var{file}. | |
3273 | ||
3274 | When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file} | |
3275 | designates a flat file and @var{recursive?} is true, its contents are added, and its | |
3276 | permission bits are kept. | |
3277 | ||
3278 | This is the declarative counterpart of the @code{interned-file} monadic | |
3279 | procedure (@pxref{The Store Monad, @code{interned-file}}). | |
3280 | @end deffn | |
3281 | ||
558e8b11 LC |
3282 | @deffn {Scheme Procedure} plain-file @var{name} @var{content} |
3283 | Return an object representing a text file called @var{name} with the given | |
3284 | @var{content} (a string) to be added to the store. | |
3285 | ||
3286 | This is the declarative counterpart of @code{text-file}. | |
3287 | @end deffn | |
3288 | ||
21b679f6 LC |
3289 | @deffn {Monadic Procedure} gexp->script @var{name} @var{exp} |
3290 | Return an executable script @var{name} that runs @var{exp} using | |
3291 | @var{guile} with @var{modules} in its search path. | |
3292 | ||
3293 | The example below builds a script that simply invokes the @command{ls} | |
3294 | command: | |
3295 | ||
3296 | @example | |
3297 | (use-modules (guix gexp) (gnu packages base)) | |
3298 | ||
3299 | (gexp->script "list-files" | |
3300 | #~(execl (string-append #$coreutils "/bin/ls") | |
3301 | "ls")) | |
3302 | @end example | |
3303 | ||
3304 | When ``running'' it through the store (@pxref{The Store Monad, | |
e20fd1bf | 3305 | @code{run-with-store}}), we obtain a derivation that produces an |
21b679f6 LC |
3306 | executable file @file{/gnu/store/@dots{}-list-files} along these lines: |
3307 | ||
3308 | @example | |
3309 | #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds | |
3310 | !# | |
3311 | (execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls") | |
3312 | "ls") | |
3313 | @end example | |
3314 | @end deffn | |
3315 | ||
3316 | @deffn {Monadic Procedure} gexp->file @var{name} @var{exp} | |
3317 | Return a derivation that builds a file @var{name} containing @var{exp}. | |
3318 | ||
3319 | The resulting file holds references to all the dependencies of @var{exp} | |
3320 | or a subset thereof. | |
3321 | @end deffn | |
1ed19464 LC |
3322 | |
3323 | @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{} | |
3324 | Return as a monadic value a derivation that builds a text file | |
3325 | containing all of @var{text}. @var{text} may list, in addition to | |
d9ae938f LC |
3326 | strings, objects of any type that can be used in a gexp: packages, |
3327 | derivations, local file objects, etc. The resulting store file holds | |
3328 | references to all these. | |
1ed19464 LC |
3329 | |
3330 | This variant should be preferred over @code{text-file} anytime the file | |
3331 | to create will reference items from the store. This is typically the | |
3332 | case when building a configuration file that embeds store file names, | |
3333 | like this: | |
3334 | ||
3335 | @example | |
3336 | (define (profile.sh) | |
3337 | ;; Return the name of a shell script in the store that | |
3338 | ;; initializes the 'PATH' environment variable. | |
3339 | (text-file* "profile.sh" | |
3340 | "export PATH=" coreutils "/bin:" | |
3341 | grep "/bin:" sed "/bin\n")) | |
3342 | @end example | |
3343 | ||
3344 | In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file | |
3345 | will references @var{coreutils}, @var{grep}, and @var{sed}, thereby | |
3346 | preventing them from being garbage-collected during its lifetime. | |
3347 | @end deffn | |
21b679f6 LC |
3348 | |
3349 | Of course, in addition to gexps embedded in ``host'' code, there are | |
3350 | also modules containing build tools. To make it clear that they are | |
3351 | meant to be used in the build stratum, these modules are kept in the | |
3352 | @code{(guix build @dots{})} name space. | |
3353 | ||
3354 | ||
568717fd LC |
3355 | @c ********************************************************************* |
3356 | @node Utilities | |
3357 | @chapter Utilities | |
3358 | ||
210cc920 LC |
3359 | This section describes tools primarily targeted at developers and users |
3360 | who write new package definitions. They complement the Scheme | |
3361 | programming interface of Guix in a convenient way. | |
3362 | ||
568717fd | 3363 | @menu |
37166310 | 3364 | * Invoking guix build:: Building packages from the command line. |
39bee8a2 | 3365 | * Invoking guix edit:: Editing package definitions. |
210cc920 | 3366 | * Invoking guix download:: Downloading a file and printing its hash. |
37166310 | 3367 | * Invoking guix hash:: Computing the cryptographic hash of a file. |
2f7d2d91 | 3368 | * Invoking guix import:: Importing package definitions. |
37166310 | 3369 | * Invoking guix refresh:: Updating package definitions. |
b4f5e0e8 | 3370 | * Invoking guix lint:: Finding errors in package definitions. |
fcc58db6 | 3371 | * Invoking guix size:: Profiling disk usage. |
372c4bbc | 3372 | * Invoking guix environment:: Setting up development environments. |
aff8ce7c | 3373 | * Invoking guix publish:: Sharing substitutes. |
568717fd LC |
3374 | @end menu |
3375 | ||
e49951eb MW |
3376 | @node Invoking guix build |
3377 | @section Invoking @command{guix build} | |
568717fd | 3378 | |
e49951eb | 3379 | The @command{guix build} command builds packages or derivations and |
6798a8e4 LC |
3380 | their dependencies, and prints the resulting store paths. Note that it |
3381 | does not modify the user's profile---this is the job of the | |
e49951eb | 3382 | @command{guix package} command (@pxref{Invoking guix package}). Thus, |
6798a8e4 LC |
3383 | it is mainly useful for distribution developers. |
3384 | ||
3385 | The general syntax is: | |
c78bd12b LC |
3386 | |
3387 | @example | |
e49951eb | 3388 | guix build @var{options} @var{package-or-derivation}@dots{} |
c78bd12b LC |
3389 | @end example |
3390 | ||
3391 | @var{package-or-derivation} may be either the name of a package found in | |
5401dd75 LC |
3392 | the software distribution such as @code{coreutils} or |
3393 | @code{coreutils-8.20}, or a derivation such as | |
834129e0 | 3394 | @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a |
e7f34eb0 LC |
3395 | package with the corresponding name (and optionally version) is searched |
3396 | for among the GNU distribution modules (@pxref{Package Modules}). | |
3397 | ||
3398 | Alternatively, the @code{--expression} option may be used to specify a | |
3399 | Scheme expression that evaluates to a package; this is useful when | |
3400 | disambiguation among several same-named packages or package variants is | |
3401 | needed. | |
c78bd12b LC |
3402 | |
3403 | The @var{options} may be zero or more of the following: | |
3404 | ||
3405 | @table @code | |
3406 | ||
3407 | @item --expression=@var{expr} | |
3408 | @itemx -e @var{expr} | |
ac5de156 | 3409 | Build the package or derivation @var{expr} evaluates to. |
c78bd12b | 3410 | |
5401dd75 | 3411 | For example, @var{expr} may be @code{(@@ (gnu packages guile) |
c78bd12b LC |
3412 | guile-1.8)}, which unambiguously designates this specific variant of |
3413 | version 1.8 of Guile. | |
3414 | ||
56b82106 LC |
3415 | Alternately, @var{expr} may be a G-expression, in which case it is used |
3416 | as a build program passed to @code{gexp->derivation} | |
3417 | (@pxref{G-Expressions}). | |
3418 | ||
3419 | Lastly, @var{expr} may refer to a zero-argument monadic procedure | |
ac5de156 LC |
3420 | (@pxref{The Store Monad}). The procedure must return a derivation as a |
3421 | monadic value, which is then passed through @code{run-with-store}. | |
3422 | ||
c78bd12b LC |
3423 | @item --source |
3424 | @itemx -S | |
3425 | Build the packages' source derivations, rather than the packages | |
3426 | themselves. | |
3427 | ||
e49951eb | 3428 | For instance, @code{guix build -S gcc} returns something like |
834129e0 | 3429 | @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball. |
c78bd12b | 3430 | |
f9cc8971 LC |
3431 | The returned source tarball is the result of applying any patches and |
3432 | code snippets specified in the package's @code{origin} (@pxref{Defining | |
3433 | Packages}). | |
3434 | ||
2cdfe13d EB |
3435 | @item --sources |
3436 | Fetch and return the source of @var{package-or-derivation} and all their | |
3437 | dependencies, recursively. This is a handy way to obtain a local copy | |
3438 | of all the source code needed to build @var{packages}, allowing you to | |
3439 | eventually build them even without network access. It is an extension | |
3440 | of the @code{--source} option and can accept one of the following | |
3441 | optional argument values: | |
3442 | ||
3443 | @table @code | |
3444 | @item package | |
3445 | This value causes the @code{--sources} option to behave in the same way | |
3446 | as the @code{--source} option. | |
3447 | ||
3448 | @item all | |
3449 | Build all packages' source derivations, including any source that might | |
3450 | be listed as @code{inputs}. This is the default value. | |
3451 | ||
3452 | @example | |
3453 | $ guix build --sources tzdata | |
3454 | The following derivations will be built: | |
3455 | /gnu/store/@dots{}-tzdata2015b.tar.gz.drv | |
3456 | /gnu/store/@dots{}-tzcode2015b.tar.gz.drv | |
3457 | @end example | |
3458 | ||
3459 | @item transitive | |
3460 | Build all packages' source derivations, as well as all source | |
3461 | derivations for packages' transitive inputs. This can be used e.g. to | |
3462 | prefetch package source for later offline building. | |
3463 | ||
3464 | @example | |
3465 | $ guix build --sources=transitive tzdata | |
3466 | The following derivations will be built: | |
3467 | /gnu/store/@dots{}-tzcode2015b.tar.gz.drv | |
3468 | /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv | |
3469 | /gnu/store/@dots{}-grep-2.21.tar.xz.drv | |
3470 | /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv | |
3471 | /gnu/store/@dots{}-make-4.1.tar.xz.drv | |
3472 | /gnu/store/@dots{}-bash-4.3.tar.xz.drv | |
3473 | @dots{} | |
3474 | @end example | |
3475 | ||
3476 | @end table | |
3477 | ||
c78bd12b LC |
3478 | @item --system=@var{system} |
3479 | @itemx -s @var{system} | |
3480 | Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of | |
3481 | the host's system type. | |
3482 | ||
3483 | An example use of this is on Linux-based systems, which can emulate | |
3484 | different personalities. For instance, passing | |
3485 | @code{--system=i686-linux} on an @code{x86_64-linux} system allows users | |
3486 | to build packages in a complete 32-bit environment. | |
3487 | ||
e55ec43d LC |
3488 | @item --target=@var{triplet} |
3489 | @cindex cross-compilation | |
3490 | Cross-build for @var{triplet}, which must be a valid GNU triplet, such | |
3491 | as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU | |
3492 | configuration triplets,, configure, GNU Configure and Build System}). | |
3493 | ||
7f3673f2 LC |
3494 | @item --with-source=@var{source} |
3495 | Use @var{source} as the source of the corresponding package. | |
3496 | @var{source} must be a file name or a URL, as for @command{guix | |
3497 | download} (@pxref{Invoking guix download}). | |
3498 | ||
3499 | The ``corresponding package'' is taken to be one specified on the | |
3500 | command line whose name matches the base of @var{source}---e.g., if | |
3501 | @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding | |
3502 | package is @code{guile}. Likewise, the version string is inferred from | |
3503 | @var{source}; in the previous example, it's @code{2.0.10}. | |
3504 | ||
3505 | This option allows users to try out versions of packages other than the | |
3506 | one provided by the distribution. The example below downloads | |
3507 | @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for | |
3508 | the @code{ed} package: | |
3509 | ||
3510 | @example | |
3511 | guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz | |
3512 | @end example | |
3513 | ||
3514 | As a developer, @code{--with-source} makes it easy to test release | |
3515 | candidates: | |
3516 | ||
3517 | @example | |
3518 | guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz | |
3519 | @end example | |
3520 | ||
a43b55f1 LC |
3521 | @dots{} or to build from a checkout in a pristine environment: |
3522 | ||
3523 | @example | |
3524 | $ git clone git://git.sv.gnu.org/guix.git | |
3525 | $ guix build guix --with-source=./guix | |
3526 | @end example | |
3527 | ||
05962f29 LC |
3528 | @item --no-grafts |
3529 | Do not ``graft'' packages. In practice, this means that package updates | |
3530 | available as grafts are not applied. @xref{Security Updates}, for more | |
3531 | information on grafts. | |
7f3673f2 | 3532 | |
c78bd12b LC |
3533 | @item --derivations |
3534 | @itemx -d | |
3535 | Return the derivation paths, not the output paths, of the given | |
3536 | packages. | |
3537 | ||
70ee5642 LC |
3538 | @item --root=@var{file} |
3539 | @itemx -r @var{file} | |
3540 | Make @var{file} a symlink to the result, and register it as a garbage | |
3541 | collector root. | |
3542 | ||
3543 | @item --log-file | |
3544 | Return the build log file names for the given | |
3545 | @var{package-or-derivation}s, or raise an error if build logs are | |
3546 | missing. | |
3547 | ||
3548 | This works regardless of how packages or derivations are specified. For | |
3549 | instance, the following invocations are equivalent: | |
3550 | ||
3551 | @example | |
3552 | guix build --log-file `guix build -d guile` | |
3553 | guix build --log-file `guix build guile` | |
3554 | guix build --log-file guile | |
3555 | guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)' | |
3556 | @end example | |
3557 | ||
3558 | ||
3559 | @end table | |
3560 | ||
3561 | @cindex common build options | |
3562 | In addition, a number of options that control the build process are | |
3563 | common to @command{guix build} and other commands that can spawn builds, | |
3564 | such as @command{guix package} or @command{guix archive}. These are the | |
3565 | following: | |
3566 | ||
3567 | @table @code | |
3568 | ||
300868ba LC |
3569 | @item --load-path=@var{directory} |
3570 | @itemx -L @var{directory} | |
3571 | Add @var{directory} to the front of the package module search path | |
3572 | (@pxref{Package Modules}). | |
3573 | ||
3574 | This allows users to define their own packages and make them visible to | |
3575 | the command-line tools. | |
3576 | ||
c78bd12b LC |
3577 | @item --keep-failed |
3578 | @itemx -K | |
3579 | Keep the build tree of failed builds. Thus, if a build fail, its build | |
3580 | tree is kept under @file{/tmp}, in a directory whose name is shown at | |
3581 | the end of the build log. This is useful when debugging build issues. | |
3582 | ||
3583 | @item --dry-run | |
3584 | @itemx -n | |
3585 | Do not build the derivations. | |
3586 | ||
56b1f4b7 LC |
3587 | @item --fallback |
3588 | When substituting a pre-built binary fails, fall back to building | |
3589 | packages locally. | |
3590 | ||
f8a8e0fe LC |
3591 | @item --substitute-urls=@var{urls} |
3592 | @anchor{client-substitute-urls} | |
3593 | Consider @var{urls} the whitespace-separated list of substitute source | |
3594 | URLs, overriding the default list of URLs of @command{guix-daemon} | |
3595 | (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}). | |
3596 | ||
3597 | This means that substitutes may be downloaded from @var{urls}, provided | |
3598 | they are signed by a key authorized by the system administrator | |
3599 | (@pxref{Substitutes}). | |
3600 | ||
c78bd12b | 3601 | @item --no-substitutes |
b5385b52 | 3602 | Do not use substitutes for build products. That is, always build things |
c4202d60 LC |
3603 | locally instead of allowing downloads of pre-built binaries |
3604 | (@pxref{Substitutes}). | |
c78bd12b | 3605 | |
425b0bfc | 3606 | @item --no-build-hook |
4ec2e92d LC |
3607 | Do not attempt to offload builds @i{via} the daemon's ``build hook'' |
3608 | (@pxref{Daemon Offload Setup}). That is, always build things locally | |
3609 | instead of offloading builds to remote machines. | |
425b0bfc | 3610 | |
969e678e LC |
3611 | @item --max-silent-time=@var{seconds} |
3612 | When the build or substitution process remains silent for more than | |
3613 | @var{seconds}, terminate it and report a build failure. | |
3614 | ||
002622b6 LC |
3615 | @item --timeout=@var{seconds} |
3616 | Likewise, when the build or substitution process lasts for more than | |
3617 | @var{seconds}, terminate it and report a build failure. | |
3618 | ||
3619 | By default there is no timeout. This behavior can be restored with | |
3620 | @code{--timeout=0}. | |
3621 | ||
07ab4bf1 LC |
3622 | @item --verbosity=@var{level} |
3623 | Use the given verbosity level. @var{level} must be an integer between 0 | |
3624 | and 5; higher means more verbose output. Setting a level of 4 or more | |
3625 | may be helpful when debugging setup issues with the build daemon. | |
3626 | ||
70ee5642 LC |
3627 | @item --cores=@var{n} |
3628 | @itemx -c @var{n} | |
3629 | Allow the use of up to @var{n} CPU cores for the build. The special | |
3630 | value @code{0} means to use as many CPU cores as available. | |
bf421152 | 3631 | |
f6526eb3 LC |
3632 | @item --max-jobs=@var{n} |
3633 | @itemx -M @var{n} | |
3634 | Allow at most @var{n} build jobs in parallel. @xref{Invoking | |
3635 | guix-daemon, @code{--max-jobs}}, for details about this option and the | |
3636 | equivalent @command{guix-daemon} option. | |
3637 | ||
c78bd12b LC |
3638 | @end table |
3639 | ||
e49951eb | 3640 | Behind the scenes, @command{guix build} is essentially an interface to |
c78bd12b LC |
3641 | the @code{package-derivation} procedure of the @code{(guix packages)} |
3642 | module, and to the @code{build-derivations} procedure of the @code{(guix | |
01d8ac64 | 3643 | derivations)} module. |
c78bd12b | 3644 | |
16eb115e DP |
3645 | In addition to options explicitly passed on the command line, |
3646 | @command{guix build} and other @command{guix} commands that support | |
3647 | building honor the @code{GUIX_BUILD_OPTIONS} environment variable. | |
3648 | ||
3649 | @defvr {Environment Variable} GUIX_BUILD_OPTIONS | |
3650 | Users can define this variable to a list of command line options that | |
3651 | will automatically be used by @command{guix build} and other | |
3652 | @command{guix} commands that can perform builds, as in the example | |
3653 | below: | |
3654 | ||
3655 | @example | |
3656 | $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar" | |
3657 | @end example | |
3658 | ||
847391fe DP |
3659 | These options are parsed independently, and the result is appended to |
3660 | the parsed command-line options. | |
16eb115e DP |
3661 | @end defvr |
3662 | ||
3663 | ||
39bee8a2 LC |
3664 | @node Invoking guix edit |
3665 | @section Invoking @command{guix edit} | |
3666 | ||
3667 | @cindex package definition, editing | |
3668 | So many packages, so many source files! The @command{guix edit} command | |
3669 | facilitates the life of packagers by pointing their editor at the source | |
3670 | file containing the definition of the specified packages. For instance: | |
3671 | ||
3672 | @example | |
3673 | guix edit gcc-4.8 vim | |
3674 | @end example | |
3675 | ||
3676 | @noindent | |
3677 | launches the program specified in the @code{EDITOR} environment variable | |
3678 | to edit the recipe of GCC@tie{}4.8.4 and that of Vim. | |
3679 | ||
3680 | If you are using Emacs, note that the Emacs user interface provides | |
6248e326 AK |
3681 | similar functionality in the ``package info'' and ``package list'' |
3682 | buffers created by @kbd{M-x guix-search-by-name} and similar commands | |
3683 | (@pxref{Emacs Commands}). | |
39bee8a2 LC |
3684 | |
3685 | ||
210cc920 LC |
3686 | @node Invoking guix download |
3687 | @section Invoking @command{guix download} | |
3688 | ||
3689 | When writing a package definition, developers typically need to download | |
3690 | the package's source tarball, compute its SHA256 hash, and write that | |
3691 | hash in the package definition (@pxref{Defining Packages}). The | |
3692 | @command{guix download} tool helps with this task: it downloads a file | |
3693 | from the given URI, adds it to the store, and prints both its file name | |
3694 | in the store and its SHA256 hash. | |
3695 | ||
3696 | The fact that the downloaded file is added to the store saves bandwidth: | |
3697 | when the developer eventually tries to build the newly defined package | |
3698 | with @command{guix build}, the source tarball will not have to be | |
3699 | downloaded again because it is already in the store. It is also a | |
3700 | convenient way to temporarily stash files, which may be deleted | |
3701 | eventually (@pxref{Invoking guix gc}). | |
3702 | ||
3703 | The @command{guix download} command supports the same URIs as used in | |
3704 | package definitions. In particular, it supports @code{mirror://} URIs. | |
3705 | @code{https} URIs (HTTP over TLS) are supported @emph{provided} the | |
3706 | Guile bindings for GnuTLS are available in the user's environment; when | |
537c8bb3 LC |
3707 | they are not available, an error is raised. @xref{Guile Preparations, |
3708 | how to install the GnuTLS bindings for Guile,, gnutls-guile, | |
3709 | GnuTLS-Guile}, for more information. | |
210cc920 LC |
3710 | |
3711 | The following option is available: | |
3712 | ||
3713 | @table @code | |
3714 | @item --format=@var{fmt} | |
3715 | @itemx -f @var{fmt} | |
3716 | Write the hash in the format specified by @var{fmt}. For more | |
081145cf | 3717 | information on the valid values for @var{fmt}, @pxref{Invoking guix hash}. |
210cc920 LC |
3718 | @end table |
3719 | ||
6c365eca NK |
3720 | @node Invoking guix hash |
3721 | @section Invoking @command{guix hash} | |
3722 | ||
210cc920 | 3723 | The @command{guix hash} command computes the SHA256 hash of a file. |
6c365eca NK |
3724 | It is primarily a convenience tool for anyone contributing to the |
3725 | distribution: it computes the cryptographic hash of a file, which can be | |
3726 | used in the definition of a package (@pxref{Defining Packages}). | |
3727 | ||
3728 | The general syntax is: | |
3729 | ||
3730 | @example | |
3731 | guix hash @var{option} @var{file} | |
3732 | @end example | |
3733 | ||
3734 | @command{guix hash} has the following option: | |
3735 | ||
3736 | @table @code | |
3737 | ||
3738 | @item --format=@var{fmt} | |
3739 | @itemx -f @var{fmt} | |
210cc920 | 3740 | Write the hash in the format specified by @var{fmt}. |
6c365eca NK |
3741 | |
3742 | Supported formats: @code{nix-base32}, @code{base32}, @code{base16} | |
3743 | (@code{hex} and @code{hexadecimal} can be used as well). | |
3744 | ||
3745 | If the @option{--format} option is not specified, @command{guix hash} | |
3746 | will output the hash in @code{nix-base32}. This representation is used | |
3747 | in the definitions of packages. | |
3748 | ||
3140f2df LC |
3749 | @item --recursive |
3750 | @itemx -r | |
3751 | Compute the hash on @var{file} recursively. | |
3752 | ||
3753 | In this case, the hash is computed on an archive containing @var{file}, | |
3754 | including its children if it is a directory. Some of @var{file}'s | |
3755 | meta-data is part of the archive; for instance, when @var{file} is a | |
3756 | regular file, the hash is different depending on whether @var{file} is | |
3757 | executable or not. Meta-data such as time stamps has no impact on the | |
3758 | hash (@pxref{Invoking guix archive}). | |
3759 | @c FIXME: Replace xref above with xref to an ``Archive'' section when | |
3760 | @c it exists. | |
3761 | ||
6c365eca NK |
3762 | @end table |
3763 | ||
2f7d2d91 LC |
3764 | @node Invoking guix import |
3765 | @section Invoking @command{guix import} | |
3766 | ||
3767 | @cindex importing packages | |
3768 | @cindex package import | |
3769 | @cindex package conversion | |
3770 | The @command{guix import} command is useful for people willing to add a | |
3771 | package to the distribution but who'd rather do as little work as | |
3772 | possible to get there---a legitimate demand. The command knows of a few | |
3773 | repositories from which it can ``import'' package meta-data. The result | |
3774 | is a package definition, or a template thereof, in the format we know | |
3775 | (@pxref{Defining Packages}). | |
3776 | ||
3777 | The general syntax is: | |
3778 | ||
3779 | @example | |
3780 | guix import @var{importer} @var{options}@dots{} | |
3781 | @end example | |
3782 | ||
3783 | @var{importer} specifies the source from which to import package | |
3784 | meta-data, and @var{options} specifies a package identifier and other | |
3785 | options specific to @var{importer}. Currently, the available | |
3786 | ``importers'' are: | |
3787 | ||
3788 | @table @code | |
3789 | @item gnu | |
3790 | Import meta-data for the given GNU package. This provides a template | |
3791 | for the latest version of that GNU package, including the hash of its | |
3792 | source tarball, and its canonical synopsis and description. | |
3793 | ||
3794 | Additional information such as the package's dependencies and its | |
3795 | license needs to be figured out manually. | |
3796 | ||
3797 | For example, the following command returns a package definition for | |
3798 | GNU@tie{}Hello: | |
3799 | ||
3800 | @example | |
3801 | guix import gnu hello | |
3802 | @end example | |
3803 | ||
3804 | Specific command-line options are: | |
3805 | ||
3806 | @table @code | |
3807 | @item --key-download=@var{policy} | |
3808 | As for @code{guix refresh}, specify the policy to handle missing OpenPGP | |
3809 | keys when verifying the package's signature. @xref{Invoking guix | |
3810 | refresh, @code{--key-download}}. | |
3811 | @end table | |
3812 | ||
3813 | @item pypi | |
3814 | @cindex pypi | |
3815 | Import meta-data from the @uref{https://pypi.python.org/, Python Package | |
3816 | Index}@footnote{This functionality requires Guile-JSON to be installed. | |
3817 | @xref{Requirements}.}. Information is taken from the JSON-formatted | |
3818 | description available at @code{pypi.python.org} and usually includes all | |
3819 | the relevant information, including package dependencies. | |
3820 | ||
3821 | The command below imports meta-data for the @code{itsdangerous} Python | |
3822 | package: | |
3823 | ||
3824 | @example | |
3825 | guix import pypi itsdangerous | |
3826 | @end example | |
3827 | ||
d45dc6da EB |
3828 | @item cpan |
3829 | @cindex CPAN | |
3830 | Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}. | |
3831 | Information is taken from the JSON-formatted meta-data provided through | |
3832 | @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most | |
66392e47 EB |
3833 | relevant information, such as module dependencies. License information |
3834 | should be checked closely. If Perl is available in the store, then the | |
3835 | @code{corelist} utility will be used to filter core modules out of the | |
3836 | list of dependencies. | |
d45dc6da EB |
3837 | |
3838 | The command command below imports meta-data for the @code{Acme::Boolean} | |
3839 | Perl module: | |
3840 | ||
3841 | @example | |
3842 | guix import cpan Acme::Boolean | |
3843 | @end example | |
3844 | ||
2f7d2d91 LC |
3845 | @item nix |
3846 | Import meta-data from a local copy of the source of the | |
3847 | @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This | |
3848 | relies on the @command{nix-instantiate} command of | |
3849 | @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are | |
3850 | typically written in a mixture of Nix-language and Bash code. This | |
3851 | command only imports the high-level package structure that is written in | |
3852 | the Nix language. It normally includes all the basic fields of a | |
3853 | package definition. | |
3854 | ||
3855 | When importing a GNU package, the synopsis and descriptions are replaced | |
3856 | by their canonical upstream variant. | |
3857 | ||
3858 | As an example, the command below imports the package definition of | |
3859 | LibreOffice (more precisely, it imports the definition of the package | |
3860 | bound to the @code{libreoffice} top-level attribute): | |
3861 | ||
3862 | @example | |
3863 | guix import nix ~/path/to/nixpkgs libreoffice | |
3864 | @end example | |
863af4e1 FB |
3865 | |
3866 | @item hackage | |
3867 | @cindex hackage | |
3868 | Import meta-data from Haskell community's central package archive | |
3869 | @uref{https://hackage.haskell.org/, Hackage}. Information is taken from | |
3870 | Cabal files and includes all the relevant information, including package | |
3871 | dependencies. | |
3872 | ||
3873 | Specific command-line options are: | |
3874 | ||
3875 | @table @code | |
a4154748 FB |
3876 | @item --stdin |
3877 | @itemx -s | |
3878 | Read a Cabal file from the standard input. | |
863af4e1 FB |
3879 | @item --no-test-dependencies |
3880 | @itemx -t | |
a4154748 FB |
3881 | Do not include dependencies required by the test suites only. |
3882 | @item --cabal-environment=@var{alist} | |
3883 | @itemx -e @var{alist} | |
3884 | @var{alist} is a Scheme alist defining the environment in which the | |
3885 | Cabal conditionals are evaluated. The accepted keys are: @code{os}, | |
3886 | @code{arch}, @code{impl} and a string representing the name of a flag. | |
3887 | The value associated with a flag has to be either the symbol | |
3888 | @code{true} or @code{false}. The value associated with other keys | |
3889 | has to conform to the Cabal file format definition. The default value | |
3890 | associated with the keys @code{os}, @code{arch} and @code{impl} is | |
3891 | @samp{linux}, @samp{x86_64} and @samp{ghc} respectively. | |
863af4e1 FB |
3892 | @end table |
3893 | ||
3894 | The command below imports meta-data for the latest version of the | |
a4154748 FB |
3895 | @code{HTTP} Haskell package without including test dependencies and |
3896 | specifying the value of the flag @samp{network-uri} as @code{false}: | |
863af4e1 FB |
3897 | |
3898 | @example | |
a4154748 | 3899 | guix import hackage -t -e "'((\"network-uri\" . false))" HTTP |
863af4e1 FB |
3900 | @end example |
3901 | ||
3902 | A specific package version may optionally be specified by following the | |
3903 | package name by a hyphen and a version number as in the following example: | |
3904 | ||
3905 | @example | |
3906 | guix import hackage mtl-2.1.3.1 | |
3907 | @end example | |
7f74a931 FB |
3908 | |
3909 | @item elpa | |
3910 | @cindex elpa | |
3911 | Import meta-data from an Emacs Lisp Package Archive (ELPA) package | |
3912 | repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}). | |
3913 | ||
3914 | Specific command-line options are: | |
3915 | ||
3916 | @table @code | |
3917 | @item --archive=@var{repo} | |
3918 | @itemx -a @var{repo} | |
3919 | @var{repo} identifies the archive repository from which to retrieve the | |
3920 | information. Currently the supported repositories and their identifiers | |
3921 | are: | |
3922 | @itemize - | |
3923 | @item | |
840bd1d3 | 3924 | @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu} |
7f74a931 FB |
3925 | identifier. This is the default. |
3926 | ||
3927 | @item | |
840bd1d3 | 3928 | @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the |
7f74a931 FB |
3929 | @code{melpa-stable} identifier. |
3930 | ||
3931 | @item | |
840bd1d3 | 3932 | @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa} |
7f74a931 FB |
3933 | identifier. |
3934 | @end itemize | |
3935 | @end table | |
2f7d2d91 LC |
3936 | @end table |
3937 | ||
3938 | The structure of the @command{guix import} code is modular. It would be | |
3939 | useful to have more importers for other package formats, and your help | |
3940 | is welcome here (@pxref{Contributing}). | |
3941 | ||
37166310 LC |
3942 | @node Invoking guix refresh |
3943 | @section Invoking @command{guix refresh} | |
3944 | ||
3945 | The primary audience of the @command{guix refresh} command is developers | |
3946 | of the GNU software distribution. By default, it reports any packages | |
3947 | provided by the distribution that are outdated compared to the latest | |
3948 | upstream version, like this: | |
3949 | ||
3950 | @example | |
3951 | $ guix refresh | |
3952 | gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1 | |
3953 | gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0 | |
3954 | @end example | |
3955 | ||
3956 | It does so by browsing each package's FTP directory and determining the | |
3957 | highest version number of the source tarballs | |
3958 | therein@footnote{Currently, this only works for GNU packages.}. | |
3959 | ||
3960 | When passed @code{--update}, it modifies distribution source files to | |
3961 | update the version numbers and source tarball hashes of those packages' | |
3962 | recipes (@pxref{Defining Packages}). This is achieved by downloading | |
3963 | each package's latest source tarball and its associated OpenPGP | |
3964 | signature, authenticating the downloaded tarball against its signature | |
3965 | using @command{gpg}, and finally computing its hash. When the public | |
3966 | key used to sign the tarball is missing from the user's keyring, an | |
3967 | attempt is made to automatically retrieve it from a public key server; | |
3968 | when it's successful, the key is added to the user's keyring; otherwise, | |
3969 | @command{guix refresh} reports an error. | |
3970 | ||
3971 | The following options are supported: | |
3972 | ||
3973 | @table @code | |
3974 | ||
3975 | @item --update | |
3976 | @itemx -u | |
3977 | Update distribution source files (package recipes) in place. | |
081145cf | 3978 | @xref{Defining Packages}, for more information on package definitions. |
37166310 LC |
3979 | |
3980 | @item --select=[@var{subset}] | |
3981 | @itemx -s @var{subset} | |
3982 | Select all the packages in @var{subset}, one of @code{core} or | |
3983 | @code{non-core}. | |
3984 | ||
3985 | The @code{core} subset refers to all the packages at the core of the | |
3986 | distribution---i.e., packages that are used to build ``everything | |
3987 | else''. This includes GCC, libc, Binutils, Bash, etc. Usually, | |
3988 | changing one of these packages in the distribution entails a rebuild of | |
3989 | all the others. Thus, such updates are an inconvenience to users in | |
3990 | terms of build time or bandwidth used to achieve the upgrade. | |
3991 | ||
3992 | The @code{non-core} subset refers to the remaining packages. It is | |
3993 | typically useful in cases where an update of the core packages would be | |
3994 | inconvenient. | |
3995 | ||
3996 | @end table | |
3997 | ||
3998 | In addition, @command{guix refresh} can be passed one or more package | |
3999 | names, as in this example: | |
4000 | ||
4001 | @example | |
4b9b3cbb | 4002 | guix refresh -u emacs idutils gcc-4.8.4 |
37166310 LC |
4003 | @end example |
4004 | ||
4005 | @noindent | |
4006 | The command above specifically updates the @code{emacs} and | |
4007 | @code{idutils} packages. The @code{--select} option would have no | |
4008 | effect in this case. | |
4009 | ||
7d193ec3 EB |
4010 | When considering whether to upgrade a package, it is sometimes |
4011 | convenient to know which packages would be affected by the upgrade and | |
4012 | should be checked for compatibility. For this the following option may | |
4013 | be used when passing @command{guix refresh} one or more package names: | |
4014 | ||
4015 | @table @code | |
4016 | ||
4017 | @item --list-dependent | |
4018 | @itemx -l | |
4019 | List top-level dependent packages that would need to be rebuilt as a | |
4020 | result of upgrading one or more packages. | |
4021 | ||
4022 | @end table | |
4023 | ||
4024 | Be aware that the @code{--list-dependent} option only | |
4025 | @emph{approximates} the rebuilds that would be required as a result of | |
4026 | an upgrade. More rebuilds might be required under some circumstances. | |
4027 | ||
4028 | @example | |
7779ab61 LC |
4029 | $ guix refresh --list-dependent flex |
4030 | Building the following 120 packages would ensure 213 dependent packages are rebuilt: | |
4031 | hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{} | |
7d193ec3 EB |
4032 | @end example |
4033 | ||
4034 | The command above lists a set of packages that could be built to check | |
4035 | for compatibility with an upgraded @code{flex} package. | |
4036 | ||
f9230085 LC |
4037 | The following options can be used to customize GnuPG operation: |
4038 | ||
4039 | @table @code | |
4040 | ||
f9230085 LC |
4041 | @item --gpg=@var{command} |
4042 | Use @var{command} as the GnuPG 2.x command. @var{command} is searched | |
4043 | for in @code{$PATH}. | |
4044 | ||
2bc53ba9 LC |
4045 | @item --key-download=@var{policy} |
4046 | Handle missing OpenPGP keys according to @var{policy}, which may be one | |
4047 | of: | |
4048 | ||
4049 | @table @code | |
4050 | @item always | |
4051 | Always download missing OpenPGP keys from the key server, and add them | |
4052 | to the user's GnuPG keyring. | |
4053 | ||
4054 | @item never | |
4055 | Never try to download missing OpenPGP keys. Instead just bail out. | |
4056 | ||
4057 | @item interactive | |
4058 | When a package signed with an unknown OpenPGP key is encountered, ask | |
4059 | the user whether to download it or not. This is the default behavior. | |
4060 | @end table | |
4061 | ||
4062 | @item --key-server=@var{host} | |
4063 | Use @var{host} as the OpenPGP key server when importing a public key. | |
4064 | ||
f9230085 LC |
4065 | @end table |
4066 | ||
b4f5e0e8 CR |
4067 | @node Invoking guix lint |
4068 | @section Invoking @command{guix lint} | |
4069 | The @command{guix lint} is meant to help package developers avoid common | |
873c4085 LC |
4070 | errors and use a consistent style. It runs a number of checks on a |
4071 | given set of packages in order to find common mistakes in their | |
4072 | definitions. Available @dfn{checkers} include (see | |
4073 | @code{--list-checkers} for a complete list): | |
4074 | ||
4075 | @table @code | |
4076 | @item synopsis | |
4077 | @itemx description | |
4078 | Validate certain typographical and stylistic rules about package | |
4079 | descriptions and synopses. | |
4080 | ||
4081 | @item inputs-should-be-native | |
4082 | Identify inputs that should most likely be native inputs. | |
4083 | ||
4084 | @item source | |
4085 | @itemx home-page | |
4086 | Probe @code{home-page} and @code{source} URLs and report those that are | |
4087 | invalid. | |
4088 | @end table | |
b4f5e0e8 CR |
4089 | |
4090 | The general syntax is: | |
4091 | ||
4092 | @example | |
4093 | guix lint @var{options} @var{package}@dots{} | |
4094 | @end example | |
4095 | ||
4096 | If no package is given on the command line, then all packages are checked. | |
4097 | The @var{options} may be zero or more of the following: | |
4098 | ||
4099 | @table @code | |
4100 | ||
dd7c013d CR |
4101 | @item --checkers |
4102 | @itemx -c | |
4103 | Only enable the checkers specified in a comma-separated list using the | |
4104 | names returned by @code{--list-checkers}. | |
4105 | ||
b4f5e0e8 CR |
4106 | @item --list-checkers |
4107 | @itemx -l | |
4108 | List and describe all the available checkers that will be run on packages | |
4109 | and exit. | |
4110 | ||
4111 | @end table | |
37166310 | 4112 | |
fcc58db6 LC |
4113 | @node Invoking guix size |
4114 | @section Invoking @command{guix size} | |
4115 | ||
4116 | The @command{guix size} command helps package developers profile the | |
4117 | disk usage of packages. It is easy to overlook the impact of an | |
4118 | additional dependency added to a package, or the impact of using a | |
4119 | single output for a package that could easily be split (@pxref{Packages | |
4120 | with Multiple Outputs}). These are the typical issues that | |
4121 | @command{guix size} can highlight. | |
4122 | ||
4123 | The command can be passed a package specification such as @code{gcc-4.8} | |
4124 | or @code{guile:debug}, or a file name in the store. Consider this | |
4125 | example: | |
4126 | ||
4127 | @example | |
4128 | $ guix size coreutils | |
4129 | store item total self | |
4130 | /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8% | |
4131 | /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6% | |
4132 | /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7% | |
4133 | /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5% | |
4134 | /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4% | |
4135 | /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1% | |
4136 | @end example | |
4137 | ||
4138 | @cindex closure | |
4139 | The store items listed here constitute the @dfn{transitive closure} of | |
4140 | Coreutils---i.e., Coreutils and all its dependencies, recursively---as | |
4141 | would be returned by: | |
4142 | ||
4143 | @example | |
4144 | $ guix gc -R /gnu/store/@dots{}-coreutils-8.23 | |
4145 | @end example | |
4146 | ||
4147 | Here the output shows 3 columns next to store items. The first column, | |
4148 | labeled ``total'', shows the size in mebibytes (MiB) of the closure of | |
4149 | the store item---that is, its own size plus the size of all its | |
4150 | dependencies. The next column, labeled ``self'', shows the size of the | |
4151 | item itself. The last column shows the ratio of the item's size to the | |
4152 | space occupied by all the items listed here. | |
4153 | ||
4154 | In this example, we see that the closure of Coreutils weighs in at | |
4155 | 70@tie{}MiB, half of which is taken by libc. (That libc represents a | |
4156 | large fraction of the closure is not a problem @i{per se} because it is | |
4157 | always available on the system anyway.) | |
4158 | ||
4159 | When the package passed to @command{guix size} is available in the | |
4160 | store, @command{guix size} queries the daemon to determine its | |
4161 | dependencies, and measures its size in the store, similar to @command{du | |
4162 | -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU | |
4163 | Coreutils}). | |
4164 | ||
4165 | When the given package is @emph{not} in the store, @command{guix size} | |
4166 | reports information based on information about the available substitutes | |
4167 | (@pxref{Substitutes}). This allows it to profile disk usage of store | |
4168 | items that are not even on disk, only available remotely. | |
4169 | ||
a8f996c6 | 4170 | The available options are: |
fcc58db6 LC |
4171 | |
4172 | @table @option | |
4173 | ||
a8f996c6 LC |
4174 | @item --map-file=@var{file} |
4175 | Write to @var{file} a graphical map of disk usage as a PNG file. | |
4176 | ||
4177 | For the example above, the map looks like this: | |
4178 | ||
4179 | @image{images/coreutils-size-map,5in,, map of Coreutils disk usage | |
4180 | produced by @command{guix size}} | |
4181 | ||
4182 | This option requires that | |
4183 | @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be | |
4184 | installed and visible in Guile's module search path. When that is not | |
4185 | the case, @command{guix size} fails as it tries to load it. | |
4186 | ||
fcc58db6 LC |
4187 | @item --system=@var{system} |
4188 | @itemx -s @var{system} | |
4189 | Consider packages for @var{system}---e.g., @code{x86_64-linux}. | |
4190 | ||
4191 | @end table | |
4192 | ||
372c4bbc DT |
4193 | @node Invoking guix environment |
4194 | @section Invoking @command{guix environment} | |
4195 | ||
f5fd4fd2 | 4196 | @cindex reproducible build environments |
fe36d84e | 4197 | @cindex development environments |
372c4bbc DT |
4198 | The purpose of @command{guix environment} is to assist hackers in |
4199 | creating reproducible development environments without polluting their | |
4200 | package profile. The @command{guix environment} tool takes one or more | |
4201 | packages, builds all of the necessary inputs, and creates a shell | |
4202 | environment to use them. | |
4203 | ||
4204 | The general syntax is: | |
4205 | ||
4206 | @example | |
4207 | guix environment @var{options} @var{package}@dots{} | |
4208 | @end example | |
4209 | ||
fe36d84e LC |
4210 | The following example spawns a new shell set up for the development of |
4211 | GNU@tie{}Guile: | |
372c4bbc DT |
4212 | |
4213 | @example | |
4214 | guix environment guile | |
4215 | @end example | |
4216 | ||
4217 | If the specified packages are not built yet, @command{guix environment} | |
4218 | automatically builds them. The new shell's environment is an augmented | |
4219 | version of the environment that @command{guix environment} was run in. | |
4220 | It contains the necessary search paths for building the given package | |
4221 | added to the existing environment variables. To create a ``pure'' | |
4222 | environment in which the original environment variables have been unset, | |
50500f7c LC |
4223 | use the @code{--pure} option@footnote{Users sometimes wrongfully augment |
4224 | environment variables such as @code{PATH} in their @file{~/.bashrc} | |
4225 | file. As a consequence, when @code{guix environment} launches it, Bash | |
4226 | may read @file{~/.bashrc}, thereby introducing ``impurities'' in these | |
4227 | environment variables. It is an error to define such environment | |
4228 | variables in @file{.bashrc}; instead, they should be defined in | |
4229 | @file{.bash_profile}, which is sourced only by log-in shells. | |
4230 | @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for | |
4231 | details on Bash start-up files.}. | |
372c4bbc | 4232 | |
28de8d25 LC |
4233 | @vindex GUIX_ENVIRONMENT |
4234 | @command{guix environment} defines the @code{GUIX_ENVIRONMENT} | |
4235 | variable in the shell it spaws. This allows users to, say, define a | |
4236 | specific prompt for development environments in their @file{.bashrc} | |
4237 | (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}): | |
4238 | ||
4239 | @example | |
4240 | if [ -n "$GUIX_ENVIRONMENT" ] | |
4241 | then | |
4242 | export PS1="\u@@\h \w [dev]\$ " | |
4243 | fi | |
4244 | @end example | |
4245 | ||
372c4bbc DT |
4246 | Additionally, more than one package may be specified, in which case the |
4247 | union of the inputs for the given packages are used. For example, the | |
4248 | command below spawns a shell where all of the dependencies of both Guile | |
4249 | and Emacs are available: | |
4250 | ||
4251 | @example | |
4252 | guix environment guile emacs | |
4253 | @end example | |
4254 | ||
4255 | Sometimes an interactive shell session is not desired. The | |
4256 | @code{--exec} option can be used to specify the command to run instead. | |
4257 | ||
4258 | @example | |
4259 | guix environment guile --exec=make | |
4260 | @end example | |
4261 | ||
fe36d84e LC |
4262 | In other situations, it is more convenient to specify the list of |
4263 | packages needed in the environment. For example, the following command | |
4264 | runs @command{python} from an environment containing Python@tie{}2.7 and | |
4265 | NumPy: | |
4266 | ||
4267 | @example | |
4268 | guix environment --ad-hoc python2-numpy python-2.7 -E python | |
4269 | @end example | |
4270 | ||
4271 | The available options are summarized below. | |
372c4bbc DT |
4272 | |
4273 | @table @code | |
4274 | @item --expression=@var{expr} | |
4275 | @itemx -e @var{expr} | |
4276 | Create an environment for the package that @var{expr} evaluates to. | |
4277 | ||
fe36d84e LC |
4278 | For example, running: |
4279 | ||
4280 | @example | |
4281 | guix environment -e '(@@ (gnu packages maths) petsc-openmpi)' | |
4282 | @end example | |
4283 | ||
4284 | starts a shell with the environment for this specific variant of the | |
4285 | PETSc package. | |
4286 | ||
372c4bbc DT |
4287 | @item --load=@var{file} |
4288 | @itemx -l @var{file} | |
4289 | Create an environment for the package that the code within @var{file} | |
4290 | evaluates to. | |
4291 | ||
fe36d84e LC |
4292 | As an example, @var{file} might contain a definition like this |
4293 | (@pxref{Defining Packages}): | |
4294 | ||
4295 | @example | |
4296 | @verbatiminclude environment-gdb.scm | |
4297 | @end example | |
4298 | ||
4299 | ||
372c4bbc DT |
4300 | @item --exec=@var{command} |
4301 | @item -E @var{command} | |
4302 | Execute @var{command} in the new environment. | |
4303 | ||
a54bd6d7 DT |
4304 | @item --ad-hoc |
4305 | Include all specified packages in the resulting environment, as if an | |
4306 | @i{ad hoc} package were defined with them as inputs. This option is | |
4307 | useful for quickly creating an environment without having to write a | |
4308 | package expression to contain the desired inputs. | |
4309 | ||
4310 | For instance, the command: | |
4311 | ||
4312 | @example | |
4313 | guix environment --ad-hoc guile guile-sdl -E guile | |
4314 | @end example | |
4315 | ||
4316 | runs @command{guile} in an environment where Guile and Guile-SDL are | |
4317 | available. | |
4318 | ||
417c39f1 LC |
4319 | Note that this example implicitly asks for the default output of |
4320 | @code{guile} and @code{guile-sdl} but it is possible to ask for a | |
4321 | specific output---e.g., @code{glib:bin} asks for the @code{bin} output | |
4322 | of @code{glib} (@pxref{Packages with Multiple Outputs}). | |
4323 | ||
372c4bbc DT |
4324 | @item --pure |
4325 | Unset existing environment variables when building the new environment. | |
4326 | This has the effect of creating an environment in which search paths | |
4327 | only contain package inputs. | |
4328 | ||
4329 | @item --search-paths | |
4330 | Display the environment variable definitions that make up the | |
4331 | environment. | |
ce367ef3 LC |
4332 | |
4333 | @item --system=@var{system} | |
4334 | @itemx -s @var{system} | |
4335 | Attempt to build for @var{system}---e.g., @code{i686-linux}. | |
372c4bbc DT |
4336 | @end table |
4337 | ||
4338 | It also supports all of the common build options that @command{guix | |
4339 | build} supports (@pxref{Invoking guix build, common build options}). | |
4340 | ||
aff8ce7c DT |
4341 | @node Invoking guix publish |
4342 | @section Invoking @command{guix publish} | |
4343 | ||
4344 | The purpose of @command{guix publish} is to enable users to easily share | |
8ce229fc LC |
4345 | their store with others, which can then use it as a substitute server |
4346 | (@pxref{Substitutes}). | |
4347 | ||
4348 | When @command{guix publish} runs, it spawns an HTTP server which allows | |
4349 | anyone with network access to obtain substitutes from it. This means | |
4350 | that any machine running Guix can also act as if it were a build farm, | |
4351 | since the HTTP interface is compatible with Hydra, the software behind | |
4352 | the @code{hydra.gnu.org} build farm. | |
aff8ce7c DT |
4353 | |
4354 | For security, each substitute is signed, allowing recipients to check | |
4355 | their authenticity and integrity (@pxref{Substitutes}). Because | |
4356 | @command{guix publish} uses the system's signing key, which is only | |
5463fe51 LC |
4357 | readable by the system administrator, it must be started as root; the |
4358 | @code{--user} option makes it drop root privileges early on. | |
aff8ce7c DT |
4359 | |
4360 | The general syntax is: | |
4361 | ||
4362 | @example | |
4363 | guix publish @var{options}@dots{} | |
4364 | @end example | |
4365 | ||
4366 | Running @command{guix publish} without any additional arguments will | |
4367 | spawn an HTTP server on port 8080: | |
4368 | ||
4369 | @example | |
4370 | guix publish | |
4371 | @end example | |
4372 | ||
4373 | Once a publishing server has been authorized (@pxref{Invoking guix | |
4374 | archive}), the daemon may download substitutes from it: | |
4375 | ||
4376 | @example | |
4377 | guix-daemon --substitute-urls=http://example.org:8080 | |
4378 | @end example | |
4379 | ||
4380 | The following options are available: | |
4381 | ||
4382 | @table @code | |
4383 | @item --port=@var{port} | |
4384 | @itemx -p @var{port} | |
4385 | Listen for HTTP requests on @var{port}. | |
4386 | ||
9e2292ef LC |
4387 | @item --listen=@var{host} |
4388 | Listen on the network interface for @var{host}. The default is to | |
4389 | accept connections from any interface. | |
4390 | ||
5463fe51 LC |
4391 | @item --user=@var{user} |
4392 | @itemx -u @var{user} | |
4393 | Change privileges to @var{user} as soon as possible---i.e., once the | |
4394 | server socket is open and the signing key has been read. | |
4395 | ||
aff8ce7c DT |
4396 | @item --repl[=@var{port}] |
4397 | @itemx -r [@var{port}] | |
4398 | Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile | |
8ce229fc LC |
4399 | Reference Manual}) on @var{port} (37146 by default). This is used |
4400 | primarily for debugging a running @command{guix publish} server. | |
aff8ce7c DT |
4401 | @end table |
4402 | ||
a1ba8475 LC |
4403 | @c ********************************************************************* |
4404 | @node GNU Distribution | |
4405 | @chapter GNU Distribution | |
4406 | ||
3ca2731c | 4407 | @cindex Guix System Distribution |
4705641f | 4408 | @cindex GuixSD |
3ca2731c LC |
4409 | Guix comes with a distribution of the GNU system consisting entirely of |
4410 | free software@footnote{The term ``free'' here refers to the | |
a1ba8475 | 4411 | @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to |
3ca2731c | 4412 | users of that software}.}. The |
35ed9306 LC |
4413 | distribution can be installed on its own (@pxref{System Installation}), |
4414 | but it is also possible to install Guix as a package manager on top of | |
4415 | an installed GNU/Linux system (@pxref{Installation}). To distinguish | |
3ca2731c | 4416 | between the two, we refer to the standalone distribution as the Guix |
4705641f | 4417 | System Distribution, or GuixSD. |
35ed9306 LC |
4418 | |
4419 | The distribution provides core GNU packages such as GNU libc, GCC, and | |
4420 | Binutils, as well as many GNU and non-GNU applications. The complete | |
4421 | list of available packages can be browsed | |
d03bb653 LC |
4422 | @url{http://www.gnu.org/software/guix/package-list.html,on-line} or by |
4423 | running @command{guix package} (@pxref{Invoking guix package}): | |
a1ba8475 LC |
4424 | |
4425 | @example | |
e49951eb | 4426 | guix package --list-available |
a1ba8475 LC |
4427 | @end example |
4428 | ||
35ed9306 | 4429 | Our goal has been to provide a practical 100% free software distribution of |
401c53c4 LC |
4430 | Linux-based and other variants of GNU, with a focus on the promotion and |
4431 | tight integration of GNU components, and an emphasis on programs and | |
4432 | tools that help users exert that freedom. | |
4433 | ||
3ca2731c | 4434 | Packages are currently available on the following platforms: |
c320011d LC |
4435 | |
4436 | @table @code | |
4437 | ||
4438 | @item x86_64-linux | |
4439 | Intel/AMD @code{x86_64} architecture, Linux-Libre kernel; | |
4440 | ||
4441 | @item i686-linux | |
4442 | Intel 32-bit architecture (IA32), Linux-Libre kernel; | |
4443 | ||
aa1e1947 MW |
4444 | @item armhf-linux |
4445 | ARMv7-A architecture with hard float, Thumb-2 and VFP3D16 coprocessor, | |
4446 | using the EABI hard-float ABI, and Linux-Libre kernel. | |
4447 | ||
c320011d LC |
4448 | @item mips64el-linux |
4449 | little-endian 64-bit MIPS processors, specifically the Loongson series, | |
4450 | n32 application binary interface (ABI), and Linux-Libre kernel. | |
4451 | ||
4452 | @end table | |
4453 | ||
4705641f | 4454 | GuixSD itself is currently only available on @code{i686} and @code{x86_64}. |
3ca2731c | 4455 | |
c320011d LC |
4456 | @noindent |
4457 | For information on porting to other architectures or kernels, | |
4458 | @xref{Porting}. | |
4459 | ||
401c53c4 | 4460 | @menu |
5af6de3e | 4461 | * System Installation:: Installing the whole operating system. |
35ed9306 | 4462 | * System Configuration:: Configuring the operating system. |
91ef73d4 | 4463 | * Installing Debugging Files:: Feeding the debugger. |
05962f29 | 4464 | * Security Updates:: Deploying security fixes quickly. |
401c53c4 | 4465 | * Package Modules:: Packages from the programmer's viewpoint. |
da7cabd4 | 4466 | * Packaging Guidelines:: Growing the distribution. |
401c53c4 | 4467 | * Bootstrapping:: GNU/Linux built from scratch. |
8b315a6d | 4468 | * Porting:: Targeting another platform or kernel. |
401c53c4 LC |
4469 | @end menu |
4470 | ||
4471 | Building this distribution is a cooperative effort, and you are invited | |
081145cf | 4472 | to join! @xref{Contributing}, for information about how you can help. |
401c53c4 | 4473 | |
5af6de3e LC |
4474 | @node System Installation |
4475 | @section System Installation | |
4476 | ||
3ca2731c LC |
4477 | @cindex Guix System Distribution |
4478 | This section explains how to install the Guix System Distribution | |
4479 | on a machine. The Guix package manager can | |
35ed9306 LC |
4480 | also be installed on top of a running GNU/Linux system, |
4481 | @pxref{Installation}. | |
5af6de3e LC |
4482 | |
4483 | @ifinfo | |
4484 | @c This paragraph is for people reading this from tty2 of the | |
4485 | @c installation image. | |
4486 | You're reading this documentation with an Info reader. For details on | |
4487 | how to use it, hit the @key{RET} key (``return'' or ``enter'') on the | |
6621cdb6 | 4488 | link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit |
5af6de3e LC |
4489 | @kbd{l} afterwards to come back here. |
4490 | @end ifinfo | |
4491 | ||
8aaaae38 LC |
4492 | @subsection Limitations |
4493 | ||
4705641f | 4494 | As of version @value{VERSION}, the Guix System Distribution (GuixSD) is |
3ca2731c | 4495 | not production-ready. It may contain bugs and lack important |
8aaaae38 LC |
4496 | features. Thus, if you are looking for a stable production system that |
4497 | respects your freedom as a computer user, a good solution at this point | |
4498 | is to consider @url{http://www.gnu.org/distros/free-distros.html, one of | |
4499 | more established GNU/Linux distributions}. We hope you can soon switch | |
4705641f | 4500 | to the GuixSD without fear, of course. In the meantime, you can |
8aaaae38 LC |
4501 | also keep using your distribution and try out the package manager on top |
4502 | of it (@pxref{Installation}). | |
4503 | ||
4504 | Before you proceed with the installation, be aware of the following | |
4505 | noteworthy limitations applicable to version @value{VERSION}: | |
4506 | ||
4507 | @itemize | |
4508 | @item | |
4509 | The installation process does not include a graphical user interface and | |
4510 | requires familiarity with GNU/Linux (see the following subsections to | |
4511 | get a feel of what that means.) | |
4512 | ||
4513 | @item | |
b1e95eca LC |
4514 | The system does not yet provide GNOME and KDE; it provides Xfce, though, |
4515 | if graphical desktop environments are your thing. | |
8aaaae38 LC |
4516 | |
4517 | @item | |
dbcb0ab1 | 4518 | Support for the Logical Volume Manager (LVM) is missing. |
8aaaae38 LC |
4519 | |
4520 | @item | |
4521 | Few system services are currently supported out-of-the-box | |
4522 | (@pxref{Services}). | |
4523 | ||
4524 | @item | |
49607566 | 4525 | On the order of 1,900 packages are available, which means that you may |
8aaaae38 LC |
4526 | occasionally find that a useful package is missing. |
4527 | @end itemize | |
4528 | ||
4529 | You've been warned. But more than a disclaimer, this is an invitation | |
4530 | to report issues (and success stories!), and join us in improving it. | |
4531 | @xref{Contributing}, for more info. | |
5af6de3e LC |
4532 | |
4533 | @subsection USB Stick Installation | |
4534 | ||
4535 | An installation image for USB sticks can be downloaded from | |
4705641f | 4536 | @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz}, |
5af6de3e LC |
4537 | where @var{system} is one of: |
4538 | ||
4539 | @table @code | |
4540 | @item x86_64-linux | |
4541 | for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs; | |
4542 | ||
4543 | @item i686-linux | |
4544 | for a 32-bit GNU/Linux system on Intel-compatible CPUs. | |
4545 | @end table | |
4546 | ||
4547 | This image contains a single partition with the tools necessary for an | |
4548 | installation. It is meant to be copied @emph{as is} to a large-enough | |
4549 | USB stick. | |
4550 | ||
4551 | To copy the image to a USB stick, follow these steps: | |
4552 | ||
4553 | @enumerate | |
4554 | @item | |
4555 | Decompress the image using the @command{xz} command: | |
4556 | ||
4557 | @example | |
4705641f | 4558 | xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz |
5af6de3e LC |
4559 | @end example |
4560 | ||
4561 | @item | |
4562 | Insert a USB stick of 1@tie{}GiB or more in your machine, and determine | |
4563 | its device name. Assuming that USB stick is known as @file{/dev/sdX}, | |
4564 | copy the image with: | |
4565 | ||
4566 | @example | |
4705641f | 4567 | dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX |
5af6de3e LC |
4568 | @end example |
4569 | ||
4570 | Access to @file{/dev/sdX} usually requires root privileges. | |
4571 | @end enumerate | |
4572 | ||
4573 | Once this is done, you should be able to reboot the system and boot from | |
4574 | the USB stick. The latter usually requires you to get in the BIOS' boot | |
4575 | menu, where you can choose to boot from the USB stick. | |
4576 | ||
4577 | @subsection Preparing for Installation | |
4578 | ||
4579 | Once you have successfully booted the image on the USB stick, you should | |
4580 | end up with a root prompt. Several console TTYs are configured and can | |
4581 | be used to run commands as root. TTY2 shows this documentation, | |
4582 | browsable using the Info reader commands (@pxref{Help,,, info, Info: An | |
4583 | Introduction}). | |
4584 | ||
4585 | To install the system, you would: | |
4586 | ||
4587 | @enumerate | |
4588 | ||
4589 | @item | |
152dd61c LC |
4590 | Configure the network, by running @command{ifconfig eno1 up && dhclient |
4591 | eno1} (to get an automatically assigned IP address from the wired | |
4592 | network interface controller@footnote{ | |
95c559c1 LC |
4593 | @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20 |
4594 | The name @code{eno1} is for the first on-board Ethernet controller. The | |
4595 | interface name for an Ethernet controller that is in the first slot of | |
4596 | the first PCI bus, for instance, would be @code{enp1s0}. Use | |
4597 | @command{ifconfig -a} to list all the available network interfaces.}), | |
4598 | or using the @command{ifconfig} command. | |
5af6de3e LC |
4599 | |
4600 | The system automatically loads drivers for your network interface | |
4601 | controllers. | |
4602 | ||
4603 | Setting up network access is almost always a requirement because the | |
4604 | image does not contain all the software and tools that may be needed. | |
4605 | ||
4606 | @item | |
4607 | Unless this has already been done, you must partition and format the | |
4608 | target partitions. | |
4609 | ||
7ab44369 LC |
4610 | Preferably, assign partitions a label so that you can easily and |
4611 | reliably refer to them in @code{file-system} declarations (@pxref{File | |
4612 | Systems}). This is typically done using the @code{-L} option of | |
4613 | @command{mkfs.ext4} and related commands. | |
4614 | ||
5af6de3e | 4615 | The installation image includes Parted (@pxref{Overview,,, parted, GNU |
b419c7f5 LC |
4616 | Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk |
4617 | encryption, and e2fsprogs, the suite of tools to manipulate | |
4618 | ext2/ext3/ext4 file systems. | |
5af6de3e | 4619 | |
83a17b62 LC |
4620 | @item |
4621 | Once that is done, mount the target root partition under @file{/mnt}. | |
4622 | ||
4623 | @item | |
4624 | Lastly, run @code{deco start cow-store /mnt}. | |
4625 | ||
4626 | This will make @file{/gnu/store} copy-on-write, such that packages added | |
4627 | to it during the installation phase will be written to the target disk | |
4628 | rather than kept in memory. | |
4629 | ||
5af6de3e LC |
4630 | @end enumerate |
4631 | ||
5af6de3e LC |
4632 | |
4633 | @subsection Proceeding with the Installation | |
4634 | ||
4635 | With the target partitions ready, you now have to edit a file and | |
4636 | provide the declaration of the operating system to be installed. To | |
4637 | that end, the installation system comes with two text editors: GNU nano | |
4638 | (@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone. | |
4639 | It is better to store that file on the target root file system, say, as | |
4640 | @file{/mnt/etc/config.scm}. | |
4641 | ||
dd51caac LC |
4642 | @xref{Using the Configuration System}, for examples of operating system |
4643 | configurations. These examples are available under | |
4644 | @file{/etc/configuration} in the installation image, so you can copy | |
4645 | them and use them as a starting point for your own configuration. | |
5af6de3e | 4646 | |
dd51caac LC |
4647 | Once you are done preparing the configuration file, the new system must |
4648 | be initialized (remember that the target root file system is mounted | |
4649 | under @file{/mnt}): | |
5af6de3e LC |
4650 | |
4651 | @example | |
4652 | guix system init /mnt/etc/config.scm /mnt | |
4653 | @end example | |
4654 | ||
4655 | @noindent | |
4656 | This will copy all the necessary files, and install GRUB on | |
4657 | @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For | |
6621cdb6 | 4658 | more information, @pxref{Invoking guix system}. This command may trigger |
5af6de3e LC |
4659 | downloads or builds of missing packages, which can take some time. |
4660 | ||
4661 | Once that command has completed---and hopefully succeeded!---you can | |
ad14d9e7 | 4662 | run @command{reboot} and boot into the new system. Cross fingers, and |
5af6de3e LC |
4663 | join us on @code{#guix} on the Freenode IRC network or on |
4664 | @file{guix-devel@@gnu.org} to share your experience---good or not so | |
4665 | good. | |
4666 | ||
4667 | @subsection Building the Installation Image | |
4668 | ||
4669 | The installation image described above was built using the @command{guix | |
4670 | system} command, specifically: | |
4671 | ||
4672 | @example | |
8a225c66 | 4673 | guix system disk-image --image-size=850MiB gnu/system/install.scm |
5af6de3e LC |
4674 | @end example |
4675 | ||
4676 | @xref{Invoking guix system}, for more information. See | |
4677 | @file{gnu/system/install.scm} in the source tree for more information | |
4678 | about the installation image. | |
4679 | ||
cf4a9129 LC |
4680 | @node System Configuration |
4681 | @section System Configuration | |
b208a005 | 4682 | |
cf4a9129 | 4683 | @cindex system configuration |
3ca2731c | 4684 | The Guix System Distribution supports a consistent whole-system configuration |
cf4a9129 LC |
4685 | mechanism. By that we mean that all aspects of the global system |
4686 | configuration---such as the available system services, timezone and | |
4687 | locale settings, user accounts---are declared in a single place. Such | |
4688 | a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected. | |
91ef73d4 | 4689 | |
cf4a9129 LC |
4690 | One of the advantages of putting all the system configuration under the |
4691 | control of Guix is that it supports transactional system upgrades, and | |
4692 | makes it possible to roll-back to a previous system instantiation, | |
4693 | should something go wrong with the new one (@pxref{Features}). Another | |
4694 | one is that it makes it easy to replicate the exact same configuration | |
4695 | across different machines, or at different points in time, without | |
4696 | having to resort to additional administration tools layered on top of | |
4697 | the system's own tools. | |
4698 | @c Yes, we're talking of Puppet, Chef, & co. here. ↑ | |
91ef73d4 | 4699 | |
cf4a9129 LC |
4700 | This section describes this mechanism. First we focus on the system |
4701 | administrator's viewpoint---explaining how the system is configured and | |
4702 | instantiated. Then we show how this mechanism can be extended, for | |
4703 | instance to support new system services. | |
91ef73d4 | 4704 | |
cf4a9129 LC |
4705 | @menu |
4706 | * Using the Configuration System:: Customizing your GNU system. | |
7313a52e | 4707 | * operating-system Reference:: Detail of operating-system declarations. |
cf4a9129 | 4708 | * File Systems:: Configuring file system mounts. |
510f9d86 | 4709 | * Mapped Devices:: Block device extra processing. |
cf4a9129 | 4710 | * User Accounts:: Specifying user accounts. |
598e19dc | 4711 | * Locales:: Language and cultural convention settings. |
cf4a9129 | 4712 | * Services:: Specifying system services. |
0ae8c15a | 4713 | * Setuid Programs:: Programs running with root privileges. |
efb5e833 | 4714 | * X.509 Certificates:: Authenticating HTTPS servers. |
996ed739 | 4715 | * Name Service Switch:: Configuring libc's name service switch. |
fd1b1fa2 | 4716 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
88faf933 | 4717 | * GRUB Configuration:: Configuring the boot loader. |
cf4a9129 LC |
4718 | * Invoking guix system:: Instantiating a system configuration. |
4719 | * Defining Services:: Adding new service definitions. | |
4720 | @end menu | |
91ef73d4 | 4721 | |
cf4a9129 LC |
4722 | @node Using the Configuration System |
4723 | @subsection Using the Configuration System | |
64d76fa6 | 4724 | |
cf4a9129 LC |
4725 | The operating system is configured by providing an |
4726 | @code{operating-system} declaration in a file that can then be passed to | |
4727 | the @command{guix system} command (@pxref{Invoking guix system}). A | |
4728 | simple setup, with the default system services, the default Linux-Libre | |
4729 | kernel, initial RAM disk, and boot loader looks like this: | |
91ef73d4 | 4730 | |
cf4a9129 LC |
4731 | @findex operating-system |
4732 | @lisp | |
dd51caac | 4733 | @include os-config-bare-bones.texi |
cf4a9129 | 4734 | @end lisp |
401c53c4 | 4735 | |
cf4a9129 LC |
4736 | This example should be self-describing. Some of the fields defined |
4737 | above, such as @code{host-name} and @code{bootloader}, are mandatory. | |
4738 | Others, such as @code{packages} and @code{services}, can be omitted, in | |
4739 | which case they get a default value. | |
e7f34eb0 | 4740 | |
cf4a9129 LC |
4741 | @vindex %base-packages |
4742 | The @code{packages} field lists | |
4743 | packages that will be globally visible on the system, for all user | |
4744 | accounts---i.e., in every user's @code{PATH} environment variable---in | |
4745 | addition to the per-user profiles (@pxref{Invoking guix package}). The | |
4746 | @var{%base-packages} variable provides all the tools one would expect | |
4747 | for basic user and administrator tasks---including the GNU Core | |
4748 | Utilities, the GNU Networking Utilities, the GNU Zile lightweight text | |
4749 | editor, @command{find}, @command{grep}, etc. The example above adds | |
4750 | Emacs to those, taken from the @code{(gnu packages emacs)} module | |
4751 | (@pxref{Package Modules}). | |
e7f34eb0 | 4752 | |
cf4a9129 LC |
4753 | @vindex %base-services |
4754 | The @code{services} field lists @dfn{system services} to be made | |
4755 | available when the system starts (@pxref{Services}). | |
4756 | The @code{operating-system} declaration above specifies that, in | |
4757 | addition to the basic services, we want the @command{lshd} secure shell | |
4758 | daemon listening on port 2222, and allowing remote @code{root} logins | |
4759 | (@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood, | |
4760 | @code{lsh-service} arranges so that @code{lshd} is started with the | |
4761 | right command-line options, possibly with supporting configuration files | |
7313a52e LC |
4762 | generated as needed (@pxref{Defining Services}). @xref{operating-system |
4763 | Reference}, for details about the available @code{operating-system} | |
4764 | fields. | |
a1ba8475 | 4765 | |
dd51caac LC |
4766 | The configuration for a typical ``desktop'' usage, with the X11 display |
4767 | server, a desktop environment, network management, an SSH server, and | |
4768 | more, would look like this: | |
4769 | ||
4770 | @lisp | |
4771 | @include os-config-desktop.texi | |
4772 | @end lisp | |
4773 | ||
4774 | @xref{Desktop Services}, for the exact list of services provided by | |
efb5e833 LC |
4775 | @var{%desktop-services}. @xref{X.509 Certificates}, for background |
4776 | information about the @code{nss-certs} package that is used here. | |
dd51caac | 4777 | |
cf4a9129 LC |
4778 | Assuming the above snippet is stored in the @file{my-system-config.scm} |
4779 | file, the @command{guix system reconfigure my-system-config.scm} command | |
4780 | instantiates that configuration, and makes it the default GRUB boot | |
4781 | entry (@pxref{Invoking guix system}). The normal way to change the | |
4782 | system's configuration is by updating this file and re-running the | |
4783 | @command{guix system} command. | |
b81e1947 | 4784 | |
cf4a9129 LC |
4785 | At the Scheme level, the bulk of an @code{operating-system} declaration |
4786 | is instantiated with the following monadic procedure (@pxref{The Store | |
4787 | Monad}): | |
b81e1947 | 4788 | |
cf4a9129 LC |
4789 | @deffn {Monadic Procedure} operating-system-derivation os |
4790 | Return a derivation that builds @var{os}, an @code{operating-system} | |
4791 | object (@pxref{Derivations}). | |
b81e1947 | 4792 | |
cf4a9129 LC |
4793 | The output of the derivation is a single directory that refers to all |
4794 | the packages, configuration files, and other supporting files needed to | |
4795 | instantiate @var{os}. | |
4796 | @end deffn | |
b81e1947 | 4797 | |
7313a52e LC |
4798 | @node operating-system Reference |
4799 | @subsection @code{operating-system} Reference | |
4800 | ||
4801 | This section summarizes all the options available in | |
4802 | @code{operating-system} declarations (@pxref{Using the Configuration | |
4803 | System}). | |
4804 | ||
4805 | @deftp {Data Type} operating-system | |
4806 | This is the data type representing an operating system configuration. | |
4807 | By that, we mean all the global system configuration, not per-user | |
4808 | configuration (@pxref{Using the Configuration System}). | |
4809 | ||
4810 | @table @asis | |
4811 | @item @code{kernel} (default: @var{linux-libre}) | |
fbb25e56 | 4812 | The package object of the operating system kernel to use@footnote{Currently |
7313a52e LC |
4813 | only the Linux-libre kernel is supported. In the future, it will be |
4814 | possible to use the GNU@tie{}Hurd.}. | |
4815 | ||
4816 | @item @code{bootloader} | |
88faf933 | 4817 | The system bootloader configuration object. @xref{GRUB Configuration}. |
7313a52e LC |
4818 | |
4819 | @item @code{initrd} (default: @code{base-initrd}) | |
4820 | A two-argument monadic procedure that returns an initial RAM disk for | |
4821 | the Linux kernel. @xref{Initial RAM Disk}. | |
4822 | ||
f34c56be LC |
4823 | @item @code{firmware} (default: @var{%base-firmware}) |
4824 | @cindex firmware | |
4825 | List of firmware packages loadable by the operating system kernel. | |
4826 | ||
4827 | The default includes firmware needed for Atheros-based WiFi devices | |
4828 | (Linux-libre module @code{ath9k}.) | |
4829 | ||
7313a52e LC |
4830 | @item @code{host-name} |
4831 | The host name. | |
4832 | ||
4833 | @item @code{hosts-file} | |
4834 | @cindex hosts file | |
24e02c28 | 4835 | A file-like object (@pxref{G-Expressions, file-like objects}) for use as |
7313a52e | 4836 | @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library |
24e02c28 | 4837 | Reference Manual}). The default is a file with entries for |
7313a52e LC |
4838 | @code{localhost} and @var{host-name}. |
4839 | ||
4840 | @item @code{mapped-devices} (default: @code{'()}) | |
4841 | A list of mapped devices. @xref{Mapped Devices}. | |
4842 | ||
4843 | @item @code{file-systems} | |
4844 | A list of file systems. @xref{File Systems}. | |
4845 | ||
4846 | @item @code{swap-devices} (default: @code{'()}) | |
4847 | @cindex swap devices | |
4848 | A list of strings identifying devices to be used for ``swap space'' | |
4849 | (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}). | |
4850 | For example, @code{'("/dev/sda3")}. | |
4851 | ||
bf87f38a | 4852 | @item @code{users} (default: @code{%base-user-accounts}) |
7313a52e LC |
4853 | @itemx @code{groups} (default: @var{%base-groups}) |
4854 | List of user accounts and groups. @xref{User Accounts}. | |
4855 | ||
4856 | @item @code{skeletons} (default: @code{(default-skeletons)}) | |
4857 | A monadic list of pairs of target file name and files. These are the | |
4858 | files that will be used as skeletons as new accounts are created. | |
4859 | ||
4860 | For instance, a valid value may look like this: | |
4861 | ||
4862 | @example | |
4863 | (mlet %store-monad ((bashrc (text-file "bashrc" "\ | |
4864 | export PATH=$HOME/.guix-profile/bin"))) | |
4865 | (return `((".bashrc" ,bashrc)))) | |
4866 | @end example | |
4867 | ||
4868 | @item @code{issue} (default: @var{%default-issue}) | |
4869 | A string denoting the contents of the @file{/etc/issue} file, which is | |
4870 | what displayed when users log in on a text console. | |
4871 | ||
4872 | @item @code{packages} (default: @var{%base-packages}) | |
4873 | The set of packages installed in the global profile, which is accessible | |
4874 | at @file{/run/current-system/profile}. | |
4875 | ||
4876 | The default set includes core utilities, but it is good practice to | |
4877 | install non-core utilities in user profiles (@pxref{Invoking guix | |
4878 | package}). | |
4879 | ||
4880 | @item @code{timezone} | |
4881 | A timezone identifying string---e.g., @code{"Europe/Paris"}. | |
4882 | ||
598e19dc LC |
4883 | @item @code{locale} (default: @code{"en_US.utf8"}) |
4884 | The name of the default locale (@pxref{Locale Names,,, libc, The GNU C | |
4885 | Library Reference Manual}). @xref{Locales}, for more information. | |
4886 | ||
4887 | @item @code{locale-definitions} (default: @var{%default-locale-definitions}) | |
4888 | The list of locale definitions to be compiled and that may be used at | |
4889 | run time. @xref{Locales}. | |
7313a52e | 4890 | |
996ed739 LC |
4891 | @item @code{name-service-switch} (default: @var{%default-nss}) |
4892 | Configuration of libc's name service switch (NSS)---a | |
4893 | @code{<name-service-switch>} object. @xref{Name Service Switch}, for | |
4894 | details. | |
4895 | ||
7313a52e LC |
4896 | @item @code{services} (default: @var{%base-services}) |
4897 | A list of monadic values denoting system services. @xref{Services}. | |
4898 | ||
4899 | @item @code{pam-services} (default: @code{(base-pam-services)}) | |
4900 | @cindex PAM | |
4901 | @cindex pluggable authentication modules | |
4902 | Linux @dfn{pluggable authentication module} (PAM) services. | |
4903 | @c FIXME: Add xref to PAM services section. | |
4904 | ||
4905 | @item @code{setuid-programs} (default: @var{%setuid-programs}) | |
4906 | List of string-valued G-expressions denoting setuid programs. | |
4907 | @xref{Setuid Programs}. | |
4908 | ||
f5a9ffa0 AK |
4909 | @item @code{sudoers-file} (default: @var{%sudoers-specification}) |
4910 | @cindex sudoers file | |
84765839 LC |
4911 | The contents of the @file{/etc/sudoers} file as a file-like object |
4912 | (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}). | |
7313a52e LC |
4913 | |
4914 | This file specifies which users can use the @command{sudo} command, what | |
4915 | they are allowed to do, and what privileges they may gain. The default | |
4916 | is that only @code{root} and members of the @code{wheel} group may use | |
4917 | @code{sudo}. | |
4918 | ||
4919 | @end table | |
4920 | @end deftp | |
4921 | ||
cf4a9129 LC |
4922 | @node File Systems |
4923 | @subsection File Systems | |
b81e1947 | 4924 | |
cf4a9129 LC |
4925 | The list of file systems to be mounted is specified in the |
4926 | @code{file-systems} field of the operating system's declaration | |
4927 | (@pxref{Using the Configuration System}). Each file system is declared | |
4928 | using the @code{file-system} form, like this: | |
b81e1947 LC |
4929 | |
4930 | @example | |
cf4a9129 LC |
4931 | (file-system |
4932 | (mount-point "/home") | |
4933 | (device "/dev/sda3") | |
4934 | (type "ext4")) | |
b81e1947 LC |
4935 | @end example |
4936 | ||
cf4a9129 LC |
4937 | As usual, some of the fields are mandatory---those shown in the example |
4938 | above---while others can be omitted. These are described below. | |
b81e1947 | 4939 | |
cf4a9129 LC |
4940 | @deftp {Data Type} file-system |
4941 | Objects of this type represent file systems to be mounted. They | |
4942 | contain the following members: | |
5ff3c4b8 | 4943 | |
cf4a9129 LC |
4944 | @table @asis |
4945 | @item @code{type} | |
4946 | This is a string specifying the type of the file system---e.g., | |
4947 | @code{"ext4"}. | |
5ff3c4b8 | 4948 | |
cf4a9129 LC |
4949 | @item @code{mount-point} |
4950 | This designates the place where the file system is to be mounted. | |
b81e1947 | 4951 | |
cf4a9129 LC |
4952 | @item @code{device} |
4953 | This names the ``source'' of the file system. By default it is the name | |
4954 | of a node under @file{/dev}, but its meaning depends on the @code{title} | |
4955 | field described below. | |
401c53c4 | 4956 | |
cf4a9129 LC |
4957 | @item @code{title} (default: @code{'device}) |
4958 | This is a symbol that specifies how the @code{device} field is to be | |
4959 | interpreted. | |
401c53c4 | 4960 | |
cf4a9129 LC |
4961 | When it is the symbol @code{device}, then the @code{device} field is |
4962 | interpreted as a file name; when it is @code{label}, then @code{device} | |
4963 | is interpreted as a partition label name; when it is @code{uuid}, | |
4964 | @code{device} is interpreted as a partition unique identifier (UUID). | |
da7cabd4 | 4965 | |
cf4a9129 LC |
4966 | The @code{label} and @code{uuid} options offer a way to refer to disk |
4967 | partitions without having to hard-code their actual device name. | |
da7cabd4 | 4968 | |
5f86a66e LC |
4969 | However, when a file system's source is a mapped device (@pxref{Mapped |
4970 | Devices}), its @code{device} field @emph{must} refer to the mapped | |
4971 | device name---e.g., @file{/dev/mapper/root-partition}---and consequently | |
4972 | @code{title} must be set to @code{'device}. This is required so that | |
4973 | the system knows that mounting the file system depends on having the | |
4974 | corresponding device mapping established. | |
4975 | ||
cf4a9129 LC |
4976 | @item @code{flags} (default: @code{'()}) |
4977 | This is a list of symbols denoting mount flags. Recognized flags | |
2c071ce9 LC |
4978 | include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow |
4979 | access to special files), @code{no-suid} (ignore setuid and setgid | |
4980 | bits), and @code{no-exec} (disallow program execution.) | |
da7cabd4 | 4981 | |
cf4a9129 LC |
4982 | @item @code{options} (default: @code{#f}) |
4983 | This is either @code{#f}, or a string denoting mount options. | |
da7cabd4 | 4984 | |
cf4a9129 LC |
4985 | @item @code{needed-for-boot?} (default: @code{#f}) |
4986 | This Boolean value indicates whether the file system is needed when | |
4987 | booting. If that is true, then the file system is mounted when the | |
4988 | initial RAM disk (initrd) is loaded. This is always the case, for | |
4989 | instance, for the root file system. | |
da7cabd4 | 4990 | |
cf4a9129 LC |
4991 | @item @code{check?} (default: @code{#t}) |
4992 | This Boolean indicates whether the file system needs to be checked for | |
4993 | errors before being mounted. | |
f9cc8971 | 4994 | |
4e469051 LC |
4995 | @item @code{create-mount-point?} (default: @code{#f}) |
4996 | When true, the mount point is created if it does not exist yet. | |
4997 | ||
cf4a9129 LC |
4998 | @end table |
4999 | @end deftp | |
da7cabd4 | 5000 | |
a69576ea LC |
5001 | The @code{(gnu system file-systems)} exports the following useful |
5002 | variables. | |
5003 | ||
5004 | @defvr {Scheme Variable} %base-file-systems | |
5005 | These are essential file systems that are required on normal systems, | |
3392ce5d LC |
5006 | such as @var{%devtmpfs-file-system} and @var{%immutable-store} (see |
5007 | below.) Operating system declarations should always contain at least | |
5008 | these. | |
a69576ea LC |
5009 | @end defvr |
5010 | ||
5011 | @defvr {Scheme Variable} %devtmpfs-file-system | |
5012 | The @code{devtmpfs} file system to be mounted on @file{/dev}. This is a | |
5013 | requirement for udev (@pxref{Base Services, @code{udev-service}}). | |
5014 | @end defvr | |
5015 | ||
7f239fd3 LC |
5016 | @defvr {Scheme Variable} %pseudo-terminal-file-system |
5017 | This is the file system to be mounted as @file{/dev/pts}. It supports | |
5018 | @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar | |
5019 | functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference | |
5020 | Manual}). Pseudo-terminals are used by terminal emulators such as | |
5021 | @command{xterm}. | |
5022 | @end defvr | |
5023 | ||
db17ae5c LC |
5024 | @defvr {Scheme Variable} %shared-memory-file-system |
5025 | This file system is mounted as @file{/dev/shm} and is used to support | |
5026 | memory sharing across processes (@pxref{Memory-mapped I/O, | |
5027 | @code{shm_open},, libc, The GNU C Library Reference Manual}). | |
5028 | @end defvr | |
5029 | ||
3392ce5d LC |
5030 | @defvr {Scheme Variable} %immutable-store |
5031 | This file system performs a read-only ``bind mount'' of | |
5032 | @file{/gnu/store}, making it read-only for all the users including | |
5033 | @code{root}. This prevents against accidental modification by software | |
5034 | running as @code{root} or by system administrators. | |
5035 | ||
5036 | The daemon itself is still able to write to the store: it remounts it | |
5037 | read-write in its own ``name space.'' | |
5038 | @end defvr | |
5039 | ||
a69576ea LC |
5040 | @defvr {Scheme Variable} %binary-format-file-system |
5041 | The @code{binfmt_misc} file system, which allows handling of arbitrary | |
5042 | executable file types to be delegated to user space. This requires the | |
5043 | @code{binfmt.ko} kernel module to be loaded. | |
5044 | @end defvr | |
5045 | ||
5046 | @defvr {Scheme Variable} %fuse-control-file-system | |
5047 | The @code{fusectl} file system, which allows unprivileged users to mount | |
5048 | and unmount user-space FUSE file systems. This requires the | |
5049 | @code{fuse.ko} kernel module to be loaded. | |
5050 | @end defvr | |
5051 | ||
510f9d86 LC |
5052 | @node Mapped Devices |
5053 | @subsection Mapped Devices | |
5054 | ||
5055 | @cindex device mapping | |
5056 | @cindex mapped devices | |
5057 | The Linux kernel has a notion of @dfn{device mapping}: a block device, | |
5058 | such as a hard disk partition, can be @dfn{mapped} into another device, | |
5059 | with additional processing over the data that flows through | |
5060 | it@footnote{Note that the GNU@tie{}Hurd makes no difference between the | |
5061 | concept of a ``mapped device'' and that of a file system: both boil down | |
5062 | to @emph{translating} input/output operations made on a file to | |
5063 | operations on its backing store. Thus, the Hurd implements mapped | |
5064 | devices, like file systems, using the generic @dfn{translator} mechanism | |
5065 | (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A | |
5066 | typical example is encryption device mapping: all writes to the mapped | |
5067 | device are encrypted, and all reads are deciphered, transparently. | |
5068 | ||
5069 | Mapped devices are declared using the @code{mapped-device} form: | |
5070 | ||
5071 | @example | |
5072 | (mapped-device | |
5073 | (source "/dev/sda3") | |
5074 | (target "home") | |
5075 | (type luks-device-mapping)) | |
5076 | @end example | |
5077 | ||
5078 | @noindent | |
5079 | @cindex disk encryption | |
5080 | @cindex LUKS | |
5081 | This example specifies a mapping from @file{/dev/sda3} to | |
5082 | @file{/dev/mapper/home} using LUKS---the | |
5083 | @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a | |
5084 | standard mechanism for disk encryption. The @file{/dev/mapper/home} | |
5085 | device can then be used as the @code{device} of a @code{file-system} | |
5086 | declaration (@pxref{File Systems}). The @code{mapped-device} form is | |
5087 | detailed below. | |
5088 | ||
5089 | @deftp {Data Type} mapped-device | |
5090 | Objects of this type represent device mappings that will be made when | |
5091 | the system boots up. | |
5092 | ||
9cb426b8 LC |
5093 | @table @code |
5094 | @item source | |
510f9d86 LC |
5095 | This string specifies the name of the block device to be mapped, such as |
5096 | @code{"/dev/sda3"}. | |
5097 | ||
9cb426b8 | 5098 | @item target |
510f9d86 LC |
5099 | This string specifies the name of the mapping to be established. For |
5100 | example, specifying @code{"my-partition"} will lead to the creation of | |
5101 | the @code{"/dev/mapper/my-partition"} device. | |
5102 | ||
9cb426b8 | 5103 | @item type |
510f9d86 LC |
5104 | This must be a @code{mapped-device-kind} object, which specifies how |
5105 | @var{source} is mapped to @var{target}. | |
5106 | @end table | |
5107 | @end deftp | |
5108 | ||
5109 | @defvr {Scheme Variable} luks-device-mapping | |
5110 | This defines LUKS block device encryption using the @command{cryptsetup} | |
5111 | command, from the same-named package. This relies on the | |
5112 | @code{dm-crypt} Linux kernel module. | |
5113 | @end defvr | |
5114 | ||
cf4a9129 LC |
5115 | @node User Accounts |
5116 | @subsection User Accounts | |
ee85f3db | 5117 | |
9bea87a5 LC |
5118 | User accounts and groups are entirely managed through the |
5119 | @code{operating-system} declaration. They are specified with the | |
5120 | @code{user-account} and @code{user-group} forms: | |
ee85f3db | 5121 | |
cf4a9129 LC |
5122 | @example |
5123 | (user-account | |
5124 | (name "alice") | |
5125 | (group "users") | |
24e752c0 LC |
5126 | (supplementary-groups '("wheel" ;allow use of sudo, etc. |
5127 | "audio" ;sound card | |
5128 | "video" ;video devices such as webcams | |
5129 | "cdrom")) ;the good ol' CD-ROM | |
cf4a9129 LC |
5130 | (comment "Bob's sister") |
5131 | (home-directory "/home/alice")) | |
5132 | @end example | |
25083588 | 5133 | |
9bea87a5 LC |
5134 | When booting or upon completion of @command{guix system reconfigure}, |
5135 | the system ensures that only the user accounts and groups specified in | |
5136 | the @code{operating-system} declaration exist, and with the specified | |
5137 | properties. Thus, account or group creations or modifications made by | |
5138 | directly invoking commands such as @command{useradd} are lost upon | |
5139 | reconfiguration or reboot. This ensures that the system remains exactly | |
5140 | as declared. | |
5141 | ||
cf4a9129 LC |
5142 | @deftp {Data Type} user-account |
5143 | Objects of this type represent user accounts. The following members may | |
5144 | be specified: | |
ee85f3db | 5145 | |
cf4a9129 LC |
5146 | @table @asis |
5147 | @item @code{name} | |
5148 | The name of the user account. | |
ee85f3db | 5149 | |
cf4a9129 LC |
5150 | @item @code{group} |
5151 | This is the name (a string) or identifier (a number) of the user group | |
5152 | this account belongs to. | |
ee85f3db | 5153 | |
cf4a9129 LC |
5154 | @item @code{supplementary-groups} (default: @code{'()}) |
5155 | Optionally, this can be defined as a list of group names that this | |
5156 | account belongs to. | |
ee85f3db | 5157 | |
cf4a9129 LC |
5158 | @item @code{uid} (default: @code{#f}) |
5159 | This is the user ID for this account (a number), or @code{#f}. In the | |
5160 | latter case, a number is automatically chosen by the system when the | |
5161 | account is created. | |
ee85f3db | 5162 | |
cf4a9129 LC |
5163 | @item @code{comment} (default: @code{""}) |
5164 | A comment about the account, such as the account's owner full name. | |
c8c871d1 | 5165 | |
cf4a9129 LC |
5166 | @item @code{home-directory} |
5167 | This is the name of the home directory for the account. | |
ee85f3db | 5168 | |
cf4a9129 LC |
5169 | @item @code{shell} (default: Bash) |
5170 | This is a G-expression denoting the file name of a program to be used as | |
5171 | the shell (@pxref{G-Expressions}). | |
ee85f3db | 5172 | |
cf4a9129 LC |
5173 | @item @code{system?} (default: @code{#f}) |
5174 | This Boolean value indicates whether the account is a ``system'' | |
5175 | account. System accounts are sometimes treated specially; for instance, | |
5176 | graphical login managers do not list them. | |
ee85f3db | 5177 | |
cf4a9129 | 5178 | @item @code{password} (default: @code{#f}) |
eb59595c LC |
5179 | You would normally leave this field to @code{#f}, initialize user |
5180 | passwords as @code{root} with the @command{passwd} command, and then let | |
9bea87a5 LC |
5181 | users change it with @command{passwd}. Passwords set with |
5182 | @command{passwd} are of course preserved across reboot and | |
5183 | reconfiguration. | |
eb59595c LC |
5184 | |
5185 | If you @emph{do} want to have a preset password for an account, then | |
5186 | this field must contain the encrypted password, as a string. | |
5d1f1177 LC |
5187 | @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information |
5188 | on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference | |
eb59595c | 5189 | Manual}, for information on Guile's @code{crypt} procedure. |
c8c871d1 | 5190 | |
cf4a9129 LC |
5191 | @end table |
5192 | @end deftp | |
ee85f3db | 5193 | |
cf4a9129 | 5194 | User group declarations are even simpler: |
ee85f3db | 5195 | |
cf4a9129 LC |
5196 | @example |
5197 | (user-group (name "students")) | |
5198 | @end example | |
ee85f3db | 5199 | |
cf4a9129 LC |
5200 | @deftp {Data Type} user-group |
5201 | This type is for, well, user groups. There are just a few fields: | |
af8a56b8 | 5202 | |
cf4a9129 LC |
5203 | @table @asis |
5204 | @item @code{name} | |
5205 | The group's name. | |
ee85f3db | 5206 | |
cf4a9129 LC |
5207 | @item @code{id} (default: @code{#f}) |
5208 | The group identifier (a number). If @code{#f}, a new number is | |
5209 | automatically allocated when the group is created. | |
ee85f3db | 5210 | |
c8fa3426 LC |
5211 | @item @code{system?} (default: @code{#f}) |
5212 | This Boolean value indicates whether the group is a ``system'' group. | |
5213 | System groups have low numerical IDs. | |
5214 | ||
cf4a9129 LC |
5215 | @item @code{password} (default: @code{#f}) |
5216 | What, user groups can have a password? Well, apparently yes. Unless | |
5217 | @code{#f}, this field specifies the group's password. | |
ee85f3db | 5218 | |
cf4a9129 LC |
5219 | @end table |
5220 | @end deftp | |
401c53c4 | 5221 | |
cf4a9129 LC |
5222 | For convenience, a variable lists all the basic user groups one may |
5223 | expect: | |
401c53c4 | 5224 | |
cf4a9129 LC |
5225 | @defvr {Scheme Variable} %base-groups |
5226 | This is the list of basic user groups that users and/or packages expect | |
5227 | to be present on the system. This includes groups such as ``root'', | |
5228 | ``wheel'', and ``users'', as well as groups used to control access to | |
5229 | specific devices such as ``audio'', ``disk'', and ``cdrom''. | |
5230 | @end defvr | |
401c53c4 | 5231 | |
bf87f38a LC |
5232 | @defvr {Scheme Variable} %base-user-accounts |
5233 | This is the list of basic system accounts that programs may expect to | |
5234 | find on a GNU/Linux system, such as the ``nobody'' account. | |
5235 | ||
5236 | Note that the ``root'' account is not included here. It is a | |
5237 | special-case and is automatically added whether or not it is specified. | |
5238 | @end defvr | |
5239 | ||
598e19dc LC |
5240 | @node Locales |
5241 | @subsection Locales | |
5242 | ||
5243 | @cindex locale | |
5244 | A @dfn{locale} defines cultural conventions for a particular language | |
5245 | and region of the world (@pxref{Locales,,, libc, The GNU C Library | |
5246 | Reference Manual}). Each locale has a name that typically has the form | |
5247 | @code{@var{language}_@var{territory}.@var{charset}}---e.g., | |
5248 | @code{fr_LU.utf8} designates the locale for the French language, with | |
5249 | cultural conventions from Luxembourg, and using the UTF-8 encoding. | |
5250 | ||
5251 | @cindex locale definition | |
5252 | Usually, you will want to specify the default locale for the machine | |
5253 | using the @code{locale} field of the @code{operating-system} declaration | |
5254 | (@pxref{operating-system Reference, @code{locale}}). | |
5255 | ||
5256 | That locale must be among the @dfn{locale definitions} that are known to | |
5257 | the system---and these are specified in the @code{locale-definitions} | |
5258 | slot of @code{operating-system}. The default value includes locale | |
5259 | definition for some widely used locales, but not for all the available | |
5260 | locales, in order to save space. | |
5261 | ||
5262 | If the locale specified in the @code{locale} field is not among the | |
5263 | definitions listed in @code{locale-definitions}, @command{guix system} | |
5264 | raises an error. In that case, you should add the locale definition to | |
5265 | the @code{locale-definitions} field. For instance, to add the North | |
5266 | Frisian locale for Germany, the value of that field may be: | |
5267 | ||
5268 | @example | |
5269 | (cons (locale-definition | |
5270 | (name "fy_DE.utf8") (source "fy_DE")) | |
5271 | %default-locale-definitions) | |
5272 | @end example | |
5273 | ||
5274 | Likewise, to save space, one might want @code{locale-definitions} to | |
5275 | list only the locales that are actually used, as in: | |
5276 | ||
5277 | @example | |
5278 | (list (locale-definition | |
5279 | (name "ja_JP.eucjp") (source "ja_JP") | |
5280 | (charset "EUC-JP"))) | |
5281 | @end example | |
5282 | ||
5283 | The @code{locale-definition} form is provided by the @code{(gnu system | |
5284 | locale)} module. Details are given below. | |
5285 | ||
5286 | @deftp {Data Type} locale-definition | |
5287 | This is the data type of a locale definition. | |
5288 | ||
5289 | @table @asis | |
5290 | ||
5291 | @item @code{name} | |
5292 | The name of the locale. @xref{Locale Names,,, libc, The GNU C Library | |
5293 | Reference Manual}, for more information on locale names. | |
5294 | ||
5295 | @item @code{source} | |
5296 | The name of the source for that locale. This is typically the | |
5297 | @code{@var{language}_@var{territory}} part of the locale name. | |
5298 | ||
5299 | @item @code{charset} (default: @code{"UTF-8"}) | |
5300 | The ``character set'' or ``code set'' for that locale, | |
5301 | @uref{http://www.iana.org/assignments/character-sets, as defined by | |
5302 | IANA}. | |
5303 | ||
5304 | @end table | |
5305 | @end deftp | |
5306 | ||
5307 | @defvr {Scheme Variable} %default-locale-definitions | |
5308 | An arbitrary list of commonly used locales, used as the default value of | |
5309 | the @code{locale-definitions} field of @code{operating-system} | |
5310 | declarations. | |
5311 | @end defvr | |
401c53c4 | 5312 | |
cf4a9129 LC |
5313 | @node Services |
5314 | @subsection Services | |
401c53c4 | 5315 | |
cf4a9129 LC |
5316 | @cindex system services |
5317 | An important part of preparing an @code{operating-system} declaration is | |
5318 | listing @dfn{system services} and their configuration (@pxref{Using the | |
5319 | Configuration System}). System services are typically daemons launched | |
5320 | when the system boots, or other actions needed at that time---e.g., | |
d8b94dbd LC |
5321 | configuring network access. |
5322 | ||
5323 | Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU | |
5324 | dmd Manual}). On a running system, the @command{deco} command allows | |
5325 | you to list the available services, show their status, start and stop | |
5326 | them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd | |
5327 | Manual}). For example: | |
5328 | ||
5329 | @example | |
5330 | # deco status dmd | |
5331 | @end example | |
5332 | ||
5333 | The above command, run as @code{root}, lists the currently defined | |
5334 | services. The @command{deco doc} command shows a synopsis of the given | |
5335 | service: | |
5336 | ||
5337 | @example | |
5338 | # deco doc nscd | |
5339 | Run libc's name service cache daemon (nscd). | |
5340 | @end example | |
5341 | ||
5342 | The @command{start}, @command{stop}, and @command{restart} sub-commands | |
5343 | have the effect you would expect. For instance, the commands below stop | |
5344 | the nscd service and restart the Xorg display server: | |
5345 | ||
5346 | @example | |
5347 | # deco stop nscd | |
5348 | Service nscd has been stopped. | |
5349 | # deco restart xorg-server | |
5350 | Service xorg-server has been stopped. | |
5351 | Service xorg-server has been started. | |
5352 | @end example | |
401c53c4 | 5353 | |
cf4a9129 | 5354 | The following sections document the available services, starting with |
d8b94dbd LC |
5355 | the core services, that may be used in an @code{operating-system} |
5356 | declaration. | |
401c53c4 | 5357 | |
cf4a9129 LC |
5358 | @menu |
5359 | * Base Services:: Essential system services. | |
5360 | * Networking Services:: Network setup, SSH daemon, etc. | |
5361 | * X Window:: Graphical display. | |
fe1a39d3 | 5362 | * Desktop Services:: D-Bus and desktop services. |
105369a4 | 5363 | * Database Services:: SQL databases. |
aa4ed923 | 5364 | * Various Services:: Other services. |
cf4a9129 | 5365 | @end menu |
401c53c4 | 5366 | |
cf4a9129 LC |
5367 | @node Base Services |
5368 | @subsubsection Base Services | |
a1ba8475 | 5369 | |
cf4a9129 LC |
5370 | The @code{(gnu services base)} module provides definitions for the basic |
5371 | services that one expects from the system. The services exported by | |
5372 | this module are listed below. | |
401c53c4 | 5373 | |
cf4a9129 LC |
5374 | @defvr {Scheme Variable} %base-services |
5375 | This variable contains a list of basic services@footnote{Technically, | |
5376 | this is a list of monadic services. @xref{The Store Monad}.} one would | |
5377 | expect from the system: a login service (mingetty) on each tty, syslogd, | |
5378 | libc's name service cache daemon (nscd), the udev device manager, and | |
5379 | more. | |
401c53c4 | 5380 | |
cf4a9129 LC |
5381 | This is the default value of the @code{services} field of |
5382 | @code{operating-system} declarations. Usually, when customizing a | |
5383 | system, you will want to append services to @var{%base-services}, like | |
5384 | this: | |
401c53c4 | 5385 | |
cf4a9129 | 5386 | @example |
fa1e31b8 | 5387 | (cons* (avahi-service) (lsh-service) %base-services) |
cf4a9129 LC |
5388 | @end example |
5389 | @end defvr | |
401c53c4 | 5390 | |
cf4a9129 LC |
5391 | @deffn {Monadic Procedure} host-name-service @var{name} |
5392 | Return a service that sets the host name to @var{name}. | |
5393 | @end deffn | |
401c53c4 | 5394 | |
cf4a9129 LC |
5395 | @deffn {Monadic Procedure} mingetty-service @var{tty} [#:motd] @ |
5396 | [#:auto-login #f] [#:login-program] [#:login-pause? #f] @ | |
5397 | [#:allow-empty-passwords? #f] | |
5398 | Return a service to run mingetty on @var{tty}. | |
401c53c4 | 5399 | |
cf4a9129 LC |
5400 | When @var{allow-empty-passwords?} is true, allow empty log-in password. When |
5401 | @var{auto-login} is true, it must be a user name under which to log-in | |
5402 | automatically. @var{login-pause?} can be set to @code{#t} in conjunction with | |
5403 | @var{auto-login}, in which case the user will have to press a key before the | |
5404 | login shell is launched. | |
401c53c4 | 5405 | |
cf4a9129 LC |
5406 | When true, @var{login-program} is a gexp or a monadic gexp denoting the name |
5407 | of the log-in program (the default is the @code{login} program from the Shadow | |
5408 | tool suite.) | |
401c53c4 | 5409 | |
cf4a9129 LC |
5410 | @var{motd} is a monadic value containing a text file to use as |
5411 | the ``message of the day''. | |
5412 | @end deffn | |
401c53c4 | 5413 | |
6454b333 LC |
5414 | @cindex name service cache daemon |
5415 | @cindex nscd | |
4aee6e60 LC |
5416 | @deffn {Monadic Procedure} nscd-service [@var{config}] [#:glibc glibc] @ |
5417 | [#:name-services '()] | |
5418 | Return a service that runs libc's name service cache daemon (nscd) with | |
5419 | the given @var{config}---an @code{<nscd-configuration>} object. | |
5420 | Optionally, @code{#:name-services} is a list of packages that provide | |
4c9050c6 LC |
5421 | name service switch (NSS) modules needed by nscd. @xref{Name Service |
5422 | Switch}, for an example. | |
cf4a9129 | 5423 | @end deffn |
401c53c4 | 5424 | |
6454b333 LC |
5425 | @defvr {Scheme Variable} %nscd-default-configuration |
5426 | This is the default @code{<nscd-configuration>} value (see below) used | |
5427 | by @code{nscd-service}. This uses the caches defined by | |
5428 | @var{%nscd-default-caches}; see below. | |
5429 | @end defvr | |
5430 | ||
5431 | @deftp {Data Type} nscd-configuration | |
5432 | This is the type representing the name service cache daemon (nscd) | |
5433 | configuration. | |
5434 | ||
5435 | @table @asis | |
5436 | ||
5437 | @item @code{log-file} (default: @code{"/var/log/nscd.log"}) | |
5438 | Name of nscd's log file. This is where debugging output goes when | |
5439 | @code{debug-level} is strictly positive. | |
5440 | ||
5441 | @item @code{debug-level} (default: @code{0}) | |
5442 | Integer denoting the debugging levels. Higher numbers mean more | |
5443 | debugging output is logged. | |
5444 | ||
5445 | @item @code{caches} (default: @var{%nscd-default-caches}) | |
5446 | List of @code{<nscd-cache>} objects denoting things to be cached; see | |
5447 | below. | |
5448 | ||
5449 | @end table | |
5450 | @end deftp | |
5451 | ||
5452 | @deftp {Data Type} nscd-cache | |
5453 | Data type representing a cache database of nscd and its parameters. | |
5454 | ||
5455 | @table @asis | |
5456 | ||
5457 | @item @code{database} | |
5458 | This is a symbol representing the name of the database to be cached. | |
5459 | Valid values are @code{passwd}, @code{group}, @code{hosts}, and | |
5460 | @code{services}, which designate the corresponding NSS database | |
5461 | (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}). | |
5462 | ||
5463 | @item @code{positive-time-to-live} | |
5464 | @itemx @code{negative-time-to-live} (default: @code{20}) | |
5465 | A number representing the number of seconds during which a positive or | |
5466 | negative lookup result remains in cache. | |
5467 | ||
5468 | @item @code{check-files?} (default: @code{#t}) | |
5469 | Whether to check for updates of the files corresponding to | |
5470 | @var{database}. | |
5471 | ||
5472 | For instance, when @var{database} is @code{hosts}, setting this flag | |
5473 | instructs nscd to check for updates in @file{/etc/hosts} and to take | |
5474 | them into account. | |
5475 | ||
5476 | @item @code{persistent?} (default: @code{#t}) | |
5477 | Whether the cache should be stored persistently on disk. | |
5478 | ||
5479 | @item @code{shared?} (default: @code{#t}) | |
5480 | Whether the cache should be shared among users. | |
5481 | ||
5482 | @item @code{max-database-size} (default: 32@tie{}MiB) | |
5483 | Maximum size in bytes of the database cache. | |
5484 | ||
5485 | @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert | |
5486 | @c settings, so leave them out. | |
5487 | ||
5488 | @end table | |
5489 | @end deftp | |
5490 | ||
5491 | @defvr {Scheme Variable} %nscd-default-caches | |
5492 | List of @code{<nscd-cache>} objects used by default by | |
5493 | @code{nscd-configuration} (see above.) | |
5494 | ||
5495 | It enables persistent and aggressive caching of service and host name | |
5496 | lookups. The latter provides better host name lookup performance, | |
5497 | resilience in the face of unreliable name servers, and also better | |
5498 | privacy---often the result of host name lookups is in local cache, so | |
5499 | external name servers do not even need to be queried. | |
5500 | @end defvr | |
5501 | ||
5502 | ||
1bb76f75 AK |
5503 | @deffn {Monadic Procedure} syslog-service [#:config-file #f] |
5504 | Return a service that runs @code{syslogd}. If configuration file name | |
5505 | @var{config-file} is not specified, use some reasonable default | |
cf4a9129 LC |
5506 | settings. |
5507 | @end deffn | |
401c53c4 | 5508 | |
cf4a9129 LC |
5509 | @deffn {Monadic Procedure} guix-service [#:guix guix] @ |
5510 | [#:builder-group "guixbuild"] [#:build-accounts 10] @ | |
02bb6b45 | 5511 | [#:authorize-hydra-key? #t] [#:use-substitutes? #t] @ |
cf4a9129 LC |
5512 | [#:extra-options '()] |
5513 | Return a service that runs the build daemon from @var{guix}, and has | |
5514 | @var{build-accounts} user accounts available under @var{builder-group}. | |
401c53c4 | 5515 | |
cf4a9129 LC |
5516 | When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key |
5517 | provided by @var{guix} is authorized upon activation, meaning that substitutes | |
5518 | from @code{hydra.gnu.org} are used by default. | |
401c53c4 | 5519 | |
cf4a9129 LC |
5520 | If @var{use-substitutes?} is false, the daemon is run with |
5521 | @option{--no-substitutes} (@pxref{Invoking guix-daemon, | |
5522 | @option{--no-substitutes}}). | |
401c53c4 | 5523 | |
cf4a9129 LC |
5524 | Finally, @var{extra-options} is a list of additional command-line options |
5525 | passed to @command{guix-daemon}. | |
5526 | @end deffn | |
a1ba8475 | 5527 | |
cf4a9129 LC |
5528 | @deffn {Monadic Procedure} udev-service [#:udev udev] |
5529 | Run @var{udev}, which populates the @file{/dev} directory dynamically. | |
5530 | @end deffn | |
401c53c4 | 5531 | |
5eca9459 AK |
5532 | @deffn {Monadic Procedure} console-keymap-service @var{file} |
5533 | Return a service to load console keymap from @var{file} using | |
5534 | @command{loadkeys} command. | |
5535 | @end deffn | |
5536 | ||
a69576ea | 5537 | |
cf4a9129 LC |
5538 | @node Networking Services |
5539 | @subsubsection Networking Services | |
401c53c4 | 5540 | |
fa1e31b8 | 5541 | The @code{(gnu services networking)} module provides services to configure |
cf4a9129 | 5542 | the network interface. |
a1ba8475 | 5543 | |
a023cca8 LC |
5544 | @cindex DHCP, networking service |
5545 | @deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}] | |
5546 | Return a service that runs @var{dhcp}, a Dynamic Host Configuration | |
5547 | Protocol (DHCP) client, on all the non-loopback network interfaces. | |
5548 | @end deffn | |
5549 | ||
cf4a9129 LC |
5550 | @deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @ |
5551 | [#:gateway #f] [#:name-services @code{'()}] | |
5552 | Return a service that starts @var{interface} with address @var{ip}. If | |
5553 | @var{gateway} is true, it must be a string specifying the default network | |
5554 | gateway. | |
5555 | @end deffn | |
8b315a6d | 5556 | |
b7d0c494 MW |
5557 | @cindex wicd |
5558 | @deffn {Monadic Procedure} wicd-service [#:wicd @var{wicd}] | |
5559 | Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a | |
5560 | network manager that aims to simplify wired and wireless networking. | |
5561 | @end deffn | |
5562 | ||
63854bcb LC |
5563 | @deffn {Monadic Procedure} ntp-service [#:ntp @var{ntp}] @ |
5564 | [#:name-service @var{%ntp-servers}] | |
5565 | Return a service that runs the daemon from @var{ntp}, the | |
5566 | @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will | |
5567 | keep the system clock synchronized with that of @var{servers}. | |
5568 | @end deffn | |
5569 | ||
5570 | @defvr {Scheme Variable} %ntp-servers | |
5571 | List of host names used as the default NTP servers. | |
5572 | @end defvr | |
5573 | ||
cf4a9129 LC |
5574 | @deffn {Monadic Procedure} tor-service [#:tor tor] |
5575 | Return a service to run the @uref{https://torproject.org,Tor} daemon. | |
8b315a6d | 5576 | |
cf4a9129 LC |
5577 | The daemon runs with the default settings (in particular the default exit |
5578 | policy) as the @code{tor} unprivileged user. | |
5579 | @end deffn | |
8b315a6d | 5580 | |
4627a464 LC |
5581 | @deffn {Monadic Procedure} bitlbee-service [#:bitlbee bitlbee] @ |
5582 | [#:interface "127.0.0.1"] [#:port 6667] @ | |
5583 | [#:extra-settings ""] | |
5584 | Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that | |
5585 | acts as a gateway between IRC and chat networks. | |
5586 | ||
5587 | The daemon will listen to the interface corresponding to the IP address | |
5588 | specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only | |
5589 | local clients can connect, whereas @code{0.0.0.0} means that connections can | |
5590 | come from any networking interface. | |
5591 | ||
5592 | In addition, @var{extra-settings} specifies a string to append to the | |
5593 | configuration file. | |
5594 | @end deffn | |
5595 | ||
f4391bec | 5596 | Furthermore, @code{(gnu services ssh)} provides the following service. |
8b315a6d | 5597 | |
cf4a9129 | 5598 | @deffn {Monadic Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @ |
5833bf33 | 5599 | [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @ |
cf4a9129 LC |
5600 | [#:allow-empty-passwords? #f] [#:root-login? #f] @ |
5601 | [#:syslog-output? #t] [#:x11-forwarding? #t] @ | |
5602 | [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @ | |
21cc905a | 5603 | [#:public-key-authentication? #t] [#:initialize? #t] |
cf4a9129 LC |
5604 | Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}. |
5605 | @var{host-key} must designate a file containing the host key, and readable | |
5606 | only by root. | |
72e25e35 | 5607 | |
5833bf33 DP |
5608 | When @var{daemonic?} is true, @command{lshd} will detach from the |
5609 | controlling terminal and log its output to syslogd, unless one sets | |
5610 | @var{syslog-output?} to false. Obviously, it also makes lsh-service | |
5611 | depend on existence of syslogd service. When @var{pid-file?} is true, | |
5612 | @command{lshd} writes its PID to the file called @var{pid-file}. | |
5613 | ||
cf4a9129 LC |
5614 | When @var{initialize?} is true, automatically create the seed and host key |
5615 | upon service activation if they do not exist yet. This may take long and | |
5616 | require interaction. | |
8b315a6d | 5617 | |
20dd519c LC |
5618 | When @var{initialize?} is false, it is up to the user to initialize the |
5619 | randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create | |
5620 | a key pair with the private key stored in file @var{host-key} (@pxref{lshd | |
5621 | basics,,, lsh, LSH Manual}). | |
5622 | ||
cf4a9129 LC |
5623 | When @var{interfaces} is empty, lshd listens for connections on all the |
5624 | network interfaces; otherwise, @var{interfaces} must be a list of host names | |
5625 | or addresses. | |
9bf3c1a7 | 5626 | |
20dd519c LC |
5627 | @var{allow-empty-passwords?} specifies whether to accept log-ins with empty |
5628 | passwords, and @var{root-login?} specifies whether to accept log-ins as | |
cf4a9129 | 5629 | root. |
4af2447e | 5630 | |
cf4a9129 LC |
5631 | The other options should be self-descriptive. |
5632 | @end deffn | |
4af2447e | 5633 | |
fa0c1d61 LC |
5634 | @defvr {Scheme Variable} %facebook-host-aliases |
5635 | This variable contains a string for use in @file{/etc/hosts} | |
5636 | (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each | |
5637 | line contains a entry that maps a known server name of the Facebook | |
5638 | on-line service---e.g., @code{www.facebook.com}---to the local | |
5639 | host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. | |
5640 | ||
5641 | This variable is typically used in the @code{hosts-file} field of an | |
7313a52e LC |
5642 | @code{operating-system} declaration (@pxref{operating-system Reference, |
5643 | @file{/etc/hosts}}): | |
fa0c1d61 LC |
5644 | |
5645 | @example | |
5646 | (use-modules (gnu) (guix)) | |
5647 | ||
5648 | (operating-system | |
5649 | (host-name "mymachine") | |
5650 | ;; ... | |
5651 | (hosts-file | |
5652 | ;; Create a /etc/hosts file with aliases for "localhost" | |
5653 | ;; and "mymachine", as well as for Facebook servers. | |
24e02c28 LC |
5654 | (plain-file "hosts" |
5655 | (string-append (local-host-aliases host-name) | |
5656 | %facebook-host-aliases)))) | |
fa0c1d61 LC |
5657 | @end example |
5658 | ||
5659 | This mechanism can prevent programs running locally, such as Web | |
5660 | browsers, from accessing Facebook. | |
5661 | @end defvr | |
5662 | ||
965a7332 LC |
5663 | The @code{(gnu services avahi)} provides the following definition. |
5664 | ||
5665 | @deffn {Monadic Procedure} avahi-service [#:avahi @var{avahi}] @ | |
5666 | [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @ | |
5667 | [#:ipv6? #t] [#:wide-area? #f] @ | |
5668 | [#:domains-to-browse '()] | |
5669 | Return a service that runs @command{avahi-daemon}, a system-wide | |
5670 | mDNS/DNS-SD responder that allows for service discovery and | |
5671 | "zero-configuration" host name lookups (see @uref{http://avahi.org/}). | |
5672 | ||
5673 | If @var{host-name} is different from @code{#f}, use that as the host name to | |
5674 | publish for this machine; otherwise, use the machine's actual host name. | |
5675 | ||
5676 | When @var{publish?} is true, publishing of host names and services is allowed; | |
5677 | in particular, avahi-daemon will publish the machine's host name and IP | |
5678 | address via mDNS on the local network. | |
5679 | ||
5680 | When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled. | |
5681 | ||
5682 | Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6 | |
5683 | sockets. | |
5684 | @end deffn | |
5685 | ||
5686 | ||
cf4a9129 LC |
5687 | @node X Window |
5688 | @subsubsection X Window | |
68ad877c | 5689 | |
cf4a9129 LC |
5690 | Support for the X Window graphical display system---specifically |
5691 | Xorg---is provided by the @code{(gnu services xorg)} module. Note that | |
5692 | there is no @code{xorg-service} procedure. Instead, the X server is | |
5693 | started by the @dfn{login manager}, currently SLiM. | |
4af2447e | 5694 | |
cf4a9129 | 5695 | @deffn {Monadic Procedure} slim-service [#:allow-empty-passwords? #f] @ |
0ecc3bf3 LC |
5696 | [#:auto-login? #f] [#:default-user ""] [#:startx] @ |
5697 | [#:theme @var{%default-slim-theme}] @ | |
4bd43bbe | 5698 | [#:theme-name @var{%default-slim-theme-name}] |
cf4a9129 LC |
5699 | Return a service that spawns the SLiM graphical login manager, which in |
5700 | turn starts the X display server with @var{startx}, a command as returned by | |
5701 | @code{xorg-start-command}. | |
4af2447e | 5702 | |
04e4e6ab LC |
5703 | @cindex X session |
5704 | ||
5705 | SLiM automatically looks for session types described by the @file{.desktop} | |
5706 | files in @file{/run/current-system/profile/share/xsessions} and allows users | |
5707 | to choose a session from the log-in screen using @kbd{F1}. Packages such as | |
5708 | @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files; | |
5709 | adding them to the system-wide set of packages automatically makes them | |
5710 | available at the log-in screen. | |
5711 | ||
5712 | In addition, @file{~/.xsession} files are honored. When available, | |
5713 | @file{~/.xsession} must be an executable that starts a window manager | |
5714 | and/or other X clients. | |
5715 | ||
cf4a9129 LC |
5716 | When @var{allow-empty-passwords?} is true, allow logins with an empty |
5717 | password. When @var{auto-login?} is true, log in automatically as | |
5718 | @var{default-user}. | |
0ecc3bf3 LC |
5719 | |
5720 | If @var{theme} is @code{#f}, the use the default log-in theme; otherwise | |
5721 | @var{theme} must be a gexp denoting the name of a directory containing the | |
5722 | theme to use. In that case, @var{theme-name} specifies the name of the | |
5723 | theme. | |
cf4a9129 | 5724 | @end deffn |
4af2447e | 5725 | |
0ecc3bf3 LC |
5726 | @defvr {Scheme Variable} %default-theme |
5727 | @defvrx {Scheme Variable} %default-theme-name | |
5728 | The G-Expression denoting the default SLiM theme and its name. | |
5729 | @end defvr | |
5730 | ||
f703413e | 5731 | @deffn {Monadic Procedure} xorg-start-command [#:guile] @ |
d1cdd7ba | 5732 | [#:configuration-file #f] [#:xorg-server @var{xorg-server}] |
f703413e | 5733 | Return a derivation that builds a @var{guile} script to start the X server |
d1cdd7ba LC |
5734 | from @var{xorg-server}. @var{configuration-file} is the server configuration |
5735 | file or a derivation that builds it; when omitted, the result of | |
5736 | @code{xorg-configuration-file} is used. | |
5737 | ||
5738 | Usually the X server is started by a login manager. | |
5739 | @end deffn | |
5740 | ||
5741 | @deffn {Monadic Procedure} xorg-configuration-file @ | |
12422c9d | 5742 | [#:drivers '()] [#:resolutions '()] [#:extra-config '()] |
d1cdd7ba LC |
5743 | Return a configuration file for the Xorg server containing search paths for |
5744 | all the common drivers. | |
f703413e LC |
5745 | |
5746 | @var{drivers} must be either the empty list, in which case Xorg chooses a | |
5747 | graphics driver automatically, or a list of driver names that will be tried in | |
d1cdd7ba | 5748 | this order---e.g., @code{(\"modesetting\" \"vesa\")}. |
d2e59637 LC |
5749 | |
5750 | Likewise, when @var{resolutions} is the empty list, Xorg chooses an | |
5751 | appropriate screen resolution; otherwise, it must be a list of | |
5752 | resolutions---e.g., @code{((1024 768) (640 480))}. | |
12422c9d LC |
5753 | |
5754 | Last, @var{extra-config} is a list of strings or objects appended to the | |
5755 | @code{text-file*} argument list. It is used to pass extra text to be added | |
5756 | verbatim to the configuration file. | |
f703413e | 5757 | @end deffn |
4af2447e | 5758 | |
fe1a39d3 LC |
5759 | @node Desktop Services |
5760 | @subsubsection Desktop Services | |
aa4ed923 | 5761 | |
fe1a39d3 LC |
5762 | The @code{(gnu services desktop)} module provides services that are |
5763 | usually useful in the context of a ``desktop'' setup---that is, on a | |
5764 | machine running a graphical display server, possibly with graphical user | |
5765 | interfaces, etc. | |
aa4ed923 | 5766 | |
4467be21 LC |
5767 | To simplify things, the module defines a variable containing the set of |
5768 | services that users typically expect on a machine with a graphical | |
5769 | environment and networking: | |
5770 | ||
5771 | @defvr {Scheme Variable} %desktop-services | |
5772 | This is a list of services that builds upon @var{%base-services} and | |
5773 | adds or adjust services for a typical ``desktop'' setup. | |
5774 | ||
5775 | In particular, it adds a graphical login manager (@pxref{X Window, | |
5776 | @code{slim-service}}), a network management tool (@pxref{Networking | |
5777 | Services, @code{wicd-service}}), energy and color management services, | |
4a3bcaee | 5778 | an NTP client (@pxref{Networking Services}), the Avahi |
4467be21 LC |
5779 | daemon, and has the name service switch service configured to be able to |
5780 | use @code{nss-mdns} (@pxref{Name Service Switch, mDNS}). | |
5781 | @end defvr | |
5782 | ||
5783 | The @var{%desktop-services} variable can be used as the @code{services} | |
5784 | field of an @code{operating-system} declaration (@pxref{operating-system | |
5785 | Reference, @code{services}}). | |
5786 | ||
5787 | The actual service definitions provided by @code{(gnu services desktop)} | |
5788 | are described below. | |
5789 | ||
fe1a39d3 LC |
5790 | @deffn {Monadic Procedure} dbus-service @var{services} @ |
5791 | [#:dbus @var{dbus}] | |
5792 | Return a service that runs the ``system bus'', using @var{dbus}, with | |
5793 | support for @var{services}. | |
aa4ed923 | 5794 | |
fe1a39d3 LC |
5795 | @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication |
5796 | facility. Its system bus is used to allow system services to communicate | |
5797 | and be notified of system-wide events. | |
aa4ed923 | 5798 | |
fe1a39d3 LC |
5799 | @var{services} must be a list of packages that provide an |
5800 | @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration | |
5801 | and policy files. For example, to allow avahi-daemon to use the system bus, | |
5802 | @var{services} must be equal to @code{(list avahi)}. | |
aa4ed923 AK |
5803 | @end deffn |
5804 | ||
be234128 AW |
5805 | @deffn {Monadic Procedure} upower-service [#:upower @var{upower}] @ |
5806 | [#:watts-up-pro? #f] @ | |
5807 | [#:poll-batteries? #t] @ | |
5808 | [#:ignore-lid? #f] @ | |
5809 | [#:use-percentage-for-policy? #f] @ | |
5810 | [#:percentage-low 10] @ | |
5811 | [#:percentage-critical 3] @ | |
5812 | [#:percentage-action 2] @ | |
5813 | [#:time-low 1200] @ | |
5814 | [#:time-critical 300] @ | |
5815 | [#:time-action 120] @ | |
5816 | [#:critical-power-action 'hybrid-sleep] | |
5817 | Return a service that runs @uref{http://upower.freedesktop.org/, | |
5818 | @command{upowerd}}, a system-wide monitor for power consumption and battery | |
5819 | levels, with the given configuration settings. It implements the | |
5820 | @code{org.freedesktop.UPower} D-Bus interface, and is notably used by | |
5821 | GNOME. | |
5822 | @end deffn | |
5823 | ||
7ce597ff AW |
5824 | @deffn {Monadic Procedure} colord-service [#:colord @var{colord}] |
5825 | Return a service that runs @command{colord}, a system service with a D-Bus | |
5826 | interface to manage the color profiles of input and output devices such as | |
5827 | screens and scanners. It is notably used by the GNOME Color Manager graphical | |
5828 | tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web | |
5829 | site} for more information. | |
5830 | @end deffn | |
5831 | ||
105369a4 DT |
5832 | @node Database Services |
5833 | @subsubsection Database Services | |
5834 | ||
5835 | The @code{(gnu services databases)} module provides the following service. | |
5836 | ||
5837 | @deffn {Monadic Procedure} postgresql-service [#:postgresql postgresql] @ | |
5838 | [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] | |
5839 | Return a service that runs @var{postgresql}, the PostgreSQL database | |
5840 | server. | |
5841 | ||
5842 | The PostgreSQL daemon loads its runtime configuration from | |
5843 | @var{config-file} and stores the database cluster in | |
5844 | @var{data-directory}. | |
5845 | @end deffn | |
fe1a39d3 LC |
5846 | |
5847 | @node Various Services | |
5848 | @subsubsection Various Services | |
5849 | ||
5850 | The @code{(gnu services lirc)} module provides the following service. | |
5851 | ||
5852 | @deffn {Monadic Procedure} lirc-service [#:lirc lirc] @ | |
5853 | [#:device #f] [#:driver #f] [#:config-file #f] @ | |
5854 | [#:extra-options '()] | |
5855 | Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that | |
5856 | decodes infrared signals from remote controls. | |
5857 | ||
5858 | Optionally, @var{device}, @var{driver} and @var{config-file} | |
5859 | (configuration file name) may be specified. See @command{lircd} manual | |
5860 | for details. | |
5861 | ||
5862 | Finally, @var{extra-options} is a list of additional command-line options | |
5863 | passed to @command{lircd}. | |
5864 | @end deffn | |
5865 | ||
5866 | ||
0ae8c15a LC |
5867 | @node Setuid Programs |
5868 | @subsection Setuid Programs | |
5869 | ||
5870 | @cindex setuid programs | |
5871 | Some programs need to run with ``root'' privileges, even when they are | |
5872 | launched by unprivileged users. A notorious example is the | |
5873 | @command{passwd} programs, which can users can run to change their | |
5874 | password, and which requires write access to the @file{/etc/passwd} and | |
5875 | @file{/etc/shadow} files---something normally restricted to root, for | |
5876 | obvious security reasons. To address that, these executables are | |
5877 | @dfn{setuid-root}, meaning that they always run with root privileges | |
5878 | (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual}, | |
5879 | for more info about the setuid mechanisms.) | |
5880 | ||
5881 | The store itself @emph{cannot} contain setuid programs: that would be a | |
5882 | security issue since any user on the system can write derivations that | |
5883 | populate the store (@pxref{The Store}). Thus, a different mechanism is | |
5884 | used: instead of changing the setuid bit directly on files that are in | |
5885 | the store, we let the system administrator @emph{declare} which programs | |
5886 | should be setuid root. | |
5887 | ||
5888 | The @code{setuid-programs} field of an @code{operating-system} | |
5889 | declaration contains a list of G-expressions denoting the names of | |
5890 | programs to be setuid-root (@pxref{Using the Configuration System}). | |
5891 | For instance, the @command{passwd} program, which is part of the Shadow | |
5892 | package, can be designated by this G-expression (@pxref{G-Expressions}): | |
5893 | ||
5894 | @example | |
5895 | #~(string-append #$shadow "/bin/passwd") | |
5896 | @end example | |
5897 | ||
5898 | A default set of setuid programs is defined by the | |
5899 | @code{%setuid-programs} variable of the @code{(gnu system)} module. | |
5900 | ||
5901 | @defvr {Scheme Variable} %setuid-programs | |
5902 | A list of G-expressions denoting common programs that are setuid-root. | |
5903 | ||
5904 | The list includes commands such as @command{passwd}, @command{ping}, | |
5905 | @command{su}, and @command{sudo}. | |
5906 | @end defvr | |
5907 | ||
5908 | Under the hood, the actual setuid programs are created in the | |
5909 | @file{/run/setuid-programs} directory at system activation time. The | |
5910 | files in this directory refer to the ``real'' binaries, which are in the | |
5911 | store. | |
5912 | ||
efb5e833 LC |
5913 | @node X.509 Certificates |
5914 | @subsection X.509 Certificates | |
5915 | ||
5916 | @cindex HTTPS, certificates | |
5917 | @cindex X.509 certificates | |
5918 | @cindex TLS | |
5919 | Web servers available over HTTPS (that is, HTTP over the transport-layer | |
5920 | security mechanism, TLS) send client programs an @dfn{X.509 certificate} | |
5921 | that the client can then use to @emph{authenticate} the server. To do | |
5922 | that, clients verify that the server's certificate is signed by a | |
5923 | so-called @dfn{certificate authority} (CA). But to verify the CA's | |
5924 | signature, clients must have first acquired the CA's certificate. | |
5925 | ||
5926 | Web browsers such as GNU@tie{}IceCat include their own set of CA | |
5927 | certificates, such that they are able to verify CA signatures | |
5928 | out-of-the-box. | |
5929 | ||
5930 | However, most other programs that can talk HTTPS---@command{wget}, | |
5931 | @command{git}, @command{w3m}, etc.---need to be told where CA | |
5932 | certificates can be found. | |
5933 | ||
5934 | @cindex @code{nss-certs} | |
5935 | In GuixSD, this is done by adding a package that provides certificates | |
5936 | to the @code{packages} field of the @code{operating-system} declaration | |
5937 | (@pxref{operating-system Reference}). GuixSD includes one such package, | |
5938 | @code{nss-certs}, which is a set of CA certificates provided as part of | |
5939 | Mozilla's Network Security Services. | |
5940 | ||
5941 | Note that it is @emph{not} part of @var{%base-packages}, so you need to | |
5942 | explicitly add it. The @file{/etc/ssl/certs} directory, which is where | |
5943 | most applications and libraries look for certificates by default, points | |
5944 | to the certificates installed globally. | |
5945 | ||
5946 | Unprivileged users can also install their own certificate package in | |
5947 | their profile. A number of environment variables need to be defined so | |
5948 | that applications and libraries know where to find them. Namely, the | |
5949 | OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE} | |
5950 | variables. Some applications add their own environment variables; for | |
5951 | instance, the Git version control system honors the certificate bundle | |
5952 | pointed to by the @code{GIT_SSL_CAINFO} environment variable. | |
5953 | ||
5954 | ||
996ed739 LC |
5955 | @node Name Service Switch |
5956 | @subsection Name Service Switch | |
5957 | ||
5958 | @cindex name service switch | |
5959 | @cindex NSS | |
5960 | The @code{(gnu system nss)} module provides bindings to the | |
5961 | configuration file of libc's @dfn{name service switch} or @dfn{NSS} | |
5962 | (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference | |
5963 | Manual}). In a nutshell, the NSS is a mechanism that allows libc to be | |
5964 | extended with new ``name'' lookup methods for system databases, which | |
5965 | includes host names, service names, user accounts, and more (@pxref{Name | |
5966 | Service Switch, System Databases and Name Service Switch,, libc, The GNU | |
5967 | C Library Reference Manual}). | |
5968 | ||
5969 | The NSS configuration specifies, for each system database, which lookup | |
5970 | method is to be used, and how the various methods are chained | |
5971 | together---for instance, under which circumstances NSS should try the | |
5972 | next method in the list. The NSS configuration is given in the | |
5973 | @code{name-service-switch} field of @code{operating-system} declarations | |
5974 | (@pxref{operating-system Reference, @code{name-service-switch}}). | |
5975 | ||
4c9050c6 LC |
5976 | @cindex nss-mdns |
5977 | @cindex .local, host name lookup | |
996ed739 | 5978 | As an example, the declaration below configures the NSS to use the |
4c9050c6 LC |
5979 | @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns} |
5980 | back-end}, which supports host name lookups over multicast DNS (mDNS) | |
5981 | for host names ending in @code{.local}: | |
996ed739 LC |
5982 | |
5983 | @example | |
5984 | (name-service-switch | |
5985 | (hosts (list %files ;first, check /etc/hosts | |
5986 | ||
5987 | ;; If the above did not succeed, try | |
5988 | ;; with 'mdns_minimal'. | |
5989 | (name-service | |
5990 | (name "mdns_minimal") | |
5991 | ||
5992 | ;; 'mdns_minimal' is authoritative for | |
5993 | ;; '.local'. When it returns "not found", | |
5994 | ;; no need to try the next methods. | |
5995 | (reaction (lookup-specification | |
5996 | (not-found => return)))) | |
5997 | ||
5998 | ;; Then fall back to DNS. | |
5999 | (name-service | |
6000 | (name "dns")) | |
6001 | ||
6002 | ;; Finally, try with the "full" 'mdns'. | |
6003 | (name-service | |
6004 | (name "mdns"))))) | |
6005 | @end example | |
6006 | ||
15137a29 LC |
6007 | Don't worry: the @code{%mdns-host-lookup-nss} variable (see below) |
6008 | contains this configuration, so you won't have to type it if all you | |
6009 | want is to have @code{.local} host lookup working. | |
6010 | ||
4c9050c6 LC |
6011 | Note that, in this case, in addition to setting the |
6012 | @code{name-service-switch} of the @code{operating-system} declaration, | |
6013 | @code{nscd-service} must be told where to find the @code{nss-mdns} | |
6014 | shared library (@pxref{Base Services, @code{nscd-service}}). Since the | |
6015 | @code{nscd} service is part of @var{%base-services}, you may want to | |
6016 | customize it by adding this snippet in the operating system | |
6017 | configuration file: | |
6018 | ||
6019 | @example | |
6020 | (use-modules (guix) (gnu)) | |
6021 | ||
6022 | (define %my-base-services | |
6023 | ;; Replace the default nscd service with one that knows | |
6024 | ;; about nss-mdns. | |
6025 | (map (lambda (mservice) | |
6026 | ;; "Bind" the MSERVICE monadic value to inspect it. | |
6027 | (mlet %store-monad ((service mservice)) | |
6028 | (if (member 'nscd (service-provision service)) | |
6029 | (nscd-service (nscd-configuration) | |
6030 | #:name-services (list nss-mdns)) | |
6031 | mservice))) | |
6032 | %base-services)) | |
6033 | @end example | |
6034 | ||
6035 | @noindent | |
6036 | @dots{} and then refer to @var{%my-base-services} instead of | |
6037 | @var{%base-services} in the @code{operating-system} declaration. | |
15137a29 | 6038 | Lastly, this relies on the availability of the Avahi service |
965a7332 | 6039 | (@pxref{Networking Services, @code{avahi-service}}). |
15137a29 LC |
6040 | |
6041 | For convenience, the following variables provide typical NSS | |
6042 | configurations. | |
6043 | ||
6044 | @defvr {Scheme Variable} %default-nss | |
6045 | This is the default name service switch configuration, a | |
6046 | @code{name-service-switch} object. | |
6047 | @end defvr | |
6048 | ||
6049 | @defvr {Scheme Variable} %mdns-host-lookup-nss | |
6050 | This is the name service switch configuration with support for host name | |
6051 | lookup over multicast DNS (mDNS) for host names ending in @code{.local}. | |
6052 | @end defvr | |
4c9050c6 | 6053 | |
996ed739 LC |
6054 | The reference for name service switch configuration is given below. It |
6055 | is a direct mapping of the C library's configuration file format, so | |
6056 | please refer to the C library manual for more information (@pxref{NSS | |
6057 | Configuration File,,, libc, The GNU C Library Reference Manual}). | |
6058 | Compared to libc's NSS configuration file format, it has the advantage | |
6059 | not only of adding this warm parenthetic feel that we like, but also | |
6060 | static checks: you'll know about syntax errors and typos as soon as you | |
6061 | run @command{guix system}. | |
6062 | ||
996ed739 LC |
6063 | @deftp {Data Type} name-service-switch |
6064 | ||
6065 | This is the data type representation the configuration of libc's name | |
6066 | service switch (NSS). Each field below represents one of the supported | |
6067 | system databases. | |
6068 | ||
6069 | @table @code | |
6070 | @item aliases | |
6071 | @itemx ethers | |
6072 | @itemx group | |
6073 | @itemx gshadow | |
6074 | @itemx hosts | |
6075 | @itemx initgroups | |
6076 | @itemx netgroup | |
6077 | @itemx networks | |
6078 | @itemx password | |
6079 | @itemx public-key | |
6080 | @itemx rpc | |
6081 | @itemx services | |
6082 | @itemx shadow | |
6083 | The system databases handled by the NSS. Each of these fields must be a | |
6084 | list of @code{<name-service>} objects (see below.) | |
6085 | @end table | |
6086 | @end deftp | |
6087 | ||
6088 | @deftp {Data Type} name-service | |
6089 | ||
6090 | This is the data type representing an actual name service and the | |
6091 | associated lookup action. | |
6092 | ||
6093 | @table @code | |
6094 | @item name | |
6095 | A string denoting the name service (@pxref{Services in the NSS | |
6096 | configuration,,, libc, The GNU C Library Reference Manual}). | |
6097 | ||
4aee6e60 LC |
6098 | Note that name services listed here must be visible to nscd. This is |
6099 | achieved by passing the @code{#:name-services} argument to | |
6100 | @code{nscd-service} the list of packages providing the needed name | |
6101 | services (@pxref{Base Services, @code{nscd-service}}). | |
6102 | ||
996ed739 LC |
6103 | @item reaction |
6104 | An action specified using the @code{lookup-specification} macro | |
6105 | (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library | |
6106 | Reference Manual}). For example: | |
6107 | ||
6108 | @example | |
6109 | (lookup-specification (unavailable => continue) | |
6110 | (success => return)) | |
6111 | @end example | |
6112 | @end table | |
6113 | @end deftp | |
0ae8c15a | 6114 | |
fd1b1fa2 LC |
6115 | @node Initial RAM Disk |
6116 | @subsection Initial RAM Disk | |
6117 | ||
6118 | @cindex initial RAM disk (initrd) | |
6119 | @cindex initrd (initial RAM disk) | |
6120 | For bootstrapping purposes, the Linux-Libre kernel is passed an | |
6121 | @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary | |
6122 | root file system, as well as an initialization script. The latter is | |
6123 | responsible for mounting the real root file system, and for loading any | |
6124 | kernel modules that may be needed to achieve that. | |
6125 | ||
6126 | The @code{initrd} field of an @code{operating-system} declaration allows | |
6127 | you to specify which initrd you would like to use. The @code{(gnu | |
6128 | system linux-initrd)} module provides two ways to build an initrd: the | |
6129 | high-level @code{base-initrd} procedure, and the low-level | |
6130 | @code{expression->initrd} procedure. | |
6131 | ||
6132 | The @code{base-initrd} procedure is intended to cover most common uses. | |
6133 | For example, if you want to add a bunch of kernel modules to be loaded | |
6134 | at boot time, you can define the @code{initrd} field of the operating | |
6135 | system declaration like this: | |
6136 | ||
6137 | @example | |
52ac153e | 6138 | (initrd (lambda (file-systems . rest) |
027981d6 LC |
6139 | ;; Create a standard initrd that has modules "foo.ko" |
6140 | ;; and "bar.ko", as well as their dependencies, in | |
6141 | ;; addition to the modules available by default. | |
52ac153e | 6142 | (apply base-initrd file-systems |
027981d6 | 6143 | #:extra-modules '("foo" "bar") |
52ac153e | 6144 | rest))) |
fd1b1fa2 LC |
6145 | @end example |
6146 | ||
52ac153e LC |
6147 | The @code{base-initrd} procedure also handles common use cases that |
6148 | involves using the system as a QEMU guest, or as a ``live'' system whose | |
6149 | root file system is volatile. | |
fd1b1fa2 LC |
6150 | |
6151 | @deffn {Monadic Procedure} base-initrd @var{file-systems} @ | |
6152 | [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @ | |
52ac153e | 6153 | [#:extra-modules '()] [#:mapped-devices '()] |
fd1b1fa2 LC |
6154 | Return a monadic derivation that builds a generic initrd. @var{file-systems} is |
6155 | a list of file-systems to be mounted by the initrd, possibly in addition to | |
6156 | the root file system specified on the kernel command line via @code{--root}. | |
52ac153e LC |
6157 | @var{mapped-devices} is a list of device mappings to realize before |
6158 | @var{file-systems} are mounted (@pxref{Mapped Devices}). | |
fd1b1fa2 LC |
6159 | |
6160 | When @var{qemu-networking?} is true, set up networking with the standard QEMU | |
6161 | parameters. When @var{virtio?} is true, load additional modules so the initrd can | |
6162 | be used as a QEMU guest with para-virtualized I/O drivers. | |
6163 | ||
6164 | When @var{volatile-root?} is true, the root file system is writable but any changes | |
6165 | to it are lost. | |
6166 | ||
6167 | The initrd is automatically populated with all the kernel modules necessary | |
6168 | for @var{file-systems} and for the given options. However, additional kernel | |
6169 | modules can be listed in @var{extra-modules}. They will be added to the initrd, and | |
6170 | loaded at boot time in the order in which they appear. | |
6171 | @end deffn | |
6172 | ||
6173 | Needless to say, the initrds we produce and use embed a | |
6174 | statically-linked Guile, and the initialization program is a Guile | |
6175 | program. That gives a lot of flexibility. The | |
6176 | @code{expression->initrd} procedure builds such an initrd, given the | |
6177 | program to run in that initrd. | |
6178 | ||
6179 | @deffn {Monadic Procedure} expression->initrd @var{exp} @ | |
6180 | [#:guile %guile-static-stripped] [#:name "guile-initrd"] @ | |
42d10464 | 6181 | [#:modules '()] |
fd1b1fa2 LC |
6182 | Return a derivation that builds a Linux initrd (a gzipped cpio archive) |
6183 | containing @var{guile} and that evaluates @var{exp}, a G-expression, | |
df650fa8 LC |
6184 | upon booting. All the derivations referenced by @var{exp} are |
6185 | automatically copied to the initrd. | |
fd1b1fa2 | 6186 | |
42d10464 LC |
6187 | @var{modules} is a list of Guile module names to be embedded in the |
6188 | initrd. | |
fd1b1fa2 LC |
6189 | @end deffn |
6190 | ||
88faf933 LC |
6191 | @node GRUB Configuration |
6192 | @subsection GRUB Configuration | |
6193 | ||
6194 | @cindex GRUB | |
6195 | @cindex boot loader | |
6196 | ||
6197 | The operating system uses GNU@tie{}GRUB as its boot loader | |
6198 | (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is | |
6199 | configured using @code{grub-configuration} declarations. This data type | |
6200 | is exported by the @code{(gnu system grub)} module, and described below. | |
6201 | ||
6202 | @deftp {Data Type} grub-configuration | |
6203 | The type of a GRUB configuration declaration. | |
6204 | ||
6205 | @table @asis | |
6206 | ||
6207 | @item @code{device} | |
6208 | This is a string denoting the boot device. It must be a device name | |
6209 | understood by the @command{grub-install} command, such as | |
6210 | @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub, | |
6211 | GNU GRUB Manual}). | |
6212 | ||
6213 | @item @code{menu-entries} (default: @code{()}) | |
6214 | A possibly empty list of @code{menu-entry} objects (see below), denoting | |
6215 | entries to appear in the GRUB boot menu, in addition to the current | |
6216 | system entry and the entry pointing to previous system generations. | |
6217 | ||
6218 | @item @code{default-entry} (default: @code{0}) | |
6219 | The index of the default boot menu entry. Index 0 is for the current | |
6220 | system's entry. | |
6221 | ||
6222 | @item @code{timeout} (default: @code{5}) | |
6223 | The number of seconds to wait for keyboard input before booting. Set to | |
6224 | 0 to boot immediately, and to -1 to wait indefinitely. | |
6225 | ||
6226 | @item @code{theme} (default: @var{%default-theme}) | |
6227 | The @code{grub-theme} object describing the theme to use. | |
6228 | @end table | |
6229 | ||
6230 | @end deftp | |
6231 | ||
6232 | Should you want to list additional boot menu entries @i{via} the | |
6233 | @code{menu-entries} field above, you will need to create them with the | |
6234 | @code{menu-entry} form: | |
6235 | ||
6236 | @deftp {Data Type} menu-entry | |
6237 | The type of an entry in the GRUB boot menu. | |
6238 | ||
6239 | @table @asis | |
6240 | ||
6241 | @item @code{label} | |
35ed9306 | 6242 | The label to show in the menu---e.g., @code{"GNU"}. |
88faf933 LC |
6243 | |
6244 | @item @code{linux} | |
6245 | The Linux kernel to boot. | |
6246 | ||
6247 | @item @code{linux-arguments} (default: @code{()}) | |
6248 | The list of extra Linux kernel command-line arguments---e.g., | |
6249 | @code{("console=ttyS0")}. | |
6250 | ||
6251 | @item @code{initrd} | |
6252 | A G-Expression or string denoting the file name of the initial RAM disk | |
6253 | to use (@pxref{G-Expressions}). | |
6254 | ||
6255 | @end table | |
6256 | @end deftp | |
6257 | ||
6258 | @c FIXME: Write documentation once it's stable. | |
6259 | Themes are created using the @code{grub-theme} form, which is not | |
6260 | documented yet. | |
6261 | ||
6262 | @defvr {Scheme Variable} %default-theme | |
6263 | This is the default GRUB theme used by the operating system, with a | |
6264 | fancy background image displaying the GNU and Guix logos. | |
6265 | @end defvr | |
6266 | ||
6267 | ||
cf4a9129 LC |
6268 | @node Invoking guix system |
6269 | @subsection Invoking @code{guix system} | |
0918e64a | 6270 | |
cf4a9129 LC |
6271 | Once you have written an operating system declaration, as seen in the |
6272 | previous section, it can be @dfn{instantiated} using the @command{guix | |
6273 | system} command. The synopsis is: | |
4af2447e | 6274 | |
cf4a9129 LC |
6275 | @example |
6276 | guix system @var{options}@dots{} @var{action} @var{file} | |
6277 | @end example | |
4af2447e | 6278 | |
cf4a9129 LC |
6279 | @var{file} must be the name of a file containing an |
6280 | @code{operating-system} declaration. @var{action} specifies how the | |
6281 | operating system is instantiate. Currently the following values are | |
6282 | supported: | |
4af2447e | 6283 | |
cf4a9129 LC |
6284 | @table @code |
6285 | @item reconfigure | |
6286 | Build the operating system described in @var{file}, activate it, and | |
6287 | switch to it@footnote{This action is usable only on systems already | |
6288 | running GNU.}. | |
4af2447e | 6289 | |
cf4a9129 LC |
6290 | This effects all the configuration specified in @var{file}: user |
6291 | accounts, system services, global package list, setuid programs, etc. | |
4af2447e | 6292 | |
cf4a9129 LC |
6293 | It also adds a GRUB menu entry for the new OS configuration, and moves |
6294 | entries for older configurations to a submenu---unless | |
6295 | @option{--no-grub} is passed. | |
4af2447e | 6296 | |
bf2479c7 LC |
6297 | @c The paragraph below refers to the problem discussed at |
6298 | @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>. | |
6299 | It is highly recommended to run @command{guix pull} once before you run | |
6300 | @command{guix system reconfigure} for the first time (@pxref{Invoking | |
6301 | guix pull}). Failing to do that you would see an older version of Guix | |
6302 | once @command{reconfigure} has completed. | |
6303 | ||
cf4a9129 LC |
6304 | @item build |
6305 | Build the operating system's derivation, which includes all the | |
6306 | configuration files and programs needed to boot and run the system. | |
6307 | This action does not actually install anything. | |
113daf62 | 6308 | |
cf4a9129 LC |
6309 | @item init |
6310 | Populate the given directory with all the files necessary to run the | |
6311 | operating system specified in @var{file}. This is useful for first-time | |
4705641f | 6312 | installations of GuixSD. For instance: |
113daf62 LC |
6313 | |
6314 | @example | |
cf4a9129 | 6315 | guix system init my-os-config.scm /mnt |
113daf62 LC |
6316 | @end example |
6317 | ||
cf4a9129 LC |
6318 | copies to @file{/mnt} all the store items required by the configuration |
6319 | specified in @file{my-os-config.scm}. This includes configuration | |
6320 | files, packages, and so on. It also creates other essential files | |
6321 | needed for the system to operate correctly---e.g., the @file{/etc}, | |
6322 | @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file. | |
113daf62 | 6323 | |
cf4a9129 LC |
6324 | This command also installs GRUB on the device specified in |
6325 | @file{my-os-config}, unless the @option{--no-grub} option was passed. | |
113daf62 | 6326 | |
cf4a9129 LC |
6327 | @item vm |
6328 | @cindex virtual machine | |
0276f697 | 6329 | @cindex VM |
cf4a9129 LC |
6330 | Build a virtual machine that contain the operating system declared in |
6331 | @var{file}, and return a script to run that virtual machine (VM). | |
810568b3 | 6332 | Arguments given to the script are passed as is to QEMU. |
113daf62 | 6333 | |
cf4a9129 | 6334 | The VM shares its store with the host system. |
113daf62 | 6335 | |
0276f697 LC |
6336 | Additional file systems can be shared between the host and the VM using |
6337 | the @code{--share} and @code{--expose} command-line options: the former | |
6338 | specifies a directory to be shared with write access, while the latter | |
6339 | provides read-only access to the shared directory. | |
6340 | ||
6341 | The example below creates a VM in which the user's home directory is | |
6342 | accessible read-only, and where the @file{/exchange} directory is a | |
6343 | read-write mapping of the host's @file{$HOME/tmp}: | |
6344 | ||
6345 | @example | |
6346 | guix system vm my-config.scm \ | |
6347 | --expose=$HOME --share=$HOME/tmp=/exchange | |
6348 | @end example | |
6349 | ||
6aa260af LC |
6350 | On GNU/Linux, the default is to boot directly to the kernel; this has |
6351 | the advantage of requiring only a very tiny root disk image since the | |
6352 | host's store can then be mounted. | |
6353 | ||
6354 | The @code{--full-boot} option forces a complete boot sequence, starting | |
6355 | with the bootloader. This requires more disk space since a root image | |
6356 | containing at least the kernel, initrd, and bootloader data files must | |
6357 | be created. The @code{--image-size} option can be used to specify the | |
6358 | image's size. | |
ab11f0be | 6359 | |
cf4a9129 LC |
6360 | @item vm-image |
6361 | @itemx disk-image | |
6362 | Return a virtual machine or disk image of the operating system declared | |
6363 | in @var{file} that stands alone. Use the @option{--image-size} option | |
6364 | to specify the size of the image. | |
113daf62 | 6365 | |
cf4a9129 LC |
6366 | When using @code{vm-image}, the returned image is in qcow2 format, which |
6367 | the QEMU emulator can efficiently use. | |
113daf62 | 6368 | |
cf4a9129 LC |
6369 | When using @code{disk-image}, a raw disk image is produced; it can be |
6370 | copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is | |
6371 | the device corresponding to a USB stick, one can copy the image on it | |
6372 | using the following command: | |
113daf62 | 6373 | |
cf4a9129 LC |
6374 | @example |
6375 | # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc | |
6376 | @end example | |
113daf62 | 6377 | |
cf4a9129 | 6378 | @end table |
113daf62 | 6379 | |
cf4a9129 LC |
6380 | @var{options} can contain any of the common build options provided by |
6381 | @command{guix build} (@pxref{Invoking guix build}). In addition, | |
6382 | @var{options} can contain one of the following: | |
113daf62 | 6383 | |
cf4a9129 LC |
6384 | @table @option |
6385 | @item --system=@var{system} | |
6386 | @itemx -s @var{system} | |
6387 | Attempt to build for @var{system} instead of the host's system type. | |
6388 | This works as per @command{guix build} (@pxref{Invoking guix build}). | |
113daf62 | 6389 | |
cf4a9129 LC |
6390 | @item --image-size=@var{size} |
6391 | For the @code{vm-image} and @code{disk-image} actions, create an image | |
6392 | of the given @var{size}. @var{size} may be a number of bytes, or it may | |
4a44d7bb LC |
6393 | include a unit as a suffix (@pxref{Block size, size specifications,, |
6394 | coreutils, GNU Coreutils}). | |
db030303 LC |
6395 | |
6396 | @item --on-error=@var{strategy} | |
6397 | Apply @var{strategy} when an error occurs when reading @var{file}. | |
6398 | @var{strategy} may be one of the following: | |
6399 | ||
6400 | @table @code | |
6401 | @item nothing-special | |
6402 | Report the error concisely and exit. This is the default strategy. | |
6403 | ||
6404 | @item backtrace | |
6405 | Likewise, but also display a backtrace. | |
6406 | ||
6407 | @item debug | |
6408 | Report the error and enter Guile's debugger. From there, you can run | |
6409 | commands such as @code{,bt} to get a backtrace, @code{,locals} to | |
6410 | display local variable values, and more generally inspect the program's | |
6411 | state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for | |
6412 | a list of available debugging commands. | |
6413 | @end table | |
113daf62 | 6414 | @end table |
113daf62 | 6415 | |
cf4a9129 LC |
6416 | Note that all the actions above, except @code{build} and @code{init}, |
6417 | rely on KVM support in the Linux-Libre kernel. Specifically, the | |
6418 | machine should have hardware virtualization support, the corresponding | |
6419 | KVM kernel module should be loaded, and the @file{/dev/kvm} device node | |
6420 | must exist and be readable and writable by the user and by the daemon's | |
6421 | build users. | |
8451a568 | 6422 | |
cf4a9129 LC |
6423 | @node Defining Services |
6424 | @subsection Defining Services | |
8451a568 | 6425 | |
cf4a9129 LC |
6426 | The @code{(gnu services @dots{})} modules define several procedures that allow |
6427 | users to declare the operating system's services (@pxref{Using the | |
6428 | Configuration System}). These procedures are @emph{monadic | |
6429 | procedures}---i.e., procedures that return a monadic value in the store | |
6430 | monad (@pxref{The Store Monad}). For examples of such procedures, | |
6431 | @xref{Services}. | |
8451a568 | 6432 | |
cf4a9129 LC |
6433 | @cindex service definition |
6434 | The monadic value returned by those procedures is a @dfn{service | |
6435 | definition}---a structure as returned by the @code{service} form. | |
6436 | Service definitions specifies the inputs the service depends on, and an | |
6437 | expression to start and stop the service. Behind the scenes, service | |
6438 | definitions are ``translated'' into the form suitable for the | |
6439 | configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU | |
6440 | dmd Manual}). | |
8451a568 | 6441 | |
cf4a9129 LC |
6442 | As an example, here is what the @code{nscd-service} procedure looks |
6443 | like: | |
8451a568 | 6444 | |
cf4a9129 LC |
6445 | @lisp |
6446 | (define (nscd-service) | |
6447 | (with-monad %store-monad | |
6448 | (return (service | |
6449 | (documentation "Run libc's name service cache daemon.") | |
6450 | (provision '(nscd)) | |
6451 | (activate #~(begin | |
6452 | (use-modules (guix build utils)) | |
6453 | (mkdir-p "/var/run/nscd"))) | |
6454 | (start #~(make-forkexec-constructor | |
6455 | (string-append #$glibc "/sbin/nscd") | |
6456 | "-f" "/dev/null" "--foreground")) | |
6457 | (stop #~(make-kill-destructor)) | |
6458 | (respawn? #f))))) | |
6459 | @end lisp | |
8451a568 | 6460 | |
cf4a9129 LC |
6461 | @noindent |
6462 | The @code{activate}, @code{start}, and @code{stop} fields are G-expressions | |
6463 | (@pxref{G-Expressions}). The @code{activate} field contains a script to | |
6464 | run at ``activation'' time; it makes sure that the @file{/var/run/nscd} | |
6465 | directory exists before @command{nscd} is started. | |
8451a568 | 6466 | |
cf4a9129 LC |
6467 | The @code{start} and @code{stop} fields refer to dmd's facilities to |
6468 | start and stop processes (@pxref{Service De- and Constructors,,, dmd, | |
6469 | GNU dmd Manual}). The @code{provision} field specifies the name under | |
6470 | which this service is known to dmd, and @code{documentation} specifies | |
6471 | on-line documentation. Thus, the commands @command{deco start ncsd}, | |
6472 | @command{deco stop nscd}, and @command{deco doc nscd} will do what you | |
6473 | would expect (@pxref{Invoking deco,,, dmd, GNU dmd Manual}). | |
8451a568 | 6474 | |
8451a568 | 6475 | |
cf4a9129 LC |
6476 | @node Installing Debugging Files |
6477 | @section Installing Debugging Files | |
8451a568 | 6478 | |
cf4a9129 LC |
6479 | @cindex debugging files |
6480 | Program binaries, as produced by the GCC compilers for instance, are | |
6481 | typically written in the ELF format, with a section containing | |
6482 | @dfn{debugging information}. Debugging information is what allows the | |
6483 | debugger, GDB, to map binary code to source code; it is required to | |
6484 | debug a compiled program in good conditions. | |
8451a568 | 6485 | |
cf4a9129 LC |
6486 | The problem with debugging information is that is takes up a fair amount |
6487 | of disk space. For example, debugging information for the GNU C Library | |
6488 | weighs in at more than 60 MiB. Thus, as a user, keeping all the | |
6489 | debugging info of all the installed programs is usually not an option. | |
6490 | Yet, space savings should not come at the cost of an impediment to | |
6491 | debugging---especially in the GNU system, which should make it easier | |
6492 | for users to exert their computing freedom (@pxref{GNU Distribution}). | |
8451a568 | 6493 | |
cf4a9129 LC |
6494 | Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a |
6495 | mechanism that allows users to get the best of both worlds: debugging | |
6496 | information can be stripped from the binaries and stored in separate | |
6497 | files. GDB is then able to load debugging information from those files, | |
6498 | when they are available (@pxref{Separate Debug Files,,, gdb, Debugging | |
6499 | with GDB}). | |
8451a568 | 6500 | |
cf4a9129 LC |
6501 | The GNU distribution takes advantage of this by storing debugging |
6502 | information in the @code{lib/debug} sub-directory of a separate package | |
6503 | output unimaginatively called @code{debug} (@pxref{Packages with | |
6504 | Multiple Outputs}). Users can choose to install the @code{debug} output | |
6505 | of a package when they need it. For instance, the following command | |
6506 | installs the debugging information for the GNU C Library and for GNU | |
6507 | Guile: | |
8451a568 LC |
6508 | |
6509 | @example | |
cf4a9129 | 6510 | guix package -i glibc:debug guile:debug |
8451a568 LC |
6511 | @end example |
6512 | ||
cf4a9129 LC |
6513 | GDB must then be told to look for debug files in the user's profile, by |
6514 | setting the @code{debug-file-directory} variable (consider setting it | |
6515 | from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with | |
6516 | GDB}): | |
8451a568 | 6517 | |
cf4a9129 LC |
6518 | @example |
6519 | (gdb) set debug-file-directory ~/.guix-profile/lib/debug | |
6520 | @end example | |
8451a568 | 6521 | |
cf4a9129 LC |
6522 | From there on, GDB will pick up debugging information from the |
6523 | @code{.debug} files under @file{~/.guix-profile/lib/debug}. | |
8451a568 | 6524 | |
cf4a9129 LC |
6525 | In addition, you will most likely want GDB to be able to show the source |
6526 | code being debugged. To do that, you will have to unpack the source | |
6527 | code of the package of interest (obtained with @code{guix build | |
6528 | --source}, @pxref{Invoking guix build}), and to point GDB to that source | |
6529 | directory using the @code{directory} command (@pxref{Source Path, | |
6530 | @code{directory},, gdb, Debugging with GDB}). | |
8451a568 | 6531 | |
cf4a9129 LC |
6532 | @c XXX: keep me up-to-date |
6533 | The @code{debug} output mechanism in Guix is implemented by the | |
6534 | @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is | |
6535 | opt-in---debugging information is available only for those packages | |
6536 | whose definition explicitly declares a @code{debug} output. This may be | |
6537 | changed to opt-out in the future, if our build farm servers can handle | |
6538 | the load. To check whether a package has a @code{debug} output, use | |
6539 | @command{guix package --list-available} (@pxref{Invoking guix package}). | |
8451a568 | 6540 | |
8451a568 | 6541 | |
05962f29 LC |
6542 | @node Security Updates |
6543 | @section Security Updates | |
6544 | ||
843858b8 LC |
6545 | @quotation Note |
6546 | As of version @value{VERSION}, the feature described in this section is | |
6547 | experimental. | |
6548 | @end quotation | |
05962f29 LC |
6549 | |
6550 | @cindex security updates | |
6551 | Occasionally, important security vulnerabilities are discovered in core | |
6552 | software packages and must be patched. Guix follows a functional | |
6553 | package management discipline (@pxref{Introduction}), which implies | |
6554 | that, when a package is changed, @emph{every package that depends on it} | |
6555 | must be rebuilt. This can significantly slow down the deployment of | |
6556 | fixes in core packages such as libc or Bash, since basically the whole | |
6557 | distribution would need to be rebuilt. Using pre-built binaries helps | |
6558 | (@pxref{Substitutes}), but deployment may still take more time than | |
6559 | desired. | |
6560 | ||
6561 | @cindex grafts | |
6562 | To address that, Guix implements @dfn{grafts}, a mechanism that allows | |
6563 | for fast deployment of critical updates without the costs associated | |
6564 | with a whole-distribution rebuild. The idea is to rebuild only the | |
6565 | package that needs to be patched, and then to ``graft'' it onto packages | |
6566 | explicitly installed by the user and that were previously referring to | |
6567 | the original package. The cost of grafting is typically very low, and | |
6568 | order of magnitudes lower than a full rebuild of the dependency chain. | |
6569 | ||
6570 | @cindex replacements of packages, for grafts | |
6571 | For instance, suppose a security update needs to be applied to Bash. | |
6572 | Guix developers will provide a package definition for the ``fixed'' | |
6573 | Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining | |
6574 | Packages}). Then, the original package definition is augmented with a | |
6575 | @code{replacement} field pointing to the package containing the bug fix: | |
6576 | ||
6577 | @example | |
6578 | (define bash | |
6579 | (package | |
6580 | (name "bash") | |
6581 | ;; @dots{} | |
6582 | (replacement bash-fixed))) | |
6583 | @end example | |
6584 | ||
6585 | From there on, any package depending directly or indirectly on Bash that | |
6586 | is installed will automatically be ``rewritten'' to refer to | |
6587 | @var{bash-fixed} instead of @var{bash}. This grafting process takes | |
6588 | time proportional to the size of the package, but expect less than a | |
6589 | minute for an ``average'' package on a recent machine. | |
6590 | ||
6591 | Currently, the graft and the package it replaces (@var{bash-fixed} and | |
6592 | @var{bash} in the example above) must have the exact same @code{name} | |
6593 | and @code{version} fields. This restriction mostly comes from the fact | |
6594 | that grafting works by patching files, including binary files, directly. | |
6595 | Other restrictions may apply: for instance, when adding a graft to a | |
6596 | package providing a shared library, the original shared library and its | |
6597 | replacement must have the same @code{SONAME} and be binary-compatible. | |
6598 | ||
6599 | ||
cf4a9129 LC |
6600 | @node Package Modules |
6601 | @section Package Modules | |
8451a568 | 6602 | |
cf4a9129 LC |
6603 | From a programming viewpoint, the package definitions of the |
6604 | GNU distribution are provided by Guile modules in the @code{(gnu packages | |
6605 | @dots{})} name space@footnote{Note that packages under the @code{(gnu | |
6606 | packages @dots{})} module name space are not necessarily ``GNU | |
6607 | packages''. This module naming scheme follows the usual Guile module | |
6608 | naming convention: @code{gnu} means that these modules are distributed | |
6609 | as part of the GNU system, and @code{packages} identifies modules that | |
6610 | define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile | |
6611 | Reference Manual}). For instance, the @code{(gnu packages emacs)} | |
6612 | module exports a variable named @code{emacs}, which is bound to a | |
6613 | @code{<package>} object (@pxref{Defining Packages}). | |
113daf62 | 6614 | |
300868ba | 6615 | The @code{(gnu packages @dots{})} module name space is |
cf4a9129 LC |
6616 | automatically scanned for packages by the command-line tools. For |
6617 | instance, when running @code{guix package -i emacs}, all the @code{(gnu | |
6618 | packages @dots{})} modules are scanned until one that exports a package | |
6619 | object whose name is @code{emacs} is found. This package search | |
6620 | facility is implemented in the @code{(gnu packages)} module. | |
113daf62 | 6621 | |
300868ba | 6622 | @cindex customization, of packages |
8689901f | 6623 | @cindex package module search path |
cf4a9129 | 6624 | Users can store package definitions in modules with different |
60142854 | 6625 | names---e.g., @code{(my-packages emacs)}@footnote{Note that the file |
c95ded7e LC |
6626 | name and module name must match. For instance, the @code{(my-packages |
6627 | emacs)} module must be stored in a @file{my-packages/emacs.scm} file | |
6628 | relative to the load path specified with @option{--load-path} or | |
6629 | @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,, | |
6630 | guile, GNU Guile Reference Manual}, for details.}. These package definitions | |
300868ba LC |
6631 | will not be visible by default. Thus, users can invoke commands such as |
6632 | @command{guix package} and @command{guix build} have to be used with the | |
c95ded7e LC |
6633 | @code{-e} option so that they know where to find the package. Better |
6634 | yet, they can use the | |
300868ba | 6635 | @code{-L} option of these commands to make those modules visible |
8689901f LC |
6636 | (@pxref{Invoking guix build, @code{--load-path}}), or define the |
6637 | @code{GUIX_PACKAGE_PATH} environment variable. This environment | |
6638 | variable makes it easy to extend or customize the distribution and is | |
6639 | honored by all the user interfaces. | |
6640 | ||
6641 | @defvr {Environment Variable} GUIX_PACKAGE_PATH | |
6642 | This is a colon-separated list of directories to search for package | |
6643 | modules. Directories listed in this variable take precedence over the | |
6644 | distribution's own modules. | |
6645 | @end defvr | |
ef5dd60a | 6646 | |
cf4a9129 LC |
6647 | The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}: |
6648 | each package is built based solely on other packages in the | |
6649 | distribution. The root of this dependency graph is a small set of | |
6650 | @dfn{bootstrap binaries}, provided by the @code{(gnu packages | |
6651 | bootstrap)} module. For more information on bootstrapping, | |
081145cf | 6652 | @pxref{Bootstrapping}. |
ef5dd60a | 6653 | |
cf4a9129 LC |
6654 | @node Packaging Guidelines |
6655 | @section Packaging Guidelines | |
ef5dd60a | 6656 | |
cf4a9129 LC |
6657 | The GNU distribution is nascent and may well lack some of your favorite |
6658 | packages. This section describes how you can help make the distribution | |
6659 | grow. @xref{Contributing}, for additional information on how you can | |
6660 | help. | |
ef5dd60a | 6661 | |
cf4a9129 LC |
6662 | Free software packages are usually distributed in the form of |
6663 | @dfn{source code tarballs}---typically @file{tar.gz} files that contain | |
6664 | all the source files. Adding a package to the distribution means | |
6665 | essentially two things: adding a @dfn{recipe} that describes how to | |
6666 | build the package, including a list of other packages required to build | |
6667 | it, and adding @dfn{package meta-data} along with that recipe, such as a | |
6668 | description and licensing information. | |
ef5dd60a | 6669 | |
cf4a9129 LC |
6670 | In Guix all this information is embodied in @dfn{package definitions}. |
6671 | Package definitions provide a high-level view of the package. They are | |
6672 | written using the syntax of the Scheme programming language; in fact, | |
6673 | for each package we define a variable bound to the package definition, | |
6674 | and export that variable from a module (@pxref{Package Modules}). | |
6675 | However, in-depth Scheme knowledge is @emph{not} a prerequisite for | |
6676 | creating packages. For more information on package definitions, | |
081145cf | 6677 | @pxref{Defining Packages}. |
ef5dd60a | 6678 | |
cf4a9129 LC |
6679 | Once a package definition is in place, stored in a file in the Guix |
6680 | source tree, it can be tested using the @command{guix build} command | |
6681 | (@pxref{Invoking guix build}). For example, assuming the new package is | |
c71979f4 LC |
6682 | called @code{gnew}, you may run this command from the Guix build tree |
6683 | (@pxref{Running Guix Before It Is Installed}): | |
ef5dd60a LC |
6684 | |
6685 | @example | |
cf4a9129 | 6686 | ./pre-inst-env guix build gnew --keep-failed |
ef5dd60a | 6687 | @end example |
ef5dd60a | 6688 | |
cf4a9129 LC |
6689 | Using @code{--keep-failed} makes it easier to debug build failures since |
6690 | it provides access to the failed build tree. Another useful | |
6691 | command-line option when debugging is @code{--log-file}, to access the | |
6692 | build log. | |
ef5dd60a | 6693 | |
cf4a9129 LC |
6694 | If the package is unknown to the @command{guix} command, it may be that |
6695 | the source file contains a syntax error, or lacks a @code{define-public} | |
6696 | clause to export the package variable. To figure it out, you may load | |
6697 | the module from Guile to get more information about the actual error: | |
ef5dd60a | 6698 | |
cf4a9129 LC |
6699 | @example |
6700 | ./pre-inst-env guile -c '(use-modules (gnu packages gnew))' | |
6701 | @end example | |
ef5dd60a | 6702 | |
cf4a9129 LC |
6703 | Once your package builds correctly, please send us a patch |
6704 | (@pxref{Contributing}). Well, if you need help, we will be happy to | |
6705 | help you too. Once the patch is committed in the Guix repository, the | |
6706 | new package automatically gets built on the supported platforms by | |
2b1cee21 | 6707 | @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration |
cf4a9129 | 6708 | system}. |
ef5dd60a | 6709 | |
cf4a9129 LC |
6710 | @cindex substituter |
6711 | Users can obtain the new package definition simply by running | |
6712 | @command{guix pull} (@pxref{Invoking guix pull}). When | |
6713 | @code{hydra.gnu.org} is done building the package, installing the | |
6714 | package automatically downloads binaries from there | |
6715 | (@pxref{Substitutes}). The only place where human intervention is | |
6716 | needed is to review and apply the patch. | |
ef5dd60a | 6717 | |
ef5dd60a | 6718 | |
cf4a9129 | 6719 | @menu |
ec0339cd LC |
6720 | * Software Freedom:: What may go into the distribution. |
6721 | * Package Naming:: What's in a name? | |
6722 | * Version Numbers:: When the name is not enough. | |
6723 | * Python Modules:: Taming the snake. | |
6724 | * Perl Modules:: Little pearls. | |
6725 | * Fonts:: Fond of fonts. | |
cf4a9129 | 6726 | @end menu |
ef5dd60a | 6727 | |
cf4a9129 LC |
6728 | @node Software Freedom |
6729 | @subsection Software Freedom | |
ef5dd60a | 6730 | |
cf4a9129 | 6731 | @c Adapted from http://www.gnu.org/philosophy/philosophy.html. |
c11a6eb1 | 6732 | |
cf4a9129 LC |
6733 | The GNU operating system has been developed so that users can have |
6734 | freedom in their computing. GNU is @dfn{free software}, meaning that | |
6735 | users have the @url{http://www.gnu.org/philosophy/free-sw.html,four | |
6736 | essential freedoms}: to run the program, to study and change the program | |
6737 | in source code form, to redistribute exact copies, and to distribute | |
6738 | modified versions. Packages found in the GNU distribution provide only | |
6739 | software that conveys these four freedoms. | |
c11a6eb1 | 6740 | |
cf4a9129 LC |
6741 | In addition, the GNU distribution follow the |
6742 | @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free | |
6743 | software distribution guidelines}. Among other things, these guidelines | |
6744 | reject non-free firmware, recommendations of non-free software, and | |
6745 | discuss ways to deal with trademarks and patents. | |
ef5dd60a | 6746 | |
cf4a9129 LC |
6747 | Some packages contain a small and optional subset that violates the |
6748 | above guidelines, for instance because this subset is itself non-free | |
6749 | code. When that happens, the offending items are removed with | |
6750 | appropriate patches or code snippets in the package definition's | |
6751 | @code{origin} form (@pxref{Defining Packages}). That way, @code{guix | |
6752 | build --source} returns the ``freed'' source rather than the unmodified | |
6753 | upstream source. | |
ef5dd60a | 6754 | |
ef5dd60a | 6755 | |
cf4a9129 LC |
6756 | @node Package Naming |
6757 | @subsection Package Naming | |
ef5dd60a | 6758 | |
cf4a9129 LC |
6759 | A package has actually two names associated with it: |
6760 | First, there is the name of the @emph{Scheme variable}, the one following | |
6761 | @code{define-public}. By this name, the package can be made known in the | |
6762 | Scheme code, for instance as input to another package. Second, there is | |
6763 | the string in the @code{name} field of a package definition. This name | |
6764 | is used by package management commands such as | |
6765 | @command{guix package} and @command{guix build}. | |
ef5dd60a | 6766 | |
cf4a9129 LC |
6767 | Both are usually the same and correspond to the lowercase conversion of |
6768 | the project name chosen upstream, with underscores replaced with | |
6769 | hyphens. For instance, GNUnet is available as @code{gnunet}, and | |
6770 | SDL_net as @code{sdl-net}. | |
927097ef | 6771 | |
cf4a9129 | 6772 | We do not add @code{lib} prefixes for library packages, unless these are |
081145cf | 6773 | already part of the official project name. But @pxref{Python |
cf4a9129 LC |
6774 | Modules} and @ref{Perl Modules} for special rules concerning modules for |
6775 | the Python and Perl languages. | |
927097ef | 6776 | |
1b366ee4 | 6777 | Font package names are handled differently, @pxref{Fonts}. |
7fec52b7 | 6778 | |
ef5dd60a | 6779 | |
cf4a9129 LC |
6780 | @node Version Numbers |
6781 | @subsection Version Numbers | |
ef5dd60a | 6782 | |
cf4a9129 LC |
6783 | We usually package only the latest version of a given free software |
6784 | project. But sometimes, for instance for incompatible library versions, | |
6785 | two (or more) versions of the same package are needed. These require | |
6786 | different Scheme variable names. We use the name as defined | |
6787 | in @ref{Package Naming} | |
6788 | for the most recent version; previous versions use the same name, suffixed | |
6789 | by @code{-} and the smallest prefix of the version number that may | |
6790 | distinguish the two versions. | |
ef5dd60a | 6791 | |
cf4a9129 LC |
6792 | The name inside the package definition is the same for all versions of a |
6793 | package and does not contain any version number. | |
ef5dd60a | 6794 | |
cf4a9129 | 6795 | For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows: |
ef5dd60a | 6796 | |
cf4a9129 LC |
6797 | @example |
6798 | (define-public gtk+ | |
6799 | (package | |
6800 | (name "gtk+") | |
6801 | (version "3.9.12") | |
6802 | ...)) | |
6803 | (define-public gtk+-2 | |
6804 | (package | |
6805 | (name "gtk+") | |
6806 | (version "2.24.20") | |
6807 | ...)) | |
6808 | @end example | |
6809 | If we also wanted GTK+ 3.8.2, this would be packaged as | |
6810 | @example | |
6811 | (define-public gtk+-3.8 | |
6812 | (package | |
6813 | (name "gtk+") | |
6814 | (version "3.8.2") | |
6815 | ...)) | |
6816 | @end example | |
ef5dd60a | 6817 | |
ef5dd60a | 6818 | |
cf4a9129 LC |
6819 | @node Python Modules |
6820 | @subsection Python Modules | |
ef5dd60a | 6821 | |
cf4a9129 LC |
6822 | We currently package Python 2 and Python 3, under the Scheme variable names |
6823 | @code{python-2} and @code{python} as explained in @ref{Version Numbers}. | |
6824 | To avoid confusion and naming clashes with other programming languages, it | |
6825 | seems desirable that the name of a package for a Python module contains | |
6826 | the word @code{python}. | |
ef5dd60a | 6827 | |
cf4a9129 LC |
6828 | Some modules are compatible with only one version of Python, others with both. |
6829 | If the package Foo compiles only with Python 3, we name it | |
6830 | @code{python-foo}; if it compiles only with Python 2, we name it | |
6831 | @code{python2-foo}. If it is compatible with both versions, we create two | |
6832 | packages with the corresponding names. | |
ef5dd60a | 6833 | |
cf4a9129 LC |
6834 | If a project already contains the word @code{python}, we drop this; |
6835 | for instance, the module python-dateutil is packaged under the names | |
6836 | @code{python-dateutil} and @code{python2-dateutil}. | |
113daf62 | 6837 | |
523e4896 | 6838 | |
cf4a9129 LC |
6839 | @node Perl Modules |
6840 | @subsection Perl Modules | |
523e4896 | 6841 | |
cf4a9129 LC |
6842 | Perl programs standing for themselves are named as any other package, |
6843 | using the lowercase upstream name. | |
6844 | For Perl packages containing a single class, we use the lowercase class name, | |
6845 | replace all occurrences of @code{::} by dashes and prepend the prefix | |
6846 | @code{perl-}. | |
6847 | So the class @code{XML::Parser} becomes @code{perl-xml-parser}. | |
6848 | Modules containing several classes keep their lowercase upstream name and | |
6849 | are also prepended by @code{perl-}. Such modules tend to have the word | |
6850 | @code{perl} somewhere in their name, which gets dropped in favor of the | |
6851 | prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}. | |
523e4896 | 6852 | |
523e4896 | 6853 | |
7fec52b7 AE |
6854 | @node Fonts |
6855 | @subsection Fonts | |
6856 | ||
6857 | For fonts that are in general not installed by a user for typesetting | |
6858 | purposes, or that are distributed as part of a larger software package, | |
6859 | we rely on the general packaging rules for software; for instance, this | |
6860 | applies to the fonts delivered as part of the X.Org system or fonts that | |
6861 | are part of TeX Live. | |
6862 | ||
6863 | To make it easier for a user to search for fonts, names for other packages | |
6864 | containing only fonts are constructed as follows, independently of the | |
6865 | upstream package name. | |
6866 | ||
6867 | The name of a package containing only one font family starts with | |
6868 | @code{font-}; it is followed by the foundry name and a dash @code{-} | |
6869 | if the foundry is known, and the font family name, in which spaces are | |
6870 | replaced by dashes (and as usual, all upper case letters are transformed | |
6871 | to lower case). | |
6872 | For example, the Gentium font family by SIL is packaged under the name | |
6873 | @code{font-sil-gentium}. | |
6874 | ||
6875 | For a package containing several font families, the name of the collection | |
6876 | is used in the place of the font family name. | |
6877 | For instance, the Liberation fonts consist of three families, | |
6878 | Liberation Sans, Liberation Serif and Liberation Mono. | |
6879 | These could be packaged separately under the names | |
6880 | @code{font-liberation-sans} and so on; but as they are distributed together | |
6881 | under a common name, we prefer to package them together as | |
6882 | @code{font-liberation}. | |
6883 | ||
6884 | In the case where several formats of the same font family or font collection | |
6885 | are packaged separately, a short form of the format, prepended by a dash, | |
6886 | is added to the package name. We use @code{-ttf} for TrueType fonts, | |
1b366ee4 | 6887 | @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1 |
7fec52b7 AE |
6888 | fonts. |
6889 | ||
6890 | ||
b25937e3 | 6891 | |
cf4a9129 LC |
6892 | @node Bootstrapping |
6893 | @section Bootstrapping | |
b25937e3 | 6894 | |
cf4a9129 | 6895 | @c Adapted from the ELS 2013 paper. |
b25937e3 | 6896 | |
cf4a9129 | 6897 | @cindex bootstrapping |
7889394e | 6898 | |
cf4a9129 LC |
6899 | Bootstrapping in our context refers to how the distribution gets built |
6900 | ``from nothing''. Remember that the build environment of a derivation | |
6901 | contains nothing but its declared inputs (@pxref{Introduction}). So | |
6902 | there's an obvious chicken-and-egg problem: how does the first package | |
6903 | get built? How does the first compiler get compiled? Note that this is | |
6904 | a question of interest only to the curious hacker, not to the regular | |
6905 | user, so you can shamelessly skip this section if you consider yourself | |
6906 | a ``regular user''. | |
72b9d60d | 6907 | |
cf4a9129 LC |
6908 | @cindex bootstrap binaries |
6909 | The GNU system is primarily made of C code, with libc at its core. The | |
6910 | GNU build system itself assumes the availability of a Bourne shell and | |
6911 | command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and | |
6912 | `grep'. Furthermore, build programs---programs that run | |
6913 | @code{./configure}, @code{make}, etc.---are written in Guile Scheme | |
6914 | (@pxref{Derivations}). Consequently, to be able to build anything at | |
6915 | all, from scratch, Guix relies on pre-built binaries of Guile, GCC, | |
6916 | Binutils, libc, and the other packages mentioned above---the | |
6917 | @dfn{bootstrap binaries}. | |
72b9d60d | 6918 | |
cf4a9129 LC |
6919 | These bootstrap binaries are ``taken for granted'', though we can also |
6920 | re-create them if needed (more on that later). | |
72b9d60d | 6921 | |
cf4a9129 | 6922 | @unnumberedsubsec Preparing to Use the Bootstrap Binaries |
c79d54fe | 6923 | |
cf4a9129 LC |
6924 | @c As of Emacs 24.3, Info-mode displays the image, but since it's a |
6925 | @c large image, it's hard to scroll. Oh well. | |
6926 | @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations} | |
523e4896 | 6927 | |
cf4a9129 LC |
6928 | The figure above shows the very beginning of the dependency graph of the |
6929 | distribution, corresponding to the package definitions of the @code{(gnu | |
6930 | packages bootstrap)} module. At this level of detail, things are | |
6931 | slightly complex. First, Guile itself consists of an ELF executable, | |
6932 | along with many source and compiled Scheme files that are dynamically | |
6933 | loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz} | |
6934 | tarball shown in this graph. This tarball is part of Guix's ``source'' | |
6935 | distribution, and gets inserted into the store with @code{add-to-store} | |
6936 | (@pxref{The Store}). | |
2e7b5cea | 6937 | |
cf4a9129 LC |
6938 | But how do we write a derivation that unpacks this tarball and adds it |
6939 | to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv} | |
6940 | derivation---the first one that gets built---uses @code{bash} as its | |
6941 | builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls | |
6942 | @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar}, | |
6943 | @file{xz}, and @file{mkdir} are statically-linked binaries, also part of | |
6944 | the Guix source distribution, whose sole purpose is to allow the Guile | |
6945 | tarball to be unpacked. | |
fb729425 | 6946 | |
cf4a9129 LC |
6947 | Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning |
6948 | Guile that can be used to run subsequent build programs. Its first task | |
6949 | is to download tarballs containing the other pre-built binaries---this | |
6950 | is what the @code{.tar.xz.drv} derivations do. Guix modules such as | |
6951 | @code{ftp-client.scm} are used for this purpose. The | |
6952 | @code{module-import.drv} derivations import those modules in a directory | |
6953 | in the store, using the original layout. The | |
6954 | @code{module-import-compiled.drv} derivations compile those modules, and | |
6955 | write them in an output directory with the right layout. This | |
6956 | corresponds to the @code{#:modules} argument of | |
6957 | @code{build-expression->derivation} (@pxref{Derivations}). | |
fb729425 | 6958 | |
cf4a9129 LC |
6959 | Finally, the various tarballs are unpacked by the |
6960 | derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv}, | |
6961 | etc., at which point we have a working C tool chain. | |
fb729425 | 6962 | |
fb729425 | 6963 | |
cf4a9129 | 6964 | @unnumberedsubsec Building the Build Tools |
523e4896 | 6965 | |
cf4a9129 LC |
6966 | @c TODO: Add a package-level dependency graph generated from (gnu |
6967 | @c packages base). | |
df2ce343 | 6968 | |
cf4a9129 LC |
6969 | Bootstrapping is complete when we have a full tool chain that does not |
6970 | depend on the pre-built bootstrap tools discussed above. This | |
6971 | no-dependency requirement is verified by checking whether the files of | |
6972 | the final tool chain contain references to the @file{/gnu/store} | |
6973 | directories of the bootstrap inputs. The process that leads to this | |
6974 | ``final'' tool chain is described by the package definitions found in | |
1f6f57df | 6975 | the @code{(gnu packages commencement)} module. |
df2ce343 | 6976 | |
cf4a9129 LC |
6977 | @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>. |
6978 | The first tool that gets built with the bootstrap binaries is | |
6979 | GNU Make, which is a prerequisite for all the following packages. | |
6980 | From there Findutils and Diffutils get built. | |
523e4896 | 6981 | |
cf4a9129 LC |
6982 | Then come the first-stage Binutils and GCC, built as pseudo cross |
6983 | tools---i.e., with @code{--target} equal to @code{--host}. They are | |
6984 | used to build libc. Thanks to this cross-build trick, this libc is | |
6985 | guaranteed not to hold any reference to the initial tool chain. | |
4af2447e | 6986 | |
cf4a9129 LC |
6987 | From there the final Binutils and GCC are built. GCC uses @code{ld} |
6988 | from the final Binutils, and links programs against the just-built libc. | |
6989 | This tool chain is used to build the other packages used by Guix and by | |
6990 | the GNU Build System: Guile, Bash, Coreutils, etc. | |
4af2447e | 6991 | |
cf4a9129 LC |
6992 | And voilà! At this point we have the complete set of build tools that |
6993 | the GNU Build System expects. These are in the @code{%final-inputs} | |
dd164244 MW |
6994 | variable of the @code{(gnu packages commencement)} module, and are |
6995 | implicitly used by any package that uses @code{gnu-build-system} | |
1f6f57df | 6996 | (@pxref{Build Systems, @code{gnu-build-system}}). |
4af2447e | 6997 | |
4af2447e | 6998 | |
cf4a9129 | 6999 | @unnumberedsubsec Building the Bootstrap Binaries |
4af2447e | 7000 | |
cf4a9129 LC |
7001 | Because the final tool chain does not depend on the bootstrap binaries, |
7002 | those rarely need to be updated. Nevertheless, it is useful to have an | |
7003 | automated way to produce them, should an update occur, and this is what | |
7004 | the @code{(gnu packages make-bootstrap)} module provides. | |
4af2447e | 7005 | |
cf4a9129 LC |
7006 | The following command builds the tarballs containing the bootstrap |
7007 | binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture | |
7008 | of Coreutils and other basic command-line tools): | |
4b2615e1 | 7009 | |
cf4a9129 LC |
7010 | @example |
7011 | guix build bootstrap-tarballs | |
7012 | @end example | |
7013 | ||
7014 | The generated tarballs are those that should be referred to in the | |
7015 | @code{(gnu packages bootstrap)} module mentioned at the beginning of | |
7016 | this section. | |
7017 | ||
7018 | Still here? Then perhaps by now you've started to wonder: when do we | |
7019 | reach a fixed point? That is an interesting question! The answer is | |
7020 | unknown, but if you would like to investigate further (and have | |
7021 | significant computational and storage resources to do so), then let us | |
7022 | know. | |
7023 | ||
7024 | @node Porting | |
7025 | @section Porting to a New Platform | |
7026 | ||
7027 | As discussed above, the GNU distribution is self-contained, and | |
7028 | self-containment is achieved by relying on pre-built ``bootstrap | |
7029 | binaries'' (@pxref{Bootstrapping}). These binaries are specific to an | |
7030 | operating system kernel, CPU architecture, and application binary | |
7031 | interface (ABI). Thus, to port the distribution to a platform that is | |
7032 | not yet supported, one must build those bootstrap binaries, and update | |
7033 | the @code{(gnu packages bootstrap)} module to use them on that platform. | |
7034 | ||
7035 | Fortunately, Guix can @emph{cross compile} those bootstrap binaries. | |
7036 | When everything goes well, and assuming the GNU tool chain supports the | |
7037 | target platform, this can be as simple as running a command like this | |
7038 | one: | |
7039 | ||
7040 | @example | |
7041 | guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs | |
7042 | @end example | |
7043 | ||
1c0c417d LC |
7044 | For this to work, the @code{glibc-dynamic-linker} procedure in |
7045 | @code{(gnu packages bootstrap)} must be augmented to return the right | |
7046 | file name for libc's dynamic linker on that platform; likewise, | |
7047 | @code{system->linux-architecture} in @code{(gnu packages linux)} must be | |
7048 | taught about the new platform. | |
7049 | ||
cf4a9129 | 7050 | Once these are built, the @code{(gnu packages bootstrap)} module needs |
1c0c417d LC |
7051 | to be updated to refer to these binaries on the target platform. That |
7052 | is, the hashes and URLs of the bootstrap tarballs for the new platform | |
7053 | must be added alongside those of the currently supported platforms. The | |
7054 | bootstrap Guile tarball is treated specially: it is expected to be | |
7055 | available locally, and @file{gnu-system.am} has rules do download it for | |
7056 | the supported architectures; a rule for the new platform must be added | |
7057 | as well. | |
cf4a9129 LC |
7058 | |
7059 | In practice, there may be some complications. First, it may be that the | |
7060 | extended GNU triplet that specifies an ABI (like the @code{eabi} suffix | |
7061 | above) is not recognized by all the GNU tools. Typically, glibc | |
7062 | recognizes some of these, whereas GCC uses an extra @code{--with-abi} | |
7063 | configure flag (see @code{gcc.scm} for examples of how to handle this). | |
7064 | Second, some of the required packages could fail to build for that | |
7065 | platform. Lastly, the generated binaries could be broken for some | |
7066 | reason. | |
4af2447e | 7067 | |
9bf3c1a7 | 7068 | @c ********************************************************************* |
8c01b9d0 | 7069 | @include contributing.texi |
c78bd12b | 7070 | |
568717fd LC |
7071 | @c ********************************************************************* |
7072 | @node Acknowledgments | |
7073 | @chapter Acknowledgments | |
7074 | ||
7075 | Guix is based on the Nix package manager, which was designed and | |
4c7ac9aa LC |
7076 | implemented by Eelco Dolstra, with contributions from other people (see |
7077 | the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package | |
568717fd LC |
7078 | management, and promoted unprecedented features, such as transactional |
7079 | package upgrades and rollbacks, per-user profiles, and referentially | |
7080 | transparent build processes. Without this work, Guix would not exist. | |
7081 | ||
7082 | The Nix-based software distributions, Nixpkgs and NixOS, have also been | |
7083 | an inspiration for Guix. | |
7084 | ||
4c7ac9aa LC |
7085 | GNU@tie{}Guix itself is a collective work with contributions from a |
7086 | number of people. See the @file{AUTHORS} file in Guix for more | |
7087 | information on these fine people. The @file{THANKS} file lists people | |
7088 | who have helped by reporting bugs, taking care of the infrastructure, | |
7089 | providing artwork and themes, making suggestions, and more---thank you! | |
7090 | ||
7091 | ||
568717fd LC |
7092 | @c ********************************************************************* |
7093 | @node GNU Free Documentation License | |
7094 | @appendix GNU Free Documentation License | |
7095 | ||
7096 | @include fdl-1.3.texi | |
7097 | ||
7098 | @c ********************************************************************* | |
7099 | @node Concept Index | |
7100 | @unnumbered Concept Index | |
7101 | @printindex cp | |
7102 | ||
a85b83d2 LC |
7103 | @node Programming Index |
7104 | @unnumbered Programming Index | |
7105 | @syncodeindex tp fn | |
7106 | @syncodeindex vr fn | |
568717fd LC |
7107 | @printindex fn |
7108 | ||
7109 | @bye | |
7110 | ||
7111 | @c Local Variables: | |
7112 | @c ispell-local-dictionary: "american"; | |
7113 | @c End: |