Skip to content

Commit c6a1b6c

Browse files
committed
libstore-c: Organize API into separate headers
Move StorePath and Derivation declarations to their own headers in a backwards compatible way: - Created nix_api_store/store_path.h for StorePath operations - Created nix_api_store/derivation.h for Derivation operations - Main nix_api_store.h includes both headers for backwards compatibility This reorganization improves modularity and hopefully makes the API easier to navigate.
1 parent 5446d63 commit c6a1b6c

File tree

4 files changed

+97
-37
lines changed

4 files changed

+97
-37
lines changed

src/libstore-c/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ include_dirs = [ include_directories('.') ]
3535

3636
headers = files(
3737
'nix_api_store.h',
38+
'nix_api_store/derivation.h',
39+
'nix_api_store/store_path.h',
3840
)
3941

4042
# TODO don't install this once tests don't use it and/or move the header into `libstore`, non-`c`

src/libstore-c/nix_api_store.h

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
*/
1313

1414
#include "nix_api_util.h"
15+
#include "nix_api_store/store_path.h"
16+
#include "nix_api_store/derivation.h"
1517
#include <stdbool.h>
1618

1719
#ifdef __cplusplus
@@ -21,10 +23,6 @@ extern "C" {
2123

2224
/** @brief Reference to a Nix store */
2325
typedef struct Store Store;
24-
/** @brief Nix store path */
25-
typedef struct StorePath StorePath;
26-
/** @brief Nix Derivation */
27-
typedef struct nix_derivation nix_derivation;
2826

2927
/**
3028
* @brief Initializes the Nix store library
@@ -108,7 +106,7 @@ nix_err
108106
nix_store_get_storedir(nix_c_context * context, Store * store, nix_get_string_callback callback, void * user_data);
109107

110108
/**
111-
* @brief Parse a Nix store path into a StorePath
109+
* @brief Parse a Nix store path that includes the store dir into a StorePath
112110
*
113111
* @note Don't forget to free this path using nix_store_path_free()!
114112
* @param[out] context Optional, stores error information
@@ -118,30 +116,6 @@ nix_store_get_storedir(nix_c_context * context, Store * store, nix_get_string_ca
118116
*/
119117
StorePath * nix_store_parse_path(nix_c_context * context, Store * store, const char * path);
120118

121-
/**
122-
* @brief Get the path name (e.g. "name" in /nix/store/...-name)
123-
*
124-
* @param[in] store_path the path to get the name from
125-
* @param[in] callback called with the name
126-
* @param[in] user_data arbitrary data, passed to the callback when it's called.
127-
*/
128-
void nix_store_path_name(const StorePath * store_path, nix_get_string_callback callback, void * user_data);
129-
130-
/**
131-
* @brief Copy a StorePath
132-
*
133-
* @param[in] p the path to copy
134-
* @return a new StorePath
135-
*/
136-
StorePath * nix_store_path_clone(const StorePath * p);
137-
138-
/** @brief Deallocate a StorePath
139-
*
140-
* Does not fail.
141-
* @param[in] p the path to free
142-
*/
143-
void nix_store_path_free(StorePath * p);
144-
145119
/**
146120
* @brief Check if a StorePath is valid (i.e. that corresponding store object and its closure of references exists in
147121
* the store)
@@ -229,14 +203,6 @@ nix_derivation * nix_derivation_from_json(nix_c_context * context, Store * store
229203
*/
230204
StorePath * nix_add_derivation(nix_c_context * context, Store * store, nix_derivation * derivation);
231205

232-
/**
233-
* @brief Deallocate a `nix_derivation`
234-
*
235-
* Does not fail.
236-
* @param[in] drv the derivation to free
237-
*/
238-
void nix_derivation_free(nix_derivation * drv);
239-
240206
/**
241207
* @brief Copy the closure of `path` from `srcStore` to `dstStore`.
242208
*
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef NIX_API_STORE_DERIVATION_H
2+
#define NIX_API_STORE_DERIVATION_H
3+
/**
4+
* @defgroup libstore_derivation Derivation
5+
* @ingroup libstore
6+
* @brief Derivation operations that don't require a Store
7+
* @{
8+
*/
9+
/** @file
10+
* @brief Derivation operations
11+
*/
12+
13+
#include "nix_api_util.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
// cffi start
19+
20+
/** @brief Nix Derivation */
21+
typedef struct nix_derivation nix_derivation;
22+
23+
/**
24+
* @brief Deallocate a `nix_derivation`
25+
*
26+
* Does not fail.
27+
* @param[in] drv the derivation to free
28+
*/
29+
void nix_derivation_free(nix_derivation * drv);
30+
31+
// cffi end
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
/**
36+
* @}
37+
*/
38+
#endif // NIX_API_STORE_DERIVATION_H
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef NIX_API_STORE_STORE_PATH_H
2+
#define NIX_API_STORE_STORE_PATH_H
3+
/**
4+
* @defgroup libstore_storepath StorePath
5+
* @ingroup libstore
6+
* @brief Store path operations that don't require a Store
7+
* @{
8+
*/
9+
/** @file
10+
* @brief Store path operations
11+
*/
12+
13+
#include "nix_api_util.h"
14+
15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
// cffi start
19+
20+
/** @brief Nix store path */
21+
typedef struct StorePath StorePath;
22+
23+
/**
24+
* @brief Copy a StorePath
25+
*
26+
* @param[in] p the path to copy
27+
* @return a new StorePath
28+
*/
29+
StorePath * nix_store_path_clone(const StorePath * p);
30+
31+
/** @brief Deallocate a StorePath
32+
*
33+
* Does not fail.
34+
* @param[in] p the path to free
35+
*/
36+
void nix_store_path_free(StorePath * p);
37+
38+
/**
39+
* @brief Get the path name (e.g. "<name>" in /nix/store/<hash>-<name>)
40+
*
41+
* @param[in] store_path the path to get the name from
42+
* @param[in] callback called with the name
43+
* @param[in] user_data arbitrary data, passed to the callback when it's called.
44+
*/
45+
void nix_store_path_name(const StorePath * store_path, nix_get_string_callback callback, void * user_data);
46+
47+
// cffi end
48+
#ifdef __cplusplus
49+
}
50+
#endif
51+
/**
52+
* @}
53+
*/
54+
#endif // NIX_API_STORE_STORE_PATH_H

0 commit comments

Comments
 (0)