44 * @brief Bindings to the Nix language evaluator
55 *
66 * See *[Embedding the Nix Evaluator](@ref nix_evaluator_example)* for an example.
7- * @{
87 */
98/** @file
109 * @brief Main entry for the libexpr C bindings
1110 */
11+ /** @defgroup libexpr_init Initialization
12+ * @ingroup libexpr
13+ * @{
14+ */
1215
1316#include "nix_api_store.h"
1417#include "nix_api_util.h"
@@ -45,7 +48,10 @@ typedef struct nix_eval_state_builder nix_eval_state_builder;
4548 */
4649typedef struct EvalState EvalState ; // nix::EvalState
4750
51+ /** @} */
52+
4853/** @brief A Nix language value, or thunk that may evaluate to a value.
54+ * @ingroup value
4955 *
5056 * Values are the primary objects manipulated in the Nix language.
5157 * They are considered to be immutable from a user's perspective, but the process of evaluating a value changes its
@@ -56,7 +62,8 @@ typedef struct EvalState EvalState; // nix::EvalState
5662 *
5763 * The evaluator manages its own memory, but your use of the C API must follow the reference counting rules.
5864 *
59- * @see value_manip
65+ * @struct nix_value
66+ * @see value_create, value_extract
6067 * @see nix_value_incref, nix_value_decref
6168 */
6269typedef struct nix_value nix_value ;
@@ -65,6 +72,7 @@ NIX_DEPRECATED("use nix_value instead") typedef nix_value Value;
6572// Function prototypes
6673/**
6774 * @brief Initialize the Nix language evaluator.
75+ * @ingroup libexpr_init
6876 *
6977 * This function must be called at least once,
7078 * at some point before constructing a EvalState for the first time.
@@ -77,6 +85,7 @@ nix_err nix_libexpr_init(nix_c_context * context);
7785
7886/**
7987 * @brief Parses and evaluates a Nix expression from a string.
88+ * @ingroup value_create
8089 *
8190 * @param[out] context Optional, stores error information
8291 * @param[in] state The state of the evaluation.
@@ -93,6 +102,7 @@ nix_err nix_expr_eval_from_string(
93102
94103/**
95104 * @brief Calls a Nix function with an argument.
105+ * @ingroup value_create
96106 *
97107 * @param[out] context Optional, stores error information
98108 * @param[in] state The state of the evaluation.
@@ -107,6 +117,7 @@ nix_err nix_value_call(nix_c_context * context, EvalState * state, nix_value * f
107117
108118/**
109119 * @brief Calls a Nix function with multiple arguments.
120+ * @ingroup value_create
110121 *
111122 * Technically these are functions that return functions. It is common for Nix
112123 * functions to be curried, so this function is useful for calling them.
@@ -126,10 +137,12 @@ nix_err nix_value_call_multi(
126137
127138/**
128139 * @brief Calls a Nix function with multiple arguments.
140+ * @ingroup value_create
129141 *
130142 * Technically these are functions that return functions. It is common for Nix
131143 * functions to be curried, so this function is useful for calling them.
132144 *
145+ * @def NIX_VALUE_CALL
133146 * @param[out] context Optional, stores error information
134147 * @param[in] state The state of the evaluation.
135148 * @param[out] value The result of the function call.
@@ -147,6 +160,7 @@ nix_err nix_value_call_multi(
147160
148161/**
149162 * @brief Forces the evaluation of a Nix value.
163+ * @ingroup value_create
150164 *
151165 * The Nix interpreter is lazy, and not-yet-evaluated values can be
152166 * of type NIX_TYPE_THUNK instead of their actual value.
@@ -180,18 +194,20 @@ nix_err nix_value_force_deep(nix_c_context * context, EvalState * state, nix_val
180194
181195/**
182196 * @brief Create a new nix_eval_state_builder
197+ * @ingroup libexpr_init
183198 *
184199 * The settings are initialized to their default value.
185200 * Values can be sourced elsewhere with nix_eval_state_builder_load.
186201 *
187202 * @param[out] context Optional, stores error information
188203 * @param[in] store The Nix store to use.
189- * @return A new nix_eval_state_builder or NULL on failure.
204+ * @return A new nix_eval_state_builder or NULL on failure. Call nix_eval_state_builder_free() when you're done.
190205 */
191206nix_eval_state_builder * nix_eval_state_builder_new (nix_c_context * context , Store * store );
192207
193208/**
194209 * @brief Read settings from the ambient environment
210+ * @ingroup libexpr_init
195211 *
196212 * Settings are sourced from environment variables and configuration files,
197213 * as documented in the Nix manual.
@@ -204,6 +220,7 @@ nix_err nix_eval_state_builder_load(nix_c_context * context, nix_eval_state_buil
204220
205221/**
206222 * @brief Set the lookup path for `<...>` expressions
223+ * @ingroup libexpr_init
207224 *
208225 * @param[in] context Optional, stores error information
209226 * @param[in] builder The builder to modify.
@@ -214,18 +231,21 @@ nix_err nix_eval_state_builder_set_lookup_path(
214231
215232/**
216233 * @brief Create a new Nix language evaluator state
234+ * @ingroup libexpr_init
217235 *
218- * Remember to nix_eval_state_builder_free after building the state.
236+ * The builder becomes unusable after this call. Remember to call nix_eval_state_builder_free()
237+ * after building the state.
219238 *
220239 * @param[out] context Optional, stores error information
221240 * @param[in] builder The builder to use and free
222- * @return A new Nix state or NULL on failure.
241+ * @return A new Nix state or NULL on failure. Call nix_state_free() when you're done.
223242 * @see nix_eval_state_builder_new, nix_eval_state_builder_free
224243 */
225244EvalState * nix_eval_state_build (nix_c_context * context , nix_eval_state_builder * builder );
226245
227246/**
228247 * @brief Free a nix_eval_state_builder
248+ * @ingroup libexpr_init
229249 *
230250 * Does not fail.
231251 *
@@ -235,19 +255,21 @@ void nix_eval_state_builder_free(nix_eval_state_builder * builder);
235255
236256/**
237257 * @brief Create a new Nix language evaluator state
258+ * @ingroup libexpr_init
238259 *
239260 * For more control, use nix_eval_state_builder
240261 *
241262 * @param[out] context Optional, stores error information
242263 * @param[in] lookupPath Null-terminated array of strings corresponding to entries in NIX_PATH.
243264 * @param[in] store The Nix store to use.
244- * @return A new Nix state or NULL on failure.
265+ * @return A new Nix state or NULL on failure. Call nix_state_free() when you're done.
245266 * @see nix_state_builder_new
246267 */
247268EvalState * nix_state_create (nix_c_context * context , const char * * lookupPath , Store * store );
248269
249270/**
250271 * @brief Frees a Nix state.
272+ * @ingroup libexpr_init
251273 *
252274 * Does not fail.
253275 *
@@ -256,6 +278,7 @@ EvalState * nix_state_create(nix_c_context * context, const char ** lookupPath,
256278void nix_state_free (EvalState * state );
257279
258280/** @addtogroup GC
281+ * @ingroup libexpr
259282 * @brief Reference counting and garbage collector operations
260283 *
261284 * The Nix language evaluator uses a garbage collector. To ease C interop, we implement
@@ -286,6 +309,9 @@ nix_err nix_gc_incref(nix_c_context * context, const void * object);
286309/**
287310 * @brief Decrement the garbage collector reference counter for the given object
288311 *
312+ * @deprecated We are phasing out the general nix_gc_decref() in favor of type-specified free functions, such as
313+ * nix_value_decref().
314+ *
289315 * We also provide typed `nix_*_decref` functions, which are
290316 * - safer to use
291317 * - easier to integrate when deriving bindings
@@ -314,12 +340,11 @@ void nix_gc_now();
314340 */
315341void nix_gc_register_finalizer (void * obj , void * cd , void (* finalizer )(void * obj , void * cd ));
316342
317- /** @} */
343+ /** @} */ // doxygen group GC
344+
318345// cffi end
319346#ifdef __cplusplus
320347}
321348#endif
322349
323- /** @} */
324-
325350#endif // NIX_API_EXPR_H
0 commit comments