The Nix Language

Nix uses a language of the same name for its package definitions.

The language is

  • purely functional
  • lazily evaluated
  • dynamically typed
  • entirely based on expressions
  • inspired by Haskell and ML
  • basically JSON with functions

Types

Basic types

Nix supports the following basic data types:

  • Integers: 123
  • Floats: 1.23
  • Strings: "Hello World"
  • Booleans: true
  • Paths: ./src/main/asdf
  • Lambdas (first-class functions): x: x + 1

Composite types

Some types are used to form structures that hold other types.

List

Lists are delimited by square brackets. Elements in the list are seperated by whitespaces.

[ 1 2 3 "Hello World" [ "Nested" "list" ] ]

Attribute sets

The most important type in Nix. Nix contains lots of syntactic sugar to make working with attribute sets a pleasant experience.

{
  a = 1;
  b = {
    hello = "World!";
  };
  # this is short for c = { hello = "World!"; }:
  c.hello = "World!";
}

#nix

Links to this page
#nix