Nix 2.34.6
Nix, the purely functional package manager: C API (experimental)
Loading...
Searching...
No Matches
PrimOps and Builtins

Data Structures

struct  PrimOp
 PrimOp function. More...

Typedefs

typedef void(* PrimOpFun) (void *user_data, nix_c_context *context, EvalState *state, nix_value **args, nix_value *ret)
 Function pointer for primops.

Functions

PrimOpnix_alloc_primop (nix_c_context *context, PrimOpFun fun, int arity, const char *name, const char **args, const char *doc, void *user_data)
 Allocate a PrimOp.
nix_err nix_register_primop (nix_c_context *context, PrimOp *primOp)
 add a primop to the builtins attribute set

Detailed Description

Typedef Documentation

◆ PrimOpFun

typedef void(* PrimOpFun) (void *user_data, nix_c_context *context, EvalState *state, nix_value **args, nix_value *ret)

Function pointer for primops.

When you want to return an error, call nix_set_err_msg(context, NIX_ERR_UNKNOWN, "your error message here").

Parameters
[in]user_dataArbitrary data that was initially supplied to nix_alloc_primop
[out]contextStores error information.
[in]stateEvaluator state
[in]argslist of arguments. Note that these can be thunks and should be forced using nix_value_force before use.
[out]retreturn value
See also
nix_alloc_primop, nix_init_primop

Function Documentation

◆ nix_alloc_primop()

PrimOp * nix_alloc_primop ( nix_c_context * context,
PrimOpFun fun,
int arity,
const char * name,
const char ** args,
const char * doc,
void * user_data )

Allocate a PrimOp.

Call nix_gc_decref() when you're done with the returned PrimOp.

Parameters
[out]contextOptional, stores error information
[in]funcallback
[in]arityexpected number of function arguments
[in]namefunction name
[in]argsarray of argument names, NULL-terminated
[in]docoptional, documentation for this primop
[in]user_dataoptional, arbitrary data, passed to the callback when it's called
Returns
primop, or null in case of errors
See also
nix_init_primop

◆ nix_register_primop()

nix_err nix_register_primop ( nix_c_context * context,
PrimOp * 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 becomes invalid. The PrimOp must not be used with nix_init_primop() before or after this call, as this would cause undefined behavior. You must call nix_gc_decref() on the original PrimOp pointer after this call to release your reference.

Parameters
[out]contextOptional, stores error information
[in]primOpPrimOp to register
Returns
error code, NIX_OK on success