gnu: gnome-shell-extension-noannoyance: Use the copy-build-system.
[jackhill/guix/guix.git] / doc / guix-cookbook.texi
1 \input texinfo
2 @c -*-texinfo-*-
3
4 @c %**start of header
5 @setfilename guix-cookbook.info
6 @documentencoding UTF-8
7 @settitle GNU Guix Cookbook
8 @c %**end of header
9
10 @copying
11 Copyright @copyright{} 2019 Ricardo Wurmus@*
12 Copyright @copyright{} 2019 Efraim Flashner@*
13 Copyright @copyright{} 2019 Pierre Neidhardt@*
14
15 Permission is granted to copy, distribute and/or modify this document
16 under the terms of the GNU Free Documentation License, Version 1.3 or
17 any later version published by the Free Software Foundation; with no
18 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
19 copy of the license is included in the section entitled ``GNU Free
20 Documentation License''.
21 @end copying
22
23 @dircategory System administration
24 @direntry
25 * Guix cookbook: (guix-cookbook). Tutorials and examples for GNU Guix.
26 @end direntry
27
28 @titlepage
29 @title GNU Guix Cookbook
30 @subtitle Tutorials and examples for using the GNU Guix Functional Package Manager
31 @author The GNU Guix Developers
32
33 @page
34 @vskip 0pt plus 1filll
35
36 @insertcopying
37 @end titlepage
38
39 @contents
40
41 @c *********************************************************************
42 @node Top
43 @top GNU Guix Cookbook
44
45 This document presents tutorials and detailed examples for GNU@tie{}Guix, a
46 functional package management tool written for the GNU system. Please
47 @pxref{Top,,, guix, GNU Guix reference manual} for details about the system,
48 its API, and related concepts.
49
50 @c TRANSLATORS: You can replace the following paragraph with information on
51 @c how to join your own translation team and how to report issues with the
52 @c translation.
53 If you would like to translate this document in your native language, consider
54 joining the @uref{https://translationproject.org/domain/guix-cookbook.html,
55 Translation Project}.
56
57 @menu
58 * Scheme tutorials:: Meet your new favorite language!
59 * Packaging:: Packaging tutorials
60 * System Configuration:: Customizing the GNU System
61 * Advanced package management:: Power to the users!
62
63 * Acknowledgments:: Thanks!
64 * GNU Free Documentation License:: The license of this document.
65 * Concept Index:: Concepts.
66
67 @detailmenu
68 --- The Detailed Node Listing ---
69
70 Scheme tutorials
71
72 * A Scheme Crash Course:: Learn the basics of Scheme
73
74 Packaging
75
76 * Packaging Tutorial:: Let's add a package to Guix!
77
78 System Configuration
79
80 * Customizing the Kernel:: Creating and using a custom Linux kernel
81
82
83 @end detailmenu
84 @end menu
85
86 @c *********************************************************************
87 @node Scheme tutorials
88 @chapter Scheme tutorials
89
90 GNU@tie{}Guix is written in the general purpose programming language Scheme,
91 and many of its features can be accessed and manipulated programmatically.
92 You can use Scheme to generate package definitions, to modify them, to build
93 them, to deploy whole operating systems, etc.
94
95 Knowing the basics of how to program in Scheme will unlock many of the
96 advanced features Guix provides --- and you don't even need to be an
97 experienced programmer to use them!
98
99 Let's get started!
100
101 @node A Scheme Crash Course
102 @section A Scheme Crash Course
103
104 @cindex Scheme, crash course
105
106 Guix uses the Guile implementation of Scheme. To start playing with the
107 language, install it with @code{guix install guile} and start a
108 @uref{https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop,
109 REPL} by running @code{guile} from the command line.
110
111 Alternatively you can also run @code{guix environment --ad-hoc guile -- guile}
112 if you'd rather not have Guile installed in your user profile.
113
114 In the following examples, lines show what you would type at the REPL;
115 lines starting with ``@result{}'' show evaluation results, while lines
116 starting with ``@print{}'' show things that get printed. @xref{Using Guile
117 Interactively,,, guile, GNU Guile Reference Manual}), for more details on the
118 REPL.
119
120 @itemize
121 @item
122 Scheme syntax boils down to a tree of expressions (or @emph{s-expression} in
123 Lisp lingo). An expression can be a literal such as numbers and strings, or a
124 compound which is a parenthesized list of compounds and literals. @code{#t}
125 and @code{#f} stand for the Booleans ``true'' and ``false'', respectively.
126
127 Examples of valid expressions:
128
129 @lisp
130 "Hello World!"
131 @result{} "Hello World!"
132
133 17
134 @result{} 17
135
136 (display (string-append "Hello " "Guix" "\n"))
137 @print{} Hello Guix!
138 @result{} #<unspecified>
139 @end lisp
140
141 @item
142 This last example is a function call nested in another function call. When a
143 parenthesized expression is evaluated, the first term is the function and the
144 rest are the arguments passed to the function. Every function returns the
145 last evaluated expression as its return value.
146
147 @item
148 Anonymous functions are declared with the @code{lambda} term:
149
150 @lisp
151 (lambda (x) (* x x))
152 @result{} #<procedure 120e348 at <unknown port>:24:0 (x)>
153 @end lisp
154
155 The above procedure returns the square of its argument. Since everything is
156 an expression, the @code{lambda} expression returns an anonymous procedure,
157 which can in turn be applied to an argument:
158
159 @lisp
160 ((lambda (x) (* x x)) 3)
161 @result{} 9
162 @end lisp
163
164 @item
165 Anything can be assigned a global name with @code{define}:
166
167 @lisp
168 (define a 3)
169 (define square (lambda (x) (* x x)))
170 (square a)
171 @result{} 9
172 @end lisp
173
174 @item
175 Procedures can be defined more concisely with the following syntax:
176
177 @lisp
178 (define (square x) (* x x))
179 @end lisp
180
181 @item
182 A list structure can be created with the @code{list} procedure:
183
184 @lisp
185 (list 2 a 5 7)
186 @result{} (2 3 5 7)
187 @end lisp
188
189 @item
190 The @dfn{quote} disables evaluation of a parenthesized expression: the
191 first term is not called over the other terms (@pxref{Expression Syntax,
192 quote,, guile, GNU Guile Reference Manual}). Thus it effectively
193 returns a list of terms.
194
195 @lisp
196 '(display (string-append "Hello " "Guix" "\n"))
197 @result{} (display (string-append "Hello " "Guix" "\n"))
198
199 '(2 a 5 7)
200 @result{} (2 a 5 7)
201 @end lisp
202
203 @item
204 The @dfn{quasiquote} disables evaluation of a parenthesized expression
205 until @dfn{unquote} (a comma) re-enables it. Thus it provides us with
206 fine-grained control over what is evaluated and what is not.
207
208 @lisp
209 `(2 a 5 7 (2 ,a 5 ,(+ a 4)))
210 @result{} (2 a 5 7 (2 3 5 7))
211 @end lisp
212
213 Note that the above result is a list of mixed elements: numbers, symbols (here
214 @code{a}) and the last element is a list itself.
215
216 @item
217 Multiple variables can be named locally with @code{let} (@pxref{Local
218 Bindings,,, guile, GNU Guile Reference Manual}):
219
220 @lisp
221 (define x 10)
222 (let ((x 2)
223 (y 3))
224 (list x y))
225 @result{} (2 3)
226
227 x
228 @result{} 10
229
230 y
231 @error{} In procedure module-lookup: Unbound variable: y
232 @end lisp
233
234 Use @code{let*} to allow later variable declarations to refer to earlier
235 definitions.
236
237 @lisp
238 (let* ((x 2)
239 (y (* x 3)))
240 (list x y))
241 @result{} (2 6)
242 @end lisp
243
244 @item
245 The keyword syntax is @code{#:}; it is used to create unique identifiers.
246 @pxref{Keywords,,, guile, GNU Guile Reference Manual}.
247
248 @item
249 The percentage @code{%} is typically used for read-only global variables in
250 the build stage. Note that it is merely a convention, like @code{_} in C.
251 Scheme treats @code{%} exactly the same as any other letter.
252
253 @item
254 Modules are created with @code{define-module} (@pxref{Creating Guile
255 Modules,,, guile, GNU Guile Reference Manual}). For instance
256
257 @lisp
258 (define-module (guix build-system ruby)
259 #:use-module (guix store)
260 #:export (ruby-build
261 ruby-build-system))
262 @end lisp
263
264 defines the module @code{guix build-system ruby} which must be located in
265 @file{guix/build-system/ruby.scm} somewhere in the Guile load path. It
266 depends on the @code{(guix store)} module and it exports two variables,
267 @code{ruby-build} and @code{ruby-build-system}.
268 @end itemize
269
270 For a more detailed introduction, check out
271 @uref{http://www.troubleshooters.com/codecorn/scheme_guile/hello.htm, Scheme
272 at a Glance}, by Steve Litt.
273
274 One of the reference Scheme books is the seminal ``Structure and
275 Interpretation of Computer Programs'', by Harold Abelson and Gerald Jay
276 Sussman, with Julie Sussman. You'll find a
277 @uref{https://mitpress.mit.edu/sites/default/files/sicp/index.html, free copy
278 online}, together with
279 @uref{https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-001-structure-and-interpretation-of-computer-programs-spring-2005/video-lectures/,
280 videos of the lectures by the authors}. The book is available in Texinfo
281 format as the @code{sicp} Guix package. Go ahead, run @code{guix install
282 sicp} and start reading with @code{info sicp} (@pxref{,,, sicp, Structure and Interpretation of Computer Programs}).
283 An @uref{https://sarabander.github.io/sicp/, unofficial ebook is also
284 available}.
285
286 You'll find more books, tutorials and other resources at
287 @url{https://schemers.org/}.
288
289
290 @c *********************************************************************
291 @node Packaging
292 @chapter Packaging
293
294 @cindex packaging
295
296 This chapter is dedicated to teaching you how to add packages to the
297 collection of packages that come with GNU Guix. This involves writing package
298 definitions in Guile Scheme, organizing them in package modules, and building
299 them.
300
301 @menu
302 * Packaging Tutorial:: A tutorial on how to add packages to Guix.
303 @end menu
304
305 @node Packaging Tutorial
306 @section Packaging Tutorial
307
308 GNU Guix stands out as the @emph{hackable} package manager, mostly because it
309 uses @uref{https://www.gnu.org/software/guile/, GNU Guile}, a powerful
310 high-level programming language, one of the
311 @uref{https://en.wikipedia.org/wiki/Scheme_%28programming_language%29, Scheme}
312 dialects from the
313 @uref{https://en.wikipedia.org/wiki/Lisp_%28programming_language%29, Lisp family}.
314
315 Package definitions are also written in Scheme, which empowers Guix in some
316 very unique ways, unlike most other package managers that use shell scripts or
317 simple languages.
318
319 @itemize
320 @item
321 Use functions, structures, macros and all of Scheme expressiveness for your
322 package definitions.
323
324 @item
325 Inheritance makes it easy to customize a package by inheriting from it and
326 modifying only what is needed.
327
328 @item
329 Batch processing: the whole package collection can be parsed, filtered and
330 processed. Building a headless server with all graphical interfaces stripped
331 out? It's possible. Want to rebuild everything from source using specific
332 compiler optimization flags? Pass the @code{#:make-flags "..."} argument to
333 the list of packages. It wouldn't be a stretch to think
334 @uref{https://wiki.gentoo.org/wiki/USE_flag, Gentoo USE flags} here, but this
335 goes even further: the changes don't have to be thought out beforehand by the
336 packager, they can be @emph{programmed} by the user!
337 @end itemize
338
339 The following tutorial covers all the basics around package creation with Guix.
340 It does not assume much knowledge of the Guix system nor of the Lisp language.
341 The reader is only expected to be familiar with the command line and to have some
342 basic programming knowledge.
343
344 @node A ``Hello World'' package
345 @subsection A ``Hello World'' package
346
347 The ``Defining Packages'' section of the manual introduces the basics of Guix
348 packaging (@pxref{Defining Packages,,, guix, GNU Guix Reference Manual}). In
349 the following section, we will partly go over those basics again.
350
351 GNU@tie{}Hello is a dummy project that serves as an idiomatic example for
352 packaging. It uses the GNU build system (@code{./configure && make && make
353 install}). Guix already provides a package definition which is a perfect
354 example to start with. You can look up its declaration with @code{guix edit
355 hello} from the command line. Let's see how it looks:
356
357 @lisp
358 (define-public hello
359 (package
360 (name "hello")
361 (version "2.10")
362 (source (origin
363 (method url-fetch)
364 (uri (string-append "mirror://gnu/hello/hello-" version
365 ".tar.gz"))
366 (sha256
367 (base32
368 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
369 (build-system gnu-build-system)
370 (synopsis "Hello, GNU world: An example GNU package")
371 (description
372 "GNU Hello prints the message \"Hello, world!\" and then exits. It
373 serves as an example of standard GNU coding practices. As such, it supports
374 command-line arguments, multiple languages, and so on.")
375 (home-page "https://www.gnu.org/software/hello/")
376 (license gpl3+)))
377 @end lisp
378
379 As you can see, most of it is rather straightforward. But let's review the
380 fields together:
381
382 @table @samp
383 @item name
384 The project name. Using Scheme conventions, we prefer to keep it
385 lower case, without underscore and using dash-separated words.
386
387 @item source
388 This field contains a description of the source code origin. The
389 @code{origin} record contains these fields:
390
391 @enumerate
392 @item The method, here @code{url-fetch} to download via HTTP/FTP, but other methods
393 exist, such as @code{git-fetch} for Git repositories.
394 @item The URI, which is typically some @code{https://} location for @code{url-fetch}. Here
395 the special `mirror://gnu` refers to a set of well known locations, all of
396 which can be used by Guix to fetch the source, should some of them fail.
397 @item The @code{sha256} checksum of the requested file. This is essential to ensure
398 the source is not corrupted. Note that Guix works with base32 strings,
399 hence the call to the @code{base32} function.
400 @end enumerate
401
402 @item build-system
403
404 This is where the power of abstraction provided by the Scheme language really
405 shines: in this case, the @code{gnu-build-system} abstracts away the famous
406 @code{./configure && make && make install} shell invocations. Other build
407 systems include the @code{trivial-build-system} which does not do anything and
408 requires from the packager to program all the build steps, the
409 @code{python-build-system}, the @code{emacs-build-system}, and many more
410 (@pxref{Build Systems,,, guix, GNU Guix Reference Manual}).
411
412 @item synopsis
413 It should be a concise summary of what the package does. For many packages a
414 tagline from the project's home page can be used as the synopsis.
415
416 @item description
417 Same as for the synopsis, it's fine to re-use the project description from the
418 homepage. Note that Guix uses Texinfo syntax.
419
420 @item home-page
421 Use HTTPS if available.
422
423 @item license
424 See @code{guix/licenses.scm} in the project source for a full list of
425 available licenses.
426 @end table
427
428 Time to build our first package! Nothing fancy here for now: we will stick to a
429 dummy @code{my-hello}, a copy of the above declaration.
430
431 As with the ritualistic ``Hello World'' taught with most programming languages,
432 this will possibly be the most ``manual'' approach. We will work out an ideal
433 setup later; for now we will go the simplest route.
434
435 Save the following to a file @file{my-hello.scm}.
436
437 @lisp
438 (use-modules (guix packages)
439 (guix download)
440 (guix build-system gnu)
441 (guix licenses))
442
443 (package
444 (name "my-hello")
445 (version "2.10")
446 (source (origin
447 (method url-fetch)
448 (uri (string-append "mirror://gnu/hello/hello-" version
449 ".tar.gz"))
450 (sha256
451 (base32
452 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
453 (build-system gnu-build-system)
454 (synopsis "Hello, Guix world: An example custom Guix package")
455 (description
456 "GNU Hello prints the message \"Hello, world!\" and then exits. It
457 serves as an example of standard GNU coding practices. As such, it supports
458 command-line arguments, multiple languages, and so on.")
459 (home-page "https://www.gnu.org/software/hello/")
460 (license gpl3+))
461 @end lisp
462
463 We will explain the extra code in a moment.
464
465 Feel free to play with the different values of the various fields. If you
466 change the source, you'll need to update the checksum. Indeed, Guix refuses to
467 build anything if the given checksum does not match the computed checksum of the
468 source code. To obtain the correct checksum of the package declaration, we
469 need to download the source, compute the sha256 checksum and convert it to
470 base32.
471
472 Thankfully, Guix can automate this task for us; all we need is to provide the
473 URI:
474
475 @c TRANSLATORS: This is example shell output.
476 @example sh
477 $ guix download mirror://gnu/hello/hello-2.10.tar.gz
478
479 Starting download of /tmp/guix-file.JLYgL7
480 From https://ftpmirror.gnu.org/gnu/hello/hello-2.10.tar.gz...
481 following redirection to `https://mirror.ibcp.fr/pub/gnu/hello/hello-2.10.tar.gz'...
482 …10.tar.gz 709KiB 2.5MiB/s 00:00 [##################] 100.0%
483 /gnu/store/hbdalsf5lpf01x4dcknwx6xbn6n5km6k-hello-2.10.tar.gz
484 0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
485 @end example
486
487 In this specific case the output tells us which mirror was chosen.
488 If the result of the above command is not the same as in the above snippet,
489 update your @code{my-hello} declaration accordingly.
490
491 Note that GNU package tarballs come with an OpenPGP signature, so you
492 should definitely check the signature of this tarball with `gpg` to
493 authenticate it before going further:
494
495 @c TRANSLATORS: This is example shell output.
496 @example sh
497 $ guix download mirror://gnu/hello/hello-2.10.tar.gz.sig
498
499 Starting download of /tmp/guix-file.03tFfb
500 From https://ftpmirror.gnu.org/gnu/hello/hello-2.10.tar.gz.sig...
501 following redirection to `https://ftp.igh.cnrs.fr/pub/gnu/hello/hello-2.10.tar.gz.sig'...
502 ….tar.gz.sig 819B 1.2MiB/s 00:00 [##################] 100.0%
503 /gnu/store/rzs8wba9ka7grrmgcpfyxvs58mly0sx6-hello-2.10.tar.gz.sig
504 0q0v86n3y38z17rl146gdakw9xc4mcscpk8dscs412j22glrv9jf
505 $ gpg --verify /gnu/store/rzs8wba9ka7grrmgcpfyxvs58mly0sx6-hello-2.10.tar.gz.sig /gnu/store/hbdalsf5lpf01x4dcknwx6xbn6n5km6k-hello-2.10.tar.gz
506 gpg: Signature made Sun 16 Nov 2014 01:08:37 PM CET
507 gpg: using RSA key A9553245FDE9B739
508 gpg: Good signature from "Sami Kerola <kerolasa@@iki.fi>" [unknown]
509 gpg: aka "Sami Kerola (http://www.iki.fi/kerolasa/) <kerolasa@@iki.fi>" [unknown]
510 gpg: WARNING: This key is not certified with a trusted signature!
511 gpg: There is no indication that the signature belongs to the owner.
512 Primary key fingerprint: 8ED3 96E3 7E38 D471 A005 30D3 A955 3245 FDE9 B739
513 @end example
514
515 You can then happily run
516
517 @c TRANSLATORS: Do not translate this command
518 @example sh
519 $ guix package --install-from-file=my-hello.scm
520 @end example
521
522 You should now have @code{my-hello} in your profile!
523
524 @c TRANSLATORS: Do not translate this command
525 @example sh
526 $ guix package --list-installed=my-hello
527 my-hello 2.10 out
528 /gnu/store/f1db2mfm8syb8qvc357c53slbvf1g9m9-my-hello-2.10
529 @end example
530
531 We've gone as far as we could without any knowledge of Scheme. Before moving
532 on to more complex packages, now is the right time to brush up on your Scheme
533 knowledge. @pxref{A Scheme Crash Course} to get up to speed.
534
535 @node Setup
536 @subsection Setup
537
538 In the rest of this chapter we will rely on some basic Scheme
539 programming knowledge. Now let's detail the different possible setups
540 for working on Guix packages.
541
542 There are several ways to set up a Guix packaging environment.
543
544 We recommend you work directly on the Guix source checkout since it makes it
545 easier for everyone to contribute to the project.
546
547 But first, let's look at other possibilities.
548
549 @node Local file
550 @subsubsection Local file
551
552 This is what we previously did with @samp{my-hello}. With the Scheme basics we've
553 covered, we are now able to explain the leading chunks. As stated in @code{guix
554 package --help}:
555
556 @example
557 -f, --install-from-file=FILE
558 install the package that the code within FILE
559 evaluates to
560 @end example
561
562 Thus the last expression @emph{must} return a package, which is the case in our
563 earlier example.
564
565 The @code{use-modules} expression tells which of the modules we need in the file.
566 Modules are a collection of values and procedures. They are commonly called
567 ``libraries'' or ``packages'' in other programming languages.
568
569 @node @samp{GUIX_PACKAGE_PATH}
570 @subsubsection @samp{GUIX_PACKAGE_PATH}
571
572 @emph{Note: Starting from Guix 0.16, the more flexible Guix @dfn{channels} are the
573 preferred way and supersede @samp{GUIX_PACKAGE_PATH}. See next section.}
574
575 It can be tedious to specify the file from the command line instead of simply
576 calling @code{guix package --install my-hello} as you would do with the official
577 packages.
578
579 Guix makes it possible to streamline the process by adding as many ``package
580 declaration directories'' as you want.
581
582 Create a directory, say @samp{~./guix-packages} and add it to the @samp{GUIX_PACKAGE_PATH}
583 environment variable:
584
585 @example
586 $ mkdir ~/guix-packages
587 $ export GUIX_PACKAGE_PATH=~/guix-packages
588 @end example
589
590 To add several directories, separate them with a colon (@code{:}).
591
592 Our previous @samp{my-hello} needs some adjustments though:
593
594 @lisp
595 (define-module (my-hello)
596 #:use-module (guix licenses)
597 #:use-module (guix packages)
598 #:use-module (guix build-system gnu)
599 #:use-module (guix download))
600
601 (define-public my-hello
602 (package
603 (name "my-hello")
604 (version "2.10")
605 (source (origin
606 (method url-fetch)
607 (uri (string-append "mirror://gnu/hello/hello-" version
608 ".tar.gz"))
609 (sha256
610 (base32
611 "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
612 (build-system gnu-build-system)
613 (synopsis "Hello, Guix world: An example custom Guix package")
614 (description
615 "GNU Hello prints the message \"Hello, world!\" and then exits. It
616 serves as an example of standard GNU coding practices. As such, it supports
617 command-line arguments, multiple languages, and so on.")
618 (home-page "https://www.gnu.org/software/hello/")
619 (license gpl3+)))
620 @end lisp
621
622 Note that we have assigned the package value to an exported variable name with
623 @code{define-public}. This is effectively assigning the package to the @code{my-hello}
624 variable so that it can be referenced, among other as dependency of other
625 packages.
626
627 If you use @code{guix package --install-from-file=my-hello.scm} on the above file, it
628 will fail because the last expression, @code{define-public}, does not return a
629 package. If you want to use @code{define-public} in this use-case nonetheless, make
630 sure the file ends with an evaluation of @code{my-hello}:
631
632 @lisp
633 ; ...
634 (define-public my-hello
635 ; ...
636 )
637
638 my-hello
639 @end lisp
640
641 This last example is not very typical.
642
643 Now @samp{my-hello} should be part of the package collection like all other official
644 packages. You can verify this with:
645
646 @example
647 $ guix package --show=my-hello
648 @end example
649
650 @node Guix channels
651 @subsubsection Guix channels
652
653 Guix 0.16 features channels, which is very similar to @samp{GUIX_PACKAGE_PATH} but
654 provides better integration and provenance tracking. Channels are not
655 necessarily local, they can be maintained as a public Git repository for
656 instance. Of course, several channels can be used at the same time.
657
658 @xref{Channels,,, guix, GNU Guix Reference Manual} for setup details.
659
660 @node Direct checkout hacking
661 @subsubsection Direct checkout hacking
662
663 Working directly on the Guix project is recommended: it reduces the friction
664 when the time comes to submit your changes upstream to let the community benefit
665 from your hard work!
666
667 Unlike most software distributions, the Guix repository holds in one place both
668 the tooling (including the package manager) and the package definitions. This
669 choice was made so that it would give developers the flexibility to modify the
670 API without breakage by updating all packages at the same time. This reduces
671 development inertia.
672
673 Check out the official @uref{https://git-scm.com/, Git} repository:
674
675 @example
676 $ git clone https://git.savannah.gnu.org/git/guix.git
677 @end example
678
679 In the rest of this article, we use @samp{$GUIX_CHECKOUT} to refer to the location of
680 the checkout.
681
682
683 Follow the instructions in the manual (@pxref{Contributing,,, guix, GNU Guix
684 Reference Manual}) to set up the repository environment.
685
686 Once ready, you should be able to use the package definitions from the
687 repository environment.
688
689 Feel free to edit package definitions found in @samp{$GUIX_CHECKOUT/gnu/packages}.
690
691 The @samp{$GUIX_CHECKOUT/pre-inst-env} script lets you use @samp{guix} over the package
692 collection of the repository (@pxref{Running Guix Before It Is
693 Installed,,, guix, GNU Guix Reference Manual}).
694
695 @itemize
696 @item
697 Search packages, such as Ruby:
698
699 @example
700 $ cd $GUIX_CHECKOUT
701 $ ./pre-inst-env guix package --list-available=ruby
702 ruby 1.8.7-p374 out gnu/packages/ruby.scm:119:2
703 ruby 2.1.6 out gnu/packages/ruby.scm:91:2
704 ruby 2.2.2 out gnu/packages/ruby.scm:39:2
705 @end example
706
707 @item
708 Build a package, here Ruby version 2.1:
709
710 @example
711 $ ./pre-inst-env guix build --keep-failed ruby@@2.1
712 /gnu/store/c13v73jxmj2nir2xjqaz5259zywsa9zi-ruby-2.1.6
713 @end example
714
715 @item
716 Install it to your user profile:
717
718 @example
719 $ ./pre-inst-env guix package --install ruby@@2.1
720 @end example
721
722 @item
723 Check for common mistakes:
724
725 @example
726 $ ./pre-inst-env guix lint ruby@@2.1
727 @end example
728 @end itemize
729
730 Guix strives at maintaining a high packaging standard; when contributing to the
731 Guix project, remember to
732
733 @itemize
734 @item
735 follow the coding style (@pxref{Coding Style,,, guix, GNU Guix Reference Manual}),
736 @item
737 and review the check list from the manual (@pxref{Submitting Patches,,, guix, GNU Guix Reference Manual}).
738 @end itemize
739
740 Once you are happy with the result, you are welcome to send your contribution to
741 make it part of Guix. This process is also detailed in the manual. (@pxref{Contributing,,, guix, GNU Guix Reference Manual})
742
743
744 It's a community effort so the more join in, the better Guix becomes!
745
746 @node Extended example
747 @subsection Extended example
748
749 The above ``Hello World'' example is as simple as it goes. Packages can be more
750 complex than that and Guix can handle more advanced scenarios. Let's look at
751 another, more sophisticated package (slightly modified from the source):
752
753 @lisp
754 (define-module (gnu packages version-control)
755 #:use-module ((guix licenses) #:prefix license:)
756 #:use-module (guix utils)
757 #:use-module (guix packages)
758 #:use-module (guix git-download)
759 #:use-module (guix build-system cmake)
760 #:use-module (gnu packages ssh)
761 #:use-module (gnu packages web)
762 #:use-module (gnu packages pkg-config)
763 #:use-module (gnu packages python)
764 #:use-module (gnu packages compression)
765 #:use-module (gnu packages tls))
766
767 (define-public my-libgit2
768 (let ((commit "e98d0a37c93574d2c6107bf7f31140b548c6a7bf")
769 (revision "1"))
770 (package
771 (name "my-libgit2")
772 (version (git-version "0.26.6" revision commit))
773 (source (origin
774 (method git-fetch)
775 (uri (git-reference
776 (url "https://github.com/libgit2/libgit2/")
777 (commit commit)))
778 (file-name (git-file-name name version))
779 (sha256
780 (base32
781 "17pjvprmdrx4h6bb1hhc98w9qi6ki7yl57f090n9kbhswxqfs7s3"))
782 (patches (search-patches "libgit2-mtime-0.patch"))
783 (modules '((guix build utils)))
784 (snippet '(begin
785 ;; Remove bundled software.
786 (delete-file-recursively "deps")
787 #t))))
788 (build-system cmake-build-system)
789 (outputs '("out" "debug"))
790 (arguments
791 `(#:tests? #t ; Run the test suite (this is the default)
792 #:configure-flags '("-DUSE_SHA1DC=ON") ; SHA-1 collision detection
793 #:phases
794 (modify-phases %standard-phases
795 (add-after 'unpack 'fix-hardcoded-paths
796 (lambda _
797 (substitute* "tests/repo/init.c"
798 (("#!/bin/sh") (string-append "#!" (which "sh"))))
799 (substitute* "tests/clar/fs.h"
800 (("/bin/cp") (which "cp"))
801 (("/bin/rm") (which "rm")))
802 #t))
803 ;; Run checks more verbosely.
804 (replace 'check
805 (lambda _ (invoke "./libgit2_clar" "-v" "-Q")))
806 (add-after 'unpack 'make-files-writable-for-tests
807 (lambda _ (for-each make-file-writable (find-files "." ".*")))))))
808 (inputs
809 `(("libssh2" ,libssh2)
810 ("http-parser" ,http-parser)
811 ("python" ,python-wrapper)))
812 (native-inputs
813 `(("pkg-config" ,pkg-config)))
814 (propagated-inputs
815 ;; These two libraries are in 'Requires.private' in libgit2.pc.
816 `(("openssl" ,openssl)
817 ("zlib" ,zlib)))
818 (home-page "https://libgit2.github.com/")
819 (synopsis "Library providing Git core methods")
820 (description
821 "Libgit2 is a portable, pure C implementation of the Git core methods
822 provided as a re-entrant linkable library with a solid API, allowing you to
823 write native speed custom Git applications in any language with bindings.")
824 ;; GPLv2 with linking exception
825 (license license:gpl2))))
826 @end lisp
827
828 (In those cases were you only want to tweak a few fields from a package
829 definition, you should rely on inheritance instead of copy-pasting everything.
830 See below.)
831
832 Let's discuss those fields in depth.
833
834 @subsubsection @code{git-fetch} method
835
836 Unlike the @code{url-fetch} method, @code{git-fetch} expects a @code{git-reference} which takes
837 a Git repository and a commit. The commit can be any Git reference such as
838 tags, so if the @code{version} is tagged, then it can be used directly. Sometimes
839 the tag is prefixed with a @code{v}, in which case you'd use @code{(commit (string-append
840 "v" version))}.
841
842 To ensure that the source code from the Git repository is stored in a unique
843 directory with a readable name we use @code{(file-name (git-file-name name
844 version))}.
845
846 Note that there is also a @code{git-version} procedure that can be used to derive the
847 version when packaging programs for a specific commit.
848
849 @subsubsection Snippets
850
851 Snippets are quoted (i.e. non-evaluated) Scheme code that are a means of patching
852 the source. They are a Guix-y alternative to the traditional @samp{.patch} files.
853 Because of the quote, the code in only evaluated when passed to the Guix daemon
854 for building. There can be as many snippets as needed.
855
856 Snippets might need additional Guile modules which can be imported from the
857 @code{modules} field.
858
859 @subsubsection Inputs
860
861 First, a syntactic comment: See the quasi-quote / comma syntax?
862
863 @lisp
864 (native-inputs
865 `(("pkg-config" ,pkg-config)))
866 @end lisp
867
868 is equivalent to
869
870 @lisp
871 (native-inputs
872 (list (list "pkg-config" pkg-config)))
873 @end lisp
874
875 You'll mostly see the former because it's shorter.
876
877 There are 3 different input types. In short:
878
879 @table @asis
880 @item native-inputs
881 Required for building but not runtime -- installing a package
882 through a substitute won't install these inputs.
883 @item inputs
884 Installed in the store but not in the profile, as well as being
885 present at build time.
886 @item propagated-inputs
887 Installed in the store and in the profile, as well as
888 being present at build time.
889 @end table
890
891 @xref{Package Reference,,, guix, GNU Guix Reference Manual} for more details.
892
893 The distinction between the various inputs is important: if a dependency can be
894 handled as an @emph{input} instead of a @emph{propagated input}, it should be done so, or
895 else it ``pollutes'' the user profile for no good reason.
896
897 For instance, a user installing a graphical program that depends on a
898 command line tool might only be interested in the graphical part, so there is no
899 need to force the command line tool into the user profile. The dependency is a
900 concern to the package, not to the user. @emph{Inputs} make it possible to handle
901 dependencies without bugging the user by adding undesired executable files (or
902 libraries) to their profile.
903
904 Same goes for @emph{native-inputs}: once the program is installed, build-time
905 dependencies can be safely garbage-collected.
906 It also matters when a substitute is available, in which case only the @emph{inputs}
907 and @emph{propagated inputs} will be fetched: the @emph{native inputs} are not required to
908 install a package from a substitute.
909
910 @subsubsection Outputs
911
912 Just like how a package can have multiple inputs, it can also produce multiple
913 outputs.
914
915 Each output corresponds to a separate directory in the store.
916
917 The user can choose which output to install; this is useful to save space or
918 to avoid polluting the user profile with unwanted executables or libraries.
919
920 Output separation is optional. When the @code{outputs} field is left out, the
921 default and only output (the complete package) is referred to as @code{"out"}.
922
923 Typical separate output names include @code{debug} and @code{doc}.
924
925 It's advised to separate outputs only when you've shown it's worth it: if the
926 output size is significant (compare with @code{guix size}) or in case the package is
927 modular.
928
929 @subsubsection Build system arguments
930
931 The @code{arguments} is a keyword-value list used to configure the build process.
932
933 The simplest argument @code{#:tests?} can be used to disable the test suite when
934 building the package. This is mostly useful when the package does not feature
935 any test suite. It's strongly recommended to keep the test suite on if there is
936 one.
937
938 Another common argument is @code{:make-flags}, which specifies a list of flags to
939 append when running make, as you would from the command line. For instance, the
940 following flags
941
942 @lisp
943 #:make-flags (list (string-append "prefix=" (assoc-ref %outputs "out"))
944 "CC=gcc")
945 @end lisp
946
947 translate into
948
949 @example
950 $ make CC=gcc prefix=/gnu/store/...-<out>
951 @end example
952
953 This sets the C compiler to @code{gcc} and the @code{prefix} variable (the installation
954 directory in Make parlance) to @code{(assoc-ref %outputs "out")}, which is a build-stage
955 global variable pointing to the destination directory in the store (something like
956 @samp{/gnu/store/...-my-libgit2-20180408}).
957
958 Similarly, it's possible to set the configure flags:
959
960 @lisp
961 #:configure-flags '("-DUSE_SHA1DC=ON")
962 @end lisp
963
964 The @code{%build-inputs} variable is also generated in scope. It's an association
965 table that maps the input names to their store directories.
966
967 The @code{phases} keyword lists the sequential steps of the build system. Typically
968 phases include @code{unpack}, @code{configure}, @code{build}, @code{install} and @code{check}. To know
969 more about those phases, you need to work out the appropriate build system
970 definition in @samp{$GUIX_CHECKOUT/guix/build/gnu-build-system.scm}:
971
972 @lisp
973 (define %standard-phases
974 ;; Standard build phases, as a list of symbol/procedure pairs.
975 (let-syntax ((phases (syntax-rules ()
976 ((_ p ...) `((p . ,p) ...)))))
977 (phases set-SOURCE-DATE-EPOCH set-paths install-locale unpack
978 bootstrap
979 patch-usr-bin-file
980 patch-source-shebangs configure patch-generated-file-shebangs
981 build check install
982 patch-shebangs strip
983 validate-runpath
984 validate-documentation-location
985 delete-info-dir-file
986 patch-dot-desktop-files
987 install-license-files
988 reset-gzip-timestamps
989 compress-documentation)))
990 @end lisp
991
992 Or from the REPL:
993
994 @lisp
995 (add-to-load-path "/path/to/guix/checkout")
996 ,use (guix build gnu-build-system)
997 (map first %standard-phases)
998 @result{} (set-SOURCE-DATE-EPOCH set-paths install-locale unpack bootstrap patch-usr-bin-file patch-source-shebangs configure patch-generated-file-shebangs build check install patch-shebangs strip validate-runpath validate-documentation-location delete-info-dir-file patch-dot-desktop-files install-license-files reset-gzip-timestamps compress-documentation)
999 @end lisp
1000
1001 If you want to know more about what happens during those phases, consult the
1002 associated procedures.
1003
1004 For instance, as of this writing the definition of @code{unpack} for the GNU build
1005 system is
1006
1007 @lisp
1008 (define* (unpack #:key source #:allow-other-keys)
1009 "Unpack SOURCE in the working directory, and change directory within the
1010 source. When SOURCE is a directory, copy it in a sub-directory of the current
1011 working directory."
1012 (if (file-is-directory? source)
1013 (begin
1014 (mkdir "source")
1015 (chdir "source")
1016
1017 ;; Preserve timestamps (set to the Epoch) on the copied tree so that
1018 ;; things work deterministically.
1019 (copy-recursively source "."
1020 #:keep-mtime? #t))
1021 (begin
1022 (if (string-suffix? ".zip" source)
1023 (invoke "unzip" source)
1024 (invoke "tar" "xvf" source))
1025 (chdir (first-subdirectory "."))))
1026 #t)
1027 @end lisp
1028
1029 Note the @code{chdir} call: it changes the working directory to where the source was
1030 unpacked.
1031 Thus every phase following the @code{unpack} will use the source as a working
1032 directory, which is why we can directly work on the source files.
1033 That is to say, unless a later phase changes the working directory to something
1034 else.
1035
1036 We modify the list of @code{%standard-phases} of the build system with the
1037 @code{modify-phases} macro as per the list of specified modifications, which may have
1038 the following forms:
1039
1040 @itemize
1041 @item
1042 @code{(add-before PHASE NEW-PHASE PROCEDURE)}: Run @code{PROCEDURE} named @code{NEW-PHASE} before @code{PHASE}.
1043 @item
1044 @code{(add-after PHASE NEW-PHASE PROCEDURE)}: Same, but afterwards.
1045 @item
1046 @code{(replace PHASE PROCEDURE)}.
1047 @item
1048 @code{(delete PHASE)}.
1049 @end itemize
1050
1051 The @code{PROCEDURE} supports the keyword arguments @code{inputs} and @code{outputs}. Each
1052 input (whether @emph{native}, @emph{propagated} or not) and output directory is referenced
1053 by their name in those variables. Thus @code{(assoc-ref outputs "out")} is the store
1054 directory of the main output of the package. A phase procedure may look like
1055 this:
1056
1057 @lisp
1058 (lambda* (#:key inputs outputs #:allow-other-keys)
1059 (let (((bash-directory (assoc-ref inputs "bash"))
1060 (output-directory (assoc-ref outputs "out"))
1061 (doc-directory (assoc-ref outputs "doc"))
1062 ; ...
1063 #t)
1064 @end lisp
1065
1066 The procedure must return @code{#t} on success. It's brittle to rely on the return
1067 value of the last expression used to tweak the phase because there is no
1068 guarantee it would be a @code{#t}. Hence the trailing @code{#t} to ensure the right value
1069 is returned on success.
1070
1071 @subsubsection Code staging
1072
1073 The astute reader may have noticed the quasi-quote and comma syntax in the
1074 argument field. Indeed, the build code in the package declaration should not be
1075 evaluated on the client side, but only when passed to the Guix daemon. This
1076 mechanism of passing code around two running processes is called @uref{https://arxiv.org/abs/1709.00833, code staging}.
1077
1078 @subsubsection Utility functions
1079
1080 When customizing @code{phases}, we often need to write code that mimics the
1081 equivalent system invocations (@code{make}, @code{mkdir}, @code{cp}, etc.) commonly used during
1082 regular ``Unix-style'' installations.
1083
1084 Some like @code{chmod} are native to Guile.
1085 @xref{,,, guile, Guile reference manual} for a complete list.
1086
1087 Guix provides additional helper functions which prove especially handy in the
1088 context of package management.
1089
1090 Some of those functions can be found in
1091 @samp{$GUIX_CHECKOUT/guix/guix/build/utils.scm}. Most of them mirror the behaviour
1092 of the traditional Unix system commands:
1093
1094 @table @asis
1095 @item which
1096 Like the @samp{which} system command.
1097 @item find-files
1098 Akin to the @samp{find} system command.
1099 @item mkdir-p
1100 Like @samp{mkdir -p}, which creates all parents as needed.
1101 @item install-file
1102 Similar to @samp{install} when installing a file to a (possibly
1103 non-existing) directory. Guile has @code{copy-file} which works
1104 like @samp{cp}.
1105 @item copy-recursively
1106 Like @samp{cp -r}.
1107 @item delete-file-recursively
1108 Like @samp{rm -rf}.
1109 @item invoke
1110 Run an executable. This should be used instead of @code{system*}.
1111 @item with-directory-excursion
1112 Run the body in a different working directory,
1113 then restore the previous working directory.
1114 @item substitute*
1115 A ``@command{sed}-like'' function.
1116 @end table
1117
1118 @subsubsection Module prefix
1119
1120 The license in our last example needs a prefix: this is because of how the
1121 @code{license} module was imported in the package, as @code{#:use-module ((guix licenses)
1122 #:prefix license:)}. The Guile module import mechanism
1123 (@pxref{Using Guile Modules,,, guile, Guile reference manual})
1124 gives the user full control over namespacing: this is needed to avoid
1125 clashes between, say, the
1126 @samp{zlib} variable from @samp{licenses.scm} (a @emph{license} value) and the @samp{zlib} variable
1127 from @samp{compression.scm} (a @emph{package} value).
1128
1129 @node Other build systems
1130 @subsection Other build systems
1131
1132 What we've seen so far covers the majority of packages using a build system
1133 other than the @code{trivial-build-system}. The latter does not automate anything
1134 and leaves you to build everything manually. This can be more demanding and we
1135 won't cover it here for now, but thankfully it is rarely necessary to fall back
1136 on this system.
1137
1138 For the other build systems, such as ASDF, Emacs, Perl, Ruby and many more, the
1139 process is very similar to the GNU build system except for a few specialized
1140 arguments.
1141
1142 @xref{Build Systems,,, guix, GNU Guix Reference Manual}, for more
1143 information on build systems, or check the source code in the
1144 @samp{$GUIX_CHECKOUT/guix/build} and
1145 @samp{$GUIX_CHECKOUT/guix/build-system} directories.
1146
1147 @node Programmable and automated package definition
1148 @subsection Programmable and automated package definition
1149
1150 We can't repeat it enough: having a full-fledged programming language at hand
1151 empowers us in ways that reach far beyond traditional package management.
1152
1153 Let's illustrate this with some awesome features of Guix!
1154
1155 @node Recursive importers
1156 @subsubsection Recursive importers
1157
1158 You might find some build systems good enough that there is little to do at all
1159 to write a package, to the point that it becomes repetitive and tedious after a
1160 while. A @emph{raison d'être} of computers is to replace human beings at those
1161 boring tasks. So let's tell Guix to do this for us and create the package
1162 definition of an R package from CRAN (the output is trimmed for conciseness):
1163
1164 @example
1165 $ guix import cran --recursive walrus
1166
1167 (define-public r-mc2d
1168 ; ...
1169 (license gpl2+)))
1170
1171 (define-public r-jmvcore
1172 ; ...
1173 (license gpl2+)))
1174
1175 (define-public r-wrs2
1176 ; ...
1177 (license gpl3)))
1178
1179 (define-public r-walrus
1180 (package
1181 (name "r-walrus")
1182 (version "1.0.3")
1183 (source
1184 (origin
1185 (method url-fetch)
1186 (uri (cran-uri "walrus" version))
1187 (sha256
1188 (base32
1189 "1nk2glcvy4hyksl5ipq2mz8jy4fss90hx6cq98m3w96kzjni6jjj"))))
1190 (build-system r-build-system)
1191 (propagated-inputs
1192 `(("r-ggplot2" ,r-ggplot2)
1193 ("r-jmvcore" ,r-jmvcore)
1194 ("r-r6" ,r-r6)
1195 ("r-wrs2" ,r-wrs2)))
1196 (home-page "https://github.com/jamovi/walrus")
1197 (synopsis "Robust Statistical Methods")
1198 (description
1199 "This package provides a toolbox of common robust statistical
1200 tests, including robust descriptives, robust t-tests, and robust ANOVA.
1201 It is also available as a module for 'jamovi' (see
1202 <https://www.jamovi.org> for more information). Walrus is based on the
1203 WRS2 package by Patrick Mair, which is in turn based on the scripts and
1204 work of Rand Wilcox. These analyses are described in depth in the book
1205 'Introduction to Robust Estimation & Hypothesis Testing'.")
1206 (license gpl3)))
1207 @end example
1208
1209 The recursive importer won't import packages for which Guix already has package
1210 definitions, except for the very first.
1211
1212 Not all applications can be packaged this way, only those relying on a select
1213 number of supported systems. Read about the full list of importers in
1214 the guix import section of the manual
1215 (@pxref{Invoking guix import,,, guix, GNU Guix Reference Manual}).
1216
1217 @node Automatic update
1218 @subsubsection Automatic update
1219
1220 Guix can be smart enough to check for updates on systems it knows. It can
1221 report outdated package definitions with
1222
1223 @example
1224 $ guix refresh hello
1225 @end example
1226
1227 In most cases, updating a package to a newer version requires little more than
1228 changing the version number and the checksum. Guix can do that automatically as
1229 well:
1230
1231 @example
1232 $ guix refresh hello --update
1233 @end example
1234
1235 @node Inheritance
1236 @subsubsection Inheritance
1237
1238 If you've started browsing the existing package definitions, you might have
1239 noticed that a significant number of them have a @code{inherit} field:
1240
1241 @lisp
1242 (define-public adwaita-icon-theme
1243 (package (inherit gnome-icon-theme)
1244 (name "adwaita-icon-theme")
1245 (version "3.26.1")
1246 (source (origin
1247 (method url-fetch)
1248 (uri (string-append "mirror://gnome/sources/" name "/"
1249 (version-major+minor version) "/"
1250 name "-" version ".tar.xz"))
1251 (sha256
1252 (base32
1253 "17fpahgh5dyckgz7rwqvzgnhx53cx9kr2xw0szprc6bnqy977fi8"))))
1254 (native-inputs
1255 `(("gtk-encode-symbolic-svg" ,gtk+ "bin")))))
1256 @end lisp
1257
1258 All unspecified fields are inherited from the parent package. This is very
1259 convenient to create alternative packages, for instance with different source,
1260 version or compilation options.
1261
1262 @node Getting help
1263 @subsection Getting help
1264
1265 Sadly, some applications can be tough to package. Sometimes they need a patch to
1266 work with the non-standard filesystem hierarchy enforced by the store.
1267 Sometimes the tests won't run properly. (They can be skipped but this is not
1268 recommended.) Other times the resulting package won't be reproducible.
1269
1270 Should you be stuck, unable to figure out how to fix any sort of packaging
1271 issue, don't hesitate to ask the community for help.
1272
1273 See the @uref{https://www.gnu.org/software/guix/contact/, Guix homepage} for information on the mailing lists, IRC, etc.
1274
1275 @node Conclusion
1276 @subsection Conclusion
1277
1278 This tutorial was a showcase of the sophisticated package management that Guix
1279 boasts. At this point we have mostly restricted this introduction to the
1280 @code{gnu-build-system} which is a core abstraction layer on which more advanced
1281 abstractions are based.
1282
1283 Where do we go from here? Next we ought to dissect the innards of the build
1284 system by removing all abstractions, using the @code{trivial-build-system}: this
1285 should give us a thorough understanding of the process before investigating some
1286 more advanced packaging techniques and edge cases.
1287
1288 Other features worth exploring are the interactive editing and debugging
1289 capabilities of Guix provided by the Guile REPL@.
1290
1291 Those fancy features are completely optional and can wait; now is a good time
1292 to take a well-deserved break. With what we've introduced here you should be
1293 well armed to package lots of programs. You can get started right away and
1294 hopefully we will see your contributions soon!
1295
1296 @node References
1297 @subsection References
1298
1299 @itemize
1300 @item
1301 The @uref{https://www.gnu.org/software/guix/manual/en/html_node/Defining-Packages.html, package reference in the manual}
1302
1303 @item
1304 @uref{https://gitlab.com/pjotrp/guix-notes/blob/master/HACKING.org, Pjotr’s hacking guide to GNU Guix}
1305
1306 @item
1307 @uref{https://www.gnu.org/software/guix/guix-ghm-andreas-20130823.pdf, ``GNU Guix: Package without a scheme!''}, by Andreas Enge
1308 @end itemize
1309
1310 @c *********************************************************************
1311 @node System Configuration
1312 @chapter System Configuration
1313
1314 Guix offers a flexible language for declaratively configuring your Guix
1315 System. This flexibility can at times be overwhelming. The purpose of this
1316 chapter is to demonstrate some advanced configuration concepts.
1317
1318 @pxref{System Configuration,,, guix, GNU Guix Reference Manual} for a complete
1319 reference.
1320
1321 @menu
1322 * Customizing the Kernel:: Creating and using a custom Linux kernel on Guix System.
1323 @end menu
1324
1325 @node Customizing the Kernel
1326 @section Customizing the Kernel
1327
1328 Guix is, at its core, a source based distribution with substitutes
1329 (@pxref{Substitutes,,, guix, GNU Guix Reference Manual}), and as such building
1330 packages from their source code is an expected part of regular package
1331 installations and upgrades. Given this starting point, it makes sense that
1332 efforts are made to reduce the amount of time spent compiling packages, and
1333 recent changes and upgrades to the building and distribution of substitutes
1334 continues to be a topic of discussion within Guix.
1335
1336 The kernel, while not requiring an overabundance of RAM to build, does take a
1337 rather long time on an average machine. The official kernel configuration, as
1338 is the case with many GNU/Linux distributions, errs on the side of
1339 inclusiveness, and this is really what causes the build to take such a long
1340 time when the kernel is built from source.
1341
1342 The Linux kernel, however, can also just be described as a regular old
1343 package, and as such can be customized just like any other package. The
1344 procedure is a little bit different, although this is primarily due to the
1345 nature of how the package definition is written.
1346
1347 The @code{linux-libre} kernel package definition is actually a procedure which
1348 creates a package.
1349
1350 @lisp
1351 (define* (make-linux-libre version hash supported-systems
1352 #:key
1353 ;; A function that takes an arch and a variant.
1354 ;; See kernel-config for an example.
1355 (extra-version #f)
1356 (configuration-file #f)
1357 (defconfig "defconfig")
1358 (extra-options %default-extra-linux-options)
1359 (patches (list %boot-logo-patch)))
1360 ...)
1361 @end lisp
1362
1363 The current @code{linux-libre} package is for the 5.1.x series, and is
1364 declared like this:
1365
1366 @lisp
1367 (define-public linux-libre
1368 (make-linux-libre %linux-libre-version
1369 %linux-libre-hash
1370 '("x86_64-linux" "i686-linux" "armhf-linux" "aarch64-linux")
1371 #:patches %linux-libre-5.1-patches
1372 #:configuration-file kernel-config))
1373 @end lisp
1374
1375 Any keys which are not assigned values inherit their default value from the
1376 @code{make-linux-libre} definition. When comparing the two snippets above,
1377 you may notice that the code comment in the first doesn't actually refer to
1378 the @code{#:extra-version} keyword; it is actually for
1379 @code{#:configuration-file}. Because of this, it is not actually easy to
1380 include a custom kernel configuration from the definition, but don't worry,
1381 there are other ways to work with what we do have.
1382
1383 There are two ways to create a kernel with a custom kernel configuration. The
1384 first is to provide a standard @file{.config} file during the build process by
1385 including an actual @file{.config} file as a native input to our custom
1386 kernel. The following is a snippet from the custom @code{'configure} phase of
1387 the @code{make-linux-libre} package definition:
1388
1389 @lisp
1390 (let ((build (assoc-ref %standard-phases 'build))
1391 (config (assoc-ref (or native-inputs inputs) "kconfig")))
1392
1393 ;; Use a custom kernel configuration file or a default
1394 ;; configuration file.
1395 (if config
1396 (begin
1397 (copy-file config ".config")
1398 (chmod ".config" #o666))
1399 (invoke "make" ,defconfig))
1400 @end lisp
1401
1402 Below is a sample kernel package. The @code{linux-libre} package is nothing
1403 special and can be inherited from and have its fields overridden like any
1404 other package:
1405
1406 @lisp
1407 (define-public linux-libre/E2140
1408 (package
1409 (inherit linux-libre)
1410 (native-inputs
1411 `(("kconfig" ,(local-file "E2140.config"))
1412 ,@@(alist-delete "kconfig"
1413 (package-native-inputs linux-libre))))))
1414 @end lisp
1415
1416 In the same directory as the file defining @code{linux-libre-E2140} is a file
1417 named @file{E2140.config}, which is an actual kernel configuration file. The
1418 @code{defconfig} keyword of @code{make-linux-libre} is left blank here, so the
1419 only kernel configuration in the package is the one which was included in the
1420 @code{native-inputs} field.
1421
1422 The second way to create a custom kernel is to pass a new value to the
1423 @code{extra-options} keyword of the @code{make-linux-libre} procedure. The
1424 @code{extra-options} keyword works with another function defined right below
1425 it:
1426
1427 @lisp
1428 (define %default-extra-linux-options
1429 `(;; https://lists.gnu.org/archive/html/guix-devel/2014-04/msg00039.html
1430 ("CONFIG_DEVPTS_MULTIPLE_INSTANCES" . #t)
1431 ;; Modules required for initrd:
1432 ("CONFIG_NET_9P" . m)
1433 ("CONFIG_NET_9P_VIRTIO" . m)
1434 ("CONFIG_VIRTIO_BLK" . m)
1435 ("CONFIG_VIRTIO_NET" . m)
1436 ("CONFIG_VIRTIO_PCI" . m)
1437 ("CONFIG_VIRTIO_BALLOON" . m)
1438 ("CONFIG_VIRTIO_MMIO" . m)
1439 ("CONFIG_FUSE_FS" . m)
1440 ("CONFIG_CIFS" . m)
1441 ("CONFIG_9P_FS" . m)))
1442
1443 (define (config->string options)
1444 (string-join (map (match-lambda
1445 ((option . 'm)
1446 (string-append option "=m"))
1447 ((option . #t)
1448 (string-append option "=y"))
1449 ((option . #f)
1450 (string-append option "=n")))
1451 options)
1452 "\n"))
1453 @end lisp
1454
1455 And in the custom configure script from the `make-linux-libre` package:
1456
1457 @lisp
1458 ;; Appending works even when the option wasn't in the
1459 ;; file. The last one prevails if duplicated.
1460 (let ((port (open-file ".config" "a"))
1461 (extra-configuration ,(config->string extra-options)))
1462 (display extra-configuration port)
1463 (close-port port))
1464
1465 (invoke "make" "oldconfig"))))
1466 @end lisp
1467
1468 So by not providing a configuration-file the @file{.config} starts blank, and
1469 then we write into it the collection of flags that we want. Here's another
1470 custom kernel:
1471
1472 @lisp
1473 (define %macbook41-full-config
1474 (append %macbook41-config-options
1475 %filesystems
1476 %efi-support
1477 %emulation
1478 (@@@@ (gnu packages linux) %default-extra-linux-options)))
1479
1480 (define-public linux-libre-macbook41
1481 ;; XXX: Access the internal 'make-linux-libre' procedure, which is
1482 ;; private and unexported, and is liable to change in the future.
1483 ((@@@@ (gnu packages linux) make-linux-libre) (@@@@ (gnu packages linux) %linux-libre-version)
1484 (@@@@ (gnu packages linux) %linux-libre-hash)
1485 '("x86_64-linux")
1486 #:extra-version "macbook41"
1487 #:patches (@@@@ (gnu packages linux) %linux-libre-5.1-patches)
1488 #:extra-options %macbook41-config-options))
1489 @end lisp
1490
1491 In the above example @code{%filesystems} is a collection of flags enabling
1492 different filesystem support, @code{%efi-support} enables EFI support and
1493 @code{%emulation} enables a x86_64-linux machine to act in 32-bit mode also.
1494 @code{%default-extra-linux-options} are the ones quoted above, which had to be
1495 added in since they were replaced in the @code{extra-options} keyword.
1496
1497 This all sounds like it should be doable, but how does one even know which
1498 modules are required for a particular system? Two places that can be helpful
1499 in trying to answer this question is the
1500 @uref{https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel, Gentoo
1501 Handbook} and the
1502 @uref{https://www.kernel.org/doc/html/latest/admin-guide/README.html?highlight=localmodconfig,
1503 documentation from the kernel itself}. From the kernel documentation, it
1504 seems that @code{make localmodconfig} is the command we want.
1505
1506 In order to actually run @code{make localmodconfig} we first need to get and
1507 unpack the kernel source code:
1508
1509 @example shell
1510 tar xf $(guix build linux-libre --source)
1511 @end example
1512
1513 Once inside the directory containing the source code run @code{touch .config}
1514 to create an initial, empty @file{.config} to start with. @code{make
1515 localmodconfig} works by seeing what you already have in @file{.config} and
1516 letting you know what you're missing. If the file is blank then you're
1517 missing everything. The next step is to run:
1518
1519 @example shell
1520 guix environment linux-libre -- make localmodconfig
1521 @end example
1522
1523 and note the output. Do note that the @file{.config} file is still empty.
1524 The output generally contains two types of warnings. The first start with
1525 "WARNING" and can actually be ignored in our case. The second read:
1526
1527 @example shell
1528 module pcspkr did not have configs CONFIG_INPUT_PCSPKR
1529 @end example
1530
1531 For each of these lines, copy the @code{CONFIG_XXXX_XXXX} portion into the
1532 @file{.config} in the directory, and append @code{=m}, so in the end it looks
1533 like this:
1534
1535 @example shell
1536 CONFIG_INPUT_PCSPKR=m
1537 CONFIG_VIRTIO=m
1538 @end example
1539
1540 After copying all the configuration options, run @code{make localmodconfig}
1541 again to make sure that you don't have any output starting with ``module''.
1542 After all of these machine specific modules there are a couple more left that
1543 are also needed. @code{CONFIG_MODULES} is necessary so that you can build and
1544 load modules separately and not have everything built into the kernel.
1545 @code{CONFIG_BLK_DEV_SD} is required for reading from hard drives. It is
1546 possible that there are other modules which you will need.
1547
1548 This post does not aim to be a guide to configuring your own kernel however,
1549 so if you do decide to build a custom kernel you'll have to seek out other
1550 guides to create a kernel which is just right for your needs.
1551
1552 The second way to setup the kernel configuration makes more use of Guix's
1553 features and allows you to share configuration segments between different
1554 kernels. For example, all machines using EFI to boot have a number of EFI
1555 configuration flags that they need. It is likely that all the kernels will
1556 share a list of filesystems to support. By using variables it is easier to
1557 see at a glance what features are enabled and to make sure you don't have
1558 features in one kernel but missing in another.
1559
1560 Left undiscussed however, is Guix's initrd and its customization. It is
1561 likely that you'll need to modify the initrd on a machine using a custom
1562 kernel, since certain modules which are expected to be built may not be
1563 available for inclusion into the initrd.
1564
1565 @c *********************************************************************
1566 @node Advanced package management
1567 @chapter Advanced package management
1568
1569 Guix is a functional package manager that offers many features beyond
1570 what more traditional package managers can do. To the uninitiated,
1571 those features might not have obvious use cases at first. The purpose
1572 of this chapter is to demonstrate some advanced package management
1573 concepts.
1574
1575 @pxref{Package Management,,, guix, GNU Guix Reference Manual} for a complete
1576 reference.
1577
1578 @menu
1579 * Guix Profiles in Practice:: Strategies for multiple profiles and manifests.
1580 @end menu
1581
1582 @node Guix Profiles in Practice
1583 @section Guix Profiles in Practice
1584
1585 Guix provides a very useful feature that may be quite foreign to newcomers:
1586 @emph{profiles}. They are a way to group package installations together and all users
1587 on the same system are free to use as many profiles as they want.
1588
1589 Whether you're a developer or not, you may find that multiple profiles bring you
1590 great power and flexibility. While they shift the paradigm somewhat compared to
1591 @emph{traditional package managers}, they are very convenient to use once you've
1592 understood how to set them up.
1593
1594 If you are familiar with Python's @samp{virtualenv}, you can think of a profile as a
1595 kind of universal @samp{virtualenv} that can hold any kind of software whatsoever, not
1596 just Python software. Furthermore, profiles are self-sufficient: they capture
1597 all the runtime dependencies which guarantees that all programs within a profile
1598 will always work at any point in time.
1599
1600 Multiple profiles have many benefits:
1601
1602 @itemize
1603 @item
1604 Clean semantic separation of the various packages a user needs for different contexts.
1605
1606 @item
1607 Multiple profiles can be made available into the environment either on login
1608 or within a dedicated shell.
1609
1610 @item
1611 Profiles can be loaded on demand. For instance, the user can use multiple
1612 shells, each of them running different profiles.
1613
1614 @item
1615 Isolation: Programs from one profile will not use programs from the other, and
1616 the user can even install different versions of the same programs to the two
1617 profiles without conflict.
1618
1619 @item
1620 Deduplication: Profiles share dependencies that happens to be the exact same.
1621 This makes multiple profiles storage-efficient.
1622
1623 @item
1624 Reproducible: when used with declarative manifests, a profile can be fully
1625 specified by the Guix commit that was active when it was set up. This means
1626 that the exact same profile can be
1627 @uref{https://guix.gnu.org/blog/2018/multi-dimensional-transactions-and-rollbacks-oh-my/,
1628 set up anywhere and anytime}, with just the commit information. See the
1629 section on @ref{Reproducible profiles}.
1630
1631 @item
1632 Easier upgrades and maintenance: Multiple profiles make it easy to keep
1633 package listings at hand and make upgrades completely friction-less.
1634 @end itemize
1635
1636 Concretely, here follows some typical profiles:
1637
1638 @itemize
1639 @item
1640 The dependencies of a project you are working on.
1641
1642 @item
1643 Your favourite programming language libraries.
1644
1645 @item
1646 Laptop-specific programs (like @samp{powertop}) that you don't need on a desktop.
1647
1648 @item
1649 @TeX{}live (this one can be really useful when you need to install just one
1650 package for this one document you've just received over email).
1651
1652 @item
1653 Games.
1654 @end itemize
1655
1656 Let's dive in the set up!
1657
1658 @node Basic setup with manifests
1659 @subsection Basic setup with manifests
1660
1661 A Guix profile can be set up @emph{via} a so-called @emph{manifest specification} that looks like
1662 this:
1663
1664 @lisp
1665 (specifications->manifest
1666 '("package-1"
1667 ;; Version 1.3 of package-2.
1668 "package-2@@1.3"
1669 ;; The "lib" output of package-3.
1670 "package-3:lib"
1671 ; ...
1672 "package-N"))
1673 @end lisp
1674
1675 @pxref{Invoking guix package,,, guix, GNU Guix Reference Manual}, for
1676 the syntax details.
1677
1678 We can create a manifest specification per profile and install them this way:
1679
1680 @example
1681 GUIX_EXTRA_PROFILES=$HOME/.guix-extra-profiles
1682 mkdir -p "$GUIX_EXTRA_PROFILES"/my-project # if it does not exist yet
1683 guix package --manifest=/path/to/guix-my-project-manifest.scm --profile="$GUIX_EXTRA_PROFILES"/my-project/my-project
1684 @end example
1685
1686 Here we set an arbitrary variable @samp{GUIX_EXTRA_PROFILES} to point to the directory
1687 where we will store our profiles in the rest of this article.
1688
1689 Placing all your profiles in a single directory, with each profile getting its
1690 own sub-directory, is somewhat cleaner. This way, each sub-directory will
1691 contain all the symlinks for precisely one profile. Besides, "looping over
1692 profiles" becomes obvious from any programming language (e.g. a shell script) by
1693 simply looping over the sub-directories of @samp{$GUIX_EXTRA_PROFILES}.
1694
1695 Note that it's also possible to loop over the output of
1696
1697 @example
1698 guix package --list-profiles
1699 @end example
1700
1701 although you'll probably have to filter out @samp{~/.config/guix/current}.
1702
1703 To enable all profiles on login, add this to your @samp{~/.bash_profile} (or similar):
1704
1705 @example
1706 for i in $GUIX_EXTRA_PROFILES/*; do
1707 profile=$i/$(basename "$i")
1708 if [ -f "$profile"/etc/profile ]; then
1709 GUIX_PROFILE="$profile"
1710 . "$GUIX_PROFILE"/etc/profile
1711 fi
1712 unset profile
1713 done
1714 @end example
1715
1716 Note to Guix System users: the above reflects how your default profile
1717 @samp{~/.guix-profile} is activated from @samp{/etc/profile}, that latter being loaded by
1718 @samp{~/.bashrc} by default.
1719
1720 You can obviously choose to only enable a subset of them:
1721
1722 @example
1723 for i in "$GUIX_EXTRA_PROFILES"/my-project-1 "$GUIX_EXTRA_PROFILES"/my-project-2; do
1724 profile=$i/$(basename "$i")
1725 if [ -f "$profile"/etc/profile ]; then
1726 GUIX_PROFILE="$profile"
1727 . "$GUIX_PROFILE"/etc/profile
1728 fi
1729 unset profile
1730 done
1731 @end example
1732
1733 When a profile is off, it's straightforward to enable it for an individual shell
1734 without "polluting" the rest of the user session:
1735
1736 @example
1737 GUIX_PROFILE="path/to/my-project" ; . "$GUIX_PROFILE"/etc/profile
1738 @end example
1739
1740 The key to enabling a profile is to @emph{source} its @samp{etc/profile} file. This file
1741 contains shell code that exports the right environment variables necessary to
1742 activate the software contained in the profile. It is built automatically by
1743 Guix and meant to be sourced.
1744 It contains the same variables you would get if you ran:
1745
1746 @example
1747 guix package --search-paths=prefix --profile=$my_profile"
1748 @end example
1749
1750 Once again, see (@pxref{Invoking guix package,,, guix, GNU Guix Reference Manual})
1751 for the command line options.
1752
1753 To upgrade a profile, simply install the manifest again:
1754
1755 @example
1756 guix package -m /path/to/guix-my-project-manifest.scm -p "$GUIX_EXTRA_PROFILES"/my-project/my-project
1757 @end example
1758
1759 To upgrade all profiles, it's easy enough to loop over them. For instance,
1760 assuming your manifest specifications are stored in
1761 @samp{~/.guix-manifests/guix-$profile-manifest.scm}, with @samp{$profile} being the name
1762 of the profile (e.g. "project1"), you could do the following in Bourne shell:
1763
1764 @example
1765 for profile in "$GUIX_EXTRA_PROFILES"/*; do
1766 guix package --profile="$profile" --manifest="$HOME/.guix-manifests/guix-$profile-manifest.scm"
1767 done
1768 @end example
1769
1770 Each profile has its own generations:
1771
1772 @example
1773 guix package -p "$GUIX_EXTRA_PROFILES"/my-project/my-project --list-generations
1774 @end example
1775
1776 You can roll-back to any generation of a given profile:
1777
1778 @example
1779 guix package -p "$GUIX_EXTRA_PROFILES"/my-project/my-project --switch-generations=17
1780 @end example
1781
1782 Finally, if you want to switch to a profile without inheriting from the
1783 current environment, you can activate it from an empty shell:
1784
1785 @example
1786 env -i $(which bash) --login --noprofile --norc
1787 . my-project/etc/profile
1788 @end example
1789
1790 @node Required packages
1791 @subsection Required packages
1792
1793 Activating a profile essentially boils down to exporting a bunch of
1794 environmental variables. This is the role of the @samp{etc/profile} within the
1795 profile.
1796
1797 @emph{Note: Only the environmental variables of the packages that consume them will
1798 be set.}
1799
1800 For instance, @samp{MANPATH} won't be set if there is no consumer application for man
1801 pages within the profile. So if you need to transparently access man pages once
1802 the profile is loaded, you've got two options:
1803
1804 @itemize
1805 @item
1806 Either export the variable manually, e.g.
1807 @example
1808 export MANPATH=/path/to/profile$@{MANPATH:+:@}$MANPATH
1809 @end example
1810
1811 @item
1812 Or include @samp{man-db} to the profile manifest.
1813 @end itemize
1814
1815 The same is true for @samp{INFOPATH} (you can install @samp{info-reader}),
1816 @samp{PKG_CONFIG_PATH} (install @samp{pkg-config}), etc.
1817
1818 @node Default profile
1819 @subsection Default profile
1820
1821 What about the default profile that Guix keeps in @samp{~/.guix-profile}?
1822
1823 You can assign it the role you want. Typically you would install the manifest
1824 of the packages you want to use all the time.
1825
1826 Alternatively, you could keep it "manifest-less" for throw-away packages
1827 that you would just use for a couple of days.
1828 This way makes it convenient to run
1829
1830 @example
1831 guix install package-foo
1832 guix upgrade package-bar
1833 @end example
1834
1835 without having to specify the path to a profile.
1836
1837 @node The benefits of manifests
1838 @subsection The benefits of manifests
1839
1840 Manifests are a convenient way to keep your package lists around and, say,
1841 to synchronize them across multiple machines using a version control system.
1842
1843 A common complaint about manifests is that they can be slow to install when they
1844 contain large number of packages. This is especially cumbersome when you just
1845 want get an upgrade for one package within a big manifest.
1846
1847 This is one more reason to use multiple profiles, which happen to be just
1848 perfect to break down manifests into multiple sets of semantically connected
1849 packages. Using multiple, small profiles provides more flexibility and
1850 usability.
1851
1852 Manifests come with multiple benefits. In particular, they ease maintenance:
1853
1854 @itemize
1855 @item
1856 When a profile is set up from a manifest, the manifest itself is
1857 self-sufficient to keep a "package listing" around and reinstall the profile
1858 later or on a different system. For ad-hoc profiles, we would need to
1859 generate a manifest specification manually and maintain the package versions
1860 for the packages that don't use the default version.
1861
1862 @item
1863 @code{guix package --upgrade} always tries to update the packages that have
1864 propagated inputs, even if there is nothing to do. Guix manifests remove this
1865 problem.
1866
1867 @item
1868 When partially upgrading a profile, conflicts may arise (due to diverging
1869 dependencies between the updated and the non-updated packages) and they can be
1870 annoying to resolve manually. Manifests remove this problem altogether since
1871 all packages are always upgraded at once.
1872
1873 @item
1874 As mentioned above, manifests allow for reproducible profiles, while the
1875 imperative @code{guix install}, @code{guix upgrade}, etc. do not, since they produce
1876 different profiles every time even when they hold the same packages. See
1877 @uref{https://issues.guix.gnu.org/issue/33285, the related discussion on the matter}.
1878
1879 @item
1880 Manifest specifications are usable by other @samp{guix} commands. For example, you
1881 can run @code{guix weather -m manifest.scm} to see how many substitutes are
1882 available, which can help you decide whether you want to try upgrading today
1883 or wait a while. Another example: you can run @code{guix pack -m manifest.scm} to
1884 create a pack containing all the packages in the manifest (and their
1885 transitive references).
1886
1887 @item
1888 Finally, manifests have a Scheme representation, the @samp{<manifest>} record type.
1889 They can be manipulated in Scheme and passed to the various Guix @uref{https://en.wikipedia.org/wiki/Api, APIs}.
1890 @end itemize
1891
1892 It's important to understand that while manifests can be used to declare
1893 profiles, they are not strictly equivalent: profiles have the side effect that
1894 they "pin" packages in the store, which prevents them from being
1895 garbage-collected (@pxref{Invoking guix gc,,, guix, GNU Guix Reference Manual})
1896 and ensures that they will still be available at any point in
1897 the future.
1898
1899 Let's take an example:
1900
1901 @enumerate
1902 @item
1903 We have an environment for hacking on a project for which there isn't a Guix
1904 package yet. We build the environment using a manifest, and then run @code{guix
1905 environment -m manifest.scm}. So far so good.
1906
1907 @item
1908 Many weeks pass and we have run a couple of @code{guix pull} in the mean time.
1909 Maybe a dependency from our manifest has been updated; or we may have run
1910 @code{guix gc} and some packages needed by our manifest have been
1911 garbage-collected.
1912
1913 @item
1914 Eventually, we set to work on that project again, so we run @code{guix environment
1915 -m manifest.scm}. But now we have to wait for Guix to build and install
1916 stuff!
1917 @end enumerate
1918
1919 Ideally, we could spare the rebuild time. And indeed we can, all we need is to
1920 install the manifest to a profile and use @code{GUIX_PROFILE=/the/profile;
1921 . "$GUIX_PROFILE"/etc/profile} as explained above: this guarantees that our
1922 hacking environment will be available at all times.
1923
1924 @emph{Security warning:} While keeping old profiles around can be convenient, keep in
1925 mind that outdated packages may not have received the latest security fixes.
1926
1927 @node Reproducible profiles
1928 @subsection Reproducible profiles
1929
1930 To reproduce a profile bit-for-bit, we need two pieces of information:
1931
1932 @itemize
1933 @item
1934 a manifest,
1935 @item
1936 a Guix channel specification.
1937 @end itemize
1938
1939 Indeed, manifests alone might not be enough: different Guix versions (or
1940 different channels) can produce different outputs for a given manifest.
1941
1942 You can output the Guix channel specification with @samp{guix describe
1943 --format=channels}.
1944 Save this to a file, say @samp{channel-specs.scm}.
1945
1946 On another computer, you can use the channel specification file and the manifest
1947 to reproduce the exact same profile:
1948
1949 @example
1950 GUIX_EXTRA_PROFILES=$HOME/.guix-extra-profiles
1951 GUIX_EXTRA=$HOME/.guix-extra
1952
1953 mkdir "$GUIX_EXTRA"/my-project
1954 guix pull --channels=channel-specs.scm --profile "$GUIX_EXTRA/my-project/guix"
1955
1956 mkdir -p "$GUIX_EXTRA_PROFILES/my-project"
1957 "$GUIX_EXTRA"/my-project/guix/bin/guix package --manifest=/path/to/guix-my-project-manifest.scm --profile="$GUIX_EXTRA_PROFILES"/my-project/my-project
1958 @end example
1959
1960 It's safe to delete the Guix channel profile you've just installed with the
1961 channel specification, the project profile does not depend on it.
1962
1963 @c *********************************************************************
1964 @node Acknowledgments
1965 @chapter Acknowledgments
1966
1967 Guix is based on the @uref{https://nixos.org/nix/, Nix package manager},
1968 which was designed and
1969 implemented by Eelco Dolstra, with contributions from other people (see
1970 the @file{nix/AUTHORS} file in Guix.) Nix pioneered functional package
1971 management, and promoted unprecedented features, such as transactional
1972 package upgrades and rollbacks, per-user profiles, and referentially
1973 transparent build processes. Without this work, Guix would not exist.
1974
1975 The Nix-based software distributions, Nixpkgs and NixOS, have also been
1976 an inspiration for Guix.
1977
1978 GNU@tie{}Guix itself is a collective work with contributions from a
1979 number of people. See the @file{AUTHORS} file in Guix for more
1980 information on these fine people. The @file{THANKS} file lists people
1981 who have helped by reporting bugs, taking care of the infrastructure,
1982 providing artwork and themes, making suggestions, and more---thank you!
1983
1984 This document includes adapted sections from articles that have previously
1985 been published on the Guix blog at @uref{https://guix.gnu.org/blog}.
1986
1987
1988 @c *********************************************************************
1989 @node GNU Free Documentation License
1990 @appendix GNU Free Documentation License
1991 @cindex license, GNU Free Documentation License
1992 @include fdl-1.3.texi
1993
1994 @c *********************************************************************
1995 @node Concept Index
1996 @unnumbered Concept Index
1997 @printindex cp
1998
1999 @bye
2000
2001 @c Local Variables:
2002 @c ispell-local-dictionary: "american";
2003 @c End: