Nix 2.36.0
Nix, the purely functional package manager: C API (experimental)
Loading...
Searching...
No Matches
Evaluation

Higher-level evaluation helpers. More...

Functions

StorePath * nix_get_derivation (nix_c_context *context, EvalState *state, nix_value *value, bool ignoreAssertionFailures)
 Determine whether a Nix value is a derivation and, if so, return its store derivation path.
nix_err nix_value_auto_call_function (nix_c_context *context, EvalState *state, nix_value *auto_args, nix_value *fn_val, nix_value *result)
 Call a function, drawing its arguments from an attribute set.

Detailed Description

Higher-level evaluation helpers.

Function Documentation

◆ nix_get_derivation()

StorePath * nix_get_derivation ( nix_c_context * context,
EvalState * state,
nix_value * value,
bool ignoreAssertionFailures )

Determine whether a Nix value is a derivation and, if so, return its store derivation path.

Forces value and inspects it. The value is considered a derivation when it is an attribute set whose type attribute is the string "derivation"; in that case its drvPath attribute is parsed and returned. Otherwise NULL is returned without recording an error.

Only the derivation path is returned. Other metadata (name, system, outputs, meta, ...) lives on value itself and can be read with the attribute-set accessors such as nix_get_attr_byname() and nix_get_string().

Parameters
[out]contextOptional, stores error information. On a NULL return, inspect the error code via nix_err_code() to tell the two NULL cases apart: NIX_OK means value is simply not a derivation, any other code means inspection failed. See Handling errors.
[in]stateThe evaluation state.
[in]valueThe value to inspect. It is forced by this call.
[in]ignoreAssertionFailuresIf true, an assertion failure raised while forcing value is treated as "not a derivation" (NULL is returned without an error) rather than being reported as an error.
Returns
A newly allocated StorePath holding the derivation path, or NULL. Free a non-NULL result with nix_store_path_free().

◆ nix_value_auto_call_function()

nix_err nix_value_auto_call_function ( nix_c_context * context,
EvalState * state,
nix_value * auto_args,
nix_value * fn_val,
nix_value * result )

Call a function, drawing its arguments from an attribute set.

Forces fn_val and writes the application result into result. The result is not forced; call nix_value_force() to evaluate it before inspecting the final value.

  • If fn_val is a function that takes a set of named arguments (e.g. { a, b ? 1 }: ...), it is called with an attribute set assembled from auto_args: each named argument is taken from auto_args when present; an argument absent from auto_args falls back to its default; an argument that is both absent and has no default is an error.
  • Otherwise fn_val is copied into result unchanged. This includes any non-function value as well as a function that takes a single unnamed argument (e.g. x: ...), since there are no named arguments to supply.
Parameters
[out]contextOptional, stores error information
[in]stateThe evaluation state.
[in]auto_argsAttribute set value supplying the named arguments, or NULL to supply none.
[in]fn_valThe value to call.
[out]resultPre-allocated nix_value that receives the result.
Returns
NIX_OK if the call was successful, an error code otherwise.