|
Nix 2.34.6
Nix, the purely functional package manager: C API (experimental)
|
Functions for allocating and initializing Nix values. More...
Data Structures | |
| struct | BindingsBuilder |
| Stores an under-construction set of bindings. More... | |
| struct | ListBuilder |
| Stores an under-construction list. More... | |
Macros | |
| #define | NIX_VALUE_CALL(context, state, value, fn, ...) |
| Calls a Nix function with multiple arguments. | |
Functions | |
| nix_err | nix_expr_eval_from_string (nix_c_context *context, EvalState *state, const char *expr, const char *path, nix_value *value) |
| Parses and evaluates a Nix expression from a string. | |
| nix_err | nix_value_call (nix_c_context *context, EvalState *state, nix_value *fn, nix_value *arg, nix_value *value) |
| Calls a Nix function with an argument. | |
| nix_err | nix_value_call_multi (nix_c_context *context, EvalState *state, nix_value *fn, size_t nargs, nix_value **args, nix_value *value) |
| Calls a Nix function with multiple arguments. | |
| nix_err | nix_value_force (nix_c_context *context, EvalState *state, nix_value *value) |
| Forces the evaluation of a Nix value. | |
| nix_value * | nix_alloc_value (nix_c_context *context, EvalState *state) |
| Allocate a Nix value. | |
Initializers | |
Values are typically "returned" by initializing already allocated memory that serves as the return value. For this reason, the construction of values is not tied their allocation. Nix is a language with immutable values. Respect this property by only initializing Values once; and only initialize Values that are meant to be initialized by you. Failing to adhere to these rules may lead to undefined behavior. | |
| nix_err | nix_init_bool (nix_c_context *context, nix_value *value, bool b) |
| Set boolean value. | |
| nix_err | nix_init_string (nix_c_context *context, nix_value *value, const char *str) |
| Set a string. | |
| nix_err | nix_init_path_string (nix_c_context *context, EvalState *s, nix_value *value, const char *str) |
| Set a path. | |
| nix_err | nix_init_float (nix_c_context *context, nix_value *value, double d) |
| Set a float. | |
| nix_err | nix_init_int (nix_c_context *context, nix_value *value, int64_t i) |
| Set an int. | |
| nix_err | nix_init_null (nix_c_context *context, nix_value *value) |
| Set null. | |
| nix_err | nix_init_apply (nix_c_context *context, nix_value *value, nix_value *fn, nix_value *arg) |
| Set the value to a thunk that will perform a function application when needed. | |
| nix_err | nix_init_external (nix_c_context *context, nix_value *value, ExternalValue *val) |
| Set an external value. | |
| nix_err | nix_make_list (nix_c_context *context, ListBuilder *list_builder, nix_value *value) |
| Create a list from a list builder. | |
| ListBuilder * | nix_make_list_builder (nix_c_context *context, EvalState *state, size_t capacity) |
| Create a list builder. | |
| nix_err | nix_make_attrs (nix_c_context *context, nix_value *value, BindingsBuilder *b) |
| Create an attribute set from a bindings builder. | |
| nix_err | nix_init_primop (nix_c_context *context, nix_value *value, PrimOp *op) |
| Set primop. | |
| nix_err | nix_copy_value (nix_c_context *context, nix_value *value, const nix_value *source) |
| Copy from another value. | |
| nix_err | nix_list_builder_insert (nix_c_context *context, ListBuilder *list_builder, unsigned int index, nix_value *value) |
| Insert bindings into a builder. | |
| void | nix_list_builder_free (ListBuilder *list_builder) |
| Free a list builder. | |
Functions for allocating and initializing Nix values.
Values are usually created with nix_alloc_value followed by nix_init_* functions. In primop callbacks, allocation is already done and only initialization is needed.
| #define NIX_VALUE_CALL | ( | context, | |
| state, | |||
| value, | |||
| fn, | |||
| ... ) |
Calls a Nix function with multiple arguments.
Technically these are functions that return functions. It is common for Nix functions to be curried, so this function is useful for calling them.
| [out] | context | Optional, stores error information |
| [in] | state | The state of the evaluation. |
| [out] | Value | The result of the function call. |
| [in] | fn | The Nix function to call. |
| [in] | ... | The arguments to pass to the function. |
| nix_value * nix_alloc_value | ( | nix_c_context * | context, |
| EvalState * | state ) |
Allocate a Nix value.
Call nix_value_decref() when you're done with the pointer
| [out] | context | Optional, stores error information |
| [in] | state | nix evaluator state |
| nix_err nix_copy_value | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| const nix_value * | source ) |
Copy from another value.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | source | value to copy from |
| nix_err nix_expr_eval_from_string | ( | nix_c_context * | context, |
| EvalState * | state, | ||
| const char * | expr, | ||
| const char * | path, | ||
| nix_value * | value ) |
Parses and evaluates a Nix expression from a string.
| [out] | context | Optional, stores error information |
| [in] | state | The state of the evaluation. |
| [in] | expr | The Nix expression to parse. |
| [in] | path | The file path to associate with the expression. This is required for expressions that contain relative paths (such as ./.) that are resolved relative to the given directory. |
| [out] | Value | The result of the evaluation. You must allocate this yourself. |
| nix_err nix_init_apply | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| nix_value * | fn, | ||
| nix_value * | arg ) |
Set the value to a thunk that will perform a function application when needed.
Thunks may be put into attribute sets and lists to perform some computation lazily; on demand. However, note that in some places, a thunk must not be returned, such as in the return value of a PrimOp. In such cases, you may use nix_value_call() instead (but note the different argument order).
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | fn | function to call |
| [in] | arg | argument to pass |
| nix_err nix_init_bool | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| bool | b ) |
Set boolean value.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | b | the boolean value |
| nix_err nix_init_external | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| ExternalValue * | val ) |
Set an external value.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | val | the external value to set. Will be GC-referenced by the value. |
| nix_err nix_init_float | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| double | d ) |
Set a float.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | d | the float, 64-bits |
| nix_err nix_init_int | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| int64_t | i ) |
Set an int.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | i | the int |
| nix_err nix_init_null | ( | nix_c_context * | context, |
| nix_value * | value ) |
Set null.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| nix_err nix_init_path_string | ( | nix_c_context * | context, |
| EvalState * | s, | ||
| nix_value * | value, | ||
| const char * | str ) |
Set a path.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | str | the path string, copied |
| nix_err nix_init_primop | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| PrimOp * | op ) |
Set primop.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | op | primop, will be gc-referenced by the value |
| nix_err nix_init_string | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| const char * | str ) |
Set a string.
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | str | the string, copied |
| void nix_list_builder_free | ( | ListBuilder * | list_builder | ) |
Free a list builder.
Does not fail.
| [in] | list_builder | The builder to free. |
| nix_err nix_list_builder_insert | ( | nix_c_context * | context, |
| ListBuilder * | list_builder, | ||
| unsigned int | index, | ||
| nix_value * | value ) |
Insert bindings into a builder.
| [out] | context | Optional, stores error information |
| [in] | list_builder | ListBuilder to insert into |
| [in] | index | index to manipulate |
| [in] | Value | value to insert |
| nix_err nix_make_attrs | ( | nix_c_context * | context, |
| nix_value * | value, | ||
| BindingsBuilder * | b ) |
Create an attribute set from a bindings builder.
After this call, the bindings builder becomes invalid and cannot be used again. The only necessary next step is to free it with nix_bindings_builder_free().
| [out] | context | Optional, stores error information |
| [out] | Value | Nix value to modify |
| [in] | b | bindings builder to use |
| nix_err nix_make_list | ( | nix_c_context * | context, |
| ListBuilder * | list_builder, | ||
| nix_value * | value ) |
Create a list from a list builder.
After this call, the list builder becomes invalid and cannot be used again. The only necessary next step is to free it with nix_list_builder_free().
| [out] | context | Optional, stores error information |
| [in] | list_builder | list builder to use |
| [out] | Value | Nix value to modify |
| ListBuilder * nix_make_list_builder | ( | nix_c_context * | context, |
| EvalState * | state, | ||
| size_t | capacity ) |
Create a list builder.
| [out] | context | Optional, stores error information |
| [in] | state | nix evaluator state |
| [in] | capacity | how many bindings you'll add. Don't exceed. |
| nix_err nix_value_call | ( | nix_c_context * | context, |
| EvalState * | state, | ||
| nix_value * | fn, | ||
| nix_value * | arg, | ||
| nix_value * | value ) |
Calls a Nix function with an argument.
| [out] | context | Optional, stores error information |
| [in] | state | The state of the evaluation. |
| [in] | fn | The Nix function to call. |
| [in] | arg | The argument to pass to the function. |
| [out] | Value | The result of the function call. |
| nix_err nix_value_call_multi | ( | nix_c_context * | context, |
| EvalState * | state, | ||
| nix_value * | fn, | ||
| size_t | nargs, | ||
| nix_value ** | args, | ||
| nix_value * | value ) |
Calls a Nix function with multiple arguments.
Technically these are functions that return functions. It is common for Nix functions to be curried, so this function is useful for calling them.
| [out] | context | Optional, stores error information |
| [in] | state | The state of the evaluation. |
| [in] | fn | The Nix function to call. |
| [in] | nargs | The number of arguments. |
| [in] | args | The arguments to pass to the function. |
| [out] | Value | The result of the function call. |
| nix_err nix_value_force | ( | nix_c_context * | context, |
| EvalState * | state, | ||
| nix_value * | value ) |
Forces the evaluation of a Nix value.
The Nix interpreter is lazy, and not-yet-evaluated values can be of type NIX_TYPE_THUNK instead of their actual value.
This function mutates such a nix_value, so that, if successful, it has its final type.
| [out] | context | Optional, stores error information |
| [in] | state | The state of the evaluation. |
| [in,out] | Value | The Nix value to force. |