Skip to content
Snippets Groups Projects
guix.texi 191 KiB
Newer Older
  • Learn to ignore specific revisions
  • \input texinfo
    @c -*-texinfo-*-
    
    @c %**start of header
    @setfilename guix.info
    @documentencoding UTF-8
    
    @settitle GNU Guix Reference Manual
    
    @c %**end of header
    
    @include version.texi
    
    Copyright @copyright{} 2012, 2013, 2014 Ludovic Courtès@*
    
    Copyright @copyright{} 2013, 2014 Andreas Enge@*
    
    Copyright @copyright{} 2013 Nikita Karetnikov
    
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 1.3 or
    any later version published by the Free Software Foundation; with no
    Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
    copy of the license is included in the section entitled ``GNU Free
    Documentation License''.
    @end copying
    
    @dircategory Package management
    
    @direntry
    * guix: (guix).       Guix, the functional package manager.
    
    * guix package: (guix)Invoking guix package
    
                          Managing packages with Guix.
    
    * guix build: (guix)Invoking guix build
    
                          Building packages with Guix.
    
    * guix system: (guix)Invoking guix system
                          Managing the operating system configuration.
    
    @end direntry
    
    
    @dircategory Software development
    @direntry
    * guix environment: (guix)Invoking guix environment
                          Building development environments with Guix.
    @end direntry
    
    
    @titlepage
    
    @title GNU Guix Reference Manual
    @subtitle Using the GNU Guix Functional Package Manager
    
    @author Ludovic Courtès
    
    @author Andreas Enge
    
    @author Nikita Karetnikov
    
    
    @page
    @vskip 0pt plus 1filll
    Edition @value{EDITION} @*
    @value{UPDATED} @*
    
    
    @insertcopying
    
    @end titlepage
    
    @contents
    
    @c *********************************************************************
    @node Top
    
    @top GNU Guix
    
    This document describes GNU Guix version @value{VERSION}, a functional
    package management tool written for the GNU system.
    
    
    @menu
    * Introduction::                What is Guix about?
    
    * Installation::                Installing Guix.
    
    * Package Management::          Package installation, upgrade, etc.
    
    * Programming Interface::       Using Guix in Scheme.
    * Utilities::                   Package management commands.
    
    * GNU Distribution::            Software for your friendly GNU system.
    
    * Contributing::                Your help needed!
    
    
    * Acknowledgments::             Thanks!
    * GNU Free Documentation License::  The license of this manual.
    * Concept Index::               Concepts.
    
    * Programming Index::           Data types, functions, and variables.
    
    @end menu
    
    @c *********************************************************************
    @node Introduction
    @chapter Introduction
    
    
    GNU Guix@footnote{``Guix'' is pronounced like ``geeks'', or ``ɡiːks''
    using the international phonetic alphabet (IPA).} is a functional
    package management tool for the GNU system.  Package management consists
    
    of all activities that relate to building packages from sources,
    honoring their build-time and run-time dependencies,
    
    installing packages in user environments, upgrading installed packages
    to new versions or rolling back to a previous set, removing unused
    software packages, etc.
    
    
    @cindex functional package management
    The term @dfn{functional} refers to a specific package management
    discipline.  In Guix, the package build and installation process is seen
    
    as a function, in the mathematical sense.  That function takes inputs,
    such as build scripts, a compiler, and libraries, and
    returns an installed package.  As a pure function, its result depends
    
    solely on its inputs---for instance, it cannot refer to software or
    scripts that were not explicitly passed as inputs.  A build function
    
    always produces the same result when passed a given set of inputs.  It
    cannot alter the system's environment in
    
    any way; for instance, it cannot create, modify, or delete files outside
    of its build and installation directories.  This is achieved by running
    
    build processes in isolated environments (or @dfn{containers}), where only their
    
    @cindex store
    
    The result of package build functions is @dfn{cached} in the file
    
    system, in a special directory called @dfn{the store} (@pxref{The
    Store}).  Each package is installed in a directory of its own, in the
    
    store---by default under @file{/gnu/store}.  The directory name contains
    
    a hash of all the inputs used to build that package; thus, changing an
    input yields a different directory name.
    
    This approach is the foundation of Guix's salient features: support for
    
    transactional package upgrade and rollback, per-user installation, and
    
    garbage collection of packages (@pxref{Features}).
    
    Guix has a command-line interface, which allows users to build, install,
    
    upgrade, and remove packages, as well as a Scheme programming interface.
    
    
    Last but not least, Guix is used to build a distribution of the GNU
    system, with many GNU and non-GNU free software packages.  @xref{GNU
    Distribution}.
    
    
    @c *********************************************************************
    @node Installation
    @chapter Installation
    
    
    GNU Guix is available for download from its website at
    @url{http://www.gnu.org/software/guix/}.  This section describes the
    software requirements of Guix, as well as how to install it and get
    ready to use it.
    
    Note that this section is concerned with the installation of the package
    manager, which can be done on top of a running GNU/Linux system.  If,
    instead, you want to install the complete GNU operating system,
    
    @pxref{System Installation}.
    
    The build procedure for Guix is the same as for other GNU software, and
    
    is not covered here.  Please see the files @file{README} and
    
    @file{INSTALL} in the Guix source tree for additional details.
    
    
    @menu
    * Requirements::                Software needed to build and run Guix.
    * Setting Up the Daemon::       Preparing the build daemon's environment.
    * Invoking guix-daemon::        Running the build daemon.
    @end menu
    
    @node Requirements
    @section Requirements
    
    GNU Guix depends on the following packages:
    
    @itemize
    
    @item @url{http://gnu.org/software/guile/, GNU Guile}, version 2.0.5 or later;
    
    @item @url{http://gnupg.org/, GNU libgcrypt};
    
    @end itemize
    
    The following dependencies are optional:
    
    @itemize
    
    @url{http://savannah.nongnu.org/projects/guile-json/, Guile-JSON} will
    allow you to use the @command{guix import pypi} command; it is of
    interest primarily for developers and not for casual users.
    
    @item
    Installing @uref{http://gnutls.org/, GnuTLS-Guile} will
    allow you to access @code{https} URLs with the @command{guix download}
    command (@pxref{Invoking guix download}) and the @command{guix import
    pypi} command.  This is primarily of interest to developers.
    @xref{Guile Preparations, how to install the GnuTLS bindings for Guile,,
    gnutls-guile, GnuTLS-Guile}.
    
    @end itemize
    
    Unless @code{--disable-daemon} was passed to @command{configure}, the
    following packages are also needed:
    
    @itemize
    @item @url{http://sqlite.org, SQLite 3}
    @item @url{http://www.bzip.org, libbz2}
    @item @url{http://gcc.gnu.org, GCC's g++}
    @end itemize
    
    
    When a working installation of @url{http://nixos.org/nix/, the Nix package
    manager} is available, you
    
    can instead configure Guix with @code{--disable-daemon}.  In that case,
    
    Nix replaces the three dependencies above.
    
    Guix is compatible with Nix, so it is possible to share the same store
    between both.  To do so, you must pass @command{configure} not only the
    same @code{--with-store-dir} value, but also the same
    
    @code{--localstatedir} value.  The latter is essential because it
    specifies where the database that stores metadata about the store is
    
    located, among other things.  The default values for Nix are
    
    @code{--with-store-dir=/nix/store} and @code{--localstatedir=/nix/var}.
    
    Note that @code{--disable-daemon} is not required if
    your goal is to share the store with Nix.
    
    @node Setting Up the Daemon
    @section Setting Up the Daemon
    
    @cindex daemon
    Operations such as building a package or running the garbage collector
    
    are all performed by a specialized process, the @dfn{build daemon}, on
    
    behalf of clients.  Only the daemon may access the store and its
    associated database.  Thus, any operation that manipulates the store
    goes through the daemon.  For instance, command-line tools such as
    
    @command{guix package} and @command{guix build} communicate with the
    
    daemon (@i{via} remote procedure calls) to instruct it what to do.
    
    
    The following sections explain how to prepare the build daemon's
    environment.
    
    @menu
    * Build Environment Setup::     Preparing the isolated build environment.
    * Daemon Offload Setup::        Offloading builds to remote machines.
    @end menu
    
    @node Build Environment Setup
    @subsection Build Environment Setup
    
    
    In a standard multi-user setup, Guix and its daemon---the
    @command{guix-daemon} program---are installed by the system
    
    administrator; @file{/gnu/store} is owned by @code{root} and
    
    @command{guix-daemon} runs as @code{root}.  Unprivileged users may use
    Guix tools to build packages or otherwise access the store, and the
    daemon will do it on their behalf, ensuring that the store is kept in a
    consistent state, and allowing built packages to be shared among users.
    
    @cindex build users
    When @command{guix-daemon} runs as @code{root}, you may not want package
    build processes themselves to run as @code{root} too, for obvious
    security reasons.  To avoid that, a special pool of @dfn{build users}
    should be created for use by build processes started by the daemon.
    These build users need not have a shell and a home directory: they will
    just be used when the daemon drops @code{root} privileges in build
    processes.  Having several such users allows the daemon to launch
    distinct build processes under separate UIDs, which guarantees that they
    do not interfere with each other---an essential feature since builds are
    regarded as pure functions (@pxref{Introduction}).
    
    On a GNU/Linux system, a build user pool may be created like this (using
    Bash syntax and the @code{shadow} commands):
    
    
    @c See http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html
    @c for why `-G' is needed.
    
    @example
    # groupadd guix-builder
    # for i in `seq 1 10`;
      do
    
        useradd -g guix-builder -G guix-builder           \
                -d /var/empty -s `which nologin`          \
    
                -c "Guix build user $i" --system          \
                guix-builder$i;
    
      done
    @end example
    
    @noindent
    The @code{guix-daemon} program may then be run as @code{root} with:
    
    @example
    # guix-daemon --build-users-group=guix-builder
    @end example
    
    
    @noindent
    This way, the daemon starts build processes in a chroot, under one of
    the @code{guix-builder} users.  On GNU/Linux, by default, the chroot
    
    environment contains nothing but:
    
    @c Keep this list in sync with libstore/build.cc! -----------------------
    @itemize
    @item
    
    a minimal @code{/dev} directory, created mostly independently from the
    host @code{/dev}@footnote{``Mostly'', because while the set of files
    that appear in the chroot's @code{/dev} is fixed, most of these files
    can only be created if the host has them.};
    
    @item
    the @code{/proc} directory; it only shows the container's processes
    since a separate PID name space is used;
    
    
    @item
    @file{/etc/passwd} with an entry for the current user and an entry for
    user @file{nobody};
    
    @item
    @file{/etc/group} with an entry for the user's group;
    
    @item
    @file{/etc/hosts} with an entry that maps @code{localhost} to
    @code{127.0.0.1};
    
    @item
    a writable @file{/tmp} directory.
    @end itemize
    
    If you are installing Guix as an unprivileged user, it is still
    
    possible to run @command{guix-daemon}.  However, build processes will
    not be isolated from one another, and not from the rest of the system.
    Thus, build processes may interfere with each other, and may access
    programs, libraries, and other files available on the system---making it
    much harder to view them as @emph{pure} functions.
    
    
    
    @node Daemon Offload Setup
    @subsection Using the Offload Facility
    
    @cindex offloading
    
    @cindex build hook
    When desired, the build daemon can @dfn{offload}
    derivation builds to other machines
    
    running Guix, using the @code{offload} @dfn{build hook}.  When that
    feature is enabled, a list of user-specified build machines is read from
    @file{/etc/guix/machines.scm}; anytime a build is requested, for
    instance via @code{guix build}, the daemon attempts to offload it to one
    of the machines that satisfies the derivation's constraints, in
    particular its system type---e.g., @file{x86_64-linux}.  Missing
    prerequisites for the build are copied over SSH to the target machine,
    which then proceeds with the build; upon success the output(s) of the
    build are copied back to the initial machine.
    
    
    The @file{/etc/guix/machines.scm} file typically looks like this:
    
    
    @example
    (list (build-machine
            (name "eightysix.example.org")
            (system "x86_64-linux")
            (user "bob")
            (speed 2.))    ; incredibly fast!
    
          (build-machine
            (name "meeps.example.org")
            (system "mips64el-linux")
            (user "alice")
            (private-key
             (string-append (getenv "HOME")
                            "/.ssh/id-rsa-for-guix"))))
    @end example
    
    @noindent
    In the example above we specify a list of two build machines, one for
    the @code{x86_64} architecture and one for the @code{mips64el}
    
    architecture.
    
    In fact, this file is---not surprisingly!---a Scheme file that is
    evaluated when the @code{offload} hook is started.  Its return value
    must be a list of @code{build-machine} objects.  While this example
    shows a fixed list of build machines, one could imagine, say, using
    DNS-SD to return a list of potential build machines discovered in the
    local network (@pxref{Introduction, Guile-Avahi,, guile-avahi, Using
    
    Avahi in Guile Scheme Programs}).  The @code{build-machine} data type is
    detailed below.
    
    @deftp {Data Type} build-machine
    This data type represents build machines the daemon may offload builds
    to.  The important fields are:
    
    
    @table @code
    
    @item name
    The remote machine's host name.
    
    @item system
    
    The remote machine's system type---e.g., @code{"x86_64-linux"}.
    
    
    @item user
    The user account to use when connecting to the remote machine over SSH.
    Note that the SSH key pair must @emph{not} be passphrase-protected, to
    allow non-interactive logins.
    
    @end table
    
    
    A number of optional fields may be specified:
    
    @item port
    Port number of the machine's SSH server (default: 22).
    
    
    @item private-key
    The SSH private key file to use when connecting to the machine.
    
    @item parallel-builds
    The number of builds that may run in parallel on the machine (1 by
    default.)
    
    @item speed
    A ``relative speed factor''.  The offload scheduler will tend to prefer
    machines with a higher speed factor.
    
    @item features
    A list of strings denoting specific features supported by the machine.
    An example is @code{"kvm"} for machines that have the KVM Linux modules
    and corresponding hardware support.  Derivations can request features by
    name, and they will be scheduled on matching build machines.
    
    @end table
    
    
    The @code{guix} command must be in the search path on the build
    machines, since offloading works by invoking the @code{guix archive} and
    @code{guix build} commands.
    
    There's one last thing to do once @file{machines.scm} is in place.  As
    explained above, when offloading, files are transferred back and forth
    between the machine stores.  For this to work, you need to generate a
    key pair to allow the daemon to export signed archives of files from the
    store (@pxref{Invoking guix archive}):
    
    @example
    # guix archive --generate-key
    @end example
    
    @noindent
    Thus, when receiving files, a machine's build daemon can make sure they
    are genuine, have not been tampered with, and that they are signed by an
    authorized key.
    
    
    
    @node Invoking guix-daemon
    @section Invoking @command{guix-daemon}
    
    The @command{guix-daemon} program implements all the functionality to
    access the store.  This includes launching build processes, running the
    garbage collector, querying the availability of a build result, etc.  It
    is normally run as @code{root} like this:
    
    @example
    # guix-daemon --build-users-group=guix-builder
    @end example
    
    @noindent
    For details on how to set it up, @ref{Setting Up the Daemon}.
    
    
    @cindex chroot
    @cindex container, build environment
    @cindex build environment
    @cindex reproducible builds
    
    By default, @command{guix-daemon} launches build processes under
    different UIDs, taken from the build group specified with
    @code{--build-users-group}.  In addition, each build process is run in a
    chroot environment that only contains the subset of the store that the
    build process depends on, as specified by its derivation
    (@pxref{Programming Interface, derivation}), plus a set of specific
    system directories.  By default, the latter contains @file{/dev} and
    
    @file{/dev/pts}.  Furthermore, on GNU/Linux, the build environment is a
    @dfn{container}: in addition to having its own file system tree, it has
    a separate mount name space, its own PID name space, network name space,
    etc.  This helps achieve reproducible builds (@pxref{Features}).
    
    
    The following command-line options are supported:
    
    @table @code
    @item --build-users-group=@var{group}
    Take users from @var{group} to run build processes (@pxref{Setting Up
    the Daemon, build users}).
    
    
    @item --no-substitutes
    
    Do not use substitutes for build products.  That is, always build things
    
    locally instead of allowing downloads of pre-built binaries
    (@pxref{Substitutes}).
    
    By default substitutes are used, unless the client---such as the
    @command{guix package} command---is explicitly invoked with
    @code{--no-substitutes}.
    
    When the daemon runs with @code{--no-substitutes}, clients can still
    explicitly enable substitution @i{via} the @code{set-build-options}
    remote procedure call (@pxref{The Store}).
    
    
    @item --substitute-urls=@var{urls}
    Consider @var{urls} the default whitespace-separated list of substitute
    source URLs.  When this option is omitted, @code{http://hydra.gnu.org}
    is used.
    
    This means that substitutes may be downloaded from @var{urls}, as long
    as they are signed by a trusted signature (@pxref{Substitutes}).
    
    
    @cindex build hook
    @item --no-build-hook
    Do not use the @dfn{build hook}.
    
    The build hook is a helper program that the daemon can start and to
    which it submits build requests.  This mechanism is used to offload
    builds to other machines (@pxref{Daemon Offload Setup}).
    
    
    @item --cache-failures
    Cache build failures.  By default, only successful builds are cached.
    
    @item --cores=@var{n}
    @itemx -c @var{n}
    Use @var{n} CPU cores to build each derivation; @code{0} means as many
    as available.
    
    The default value is @code{1}, but it may be overridden by clients, such
    
    as the @code{--cores} option of @command{guix build} (@pxref{Invoking
    guix build}).
    
    
    The effect is to define the @code{NIX_BUILD_CORES} environment variable
    in the build process, which can then use it to exploit internal
    parallelism---for instance, by running @code{make -j$NIX_BUILD_CORES}.
    
    @item --max-jobs=@var{n}
    @itemx -M @var{n}
    Allow at most @var{n} build jobs in parallel.  The default value is
    @code{1}.
    
    @item --debug
    Produce debugging output.
    
    This is useful to debug daemon start-up issues, but then it may be
    overridden by clients, for example the @code{--verbosity} option of
    
    @command{guix build} (@pxref{Invoking guix build}).
    
    
    @item --chroot-directory=@var{dir}
    Add @var{dir} to the build chroot.
    
    Doing this may change the result of build processes---for instance if
    they use optional dependencies found in @var{dir} when it is available,
    and not otherwise.  For that reason, it is not recommended to do so.
    Instead, make sure that each derivation declares all the inputs that it
    needs.
    
    @item --disable-chroot
    Disable chroot builds.
    
    Using this option is not recommended since, again, it would allow build
    processes to gain access to undeclared dependencies.
    
    @item --disable-log-compression
    Disable compression of the build logs.
    
    
    Unless @code{--lose-logs} is used, all the build logs are kept in the
    @var{localstatedir}.  To save space, the daemon automatically compresses
    them with bzip2 by default.  This option disables that.
    
    
    @item --disable-deduplication
    @cindex deduplication
    
    Disable automatic file ``deduplication'' in the store.
    
    
    By default, files added to the store are automatically ``deduplicated'':
    
    if a newly added file is identical to another one found in the store,
    the daemon makes the new file a hard link to the other file.  This can
    noticeably reduce disk usage, at the expense of slightly increasde
    input/output load at the end of a build process.  This option disables
    this optimization.
    
    @item --gc-keep-outputs[=yes|no]
    Tell whether the garbage collector (GC) must keep outputs of live
    derivations.
    
    When set to ``yes'', the GC will keep the outputs of any live derivation
    available in the store---the @code{.drv} files.  The default is ``no'',
    meaning that derivation outputs are kept only if they are GC roots.
    
    @item --gc-keep-derivations[=yes|no]
    Tell whether the garbage collector (GC) must keep derivations
    corresponding to live outputs.
    
    When set to ``yes'', as is the case by default, the GC keeps
    derivations---i.e., @code{.drv} files---as long as at least one of their
    outputs is live.  This allows users to keep track of the origins of
    items in their store.  Setting it to ``no'' saves a bit of disk space.
    
    Note that when both @code{--gc-keep-derivations} and
    @code{--gc-keep-outputs} are used, the effect is to keep all the build
    prerequisites (the sources, compiler, libraries, and other build-time
    tools) of live objects in the store, regardless of whether these
    prerequisites are live.  This is convenient for developers since it
    saves rebuilds or downloads.
    
    
    @item --impersonate-linux-2.6
    On Linux-based systems, impersonate Linux 2.6.  This means that the
    kernel's @code{uname} system call will report 2.6 as the release number.
    
    This might be helpful to build programs that (usually wrongfully) depend
    on the kernel version number.
    
    @item --lose-logs
    Do not keep build logs.  By default they are kept under
    
    @code{@var{localstatedir}/guix/log}.
    
    
    @item --system=@var{system}
    Assume @var{system} as the current system type.  By default it is the
    architecture/kernel pair found at configure time, such as
    @code{x86_64-linux}.
    
    
    @item --listen=@var{socket}
    Listen for connections on @var{socket}, the file name of a Unix-domain
    socket.  The default socket is
    @file{@var{localstatedir}/daemon-socket/socket}.  This option is only
    useful in exceptional circumstances, such as if you need to run several
    daemons on the same machine.
    
    @c *********************************************************************
    @node Package Management
    @chapter Package Management
    
    
    The purpose of GNU Guix is to allow users to easily install, upgrade, and
    
    remove software packages, without having to know about their build
    procedure or dependencies.  Guix also goes beyond this obvious set of
    features.
    
    This chapter describes the main features of Guix, as well as the package
    
    management tools it provides.  Two user interfaces are provided for
    routine package management tasks: a command-line interface
    (@pxref{Invoking guix package, @code{guix package}}), and a visual user
    interface in Emacs (@pxref{Emacs Interface}).
    
    
    @menu
    * Features::                    How Guix will make your life brighter.
    
    * Invoking guix package::       Package installation, removal, etc.
    
    Alex Kost's avatar
    Alex Kost committed
    * Emacs Interface::             Package management from Emacs.
    
    * Substitutes::                 Downloading pre-built binaries.
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    * Packages with Multiple Outputs::  Single source package, multiple outputs.
    
    * Invoking guix gc::            Running the garbage collector.
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    * Invoking guix pull::          Fetching the latest Guix and distribution.
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    * Invoking guix archive::       Exporting and importing store files.
    
    @end menu
    
    @node Features
    @section Features
    
    When using Guix, each package ends up in the @dfn{package store}, in its
    own directory---something that resembles
    
    Alex Kost's avatar
    Alex Kost committed
    @file{/gnu/store/xxx-package-1.2}, where @code{xxx} is a base32 string
    (note that Guix comes with an Emacs extension to shorten those file
    names, @ref{Emacs Prettify}.)
    
    
    Instead of referring to these directories, users have their own
    @dfn{profile}, which points to the packages that they actually want to
    
    use.  These profiles are stored within each user's home directory, at
    @code{$HOME/.guix-profile}.
    
    For example, @code{alice} installs GCC 4.7.2.  As a result,
    
    @file{/home/alice/.guix-profile/bin/gcc} points to
    
    @file{/gnu/store/@dots{}-gcc-4.7.2/bin/gcc}.  Now, on the same machine,
    
    @code{bob} had already installed GCC 4.8.0.  The profile of @code{bob}
    simply continues to point to
    
    @file{/gnu/store/@dots{}-gcc-4.8.0/bin/gcc}---i.e., both versions of GCC
    
    coexist on the same system without any interference.
    
    The @command{guix package} command is the central tool to manage
    packages (@pxref{Invoking guix package}).  It operates on those per-user
    
    profiles, and can be used @emph{with normal user privileges}.
    
    
    The command provides the obvious install, remove, and upgrade
    operations.  Each invocation is actually a @emph{transaction}: either
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    the specified operation succeeds, or nothing happens.  Thus, if the
    
    @command{guix package} process is terminated during the transaction,
    
    or if a power outage occurs during the transaction, then the user's
    profile remains in its previous state, and remains usable.
    
    In addition, any package transaction may be @emph{rolled back}.  So, if,
    for example, an upgrade installs a new version of a package that turns
    out to have a serious bug, users may roll back to the previous instance
    
    of their profile, which was known to work well.  Similarly, the global
    system configuration is subject to transactional upgrades and roll-back
    (@pxref{Using the Configuration System}).
    
    
    All those packages in the package store may be @emph{garbage-collected}.
    Guix can determine which packages are still referenced by the user
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    profiles, and remove those that are provably no longer referenced
    
    (@pxref{Invoking guix gc}).  Users may also explicitly remove old
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    generations of their profile so that the packages they refer to can be
    collected.
    
    @cindex reproducibility
    @cindex reproducible builds
    
    Finally, Guix takes a @dfn{purely functional} approach to package
    management, as described in the introduction (@pxref{Introduction}).
    
    Each @file{/gnu/store} package directory name contains a hash of all the
    
    inputs that were used to build that package---compiler, libraries, build
    scripts, etc.  This direct correspondence allows users to make sure a
    given package installation matches the current state of their
    
    distribution.  It also helps maximize @dfn{build reproducibility}:
    thanks to the isolated build environments that are used, a given build
    is likely to yield bit-identical files when performed on different
    machines (@pxref{Invoking guix-daemon, container}).
    
    @cindex substitutes
    
    This foundation allows Guix to support @dfn{transparent binary/source
    
    deployment}.  When a pre-built binary for a @file{/gnu/store} item is
    
    available from an external source---a @dfn{substitute}, Guix just
    
    downloads it and unpacks it;
    otherwise, it builds the package from source, locally
    (@pxref{Substitutes}).
    
    Control over the build environment is a feature that is also useful for
    developers.  The @command{guix environment} command allows developers of
    a package to quickly set up the right development environment for their
    package, without having to manually install the package's dependencies
    in their profile (@pxref{Invoking guix environment}).
    
    
    @node Invoking guix package
    @section Invoking @command{guix package}
    
    The @command{guix package} command is the tool that allows users to
    
    install, upgrade, and remove packages, as well as rolling back to
    previous configurations.  It operates only on the user's own profile,
    and works with normal user privileges (@pxref{Features}).  Its syntax
    is:
    
    @example
    
    guix package @var{options}
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    Primarily, @var{options} specifies the operations to be performed during
    
    the transaction.  Upon completion, a new profile is created, but
    previous generations of the profile remain available, should the user
    want to roll back.
    
    
    For example, to remove @code{lua} and install @code{guile} and
    @code{guile-cairo} in a single transaction:
    
    @example
    guix package -r lua -i guile guile-cairo
    @end example
    
    
    For each user, a symlink to the user's default profile is automatically
    
    created in @file{$HOME/.guix-profile}.  This symlink always points to the
    
    current generation of the user's default profile.  Thus, users can add
    @file{$HOME/.guix-profile/bin} to their @code{PATH} environment
    variable, and so on.
    
    
    In a multi-user setup, user profiles must be stored in a place
    registered as a @dfn{garbage-collector root}, which
    
    @file{$HOME/.guix-profile} points to (@pxref{Invoking guix gc}).  That
    
    directory is normally
    @code{@var{localstatedir}/profiles/per-user/@var{user}}, where
    @var{localstatedir} is the value passed to @code{configure} as
    @code{--localstatedir}, and @var{user} is the user name.  It must be
    created by @code{root}, with @var{user} as the owner.  When it does not
    
    exist, or is not owned by @var{user}, @command{guix package} emits an
    error about it.
    
    
    The @var{options} can be among the following:
    
    
    @item --install=@var{package} @dots{}
    @itemx -i @var{package} @dots{}
    Install the specified @var{package}s.
    
    Each @var{package} may specify either a simple package name, such as
    
    @code{guile}, or a package name followed by a hyphen and version number,
    
    such as @code{guile-1.8.8}.  If no version number is specified, the
    newest available version will be selected.  In addition, @var{package}
    may contain a colon, followed by the name of one of the outputs of the
    
    package, as in @code{gcc:doc} or @code{binutils-2.22:lib}
    
    (@pxref{Packages with Multiple Outputs}).  Packages with a corresponding
    name (and optionally version) are searched for among the GNU
    distribution modules (@pxref{Package Modules}).
    
    @cindex propagated inputs
    Sometimes packages have @dfn{propagated inputs}: these are dependencies
    that automatically get installed along with the required package.
    
    An example is the GNU MPC library: its C header files refer to those of
    the GNU MPFR library, which in turn refer to those of the GMP library.
    Thus, when installing MPC, the MPFR and GMP libraries also get installed
    in the profile; removing MPC also removes MPFR and GMP---unless they had
    also been explicitly installed independently.
    
    
    Nikita Karetnikov's avatar
    Nikita Karetnikov committed
    Besides, packages sometimes rely on the definition of environment
    
    variables for their search paths (see explanation of
    
    Nikita Karetnikov's avatar
    Nikita Karetnikov committed
    @code{--search-paths} below).  Any missing or possibly incorrect
    
    environment variable definitions are reported here.
    
    
    Finally, when installing a GNU package, the tool reports the
    
    availability of a newer upstream version.  In the future, it may provide
    the option of installing directly from the upstream version, even if
    that version is not yet in the distribution.
    
    
    @item --install-from-expression=@var{exp}
    @itemx -e @var{exp}
    Install the package @var{exp} evaluates to.
    
    @var{exp} must be a Scheme expression that evaluates to a
    @code{<package>} object.  This option is notably useful to disambiguate
    between same-named variants of a package, with expressions such as
    @code{(@@ (gnu packages base) guile-final)}.
    
    Note that this option installs the first output of the specified
    package, which may be insufficient when needing a specific output of a
    multiple-output package.
    
    
    @item --remove=@var{package} @dots{}
    @itemx -r @var{package} @dots{}
    Remove the specified @var{package}s.
    
    As for @code{--install}, each @var{package} may specify a version number
    
    and/or output name in addition to the package name.  For instance,
    @code{-r glibc:debug} would remove the @code{debug} output of
    @code{glibc}.
    
    
    @item --upgrade[=@var{regexp} @dots{}]
    @itemx -u [@var{regexp} @dots{}]
    Upgrade all the installed packages.  If one or more @var{regexp}s are
    specified, upgrade only installed packages whose name matches a
    @var{regexp}.
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    Note that this upgrades package to the latest version of packages found
    in the distribution currently installed.  To update your distribution,
    you should regularly run @command{guix pull} (@pxref{Invoking guix
    pull}).
    
    
    @item --roll-back
    Roll back to the previous @dfn{generation} of the profile---i.e., undo
    the last transaction.
    
    When combined with options such as @code{--install}, roll back occurs
    before any other actions.
    
    
    When rolling back from the first generation that actually contains
    
    installed packages, the profile is made to point to the @dfn{zeroth
    generation}, which contains no files apart from its own meta-data.
    
    Installing, removing, or upgrading packages from a generation that has
    been rolled back to overwrites previous future generations.  Thus, the
    history of a profile's generations is always linear.
    
    
    @item --switch-generation=@var{pattern}
    @itemx -S @var{pattern}
    Switch to a particular generation defined by @var{pattern}.
    
    @var{pattern} may be either a generation number or a number prefixed
    with ``+'' or ``-''.  The latter means: move forward/backward by a
    specified number of generations.  For example, if you want to return to
    the latest generation after @code{--roll-back}, use
    @code{--switch-generation=+1}.
    
    The difference between @code{--roll-back} and
    @code{--switch-generation=-1} is that @code{--switch-generation} will
    not make a zeroth generation, so if a specified generation does not
    exist, the current generation will not be changed.
    
    
    @item --search-paths
    @cindex search paths
    Report environment variable definitions, in Bash syntax, that may be
    needed in order to use the set of installed packages.  These environment
    variables are used to specify @dfn{search paths} for files used by some
    of the installed packages.
    
    For example, GCC needs the @code{CPATH} and @code{LIBRARY_PATH}
    environment variables to be defined so it can look for headers and
    libraries in the user's profile (@pxref{Environment Variables,,, gcc,
    Using the GNU Compiler Collection (GCC)}).  If GCC and, say, the C
    library are installed in the profile, then @code{--search-paths} will
    suggest setting these variables to @code{@var{profile}/include} and
    @code{@var{profile}/lib}, respectively.
    
    
    @item --profile=@var{profile}
    @itemx -p @var{profile}
    Use @var{profile} instead of the user's default profile.
    
    
    @item --verbose
    Produce verbose output.  In particular, emit the environment's build log
    on the standard error port.
    
    
    @item --bootstrap
    Use the bootstrap Guile to build the profile.  This option is only
    useful to distribution developers.
    
    @end table
    
    
    In addition to these actions @command{guix package} supports the
    
    following options to query the current state of a profile, or the
    availability of packages:
    
    @item --search=@var{regexp}
    @itemx -s @var{regexp}
    List the available packages whose synopsis or description matches
    
    @var{regexp}.  Print all the meta-data of matching packages in
    @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils,
    GNU recutils manual}).
    
    This allows specific fields to be extracted using the @command{recsel}
    command, for instance:
    
    @example
    
    $ guix package -s malloc | recsel -p name,version
    
    name: glibc
    version: 2.17
    
    name: libgc
    version: 7.2alpha6
    @end example
    
    Similarly, to show the name of all the packages available under the
    terms of the GNU@tie{}LGPL version 3:
    
    @example
    $ guix package -s "" | recsel -p name -e 'license ~ "LGPL 3"'
    name: elfutils
    
    name: gmp
    @dots{}
    @end example
    
    
    @item --show=@var{package}
    Show details about @var{package}, taken from the list of available packages, in
    @code{recutils} format (@pxref{Top, GNU recutils databases,, recutils, GNU
    recutils manual}).
    
    @example
    $ guix package --show=python | recsel -p name,version
    name: python
    version: 2.7.6
    
    name: python
    version: 3.3.5
    @end example
    
    You may also specify the full name of a package to only get details about a
    specific version of it:
    @example
    $ guix package --show=python-3.3.5 | recsel -p name,version
    name: python
    version: 3.3.5
    @end example
    
    
    
    
    @item --list-installed[=@var{regexp}]
    @itemx -I [@var{regexp}]
    
    List the currently installed packages in the specified profile, with the
    most recently installed packages shown last.  When @var{regexp} is
    specified, list only installed packages whose name matches @var{regexp}.
    
    
    For each installed package, print the following items, separated by
    tabs: the package name, its version string, the part of the package that
    is installed (for instance, @code{out} for the default output,
    @code{include} for its headers, etc.), and the path of this package in
    the store.
    
    
    @item --list-available[=@var{regexp}]
    @itemx -A [@var{regexp}]
    
    List packages currently available in the software distribution
    (@pxref{GNU Distribution}).  When @var{regexp} is specified, list only
    installed packages whose name matches @var{regexp}.
    
    
    For each package, print the following items separated by tabs: its name,
    
    its version string, the parts of the package (@pxref{Packages with
    Multiple Outputs}), and the source location of its definition.
    
    @item --list-generations[=@var{pattern}]
    @itemx -l [@var{pattern}]
    Return a list of generations along with their creation dates; for each
    generation, show the installed packages, with the most recently
    
    installed packages shown last.  Note that the zeroth generation is never
    shown.
    
    
    For each installed package, print the following items, separated by
    tabs: the name of a package, its version string, the part of the package
    that is installed (@pxref{Packages with Multiple Outputs}), and the
    location of this package in the store.
    
    When @var{pattern} is used, the command returns only matching
    generations.  Valid patterns include:
    
    @itemize
    @item @emph{Integers and comma-separated integers}.  Both patterns denote
    generation numbers.  For instance, @code{--list-generations=1} returns
    the first one.
    
    And @code{--list-generations=1,8,2} outputs three generations in the
    specified order.  Neither spaces nor trailing commas are allowed.
    
    @item @emph{Ranges}.  @code{--list-generations=2..9} prints the
    specified generations and everything in between.  Note that the start of
    a range must be lesser than its end.
    
    It is also possible to omit the endpoint.  For example,
    @code{--list-generations=2..}, returns all generations starting from the
    second one.
    
    @item @emph{Durations}.  You can also get the last @emph{N}@tie{}days, weeks,
    or months by passing an integer along with the first letter of the
    
    duration.  For example, @code{--list-generations=20d} lists generations
    that are up to 20 days old.
    
    @item --delete-generations[=@var{pattern}]
    @itemx -d [@var{pattern}]
    
    When @var{pattern} is omitted, delete all generations except the current
    one.
    
    
    This command accepts the same patterns as @option{--list-generations}.