Skip to content

Nix

Reproducible (declarative) builds and deployments.

Create Small Docker Images

Create nix image definition:

cat << 'EOF' > hello.nix
{ pkgs ? import <nixpkgs> { }
, pkgsLinux ? import <nixpkgs> { system = "x86_64-linux"; }
}:

pkgs.dockerTools.buildImage {
  name = "hello-docker";
  config = {
    Cmd = [ "${pkgsLinux.hello}/bin/hello" ];
  };
}
EOF

Generate Docker image:

nix-build hello.nix # Outputs image to "result" file

Load Docker image:

docker load < result

Run in Docker:

docker run -t hello-docker:<SHA-1>

References

Alternatives

  • Ansible: Suite of software tools that enables infrastructure as code.
  • OSTree: Manage multiple bootable versioned filesystem trees.