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