Skip to content
Snippets Groups Projects
guix.texi 953 KiB
Newer Older
  • Learn to ignore specific revisions
  • Build actions are performed by the Guix daemon, on behalf of users.  In a
    standard setup, the daemon has write access to the store---the
    @file{/gnu/store} directory---whereas users do not.  The recommended
    setup also has the daemon perform builds in chroots, under a specific
    build users, to minimize interference with the rest of the system.
    
    @cindex derivation
    Lower-level APIs are available to interact with the daemon and the
    store.  To instruct the daemon to perform a build action, users actually
    provide it with a @dfn{derivation}.  A derivation is a low-level
    representation of the build actions to be taken, and the environment in
    which they should occur---derivations are to package definitions what
    assembly is to C programs.  The term ``derivation'' comes from the fact
    that build results @emph{derive} from them.
    
    This chapter describes all these APIs in turn, starting from high-level
    package definitions.
    
    @menu
    * Package Modules::             Packages from the programmer's viewpoint.
    * Defining Packages::           Defining new packages.
    * Build Systems::               Specifying how packages are built.
    * The Store::                   Manipulating the package store.
    * Derivations::                 Low-level interface to package derivations.
    * The Store Monad::             Purely functional interface to the store.
    * G-Expressions::               Manipulating build expressions.
    * Invoking guix repl::          Fiddling with Guix interactively.
    @end menu
    
    @node Package Modules
    @section Package Modules
    
    From a programming viewpoint, the package definitions of the
    GNU distribution are provided by Guile modules in the @code{(gnu packages
    @dots{})} name space@footnote{Note that packages under the @code{(gnu
    packages @dots{})} module name space are not necessarily ``GNU
    packages''.  This module naming scheme follows the usual Guile module
    naming convention: @code{gnu} means that these modules are distributed
    as part of the GNU system, and @code{packages} identifies modules that
    define packages.}  (@pxref{Modules, Guile modules,, guile, GNU Guile
    Reference Manual}).  For instance, the @code{(gnu packages emacs)}
    module exports a variable named @code{emacs}, which is bound to a
    @code{<package>} object (@pxref{Defining Packages}).
    
    The @code{(gnu packages @dots{})} module name space is
    automatically scanned for packages by the command-line tools.  For
    
    instance, when running @code{guix install emacs}, all the @code{(gnu
    
    packages @dots{})} modules are scanned until one that exports a package
    object whose name is @code{emacs} is found.  This package search
    facility is implemented in the @code{(gnu packages)} module.
    
    @cindex customization, of packages
    @cindex package module search path
    Users can store package definitions in modules with different
    names---e.g., @code{(my-packages emacs)}@footnote{Note that the file
    name and module name must match.  For instance, the @code{(my-packages
    emacs)} module must be stored in a @file{my-packages/emacs.scm} file
    relative to the load path specified with @option{--load-path} or
    @code{GUIX_PACKAGE_PATH}.  @xref{Modules and the File System,,,
    guile, GNU Guile Reference Manual}, for details.}.  There are two ways to make
    these package definitions visible to the user interfaces:
    
    @enumerate
    @item
    By adding the directory containing your package modules to the search path
    with the @code{-L} flag of @command{guix package} and other commands
    (@pxref{Common Build Options}), or by setting the @code{GUIX_PACKAGE_PATH}
    environment variable described below.
    
    @item
    By defining a @dfn{channel} and configuring @command{guix pull} so that it
    pulls from it.  A channel is essentially a Git repository containing package
    modules.  @xref{Channels}, for more information on how to define and use
    channels.
    @end enumerate
    
    @code{GUIX_PACKAGE_PATH} works similarly to other search path variables:
    
    @defvr {Environment Variable} GUIX_PACKAGE_PATH
    This is a colon-separated list of directories to search for additional
    package modules.  Directories listed in this variable take precedence
    over the own modules of the distribution.
    
    The distribution is fully @dfn{bootstrapped} and @dfn{self-contained}:
    each package is built based solely on other packages in the
    distribution.  The root of this dependency graph is a small set of
    @dfn{bootstrap binaries}, provided by the @code{(gnu packages
    bootstrap)} module.  For more information on bootstrapping,
    @pxref{Bootstrapping}.
    
    @node Defining Packages
    @section Defining Packages
    
    The high-level interface to package definitions is implemented in the
    @code{(guix packages)} and @code{(guix build-system)} modules.  As an
    example, the package definition, or @dfn{recipe}, for the GNU Hello
    package looks like this:
    
    @example
    (define-module (gnu packages hello)
      #:use-module (guix packages)
      #:use-module (guix download)
      #:use-module (guix build-system gnu)
      #:use-module (guix licenses)
      #:use-module (gnu packages gawk))
    
    (define-public hello
      (package
        (name "hello")
        (version "2.10")
        (source (origin
                  (method url-fetch)
                  (uri (string-append "mirror://gnu/hello/hello-" version
                                      ".tar.gz"))
                  (sha256
                   (base32
                    "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i"))))
        (build-system gnu-build-system)
        (arguments '(#:configure-flags '("--enable-silent-rules")))
        (inputs `(("gawk" ,gawk)))
        (synopsis "Hello, GNU world: An example GNU package")
        (description "Guess what GNU Hello prints!")
    
    Marius Bakke's avatar
    Marius Bakke committed
        (home-page "https://www.gnu.org/software/hello/")
    
        (license gpl3+)))
    @end example
    
    @noindent
    Without being a Scheme expert, the reader may have guessed the meaning
    of the various fields here.  This expression binds the variable
    @code{hello} to a @code{<package>} object, which is essentially a record
    (@pxref{SRFI-9, Scheme records,, guile, GNU Guile Reference Manual}).
    This package object can be inspected using procedures found in the
    @code{(guix packages)} module; for instance, @code{(package-name hello)}
    returns---surprise!---@code{"hello"}.
    
    With luck, you may be able to import part or all of the definition of
    the package you are interested in from another repository, using the
    @code{guix import} command (@pxref{Invoking guix import}).
    
    In the example above, @var{hello} is defined in a module of its own,
    @code{(gnu packages hello)}.  Technically, this is not strictly
    necessary, but it is convenient to do so: all the packages defined in
    modules under @code{(gnu packages @dots{})} are automatically known to
    the command-line tools (@pxref{Package Modules}).
    
    There are a few points worth noting in the above package definition:
    
    @itemize
    @item
    The @code{source} field of the package is an @code{<origin>} object
    (@pxref{origin Reference}, for the complete reference).
    Here, the @code{url-fetch} method from @code{(guix download)} is used,
    meaning that the source is a file to be downloaded over FTP or HTTP.
    
    The @code{mirror://gnu} prefix instructs @code{url-fetch} to use one of
    the GNU mirrors defined in @code{(guix download)}.
    
    The @code{sha256} field specifies the expected SHA256 hash of the file
    being downloaded.  It is mandatory, and allows Guix to check the
    integrity of the file.  The @code{(base32 @dots{})} form introduces the
    base32 representation of the hash.  You can obtain this information with
    @code{guix download} (@pxref{Invoking guix download}) and @code{guix
    hash} (@pxref{Invoking guix hash}).
    
    @cindex patches
    When needed, the @code{origin} form can also have a @code{patches} field
    listing patches to be applied, and a @code{snippet} field giving a
    Scheme expression to modify the source code.
    
    @item
    @cindex GNU Build System
    The @code{build-system} field specifies the procedure to build the
    package (@pxref{Build Systems}).  Here, @var{gnu-build-system}
    represents the familiar GNU Build System, where packages may be
    configured, built, and installed with the usual @code{./configure &&
    make && make check && make install} command sequence.
    
    @item
    The @code{arguments} field specifies options for the build system
    (@pxref{Build Systems}).  Here it is interpreted by
    @var{gnu-build-system} as a request run @file{configure} with the
    @code{--enable-silent-rules} flag.
    
    @cindex quote
    @cindex quoting
    @findex '
    @findex quote
    What about these quote (@code{'}) characters?  They are Scheme syntax to
    introduce a literal list; @code{'} is synonymous with @code{quote}.
    @xref{Expression Syntax, quoting,, guile, GNU Guile Reference Manual},
    for details.  Here the value of the @code{arguments} field is a list of
    arguments passed to the build system down the road, as with @code{apply}
    (@pxref{Fly Evaluation, @code{apply},, guile, GNU Guile Reference
    Manual}).
    
    The hash-colon (@code{#:}) sequence defines a Scheme @dfn{keyword}
    (@pxref{Keywords,,, guile, GNU Guile Reference Manual}), and
    @code{#:configure-flags} is a keyword used to pass a keyword argument
    to the build system (@pxref{Coding With Keywords,,, guile, GNU Guile
    Reference Manual}).
    
    @item
    The @code{inputs} field specifies inputs to the build process---i.e.,
    build-time or run-time dependencies of the package.  Here, we define an
    input called @code{"gawk"} whose value is that of the @var{gawk}
    variable; @var{gawk} is itself bound to a @code{<package>} object.
    
    @cindex backquote (quasiquote)
    @findex `
    @findex quasiquote
    @cindex comma (unquote)
    @findex ,
    @findex unquote
    @findex ,@@
    @findex unquote-splicing
    Again, @code{`} (a backquote, synonymous with @code{quasiquote}) allows
    us to introduce a literal list in the @code{inputs} field, while
    @code{,} (a comma, synonymous with @code{unquote}) allows us to insert a
    value in that list (@pxref{Expression Syntax, unquote,, guile, GNU Guile
    Reference Manual}).
    
    Note that GCC, Coreutils, Bash, and other essential tools do not need to
    be specified as inputs here.  Instead, @var{gnu-build-system} takes care
    of ensuring that they are present (@pxref{Build Systems}).
    
    However, any other dependencies need to be specified in the
    @code{inputs} field.  Any dependency not specified here will simply be
    unavailable to the build process, possibly leading to a build failure.
    @end itemize
    
    @xref{package Reference}, for a full description of possible fields.
    
    Once a package definition is in place, the
    package may actually be built using the @code{guix build} command-line
    tool (@pxref{Invoking guix build}), troubleshooting any build failures
    you encounter (@pxref{Debugging Build Failures}).  You can easily jump back to the
    package definition using the @command{guix edit} command
    (@pxref{Invoking guix edit}).
    @xref{Packaging Guidelines}, for
    more information on how to test package definitions, and
    @ref{Invoking guix lint}, for information on how to check a definition
    for style conformance.
    @vindex GUIX_PACKAGE_PATH
    Lastly, @pxref{Channels}, for information
    on how to extend the distribution by adding your own package definitions
    in a ``channel''.
    
    Finally, updating the package definition to a new upstream version
    can be partly automated by the @command{guix refresh} command
    (@pxref{Invoking guix refresh}).
    
    Behind the scenes, a derivation corresponding to the @code{<package>}
    object is first computed by the @code{package-derivation} procedure.
    That derivation is stored in a @code{.drv} file under @file{/gnu/store}.
    The build actions it prescribes may then be realized by using the
    @code{build-derivations} procedure (@pxref{The Store}).
    
    @deffn {Scheme Procedure} package-derivation @var{store} @var{package} [@var{system}]
    Return the @code{<derivation>} object of @var{package} for @var{system}
    (@pxref{Derivations}).
    
    @var{package} must be a valid @code{<package>} object, and @var{system}
    must be a string denoting the target system type---e.g.,
    @code{"x86_64-linux"} for an x86_64 Linux-based GNU system.  @var{store}
    must be a connection to the daemon, which operates on the store
    (@pxref{The Store}).
    @end deffn
    
    @noindent
    @cindex cross-compilation
    Similarly, it is possible to compute a derivation that cross-builds a
    package for some other system:
    
    @deffn {Scheme Procedure} package-cross-derivation @var{store} @
                @var{package} @var{target} [@var{system}]
    Return the @code{<derivation>} object of @var{package} cross-built from
    @var{system} to @var{target}.
    
    @var{target} must be a valid GNU triplet denoting the target hardware
    and operating system, such as @code{"mips64el-linux-gnu"}
    
    (@pxref{Specifying Target Triplets,,, autoconf, Autoconf}).
    
    @end deffn
    
    @cindex package transformations
    @cindex input rewriting
    @cindex dependency tree rewriting
    Packages can be manipulated in arbitrary ways.  An example of a useful
    transformation is @dfn{input rewriting}, whereby the dependency tree of
    a package is rewritten by replacing specific inputs by others:
    
    @deffn {Scheme Procedure} package-input-rewriting @var{replacements} @
               [@var{rewrite-name}]
    Return a procedure that, when passed a package, replaces its direct and
    indirect dependencies (but not its implicit inputs) according to
    @var{replacements}.  @var{replacements} is a list of package pairs; the
    first element of each pair is the package to replace, and the second one
    is the replacement.
    
    Optionally, @var{rewrite-name} is a one-argument procedure that takes
    the name of a package and returns its new name after rewrite.
    @end deffn
    
    @noindent
    Consider this example:
    
    @example
    (define libressl-instead-of-openssl
      ;; This is a procedure to replace OPENSSL by LIBRESSL,
      ;; recursively.
      (package-input-rewriting `((,openssl . ,libressl))))
    
    (define git-with-libressl
      (libressl-instead-of-openssl git))
    @end example
    
    @noindent
    Here we first define a rewriting procedure that replaces @var{openssl}
    with @var{libressl}.  Then we use it to define a @dfn{variant} of the
    @var{git} package that uses @var{libressl} instead of @var{openssl}.
    This is exactly what the @option{--with-input} command-line option does
    (@pxref{Package Transformation Options, @option{--with-input}}).
    
    
    The following variant of @code{package-input-rewriting} can match packages to
    be replaced by name rather than by identity.
    
    @deffn {Scheme Procedure} package-input-rewriting/spec @var{replacements}
    Return a procedure that, given a package, applies the given @var{replacements} to
    all the package graph (excluding implicit inputs).  @var{replacements} is a list of
    spec/procedures pair; each spec is a package specification such as @code{"gcc"} or
    @code{"guile@@2"}, and each procedure takes a matching package and returns a
    replacement for that package.
    @end deffn
    
    The example above could be rewritten this way:
    
    @example
    (define libressl-instead-of-openssl
      ;; Replace all the packages called "openssl" with LibreSSL.
      (package-input-rewriting/spec `(("openssl" . ,(const libressl)))))
    @end example
    
    The key difference here is that, this time, packages are matched by spec and
    not by identity.  In other words, any package in the graph that is called
    @code{openssl} will be replaced.
    
    
    A more generic procedure to rewrite a package dependency graph is
    @code{package-mapping}: it supports arbitrary changes to nodes in the
    graph.
    
    @deffn {Scheme Procedure} package-mapping @var{proc} [@var{cut?}]
    Return a procedure that, given a package, applies @var{proc} to all the packages
    depended on and returns the resulting package.  The procedure stops recursion
    when @var{cut?} returns true for a given package.
    @end deffn
    
    @menu
    * package Reference::           The package data type.
    * origin Reference::            The origin data type.
    @end menu
    
    
    @node package Reference
    @subsection @code{package} Reference
    
    This section summarizes all the options available in @code{package}
    declarations (@pxref{Defining Packages}).
    
    @deftp {Data Type} package
    This is the data type representing a package recipe.
    
    @table @asis
    @item @code{name}
    The name of the package, as a string.
    
    @item @code{version}
    The version of the package, as a string.
    
    @item @code{source}
    An object telling how the source code for the package should be
    acquired.  Most of the time, this is an @code{origin} object, which
    denotes a file fetched from the Internet (@pxref{origin Reference}).  It
    can also be any other ``file-like'' object such as a @code{local-file},
    which denotes a file from the local file system (@pxref{G-Expressions,
    @code{local-file}}).
    
    @item @code{build-system}
    The build system that should be used to build the package (@pxref{Build
    Systems}).
    
    @item @code{arguments} (default: @code{'()})
    The arguments that should be passed to the build system.  This is a
    list, typically containing sequential keyword-value pairs.
    
    @item @code{inputs} (default: @code{'()})
    @itemx @code{native-inputs} (default: @code{'()})
    @itemx @code{propagated-inputs} (default: @code{'()})
    @cindex inputs, of packages
    These fields list dependencies of the package.  Each one is a list of
    tuples, where each tuple has a label for the input (a string) as its
    first element, a package, origin, or derivation as its second element,
    and optionally the name of the output thereof that should be used, which
    defaults to @code{"out"} (@pxref{Packages with Multiple Outputs}, for
    more on package outputs).  For example, the list below specifies three
    inputs:
    
    @example
    `(("libffi" ,libffi)
      ("libunistring" ,libunistring)
      ("glib:bin" ,glib "bin"))  ;the "bin" output of Glib
    @end example
    
    @cindex cross compilation, package dependencies
    The distinction between @code{native-inputs} and @code{inputs} is
    necessary when considering cross-compilation.  When cross-compiling,
    dependencies listed in @code{inputs} are built for the @emph{target}
    architecture; conversely, dependencies listed in @code{native-inputs}
    are built for the architecture of the @emph{build} machine.
    
    @code{native-inputs} is typically used to list tools needed at
    build time, but not at run time, such as Autoconf, Automake, pkg-config,
    Gettext, or Bison.  @command{guix lint} can report likely mistakes in
    this area (@pxref{Invoking guix lint}).
    
    @anchor{package-propagated-inputs}
    Lastly, @code{propagated-inputs} is similar to @code{inputs}, but the
    specified packages will be automatically installed alongside the package
    they belong to (@pxref{package-cmd-propagated-inputs, @command{guix
    package}}, for information on how @command{guix package} deals with
    propagated inputs.)
    
    For example this is necessary when a C/C++ library needs headers of
    another library to compile, or when a pkg-config file refers to another
    one @i{via} its @code{Requires} field.
    
    Another example where @code{propagated-inputs} is useful is for languages
    that lack a facility to record the run-time search path akin to the
    @code{RUNPATH} of ELF files; this includes Guile, Python, Perl, and
    more.  To ensure that libraries written in those languages can find
    library code they depend on at run time, run-time dependencies must be
    listed in @code{propagated-inputs} rather than @code{inputs}.
    
    @item @code{outputs} (default: @code{'("out")})
    The list of output names of the package.  @xref{Packages with Multiple
    Outputs}, for typical uses of additional outputs.
    
    @item @code{native-search-paths} (default: @code{'()})
    @itemx @code{search-paths} (default: @code{'()})
    A list of @code{search-path-specification} objects describing
    search-path environment variables honored by the package.
    
    @item @code{replacement} (default: @code{#f})
    This must be either @code{#f} or a package object that will be used as a
    @dfn{replacement} for this package.  @xref{Security Updates, grafts},
    for details.
    
    @item @code{synopsis}
    A one-line description of the package.
    
    @item @code{description}
    A more elaborate description of the package.
    
    @item @code{license}
    @cindex license, of packages
    The license of the package; a value from @code{(guix licenses)},
    or a list of such values.
    
    @item @code{home-page}
    The URL to the home-page of the package, as a string.
    
    @item @code{supported-systems} (default: @var{%supported-systems})
    The list of systems supported by the package, as strings of the form
    @code{architecture-kernel}, for example @code{"x86_64-linux"}.
    
    @item @code{maintainers} (default: @code{'()})
    The list of maintainers of the package, as @code{maintainer} objects.
    
    @item @code{location} (default: source location of the @code{package} form)
    The source location of the package.  It is useful to override this when
    inheriting from another package, in which case this field is not
    automatically corrected.
    
    @deffn {Scheme Syntax} this-package
    When used in the @emph{lexical scope} of a package field definition, this
    identifier resolves to the package being defined.
    
    The example below shows how to add a package as a native input of itself when
    cross-compiling:
    
    @example
    (package
      (name "guile")
      ;; ...
    
      ;; When cross-compiled, Guile, for example, depends on
      ;; a native version of itself.  Add it here.
      (native-inputs (if (%current-target-system)
                         `(("self" ,this-package))
                         '())))
    @end example
    
    It is an error to refer to @code{this-package} outside a package definition.
    @end deffn
    
    @node origin Reference
    @subsection @code{origin} Reference
    
    This section summarizes all the options available in @code{origin}
    declarations (@pxref{Defining Packages}).
    
    @deftp {Data Type} origin
    This is the data type representing a source code origin.
    
    @table @asis
    @item @code{uri}
    An object containing the URI of the source.  The object type depends on
    the @code{method} (see below).  For example, when using the
    @var{url-fetch} method of @code{(guix download)}, the valid @code{uri}
    values are: a URL represented as a string, or a list thereof.
    
    @item @code{method}
    A procedure that handles the URI.
    
    Examples include:
    
    @table @asis
    @item @var{url-fetch} from @code{(guix download)}
    download a file from the HTTP, HTTPS, or FTP URL specified in the
    @code{uri} field;
    
    @vindex git-fetch
    @item @var{git-fetch} from @code{(guix git-download)}
    clone the Git version control repository, and check out the revision
    specified in the @code{uri} field as a @code{git-reference} object; a
    @code{git-reference} looks like this:
    
    @example
    (git-reference
      (url "git://git.debian.org/git/pkg-shadow/shadow")
      (commit "v4.1.5.1"))
    @end example
    @end table
    
    @item @code{sha256}
    A bytevector containing the SHA-256 hash of the source.  Typically the
    @code{base32} form is used here to generate the bytevector from a
    base-32 string.
    
    You can obtain this information using @code{guix download}
    (@pxref{Invoking guix download}) or @code{guix hash} (@pxref{Invoking
    guix hash}).
    
    @item @code{file-name} (default: @code{#f})
    The file name under which the source code should be saved.  When this is
    @code{#f}, a sensible default value will be used in most cases.  In case
    the source is fetched from a URL, the file name from the URL will be
    used.  For version control checkouts, it is recommended to provide the
    file name explicitly because the default is not very descriptive.
    
    @item @code{patches} (default: @code{'()})
    A list of file names, origins, or file-like objects (@pxref{G-Expressions,
    file-like objects}) pointing to patches to be applied to the source.
    
    This list of patches must be unconditional.  In particular, it cannot
    depend on the value of @code{%current-system} or
    @code{%current-target-system}.
    
    @item @code{snippet} (default: @code{#f})
    A G-expression (@pxref{G-Expressions}) or S-expression that will be run
    in the source directory.  This is a convenient way to modify the source,
    sometimes more convenient than a patch.
    
    @item @code{patch-flags} (default: @code{'("-p1")})
    A list of command-line flags that should be passed to the @code{patch}
    command.
    
    @item @code{patch-inputs} (default: @code{#f})
    Input packages or derivations to the patching process.  When this is
    @code{#f}, the usual set of inputs necessary for patching are provided,
    such as GNU@tie{}Patch.
    
    @item @code{modules} (default: @code{'()})
    A list of Guile modules that should be loaded during the patching
    process and while running the code in the @code{snippet} field.
    
    @item @code{patch-guile} (default: @code{#f})
    The Guile package that should be used in the patching process.  When
    this is @code{#f}, a sensible default is used.
    
    @node Build Systems
    @section Build Systems
    
    @cindex build system
    Each package definition specifies a @dfn{build system} and arguments for
    that build system (@pxref{Defining Packages}).  This @code{build-system}
    field represents the build procedure of the package, as well as implicit
    dependencies of that build procedure.
    
    Build systems are @code{<build-system>} objects.  The interface to
    create and manipulate them is provided by the @code{(guix build-system)}
    module, and actual build systems are exported by specific modules.
    
    @cindex bag (low-level package representation)
    Under the hood, build systems first compile package objects to
    @dfn{bags}.  A @dfn{bag} is like a package, but with less
    ornamentation---in other words, a bag is a lower-level representation of
    a package, which includes all the inputs of that package, including some
    that were implicitly added by the build system.  This intermediate
    representation is then compiled to a derivation (@pxref{Derivations}).
    
    Build systems accept an optional list of @dfn{arguments}.  In package
    definitions, these are passed @i{via} the @code{arguments} field
    (@pxref{Defining Packages}).  They are typically keyword arguments
    (@pxref{Optional Arguments, keyword arguments in Guile,, guile, GNU
    Guile Reference Manual}).  The value of these arguments is usually
    evaluated in the @dfn{build stratum}---i.e., by a Guile process launched
    by the daemon (@pxref{Derivations}).
    
    The main build system is @var{gnu-build-system}, which implements the
    standard build procedure for GNU and many other packages.  It
    is provided by the @code{(guix build-system gnu)} module.
    
    @defvr {Scheme Variable} gnu-build-system
    @var{gnu-build-system} represents the GNU Build System, and variants
    thereof (@pxref{Configuration, configuration and makefile conventions,,
    standards, GNU Coding Standards}).
    
    @cindex build phases
    In a nutshell, packages using it are configured, built, and installed with
    the usual @code{./configure && make && make check && make install}
    command sequence.  In practice, a few additional steps are often needed.
    All these steps are split up in separate @dfn{phases},
    notably@footnote{Please see the @code{(guix build gnu-build-system)}
    modules for more details about the build phases.}:
    
    @table @code
    @item unpack
    Unpack the source tarball, and change the current directory to the
    extracted source tree.  If the source is actually a directory, copy it
    to the build tree, and enter that directory.
    
    @item patch-source-shebangs
    Patch shebangs encountered in source files so they refer to the right
    store file names.  For instance, this changes @code{#!/bin/sh} to
    @code{#!/gnu/store/@dots{}-bash-4.3/bin/sh}.
    
    @item configure
    Run the @file{configure} script with a number of default options, such
    as @code{--prefix=/gnu/store/@dots{}}, as well as the options specified
    by the @code{#:configure-flags} argument.
    
    @item build
    Run @code{make} with the list of flags specified with
    @code{#:make-flags}.  If the @code{#:parallel-build?} argument is true
    (the default), build with @code{make -j}.
    
    @item check
    Run @code{make check}, or some other target specified with
    @code{#:test-target}, unless @code{#:tests? #f} is passed.  If the
    @code{#:parallel-tests?} argument is true (the default), run @code{make
    check -j}.
    
    @item install
    Run @code{make install} with the flags listed in @code{#:make-flags}.
    
    @item patch-shebangs
    Patch shebangs on the installed executable files.
    
    @item strip
    Strip debugging symbols from ELF files (unless @code{#:strip-binaries?}
    is false), copying them to the @code{debug} output when available
    (@pxref{Installing Debugging Files}).
    @end table
    
    @vindex %standard-phases
    The build-side module @code{(guix build gnu-build-system)} defines
    @var{%standard-phases} as the default list of build phases.
    @var{%standard-phases} is a list of symbol/procedure pairs, where the
    procedure implements the actual phase.
    
    The list of phases used for a particular package can be changed with the
    @code{#:phases} parameter.  For instance, passing:
    
    @example
    #:phases (modify-phases %standard-phases (delete 'configure))
    @end example
    
    means that all the phases described above will be used, except the
    @code{configure} phase.
    
    In addition, this build system ensures that the ``standard'' environment
    for GNU packages is available.  This includes tools such as GCC, libc,
    Coreutils, Bash, Make, Diffutils, grep, and sed (see the @code{(guix
    build-system gnu)} module for a complete list).  We call these the
    @dfn{implicit inputs} of a package, because package definitions do not
    have to mention them.
    
    Other @code{<build-system>} objects are defined to support other
    conventions and tools used by free software packages.  They inherit most
    of @var{gnu-build-system}, and differ mainly in the set of inputs
    implicitly added to the build process, and in the list of phases
    executed.  Some of these build systems are listed below.
    
    @defvr {Scheme Variable} ant-build-system
    This variable is exported by @code{(guix build-system ant)}.  It
    implements the build procedure for Java packages that can be built with
    
    Marius Bakke's avatar
    Marius Bakke committed
    @url{https://ant.apache.org/, Ant build tool}.
    
    It adds both @code{ant} and the @dfn{Java Development Kit} (JDK) as
    provided by the @code{icedtea} package to the set of inputs.  Different
    packages can be specified with the @code{#:ant} and @code{#:jdk}
    parameters, respectively.
    
    When the original package does not provide a suitable Ant build file,
    the parameter @code{#:jar-name} can be used to generate a minimal Ant
    build file @file{build.xml} with tasks to build the specified jar
    archive.  In this case the parameter @code{#:source-dir} can be used to
    specify the source sub-directory, defaulting to ``src''.
    
    The @code{#:main-class} parameter can be used with the minimal ant 
    buildfile to specify the main class of the resulting jar.  This makes the 
    jar file executable.  The @code{#:test-include} parameter can be used to 
    specify the list of junit tests to run. It defaults to
    @code{(list "**/*Test.java")}.  The @code{#:test-exclude} can be used to
    disable some tests. It defaults to @code{(list "**/Abstract*.java")},
    because abstract classes cannot be run as tests.
    
    The parameter @code{#:build-target} can be used to specify the Ant task
    that should be run during the @code{build} phase.  By default the
    ``jar'' task will be run.
    
    @defvr {Scheme Variable} android-ndk-build-system
    @cindex Android distribution
    @cindex Android NDK build system
    This variable is exported by @code{(guix build-system android-ndk)}.  It
    implements a build procedure for Android NDK (native development kit)
    packages using a Guix-specific build process.
    
    The build system assumes that packages install their public interface
    (header) files to the subdirectory "include" of the "out" output and
    their libraries to the subdirectory "lib" of the "out" output.
    
    It's also assumed that the union of all the dependencies of a package
    has no conflicting files.
    
    For the time being, cross-compilation is not supported - so right now
    the libraries and header files are assumed to be host tools.
    
    @defvr {Scheme Variable} asdf-build-system/source
    @defvrx {Scheme Variable} asdf-build-system/sbcl
    @defvrx {Scheme Variable} asdf-build-system/ecl
    
    These variables, exported by @code{(guix build-system asdf)}, implement
    build procedures for Common Lisp packages using
    @url{https://common-lisp.net/project/asdf/, ``ASDF''}. ASDF is a system
    definition facility for Common Lisp programs and libraries.
    
    The @code{asdf-build-system/source} system installs the packages in
    source form, and can be loaded using any common lisp implementation, via
    ASDF.  The others, such as @code{asdf-build-system/sbcl}, install binary
    systems in the format which a particular implementation understands.
    These build systems can also be used to produce executable programs, or
    lisp images which contain a set of packages pre-loaded.
    
    The build system uses naming conventions.  For binary packages, the
    package name should be prefixed with the lisp implementation, such as
    @code{sbcl-} for @code{asdf-build-system/sbcl}.
    
    Additionally, the corresponding source package should be labeled using
    the same convention as python packages (see @ref{Python Modules}), using
    the @code{cl-} prefix.
    
    For binary packages, each system should be defined as a Guix package.
    If one package @code{origin} contains several systems, package variants
    can be created in order to build all the systems.  Source packages,
    which use @code{asdf-build-system/source}, may contain several systems.
    
    In order to create executable programs and images, the build-side
    procedures @code{build-program} and @code{build-image} can be used.
    They should be called in a build phase after the @code{create-symlinks}
    phase, so that the system which was just built can be used within the
    resulting image.  @code{build-program} requires a list of Common Lisp
    expressions to be passed as the @code{#:entry-program} argument.
    
    If the system is not defined within its own @code{.asd} file of the same
    name, then the @code{#:asd-file} parameter should be used to specify
    which file the system is defined in.  Furthermore, if the package
    defines a system for its tests in a separate file, it will be loaded
    before the tests are run if it is specified by the
    @code{#:test-asd-file} parameter.  If it is not set, the files
    @code{<system>-tests.asd}, @code{<system>-test.asd}, @code{tests.asd},
    and @code{test.asd} will be tried if they exist.
    
    If for some reason the package must be named in a different way than the
    naming conventions suggest, the @code{#:asd-system-name} parameter can
    be used to specify the name of the system.
    
    @defvr {Scheme Variable} cargo-build-system
    @cindex Rust programming language
    @cindex Cargo (Rust build system)
    This variable is exported by @code{(guix build-system cargo)}.  It
    supports builds of packages using Cargo, the build tool of the
    @uref{https://www.rust-lang.org, Rust programming language}.
    
    It adds @code{rustc} and @code{cargo} to the set of inputs.
    A different Rust package can be specified with the @code{#:rust} parameter.
    
    Regular cargo dependencies should be added to the package definition via the
    @code{#:cargo-inputs} parameter as a list of name and spec pairs, where the
    spec can be a package or a source definition.  Note that the spec must
    evaluate to a path to a gzipped tarball which includes a @code{Cargo.toml}
    file at its root, or it will be ignored.  Similarly, cargo dev-dependencies
    should be added to the package definition via the
    @code{#:cargo-development-inputs} parameter.
    
    In its @code{configure} phase, this build system will make any source inputs
    specified in the @code{#:cargo-inputs} and @code{#:cargo-development-inputs}
    parameters available to cargo.  The @code{install} phase installs any crate
    the binaries if they are defined by the crate.
    
    @cindex Clojure (programming language)
    @cindex simple Clojure build system
    @defvr {Scheme Variable} clojure-build-system
    This variable is exported by @code{(guix build-system clojure)}.  It implements
    a simple build procedure for @uref{https://clojure.org/, Clojure} packages
    using plain old @code{compile} in Clojure.  Cross-compilation is not supported
    yet.
    
    It adds @code{clojure}, @code{icedtea} and @code{zip} to the set of inputs.
    Different packages can be specified with the @code{#:clojure}, @code{#:jdk} and
    @code{#:zip} parameters, respectively.
    
    A list of source directories, test directories and jar names can be specified
    with the @code{#:source-dirs}, @code{#:test-dirs} and @code{#:jar-names}
    parameters, respectively.  Compile directory and main class can be specified
    with the @code{#:compile-dir} and @code{#:main-class} parameters, respectively.
    Other parameters are documented below.
    
    This build system is an extension of @var{ant-build-system}, but with the
    following phases changed:
    
    This phase calls @code{compile} in Clojure to compile source files and runs
    @command{jar} to create jars from both source files and compiled files
    according to the include list and exclude list specified in
    @code{#:aot-include} and @code{#:aot-exclude}, respectively.  The exclude list
    has priority over the include list.  These lists consist of symbols
    representing Clojure libraries or the special keyword @code{#:all} representing
    all Clojure libraries found under the source directories.  The parameter
    @code{#:omit-source?} decides if source should be included into the jars.
    
    This phase runs tests according to the include list and exclude list specified
    in @code{#:test-include} and @code{#:test-exclude}, respectively.  Their
    meanings are analogous to that of @code{#:aot-include} and
    @code{#:aot-exclude}, except that the special keyword @code{#:all} now
    stands for all Clojure libraries found under the test directories.  The
    parameter @code{#:tests?} decides if tests should be run.
    
    This phase installs all jars built previously.
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    @end table
    
    
    Apart from the above, this build system also contains an additional phase:
    
    @item install-doc
    This phase installs all top-level files with base name matching
    @var{%doc-regex}.  A different regex can be specified with the
    @code{#:doc-regex} parameter.  All files (recursively) inside the documentation
    directories specified in @code{#:doc-dirs} are installed as well.
    
    @defvr {Scheme Variable} cmake-build-system
    This variable is exported by @code{(guix build-system cmake)}.  It
    implements the build procedure for packages using the
    
    Marius Bakke's avatar
    Marius Bakke committed
    @url{https://www.cmake.org, CMake build tool}.
    
    It automatically adds the @code{cmake} package to the set of inputs.
    Which package is used can be specified with the @code{#:cmake}
    parameter.
    
    The @code{#:configure-flags} parameter is taken as a list of flags
    passed to the @command{cmake} command.  The @code{#:build-type}
    parameter specifies in abstract terms the flags passed to the compiler;
    it defaults to @code{"RelWithDebInfo"} (short for ``release mode with
    debugging information''), which roughly means that code is compiled with
    @code{-O2 -g}, as is the case for Autoconf-based packages by default.
    
    @defvr {Scheme Variable} dune-build-system
    This variable is exported by @code{(guix build-system dune)}.  It
    supports builds of packages using @uref{https://dune.build/, Dune}, a build
    tool for the OCaml programming language.  It is implemented as an extension
    of the @code{ocaml-build-system} which is described below.  As such, the
    @code{#:ocaml} and @code{#:findlib} parameters can be passed to this build
    system.
    
    It automatically adds the @code{dune} package to the set of inputs.
    Which package is used can be specified with the @code{#:dune}
    parameter.
    
    There is no @code{configure} phase because dune packages typically don't
    need to be configured.  The @code{#:build-flags} parameter is taken as a
    list of flags passed to the @code{dune} command during the build.
    
    The @code{#:jbuild?} parameter can be passed to use the @code{jbuild}
    command instead of the more recent @code{dune} command while building
    a package.  Its default value is @code{#f}.
    
    
    The @code{#:package} parameter can be passed to specify a package name, which
    is useful when a package contains multiple packages and you want to build
    only one of them.  This is equivalent to passing the @code{-p} argument to
    @code{dune}.
    
    @defvr {Scheme Variable} go-build-system
    This variable is exported by @code{(guix build-system go)}.  It
    implements a build procedure for Go packages using the standard
    @url{https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies,
    Go build mechanisms}.
    
    The user is expected to provide a value for the key @code{#:import-path}
    and, in some cases, @code{#:unpack-path}.  The
    @url{https://golang.org/doc/code.html#ImportPaths, import path}
    corresponds to the file system path expected by the package's build
    scripts and any referring packages, and provides a unique way to
    refer to a Go package.  It is typically based on a combination of the
    package source code's remote URI and file system hierarchy structure.  In
    some cases, you will need to unpack the package's source code to a
    different directory structure than the one indicated by the import path,
    and @code{#:unpack-path} should be used in such cases.
    
    Packages that provide Go libraries should install their source code into
    the built output.  The key @code{#:install-source?}, which defaults to
    
    @code{#t}, controls whether or not the source code is installed.  It can
    be set to @code{#f} for packages that only provide executable files.
    @end defvr
    
    @defvr {Scheme Variable} glib-or-gtk-build-system
    This variable is exported by @code{(guix build-system glib-or-gtk)}.  It
    is intended for use with packages making use of GLib or GTK+.
    
    This build system adds the following two phases to the ones defined by
    @var{gnu-build-system}:
    
    @table @code
    @item glib-or-gtk-wrap
    The phase @code{glib-or-gtk-wrap} ensures that programs in
    @file{bin/} are able to find GLib ``schemas'' and
    @uref{https://developer.gnome.org/gtk3/stable/gtk-running.html, GTK+
    modules}.  This is achieved by wrapping the programs in launch scripts
    that appropriately set the @code{XDG_DATA_DIRS} and @code{GTK_PATH}
    environment variables.
    
    It is possible to exclude specific package outputs from that wrapping
    process by listing their names in the
    @code{#:glib-or-gtk-wrap-excluded-outputs} parameter.  This is useful
    when an output is known not to contain any GLib or GTK+ binaries, and
    where wrapping would gratuitously add a dependency of that output on
    GLib and GTK+.
    
    @item glib-or-gtk-compile-schemas
    The phase @code{glib-or-gtk-compile-schemas} makes sure that all
    @uref{https://developer.gnome.org/gio/stable/glib-compile-schemas.html,
    GSettings schemas} of GLib are compiled.  Compilation is performed by the
    @command{glib-compile-schemas} program.  It is provided by the package
    @code{glib:bin} which is automatically imported by the build system.
    The @code{glib} package providing @command{glib-compile-schemas} can be
    specified with the @code{#:glib} parameter.
    @end table
    
    Both phases are executed after the @code{install} phase.
    @end defvr
    
    @defvr {Scheme Variable} guile-build-system
    This build system is for Guile packages that consist exclusively of Scheme
    code and that are so lean that they don't even have a makefile, let alone a
    @file{configure} script.  It compiles Scheme code using @command{guild
    compile} (@pxref{Compilation,,, guile, GNU Guile Reference Manual}) and
    installs the @file{.scm} and @file{.go} files in the right place.  It also
    installs documentation.