Skip to content
Snippets Groups Projects
guix.texi 315 KiB
Newer Older
  • Learn to ignore specific revisions
  • accounts, system services, global package list, setuid programs, etc.
    
    It also adds a GRUB menu entry for the new OS configuration, and moves
    entries for older configurations to a submenu---unless
    @option{--no-grub} is passed.
    
    @c The paragraph below refers to the problem discussed at
    @c <http://lists.gnu.org/archive/html/guix-devel/2014-08/msg00057.html>.
    It is highly recommended to run @command{guix pull} once before you run
    @command{guix system reconfigure} for the first time (@pxref{Invoking
    guix pull}).  Failing to do that you would see an older version of Guix
    once @command{reconfigure} has completed.
    
    
    @item build
    Build the operating system's derivation, which includes all the
    configuration files and programs needed to boot and run the system.
    This action does not actually install anything.
    
    @item init
    Populate the given directory with all the files necessary to run the
    operating system specified in @var{file}.  This is useful for first-time
    
    installations of GuixSD.  For instance:
    
    guix system init my-os-config.scm /mnt
    
    copies to @file{/mnt} all the store items required by the configuration
    specified in @file{my-os-config.scm}.  This includes configuration
    files, packages, and so on.  It also creates other essential files
    needed for the system to operate correctly---e.g., the @file{/etc},
    @file{/var}, and @file{/run} directories, and the @file{/bin/sh} file.
    
    This command also installs GRUB on the device specified in
    @file{my-os-config}, unless the @option{--no-grub} option was passed.
    
    @item vm
    @cindex virtual machine
    
    Build a virtual machine that contain the operating system declared in
    @var{file}, and return a script to run that virtual machine (VM).
    
    Arguments given to the script are passed as is to QEMU.
    
    The VM shares its store with the host system.
    
    Additional file systems can be shared between the host and the VM using
    the @code{--share} and @code{--expose} command-line options: the former
    specifies a directory to be shared with write access, while the latter
    provides read-only access to the shared directory.
    
    The example below creates a VM in which the user's home directory is
    accessible read-only, and where the @file{/exchange} directory is a
    read-write mapping of the host's @file{$HOME/tmp}:
    
    @example
    guix system vm my-config.scm \
       --expose=$HOME --share=$HOME/tmp=/exchange
    @end example
    
    
    On GNU/Linux, the default is to boot directly to the kernel; this has
    the advantage of requiring only a very tiny root disk image since the
    host's store can then be mounted.
    
    The @code{--full-boot} option forces a complete boot sequence, starting
    with the bootloader.  This requires more disk space since a root image
    containing at least the kernel, initrd, and bootloader data files must
    be created.  The @code{--image-size} option can be used to specify the
    image's size.
    
    @item vm-image
    @itemx disk-image
    Return a virtual machine or disk image of the operating system declared
    in @var{file} that stands alone.  Use the @option{--image-size} option
    to specify the size of the image.
    
    When using @code{vm-image}, the returned image is in qcow2 format, which
    the QEMU emulator can efficiently use.
    
    When using @code{disk-image}, a raw disk image is produced; it can be
    copied as is to a USB stick, for instance.  Assuming @code{/dev/sdc} is
    the device corresponding to a USB stick, one can copy the image on it
    using the following command:
    
    @example
    # dd if=$(guix system disk-image my-os.scm) of=/dev/sdc
    @end example
    
    @var{options} can contain any of the common build options provided by
    @command{guix build} (@pxref{Invoking guix build}).  In addition,
    @var{options} can contain one of the following:
    
    @table @option
    @item --system=@var{system}
    @itemx -s @var{system}
    Attempt to build for @var{system} instead of the host's system type.
    This works as per @command{guix build} (@pxref{Invoking guix build}).
    
    @item --derivation
    @itemx -d
    Return the derivation file name of the given operating system without
    building anything.
    
    
    @item --image-size=@var{size}
    For the @code{vm-image} and @code{disk-image} actions, create an image
    of the given @var{size}.  @var{size} may be a number of bytes, or it may
    
    include a unit as a suffix (@pxref{Block size, size specifications,,
    coreutils, GNU Coreutils}).
    
    
    @item --on-error=@var{strategy}
    Apply @var{strategy} when an error occurs when reading @var{file}.
    @var{strategy} may be one of the following:
    
    @table @code
    @item nothing-special
    Report the error concisely and exit.  This is the default strategy.
    
    @item backtrace
    Likewise, but also display a backtrace.
    
    @item debug
    Report the error and enter Guile's debugger.  From there, you can run
    commands such as @code{,bt} to get a backtrace, @code{,locals} to
    display local variable values, and more generally inspect the program's
    state.  @xref{Debug Commands,,, guile, GNU Guile Reference Manual}, for
    a list of available debugging commands.
    @end table
    
    Note that all the actions above, except @code{build} and @code{init},
    rely on KVM support in the Linux-Libre kernel.  Specifically, the
    machine should have hardware virtualization support, the corresponding
    KVM kernel module should be loaded, and the @file{/dev/kvm} device node
    must exist and be readable and writable by the user and by the daemon's
    build users.
    
    The @command{guix system} command has even more to offer!  The following
    sub-commands allow you to visualize how your system services relate to
    each other:
    
    @anchor{system-extension-graph}
    @table @code
    
    @item extension-graph
    Emit in Dot/Graphviz format to standard output the @dfn{service
    extension graph} of the operating system defined in @var{file}
    (@pxref{Service Composition}, for more information on service
    extensions.)
    
    The command:
    
    @example
    $ guix system extension-graph @var{file} | dot -Tpdf > services.pdf
    @end example
    
    produces a PDF file showing the extension relations among services.
    
    
    @anchor{system-dmd-graph}
    @item dmd-graph
    Emit in Dot/Graphviz format to standard output the @dfn{dependency
    graph} of dmd services of the operating system defined in @var{file}.
    @xref{dmd Services}, for more information and for an example graph.
    
    
    @node Defining Services
    @subsection Defining Services
    
    Alex Kost's avatar
    Alex Kost committed
    The previous sections show the available services and how one can combine
    
    them in an @code{operating-system} declaration.  But how do we define
    them in the first place?  And what is a service anyway?
    
    @menu
    * Service Composition::         The model for composing services.
    * Service Types and Services::  Types and services.
    * Service Reference::           API reference.
    * dmd Services::                A particular type of service.
    @end menu
    
    @node Service Composition
    @subsubsection Service Composition
    
    @cindex services
    @cindex daemons
    Here we define a @dfn{service} as, broadly, something that extends the
    operating system's functionality.  Often a service is a process---a
    @dfn{daemon}---started when the system boots: a secure shell server, a
    Web server, the Guix build daemon, etc.  Sometimes a service is a daemon
    whose execution can be triggered by another daemon---e.g., an FTP server
    started by @command{inetd} or a D-Bus service activated by
    @command{dbus-daemon}.  Occasionally, a service does not map to a
    daemon.  For instance, the ``account'' service collects user accounts
    and makes sure they exist when the system runs; the ``udev'' service
    collects device management rules and makes them available to the eudev
    daemon; the @file{/etc} service populates the system's @file{/etc}
    directory.
    
    
    @cindex service extensions
    
    GuixSD services are connected by @dfn{extensions}.  For instance, the
    secure shell service @emph{extends} dmd---GuixSD's initialization system,
    running as PID@tie{}1---by giving it the command lines to start and stop
    the secure shell daemon (@pxref{Networking Services,
    @code{lsh-service}}); the UPower service extends the D-Bus service by
    passing it its @file{.service} specification, and extends the udev
    service by passing it device management rules (@pxref{Desktop Services,
    @code{upower-service}}); the Guix daemon service extends dmd by passing
    it the command lines to start and stop the daemon, and extends the
    account service by passing it a list of required build user accounts
    (@pxref{Base Services}).
    
    All in all, services and their ``extends'' relations form a directed
    acyclic graph (DAG).  If we represent services as boxes and extensions
    as arrows, a typical system might provide something like this:
    
    @image{images/service-graph,,5in,Typical service extension graph.}
    
    At the bottom, we see the @dfn{boot service}, which produces the boot
    script that is executed at boot time from the initial RAM disk.
    
    @xref{system-extension-graph, the @command{guix system extension-graph}
    command}, for information on how to generate this representation for a
    particular operating system definition.
    
    
    @cindex service types
    Technically, developers can define @dfn{service types} to express these
    relations.  There can be any number of services of a given type on the
    system---for instance, a system running two instances of the GNU secure
    shell server (lsh) has two instances of @var{lsh-service-type}, with
    different parameters.
    
    The following section describes the programming interface for service
    types and services.
    
    @node Service Types and Services
    @subsubsection Service Types and Services
    
    A @dfn{service type} is a node in the DAG described above.  Let us start
    with a simple example, the service type for the Guix build daemon
    (@pxref{Invoking guix-daemon}):
    
    @example
    (define guix-service-type
      (service-type
       (name 'guix)
       (extensions
        (list (service-extension dmd-root-service-type guix-dmd-service)
              (service-extension account-service-type guix-accounts)
              (service-extension activation-service-type guix-activation)))))
    @end example
    
    It defines a two things:
    
    @enumerate
    @item
    A name, whose sole purpose is to make inspection and debugging easier.
    
    @item
    A list of @dfn{service extensions}, where each extension designates the
    target service type and a procedure that, given the service's
    parameters, returns a list of object to extend the service of that type.
    
    Every service type has at least one service extension.  The only
    exception is the @dfn{boot service type}, which is the ultimate service.
    @end enumerate
    
    In this example, @var{guix-service-type} extends three services:
    
    @table @var
    @item dmd-root-service-type
    The @var{guix-dmd-service} procedure defines how the dmd service is
    extended.  Namely, it returns a @code{<dmd-service>} object that defines
    how @command{guix-daemon} is started and stopped (@pxref{dmd Services}).
    
    @item account-service-type
    This extension for this service is computed by @var{guix-accounts},
    which returns a list of @code{user-group} and @code{user-account}
    objects representing the build user accounts (@pxref{Invoking
    guix-daemon}).
    
    @item activation-service-type
    Here @var{guix-activation} is a procedure that returns a gexp, which is
    a code snippet to run at ``activation time''---e.g., when the service is
    booted.
    @end table
    
    A service of this type is instantiated like this:
    
    @example
    (service guix-service-type
             (guix-configuration
               (build-accounts 5)
               (use-substitutes? #f)))
    @end example
    
    The second argument to the @code{service} form is a value representing
    the parameters of this specific service instance.
    @xref{guix-configuration-type, @code{guix-configuration}}, for
    information about the @code{guix-configuration} data type.
    
    @var{guix-service-type} is quite simple because it extends other
    services but is not extensible itself.
    
    @c @subsubsubsection Extensible Service Types
    
    The service type for an @emph{extensible} service looks like this:
    
    @example
    (define udev-service-type
      (service-type (name 'udev)
                    (extensions
                     (list (service-extension dmd-root-service-type
                                              udev-dmd-service)))
    
                    (compose concatenate)       ;concatenate the list of rules
                    (extend (lambda (config rules)
                              (match config
                                (($ <udev-configuration> udev initial-rules)
                                 (udev-configuration
                                  (udev udev)   ;the udev package to use
                                  (rules (append initial-rules rules)))))))))
    @end example
    
    This is the service type for the
    @uref{https://wiki.gentoo.org/wiki/Project:Eudev, eudev device
    management daemon}.  Compared to the previous example, in addition to an
    extension of @var{dmd-root-service-type}, we see two new fields:
    
    @table @code
    @item compose
    This is the procedure to @dfn{compose} the list of extensions to
    services of this type.
    
    Services can extend the udev service by passing it lists of rules; we
    compose those extensions simply by concatenating them.
    
    @item extend
    This procedure defines how the service's value is @dfn{extended} with
    the composition of the extensions.
    
    Udev extensions are composed into a list of rules, but the udev service
    value is itself a @code{<udev-configuration>} record.  So here, we
    extend that record by appending the list of rules is contains to the
    list of contributed rules.
    @end table
    
    There can be only one instance of an extensible service type such as
    @var{udev-service-type}.  If there were more, the
    @code{service-extension} specifications would be ambiguous.
    
    Still here?  The next section provides a reference of the programming
    interface for services.
    
    @node Service Reference
    @subsubsection Service Reference
    
    We have seen an overview of service types (@pxref{Service Types and
    Services}).  This section provides a reference on how to manipulate
    services and service types.  This interface is provided by the
    @code{(gnu services)} module.
    
    @deffn {Scheme Procedure} service @var{type} @var{value}
    Return a new service of @var{type}, a @code{<service-type>} object (see
    below.)  @var{value} can be any object; it represents the parameters of
    this particular service instance.
    @end deffn
    
    @deffn {Scheme Procedure} service? @var{obj}
    Return true if @var{obj} is a service.
    @end deffn
    
    @deffn {Scheme Procedure} service-kind @var{service}
    Return the type of @var{service}---i.e., a @code{<service-type>} object.
    @end deffn
    
    @deffn {Scheme Procedure} service-parameters @var{service}
    Return the value associated with @var{service}.  It represents its
    parameters.
    @end deffn
    
    Here is an example of how a service is created and manipulated:
    
    @example
    (define s
      (service nginx-service-type
               (nginx-configuration
                (nginx nginx)
                (log-directory log-directory)
                (run-directory run-directory)
                (file config-file))))
    
    (service? s)
    @result{} #t
    
    (eq? (service-kind s) nginx-service-type)
    @result{} #t
    @end example
    
    @deftp {Data Type} service-type
    @cindex service type
    This is the representation of a @dfn{service type} (@pxref{Service Types
    and Services}).
    
    @table @asis
    @item @code{name}
    This is a symbol, used only to simplify inspection and debugging.
    
    @item @code{extensions}
    A non-empty list of @code{<service-extension>} objects (see below.)
    
    @item @code{compose} (default: @code{#f})
    If this is @code{#f}, then the service type denotes services that cannot
    be extended---i.e., services that do not receive ``values'' from other
    services.
    
    Otherwise, it must be a one-argument procedure.  The procedure is called
    by @code{fold-services} and is passed a list of values collected from
    extensions.  It must return a value that is a valid parameter value for
    the service instance.
    
    @item @code{extend} (default: @code{#f})
    If this is @code{#f}, services of this type cannot be extended.
    
    Otherwise, it must be a two-argument procedure: @code{fold-services}
    calls it, passing it the service's initial value as the first argument
    and the result of applying @code{compose} to the extension values as the
    second argument.
    @end table
    
    @xref{Service Types and Services}, for examples.
    @end deftp
    
    @deffn {Scheme Procedure} service-extension @var{target-type} @
                                  @var{compute}
    Return a new extension for services of type @var{target-type}.
    @var{compute} must be a one-argument procedure: @code{fold-services}
    calls it, passing it the value associated with the service that provides
    the extension; it must return a valid value for the target service.
    @end deffn
    
    @deffn {Scheme Procedure} service-extension? @var{obj}
    Return true if @var{obj} is a service extension.
    @end deffn
    
    At the core of the service abstraction lies the @code{fold-services}
    procedure, which is responsible for ``compiling'' a list of services
    down to a single boot script.  In essence, it propagates service
    extensions down the service graph, updating each node parameters on the
    way, until it reaches the root node.
    
    @deffn {Scheme Procedure} fold-services @var{services} @
                                [#:target-type @var{boot-service-type}]
    Fold @var{services} by propagating their extensions down to the root of
    type @var{target-type}; return the root service adjusted accordingly.
    @end deffn
    
    Lastly, the @code{(gnu services)} module also defines several essential
    service types, some of which are listed below.
    
    @defvr {Scheme Variable} boot-service-type
    The type of the ``boot service'', which is the root of the service
    graph.
    @end defvr
    
    @defvr {Scheme Variable} etc-service-type
    The type of the @file{/etc} service.  This service can be extended by
    passing it name/file tuples such as:
    
    @example
    (list `("issue" ,(plain-file "issue" "Welcome!\n")))
    @end example
    
    In this example, the effect would be to add an @file{/etc/issue} file
    pointing to the given file.
    @end defvr
    
    @defvr {Scheme Variable} setuid-program-service-type
    Type for the ``setuid-program service''.  This service collects lists of
    executable file names, passed as gexps, and adds them to the set of
    setuid-root programs on the system (@pxref{Setuid Programs}).
    @end defvr
    
    
    @node dmd Services
    @subsubsection dmd Services
    
    @cindex PID 1
    @cindex init system
    The @code{(gnu services dmd)} provides a way to define services managed
    by GNU@tie{}dmd, which is GuixSD initialization system---the first
    process that is started when the system boots, aka. PID@tie{}1
    
    (@pxref{Introduction,,, dmd, GNU dmd Manual}).
    
    Services in dmd can depend on each other.  For instance, the SSH daemon
    may need to be started after the syslog daemon has been started, which
    in turn can only happen once all the file systems have been mounted.
    The simple operating system defined earlier (@pxref{Using the
    Configuration System}) results in a service graph like this:
    
    @image{images/dmd-graph,,5in,Typical dmd service graph.}
    
    You can actually generate such a graph for any operating system
    definition using the @command{guix system dmd-graph} command
    (@pxref{system-dmd-graph, @command{guix system dmd-graph}}).
    
    The @var{%dmd-root-service} is a service object representing PID@tie{}1,
    of type @var{dmd-root-service-type}; it can be extended by passing it
    lists of @code{<dmd-service>} objects.
    
    
    @deftp {Data Type} dmd-service
    The data type representing a service managed by dmd.
    
    @table @asis
    @item @code{provision}
    This is a list of symbols denoting what the service provides.
    
    These are the names that may be passed to @command{deco start},
    @command{deco status}, and similar commands (@pxref{Invoking deco,,,
    dmd, GNU dmd Manual}).  @xref{Slots of services, the @code{provides}
    slot,, dmd, GNU dmd Manual}, for details.
    
    @item @code{requirements} (default: @code{'()})
    List of symbols denoting the dmd services this one depends on.
    
    @item @code{respawn?} (default: @code{#t})
    Whether to restart the service when it stops, for instance when the
    underlying process dies.
    
    @item @code{start}
    @itemx @code{stop} (default: @code{#~(const #f)})
    
    The @code{start} and @code{stop} fields refer to dmd's facilities to
    start and stop processes (@pxref{Service De- and Constructors,,, dmd,
    
    GNU dmd Manual}).  They are given as G-expressions that get expanded in
    the dmd configuration file (@pxref{G-Expressions}).
    
    @item @code{documentation}
    A documentation string, as shown when running:
    
    @example
    deco doc @var{service-name}
    @end example
    
    where @var{service-name} is one of the symbols in @var{provision}
    (@pxref{Invoking deco,,, dmd, GNU dmd Manual}).
    @end table
    @end deftp
    
    @defvr {Scheme Variable} dmd-root-service-type
    The service type for the dmd ``root service''---i.e., PID@tie{}1.
    
    This is the service type that extensions target when they want to create
    dmd services (@pxref{Service Types and Services}, for an example).  Each
    extension must pass a list of @code{<dmd-service>}.
    @end defvr
    
    @defvr {Scheme Variable} %dmd-root-service
    This service represents PID@tie{}1.
    @end defvr
    
    @node Installing Debugging Files
    @section Installing Debugging Files
    
    @cindex debugging files
    Program binaries, as produced by the GCC compilers for instance, are
    typically written in the ELF format, with a section containing
    @dfn{debugging information}.  Debugging information is what allows the
    debugger, GDB, to map binary code to source code; it is required to
    debug a compiled program in good conditions.
    
    The problem with debugging information is that is takes up a fair amount
    of disk space.  For example, debugging information for the GNU C Library
    weighs in at more than 60 MiB.  Thus, as a user, keeping all the
    debugging info of all the installed programs is usually not an option.
    Yet, space savings should not come at the cost of an impediment to
    debugging---especially in the GNU system, which should make it easier
    for users to exert their computing freedom (@pxref{GNU Distribution}).
    
    Thankfully, the GNU Binary Utilities (Binutils) and GDB provide a
    mechanism that allows users to get the best of both worlds: debugging
    information can be stripped from the binaries and stored in separate
    files.  GDB is then able to load debugging information from those files,
    when they are available (@pxref{Separate Debug Files,,, gdb, Debugging
    with GDB}).
    
    The GNU distribution takes advantage of this by storing debugging
    information in the @code{lib/debug} sub-directory of a separate package
    output unimaginatively called @code{debug} (@pxref{Packages with
    Multiple Outputs}).  Users can choose to install the @code{debug} output
    of a package when they need it.  For instance, the following command
    installs the debugging information for the GNU C Library and for GNU
    Guile:
    
    guix package -i glibc:debug guile:debug
    
    GDB must then be told to look for debug files in the user's profile, by
    setting the @code{debug-file-directory} variable (consider setting it
    from the @file{~/.gdbinit} file, @pxref{Startup,,, gdb, Debugging with
    GDB}):
    
    @example
    (gdb) set debug-file-directory ~/.guix-profile/lib/debug
    @end example
    
    From there on, GDB will pick up debugging information from the
    @code{.debug} files under @file{~/.guix-profile/lib/debug}.
    
    In addition, you will most likely want GDB to be able to show the source
    code being debugged.  To do that, you will have to unpack the source
    code of the package of interest (obtained with @code{guix build
    --source}, @pxref{Invoking guix build}), and to point GDB to that source
    directory using the @code{directory} command (@pxref{Source Path,
    @code{directory},, gdb, Debugging with GDB}).
    
    @c XXX: keep me up-to-date
    The @code{debug} output mechanism in Guix is implemented by the
    @code{gnu-build-system} (@pxref{Build Systems}).  Currently, it is
    opt-in---debugging information is available only for those packages
    whose definition explicitly declares a @code{debug} output.  This may be
    changed to opt-out in the future, if our build farm servers can handle
    the load.  To check whether a package has a @code{debug} output, use
    @command{guix package --list-available} (@pxref{Invoking guix package}).
    
    @node Security Updates
    @section Security Updates
    
    
    @quotation Note
    As of version @value{VERSION}, the feature described in this section is
    experimental.
    @end quotation
    
    
    @cindex security updates
    Occasionally, important security vulnerabilities are discovered in core
    software packages and must be patched.  Guix follows a functional
    package management discipline (@pxref{Introduction}), which implies
    that, when a package is changed, @emph{every package that depends on it}
    must be rebuilt.  This can significantly slow down the deployment of
    fixes in core packages such as libc or Bash, since basically the whole
    distribution would need to be rebuilt.  Using pre-built binaries helps
    (@pxref{Substitutes}), but deployment may still take more time than
    desired.
    
    @cindex grafts
    To address that, Guix implements @dfn{grafts}, a mechanism that allows
    for fast deployment of critical updates without the costs associated
    with a whole-distribution rebuild.  The idea is to rebuild only the
    package that needs to be patched, and then to ``graft'' it onto packages
    explicitly installed by the user and that were previously referring to
    the original package.  The cost of grafting is typically very low, and
    order of magnitudes lower than a full rebuild of the dependency chain.
    
    @cindex replacements of packages, for grafts
    For instance, suppose a security update needs to be applied to Bash.
    Guix developers will provide a package definition for the ``fixed''
    Bash, say @var{bash-fixed}, in the usual way (@pxref{Defining
    Packages}).  Then, the original package definition is augmented with a
    @code{replacement} field pointing to the package containing the bug fix:
    
    @example
    (define bash
      (package
        (name "bash")
        ;; @dots{}
        (replacement bash-fixed)))
    @end example
    
    From there on, any package depending directly or indirectly on Bash that
    is installed will automatically be ``rewritten'' to refer to
    @var{bash-fixed} instead of @var{bash}.  This grafting process takes
    time proportional to the size of the package, but expect less than a
    minute for an ``average'' package on a recent machine.
    
    Currently, the graft and the package it replaces (@var{bash-fixed} and
    @var{bash} in the example above) must have the exact same @code{name}
    and @code{version} fields.  This restriction mostly comes from the fact
    that grafting works by patching files, including binary files, directly.
    Other restrictions may apply: for instance, when adding a graft to a
    package providing a shared library, the original shared library and its
    replacement must have the same @code{SONAME} and be binary-compatible.
    
    
    
    @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 package -i 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.}.  These package definitions
    
    will not be visible by default.  Thus, users can invoke commands such as
    @command{guix package} and @command{guix build} have to be used with the
    
    @code{-e} option so that they know where to find the package.  Better
    yet, they can use the
    
    @code{-L} option of these commands to make those modules visible
    
    (@pxref{Invoking guix build, @code{--load-path}}), or define the
    @code{GUIX_PACKAGE_PATH} environment variable.  This environment
    variable makes it easy to extend or customize the distribution and is
    honored by all the user interfaces.
    
    @defvr {Environment Variable} GUIX_PACKAGE_PATH
    This is a colon-separated list of directories to search for package
    modules.  Directories listed in this variable take precedence over the
    distribution's own modules.
    @end defvr
    
    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 Packaging Guidelines
    @section Packaging Guidelines
    
    The GNU distribution is nascent and may well lack some of your favorite
    packages.  This section describes how you can help make the distribution
    grow.  @xref{Contributing}, for additional information on how you can
    help.
    
    Free software packages are usually distributed in the form of
    @dfn{source code tarballs}---typically @file{tar.gz} files that contain
    all the source files.  Adding a package to the distribution means
    essentially two things: adding a @dfn{recipe} that describes how to
    build the package, including a list of other packages required to build
    it, and adding @dfn{package meta-data} along with that recipe, such as a
    description and licensing information.
    
    In Guix all this information is embodied in @dfn{package definitions}.
    Package definitions provide a high-level view of the package.  They are
    written using the syntax of the Scheme programming language; in fact,
    for each package we define a variable bound to the package definition,
    and export that variable from a module (@pxref{Package Modules}).
    However, in-depth Scheme knowledge is @emph{not} a prerequisite for
    creating packages.  For more information on package definitions,
    
    @pxref{Defining Packages}.
    
    Once a package definition is in place, stored in a file in the Guix
    source tree, it can be tested using the @command{guix build} command
    (@pxref{Invoking guix build}).  For example, assuming the new package is
    
    called @code{gnew}, you may run this command from the Guix build tree
    (@pxref{Running Guix Before It Is Installed}):
    
    ./pre-inst-env guix build gnew --keep-failed
    
    Using @code{--keep-failed} makes it easier to debug build failures since
    it provides access to the failed build tree.  Another useful
    command-line option when debugging is @code{--log-file}, to access the
    build log.
    
    If the package is unknown to the @command{guix} command, it may be that
    the source file contains a syntax error, or lacks a @code{define-public}
    clause to export the package variable.  To figure it out, you may load
    the module from Guile to get more information about the actual error:
    
    @example
    ./pre-inst-env guile -c '(use-modules (gnu packages gnew))'
    @end example
    
    Once your package builds correctly, please send us a patch
    (@pxref{Contributing}).  Well, if you need help, we will be happy to
    help you too.  Once the patch is committed in the Guix repository, the
    new package automatically gets built on the supported platforms by
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    @url{http://hydra.gnu.org/jobset/gnu/master, our continuous integration
    
    @cindex substituter
    Users can obtain the new package definition simply by running
    @command{guix pull} (@pxref{Invoking guix pull}).  When
    @code{hydra.gnu.org} is done building the package, installing the
    package automatically downloads binaries from there
    (@pxref{Substitutes}).  The only place where human intervention is
    needed is to review and apply the patch.
    
    * Software Freedom::            What may go into the distribution.
    * Package Naming::              What's in a name?
    * Version Numbers::             When the name is not enough.
    
    * Synopses and Descriptions::   Helping users find the right package.
    
    * Python Modules::              Taming the snake.
    * Perl Modules::                Little pearls.
    * Fonts::                       Fond of fonts.
    
    @node Software Freedom
    @subsection Software Freedom
    
    @c Adapted from http://www.gnu.org/philosophy/philosophy.html.
    
    The GNU operating system has been developed so that users can have
    freedom in their computing.  GNU is @dfn{free software}, meaning that
    users have the @url{http://www.gnu.org/philosophy/free-sw.html,four
    essential freedoms}: to run the program, to study and change the program
    in source code form, to redistribute exact copies, and to distribute
    modified versions.  Packages found in the GNU distribution provide only
    software that conveys these four freedoms.
    
    In addition, the GNU distribution follow the
    @url{http://www.gnu.org/distros/free-system-distribution-guidelines.html,free
    software distribution guidelines}.  Among other things, these guidelines
    reject non-free firmware, recommendations of non-free software, and
    discuss ways to deal with trademarks and patents.
    
    Some packages contain a small and optional subset that violates the
    above guidelines, for instance because this subset is itself non-free
    code.  When that happens, the offending items are removed with
    appropriate patches or code snippets in the package definition's
    @code{origin} form (@pxref{Defining Packages}).  That way, @code{guix
    build --source} returns the ``freed'' source rather than the unmodified
    upstream source.
    
    @node Package Naming
    @subsection Package Naming
    
    A package has actually two names associated with it:
    First, there is the name of the @emph{Scheme variable}, the one following
    @code{define-public}.  By this name, the package can be made known in the
    Scheme code, for instance as input to another package.  Second, there is
    the string in the @code{name} field of a package definition.  This name
    is used by package management commands such as
    @command{guix package} and @command{guix build}.
    
    Both are usually the same and correspond to the lowercase conversion of
    the project name chosen upstream, with underscores replaced with
    hyphens.  For instance, GNUnet is available as @code{gnunet}, and
    SDL_net as @code{sdl-net}.
    
    We do not add @code{lib} prefixes for library packages, unless these are
    
    already part of the official project name.  But @pxref{Python
    
    Modules} and @ref{Perl Modules} for special rules concerning modules for
    the Python and Perl languages.
    
    Font package names are handled differently, @pxref{Fonts}.
    
    @node Version Numbers
    @subsection Version Numbers
    
    We usually package only the latest version of a given free software
    project.  But sometimes, for instance for incompatible library versions,
    two (or more) versions of the same package are needed.  These require
    different Scheme variable names.  We use the name as defined
    in @ref{Package Naming}
    for the most recent version; previous versions use the same name, suffixed
    by @code{-} and the smallest prefix of the version number that may
    distinguish the two versions.
    
    The name inside the package definition is the same for all versions of a
    package and does not contain any version number.
    
    For instance, the versions 2.24.20 and 3.9.12 of GTK+ may be packaged as follows:
    
    @example
    (define-public gtk+
      (package
    
        (name "gtk+")
        (version "3.9.12")
        ...))
    
    (define-public gtk+-2
      (package
    
        (name "gtk+")
        (version "2.24.20")
        ...))
    
    @end example
    If we also wanted GTK+ 3.8.2, this would be packaged as
    @example
    (define-public gtk+-3.8
      (package
    
        (name "gtk+")
        (version "3.8.2")
        ...))
    
    @node Synopses and Descriptions
    @subsection Synopses and Descriptions
    
    As we have seen before, each package in GNU@tie{}Guix includes a
    synopsis and a description (@pxref{Defining Packages}).  Synopses and
    descriptions are important: They are what @command{guix package
    --search} searches, and a crucial piece of information to help users
    determine whether a given package suits their needs.  Consequently,
    packagers should pay attention to what goes into them.
    
    Synopses must start with a capital letter and must not end with a
    period.  They must not start with ``a'' or ``the'', which usually does
    not bring anything; for instance, prefer ``File-frobbing tool'' over ``A
    tool that frobs files''.  The synopsis should say what the package
    is---e.g., ``Core GNU utilities (file, text, shell)''---or what it is
    used for---e.g., the synopsis for GNU@tie{}grep is ``Print lines
    matching a pattern''.
    
    Keep in mind that the synopsis must be meaningful for a very wide
    audience.  For example, ``Manipulate alignments in the SAM format''
    might make sense for a seasoned bioinformatics researcher, but might be
    fairly unhelpful or even misleading to a non-specialized audience.  It
    is a good idea to come up with a synopsis that gives an idea of the
    application domain of the package.  In this example, this might give
    something like ``Manipulate nucleotide sequence alignments'', which
    hopefully gives the user a better idea of whether this is what they are
    looking for.
    
    @cindex Texinfo markup, in package descriptions
    Descriptions should take between five and ten lines.  Use full
    sentences, and avoid using acronyms without first introducing them.
    Descriptions can include Texinfo markup, which is useful to introduce
    ornaments such as @code{@@code} or @code{@@dfn}, bullet lists, or
    
    hyperlinks (@pxref{Overview,,, texinfo, GNU Texinfo}).  However you
    should be careful when using some characters for example @samp{@@} and
    curly braces which are the basic special characters in Texinfo
    (@pxref{Special Characters,,, texinfo, GNU Texinfo}).  User interfaces
    such as @command{guix package --show} take care of rendering it
    appropriately.
    
    
    Synopses and descriptions are translated by volunteers
    @uref{http://translationproject.org/domain/guix-packages.html, at the
    Translation Project} so that as many users as possible can read them in
    their native language.  User interfaces search them and display them in
    the language specified by the current locale.
    
    Translation is a lot of work so, as a packager, please pay even more
    attention to your synopses and descriptions as every change may entail
    
    additional work for translators.  In order to help them, it is possible
    
    Mark H Weaver's avatar
    Mark H Weaver committed
    to make recommendations or instructions visible to them by inserting
    
    special comments like this (@pxref{xgettext Invocation,,, gettext, GNU
    Gettext}):
    
    @example
    ;; TRANSLATORS: "X11 resize-and-rotate" should not be translated.
    (description "ARandR is designed to provide a simple visual front end
    for the X11 resize-and-rotate (RandR) extension. @dots{}")
    @end example
    
    @node Python Modules
    @subsection Python Modules
    
    We currently package Python 2 and Python 3, under the Scheme variable names
    @code{python-2} and @code{python} as explained in @ref{Version Numbers}.
    To avoid confusion and naming clashes with other programming languages, it
    seems desirable that the name of a package for a Python module contains
    the word @code{python}.
    
    Some modules are compatible with only one version of Python, others with both.
    If the package Foo compiles only with Python 3, we name it
    @code{python-foo}; if it compiles only with Python 2, we name it
    @code{python2-foo}. If it is compatible with both versions, we create two
    packages with the corresponding names.
    
    If a project already contains the word @code{python}, we drop this;
    for instance, the module python-dateutil is packaged under the names
    @code{python-dateutil} and @code{python2-dateutil}.
    
    @node Perl Modules
    @subsection Perl Modules
    
    Perl programs standing for themselves are named as any other package,
    using the lowercase upstream name.
    For Perl packages containing a single class, we use the lowercase class name,
    replace all occurrences of @code{::} by dashes and prepend the prefix
    @code{perl-}.
    So the class @code{XML::Parser} becomes @code{perl-xml-parser}.
    Modules containing several classes keep their lowercase upstream name and
    are also prepended by @code{perl-}.  Such modules tend to have the word
    @code{perl} somewhere in their name, which gets dropped in favor of the
    prefix.  For instance, @code{libwww-perl} becomes @code{perl-libwww}.