Built-in Constants

These constants are built into the Nix language evaluator:

builtins (set)

Contains all the built-in functions and values.

Since built-in functions were added over time, testing for attributes in builtins can be used for graceful fallback on older Nix installations:

# if hasContext is not available, we assume `s` has a context
if builtins ? hasContext then builtins.hasContext s else true
currentSystem (string)

The value of the eval-system or else system configuration option.

It can be used to set the system attribute for builtins.derivation such that the resulting derivation can be built on the same system that evaluates the Nix expression:

 builtins.derivation {
   # ...
   system = builtins.currentSystem;
}

It can be overridden in order to create derivations for different system than the current one:

$ nix-instantiate --system "mips64-linux" --eval --expr 'builtins.currentSystem'
"mips64-linux"

Note

Not available in pure evaluation mode.

currentTime (integer)

Return the Unix time at first evaluation. Repeated references to that name will re-use the initially obtained value.

Example:

$ nix repl
Welcome to Nix 2.15.1 Type :? for help.

nix-repl> builtins.currentTime
1683705525

nix-repl> builtins.currentTime
1683705525

The store path of a derivation depending on currentTime will differ for each evaluation, unless both evaluate builtins.currentTime in the same second.

Note

Not available in pure evaluation mode.

false (Boolean)

Primitive value.

It can be returned by comparison operators and used in conditional expressions.

The name false is not special, and can be shadowed:

nix-repl> let false = 1; in false
1
langVersion (integer)

The current version of the Nix language.

nixPath (list)

The value of the nix-path configuration setting: a list of search path entries used to resolve lookup paths.

Lookup path expressions are desugared using this and builtins.findFile:

<nixpkgs>

is equivalent to:

builtins.findFile builtins.nixPath "nixpkgs"
nixVersion (string)

The version of Nix.

For example, where the command line returns the current Nix version,

$ nix --version
nix (Nix) 2.16.0

the Nix language evaluator returns the same value:

nix-repl> builtins.nixVersion
"2.16.0"
null (null)

Primitive value.

The name null is not special, and can be shadowed:

nix-repl> let null = 1; in null
1
storeDir (string)

Logical file system location of the Nix store currently in use.

This value is determined by the store parameter in Store URLs:

$ nix-instantiate --store 'dummy://?store=/blah' --eval --expr builtins.storeDir
"/blah"
true (Boolean)

Primitive value.

It can be returned by comparison operators and used in conditional expressions.

The name true is not special, and can be shadowed:

nix-repl> let true = 1; in true
1