Home Explore Blog CI



nix

3rd chunk of `doc/manual/source/introduction.md`
7a029bd36927adf973ee187ad50fa50533f395771e7ce2420000000100000d38
functional language.  A Nix expression describes everything that goes
into a package build task (a “derivation”): other packages, sources,
the build script, environment variables for the build script, etc.
Nix tries very hard to ensure that Nix expressions are
_deterministic_: building a Nix expression twice should yield the same
result.

Because it’s a functional language, it’s easy to support
building variants of a package: turn the Nix expression into a
function and call it any number of times with the appropriate
arguments.  Due to the hashing scheme, variants don’t conflict with
each other in the Nix store.

## Transparent source/binary deployment

Nix expressions generally describe how to build a package from
source, so an installation action like

```console
$ nix-env --install --attr nixpkgs.firefox
```

_could_ cause quite a bit of build activity, as not only Firefox but
also all its dependencies (all the way up to the C library and the
compiler) would have to be built, at least if they are not already in the
Nix store.  This is a _source deployment model_.  For most users,
building from source is not very pleasant as it takes far too long.
However, Nix can automatically skip building from source and instead
use a _binary cache_, a web server that provides pre-built
binaries. For instance, when asked to build
`/nix/store/b6gvzjyb2pg0…-firefox-33.1` from source, Nix would first
check if the file `https://cache.nixos.org/b6gvzjyb2pg0….narinfo`
exists, and if so, fetch the pre-built binary referenced from there;
otherwise, it would fall back to building from source.

## Nix Packages collection

We provide a large set of Nix expressions containing hundreds of
existing Unix packages, the _Nix Packages collection_ (Nixpkgs).

## Managing build environments

Nix is extremely useful for developers as it makes it easy to
automatically set up the build environment for a package. Given a Nix
expression that describes the dependencies of your package, the
command `nix-shell` will build or download those dependencies if
they’re not already in your Nix store, and then start a Bash shell in
which all necessary environment variables (such as compiler search
paths) are set.

For example, the following command gets all dependencies of the
Pan newsreader, as described by [its
Nix expression](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/newsreaders/pan/default.nix):

```console
$ nix-shell '<nixpkgs>' --attr pan
```

You’re then dropped into a shell where you can edit, build and test
the package:

```console
[nix-shell]$ unpackPhase
[nix-shell]$ cd pan-*
[nix-shell]$ configurePhase
[nix-shell]$ buildPhase
[nix-shell]$ ./pan/gui/pan
```

## Portability

Nix runs on Linux and macOS.

## NixOS

NixOS is a Linux distribution based on Nix.  It uses Nix not just for
package management but also to manage the system configuration (e.g.,
to build configuration files in `/etc`).  This means, among other
things, that it is easy to roll back the entire configuration of the
system to an earlier state.  Also, users can install software without
root privileges.  For more information and downloads, see the [NixOS
homepage](https://nixos.org/).

## License

Nix is released under the terms of the [GNU LGPLv2.1 or (at your
option) any later
version](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).

Title: Nix Features: Transparent Deployment, Package Collection, Build Environments, Portability, NixOS, and License
Summary
Nix expressions, written in a functional language, define package build tasks deterministically and support variants. Nix offers transparent source/binary deployment, using binary caches to avoid building from source. Nix provides a large package collection (Nixpkgs) and simplifies setting up build environments with `nix-shell`. Nix runs on Linux and macOS and is the base for NixOS, a Linux distribution that uses Nix for system configuration management. Nix is licensed under the GNU LGPLv2.1.