Skip to content

Basics of the Nix Language

The Nix language is essential for declaring configurations to be built by Nix. To fully enjoy the benefits of NixOS and Flakes, it is necessary to grasp the fundamentals of this language.

The Nix language is a straightforward "lazy" functional language. The lazy aspect means a value doesn't exist until it is used. In particular, a function return a set of values can be provided that result as input (like a snake eating its tail) provided the part of the function using the value is not responsible for also producing the part of the value it is using. If that is the case the you get a recursion error. This recursion pattern is somewhat common in NixPkgs where some functions expect their result as a self argument. (This is curious considering the rec { } offers a near similar ability.)

If you have some programming experience, it should take you less than 2 hours to grasp its basics.

The community already has a lot of good Nix language tutorials, so I won't remake the wheel. To get started, I recommend reading the following resources for a quick introduction to the Nix language:

  1. Nix Language Basics - nix.dev: This tutorial provides a comprehensive overview of the basics of the Nix language, recommended for beginners.
  2. A tour of Nix: An online interactive tutorial focuses on programming language constructs and how Nix can be algorithmically used to solve problems.
  3. Nix Language - Nix Reference Manual: The official documentation of the Nix language.
    1. nix.dev are suitable for starter reading only, and neither of them fully introduces the full syntax of Nix. If you encounter a new syntax that you have not come across before, please refer to this official document.
  4. https://noogle.dev/ is a Nix function library search engine that can help you quickly find the functions you need and their usage, which is very practical.

It's okay to have a rough impression of the syntax for now. You can come back to review the syntax when you find something you don't understand later.