Original article
Nix Pills - basics-of-language
Nix Expression Language - NixOS Wiki
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Nix language
Nix expression language
    A pure, lazy, functional language.

    Not a full-featured, general purpose
    language.

    Functions are “normal” values that can be
    passed around and manipulated in
    interesting ways.

    Its main job is to describe packages,
    compositions of packages, and the variability
    within packages.
  • everything is an expression (there are no statements)
  • values in Nix are immutable.

My version of nix

1
nix-env --version
nix-env (Nix) 2.2.2

REPL

https://nixos.wiki/wiki/Nix-repl

kb f
:q exit
:? help

Value types

  • basic arithmetic operations: +, -, * and /

Suprises

1
2
nix-repl> 6/3
/home/shane/blog/posts/6/3

What happened?

Recall that Nix is not a general purpose language, it’s a domain-specific language for writing packages.

Integer division isn’t actually that useful when writing package expressions.

Nix parsed 6/3 as a relative path to the current directory.

To get Nix to perform division instead, leave a space after the /.

Alternatively, you can use builtins.div.

Demonstration

asciinema recording