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 elsesystem
configuration option.It can be used to set the
system
attribute forbuiltins.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 evaluatebuiltins.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 legacy version of the Nix language. Always is
6
on Lix, matching Nix 2.18.Code in the Nix language should use other means of feature detection like detecting the presence of builtins, rather than trying to find the version of the Nix implementation, as there may be other Nix implementations with different feature combinations.
If the feature you want to write compatibility code for cannot be detected by any means, please file a Lix bug.
-
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) -
Legacy version of Nix. Always returns "2.18.3-lix" on Lix.
Code in the Nix language should use other means of feature detection like detecting the presence of builtins, rather than trying to find the version of the Nix implementation, as there may be other Nix implementations with different feature combinations.
If the feature you want to write compatibility code for cannot be detected by any means, please file a Lix bug.
-
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
Things which might be mistaken for constants
__curPos
-
This is not a constant but a context-dependent keyword