Nix 2.34.6
Nix, the purely functional package manager: C API (experimental)
Loading...
Searching...
No Matches
Value Extraction

Functions for extracting data from Nix values. More...

Functions

ValueType nix_get_type (nix_c_context *context, const nix_value *value)
 Get value type.
const char * nix_get_typename (nix_c_context *context, const nix_value *value)
 Get type name of value as defined in the evaluator.
bool nix_get_bool (nix_c_context *context, const nix_value *value)
 Get boolean value.
nix_err nix_get_string (nix_c_context *context, const nix_value *value, nix_get_string_callback callback, void *user_data)
 Get the raw string.
const char * nix_get_path_string (nix_c_context *context, const nix_value *value)
 Get path as string.
unsigned int nix_get_list_size (nix_c_context *context, const nix_value *value)
 Get the length of a list.
unsigned int nix_get_attrs_size (nix_c_context *context, const nix_value *value)
 Get the element count of an attrset.
double nix_get_float (nix_c_context *context, const nix_value *value)
 Get float value in 64 bits.
int64_t nix_get_int (nix_c_context *context, const nix_value *value)
 Get int value.
ExternalValuenix_get_external (nix_c_context *context, nix_value *value)
 Get external reference.
nix_valuenix_get_list_byidx (nix_c_context *context, const nix_value *value, EvalState *state, unsigned int ix)
 Get the ix'th element of a list.
nix_valuenix_get_list_byidx_lazy (nix_c_context *context, const nix_value *value, EvalState *state, unsigned int ix)
 Get the ix'th element of a list without forcing evaluation of the element.
nix_valuenix_get_attr_byname (nix_c_context *context, const nix_value *value, EvalState *state, const char *name)
 Get an attr by name.
nix_valuenix_get_attr_byname_lazy (nix_c_context *context, const nix_value *value, EvalState *state, const char *name)
 Get an attribute value by attribute name, without forcing evaluation of the attribute's value.
bool nix_has_attr_byname (nix_c_context *context, const nix_value *value, EvalState *state, const char *name)
 Check if an attribute name exists on a value.
nix_valuenix_get_attr_byidx (nix_c_context *context, nix_value *value, EvalState *state, unsigned int i, const char **name)
 Get an attribute by index.
nix_valuenix_get_attr_byidx_lazy (nix_c_context *context, nix_value *value, EvalState *state, unsigned int i, const char **name)
 Get an attribute by index, without forcing evaluation of the attribute's value.
const char * nix_get_attr_name_byidx (nix_c_context *context, nix_value *value, EvalState *state, unsigned int i)
 Get an attribute name by index.

Detailed Description

Functions for extracting data from Nix values.

Function Documentation

◆ nix_get_attr_byidx()

nix_value * nix_get_attr_byidx ( nix_c_context * context,
nix_value * value,
EvalState * state,
unsigned int i,
const char ** name )

Get an attribute by index.

Also gives you the name.

Attributes are returned in an unspecified order which is NOT suitable for reproducible operations. In Nix's domain, reproducibility is paramount. The caller is responsible for sorting the attributes or storing them in an ordered map to ensure deterministic behavior in your application.

Note
When Nix does sort attributes, which it does for virtually all intermediate operations and outputs, it uses byte-wise lexicographic order (equivalent to lexicographic order by Unicode scalar value for valid UTF-8). We recommend applying this same ordering for consistency.

Call nix_value_decref() when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
[in]statenix evaluator state
[in]iattribute index
[out]namewill store a pointer to the attribute name, valid until state is freed
Returns
value, NULL in case of errors

◆ nix_get_attr_byidx_lazy()

nix_value * nix_get_attr_byidx_lazy ( nix_c_context * context,
nix_value * value,
EvalState * state,
unsigned int i,
const char ** name )

Get an attribute by index, without forcing evaluation of the attribute's value.

Also gives you the name.

Returns the attribute value without forcing its evaluation, allowing access to lazy values. The attribute set value itself must already have been evaluated.

Attributes are returned in an unspecified order which is NOT suitable for reproducible operations. In Nix's domain, reproducibility is paramount. The caller is responsible for sorting the attributes or storing them in an ordered map to ensure deterministic behavior in your application.

Note
When Nix does sort attributes, which it does for virtually all intermediate operations and outputs, it uses byte-wise lexicographic order (equivalent to lexicographic order by Unicode scalar value for valid UTF-8). We recommend applying this same ordering for consistency.

Call nix_value_decref() when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect (must be an evaluated attribute set)
[in]statenix evaluator state
[in]iattribute index
[out]namewill store a pointer to the attribute name, valid until state is freed
Returns
value, NULL in case of errors

◆ nix_get_attr_byname()

nix_value * nix_get_attr_byname ( nix_c_context * context,
const nix_value * value,
EvalState * state,
const char * name )

Get an attr by name.

Call nix_value_decref() when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
[in]statenix evaluator state
[in]nameattribute name
Returns
value, NULL in case of errors

◆ nix_get_attr_byname_lazy()

nix_value * nix_get_attr_byname_lazy ( nix_c_context * context,
const nix_value * value,
EvalState * state,
const char * name )

Get an attribute value by attribute name, without forcing evaluation of the attribute's value.

Returns the attribute value without forcing its evaluation, allowing access to lazy values. The attribute set value itself must already be evaluated.

Call nix_value_decref() when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect (must be an evaluated attribute set)
[in]statenix evaluator state
[in]nameattribute name
Returns
value, NULL in case of errors

◆ nix_get_attr_name_byidx()

const char * nix_get_attr_name_byidx ( nix_c_context * context,
nix_value * value,
EvalState * state,
unsigned int i )

Get an attribute name by index.

Returns the attribute name without forcing evaluation of the attribute's value.

Attributes are returned in an unspecified order which is NOT suitable for reproducible operations. In Nix's domain, reproducibility is paramount. The caller is responsible for sorting the attributes or storing them in an ordered map to ensure deterministic behavior in your application.

Note
When Nix does sort attributes, which it does for virtually all intermediate operations and outputs, it uses byte-wise lexicographic order (equivalent to lexicographic order by Unicode scalar value for valid UTF-8). We recommend applying this same ordering for consistency.
Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
[in]statenix evaluator state
[in]iattribute index
Returns
name string valid until state is freed, NULL in case of errors

◆ nix_get_attrs_size()

unsigned int nix_get_attrs_size ( nix_c_context * context,
const nix_value * value )

Get the element count of an attrset.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
attrset element count, error info via context

◆ nix_get_bool()

bool nix_get_bool ( nix_c_context * context,
const nix_value * value )

Get boolean value.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
true or false, error info via context

◆ nix_get_external()

ExternalValue * nix_get_external ( nix_c_context * context,
nix_value * value )

Get external reference.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
reference valid while value is valid. Call nix_gc_incref() if you need it to live longer, then only in that case call nix_gc_decref() when done. NULL in case of error

◆ nix_get_float()

double nix_get_float ( nix_c_context * context,
const nix_value * value )

Get float value in 64 bits.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
float contents, error info via context

◆ nix_get_int()

int64_t nix_get_int ( nix_c_context * context,
const nix_value * value )

Get int value.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
int contents, error info via context

◆ nix_get_list_byidx()

nix_value * nix_get_list_byidx ( nix_c_context * context,
const nix_value * value,
EvalState * state,
unsigned int ix )

Get the ix'th element of a list.

Call nix_value_decref() when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
[in]statenix evaluator state
[in]ixlist element to get
Returns
value, NULL in case of errors

◆ nix_get_list_byidx_lazy()

nix_value * nix_get_list_byidx_lazy ( nix_c_context * context,
const nix_value * value,
EvalState * state,
unsigned int ix )

Get the ix'th element of a list without forcing evaluation of the element.

Returns the list element without forcing its evaluation, allowing access to lazy values. The list value itself must already be evaluated.

Call nix_value_decref() when you're done with the pointer

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect (must be an evaluated list)
[in]statenix evaluator state
[in]ixlist element to get
Returns
value, NULL in case of errors

◆ nix_get_list_size()

unsigned int nix_get_list_size ( nix_c_context * context,
const nix_value * value )

Get the length of a list.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
length of list, error info via context

◆ nix_get_path_string()

const char * nix_get_path_string ( nix_c_context * context,
const nix_value * value )

Get path as string.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
string valid while value is valid, NULL in case of error

◆ nix_get_string()

nix_err nix_get_string ( nix_c_context * context,
const nix_value * value,
nix_get_string_callback callback,
void * user_data )

Get the raw string.

This may contain placeholders.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
[in]callbackCalled with the string value.
[in]user_dataoptional, arbitrary data, passed to the callback when it's called.
Returns
error code, NIX_OK on success.

◆ nix_get_type()

ValueType nix_get_type ( nix_c_context * context,
const nix_value * value )

Get value type.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
type of nix value

◆ nix_get_typename()

const char * nix_get_typename ( nix_c_context * context,
const nix_value * value )

Get type name of value as defined in the evaluator.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
Returns
type name string, free with free()

◆ nix_has_attr_byname()

bool nix_has_attr_byname ( nix_c_context * context,
const nix_value * value,
EvalState * state,
const char * name )

Check if an attribute name exists on a value.

Parameters
[out]contextOptional, stores error information
[in]ValueNix value to inspect
[in]statenix evaluator state
[in]nameattribute name
Returns
value, error info via context