Home Explore Blog Models CI



nix

3rd chunk of `doc/manual/source/introduction.md`
bd1e735008d79487aca2dd06b8d11048103e668565054fdb0000000100000d38
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: Functional Language, Deployment, Development Tools, and NixOS Integration
Summary
This chunk elaborates on several key features of Nix. It explains that Nix expressions, a functional language, ensure deterministic builds and facilitate creating package variants without conflicts. The system offers transparent source/binary deployment, initially describing how to build from source but automatically fetching pre-built binaries from caches (like `cache.nixos.org`) for speed, falling back to source compilation if binaries are unavailable. The 'Nix Packages collection' (Nixpkgs) provides a vast library of existing Unix package definitions. Nix significantly aids developers by allowing `nix-shell` to automatically set up isolated build environments with all dependencies. Nix is portable across Linux and macOS. Finally, it introduces NixOS, a Linux distribution that extends Nix's functional package management to the entire system configuration, enabling full system rollbacks and non-root software installation. Nix itself is licensed under GNU LGPLv2.1 or later.