This years NixCon will take place online on October 16th-18th 2020. It is a community-oriented conference for contributors and users of Nix and NixOS.
Please help the organizers to plan the event by filling out this survey!

Reproducible builds and deployments.

Nix is a powerful package manager for Linux and other Unix systems that makes package management reliable and reproducible. Share your development and build environments across different machines.

NixOS is a Linux distribution with a unique approach to package and configuration management. Built on top of the Nix package manager, it is completely declarative, makes upgrading systems reliable, and has many other advantages.

Download Get started

Reproducible

Nix builds packages in isolation from each other. This ensures that they are reproducible and don't have undeclared dependencies, so if a package works on one machine, it will also work on another.

Declarative

Nix makes it trivial to share development and build environments for your projects, regardless of what programming languages and tools you’re using.

Reliable

Nix ensures that installing or upgrading one package cannot break other packages. It allows you to roll back to previous versions, and ensures that no package is in an inconsistent state during an upgrade.



Examples...

Try new tools without fear

Don't clutter your system with tools that you use only now and then.

$ python --version
python: command not found
$ nix-shell -p python3
[nix-shell]$ python --version
Python 3.7.7

Multiple languages, one tool

$ nix-shell -p python3 nodejs go rustc
[nix-shell]$ node --version
v10.20.1
[nix-shell]$ go version
go version go1.14.1 linux/amd64
[nix-shell]$ rustc --version
rustc 1.42.0

Isolated development environments

After you get familiar with nix-shell -p you can take the next step and learn some Nix. To setup a more persistent environment you can also write a simple shell.nix file:

{ pkgs ? import <nixpkgs> {}
}:
pkgs.mkShell {
  name = "dev-shell";
  buildInputs = [
    pkgs.python3
    pkgs.python3Packages.virtualenv
    pkgs.nodejs
    pkgs.yarn
  ];
}

Then enter development environment with:

$ nix-shell
[nix-shell]$ virtualenv --version
16.7.9
[nix-shell]$ yarn --version
1.22.4

Commit the above shell.nix file and help your coworkers have an easier time setting their development environment.

Minimal Docker image

Using a Dockerfile, you are responsible for:

  • cleaning up everything that is not needed at runtime
  • deciding how to split into layers for better caching

Writing a Dockerfile that would produce a minimal image is at best a very error prone process.

With Nix, only packages you define are included in the Docker image. No cleaning up needed. There are no build tools left in your Docker image, keeping it as small as possible.

Nix also knows how to layer your resulting Docker image, automatically. The resulting layers are optimized for caching as much as possible.

The following Nix expression (default.nix) defines a Docker image with only the hello package in it.

{ pkgs ? import <nixpkgs> {}
}:
pkgs.dockerTools.buildLayeredImage {
  name = "only-hello";
  contents = [ pkgs.hello ];
}

To build and run the image you need to:

$ nix-build default.nix -o ./result
...
/nix/store/…-docker-image-only-hello.tar.gz
$ docker load -i ./result
1c31fbac2eb1: Loading layer [==================>]  1.649MB/1.649MB
03b22f688054: Loading layer [==================>]    256kB/256kB
29c350a9c392: Loading layer [==================>]  31.61MB/31.61MB
6a87e4d71e07: Loading layer [==================>]  266.2kB/266.2kB
c09c43a6b910: Loading layer [==================>]  71.68kB/71.68kB
Loaded image: only-hello:qn5x1pnk7d467jsl81jng7168qsks42l
$ docker run only-hello:qn5x1pnk7d467jsl81jng7168qsks42l hello
Hello, world

Learn more about how to build Docker images.

Declarative cloud images

How hard would it be to build and configure an Amazon EC2 image?

With the following amazon.nix we configured nginx to serve a "Welcome to nginx!" page, with a valid SSL certificate (via LetsEncrypt) and recommended security settings.

{ pkgs, ...}:
{
  security.acme.acceptTerms = true;
  security.acme.email = "nix@example.com";
  services.nginx = {
    enable = true;
    recommendedGzipSettings = true;
    recommendedOptimisation = true;
    recommendedProxySettings = true;
    recommendedTlsSettings = true;
    virtualHosts."example.com" = {
      enableACME = true;
      forceSSL = true;
      locations."/".root = "${pkgs.nginx}/html";
    };
  };
}

Now we just need to build it.

$ nix-build '<nixpkgs/nixos/release.nix>' \
    -A amazonImage.x86_64-linux \
    --arg configuration ./amazon.nix \
    -o ./result
...
$ ls ./result/
nixos-amazon-image-20.09pre130979.gfedcba-x86_64-linux.vhd
nix-support

The resulting Virtual Hard Disk image can be then be imported to Amazon EC2 as usual.