Module bindings

Source

Structs§

BindingsBuilder
EvalState
ExternalValue
ListBuilder
NixCExternalValueDesc
Definition for a class of external values Create and implement one of these, then pass it to nix_create_external_value Make sure to keep it alive while the external value lives. Optional functions can be set to NULL
PrimOp
Store
StorePath
__fsid_t
max_align_t
nix_c_context
nix_eval_state_builder
nix_flake_settings
nix_printer
nix_realised_string
nix_string_context
nix_string_return
nix_value

Constants§

INT8_MAX
INT8_MIN
INT16_MAX
INT16_MIN
INT32_MAX
INT32_MIN
INTPTR_MAX
INTPTR_MIN
INT_FAST8_MAX
INT_FAST8_MIN
INT_FAST16_MAX
INT_FAST16_MIN
INT_FAST32_MAX
INT_FAST32_MIN
INT_LEAST8_MAX
INT_LEAST8_MIN
INT_LEAST16_MAX
INT_LEAST16_MIN
INT_LEAST32_MAX
INT_LEAST32_MIN
PTRDIFF_MAX
PTRDIFF_MIN
SIG_ATOMIC_MAX
SIG_ATOMIC_MIN
SIZE_MAX
UINT8_MAX
UINT16_MAX
UINT32_MAX
UINTPTR_MAX
UINT_FAST8_MAX
UINT_FAST16_MAX
UINT_FAST32_MAX
UINT_LEAST8_MAX
UINT_LEAST16_MAX
UINT_LEAST32_MAX
ValueType_NIX_TYPE_ATTRS
ValueType_NIX_TYPE_BOOL
ValueType_NIX_TYPE_EXTERNAL
ValueType_NIX_TYPE_FLOAT
ValueType_NIX_TYPE_FUNCTION
ValueType_NIX_TYPE_INT
ValueType_NIX_TYPE_LIST
ValueType_NIX_TYPE_NULL
ValueType_NIX_TYPE_PATH
ValueType_NIX_TYPE_STRING
ValueType_NIX_TYPE_THUNK
WINT_MAX
WINT_MIN
_ATFILE_SOURCE
_BITS_STDINT_INTN_H
_BITS_STDINT_LEAST_H
_BITS_STDINT_UINTN_H
_BITS_TIME64_H
_BITS_TYPESIZES_H
_BITS_TYPES_H
_BITS_WCHAR_H
_DEFAULT_SOURCE
_FEATURES_H
_POSIX_C_SOURCE
_POSIX_SOURCE
_STDC_PREDEF_H
_STDINT_H
_SYS_CDEFS_H
__FD_SETSIZE
__GLIBC_MINOR__
__GLIBC_USE_C23_STRTOL
__GLIBC_USE_DEPRECATED_GETS
__GLIBC_USE_DEPRECATED_SCANF
__GLIBC_USE_IEC_60559_BFP_EXT
__GLIBC_USE_IEC_60559_BFP_EXT_C23
__GLIBC_USE_IEC_60559_EXT
__GLIBC_USE_IEC_60559_FUNCS_EXT
__GLIBC_USE_IEC_60559_FUNCS_EXT_C23
__GLIBC_USE_IEC_60559_TYPES_EXT
__GLIBC_USE_ISOC23
__GLIBC_USE_LIB_EXT2
__GLIBC__
__GNU_LIBRARY__
__HAVE_GENERIC_SELECTION
__INO_T_MATCHES_INO64_T
__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64
__LDOUBLE_REDIRECTS_TO_FLOAT128_ABI
__OFF_T_MATCHES_OFF64_T
__RLIM_T_MATCHES_RLIM64_T
__STATFS_MATCHES_STATFS64
__STDC_IEC_559_COMPLEX__
__STDC_IEC_559__
__STDC_IEC_60559_BFP__
__STDC_IEC_60559_COMPLEX__
__STDC_ISO_10646__
__SYSCALL_WORDSIZE
__TIMESIZE
__USE_ATFILE
__USE_FORTIFY_LEVEL
__USE_ISOC11
__USE_ISOC95
__USE_ISOC99
__USE_MISC
__USE_POSIX
__USE_POSIX2
__USE_POSIX199309
__USE_POSIX199506
__USE_POSIX_IMPLICITLY
__USE_TIME_BITS64
__USE_XOPEN2K
__USE_XOPEN2K8
__WORDSIZE
__WORDSIZE_TIME64_COMPAT32
__bool_true_false_are_defined
__glibc_c99_flexarr_available
false_
nix_err_NIX_ERR_KEY
A key error occurred. This error code is returned when a key error occurred during the function execution.
nix_err_NIX_ERR_NIX_ERROR
A generic Nix error occurred. This error code is returned when a generic Nix error occurred during the function execution.
nix_err_NIX_ERR_OVERFLOW
An overflow error occurred. This error code is returned when an overflow error occurred during the function execution.
nix_err_NIX_ERR_UNKNOWN
An unknown error occurred. This error code is returned when an unknown error occurred during the function execution.
nix_err_NIX_OK
No error occurred. This error code is returned when no error has occurred during the function execution.
true_

Functions§

nix_alloc_primop
Allocate a PrimOp Owned by the garbage collector. Use nix_gc_decref() when you’re done with the returned PrimOp.
nix_alloc_value
Allocate a Nix value Owned by the GC. Use nix_gc_decref() when you’re done with the pointer
nix_bindings_builder_free
Free a bindings builder Does not fail.
nix_bindings_builder_insert
Insert bindings into a builder
nix_c_context_create
Allocate a new nix_c_context. @throws std::bad_alloc
nix_c_context_free
Free a nix_c_context. Does not fail.
nix_clear_err
Clear the error message from a nix context. This is performed implicitly by all functions that accept a context, so this won’t be necessary in most cases. However, if you want to clear the error message without calling another function, you can use this. Example use case: a higher order function that helps with error handling, to make it more robust in the following scenario:
nix_copy_value
Copy from another value
nix_create_external_value
Create an external value, that can be given to nix_init_external Owned by the GC. Use nix_gc_decref when you’re done with the pointer.
nix_err_code
Retrieves the most recent error code from a nix_c_context Equivalent to reading the first field of the context. Does not fail
nix_err_info_msg
Retrieves the error message from errorInfo in a context. Used to inspect nix Error messages. @pre This function should only be called after a previous nix function has returned a NIX_ERR_NIX_ERROR
nix_err_msg
@addtogroup errors Retrieves the most recent error message from a context. @pre This function should only be called after a previous nix function has returned an error.
nix_err_name
Retrieves the error name from a context. Used to inspect nix Error messages. @pre This function should only be called after a previous nix function has returned a NIX_ERR_NIX_ERROR
nix_eval_state_build
Create a new Nix language evaluator state Remember to nix_eval_state_builder_free after building the state.
nix_eval_state_builder_free
Free a nix_eval_state_builder Does not fail.
nix_eval_state_builder_load
Read settings from the ambient environment Settings are sourced from environment variables and configuration files, as documented in the Nix manual.
nix_eval_state_builder_new
Create a new nix_eval_state_builder The settings are initialized to their default value. Values can be sourced elsewhere with nix_eval_state_builder_load.
nix_eval_state_builder_set_lookup_path
Set the lookup path for <...> expressions
nix_expr_eval_from_string
Parses and evaluates a Nix expression from a string.
nix_external_add_string_context
Add string context to the nix_string_context object
nix_external_print
Print to the nix_printer
nix_flake_settings_add_to_eval_state_builder
Initialize a nix_flake_settings to contain builtins.getFlake and potentially more.
nix_flake_settings_free
Release the resources associated with a nix_flake_settings.
nix_flake_settings_new
Create a nix_flake_settings initialized with default values.
nix_gc_decref
Decrement the garbage collector reference counter for the given object
nix_gc_incref
Increment the garbage collector reference counter for the given object. The Nix language evaluator C API keeps track of alive objects by reference counting. When you’re done with a refcounted pointer, call nix_gc_decref().
nix_gc_now
Trigger the garbage collector manually You should not need to do this, but it can be useful for debugging.
nix_gc_register_finalizer
Register a callback that gets called when the object is garbage collected.
nix_get_attr_byidx
Get an attribute by index in the sorted bindings Also gives you the name. Owned by the GC. Use nix_gc_decref when you’re done with the pointer
nix_get_attr_byname
Get an attr by name Owned by the GC. Use nix_gc_decref when you’re done with the pointer
nix_get_attr_name_byidx
Get an attribute name by index in the sorted bindings Useful when you want the name but want to avoid evaluation. Owned by the nix EvalState
nix_get_attrs_size
Get the element count of an attrset
nix_get_bool
Get boolean value
nix_get_external
Get external reference
nix_get_external_value_content
Extract the pointer from a nix c external value.
nix_get_float
Get float value in 64 bits
nix_get_int
Get int value
nix_get_list_byidx
Get the ix’th element of a list Owned by the GC. Use nix_gc_decref when you’re done with the pointer
nix_get_list_size
Get the length of a list
nix_get_path_string
Get path as string
nix_get_string
Get the raw string This may contain placeholders.
nix_get_type
@addtogroup value_manip Manipulating values Functions to inspect and change Nix language values, represented by nix_value. @name Getters
nix_get_typename
Get type name of value as defined in the evaluator
nix_has_attr_byname
Check if an attribute name exists on a value
nix_init_apply
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).
nix_init_bool
@}*/ /** @name 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_init_external
Set an external value
nix_init_float
Set a float
nix_init_int
Set an int
nix_init_null
Set null
nix_init_path_string
Set a path
nix_init_plugins
Loads the plugins specified in Nix’s plugin-files setting. Call this once, after calling your desired init functions and setting relevant settings.
nix_init_primop
Set primop
nix_init_string
Set a string
nix_libexpr_init
Initialize the Nix language evaluator. This function must be called at least once, at some point before constructing a EvalState for the first time. This function can be called multiple times, and is idempotent.
nix_libstore_init
Initializes the Nix store library This function should be called before creating a Store This function can be called multiple times.
nix_libstore_init_no_load_config
Like nix_libstore_init, but does not load the Nix configuration. This is useful when external configuration is not desired, such as when running unit tests.
nix_libutil_init
Initializes nix_libutil and its dependencies. This function can be called multiple times, but should be called at least once prior to any other nix function.
nix_list_builder_free
Free a list builder Does not fail.
nix_list_builder_insert
Insert bindings into a builder
nix_make_attrs
Create an attribute set from a bindings builder
nix_make_bindings_builder
Create a bindings builder
nix_make_list
Create a list from a list builder
nix_make_list_builder
Create a list builder
nix_realised_string_free
Free a realised string
nix_realised_string_get_buffer_size
Length of the string
nix_realised_string_get_buffer_start
Start of the string
nix_realised_string_get_store_path
Get a store path. The store paths are stored in an arbitrary order.
nix_realised_string_get_store_path_count
Number of realised store paths
nix_register_primop
add a primop to the builtins attribute set Only applies to States created after this call. Moves your PrimOp content into the global evaluator registry, meaning your input PrimOp pointer is no longer usable. You are free to remove your references to it, after which it will be garbage collected.
nix_set_err_msg
Set an error message on a nix context. This should be used when you want to throw an error from a PrimOp callback. All other use is internal to the API.
nix_set_string_return
Sets the contents of a nix_string_return Copies the passed string.
nix_setting_get
@defgroup settings Nix configuration settings Retrieves a setting from the nix global configuration. This function requires nix_libutil_init() to be called at least once prior to its use.
nix_setting_set
Sets a setting in the nix global configuration. Use “extra-” to append to the setting’s value. Settings only apply for new State%s. Call nix_plugins_init() when you are done with the settings to load any plugins.
nix_state_create
Create a new Nix language evaluator state For more control, use nix_eval_state_builder
nix_state_free
Frees a Nix state. Does not fail.
nix_store_copy_closure
Copy the closure of path from srcStore to dstStore.
nix_store_free
Deallocate a nix store and free any resources if not also held by other Store instances. Does not fail.
nix_store_get_storedir
get the storeDir of a Nix store, typically "/nix/store"
nix_store_get_uri
get the URI of a nix store
nix_store_get_version
get the version of a nix store. If the store doesn’t have a version (like the dummy store), returns an empty string.
nix_store_is_valid_path
Check if a StorePath is valid (i.e. that corresponding store object and its closure of references exists in the store)
nix_store_open
Open a nix store. Store instances may share state and resources behind the scenes.
nix_store_parse_path
Parse a Nix store path into a StorePath
nix_store_path_clone
Copy a StorePath
nix_store_path_free
Deallocate a StorePath Does not fail.
nix_store_path_name
Get the path name (e.g. “name” in /nix/store/…-name)
nix_store_real_path
Get the physical location of a store path A store may reside at a different location than its storeDir suggests. This situation is called a relocated store. Relocated stores are used during NixOS installation, as well as in restricted computing environments that don’t offer a writable /nix/store. Not all types of stores support this operation.
nix_store_realise
Realise a Nix store path Blocking, calls callback once for each realised output.
nix_string_realise
Realise a string context. This will
nix_value_call
Calls a Nix function with an argument.
nix_value_call_multi
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.
nix_value_decref
Decrement the garbage collector reference counter for the given object
nix_value_force
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.
nix_value_force_deep
Forces the deep evaluation of a Nix value. Recursively calls nix_value_force
nix_value_incref
Increment the garbage collector reference counter for the given nix_value. The Nix language evaluator C API keeps track of alive objects by reference counting. When you’re done with a refcounted pointer, call nix_value_decref().
nix_version_get
Retrieves the nix library version. Does not fail.

Type Aliases§

PrimOpFun
@defgroup primops Adding primops When you want to return an error, call nix_set_err_msg(context, NIX_ERR_UNKNOWN, “your error message here”).
Value
ValueType
__blkcnt64_t
__blkcnt_t
__blksize_t
__caddr_t
__clock_t
__clockid_t
__daddr_t
__dev_t
__fsblkcnt64_t
__fsblkcnt_t
__fsfilcnt64_t
__fsfilcnt_t
__fsword_t
__gid_t
__id_t
__ino64_t
__ino_t
__int8_t
__int16_t
__int32_t
__int64_t
__int_least8_t
__int_least16_t
__int_least32_t
__int_least64_t
__intmax_t
__intptr_t
__key_t
__loff_t
__mode_t
__nlink_t
__off64_t
__off_t
__pid_t
__quad_t
__rlim64_t
__rlim_t
__sig_atomic_t
__socklen_t
__ssize_t
__suseconds64_t
__suseconds_t
__syscall_slong_t
__syscall_ulong_t
__time_t
__timer_t
__u_char
__u_int
__u_long
__u_quad_t
__u_short
__uid_t
__uint8_t
__uint16_t
__uint32_t
__uint64_t
__uint_least8_t
__uint_least16_t
__uint_least32_t
__uint_least64_t
__uintmax_t
__useconds_t
int_fast8_t
int_fast16_t
int_fast32_t
int_fast64_t
int_least8_t
int_least16_t
int_least32_t
int_least64_t
intmax_t
nix_err
Type for error codes in the Nix system This type can have one of several predefined constants:
nix_get_string_callback
Called to get the value of a string owned by Nix.
uint_fast8_t
uint_fast16_t
uint_fast32_t
uint_fast64_t
uint_least8_t
uint_least16_t
uint_least32_t
uint_least64_t
uintmax_t
wchar_t