Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/libstore-c/nix_api_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,35 @@ nix_err nix_derivation_to_json(
NIXC_CATCH_ERRS
}

DerivedPath * nix_store_parse_derived_path(nix_c_context * context, Store * store, const char * path)
{
if (context)
context->last_err_code = NIX_OK;
try {
auto d = nix::SingleDerivedPath::parse(store->ptr->config, path);
return new DerivedPath{std::move(d)};
}
NIXC_CATCH_ERRS_NULL
}

void nix_derived_path_free(const DerivedPath * d)
{
delete d;
}

DerivedPath * nix_derived_path_clone(const DerivedPath * d)
{
return new DerivedPath{d->drv_path};
}

StorePath * nix_derived_path_get_store_path(nix_c_context * context, DerivedPath * d)
{
if (context)
context->last_err_code = NIX_OK;
try {
return new StorePath{d->drv_path.getBaseStorePath()};
}
NIXC_CATCH_ERRS_NULL
}

} // extern "C"
38 changes: 38 additions & 0 deletions src/libstore-c/nix_api_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ extern "C" {
typedef struct Store Store;
/** @brief Nix store path */
typedef struct StorePath StorePath;
/** @brief Nix Derived Path */
typedef struct DerivedPath DerivedPath;
/** @brief Nix Derivation */
typedef struct nix_derivation nix_derivation;

Expand Down Expand Up @@ -377,6 +379,42 @@ nix_err nix_derivation_get_outputs_and_optpaths(
nix_err nix_derivation_to_json(
nix_c_context * context, const nix_derivation * drv, nix_get_string_callback callback, void * userdata);

/**
* @brief Parse a Nix derived path into a DerivedPath
*
* @note Don't forget to free this path using nix_derived_path_free()!
* @param[out] context Optional, stores error information
* @param[in] store nix store reference
* @param[in] path Path string to parse, copied
* @return owned store path, NULL on error
*/
DerivedPath * nix_store_parse_derived_path(nix_c_context * context, Store * store, const char * path);

/**
* @brief Deallocate a `DerivedPath`
*
* Does not fail.
* @param[in] d the derived path to free
*/
void nix_derived_path_free(const DerivedPath * d);

/**
* @brief Copy a `DerivedPath`
*
* @param[in] d the derived path to copy
* @return a new `DerivedPath`
*/
DerivedPath * nix_derived_path_clone(const DerivedPath * d);

/**
* @brief Gets the store path for a derived path by realising it.
*
* @param[out] context Optional, stores error information
* @param[in] d the derived path
* @return The derivation path, NULL on error
*/
StorePath * nix_derived_path_get_store_path(nix_c_context * context, DerivedPath * d);

// cffi end
#ifdef __cplusplus
}
Expand Down
5 changes: 5 additions & 0 deletions src/libstore-c/nix_api_store_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ struct StorePath
nix::StorePath path;
};

struct DerivedPath
{
nix::SingleDerivedPath drv_path;
};

struct nix_derivation
{
nix::Derivation drv;
Expand Down