Skip to content

Intro

... a cookbook and survival guide for the decidedly average user.

Nix is très cool, but the documentation really is not. I'm writing this cookbook to scratch my own itch, but in the hopes that you will derive value from it too.

What is Nix

Nix is actually several things:

  1. Nix is a package manager
  2. Nix is also a declarative, functional, lazily evaluated language
    • Used to write scripts which, ultimately packages software
    • Also used by NixOS to declaractively configure the operating system
  3. (kind of) NixOS
    • A Linux distribution
    • Using Nix (the package manager) to manage software
    • Using Nix (the language) to manage the system's configuration

What can I do with Nix?

Distribute Software

With Nix, you can write build scripts which declare how to build a software package for nix - not unlike how RPM and deb packages are built.

With nix flakes, you can distribute those build scripts via a Git repository, not unlike a tap for homebrew which users can reference to install the software you packaged into NixOS or into development environments managed by nix (see next).

Distribute development environments

Nix flakes can also define entire development environments called dev shells. You can enter a dev shell, which works a bit like an interactive bash session in a docker container or a Python virtual environment. The flake can define what software and libraries to make available in the shell and to define additional environment variables, even run some commands automatically on entering the shell, like direnv.

Unlike working in a container, a nix dev shell still operates on your machines' normal file system, and you can still use programs installed on the host - the dev shell just augments your host's environment.

Declaratively build VM's, containers

The NixOS generators project provides functions which can be used inside a Nix flake to build QEMU VM's, docker containers or cloud-vendor system images, exactly as you would build any other NixOS installation.