Introduction
The number of Nix installations in the world
has grown to 5, with more expected.
Nix is a system for the deployment of software. Software
deployment is concerned with the creation, distribution, and
management of software components (packages
). There
are many tools for this, but they tend to ignore some important
requirements for deployment:
Correctness. The basic goal of
software deployment is to transfer software from one machine (e.g.,
the developer's, where it presumably works) to another machine (e.g.,
the end user's). The software should work exactly the same on the
target machine as on the source machine. But this in practice turns
out to be rather difficult due to dependencies between
components and interference between
components. If we deploy a component that depends on other
components, then we should deploy those dependencies as well. If they
are missing on the target system, the component probably won't work.
If they are present but are not the right
version, the component might not work. And if even if they are the
right version, they may have been built with different flags or
options, which can cause incompatibilities. Interference occurs when
components collide
with each other in the file system.
For instance, different versions of the same package tend to overwrite
each other, so they cannot be installed at the same time. But always
picking the latest version might break components that only work with
some older version.
Variability. Many package
management tools have difficulty supporting the installation of
multiple versions or variants of the same component. This is bad
because as ...
Here are some of Nix's main features:
Nix can quite reliably figure out the dependencies
between components.
This manual is a work in progress. It's quite likely
to be incomplete, inconsistent with the current implementation, or
simply wrong.
Some background information on Nix can be found in two
papers. The ICSE 2004 paper Imposing
a Memory Management Discipline on Software
Deployment discusses the hashing mechanism used to
ensure reliable dependency identification and non-interference between
different versions and variants of packages. The LISA 2004 paper
Nix: A Safe and Policy-Free System for Software
Deployment gives a more general discussion of Nix from a
system-administration perspective.
Nix solves some large problems that exist in most current deployment and
package management systems. Dependency determination
is a big one: the correct installation of a software component requires
that all dependencies of that component (i.e., other components used by it)
are also installed. Most systems have no way to verify that the specified
dependencies of a component are actually sufficient.
Another big problem is the lack of support for concurrent availability of
multiple variants of a component. It must be possible
to have several versions of a component installed at the same time, or
several instances of the same version built with different parameters.
Unfortunately, components are in general not properly isolated from each
other. For instance, upgrading a component that is a dependency for some
other component might break the latter.
Nix solves these problems by building and storing packages in paths that
are infeasible to predict in advance. For example, the artifacts of a
package X might be stored in
/nix/store/d58a0606ed616820de291d594602665d-X, rather
than in, say, /usr/lib. The path component
d58a... is actually a cryptographic hash of all the
inputs (i.e., sources, requisites, and build flags) used in building
X, and as such is very fragile: any change to the inputs
will change the hash. Therefore it is not sensible to
hard-code such a path into the build scripts of a
package Y that uses X (as does happen
with fixed
paths such as /usr/lib).
Rather, the build script of package Y is parameterised
with the actual location of X, which is supplied by the
Nix system.
As stated above, the path name of a file system object contain a
cryptographic hash of all inputs involved in building it. A change to any
of the inputs will cause the hash to change--and by extension, the path
name. These inputs include both sources (variation in time) and
configuration options (variation in space). Therefore variants of the same
package don't clash---they can co-exist peacefully within the same file
system.
Other features:
Transparent source/binary deployment.
Unambiguous identification of configuration.
Automatic storage management.
Atomic upgrades and rollbacks.
Support for many simultaneous configurations.
Portability. Nix is quite portable. Contrary to
build systems like those in, e.g., Vesta and ClearCase, it does not rely on
operating system extensions.