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
builtinscan 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
systemconfiguration option.It can be used to set the
systemattribute forbuiltins.derivationsuch 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 1683705525The store path of a derivation depending on
currentTimewill differ for each evaluation, unless both evaluatebuiltins.currentTimein 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
falseis 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 search path used to resolve angle bracket path lookups.
Angle bracket expressions can be 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.0the Nix language evaluator returns the same value:
nix-repl> builtins.nixVersion "2.16.0" -
null(null) -
Primitive value.
The name
nullis 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
storeparameter 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
trueis not special, and can be shadowed:nix-repl> let true = 1; in true 1