This section summarizes all the options available in
declarations (see 定义软件包).
This is the data type representing a package recipe.
The name of the package, as a string.
The version of the package, as a string.
An object telling how the source code for the package should be acquired.
Most of the time, this is an
origin object, which denotes a file
fetched from the Internet (see origin参考手册). It can also be any
other “file-like” object such as a
local-file, which denotes a file
from the local file system (see
The build system that should be used to build the package (see 构建系统).
The arguments that should be passed to the build system. This is a list, typically containing sequential keyword-value pairs.
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
"out" (see 有多个输出的软件包, for more
on package outputs). For example, the list below specifies three inputs:
`(("libffi" ,libffi) ("libunistring" ,libunistring) ("glib:bin" ,glib "bin")) ;the "bin" output of Glib
The distinction between
inputs is necessary
when considering cross-compilation. When cross-compiling, dependencies
inputs are built for the target architecture;
conversely, dependencies listed in
native-inputs are built for the
architecture of the build machine.
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
guix lint can report likely mistakes in this area
(see 调用guix lint).
propagated-inputs is similar to
inputs, but the
specified packages will be automatically installed to profiles
(see the role of profiles in Guix) alongside the package they
belong to (see
for information on how
guix package deals with propagated inputs).
For example this is necessary when packaging a C/C++ library that needs
headers of another library to compile, or when a pkg-config file refers to
another one via its
Another example where
propagated-inputs is useful is for languages
that lack a facility to record the run-time search path akin to the
RUNPATH of ELF files; this includes Guile, Python, Perl, and more.
When packaging libraries written in those languages, ensure they can find
library code they depend on at run time by listing run-time dependencies in
propagated-inputs rather than
The list of output names of the package. See 有多个输出的软件包, for typical uses of additional outputs.
A list of
search-path-specification objects describing search-path
environment variables honored by the package.
This must be either
#f or a package object that will be used as a
replacement for this package. See grafts, for
A one-line description of the package.
A more elaborate description of the package.
The license of the package; a value from
(guix licenses), or a list
of such values.
The URL to the home-page of the package, as a string.
The list of systems supported by the package, as strings of the form
architecture-kernel, for example
location(default: source location of the
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.
When used in the 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:
(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)) '())))
It is an error to refer to
this-package outside a package definition.
Because packages are regular Scheme objects that capture a complete dependency graph and associated build procedures, it is often useful to write procedures that take a package and return a modified version thereof according to some parameters. Below are a few examples.
Return a variant of package that uses toolchain instead of the
default GNU C/C++ toolchain. toolchain must be a list of inputs
(label/package tuples) providing equivalent functionality, such as the
The example below returns a variant of the
hello package built with
GCC 10.x and the rest of the GNU tool chain (Binutils and the GNU C
Library) instead of the default tool chain:
(let ((toolchain (specification->package "gcc-toolchain@10"))) (package-with-c-toolchain hello `(("toolchain" ,toolchain))))
The build tool chain is part of the implicit inputs of packages—it’s usually not listed as part of the various “inputs” fields and is instead pulled in by the build system. Consequently, this procedure works by changing the build system of package so that it pulls in toolchain instead of the defaults. 构建系统, for more on build systems.