lix/doc/manual/src/language/builtin-constants.md
Valentin Gagarin 6a5a8f51bb add cross-references to pure evaluation mode
use consistent wording everywhere.
add some details on the configuration option documentation.
2023-05-17 15:01:54 +02:00

1.5 KiB

Built-in Constants

These constants are built into the Nix language evaluator:

  • [builtins]{#builtins-builtins} (attribute set)

    Contains all the built-in functions and values, in order to avoid polluting the global scope.

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

    if builtins ? getEnv then builtins.getEnv "PATH" else ""
    
  • [builtins.currentSystem]{#builtins-currentSystem} (string)

    The built-in value currentSystem evaluates to the Nix platform identifier for the Nix installation on which the expression is being evaluated, such as "i686-linux" or "x86_64-darwin".

    Not available in pure evaluation mode.

  • [builtins.currentTime]{#builtins-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.

    Not available in pure evaluation mode.