Skip to content
Snippets Groups Projects
guix.texi 964 KiB
Newer Older
  • Learn to ignore specific revisions
  • @code{(guix inferior)} module allows you to create inferiors and to
    communicate with them.  It also provides a high-level interface to browse and
    manipulate the packages that an inferior provides---@dfn{inferior packages}.
    
    When combined with channels (@pxref{Channels}), inferiors provide a simple way
    to interact with a separate revision of Guix.  For example, let's assume you
    want to install in your profile the current @code{guile} package, along with
    the @code{guile-json} as it existed in an older revision of Guix---perhaps
    because the newer @code{guile-json} has an incompatible API and you want to
    run your code against the old API@.  To do that, you could write a manifest for
    use by @code{guix package --manifest} (@pxref{Invoking guix package}); in that
    manifest, you would create an inferior for that old Guix revision you care
    about, and you would look up the @code{guile-json} package in the inferior:
    
    @lisp
    (use-modules (guix inferior) (guix channels)
                 (srfi srfi-1))   ;for 'first'
    
    (define channels
      ;; This is the old revision from which we want to
      ;; extract guile-json.
      (list (channel
             (name 'guix)
             (url "https://git.savannah.gnu.org/git/guix.git")
             (commit
              "65956ad3526ba09e1f7a40722c96c6ef7c0936fe"))))
    
    (define inferior
      ;; An inferior representing the above revision.
      (inferior-for-channels channels))
    
    ;; Now create a manifest with the current "guile" package
    ;; and the old "guile-json" package.
    (packages->manifest
     (list (first (lookup-inferior-packages inferior "guile-json"))
           (specification->package "guile")))
    @end lisp
    
    On its first run, @command{guix package --manifest} might have to build the
    channel you specified before it can create the inferior; subsequent runs will
    be much faster because the Guix revision will be cached.
    
    The @code{(guix inferior)} module provides the following procedures to open an
    inferior:
    
    @deffn {Scheme Procedure} inferior-for-channels @var{channels} @
       [#:cache-directory] [#:ttl]
    Return an inferior for @var{channels}, a list of channels.  Use the cache at
    @var{cache-directory}, where entries can be reclaimed after @var{ttl} seconds.
    This procedure opens a new connection to the build daemon.
    
    As a side effect, this procedure may build or substitute binaries for
    @var{channels}, which can take time.
    @end deffn
    
    @deffn {Scheme Procedure} open-inferior @var{directory} @
      [#:command "bin/guix"]
    Open the inferior Guix in @var{directory}, running
    @code{@var{directory}/@var{command} repl} or equivalent.  Return @code{#f} if
    the inferior could not be launched.
    @end deffn
    
    @cindex inferior packages
    The procedures listed below allow you to obtain and manipulate inferior
    packages.
    
    @deffn {Scheme Procedure} inferior-packages @var{inferior}
    Return the list of packages known to @var{inferior}.
    @end deffn
    
    @deffn {Scheme Procedure} lookup-inferior-packages @var{inferior} @var{name} @
       [@var{version}]
    Return the sorted list of inferior packages matching @var{name} in
    @var{inferior}, with highest version numbers first.  If @var{version} is true,
    return only packages with a version number prefixed by @var{version}.
    @end deffn
    
    @deffn {Scheme Procedure} inferior-package? @var{obj}
    Return true if @var{obj} is an inferior package.
    @end deffn
    
    @deffn {Scheme Procedure} inferior-package-name @var{package}
    @deffnx {Scheme Procedure} inferior-package-version @var{package}
    @deffnx {Scheme Procedure} inferior-package-synopsis @var{package}
    @deffnx {Scheme Procedure} inferior-package-description @var{package}
    @deffnx {Scheme Procedure} inferior-package-home-page @var{package}
    @deffnx {Scheme Procedure} inferior-package-location @var{package}
    @deffnx {Scheme Procedure} inferior-package-inputs @var{package}
    @deffnx {Scheme Procedure} inferior-package-native-inputs @var{package}
    @deffnx {Scheme Procedure} inferior-package-propagated-inputs @var{package}
    @deffnx {Scheme Procedure} inferior-package-transitive-propagated-inputs @var{package}
    @deffnx {Scheme Procedure} inferior-package-native-search-paths @var{package}
    @deffnx {Scheme Procedure} inferior-package-transitive-native-search-paths @var{package}
    @deffnx {Scheme Procedure} inferior-package-search-paths @var{package}
    These procedures are the counterpart of package record accessors
    (@pxref{package Reference}).  Most of them work by querying the inferior
    @var{package} comes from, so the inferior must still be live when you call
    these procedures.
    @end deffn
    
    Inferior packages can be used transparently like any other package or
    file-like object in G-expressions (@pxref{G-Expressions}).  They are also
    transparently handled by the @code{packages->manifest} procedure, which is
    commonly use in manifests (@pxref{Invoking guix package, the
    @option{--manifest} option of @command{guix package}}).  Thus you can insert
    an inferior package pretty much anywhere you would insert a regular package:
    in manifests, in the @code{packages} field of your @code{operating-system}
    declaration, and so on.
    
    @node Invoking guix describe
    @section Invoking @command{guix describe}
    
    @cindex reproducibility
    @cindex replicating Guix
    Often you may want to answer questions like: ``Which revision of Guix am I
    using?'' or ``Which channels am I using?''  This is useful information in many
    situations: if you want to @emph{replicate} an environment on a different
    machine or user account, if you want to report a bug or to determine what
    change in the channels you are using caused it, or if you want to record your
    system state for reproducibility purposes.  The @command{guix describe}
    command answers these questions.
    
    When run from a @command{guix pull}ed @command{guix}, @command{guix describe}
    displays the channel(s) that it was built from, including their repository URL
    and commit IDs (@pxref{Channels}):
    
    @example
    $ guix describe
    Generation 10	Sep 03 2018 17:32:44	(current)
      guix e0fa68c
        repository URL: https://git.savannah.gnu.org/git/guix.git
        branch: master
        commit: e0fa68c7718fffd33d81af415279d6ddb518f727
    @end example
    
    If you're familiar with the Git version control system, this is similar in
    spirit to @command{git describe}; the output is also similar to that of
    @command{guix pull --list-generations}, but limited to the current generation
    (@pxref{Invoking guix pull, the @option{--list-generations} option}).  Because
    the Git commit ID shown above unambiguously refers to a snapshot of Guix, this
    information is all it takes to describe the revision of Guix you're using, and
    also to replicate it.
    
    To make it easier to replicate Guix, @command{guix describe} can also be asked
    to return a list of channels instead of the human-readable description above:
    
    @example
    $ guix describe -f channels
    (list (channel
            (name 'guix)
            (url "https://git.savannah.gnu.org/git/guix.git")
            (commit
              "e0fa68c7718fffd33d81af415279d6ddb518f727")))
    @end example
    
    @noindent
    You can save this to a file and feed it to @command{guix pull -C} on some
    other machine or at a later point in time, which will instantiate @emph{this
    exact Guix revision} (@pxref{Invoking guix pull, the @option{-C} option}).
    From there on, since you're able to deploy the same revision of Guix, you can
    just as well @emph{replicate a complete software environment}.  We humbly
    think that this is @emph{awesome}, and we hope you'll like it too!
    
    The details of the options supported by @command{guix describe} are as
    follows:
    
    @table @code
    @item --format=@var{format}
    @itemx -f @var{format}
    Produce output in the specified @var{format}, one of:
    
    @table @code
    @item human
    produce human-readable output;
    @item channels
    produce a list of channel specifications that can be passed to @command{guix
    pull -C} or installed as @file{~/.config/guix/channels.scm} (@pxref{Invoking
    guix pull});
    @item json
    @cindex JSON
    produce a list of channel specifications in JSON format;
    @item recutils
    produce a list of channel specifications in Recutils format.
    @end table
    
    @item --profile=@var{profile}
    @itemx -p @var{profile}
    Display information about @var{profile}.
    @end table
    
    @node Invoking guix archive
    @section Invoking @command{guix archive}
    
    @cindex @command{guix archive}
    @cindex archive
    The @command{guix archive} command allows users to @dfn{export} files
    from the store into a single archive, and to later @dfn{import} them on
    a machine that runs Guix.
    In particular, it allows store files to be transferred from one machine
    to the store on another machine.
    
    @quotation Note
    If you're looking for a way to produce archives in a format suitable for
    tools other than Guix, @pxref{Invoking guix pack}.
    @end quotation
    
    @cindex exporting store items
    To export store files as an archive to standard output, run:
    
    @example
    guix archive --export @var{options} @var{specifications}...
    @end example
    
    @var{specifications} may be either store file names or package
    specifications, as for @command{guix package} (@pxref{Invoking guix
    package}).  For instance, the following command creates an archive
    containing the @code{gui} output of the @code{git} package and the main
    output of @code{emacs}:
    
    @example
    guix archive --export git:gui /gnu/store/...-emacs-24.3 > great.nar
    @end example
    
    If the specified packages are not built yet, @command{guix archive}
    automatically builds them.  The build process may be controlled with the
    common build options (@pxref{Common Build Options}).
    
    To transfer the @code{emacs} package to a machine connected over SSH,
    one would run:
    
    @example
    guix archive --export -r emacs | ssh the-machine guix archive --import
    @end example
    
    @noindent
    Similarly, a complete user profile may be transferred from one machine
    to another like this:
    
    @example
    guix archive --export -r $(readlink -f ~/.guix-profile) | \
    
    Diego Nicola Barbato's avatar
    Diego Nicola Barbato committed
      ssh the-machine guix archive --import
    
    @noindent
    However, note that, in both examples, all of @code{emacs} and the
    profile as well as all of their dependencies are transferred (due to
    @code{-r}), regardless of what is already available in the store on the
    target machine.  The @code{--missing} option can help figure out which
    items are missing from the target store.  The @command{guix copy}
    command simplifies and optimizes this whole process, so this is probably
    what you should use in this case (@pxref{Invoking guix copy}).
    
    @cindex nar, archive format
    @cindex normalized archive (nar)
    Archives are stored in the ``normalized archive'' or ``nar'' format, which is
    comparable in spirit to `tar', but with differences
    that make it more appropriate for our purposes.  First, rather than
    recording all Unix metadata for each file, the nar format only mentions
    the file type (regular, directory, or symbolic link); Unix permissions
    and owner/group are dismissed.  Second, the order in which directory
    entries are stored always follows the order of file names according to
    the C locale collation order.  This makes archive production fully
    deterministic.
    
    When exporting, the daemon digitally signs the contents of the archive,
    and that digital signature is appended.  When importing, the daemon
    verifies the signature and rejects the import in case of an invalid
    signature or if the signing key is not authorized.
    @c FIXME: Add xref to daemon doc about signatures.
    
    @item --export
    Export the specified store files or packages (see below.)  Write the
    resulting archive to the standard output.
    
    Dependencies are @emph{not} included in the output, unless
    @code{--recursive} is passed.
    
    @item -r
    @itemx --recursive
    When combined with @code{--export}, this instructs @command{guix
    archive} to include dependencies of the given items in the archive.
    Thus, the resulting archive is self-contained: it contains the closure
    of the exported store items.
    
    @item --import
    Read an archive from the standard input, and import the files listed
    therein into the store.  Abort if the archive has an invalid digital
    signature, or if it is signed by a public key not among the authorized
    keys (see @code{--authorize} below.)
    
    @item --missing
    Read a list of store file names from the standard input, one per line,
    and write on the standard output the subset of these files missing from
    the store.
    
    @item --generate-key[=@var{parameters}]
    @cindex signing, archives
    Generate a new key pair for the daemon.  This is a prerequisite before
    archives can be exported with @code{--export}.  Note that this operation
    usually takes time, because it needs to gather enough entropy to
    generate the key pair.
    
    The generated key pair is typically stored under @file{/etc/guix}, in
    @file{signing-key.pub} (public key) and @file{signing-key.sec} (private
    key, which must be kept secret.)  When @var{parameters} is omitted,
    an ECDSA key using the Ed25519 curve is generated, or, for Libgcrypt
    versions before 1.6.0, it is a 4096-bit RSA key.
    Alternatively, @var{parameters} can specify
    @code{genkey} parameters suitable for Libgcrypt (@pxref{General
    public-key related Functions, @code{gcry_pk_genkey},, gcrypt, The
    Libgcrypt Reference Manual}).
    
    @item --authorize
    @cindex authorizing, archives
    Authorize imports signed by the public key passed on standard input.
    The public key must be in ``s-expression advanced format''---i.e., the
    same format as the @file{signing-key.pub} file.
    
    The list of authorized keys is kept in the human-editable file
    @file{/etc/guix/acl}.  The file contains
    
    Marius Bakke's avatar
    Marius Bakke committed
    @url{https://people.csail.mit.edu/rivest/Sexp.txt, ``advanced-format
    
    s-expressions''} and is structured as an access-control list in the
    
    Marius Bakke's avatar
    Marius Bakke committed
    @url{https://theworld.com/~cme/spki.txt, Simple Public-Key Infrastructure
    
    @item --extract=@var{directory}
    @itemx -x @var{directory}
    Read a single-item archive as served by substitute servers
    (@pxref{Substitutes}) and extract it to @var{directory}.  This is a
    low-level operation needed in only very narrow use cases; see below.
    
    For example, the following command extracts the substitute for Emacs
    served by @code{@value{SUBSTITUTE-SERVER}} to @file{/tmp/emacs}:
    
    @example
    $ wget -O - \
      https://@value{SUBSTITUTE-SERVER}/nar/@dots{}-emacs-24.5 \
      | bunzip2 | guix archive -x /tmp/emacs
    @end example
    
    Single-item archives are different from multiple-item archives produced
    by @command{guix archive --export}; they contain a single store item,
    and they do @emph{not} embed a signature.  Thus this operation does
    @emph{no} signature verification and its output should be considered
    unsafe.
    
    The primary purpose of this operation is to facilitate inspection of
    archive contents coming from possibly untrusted substitute servers.
    
    @c *********************************************************************
    
    @node Development
    @chapter Development
    
    @cindex software development
    If you are a software developer, Guix provides tools that you should find
    helpful---independently of the language you're developing in.  This is what
    this chapter is about.
    
    The @command{guix environment} command provides a convenient way to set up
    @dfn{development environments} containing all the dependencies and tools
    necessary to work on the software package of your choice.  The @command{guix
    pack} command allows you to create @dfn{application bundles} that can be
    easily distributed to users who do not run Guix.
    
    * Invoking guix environment::   Setting up development environments.
    * Invoking guix pack::          Creating software bundles.
    
    @node Invoking guix environment
    @section Invoking @command{guix environment}
    
    @cindex reproducible build environments
    @cindex development environments
    @cindex @command{guix environment}
    @cindex environment, package build environment
    The purpose of @command{guix environment} is to assist hackers in
    creating reproducible development environments without polluting their
    package profile.  The @command{guix environment} tool takes one or more
    packages, builds all of their inputs, and creates a shell
    environment to use them.
    
    The general syntax is:
    
    @example
    guix environment @var{options} @var{package}@dots{}
    @end example
    
    The following example spawns a new shell set up for the development of
    GNU@tie{}Guile:
    
    @example
    guix environment guile
    @end example
    
    If the needed dependencies are not built yet, @command{guix environment}
    automatically builds them.  The environment of the new shell is an augmented
    version of the environment that @command{guix environment} was run in.
    It contains the necessary search paths for building the given package
    added to the existing environment variables.  To create a ``pure''
    environment, in which the original environment variables have been unset,
    use the @code{--pure} option@footnote{Users sometimes wrongfully augment
    environment variables such as @code{PATH} in their @file{~/.bashrc}
    file.  As a consequence, when @code{guix environment} launches it, Bash
    may read @file{~/.bashrc}, thereby introducing ``impurities'' in these
    environment variables.  It is an error to define such environment
    variables in @file{.bashrc}; instead, they should be defined in
    @file{.bash_profile}, which is sourced only by log-in shells.
    @xref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}, for
    details on Bash start-up files.}.
    
    @vindex GUIX_ENVIRONMENT
    @command{guix environment} defines the @code{GUIX_ENVIRONMENT}
    variable in the shell it spawns; its value is the file name of the
    profile of this environment.  This allows users to, say, define a
    specific prompt for development environments in their @file{.bashrc}
    (@pxref{Bash Startup Files,,, bash, The GNU Bash Reference Manual}):
    
    @example
    if [ -n "$GUIX_ENVIRONMENT" ]
    then
        export PS1="\u@@\h \w [dev]\$ "
    fi
    @end example
    
    @noindent
    ...@: or to browse the profile:
    
    @example
    $ ls "$GUIX_ENVIRONMENT/bin"
    @end example
    
    Additionally, more than one package may be specified, in which case the
    union of the inputs for the given packages are used.  For example, the
    command below spawns a shell where all of the dependencies of both Guile
    and Emacs are available:
    
    guix environment guile emacs
    @end example
    
    Sometimes an interactive shell session is not desired.  An arbitrary
    command may be invoked by placing the @code{--} token to separate the
    command from the rest of the arguments:
    
    @example
    guix environment guile -- make -j4
    
    In other situations, it is more convenient to specify the list of
    packages needed in the environment.  For example, the following command
    runs @command{python} from an environment containing Python@tie{}2.7 and
    NumPy:
    
    @example
    guix environment --ad-hoc python2-numpy python-2.7 -- python
    @end example
    
    Furthermore, one might want the dependencies of a package and also some
    additional packages that are not build-time or runtime dependencies, but
    are useful when developing nonetheless.  Because of this, the
    @code{--ad-hoc} flag is positional.  Packages appearing before
    @code{--ad-hoc} are interpreted as packages whose dependencies will be
    added to the environment.  Packages appearing after are interpreted as
    packages that will be added to the environment directly.  For example,
    the following command creates a Guix development environment that
    additionally includes Git and strace:
    
    @example
    guix environment guix --ad-hoc git strace
    @end example
    
    Sometimes it is desirable to isolate the environment as much as
    possible, for maximal purity and reproducibility.  In particular, when
    using Guix on a host distro that is not Guix System, it is desirable to
    prevent access to @file{/usr/bin} and other system-wide resources from
    the development environment.  For example, the following command spawns
    a Guile REPL in a ``container'' where only the store and the current
    working directory are mounted:
    
    @example
    guix environment --ad-hoc --container guile -- guile
    @end example
    
    @quotation Note
    The @code{--container} option requires Linux-libre 3.19 or newer.
    @end quotation
    
    The available options are summarized below.
    
    @table @code
    @item --root=@var{file}
    @itemx -r @var{file}
    @cindex persistent environment
    @cindex garbage collector root, for environments
    Make @var{file} a symlink to the profile for this environment, and
    register it as a garbage collector root.
    
    This is useful if you want to protect your environment from garbage
    collection, to make it ``persistent''.
    
    When this option is omitted, the environment is protected from garbage
    collection only for the duration of the @command{guix environment}
    session.  This means that next time you recreate the same environment,
    you could have to rebuild or re-download packages.  @xref{Invoking guix
    gc}, for more on GC roots.
    
    @item --expression=@var{expr}
    @itemx -e @var{expr}
    Create an environment for the package or list of packages that
    @var{expr} evaluates to.
    
    For example, running:
    
    @example
    guix environment -e '(@@ (gnu packages maths) petsc-openmpi)'
    @end example
    
    starts a shell with the environment for this specific variant of the
    PETSc package.
    
    @example
    guix environment --ad-hoc -e '(@@ (gnu) %base-packages)'
    @end example
    
    starts a shell with all the base system packages available.
    
    The above commands only use the default output of the given packages.
    To select other outputs, two element tuples can be specified:
    
    @example
    guix environment --ad-hoc -e '(list (@@ (gnu packages bash) bash) "include")'
    @end example
    
    @item --load=@var{file}
    @itemx -l @var{file}
    Create an environment for the package or list of packages that the code
    within @var{file} evaluates to.
    
    As an example, @var{file} might contain a definition like this
    (@pxref{Defining Packages}):
    
    @example
    @verbatiminclude environment-gdb.scm
    @end example
    
    @item --manifest=@var{file}
    @itemx -m @var{file}
    Create an environment for the packages contained in the manifest object
    returned by the Scheme code in @var{file}.
    
    This is similar to the same-named option in @command{guix package}
    (@pxref{profile-manifest, @option{--manifest}}) and uses the same
    manifest files.
    
    @item --ad-hoc
    Include all specified packages in the resulting environment, as if an
    @i{ad hoc} package were defined with them as inputs.  This option is
    useful for quickly creating an environment without having to write a
    package expression to contain the desired inputs.
    
    For instance, the command:
    
    guix environment --ad-hoc guile guile-sdl -- guile
    
    runs @command{guile} in an environment where Guile and Guile-SDL are
    available.
    
    Note that this example implicitly asks for the default output of
    @code{guile} and @code{guile-sdl}, but it is possible to ask for a
    specific output---e.g., @code{glib:bin} asks for the @code{bin} output
    of @code{glib} (@pxref{Packages with Multiple Outputs}).
    
    This option may be composed with the default behavior of @command{guix
    environment}.  Packages appearing before @code{--ad-hoc} are interpreted
    as packages whose dependencies will be added to the environment, the
    default behavior.  Packages appearing after are interpreted as packages
    that will be added to the environment directly.
    
    @item --pure
    
    Unset existing environment variables when building the new environment, except
    
    those specified with @option{--preserve} (see below.)  This has the effect of
    
    creating an environment in which search paths only contain package inputs.
    
    
    @item --preserve=@var{regexp}
    @itemx -E @var{regexp}
    When used alongside @option{--pure}, preserve the environment variables
    
    matching @var{regexp}---in other words, put them on a ``white list'' of
    
    environment variables that must be preserved.  This option can be repeated
    several times.
    
    guix environment --pure --preserve=^SLURM --ad-hoc openmpi @dots{} \
    
      -- mpirun @dots{}
    @end example
    
    This example runs @command{mpirun} in a context where the only environment
    variables defined are @code{PATH}, environment variables whose name starts
    with @code{SLURM}, as well as the usual ``precious'' variables (@code{HOME},
    @code{USER}, etc.)
    
    @item --search-paths
    Display the environment variable definitions that make up the
    environment.
    
    @item --system=@var{system}
    @itemx -s @var{system}
    Attempt to build for @var{system}---e.g., @code{i686-linux}.
    
    @item --container
    @itemx -C
    @cindex container
    Run @var{command} within an isolated container.  The current working
    directory outside the container is mapped inside the container.
    Additionally, unless overridden with @code{--user}, a dummy home
    directory is created that matches the current user's home directory, and
    
    @file{/etc/passwd} is configured accordingly.
    
    The spawned process runs as the current user outside the container.  Inside
    the container, it has the same UID and GID as the current user, unless
    @option{--user} is passed (see below.)
    
    @item --network
    @itemx -N
    For containers, share the network namespace with the host system.
    Containers created without this flag only have access to the loopback
    device.
    
    @item --link-profile
    @itemx -P
    For containers, link the environment profile to
    @file{~/.guix-profile} within the container.  This is equivalent to
    running the command @command{ln -s $GUIX_ENVIRONMENT ~/.guix-profile}
    within the container.  Linking will fail and abort the environment if
    the directory already exists, which will certainly be the case if
    @command{guix environment} was invoked in the user's home directory.
    
    Certain packages are configured to look in
    @code{~/.guix-profile} for configuration files and data;@footnote{For
    example, the @code{fontconfig} package inspects
    @file{~/.guix-profile/share/fonts} for additional fonts.}
    @code{--link-profile} allows these programs to behave as expected within
    the environment.
    
    @item --user=@var{user}
    @itemx -u @var{user}
    For containers, use the username @var{user} in place of the current
    user.  The generated @file{/etc/passwd} entry within the container will
    
    contain the name @var{user}, the home directory will be
    @file{/home/@var{user}}, and no user GECOS data will be copied.  Furthermore,
    the UID and GID inside the container are 1000.  @var{user}
    
    need not exist on the system.
    
    Additionally, any shared or exposed path (see @code{--share} and
    @code{--expose} respectively) whose target is within the current user's
    home directory will be remapped relative to @file{/home/USER}; this
    includes the automatic mapping of the current working directory.
    
    # will expose paths as /home/foo/wd, /home/foo/test, and /home/foo/target
    cd $HOME/wd
    guix environment --container --user=foo \
         --expose=$HOME/test \
         --expose=/tmp/target=$HOME/target
    
    While this will limit the leaking of user identity through home paths
    and each of the user fields, this is only one useful component of a
    broader privacy/anonymity solution---not one in and of itself.
    
    @item --no-cwd
    For containers, the default behavior is to share the current working
    directory with the isolated container and immediately change to that
    directory within the container.  If this is undesirable, @code{--no-cwd}
    will cause the current working directory to @emph{not} be automatically
    shared and will change to the user's home directory within the container
    instead.  See also @code{--user}.
    
    
    @item --expose=@var{source}[=@var{target}]
    For containers, expose the file system @var{source} from the host system
    as the read-only file system @var{target} within the container.  If
    @var{target} is not specified, @var{source} is used as the target mount
    point in the container.
    
    The example below spawns a Guile REPL in a container in which the user's
    home directory is accessible read-only via the @file{/exchange}
    directory:
    
    @example
    guix environment --container --expose=$HOME=/exchange --ad-hoc guile -- guile
    @end example
    
    @item --share=@var{source}[=@var{target}]
    For containers, share the file system @var{source} from the host system
    as the writable file system @var{target} within the container.  If
    @var{target} is not specified, @var{source} is used as the target mount
    point in the container.
    
    The example below spawns a Guile REPL in a container in which the user's
    home directory is accessible for both reading and writing via the
    @file{/exchange} directory:
    
    @example
    guix environment --container --share=$HOME=/exchange --ad-hoc guile -- guile
    @end example
    @end table
    
    @command{guix environment}
    also supports all of the common build options that @command{guix
    build} supports (@pxref{Common Build Options}) as well as package
    transformation options (@pxref{Package Transformation Options}).
    
    @node Invoking guix pack
    @section Invoking @command{guix pack}
    
    Occasionally you want to pass software to people who are not (yet!)
    lucky enough to be using Guix.  You'd tell them to run @command{guix
    package -i @var{something}}, but that's not possible in this case.  This
    is where @command{guix pack} comes in.
    
    @quotation Note
    If you are looking for ways to exchange binaries among machines that
    already run Guix, @pxref{Invoking guix copy}, @ref{Invoking guix
    publish}, and @ref{Invoking guix archive}.
    @end quotation
    
    @cindex pack
    @cindex bundle
    @cindex application bundle
    @cindex software bundle
    The @command{guix pack} command creates a shrink-wrapped @dfn{pack} or
    @dfn{software bundle}: it creates a tarball or some other archive
    containing the binaries of the software you're interested in, and all
    its dependencies.  The resulting archive can be used on any machine that
    does not have Guix, and people can run the exact same binaries as those
    you have with Guix.  The pack itself is created in a bit-reproducible
    fashion, so anyone can verify that it really contains the build results
    that you pretend to be shipping.
    
    For example, to create a bundle containing Guile, Emacs, Geiser, and all
    their dependencies, you can run:
    
    @example
    $ guix pack guile emacs geiser
    @dots{}
    /gnu/store/@dots{}-pack.tar.gz
    @end example
    
    The result here is a tarball containing a @file{/gnu/store} directory
    with all the relevant packages.  The resulting tarball contains a
    @dfn{profile} with the three packages of interest; the profile is the
    same as would be created by @command{guix package -i}.  It is this
    mechanism that is used to create Guix's own standalone binary tarball
    (@pxref{Binary Installation}).
    
    Users of this pack would have to run
    @file{/gnu/store/@dots{}-profile/bin/guile} to run Guile, which you may
    find inconvenient.  To work around it, you can create, say, a
    @file{/opt/gnu/bin} symlink to the profile:
    
    @example
    guix pack -S /opt/gnu/bin=bin guile emacs geiser
    @end example
    
    @noindent
    That way, users can happily type @file{/opt/gnu/bin/guile} and enjoy.
    
    @cindex relocatable binaries, with @command{guix pack}
    What if the recipient of your pack does not have root privileges on
    their machine, and thus cannot unpack it in the root file system?  In
    that case, you will want to use the @code{--relocatable} option (see
    below).  This option produces @dfn{relocatable binaries}, meaning they
    they can be placed anywhere in the file system hierarchy: in the example
    above, users can unpack your tarball in their home directory and
    directly run @file{./opt/gnu/bin/guile}.
    
    @cindex Docker, build an image with guix pack
    Alternatively, you can produce a pack in the Docker image format using
    the following command:
    
    @example
    guix pack -f docker guile emacs geiser
    @end example
    
    @noindent
    The result is a tarball that can be passed to the @command{docker load}
    command.  See the
    @uref{https://docs.docker.com/engine/reference/commandline/load/, Docker
    documentation} for more information.
    
    @cindex Singularity, build an image with guix pack
    @cindex SquashFS, build an image with guix pack
    Yet another option is to produce a SquashFS image with the following
    command:
    
    guix pack -f squashfs guile emacs geiser
    
    @noindent
    The result is a SquashFS file system image that can either be mounted or
    directly be used as a file system container image with the
    
    Marius Bakke's avatar
    Marius Bakke committed
    @uref{https://singularity.lbl.gov, Singularity container execution
    
    environment}, using commands like @command{singularity shell} or
    @command{singularity exec}.
    
    Several command-line options allow you to customize your pack:
    
    @table @code
    @item --format=@var{format}
    @itemx -f @var{format}
    Produce a pack in the given @var{format}.
    
    The available formats are:
    
    @table @code
    @item tarball
    This is the default format.  It produces a tarball containing all the
    specified binaries and symlinks.
    
    @item docker
    This produces a tarball that follows the
    @uref{https://github.com/docker/docker/blob/master/image/spec/v1.2.md,
    Docker Image Specification}.
    
    @item squashfs
    This produces a SquashFS image containing all the specified binaries and
    symlinks, as well as empty mount points for virtual file systems like
    procfs.
    @end table
    
    @cindex relocatable binaries
    
    @item --relocatable
    @itemx -R
    Produce @dfn{relocatable binaries}---i.e., binaries that can be placed
    
    anywhere in the file system hierarchy and run from there.
    
    When this option is passed once, the resulting binaries require support for
    @dfn{user namespaces} in the kernel Linux; when passed
    @emph{twice}@footnote{Here's a trick to memorize it: @code{-RR}, which adds
    PRoot support, can be thought of as the abbreviation of ``Really
    Relocatable''.  Neat, isn't it?}, relocatable binaries fall to back to PRoot
    if user namespaces are unavailable, and essentially work anywhere---see below
    for the implications.
    
    For example, if you create a pack containing Bash with:
    
    guix pack -RR -S /mybin=bin bash
    
    @end example
    
    @noindent
    ...@: you can copy that pack to a machine that lacks Guix, and from your
    home directory as a normal user, run:
    
    @example
    tar xf pack.tar.gz
    ./mybin/sh
    @end example
    
    @noindent
    In that shell, if you type @code{ls /gnu/store}, you'll notice that
    @file{/gnu/store} shows up and contains all the dependencies of
    @code{bash}, even though the machine actually lacks @file{/gnu/store}
    altogether!  That is probably the simplest way to deploy Guix-built
    software on a non-Guix machine.
    
    @quotation Note
    By default, relocatable binaries rely on the @dfn{user namespace} feature of
    the kernel Linux, which allows unprivileged users to mount or change root.
    Old versions of Linux did not support it, and some GNU/Linux distributions
    turn it off.
    
    To produce relocatable binaries that work even in the absence of user
    namespaces, pass @option{--relocatable} or @option{-R} @emph{twice}.  In that
    case, binaries will try user namespace support and fall back to PRoot if user
    namespaces are not supported.
    
    The @uref{https://proot-me.github.io/, PRoot} program provides the necessary
    support for file system virtualization.  It achieves that by using the
    @code{ptrace} system call on the running program.  This approach has the
    advantage to work without requiring special kernel support, but it incurs
    run-time overhead every time a system call is made.
    @end quotation
    
    @cindex entry point, for Docker images
    @item --entry-point=@var{command}
    Use @var{command} as the @dfn{entry point} of the resulting pack, if the pack
    format supports it---currently @code{docker} and @code{squashfs} (Singularity)
    support it.  @var{command} must be relative to the profile contained in the
    pack.
    
    The entry point specifies the command that tools like @code{docker run} or
    @code{singularity run} automatically start by default.  For example, you can
    do:
    
    @example
    guix pack -f docker --entry-point=bin/guile guile
    @end example
    
    The resulting pack can easily be loaded and @code{docker run} with no extra
    arguments will spawn @code{bin/guile}:
    
    @example
    docker load -i pack.tar.gz
    docker run @var{image-id}
    @end example
    
    
    @item --expression=@var{expr}
    @itemx -e @var{expr}
    Consider the package @var{expr} evaluates to.
    
    This has the same purpose as the same-named option in @command{guix
    build} (@pxref{Additional Build Options, @code{--expression} in
    @command{guix build}}).
    
    @item --manifest=@var{file}
    @itemx -m @var{file}
    Use the packages contained in the manifest object returned by the Scheme
    code in @var{file}.
    
    This has a similar purpose as the same-named option in @command{guix
    package} (@pxref{profile-manifest, @option{--manifest}}) and uses the
    same manifest files.  It allows you to define a collection of packages
    once and use it both for creating profiles and for creating archives
    for use on machines that do not have Guix installed.  Note that you can
    specify @emph{either} a manifest file @emph{or} a list of packages,
    but not both.
    
    @item --system=@var{system}
    @itemx -s @var{system}
    Attempt to build for @var{system}---e.g., @code{i686-linux}---instead of
    the system type of the build host.
    
    @item --target=@var{triplet}
    @cindex cross-compilation
    Cross-build for @var{triplet}, which must be a valid GNU triplet, such
    as @code{"mips64el-linux-gnu"} (@pxref{Specifying target triplets, GNU
    configuration triplets,, autoconf, Autoconf}).
    
    @item --compression=@var{tool}
    @itemx -C @var{tool}
    Compress the resulting tarball using @var{tool}---one of @code{gzip},
    @code{bzip2}, @code{xz}, @code{lzip}, or @code{none} for no compression.
    
    @item --symlink=@var{spec}
    @itemx -S @var{spec}
    Add the symlinks specified by @var{spec} to the pack.  This option can
    appear several times.
    
    @var{spec} has the form @code{@var{source}=@var{target}}, where
    @var{source} is the symlink that will be created and @var{target} is the
    symlink target.
    
    For instance, @code{-S /opt/gnu/bin=bin} creates a @file{/opt/gnu/bin}
    symlink pointing to the @file{bin} sub-directory of the profile.
    
    @item --save-provenance
    Save provenance information for the packages passed on the command line.
    Provenance information includes the URL and commit of the channels in use
    (@pxref{Channels}).
    
    Provenance information is saved in the
    @file{/gnu/store/@dots{}-profile/manifest} file in the pack, along with the
    usual package metadata---the name and version of each package, their
    propagated inputs, and so on.  It is useful information to the recipient of
    the pack, who then knows how the pack was (supposedly) obtained.
    
    This option is not enabled by default because, like timestamps, provenance
    information contributes nothing to the build process.  In other words, there
    is an infinity of channel URLs and commit IDs that can lead to the same pack.
    Recording such ``silent'' metadata in the output thus potentially breaks the
    source-to-binary bitwise reproducibility property.
    
    
    Ludovic Courtès's avatar
    Ludovic Courtès committed
    @item --root=@var{file}
    @itemx -r @var{file}
    @cindex garbage collector root, for packs
    Make @var{file} a symlink to the resulting pack, and register it as a garbage
    collector root.
    
    
    @item --localstatedir
    @itemx --profile-name=@var{name}
    Include the ``local state directory'', @file{/var/guix}, in the resulting
    pack, and notably the @file{/var/guix/profiles/per-user/root/@var{name}}
    profile---by default @var{name} is @code{guix-profile}, which corresponds to
    @file{~root/.guix-profile}.
    
    @file{/var/guix} contains the store database (@pxref{The Store}) as well
    as garbage-collector roots (@pxref{Invoking guix gc}).  Providing it in
    the pack means that the store is ``complete'' and manageable by Guix;