You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8808 lines
335 KiB

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