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 | |
2cbed07e | 48 | @author The GNU Guix Developers |
568717fd LC |
49 | |
50 | @page | |
51 | @vskip 0pt plus 1filll | |
52 | Edition @value{EDITION} @* | |
53 | @value{UPDATED} @* | |
54 | ||
7df7a74e | 55 | @insertcopying |
568717fd LC |
56 | @end titlepage |
57 | ||
568717fd LC |
58 | @contents |
59 | ||
60 | @c ********************************************************************* | |
61 | @node Top | |
f8348b91 | 62 | @top GNU Guix |
568717fd | 63 | |
f8348b91 LC |
64 | This document describes GNU Guix version @value{VERSION}, a functional |
65 | package management tool written for the GNU system. | |
568717fd LC |
66 | |
67 | @menu | |
68 | * Introduction:: What is Guix about? | |
bd5e766b | 69 | * Installation:: Installing Guix. |
eeaf4427 | 70 | * Package Management:: Package installation, upgrade, etc. |
c554de89 | 71 | * Emacs Interface:: Using Guix from Emacs. |
568717fd LC |
72 | * Programming Interface:: Using Guix in Scheme. |
73 | * Utilities:: Package management commands. | |
a1ba8475 | 74 | * GNU Distribution:: Software for your friendly GNU system. |
9bf3c1a7 | 75 | * Contributing:: Your help needed! |
568717fd LC |
76 | |
77 | * Acknowledgments:: Thanks! | |
78 | * GNU Free Documentation License:: The license of this manual. | |
79 | * Concept Index:: Concepts. | |
a85b83d2 | 80 | * Programming Index:: Data types, functions, and variables. |
aaa3eaa9 LC |
81 | |
82 | @detailmenu | |
83 | --- The Detailed Node Listing --- | |
84 | ||
85 | Installation | |
86 | ||
1b2b8177 | 87 | * Binary Installation:: Getting Guix running in no time! |
aaa3eaa9 | 88 | * Requirements:: Software needed to build and run Guix. |
ec0339cd | 89 | * Running the Test Suite:: Testing Guix. |
aaa3eaa9 LC |
90 | * Setting Up the Daemon:: Preparing the build daemon's environment. |
91 | * Invoking guix-daemon:: Running the build daemon. | |
0e2d0213 | 92 | * Application Setup:: Application-specific setup. |
aaa3eaa9 LC |
93 | |
94 | Setting Up the Daemon | |
95 | ||
96 | * Build Environment Setup:: Preparing the isolated build environment. | |
97 | * Daemon Offload Setup:: Offloading builds to remote machines. | |
98 | ||
99 | Package Management | |
100 | ||
101 | * Features:: How Guix will make your life brighter. | |
102 | * Invoking guix package:: Package installation, removal, etc. | |
aaa3eaa9 LC |
103 | * Substitutes:: Downloading pre-built binaries. |
104 | * Packages with Multiple Outputs:: Single source package, multiple outputs. | |
105 | * Invoking guix gc:: Running the garbage collector. | |
106 | * Invoking guix pull:: Fetching the latest Guix and distribution. | |
107 | * Invoking guix archive:: Exporting and importing store files. | |
108 | ||
c554de89 AK |
109 | Emacs Interface |
110 | ||
111 | * Initial Setup: Emacs Initial Setup. Preparing @file{~/.emacs}. | |
112 | * Package Management: Emacs Package Management. Managing packages and generations. | |
9b0afb0d | 113 | * Popup Interface: Emacs Popup Interface. Magit-like interface for guix commands. |
c554de89 | 114 | * Prettify Mode: Emacs Prettify. Abbreviating @file{/gnu/store/@dots{}} file names. |
34850cd5 | 115 | * Build Log Mode: Emacs Build Log. Highlighting Guix build logs. |
187f80c6 AK |
116 | * Completions: Emacs Completions. Completing @command{guix} shell command. |
117 | * Development: Emacs Development. Tools for Guix developers. | |
c554de89 | 118 | |
aaa3eaa9 LC |
119 | Programming Interface |
120 | ||
121 | * Defining Packages:: Defining new packages. | |
122 | * Build Systems:: Specifying how packages are built. | |
123 | * The Store:: Manipulating the package store. | |
124 | * Derivations:: Low-level interface to package derivations. | |
125 | * The Store Monad:: Purely functional interface to the store. | |
126 | * G-Expressions:: Manipulating build expressions. | |
127 | ||
92492b23 LC |
128 | Defining Packages |
129 | ||
130 | * package Reference:: The package data type. | |
131 | * origin Reference:: The origin data type. | |
132 | ||
aaa3eaa9 LC |
133 | Utilities |
134 | ||
135 | * Invoking guix build:: Building packages from the command line. | |
fcc58db6 | 136 | * Invoking guix edit:: Editing package definitions. |
aaa3eaa9 LC |
137 | * Invoking guix download:: Downloading a file and printing its hash. |
138 | * Invoking guix hash:: Computing the cryptographic hash of a file. | |
139 | * Invoking guix import:: Importing package definitions. | |
140 | * Invoking guix refresh:: Updating package definitions. | |
141 | * Invoking guix lint:: Finding errors in package definitions. | |
fcc58db6 | 142 | * Invoking guix size:: Profiling disk usage. |
88856916 | 143 | * Invoking guix graph:: Visualizing the graph of packages. |
aaa3eaa9 | 144 | * Invoking guix environment:: Setting up development environments. |
aff8ce7c | 145 | * Invoking guix publish:: Sharing substitutes. |
aaa3eaa9 LC |
146 | |
147 | GNU Distribution | |
148 | ||
149 | * System Installation:: Installing the whole operating system. | |
35ed9306 | 150 | * System Configuration:: Configuring the operating system. |
aaa3eaa9 LC |
151 | * Installing Debugging Files:: Feeding the debugger. |
152 | * Security Updates:: Deploying security fixes quickly. | |
153 | * Package Modules:: Packages from the programmer's viewpoint. | |
154 | * Packaging Guidelines:: Growing the distribution. | |
155 | * Bootstrapping:: GNU/Linux built from scratch. | |
156 | * Porting:: Targeting another platform or kernel. | |
157 | ||
158 | System Configuration | |
159 | ||
160 | * Using the Configuration System:: Customizing your GNU system. | |
161 | * operating-system Reference:: Detail of operating-system declarations. | |
162 | * File Systems:: Configuring file system mounts. | |
163 | * Mapped Devices:: Block device extra processing. | |
164 | * User Accounts:: Specifying user accounts. | |
598e19dc | 165 | * Locales:: Language and cultural convention settings. |
aaa3eaa9 LC |
166 | * Services:: Specifying system services. |
167 | * Setuid Programs:: Programs running with root privileges. | |
1b2b8177 | 168 | * X.509 Certificates:: Authenticating HTTPS servers. |
996ed739 | 169 | * Name Service Switch:: Configuring libc's name service switch. |
aaa3eaa9 LC |
170 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
171 | * GRUB Configuration:: Configuring the boot loader. | |
172 | * Invoking guix system:: Instantiating a system configuration. | |
173 | * Defining Services:: Adding new service definitions. | |
174 | ||
175 | Services | |
176 | ||
177 | * Base Services:: Essential system services. | |
178 | * Networking Services:: Network setup, SSH daemon, etc. | |
179 | * X Window:: Graphical display. | |
1b2b8177 LC |
180 | * Desktop Services:: D-Bus and desktop services. |
181 | * Database Services:: SQL databases. | |
cbd02397 | 182 | * Web Services:: Web servers. |
aa4ed923 | 183 | * Various Services:: Other services. |
aaa3eaa9 LC |
184 | |
185 | Packaging Guidelines | |
186 | ||
ec0339cd LC |
187 | * Software Freedom:: What may go into the distribution. |
188 | * Package Naming:: What's in a name? | |
189 | * Version Numbers:: When the name is not enough. | |
cbd02397 | 190 | * Synopses and Descriptions:: Helping users find the right package. |
ec0339cd LC |
191 | * Python Modules:: Taming the snake. |
192 | * Perl Modules:: Little pearls. | |
193 | * Fonts:: Fond of fonts. | |
aaa3eaa9 | 194 | |
8c01b9d0 ML |
195 | Contributing |
196 | ||
197 | * Building from Git:: The latest and greatest. | |
198 | * Running Guix Before It Is Installed:: Hacker tricks. | |
199 | * The Perfect Setup:: The right tools. | |
200 | * Coding Style:: Hygiene of the contributor. | |
201 | * Submitting Patches:: Share your work. | |
202 | ||
203 | Coding Style | |
204 | ||
205 | * Programming Paradigm:: How to compose your elements. | |
206 | * Modules:: Where to store your code? | |
207 | * Data Types and Pattern Matching:: Implementing data structures. | |
208 | * Formatting Code:: Writing conventions. | |
209 | ||
aaa3eaa9 | 210 | @end detailmenu |
568717fd LC |
211 | @end menu |
212 | ||
213 | @c ********************************************************************* | |
214 | @node Introduction | |
215 | @chapter Introduction | |
216 | ||
c80e7e55 LC |
217 | GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks'' |
218 | using the international phonetic alphabet (IPA).} is a functional | |
219 | package management tool for the GNU system. Package management consists | |
4bfc4ea3 NK |
220 | of all activities that relate to building packages from sources, |
221 | honoring their build-time and run-time dependencies, | |
c80e7e55 LC |
222 | installing packages in user environments, upgrading installed packages |
223 | to new versions or rolling back to a previous set, removing unused | |
224 | software packages, etc. | |
568717fd LC |
225 | |
226 | @cindex functional package management | |
227 | The term @dfn{functional} refers to a specific package management | |
228 | discipline. In Guix, the package build and installation process is seen | |
4bfc4ea3 NK |
229 | as a function, in the mathematical sense. That function takes inputs, |
230 | such as build scripts, a compiler, and libraries, and | |
231 | returns an installed package. As a pure function, its result depends | |
568717fd LC |
232 | solely on its inputs---for instance, it cannot refer to software or |
233 | scripts that were not explicitly passed as inputs. A build function | |
4bfc4ea3 NK |
234 | always produces the same result when passed a given set of inputs. It |
235 | cannot alter the system's environment in | |
568717fd LC |
236 | any way; for instance, it cannot create, modify, or delete files outside |
237 | of its build and installation directories. This is achieved by running | |
e900c503 | 238 | build processes in isolated environments (or @dfn{containers}), where only their |
4bfc4ea3 | 239 | explicit inputs are visible. |
568717fd | 240 | |
e531ac2a | 241 | @cindex store |
568717fd | 242 | The result of package build functions is @dfn{cached} in the file |
e531ac2a LC |
243 | system, in a special directory called @dfn{the store} (@pxref{The |
244 | Store}). Each package is installed in a directory of its own, in the | |
834129e0 | 245 | store---by default under @file{/gnu/store}. The directory name contains |
568717fd LC |
246 | a hash of all the inputs used to build that package; thus, changing an |
247 | input yields a different directory name. | |
248 | ||
249 | This approach is the foundation of Guix's salient features: support for | |
4bfc4ea3 | 250 | transactional package upgrade and rollback, per-user installation, and |
eeaf4427 | 251 | garbage collection of packages (@pxref{Features}). |
568717fd | 252 | |
4bfc4ea3 | 253 | Guix has a command-line interface, which allows users to build, install, |
568717fd | 254 | upgrade, and remove packages, as well as a Scheme programming interface. |
568717fd | 255 | |
3ca2731c | 256 | @cindex Guix System Distribution |
4705641f | 257 | @cindex GuixSD |
a1ba8475 | 258 | Last but not least, Guix is used to build a distribution of the GNU |
3ca2731c | 259 | system, with many GNU and non-GNU free software packages. The Guix |
4705641f LC |
260 | System Distribution, or GNU@tie{}GuixSD, takes advantage of the core |
261 | properties of Guix at the system level. With GuixSD, users | |
3ca2731c LC |
262 | @emph{declare} all aspects of the operating system configuration, and |
263 | Guix takes care of instantiating that configuration in a reproducible, | |
264 | stateless fashion. @xref{GNU Distribution}. | |
a1ba8475 | 265 | |
bd5e766b LC |
266 | @c ********************************************************************* |
267 | @node Installation | |
268 | @chapter Installation | |
269 | ||
48febeb8 LC |
270 | GNU Guix is available for download from its website at |
271 | @url{http://www.gnu.org/software/guix/}. This section describes the | |
272 | software requirements of Guix, as well as how to install it and get | |
273 | ready to use it. | |
bd5e766b | 274 | |
5af6de3e LC |
275 | Note that this section is concerned with the installation of the package |
276 | manager, which can be done on top of a running GNU/Linux system. If, | |
277 | instead, you want to install the complete GNU operating system, | |
6621cdb6 | 278 | @pxref{System Installation}. |
5af6de3e | 279 | |
bd5e766b | 280 | @menu |
09722b11 | 281 | * Binary Installation:: Getting Guix running in no time! |
bd5e766b | 282 | * Requirements:: Software needed to build and run Guix. |
ec0339cd | 283 | * Running the Test Suite:: Testing Guix. |
bd5e766b LC |
284 | * Setting Up the Daemon:: Preparing the build daemon's environment. |
285 | * Invoking guix-daemon:: Running the build daemon. | |
0e2d0213 | 286 | * Application Setup:: Application-specific setup. |
bd5e766b LC |
287 | @end menu |
288 | ||
09722b11 LC |
289 | @node Binary Installation |
290 | @section Binary Installation | |
291 | ||
292 | This section describes how to install Guix on an arbitrary system from a | |
293 | self-contained tarball providing binaries for Guix and for all its | |
294 | dependencies. This is often quicker than installing from source, which | |
295 | is described in the next sections. The only requirement is to have | |
296 | GNU@tie{}tar and Xz. | |
297 | ||
298 | Installing goes along these lines: | |
299 | ||
300 | @enumerate | |
301 | @item | |
302 | Download the binary tarball from | |
ae806096 | 303 | @indicateurl{ftp://alpha.gnu.org/gnu/guix/guix-binary-@value{VERSION}.@var{system}.tar.xz}@footnote{As |
09722b11 LC |
304 | usual, make sure to download the associated @file{.sig} file and to |
305 | verify the authenticity of the tarball against it!}, where @var{system} | |
306 | is @code{x86_64-linux} for an @code{x86_64} machine already running the | |
307 | kernel Linux, and so on. | |
308 | ||
309 | @item | |
310 | As @code{root}, run: | |
311 | ||
312 | @example | |
5dc42964 | 313 | # cd /tmp |
254b1c2e LC |
314 | # tar --warning=no-timestamp -xf \ |
315 | guix-binary-@value{VERSION}.@var{system}.tar.xz | |
5dc42964 | 316 | # mv var/guix /var/ && mv gnu / |
09722b11 LC |
317 | @end example |
318 | ||
7acd3439 LC |
319 | This creates @file{/gnu/store} (@pxref{The Store}) and @file{/var/guix}. |
320 | The latter contains a ready-to-use profile for @code{root} (see next | |
321 | step.) | |
09722b11 | 322 | |
5dc3ce5f LC |
323 | Do @emph{not} unpack the tarball on a working Guix system since that |
324 | would overwrite its own essential files. | |
325 | ||
254b1c2e | 326 | The @code{--warning=no-timestamp} option makes sure GNU@tie{}tar does |
e9ba6357 LC |
327 | not emit warnings about ``implausibly old time stamps'' (such |
328 | warnings were triggered by GNU@tie{}tar 1.26 and older; recent | |
329 | versions are fine.) | |
330 | They stem from the fact that all the | |
254b1c2e LC |
331 | files in the archive have their modification time set to zero (which |
332 | means January 1st, 1970.) This is done on purpose to make sure the | |
333 | archive content is independent of its creation time, thus making it | |
334 | reproducible. | |
335 | ||
7acd3439 LC |
336 | @item |
337 | Make @code{root}'s profile available under @file{~/.guix-profile}: | |
338 | ||
339 | @example | |
340 | # ln -sf /var/guix/profiles/per-user/root/guix-profile \ | |
341 | ~root/.guix-profile | |
342 | @end example | |
343 | ||
43c33047 LC |
344 | @item |
345 | Create the group and user accounts for build users as explained below | |
346 | (@pxref{Build Environment Setup}). | |
347 | ||
09722b11 | 348 | @item |
175ced41 | 349 | Run the daemon: |
09722b11 LC |
350 | |
351 | @example | |
7acd3439 | 352 | # ~root/.guix-profile/bin/guix-daemon --build-users-group=guixbuild |
09722b11 LC |
353 | @end example |
354 | ||
d2825c96 LC |
355 | On hosts using the systemd init system, drop |
356 | @file{~root/.guix-profile/lib/systemd/system/guix-daemon.service} in | |
357 | @file{/etc/systemd/system}. | |
358 | ||
09722b11 LC |
359 | @item |
360 | Make the @command{guix} command available to other users on the machine, | |
361 | for instance with: | |
362 | ||
363 | @example | |
364 | # mkdir -p /usr/local/bin | |
365 | # cd /usr/local/bin | |
d72d05f9 | 366 | # ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix |
09722b11 | 367 | @end example |
39f8ed14 LC |
368 | |
369 | @item | |
370 | To use substitutes from @code{hydra.gnu.org} (@pxref{Substitutes}), | |
371 | authorize them: | |
372 | ||
373 | @example | |
7acd3439 | 374 | # guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub |
39f8ed14 | 375 | @end example |
09722b11 LC |
376 | @end enumerate |
377 | ||
53de532f LC |
378 | And that's it! For additional tips and tricks, @pxref{Application |
379 | Setup}. | |
09722b11 | 380 | |
5dc3ce5f | 381 | The @code{guix} package must remain available in @code{root}'s |
09722b11 LC |
382 | profile, or it would become subject to garbage collection---in which |
383 | case you would find yourself badly handicapped by the lack of the | |
384 | @command{guix} command. | |
385 | ||
39f8ed14 LC |
386 | The tarball in question can be (re)produced and verified simply by |
387 | running the following command in the Guix source tree: | |
09722b11 LC |
388 | |
389 | @example | |
390 | make guix-binary.@var{system}.tar.xz | |
391 | @end example | |
392 | ||
393 | ||
bd5e766b LC |
394 | @node Requirements |
395 | @section Requirements | |
396 | ||
09722b11 LC |
397 | This section lists requirements when building Guix from source. The |
398 | build procedure for Guix is the same as for other GNU software, and is | |
399 | not covered here. Please see the files @file{README} and @file{INSTALL} | |
400 | in the Guix source tree for additional details. | |
401 | ||
bd5e766b LC |
402 | GNU Guix depends on the following packages: |
403 | ||
404 | @itemize | |
47c66da0 | 405 | @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.7 or later; |
288dca55 | 406 | @item @url{http://gnupg.org/, GNU libgcrypt}; |
f0b98b84 | 407 | @item @url{http://www.gnu.org/software/make/, GNU Make}. |
8a96bd4b ID |
408 | @end itemize |
409 | ||
410 | The following dependencies are optional: | |
411 | ||
412 | @itemize | |
288dca55 | 413 | @item |
8a96bd4b | 414 | Installing |
288dca55 | 415 | @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will |
2f7d2d91 LC |
416 | allow you to use the @command{guix import pypi} command (@pxref{Invoking |
417 | guix import}). It is of | |
288dca55 | 418 | interest primarily for developers and not for casual users. |
8a96bd4b ID |
419 | @item |
420 | Installing @uref{http://gnutls.org/, GnuTLS-Guile} will | |
421 | allow you to access @code{https} URLs with the @command{guix download} | |
d45dc6da EB |
422 | command (@pxref{Invoking guix download}), the @command{guix import pypi} |
423 | command, and the @command{guix import cpan} command. This is primarily | |
424 | of interest to developers. @xref{Guile Preparations, how to install the | |
425 | GnuTLS bindings for Guile,, gnutls-guile, GnuTLS-Guile}. | |
bd5e766b LC |
426 | @end itemize |
427 | ||
428 | Unless @code{--disable-daemon} was passed to @command{configure}, the | |
429 | following packages are also needed: | |
430 | ||
431 | @itemize | |
368d08f7 LC |
432 | @item @url{http://sqlite.org, SQLite 3}; |
433 | @item @url{http://www.bzip.org, libbz2}; | |
434 | @item @url{http://gcc.gnu.org, GCC's g++}, with support for the | |
435 | C++11 standard. | |
bd5e766b LC |
436 | @end itemize |
437 | ||
4bfc4ea3 NK |
438 | When a working installation of @url{http://nixos.org/nix/, the Nix package |
439 | manager} is available, you | |
bd5e766b | 440 | can instead configure Guix with @code{--disable-daemon}. In that case, |
4bfc4ea3 | 441 | Nix replaces the three dependencies above. |
bd5e766b | 442 | |
b22a12fd LC |
443 | Guix is compatible with Nix, so it is possible to share the same store |
444 | between both. To do so, you must pass @command{configure} not only the | |
445 | same @code{--with-store-dir} value, but also the same | |
4bfc4ea3 NK |
446 | @code{--localstatedir} value. The latter is essential because it |
447 | specifies where the database that stores metadata about the store is | |
834129e0 | 448 | located, among other things. The default values for Nix are |
b22a12fd | 449 | @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}. |
4bfc4ea3 NK |
450 | Note that @code{--disable-daemon} is not required if |
451 | your goal is to share the store with Nix. | |
b22a12fd | 452 | |
ec0339cd LC |
453 | @node Running the Test Suite |
454 | @section Running the Test Suite | |
455 | ||
456 | After a successful @command{configure} and @code{make} run, it is a good | |
457 | idea to run the test suite. It can help catch issues with the setup or | |
458 | environment, or bugs in Guix itself---and really, reporting test | |
459 | failures is a good way to help improve the software. To run the test | |
460 | suite, type: | |
461 | ||
462 | @example | |
463 | make check | |
464 | @end example | |
465 | ||
466 | Test cases can run in parallel: you can use the @code{-j} option of | |
467 | GNU@tie{}make to speed things up. The first run may take a few minutes | |
468 | on a recent machine; subsequent runs will be faster because the store | |
469 | that is created for test purposes will already have various things in | |
470 | cache. | |
471 | ||
472 | Upon failure, please email @email{bug-guix@@gnu.org} and attach the | |
473 | @file{test-suite.log} file. When @file{tests/@var{something}.scm} | |
474 | fails, please also attach the @file{@var{something}.log} file available | |
475 | in the top-level build directory. Please specify the Guix version being | |
476 | used as well as version numbers of the dependencies | |
477 | (@pxref{Requirements}) in your message. | |
478 | ||
bd5e766b LC |
479 | @node Setting Up the Daemon |
480 | @section Setting Up the Daemon | |
481 | ||
482 | @cindex daemon | |
483 | Operations such as building a package or running the garbage collector | |
49e6291a | 484 | are all performed by a specialized process, the @dfn{build daemon}, on |
bd5e766b LC |
485 | behalf of clients. Only the daemon may access the store and its |
486 | associated database. Thus, any operation that manipulates the store | |
487 | goes through the daemon. For instance, command-line tools such as | |
e49951eb | 488 | @command{guix package} and @command{guix build} communicate with the |
bd5e766b LC |
489 | daemon (@i{via} remote procedure calls) to instruct it what to do. |
490 | ||
49e6291a | 491 | The following sections explain how to prepare the build daemon's |
225dafde LC |
492 | environment. Also @ref{Substitutes}, for information on how to allow |
493 | the daemon to download pre-built binaries. | |
49e6291a LC |
494 | |
495 | @menu | |
496 | * Build Environment Setup:: Preparing the isolated build environment. | |
497 | * Daemon Offload Setup:: Offloading builds to remote machines. | |
498 | @end menu | |
499 | ||
500 | @node Build Environment Setup | |
501 | @subsection Build Environment Setup | |
502 | ||
bd5e766b LC |
503 | In a standard multi-user setup, Guix and its daemon---the |
504 | @command{guix-daemon} program---are installed by the system | |
834129e0 | 505 | administrator; @file{/gnu/store} is owned by @code{root} and |
bd5e766b LC |
506 | @command{guix-daemon} runs as @code{root}. Unprivileged users may use |
507 | Guix tools to build packages or otherwise access the store, and the | |
508 | daemon will do it on their behalf, ensuring that the store is kept in a | |
509 | consistent state, and allowing built packages to be shared among users. | |
510 | ||
511 | @cindex build users | |
512 | When @command{guix-daemon} runs as @code{root}, you may not want package | |
513 | build processes themselves to run as @code{root} too, for obvious | |
514 | security reasons. To avoid that, a special pool of @dfn{build users} | |
515 | should be created for use by build processes started by the daemon. | |
516 | These build users need not have a shell and a home directory: they will | |
517 | just be used when the daemon drops @code{root} privileges in build | |
518 | processes. Having several such users allows the daemon to launch | |
519 | distinct build processes under separate UIDs, which guarantees that they | |
520 | do not interfere with each other---an essential feature since builds are | |
521 | regarded as pure functions (@pxref{Introduction}). | |
522 | ||
523 | On a GNU/Linux system, a build user pool may be created like this (using | |
524 | Bash syntax and the @code{shadow} commands): | |
525 | ||
091196b3 LC |
526 | @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html |
527 | @c for why `-G' is needed. | |
bd5e766b | 528 | @example |
cfc149dc LC |
529 | # groupadd --system guixbuild |
530 | # for i in `seq -w 1 10`; | |
bd5e766b | 531 | do |
cfc149dc LC |
532 | useradd -g guixbuild -G guixbuild \ |
533 | -d /var/empty -s `which nologin` \ | |
534 | -c "Guix build user $i" --system \ | |
535 | guixbuilder$i; | |
bd5e766b LC |
536 | done |
537 | @end example | |
538 | ||
539 | @noindent | |
54eb03ab LC |
540 | The number of build users determines how many build jobs may run in |
541 | parallel, as specified by the @option{--max-jobs} option | |
d2825c96 LC |
542 | (@pxref{Invoking guix-daemon, @option{--max-jobs}}). The |
543 | @code{guix-daemon} program may then be run as @code{root} with the | |
544 | following command@footnote{If your machine uses the systemd init system, | |
545 | dropping the @file{@var{prefix}/lib/systemd/system/guix-daemon.service} | |
546 | file in @file{/etc/systemd/system} will ensure that | |
547 | @command{guix-daemon} is automatically started.}: | |
bd5e766b LC |
548 | |
549 | @example | |
cfc149dc | 550 | # guix-daemon --build-users-group=guixbuild |
bd5e766b LC |
551 | @end example |
552 | ||
e900c503 | 553 | @cindex chroot |
b095792f LC |
554 | @noindent |
555 | This way, the daemon starts build processes in a chroot, under one of | |
cfc149dc | 556 | the @code{guixbuilder} users. On GNU/Linux, by default, the chroot |
6dc99317 LC |
557 | environment contains nothing but: |
558 | ||
559 | @c Keep this list in sync with libstore/build.cc! ----------------------- | |
560 | @itemize | |
561 | @item | |
4743a4da LC |
562 | a minimal @code{/dev} directory, created mostly independently from the |
563 | host @code{/dev}@footnote{``Mostly'', because while the set of files | |
564 | that appear in the chroot's @code{/dev} is fixed, most of these files | |
565 | can only be created if the host has them.}; | |
566 | ||
567 | @item | |
568 | the @code{/proc} directory; it only shows the container's processes | |
569 | since a separate PID name space is used; | |
6dc99317 LC |
570 | |
571 | @item | |
572 | @file{/etc/passwd} with an entry for the current user and an entry for | |
573 | user @file{nobody}; | |
574 | ||
575 | @item | |
576 | @file{/etc/group} with an entry for the user's group; | |
577 | ||
578 | @item | |
579 | @file{/etc/hosts} with an entry that maps @code{localhost} to | |
580 | @code{127.0.0.1}; | |
581 | ||
582 | @item | |
583 | a writable @file{/tmp} directory. | |
584 | @end itemize | |
b095792f | 585 | |
1e2644bb LC |
586 | If you are installing Guix as an unprivileged user, it is still possible |
587 | to run @command{guix-daemon} provided you pass @code{--disable-chroot}. | |
588 | However, build processes will not be isolated from one another, and not | |
589 | from the rest of the system. Thus, build processes may interfere with | |
590 | each other, and may access programs, libraries, and other files | |
591 | available on the system---making it much harder to view them as | |
592 | @emph{pure} functions. | |
bd5e766b | 593 | |
49e6291a LC |
594 | |
595 | @node Daemon Offload Setup | |
596 | @subsection Using the Offload Facility | |
597 | ||
598 | @cindex offloading | |
4ec2e92d LC |
599 | @cindex build hook |
600 | When desired, the build daemon can @dfn{offload} | |
601 | derivation builds to other machines | |
49e6291a LC |
602 | running Guix, using the @code{offload} @dfn{build hook}. When that |
603 | feature is enabled, a list of user-specified build machines is read from | |
604 | @file{/etc/guix/machines.scm}; anytime a build is requested, for | |
605 | instance via @code{guix build}, the daemon attempts to offload it to one | |
606 | of the machines that satisfies the derivation's constraints, in | |
607 | particular its system type---e.g., @file{x86_64-linux}. Missing | |
608 | prerequisites for the build are copied over SSH to the target machine, | |
609 | which then proceeds with the build; upon success the output(s) of the | |
610 | build are copied back to the initial machine. | |
611 | ||
4ec2e92d | 612 | The @file{/etc/guix/machines.scm} file typically looks like this: |
49e6291a LC |
613 | |
614 | @example | |
615 | (list (build-machine | |
616 | (name "eightysix.example.org") | |
617 | (system "x86_64-linux") | |
618 | (user "bob") | |
619 | (speed 2.)) ; incredibly fast! | |
620 | ||
621 | (build-machine | |
622 | (name "meeps.example.org") | |
623 | (system "mips64el-linux") | |
624 | (user "alice") | |
625 | (private-key | |
626 | (string-append (getenv "HOME") | |
c4fdfd6f | 627 | "/.lsh/identity-for-guix")))) |
49e6291a LC |
628 | @end example |
629 | ||
630 | @noindent | |
631 | In the example above we specify a list of two build machines, one for | |
632 | the @code{x86_64} architecture and one for the @code{mips64el} | |
4ec2e92d LC |
633 | architecture. |
634 | ||
635 | In fact, this file is---not surprisingly!---a Scheme file that is | |
636 | evaluated when the @code{offload} hook is started. Its return value | |
637 | must be a list of @code{build-machine} objects. While this example | |
638 | shows a fixed list of build machines, one could imagine, say, using | |
639 | DNS-SD to return a list of potential build machines discovered in the | |
640 | local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using | |
c678a4ee LC |
641 | Avahi in Guile Scheme Programs}). The @code{build-machine} data type is |
642 | detailed below. | |
4ec2e92d | 643 | |
c678a4ee LC |
644 | @deftp {Data Type} build-machine |
645 | This data type represents build machines the daemon may offload builds | |
646 | to. The important fields are: | |
49e6291a LC |
647 | |
648 | @table @code | |
649 | ||
650 | @item name | |
651 | The remote machine's host name. | |
652 | ||
653 | @item system | |
c678a4ee | 654 | The remote machine's system type---e.g., @code{"x86_64-linux"}. |
49e6291a LC |
655 | |
656 | @item user | |
657 | The user account to use when connecting to the remote machine over SSH. | |
658 | Note that the SSH key pair must @emph{not} be passphrase-protected, to | |
659 | allow non-interactive logins. | |
660 | ||
661 | @end table | |
662 | ||
4ec2e92d | 663 | A number of optional fields may be specified: |
49e6291a LC |
664 | |
665 | @table @code | |
666 | ||
cecd72d5 LC |
667 | @item port |
668 | Port number of the machine's SSH server (default: 22). | |
669 | ||
49e6291a LC |
670 | @item private-key |
671 | The SSH private key file to use when connecting to the machine. | |
672 | ||
c4fdfd6f LC |
673 | Currently offloading uses GNU@tie{}lsh as its SSH client |
674 | (@pxref{Invoking lsh,,, GNU lsh Manual}). Thus, the key file here must | |
675 | be an lsh key file. This may change in the future, though. | |
676 | ||
49e6291a LC |
677 | @item parallel-builds |
678 | The number of builds that may run in parallel on the machine (1 by | |
679 | default.) | |
680 | ||
681 | @item speed | |
682 | A ``relative speed factor''. The offload scheduler will tend to prefer | |
683 | machines with a higher speed factor. | |
684 | ||
685 | @item features | |
686 | A list of strings denoting specific features supported by the machine. | |
687 | An example is @code{"kvm"} for machines that have the KVM Linux modules | |
688 | and corresponding hardware support. Derivations can request features by | |
689 | name, and they will be scheduled on matching build machines. | |
690 | ||
691 | @end table | |
c678a4ee | 692 | @end deftp |
49e6291a LC |
693 | |
694 | The @code{guix} command must be in the search path on the build | |
695 | machines, since offloading works by invoking the @code{guix archive} and | |
c4fdfd6f LC |
696 | @code{guix build} commands. In addition, the Guix modules must be in |
697 | @code{$GUILE_LOAD_PATH} on the build machine---you can check whether | |
698 | this is the case by running: | |
699 | ||
700 | @example | |
701 | lsh build-machine guile -c '(use-modules (guix config))' | |
702 | @end example | |
49e6291a LC |
703 | |
704 | There's one last thing to do once @file{machines.scm} is in place. As | |
705 | explained above, when offloading, files are transferred back and forth | |
c4fdfd6f LC |
706 | between the machine stores. For this to work, you first need to |
707 | generate a key pair on each machine to allow the daemon to export signed | |
708 | archives of files from the store (@pxref{Invoking guix archive}): | |
49e6291a LC |
709 | |
710 | @example | |
711 | # guix archive --generate-key | |
712 | @end example | |
713 | ||
714 | @noindent | |
c4fdfd6f LC |
715 | Each build machine must authorize the key of the master machine so that |
716 | it accepts store items it receives from the master: | |
717 | ||
718 | @example | |
719 | # guix archive --authorize < master-public-key.txt | |
720 | @end example | |
721 | ||
722 | @noindent | |
723 | Likewise, the master machine must authorize the key of each build machine. | |
724 | ||
725 | All the fuss with keys is here to express pairwise mutual trust | |
726 | relations between the master and the build machines. Concretely, when | |
727 | the master receives files from a build machine (and @i{vice versa}), its | |
728 | build daemon can make sure they are genuine, have not been tampered | |
729 | with, and that they are signed by an authorized key. | |
49e6291a LC |
730 | |
731 | ||
bd5e766b LC |
732 | @node Invoking guix-daemon |
733 | @section Invoking @command{guix-daemon} | |
734 | ||
735 | The @command{guix-daemon} program implements all the functionality to | |
736 | access the store. This includes launching build processes, running the | |
737 | garbage collector, querying the availability of a build result, etc. It | |
738 | is normally run as @code{root} like this: | |
739 | ||
740 | @example | |
cfc149dc | 741 | # guix-daemon --build-users-group=guixbuild |
bd5e766b LC |
742 | @end example |
743 | ||
744 | @noindent | |
081145cf | 745 | For details on how to set it up, @pxref{Setting Up the Daemon}. |
bd5e766b | 746 | |
e900c503 LC |
747 | @cindex chroot |
748 | @cindex container, build environment | |
749 | @cindex build environment | |
750 | @cindex reproducible builds | |
bd5e766b LC |
751 | By default, @command{guix-daemon} launches build processes under |
752 | different UIDs, taken from the build group specified with | |
753 | @code{--build-users-group}. In addition, each build process is run in a | |
754 | chroot environment that only contains the subset of the store that the | |
755 | build process depends on, as specified by its derivation | |
756 | (@pxref{Programming Interface, derivation}), plus a set of specific | |
757 | system directories. By default, the latter contains @file{/dev} and | |
e900c503 LC |
758 | @file{/dev/pts}. Furthermore, on GNU/Linux, the build environment is a |
759 | @dfn{container}: in addition to having its own file system tree, it has | |
760 | a separate mount name space, its own PID name space, network name space, | |
761 | etc. This helps achieve reproducible builds (@pxref{Features}). | |
bd5e766b | 762 | |
cbc538fe LC |
763 | When the daemon performs a build on behalf of the user, it creates a |
764 | build directory under @file{/tmp} or under the directory specified by | |
765 | its @code{TMPDIR} environment variable; this directory is shared with | |
766 | the container for the duration of the build. Be aware that using a | |
767 | directory other than @file{/tmp} can affect build results---for example, | |
768 | with a longer directory name, a build process that uses Unix-domain | |
769 | sockets might hit the name length limitation for @code{sun_path}, which | |
770 | it would otherwise not hit. | |
771 | ||
772 | The build directory is automatically deleted upon completion, unless the | |
773 | build failed and the client specified @option{--keep-failed} | |
774 | (@pxref{Invoking guix build, @option{--keep-failed}}). | |
775 | ||
bd5e766b LC |
776 | The following command-line options are supported: |
777 | ||
778 | @table @code | |
779 | @item --build-users-group=@var{group} | |
780 | Take users from @var{group} to run build processes (@pxref{Setting Up | |
781 | the Daemon, build users}). | |
782 | ||
6858f9d1 | 783 | @item --no-substitutes |
b5385b52 | 784 | @cindex substitutes |
6858f9d1 | 785 | Do not use substitutes for build products. That is, always build things |
c4202d60 LC |
786 | locally instead of allowing downloads of pre-built binaries |
787 | (@pxref{Substitutes}). | |
6858f9d1 | 788 | |
b5385b52 LC |
789 | By default substitutes are used, unless the client---such as the |
790 | @command{guix package} command---is explicitly invoked with | |
791 | @code{--no-substitutes}. | |
792 | ||
793 | When the daemon runs with @code{--no-substitutes}, clients can still | |
794 | explicitly enable substitution @i{via} the @code{set-build-options} | |
795 | remote procedure call (@pxref{The Store}). | |
796 | ||
9176607e | 797 | @item --substitute-urls=@var{urls} |
f8a8e0fe | 798 | @anchor{daemon-substitute-urls} |
9176607e | 799 | Consider @var{urls} the default whitespace-separated list of substitute |
ae806096 | 800 | source URLs. When this option is omitted, @indicateurl{http://hydra.gnu.org} |
9176607e LC |
801 | is used. |
802 | ||
803 | This means that substitutes may be downloaded from @var{urls}, as long | |
804 | as they are signed by a trusted signature (@pxref{Substitutes}). | |
805 | ||
4ec2e92d LC |
806 | @cindex build hook |
807 | @item --no-build-hook | |
808 | Do not use the @dfn{build hook}. | |
809 | ||
810 | The build hook is a helper program that the daemon can start and to | |
811 | which it submits build requests. This mechanism is used to offload | |
812 | builds to other machines (@pxref{Daemon Offload Setup}). | |
813 | ||
bd5e766b LC |
814 | @item --cache-failures |
815 | Cache build failures. By default, only successful builds are cached. | |
816 | ||
30d9aa54 LC |
817 | When this option is used, @command{guix gc --list-failures} can be used |
818 | to query the set of store items marked as failed; @command{guix gc | |
819 | --clear-failures} removes store items from the set of cached failures. | |
820 | @xref{Invoking guix gc}. | |
821 | ||
bd5e766b LC |
822 | @item --cores=@var{n} |
823 | @itemx -c @var{n} | |
824 | Use @var{n} CPU cores to build each derivation; @code{0} means as many | |
825 | as available. | |
826 | ||
6efc160e | 827 | The default value is @code{0}, but it may be overridden by clients, such |
e49951eb MW |
828 | as the @code{--cores} option of @command{guix build} (@pxref{Invoking |
829 | guix build}). | |
bd5e766b LC |
830 | |
831 | The effect is to define the @code{NIX_BUILD_CORES} environment variable | |
832 | in the build process, which can then use it to exploit internal | |
833 | parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}. | |
834 | ||
835 | @item --max-jobs=@var{n} | |
836 | @itemx -M @var{n} | |
837 | Allow at most @var{n} build jobs in parallel. The default value is | |
f6526eb3 LC |
838 | @code{1}. Setting it to @code{0} means that no builds will be performed |
839 | locally; instead, the daemon will offload builds (@pxref{Daemon Offload | |
840 | Setup}), or simply fail. | |
bd5e766b LC |
841 | |
842 | @item --debug | |
843 | Produce debugging output. | |
844 | ||
845 | This is useful to debug daemon start-up issues, but then it may be | |
846 | overridden by clients, for example the @code{--verbosity} option of | |
e49951eb | 847 | @command{guix build} (@pxref{Invoking guix build}). |
bd5e766b LC |
848 | |
849 | @item --chroot-directory=@var{dir} | |
850 | Add @var{dir} to the build chroot. | |
851 | ||
852 | Doing this may change the result of build processes---for instance if | |
853 | they use optional dependencies found in @var{dir} when it is available, | |
854 | and not otherwise. For that reason, it is not recommended to do so. | |
855 | Instead, make sure that each derivation declares all the inputs that it | |
856 | needs. | |
857 | ||
858 | @item --disable-chroot | |
859 | Disable chroot builds. | |
860 | ||
861 | Using this option is not recommended since, again, it would allow build | |
1e2644bb LC |
862 | processes to gain access to undeclared dependencies. It is necessary, |
863 | though, when @command{guix-daemon} is running under an unprivileged user | |
864 | account. | |
bd5e766b LC |
865 | |
866 | @item --disable-log-compression | |
867 | Disable compression of the build logs. | |
868 | ||
1da983b9 LC |
869 | Unless @code{--lose-logs} is used, all the build logs are kept in the |
870 | @var{localstatedir}. To save space, the daemon automatically compresses | |
871 | them with bzip2 by default. This option disables that. | |
872 | ||
ab3893d7 LC |
873 | @item --disable-deduplication |
874 | @cindex deduplication | |
bd5e766b LC |
875 | Disable automatic file ``deduplication'' in the store. |
876 | ||
1da983b9 | 877 | By default, files added to the store are automatically ``deduplicated'': |
ab3893d7 LC |
878 | if a newly added file is identical to another one found in the store, |
879 | the daemon makes the new file a hard link to the other file. This can | |
4988dd40 | 880 | noticeably reduce disk usage, at the expense of slightly increased |
ab3893d7 LC |
881 | input/output load at the end of a build process. This option disables |
882 | this optimization. | |
1da983b9 | 883 | |
6e37066e LC |
884 | @item --gc-keep-outputs[=yes|no] |
885 | Tell whether the garbage collector (GC) must keep outputs of live | |
886 | derivations. | |
887 | ||
888 | When set to ``yes'', the GC will keep the outputs of any live derivation | |
889 | available in the store---the @code{.drv} files. The default is ``no'', | |
890 | meaning that derivation outputs are kept only if they are GC roots. | |
891 | ||
892 | @item --gc-keep-derivations[=yes|no] | |
893 | Tell whether the garbage collector (GC) must keep derivations | |
894 | corresponding to live outputs. | |
895 | ||
896 | When set to ``yes'', as is the case by default, the GC keeps | |
897 | derivations---i.e., @code{.drv} files---as long as at least one of their | |
898 | outputs is live. This allows users to keep track of the origins of | |
899 | items in their store. Setting it to ``no'' saves a bit of disk space. | |
900 | ||
901 | Note that when both @code{--gc-keep-derivations} and | |
902 | @code{--gc-keep-outputs} are used, the effect is to keep all the build | |
903 | prerequisites (the sources, compiler, libraries, and other build-time | |
904 | tools) of live objects in the store, regardless of whether these | |
905 | prerequisites are live. This is convenient for developers since it | |
906 | saves rebuilds or downloads. | |
907 | ||
bd5e766b LC |
908 | @item --impersonate-linux-2.6 |
909 | On Linux-based systems, impersonate Linux 2.6. This means that the | |
910 | kernel's @code{uname} system call will report 2.6 as the release number. | |
911 | ||
912 | This might be helpful to build programs that (usually wrongfully) depend | |
913 | on the kernel version number. | |
914 | ||
915 | @item --lose-logs | |
916 | Do not keep build logs. By default they are kept under | |
ce33631f | 917 | @code{@var{localstatedir}/guix/log}. |
bd5e766b LC |
918 | |
919 | @item --system=@var{system} | |
920 | Assume @var{system} as the current system type. By default it is the | |
921 | architecture/kernel pair found at configure time, such as | |
922 | @code{x86_64-linux}. | |
b8d2aa26 LC |
923 | |
924 | @item --listen=@var{socket} | |
925 | Listen for connections on @var{socket}, the file name of a Unix-domain | |
926 | socket. The default socket is | |
927 | @file{@var{localstatedir}/daemon-socket/socket}. This option is only | |
928 | useful in exceptional circumstances, such as if you need to run several | |
929 | daemons on the same machine. | |
bd5e766b LC |
930 | @end table |
931 | ||
932 | ||
0e2d0213 LC |
933 | @node Application Setup |
934 | @section Application Setup | |
935 | ||
936 | When using Guix on top of GNU/Linux distribution other than GuixSD, a | |
937 | few additional steps are needed to get everything in place. Here are | |
938 | some of them. | |
939 | ||
940 | @subsection Locales | |
941 | ||
5c3c1427 | 942 | @anchor{locales-and-locpath} |
0e2d0213 | 943 | @cindex locales, when not on GuixSD |
5c3c1427 | 944 | @vindex LOCPATH |
0e2d0213 LC |
945 | Packages installed @i{via} Guix will not use the host system's locale |
946 | data. Instead, you must first install one of the locale packages | |
947 | available with Guix and then define the @code{LOCPATH} environment | |
948 | variable (@pxref{Locale Names, @code{LOCPATH},, libc, The GNU C Library | |
949 | Reference Manual}): | |
950 | ||
951 | @example | |
952 | $ guix package -i glibc-locales | |
953 | $ export LOCPATH=$HOME/.guix-profile/lib/locale | |
954 | @end example | |
955 | ||
956 | Note that the @code{glibc-locales} package contains data for all the | |
957 | locales supported by the GNU@tie{}libc and weighs in at around | |
958 | 110@tie{}MiB. Alternately, the @code{glibc-utf8-locales} is smaller but | |
959 | limited to a few UTF-8 locales. | |
960 | ||
961 | @subsection X11 Fonts | |
962 | ||
4988dd40 | 963 | The majority of graphical applications use Fontconfig to locate and |
0e2d0213 LC |
964 | load fonts and perform X11-client-side rendering. Guix's |
965 | @code{fontconfig} package looks for fonts in @file{$HOME/.guix-profile} | |
966 | by default. Thus, to allow graphical applications installed with Guix | |
967 | to display fonts, you will have to install fonts with Guix as well. | |
968 | Essential font packages include @code{gs-fonts}, @code{font-dejavu}, and | |
8fe5b1d1 | 969 | @code{font-gnu-freefont-ttf}. |
0e2d0213 LC |
970 | |
971 | @c TODO What else? | |
972 | ||
eeaf4427 LC |
973 | @c ********************************************************************* |
974 | @node Package Management | |
975 | @chapter Package Management | |
976 | ||
f8348b91 | 977 | The purpose of GNU Guix is to allow users to easily install, upgrade, and |
eeaf4427 LC |
978 | remove software packages, without having to know about their build |
979 | procedure or dependencies. Guix also goes beyond this obvious set of | |
980 | features. | |
981 | ||
982 | This chapter describes the main features of Guix, as well as the package | |
c1941588 | 983 | management tools it provides. Two user interfaces are provided for |
c554de89 AK |
984 | routine package management tasks: A command-line interface described below |
985 | (@pxref{Invoking guix package, @code{guix package}}), as well as a visual user | |
986 | interface in Emacs described in a subsequent chapter (@pxref{Emacs Interface}). | |
eeaf4427 LC |
987 | |
988 | @menu | |
989 | * Features:: How Guix will make your life brighter. | |
e49951eb | 990 | * Invoking guix package:: Package installation, removal, etc. |
c4202d60 | 991 | * Substitutes:: Downloading pre-built binaries. |
760c60d6 | 992 | * Packages with Multiple Outputs:: Single source package, multiple outputs. |
e49951eb | 993 | * Invoking guix gc:: Running the garbage collector. |
f651b477 | 994 | * Invoking guix pull:: Fetching the latest Guix and distribution. |
760c60d6 | 995 | * Invoking guix archive:: Exporting and importing store files. |
eeaf4427 LC |
996 | @end menu |
997 | ||
998 | @node Features | |
999 | @section Features | |
1000 | ||
1001 | When using Guix, each package ends up in the @dfn{package store}, in its | |
1002 | own directory---something that resembles | |
9a130e19 AK |
1003 | @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string |
1004 | (note that Guix comes with an Emacs extension to shorten those file | |
081145cf | 1005 | names, @pxref{Emacs Prettify}.) |
eeaf4427 LC |
1006 | |
1007 | Instead of referring to these directories, users have their own | |
1008 | @dfn{profile}, which points to the packages that they actually want to | |
821b0015 LC |
1009 | use. These profiles are stored within each user's home directory, at |
1010 | @code{$HOME/.guix-profile}. | |
eeaf4427 | 1011 | |
821b0015 | 1012 | For example, @code{alice} installs GCC 4.7.2. As a result, |
eeaf4427 | 1013 | @file{/home/alice/.guix-profile/bin/gcc} points to |
834129e0 | 1014 | @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}. Now, on the same machine, |
821b0015 LC |
1015 | @code{bob} had already installed GCC 4.8.0. The profile of @code{bob} |
1016 | simply continues to point to | |
834129e0 | 1017 | @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC |
821b0015 | 1018 | coexist on the same system without any interference. |
eeaf4427 | 1019 | |
e49951eb MW |
1020 | The @command{guix package} command is the central tool to manage |
1021 | packages (@pxref{Invoking guix package}). It operates on those per-user | |
821b0015 | 1022 | profiles, and can be used @emph{with normal user privileges}. |
eeaf4427 LC |
1023 | |
1024 | The command provides the obvious install, remove, and upgrade | |
1025 | operations. Each invocation is actually a @emph{transaction}: either | |
ba55b1cb | 1026 | the specified operation succeeds, or nothing happens. Thus, if the |
e49951eb | 1027 | @command{guix package} process is terminated during the transaction, |
eeaf4427 LC |
1028 | or if a power outage occurs during the transaction, then the user's |
1029 | profile remains in its previous state, and remains usable. | |
1030 | ||
1031 | In addition, any package transaction may be @emph{rolled back}. So, if, | |
1032 | for example, an upgrade installs a new version of a package that turns | |
1033 | out to have a serious bug, users may roll back to the previous instance | |
4af2447e LC |
1034 | of their profile, which was known to work well. Similarly, the global |
1035 | system configuration is subject to transactional upgrades and roll-back | |
1036 | (@pxref{Using the Configuration System}). | |
eeaf4427 LC |
1037 | |
1038 | All those packages in the package store may be @emph{garbage-collected}. | |
1039 | Guix can determine which packages are still referenced by the user | |
fe8ff028 | 1040 | profiles, and remove those that are provably no longer referenced |
e49951eb | 1041 | (@pxref{Invoking guix gc}). Users may also explicitly remove old |
fe8ff028 LC |
1042 | generations of their profile so that the packages they refer to can be |
1043 | collected. | |
eeaf4427 | 1044 | |
e900c503 LC |
1045 | @cindex reproducibility |
1046 | @cindex reproducible builds | |
eeaf4427 LC |
1047 | Finally, Guix takes a @dfn{purely functional} approach to package |
1048 | management, as described in the introduction (@pxref{Introduction}). | |
834129e0 | 1049 | Each @file{/gnu/store} package directory name contains a hash of all the |
eeaf4427 LC |
1050 | inputs that were used to build that package---compiler, libraries, build |
1051 | scripts, etc. This direct correspondence allows users to make sure a | |
1052 | given package installation matches the current state of their | |
e900c503 LC |
1053 | distribution. It also helps maximize @dfn{build reproducibility}: |
1054 | thanks to the isolated build environments that are used, a given build | |
1055 | is likely to yield bit-identical files when performed on different | |
1056 | machines (@pxref{Invoking guix-daemon, container}). | |
eeaf4427 | 1057 | |
c4202d60 | 1058 | @cindex substitutes |
eeaf4427 | 1059 | This foundation allows Guix to support @dfn{transparent binary/source |
c4202d60 | 1060 | deployment}. When a pre-built binary for a @file{/gnu/store} item is |
18f2887b | 1061 | available from an external source---a @dfn{substitute}, Guix just |
c4202d60 LC |
1062 | downloads it and unpacks it; |
1063 | otherwise, it builds the package from source, locally | |
1064 | (@pxref{Substitutes}). | |
eeaf4427 | 1065 | |
f5fd4fd2 LC |
1066 | Control over the build environment is a feature that is also useful for |
1067 | developers. The @command{guix environment} command allows developers of | |
1068 | a package to quickly set up the right development environment for their | |
1069 | package, without having to manually install the package's dependencies | |
1070 | in their profile (@pxref{Invoking guix environment}). | |
1071 | ||
e49951eb MW |
1072 | @node Invoking guix package |
1073 | @section Invoking @command{guix package} | |
eeaf4427 | 1074 | |
e49951eb | 1075 | The @command{guix package} command is the tool that allows users to |
eeaf4427 LC |
1076 | install, upgrade, and remove packages, as well as rolling back to |
1077 | previous configurations. It operates only on the user's own profile, | |
1078 | and works with normal user privileges (@pxref{Features}). Its syntax | |
1079 | is: | |
1080 | ||
1081 | @example | |
e49951eb | 1082 | guix package @var{options} |
eeaf4427 LC |
1083 | @end example |
1084 | ||
ba55b1cb | 1085 | Primarily, @var{options} specifies the operations to be performed during |
eeaf4427 | 1086 | the transaction. Upon completion, a new profile is created, but |
99bd74d5 | 1087 | previous @dfn{generations} of the profile remain available, should the user |
eeaf4427 LC |
1088 | want to roll back. |
1089 | ||
6447738c MW |
1090 | For example, to remove @code{lua} and install @code{guile} and |
1091 | @code{guile-cairo} in a single transaction: | |
1092 | ||
1093 | @example | |
1094 | guix package -r lua -i guile guile-cairo | |
1095 | @end example | |
1096 | ||
99bd74d5 LC |
1097 | @command{guix package} also supports a @dfn{declarative approach} |
1098 | whereby the user specifies the exact set of packages to be available and | |
1099 | passes it @i{via} the @option{--manifest} option | |
1100 | (@pxref{profile-manifest, @option{--manifest}}). | |
1101 | ||
b9e5c0a9 | 1102 | For each user, a symlink to the user's default profile is automatically |
0ec1af59 | 1103 | created in @file{$HOME/.guix-profile}. This symlink always points to the |
b9e5c0a9 LC |
1104 | current generation of the user's default profile. Thus, users can add |
1105 | @file{$HOME/.guix-profile/bin} to their @code{PATH} environment | |
1106 | variable, and so on. | |
d664f1b4 LC |
1107 | @cindex search paths |
1108 | If you are not using the Guix System Distribution, consider adding the | |
1109 | following lines to your @file{~/.bash_profile} (@pxref{Bash Startup | |
1110 | Files,,, bash, The GNU Bash Reference Manual}) so that newly-spawned | |
1111 | shells get all the right environment variable definitions: | |
1112 | ||
1113 | @example | |
1114 | GUIX_PROFILE="$HOME/.guix-profile" \ | |
1115 | source "$HOME/.guix-profile/etc/profile" | |
1116 | @end example | |
b9e5c0a9 | 1117 | |
4379c35b LC |
1118 | In a multi-user setup, user profiles are stored in a place registered as |
1119 | a @dfn{garbage-collector root}, which @file{$HOME/.guix-profile} points | |
1120 | to (@pxref{Invoking guix gc}). That directory is normally | |
0ec1af59 LC |
1121 | @code{@var{localstatedir}/profiles/per-user/@var{user}}, where |
1122 | @var{localstatedir} is the value passed to @code{configure} as | |
4379c35b LC |
1123 | @code{--localstatedir}, and @var{user} is the user name. The |
1124 | @file{per-user} directory is created when @command{guix-daemon} is | |
1125 | started, and the @var{user} sub-directory is created by @command{guix | |
1126 | package}. | |
0ec1af59 LC |
1127 | |
1128 | The @var{options} can be among the following: | |
1129 | ||
eeaf4427 LC |
1130 | @table @code |
1131 | ||
6447738c MW |
1132 | @item --install=@var{package} @dots{} |
1133 | @itemx -i @var{package} @dots{} | |
1134 | Install the specified @var{package}s. | |
eeaf4427 | 1135 | |
6447738c | 1136 | Each @var{package} may specify either a simple package name, such as |
eeaf4427 | 1137 | @code{guile}, or a package name followed by a hyphen and version number, |
724311a2 LC |
1138 | such as @code{guile-1.8.8} or simply @code{guile-1.8} (in the latter |
1139 | case, the newest version prefixed by @code{1.8} is selected.) | |
1140 | ||
1141 | If no version number is specified, the | |
dc5669cd MW |
1142 | newest available version will be selected. In addition, @var{package} |
1143 | may contain a colon, followed by the name of one of the outputs of the | |
6e721c4d | 1144 | package, as in @code{gcc:doc} or @code{binutils-2.22:lib} |
e7f34eb0 LC |
1145 | (@pxref{Packages with Multiple Outputs}). Packages with a corresponding |
1146 | name (and optionally version) are searched for among the GNU | |
1147 | distribution modules (@pxref{Package Modules}). | |
eeaf4427 | 1148 | |
461572cc LC |
1149 | @cindex propagated inputs |
1150 | Sometimes packages have @dfn{propagated inputs}: these are dependencies | |
21461f27 LC |
1151 | that automatically get installed along with the required package |
1152 | (@pxref{package-propagated-inputs, @code{propagated-inputs} in | |
1153 | @code{package} objects}, for information about propagated inputs in | |
1154 | package definitions). | |
461572cc | 1155 | |
21461f27 | 1156 | @anchor{package-cmd-propagated-inputs} |
461572cc LC |
1157 | An example is the GNU MPC library: its C header files refer to those of |
1158 | the GNU MPFR library, which in turn refer to those of the GMP library. | |
1159 | Thus, when installing MPC, the MPFR and GMP libraries also get installed | |
1160 | in the profile; removing MPC also removes MPFR and GMP---unless they had | |
1161 | also been explicitly installed independently. | |
1162 | ||
ba7ea5ce | 1163 | Besides, packages sometimes rely on the definition of environment |
5924080d | 1164 | variables for their search paths (see explanation of |
ba7ea5ce | 1165 | @code{--search-paths} below). Any missing or possibly incorrect |
5924080d LC |
1166 | environment variable definitions are reported here. |
1167 | ||
ef010c0f | 1168 | @c XXX: keep me up-to-date |
5924080d | 1169 | Finally, when installing a GNU package, the tool reports the |
ef010c0f LC |
1170 | availability of a newer upstream version. In the future, it may provide |
1171 | the option of installing directly from the upstream version, even if | |
1172 | that version is not yet in the distribution. | |
1173 | ||
5d4b411f LC |
1174 | @item --install-from-expression=@var{exp} |
1175 | @itemx -e @var{exp} | |
1176 | Install the package @var{exp} evaluates to. | |
1177 | ||
1178 | @var{exp} must be a Scheme expression that evaluates to a | |
1179 | @code{<package>} object. This option is notably useful to disambiguate | |
1180 | between same-named variants of a package, with expressions such as | |
1181 | @code{(@@ (gnu packages base) guile-final)}. | |
1182 | ||
1183 | Note that this option installs the first output of the specified | |
1184 | package, which may be insufficient when needing a specific output of a | |
1185 | multiple-output package. | |
1186 | ||
0d279400 DT |
1187 | @item --install-from-file=@var{file} |
1188 | @itemx -f @var{file} | |
1189 | Install the package that the code within @var{file} evaluates to. | |
1190 | ||
1191 | As an example, @var{file} might contain a definition like this | |
1192 | (@pxref{Defining Packages}): | |
1193 | ||
1194 | @example | |
1195 | @verbatiminclude package-hello.scm | |
1196 | @end example | |
1197 | ||
1198 | Developers may find it useful to include such a @file{package.scm} file | |
1199 | in the root of their project's source tree that can be used to test | |
1200 | development snapshots and create reproducible development environments | |
1201 | (@pxref{Invoking guix environment}). | |
1202 | ||
6447738c MW |
1203 | @item --remove=@var{package} @dots{} |
1204 | @itemx -r @var{package} @dots{} | |
1205 | Remove the specified @var{package}s. | |
eeaf4427 | 1206 | |
6447738c | 1207 | As for @code{--install}, each @var{package} may specify a version number |
13ed095c LC |
1208 | and/or output name in addition to the package name. For instance, |
1209 | @code{-r glibc:debug} would remove the @code{debug} output of | |
1210 | @code{glibc}. | |
1211 | ||
6447738c MW |
1212 | @item --upgrade[=@var{regexp} @dots{}] |
1213 | @itemx -u [@var{regexp} @dots{}] | |
1214 | Upgrade all the installed packages. If one or more @var{regexp}s are | |
1215 | specified, upgrade only installed packages whose name matches a | |
d5f01e48 | 1216 | @var{regexp}. Also see the @code{--do-not-upgrade} option below. |
eeaf4427 | 1217 | |
f651b477 LC |
1218 | Note that this upgrades package to the latest version of packages found |
1219 | in the distribution currently installed. To update your distribution, | |
1220 | you should regularly run @command{guix pull} (@pxref{Invoking guix | |
1221 | pull}). | |
1222 | ||
d5f01e48 MW |
1223 | @item --do-not-upgrade[=@var{regexp} @dots{}] |
1224 | When used together with the @code{--upgrade} option, do @emph{not} | |
1225 | upgrade any packages whose name matches a @var{regexp}. For example, to | |
1226 | upgrade all packages in the current profile except those containing the | |
1227 | substring ``emacs'': | |
1228 | ||
1229 | @example | |
1230 | $ guix package --upgrade . --do-not-upgrade emacs | |
1231 | @end example | |
1232 | ||
99bd74d5 | 1233 | @item @anchor{profile-manifest}--manifest=@var{file} |
1b676447 | 1234 | @itemx -m @var{file} |
99bd74d5 LC |
1235 | @cindex profile declaration |
1236 | @cindex profile manifest | |
1237 | Create a new generation of the profile from the manifest object | |
1b676447 DT |
1238 | returned by the Scheme code in @var{file}. |
1239 | ||
99bd74d5 LC |
1240 | This allows you to @emph{declare} the profile's contents rather than |
1241 | constructing it through a sequence of @code{--install} and similar | |
1242 | commands. The advantage is that @var{file} can be put under version | |
1243 | control, copied to different machines to reproduce the same profile, and | |
1244 | so on. | |
1245 | ||
1246 | @c FIXME: Add reference to (guix profile) documentation when available. | |
1247 | @var{file} must return a @dfn{manifest} object, which is roughly a list | |
1248 | of packages: | |
1b676447 | 1249 | |
99bd74d5 | 1250 | @findex packages->manifest |
1b676447 | 1251 | @example |
99bd74d5 | 1252 | (use-package-modules guile emacs) |
1b676447 DT |
1253 | |
1254 | (packages->manifest | |
99bd74d5 LC |
1255 | (list emacs |
1256 | guile-2.0 | |
1b676447 | 1257 | ;; Use a specific package output. |
99bd74d5 | 1258 | (list guile-2.0 "debug"))) |
1b676447 DT |
1259 | @end example |
1260 | ||
24e262f0 LC |
1261 | @item --roll-back |
1262 | Roll back to the previous @dfn{generation} of the profile---i.e., undo | |
1263 | the last transaction. | |
1264 | ||
1265 | When combined with options such as @code{--install}, roll back occurs | |
1266 | before any other actions. | |
1267 | ||
d9307267 | 1268 | When rolling back from the first generation that actually contains |
4b2bc804 NK |
1269 | installed packages, the profile is made to point to the @dfn{zeroth |
1270 | generation}, which contains no files apart from its own meta-data. | |
d9307267 | 1271 | |
82fe08ed LC |
1272 | Installing, removing, or upgrading packages from a generation that has |
1273 | been rolled back to overwrites previous future generations. Thus, the | |
1274 | history of a profile's generations is always linear. | |
1275 | ||
b3bb82f1 AK |
1276 | @item --switch-generation=@var{pattern} |
1277 | @itemx -S @var{pattern} | |
1278 | Switch to a particular generation defined by @var{pattern}. | |
1279 | ||
1280 | @var{pattern} may be either a generation number or a number prefixed | |
1281 | with ``+'' or ``-''. The latter means: move forward/backward by a | |
1282 | specified number of generations. For example, if you want to return to | |
1283 | the latest generation after @code{--roll-back}, use | |
1284 | @code{--switch-generation=+1}. | |
1285 | ||
1286 | The difference between @code{--roll-back} and | |
1287 | @code{--switch-generation=-1} is that @code{--switch-generation} will | |
1288 | not make a zeroth generation, so if a specified generation does not | |
1289 | exist, the current generation will not be changed. | |
1290 | ||
dbc31ab2 | 1291 | @item --search-paths[=@var{kind}] |
5924080d LC |
1292 | @cindex search paths |
1293 | Report environment variable definitions, in Bash syntax, that may be | |
1294 | needed in order to use the set of installed packages. These environment | |
1295 | variables are used to specify @dfn{search paths} for files used by some | |
1296 | of the installed packages. | |
1297 | ||
1298 | For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH} | |
1299 | environment variables to be defined so it can look for headers and | |
1300 | libraries in the user's profile (@pxref{Environment Variables,,, gcc, | |
1301 | Using the GNU Compiler Collection (GCC)}). If GCC and, say, the C | |
1302 | library are installed in the profile, then @code{--search-paths} will | |
1303 | suggest setting these variables to @code{@var{profile}/include} and | |
1304 | @code{@var{profile}/lib}, respectively. | |
1305 | ||
dbc31ab2 LC |
1306 | The typical use case is to define these environment variables in the |
1307 | shell: | |
1308 | ||
1309 | @example | |
1310 | $ eval `guix package --search-paths` | |
1311 | @end example | |
1312 | ||
1313 | @var{kind} may be one of @code{exact}, @code{prefix}, or @code{suffix}, | |
1314 | meaning that the returned environment variable definitions will either | |
1315 | be exact settings, or prefixes or suffixes of the current value of these | |
1316 | variables. When omitted, @var{kind} defaults to @code{exact}. | |
1317 | ||
eeaf4427 LC |
1318 | @item --profile=@var{profile} |
1319 | @itemx -p @var{profile} | |
1320 | Use @var{profile} instead of the user's default profile. | |
1321 | ||
70915c1a LC |
1322 | @item --verbose |
1323 | Produce verbose output. In particular, emit the environment's build log | |
1324 | on the standard error port. | |
1325 | ||
eeaf4427 LC |
1326 | @item --bootstrap |
1327 | Use the bootstrap Guile to build the profile. This option is only | |
1328 | useful to distribution developers. | |
1329 | ||
1330 | @end table | |
1331 | ||
e49951eb | 1332 | In addition to these actions @command{guix package} supports the |
733b4130 LC |
1333 | following options to query the current state of a profile, or the |
1334 | availability of packages: | |
eeaf4427 | 1335 | |
733b4130 LC |
1336 | @table @option |
1337 | ||
acc08466 NK |
1338 | @item --search=@var{regexp} |
1339 | @itemx -s @var{regexp} | |
5763ad92 | 1340 | List the available packages whose name, synopsis, or description matches |
299112d3 LC |
1341 | @var{regexp}. Print all the meta-data of matching packages in |
1342 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, | |
1343 | GNU recutils manual}). | |
acc08466 | 1344 | |
299112d3 LC |
1345 | This allows specific fields to be extracted using the @command{recsel} |
1346 | command, for instance: | |
1347 | ||
1348 | @example | |
e49951eb | 1349 | $ guix package -s malloc | recsel -p name,version |
299112d3 LC |
1350 | name: glibc |
1351 | version: 2.17 | |
1352 | ||
1353 | name: libgc | |
1354 | version: 7.2alpha6 | |
1355 | @end example | |
acc08466 | 1356 | |
a12d92f5 LC |
1357 | Similarly, to show the name of all the packages available under the |
1358 | terms of the GNU@tie{}LGPL version 3: | |
1359 | ||
1360 | @example | |
1361 | $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"' | |
1362 | name: elfutils | |
1363 | ||
1364 | name: gmp | |
1365 | @dots{} | |
1366 | @end example | |
1367 | ||
2aa6efb0 CR |
1368 | @item --show=@var{package} |
1369 | Show details about @var{package}, taken from the list of available packages, in | |
1370 | @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU | |
1371 | recutils manual}). | |
1372 | ||
1373 | @example | |
1374 | $ guix package --show=python | recsel -p name,version | |
1375 | name: python | |
1376 | version: 2.7.6 | |
1377 | ||
1378 | name: python | |
1379 | version: 3.3.5 | |
1380 | @end example | |
1381 | ||
1382 | You may also specify the full name of a package to only get details about a | |
1383 | specific version of it: | |
1384 | @example | |
1385 | $ guix package --show=python-3.3.5 | recsel -p name,version | |
1386 | name: python | |
1387 | version: 3.3.5 | |
1388 | @end example | |
1389 | ||
1390 | ||
1391 | ||
733b4130 LC |
1392 | @item --list-installed[=@var{regexp}] |
1393 | @itemx -I [@var{regexp}] | |
bd9bde1c LC |
1394 | List the currently installed packages in the specified profile, with the |
1395 | most recently installed packages shown last. When @var{regexp} is | |
1396 | specified, list only installed packages whose name matches @var{regexp}. | |
733b4130 LC |
1397 | |
1398 | For each installed package, print the following items, separated by | |
1399 | tabs: the package name, its version string, the part of the package that | |
1400 | is installed (for instance, @code{out} for the default output, | |
1401 | @code{include} for its headers, etc.), and the path of this package in | |
1402 | the store. | |
1403 | ||
64fc89b6 LC |
1404 | @item --list-available[=@var{regexp}] |
1405 | @itemx -A [@var{regexp}] | |
5763ad92 | 1406 | List packages currently available in the distribution for this system |
a1ba8475 LC |
1407 | (@pxref{GNU Distribution}). When @var{regexp} is specified, list only |
1408 | installed packages whose name matches @var{regexp}. | |
64fc89b6 LC |
1409 | |
1410 | For each package, print the following items separated by tabs: its name, | |
6e721c4d LC |
1411 | its version string, the parts of the package (@pxref{Packages with |
1412 | Multiple Outputs}), and the source location of its definition. | |
64fc89b6 | 1413 | |
f566d765 LC |
1414 | @item --list-generations[=@var{pattern}] |
1415 | @itemx -l [@var{pattern}] | |
1416 | Return a list of generations along with their creation dates; for each | |
1417 | generation, show the installed packages, with the most recently | |
4b2bc804 NK |
1418 | installed packages shown last. Note that the zeroth generation is never |
1419 | shown. | |
f566d765 LC |
1420 | |
1421 | For each installed package, print the following items, separated by | |
1422 | tabs: the name of a package, its version string, the part of the package | |
1423 | that is installed (@pxref{Packages with Multiple Outputs}), and the | |
1424 | location of this package in the store. | |
1425 | ||
1426 | When @var{pattern} is used, the command returns only matching | |
1427 | generations. Valid patterns include: | |
1428 | ||
1429 | @itemize | |
1430 | @item @emph{Integers and comma-separated integers}. Both patterns denote | |
1431 | generation numbers. For instance, @code{--list-generations=1} returns | |
1432 | the first one. | |
1433 | ||
1434 | And @code{--list-generations=1,8,2} outputs three generations in the | |
1435 | specified order. Neither spaces nor trailing commas are allowed. | |
1436 | ||
1437 | @item @emph{Ranges}. @code{--list-generations=2..9} prints the | |
1438 | specified generations and everything in between. Note that the start of | |
1439 | a range must be lesser than its end. | |
1440 | ||
1441 | It is also possible to omit the endpoint. For example, | |
1442 | @code{--list-generations=2..}, returns all generations starting from the | |
1443 | second one. | |
1444 | ||
1445 | @item @emph{Durations}. You can also get the last @emph{N}@tie{}days, weeks, | |
1446 | or months by passing an integer along with the first letter of the | |
d7ddb257 LC |
1447 | duration. For example, @code{--list-generations=20d} lists generations |
1448 | that are up to 20 days old. | |
f566d765 LC |
1449 | @end itemize |
1450 | ||
b7884ca3 NK |
1451 | @item --delete-generations[=@var{pattern}] |
1452 | @itemx -d [@var{pattern}] | |
d7ddb257 LC |
1453 | When @var{pattern} is omitted, delete all generations except the current |
1454 | one. | |
b7884ca3 NK |
1455 | |
1456 | This command accepts the same patterns as @option{--list-generations}. | |
d7ddb257 LC |
1457 | When @var{pattern} is specified, delete the matching generations. When |
1458 | @var{pattern} specifies a duration, generations @emph{older} than the | |
1459 | specified duration match. For instance, @code{--delete-generations=1m} | |
1460 | deletes generations that are more than one month old. | |
1461 | ||
391bdd8f LC |
1462 | If the current generation matches, it is @emph{not} deleted. Also, the |
1463 | zeroth generation is never deleted. | |
b7884ca3 | 1464 | |
1bb9900a LC |
1465 | Note that deleting generations prevents roll-back to them. |
1466 | Consequently, this command must be used with care. | |
1467 | ||
733b4130 | 1468 | @end table |
eeaf4427 | 1469 | |
70ee5642 LC |
1470 | Finally, since @command{guix package} may actually start build |
1471 | processes, it supports all the common build options that @command{guix | |
1472 | build} supports (@pxref{Invoking guix build, common build options}). | |
1473 | ||
c4202d60 LC |
1474 | @node Substitutes |
1475 | @section Substitutes | |
1476 | ||
1477 | @cindex substitutes | |
1478 | @cindex pre-built binaries | |
1479 | Guix supports transparent source/binary deployment, which means that it | |
1480 | can either build things locally, or download pre-built items from a | |
1481 | server. We call these pre-built items @dfn{substitutes}---they are | |
1482 | substitutes for local build results. In many cases, downloading a | |
1483 | substitute is much faster than building things locally. | |
1484 | ||
1485 | Substitutes can be anything resulting from a derivation build | |
1486 | (@pxref{Derivations}). Of course, in the common case, they are | |
1487 | pre-built package binaries, but source tarballs, for instance, which | |
1488 | also result from derivation builds, can be available as substitutes. | |
1489 | ||
1490 | The @code{hydra.gnu.org} server is a front-end to a build farm that | |
1491 | builds packages from the GNU distribution continuously for some | |
9176607e | 1492 | architectures, and makes them available as substitutes. This is the |
f8a8e0fe LC |
1493 | default source of substitutes; it can be overridden by passing the |
1494 | @option{--substitute-urls} option either to @command{guix-daemon} | |
1495 | (@pxref{daemon-substitute-urls,, @code{guix-daemon --substitute-urls}}) | |
1496 | or to client tools such as @command{guix package} | |
1497 | (@pxref{client-substitute-urls,, client @option{--substitute-urls} | |
1498 | option}). | |
c4202d60 LC |
1499 | |
1500 | @cindex security | |
1501 | @cindex digital signatures | |
1502 | To allow Guix to download substitutes from @code{hydra.gnu.org}, you | |
1503 | must add its public key to the access control list (ACL) of archive | |
1504 | imports, using the @command{guix archive} command (@pxref{Invoking guix | |
1505 | archive}). Doing so implies that you trust @code{hydra.gnu.org} to not | |
1506 | be compromised and to serve genuine substitutes. | |
1507 | ||
1508 | This public key is installed along with Guix, in | |
1509 | @code{@var{prefix}/share/guix/hydra.gnu.org.pub}, where @var{prefix} is | |
1510 | the installation prefix of Guix. If you installed Guix from source, | |
1511 | make sure you checked the GPG signature of | |
1512 | @file{guix-@value{VERSION}.tar.gz}, which contains this public key file. | |
1513 | Then, you can run something like this: | |
1514 | ||
1515 | @example | |
1516 | # guix archive --authorize < hydra.gnu.org.pub | |
1517 | @end example | |
1518 | ||
1519 | Once this is in place, the output of a command like @code{guix build} | |
1520 | should change from something like: | |
1521 | ||
1522 | @example | |
1523 | $ guix build emacs --dry-run | |
1524 | The following derivations would be built: | |
1525 | /gnu/store/yr7bnx8xwcayd6j95r2clmkdl1qh688w-emacs-24.3.drv | |
1526 | /gnu/store/x8qsh1hlhgjx6cwsjyvybnfv2i37z23w-dbus-1.6.4.tar.gz.drv | |
1527 | /gnu/store/1ixwp12fl950d15h2cj11c73733jay0z-alsa-lib-1.0.27.1.tar.bz2.drv | |
1528 | /gnu/store/nlma1pw0p603fpfiqy7kn4zm105r5dmw-util-linux-2.21.drv | |
1529 | @dots{} | |
1530 | @end example | |
1531 | ||
1532 | @noindent | |
1533 | to something like: | |
1534 | ||
1535 | @example | |
1536 | $ guix build emacs --dry-run | |
1537 | The following files would be downloaded: | |
1538 | /gnu/store/pk3n22lbq6ydamyymqkkz7i69wiwjiwi-emacs-24.3 | |
1539 | /gnu/store/2ygn4ncnhrpr61rssa6z0d9x22si0va3-libjpeg-8d | |
1540 | /gnu/store/71yz6lgx4dazma9dwn2mcjxaah9w77jq-cairo-1.12.16 | |
1541 | /gnu/store/7zdhgp0n1518lvfn8mb96sxqfmvqrl7v-libxrender-0.9.7 | |
1542 | @dots{} | |
1543 | @end example | |
1544 | ||
1545 | @noindent | |
1546 | This indicates that substitutes from @code{hydra.gnu.org} are usable and | |
1547 | will be downloaded, when possible, for future builds. | |
1548 | ||
1549 | Guix ignores substitutes that are not signed, or that are not signed by | |
ef27aa9c | 1550 | one of the keys listed in the ACL. It also detects and raises an error |
c4202d60 LC |
1551 | when attempting to use a substitute that has been tampered with. |
1552 | ||
1553 | The substitute mechanism can be disabled globally by running | |
1554 | @code{guix-daemon} with @code{--no-substitutes} (@pxref{Invoking | |
1555 | guix-daemon}). It can also be disabled temporarily by passing the | |
1556 | @code{--no-substitutes} option to @command{guix package}, @command{guix | |
1557 | build}, and other command-line tools. | |
1558 | ||
1559 | ||
1560 | Today, each individual's control over their own computing is at the | |
1561 | mercy of institutions, corporations, and groups with enough power and | |
1562 | determination to subvert the computing infrastructure and exploit its | |
1563 | weaknesses. While using @code{hydra.gnu.org} substitutes can be | |
1564 | convenient, we encourage users to also build on their own, or even run | |
1565 | their own build farm, such that @code{hydra.gnu.org} is less of an | |
8ce229fc LC |
1566 | interesting target. One way to help is by publishing the software you |
1567 | build using @command{guix publish} so that others have one more choice | |
1568 | of server to download substitutes from (@pxref{Invoking guix publish}). | |
c4202d60 LC |
1569 | |
1570 | Guix has the foundations to maximize build reproducibility | |
1571 | (@pxref{Features}). In most cases, independent builds of a given | |
1572 | package or derivation should yield bit-identical results. Thus, through | |
1573 | a diverse set of independent package builds, we can strengthen the | |
1574 | integrity of our systems. | |
1575 | ||
1576 | In the future, we want Guix to have support to publish and retrieve | |
1577 | binaries to/from other users, in a peer-to-peer fashion. If you would | |
1578 | like to discuss this project, join us on @email{guix-devel@@gnu.org}. | |
1579 | ||
1580 | ||
6e721c4d LC |
1581 | @node Packages with Multiple Outputs |
1582 | @section Packages with Multiple Outputs | |
1583 | ||
1584 | @cindex multiple-output packages | |
1585 | @cindex package outputs | |
1586 | ||
1587 | Often, packages defined in Guix have a single @dfn{output}---i.e., the | |
1588 | source package leads exactly one directory in the store. When running | |
1589 | @command{guix package -i glibc}, one installs the default output of the | |
1590 | GNU libc package; the default output is called @code{out}, but its name | |
1591 | can be omitted as shown in this command. In this particular case, the | |
1592 | default output of @code{glibc} contains all the C header files, shared | |
1593 | libraries, static libraries, Info documentation, and other supporting | |
1594 | files. | |
1595 | ||
1596 | Sometimes it is more appropriate to separate the various types of files | |
1597 | produced from a single source package into separate outputs. For | |
1598 | instance, the GLib C library (used by GTK+ and related packages) | |
1599 | installs more than 20 MiB of reference documentation as HTML pages. | |
1600 | To save space for users who do not need it, the documentation goes to a | |
1601 | separate output, called @code{doc}. To install the main GLib output, | |
1602 | which contains everything but the documentation, one would run: | |
1603 | ||
1604 | @example | |
1605 | guix package -i glib | |
1606 | @end example | |
1607 | ||
1608 | The command to install its documentation is: | |
1609 | ||
1610 | @example | |
1611 | guix package -i glib:doc | |
1612 | @end example | |
1613 | ||
1614 | Some packages install programs with different ``dependency footprints''. | |
1615 | For instance, the WordNet package install both command-line tools and | |
1616 | graphical user interfaces (GUIs). The former depend solely on the C | |
1617 | library, whereas the latter depend on Tcl/Tk and the underlying X | |
1618 | libraries. In this case, we leave the command-line tools in the default | |
1619 | output, whereas the GUIs are in a separate output. This allows users | |
fcc58db6 LC |
1620 | who do not need the GUIs to save space. The @command{guix size} command |
1621 | can help find out about such situations (@pxref{Invoking guix size}). | |
88856916 | 1622 | @command{guix graph} can also be helpful (@pxref{Invoking guix graph}). |
6e721c4d LC |
1623 | |
1624 | There are several such multiple-output packages in the GNU distribution. | |
91ef73d4 LC |
1625 | Other conventional output names include @code{lib} for libraries and |
1626 | possibly header files, @code{bin} for stand-alone programs, and | |
1627 | @code{debug} for debugging information (@pxref{Installing Debugging | |
1628 | Files}). The outputs of a packages are listed in the third column of | |
1629 | the output of @command{guix package --list-available} (@pxref{Invoking | |
1630 | guix package}). | |
6e721c4d | 1631 | |
eeaf4427 | 1632 | |
e49951eb MW |
1633 | @node Invoking guix gc |
1634 | @section Invoking @command{guix gc} | |
fe8ff028 LC |
1635 | |
1636 | @cindex garbage collector | |
1637 | Packages that are installed but not used may be @dfn{garbage-collected}. | |
e49951eb | 1638 | The @command{guix gc} command allows users to explicitly run the garbage |
c22eb992 LC |
1639 | collector to reclaim space from the @file{/gnu/store} directory. It is |
1640 | the @emph{only} way to remove files from @file{/gnu/store}---removing | |
1641 | files or directories manually may break it beyond repair! | |
fe8ff028 LC |
1642 | |
1643 | The garbage collector has a set of known @dfn{roots}: any file under | |
834129e0 | 1644 | @file{/gnu/store} reachable from a root is considered @dfn{live} and |
fe8ff028 LC |
1645 | cannot be deleted; any other file is considered @dfn{dead} and may be |
1646 | deleted. The set of garbage collector roots includes default user | |
e49951eb MW |
1647 | profiles, and may be augmented with @command{guix build --root}, for |
1648 | example (@pxref{Invoking guix build}). | |
fe8ff028 | 1649 | |
1bb9900a LC |
1650 | Prior to running @code{guix gc --collect-garbage} to make space, it is |
1651 | often useful to remove old generations from user profiles; that way, old | |
1652 | package builds referenced by those generations can be reclaimed. This | |
1653 | is achieved by running @code{guix package --delete-generations} | |
1654 | (@pxref{Invoking guix package}). | |
1655 | ||
e49951eb | 1656 | The @command{guix gc} command has three modes of operation: it can be |
fe8ff028 | 1657 | used to garbage-collect any dead files (the default), to delete specific |
7770aafc LC |
1658 | files (the @code{--delete} option), to print garbage-collector |
1659 | information, or for more advanced queries. The garbage collection | |
1660 | options are as follows: | |
fe8ff028 LC |
1661 | |
1662 | @table @code | |
1663 | @item --collect-garbage[=@var{min}] | |
1664 | @itemx -C [@var{min}] | |
834129e0 | 1665 | Collect garbage---i.e., unreachable @file{/gnu/store} files and |
fe8ff028 LC |
1666 | sub-directories. This is the default operation when no option is |
1667 | specified. | |
1668 | ||
1669 | When @var{min} is given, stop once @var{min} bytes have been collected. | |
1670 | @var{min} may be a number of bytes, or it may include a unit as a | |
4a44d7bb LC |
1671 | suffix, such as @code{MiB} for mebibytes and @code{GB} for gigabytes |
1672 | (@pxref{Block size, size specifications,, coreutils, GNU Coreutils}). | |
fe8ff028 LC |
1673 | |
1674 | When @var{min} is omitted, collect all the garbage. | |
1675 | ||
1676 | @item --delete | |
1677 | @itemx -d | |
1678 | Attempt to delete all the store files and directories specified as | |
1679 | arguments. This fails if some of the files are not in the store, or if | |
1680 | they are still live. | |
1681 | ||
30d9aa54 LC |
1682 | @item --list-failures |
1683 | List store items corresponding to cached build failures. | |
1684 | ||
1685 | This prints nothing unless the daemon was started with | |
1686 | @option{--cache-failures} (@pxref{Invoking guix-daemon, | |
1687 | @option{--cache-failures}}). | |
1688 | ||
1689 | @item --clear-failures | |
1690 | Remove the specified store items from the failed-build cache. | |
1691 | ||
1692 | Again, this option only makes sense when the daemon is started with | |
1693 | @option{--cache-failures}. Otherwise, it does nothing. | |
1694 | ||
fe8ff028 LC |
1695 | @item --list-dead |
1696 | Show the list of dead files and directories still present in the | |
1697 | store---i.e., files and directories no longer reachable from any root. | |
1698 | ||
1699 | @item --list-live | |
1700 | Show the list of live store files and directories. | |
ba8b732d LC |
1701 | |
1702 | @end table | |
1703 | ||
1704 | In addition, the references among existing store files can be queried: | |
1705 | ||
1706 | @table @code | |
1707 | ||
1708 | @item --references | |
1709 | @itemx --referrers | |
1710 | List the references (respectively, the referrers) of store files given | |
1711 | as arguments. | |
1712 | ||
8e59fdd5 LC |
1713 | @item --requisites |
1714 | @itemx -R | |
fcc58db6 | 1715 | @cindex closure |
8e59fdd5 LC |
1716 | List the requisites of the store files passed as arguments. Requisites |
1717 | include the store files themselves, their references, and the references | |
1718 | of these, recursively. In other words, the returned list is the | |
1719 | @dfn{transitive closure} of the store files. | |
1720 | ||
fcc58db6 | 1721 | @xref{Invoking guix size}, for a tool to profile the size of an |
88856916 LC |
1722 | element's closure. @xref{Invoking guix graph}, for a tool to visualize |
1723 | the graph of references. | |
fcc58db6 | 1724 | |
fe8ff028 LC |
1725 | @end table |
1726 | ||
7770aafc LC |
1727 | Lastly, the following options allow you to check the integrity of the |
1728 | store and to control disk usage. | |
1729 | ||
1730 | @table @option | |
1731 | ||
1732 | @item --verify[=@var{options}] | |
1733 | @cindex integrity, of the store | |
1734 | @cindex integrity checking | |
1735 | Verify the integrity of the store. | |
1736 | ||
1737 | By default, make sure that all the store items marked as valid in the | |
1738 | daemon's database actually exist in @file{/gnu/store}. | |
1739 | ||
1740 | When provided, @var{options} must a comma-separated list containing one | |
1741 | or more of @code{contents} and @code{repair}. | |
1742 | ||
1743 | When passing @option{--verify=contents}, the daemon will compute the | |
1744 | content hash of each store item and compare it against its hash in the | |
1745 | database. Hash mismatches are reported as data corruptions. Because it | |
1746 | traverses @emph{all the files in the store}, this command can take a | |
1747 | long time, especially on systems with a slow disk drive. | |
1748 | ||
1749 | @cindex repairing the store | |
1750 | Using @option{--verify=repair} or @option{--verify=contents,repair} | |
1751 | causes the daemon to try to repair corrupt store items by fetching | |
1752 | substitutes for them (@pxref{Substitutes}). Because repairing is not | |
1753 | atomic, and thus potentially dangerous, it is available only to the | |
1754 | system administrator. | |
1755 | ||
1756 | @item --optimize | |
1757 | @cindex deduplication | |
1758 | Optimize the store by hard-linking identical files---this is | |
1759 | @dfn{deduplication}. | |
1760 | ||
1761 | The daemon performs deduplication after each successful build or archive | |
1762 | import, unless it was started with @code{--disable-deduplication} | |
1763 | (@pxref{Invoking guix-daemon, @code{--disable-deduplication}}). Thus, | |
1764 | this option is primarily useful when the daemon was running with | |
1765 | @code{--disable-deduplication}. | |
1766 | ||
1767 | @end table | |
eeaf4427 | 1768 | |
f651b477 LC |
1769 | @node Invoking guix pull |
1770 | @section Invoking @command{guix pull} | |
1771 | ||
1772 | Packages are installed or upgraded to the latest version available in | |
1773 | the distribution currently available on your local machine. To update | |
1774 | that distribution, along with the Guix tools, you must run @command{guix | |
1775 | pull}: the command downloads the latest Guix source code and package | |
1776 | descriptions, and deploys it. | |
1777 | ||
1778 | On completion, @command{guix package} will use packages and package | |
1779 | versions from this just-retrieved copy of Guix. Not only that, but all | |
1780 | the Guix commands and Scheme modules will also be taken from that latest | |
1781 | version. New @command{guix} sub-commands added by the update also | |
1782 | become available. | |
1783 | ||
1784 | The @command{guix pull} command is usually invoked with no arguments, | |
1785 | but it supports the following options: | |
1786 | ||
1787 | @table @code | |
1788 | @item --verbose | |
1789 | Produce verbose output, writing build logs to the standard error output. | |
1790 | ||
ab5d72ad LC |
1791 | @item --url=@var{url} |
1792 | Download the source tarball of Guix from @var{url}. | |
1793 | ||
1794 | By default, the tarball is taken from its canonical address at | |
1795 | @code{gnu.org}, for the stable branch of Guix. | |
1796 | ||
f651b477 LC |
1797 | @item --bootstrap |
1798 | Use the bootstrap Guile to build the latest Guix. This option is only | |
1799 | useful to Guix developers. | |
1800 | @end table | |
1801 | ||
760c60d6 LC |
1802 | |
1803 | @node Invoking guix archive | |
1804 | @section Invoking @command{guix archive} | |
1805 | ||
1806 | The @command{guix archive} command allows users to @dfn{export} files | |
1807 | from the store into a single archive, and to later @dfn{import} them. | |
1808 | In particular, it allows store files to be transferred from one machine | |
1809 | to another machine's store. For example, to transfer the @code{emacs} | |
1810 | package to a machine connected over SSH, one would run: | |
1811 | ||
1812 | @example | |
56607088 | 1813 | guix archive --export -r emacs | ssh the-machine guix archive --import |
760c60d6 LC |
1814 | @end example |
1815 | ||
87236aed | 1816 | @noindent |
56607088 LC |
1817 | Similarly, a complete user profile may be transferred from one machine |
1818 | to another like this: | |
1819 | ||
1820 | @example | |
1821 | guix archive --export -r $(readlink -f ~/.guix-profile) | \ | |
1822 | ssh the-machine guix-archive --import | |
1823 | @end example | |
1824 | ||
1825 | @noindent | |
1826 | However, note that, in both examples, all of @code{emacs} and the | |
1827 | profile as well as all of their dependencies are transferred (due to | |
1828 | @code{-r}), regardless of what is already available in the target | |
1829 | machine's store. The @code{--missing} option can help figure out which | |
1830 | items are missing from the target's store. | |
87236aed | 1831 | |
760c60d6 | 1832 | Archives are stored in the ``Nix archive'' or ``Nar'' format, which is |
0dbd88db LC |
1833 | comparable in spirit to `tar', but with a few noteworthy differences |
1834 | that make it more appropriate for our purposes. First, rather than | |
1835 | recording all Unix meta-data for each file, the Nar format only mentions | |
1836 | the file type (regular, directory, or symbolic link); Unix permissions | |
1837 | and owner/group are dismissed. Second, the order in which directory | |
1838 | entries are stored always follows the order of file names according to | |
1839 | the C locale collation order. This makes archive production fully | |
1840 | deterministic. | |
1841 | ||
1842 | When exporting, the daemon digitally signs the contents of the archive, | |
1843 | and that digital signature is appended. When importing, the daemon | |
1844 | verifies the signature and rejects the import in case of an invalid | |
1845 | signature or if the signing key is not authorized. | |
760c60d6 LC |
1846 | @c FIXME: Add xref to daemon doc about signatures. |
1847 | ||
1848 | The main options are: | |
1849 | ||
1850 | @table @code | |
1851 | @item --export | |
1852 | Export the specified store files or packages (see below.) Write the | |
1853 | resulting archive to the standard output. | |
1854 | ||
56607088 LC |
1855 | Dependencies are @emph{not} included in the output, unless |
1856 | @code{--recursive} is passed. | |
1857 | ||
1858 | @item -r | |
1859 | @itemx --recursive | |
1860 | When combined with @code{--export}, this instructs @command{guix | |
1861 | archive} to include dependencies of the given items in the archive. | |
1862 | Thus, the resulting archive is self-contained: it contains the closure | |
1863 | of the exported store items. | |
1864 | ||
760c60d6 LC |
1865 | @item --import |
1866 | Read an archive from the standard input, and import the files listed | |
1867 | therein into the store. Abort if the archive has an invalid digital | |
f82cc5fd LC |
1868 | signature, or if it is signed by a public key not among the authorized |
1869 | keys (see @code{--authorize} below.) | |
554f26ec | 1870 | |
87236aed LC |
1871 | @item --missing |
1872 | Read a list of store file names from the standard input, one per line, | |
1873 | and write on the standard output the subset of these files missing from | |
1874 | the store. | |
1875 | ||
554f26ec | 1876 | @item --generate-key[=@var{parameters}] |
f82cc5fd | 1877 | @cindex signing, archives |
554f26ec LC |
1878 | Generate a new key pair for the daemons. This is a prerequisite before |
1879 | archives can be exported with @code{--export}. Note that this operation | |
1880 | usually takes time, because it needs to gather enough entropy to | |
1881 | generate the key pair. | |
1882 | ||
1883 | The generated key pair is typically stored under @file{/etc/guix}, in | |
1884 | @file{signing-key.pub} (public key) and @file{signing-key.sec} (private | |
867d8473 LC |
1885 | key, which must be kept secret.) When @var{parameters} is omitted, |
1886 | an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt | |
1887 | versions before 1.6.0, it is a 4096-bit RSA key. | |
1888 | Alternately, @var{parameters} can specify | |
554f26ec LC |
1889 | @code{genkey} parameters suitable for Libgcrypt (@pxref{General |
1890 | public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The | |
1891 | Libgcrypt Reference Manual}). | |
f82cc5fd LC |
1892 | |
1893 | @item --authorize | |
1894 | @cindex authorizing, archives | |
1895 | Authorize imports signed by the public key passed on standard input. | |
1896 | The public key must be in ``s-expression advanced format''---i.e., the | |
1897 | same format as the @file{signing-key.pub} file. | |
1898 | ||
1899 | The list of authorized keys is kept in the human-editable file | |
1900 | @file{/etc/guix/acl}. The file contains | |
1901 | @url{http://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format | |
1902 | s-expressions''} and is structured as an access-control list in the | |
1903 | @url{http://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure | |
1904 | (SPKI)}. | |
760c60d6 LC |
1905 | @end table |
1906 | ||
1907 | To export store files as an archive to the standard output, run: | |
1908 | ||
1909 | @example | |
1910 | guix archive --export @var{options} @var{specifications}... | |
1911 | @end example | |
1912 | ||
1913 | @var{specifications} may be either store file names or package | |
1914 | specifications, as for @command{guix package} (@pxref{Invoking guix | |
1915 | package}). For instance, the following command creates an archive | |
1916 | containing the @code{gui} output of the @code{git} package and the main | |
1917 | output of @code{emacs}: | |
1918 | ||
1919 | @example | |
834129e0 | 1920 | guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar |
760c60d6 LC |
1921 | @end example |
1922 | ||
1923 | If the specified packages are not built yet, @command{guix archive} | |
1924 | automatically builds them. The build process may be controlled with the | |
1925 | same options that can be passed to the @command{guix build} command | |
70ee5642 | 1926 | (@pxref{Invoking guix build, common build options}). |
760c60d6 | 1927 | |
c554de89 AK |
1928 | @c ********************************************************************* |
1929 | @include emacs.texi | |
760c60d6 | 1930 | |
568717fd LC |
1931 | @c ********************************************************************* |
1932 | @node Programming Interface | |
1933 | @chapter Programming Interface | |
1934 | ||
3dc1970d LC |
1935 | GNU Guix provides several Scheme programming interfaces (APIs) to |
1936 | define, build, and query packages. The first interface allows users to | |
1937 | write high-level package definitions. These definitions refer to | |
1938 | familiar packaging concepts, such as the name and version of a package, | |
1939 | its build system, and its dependencies. These definitions can then be | |
1940 | turned into concrete build actions. | |
1941 | ||
ba55b1cb | 1942 | Build actions are performed by the Guix daemon, on behalf of users. In a |
3dc1970d | 1943 | standard setup, the daemon has write access to the store---the |
834129e0 | 1944 | @file{/gnu/store} directory---whereas users do not. The recommended |
3dc1970d LC |
1945 | setup also has the daemon perform builds in chroots, under a specific |
1946 | build users, to minimize interference with the rest of the system. | |
1947 | ||
1948 | @cindex derivation | |
1949 | Lower-level APIs are available to interact with the daemon and the | |
1950 | store. To instruct the daemon to perform a build action, users actually | |
1951 | provide it with a @dfn{derivation}. A derivation is a low-level | |
1952 | representation of the build actions to be taken, and the environment in | |
1953 | which they should occur---derivations are to package definitions what | |
49ad317a LC |
1954 | assembly is to C programs. The term ``derivation'' comes from the fact |
1955 | that build results @emph{derive} from them. | |
3dc1970d LC |
1956 | |
1957 | This chapter describes all these APIs in turn, starting from high-level | |
1958 | package definitions. | |
1959 | ||
568717fd | 1960 | @menu |
b860f382 | 1961 | * Defining Packages:: Defining new packages. |
7458bd0a | 1962 | * Build Systems:: Specifying how packages are built. |
b860f382 LC |
1963 | * The Store:: Manipulating the package store. |
1964 | * Derivations:: Low-level interface to package derivations. | |
1965 | * The Store Monad:: Purely functional interface to the store. | |
21b679f6 | 1966 | * G-Expressions:: Manipulating build expressions. |
568717fd LC |
1967 | @end menu |
1968 | ||
1969 | @node Defining Packages | |
1970 | @section Defining Packages | |
1971 | ||
3dc1970d LC |
1972 | The high-level interface to package definitions is implemented in the |
1973 | @code{(guix packages)} and @code{(guix build-system)} modules. As an | |
1974 | example, the package definition, or @dfn{recipe}, for the GNU Hello | |
1975 | package looks like this: | |
1976 | ||
1977 | @example | |
e7f34eb0 LC |
1978 | (define-module (gnu packages hello) |
1979 | #:use-module (guix packages) | |
1980 | #:use-module (guix download) | |
1981 | #:use-module (guix build-system gnu) | |
a6dcdcac SB |
1982 | #:use-module (guix licenses) |
1983 | #:use-module (gnu packages gawk)) | |
b22a12fd | 1984 | |
79f5dd59 | 1985 | (define-public hello |
3dc1970d LC |
1986 | (package |
1987 | (name "hello") | |
17d8e33f | 1988 | (version "2.10") |
3dc1970d | 1989 | (source (origin |
17d8e33f ML |
1990 | (method url-fetch) |
1991 | (uri (string-append "mirror://gnu/hello/hello-" version | |
1992 | ".tar.gz")) | |
1993 | (sha256 | |
1994 | (base32 | |
1995 | "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i")))) | |
3dc1970d | 1996 | (build-system gnu-build-system) |
7458bd0a | 1997 | (arguments `(#:configure-flags '("--enable-silent-rules"))) |
3dc1970d | 1998 | (inputs `(("gawk" ,gawk))) |
7458bd0a LC |
1999 | (synopsis "Hello, GNU world: An example GNU package") |
2000 | (description "Guess what GNU Hello prints!") | |
3dc1970d | 2001 | (home-page "http://www.gnu.org/software/hello/") |
b22a12fd | 2002 | (license gpl3+))) |
3dc1970d LC |
2003 | @end example |
2004 | ||
2005 | @noindent | |
2006 | Without being a Scheme expert, the reader may have guessed the meaning | |
e7f34eb0 | 2007 | of the various fields here. This expression binds variable @code{hello} |
3dc1970d LC |
2008 | to a @code{<package>} object, which is essentially a record |
2009 | (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}). | |
2010 | This package object can be inspected using procedures found in the | |
2011 | @code{(guix packages)} module; for instance, @code{(package-name hello)} | |
2012 | returns---surprise!---@code{"hello"}. | |
2013 | ||
2f7d2d91 LC |
2014 | With luck, you may be able to import part or all of the definition of |
2015 | the package you are interested in from another repository, using the | |
2016 | @code{guix import} command (@pxref{Invoking guix import}). | |
2017 | ||
e7f34eb0 LC |
2018 | In the example above, @var{hello} is defined into a module of its own, |
2019 | @code{(gnu packages hello)}. Technically, this is not strictly | |
2020 | necessary, but it is convenient to do so: all the packages defined in | |
2021 | modules under @code{(gnu packages @dots{})} are automatically known to | |
2022 | the command-line tools (@pxref{Package Modules}). | |
2023 | ||
3dc1970d LC |
2024 | There are a few points worth noting in the above package definition: |
2025 | ||
2026 | @itemize | |
2027 | @item | |
a2bf4907 LC |
2028 | The @code{source} field of the package is an @code{<origin>} object |
2029 | (@pxref{origin Reference}, for the complete reference). | |
3dc1970d LC |
2030 | Here, the @code{url-fetch} method from @code{(guix download)} is used, |
2031 | meaning that the source is a file to be downloaded over FTP or HTTP. | |
2032 | ||
2033 | The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of | |
2034 | the GNU mirrors defined in @code{(guix download)}. | |
2035 | ||
2036 | The @code{sha256} field specifies the expected SHA256 hash of the file | |
2037 | being downloaded. It is mandatory, and allows Guix to check the | |
2038 | integrity of the file. The @code{(base32 @dots{})} form introduces the | |
6c365eca | 2039 | base32 representation of the hash. You can obtain this information with |
210cc920 LC |
2040 | @code{guix download} (@pxref{Invoking guix download}) and @code{guix |
2041 | hash} (@pxref{Invoking guix hash}). | |
3dc1970d | 2042 | |
f9cc8971 LC |
2043 | @cindex patches |
2044 | When needed, the @code{origin} form can also have a @code{patches} field | |
2045 | listing patches to be applied, and a @code{snippet} field giving a | |
2046 | Scheme expression to modify the source code. | |
2047 | ||
3dc1970d LC |
2048 | @item |
2049 | @cindex GNU Build System | |
7458bd0a LC |
2050 | The @code{build-system} field specifies the procedure to build the |
2051 | package (@pxref{Build Systems}). Here, @var{gnu-build-system} | |
2052 | represents the familiar GNU Build System, where packages may be | |
2053 | configured, built, and installed with the usual @code{./configure && | |
2054 | make && make check && make install} command sequence. | |
2055 | ||
2056 | @item | |
2057 | The @code{arguments} field specifies options for the build system | |
2058 | (@pxref{Build Systems}). Here it is interpreted by | |
2059 | @var{gnu-build-system} as a request run @file{configure} with the | |
2060 | @code{--enable-silent-rules} flag. | |
3dc1970d LC |
2061 | |
2062 | @item | |
2063 | The @code{inputs} field specifies inputs to the build process---i.e., | |
2064 | build-time or run-time dependencies of the package. Here, we define an | |
2065 | input called @code{"gawk"} whose value is that of the @var{gawk} | |
2066 | variable; @var{gawk} is itself bound to a @code{<package>} object. | |
2067 | ||
2068 | Note that GCC, Coreutils, Bash, and other essential tools do not need to | |
2069 | be specified as inputs here. Instead, @var{gnu-build-system} takes care | |
7458bd0a | 2070 | of ensuring that they are present (@pxref{Build Systems}). |
3dc1970d LC |
2071 | |
2072 | However, any other dependencies need to be specified in the | |
2073 | @code{inputs} field. Any dependency not specified here will simply be | |
2074 | unavailable to the build process, possibly leading to a build failure. | |
2075 | @end itemize | |
2076 | ||
87eafdbd TUBK |
2077 | @xref{package Reference}, for a full description of possible fields. |
2078 | ||
2f7d2d91 | 2079 | Once a package definition is in place, the |
e49951eb | 2080 | package may actually be built using the @code{guix build} command-line |
39bee8a2 LC |
2081 | tool (@pxref{Invoking guix build}). You can easily jump back to the |
2082 | package definition using the @command{guix edit} command | |
2083 | (@pxref{Invoking guix edit}). | |
2084 | @xref{Packaging Guidelines}, for | |
b4f5e0e8 CR |
2085 | more information on how to test package definitions, and |
2086 | @ref{Invoking guix lint}, for information on how to check a definition | |
2087 | for style conformance. | |
2088 | ||
7458bd0a LC |
2089 | Eventually, updating the package definition to a new upstream version |
2090 | can be partly automated by the @command{guix refresh} command | |
2091 | (@pxref{Invoking guix refresh}). | |
3dc1970d LC |
2092 | |
2093 | Behind the scenes, a derivation corresponding to the @code{<package>} | |
2094 | object is first computed by the @code{package-derivation} procedure. | |
834129e0 | 2095 | That derivation is stored in a @code{.drv} file under @file{/gnu/store}. |
ba55b1cb | 2096 | The build actions it prescribes may then be realized by using the |
3dc1970d LC |
2097 | @code{build-derivations} procedure (@pxref{The Store}). |
2098 | ||
2099 | @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}] | |
59688fc4 LC |
2100 | Return the @code{<derivation>} object of @var{package} for @var{system} |
2101 | (@pxref{Derivations}). | |
3dc1970d LC |
2102 | |
2103 | @var{package} must be a valid @code{<package>} object, and @var{system} | |
2104 | must be a string denoting the target system type---e.g., | |
2105 | @code{"x86_64-linux"} for an x86_64 Linux-based GNU system. @var{store} | |
2106 | must be a connection to the daemon, which operates on the store | |
2107 | (@pxref{The Store}). | |
2108 | @end deffn | |
568717fd | 2109 | |
9c1edabd LC |
2110 | @noindent |
2111 | @cindex cross-compilation | |
2112 | Similarly, it is possible to compute a derivation that cross-builds a | |
2113 | package for some other system: | |
2114 | ||
2115 | @deffn {Scheme Procedure} package-cross-derivation @var{store} @ | |
2116 | @var{package} @var{target} [@var{system}] | |
59688fc4 LC |
2117 | Return the @code{<derivation>} object of @var{package} cross-built from |
2118 | @var{system} to @var{target}. | |
9c1edabd LC |
2119 | |
2120 | @var{target} must be a valid GNU triplet denoting the target hardware | |
2121 | and operating system, such as @code{"mips64el-linux-gnu"} | |
2122 | (@pxref{Configuration Names, GNU configuration triplets,, configure, GNU | |
2123 | Configure and Build System}). | |
2124 | @end deffn | |
2125 | ||
87eafdbd TUBK |
2126 | @menu |
2127 | * package Reference :: The package data type. | |
2128 | * origin Reference:: The origin data type. | |
2129 | @end menu | |
2130 | ||
2131 | ||
2132 | @node package Reference | |
2133 | @subsection @code{package} Reference | |
2134 | ||
2135 | This section summarizes all the options available in @code{package} | |
2136 | declarations (@pxref{Defining Packages}). | |
2137 | ||
2138 | @deftp {Data Type} package | |
2139 | This is the data type representing a package recipe. | |
2140 | ||
2141 | @table @asis | |
2142 | @item @code{name} | |
2143 | The name of the package, as a string. | |
2144 | ||
2145 | @item @code{version} | |
2146 | The version of the package, as a string. | |
2147 | ||
2148 | @item @code{source} | |
2149 | An origin object telling how the source code for the package should be | |
2150 | acquired (@pxref{origin Reference}). | |
2151 | ||
2152 | @item @code{build-system} | |
2153 | The build system that should be used to build the package (@pxref{Build | |
2154 | Systems}). | |
2155 | ||
2156 | @item @code{arguments} (default: @code{'()}) | |
2157 | The arguments that should be passed to the build system. This is a | |
2158 | list, typically containing sequential keyword-value pairs. | |
2159 | ||
2160 | @item @code{inputs} (default: @code{'()}) | |
2161 | Package or derivation inputs to the build. This is a list of lists, | |
2162 | where each list has the name of the input (a string) as its first | |
2163 | element, a package or derivation object as its second element, and | |
2164 | optionally the name of the output of the package or derivation that | |
2165 | should be used, which defaults to @code{"out"}. | |
2166 | ||
21461f27 LC |
2167 | @item @anchor{package-propagated-inputs}@code{propagated-inputs} (default: @code{'()}) |
2168 | @cindex propagated inputs | |
87eafdbd | 2169 | This field is like @code{inputs}, but the specified packages will be |
21461f27 LC |
2170 | force-installed alongside the package they belong to |
2171 | (@pxref{package-cmd-propagated-inputs, @command{guix package}}, for | |
2172 | information on how @command{guix package} deals with propagated inputs.) | |
2173 | ||
2174 | For example this is necessary when a library needs headers of another | |
2175 | library to compile, or needs another shared library to be linked | |
2176 | alongside itself when a program wants to link to it. | |
87eafdbd TUBK |
2177 | |
2178 | @item @code{native-inputs} (default: @code{'()}) | |
2179 | This field is like @code{inputs}, but in case of a cross-compilation it | |
2180 | will be ensured that packages for the architecture of the build machine | |
2181 | are present, such that executables from them can be used during the | |
21461f27 LC |
2182 | build. |
2183 | ||
2184 | This is typically where you would list tools needed at build time but | |
2185 | not at run time, such as Autoconf, Automake, pkg-config, Gettext, or | |
2186 | Bison. @command{guix lint} can report likely mistakes in this area | |
2187 | (@pxref{Invoking guix lint}). | |
87eafdbd TUBK |
2188 | |
2189 | @item @code{self-native-input?} (default: @code{#f}) | |
2190 | This is a Boolean field telling whether the package should use itself as | |
2191 | a native input when cross-compiling. | |
2192 | ||
2193 | @item @code{outputs} (default: @code{'("out")}) | |
2194 | The list of output names of the package. @xref{Packages with Multiple | |
2195 | Outputs}, for typical uses of additional outputs. | |
2196 | ||
2197 | @item @code{native-search-paths} (default: @code{'()}) | |
2198 | @itemx @code{search-paths} (default: @code{'()}) | |
2199 | A list of @code{search-path-specification} objects describing | |
2200 | search-path environment variables honored by the package. | |
2201 | ||
2202 | @item @code{replacement} (default: @code{#f}) | |
2203 | This must either @code{#f} or a package object that will be used as a | |
2204 | @dfn{replacement} for this package. @xref{Security Updates, grafts}, | |
2205 | for details. | |
2206 | ||
2207 | @item @code{synopsis} | |
2208 | A one-line description of the package. | |
2209 | ||
2210 | @item @code{description} | |
2211 | A more elaborate description of the package. | |
2212 | ||
2213 | @item @code{license} | |
2214 | The license of the package; a value from @code{(guix licenses)}. | |
2215 | ||
2216 | @item @code{home-page} | |
2217 | The URL to the home-page of the package, as a string. | |
2218 | ||
2219 | @item @code{supported-systems} (default: @var{%supported-systems}) | |
2220 | The list of systems supported by the package, as strings of the form | |
2221 | @code{architecture-kernel}, for example @code{"x86_64-linux"}. | |
2222 | ||
2223 | @item @code{maintainers} (default: @code{'()}) | |
2224 | The list of maintainers of the package, as @code{maintainer} objects. | |
2225 | ||
2226 | @item @code{location} (default: source location of the @code{package} form) | |
2227 | The source location of the package. It's useful to override this when | |
2228 | inheriting from another package, in which case this field is not | |
2229 | automatically corrected. | |
2230 | @end table | |
2231 | @end deftp | |
2232 | ||
2233 | ||
2234 | @node origin Reference | |
2235 | @subsection @code{origin} Reference | |
2236 | ||
2237 | This section summarizes all the options available in @code{origin} | |
2238 | declarations (@pxref{Defining Packages}). | |
2239 | ||
2240 | @deftp {Data Type} origin | |
2241 | This is the data type representing a source code origin. | |
2242 | ||
2243 | @table @asis | |
2244 | @item @code{uri} | |
2245 | An object containing the URI of the source. The object type depends on | |
2246 | the @code{method} (see below). For example, when using the | |
2247 | @var{url-fetch} method of @code{(guix download)}, the valid @code{uri} | |
2248 | values are: a URL represented as a string, or a list thereof. | |
2249 | ||
2250 | @item @code{method} | |
2251 | A procedure that will handle the URI. | |
2252 | ||
2253 | Examples include: | |
2254 | ||
2255 | @table @asis | |
2256 | @item @var{url-fetch} from @code{(guix download)} | |
2257 | download a file the HTTP, HTTPS, or FTP URL specified in the | |
2258 | @code{uri} field; | |
2259 | ||
2260 | @item @var{git-fetch} from @code{(guix git-download)} | |
2261 | clone the Git version control repository, and check out the revision | |
2262 | specified in the @code{uri} field as a @code{git-reference} object; a | |
2263 | @code{git-reference} looks like this: | |
2264 | ||
2265 | @example | |
2266 | (git-reference | |
2267 | (url "git://git.debian.org/git/pkg-shadow/shadow") | |
2268 | (commit "v4.1.5.1")) | |
2269 | @end example | |
2270 | @end table | |
2271 | ||
2272 | @item @code{sha256} | |
2273 | A bytevector containing the SHA-256 hash of the source. Typically the | |
2274 | @code{base32} form is used here to generate the bytevector from a | |
2275 | base-32 string. | |
2276 | ||
2277 | @item @code{file-name} (default: @code{#f}) | |
2278 | The file name under which the source code should be saved. When this is | |
2279 | @code{#f}, a sensible default value will be used in most cases. In case | |
2280 | the source is fetched from a URL, the file name from the URL will be | |
2281 | used. For version control checkouts, it's recommended to provide the | |
2282 | file name explicitly because the default is not very descriptive. | |
2283 | ||
2284 | @item @code{patches} (default: @code{'()}) | |
2285 | A list of file names containing patches to be applied to the source. | |
2286 | ||
2287 | @item @code{snippet} (default: @code{#f}) | |
2288 | A quoted piece of code that will be run in the source directory to make | |
2289 | any modifications, which is sometimes more convenient than a patch. | |
2290 | ||
2291 | @item @code{patch-flags} (default: @code{'("-p1")}) | |
2292 | A list of command-line flags that should be passed to the @code{patch} | |
2293 | command. | |
2294 | ||
2295 | @item @code{patch-inputs} (default: @code{#f}) | |
2296 | Input packages or derivations to the patching process. When this is | |
2297 | @code{#f}, the usual set of inputs necessary for patching are provided, | |
2298 | such as GNU@tie{}Patch. | |
2299 | ||
2300 | @item @code{modules} (default: @code{'()}) | |
2301 | A list of Guile modules that should be loaded during the patching | |
2302 | process and while running the code in the @code{snippet} field. | |
2303 | ||
2304 | @item @code{imported-modules} (default: @code{'()}) | |
2305 | The list of Guile modules to import in the patch derivation, for use by | |
2306 | the @code{snippet}. | |
2307 | ||
2308 | @item @code{patch-guile} (default: @code{#f}) | |
2309 | The Guile package that should be used in the patching process. When | |
2310 | this is @code{#f}, a sensible default is used. | |
2311 | @end table | |
2312 | @end deftp | |
2313 | ||
9c1edabd | 2314 | |
7458bd0a LC |
2315 | @node Build Systems |
2316 | @section Build Systems | |
2317 | ||
2318 | @cindex build system | |
2319 | Each package definition specifies a @dfn{build system} and arguments for | |
2320 | that build system (@pxref{Defining Packages}). This @code{build-system} | |
2321 | field represents the build procedure of the package, as well implicit | |
2322 | dependencies of that build procedure. | |
2323 | ||
2324 | Build systems are @code{<build-system>} objects. The interface to | |
2325 | create and manipulate them is provided by the @code{(guix build-system)} | |
2326 | module, and actual build systems are exported by specific modules. | |
2327 | ||
f5fd4fd2 | 2328 | @cindex bag (low-level package representation) |
0d5a559f LC |
2329 | Under the hood, build systems first compile package objects to |
2330 | @dfn{bags}. A @dfn{bag} is like a package, but with less | |
2331 | ornamentation---in other words, a bag is a lower-level representation of | |
2332 | a package, which includes all the inputs of that package, including some | |
2333 | that were implicitly added by the build system. This intermediate | |
2334 | representation is then compiled to a derivation (@pxref{Derivations}). | |
2335 | ||
7458bd0a LC |
2336 | Build systems accept an optional list of @dfn{arguments}. In package |
2337 | definitions, these are passed @i{via} the @code{arguments} field | |
2338 | (@pxref{Defining Packages}). They are typically keyword arguments | |
2339 | (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU | |
2340 | Guile Reference Manual}). The value of these arguments is usually | |
2341 | evaluated in the @dfn{build stratum}---i.e., by a Guile process launched | |
2342 | by the daemon (@pxref{Derivations}). | |
2343 | ||
2344 | The main build system is @var{gnu-build-system}, which implements the | |
2345 | standard build procedure for GNU packages and many other packages. It | |
2346 | is provided by the @code{(guix build-system gnu)} module. | |
2347 | ||
2348 | @defvr {Scheme Variable} gnu-build-system | |
2349 | @var{gnu-build-system} represents the GNU Build System, and variants | |
2350 | thereof (@pxref{Configuration, configuration and makefile conventions,, | |
2351 | standards, GNU Coding Standards}). | |
2352 | ||
2353 | @cindex build phases | |
2354 | In a nutshell, packages using it configured, built, and installed with | |
2355 | the usual @code{./configure && make && make check && make install} | |
2356 | command sequence. In practice, a few additional steps are often needed. | |
2357 | All these steps are split up in separate @dfn{phases}, | |
2358 | notably@footnote{Please see the @code{(guix build gnu-build-system)} | |
2359 | modules for more details about the build phases.}: | |
2360 | ||
2361 | @table @code | |
2362 | @item unpack | |
2363 | Unpack the source tarball, and change the current directory to the | |
2364 | extracted source tree. If the source is actually a directory, copy it | |
2365 | to the build tree, and enter that directory. | |
2366 | ||
2367 | @item patch-source-shebangs | |
2368 | Patch shebangs encountered in source files so they refer to the right | |
2369 | store file names. For instance, this changes @code{#!/bin/sh} to | |
2370 | @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}. | |
2371 | ||
2372 | @item configure | |
2373 | Run the @file{configure} script with a number of default options, such | |
2374 | as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified | |
2375 | by the @code{#:configure-flags} argument. | |
2376 | ||
2377 | @item build | |
2378 | Run @code{make} with the list of flags specified with | |
2379 | @code{#:make-flags}. If the @code{#:parallel-builds?} argument is true | |
2380 | (the default), build with @code{make -j}. | |
2381 | ||
2382 | @item check | |
2383 | Run @code{make check}, or some other target specified with | |
2384 | @code{#:test-target}, unless @code{#:tests? #f} is passed. If the | |
2385 | @code{#:parallel-tests?} argument is true (the default), run @code{make | |
2386 | check -j}. | |
2387 | ||
2388 | @item install | |
2389 | Run @code{make install} with the flags listed in @code{#:make-flags}. | |
2390 | ||
2391 | @item patch-shebangs | |
2392 | Patch shebangs on the installed executable files. | |
2393 | ||
2394 | @item strip | |
2395 | Strip debugging symbols from ELF files (unless @code{#:strip-binaries?} | |
2396 | is false), copying them to the @code{debug} output when available | |
2397 | (@pxref{Installing Debugging Files}). | |
2398 | @end table | |
2399 | ||
2400 | @vindex %standard-phases | |
2401 | The build-side module @code{(guix build gnu-build-system)} defines | |
2402 | @var{%standard-phases} as the default list of build phases. | |
2403 | @var{%standard-phases} is a list of symbol/procedure pairs, where the | |
2404 | procedure implements the actual phase. | |
2405 | ||
2406 | The list of phases used for a particular package can be changed with the | |
2407 | @code{#:phases} parameter. For instance, passing: | |
2408 | ||
2409 | @example | |
2410 | #:phases (alist-delete 'configure %standard-phases) | |
2411 | @end example | |
2412 | ||
9bf404e9 | 2413 | means that all the phases described above will be used, except the |
7458bd0a LC |
2414 | @code{configure} phase. |
2415 | ||
2416 | In addition, this build system ensures that the ``standard'' environment | |
2417 | for GNU packages is available. This includes tools such as GCC, libc, | |
2418 | Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix | |
2419 | build-system gnu)} module for a complete list.) We call these the | |
2420 | @dfn{implicit inputs} of a package, because package definitions don't | |
2421 | have to mention them. | |
2422 | @end defvr | |
2423 | ||
2424 | Other @code{<build-system>} objects are defined to support other | |
2425 | conventions and tools used by free software packages. They inherit most | |
2426 | of @var{gnu-build-system}, and differ mainly in the set of inputs | |
2427 | implicitly added to the build process, and in the list of phases | |
2428 | executed. Some of these build systems are listed below. | |
2429 | ||
2430 | @defvr {Scheme Variable} cmake-build-system | |
2431 | This variable is exported by @code{(guix build-system cmake)}. It | |
2432 | implements the build procedure for packages using the | |
2433 | @url{http://www.cmake.org, CMake build tool}. | |
2434 | ||
2435 | It automatically adds the @code{cmake} package to the set of inputs. | |
2436 | Which package is used can be specified with the @code{#:cmake} | |
2437 | parameter. | |
9849cfc1 LC |
2438 | |
2439 | The @code{#:configure-flags} parameter is taken as a list of flags | |
2440 | passed to the @command{cmake} command. The @code{#:build-type} | |
2441 | parameter specifies in abstract terms the flags passed to the compiler; | |
2442 | it defaults to @code{"RelWithDebInfo"} (short for ``release mode with | |
2443 | debugging information''), which roughly means that code is compiled with | |
2444 | @code{-O2 -g}, as is the case for Autoconf-based packages by default. | |
7458bd0a LC |
2445 | @end defvr |
2446 | ||
3afcf52b FB |
2447 | @defvr {Scheme Variable} glib-or-gtk-build-system |
2448 | This variable is exported by @code{(guix build-system glib-or-gtk)}. It | |
2449 | is intended for use with packages making use of GLib or GTK+. | |
2450 | ||
2451 | This build system adds the following two phases to the ones defined by | |
2452 | @var{gnu-build-system}: | |
2453 | ||
2454 | @table @code | |
2455 | @item glib-or-gtk-wrap | |
2456 | The phase @code{glib-or-gtk-wrap} ensures that programs found under | |
2457 | @file{bin/} are able to find GLib's ``schemas'' and | |
2458 | @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+ | |
2459 | modules}. This is achieved by wrapping the programs in launch scripts | |
2460 | that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH} | |
2461 | environment variables. | |
2462 | ||
73aa8ddb LC |
2463 | It is possible to exclude specific package outputs from that wrapping |
2464 | process by listing their names in the | |
2465 | @code{#:glib-or-gtk-wrap-excluded-outputs} parameter. This is useful | |
2466 | when an output is known not to contain any GLib or GTK+ binaries, and | |
2467 | where wrapping would gratuitously add a dependency of that output on | |
2468 | GLib and GTK+. | |
2469 | ||
3afcf52b FB |
2470 | @item glib-or-gtk-compile-schemas |
2471 | The phase @code{glib-or-gtk-compile-schemas} makes sure that all GLib's | |
2472 | @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html, | |
2473 | GSettings schemas} are compiled. Compilation is performed by the | |
2474 | @command{glib-compile-schemas} program. It is provided by the package | |
2475 | @code{glib:bin} which is automatically imported by the build system. | |
2476 | The @code{glib} package providing @command{glib-compile-schemas} can be | |
2477 | specified with the @code{#:glib} parameter. | |
2478 | @end table | |
2479 | ||
2480 | Both phases are executed after the @code{install} phase. | |
2481 | @end defvr | |
2482 | ||
7458bd0a LC |
2483 | @defvr {Scheme Variable} python-build-system |
2484 | This variable is exported by @code{(guix build-system python)}. It | |
2485 | implements the more or less standard build procedure used by Python | |
2486 | packages, which consists in running @code{python setup.py build} and | |
2487 | then @code{python setup.py install --prefix=/gnu/store/@dots{}}. | |
2488 | ||
2489 | For packages that install stand-alone Python programs under @code{bin/}, | |
2490 | it takes care of wrapping these programs so their @code{PYTHONPATH} | |
2491 | environment variable points to all the Python libraries they depend on. | |
2492 | ||
2493 | Which Python package is used can be specified with the @code{#:python} | |
2494 | parameter. | |
2495 | @end defvr | |
2496 | ||
2497 | @defvr {Scheme Variable} perl-build-system | |
2498 | This variable is exported by @code{(guix build-system perl)}. It | |
2d2a53fc EB |
2499 | implements the standard build procedure for Perl packages, which either |
2500 | consists in running @code{perl Build.PL --prefix=/gnu/store/@dots{}}, | |
2501 | followed by @code{Build} and @code{Build install}; or in running | |
2502 | @code{perl Makefile.PL PREFIX=/gnu/store/@dots{}}, followed by | |
2503 | @code{make} and @code{make install}; depending on which of | |
2504 | @code{Build.PL} or @code{Makefile.PL} is present in the package | |
2505 | distribution. Preference is given to the former if both @code{Build.PL} | |
2506 | and @code{Makefile.PL} exist in the package distribution. This | |
2507 | preference can be reversed by specifying @code{#t} for the | |
2508 | @code{#:make-maker?} parameter. | |
2509 | ||
2510 | The initial @code{perl Makefile.PL} or @code{perl Build.PL} invocation | |
2511 | passes flags specified by the @code{#:make-maker-flags} or | |
2512 | @code{#:module-build-flags} parameter, respectively. | |
7458bd0a LC |
2513 | |
2514 | Which Perl package is used can be specified with @code{#:perl}. | |
2515 | @end defvr | |
2516 | ||
f8f3bef6 RW |
2517 | @defvr {Scheme Variable} r-build-system |
2518 | This variable is exported by @code{(guix build-system r)}. It | |
2519 | implements the build procedure used by @uref{http://r-project.org, R} | |
2520 | packages, which essentially is little more than running @code{R CMD | |
2521 | INSTALL --library=/gnu/store/@dots{}} in an environment where | |
2522 | @code{R_LIBS_SITE} contains the paths to all R package inputs. Tests | |
2523 | are run after installation using the R function | |
2524 | @code{tools::testInstalledPackage}. | |
2525 | @end defvr | |
2526 | ||
c08f9818 DT |
2527 | @defvr {Scheme Variable} ruby-build-system |
2528 | This variable is exported by @code{(guix build-system ruby)}. It | |
2529 | implements the RubyGems build procedure used by Ruby packages, which | |
2530 | involves running @code{gem build} followed by @code{gem install}. | |
2531 | ||
5dc87623 DT |
2532 | The @code{source} field of a package that uses this build system |
2533 | typically references a gem archive, since this is the format that Ruby | |
2534 | developers use when releasing their software. The build system unpacks | |
2535 | the gem archive, potentially patches the source, runs the test suite, | |
2536 | repackages the gem, and installs it. Additionally, directories and | |
2537 | tarballs may be referenced to allow building unreleased gems from Git or | |
2538 | a traditional source release tarball. | |
e83c6d00 | 2539 | |
c08f9818 | 2540 | Which Ruby package is used can be specified with the @code{#:ruby} |
6e9f2913 PP |
2541 | parameter. A list of additional flags to be passed to the @command{gem} |
2542 | command can be specified with the @code{#:gem-flags} parameter. | |
c08f9818 | 2543 | @end defvr |
7458bd0a | 2544 | |
a677c726 RW |
2545 | @defvr {Scheme Variable} waf-build-system |
2546 | This variable is exported by @code{(guix build-system waf)}. It | |
2547 | implements a build procedure around the @code{waf} script. The common | |
2548 | phases---@code{configure}, @code{build}, and @code{install}---are | |
2549 | implemented by passing their names as arguments to the @code{waf} | |
2550 | script. | |
2551 | ||
2552 | The @code{waf} script is executed by the Python interpreter. Which | |
2553 | Python package is used to run the script can be specified with the | |
2554 | @code{#:python} parameter. | |
2555 | @end defvr | |
2556 | ||
14dfdf2e FB |
2557 | @defvr {Scheme Variable} haskell-build-system |
2558 | This variable is exported by @code{(guix build-system haskell)}. It | |
2559 | implements the Cabal build procedure used by Haskell packages, which | |
2560 | involves running @code{runhaskell Setup.hs configure | |
2561 | --prefix=/gnu/store/@dots{}} and @code{runhaskell Setup.hs build}. | |
2562 | Instead of installing the package by running @code{runhaskell Setup.hs | |
2563 | install}, to avoid trying to register libraries in the read-only | |
2564 | compiler store directory, the build system uses @code{runhaskell | |
2565 | Setup.hs copy}, followed by @code{runhaskell Setup.hs register}. In | |
2566 | addition, the build system generates the package documentation by | |
2567 | running @code{runhaskell Setup.hs haddock}, unless @code{#:haddock? #f} | |
2568 | is passed. Optional Haddock parameters can be passed with the help of | |
2569 | the @code{#:haddock-flags} parameter. If the file @code{Setup.hs} is | |
2570 | not found, the build system looks for @code{Setup.lhs} instead. | |
2571 | ||
2572 | Which Haskell compiler is used can be specified with the @code{#:haskell} | |
a54bd6d7 | 2573 | parameter which defaults to @code{ghc}. |
14dfdf2e FB |
2574 | @end defvr |
2575 | ||
e9137a53 FB |
2576 | @defvr {Scheme Variable} emacs-build-system |
2577 | This variable is exported by @code{(guix build-system emacs)}. It | |
2578 | implements an installation procedure similar to the one of Emacs' own | |
2579 | packaging system (@pxref{Packages,,, emacs, The GNU Emacs Manual}). | |
2580 | ||
2581 | It first creates the @code{@var{package}-autoloads.el} file, then it | |
2582 | byte compiles all Emacs Lisp files. Differently from the Emacs | |
2583 | packaging system, the Info documentation files are moved to the standard | |
2584 | documentation directory and the @file{dir} file is deleted. Each | |
2585 | package is installed in its own directory under | |
2586 | @file{share/emacs/site-lisp/guix.d}. | |
2587 | @end defvr | |
2588 | ||
7458bd0a LC |
2589 | Lastly, for packages that do not need anything as sophisticated, a |
2590 | ``trivial'' build system is provided. It is trivial in the sense that | |
2591 | it provides basically no support: it does not pull any implicit inputs, | |
2592 | and does not have a notion of build phases. | |
2593 | ||
2594 | @defvr {Scheme Variable} trivial-build-system | |
2595 | This variable is exported by @code{(guix build-system trivial)}. | |
2596 | ||
2597 | This build system requires a @code{#:builder} argument. This argument | |
2598 | must be a Scheme expression that builds the package's output(s)---as | |
2599 | with @code{build-expression->derivation} (@pxref{Derivations, | |
2600 | @code{build-expression->derivation}}). | |
2601 | @end defvr | |
2602 | ||
568717fd LC |
2603 | @node The Store |
2604 | @section The Store | |
2605 | ||
e531ac2a LC |
2606 | @cindex store |
2607 | @cindex store paths | |
2608 | ||
2609 | Conceptually, the @dfn{store} is where derivations that have been | |
834129e0 | 2610 | successfully built are stored---by default, under @file{/gnu/store}. |
e531ac2a | 2611 | Sub-directories in the store are referred to as @dfn{store paths}. The |
4988dd40 | 2612 | store has an associated database that contains information such as the |
e531ac2a LC |
2613 | store paths referred to by each store path, and the list of @emph{valid} |
2614 | store paths---paths that result from a successful build. | |
2615 | ||
2616 | The store is always accessed by the daemon on behalf of its clients | |
2617 | (@pxref{Invoking guix-daemon}). To manipulate the store, clients | |
2618 | connect to the daemon over a Unix-domain socket, send it requests, and | |
2619 | read the result---these are remote procedure calls, or RPCs. | |
2620 | ||
2621 | The @code{(guix store)} module provides procedures to connect to the | |
2622 | daemon, and to perform RPCs. These are described below. | |
2623 | ||
2624 | @deffn {Scheme Procedure} open-connection [@var{file}] [#:reserve-space? #t] | |
2625 | Connect to the daemon over the Unix-domain socket at @var{file}. When | |
2626 | @var{reserve-space?} is true, instruct it to reserve a little bit of | |
2627 | extra space on the file system so that the garbage collector can still | |
2628 | operate, should the disk become full. Return a server object. | |
2629 | ||
2630 | @var{file} defaults to @var{%default-socket-path}, which is the normal | |
2631 | location given the options that were passed to @command{configure}. | |
2632 | @end deffn | |
2633 | ||
2634 | @deffn {Scheme Procedure} close-connection @var{server} | |
2635 | Close the connection to @var{server}. | |
2636 | @end deffn | |
2637 | ||
2638 | @defvr {Scheme Variable} current-build-output-port | |
2639 | This variable is bound to a SRFI-39 parameter, which refers to the port | |
2640 | where build and error logs sent by the daemon should be written. | |
2641 | @end defvr | |
2642 | ||
2643 | Procedures that make RPCs all take a server object as their first | |
2644 | argument. | |
2645 | ||
2646 | @deffn {Scheme Procedure} valid-path? @var{server} @var{path} | |
2647 | Return @code{#t} when @var{path} is a valid store path. | |
2648 | @end deffn | |
2649 | ||
cfbf9160 | 2650 | @deffn {Scheme Procedure} add-text-to-store @var{server} @var{name} @var{text} [@var{references}] |
e531ac2a LC |
2651 | Add @var{text} under file @var{name} in the store, and return its store |
2652 | path. @var{references} is the list of store paths referred to by the | |
2653 | resulting store path. | |
2654 | @end deffn | |
2655 | ||
874e6874 | 2656 | @deffn {Scheme Procedure} build-derivations @var{server} @var{derivations} |
59688fc4 LC |
2657 | Build @var{derivations} (a list of @code{<derivation>} objects or |
2658 | derivation paths), and return when the worker is done building them. | |
2659 | Return @code{#t} on success. | |
874e6874 LC |
2660 | @end deffn |
2661 | ||
b860f382 LC |
2662 | Note that the @code{(guix monads)} module provides a monad as well as |
2663 | monadic versions of the above procedures, with the goal of making it | |
2664 | more convenient to work with code that accesses the store (@pxref{The | |
2665 | Store Monad}). | |
2666 | ||
e531ac2a LC |
2667 | @c FIXME |
2668 | @i{This section is currently incomplete.} | |
568717fd LC |
2669 | |
2670 | @node Derivations | |
2671 | @section Derivations | |
2672 | ||
874e6874 LC |
2673 | @cindex derivations |
2674 | Low-level build actions and the environment in which they are performed | |
2675 | are represented by @dfn{derivations}. A derivation contain the | |
2676 | following pieces of information: | |
2677 | ||
2678 | @itemize | |
2679 | @item | |
2680 | The outputs of the derivation---derivations produce at least one file or | |
2681 | directory in the store, but may produce more. | |
2682 | ||
2683 | @item | |
2684 | The inputs of the derivations, which may be other derivations or plain | |
2685 | files in the store (patches, build scripts, etc.) | |
2686 | ||
2687 | @item | |
2688 | The system type targeted by the derivation---e.g., @code{x86_64-linux}. | |
2689 | ||
2690 | @item | |
2691 | The file name of a build script in the store, along with the arguments | |
2692 | to be passed. | |
2693 | ||
2694 | @item | |
2695 | A list of environment variables to be defined. | |
2696 | ||
2697 | @end itemize | |
2698 | ||
2699 | @cindex derivation path | |
2700 | Derivations allow clients of the daemon to communicate build actions to | |
2701 | the store. They exist in two forms: as an in-memory representation, | |
2702 | both on the client- and daemon-side, and as files in the store whose | |
2703 | name end in @code{.drv}---these files are referred to as @dfn{derivation | |
2704 | paths}. Derivations paths can be passed to the @code{build-derivations} | |
2705 | procedure to perform the build actions they prescribe (@pxref{The | |
2706 | Store}). | |
2707 | ||
2708 | The @code{(guix derivations)} module provides a representation of | |
2709 | derivations as Scheme objects, along with procedures to create and | |
2710 | otherwise manipulate derivations. The lowest-level primitive to create | |
2711 | a derivation is the @code{derivation} procedure: | |
2712 | ||
1909431c LC |
2713 | @deffn {Scheme Procedure} derivation @var{store} @var{name} @var{builder} @ |
2714 | @var{args} [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @ | |
2096ef47 | 2715 | [#:recursive? #f] [#:inputs '()] [#:env-vars '()] @ |
1909431c | 2716 | [#:system (%current-system)] [#:references-graphs #f] @ |
4a6aeb67 LC |
2717 | [#:allowed-references #f] [#:leaked-env-vars #f] [#:local-build? #f] @ |
2718 | [#:substitutable? #t] | |
59688fc4 LC |
2719 | Build a derivation with the given arguments, and return the resulting |
2720 | @code{<derivation>} object. | |
874e6874 | 2721 | |
2096ef47 | 2722 | When @var{hash} and @var{hash-algo} are given, a |
874e6874 | 2723 | @dfn{fixed-output derivation} is created---i.e., one whose result is |
36bbbbd1 LC |
2724 | known in advance, such as a file download. If, in addition, |
2725 | @var{recursive?} is true, then that fixed output may be an executable | |
2726 | file or a directory and @var{hash} must be the hash of an archive | |
2727 | containing this output. | |
5b0c9d16 | 2728 | |
858e9282 | 2729 | When @var{references-graphs} is true, it must be a list of file |
5b0c9d16 LC |
2730 | name/store path pairs. In that case, the reference graph of each store |
2731 | path is exported in the build environment in the corresponding file, in | |
2732 | a simple text format. | |
1909431c | 2733 | |
b53be755 LC |
2734 | When @var{allowed-references} is true, it must be a list of store items |
2735 | or outputs that the derivation's output may refer to. | |
2736 | ||
c0468155 LC |
2737 | When @var{leaked-env-vars} is true, it must be a list of strings |
2738 | denoting environment variables that are allowed to ``leak'' from the | |
2739 | daemon's environment to the build environment. This is only applicable | |
2740 | to fixed-output derivations---i.e., when @var{hash} is true. The main | |
2741 | use is to allow variables such as @code{http_proxy} to be passed to | |
2742 | derivations that download files. | |
2743 | ||
1909431c LC |
2744 | When @var{local-build?} is true, declare that the derivation is not a |
2745 | good candidate for offloading and should rather be built locally | |
2746 | (@pxref{Daemon Offload Setup}). This is the case for small derivations | |
2747 | where the costs of data transfers would outweigh the benefits. | |
4a6aeb67 LC |
2748 | |
2749 | When @var{substitutable?} is false, declare that substitutes of the | |
2750 | derivation's output should not be used (@pxref{Substitutes}). This is | |
2751 | useful, for instance, when building packages that capture details of the | |
2752 | host CPU instruction set. | |
874e6874 LC |
2753 | @end deffn |
2754 | ||
2755 | @noindent | |
2756 | Here's an example with a shell script as its builder, assuming | |
2757 | @var{store} is an open connection to the daemon, and @var{bash} points | |
2758 | to a Bash executable in the store: | |
2759 | ||
2760 | @lisp | |
2761 | (use-modules (guix utils) | |
2762 | (guix store) | |
2763 | (guix derivations)) | |
2764 | ||
59688fc4 LC |
2765 | (let ((builder ; add the Bash script to the store |
2766 | (add-text-to-store store "my-builder.sh" | |
2767 | "echo hello world > $out\n" '()))) | |
2768 | (derivation store "foo" | |
2769 | bash `("-e" ,builder) | |
21b679f6 | 2770 | #:inputs `((,bash) (,builder)) |
59688fc4 | 2771 | #:env-vars '(("HOME" . "/homeless")))) |
834129e0 | 2772 | @result{} #<derivation /gnu/store/@dots{}-foo.drv => /gnu/store/@dots{}-foo> |
874e6874 LC |
2773 | @end lisp |
2774 | ||
21b679f6 LC |
2775 | As can be guessed, this primitive is cumbersome to use directly. A |
2776 | better approach is to write build scripts in Scheme, of course! The | |
2777 | best course of action for that is to write the build code as a | |
2778 | ``G-expression'', and to pass it to @code{gexp->derivation}. For more | |
6621cdb6 | 2779 | information, @pxref{G-Expressions}. |
21b679f6 LC |
2780 | |
2781 | Once upon a time, @code{gexp->derivation} did not exist and constructing | |
2782 | derivations with build code written in Scheme was achieved with | |
2783 | @code{build-expression->derivation}, documented below. This procedure | |
2784 | is now deprecated in favor of the much nicer @code{gexp->derivation}. | |
874e6874 | 2785 | |
dd1a5a15 LC |
2786 | @deffn {Scheme Procedure} build-expression->derivation @var{store} @ |
2787 | @var{name} @var{exp} @ | |
2788 | [#:system (%current-system)] [#:inputs '()] @ | |
2789 | [#:outputs '("out")] [#:hash #f] [#:hash-algo #f] @ | |
36bbbbd1 | 2790 | [#:recursive? #f] [#:env-vars '()] [#:modules '()] @ |
63a42824 | 2791 | [#:references-graphs #f] [#:allowed-references #f] @ |
4a6aeb67 | 2792 | [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f] |
874e6874 LC |
2793 | Return a derivation that executes Scheme expression @var{exp} as a |
2794 | builder for derivation @var{name}. @var{inputs} must be a list of | |
2795 | @code{(name drv-path sub-drv)} tuples; when @var{sub-drv} is omitted, | |
2796 | @code{"out"} is assumed. @var{modules} is a list of names of Guile | |
2797 | modules from the current search path to be copied in the store, | |
2798 | compiled, and made available in the load path during the execution of | |
2799 | @var{exp}---e.g., @code{((guix build utils) (guix build | |
2800 | gnu-build-system))}. | |
2801 | ||
2802 | @var{exp} is evaluated in an environment where @code{%outputs} is bound | |
2803 | to a list of output/path pairs, and where @code{%build-inputs} is bound | |
2804 | to a list of string/output-path pairs made from @var{inputs}. | |
2805 | Optionally, @var{env-vars} is a list of string pairs specifying the name | |
2806 | and value of environment variables visible to the builder. The builder | |
2807 | terminates by passing the result of @var{exp} to @code{exit}; thus, when | |
2808 | @var{exp} returns @code{#f}, the build is considered to have failed. | |
2809 | ||
2810 | @var{exp} is built using @var{guile-for-build} (a derivation). When | |
2811 | @var{guile-for-build} is omitted or is @code{#f}, the value of the | |
2812 | @code{%guile-for-build} fluid is used instead. | |
9c629a27 | 2813 | |
63a42824 | 2814 | See the @code{derivation} procedure for the meaning of |
4a6aeb67 LC |
2815 | @var{references-graphs}, @var{allowed-references}, @var{local-build?}, |
2816 | and @var{substitutable?}. | |
874e6874 LC |
2817 | @end deffn |
2818 | ||
2819 | @noindent | |
2820 | Here's an example of a single-output derivation that creates a directory | |
2821 | containing one file: | |
2822 | ||
2823 | @lisp | |
2824 | (let ((builder '(let ((out (assoc-ref %outputs "out"))) | |
834129e0 | 2825 | (mkdir out) ; create /gnu/store/@dots{}-goo |
874e6874 LC |
2826 | (call-with-output-file (string-append out "/test") |
2827 | (lambda (p) | |
2828 | (display '(hello guix) p)))))) | |
dd1a5a15 | 2829 | (build-expression->derivation store "goo" builder)) |
874e6874 | 2830 | |
834129e0 | 2831 | @result{} #<derivation /gnu/store/@dots{}-goo.drv => @dots{}> |
874e6874 LC |
2832 | @end lisp |
2833 | ||
568717fd | 2834 | |
b860f382 LC |
2835 | @node The Store Monad |
2836 | @section The Store Monad | |
2837 | ||
2838 | @cindex monad | |
2839 | ||
2840 | The procedures that operate on the store described in the previous | |
2841 | sections all take an open connection to the build daemon as their first | |
2842 | argument. Although the underlying model is functional, they either have | |
2843 | side effects or depend on the current state of the store. | |
2844 | ||
2845 | The former is inconvenient: the connection to the build daemon has to be | |
2846 | carried around in all those functions, making it impossible to compose | |
2847 | functions that do not take that parameter with functions that do. The | |
2848 | latter can be problematic: since store operations have side effects | |
2849 | and/or depend on external state, they have to be properly sequenced. | |
2850 | ||
2851 | @cindex monadic values | |
2852 | @cindex monadic functions | |
2853 | This is where the @code{(guix monads)} module comes in. This module | |
2854 | provides a framework for working with @dfn{monads}, and a particularly | |
2855 | useful monad for our uses, the @dfn{store monad}. Monads are a | |
2856 | construct that allows two things: associating ``context'' with values | |
2857 | (in our case, the context is the store), and building sequences of | |
561fb6c3 | 2858 | computations (here computations include accesses to the store.) Values |
b860f382 LC |
2859 | in a monad---values that carry this additional context---are called |
2860 | @dfn{monadic values}; procedures that return such values are called | |
2861 | @dfn{monadic procedures}. | |
2862 | ||
2863 | Consider this ``normal'' procedure: | |
2864 | ||
2865 | @example | |
45adbd62 LC |
2866 | (define (sh-symlink store) |
2867 | ;; Return a derivation that symlinks the 'bash' executable. | |
2868 | (let* ((drv (package-derivation store bash)) | |
2869 | (out (derivation->output-path drv)) | |
2870 | (sh (string-append out "/bin/bash"))) | |
2871 | (build-expression->derivation store "sh" | |
2872 | `(symlink ,sh %output)))) | |
b860f382 LC |
2873 | @end example |
2874 | ||
c6f30b81 LC |
2875 | Using @code{(guix monads)} and @code{(guix gexp)}, it may be rewritten |
2876 | as a monadic function: | |
b860f382 LC |
2877 | |
2878 | @example | |
45adbd62 | 2879 | (define (sh-symlink) |
b860f382 | 2880 | ;; Same, but return a monadic value. |
c6f30b81 LC |
2881 | (mlet %store-monad ((drv (package->derivation bash))) |
2882 | (gexp->derivation "sh" | |
2883 | #~(symlink (string-append #$drv "/bin/bash") | |
2884 | #$output)))) | |
b860f382 LC |
2885 | @end example |
2886 | ||
c6f30b81 LC |
2887 | There several things to note in the second version: the @code{store} |
2888 | parameter is now implicit and is ``threaded'' in the calls to the | |
2889 | @code{package->derivation} and @code{gexp->derivation} monadic | |
2890 | procedures, and the monadic value returned by @code{package->derivation} | |
2891 | is @dfn{bound} using @code{mlet} instead of plain @code{let}. | |
2892 | ||
2893 | As it turns out, the call to @code{package->derivation} can even be | |
2894 | omitted since it will take place implicitly, as we will see later | |
2895 | (@pxref{G-Expressions}): | |
2896 | ||
2897 | @example | |
2898 | (define (sh-symlink) | |
2899 | (gexp->derivation "sh" | |
2900 | #~(symlink (string-append #$bash "/bin/bash") | |
2901 | #$output))) | |
2902 | @end example | |
b860f382 | 2903 | |
7ce21611 LC |
2904 | @c See |
2905 | @c <https://syntaxexclamation.wordpress.com/2014/06/26/escaping-continuations/> | |
2906 | @c for the funny quote. | |
2907 | Calling the monadic @code{sh-symlink} has no effect. As someone once | |
2908 | said, ``you exit a monad like you exit a building on fire: by running''. | |
2909 | So, to exit the monad and get the desired effect, one must use | |
2910 | @code{run-with-store}: | |
b860f382 LC |
2911 | |
2912 | @example | |
8e9aa37f CAW |
2913 | (run-with-store (open-connection) (sh-symlink)) |
2914 | @result{} /gnu/store/...-sh-symlink | |
b860f382 LC |
2915 | @end example |
2916 | ||
b9b86078 LC |
2917 | Note that the @code{(guix monad-repl)} module extends Guile's REPL with |
2918 | new ``meta-commands'' to make it easier to deal with monadic procedures: | |
2919 | @code{run-in-store}, and @code{enter-store-monad}. The former, is used | |
2920 | to ``run'' a single monadic value through the store: | |
2921 | ||
2922 | @example | |
2923 | scheme@@(guile-user)> ,run-in-store (package->derivation hello) | |
2924 | $1 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}> | |
2925 | @end example | |
2926 | ||
2927 | The latter enters a recursive REPL, where all the return values are | |
2928 | automatically run through the store: | |
2929 | ||
2930 | @example | |
2931 | scheme@@(guile-user)> ,enter-store-monad | |
2932 | store-monad@@(guile-user) [1]> (package->derivation hello) | |
2933 | $2 = #<derivation /gnu/store/@dots{}-hello-2.9.drv => @dots{}> | |
2934 | store-monad@@(guile-user) [1]> (text-file "foo" "Hello!") | |
2935 | $3 = "/gnu/store/@dots{}-foo" | |
2936 | store-monad@@(guile-user) [1]> ,q | |
2937 | scheme@@(guile-user)> | |
2938 | @end example | |
2939 | ||
2940 | @noindent | |
2941 | Note that non-monadic values cannot be returned in the | |
2942 | @code{store-monad} REPL. | |
2943 | ||
e87f0591 LC |
2944 | The main syntactic forms to deal with monads in general are provided by |
2945 | the @code{(guix monads)} module and are described below. | |
b860f382 LC |
2946 | |
2947 | @deffn {Scheme Syntax} with-monad @var{monad} @var{body} ... | |
2948 | Evaluate any @code{>>=} or @code{return} forms in @var{body} as being | |
2949 | in @var{monad}. | |
2950 | @end deffn | |
2951 | ||
2952 | @deffn {Scheme Syntax} return @var{val} | |
2953 | Return a monadic value that encapsulates @var{val}. | |
2954 | @end deffn | |
2955 | ||
751630c9 | 2956 | @deffn {Scheme Syntax} >>= @var{mval} @var{mproc} ... |
b860f382 | 2957 | @dfn{Bind} monadic value @var{mval}, passing its ``contents'' to monadic |
751630c9 LC |
2958 | procedures @var{mproc}@dots{}@footnote{This operation is commonly |
2959 | referred to as ``bind'', but that name denotes an unrelated procedure in | |
2960 | Guile. Thus we use this somewhat cryptic symbol inherited from the | |
2961 | Haskell language.}. There can be one @var{mproc} or several of them, as | |
2962 | in this example: | |
2963 | ||
2964 | @example | |
2965 | (run-with-state | |
2966 | (with-monad %state-monad | |
2967 | (>>= (return 1) | |
2968 | (lambda (x) (return (+ 1 x))) | |
2969 | (lambda (x) (return (* 2 x))))) | |
2970 | 'some-state) | |
2971 | ||
2972 | @result{} 4 | |
2973 | @result{} some-state | |
2974 | @end example | |
b860f382 LC |
2975 | @end deffn |
2976 | ||
2977 | @deffn {Scheme Syntax} mlet @var{monad} ((@var{var} @var{mval}) ...) @ | |
2978 | @var{body} ... | |
2979 | @deffnx {Scheme Syntax} mlet* @var{monad} ((@var{var} @var{mval}) ...) @ | |
2980 | @var{body} ... | |
2981 | Bind the variables @var{var} to the monadic values @var{mval} in | |
2982 | @var{body}. The form (@var{var} -> @var{val}) binds @var{var} to the | |
2983 | ``normal'' value @var{val}, as per @code{let}. | |
2984 | ||
2985 | @code{mlet*} is to @code{mlet} what @code{let*} is to @code{let} | |
2986 | (@pxref{Local Bindings,,, guile, GNU Guile Reference Manual}). | |
2987 | @end deffn | |
2988 | ||
405a9d4e LC |
2989 | @deffn {Scheme System} mbegin @var{monad} @var{mexp} ... |
2990 | Bind @var{mexp} and the following monadic expressions in sequence, | |
2991 | returning the result of the last expression. | |
2992 | ||
2993 | This is akin to @code{mlet}, except that the return values of the | |
2994 | monadic expressions are ignored. In that sense, it is analogous to | |
2995 | @code{begin}, but applied to monadic expressions. | |
2996 | @end deffn | |
2997 | ||
561fb6c3 LC |
2998 | @cindex state monad |
2999 | The @code{(guix monads)} module provides the @dfn{state monad}, which | |
3000 | allows an additional value---the state---to be @emph{threaded} through | |
3001 | monadic procedure calls. | |
3002 | ||
3003 | @defvr {Scheme Variable} %state-monad | |
3004 | The state monad. Procedures in the state monad can access and change | |
3005 | the state that is threaded. | |
3006 | ||
3007 | Consider the example below. The @code{square} procedure returns a value | |
3008 | in the state monad. It returns the square of its argument, but also | |
3009 | increments the current state value: | |
3010 | ||
3011 | @example | |
3012 | (define (square x) | |
3013 | (mlet %state-monad ((count (current-state))) | |
3014 | (mbegin %state-monad | |
3015 | (set-current-state (+ 1 count)) | |
3016 | (return (* x x))))) | |
3017 | ||
3018 | (run-with-state (sequence %state-monad (map square (iota 3))) 0) | |
3019 | @result{} (0 1 4) | |
3020 | @result{} 3 | |
3021 | @end example | |
3022 | ||
3023 | When ``run'' through @var{%state-monad}, we obtain that additional state | |
3024 | value, which is the number of @code{square} calls. | |
3025 | @end defvr | |
3026 | ||
3027 | @deffn {Monadic Procedure} current-state | |
3028 | Return the current state as a monadic value. | |
3029 | @end deffn | |
3030 | ||
3031 | @deffn {Monadic Procedure} set-current-state @var{value} | |
3032 | Set the current state to @var{value} and return the previous state as a | |
3033 | monadic value. | |
3034 | @end deffn | |
3035 | ||
3036 | @deffn {Monadic Procedure} state-push @var{value} | |
3037 | Push @var{value} to the current state, which is assumed to be a list, | |
3038 | and return the previous state as a monadic value. | |
3039 | @end deffn | |
3040 | ||
3041 | @deffn {Monadic Procedure} state-pop | |
3042 | Pop a value from the current state and return it as a monadic value. | |
3043 | The state is assumed to be a list. | |
3044 | @end deffn | |
3045 | ||
3046 | @deffn {Scheme Procedure} run-with-state @var{mval} [@var{state}] | |
3047 | Run monadic value @var{mval} starting with @var{state} as the initial | |
3048 | state. Return two values: the resulting value, and the resulting state. | |
3049 | @end deffn | |
3050 | ||
e87f0591 LC |
3051 | The main interface to the store monad, provided by the @code{(guix |
3052 | store)} module, is as follows. | |
b860f382 LC |
3053 | |
3054 | @defvr {Scheme Variable} %store-monad | |
561fb6c3 LC |
3055 | The store monad---an alias for @var{%state-monad}. |
3056 | ||
3057 | Values in the store monad encapsulate accesses to the store. When its | |
3058 | effect is needed, a value of the store monad must be ``evaluated'' by | |
3059 | passing it to the @code{run-with-store} procedure (see below.) | |
b860f382 LC |
3060 | @end defvr |
3061 | ||
3062 | @deffn {Scheme Procedure} run-with-store @var{store} @var{mval} [#:guile-for-build] [#:system (%current-system)] | |
3063 | Run @var{mval}, a monadic value in the store monad, in @var{store}, an | |
3064 | open store connection. | |
3065 | @end deffn | |
3066 | ||
ad372953 | 3067 | @deffn {Monadic Procedure} text-file @var{name} @var{text} [@var{references}] |
b860f382 | 3068 | Return as a monadic value the absolute file name in the store of the file |
ad372953 LC |
3069 | containing @var{text}, a string. @var{references} is a list of store items that the |
3070 | resulting text file refers to; it defaults to the empty list. | |
45adbd62 LC |
3071 | @end deffn |
3072 | ||
0a90af15 LC |
3073 | @deffn {Monadic Procedure} interned-file @var{file} [@var{name}] @ |
3074 | [#:recursive? #t] | |
3075 | Return the name of @var{file} once interned in the store. Use | |
3076 | @var{name} as its store name, or the basename of @var{file} if | |
3077 | @var{name} is omitted. | |
3078 | ||
3079 | When @var{recursive?} is true, the contents of @var{file} are added | |
3080 | recursively; if @var{file} designates a flat file and @var{recursive?} | |
3081 | is true, its contents are added, and its permission bits are kept. | |
3082 | ||
3083 | The example below adds a file to the store, under two different names: | |
3084 | ||
3085 | @example | |
3086 | (run-with-store (open-connection) | |
3087 | (mlet %store-monad ((a (interned-file "README")) | |
3088 | (b (interned-file "README" "LEGU-MIN"))) | |
3089 | (return (list a b)))) | |
3090 | ||
3091 | @result{} ("/gnu/store/rwm@dots{}-README" "/gnu/store/44i@dots{}-LEGU-MIN") | |
3092 | @end example | |
3093 | ||
3094 | @end deffn | |
3095 | ||
e87f0591 LC |
3096 | The @code{(guix packages)} module exports the following package-related |
3097 | monadic procedures: | |
3098 | ||
b860f382 | 3099 | @deffn {Monadic Procedure} package-file @var{package} [@var{file}] @ |
4231f05b LC |
3100 | [#:system (%current-system)] [#:target #f] @ |
3101 | [#:output "out"] Return as a monadic | |
b860f382 LC |
3102 | value in the absolute file name of @var{file} within the @var{output} |
3103 | directory of @var{package}. When @var{file} is omitted, return the name | |
4231f05b LC |
3104 | of the @var{output} directory of @var{package}. When @var{target} is |
3105 | true, use it as a cross-compilation target triplet. | |
b860f382 LC |
3106 | @end deffn |
3107 | ||
b860f382 | 3108 | @deffn {Monadic Procedure} package->derivation @var{package} [@var{system}] |
4231f05b LC |
3109 | @deffnx {Monadic Procedure} package->cross-derivation @var{package} @ |
3110 | @var{target} [@var{system}] | |
3111 | Monadic version of @code{package-derivation} and | |
3112 | @code{package-cross-derivation} (@pxref{Defining Packages}). | |
b860f382 LC |
3113 | @end deffn |
3114 | ||
3115 | ||
21b679f6 LC |
3116 | @node G-Expressions |
3117 | @section G-Expressions | |
3118 | ||
3119 | @cindex G-expression | |
3120 | @cindex build code quoting | |
3121 | So we have ``derivations'', which represent a sequence of build actions | |
3122 | to be performed to produce an item in the store (@pxref{Derivations}). | |
3123 | Those build actions are performed when asking the daemon to actually | |
3124 | build the derivations; they are run by the daemon in a container | |
3125 | (@pxref{Invoking guix-daemon}). | |
3126 | ||
3127 | @cindex strata of code | |
3128 | It should come as no surprise that we like to write those build actions | |
3129 | in Scheme. When we do that, we end up with two @dfn{strata} of Scheme | |
3130 | code@footnote{The term @dfn{stratum} in this context was coined by | |
ef4ab0a4 LC |
3131 | Manuel Serrano et al.@: in the context of their work on Hop. Oleg |
3132 | Kiselyov, who has written insightful | |
3133 | @url{http://okmij.org/ftp/meta-programming/#meta-scheme, essays and code | |
3134 | on this topic}, refers to this kind of code generation as | |
3135 | @dfn{staging}.}: the ``host code''---code that defines packages, talks | |
3136 | to the daemon, etc.---and the ``build code''---code that actually | |
3137 | performs build actions, such as making directories, invoking | |
3138 | @command{make}, etc. | |
21b679f6 LC |
3139 | |
3140 | To describe a derivation and its build actions, one typically needs to | |
3141 | embed build code inside host code. It boils down to manipulating build | |
3142 | code as data, and Scheme's homoiconicity---code has a direct | |
3143 | representation as data---comes in handy for that. But we need more than | |
3144 | Scheme's normal @code{quasiquote} mechanism to construct build | |
3145 | expressions. | |
3146 | ||
3147 | The @code{(guix gexp)} module implements @dfn{G-expressions}, a form of | |
3148 | S-expressions adapted to build expressions. G-expressions, or | |
3149 | @dfn{gexps}, consist essentially in three syntactic forms: @code{gexp}, | |
3150 | @code{ungexp}, and @code{ungexp-splicing} (or simply: @code{#~}, | |
3151 | @code{#$}, and @code{#$@@}), which are comparable respectively to | |
3152 | @code{quasiquote}, @code{unquote}, and @code{unquote-splicing} | |
3153 | (@pxref{Expression Syntax, @code{quasiquote},, guile, GNU Guile | |
3154 | Reference Manual}). However, there are major differences: | |
3155 | ||
3156 | @itemize | |
3157 | @item | |
3158 | Gexps are meant to be written to a file and run or manipulated by other | |
3159 | processes. | |
3160 | ||
3161 | @item | |
b39fc6f7 LC |
3162 | When a high-level object such as a package or derivation is unquoted |
3163 | inside a gexp, the result is as if its output file name had been | |
3164 | introduced. | |
ff40e9b7 | 3165 | |
21b679f6 LC |
3166 | @item |
3167 | Gexps carry information about the packages or derivations they refer to, | |
3168 | and these dependencies are automatically added as inputs to the build | |
3169 | processes that use them. | |
3170 | @end itemize | |
3171 | ||
c2b84676 | 3172 | @cindex lowering, of high-level objects in gexps |
343eacbe LC |
3173 | This mechanism is not limited to package and derivation |
3174 | objects: @dfn{compilers} able to ``lower'' other high-level objects to | |
c2b84676 LC |
3175 | derivations or files in the store can be defined, |
3176 | such that these objects can also be inserted | |
343eacbe LC |
3177 | into gexps. For example, a useful type of high-level object that can be |
3178 | inserted in a gexp is ``file-like objects'', which make it easy to | |
3179 | add files to the store and refer to them in | |
558e8b11 LC |
3180 | derivations and such (see @code{local-file} and @code{plain-file} |
3181 | below.) | |
b39fc6f7 | 3182 | |
21b679f6 LC |
3183 | To illustrate the idea, here is an example of a gexp: |
3184 | ||
3185 | @example | |
3186 | (define build-exp | |
3187 | #~(begin | |
3188 | (mkdir #$output) | |
3189 | (chdir #$output) | |
aff8ce7c | 3190 | (symlink (string-append #$coreutils "/bin/ls") |
21b679f6 LC |
3191 | "list-files"))) |
3192 | @end example | |
3193 | ||
3194 | This gexp can be passed to @code{gexp->derivation}; we obtain a | |
3195 | derivation that builds a directory containing exactly one symlink to | |
3196 | @file{/gnu/store/@dots{}-coreutils-8.22/bin/ls}: | |
3197 | ||
3198 | @example | |
3199 | (gexp->derivation "the-thing" build-exp) | |
3200 | @end example | |
3201 | ||
e20fd1bf | 3202 | As one would expect, the @code{"/gnu/store/@dots{}-coreutils-8.22"} string is |
21b679f6 LC |
3203 | substituted to the reference to the @var{coreutils} package in the |
3204 | actual build code, and @var{coreutils} is automatically made an input to | |
3205 | the derivation. Likewise, @code{#$output} (equivalent to @code{(ungexp | |
3206 | output)}) is replaced by a string containing the derivation's output | |
667b2508 LC |
3207 | directory name. |
3208 | ||
3209 | @cindex cross compilation | |
3210 | In a cross-compilation context, it is useful to distinguish between | |
3211 | references to the @emph{native} build of a package---that can run on the | |
3212 | host---versus references to cross builds of a package. To that end, the | |
3213 | @code{#+} plays the same role as @code{#$}, but is a reference to a | |
3214 | native package build: | |
3215 | ||
3216 | @example | |
3217 | (gexp->derivation "vi" | |
3218 | #~(begin | |
3219 | (mkdir #$output) | |
3220 | (system* (string-append #+coreutils "/bin/ln") | |
3221 | "-s" | |
3222 | (string-append #$emacs "/bin/emacs") | |
3223 | (string-append #$output "/bin/vi"))) | |
3224 | #:target "mips64el-linux") | |
3225 | @end example | |
3226 | ||
3227 | @noindent | |
3228 | In the example above, the native build of @var{coreutils} is used, so | |
3229 | that @command{ln} can actually run on the host; but then the | |
3230 | cross-compiled build of @var{emacs} is referenced. | |
3231 | ||
3232 | The syntactic form to construct gexps is summarized below. | |
21b679f6 LC |
3233 | |
3234 | @deffn {Scheme Syntax} #~@var{exp} | |
3235 | @deffnx {Scheme Syntax} (gexp @var{exp}) | |
3236 | Return a G-expression containing @var{exp}. @var{exp} may contain one | |
3237 | or more of the following forms: | |
3238 | ||
3239 | @table @code | |
3240 | @item #$@var{obj} | |
3241 | @itemx (ungexp @var{obj}) | |
b39fc6f7 LC |
3242 | Introduce a reference to @var{obj}. @var{obj} may have one of the |
3243 | supported types, for example a package or a | |
21b679f6 LC |
3244 | derivation, in which case the @code{ungexp} form is replaced by its |
3245 | output file name---e.g., @code{"/gnu/store/@dots{}-coreutils-8.22}. | |
3246 | ||
b39fc6f7 LC |
3247 | If @var{obj} is a list, it is traversed and references to supported |
3248 | objects are substituted similarly. | |
21b679f6 LC |
3249 | |
3250 | If @var{obj} is another gexp, its contents are inserted and its | |
3251 | dependencies are added to those of the containing gexp. | |
3252 | ||
3253 | If @var{obj} is another kind of object, it is inserted as is. | |
3254 | ||
b39fc6f7 LC |
3255 | @item #$@var{obj}:@var{output} |
3256 | @itemx (ungexp @var{obj} @var{output}) | |
21b679f6 | 3257 | This is like the form above, but referring explicitly to the |
b39fc6f7 LC |
3258 | @var{output} of @var{obj}---this is useful when @var{obj} produces |
3259 | multiple outputs (@pxref{Packages with Multiple Outputs}). | |
21b679f6 | 3260 | |
667b2508 LC |
3261 | @item #+@var{obj} |
3262 | @itemx #+@var{obj}:output | |
3263 | @itemx (ungexp-native @var{obj}) | |
3264 | @itemx (ungexp-native @var{obj} @var{output}) | |
3265 | Same as @code{ungexp}, but produces a reference to the @emph{native} | |
3266 | build of @var{obj} when used in a cross compilation context. | |
3267 | ||
21b679f6 LC |
3268 | @item #$output[:@var{output}] |
3269 | @itemx (ungexp output [@var{output}]) | |
3270 | Insert a reference to derivation output @var{output}, or to the main | |
3271 | output when @var{output} is omitted. | |
3272 | ||
3273 | This only makes sense for gexps passed to @code{gexp->derivation}. | |
3274 | ||
3275 | @item #$@@@var{lst} | |
3276 | @itemx (ungexp-splicing @var{lst}) | |
3277 | Like the above, but splices the contents of @var{lst} inside the | |
3278 | containing list. | |
3279 | ||
667b2508 LC |
3280 | @item #+@@@var{lst} |
3281 | @itemx (ungexp-native-splicing @var{lst}) | |
3282 | Like the above, but refers to native builds of the objects listed in | |
3283 | @var{lst}. | |
3284 | ||
21b679f6 LC |
3285 | @end table |
3286 | ||
3287 | G-expressions created by @code{gexp} or @code{#~} are run-time objects | |
3288 | of the @code{gexp?} type (see below.) | |
3289 | @end deffn | |
3290 | ||
3291 | @deffn {Scheme Procedure} gexp? @var{obj} | |
3292 | Return @code{#t} if @var{obj} is a G-expression. | |
3293 | @end deffn | |
3294 | ||
3295 | G-expressions are meant to be written to disk, either as code building | |
3296 | some derivation, or as plain files in the store. The monadic procedures | |
3297 | below allow you to do that (@pxref{The Store Monad}, for more | |
3298 | information about monads.) | |
3299 | ||
3300 | @deffn {Monadic Procedure} gexp->derivation @var{name} @var{exp} @ | |
ce45eb4c | 3301 | [#:system (%current-system)] [#:target #f] [#:graft? #t] @ |
21b679f6 LC |
3302 | [#:hash #f] [#:hash-algo #f] @ |
3303 | [#:recursive? #f] [#:env-vars '()] [#:modules '()] @ | |
4684f301 | 3304 | [#:module-path @var{%load-path}] @ |
c8351d9a | 3305 | [#:references-graphs #f] [#:allowed-references #f] @ |
c0468155 | 3306 | [#:leaked-env-vars #f] @ |
0309e1b0 | 3307 | [#:script-name (string-append @var{name} "-builder")] @ |
4a6aeb67 | 3308 | [#:local-build? #f] [#:substitutable? #t] [#:guile-for-build #f] |
21b679f6 | 3309 | Return a derivation @var{name} that runs @var{exp} (a gexp) with |
0309e1b0 LC |
3310 | @var{guile-for-build} (a derivation) on @var{system}; @var{exp} is |
3311 | stored in a file called @var{script-name}. When @var{target} is true, | |
3312 | it is used as the cross-compilation target triplet for packages referred | |
3313 | to by @var{exp}. | |
21b679f6 | 3314 | |
ce45eb4c LC |
3315 | Make @var{modules} available in the evaluation context of @var{exp}; |
3316 | @var{modules} is a list of names of Guile modules searched in | |
3317 | @var{module-path} to be copied in the store, compiled, and made available in | |
21b679f6 LC |
3318 | the load path during the execution of @var{exp}---e.g., @code{((guix |
3319 | build utils) (guix build gnu-build-system))}. | |
3320 | ||
ce45eb4c LC |
3321 | @var{graft?} determines whether packages referred to by @var{exp} should be grafted when |
3322 | applicable. | |
3323 | ||
b53833b2 LC |
3324 | When @var{references-graphs} is true, it must be a list of tuples of one of the |
3325 | following forms: | |
3326 | ||
3327 | @example | |
3328 | (@var{file-name} @var{package}) | |
3329 | (@var{file-name} @var{package} @var{output}) | |
3330 | (@var{file-name} @var{derivation}) | |
3331 | (@var{file-name} @var{derivation} @var{output}) | |
3332 | (@var{file-name} @var{store-item}) | |
3333 | @end example | |
3334 | ||
3335 | The right-hand-side of each element of @var{references-graphs} is automatically made | |
3336 | an input of the build process of @var{exp}. In the build environment, each | |
3337 | @var{file-name} contains the reference graph of the corresponding item, in a simple | |
3338 | text format. | |
3339 | ||
c8351d9a LC |
3340 | @var{allowed-references} must be either @code{#f} or a list of output names and packages. |
3341 | In the latter case, the list denotes store items that the result is allowed to | |
3342 | refer to. Any reference to another store item will lead to a build error. | |
3343 | ||
e20fd1bf | 3344 | The other arguments are as for @code{derivation} (@pxref{Derivations}). |
21b679f6 LC |
3345 | @end deffn |
3346 | ||
343eacbe LC |
3347 | @cindex file-like objects |
3348 | The @code{local-file} and @code{plain-file} procedures below return | |
3349 | @dfn{file-like objects}. That is, when unquoted in a G-expression, | |
3350 | these objects lead to a file in the store. Consider this G-expression: | |
3351 | ||
3352 | @example | |
3353 | #~(system* (string-append #$glibc "/sbin/nscd") "-f" | |
3354 | #$(local-file "/tmp/my-nscd.conf")) | |
3355 | @end example | |
3356 | ||
3357 | The effect here is to ``intern'' @file{/tmp/my-nscd.conf} by copying it | |
3358 | to the store. Once expanded, for instance @i{via} | |
3359 | @code{gexp->derivation}, the G-expression refers to that copy under | |
3360 | @file{/gnu/store}; thus, modifying or removing the file in @file{/tmp} | |
3361 | does not have any effect on what the G-expression does. | |
3362 | @code{plain-file} can be used similarly; it differs in that the file | |
3363 | content is directly passed as a string. | |
3364 | ||
d9ae938f LC |
3365 | @deffn {Scheme Procedure} local-file @var{file} [@var{name}] @ |
3366 | [#:recursive? #t] | |
3367 | Return an object representing local file @var{file} to add to the store; this | |
3368 | object can be used in a gexp. @var{file} will be added to the store under @var{name}--by | |
3369 | default the base name of @var{file}. | |
3370 | ||
3371 | When @var{recursive?} is true, the contents of @var{file} are added recursively; if @var{file} | |
3372 | designates a flat file and @var{recursive?} is true, its contents are added, and its | |
3373 | permission bits are kept. | |
3374 | ||
3375 | This is the declarative counterpart of the @code{interned-file} monadic | |
3376 | procedure (@pxref{The Store Monad, @code{interned-file}}). | |
3377 | @end deffn | |
3378 | ||
558e8b11 LC |
3379 | @deffn {Scheme Procedure} plain-file @var{name} @var{content} |
3380 | Return an object representing a text file called @var{name} with the given | |
3381 | @var{content} (a string) to be added to the store. | |
3382 | ||
3383 | This is the declarative counterpart of @code{text-file}. | |
3384 | @end deffn | |
3385 | ||
21b679f6 LC |
3386 | @deffn {Monadic Procedure} gexp->script @var{name} @var{exp} |
3387 | Return an executable script @var{name} that runs @var{exp} using | |
3388 | @var{guile} with @var{modules} in its search path. | |
3389 | ||
3390 | The example below builds a script that simply invokes the @command{ls} | |
3391 | command: | |
3392 | ||
3393 | @example | |
3394 | (use-modules (guix gexp) (gnu packages base)) | |
3395 | ||
3396 | (gexp->script "list-files" | |
3397 | #~(execl (string-append #$coreutils "/bin/ls") | |
3398 | "ls")) | |
3399 | @end example | |
3400 | ||
3401 | When ``running'' it through the store (@pxref{The Store Monad, | |
e20fd1bf | 3402 | @code{run-with-store}}), we obtain a derivation that produces an |
21b679f6 LC |
3403 | executable file @file{/gnu/store/@dots{}-list-files} along these lines: |
3404 | ||
3405 | @example | |
3406 | #!/gnu/store/@dots{}-guile-2.0.11/bin/guile -ds | |
3407 | !# | |
3408 | (execl (string-append "/gnu/store/@dots{}-coreutils-8.22"/bin/ls") | |
3409 | "ls") | |
3410 | @end example | |
3411 | @end deffn | |
3412 | ||
3413 | @deffn {Monadic Procedure} gexp->file @var{name} @var{exp} | |
3414 | Return a derivation that builds a file @var{name} containing @var{exp}. | |
3415 | ||
3416 | The resulting file holds references to all the dependencies of @var{exp} | |
3417 | or a subset thereof. | |
3418 | @end deffn | |
1ed19464 LC |
3419 | |
3420 | @deffn {Monadic Procedure} text-file* @var{name} @var{text} @dots{} | |
3421 | Return as a monadic value a derivation that builds a text file | |
3422 | containing all of @var{text}. @var{text} may list, in addition to | |
d9ae938f LC |
3423 | strings, objects of any type that can be used in a gexp: packages, |
3424 | derivations, local file objects, etc. The resulting store file holds | |
3425 | references to all these. | |
1ed19464 LC |
3426 | |
3427 | This variant should be preferred over @code{text-file} anytime the file | |
3428 | to create will reference items from the store. This is typically the | |
3429 | case when building a configuration file that embeds store file names, | |
3430 | like this: | |
3431 | ||
3432 | @example | |
3433 | (define (profile.sh) | |
3434 | ;; Return the name of a shell script in the store that | |
3435 | ;; initializes the 'PATH' environment variable. | |
3436 | (text-file* "profile.sh" | |
3437 | "export PATH=" coreutils "/bin:" | |
3438 | grep "/bin:" sed "/bin\n")) | |
3439 | @end example | |
3440 | ||
3441 | In this example, the resulting @file{/gnu/store/@dots{}-profile.sh} file | |
3442 | will references @var{coreutils}, @var{grep}, and @var{sed}, thereby | |
3443 | preventing them from being garbage-collected during its lifetime. | |
3444 | @end deffn | |
21b679f6 LC |
3445 | |
3446 | Of course, in addition to gexps embedded in ``host'' code, there are | |
3447 | also modules containing build tools. To make it clear that they are | |
3448 | meant to be used in the build stratum, these modules are kept in the | |
3449 | @code{(guix build @dots{})} name space. | |
3450 | ||
c2b84676 LC |
3451 | @cindex lowering, of high-level objects in gexps |
3452 | Internally, high-level objects are @dfn{lowered}, using their compiler, | |
3453 | to either derivations or store items. For instance, lowering a package | |
3454 | yields a derivation, and lowering a @code{plain-file} yields a store | |
3455 | item. This is achieved using the @code{lower-object} monadic procedure. | |
3456 | ||
3457 | @deffn {Monadic Procedure} lower-object @var{obj} [@var{system}] @ | |
3458 | [#:target #f] | |
3459 | Return as a value in @var{%store-monad} the derivation or store item | |
3460 | corresponding to @var{obj} for @var{system}, cross-compiling for | |
3461 | @var{target} if @var{target} is true. @var{obj} must be an object that | |
3462 | has an associated gexp compiler, such as a @code{<package>}. | |
3463 | @end deffn | |
3464 | ||
21b679f6 | 3465 | |
568717fd LC |
3466 | @c ********************************************************************* |
3467 | @node Utilities | |
3468 | @chapter Utilities | |
3469 | ||
210cc920 LC |
3470 | This section describes tools primarily targeted at developers and users |
3471 | who write new package definitions. They complement the Scheme | |
3472 | programming interface of Guix in a convenient way. | |
3473 | ||
568717fd | 3474 | @menu |
37166310 | 3475 | * Invoking guix build:: Building packages from the command line. |
39bee8a2 | 3476 | * Invoking guix edit:: Editing package definitions. |
210cc920 | 3477 | * Invoking guix download:: Downloading a file and printing its hash. |
37166310 | 3478 | * Invoking guix hash:: Computing the cryptographic hash of a file. |
2f7d2d91 | 3479 | * Invoking guix import:: Importing package definitions. |
37166310 | 3480 | * Invoking guix refresh:: Updating package definitions. |
b4f5e0e8 | 3481 | * Invoking guix lint:: Finding errors in package definitions. |
fcc58db6 | 3482 | * Invoking guix size:: Profiling disk usage. |
88856916 | 3483 | * Invoking guix graph:: Visualizing the graph of packages. |
372c4bbc | 3484 | * Invoking guix environment:: Setting up development environments. |
aff8ce7c | 3485 | * Invoking guix publish:: Sharing substitutes. |
568717fd LC |
3486 | @end menu |
3487 | ||
e49951eb MW |
3488 | @node Invoking guix build |
3489 | @section Invoking @command{guix build} | |
568717fd | 3490 | |
e49951eb | 3491 | The @command{guix build} command builds packages or derivations and |
6798a8e4 LC |
3492 | their dependencies, and prints the resulting store paths. Note that it |
3493 | does not modify the user's profile---this is the job of the | |
e49951eb | 3494 | @command{guix package} command (@pxref{Invoking guix package}). Thus, |
6798a8e4 LC |
3495 | it is mainly useful for distribution developers. |
3496 | ||
3497 | The general syntax is: | |
c78bd12b LC |
3498 | |
3499 | @example | |
e49951eb | 3500 | guix build @var{options} @var{package-or-derivation}@dots{} |
c78bd12b LC |
3501 | @end example |
3502 | ||
3503 | @var{package-or-derivation} may be either the name of a package found in | |
5401dd75 LC |
3504 | the software distribution such as @code{coreutils} or |
3505 | @code{coreutils-8.20}, or a derivation such as | |
834129e0 | 3506 | @file{/gnu/store/@dots{}-coreutils-8.19.drv}. In the former case, a |
e7f34eb0 LC |
3507 | package with the corresponding name (and optionally version) is searched |
3508 | for among the GNU distribution modules (@pxref{Package Modules}). | |
3509 | ||
3510 | Alternatively, the @code{--expression} option may be used to specify a | |
3511 | Scheme expression that evaluates to a package; this is useful when | |
3512 | disambiguation among several same-named packages or package variants is | |
3513 | needed. | |
c78bd12b LC |
3514 | |
3515 | The @var{options} may be zero or more of the following: | |
3516 | ||
3517 | @table @code | |
3518 | ||
3519 | @item --expression=@var{expr} | |
3520 | @itemx -e @var{expr} | |
ac5de156 | 3521 | Build the package or derivation @var{expr} evaluates to. |
c78bd12b | 3522 | |
5401dd75 | 3523 | For example, @var{expr} may be @code{(@@ (gnu packages guile) |
c78bd12b LC |
3524 | guile-1.8)}, which unambiguously designates this specific variant of |
3525 | version 1.8 of Guile. | |
3526 | ||
56b82106 LC |
3527 | Alternately, @var{expr} may be a G-expression, in which case it is used |
3528 | as a build program passed to @code{gexp->derivation} | |
3529 | (@pxref{G-Expressions}). | |
3530 | ||
3531 | Lastly, @var{expr} may refer to a zero-argument monadic procedure | |
ac5de156 LC |
3532 | (@pxref{The Store Monad}). The procedure must return a derivation as a |
3533 | monadic value, which is then passed through @code{run-with-store}. | |
3534 | ||
c78bd12b LC |
3535 | @item --source |
3536 | @itemx -S | |
3537 | Build the packages' source derivations, rather than the packages | |
3538 | themselves. | |
3539 | ||
e49951eb | 3540 | For instance, @code{guix build -S gcc} returns something like |
834129e0 | 3541 | @file{/gnu/store/@dots{}-gcc-4.7.2.tar.bz2}, which is GCC's source tarball. |
c78bd12b | 3542 | |
f9cc8971 LC |
3543 | The returned source tarball is the result of applying any patches and |
3544 | code snippets specified in the package's @code{origin} (@pxref{Defining | |
3545 | Packages}). | |
3546 | ||
2cdfe13d EB |
3547 | @item --sources |
3548 | Fetch and return the source of @var{package-or-derivation} and all their | |
3549 | dependencies, recursively. This is a handy way to obtain a local copy | |
3550 | of all the source code needed to build @var{packages}, allowing you to | |
3551 | eventually build them even without network access. It is an extension | |
3552 | of the @code{--source} option and can accept one of the following | |
3553 | optional argument values: | |
3554 | ||
3555 | @table @code | |
3556 | @item package | |
3557 | This value causes the @code{--sources} option to behave in the same way | |
3558 | as the @code{--source} option. | |
3559 | ||
3560 | @item all | |
3561 | Build all packages' source derivations, including any source that might | |
3562 | be listed as @code{inputs}. This is the default value. | |
3563 | ||
3564 | @example | |
3565 | $ guix build --sources tzdata | |
3566 | The following derivations will be built: | |
3567 | /gnu/store/@dots{}-tzdata2015b.tar.gz.drv | |
3568 | /gnu/store/@dots{}-tzcode2015b.tar.gz.drv | |
3569 | @end example | |
3570 | ||
3571 | @item transitive | |
3572 | Build all packages' source derivations, as well as all source | |
3573 | derivations for packages' transitive inputs. This can be used e.g. to | |
3574 | prefetch package source for later offline building. | |
3575 | ||
3576 | @example | |
3577 | $ guix build --sources=transitive tzdata | |
3578 | The following derivations will be built: | |
3579 | /gnu/store/@dots{}-tzcode2015b.tar.gz.drv | |
3580 | /gnu/store/@dots{}-findutils-4.4.2.tar.xz.drv | |
3581 | /gnu/store/@dots{}-grep-2.21.tar.xz.drv | |
3582 | /gnu/store/@dots{}-coreutils-8.23.tar.xz.drv | |
3583 | /gnu/store/@dots{}-make-4.1.tar.xz.drv | |
3584 | /gnu/store/@dots{}-bash-4.3.tar.xz.drv | |
3585 | @dots{} | |
3586 | @end example | |
3587 | ||
3588 | @end table | |
3589 | ||
c78bd12b LC |
3590 | @item --system=@var{system} |
3591 | @itemx -s @var{system} | |
3592 | Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of | |
3593 | the host's system type. | |
3594 | ||
3595 | An example use of this is on Linux-based systems, which can emulate | |
3596 | different personalities. For instance, passing | |
3597 | @code{--system=i686-linux} on an @code{x86_64-linux} system allows users | |
3598 | to build packages in a complete 32-bit environment. | |
3599 | ||
e55ec43d LC |
3600 | @item --target=@var{triplet} |
3601 | @cindex cross-compilation | |
3602 | Cross-build for @var{triplet}, which must be a valid GNU triplet, such | |
3603 | as @code{"mips64el-linux-gnu"} (@pxref{Configuration Names, GNU | |
3604 | configuration triplets,, configure, GNU Configure and Build System}). | |
3605 | ||
7f3673f2 LC |
3606 | @item --with-source=@var{source} |
3607 | Use @var{source} as the source of the corresponding package. | |
3608 | @var{source} must be a file name or a URL, as for @command{guix | |
3609 | download} (@pxref{Invoking guix download}). | |
3610 | ||
3611 | The ``corresponding package'' is taken to be one specified on the | |
3612 | command line whose name matches the base of @var{source}---e.g., if | |
3613 | @var{source} is @code{/src/guile-2.0.10.tar.gz}, the corresponding | |
3614 | package is @code{guile}. Likewise, the version string is inferred from | |
3615 | @var{source}; in the previous example, it's @code{2.0.10}. | |
3616 | ||
3617 | This option allows users to try out versions of packages other than the | |
3618 | one provided by the distribution. The example below downloads | |
3619 | @file{ed-1.7.tar.gz} from a GNU mirror and uses that as the source for | |
3620 | the @code{ed} package: | |
3621 | ||
3622 | @example | |
3623 | guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz | |
3624 | @end example | |
3625 | ||
3626 | As a developer, @code{--with-source} makes it easy to test release | |
3627 | candidates: | |
3628 | ||
3629 | @example | |
3630 | guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz | |
3631 | @end example | |
3632 | ||
a43b55f1 LC |
3633 | @dots{} or to build from a checkout in a pristine environment: |
3634 | ||
3635 | @example | |
3636 | $ git clone git://git.sv.gnu.org/guix.git | |
3637 | $ guix build guix --with-source=./guix | |
3638 | @end example | |
3639 | ||
05962f29 LC |
3640 | @item --no-grafts |
3641 | Do not ``graft'' packages. In practice, this means that package updates | |
3642 | available as grafts are not applied. @xref{Security Updates}, for more | |
3643 | information on grafts. | |
7f3673f2 | 3644 | |
c78bd12b LC |
3645 | @item --derivations |
3646 | @itemx -d | |
3647 | Return the derivation paths, not the output paths, of the given | |
3648 | packages. | |
3649 | ||
70ee5642 LC |
3650 | @item --root=@var{file} |
3651 | @itemx -r @var{file} | |
3652 | Make @var{file} a symlink to the result, and register it as a garbage | |
3653 | collector root. | |
3654 | ||
3655 | @item --log-file | |
3f208ad7 | 3656 | Return the build log file names or URLs for the given |
70ee5642 LC |
3657 | @var{package-or-derivation}s, or raise an error if build logs are |
3658 | missing. | |
3659 | ||
3660 | This works regardless of how packages or derivations are specified. For | |
3661 | instance, the following invocations are equivalent: | |
3662 | ||
3663 | @example | |
3664 | guix build --log-file `guix build -d guile` | |
3665 | guix build --log-file `guix build guile` | |
3666 | guix build --log-file guile | |
3667 | guix build --log-file -e '(@@ (gnu packages guile) guile-2.0)' | |
3668 | @end example | |
3669 | ||
3f208ad7 LC |
3670 | If a log is unavailable locally, and unless @code{--no-substitutes} is |
3671 | passed, the command looks for a corresponding log on one of the | |
3672 | substitute servers (as specified with @code{--substitute-urls}.) | |
70ee5642 | 3673 | |
3f208ad7 LC |
3674 | So for instance, let's say you want to see the build log of GDB on MIPS |
3675 | but you're actually on an @code{x86_64} machine: | |
3676 | ||
3677 | @example | |
3678 | $ guix build --log-file gdb -s mips64el-linux | |
3679 | http://hydra.gnu.org/log/@dots{}-gdb-7.10 | |
3680 | @end example | |
3681 | ||
3682 | You can freely access a huge library of build logs! | |
70ee5642 LC |
3683 | @end table |
3684 | ||
3685 | @cindex common build options | |
3686 | In addition, a number of options that control the build process are | |
3687 | common to @command{guix build} and other commands that can spawn builds, | |
3688 | such as @command{guix package} or @command{guix archive}. These are the | |
3689 | following: | |
3690 | ||
3691 | @table @code | |
3692 | ||
300868ba LC |
3693 | @item --load-path=@var{directory} |
3694 | @itemx -L @var{directory} | |
3695 | Add @var{directory} to the front of the package module search path | |
3696 | (@pxref{Package Modules}). | |
3697 | ||
3698 | This allows users to define their own packages and make them visible to | |
3699 | the command-line tools. | |
3700 | ||
c78bd12b LC |
3701 | @item --keep-failed |
3702 | @itemx -K | |
3703 | Keep the build tree of failed builds. Thus, if a build fail, its build | |
3704 | tree is kept under @file{/tmp}, in a directory whose name is shown at | |
3705 | the end of the build log. This is useful when debugging build issues. | |
3706 | ||
3707 | @item --dry-run | |
3708 | @itemx -n | |
3709 | Do not build the derivations. | |
3710 | ||
56b1f4b7 LC |
3711 | @item --fallback |
3712 | When substituting a pre-built binary fails, fall back to building | |
3713 | packages locally. | |
3714 | ||
f8a8e0fe LC |
3715 | @item --substitute-urls=@var{urls} |
3716 | @anchor{client-substitute-urls} | |
3717 | Consider @var{urls} the whitespace-separated list of substitute source | |
3718 | URLs, overriding the default list of URLs of @command{guix-daemon} | |
3719 | (@pxref{daemon-substitute-urls,, @command{guix-daemon} URLs}). | |
3720 | ||
3721 | This means that substitutes may be downloaded from @var{urls}, provided | |
3722 | they are signed by a key authorized by the system administrator | |
3723 | (@pxref{Substitutes}). | |
3724 | ||
c78bd12b | 3725 | @item --no-substitutes |
b5385b52 | 3726 | Do not use substitutes for build products. That is, always build things |
c4202d60 LC |
3727 | locally instead of allowing downloads of pre-built binaries |
3728 | (@pxref{Substitutes}). | |
c78bd12b | 3729 | |
425b0bfc | 3730 | @item --no-build-hook |
4ec2e92d LC |
3731 | Do not attempt to offload builds @i{via} the daemon's ``build hook'' |
3732 | (@pxref{Daemon Offload Setup}). That is, always build things locally | |
3733 | instead of offloading builds to remote machines. | |
425b0bfc | 3734 | |
969e678e LC |
3735 | @item --max-silent-time=@var{seconds} |
3736 | When the build or substitution process remains silent for more than | |
3737 | @var{seconds}, terminate it and report a build failure. | |
3738 | ||
002622b6 LC |
3739 | @item --timeout=@var{seconds} |
3740 | Likewise, when the build or substitution process lasts for more than | |
3741 | @var{seconds}, terminate it and report a build failure. | |
3742 | ||
3743 | By default there is no timeout. This behavior can be restored with | |
3744 | @code{--timeout=0}. | |
3745 | ||
07ab4bf1 LC |
3746 | @item --verbosity=@var{level} |
3747 | Use the given verbosity level. @var{level} must be an integer between 0 | |
3748 | and 5; higher means more verbose output. Setting a level of 4 or more | |
3749 | may be helpful when debugging setup issues with the build daemon. | |
3750 | ||
70ee5642 LC |
3751 | @item --cores=@var{n} |
3752 | @itemx -c @var{n} | |
3753 | Allow the use of up to @var{n} CPU cores for the build. The special | |
3754 | value @code{0} means to use as many CPU cores as available. | |
bf421152 | 3755 | |
f6526eb3 LC |
3756 | @item --max-jobs=@var{n} |
3757 | @itemx -M @var{n} | |
3758 | Allow at most @var{n} build jobs in parallel. @xref{Invoking | |
3759 | guix-daemon, @code{--max-jobs}}, for details about this option and the | |
3760 | equivalent @command{guix-daemon} option. | |
3761 | ||
c78bd12b LC |
3762 | @end table |
3763 | ||
e49951eb | 3764 | Behind the scenes, @command{guix build} is essentially an interface to |
c78bd12b LC |
3765 | the @code{package-derivation} procedure of the @code{(guix packages)} |
3766 | module, and to the @code{build-derivations} procedure of the @code{(guix | |
01d8ac64 | 3767 | derivations)} module. |
c78bd12b | 3768 | |
16eb115e DP |
3769 | In addition to options explicitly passed on the command line, |
3770 | @command{guix build} and other @command{guix} commands that support | |
3771 | building honor the @code{GUIX_BUILD_OPTIONS} environment variable. | |
3772 | ||
3773 | @defvr {Environment Variable} GUIX_BUILD_OPTIONS | |
3774 | Users can define this variable to a list of command line options that | |
3775 | will automatically be used by @command{guix build} and other | |
3776 | @command{guix} commands that can perform builds, as in the example | |
3777 | below: | |
3778 | ||
3779 | @example | |
3780 | $ export GUIX_BUILD_OPTIONS="--no-substitutes -c 2 -L /foo/bar" | |
3781 | @end example | |
3782 | ||
847391fe DP |
3783 | These options are parsed independently, and the result is appended to |
3784 | the parsed command-line options. | |
16eb115e DP |
3785 | @end defvr |
3786 | ||
3787 | ||
39bee8a2 LC |
3788 | @node Invoking guix edit |
3789 | @section Invoking @command{guix edit} | |
3790 | ||
3791 | @cindex package definition, editing | |
3792 | So many packages, so many source files! The @command{guix edit} command | |
3793 | facilitates the life of packagers by pointing their editor at the source | |
3794 | file containing the definition of the specified packages. For instance: | |
3795 | ||
3796 | @example | |
3797 | guix edit gcc-4.8 vim | |
3798 | @end example | |
3799 | ||
3800 | @noindent | |
3801 | launches the program specified in the @code{EDITOR} environment variable | |
3802 | to edit the recipe of GCC@tie{}4.8.4 and that of Vim. | |
3803 | ||
3804 | If you are using Emacs, note that the Emacs user interface provides | |
6248e326 AK |
3805 | similar functionality in the ``package info'' and ``package list'' |
3806 | buffers created by @kbd{M-x guix-search-by-name} and similar commands | |
3807 | (@pxref{Emacs Commands}). | |
39bee8a2 LC |
3808 | |
3809 | ||
210cc920 LC |
3810 | @node Invoking guix download |
3811 | @section Invoking @command{guix download} | |
3812 | ||
3813 | When writing a package definition, developers typically need to download | |
3814 | the package's source tarball, compute its SHA256 hash, and write that | |
3815 | hash in the package definition (@pxref{Defining Packages}). The | |
3816 | @command{guix download} tool helps with this task: it downloads a file | |
3817 | from the given URI, adds it to the store, and prints both its file name | |
3818 | in the store and its SHA256 hash. | |
3819 | ||
3820 | The fact that the downloaded file is added to the store saves bandwidth: | |
3821 | when the developer eventually tries to build the newly defined package | |
3822 | with @command{guix build}, the source tarball will not have to be | |
3823 | downloaded again because it is already in the store. It is also a | |
3824 | convenient way to temporarily stash files, which may be deleted | |
3825 | eventually (@pxref{Invoking guix gc}). | |
3826 | ||
3827 | The @command{guix download} command supports the same URIs as used in | |
3828 | package definitions. In particular, it supports @code{mirror://} URIs. | |
3829 | @code{https} URIs (HTTP over TLS) are supported @emph{provided} the | |
3830 | Guile bindings for GnuTLS are available in the user's environment; when | |
537c8bb3 LC |
3831 | they are not available, an error is raised. @xref{Guile Preparations, |
3832 | how to install the GnuTLS bindings for Guile,, gnutls-guile, | |
3833 | GnuTLS-Guile}, for more information. | |
210cc920 LC |
3834 | |
3835 | The following option is available: | |
3836 | ||
3837 | @table @code | |
3838 | @item --format=@var{fmt} | |
3839 | @itemx -f @var{fmt} | |
3840 | Write the hash in the format specified by @var{fmt}. For more | |
081145cf | 3841 | information on the valid values for @var{fmt}, @pxref{Invoking guix hash}. |
210cc920 LC |
3842 | @end table |
3843 | ||
6c365eca NK |
3844 | @node Invoking guix hash |
3845 | @section Invoking @command{guix hash} | |
3846 | ||
210cc920 | 3847 | The @command{guix hash} command computes the SHA256 hash of a file. |
6c365eca NK |
3848 | It is primarily a convenience tool for anyone contributing to the |
3849 | distribution: it computes the cryptographic hash of a file, which can be | |
3850 | used in the definition of a package (@pxref{Defining Packages}). | |
3851 | ||
3852 | The general syntax is: | |
3853 | ||
3854 | @example | |
3855 | guix hash @var{option} @var{file} | |
3856 | @end example | |
3857 | ||
3858 | @command{guix hash} has the following option: | |
3859 | ||
3860 | @table @code | |
3861 | ||
3862 | @item --format=@var{fmt} | |
3863 | @itemx -f @var{fmt} | |
210cc920 | 3864 | Write the hash in the format specified by @var{fmt}. |
6c365eca NK |
3865 | |
3866 | Supported formats: @code{nix-base32}, @code{base32}, @code{base16} | |
3867 | (@code{hex} and @code{hexadecimal} can be used as well). | |
3868 | ||
3869 | If the @option{--format} option is not specified, @command{guix hash} | |
3870 | will output the hash in @code{nix-base32}. This representation is used | |
3871 | in the definitions of packages. | |
3872 | ||
3140f2df LC |
3873 | @item --recursive |
3874 | @itemx -r | |
3875 | Compute the hash on @var{file} recursively. | |
3876 | ||
3877 | In this case, the hash is computed on an archive containing @var{file}, | |
3878 | including its children if it is a directory. Some of @var{file}'s | |
3879 | meta-data is part of the archive; for instance, when @var{file} is a | |
3880 | regular file, the hash is different depending on whether @var{file} is | |
3881 | executable or not. Meta-data such as time stamps has no impact on the | |
3882 | hash (@pxref{Invoking guix archive}). | |
3883 | @c FIXME: Replace xref above with xref to an ``Archive'' section when | |
3884 | @c it exists. | |
3885 | ||
6c365eca NK |
3886 | @end table |
3887 | ||
2f7d2d91 LC |
3888 | @node Invoking guix import |
3889 | @section Invoking @command{guix import} | |
3890 | ||
3891 | @cindex importing packages | |
3892 | @cindex package import | |
3893 | @cindex package conversion | |
3894 | The @command{guix import} command is useful for people willing to add a | |
3895 | package to the distribution but who'd rather do as little work as | |
3896 | possible to get there---a legitimate demand. The command knows of a few | |
3897 | repositories from which it can ``import'' package meta-data. The result | |
3898 | is a package definition, or a template thereof, in the format we know | |
3899 | (@pxref{Defining Packages}). | |
3900 | ||
3901 | The general syntax is: | |
3902 | ||
3903 | @example | |
3904 | guix import @var{importer} @var{options}@dots{} | |
3905 | @end example | |
3906 | ||
3907 | @var{importer} specifies the source from which to import package | |
3908 | meta-data, and @var{options} specifies a package identifier and other | |
3909 | options specific to @var{importer}. Currently, the available | |
3910 | ``importers'' are: | |
3911 | ||
3912 | @table @code | |
3913 | @item gnu | |
3914 | Import meta-data for the given GNU package. This provides a template | |
3915 | for the latest version of that GNU package, including the hash of its | |
3916 | source tarball, and its canonical synopsis and description. | |
3917 | ||
3918 | Additional information such as the package's dependencies and its | |
3919 | license needs to be figured out manually. | |
3920 | ||
3921 | For example, the following command returns a package definition for | |
3922 | GNU@tie{}Hello: | |
3923 | ||
3924 | @example | |
3925 | guix import gnu hello | |
3926 | @end example | |
3927 | ||
3928 | Specific command-line options are: | |
3929 | ||
3930 | @table @code | |
3931 | @item --key-download=@var{policy} | |
3932 | As for @code{guix refresh}, specify the policy to handle missing OpenPGP | |
3933 | keys when verifying the package's signature. @xref{Invoking guix | |
3934 | refresh, @code{--key-download}}. | |
3935 | @end table | |
3936 | ||
3937 | @item pypi | |
3938 | @cindex pypi | |
3939 | Import meta-data from the @uref{https://pypi.python.org/, Python Package | |
3940 | Index}@footnote{This functionality requires Guile-JSON to be installed. | |
3941 | @xref{Requirements}.}. Information is taken from the JSON-formatted | |
3942 | description available at @code{pypi.python.org} and usually includes all | |
3943 | the relevant information, including package dependencies. | |
3944 | ||
3945 | The command below imports meta-data for the @code{itsdangerous} Python | |
3946 | package: | |
3947 | ||
3948 | @example | |
3949 | guix import pypi itsdangerous | |
3950 | @end example | |
3951 | ||
3aae8145 DT |
3952 | @item gem |
3953 | @cindex gem | |
3954 | Import meta-data from @uref{https://rubygems.org/, | |
3955 | RubyGems}@footnote{This functionality requires Guile-JSON to be | |
3956 | installed. @xref{Requirements}.}. Information is taken from the | |
3957 | JSON-formatted description available at @code{rubygems.org} and includes | |
3958 | most relevant information, including runtime dependencies. There are | |
3959 | some caveats, however. The meta-data doesn't distinguish between | |
3960 | synopses and descriptions, so the same string is used for both fields. | |
3961 | Additionally, the details of non-Ruby dependencies required to build | |
3962 | native extensions is unavailable and left as an exercise to the | |
3963 | packager. | |
3964 | ||
3965 | The command below imports meta-data for the @code{rails} Ruby package: | |
3966 | ||
3967 | @example | |
3968 | guix import gem rails | |
3969 | @end example | |
3970 | ||
d45dc6da EB |
3971 | @item cpan |
3972 | @cindex CPAN | |
3973 | Import meta-data from @uref{https://www.metacpan.org/, MetaCPAN}. | |
3974 | Information is taken from the JSON-formatted meta-data provided through | |
3975 | @uref{https://api.metacpan.org/, MetaCPAN's API} and includes most | |
66392e47 EB |
3976 | relevant information, such as module dependencies. License information |
3977 | should be checked closely. If Perl is available in the store, then the | |
3978 | @code{corelist} utility will be used to filter core modules out of the | |
3979 | list of dependencies. | |
d45dc6da EB |
3980 | |
3981 | The command command below imports meta-data for the @code{Acme::Boolean} | |
3982 | Perl module: | |
3983 | ||
3984 | @example | |
3985 | guix import cpan Acme::Boolean | |
3986 | @end example | |
3987 | ||
e1248602 RW |
3988 | @item cran |
3989 | @cindex CRAN | |
3990 | Import meta-data from @uref{http://cran.r-project.org/, CRAN}, the | |
3991 | central repository for the @uref{http://r-project.org, GNU@tie{}R | |
3992 | statistical and graphical environment}. | |
3993 | ||
3994 | Information is extracted from the HTML package description. | |
3995 | ||
3996 | The command command below imports meta-data for the @code{Cairo} | |
3997 | R package: | |
3998 | ||
3999 | @example | |
4000 | guix import cran Cairo | |
4001 | @end example | |
4002 | ||
2f7d2d91 LC |
4003 | @item nix |
4004 | Import meta-data from a local copy of the source of the | |
4005 | @uref{http://nixos.org/nixpkgs/, Nixpkgs distribution}@footnote{This | |
4006 | relies on the @command{nix-instantiate} command of | |
4007 | @uref{http://nixos.org/nix/, Nix}.}. Package definitions in Nixpkgs are | |
4008 | typically written in a mixture of Nix-language and Bash code. This | |
4009 | command only imports the high-level package structure that is written in | |
4010 | the Nix language. It normally includes all the basic fields of a | |
4011 | package definition. | |
4012 | ||
4013 | When importing a GNU package, the synopsis and descriptions are replaced | |
4014 | by their canonical upstream variant. | |
4015 | ||
4016 | As an example, the command below imports the package definition of | |
4017 | LibreOffice (more precisely, it imports the definition of the package | |
4018 | bound to the @code{libreoffice} top-level attribute): | |
4019 | ||
4020 | @example | |
4021 | guix import nix ~/path/to/nixpkgs libreoffice | |
4022 | @end example | |
863af4e1 FB |
4023 | |
4024 | @item hackage | |
4025 | @cindex hackage | |
4026 | Import meta-data from Haskell community's central package archive | |
4027 | @uref{https://hackage.haskell.org/, Hackage}. Information is taken from | |
4028 | Cabal files and includes all the relevant information, including package | |
4029 | dependencies. | |
4030 | ||
4031 | Specific command-line options are: | |
4032 | ||
4033 | @table @code | |
a4154748 FB |
4034 | @item --stdin |
4035 | @itemx -s | |
4036 | Read a Cabal file from the standard input. | |
863af4e1 FB |
4037 | @item --no-test-dependencies |
4038 | @itemx -t | |
a4154748 FB |
4039 | Do not include dependencies required by the test suites only. |
4040 | @item --cabal-environment=@var{alist} | |
4041 | @itemx -e @var{alist} | |
4042 | @var{alist} is a Scheme alist defining the environment in which the | |
4043 | Cabal conditionals are evaluated. The accepted keys are: @code{os}, | |
4044 | @code{arch}, @code{impl} and a string representing the name of a flag. | |
4045 | The value associated with a flag has to be either the symbol | |
4046 | @code{true} or @code{false}. The value associated with other keys | |
4047 | has to conform to the Cabal file format definition. The default value | |
4048 | associated with the keys @code{os}, @code{arch} and @code{impl} is | |
4049 | @samp{linux}, @samp{x86_64} and @samp{ghc} respectively. | |
863af4e1 FB |
4050 | @end table |
4051 | ||
4052 | The command below imports meta-data for the latest version of the | |
a4154748 FB |
4053 | @code{HTTP} Haskell package without including test dependencies and |
4054 | specifying the value of the flag @samp{network-uri} as @code{false}: | |
863af4e1 FB |
4055 | |
4056 | @example | |
a4154748 | 4057 | guix import hackage -t -e "'((\"network-uri\" . false))" HTTP |
863af4e1 FB |
4058 | @end example |
4059 | ||
4060 | A specific package version may optionally be specified by following the | |
4061 | package name by a hyphen and a version number as in the following example: | |
4062 | ||
4063 | @example | |
4064 | guix import hackage mtl-2.1.3.1 | |
4065 | @end example | |
7f74a931 FB |
4066 | |
4067 | @item elpa | |
4068 | @cindex elpa | |
4069 | Import meta-data from an Emacs Lisp Package Archive (ELPA) package | |
4070 | repository (@pxref{Packages,,, emacs, The GNU Emacs Manual}). | |
4071 | ||
4072 | Specific command-line options are: | |
4073 | ||
4074 | @table @code | |
4075 | @item --archive=@var{repo} | |
4076 | @itemx -a @var{repo} | |
4077 | @var{repo} identifies the archive repository from which to retrieve the | |
4078 | information. Currently the supported repositories and their identifiers | |
4079 | are: | |
4080 | @itemize - | |
4081 | @item | |
840bd1d3 | 4082 | @uref{http://elpa.gnu.org/packages, GNU}, selected by the @code{gnu} |
7f74a931 FB |
4083 | identifier. This is the default. |
4084 | ||
4085 | @item | |
840bd1d3 | 4086 | @uref{http://stable.melpa.org/packages, MELPA-Stable}, selected by the |
7f74a931 FB |
4087 | @code{melpa-stable} identifier. |
4088 | ||
4089 | @item | |
840bd1d3 | 4090 | @uref{http://melpa.org/packages, MELPA}, selected by the @code{melpa} |
7f74a931 FB |
4091 | identifier. |
4092 | @end itemize | |
4093 | @end table | |
2f7d2d91 LC |
4094 | @end table |
4095 | ||
4096 | The structure of the @command{guix import} code is modular. It would be | |
4097 | useful to have more importers for other package formats, and your help | |
4098 | is welcome here (@pxref{Contributing}). | |
4099 | ||
37166310 LC |
4100 | @node Invoking guix refresh |
4101 | @section Invoking @command{guix refresh} | |
4102 | ||
4103 | The primary audience of the @command{guix refresh} command is developers | |
4104 | of the GNU software distribution. By default, it reports any packages | |
4105 | provided by the distribution that are outdated compared to the latest | |
4106 | upstream version, like this: | |
4107 | ||
4108 | @example | |
4109 | $ guix refresh | |
4110 | gnu/packages/gettext.scm:29:13: gettext would be upgraded from 0.18.1.1 to 0.18.2.1 | |
4111 | gnu/packages/glib.scm:77:12: glib would be upgraded from 2.34.3 to 2.37.0 | |
4112 | @end example | |
4113 | ||
4114 | It does so by browsing each package's FTP directory and determining the | |
4115 | highest version number of the source tarballs | |
4116 | therein@footnote{Currently, this only works for GNU packages.}. | |
4117 | ||
4118 | When passed @code{--update}, it modifies distribution source files to | |
4119 | update the version numbers and source tarball hashes of those packages' | |
4120 | recipes (@pxref{Defining Packages}). This is achieved by downloading | |
4121 | each package's latest source tarball and its associated OpenPGP | |
4122 | signature, authenticating the downloaded tarball against its signature | |
4123 | using @command{gpg}, and finally computing its hash. When the public | |
4124 | key used to sign the tarball is missing from the user's keyring, an | |
4125 | attempt is made to automatically retrieve it from a public key server; | |
4126 | when it's successful, the key is added to the user's keyring; otherwise, | |
4127 | @command{guix refresh} reports an error. | |
4128 | ||
4129 | The following options are supported: | |
4130 | ||
4131 | @table @code | |
4132 | ||
4133 | @item --update | |
4134 | @itemx -u | |
4135 | Update distribution source files (package recipes) in place. | |
081145cf | 4136 | @xref{Defining Packages}, for more information on package definitions. |
37166310 LC |
4137 | |
4138 | @item --select=[@var{subset}] | |
4139 | @itemx -s @var{subset} | |
4140 | Select all the packages in @var{subset}, one of @code{core} or | |
4141 | @code{non-core}. | |
4142 | ||
4143 | The @code{core} subset refers to all the packages at the core of the | |
4144 | distribution---i.e., packages that are used to build ``everything | |
4145 | else''. This includes GCC, libc, Binutils, Bash, etc. Usually, | |
4146 | changing one of these packages in the distribution entails a rebuild of | |
4147 | all the others. Thus, such updates are an inconvenience to users in | |
4148 | terms of build time or bandwidth used to achieve the upgrade. | |
4149 | ||
4150 | The @code{non-core} subset refers to the remaining packages. It is | |
4151 | typically useful in cases where an update of the core packages would be | |
4152 | inconvenient. | |
4153 | ||
4154 | @end table | |
4155 | ||
4156 | In addition, @command{guix refresh} can be passed one or more package | |
4157 | names, as in this example: | |
4158 | ||
4159 | @example | |
4b9b3cbb | 4160 | guix refresh -u emacs idutils gcc-4.8.4 |
37166310 LC |
4161 | @end example |
4162 | ||
4163 | @noindent | |
4164 | The command above specifically updates the @code{emacs} and | |
4165 | @code{idutils} packages. The @code{--select} option would have no | |
4166 | effect in this case. | |
4167 | ||
7d193ec3 EB |
4168 | When considering whether to upgrade a package, it is sometimes |
4169 | convenient to know which packages would be affected by the upgrade and | |
4170 | should be checked for compatibility. For this the following option may | |
4171 | be used when passing @command{guix refresh} one or more package names: | |
4172 | ||
4173 | @table @code | |
4174 | ||
4175 | @item --list-dependent | |
4176 | @itemx -l | |
4177 | List top-level dependent packages that would need to be rebuilt as a | |
4178 | result of upgrading one or more packages. | |
4179 | ||
4180 | @end table | |
4181 | ||
4182 | Be aware that the @code{--list-dependent} option only | |
4183 | @emph{approximates} the rebuilds that would be required as a result of | |
4184 | an upgrade. More rebuilds might be required under some circumstances. | |
4185 | ||
4186 | @example | |
7779ab61 LC |
4187 | $ guix refresh --list-dependent flex |
4188 | Building the following 120 packages would ensure 213 dependent packages are rebuilt: | |
4189 | hop-2.4.0 geiser-0.4 notmuch-0.18 mu-0.9.9.5 cflow-1.4 idutils-4.6 @dots{} | |
7d193ec3 EB |
4190 | @end example |
4191 | ||
4192 | The command above lists a set of packages that could be built to check | |
4193 | for compatibility with an upgraded @code{flex} package. | |
4194 | ||
f9230085 LC |
4195 | The following options can be used to customize GnuPG operation: |
4196 | ||
4197 | @table @code | |
4198 | ||
f9230085 LC |
4199 | @item --gpg=@var{command} |
4200 | Use @var{command} as the GnuPG 2.x command. @var{command} is searched | |
4201 | for in @code{$PATH}. | |
4202 | ||
2bc53ba9 LC |
4203 | @item --key-download=@var{policy} |
4204 | Handle missing OpenPGP keys according to @var{policy}, which may be one | |
4205 | of: | |
4206 | ||
4207 | @table @code | |
4208 | @item always | |
4209 | Always download missing OpenPGP keys from the key server, and add them | |
4210 | to the user's GnuPG keyring. | |
4211 | ||
4212 | @item never | |
4213 | Never try to download missing OpenPGP keys. Instead just bail out. | |
4214 | ||
4215 | @item interactive | |
4216 | When a package signed with an unknown OpenPGP key is encountered, ask | |
4217 | the user whether to download it or not. This is the default behavior. | |
4218 | @end table | |
4219 | ||
4220 | @item --key-server=@var{host} | |
4221 | Use @var{host} as the OpenPGP key server when importing a public key. | |
4222 | ||
f9230085 LC |
4223 | @end table |
4224 | ||
b4f5e0e8 CR |
4225 | @node Invoking guix lint |
4226 | @section Invoking @command{guix lint} | |
4227 | The @command{guix lint} is meant to help package developers avoid common | |
873c4085 LC |
4228 | errors and use a consistent style. It runs a number of checks on a |
4229 | given set of packages in order to find common mistakes in their | |
4230 | definitions. Available @dfn{checkers} include (see | |
4231 | @code{--list-checkers} for a complete list): | |
4232 | ||
4233 | @table @code | |
4234 | @item synopsis | |
4235 | @itemx description | |
4236 | Validate certain typographical and stylistic rules about package | |
4237 | descriptions and synopses. | |
4238 | ||
4239 | @item inputs-should-be-native | |
4240 | Identify inputs that should most likely be native inputs. | |
4241 | ||
4242 | @item source | |
4243 | @itemx home-page | |
50f5c46d | 4244 | @itemx source-file-name |
873c4085 | 4245 | Probe @code{home-page} and @code{source} URLs and report those that are |
50f5c46d EB |
4246 | invalid. Check that the source file name is meaningful, e.g. is not |
4247 | just a version number or ``git-checkout'', and should not have a | |
4248 | @code{file-name} declared (@pxref{origin Reference}). | |
40a7d4e5 LC |
4249 | |
4250 | @item formatting | |
4251 | Warn about obvious source code formatting issues: trailing white space, | |
4252 | use of tabulations, etc. | |
873c4085 | 4253 | @end table |
b4f5e0e8 CR |
4254 | |
4255 | The general syntax is: | |
4256 | ||
4257 | @example | |
4258 | guix lint @var{options} @var{package}@dots{} | |
4259 | @end example | |
4260 | ||
4261 | If no package is given on the command line, then all packages are checked. | |
4262 | The @var{options} may be zero or more of the following: | |
4263 | ||
4264 | @table @code | |
4265 | ||
dd7c013d CR |
4266 | @item --checkers |
4267 | @itemx -c | |
4268 | Only enable the checkers specified in a comma-separated list using the | |
4269 | names returned by @code{--list-checkers}. | |
4270 | ||
b4f5e0e8 CR |
4271 | @item --list-checkers |
4272 | @itemx -l | |
4273 | List and describe all the available checkers that will be run on packages | |
4274 | and exit. | |
4275 | ||
4276 | @end table | |
37166310 | 4277 | |
fcc58db6 LC |
4278 | @node Invoking guix size |
4279 | @section Invoking @command{guix size} | |
4280 | ||
4281 | The @command{guix size} command helps package developers profile the | |
4282 | disk usage of packages. It is easy to overlook the impact of an | |
4283 | additional dependency added to a package, or the impact of using a | |
4284 | single output for a package that could easily be split (@pxref{Packages | |
4285 | with Multiple Outputs}). These are the typical issues that | |
4286 | @command{guix size} can highlight. | |
4287 | ||
4288 | The command can be passed a package specification such as @code{gcc-4.8} | |
4289 | or @code{guile:debug}, or a file name in the store. Consider this | |
4290 | example: | |
4291 | ||
4292 | @example | |
4293 | $ guix size coreutils | |
4294 | store item total self | |
4295 | /gnu/store/@dots{}-coreutils-8.23 70.0 13.9 19.8% | |
4296 | /gnu/store/@dots{}-gmp-6.0.0a 55.3 2.5 3.6% | |
4297 | /gnu/store/@dots{}-acl-2.2.52 53.7 0.5 0.7% | |
4298 | /gnu/store/@dots{}-attr-2.4.46 53.2 0.3 0.5% | |
4299 | /gnu/store/@dots{}-gcc-4.8.4-lib 52.9 15.7 22.4% | |
4300 | /gnu/store/@dots{}-glibc-2.21 37.2 37.2 53.1% | |
4301 | @end example | |
4302 | ||
4303 | @cindex closure | |
4304 | The store items listed here constitute the @dfn{transitive closure} of | |
4305 | Coreutils---i.e., Coreutils and all its dependencies, recursively---as | |
4306 | would be returned by: | |
4307 | ||
4308 | @example | |
4309 | $ guix gc -R /gnu/store/@dots{}-coreutils-8.23 | |
4310 | @end example | |
4311 | ||
4312 | Here the output shows 3 columns next to store items. The first column, | |
4313 | labeled ``total'', shows the size in mebibytes (MiB) of the closure of | |
4314 | the store item---that is, its own size plus the size of all its | |
4315 | dependencies. The next column, labeled ``self'', shows the size of the | |
4316 | item itself. The last column shows the ratio of the item's size to the | |
4317 | space occupied by all the items listed here. | |
4318 | ||
4319 | In this example, we see that the closure of Coreutils weighs in at | |
4320 | 70@tie{}MiB, half of which is taken by libc. (That libc represents a | |
4321 | large fraction of the closure is not a problem @i{per se} because it is | |
4322 | always available on the system anyway.) | |
4323 | ||
4324 | When the package passed to @command{guix size} is available in the | |
4325 | store, @command{guix size} queries the daemon to determine its | |
4326 | dependencies, and measures its size in the store, similar to @command{du | |
4327 | -ms --apparent-size} (@pxref{du invocation,,, coreutils, GNU | |
4328 | Coreutils}). | |
4329 | ||
4330 | When the given package is @emph{not} in the store, @command{guix size} | |
4331 | reports information based on information about the available substitutes | |
4332 | (@pxref{Substitutes}). This allows it to profile disk usage of store | |
4333 | items that are not even on disk, only available remotely. | |
4334 | ||
a8f996c6 | 4335 | The available options are: |
fcc58db6 LC |
4336 | |
4337 | @table @option | |
4338 | ||
d490d06e LC |
4339 | @item --substitute-urls=@var{urls} |
4340 | Use substitute information from @var{urls}. | |
4341 | @xref{client-substitute-urls, the same option for @code{guix build}}. | |
4342 | ||
a8f996c6 LC |
4343 | @item --map-file=@var{file} |
4344 | Write to @var{file} a graphical map of disk usage as a PNG file. | |
4345 | ||
4346 | For the example above, the map looks like this: | |
4347 | ||
4348 | @image{images/coreutils-size-map,5in,, map of Coreutils disk usage | |
4349 | produced by @command{guix size}} | |
4350 | ||
4351 | This option requires that | |
4352 | @uref{http://wingolog.org/software/guile-charting/, Guile-Charting} be | |
4353 | installed and visible in Guile's module search path. When that is not | |
4354 | the case, @command{guix size} fails as it tries to load it. | |
4355 | ||
fcc58db6 LC |
4356 | @item --system=@var{system} |
4357 | @itemx -s @var{system} | |
4358 | Consider packages for @var{system}---e.g., @code{x86_64-linux}. | |
4359 | ||
4360 | @end table | |
4361 | ||
88856916 LC |
4362 | @node Invoking guix graph |
4363 | @section Invoking @command{guix graph} | |
4364 | ||
4365 | @cindex DAG | |
4366 | Packages and their dependencies form a @dfn{graph}, specifically a | |
4367 | directed acyclic graph (DAG). It can quickly become difficult to have a | |
4368 | mental model of the package DAG, so the @command{guix graph} command is | |
4369 | here to provide a visual representation of the DAG. @command{guix | |
4370 | graph} emits a DAG representation in the input format of | |
4371 | @uref{http://www.graphviz.org/, Graphviz}, so its output can be passed | |
4372 | directly to Graphviz's @command{dot} command, for instance. The general | |
4373 | syntax is: | |
4374 | ||
4375 | @example | |
4376 | guix graph @var{options} @var{package}@dots{} | |
4377 | @end example | |
4378 | ||
4379 | For example, the following command generates a PDF file representing the | |
4380 | package DAG for the GNU@tie{}Core Utilities, showing its build-time | |
4381 | dependencies: | |
4382 | ||
4383 | @example | |
4384 | guix graph coreutils | dot -Tpdf > dag.pdf | |
4385 | @end example | |
4386 | ||
4387 | The output looks like this: | |
4388 | ||
4389 | @image{images/coreutils-graph,2in,,Dependency graph of the GNU Coreutils} | |
4390 | ||
4391 | Nice little graph, no? | |
4392 | ||
4393 | But there's more than one graph! The one above is concise: it's the | |
4394 | graph of package objects, omitting implicit inputs such as GCC, libc, | |
4395 | grep, etc. It's often useful to have such a concise graph, but | |
4396 | sometimes you want to see more details. @command{guix graph} supports | |
4397 | several types of graphs, allowing you to choose the level of details: | |
4398 | ||
4399 | @table @code | |
4400 | @item package | |
4401 | This is the default type, the one we used above. It shows the DAG of | |
4402 | package objects, excluding implicit dependencies. It is concise, but | |
4403 | filters out many details. | |
4404 | ||
4405 | @item bag-emerged | |
4406 | This is the package DAG, @emph{including} implicit inputs. | |
4407 | ||
4408 | For instance, the following command: | |
4409 | ||
4410 | @example | |
4411 | guix graph --type=bag-emerged coreutils | dot -Tpdf > dag.pdf | |
4412 | @end example | |
4413 | ||
4414 | ... yields this bigger graph: | |
4415 | ||
4416 | @image{images/coreutils-bag-graph,,5in,Detailed dependency graph of the GNU Coreutils} | |
4417 | ||
4418 | At the bottom of the graph, we see all the implicit inputs of | |
4419 | @var{gnu-build-system} (@pxref{Build Systems, @code{gnu-build-system}}). | |
4420 | ||
4421 | Now, note that the dependencies of those implicit inputs---that is, the | |
4422 | @dfn{bootstrap dependencies} (@pxref{Bootstrapping})---are not shown | |
4423 | here, for conciseness. | |
4424 | ||
4425 | @item bag | |
4426 | Similar to @code{bag-emerged}, but this time including all the bootstrap | |
4427 | dependencies. | |
4428 | ||
4429 | @item derivations | |
4430 | This is the most detailed representation: It shows the DAG of | |
4431 | derivations (@pxref{Derivations}) and plain store items. Compared to | |
4432 | the above representation, many additional nodes are visible, including | |
4433 | builds scripts, patches, Guile modules, etc. | |
4434 | ||
4435 | @end table | |
4436 | ||
4437 | All the above types correspond to @emph{build-time dependencies}. The | |
4438 | following graph type represents the @emph{run-time dependencies}: | |
4439 | ||
4440 | @table @code | |
4441 | @item references | |
4442 | This is the graph of @dfn{references} of a package output, as returned | |
4443 | by @command{guix gc --references} (@pxref{Invoking guix gc}). | |
4444 | ||
4445 | If the given package output is not available in the store, @command{guix | |
4446 | graph} attempts to obtain dependency information from substitutes. | |
4447 | @end table | |
4448 | ||
4449 | The available options are the following: | |
4450 | ||
4451 | @table @option | |
4452 | @item --type=@var{type} | |
4453 | @itemx -t @var{type} | |
4454 | Produce a graph output of @var{type}, where @var{type} must be one of | |
4455 | the values listed above. | |
4456 | ||
4457 | @item --list-types | |
4458 | List the supported graph types. | |
4c8f997a LC |
4459 | |
4460 | @item --expression=@var{expr} | |
4461 | @itemx -e @var{expr} | |
4462 | Consider the package @var{expr} evaluates to. | |
4463 | ||
4464 | This is useful to precisely refer to a package, as in this example: | |
4465 | ||
4466 | @example | |
4467 | guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)' | |
4468 | @end example | |
88856916 LC |
4469 | @end table |
4470 | ||
4471 | ||
372c4bbc DT |
4472 | @node Invoking guix environment |
4473 | @section Invoking @command{guix environment} | |
4474 | ||
f5fd4fd2 | 4475 | @cindex reproducible build environments |
fe36d84e | 4476 | @cindex development environments |
372c4bbc DT |
4477 | The purpose of @command{guix environment} is to assist hackers in |
4478 | creating reproducible development environments without polluting their | |
4479 | package profile. The @command{guix environment} tool takes one or more | |
4480 | packages, builds all of the necessary inputs, and creates a shell | |
4481 | environment to use them. | |
4482 | ||
4483 | The general syntax is: | |
4484 | ||
4485 | @example | |
4486 | guix environment @var{options} @var{package}@dots{} | |
4487 | @end example | |
4488 | ||
fe36d84e LC |
4489 | The following example spawns a new shell set up for the development of |
4490 | GNU@tie{}Guile: | |
372c4bbc DT |
4491 | |
4492 | @example | |
4493 | guix environment guile | |
4494 | @end example | |
4495 | ||
4496 | If the specified packages are not built yet, @command{guix environment} | |
4497 | automatically builds them. The new shell's environment is an augmented | |
4498 | version of the environment that @command{guix environment} was run in. | |
4499 | It contains the necessary search paths for building the given package | |
4500 | added to the existing environment variables. To create a ``pure'' | |
4501 | environment in which the original environment variables have been unset, | |
50500f7c LC |
4502 | use the @code{--pure} option@footnote{Users sometimes wrongfully augment |
4503 | environment variables such as @code{PATH} in their @file{~/.bashrc} | |
4504 | file. As a consequence, when @code{guix environment} launches it, Bash | |
4505 | may read @file{~/.bashrc}, thereby introducing ``impurities'' in these | |
4506 | environment variables. It is an error to define such environment | |
4507 | variables in @file{.bashrc}; instead, they should be defined in | |
4508 | @file{.bash_profile}, which is sourced only by log-in shells. | |
4509 | @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for | |
4510 | details on Bash start-up files.}. | |
372c4bbc | 4511 | |
28de8d25 LC |
4512 | @vindex GUIX_ENVIRONMENT |
4513 | @command{guix environment} defines the @code{GUIX_ENVIRONMENT} | |
4514 | variable in the shell it spaws. This allows users to, say, define a | |
4515 | specific prompt for development environments in their @file{.bashrc} | |
4516 | (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}): | |
4517 | ||
4518 | @example | |
4519 | if [ -n "$GUIX_ENVIRONMENT" ] | |
4520 | then | |
4521 | export PS1="\u@@\h \w [dev]\$ " | |
4522 | fi | |
4523 | @end example | |
4524 | ||
372c4bbc DT |
4525 | Additionally, more than one package may be specified, in which case the |
4526 | union of the inputs for the given packages are used. For example, the | |
4527 | command below spawns a shell where all of the dependencies of both Guile | |
4528 | and Emacs are available: | |
4529 | ||
4530 | @example | |
4531 | guix environment guile emacs | |
4532 | @end example | |
4533 | ||
4534 | Sometimes an interactive shell session is not desired. The | |
4535 | @code{--exec} option can be used to specify the command to run instead. | |
4536 | ||
4537 | @example | |
4538 | guix environment guile --exec=make | |
4539 | @end example | |
4540 | ||
fe36d84e LC |
4541 | In other situations, it is more convenient to specify the list of |
4542 | packages needed in the environment. For example, the following command | |
4543 | runs @command{python} from an environment containing Python@tie{}2.7 and | |
4544 | NumPy: | |
4545 | ||
4546 | @example | |
4547 | guix environment --ad-hoc python2-numpy python-2.7 -E python | |
4548 | @end example | |
4549 | ||
4550 | The available options are summarized below. | |
372c4bbc DT |
4551 | |
4552 | @table @code | |
4553 | @item --expression=@var{expr} | |
4554 | @itemx -e @var{expr} | |
4555 | Create an environment for the package that @var{expr} evaluates to. | |
4556 | ||
fe36d84e LC |
4557 | For example, running: |
4558 | ||
4559 | @example | |
4560 | guix environment -e '(@@ (gnu packages maths) petsc-openmpi)' | |
4561 | @end example | |
4562 | ||
4563 | starts a shell with the environment for this specific variant of the | |
4564 | PETSc package. | |
4565 | ||
372c4bbc DT |
4566 | @item --load=@var{file} |
4567 | @itemx -l @var{file} | |
4568 | Create an environment for the package that the code within @var{file} | |
4569 | evaluates to. | |
4570 | ||
fe36d84e LC |
4571 | As an example, @var{file} might contain a definition like this |
4572 | (@pxref{Defining Packages}): | |
4573 | ||
4574 | @example | |
4575 | @verbatiminclude environment-gdb.scm | |
4576 | @end example | |
4577 | ||
4578 | ||
372c4bbc DT |
4579 | @item --exec=@var{command} |
4580 | @item -E @var{command} | |
4581 | Execute @var{command} in the new environment. | |
4582 | ||
a54bd6d7 DT |
4583 | @item --ad-hoc |
4584 | Include all specified packages in the resulting environment, as if an | |
4585 | @i{ad hoc} package were defined with them as inputs. This option is | |
4586 | useful for quickly creating an environment without having to write a | |
4587 | package expression to contain the desired inputs. | |
4588 | ||
4589 | For instance, the command: | |
4590 | ||
4591 | @example | |
4592 | guix environment --ad-hoc guile guile-sdl -E guile | |
4593 | @end example | |
4594 | ||
4595 | runs @command{guile} in an environment where Guile and Guile-SDL are | |
4596 | available. | |
4597 | ||
417c39f1 LC |
4598 | Note that this example implicitly asks for the default output of |
4599 | @code{guile} and @code{guile-sdl} but it is possible to ask for a | |
4600 | specific output---e.g., @code{glib:bin} asks for the @code{bin} output | |
4601 | of @code{glib} (@pxref{Packages with Multiple Outputs}). | |
4602 | ||
372c4bbc DT |
4603 | @item --pure |
4604 | Unset existing environment variables when building the new environment. | |
4605 | This has the effect of creating an environment in which search paths | |
4606 | only contain package inputs. | |
4607 | ||
4608 | @item --search-paths | |
4609 | Display the environment variable definitions that make up the | |
4610 | environment. | |
ce367ef3 LC |
4611 | |
4612 | @item --system=@var{system} | |
4613 | @itemx -s @var{system} | |
4614 | Attempt to build for @var{system}---e.g., @code{i686-linux}. | |
372c4bbc DT |
4615 | @end table |
4616 | ||
4617 | It also supports all of the common build options that @command{guix | |
4618 | build} supports (@pxref{Invoking guix build, common build options}). | |
4619 | ||
aff8ce7c DT |
4620 | @node Invoking guix publish |
4621 | @section Invoking @command{guix publish} | |
4622 | ||
4623 | The purpose of @command{guix publish} is to enable users to easily share | |
8ce229fc LC |
4624 | their store with others, which can then use it as a substitute server |
4625 | (@pxref{Substitutes}). | |
4626 | ||
4627 | When @command{guix publish} runs, it spawns an HTTP server which allows | |
4628 | anyone with network access to obtain substitutes from it. This means | |
4629 | that any machine running Guix can also act as if it were a build farm, | |
4630 | since the HTTP interface is compatible with Hydra, the software behind | |
4631 | the @code{hydra.gnu.org} build farm. | |
aff8ce7c DT |
4632 | |
4633 | For security, each substitute is signed, allowing recipients to check | |
4634 | their authenticity and integrity (@pxref{Substitutes}). Because | |
4635 | @command{guix publish} uses the system's signing key, which is only | |
5463fe51 LC |
4636 | readable by the system administrator, it must be started as root; the |
4637 | @code{--user} option makes it drop root privileges early on. | |
aff8ce7c DT |
4638 | |
4639 | The general syntax is: | |
4640 | ||
4641 | @example | |
4642 | guix publish @var{options}@dots{} | |
4643 | @end example | |
4644 | ||
4645 | Running @command{guix publish} without any additional arguments will | |
4646 | spawn an HTTP server on port 8080: | |
4647 | ||
4648 | @example | |
4649 | guix publish | |
4650 | @end example | |
4651 | ||
4652 | Once a publishing server has been authorized (@pxref{Invoking guix | |
4653 | archive}), the daemon may download substitutes from it: | |
4654 | ||
4655 | @example | |
4656 | guix-daemon --substitute-urls=http://example.org:8080 | |
4657 | @end example | |
4658 | ||
4659 | The following options are available: | |
4660 | ||
4661 | @table @code | |
4662 | @item --port=@var{port} | |
4663 | @itemx -p @var{port} | |
4664 | Listen for HTTP requests on @var{port}. | |
4665 | ||
9e2292ef LC |
4666 | @item --listen=@var{host} |
4667 | Listen on the network interface for @var{host}. The default is to | |
4668 | accept connections from any interface. | |
4669 | ||
5463fe51 LC |
4670 | @item --user=@var{user} |
4671 | @itemx -u @var{user} | |
4672 | Change privileges to @var{user} as soon as possible---i.e., once the | |
4673 | server socket is open and the signing key has been read. | |
4674 | ||
aff8ce7c DT |
4675 | @item --repl[=@var{port}] |
4676 | @itemx -r [@var{port}] | |
4677 | Spawn a Guile REPL server (@pxref{REPL Servers,,, guile, GNU Guile | |
8ce229fc LC |
4678 | Reference Manual}) on @var{port} (37146 by default). This is used |
4679 | primarily for debugging a running @command{guix publish} server. | |
aff8ce7c DT |
4680 | @end table |
4681 | ||
a1ba8475 LC |
4682 | @c ********************************************************************* |
4683 | @node GNU Distribution | |
4684 | @chapter GNU Distribution | |
4685 | ||
3ca2731c | 4686 | @cindex Guix System Distribution |
4705641f | 4687 | @cindex GuixSD |
3ca2731c LC |
4688 | Guix comes with a distribution of the GNU system consisting entirely of |
4689 | free software@footnote{The term ``free'' here refers to the | |
a1ba8475 | 4690 | @url{http://www.gnu.org/philosophy/free-sw.html,freedom provided to |
3ca2731c | 4691 | users of that software}.}. The |
35ed9306 LC |
4692 | distribution can be installed on its own (@pxref{System Installation}), |
4693 | but it is also possible to install Guix as a package manager on top of | |
4694 | an installed GNU/Linux system (@pxref{Installation}). To distinguish | |
3ca2731c | 4695 | between the two, we refer to the standalone distribution as the Guix |
4705641f | 4696 | System Distribution, or GuixSD. |
35ed9306 LC |
4697 | |
4698 | The distribution provides core GNU packages such as GNU libc, GCC, and | |
4699 | Binutils, as well as many GNU and non-GNU applications. The complete | |
4700 | list of available packages can be browsed | |
093ae1be | 4701 | @url{http://www.gnu.org/software/guix/packages,on-line} or by |
d03bb653 | 4702 | running @command{guix package} (@pxref{Invoking guix package}): |
a1ba8475 LC |
4703 | |
4704 | @example | |
e49951eb | 4705 | guix package --list-available |
a1ba8475 LC |
4706 | @end example |
4707 | ||
35ed9306 | 4708 | Our goal has been to provide a practical 100% free software distribution of |
401c53c4 LC |
4709 | Linux-based and other variants of GNU, with a focus on the promotion and |
4710 | tight integration of GNU components, and an emphasis on programs and | |
4711 | tools that help users exert that freedom. | |
4712 | ||
3ca2731c | 4713 | Packages are currently available on the following platforms: |
c320011d LC |
4714 | |
4715 | @table @code | |
4716 | ||
4717 | @item x86_64-linux | |
4718 | Intel/AMD @code{x86_64} architecture, Linux-Libre kernel; | |
4719 | ||
4720 | @item i686-linux | |
4721 | Intel 32-bit architecture (IA32), Linux-Libre kernel; | |
4722 | ||
aa1e1947 | 4723 | @item armhf-linux |
aa725117 | 4724 | ARMv7-A architecture with hard float, Thumb-2 and NEON, |
aa1e1947 MW |
4725 | using the EABI hard-float ABI, and Linux-Libre kernel. |
4726 | ||
c320011d LC |
4727 | @item mips64el-linux |
4728 | little-endian 64-bit MIPS processors, specifically the Loongson series, | |
4729 | n32 application binary interface (ABI), and Linux-Libre kernel. | |
4730 | ||
4731 | @end table | |
4732 | ||
4705641f | 4733 | GuixSD itself is currently only available on @code{i686} and @code{x86_64}. |
3ca2731c | 4734 | |
c320011d LC |
4735 | @noindent |
4736 | For information on porting to other architectures or kernels, | |
4737 | @xref{Porting}. | |
4738 | ||
401c53c4 | 4739 | @menu |
5af6de3e | 4740 | * System Installation:: Installing the whole operating system. |
35ed9306 | 4741 | * System Configuration:: Configuring the operating system. |
91ef73d4 | 4742 | * Installing Debugging Files:: Feeding the debugger. |
05962f29 | 4743 | * Security Updates:: Deploying security fixes quickly. |
401c53c4 | 4744 | * Package Modules:: Packages from the programmer's viewpoint. |
da7cabd4 | 4745 | * Packaging Guidelines:: Growing the distribution. |
401c53c4 | 4746 | * Bootstrapping:: GNU/Linux built from scratch. |
8b315a6d | 4747 | * Porting:: Targeting another platform or kernel. |
401c53c4 LC |
4748 | @end menu |
4749 | ||
4750 | Building this distribution is a cooperative effort, and you are invited | |
081145cf | 4751 | to join! @xref{Contributing}, for information about how you can help. |
401c53c4 | 4752 | |
5af6de3e LC |
4753 | @node System Installation |
4754 | @section System Installation | |
4755 | ||
3ca2731c LC |
4756 | @cindex Guix System Distribution |
4757 | This section explains how to install the Guix System Distribution | |
4758 | on a machine. The Guix package manager can | |
35ed9306 LC |
4759 | also be installed on top of a running GNU/Linux system, |
4760 | @pxref{Installation}. | |
5af6de3e LC |
4761 | |
4762 | @ifinfo | |
4763 | @c This paragraph is for people reading this from tty2 of the | |
4764 | @c installation image. | |
4765 | You're reading this documentation with an Info reader. For details on | |
4766 | how to use it, hit the @key{RET} key (``return'' or ``enter'') on the | |
6621cdb6 | 4767 | link that follows: @pxref{Help,,, info, Info: An Introduction}. Hit |
5af6de3e LC |
4768 | @kbd{l} afterwards to come back here. |
4769 | @end ifinfo | |
4770 | ||
8aaaae38 LC |
4771 | @subsection Limitations |
4772 | ||
4705641f | 4773 | As of version @value{VERSION}, the Guix System Distribution (GuixSD) is |
3ca2731c | 4774 | not production-ready. It may contain bugs and lack important |
8aaaae38 LC |
4775 | features. Thus, if you are looking for a stable production system that |
4776 | respects your freedom as a computer user, a good solution at this point | |
4777 | is to consider @url{http://www.gnu.org/distros/free-distros.html, one of | |
4778 | more established GNU/Linux distributions}. We hope you can soon switch | |
4705641f | 4779 | to the GuixSD without fear, of course. In the meantime, you can |
8aaaae38 LC |
4780 | also keep using your distribution and try out the package manager on top |
4781 | of it (@pxref{Installation}). | |
4782 | ||
4783 | Before you proceed with the installation, be aware of the following | |
4784 | noteworthy limitations applicable to version @value{VERSION}: | |
4785 | ||
4786 | @itemize | |
4787 | @item | |
4788 | The installation process does not include a graphical user interface and | |
4789 | requires familiarity with GNU/Linux (see the following subsections to | |
4790 | get a feel of what that means.) | |
4791 | ||
4792 | @item | |
093ae1be LC |
4793 | The system does not yet provide full GNOME and KDE desktops. Xfce and |
4794 | Enlightenment are available though, if graphical desktop environments | |
4795 | are your thing, as well as a number of X11 window managers. | |
8aaaae38 LC |
4796 | |
4797 | @item | |
dbcb0ab1 | 4798 | Support for the Logical Volume Manager (LVM) is missing. |
8aaaae38 LC |
4799 | |
4800 | @item | |
4801 | Few system services are currently supported out-of-the-box | |
4802 | (@pxref{Services}). | |
4803 | ||
4804 | @item | |
093ae1be | 4805 | More than 2,000 packages are available, but you may |
8aaaae38 LC |
4806 | occasionally find that a useful package is missing. |
4807 | @end itemize | |
4808 | ||
4809 | You've been warned. But more than a disclaimer, this is an invitation | |
4810 | to report issues (and success stories!), and join us in improving it. | |
4811 | @xref{Contributing}, for more info. | |
5af6de3e LC |
4812 | |
4813 | @subsection USB Stick Installation | |
4814 | ||
4815 | An installation image for USB sticks can be downloaded from | |
4705641f | 4816 | @indicateurl{ftp://alpha.gnu.org/gnu/guix/guixsd-usb-install-@value{VERSION}.@var{system}.xz}, |
5af6de3e LC |
4817 | where @var{system} is one of: |
4818 | ||
4819 | @table @code | |
4820 | @item x86_64-linux | |
4821 | for a GNU/Linux system on Intel/AMD-compatible 64-bit CPUs; | |
4822 | ||
4823 | @item i686-linux | |
4824 | for a 32-bit GNU/Linux system on Intel-compatible CPUs. | |
4825 | @end table | |
4826 | ||
4827 | This image contains a single partition with the tools necessary for an | |
4828 | installation. It is meant to be copied @emph{as is} to a large-enough | |
4829 | USB stick. | |
4830 | ||
4831 | To copy the image to a USB stick, follow these steps: | |
4832 | ||
4833 | @enumerate | |
4834 | @item | |
4835 | Decompress the image using the @command{xz} command: | |
4836 | ||
4837 | @example | |
4705641f | 4838 | xz -d guixsd-usb-install-@value{VERSION}.@var{system}.xz |
5af6de3e LC |
4839 | @end example |
4840 | ||
4841 | @item | |
4842 | Insert a USB stick of 1@tie{}GiB or more in your machine, and determine | |
4843 | its device name. Assuming that USB stick is known as @file{/dev/sdX}, | |
4844 | copy the image with: | |
4845 | ||
4846 | @example | |
4705641f | 4847 | dd if=guixsd-usb-install-@value{VERSION}.x86_64 of=/dev/sdX |
5af6de3e LC |
4848 | @end example |
4849 | ||
4850 | Access to @file{/dev/sdX} usually requires root privileges. | |
4851 | @end enumerate | |
4852 | ||
4853 | Once this is done, you should be able to reboot the system and boot from | |
4854 | the USB stick. The latter usually requires you to get in the BIOS' boot | |
4855 | menu, where you can choose to boot from the USB stick. | |
4856 | ||
4857 | @subsection Preparing for Installation | |
4858 | ||
4859 | Once you have successfully booted the image on the USB stick, you should | |
4860 | end up with a root prompt. Several console TTYs are configured and can | |
4861 | be used to run commands as root. TTY2 shows this documentation, | |
4862 | browsable using the Info reader commands (@pxref{Help,,, info, Info: An | |
4863 | Introduction}). | |
4864 | ||
4865 | To install the system, you would: | |
4866 | ||
4867 | @enumerate | |
4868 | ||
4869 | @item | |
152dd61c LC |
4870 | Configure the network, by running @command{ifconfig eno1 up && dhclient |
4871 | eno1} (to get an automatically assigned IP address from the wired | |
4872 | network interface controller@footnote{ | |
95c559c1 LC |
4873 | @c http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c#n20 |
4874 | The name @code{eno1} is for the first on-board Ethernet controller. The | |
4875 | interface name for an Ethernet controller that is in the first slot of | |
4876 | the first PCI bus, for instance, would be @code{enp1s0}. Use | |
4877 | @command{ifconfig -a} to list all the available network interfaces.}), | |
4878 | or using the @command{ifconfig} command. | |
5af6de3e LC |
4879 | |
4880 | The system automatically loads drivers for your network interface | |
4881 | controllers. | |
4882 | ||
4883 | Setting up network access is almost always a requirement because the | |
4884 | image does not contain all the software and tools that may be needed. | |
4885 | ||
4886 | @item | |
4887 | Unless this has already been done, you must partition and format the | |
4888 | target partitions. | |
4889 | ||
7ab44369 LC |
4890 | Preferably, assign partitions a label so that you can easily and |
4891 | reliably refer to them in @code{file-system} declarations (@pxref{File | |
4892 | Systems}). This is typically done using the @code{-L} option of | |
4893 | @command{mkfs.ext4} and related commands. | |
4894 | ||
5af6de3e | 4895 | The installation image includes Parted (@pxref{Overview,,, parted, GNU |
b419c7f5 LC |
4896 | Parted User Manual}), @command{fdisk}, Cryptsetup/LUKS for disk |
4897 | encryption, and e2fsprogs, the suite of tools to manipulate | |
4898 | ext2/ext3/ext4 file systems. | |
5af6de3e | 4899 | |
83a17b62 LC |
4900 | @item |
4901 | Once that is done, mount the target root partition under @file{/mnt}. | |
4902 | ||
4903 | @item | |
4904 | Lastly, run @code{deco start cow-store /mnt}. | |
4905 | ||
4906 | This will make @file{/gnu/store} copy-on-write, such that packages added | |
4907 | to it during the installation phase will be written to the target disk | |
4908 | rather than kept in memory. | |
4909 | ||
5af6de3e LC |
4910 | @end enumerate |
4911 | ||
5af6de3e LC |
4912 | |
4913 | @subsection Proceeding with the Installation | |
4914 | ||
4915 | With the target partitions ready, you now have to edit a file and | |
4916 | provide the declaration of the operating system to be installed. To | |
4917 | that end, the installation system comes with two text editors: GNU nano | |
4918 | (@pxref{Top,,, nano, GNU nano Manual}), and GNU Zile, an Emacs clone. | |
4919 | It is better to store that file on the target root file system, say, as | |
4920 | @file{/mnt/etc/config.scm}. | |
4921 | ||
dd51caac LC |
4922 | @xref{Using the Configuration System}, for examples of operating system |
4923 | configurations. These examples are available under | |
4924 | @file{/etc/configuration} in the installation image, so you can copy | |
4925 | them and use them as a starting point for your own configuration. | |
5af6de3e | 4926 | |
dd51caac LC |
4927 | Once you are done preparing the configuration file, the new system must |
4928 | be initialized (remember that the target root file system is mounted | |
4929 | under @file{/mnt}): | |
5af6de3e LC |
4930 | |
4931 | @example | |
4932 | guix system init /mnt/etc/config.scm /mnt | |
4933 | @end example | |
4934 | ||
4935 | @noindent | |
4936 | This will copy all the necessary files, and install GRUB on | |
4937 | @file{/dev/sdX}, unless you pass the @option{--no-grub} option. For | |
6621cdb6 | 4938 | more information, @pxref{Invoking guix system}. This command may trigger |
5af6de3e LC |
4939 | downloads or builds of missing packages, which can take some time. |
4940 | ||
1bd4e6db LC |
4941 | Once that command has completed---and hopefully succeeded!---you can run |
4942 | @command{reboot} and boot into the new system. The @code{root} password | |
4943 | in the new system is initially empty; other users' passwords need to be | |
4944 | initialized by running the @command{passwd} command as @code{root}, | |
4945 | unless your configuration specifies otherwise | |
4946 | (@pxref{user-account-password, user account passwords}). | |
4947 | ||
4948 | Join us on @code{#guix} on the Freenode IRC network or on | |
5af6de3e LC |
4949 | @file{guix-devel@@gnu.org} to share your experience---good or not so |
4950 | good. | |
4951 | ||
4952 | @subsection Building the Installation Image | |
4953 | ||
4954 | The installation image described above was built using the @command{guix | |
4955 | system} command, specifically: | |
4956 | ||
4957 | @example | |
8a225c66 | 4958 | guix system disk-image --image-size=850MiB gnu/system/install.scm |
5af6de3e LC |
4959 | @end example |
4960 | ||
4961 | @xref{Invoking guix system}, for more information. See | |
4962 | @file{gnu/system/install.scm} in the source tree for more information | |
4963 | about the installation image. | |
4964 | ||
cf4a9129 LC |
4965 | @node System Configuration |
4966 | @section System Configuration | |
b208a005 | 4967 | |
cf4a9129 | 4968 | @cindex system configuration |
3ca2731c | 4969 | The Guix System Distribution supports a consistent whole-system configuration |
cf4a9129 LC |
4970 | mechanism. By that we mean that all aspects of the global system |
4971 | configuration---such as the available system services, timezone and | |
4972 | locale settings, user accounts---are declared in a single place. Such | |
4973 | a @dfn{system configuration} can be @dfn{instantiated}---i.e., effected. | |
91ef73d4 | 4974 | |
cf4a9129 LC |
4975 | One of the advantages of putting all the system configuration under the |
4976 | control of Guix is that it supports transactional system upgrades, and | |
4977 | makes it possible to roll-back to a previous system instantiation, | |
4978 | should something go wrong with the new one (@pxref{Features}). Another | |
4979 | one is that it makes it easy to replicate the exact same configuration | |
4980 | across different machines, or at different points in time, without | |
4981 | having to resort to additional administration tools layered on top of | |
4982 | the system's own tools. | |
4983 | @c Yes, we're talking of Puppet, Chef, & co. here. ↑ | |
91ef73d4 | 4984 | |
cf4a9129 LC |
4985 | This section describes this mechanism. First we focus on the system |
4986 | administrator's viewpoint---explaining how the system is configured and | |
4987 | instantiated. Then we show how this mechanism can be extended, for | |
4988 | instance to support new system services. | |
91ef73d4 | 4989 | |
cf4a9129 LC |
4990 | @menu |
4991 | * Using the Configuration System:: Customizing your GNU system. | |
7313a52e | 4992 | * operating-system Reference:: Detail of operating-system declarations. |
cf4a9129 | 4993 | * File Systems:: Configuring file system mounts. |
510f9d86 | 4994 | * Mapped Devices:: Block device extra processing. |
cf4a9129 | 4995 | * User Accounts:: Specifying user accounts. |
598e19dc | 4996 | * Locales:: Language and cultural convention settings. |
cf4a9129 | 4997 | * Services:: Specifying system services. |
0ae8c15a | 4998 | * Setuid Programs:: Programs running with root privileges. |
efb5e833 | 4999 | * X.509 Certificates:: Authenticating HTTPS servers. |
996ed739 | 5000 | * Name Service Switch:: Configuring libc's name service switch. |
fd1b1fa2 | 5001 | * Initial RAM Disk:: Linux-Libre bootstrapping. |
88faf933 | 5002 | * GRUB Configuration:: Configuring the boot loader. |
cf4a9129 LC |
5003 | * Invoking guix system:: Instantiating a system configuration. |
5004 | * Defining Services:: Adding new service definitions. | |
5005 | @end menu | |
91ef73d4 | 5006 | |
cf4a9129 LC |
5007 | @node Using the Configuration System |
5008 | @subsection Using the Configuration System | |
64d76fa6 | 5009 | |
cf4a9129 LC |
5010 | The operating system is configured by providing an |
5011 | @code{operating-system} declaration in a file that can then be passed to | |
5012 | the @command{guix system} command (@pxref{Invoking guix system}). A | |
5013 | simple setup, with the default system services, the default Linux-Libre | |
5014 | kernel, initial RAM disk, and boot loader looks like this: | |
91ef73d4 | 5015 | |
cf4a9129 LC |
5016 | @findex operating-system |
5017 | @lisp | |
dd51caac | 5018 | @include os-config-bare-bones.texi |
cf4a9129 | 5019 | @end lisp |
401c53c4 | 5020 | |
cf4a9129 LC |
5021 | This example should be self-describing. Some of the fields defined |
5022 | above, such as @code{host-name} and @code{bootloader}, are mandatory. | |
5023 | Others, such as @code{packages} and @code{services}, can be omitted, in | |
5024 | which case they get a default value. | |
e7f34eb0 | 5025 | |
cf4a9129 LC |
5026 | @vindex %base-packages |
5027 | The @code{packages} field lists | |
5028 | packages that will be globally visible on the system, for all user | |
5029 | accounts---i.e., in every user's @code{PATH} environment variable---in | |
5030 | addition to the per-user profiles (@pxref{Invoking guix package}). The | |
5031 | @var{%base-packages} variable provides all the tools one would expect | |
5032 | for basic user and administrator tasks---including the GNU Core | |
5033 | Utilities, the GNU Networking Utilities, the GNU Zile lightweight text | |
5034 | editor, @command{find}, @command{grep}, etc. The example above adds | |
5035 | Emacs to those, taken from the @code{(gnu packages emacs)} module | |
5036 | (@pxref{Package Modules}). | |
e7f34eb0 | 5037 | |
cf4a9129 LC |
5038 | @vindex %base-services |
5039 | The @code{services} field lists @dfn{system services} to be made | |
5040 | available when the system starts (@pxref{Services}). | |
5041 | The @code{operating-system} declaration above specifies that, in | |
5042 | addition to the basic services, we want the @command{lshd} secure shell | |
5043 | daemon listening on port 2222, and allowing remote @code{root} logins | |
5044 | (@pxref{Invoking lshd,,, lsh, GNU lsh Manual}). Under the hood, | |
5045 | @code{lsh-service} arranges so that @code{lshd} is started with the | |
5046 | right command-line options, possibly with supporting configuration files | |
7313a52e LC |
5047 | generated as needed (@pxref{Defining Services}). @xref{operating-system |
5048 | Reference}, for details about the available @code{operating-system} | |
5049 | fields. | |
a1ba8475 | 5050 | |
dd51caac LC |
5051 | The configuration for a typical ``desktop'' usage, with the X11 display |
5052 | server, a desktop environment, network management, an SSH server, and | |
5053 | more, would look like this: | |
5054 | ||
5055 | @lisp | |
5056 | @include os-config-desktop.texi | |
5057 | @end lisp | |
5058 | ||
5059 | @xref{Desktop Services}, for the exact list of services provided by | |
efb5e833 LC |
5060 | @var{%desktop-services}. @xref{X.509 Certificates}, for background |
5061 | information about the @code{nss-certs} package that is used here. | |
dd51caac | 5062 | |
cf4a9129 LC |
5063 | Assuming the above snippet is stored in the @file{my-system-config.scm} |
5064 | file, the @command{guix system reconfigure my-system-config.scm} command | |
5065 | instantiates that configuration, and makes it the default GRUB boot | |
5066 | entry (@pxref{Invoking guix system}). The normal way to change the | |
5067 | system's configuration is by updating this file and re-running the | |
5068 | @command{guix system} command. | |
b81e1947 | 5069 | |
cf4a9129 LC |
5070 | At the Scheme level, the bulk of an @code{operating-system} declaration |
5071 | is instantiated with the following monadic procedure (@pxref{The Store | |
5072 | Monad}): | |
b81e1947 | 5073 | |
cf4a9129 LC |
5074 | @deffn {Monadic Procedure} operating-system-derivation os |
5075 | Return a derivation that builds @var{os}, an @code{operating-system} | |
5076 | object (@pxref{Derivations}). | |
b81e1947 | 5077 | |
cf4a9129 LC |
5078 | The output of the derivation is a single directory that refers to all |
5079 | the packages, configuration files, and other supporting files needed to | |
5080 | instantiate @var{os}. | |
5081 | @end deffn | |
b81e1947 | 5082 | |
7313a52e LC |
5083 | @node operating-system Reference |
5084 | @subsection @code{operating-system} Reference | |
5085 | ||
5086 | This section summarizes all the options available in | |
5087 | @code{operating-system} declarations (@pxref{Using the Configuration | |
5088 | System}). | |
5089 | ||
5090 | @deftp {Data Type} operating-system | |
5091 | This is the data type representing an operating system configuration. | |
5092 | By that, we mean all the global system configuration, not per-user | |
5093 | configuration (@pxref{Using the Configuration System}). | |
5094 | ||
5095 | @table @asis | |
5096 | @item @code{kernel} (default: @var{linux-libre}) | |
fbb25e56 | 5097 | The package object of the operating system kernel to use@footnote{Currently |
7313a52e LC |
5098 | only the Linux-libre kernel is supported. In the future, it will be |
5099 | possible to use the GNU@tie{}Hurd.}. | |
5100 | ||
ee2a6304 LC |
5101 | @item @code{kernel-arguments} (default: @code{'()}) |
5102 | List of strings or gexps representing additional arguments to pass on | |
5103 | the kernel's command-line---e.g., @code{("console=ttyS0")}. | |
5104 | ||
7313a52e | 5105 | @item @code{bootloader} |
88faf933 | 5106 | The system bootloader configuration object. @xref{GRUB Configuration}. |
7313a52e LC |
5107 | |
5108 | @item @code{initrd} (default: @code{base-initrd}) | |
5109 | A two-argument monadic procedure that returns an initial RAM disk for | |
5110 | the Linux kernel. @xref{Initial RAM Disk}. | |
5111 | ||
f34c56be LC |
5112 | @item @code{firmware} (default: @var{%base-firmware}) |
5113 | @cindex firmware | |
5114 | List of firmware packages loadable by the operating system kernel. | |
5115 | ||
5116 | The default includes firmware needed for Atheros-based WiFi devices | |
5117 | (Linux-libre module @code{ath9k}.) | |
5118 | ||
7313a52e LC |
5119 | @item @code{host-name} |
5120 | The host name. | |
5121 | ||
5122 | @item @code{hosts-file} | |
5123 | @cindex hosts file | |
24e02c28 | 5124 | A file-like object (@pxref{G-Expressions, file-like objects}) for use as |
7313a52e | 5125 | @file{/etc/hosts} (@pxref{Host Names,,, libc, The GNU C Library |
24e02c28 | 5126 | Reference Manual}). The default is a file with entries for |
7313a52e LC |
5127 | @code{localhost} and @var{host-name}. |
5128 | ||
5129 | @item @code{mapped-devices} (default: @code{'()}) | |
5130 | A list of mapped devices. @xref{Mapped Devices}. | |
5131 | ||
5132 | @item @code{file-systems} | |
5133 | A list of file systems. @xref{File Systems}. | |
5134 | ||
5135 | @item @code{swap-devices} (default: @code{'()}) | |
5136 | @cindex swap devices | |
5137 | A list of strings identifying devices to be used for ``swap space'' | |
5138 | (@pxref{Memory Concepts,,, libc, The GNU C Library Reference Manual}). | |
5139 | For example, @code{'("/dev/sda3")}. | |
5140 | ||
bf87f38a | 5141 | @item @code{users} (default: @code{%base-user-accounts}) |
7313a52e LC |
5142 | @itemx @code{groups} (default: @var{%base-groups}) |
5143 | List of user accounts and groups. @xref{User Accounts}. | |
5144 | ||
5145 | @item @code{skeletons} (default: @code{(default-skeletons)}) | |
5146 | A monadic list of pairs of target file name and files. These are the | |
5147 | files that will be used as skeletons as new accounts are created. | |
5148 | ||
5149 | For instance, a valid value may look like this: | |
5150 | ||
5151 | @example | |
5152 | (mlet %store-monad ((bashrc (text-file "bashrc" "\ | |
5153 | export PATH=$HOME/.guix-profile/bin"))) | |
5154 | (return `((".bashrc" ,bashrc)))) | |
5155 | @end example | |
5156 | ||
5157 | @item @code{issue} (default: @var{%default-issue}) | |
5158 | A string denoting the contents of the @file{/etc/issue} file, which is | |
5159 | what displayed when users log in on a text console. | |
5160 | ||
5161 | @item @code{packages} (default: @var{%base-packages}) | |
5162 | The set of packages installed in the global profile, which is accessible | |
5163 | at @file{/run/current-system/profile}. | |
5164 | ||
5165 | The default set includes core utilities, but it is good practice to | |
5166 | install non-core utilities in user profiles (@pxref{Invoking guix | |
5167 | package}). | |
5168 | ||
5169 | @item @code{timezone} | |
5170 | A timezone identifying string---e.g., @code{"Europe/Paris"}. | |
5171 | ||
598e19dc LC |
5172 | @item @code{locale} (default: @code{"en_US.utf8"}) |
5173 | The name of the default locale (@pxref{Locale Names,,, libc, The GNU C | |
5174 | Library Reference Manual}). @xref{Locales}, for more information. | |
5175 | ||
5176 | @item @code{locale-definitions} (default: @var{%default-locale-definitions}) | |
5177 | The list of locale definitions to be compiled and that may be used at | |
5178 | run time. @xref{Locales}. | |
7313a52e | 5179 | |
996ed739 LC |
5180 | @item @code{name-service-switch} (default: @var{%default-nss}) |
5181 | Configuration of libc's name service switch (NSS)---a | |
5182 | @code{<name-service-switch>} object. @xref{Name Service Switch}, for | |
5183 | details. | |
5184 | ||
7313a52e LC |
5185 | @item @code{services} (default: @var{%base-services}) |
5186 | A list of monadic values denoting system services. @xref{Services}. | |
5187 | ||
5188 | @item @code{pam-services} (default: @code{(base-pam-services)}) | |
5189 | @cindex PAM | |
5190 | @cindex pluggable authentication modules | |
5191 | Linux @dfn{pluggable authentication module} (PAM) services. | |
5192 | @c FIXME: Add xref to PAM services section. | |
5193 | ||
5194 | @item @code{setuid-programs} (default: @var{%setuid-programs}) | |
5195 | List of string-valued G-expressions denoting setuid programs. | |
5196 | @xref{Setuid Programs}. | |
5197 | ||
f5a9ffa0 AK |
5198 | @item @code{sudoers-file} (default: @var{%sudoers-specification}) |
5199 | @cindex sudoers file | |
84765839 LC |
5200 | The contents of the @file{/etc/sudoers} file as a file-like object |
5201 | (@pxref{G-Expressions, @code{local-file} and @code{plain-file}}). | |
7313a52e LC |
5202 | |
5203 | This file specifies which users can use the @command{sudo} command, what | |
5204 | they are allowed to do, and what privileges they may gain. The default | |
5205 | is that only @code{root} and members of the @code{wheel} group may use | |
5206 | @code{sudo}. | |
5207 | ||
5208 | @end table | |
5209 | @end deftp | |
5210 | ||
cf4a9129 LC |
5211 | @node File Systems |
5212 | @subsection File Systems | |
b81e1947 | 5213 | |
cf4a9129 LC |
5214 | The list of file systems to be mounted is specified in the |
5215 | @code{file-systems} field of the operating system's declaration | |
5216 | (@pxref{Using the Configuration System}). Each file system is declared | |
5217 | using the @code{file-system} form, like this: | |
b81e1947 LC |
5218 | |
5219 | @example | |
cf4a9129 LC |
5220 | (file-system |
5221 | (mount-point "/home") | |
5222 | (device "/dev/sda3") | |
5223 | (type "ext4")) | |
b81e1947 LC |
5224 | @end example |
5225 | ||
cf4a9129 LC |
5226 | As usual, some of the fields are mandatory---those shown in the example |
5227 | above---while others can be omitted. These are described below. | |
b81e1947 | 5228 | |
cf4a9129 LC |
5229 | @deftp {Data Type} file-system |
5230 | Objects of this type represent file systems to be mounted. They | |
5231 | contain the following members: | |
5ff3c4b8 | 5232 | |
cf4a9129 LC |
5233 | @table @asis |
5234 | @item @code{type} | |
5235 | This is a string specifying the type of the file system---e.g., | |
5236 | @code{"ext4"}. | |
5ff3c4b8 | 5237 | |
cf4a9129 LC |
5238 | @item @code{mount-point} |
5239 | This designates the place where the file system is to be mounted. | |
b81e1947 | 5240 | |
cf4a9129 LC |
5241 | @item @code{device} |
5242 | This names the ``source'' of the file system. By default it is the name | |
5243 | of a node under @file{/dev}, but its meaning depends on the @code{title} | |
5244 | field described below. | |
401c53c4 | 5245 | |
cf4a9129 LC |
5246 | @item @code{title} (default: @code{'device}) |
5247 | This is a symbol that specifies how the @code{device} field is to be | |
5248 | interpreted. | |
401c53c4 | 5249 | |
cf4a9129 LC |
5250 | When it is the symbol @code{device}, then the @code{device} field is |
5251 | interpreted as a file name; when it is @code{label}, then @code{device} | |
5252 | is interpreted as a partition label name; when it is @code{uuid}, | |
5253 | @code{device} is interpreted as a partition unique identifier (UUID). | |
da7cabd4 | 5254 | |
661a1d79 LC |
5255 | UUIDs may be converted from their string representation (as shown by the |
5256 | @command{tune2fs -l} command) using the @code{uuid} form, like this: | |
5257 | ||
5258 | @example | |
5259 | (file-system | |
5260 | (mount-point "/home") | |
5261 | (type "ext4") | |
5262 | (title 'uuid) | |
5263 | (device (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb"))) | |
5264 | @end example | |
5265 | ||
cf4a9129 | 5266 | The @code{label} and @code{uuid} options offer a way to refer to disk |
661a1d79 LC |
5267 | partitions without having to hard-code their actual device |
5268 | name@footnote{Note that, while it is tempting to use | |
5269 | @file{/dev/disk/by-uuid} and similar device names to achieve the same | |
5270 | result, this is not recommended: These special device nodes are created | |
5271 | by the udev daemon and may be unavailable at the time the device is | |
5272 | mounted.}. | |
da7cabd4 | 5273 | |
5f86a66e LC |
5274 | However, when a file system's source is a mapped device (@pxref{Mapped |
5275 | Devices}), its @code{device} field @emph{must} refer to the mapped | |
5276 | device name---e.g., @file{/dev/mapper/root-partition}---and consequently | |
5277 | @code{title} must be set to @code{'device}. This is required so that | |
5278 | the system knows that mounting the file system depends on having the | |
5279 | corresponding device mapping established. | |
5280 | ||
cf4a9129 LC |
5281 | @item @code{flags} (default: @code{'()}) |
5282 | This is a list of symbols denoting mount flags. Recognized flags | |
2c071ce9 LC |
5283 | include @code{read-only}, @code{bind-mount}, @code{no-dev} (disallow |
5284 | access to special files), @code{no-suid} (ignore setuid and setgid | |
5285 | bits), and @code{no-exec} (disallow program execution.) | |
da7cabd4 | 5286 | |
cf4a9129 LC |
5287 | @item @code{options} (default: @code{#f}) |
5288 | This is either @code{#f}, or a string denoting mount options. | |
da7cabd4 | 5289 | |
cf4a9129 LC |
5290 | @item @code{needed-for-boot?} (default: @code{#f}) |
5291 | This Boolean value indicates whether the file system is needed when | |
5292 | booting. If that is true, then the file system is mounted when the | |
5293 | initial RAM disk (initrd) is loaded. This is always the case, for | |
5294 | instance, for the root file system. | |
da7cabd4 | 5295 | |
cf4a9129 LC |
5296 | @item @code{check?} (default: @code{#t}) |
5297 | This Boolean indicates whether the file system needs to be checked for | |
5298 | errors before being mounted. | |
f9cc8971 | 5299 | |
4e469051 LC |
5300 | @item @code{create-mount-point?} (default: @code{#f}) |
5301 | When true, the mount point is created if it does not exist yet. | |
5302 | ||
e51710d1 LC |
5303 | @item @code{dependencies} (default: @code{'()}) |
5304 | This is a list of @code{<file-system>} objects representing file systems | |
5305 | that must be mounted before (and unmounted after) this one. | |
5306 | ||
5307 | As an example, consider a hierarchy of mounts: @file{/sys/fs/cgroup} is | |
5308 | a dependency of @file{/sys/fs/cgroup/cpu} and | |
5309 | @file{/sys/fs/cgroup/memory}. | |
5310 | ||
cf4a9129 LC |
5311 | @end table |
5312 | @end deftp | |
da7cabd4 | 5313 | |
a69576ea LC |
5314 | The @code{(gnu system file-systems)} exports the following useful |
5315 | variables. | |
5316 | ||
5317 | @defvr {Scheme Variable} %base-file-systems | |
5318 | These are essential file systems that are required on normal systems, | |
cc0e575a | 5319 | such as @var{%pseudo-terminal-file-system} and @var{%immutable-store} (see |
3392ce5d LC |
5320 | below.) Operating system declarations should always contain at least |
5321 | these. | |
a69576ea LC |
5322 | @end defvr |
5323 | ||
7f239fd3 LC |
5324 | @defvr {Scheme Variable} %pseudo-terminal-file-system |
5325 | This is the file system to be mounted as @file{/dev/pts}. It supports | |
5326 | @dfn{pseudo-terminals} created @i{via} @code{openpty} and similar | |
5327 | functions (@pxref{Pseudo-Terminals,,, libc, The GNU C Library Reference | |
5328 | Manual}). Pseudo-terminals are used by terminal emulators such as | |
5329 | @command{xterm}. | |
5330 | @end defvr | |
5331 | ||
db17ae5c LC |
5332 | @defvr {Scheme Variable} %shared-memory-file-system |
5333 | This file system is mounted as @file{/dev/shm} and is used to support | |
5334 | memory sharing across processes (@pxref{Memory-mapped I/O, | |
5335 | @code{shm_open},, libc, The GNU C Library Reference Manual}). | |
5336 | @end defvr | |
5337 | ||
3392ce5d LC |
5338 | @defvr {Scheme Variable} %immutable-store |
5339 | This file system performs a read-only ``bind mount'' of | |
5340 | @file{/gnu/store}, making it read-only for all the users including | |
5341 | @code{root}. This prevents against accidental modification by software | |
5342 | running as @code{root} or by system administrators. | |
5343 | ||
5344 | The daemon itself is still able to write to the store: it remounts it | |
5345 | read-write in its own ``name space.'' | |
5346 | @end defvr | |
5347 | ||
a69576ea LC |
5348 | @defvr {Scheme Variable} %binary-format-file-system |
5349 | The @code{binfmt_misc} file system, which allows handling of arbitrary | |
5350 | executable file types to be delegated to user space. This requires the | |
5351 | @code{binfmt.ko} kernel module to be loaded. | |
5352 | @end defvr | |
5353 | ||
5354 | @defvr {Scheme Variable} %fuse-control-file-system | |
5355 | The @code{fusectl} file system, which allows unprivileged users to mount | |
5356 | and unmount user-space FUSE file systems. This requires the | |
5357 | @code{fuse.ko} kernel module to be loaded. | |
5358 | @end defvr | |
5359 | ||
510f9d86 LC |
5360 | @node Mapped Devices |
5361 | @subsection Mapped Devices | |
5362 | ||
5363 | @cindex device mapping | |
5364 | @cindex mapped devices | |
5365 | The Linux kernel has a notion of @dfn{device mapping}: a block device, | |
5366 | such as a hard disk partition, can be @dfn{mapped} into another device, | |
5367 | with additional processing over the data that flows through | |
5368 | it@footnote{Note that the GNU@tie{}Hurd makes no difference between the | |
5369 | concept of a ``mapped device'' and that of a file system: both boil down | |
5370 | to @emph{translating} input/output operations made on a file to | |
5371 | operations on its backing store. Thus, the Hurd implements mapped | |
5372 | devices, like file systems, using the generic @dfn{translator} mechanism | |
5373 | (@pxref{Translators,,, hurd, The GNU Hurd Reference Manual}).}. A | |
5374 | typical example is encryption device mapping: all writes to the mapped | |
5375 | device are encrypted, and all reads are deciphered, transparently. | |
5376 | ||
5377 | Mapped devices are declared using the @code{mapped-device} form: | |
5378 | ||
5379 | @example | |
5380 | (mapped-device | |
5381 | (source "/dev/sda3") | |
5382 | (target "home") | |
5383 | (type luks-device-mapping)) | |
5384 | @end example | |
5385 | ||
5386 | @noindent | |
5387 | @cindex disk encryption | |
5388 | @cindex LUKS | |
5389 | This example specifies a mapping from @file{/dev/sda3} to | |
5390 | @file{/dev/mapper/home} using LUKS---the | |
5391 | @url{http://code.google.com/p/cryptsetup,Linux Unified Key Setup}, a | |
5392 | standard mechanism for disk encryption. The @file{/dev/mapper/home} | |
5393 | device can then be used as the @code{device} of a @code{file-system} | |
5394 | declaration (@pxref{File Systems}). The @code{mapped-device} form is | |
5395 | detailed below. | |
5396 | ||
5397 | @deftp {Data Type} mapped-device | |
5398 | Objects of this type represent device mappings that will be made when | |
5399 | the system boots up. | |
5400 | ||
9cb426b8 LC |
5401 | @table @code |
5402 | @item source | |
510f9d86 LC |
5403 | This string specifies the name of the block device to be mapped, such as |
5404 | @code{"/dev/sda3"}. | |
5405 | ||
9cb426b8 | 5406 | @item target |
510f9d86 LC |
5407 | This string specifies the name of the mapping to be established. For |
5408 | example, specifying @code{"my-partition"} will lead to the creation of | |
5409 | the @code{"/dev/mapper/my-partition"} device. | |
5410 | ||
9cb426b8 | 5411 | @item type |
510f9d86 LC |
5412 | This must be a @code{mapped-device-kind} object, which specifies how |
5413 | @var{source} is mapped to @var{target}. | |
5414 | @end table | |
5415 | @end deftp | |
5416 | ||
5417 | @defvr {Scheme Variable} luks-device-mapping | |
5418 | This defines LUKS block device encryption using the @command{cryptsetup} | |
5419 | command, from the same-named package. This relies on the | |
5420 | @code{dm-crypt} Linux kernel module. | |
5421 | @end defvr | |
5422 | ||
cf4a9129 LC |
5423 | @node User Accounts |
5424 | @subsection User Accounts | |
ee85f3db | 5425 | |
9bea87a5 LC |
5426 | User accounts and groups are entirely managed through the |
5427 | @code{operating-system} declaration. They are specified with the | |
5428 | @code{user-account} and @code{user-group} forms: | |
ee85f3db | 5429 | |
cf4a9129 LC |
5430 | @example |
5431 | (user-account | |
5432 | (name "alice") | |
5433 | (group "users") | |
24e752c0 LC |
5434 | (supplementary-groups '("wheel" ;allow use of sudo, etc. |
5435 | "audio" ;sound card | |
5436 | "video" ;video devices such as webcams | |
5437 | "cdrom")) ;the good ol' CD-ROM | |
cf4a9129 LC |
5438 | (comment "Bob's sister") |
5439 | (home-directory "/home/alice")) | |
5440 | @end example | |
25083588 | 5441 | |
9bea87a5 LC |
5442 | When booting or upon completion of @command{guix system reconfigure}, |
5443 | the system ensures that only the user accounts and groups specified in | |
5444 | the @code{operating-system} declaration exist, and with the specified | |
5445 | properties. Thus, account or group creations or modifications made by | |
5446 | directly invoking commands such as @command{useradd} are lost upon | |
5447 | reconfiguration or reboot. This ensures that the system remains exactly | |
5448 | as declared. | |
5449 | ||
cf4a9129 LC |
5450 | @deftp {Data Type} user-account |
5451 | Objects of this type represent user accounts. The following members may | |
5452 | be specified: | |
ee85f3db | 5453 | |
cf4a9129 LC |
5454 | @table @asis |
5455 | @item @code{name} | |
5456 | The name of the user account. | |
ee85f3db | 5457 | |
cf4a9129 LC |
5458 | @item @code{group} |
5459 | This is the name (a string) or identifier (a number) of the user group | |
5460 | this account belongs to. | |
ee85f3db | 5461 | |
cf4a9129 LC |
5462 | @item @code{supplementary-groups} (default: @code{'()}) |
5463 | Optionally, this can be defined as a list of group names that this | |
5464 | account belongs to. | |
ee85f3db | 5465 | |
cf4a9129 LC |
5466 | @item @code{uid} (default: @code{#f}) |
5467 | This is the user ID for this account (a number), or @code{#f}. In the | |
5468 | latter case, a number is automatically chosen by the system when the | |
5469 | account is created. | |
ee85f3db | 5470 | |
cf4a9129 LC |
5471 | @item @code{comment} (default: @code{""}) |
5472 | A comment about the account, such as the account's owner full name. | |
c8c871d1 | 5473 | |
cf4a9129 LC |
5474 | @item @code{home-directory} |
5475 | This is the name of the home directory for the account. | |
ee85f3db | 5476 | |
cf4a9129 LC |
5477 | @item @code{shell} (default: Bash) |
5478 | This is a G-expression denoting the file name of a program to be used as | |
5479 | the shell (@pxref{G-Expressions}). | |
ee85f3db | 5480 | |
cf4a9129 LC |
5481 | @item @code{system?} (default: @code{#f}) |
5482 | This Boolean value indicates whether the account is a ``system'' | |
5483 | account. System accounts are sometimes treated specially; for instance, | |
5484 | graphical login managers do not list them. | |
ee85f3db | 5485 | |
1bd4e6db | 5486 | @anchor{user-account-password} |
cf4a9129 | 5487 | @item @code{password} (default: @code{#f}) |
eb59595c LC |
5488 | You would normally leave this field to @code{#f}, initialize user |
5489 | passwords as @code{root} with the @command{passwd} command, and then let | |
9bea87a5 LC |
5490 | users change it with @command{passwd}. Passwords set with |
5491 | @command{passwd} are of course preserved across reboot and | |
5492 | reconfiguration. | |
eb59595c LC |
5493 | |
5494 | If you @emph{do} want to have a preset password for an account, then | |
5495 | this field must contain the encrypted password, as a string. | |
5d1f1177 LC |
5496 | @xref{crypt,,, libc, The GNU C Library Reference Manual}, for more information |
5497 | on password encryption, and @ref{Encryption,,, guile, GNU Guile Reference | |
eb59595c | 5498 | Manual}, for information on Guile's @code{crypt} procedure. |
c8c871d1 | 5499 | |
cf4a9129 LC |
5500 | @end table |
5501 | @end deftp | |
ee85f3db | 5502 | |
cf4a9129 | 5503 | User group declarations are even simpler: |
ee85f3db | 5504 | |
cf4a9129 LC |
5505 | @example |
5506 | (user-group (name "students")) | |
5507 | @end example | |
ee85f3db | 5508 | |
cf4a9129 LC |
5509 | @deftp {Data Type} user-group |
5510 | This type is for, well, user groups. There are just a few fields: | |
af8a56b8 | 5511 | |
cf4a9129 LC |
5512 | @table @asis |
5513 | @item @code{name} | |
5514 | The group's name. | |
ee85f3db | 5515 | |
cf4a9129 LC |
5516 | @item @code{id} (default: @code{#f}) |
5517 | The group identifier (a number). If @code{#f}, a new number is | |
5518 | automatically allocated when the group is created. | |
ee85f3db | 5519 | |
c8fa3426 LC |
5520 | @item @code{system?} (default: @code{#f}) |
5521 | This Boolean value indicates whether the group is a ``system'' group. | |
5522 | System groups have low numerical IDs. | |
5523 | ||
cf4a9129 LC |
5524 | @item @code{password} (default: @code{#f}) |
5525 | What, user groups can have a password? Well, apparently yes. Unless | |
5526 | @code{#f}, this field specifies the group's password. | |
ee85f3db | 5527 | |
cf4a9129 LC |
5528 | @end table |
5529 | @end deftp | |
401c53c4 | 5530 | |
cf4a9129 LC |
5531 | For convenience, a variable lists all the basic user groups one may |
5532 | expect: | |
401c53c4 | 5533 | |
cf4a9129 LC |
5534 | @defvr {Scheme Variable} %base-groups |
5535 | This is the list of basic user groups that users and/or packages expect | |
5536 | to be present on the system. This includes groups such as ``root'', | |
5537 | ``wheel'', and ``users'', as well as groups used to control access to | |
5538 | specific devices such as ``audio'', ``disk'', and ``cdrom''. | |
5539 | @end defvr | |
401c53c4 | 5540 | |
bf87f38a LC |
5541 | @defvr {Scheme Variable} %base-user-accounts |
5542 | This is the list of basic system accounts that programs may expect to | |
5543 | find on a GNU/Linux system, such as the ``nobody'' account. | |
5544 | ||
5545 | Note that the ``root'' account is not included here. It is a | |
5546 | special-case and is automatically added whether or not it is specified. | |
5547 | @end defvr | |
5548 | ||
598e19dc LC |
5549 | @node Locales |
5550 | @subsection Locales | |
5551 | ||
5552 | @cindex locale | |
5553 | A @dfn{locale} defines cultural conventions for a particular language | |
5554 | and region of the world (@pxref{Locales,,, libc, The GNU C Library | |
5555 | Reference Manual}). Each locale has a name that typically has the form | |
b2636518 | 5556 | @code{@var{language}_@var{territory}.@var{codeset}}---e.g., |
598e19dc LC |
5557 | @code{fr_LU.utf8} designates the locale for the French language, with |
5558 | cultural conventions from Luxembourg, and using the UTF-8 encoding. | |
5559 | ||
5560 | @cindex locale definition | |
5561 | Usually, you will want to specify the default locale for the machine | |
5562 | using the @code{locale} field of the @code{operating-system} declaration | |
5563 | (@pxref{operating-system Reference, @code{locale}}). | |
5564 | ||
5565 | That locale must be among the @dfn{locale definitions} that are known to | |
5566 | the system---and these are specified in the @code{locale-definitions} | |
5567 | slot of @code{operating-system}. The default value includes locale | |
5568 | definition for some widely used locales, but not for all the available | |
5569 | locales, in order to save space. | |
5570 | ||
5571 | If the locale specified in the @code{locale} field is not among the | |
5572 | definitions listed in @code{locale-definitions}, @command{guix system} | |
5573 | raises an error. In that case, you should add the locale definition to | |
5574 | the @code{locale-definitions} field. For instance, to add the North | |
5575 | Frisian locale for Germany, the value of that field may be: | |
5576 | ||
5577 | @example | |
5578 | (cons (locale-definition | |
5579 | (name "fy_DE.utf8") (source "fy_DE")) | |
5580 | %default-locale-definitions) | |
5581 | @end example | |
5582 | ||
5583 | Likewise, to save space, one might want @code{locale-definitions} to | |
5584 | list only the locales that are actually used, as in: | |
5585 | ||
5586 | @example | |
5587 | (list (locale-definition | |
5588 | (name "ja_JP.eucjp") (source "ja_JP") | |
5589 | (charset "EUC-JP"))) | |
5590 | @end example | |
5591 | ||
5c3c1427 LC |
5592 | @vindex LOCPATH |
5593 | The compiled locale definitions are available at | |
5594 | @file{/run/current-system/locale}, which is the default location where | |
5595 | the GNU@tie{}libc looks for locale data. This can be overridden using | |
5596 | the @code{LOCPATH} environment variable (@pxref{locales-and-locpath, | |
5597 | @code{LOCPATH} and locale packages}). | |
5598 | ||
598e19dc LC |
5599 | The @code{locale-definition} form is provided by the @code{(gnu system |
5600 | locale)} module. Details are given below. | |
5601 | ||
5602 | @deftp {Data Type} locale-definition | |
5603 | This is the data type of a locale definition. | |
5604 | ||
5605 | @table @asis | |
5606 | ||
5607 | @item @code{name} | |
5608 | The name of the locale. @xref{Locale Names,,, libc, The GNU C Library | |
5609 | Reference Manual}, for more information on locale names. | |
5610 | ||
5611 | @item @code{source} | |
5612 | The name of the source for that locale. This is typically the | |
5613 | @code{@var{language}_@var{territory}} part of the locale name. | |
5614 | ||
5615 | @item @code{charset} (default: @code{"UTF-8"}) | |
5616 | The ``character set'' or ``code set'' for that locale, | |
5617 | @uref{http://www.iana.org/assignments/character-sets, as defined by | |
5618 | IANA}. | |
5619 | ||
5620 | @end table | |
5621 | @end deftp | |
5622 | ||
5623 | @defvr {Scheme Variable} %default-locale-definitions | |
b2636518 LC |
5624 | An arbitrary list of commonly used UTF-8 locales, used as the default |
5625 | value of the @code{locale-definitions} field of @code{operating-system} | |
598e19dc | 5626 | declarations. |
b2636518 LC |
5627 | |
5628 | @cindex locale name | |
5629 | @cindex normalized codeset in locale names | |
5630 | These locale definitions use the @dfn{normalized codeset} for the part | |
5631 | that follows the dot in the name (@pxref{Using gettextized software, | |
5632 | normalized codeset,, libc, The GNU C Library Reference Manual}). So for | |
5633 | instance it has @code{uk_UA.utf8} but @emph{not}, say, | |
5634 | @code{uk_UA.UTF-8}. | |
598e19dc | 5635 | @end defvr |
401c53c4 | 5636 | |
cf4a9129 LC |
5637 | @node Services |
5638 | @subsection Services | |
401c53c4 | 5639 | |
cf4a9129 LC |
5640 | @cindex system services |
5641 | An important part of preparing an @code{operating-system} declaration is | |
5642 | listing @dfn{system services} and their configuration (@pxref{Using the | |
5643 | Configuration System}). System services are typically daemons launched | |
5644 | when the system boots, or other actions needed at that time---e.g., | |
d8b94dbd LC |
5645 | configuring network access. |
5646 | ||
5647 | Services are managed by GNU@tie{}dmd (@pxref{Introduction,,, dmd, GNU | |
5648 | dmd Manual}). On a running system, the @command{deco} command allows | |
5649 | you to list the available services, show their status, start and stop | |
5650 | them, or do other specific operations (@pxref{Jump Start,,, dmd, GNU dmd | |
5651 | Manual}). For example: | |
5652 | ||
5653 | @example | |
5654 | # deco status dmd | |
5655 | @end example | |
5656 | ||
5657 | The above command, run as @code{root}, lists the currently defined | |
5658 | services. The @command{deco doc} command shows a synopsis of the given | |
5659 | service: | |
5660 | ||
5661 | @example | |
5662 | # deco doc nscd | |
5663 | Run libc's name service cache daemon (nscd). | |
5664 | @end example | |
5665 | ||
5666 | The @command{start}, @command{stop}, and @command{restart} sub-commands | |
5667 | have the effect you would expect. For instance, the commands below stop | |
5668 | the nscd service and restart the Xorg display server: | |
5669 | ||
5670 | @example | |
5671 | # deco stop nscd | |
5672 | Service nscd has been stopped. | |
5673 | # deco restart xorg-server | |
5674 | Service xorg-server has been stopped. | |
5675 | Service xorg-server has been started. | |
5676 | @end example | |
401c53c4 | 5677 | |
cf4a9129 | 5678 | The following sections document the available services, starting with |
d8b94dbd LC |
5679 | the core services, that may be used in an @code{operating-system} |
5680 | declaration. | |
401c53c4 | 5681 | |
cf4a9129 LC |
5682 | @menu |
5683 | * Base Services:: Essential system services. | |
5684 | * Networking Services:: Network setup, SSH daemon, etc. | |
5685 | * X Window:: Graphical display. | |
fe1a39d3 | 5686 | * Desktop Services:: D-Bus and desktop services. |
105369a4 | 5687 | * Database Services:: SQL databases. |
58724c48 | 5688 | * Web Services:: Web servers. |
aa4ed923 | 5689 | * Various Services:: Other services. |
cf4a9129 | 5690 | @end menu |
401c53c4 | 5691 | |
cf4a9129 LC |
5692 | @node Base Services |
5693 | @subsubsection Base Services | |
a1ba8475 | 5694 | |
cf4a9129 LC |
5695 | The @code{(gnu services base)} module provides definitions for the basic |
5696 | services that one expects from the system. The services exported by | |
5697 | this module are listed below. | |
401c53c4 | 5698 | |
cf4a9129 LC |
5699 | @defvr {Scheme Variable} %base-services |
5700 | This variable contains a list of basic services@footnote{Technically, | |
5701 | this is a list of monadic services. @xref{The Store Monad}.} one would | |
5702 | expect from the system: a login service (mingetty) on each tty, syslogd, | |
5703 | libc's name service cache daemon (nscd), the udev device manager, and | |
5704 | more. | |
401c53c4 | 5705 | |
cf4a9129 LC |
5706 | This is the default value of the @code{services} field of |
5707 | @code{operating-system} declarations. Usually, when customizing a | |
5708 | system, you will want to append services to @var{%base-services}, like | |
5709 | this: | |
401c53c4 | 5710 | |
cf4a9129 | 5711 | @example |
fa1e31b8 | 5712 | (cons* (avahi-service) (lsh-service) %base-services) |
cf4a9129 LC |
5713 | @end example |
5714 | @end defvr | |
401c53c4 | 5715 | |
cf4a9129 LC |
5716 | @deffn {Monadic Procedure} host-name-service @var{name} |
5717 | Return a service that sets the host name to @var{name}. | |
5718 | @end deffn | |
401c53c4 | 5719 | |
cf4a9129 LC |
5720 | @deffn {Monadic Procedure} mingetty-service @var{tty} [#:motd] @ |
5721 | [#:auto-login #f] [#:login-program] [#:login-pause? #f] @ | |
5722 | [#:allow-empty-passwords? #f] | |
5723 | Return a service to run mingetty on @var{tty}. | |
401c53c4 | 5724 | |
cf4a9129 LC |
5725 | When @var{allow-empty-passwords?} is true, allow empty log-in password. When |
5726 | @var{auto-login} is true, it must be a user name under which to log-in | |
5727 | automatically. @var{login-pause?} can be set to @code{#t} in conjunction with | |
5728 | @var{auto-login}, in which case the user will have to press a key before the | |
5729 | login shell is launched. | |
401c53c4 | 5730 | |
0081410d | 5731 | When true, @var{login-program} is a gexp or a monadic gexp denoting the name |
cf4a9129 LC |
5732 | of the log-in program (the default is the @code{login} program from the Shadow |
5733 | tool suite.) | |
401c53c4 | 5734 | |
cf4a9129 LC |
5735 | @var{motd} is a monadic value containing a text file to use as |
5736 | the ``message of the day''. | |
5737 | @end deffn | |
401c53c4 | 5738 | |
6454b333 LC |
5739 | @cindex name service cache daemon |
5740 | @cindex nscd | |
4aee6e60 LC |
5741 | @deffn {Monadic Procedure} nscd-service [@var{config}] [#:glibc glibc] @ |
5742 | [#:name-services '()] | |
5743 | Return a service that runs libc's name service cache daemon (nscd) with | |
5744 | the given @var{config}---an @code{<nscd-configuration>} object. | |
5745 | Optionally, @code{#:name-services} is a list of packages that provide | |
4c9050c6 LC |
5746 | name service switch (NSS) modules needed by nscd. @xref{Name Service |
5747 | Switch}, for an example. | |
cf4a9129 | 5748 | @end deffn |
401c53c4 | 5749 | |
6454b333 LC |
5750 | @defvr {Scheme Variable} %nscd-default-configuration |
5751 | This is the default @code{<nscd-configuration>} value (see below) used | |
5752 | by @code{nscd-service}. This uses the caches defined by | |
5753 | @var{%nscd-default-caches}; see below. | |
5754 | @end defvr | |
5755 | ||
5756 | @deftp {Data Type} nscd-configuration | |
5757 | This is the type representing the name service cache daemon (nscd) | |
5758 | configuration. | |
5759 | ||
5760 | @table @asis | |
5761 | ||
5762 | @item @code{log-file} (default: @code{"/var/log/nscd.log"}) | |
5763 | Name of nscd's log file. This is where debugging output goes when | |
5764 | @code{debug-level} is strictly positive. | |
5765 | ||
5766 | @item @code{debug-level} (default: @code{0}) | |
5767 | Integer denoting the debugging levels. Higher numbers mean more | |
5768 | debugging output is logged. | |
5769 | ||
5770 | @item @code{caches} (default: @var{%nscd-default-caches}) | |
5771 | List of @code{<nscd-cache>} objects denoting things to be cached; see | |
5772 | below. | |
5773 | ||
5774 | @end table | |
5775 | @end deftp | |
5776 | ||
5777 | @deftp {Data Type} nscd-cache | |
5778 | Data type representing a cache database of nscd and its parameters. | |
5779 | ||
5780 | @table @asis | |
5781 | ||
5782 | @item @code{database} | |
5783 | This is a symbol representing the name of the database to be cached. | |
5784 | Valid values are @code{passwd}, @code{group}, @code{hosts}, and | |
5785 | @code{services}, which designate the corresponding NSS database | |
5786 | (@pxref{NSS Basics,,, libc, The GNU C Library Reference Manual}). | |
5787 | ||
5788 | @item @code{positive-time-to-live} | |
5789 | @itemx @code{negative-time-to-live} (default: @code{20}) | |
5790 | A number representing the number of seconds during which a positive or | |
5791 | negative lookup result remains in cache. | |
5792 | ||
5793 | @item @code{check-files?} (default: @code{#t}) | |
5794 | Whether to check for updates of the files corresponding to | |
5795 | @var{database}. | |
5796 | ||
5797 | For instance, when @var{database} is @code{hosts}, setting this flag | |
5798 | instructs nscd to check for updates in @file{/etc/hosts} and to take | |
5799 | them into account. | |
5800 | ||
5801 | @item @code{persistent?} (default: @code{#t}) | |
5802 | Whether the cache should be stored persistently on disk. | |
5803 | ||
5804 | @item @code{shared?} (default: @code{#t}) | |
5805 | Whether the cache should be shared among users. | |
5806 | ||
5807 | @item @code{max-database-size} (default: 32@tie{}MiB) | |
5808 | Maximum size in bytes of the database cache. | |
5809 | ||
5810 | @c XXX: 'suggested-size' and 'auto-propagate?' seem to be expert | |
5811 | @c settings, so leave them out. | |
5812 | ||
5813 | @end table | |
5814 | @end deftp | |
5815 | ||
5816 | @defvr {Scheme Variable} %nscd-default-caches | |
5817 | List of @code{<nscd-cache>} objects used by default by | |
5818 | @code{nscd-configuration} (see above.) | |
5819 | ||
5820 | It enables persistent and aggressive caching of service and host name | |
5821 | lookups. The latter provides better host name lookup performance, | |
5822 | resilience in the face of unreliable name servers, and also better | |
5823 | privacy---often the result of host name lookups is in local cache, so | |
5824 | external name servers do not even need to be queried. | |
5825 | @end defvr | |
5826 | ||
5827 | ||
1bb76f75 AK |
5828 | @deffn {Monadic Procedure} syslog-service [#:config-file #f] |
5829 | Return a service that runs @code{syslogd}. If configuration file name | |
5830 | @var{config-file} is not specified, use some reasonable default | |
cf4a9129 LC |
5831 | settings. |
5832 | @end deffn | |
401c53c4 | 5833 | |
cf4a9129 LC |
5834 | @deffn {Monadic Procedure} guix-service [#:guix guix] @ |
5835 | [#:builder-group "guixbuild"] [#:build-accounts 10] @ | |
02bb6b45 | 5836 | [#:authorize-hydra-key? #t] [#:use-substitutes? #t] @ |
cf4a9129 LC |
5837 | [#:extra-options '()] |
5838 | Return a service that runs the build daemon from @var{guix}, and has | |
5839 | @var{build-accounts} user accounts available under @var{builder-group}. | |
401c53c4 | 5840 | |
cf4a9129 LC |
5841 | When @var{authorize-hydra-key?} is true, the @code{hydra.gnu.org} public key |
5842 | provided by @var{guix} is authorized upon activation, meaning that substitutes | |
5843 | from @code{hydra.gnu.org} are used by default. | |
401c53c4 | 5844 | |
cf4a9129 LC |
5845 | If @var{use-substitutes?} is false, the daemon is run with |
5846 | @option{--no-substitutes} (@pxref{Invoking guix-daemon, | |
5847 | @option{--no-substitutes}}). | |
401c53c4 | 5848 | |
cf4a9129 LC |
5849 | Finally, @var{extra-options} is a list of additional command-line options |
5850 | passed to @command{guix-daemon}. | |
5851 | @end deffn | |
a1ba8475 | 5852 | |
cf4a9129 LC |
5853 | @deffn {Monadic Procedure} udev-service [#:udev udev] |
5854 | Run @var{udev}, which populates the @file{/dev} directory dynamically. | |
5855 | @end deffn | |
401c53c4 | 5856 | |
5eca9459 AK |
5857 | @deffn {Monadic Procedure} console-keymap-service @var{file} |
5858 | Return a service to load console keymap from @var{file} using | |
5859 | @command{loadkeys} command. | |
5860 | @end deffn | |
5861 | ||
a69576ea | 5862 | |
cf4a9129 LC |
5863 | @node Networking Services |
5864 | @subsubsection Networking Services | |
401c53c4 | 5865 | |
fa1e31b8 | 5866 | The @code{(gnu services networking)} module provides services to configure |
cf4a9129 | 5867 | the network interface. |
a1ba8475 | 5868 | |
a023cca8 LC |
5869 | @cindex DHCP, networking service |
5870 | @deffn {Monadic Procedure} dhcp-client-service [#:dhcp @var{isc-dhcp}] | |
5871 | Return a service that runs @var{dhcp}, a Dynamic Host Configuration | |
5872 | Protocol (DHCP) client, on all the non-loopback network interfaces. | |
5873 | @end deffn | |
5874 | ||
cf4a9129 LC |
5875 | @deffn {Monadic Procedure} static-networking-service @var{interface} @var{ip} @ |
5876 | [#:gateway #f] [#:name-services @code{'()}] | |
5877 | Return a service that starts @var{interface} with address @var{ip}. If | |
5878 | @var{gateway} is true, it must be a string specifying the default network | |
5879 | gateway. | |
5880 | @end deffn | |
8b315a6d | 5881 | |
b7d0c494 MW |
5882 | @cindex wicd |
5883 | @deffn {Monadic Procedure} wicd-service [#:wicd @var{wicd}] | |
5884 | Return a service that runs @url{https://launchpad.net/wicd,Wicd}, a | |
5885 | network manager that aims to simplify wired and wireless networking. | |
5886 | @end deffn | |
5887 | ||
63854bcb LC |
5888 | @deffn {Monadic Procedure} ntp-service [#:ntp @var{ntp}] @ |
5889 | [#:name-service @var{%ntp-servers}] | |
5890 | Return a service that runs the daemon from @var{ntp}, the | |
5891 | @uref{http://www.ntp.org, Network Time Protocol package}. The daemon will | |
5892 | keep the system clock synchronized with that of @var{servers}. | |
5893 | @end deffn | |
5894 | ||
5895 | @defvr {Scheme Variable} %ntp-servers | |
5896 | List of host names used as the default NTP servers. | |
5897 | @end defvr | |
5898 | ||
cf4a9129 LC |
5899 | @deffn {Monadic Procedure} tor-service [#:tor tor] |
5900 | Return a service to run the @uref{https://torproject.org,Tor} daemon. | |
8b315a6d | 5901 | |
cf4a9129 LC |
5902 | The daemon runs with the default settings (in particular the default exit |
5903 | policy) as the @code{tor} unprivileged user. | |
5904 | @end deffn | |
8b315a6d | 5905 | |
4627a464 LC |
5906 | @deffn {Monadic Procedure} bitlbee-service [#:bitlbee bitlbee] @ |
5907 | [#:interface "127.0.0.1"] [#:port 6667] @ | |
5908 | [#:extra-settings ""] | |
5909 | Return a service that runs @url{http://bitlbee.org,BitlBee}, a daemon that | |
5910 | acts as a gateway between IRC and chat networks. | |
5911 | ||
5912 | The daemon will listen to the interface corresponding to the IP address | |
5913 | specified in @var{interface}, on @var{port}. @code{127.0.0.1} means that only | |
5914 | local clients can connect, whereas @code{0.0.0.0} means that connections can | |
5915 | come from any networking interface. | |
5916 | ||
5917 | In addition, @var{extra-settings} specifies a string to append to the | |
5918 | configuration file. | |
5919 | @end deffn | |
5920 | ||
f4391bec | 5921 | Furthermore, @code{(gnu services ssh)} provides the following service. |
8b315a6d | 5922 | |
cf4a9129 | 5923 | @deffn {Monadic Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @ |
5833bf33 | 5924 | [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @ |
cf4a9129 LC |
5925 | [#:allow-empty-passwords? #f] [#:root-login? #f] @ |
5926 | [#:syslog-output? #t] [#:x11-forwarding? #t] @ | |
5927 | [#:tcp/ip-forwarding? #t] [#:password-authentication? #t] @ | |
21cc905a | 5928 | [#:public-key-authentication? #t] [#:initialize? #t] |
cf4a9129 LC |
5929 | Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}. |
5930 | @var{host-key} must designate a file containing the host key, and readable | |
5931 | only by root. | |
72e25e35 | 5932 | |
5833bf33 DP |
5933 | When @var{daemonic?} is true, @command{lshd} will detach from the |
5934 | controlling terminal and log its output to syslogd, unless one sets | |
5935 | @var{syslog-output?} to false. Obviously, it also makes lsh-service | |
5936 | depend on existence of syslogd service. When @var{pid-file?} is true, | |
5937 | @command{lshd} writes its PID to the file called @var{pid-file}. | |
5938 | ||
cf4a9129 LC |
5939 | When @var{initialize?} is true, automatically create the seed and host key |
5940 | upon service activation if they do not exist yet. This may take long and | |
5941 | require interaction. | |
8b315a6d | 5942 | |
20dd519c LC |
5943 | When @var{initialize?} is false, it is up to the user to initialize the |
5944 | randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create | |
5945 | a key pair with the private key stored in file @var{host-key} (@pxref{lshd | |
5946 | basics,,, lsh, LSH Manual}). | |
5947 | ||
cf4a9129 LC |
5948 | When @var{interfaces} is empty, lshd listens for connections on all the |
5949 | network interfaces; otherwise, @var{interfaces} must be a list of host names | |
5950 | or addresses. | |
9bf3c1a7 | 5951 | |
20dd519c LC |
5952 | @var{allow-empty-passwords?} specifies whether to accept log-ins with empty |
5953 | passwords, and @var{root-login?} specifies whether to accept log-ins as | |
cf4a9129 | 5954 | root. |
4af2447e | 5955 | |
cf4a9129 LC |
5956 | The other options should be self-descriptive. |
5957 | @end deffn | |
4af2447e | 5958 | |
fa0c1d61 LC |
5959 | @defvr {Scheme Variable} %facebook-host-aliases |
5960 | This variable contains a string for use in @file{/etc/hosts} | |
5961 | (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}). Each | |
5962 | line contains a entry that maps a known server name of the Facebook | |
5963 | on-line service---e.g., @code{www.facebook.com}---to the local | |
5964 | host---@code{127.0.0.1} or its IPv6 equivalent, @code{::1}. | |
5965 | ||
5966 | This variable is typically used in the @code{hosts-file} field of an | |
7313a52e LC |
5967 | @code{operating-system} declaration (@pxref{operating-system Reference, |
5968 | @file{/etc/hosts}}): | |
fa0c1d61 LC |
5969 | |
5970 | @example | |
5971 | (use-modules (gnu) (guix)) | |
5972 | ||
5973 | (operating-system | |
5974 | (host-name "mymachine") | |
5975 | ;; ... | |
5976 | (hosts-file | |
5977 | ;; Create a /etc/hosts file with aliases for "localhost" | |
5978 | ;; and "mymachine", as well as for Facebook servers. | |
24e02c28 LC |
5979 | (plain-file "hosts" |
5980 | (string-append (local-host-aliases host-name) | |
5981 | %facebook-host-aliases)))) | |
fa0c1d61 LC |
5982 | @end example |
5983 | ||
5984 | This mechanism can prevent programs running locally, such as Web | |
5985 | browsers, from accessing Facebook. | |
5986 | @end defvr | |
5987 | ||
965a7332 LC |
5988 | The @code{(gnu services avahi)} provides the following definition. |
5989 | ||
5990 | @deffn {Monadic Procedure} avahi-service [#:avahi @var{avahi}] @ | |
5991 | [#:host-name #f] [#:publish? #t] [#:ipv4? #t] @ | |
5992 | [#:ipv6? #t] [#:wide-area? #f] @ | |
5993 | [#:domains-to-browse '()] | |
5994 | Return a service that runs @command{avahi-daemon}, a system-wide | |
5995 | mDNS/DNS-SD responder that allows for service discovery and | |
5996 | "zero-configuration" host name lookups (see @uref{http://avahi.org/}). | |
5997 | ||
5998 | If @var{host-name} is different from @code{#f}, use that as the host name to | |
5999 | publish for this machine; otherwise, use the machine's actual host name. | |
6000 | ||
6001 | When @var{publish?} is true, publishing of host names and services is allowed; | |
6002 | in particular, avahi-daemon will publish the machine's host name and IP | |
6003 | address via mDNS on the local network. | |
6004 | ||
6005 | When @var{wide-area?} is true, DNS-SD over unicast DNS is enabled. | |
6006 | ||
6007 | Boolean values @var{ipv4?} and @var{ipv6?} determine whether to use IPv4/IPv6 | |
6008 | sockets. | |
6009 | @end deffn | |
6010 | ||
6011 | ||
cf4a9129 LC |
6012 | @node X Window |
6013 | @subsubsection X Window | |
68ad877c | 6014 | |
cf4a9129 LC |
6015 | Support for the X Window graphical display system---specifically |
6016 | Xorg---is provided by the @code{(gnu services xorg)} module. Note that | |
6017 | there is no @code{xorg-service} procedure. Instead, the X server is | |
6018 | started by the @dfn{login manager}, currently SLiM. | |
4af2447e | 6019 | |
cf4a9129 | 6020 | @deffn {Monadic Procedure} slim-service [#:allow-empty-passwords? #f] @ |
0ecc3bf3 LC |
6021 | [#:auto-login? #f] [#:default-user ""] [#:startx] @ |
6022 | [#:theme @var{%default-slim-theme}] @ | |
4bd43bbe | 6023 | [#:theme-name @var{%default-slim-theme-name}] |
cf4a9129 LC |
6024 | Return a service that spawns the SLiM graphical login manager, which in |
6025 | turn starts the X display server with @var{startx}, a command as returned by | |
6026 | @code{xorg-start-command}. | |
4af2447e | 6027 | |
04e4e6ab LC |
6028 | @cindex X session |
6029 | ||
6030 | SLiM automatically looks for session types described by the @file{.desktop} | |
6031 | files in @file{/run/current-system/profile/share/xsessions} and allows users | |
6032 | to choose a session from the log-in screen using @kbd{F1}. Packages such as | |
6033 | @var{xfce}, @var{sawfish}, and @var{ratpoison} provide @file{.desktop} files; | |
6034 | adding them to the system-wide set of packages automatically makes them | |
6035 | available at the log-in screen. | |
6036 | ||
6037 | In addition, @file{~/.xsession} files are honored. When available, | |
6038 | @file{~/.xsession} must be an executable that starts a window manager | |
6039 | and/or other X clients. | |
6040 | ||
cf4a9129 LC |
6041 | When @var{allow-empty-passwords?} is true, allow logins with an empty |
6042 | password. When @var{auto-login?} is true, log in automatically as | |
6043 | @var{default-user}. | |
0ecc3bf3 LC |
6044 | |
6045 | If @var{theme} is @code{#f}, the use the default log-in theme; otherwise | |
6046 | @var{theme} must be a gexp denoting the name of a directory containing the | |
6047 | theme to use. In that case, @var{theme-name} specifies the name of the | |
6048 | theme. | |
cf4a9129 | 6049 | @end deffn |
4af2447e | 6050 | |
0ecc3bf3 LC |
6051 | @defvr {Scheme Variable} %default-theme |
6052 | @defvrx {Scheme Variable} %default-theme-name | |
6053 | The G-Expression denoting the default SLiM theme and its name. | |
6054 | @end defvr | |
6055 | ||
f703413e | 6056 | @deffn {Monadic Procedure} xorg-start-command [#:guile] @ |
d1cdd7ba | 6057 | [#:configuration-file #f] [#:xorg-server @var{xorg-server}] |
f703413e | 6058 | Return a derivation that builds a @var{guile} script to start the X server |
d1cdd7ba LC |
6059 | from @var{xorg-server}. @var{configuration-file} is the server configuration |
6060 | file or a derivation that builds it; when omitted, the result of | |
6061 | @code{xorg-configuration-file} is used. | |
6062 | ||
6063 | Usually the X server is started by a login manager. | |
6064 | @end deffn | |
6065 | ||
6066 | @deffn {Monadic Procedure} xorg-configuration-file @ | |
12422c9d | 6067 | [#:drivers '()] [#:resolutions '()] [#:extra-config '()] |
d1cdd7ba LC |
6068 | Return a configuration file for the Xorg server containing search paths for |
6069 | all the common drivers. | |
f703413e LC |
6070 | |
6071 | @var{drivers} must be either the empty list, in which case Xorg chooses a | |
6072 | graphics driver automatically, or a list of driver names that will be tried in | |
d1cdd7ba | 6073 | this order---e.g., @code{(\"modesetting\" \"vesa\")}. |
d2e59637 LC |
6074 | |
6075 | Likewise, when @var{resolutions} is the empty list, Xorg chooses an | |
6076 | appropriate screen resolution; otherwise, it must be a list of | |
6077 | resolutions---e.g., @code{((1024 768) (640 480))}. | |
12422c9d LC |
6078 | |
6079 | Last, @var{extra-config} is a list of strings or objects appended to the | |
6080 | @code{text-file*} argument list. It is used to pass extra text to be added | |
6081 | verbatim to the configuration file. | |
f703413e | 6082 | @end deffn |
4af2447e | 6083 | |
fe1a39d3 LC |
6084 | @node Desktop Services |
6085 | @subsubsection Desktop Services | |
aa4ed923 | 6086 | |
fe1a39d3 LC |
6087 | The @code{(gnu services desktop)} module provides services that are |
6088 | usually useful in the context of a ``desktop'' setup---that is, on a | |
6089 | machine running a graphical display server, possibly with graphical user | |
6090 | interfaces, etc. | |
aa4ed923 | 6091 | |
4467be21 LC |
6092 | To simplify things, the module defines a variable containing the set of |
6093 | services that users typically expect on a machine with a graphical | |
6094 | environment and networking: | |
6095 | ||
6096 | @defvr {Scheme Variable} %desktop-services | |
6097 | This is a list of services that builds upon @var{%base-services} and | |
6098 | adds or adjust services for a typical ``desktop'' setup. | |
6099 | ||
6100 | In particular, it adds a graphical login manager (@pxref{X Window, | |
6101 | @code{slim-service}}), a network management tool (@pxref{Networking | |
6102 | Services, @code{wicd-service}}), energy and color management services, | |
4650a77e | 6103 | the @code{elogind} login and seat manager, the Polkit privilege service, |
cee32ee4 AW |
6104 | the GeoClue location service, an NTP client (@pxref{Networking |
6105 | Services}), the Avahi daemon, and has the name service switch service | |
6106 | configured to be able to use @code{nss-mdns} (@pxref{Name Service | |
6107 | Switch, mDNS}). | |
4467be21 LC |
6108 | @end defvr |
6109 | ||
6110 | The @var{%desktop-services} variable can be used as the @code{services} | |
6111 | field of an @code{operating-system} declaration (@pxref{operating-system | |
6112 | Reference, @code{services}}). | |
6113 | ||
6114 | The actual service definitions provided by @code{(gnu services desktop)} | |
6115 | are described below. | |
6116 | ||
fe1a39d3 LC |
6117 | @deffn {Monadic Procedure} dbus-service @var{services} @ |
6118 | [#:dbus @var{dbus}] | |
6119 | Return a service that runs the ``system bus'', using @var{dbus}, with | |
6120 | support for @var{services}. | |
aa4ed923 | 6121 | |
fe1a39d3 LC |
6122 | @uref{http://dbus.freedesktop.org/, D-Bus} is an inter-process communication |
6123 | facility. Its system bus is used to allow system services to communicate | |
6124 | and be notified of system-wide events. | |
aa4ed923 | 6125 | |
fe1a39d3 LC |
6126 | @var{services} must be a list of packages that provide an |
6127 | @file{etc/dbus-1/system.d} directory containing additional D-Bus configuration | |
6128 | and policy files. For example, to allow avahi-daemon to use the system bus, | |
6129 | @var{services} must be equal to @code{(list avahi)}. | |
aa4ed923 AK |
6130 | @end deffn |
6131 | ||
4650a77e AW |
6132 | @deffn {Monadic Procedure} elogind-service @ |
6133 | [#:elogind @var{elogind}] [#:config @var{config}] | |
6134 | Return a service that runs the @code{elogind} login and | |
6135 | seat management daemon. @uref{https://github.com/andywingo/elogind, | |
6136 | Elogind} exposes a D-Bus interface that can be used to know which users | |
6137 | are logged in, know what kind of sessions they have open, suspend the | |
6138 | system, inhibit system suspend, reboot the system, and other tasks. | |
6139 | ||
6140 | Elogind handles most system-level power events for a computer, for | |
6141 | example suspending the system when a lid is closed, or shutting it down | |
6142 | when the power button is pressed. | |
6143 | ||
6144 | The @var{config} keyword argument specifies the configuration for | |
6145 | elogind, and should be the result of a @code{(elogind-configuration | |
6146 | (@var{parameter} @var{value})...)} invocation. Available parameters and | |
6147 | their default values are: | |
6148 | ||
6149 | @table @code | |
6150 | @item kill-user-processes? | |
6151 | @code{#f} | |
6152 | @item kill-only-users | |
6153 | @code{()} | |
6154 | @item kill-exclude-users | |
6155 | @code{("root")} | |
6156 | @item inhibit-delay-max-seconds | |
6157 | @code{5} | |
6158 | @item handle-power-key | |
6159 | @code{poweroff} | |
6160 | @item handle-suspend-key | |
6161 | @code{suspend} | |
6162 | @item handle-hibernate-key | |
6163 | @code{hibernate} | |
6164 | @item handle-lid-switch | |
6165 | @code{suspend} | |
6166 | @item handle-lid-switch-docked | |
6167 | @code{ignore} | |
6168 | @item power-key-ignore-inhibited? | |
6169 | @code{#f} | |
6170 | @item suspend-key-ignore-inhibited? | |
6171 | @code{#f} | |
6172 | @item hibernate-key-ignore-inhibited? | |
6173 | @code{#f} | |
6174 | @item lid-switch-ignore-inhibited? | |
6175 | @code{#t} | |
6176 | @item holdoff-timeout-seconds | |
6177 | @code{30} | |
6178 | @item idle-action | |
6179 | @code{ignore} | |
6180 | @item idle-action-seconds | |
6181 | @code{(* 30 60)} | |
6182 | @item runtime-directory-size-percent | |
6183 | @code{10} | |
6184 | @item runtime-directory-size | |
6185 | @code{#f} | |
6186 | @item remove-ipc? | |
6187 | @code{#t} | |
6188 | @item suspend-state | |
6189 | @code{("mem" "standby" "freeze")} | |
6190 | @item suspend-mode | |
6191 | @code{()} | |
6192 | @item hibernate-state | |
6193 | @code{("disk")} | |
6194 | @item hibernate-mode | |
6195 | @code{("platform" "shutdown")} | |
6196 | @item hybrid-sleep-state | |
6197 | @code{("disk")} | |
6198 | @item hybrid-sleep-mode | |
6199 | @code{("suspend" "platform" "shutdown")} | |
6200 | @end table | |
6201 | @end deffn | |
6202 | ||
6203 | @deffn {Monadic Procedure} polkit-service @ | |
6204 | [#:polkit @var{polkit}] | |
6205 | Return a service that runs the Polkit privilege manager. | |
6206 | @uref{http://www.freedesktop.org/wiki/Software/polkit/, Polkit} allows | |
6207 | system administrators to grant access to privileged operations in a | |
6208 | structured way. For example, polkit rules can allow a logged-in user | |
6209 | whose session is active to shut down the machine, if there are no other | |
6210 | users active. | |
6211 | @end deffn | |
6212 | ||
be234128 AW |
6213 | @deffn {Monadic Procedure} upower-service [#:upower @var{upower}] @ |
6214 | [#:watts-up-pro? #f] @ | |
6215 | [#:poll-batteries? #t] @ | |
6216 | [#:ignore-lid? #f] @ | |
6217 | [#:use-percentage-for-policy? #f] @ | |
6218 | [#:percentage-low 10] @ | |
6219 | [#:percentage-critical 3] @ | |
6220 | [#:percentage-action 2] @ | |
6221 | [#:time-low 1200] @ | |
6222 | [#:time-critical 300] @ | |
6223 | [#:time-action 120] @ | |
6224 | [#:critical-power-action 'hybrid-sleep] | |
6225 | Return a service that runs @uref{http://upower.freedesktop.org/, | |
6226 | @command{upowerd}}, a system-wide monitor for power consumption and battery | |
6227 | levels, with the given configuration settings. It implements the | |
6228 | @code{org.freedesktop.UPower} D-Bus interface, and is notably used by | |
6229 | GNOME. | |
6230 | @end deffn | |
6231 | ||
7ce597ff AW |
6232 | @deffn {Monadic Procedure} colord-service [#:colord @var{colord}] |
6233 | Return a service that runs @command{colord}, a system service with a D-Bus | |
6234 | interface to manage the color profiles of input and output devices such as | |
6235 | screens and scanners. It is notably used by the GNOME Color Manager graphical | |
6236 | tool. See @uref{http://www.freedesktop.org/software/colord/, the colord web | |
6237 | site} for more information. | |
6238 | @end deffn | |
6239 | ||
cee32ee4 AW |
6240 | @deffn {Scheme Procedure} geoclue-application name [#:allowed? #t] [#:system? #f] [#:users '()] |
6241 | Return an configuration allowing an application to access GeoClue | |
6242 | location data. @var{name} is the Desktop ID of the application, without | |
6243 | the @code{.desktop} part. If @var{allowed?} is true, the application | |
6244 | will have access to location information by default. The boolean | |
6245 | @var{system?} value indicates that an application is a system component | |
6246 | or not. Finally @var{users} is a list of UIDs of all users for which | |
6247 | this application is allowed location info access. An empty users list | |
6248 | means that all users are allowed. | |
6249 | @end deffn | |
6250 | ||
6251 | @defvr {Scheme Variable} %standard-geoclue-applications | |
6252 | The standard list of well-known GeoClue application configurations, | |
6253 | granting authority to GNOME's date-and-time utility to ask for the | |
6254 | current location in order to set the time zone, and allowing the Firefox | |
6255 | (IceCat) and Epiphany web browsers to request location information. | |
6256 | Firefox and Epiphany both query the user before allowing a web page to | |
6257 | know the user's location. | |
6258 | @end defvr | |
6259 | ||
6260 | @deffn {Monadic Procedure} geoclue-service [#:colord @var{colord}] @ | |
6261 | [#:whitelist '()] @ | |
6262 | [#:wifi-geolocation-url "https://location.services.mozilla.com/v1/geolocate?key=geoclue"] @ | |
6263 | [#:submit-data? #f] | |
6264 | [#:wifi-submission-url "https://location.services.mozilla.com/v1/submit?key=geoclue"] @ | |
6265 | [#:submission-nick "geoclue"] @ | |
6266 | [#:applications %standard-geoclue-applications] | |
6267 | Return a service that runs the GeoClue location service. This service | |
6268 | provides a D-Bus interface to allow applications to request access to a | |
6269 | user's physical location, and optionally to add information to online | |
6270 | location databases. See | |
6271 | @uref{https://wiki.freedesktop.org/www/Software/GeoClue/, the GeoClue | |
6272 | web site} for more information. | |
6273 | @end deffn | |
6274 | ||
105369a4 DT |
6275 | @node Database Services |
6276 | @subsubsection Database Services | |
6277 | ||
6278 | The @code{(gnu services databases)} module provides the following service. | |
6279 | ||
6280 | @deffn {Monadic Procedure} postgresql-service [#:postgresql postgresql] @ | |
6281 | [#:config-file] [#:data-directory ``/var/lib/postgresql/data''] | |
6282 | Return a service that runs @var{postgresql}, the PostgreSQL database | |
6283 | server. | |
6284 | ||
6285 | The PostgreSQL daemon loads its runtime configuration from | |
6286 | @var{config-file} and stores the database cluster in | |
6287 | @var{data-directory}. | |
6288 | @end deffn | |
fe1a39d3 | 6289 | |
58724c48 DT |
6290 | @node Web Services |
6291 | @subsubsection Web Services | |
6292 | ||
6293 | The @code{(gnu services web)} module provides the following service: | |
6294 | ||
6295 | @deffn {Monadic Procedure} nginx-service [#:nginx nginx] @ | |
6296 | [#:log-directory ``/var/log/nginx''] @ | |
6297 | [#:run-directory ``/var/run/nginx''] @ | |
6298 | [#:config-file] | |
6299 | ||
6300 | Return a service that runs @var{nginx}, the nginx web server. | |
6301 | ||
6302 | The nginx daemon loads its runtime configuration from @var{config-file}. | |
6303 | Log files are written to @var{log-directory} and temporary runtime data | |
6304 | files are written to @var{run-directory}. For proper operation, these | |
6305 | arguments should match what is in @var{config-file} to ensure that the | |
6306 | directories are created when the service is activated. | |
6307 | ||
6308 | @end deffn | |
6309 | ||
fe1a39d3 LC |
6310 | @node Various Services |
6311 | @subsubsection Various Services | |
6312 | ||
6313 | The @code{(gnu services lirc)} module provides the following service. | |
6314 | ||
6315 | @deffn {Monadic Procedure} lirc-service [#:lirc lirc] @ | |
6316 | [#:device #f] [#:driver #f] [#:config-file #f] @ | |
6317 | [#:extra-options '()] | |
6318 | Return a service that runs @url{http://www.lirc.org,LIRC}, a daemon that | |
6319 | decodes infrared signals from remote controls. | |
6320 | ||
6321 | Optionally, @var{device}, @var{driver} and @var{config-file} | |
6322 | (configuration file name) may be specified. See @command{lircd} manual | |
6323 | for details. | |
6324 | ||
6325 | Finally, @var{extra-options} is a list of additional command-line options | |
6326 | passed to @command{lircd}. | |
6327 | @end deffn | |
6328 | ||
6329 | ||
0ae8c15a LC |
6330 | @node Setuid Programs |
6331 | @subsection Setuid Programs | |
6332 | ||
6333 | @cindex setuid programs | |
6334 | Some programs need to run with ``root'' privileges, even when they are | |
6335 | launched by unprivileged users. A notorious example is the | |
4d40227c LC |
6336 | @command{passwd} program, which users can run to change their |
6337 | password, and which needs to access the @file{/etc/passwd} and | |
0ae8c15a LC |
6338 | @file{/etc/shadow} files---something normally restricted to root, for |
6339 | obvious security reasons. To address that, these executables are | |
6340 | @dfn{setuid-root}, meaning that they always run with root privileges | |
6341 | (@pxref{How Change Persona,,, libc, The GNU C Library Reference Manual}, | |
6342 | for more info about the setuid mechanisms.) | |
6343 | ||
6344 | The store itself @emph{cannot} contain setuid programs: that would be a | |
6345 | security issue since any user on the system can write derivations that | |
6346 | populate the store (@pxref{The Store}). Thus, a different mechanism is | |
6347 | used: instead of changing the setuid bit directly on files that are in | |
6348 | the store, we let the system administrator @emph{declare} which programs | |
6349 | should be setuid root. | |
6350 | ||
6351 | The @code{setuid-programs} field of an @code{operating-system} | |
6352 | declaration contains a list of G-expressions denoting the names of | |
6353 | programs to be setuid-root (@pxref{Using the Configuration System}). | |
6354 | For instance, the @command{passwd} program, which is part of the Shadow | |
6355 | package, can be designated by this G-expression (@pxref{G-Expressions}): | |
6356 | ||
6357 | @example | |
6358 | #~(string-append #$shadow "/bin/passwd") | |
6359 | @end example | |
6360 | ||
6361 | A default set of setuid programs is defined by the | |
6362 | @code{%setuid-programs} variable of the @code{(gnu system)} module. | |
6363 | ||
6364 | @defvr {Scheme Variable} %setuid-programs | |
6365 | A list of G-expressions denoting common programs that are setuid-root. | |
6366 | ||
6367 | The list includes commands such as @command{passwd}, @command{ping}, | |
6368 | @command{su}, and @command{sudo}. | |
6369 | @end defvr | |
6370 | ||
6371 | Under the hood, the actual setuid programs are created in the | |
6372 | @file{/run/setuid-programs} directory at system activation time. The | |
6373 | files in this directory refer to the ``real'' binaries, which are in the | |
6374 | store. | |
6375 | ||
efb5e833 LC |
6376 | @node X.509 Certificates |
6377 | @subsection X.509 Certificates | |
6378 | ||
6379 | @cindex HTTPS, certificates | |
6380 | @cindex X.509 certificates | |
6381 | @cindex TLS | |
6382 | Web servers available over HTTPS (that is, HTTP over the transport-layer | |
6383 | security mechanism, TLS) send client programs an @dfn{X.509 certificate} | |
6384 | that the client can then use to @emph{authenticate} the server. To do | |
6385 | that, clients verify that the server's certificate is signed by a | |
6386 | so-called @dfn{certificate authority} (CA). But to verify the CA's | |
6387 | signature, clients must have first acquired the CA's certificate. | |
6388 | ||
6389 | Web browsers such as GNU@tie{}IceCat include their own set of CA | |
6390 | certificates, such that they are able to verify CA signatures | |
6391 | out-of-the-box. | |
6392 | ||
6393 | However, most other programs that can talk HTTPS---@command{wget}, | |
6394 | @command{git}, @command{w3m}, etc.---need to be told where CA | |
6395 | certificates can be found. | |
6396 | ||
6397 | @cindex @code{nss-certs} | |
6398 | In GuixSD, this is done by adding a package that provides certificates | |
6399 | to the @code{packages} field of the @code{operating-system} declaration | |
6400 | (@pxref{operating-system Reference}). GuixSD includes one such package, | |
6401 | @code{nss-certs}, which is a set of CA certificates provided as part of | |
6402 | Mozilla's Network Security Services. | |
6403 | ||
6404 | Note that it is @emph{not} part of @var{%base-packages}, so you need to | |
6405 | explicitly add it. The @file{/etc/ssl/certs} directory, which is where | |
6406 | most applications and libraries look for certificates by default, points | |
6407 | to the certificates installed globally. | |
6408 | ||
6409 | Unprivileged users can also install their own certificate package in | |
6410 | their profile. A number of environment variables need to be defined so | |
6411 | that applications and libraries know where to find them. Namely, the | |
6412 | OpenSSL library honors the @code{SSL_CERT_DIR} and @code{SSL_CERT_FILE} | |
6413 | variables. Some applications add their own environment variables; for | |
6414 | instance, the Git version control system honors the certificate bundle | |
6415 | pointed to by the @code{GIT_SSL_CAINFO} environment variable. | |
6416 | ||
6417 | ||
996ed739 LC |
6418 | @node Name Service Switch |
6419 | @subsection Name Service Switch | |
6420 | ||
6421 | @cindex name service switch | |
6422 | @cindex NSS | |
6423 | The @code{(gnu system nss)} module provides bindings to the | |
6424 | configuration file of libc's @dfn{name service switch} or @dfn{NSS} | |
6425 | (@pxref{NSS Configuration File,,, libc, The GNU C Library Reference | |
6426 | Manual}). In a nutshell, the NSS is a mechanism that allows libc to be | |
6427 | extended with new ``name'' lookup methods for system databases, which | |
6428 | includes host names, service names, user accounts, and more (@pxref{Name | |
6429 | Service Switch, System Databases and Name Service Switch,, libc, The GNU | |
6430 | C Library Reference Manual}). | |
6431 | ||
6432 | The NSS configuration specifies, for each system database, which lookup | |
6433 | method is to be used, and how the various methods are chained | |
6434 | together---for instance, under which circumstances NSS should try the | |
6435 | next method in the list. The NSS configuration is given in the | |
6436 | @code{name-service-switch} field of @code{operating-system} declarations | |
6437 | (@pxref{operating-system Reference, @code{name-service-switch}}). | |
6438 | ||
4c9050c6 LC |
6439 | @cindex nss-mdns |
6440 | @cindex .local, host name lookup | |
996ed739 | 6441 | As an example, the declaration below configures the NSS to use the |
4c9050c6 LC |
6442 | @uref{http://0pointer.de/lennart/projects/nss-mdns/, @code{nss-mdns} |
6443 | back-end}, which supports host name lookups over multicast DNS (mDNS) | |
6444 | for host names ending in @code{.local}: | |
996ed739 LC |
6445 | |
6446 | @example | |
6447 | (name-service-switch | |
6448 | (hosts (list %files ;first, check /etc/hosts | |
6449 | ||
6450 | ;; If the above did not succeed, try | |
6451 | ;; with 'mdns_minimal'. | |
6452 | (name-service | |
6453 | (name "mdns_minimal") | |
6454 | ||
6455 | ;; 'mdns_minimal' is authoritative for | |
6456 | ;; '.local'. When it returns "not found", | |
6457 | ;; no need to try the next methods. | |
6458 | (reaction (lookup-specification | |
6459 | (not-found => return)))) | |
6460 | ||
6461 | ;; Then fall back to DNS. | |
6462 | (name-service | |
6463 | (name "dns")) | |
6464 | ||
6465 | ;; Finally, try with the "full" 'mdns'. | |
6466 | (name-service | |
6467 | (name "mdns"))))) | |
6468 | @end example | |
6469 | ||
15137a29 LC |
6470 | Don't worry: the @code{%mdns-host-lookup-nss} variable (see below) |
6471 | contains this configuration, so you won't have to type it if all you | |
6472 | want is to have @code{.local} host lookup working. | |
6473 | ||
4c9050c6 LC |
6474 | Note that, in this case, in addition to setting the |
6475 | @code{name-service-switch} of the @code{operating-system} declaration, | |
6476 | @code{nscd-service} must be told where to find the @code{nss-mdns} | |
6477 | shared library (@pxref{Base Services, @code{nscd-service}}). Since the | |
6478 | @code{nscd} service is part of @var{%base-services}, you may want to | |
6479 | customize it by adding this snippet in the operating system | |
6480 | configuration file: | |
6481 | ||
6482 | @example | |
6483 | (use-modules (guix) (gnu)) | |
6484 | ||
6485 | (define %my-base-services | |
6486 | ;; Replace the default nscd service with one that knows | |
6487 | ;; about nss-mdns. | |
6488 | (map (lambda (mservice) | |
6489 | ;; "Bind" the MSERVICE monadic value to inspect it. | |
6490 | (mlet %store-monad ((service mservice)) | |
6491 | (if (member 'nscd (service-provision service)) | |
6492 | (nscd-service (nscd-configuration) | |
6493 | #:name-services (list nss-mdns)) | |
6494 | mservice))) | |
6495 | %base-services)) | |
6496 | @end example | |
6497 | ||
6498 | @noindent | |
6499 | @dots{} and then refer to @var{%my-base-services} instead of | |
6500 | @var{%base-services} in the @code{operating-system} declaration. | |
15137a29 | 6501 | Lastly, this relies on the availability of the Avahi service |
965a7332 | 6502 | (@pxref{Networking Services, @code{avahi-service}}). |
15137a29 LC |
6503 | |
6504 | For convenience, the following variables provide typical NSS | |
6505 | configurations. | |
6506 | ||
6507 | @defvr {Scheme Variable} %default-nss | |
6508 | This is the default name service switch configuration, a | |
6509 | @code{name-service-switch} object. | |
6510 | @end defvr | |
6511 | ||
6512 | @defvr {Scheme Variable} %mdns-host-lookup-nss | |
6513 | This is the name service switch configuration with support for host name | |
6514 | lookup over multicast DNS (mDNS) for host names ending in @code{.local}. | |
6515 | @end defvr | |
4c9050c6 | 6516 | |
996ed739 LC |
6517 | The reference for name service switch configuration is given below. It |
6518 | is a direct mapping of the C library's configuration file format, so | |
6519 | please refer to the C library manual for more information (@pxref{NSS | |
6520 | Configuration File,,, libc, The GNU C Library Reference Manual}). | |
6521 | Compared to libc's NSS configuration file format, it has the advantage | |
6522 | not only of adding this warm parenthetic feel that we like, but also | |
6523 | static checks: you'll know about syntax errors and typos as soon as you | |
6524 | run @command{guix system}. | |
6525 | ||
996ed739 LC |
6526 | @deftp {Data Type} name-service-switch |
6527 | ||
6528 | This is the data type representation the configuration of libc's name | |
6529 | service switch (NSS). Each field below represents one of the supported | |
6530 | system databases. | |
6531 | ||
6532 | @table @code | |
6533 | @item aliases | |
6534 | @itemx ethers | |
6535 | @itemx group | |
6536 | @itemx gshadow | |
6537 | @itemx hosts | |
6538 | @itemx initgroups | |
6539 | @itemx netgroup | |
6540 | @itemx networks | |
6541 | @itemx password | |
6542 | @itemx public-key | |
6543 | @itemx rpc | |
6544 | @itemx services | |
6545 | @itemx shadow | |
6546 | The system databases handled by the NSS. Each of these fields must be a | |
6547 | list of @code{<name-service>} objects (see below.) | |
6548 | @end table | |
6549 | @end deftp | |
6550 | ||
6551 | @deftp {Data Type} name-service | |
6552 | ||
6553 | This is the data type representing an actual name service and the | |
6554 | associated lookup action. | |
6555 | ||
6556 | @table @code | |
6557 | @item name | |
6558 | A string denoting the name service (@pxref{Services in the NSS | |
6559 | configuration,,, libc, The GNU C Library Reference Manual}). | |
6560 | ||
4aee6e60 LC |
6561 | Note that name services listed here must be visible to nscd. This is |
6562 | achieved by passing the @code{#:name-services} argument to | |
6563 | @code{nscd-service} the list of packages providing the needed name | |
6564 | services (@pxref{Base Services, @code{nscd-service}}). | |
6565 | ||
996ed739 LC |
6566 | @item reaction |
6567 | An action specified using the @code{lookup-specification} macro | |
6568 | (@pxref{Actions in the NSS configuration,,, libc, The GNU C Library | |
6569 | Reference Manual}). For example: | |
6570 | ||
6571 | @example | |
6572 | (lookup-specification (unavailable => continue) | |
6573 | (success => return)) | |
6574 | @end example | |
6575 | @end table | |
6576 | @end deftp | |
0ae8c15a | 6577 | |
fd1b1fa2 LC |
6578 | @node Initial RAM Disk |
6579 | @subsection Initial RAM Disk | |
6580 | ||
6581 | @cindex initial RAM disk (initrd) | |
6582 | @cindex initrd (initial RAM disk) | |
6583 | For bootstrapping purposes, the Linux-Libre kernel is passed an | |
6584 | @dfn{initial RAM disk}, or @dfn{initrd}. An initrd contains a temporary | |
6585 | root file system, as well as an initialization script. The latter is | |
6586 | responsible for mounting the real root file system, and for loading any | |
6587 | kernel modules that may be needed to achieve that. | |
6588 | ||
6589 | The @code{initrd} field of an @code{operating-system} declaration allows | |
6590 | you to specify which initrd you would like to use. The @code{(gnu | |
6591 | system linux-initrd)} module provides two ways to build an initrd: the | |
6592 | high-level @code{base-initrd} procedure, and the low-level | |
6593 | @code{expression->initrd} procedure. | |
6594 | ||
6595 | The @code{base-initrd} procedure is intended to cover most common uses. | |
6596 | For example, if you want to add a bunch of kernel modules to be loaded | |
6597 | at boot time, you can define the @code{initrd} field of the operating | |
6598 | system declaration like this: | |
6599 | ||
6600 | @example | |
52ac153e | 6601 | (initrd (lambda (file-systems . rest) |
027981d6 LC |
6602 | ;; Create a standard initrd that has modules "foo.ko" |
6603 | ;; and "bar.ko", as well as their dependencies, in | |
6604 | ;; addition to the modules available by default. | |
52ac153e | 6605 | (apply base-initrd file-systems |
027981d6 | 6606 | #:extra-modules '("foo" "bar") |
52ac153e | 6607 | rest))) |
fd1b1fa2 LC |
6608 | @end example |
6609 | ||
52ac153e LC |
6610 | The @code{base-initrd} procedure also handles common use cases that |
6611 | involves using the system as a QEMU guest, or as a ``live'' system whose | |
6612 | root file system is volatile. | |
fd1b1fa2 LC |
6613 | |
6614 | @deffn {Monadic Procedure} base-initrd @var{file-systems} @ | |
6615 | [#:qemu-networking? #f] [#:virtio? #f] [#:volatile-root? #f] @ | |
52ac153e | 6616 | [#:extra-modules '()] [#:mapped-devices '()] |
fd1b1fa2 LC |
6617 | Return a monadic derivation that builds a generic initrd. @var{file-systems} is |
6618 | a list of file-systems to be mounted by the initrd, possibly in addition to | |
6619 | the root file system specified on the kernel command line via @code{--root}. | |
52ac153e LC |
6620 | @var{mapped-devices} is a list of device mappings to realize before |
6621 | @var{file-systems} are mounted (@pxref{Mapped Devices}). | |
fd1b1fa2 LC |
6622 | |
6623 | When @var{qemu-networking?} is true, set up networking with the standard QEMU | |
6624 | parameters. When @var{virtio?} is true, load additional modules so the initrd can | |
6625 | be used as a QEMU guest with para-virtualized I/O drivers. | |
6626 | ||
6627 | When @var{volatile-root?} is true, the root file system is writable but any changes | |
6628 | to it are lost. | |
6629 | ||
6630 | The initrd is automatically populated with all the kernel modules necessary | |
6631 | for @var{file-systems} and for the given options. However, additional kernel | |
6632 | modules can be listed in @var{extra-modules}. They will be added to the initrd, and | |
6633 | loaded at boot time in the order in which they appear. | |
6634 | @end deffn | |
6635 | ||
6636 | Needless to say, the initrds we produce and use embed a | |
6637 | statically-linked Guile, and the initialization program is a Guile | |
6638 | program. That gives a lot of flexibility. The | |
6639 | @code{expression->initrd} procedure builds such an initrd, given the | |
6640 | program to run in that initrd. | |
6641 | ||
6642 | @deffn {Monadic Procedure} expression->initrd @var{exp} @ | |
6643 | [#:guile %guile-static-stripped] [#:name "guile-initrd"] @ | |
42d10464 | 6644 | [#:modules '()] |
fd1b1fa2 LC |
6645 | Return a derivation that builds a Linux initrd (a gzipped cpio archive) |
6646 | containing @var{guile} and that evaluates @var{exp}, a G-expression, | |
df650fa8 LC |
6647 | upon booting. All the derivations referenced by @var{exp} are |
6648 | automatically copied to the initrd. | |
fd1b1fa2 | 6649 | |
42d10464 LC |
6650 | @var{modules} is a list of Guile module names to be embedded in the |
6651 | initrd. | |
fd1b1fa2 LC |
6652 | @end deffn |
6653 | ||
88faf933 LC |
6654 | @node GRUB Configuration |
6655 | @subsection GRUB Configuration | |
6656 | ||
6657 | @cindex GRUB | |
6658 | @cindex boot loader | |
6659 | ||
6660 | The operating system uses GNU@tie{}GRUB as its boot loader | |
6661 | (@pxref{Overview, overview of GRUB,, grub, GNU GRUB Manual}). It is | |
6662 | configured using @code{grub-configuration} declarations. This data type | |
6663 | is exported by the @code{(gnu system grub)} module, and described below. | |
6664 | ||
6665 | @deftp {Data Type} grub-configuration | |
6666 | The type of a GRUB configuration declaration. | |
6667 | ||
6668 | @table @asis | |
6669 | ||
6670 | @item @code{device} | |
6671 | This is a string denoting the boot device. It must be a device name | |
6672 | understood by the @command{grub-install} command, such as | |
6673 | @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub, | |
6674 | GNU GRUB Manual}). | |
6675 | ||
6676 | @item @code{menu-entries} (default: @code{()}) | |
6677 | A possibly empty list of @code{menu-entry} objects (see below), denoting | |
6678 | entries to appear in the GRUB boot menu, in addition to the current | |
6679 | system entry and the entry pointing to previous system generations. | |
6680 | ||
6681 | @item @code{default-entry} (default: @code{0}) | |
6682 | The index of the default boot menu entry. Index 0 is for the current | |
6683 | system's entry. | |
6684 | ||
6685 | @item @code{timeout} (default: @code{5}) | |
6686 | The number of seconds to wait for keyboard input before booting. Set to | |
6687 | 0 to boot immediately, and to -1 to wait indefinitely. | |
6688 | ||
6689 | @item @code{theme} (default: @var{%default-theme}) | |
6690 | The @code{grub-theme} object describing the theme to use. | |
6691 | @end table | |
6692 | ||
6693 | @end deftp | |
6694 | ||
6695 | Should you want to list additional boot menu entries @i{via} the | |
6696 | @code{menu-entries} field above, you will need to create them with the | |
6697 | @code{menu-entry} form: | |
6698 | ||
6699 | @deftp {Data Type} menu-entry | |
6700 | The type of an entry in the GRUB boot menu. | |
6701 | ||
6702 | @table @asis | |
6703 | ||
6704 | @item @code{label} | |
35ed9306 | 6705 | The label to show in the menu---e.g., @code{"GNU"}. |
88faf933 LC |
6706 | |
6707 | @item @code{linux} | |
6708 | The Linux kernel to boot. | |
6709 | ||
6710 | @item @code{linux-arguments} (default: @code{()}) | |
6711 | The list of extra Linux kernel command-line arguments---e.g., | |
6712 | @code{("console=ttyS0")}. | |
6713 | ||
6714 | @item @code{initrd} | |
6715 | A G-Expression or string denoting the file name of the initial RAM disk | |
6716 | to use (@pxref{G-Expressions}). | |
6717 | ||
6718 | @end table | |
6719 | @end deftp | |
6720 | ||
6721 | @c FIXME: Write documentation once it's stable. | |
6722 | Themes are created using the @code{grub-theme} form, which is not | |
6723 | documented yet. | |
6724 | ||
6725 | @defvr {Scheme Variable} %default-theme | |
6726 | This is the default GRUB theme used by the operating system, with a | |
6727 | fancy background image displaying the GNU and Guix logos. | |
6728 | @end defvr | |
6729 | ||
6730 | ||
cf4a9129 LC |
6731 | @node Invoking guix system |
6732 | @subsection Invoking @code{guix system} | |
0918e64a | 6733 | |
cf4a9129 LC |
6734 | Once you have written an operating system declaration, as seen in the |
6735 | previous section, it can be @dfn{instantiated} using the @command{guix | |
6736 | system} command. The synopsis is: | |
4af2447e | 6737 | |
cf4a9129 LC |
6738 | @example |
6739 | guix system @var{options}@dots{} @var{action} @var{file} | |
6740 | @end example | |
4af2447e | 6741 | |
cf4a9129 LC |
6742 | @var{file} must be the name of a file containing an |
6743 | @code{operating-system} declaration. @var{action} specifies how the | |
6744 | operating system is instantiate. Currently the following values are | |
6745 | supported: | |
4af2447e | 6746 | |
cf4a9129 LC |
6747 | @table @code |
6748 | @item reconfigure | |
6749 | Build the operating system described in @var{file}, activate it, and | |
6750 | switch to it@footnote{This action is usable only on systems already | |
6751 | running GNU.}. | |
4af2447e | 6752 | |
cf4a9129 LC |
6753 | This effects all the configuration specified in @var{file}: user |
6754 | accounts, system services, global package list, setuid programs, etc. | |
4af2447e | 6755 | |
cf4a9129 LC |
6756 | It also adds a GRUB menu entry for the new OS configuration, and moves |
6757 | entries for older configurations to a submenu---unless | |
6758 | @option{--no-grub} is passed. | |
4af2447e | 6759 | |
bf2479c7 LC |
6760 | @c The paragraph below refers to the problem discussed at |
6761 | @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>. | |
6762 | It is highly recommended to run @command{guix pull} once before you run | |
6763 | @command{guix system reconfigure} for the first time (@pxref{Invoking | |
6764 | guix pull}). Failing to do that you would see an older version of Guix | |
6765 | once @command{reconfigure} has completed. | |
6766 | ||
cf4a9129 LC |
6767 | @item build |
6768 | Build the operating system's derivation, which includes all the | |
6769 | configuration files and programs needed to boot and run the system. | |
6770 | This action does not actually install anything. | |
113daf62 | 6771 | |
cf4a9129 LC |
6772 | @item init |
6773 | Populate the given directory with all the files necessary to run the | |
6774 | operating system specified in @var{file}. This is useful for first-time | |
4705641f | 6775 | installations of GuixSD. For instance: |
113daf62 LC |
6776 | |
6777 | @example | |
cf4a9129 | 6778 | guix system init my-os-config.scm /mnt |
113daf62 LC |
6779 | @end example |
6780 | ||
cf4a9129 LC |
6781 | copies to @file{/mnt} all the store items required by the configuration |
6782 | specified in @file{my-os-config.scm}. This includes configuration | |
6783 | files, packages, and so on. It also creates other essential files | |
6784 | needed for the system to operate correctly---e.g., the @file{/etc}, | |
6785 | @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file. | |
113daf62 | 6786 | |
cf4a9129 LC |
6787 | This command also installs GRUB on the device specified in |
6788 | @file{my-os-config}, unless the @option{--no-grub} option was passed. | |
113daf62 | 6789 | |
cf4a9129 LC |
6790 | @item vm |
6791 | @cindex virtual machine | |
0276f697 | 6792 | @cindex VM |
cf4a9129 LC |
6793 | Build a virtual machine that contain the operating system declared in |
6794 | @var{file}, and return a script to run that virtual machine (VM). | |
810568b3 | 6795 | Arguments given to the script are passed as is to QEMU. |
113daf62 | 6796 | |
cf4a9129 | 6797 | The VM shares its store with the host system. |
113daf62 | 6798 | |
0276f697 LC |
6799 | Additional file systems can be shared between the host and the VM using |
6800 | the @code{--share} and @code{--expose} command-line options: the former | |
6801 | specifies a directory to be shared with write access, while the latter | |
6802 | provides read-only access to the shared directory. | |
6803 | ||
6804 | The example below creates a VM in which the user's home directory is | |
6805 | accessible read-only, and where the @file{/exchange} directory is a | |
6806 | read-write mapping of the host's @file{$HOME/tmp}: | |
6807 | ||
6808 | @example | |
6809 | guix system vm my-config.scm \ | |
6810 | --expose=$HOME --share=$HOME/tmp=/exchange | |
6811 | @end example | |
6812 | ||
6aa260af LC |
6813 | On GNU/Linux, the default is to boot directly to the kernel; this has |
6814 | the advantage of requiring only a very tiny root disk image since the | |
6815 | host's store can then be mounted. | |
6816 | ||
6817 | The @code{--full-boot} option forces a complete boot sequence, starting | |
6818 | with the bootloader. This requires more disk space since a root image | |
6819 | containing at least the kernel, initrd, and bootloader data files must | |
6820 | be created. The @code{--image-size} option can be used to specify the | |
6821 | image's size. | |
ab11f0be | 6822 | |
cf4a9129 LC |
6823 | @item vm-image |
6824 | @itemx disk-image | |
6825 | Return a virtual machine or disk image of the operating system declared | |
6826 | in @var{file} that stands alone. Use the @option{--image-size} option | |
6827 | to specify the size of the image. | |
113daf62 | 6828 | |
cf4a9129 LC |
6829 | When using @code{vm-image}, the returned image is in qcow2 format, which |
6830 | the QEMU emulator can efficiently use. | |
113daf62 | 6831 | |
cf4a9129 LC |
6832 | When using @code{disk-image}, a raw disk image is produced; it can be |
6833 | copied as is to a USB stick, for instance. Assuming @code{/dev/sdc} is | |
6834 | the device corresponding to a USB stick, one can copy the image on it | |
6835 | using the following command: | |
113daf62 | 6836 | |
cf4a9129 LC |
6837 | @example |
6838 | # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc | |
6839 | @end example | |
113daf62 | 6840 | |
cf4a9129 | 6841 | @end table |
113daf62 | 6842 | |
cf4a9129 LC |
6843 | @var{options} can contain any of the common build options provided by |
6844 | @command{guix build} (@pxref{Invoking guix build}). In addition, | |
6845 | @var{options} can contain one of the following: | |
113daf62 | 6846 | |
cf4a9129 LC |
6847 | @table @option |
6848 | @item --system=@var{system} | |
6849 | @itemx -s @var{system} | |
6850 | Attempt to build for @var{system} instead of the host's system type. | |
6851 | This works as per @command{guix build} (@pxref{Invoking guix build}). | |
113daf62 | 6852 | |
cf4a9129 LC |
6853 | @item --image-size=@var{size} |
6854 | For the @code{vm-image} and @code{disk-image} actions, create an image | |
6855 | of the given @var{size}. @var{size} may be a number of bytes, or it may | |
4a44d7bb LC |
6856 | include a unit as a suffix (@pxref{Block size, size specifications,, |
6857 | coreutils, GNU Coreutils}). | |
db030303 LC |
6858 | |
6859 | @item --on-error=@var{strategy} | |
6860 | Apply @var{strategy} when an error occurs when reading @var{file}. | |
6861 | @var{strategy} may be one of the following: | |
6862 | ||
6863 | @table @code | |
6864 | @item nothing-special | |
6865 | Report the error concisely and exit. This is the default strategy. | |
6866 | ||
6867 | @item backtrace | |
6868 | Likewise, but also display a backtrace. | |
6869 | ||
6870 | @item debug | |
6871 | Report the error and enter Guile's debugger. From there, you can run | |
6872 | commands such as @code{,bt} to get a backtrace, @code{,locals} to | |
6873 | display local variable values, and more generally inspect the program's | |
6874 | state. @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for | |
6875 | a list of available debugging commands. | |
6876 | @end table | |
113daf62 | 6877 | @end table |
113daf62 | 6878 | |
cf4a9129 LC |
6879 | Note that all the actions above, except @code{build} and @code{init}, |
6880 | rely on KVM support in the Linux-Libre kernel. Specifically, the | |
6881 | machine should have hardware virtualization support, the corresponding | |
6882 | KVM kernel module should be loaded, and the @file{/dev/kvm} device node | |
6883 | must exist and be readable and writable by the user and by the daemon's | |
6884 | build users. | |
8451a568 | 6885 | |
cf4a9129 LC |
6886 | @node Defining Services |
6887 | @subsection Defining Services | |
8451a568 | 6888 | |
cf4a9129 LC |
6889 | The @code{(gnu services @dots{})} modules define several procedures that allow |
6890 | users to declare the operating system's services (@pxref{Using the | |
6891 | Configuration System}). These procedures are @emph{monadic | |
6892 | procedures}---i.e., procedures that return a monadic value in the store | |
6893 | monad (@pxref{The Store Monad}). For examples of such procedures, | |
6894 | @xref{Services}. | |
8451a568 | 6895 | |
cf4a9129 LC |
6896 | @cindex service definition |
6897 | The monadic value returned by those procedures is a @dfn{service | |
6898 | definition}---a structure as returned by the @code{service} form. | |
6899 | Service definitions specifies the inputs the service depends on, and an | |
6900 | expression to start and stop the service. Behind the scenes, service | |
6901 | definitions are ``translated'' into the form suitable for the | |
6902 | configuration file of dmd, the init system (@pxref{Services,,, dmd, GNU | |
6903 | dmd Manual}). | |
8451a568 | 6904 | |
cf4a9129 LC |
6905 | As an example, here is what the @code{nscd-service} procedure looks |
6906 | like: | |
8451a568 | 6907 | |
cf4a9129 LC |
6908 | @lisp |
6909 | (define (nscd-service) | |
6910 | (with-monad %store-monad | |
6911 | (return (service | |
6912 | (documentation "Run libc's name service cache daemon.") | |
6913 | (provision '(nscd)) | |
6914 | (activate #~(begin | |
6915 | (use-modules (guix build utils)) | |
6916 | (mkdir-p "/var/run/nscd"))) | |
6917 | (start #~(make-forkexec-constructor | |
6918 | (string-append #$glibc "/sbin/nscd") | |
6919 | "-f" "/dev/null" "--foreground")) | |
6920 | (stop #~(make-kill-destructor)) | |
6921 | (respawn? #f))))) | |
6922 | @end lisp | |
8451a568 | 6923 | |
cf4a9129 LC |
6924 | @noindent |
6925 | The @code{activate}, @code{start}, and @code{stop} fields are G-expressions | |
6926 | (@pxref{G-Expressions}). The @code{activate} field contains a script to | |
6927 | run at ``activation'' time; it makes sure that the @file{/var/run/nscd} | |
6928 | directory exists before @command{nscd} is started. | |
8451a568 | 6929 | |
cf4a9129 LC |
6930 | The @code{start} and @code{stop} fields refer to dmd's facilities to |
6931 | start and stop processes (@pxref{Service De- and Constructors,,, dmd, | |
6932 | GNU dmd Manual}). The @code{provision} field specifies the name under | |
6933 | which this service is known to dmd, and @code{documentation} specifies | |
6934 | on-line documentation. Thus, the commands @command{deco start ncsd}, | |
6935 | @command{deco stop nscd}, and @command{deco doc nscd} will do what you | |
6936 | would expect (@pxref{Invoking deco,,, dmd, GNU dmd Manual}). | |
8451a568 | 6937 | |
8451a568 | 6938 | |
cf4a9129 LC |
6939 | @node Installing Debugging Files |
6940 | @section Installing Debugging Files | |
8451a568 | 6941 | |
cf4a9129 LC |
6942 | @cindex debugging files |
6943 | Program binaries, as produced by the GCC compilers for instance, are | |
6944 | typically written in the ELF format, with a section containing | |
6945 | @dfn{debugging information}. Debugging information is what allows the | |
6946 | debugger, GDB, to map binary code to source code; it is required to | |
6947 | debug a compiled program in good conditions. | |
8451a568 | 6948 | |
cf4a9129 LC |
6949 | The problem with debugging information is that is takes up a fair amount |
6950 | of disk space. For example, debugging information for the GNU C Library | |
6951 | weighs in at more than 60 MiB. Thus, as a user, keeping all the | |
6952 | debugging info of all the installed programs is usually not an option. | |
6953 | Yet, space savings should not come at the cost of an impediment to | |
6954 | debugging---especially in the GNU system, which should make it easier | |
6955 | for users to exert their computing freedom (@pxref{GNU Distribution}). | |
8451a568 | 6956 | |
cf4a9129 LC |
6957 | Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a |
6958 | mechanism that allows users to get the best of both worlds: debugging | |
6959 | information can be stripped from the binaries and stored in separate | |
6960 | files. GDB is then able to load debugging information from those files, | |
6961 | when they are available (@pxref{Separate Debug Files,,, gdb, Debugging | |
6962 | with GDB}). | |
8451a568 | 6963 | |
cf4a9129 LC |
6964 | The GNU distribution takes advantage of this by storing debugging |
6965 | information in the @code{lib/debug} sub-directory of a separate package | |
6966 | output unimaginatively called @code{debug} (@pxref{Packages with | |
6967 | Multiple Outputs}). Users can choose to install the @code{debug} output | |
6968 | of a package when they need it. For instance, the following command | |
6969 | installs the debugging information for the GNU C Library and for GNU | |
6970 | Guile: | |
8451a568 LC |
6971 | |
6972 | @example | |
cf4a9129 | 6973 | guix package -i glibc:debug guile:debug |
8451a568 LC |
6974 | @end example |
6975 | ||
cf4a9129 LC |
6976 | GDB must then be told to look for debug files in the user's profile, by |
6977 | setting the @code{debug-file-directory} variable (consider setting it | |
6978 | from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with | |
6979 | GDB}): | |
8451a568 | 6980 | |
cf4a9129 LC |
6981 | @example |
6982 | (gdb) set debug-file-directory ~/.guix-profile/lib/debug | |
6983 | @end example | |
8451a568 | 6984 | |
cf4a9129 LC |
6985 | From there on, GDB will pick up debugging information from the |
6986 | @code{.debug} files under @file{~/.guix-profile/lib/debug}. | |
8451a568 | 6987 | |
cf4a9129 LC |
6988 | In addition, you will most likely want GDB to be able to show the source |
6989 | code being debugged. To do that, you will have to unpack the source | |
6990 | code of the package of interest (obtained with @code{guix build | |
6991 | --source}, @pxref{Invoking guix build}), and to point GDB to that source | |
6992 | directory using the @code{directory} command (@pxref{Source Path, | |
6993 | @code{directory},, gdb, Debugging with GDB}). | |
8451a568 | 6994 | |
cf4a9129 LC |
6995 | @c XXX: keep me up-to-date |
6996 | The @code{debug} output mechanism in Guix is implemented by the | |
6997 | @code{gnu-build-system} (@pxref{Build Systems}). Currently, it is | |
6998 | opt-in---debugging information is available only for those packages | |
6999 | whose definition explicitly declares a @code{debug} output. This may be | |
7000 | changed to opt-out in the future, if our build farm servers can handle | |
7001 | the load. To check whether a package has a @code{debug} output, use | |
7002 | @command{guix package --list-available} (@pxref{Invoking guix package}). | |
8451a568 | 7003 | |
8451a568 | 7004 | |
05962f29 LC |
7005 | @node Security Updates |
7006 | @section Security Updates | |
7007 | ||
843858b8 LC |
7008 | @quotation Note |
7009 | As of version @value{VERSION}, the feature described in this section is | |
7010 | experimental. | |
7011 | @end quotation | |
05962f29 LC |
7012 | |
7013 | @cindex security updates | |
7014 | Occasionally, important security vulnerabilities are discovered in core | |
7015 | software packages and must be patched. Guix follows a functional | |
7016 | package management discipline (@pxref{Introduction}), which implies | |
7017 | that, when a package is changed, @emph{every package that depends on it} | |
7018 | must be rebuilt. This can significantly slow down the deployment of | |
7019 | fixes in core packages such as libc or Bash, since basically the whole | |
7020 | distribution would need to be rebuilt. Using pre-built binaries helps | |
7021 | (@pxref{Substitutes}), but deployment may still take more time than | |
7022 | desired. | |
7023 | ||
7024 | @cindex grafts | |
7025 | To address that, Guix implements @dfn{grafts}, a mechanism that allows | |
7026 | for fast deployment of critical updates without the costs associated | |
7027 | with a whole-distribution rebuild. The idea is to rebuild only the | |
7028 | package that needs to be patched, and then to ``graft'' it onto packages | |
7029 | explicitly installed by the user and that were previously referring to | |
7030 | the original package. The cost of grafting is typically very low, and | |
7031 | order of magnitudes lower than a full rebuild of the dependency chain. | |
7032 | ||
7033 | @cindex replacements of packages, for grafts | |
7034 | For instance, suppose a security update needs to be applied to Bash. | |
7035 | Guix developers will provide a package definition for the ``fixed'' | |
7036 | Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining | |
7037 | Packages}). Then, the original package definition is augmented with a | |
7038 | @code{replacement} field pointing to the package containing the bug fix: | |
7039 | ||
7040 | @example | |
7041 | (define bash | |
7042 | (package | |
7043 | (name "bash") | |
7044 | ;; @dots{} | |
7045 | (replacement bash-fixed))) | |
7046 | @end example | |
7047 | ||
7048 | From there on, any package depending directly or indirectly on Bash that | |
7049 | is installed will automatically be ``rewritten'' to refer to | |
7050 | @var{bash-fixed} instead of @var{bash}. This grafting process takes | |
7051 | time proportional to the size of the package, but expect less than a | |
7052 | minute for an ``average'' package on a recent machine. | |
7053 | ||
7054 | Currently, the graft and the package it replaces (@var{bash-fixed} and | |
7055 | @var{bash} in the example above) must have the exact same @code{name} | |
7056 | and @code{version} fields. This restriction mostly comes from the fact | |
7057 | that grafting works by patching files, including binary files, directly. | |
7058 | Other restrictions may apply: for instance, when adding a graft to a | |
7059 | package providing a shared library, the original shared library and its | |
7060 | replacement must have the same @code{SONAME} and be binary-compatible. | |
7061 | ||
7062 | ||
cf4a9129 LC |
7063 | @node Package Modules |
7064 | @section Package Modules | |
8451a568 | 7065 | |
cf4a9129 LC |
7066 | From a programming viewpoint, the package definitions of the |
7067 | GNU distribution are provided by Guile modules in the @code{(gnu packages | |
7068 | @dots{})} name space@footnote{Note that packages under the @code{(gnu | |
7069 | packages @dots{})} module name space are not necessarily ``GNU | |
7070 | packages''. This module naming scheme follows the usual Guile module | |
7071 | naming convention: @code{gnu} means that these modules are distributed | |
7072 | as part of the GNU system, and @code{packages} identifies modules that | |
7073 | define packages.} (@pxref{Modules, Guile modules,, guile, GNU Guile | |
7074 | Reference Manual}). For instance, the @code{(gnu packages emacs)} | |
7075 | module exports a variable named @code{emacs}, which is bound to a | |
7076 | @code{<package>} object (@pxref{Defining Packages}). | |
113daf62 | 7077 | |
300868ba | 7078 | The @code{(gnu packages @dots{})} module name space is |
cf4a9129 LC |
7079 | automatically scanned for packages by the command-line tools. For |
7080 | instance, when running @code{guix package -i emacs}, all the @code{(gnu | |
7081 | packages @dots{})} modules are scanned until one that exports a package | |
7082 | object whose name is @code{emacs} is found. This package search | |
7083 | facility is implemented in the @code{(gnu packages)} module. | |
113daf62 | 7084 | |
300868ba | 7085 | @cindex customization, of packages |
8689901f | 7086 | @cindex package module search path |
cf4a9129 | 7087 | Users can store package definitions in modules with different |
60142854 | 7088 | names---e.g., @code{(my-packages emacs)}@footnote{Note that the file |
c95ded7e LC |
7089 | name and module name must match. For instance, the @code{(my-packages |
7090 | emacs)} module must be stored in a @file{my-packages/emacs.scm} file | |
7091 | relative to the load path specified with @option{--load-path} or | |
7092 | @code{GUIX_PACKAGE_PATH}. @xref{Modules and the File System,,, | |
7093 | guile, GNU Guile Reference Manual}, for details.}. These package definitions | |
300868ba LC |
7094 | will not be visible by default. Thus, users can invoke commands such as |
7095 | @command{guix package} and @command{guix build} have to be used with the | |
c95ded7e LC |
7096 | @code{-e} option so that they know where to find the package. Better |
7097 | yet, they can use the | |
300868ba | 7098 | @code{-L} option of these commands to make those modules visible |
8689901f LC |
7099 | (@pxref{Invoking guix build, @code{--load-path}}), or define the |
7100 | @code{GUIX_PACKAGE_PATH} environment variable. This environment | |
7101 | variable makes it easy to extend or customize the distribution and is | |
7102 | honored by all the user interfaces. | |
7103 | ||
7104 | @defvr {Environment Variable} GUIX_PACKAGE_PATH | |
7105 | This is a colon-separated list of directories to search for package | |
7106 | modules. Directories listed in this variable take precedence over the | |
7107 | distribution's own modules. | |
7108 | @end defvr | |
ef5dd60a | 7109 | |
cf4a9129 LC |
7110 | The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}: |
7111 | each package is built based solely on other packages in the | |
7112 | distribution. The root of this dependency graph is a small set of | |
7113 | @dfn{bootstrap binaries}, provided by the @code{(gnu packages | |
7114 | bootstrap)} module. For more information on bootstrapping, | |
081145cf | 7115 | @pxref{Bootstrapping}. |
ef5dd60a | 7116 | |
cf4a9129 LC |
7117 | @node Packaging Guidelines |
7118 | @section Packaging Guidelines | |
ef5dd60a | 7119 | |
cf4a9129 LC |
7120 | The GNU distribution is nascent and may well lack some of your favorite |
7121 | packages. This section describes how you can help make the distribution | |
7122 | grow. @xref{Contributing}, for additional information on how you can | |
7123 | help. | |
ef5dd60a | 7124 | |
cf4a9129 LC |
7125 | Free software packages are usually distributed in the form of |
7126 | @dfn{source code tarballs}---typically @file{tar.gz} files that contain | |
7127 | all the source files. Adding a package to the distribution means | |
7128 | essentially two things: adding a @dfn{recipe} that describes how to | |
7129 | build the package, including a list of other packages required to build | |
7130 | it, and adding @dfn{package meta-data} along with that recipe, such as a | |
7131 | description and licensing information. | |
ef5dd60a | 7132 | |
cf4a9129 LC |
7133 | In Guix all this information is embodied in @dfn{package definitions}. |
7134 | Package definitions provide a high-level view of the package. They are | |
7135 | written using the syntax of the Scheme programming language; in fact, | |
7136 | for each package we define a variable bound to the package definition, | |
7137 | and export that variable from a module (@pxref{Package Modules}). | |
7138 | However, in-depth Scheme knowledge is @emph{not} a prerequisite for | |
7139 | creating packages. For more information on package definitions, | |
081145cf | 7140 | @pxref{Defining Packages}. |
ef5dd60a | 7141 | |
cf4a9129 LC |
7142 | Once a package definition is in place, stored in a file in the Guix |
7143 | source tree, it can be tested using the @command{guix build} command | |
7144 | (@pxref{Invoking guix build}). For example, assuming the new package is | |
c71979f4 LC |
7145 | called @code{gnew}, you may run this command from the Guix build tree |
7146 | (@pxref{Running Guix Before It Is Installed}): | |
ef5dd60a LC |
7147 | |
7148 | @example | |
cf4a9129 | 7149 | ./pre-inst-env guix build gnew --keep-failed |
ef5dd60a | 7150 | @end example |
ef5dd60a | 7151 | |
cf4a9129 LC |
7152 | Using @code{--keep-failed} makes it easier to debug build failures since |
7153 | it provides access to the failed build tree. Another useful | |
7154 | command-line option when debugging is @code{--log-file}, to access the | |
7155 | build log. | |
ef5dd60a | 7156 | |
cf4a9129 LC |
7157 | If the package is unknown to the @command{guix} command, it may be that |
7158 | the source file contains a syntax error, or lacks a @code{define-public} | |
7159 | clause to export the package variable. To figure it out, you may load | |
7160 | the module from Guile to get more information about the actual error: | |
ef5dd60a | 7161 | |
cf4a9129 LC |
7162 | @example |
7163 | ./pre-inst-env guile -c '(use-modules (gnu packages gnew))' | |
7164 | @end example | |
ef5dd60a | 7165 | |
cf4a9129 LC |
7166 | Once your package builds correctly, please send us a patch |
7167 | (@pxref{Contributing}). Well, if you need help, we will be happy to | |
7168 | help you too. Once the patch is committed in the Guix repository, the | |
7169 | new package automatically gets built on the supported platforms by | |
2b1cee21 | 7170 | @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration |
cf4a9129 | 7171 | system}. |
ef5dd60a | 7172 | |
cf4a9129 LC |
7173 | @cindex substituter |
7174 | Users can obtain the new package definition simply by running | |
7175 | @command{guix pull} (@pxref{Invoking guix pull}). When | |
7176 | @code{hydra.gnu.org} is done building the package, installing the | |
7177 | package automatically downloads binaries from there | |
7178 | (@pxref{Substitutes}). The only place where human intervention is | |
7179 | needed is to review and apply the patch. | |
ef5dd60a | 7180 | |
ef5dd60a | 7181 | |
cf4a9129 | 7182 | @menu |
ec0339cd LC |
7183 | * Software Freedom:: What may go into the distribution. |
7184 | * Package Naming:: What's in a name? | |
7185 | * Version Numbers:: When the name is not enough. | |
cbd02397 | 7186 | * Synopses and Descriptions:: Helping users find the right package. |
ec0339cd LC |
7187 | * Python Modules:: Taming the snake. |
7188 | * Perl Modules:: Little pearls. | |
7189 | * Fonts:: Fond of fonts. | |
cf4a9129 | 7190 | @end menu |
ef5dd60a | 7191 | |
cf4a9129 LC |
7192 | @node Software Freedom |
7193 | @subsection Software Freedom | |
ef5dd60a | 7194 | |
cf4a9129 | 7195 | @c Adapted from http://www.gnu.org/philosophy/philosophy.html. |
c11a6eb1 | 7196 | |
cf4a9129 LC |
7197 | The GNU operating system has been developed so that users can have |
7198 | freedom in their computing. GNU is @dfn{free software}, meaning that | |
7199 | users have the @url{http://www.gnu.org/philosophy/free-sw.html,four | |
7200 | essential freedoms}: to run the program, to study and change the program | |
7201 | in source code form, to redistribute exact copies, and to distribute | |
7202 | modified versions. Packages found in the GNU distribution provide only | |
7203 | software that conveys these four freedoms. | |
c11a6eb1 | 7204 | |
cf4a9129 LC |
7205 | In addition, the GNU distribution follow the |
7206 | @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free | |
7207 | software distribution guidelines}. Among other things, these guidelines | |
7208 | reject non-free firmware, recommendations of non-free software, and | |
7209 | discuss ways to deal with trademarks and patents. | |
ef5dd60a | 7210 | |
cf4a9129 LC |
7211 | Some packages contain a small and optional subset that violates the |
7212 | above guidelines, for instance because this subset is itself non-free | |
7213 | code. When that happens, the offending items are removed with | |
7214 | appropriate patches or code snippets in the package definition's | |
7215 | @code{origin} form (@pxref{Defining Packages}). That way, @code{guix | |
7216 | build --source} returns the ``freed'' source rather than the unmodified | |
7217 | upstream source. | |
ef5dd60a | 7218 | |
ef5dd60a | 7219 | |
cf4a9129 LC |
7220 | @node Package Naming |
7221 | @subsection Package Naming | |
ef5dd60a | 7222 | |
cf4a9129 LC |
7223 | A package has actually two names associated with it: |
7224 | First, there is the name of the @emph{Scheme variable}, the one following | |
7225 | @code{define-public}. By this name, the package can be made known in the | |
7226 | Scheme code, for instance as input to another package. Second, there is | |
7227 | the string in the @code{name} field of a package definition. This name | |
7228 | is used by package management commands such as | |
7229 | @command{guix package} and @command{guix build}. | |
ef5dd60a | 7230 | |
cf4a9129 LC |
7231 | Both are usually the same and correspond to the lowercase conversion of |
7232 | the project name chosen upstream, with underscores replaced with | |
7233 | hyphens. For instance, GNUnet is available as @code{gnunet}, and | |
7234 | SDL_net as @code{sdl-net}. | |
927097ef | 7235 | |
cf4a9129 | 7236 | We do not add @code{lib} prefixes for library packages, unless these are |
081145cf | 7237 | already part of the official project name. But @pxref{Python |
cf4a9129 LC |
7238 | Modules} and @ref{Perl Modules} for special rules concerning modules for |
7239 | the Python and Perl languages. | |
927097ef | 7240 | |
1b366ee4 | 7241 | Font package names are handled differently, @pxref{Fonts}. |
7fec52b7 | 7242 | |
ef5dd60a | 7243 | |
cf4a9129 LC |
7244 | @node Version Numbers |
7245 | @subsection Version Numbers | |
ef5dd60a | 7246 | |
cf4a9129 LC |
7247 | We usually package only the latest version of a given free software |
7248 | project. But sometimes, for instance for incompatible library versions, | |
7249 | two (or more) versions of the same package are needed. These require | |
7250 | different Scheme variable names. We use the name as defined | |
7251 | in @ref{Package Naming} | |
7252 | for the most recent version; previous versions use the same name, suffixed | |
7253 | by @code{-} and the smallest prefix of the version number that may | |
7254 | distinguish the two versions. | |
ef5dd60a | 7255 | |
cf4a9129 LC |
7256 | The name inside the package definition is the same for all versions of a |
7257 | package and does not contain any version number. | |
ef5dd60a | 7258 | |
cf4a9129 | 7259 | For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows: |
ef5dd60a | 7260 | |
cf4a9129 LC |
7261 | @example |
7262 | (define-public gtk+ | |
7263 | (package | |
17d8e33f ML |
7264 | (name "gtk+") |
7265 | (version "3.9.12") | |
7266 | ...)) | |
cf4a9129 LC |
7267 | (define-public gtk+-2 |
7268 | (package | |
17d8e33f ML |
7269 | (name "gtk+") |
7270 | (version "2.24.20") | |
7271 | ...)) | |
cf4a9129 LC |
7272 | @end example |
7273 | If we also wanted GTK+ 3.8.2, this would be packaged as | |
7274 | @example | |
7275 | (define-public gtk+-3.8 | |
7276 | (package | |
17d8e33f ML |
7277 | (name "gtk+") |
7278 | (version "3.8.2") | |
7279 | ...)) | |
cf4a9129 | 7280 | @end example |
ef5dd60a | 7281 | |
cbd02397 LC |
7282 | @node Synopses and Descriptions |
7283 | @subsection Synopses and Descriptions | |
7284 | ||
7285 | As we have seen before, each package in GNU@tie{}Guix includes a | |
7286 | synopsis and a description (@pxref{Defining Packages}). Synopses and | |
7287 | descriptions are important: They are what @command{guix package | |
7288 | --search} searches, and a crucial piece of information to help users | |
7289 | determine whether a given package suits their needs. Consequently, | |
7290 | packagers should pay attention to what goes into them. | |
7291 | ||
7292 | Synopses must start with a capital letter and must not end with a | |
7293 | period. They must not start with ``a'' or ``the'', which usually does | |
7294 | not bring anything; for instance, prefer ``File-frobbing tool'' over ``A | |
7295 | tool that frobs files''. The synopsis should say what the package | |
7296 | is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is | |
7297 | used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines | |
7298 | matching a pattern''. | |
7299 | ||
7300 | Keep in mind that the synopsis must be meaningful for a very wide | |
7301 | audience. For example, ``Manipulate alignments in the SAM format'' | |
7302 | might make sense for a seasoned bioinformatics researcher, but might be | |
7303 | fairly unhelpful or even misleading to a non-specialized audience. It | |
7304 | is a good idea to come up with a synopsis that gives an idea of the | |
7305 | application domain of the package. In this example, this might give | |
7306 | something like ``Manipulate nucleotide sequence alignments'', which | |
7307 | hopefully gives the user a better idea of whether this is what they are | |
7308 | looking for. | |
7309 | ||
7310 | @cindex Texinfo markup, in package descriptions | |
7311 | Descriptions should take between five and ten lines. Use full | |
7312 | sentences, and avoid using acronyms without first introducing them. | |
7313 | Descriptions can include Texinfo markup, which is useful to introduce | |
7314 | ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or | |
ba7d6c76 ML |
7315 | hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}). However you |
7316 | should be careful when using some characters for example @samp{@@} and | |
7317 | curly braces which are the basic special characters in Texinfo | |
7318 | (@pxref{Special Characters,,, texinfo, GNU Texinfo}). User interfaces | |
7319 | such as @command{guix package --show} take care of rendering it | |
7320 | appropriately. | |
cbd02397 LC |
7321 | |
7322 | Synopses and descriptions are translated by volunteers | |
7323 | @uref{http://translationproject.org/domain/guix-packages.html, at the | |
7324 | Translation Project} so that as many users as possible can read them in | |
7325 | their native language. User interfaces search them and display them in | |
7326 | the language specified by the current locale. | |
7327 | ||
7328 | Translation is a lot of work so, as a packager, please pay even more | |
7329 | attention to your synopses and descriptions as every change may entail | |
ba7d6c76 | 7330 | additional work for translators. In order to help them, it is possible |
36743e71 | 7331 | to make recommendations or instructions visible to them by inserting |
ba7d6c76 ML |
7332 | special comments like this (@pxref{xgettext Invocation,,, gettext, GNU |
7333 | Gettext}): | |
7334 | ||
7335 | @example | |
7336 | ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated. | |
7337 | (description "ARandR is designed to provide a simple visual front end | |
7338 | for the X11 resize-and-rotate (RandR) extension. @dots{}") | |
7339 | @end example | |
cbd02397 | 7340 | |
ef5dd60a | 7341 | |
cf4a9129 LC |
7342 | @node Python Modules |
7343 | @subsection Python Modules | |
ef5dd60a | 7344 | |
cf4a9129 LC |
7345 | We currently package Python 2 and Python 3, under the Scheme variable names |
7346 | @code{python-2} and @code{python} as explained in @ref{Version Numbers}. | |
7347 | To avoid confusion and naming clashes with other programming languages, it | |
7348 | seems desirable that the name of a package for a Python module contains | |
7349 | the word @code{python}. | |
ef5dd60a | 7350 | |
cf4a9129 LC |
7351 | Some modules are compatible with only one version of Python, others with both. |
7352 | If the package Foo compiles only with Python 3, we name it | |
7353 | @code{python-foo}; if it compiles only with Python 2, we name it | |
7354 | @code{python2-foo}. If it is compatible with both versions, we create two | |
7355 | packages with the corresponding names. | |
ef5dd60a | 7356 | |
cf4a9129 LC |
7357 | If a project already contains the word @code{python}, we drop this; |
7358 | for instance, the module python-dateutil is packaged under the names | |
7359 | @code{python-dateutil} and @code{python2-dateutil}. | |
113daf62 | 7360 | |
523e4896 | 7361 | |
cf4a9129 LC |
7362 | @node Perl Modules |
7363 | @subsection Perl Modules | |
523e4896 | 7364 | |
cf4a9129 LC |
7365 | Perl programs standing for themselves are named as any other package, |
7366 | using the lowercase upstream name. | |
7367 | For Perl packages containing a single class, we use the lowercase class name, | |
7368 | replace all occurrences of @code{::} by dashes and prepend the prefix | |
7369 | @code{perl-}. | |
7370 | So the class @code{XML::Parser} becomes @code{perl-xml-parser}. | |
7371 | Modules containing several classes keep their lowercase upstream name and | |
7372 | are also prepended by @code{perl-}. Such modules tend to have the word | |
7373 | @code{perl} somewhere in their name, which gets dropped in favor of the | |
7374 | prefix. For instance, @code{libwww-perl} becomes @code{perl-libwww}. | |
523e4896 | 7375 | |
523e4896 | 7376 | |
7fec52b7 AE |
7377 | @node Fonts |
7378 | @subsection Fonts | |
7379 | ||
7380 | For fonts that are in general not installed by a user for typesetting | |
7381 | purposes, or that are distributed as part of a larger software package, | |
7382 | we rely on the general packaging rules for software; for instance, this | |
7383 | applies to the fonts delivered as part of the X.Org system or fonts that | |
7384 | are part of TeX Live. | |
7385 | ||
7386 | To make it easier for a user to search for fonts, names for other packages | |
7387 | containing only fonts are constructed as follows, independently of the | |
7388 | upstream package name. | |
7389 | ||
7390 | The name of a package containing only one font family starts with | |
7391 | @code{font-}; it is followed by the foundry name and a dash @code{-} | |
7392 | if the foundry is known, and the font family name, in which spaces are | |
7393 | replaced by dashes (and as usual, all upper case letters are transformed | |
7394 | to lower case). | |
7395 | For example, the Gentium font family by SIL is packaged under the name | |
7396 | @code{font-sil-gentium}. | |
7397 | ||
7398 | For a package containing several font families, the name of the collection | |
7399 | is used in the place of the font family name. | |
7400 | For instance, the Liberation fonts consist of three families, | |
7401 | Liberation Sans, Liberation Serif and Liberation Mono. | |
7402 | These could be packaged separately under the names | |
7403 | @code{font-liberation-sans} and so on; but as they are distributed together | |
7404 | under a common name, we prefer to package them together as | |
7405 | @code{font-liberation}. | |
7406 | ||
7407 | In the case where several formats of the same font family or font collection | |
7408 | are packaged separately, a short form of the format, prepended by a dash, | |
7409 | is added to the package name. We use @code{-ttf} for TrueType fonts, | |
1b366ee4 | 7410 | @code{-otf} for OpenType fonts and @code{-type1} for PostScript Type 1 |
7fec52b7 AE |
7411 | fonts. |
7412 | ||
7413 | ||
b25937e3 | 7414 | |
cf4a9129 LC |
7415 | @node Bootstrapping |
7416 | @section Bootstrapping | |
b25937e3 | 7417 | |
cf4a9129 | 7418 | @c Adapted from the ELS 2013 paper. |
b25937e3 | 7419 | |
cf4a9129 | 7420 | @cindex bootstrapping |
7889394e | 7421 | |
cf4a9129 LC |
7422 | Bootstrapping in our context refers to how the distribution gets built |
7423 | ``from nothing''. Remember that the build environment of a derivation | |
7424 | contains nothing but its declared inputs (@pxref{Introduction}). So | |
7425 | there's an obvious chicken-and-egg problem: how does the first package | |
7426 | get built? How does the first compiler get compiled? Note that this is | |
7427 | a question of interest only to the curious hacker, not to the regular | |
7428 | user, so you can shamelessly skip this section if you consider yourself | |
7429 | a ``regular user''. | |
72b9d60d | 7430 | |
cf4a9129 LC |
7431 | @cindex bootstrap binaries |
7432 | The GNU system is primarily made of C code, with libc at its core. The | |
7433 | GNU build system itself assumes the availability of a Bourne shell and | |
7434 | command-line tools provided by GNU Coreutils, Awk, Findutils, `sed', and | |
7435 | `grep'. Furthermore, build programs---programs that run | |
7436 | @code{./configure}, @code{make}, etc.---are written in Guile Scheme | |
7437 | (@pxref{Derivations}). Consequently, to be able to build anything at | |
7438 | all, from scratch, Guix relies on pre-built binaries of Guile, GCC, | |
7439 | Binutils, libc, and the other packages mentioned above---the | |
7440 | @dfn{bootstrap binaries}. | |
72b9d60d | 7441 | |
cf4a9129 LC |
7442 | These bootstrap binaries are ``taken for granted'', though we can also |
7443 | re-create them if needed (more on that later). | |
72b9d60d | 7444 | |
cf4a9129 | 7445 | @unnumberedsubsec Preparing to Use the Bootstrap Binaries |
c79d54fe | 7446 | |
cf4a9129 LC |
7447 | @c As of Emacs 24.3, Info-mode displays the image, but since it's a |
7448 | @c large image, it's hard to scroll. Oh well. | |
7449 | @image{images/bootstrap-graph,6in,,Dependency graph of the early bootstrap derivations} | |
523e4896 | 7450 | |
cf4a9129 LC |
7451 | The figure above shows the very beginning of the dependency graph of the |
7452 | distribution, corresponding to the package definitions of the @code{(gnu | |
7453 | packages bootstrap)} module. At this level of detail, things are | |
7454 | slightly complex. First, Guile itself consists of an ELF executable, | |
7455 | along with many source and compiled Scheme files that are dynamically | |
7456 | loaded when it runs. This gets stored in the @file{guile-2.0.7.tar.xz} | |
7457 | tarball shown in this graph. This tarball is part of Guix's ``source'' | |
7458 | distribution, and gets inserted into the store with @code{add-to-store} | |
7459 | (@pxref{The Store}). | |
2e7b5cea | 7460 | |
cf4a9129 LC |
7461 | But how do we write a derivation that unpacks this tarball and adds it |
7462 | to the store? To solve this problem, the @code{guile-bootstrap-2.0.drv} | |
7463 | derivation---the first one that gets built---uses @code{bash} as its | |
7464 | builder, which runs @code{build-bootstrap-guile.sh}, which in turn calls | |
7465 | @code{tar} to unpack the tarball. Thus, @file{bash}, @file{tar}, | |
7466 | @file{xz}, and @file{mkdir} are statically-linked binaries, also part of | |
7467 | the Guix source distribution, whose sole purpose is to allow the Guile | |
7468 | tarball to be unpacked. | |
fb729425 | 7469 | |
cf4a9129 LC |
7470 | Once @code{guile-bootstrap-2.0.drv} is built, we have a functioning |
7471 | Guile that can be used to run subsequent build programs. Its first task | |
7472 | is to download tarballs containing the other pre-built binaries---this | |
7473 | is what the @code{.tar.xz.drv} derivations do. Guix modules such as | |
7474 | @code{ftp-client.scm} are used for this purpose. The | |
7475 | @code{module-import.drv} derivations import those modules in a directory | |
7476 | in the store, using the original layout. The | |
7477 | @code{module-import-compiled.drv} derivations compile those modules, and | |
7478 | write them in an output directory with the right layout. This | |
7479 | corresponds to the @code{#:modules} argument of | |
7480 | @code{build-expression->derivation} (@pxref{Derivations}). | |
fb729425 | 7481 | |
cf4a9129 LC |
7482 | Finally, the various tarballs are unpacked by the |
7483 | derivations @code{gcc-bootstrap-0.drv}, @code{glibc-bootstrap-0.drv}, | |
7484 | etc., at which point we have a working C tool chain. | |
fb729425 | 7485 | |
fb729425 | 7486 | |
cf4a9129 | 7487 | @unnumberedsubsec Building the Build Tools |
523e4896 | 7488 | |
cf4a9129 LC |
7489 | @c TODO: Add a package-level dependency graph generated from (gnu |
7490 | @c packages base). | |
df2ce343 | 7491 | |
cf4a9129 LC |
7492 | Bootstrapping is complete when we have a full tool chain that does not |
7493 | depend on the pre-built bootstrap tools discussed above. This | |
7494 | no-dependency requirement is verified by checking whether the files of | |
7495 | the final tool chain contain references to the @file{/gnu/store} | |
7496 | directories of the bootstrap inputs. The process that leads to this | |
7497 | ``final'' tool chain is described by the package definitions found in | |
1f6f57df | 7498 | the @code{(gnu packages commencement)} module. |
df2ce343 | 7499 | |
cf4a9129 LC |
7500 | @c See <http://lists.gnu.org/archive/html/gnu-system-discuss/2012-10/msg00000.html>. |
7501 | The first tool that gets built with the bootstrap binaries is | |
7502 | GNU Make, which is a prerequisite for all the following packages. | |
7503 | From there Findutils and Diffutils get built. | |
523e4896 | 7504 | |
cf4a9129 LC |
7505 | Then come the first-stage Binutils and GCC, built as pseudo cross |
7506 | tools---i.e., with @code{--target} equal to @code{--host}. They are | |
7507 | used to build libc. Thanks to this cross-build trick, this libc is | |
7508 | guaranteed not to hold any reference to the initial tool chain. | |
4af2447e | 7509 | |
cf4a9129 LC |
7510 | From there the final Binutils and GCC are built. GCC uses @code{ld} |
7511 | from the final Binutils, and links programs against the just-built libc. | |
7512 | This tool chain is used to build the other packages used by Guix and by | |
7513 | the GNU Build System: Guile, Bash, Coreutils, etc. | |
4af2447e | 7514 | |
cf4a9129 LC |
7515 | And voilà! At this point we have the complete set of build tools that |
7516 | the GNU Build System expects. These are in the @code{%final-inputs} | |
dd164244 MW |
7517 | variable of the @code{(gnu packages commencement)} module, and are |
7518 | implicitly used by any package that uses @code{gnu-build-system} | |
1f6f57df | 7519 | (@pxref{Build Systems, @code{gnu-build-system}}). |
4af2447e | 7520 | |
4af2447e | 7521 | |
cf4a9129 | 7522 | @unnumberedsubsec Building the Bootstrap Binaries |
4af2447e | 7523 | |
cf4a9129 LC |
7524 | Because the final tool chain does not depend on the bootstrap binaries, |
7525 | those rarely need to be updated. Nevertheless, it is useful to have an | |
7526 | automated way to produce them, should an update occur, and this is what | |
7527 | the @code{(gnu packages make-bootstrap)} module provides. | |
4af2447e | 7528 | |
cf4a9129 LC |
7529 | The following command builds the tarballs containing the bootstrap |
7530 | binaries (Guile, Binutils, GCC, libc, and a tarball containing a mixture | |
7531 | of Coreutils and other basic command-line tools): | |
4b2615e1 | 7532 | |
cf4a9129 LC |
7533 | @example |
7534 | guix build bootstrap-tarballs | |
7535 | @end example | |
7536 | ||
7537 | The generated tarballs are those that should be referred to in the | |
7538 | @code{(gnu packages bootstrap)} module mentioned at the beginning of | |
7539 | this section. | |
7540 | ||
7541 | Still here? Then perhaps by now you've started to wonder: when do we | |
7542 | reach a fixed point? That is an interesting question! The answer is | |
7543 | unknown, but if you would like to investigate further (and have | |
7544 | significant computational and storage resources to do so), then let us | |
7545 | know. | |
7546 | ||
7547 | @node Porting | |
7548 | @section Porting to a New Platform | |
7549 | ||
7550 | As discussed above, the GNU distribution is self-contained, and | |
7551 | self-containment is achieved by relying on pre-built ``bootstrap | |
7552 | binaries'' (@pxref{Bootstrapping}). These binaries are specific to an | |
7553 | operating system kernel, CPU architecture, and application binary | |
7554 | interface (ABI). Thus, to port the distribution to a platform that is | |
7555 | not yet supported, one must build those bootstrap binaries, and update | |
7556 | the @code{(gnu packages bootstrap)} module to use them on that platform. | |
7557 | ||
7558 | Fortunately, Guix can @emph{cross compile} those bootstrap binaries. | |
7559 | When everything goes well, and assuming the GNU tool chain supports the | |
7560 | target platform, this can be as simple as running a command like this | |
7561 | one: | |
7562 | ||
7563 | @example | |
7564 | guix build --target=armv5tel-linux-gnueabi bootstrap-tarballs | |
7565 | @end example | |
7566 | ||
1c0c417d LC |
7567 | For this to work, the @code{glibc-dynamic-linker} procedure in |
7568 | @code{(gnu packages bootstrap)} must be augmented to return the right | |
7569 | file name for libc's dynamic linker on that platform; likewise, | |
7570 | @code{system->linux-architecture} in @code{(gnu packages linux)} must be | |
7571 | taught about the new platform. | |
7572 | ||
cf4a9129 | 7573 | Once these are built, the @code{(gnu packages bootstrap)} module needs |
1c0c417d LC |
7574 | to be updated to refer to these binaries on the target platform. That |
7575 | is, the hashes and URLs of the bootstrap tarballs for the new platform | |
7576 | must be added alongside those of the currently supported platforms. The | |
7577 | bootstrap Guile tarball is treated specially: it is expected to be | |
7578 | available locally, and @file{gnu-system.am} has rules do download it for | |
7579 | the supported architectures; a rule for the new platform must be added | |
7580 | as well. | |
cf4a9129 LC |
7581 | |
7582 | In practice, there may be some complications. First, it may be that the | |
7583 | extended GNU triplet that specifies an ABI (like the @code{eabi} suffix | |
7584 | above) is not recognized by all the GNU tools. Typically, glibc | |
7585 | recognizes some of these, whereas GCC uses an extra @code{--with-abi} | |
7586 | configure flag (see @code{gcc.scm} for examples of how to handle this). | |
7587 | Second, some of the required packages could fail to build for that | |
7588 | platform. Lastly, the generated binaries could be broken for some | |
7589 | reason. | |
4af2447e | 7590 | |
9bf3c1a7 | 7591 | @c ********************************************************************* |
8c01b9d0 | 7592 | @include contributing.texi |
c78bd12b | 7593 | |
568717fd LC |
7594 | @c ********************************************************************* |
7595 | @node Acknowledgments | |
7596 | @chapter Acknowledgments | |
7597 | ||
7598 | Guix is based on the Nix package manager, which was designed and | |
4c7ac9aa LC |
7599 | implemented by Eelco Dolstra, with contributions from other people (see |
7600 | the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package | |
568717fd LC |
7601 | management, and promoted unprecedented features, such as transactional |
7602 | package upgrades and rollbacks, per-user profiles, and referentially | |
7603 | transparent build processes. Without this work, Guix would not exist. | |
7604 | ||
7605 | The Nix-based software distributions, Nixpkgs and NixOS, have also been | |
7606 | an inspiration for Guix. | |
7607 | ||
4c7ac9aa LC |
7608 | GNU@tie{}Guix itself is a collective work with contributions from a |
7609 | number of people. See the @file{AUTHORS} file in Guix for more | |
7610 | information on these fine people. The @file{THANKS} file lists people | |
7611 | who have helped by reporting bugs, taking care of the infrastructure, | |
7612 | providing artwork and themes, making suggestions, and more---thank you! | |
7613 | ||
7614 | ||
568717fd LC |
7615 | @c ********************************************************************* |
7616 | @node GNU Free Documentation License | |
7617 | @appendix GNU Free Documentation License | |
7618 | ||
7619 | @include fdl-1.3.texi | |
7620 | ||
7621 | @c ********************************************************************* | |
7622 | @node Concept Index | |
7623 | @unnumbered Concept Index | |
7624 | @printindex cp | |
7625 | ||
a85b83d2 LC |
7626 | @node Programming Index |
7627 | @unnumbered Programming Index | |
7628 | @syncodeindex tp fn | |
7629 | @syncodeindex vr fn | |
568717fd LC |
7630 | @printindex fn |
7631 | ||
7632 | @bye | |
7633 | ||
7634 | @c Local Variables: | |
7635 | @c ispell-local-dictionary: "american"; | |
7636 | @c End: |