Rename crates nix- -> nix-bindings-

This way, the crates can be published without interfering with
potential future non-bindings `nix-` crates, if Nix proper wants to
have native rust code, for instance.
This commit is contained in:
Robert Hensing 2025-10-04 02:44:22 +02:00
parent 4b13929db3
commit b3171585d1
30 changed files with 209 additions and 1853 deletions

1804
rust/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,10 @@
[workspace]
members = [
"nix-c-raw",
"nix-expr",
"nix-fetchers",
"nix-flake",
"nix-store",
"nix-util",
"nix-bindings-bindgen-raw",
"nix-bindings-expr",
"nix-bindings-fetchers",
"nix-bindings-flake",
"nix-bindings-store",
"nix-bindings-util",
]
resolver = "2"

View file

@ -1,5 +1,5 @@
[package]
name = "nix-c-raw"
name = "nix-bindings-bindgen-raw"
version = "0.1.0"
edition = "2021"
build = "build.rs"

View file

@ -1,8 +1,8 @@
# nix-c-raw
# nix-bindings-bindgen-raw
This crate contains generated bindings for the Nix C API.
**You should not have to use this crate directly,** and so you should probably not add it to your dependencies.
Instead, use the `nix-util`, `nix-store` and `nix-expr` crates, which _should_ be sufficient.
Instead, use the `nix-bindings-util`, `nix-bindings-store` and `nix-bindings-expr` crates, which _should_ be sufficient.
## Design

View file

@ -0,0 +1,18 @@
[package]
name = "nix-bindings-expr"
version = "0.1.0"
edition = "2021"
license = "LGPL-2.1"
[lib]
path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-bindings-store = { path = "../nix-bindings-store" }
nix-bindings-util = { path = "../nix-bindings-util" }
nix-bindings-bindgen-raw = { path = "../nix-bindings-bindgen-raw" }
lazy_static = "1.4"
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"

View file

@ -17,8 +17,8 @@
//! Create an [`EvalState`] using [`EvalState::new`] or [`EvalStateBuilder`] for advanced configuration:
//!
//! ```rust
//! # use nix_expr::eval_state::{EvalState, EvalStateBuilder, test_init, gc_register_my_thread};
//! # use nix_store::store::Store;
//! # use nix_bindings_expr::eval_state::{EvalState, EvalStateBuilder, test_init, gc_register_my_thread};
//! # use nix_bindings_store::store::Store;
//! # use std::collections::HashMap;
//! # fn example() -> anyhow::Result<()> {
//! # test_init(); let guard = gc_register_my_thread()?;
@ -71,7 +71,7 @@
//! Before using [`EvalState`] in a thread, register it with the (process memory) garbage collector:
//!
//! ```rust,no_run
//! # use nix_expr::eval_state::{init, gc_register_my_thread, test_init};
//! # use nix_bindings_expr::eval_state::{init, gc_register_my_thread, test_init};
//! # fn example() -> anyhow::Result<()> {
//! # test_init(); // Use test_init() in tests
//! init()?; // Initialize Nix library
@ -92,8 +92,8 @@
//! ## Examples
//!
//! ```rust
//! use nix_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
//! use nix_store::store::Store;
//! use nix_bindings_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
//! use nix_bindings_store::store::Store;
//! use std::collections::HashMap;
//!
//! # fn main() -> anyhow::Result<()> {
@ -134,12 +134,12 @@ use anyhow::Context as _;
use anyhow::{bail, Result};
use cstr::cstr;
use lazy_static::lazy_static;
use nix_c_raw as raw;
use nix_store::path::StorePath;
use nix_store::store::{Store, StoreWeak};
use nix_util::context::Context;
use nix_util::string_return::{callback_get_result_string, callback_get_result_string_data};
use nix_util::{check_call, check_call_opt_key, result_string_init};
use nix_bindings_bindgen_raw as raw;
use nix_bindings_store::path::StorePath;
use nix_bindings_store::store::{Store, StoreWeak};
use nix_bindings_util::context::Context;
use nix_bindings_util::string_return::{callback_get_result_string, callback_get_result_string_data};
use nix_bindings_util::{check_call, check_call_opt_key, result_string_init};
use std::ffi::{c_char, CString};
use std::iter::FromIterator;
use std::os::raw::c_uint;
@ -162,7 +162,7 @@ pub fn init() -> Result<()> {
Ok(_) => Ok(()),
Err(e) => {
// Couldn't just clone the error, so we have to print it here.
Err(anyhow::format_err!("nix_expr::init error: {}", e))
Err(anyhow::format_err!("nix_bindings_expr::init error: {}", e))
}
}
}
@ -225,8 +225,8 @@ impl Drop for EvalStateRef {
/// # Examples
///
/// ```rust
/// # use nix_expr::eval_state::{EvalState, EvalStateBuilder, test_init, gc_register_my_thread};
/// # use nix_store::store::Store;
/// # use nix_bindings_expr::eval_state::{EvalState, EvalStateBuilder, test_init, gc_register_my_thread};
/// # use nix_bindings_store::store::Store;
/// # use std::collections::HashMap;
/// # fn example() -> anyhow::Result<()> {
/// # test_init();
@ -369,9 +369,9 @@ impl EvalState {
/// # Examples
///
/// ```
/// # use nix_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// use nix_store::store::Store;
/// use nix_expr::value::Value;
/// # use nix_bindings_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// use nix_bindings_store::store::Store;
/// use nix_bindings_expr::value::Value;
/// use std::collections::HashMap;
///
/// # fn main() -> anyhow::Result<()> {
@ -474,8 +474,8 @@ impl EvalState {
/// # Examples
///
/// ```rust
/// # use nix_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// # use nix_store::store::Store;
/// # use nix_bindings_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// # use nix_bindings_store::store::Store;
/// # use std::collections::HashMap;
/// # fn example() -> anyhow::Result<()> {
/// # test_init();
@ -529,9 +529,9 @@ impl EvalState {
/// # Examples
///
/// ```rust,no_run
/// # use nix_expr::value::Value;
/// # use nix_bindings_expr::value::Value;
/// # use std::collections::{VecDeque, LinkedList};
/// # fn example(es: &mut nix_expr::eval_state::EvalState, list_value: &Value) -> anyhow::Result<()> {
/// # fn example(es: &mut nix_bindings_expr::eval_state::EvalState, list_value: &Value) -> anyhow::Result<()> {
/// let vec: Vec<Value> = es.require_list_strict(&list_value)?;
/// let deque: VecDeque<Value> = es.require_list_strict(&list_value)?;
/// let linked_list = es.require_list_strict::<LinkedList<Value>>(&list_value)?;
@ -942,8 +942,8 @@ impl EvalState {
/// # Examples
///
/// ```rust
/// # use nix_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// # use nix_store::store::Store;
/// # use nix_bindings_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// # use nix_bindings_store::store::Store;
/// # use std::collections::HashMap;
/// # fn example() -> anyhow::Result<()> {
/// # test_init();
@ -1043,8 +1043,8 @@ impl EvalState {
/// # Examples
///
/// ```rust
/// # use nix_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// # use nix_store::store::Store;
/// # use nix_bindings_expr::eval_state::{EvalState, test_init, gc_register_my_thread};
/// # use nix_bindings_store::store::Store;
/// # use std::collections::HashMap;
/// # fn example() -> anyhow::Result<()> {
/// # test_init();
@ -1211,18 +1211,18 @@ pub fn test_init() {
// would cause the test suite to reinvokes itself, causing an infinite loop.
// While _NIX_TEST_NO_SANDBOX=1 should prevent this, we may also set the
// build hook to "" to prevent this.
nix_util::settings::set("build-hook", "").unwrap();
nix_bindings_util::settings::set("build-hook", "").unwrap();
// When testing in the sandbox, the default build dir would be a parent of the storeDir,
// which causes an error. So we set a custom build dir here.
// Only available on linux
if cfg!(target_os = "linux") {
nix_util::settings::set("sandbox-build-dir", "/custom-build-dir-for-test").unwrap();
nix_bindings_util::settings::set("sandbox-build-dir", "/custom-build-dir-for-test").unwrap();
}
std::env::set_var("_NIX_TEST_NO_SANDBOX", "1");
// The tests run offline
nix_util::settings::set("substituters", "").unwrap();
nix_bindings_util::settings::set("substituters", "").unwrap();
}
#[cfg(test)]

View file

@ -1,8 +1,8 @@
use crate::eval_state::{EvalState, EvalStateWeak};
use crate::value::Value;
use anyhow::Result;
use nix_c_raw as raw;
use nix_util::check_call;
use nix_bindings_bindgen_raw as raw;
use nix_bindings_util::check_call;
use std::ffi::{c_int, c_void, CStr, CString};
use std::mem::ManuallyDrop;
use std::ptr::{null, null_mut};

View file

@ -1,7 +1,7 @@
pub mod __private;
use nix_c_raw as raw;
use nix_util::{check_call, context::Context};
use nix_bindings_bindgen_raw as raw;
use nix_bindings_util::{check_call, context::Context};
use std::ptr::{null_mut, NonNull};
// TODO: test: cloning a thunk does not duplicate the evaluation.

View file

@ -1,6 +1,6 @@
//! Functions that are relevant for other bindings modules, but normally not end users.
use super::Value;
use nix_c_raw as raw;
use nix_bindings_bindgen_raw as raw;
/// See [Value::new].
pub unsafe fn raw_value_new(ptr: *mut raw::Value) -> Value {

View file

@ -0,0 +1,17 @@
[package]
name = "nix-bindings-fetchers"
version = "0.1.0"
edition = "2021"
license = "LGPL-2.1"
[lib]
path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-bindings-store = { path = "../nix-bindings-store" }
nix-bindings-util = { path = "../nix-bindings-util" }
nix-bindings-bindgen-raw = { path = "../nix-bindings-bindgen-raw" }
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"

View file

@ -1,6 +1,6 @@
use anyhow::{Context as _, Result};
use nix_c_raw as raw;
use nix_util::context::{self, Context};
use nix_bindings_bindgen_raw as raw;
use nix_bindings_util::context::{self, Context};
use std::ptr::NonNull;
pub struct FetchersSettings {

View file

@ -0,0 +1,20 @@
[package]
name = "nix-bindings-flake"
version = "0.1.0"
edition = "2021"
license = "LGPL-2.1"
[lib]
path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-bindings-expr = { path = "../nix-bindings-expr" }
nix-bindings-fetchers = { path = "../nix-bindings-fetchers" }
nix-bindings-store = { path = "../nix-bindings-store" }
nix-bindings-util = { path = "../nix-bindings-util" }
nix-bindings-bindgen-raw = { path = "../nix-bindings-bindgen-raw" }
lazy_static = "1.4"
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"

View file

@ -1,10 +1,10 @@
use std::{ffi::CString, os::raw::c_char, ptr::NonNull};
use anyhow::{Context as _, Result};
use nix_c_raw as raw;
use nix_expr::eval_state::EvalState;
use nix_fetchers::FetchersSettings;
use nix_util::{
use nix_bindings_bindgen_raw as raw;
use nix_bindings_expr::eval_state::EvalState;
use nix_bindings_fetchers::FetchersSettings;
use nix_bindings_util::{
context::{self, Context},
result_string_init,
string_return::{callback_get_result_string, callback_get_result_string_data},
@ -29,7 +29,7 @@ impl FlakeSettings {
}
fn add_to_eval_state_builder(
&self,
builder: &mut nix_expr::eval_state::EvalStateBuilder,
builder: &mut nix_bindings_expr::eval_state::EvalStateBuilder,
) -> Result<()> {
let mut ctx = Context::new();
unsafe {
@ -45,14 +45,14 @@ impl FlakeSettings {
pub trait EvalStateBuilderExt {
/// Configures the eval state to provide flakes features such as `builtins.getFlake`.
fn flakes(self, settings: &FlakeSettings) -> Result<nix_expr::eval_state::EvalStateBuilder>;
fn flakes(self, settings: &FlakeSettings) -> Result<nix_bindings_expr::eval_state::EvalStateBuilder>;
}
impl EvalStateBuilderExt for nix_expr::eval_state::EvalStateBuilder {
impl EvalStateBuilderExt for nix_bindings_expr::eval_state::EvalStateBuilder {
/// Configures the eval state to provide flakes features such as `builtins.getFlake`.
fn flakes(
mut self,
settings: &FlakeSettings,
) -> Result<nix_expr::eval_state::EvalStateBuilder> {
) -> Result<nix_bindings_expr::eval_state::EvalStateBuilder> {
settings.add_to_eval_state_builder(&mut self)?;
Ok(self)
}
@ -239,7 +239,7 @@ impl LockedFlake {
&self,
flake_settings: &FlakeSettings,
eval_state: &mut EvalState,
) -> Result<nix_expr::value::Value> {
) -> Result<nix_bindings_expr::value::Value> {
let mut ctx = Context::new();
unsafe {
let r = context::check_call!(raw::locked_flake_get_output_attrs(
@ -248,15 +248,15 @@ impl LockedFlake {
eval_state.raw_ptr(),
self.ptr.as_ptr()
))?;
Ok(nix_expr::value::__private::raw_value_new(r))
Ok(nix_bindings_expr::value::__private::raw_value_new(r))
}
}
}
#[cfg(test)]
mod tests {
use nix_expr::eval_state::{gc_register_my_thread, EvalStateBuilder};
use nix_store::store::Store;
use nix_bindings_expr::eval_state::{gc_register_my_thread, EvalStateBuilder};
use nix_bindings_store::store::Store;
use super::*;
use std::sync::Once;
@ -267,7 +267,7 @@ mod tests {
// Only set experimental-features once to minimize the window where
// concurrent Nix operations might read the setting while it's being modified
INIT.call_once(|| {
nix_util::settings::set("experimental-features", "flakes").unwrap();
nix_bindings_util::settings::set("experimental-features", "flakes").unwrap();
});
}

View file

@ -1,5 +1,5 @@
[package]
name = "nix-store"
name = "nix-bindings-store"
version = "0.1.0"
edition = "2021"
build = "build.rs"
@ -10,8 +10,8 @@ path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-util = { path = "../nix-util" }
nix-c-raw = { path = "../nix-c-raw" }
nix-bindings-util = { path = "../nix-bindings-util" }
nix-bindings-bindgen-raw = { path = "../nix-bindings-bindgen-raw" }
lazy_static = "1.4"
[build-dependencies]

View file

@ -1,8 +1,8 @@
use std::ptr::NonNull;
use anyhow::Result;
use nix_c_raw as raw;
use nix_util::{
use nix_bindings_bindgen_raw as raw;
use nix_bindings_util::{
result_string_init,
string_return::{callback_get_result_string, callback_get_result_string_data},
};
@ -60,7 +60,7 @@ impl StorePath {
/// # Safety
///
/// This function is unsafe because it returns a raw pointer. The caller must ensure that the pointer is not used beyond the lifetime of this `StorePath`.
pub unsafe fn as_ptr(&self) -> *mut nix_c_raw::StorePath {
pub unsafe fn as_ptr(&self) -> *mut raw::StorePath {
self.raw.as_ptr()
}
}

View file

@ -1,9 +1,9 @@
use anyhow::{bail, Error, Result};
use lazy_static::lazy_static;
use nix_c_raw as raw;
use nix_util::context::Context;
use nix_util::string_return::{callback_get_result_string, callback_get_result_string_data};
use nix_util::{check_call, result_string_init};
use nix_bindings_bindgen_raw as raw;
use nix_bindings_util::context::Context;
use nix_bindings_util::string_return::{callback_get_result_string, callback_get_result_string_data};
use nix_bindings_util::{check_call, result_string_init};
use std::collections::HashMap;
use std::ffi::{c_char, CString};
use std::ptr::null_mut;

View file

@ -1,5 +1,5 @@
[package]
name = "nix-util"
name = "nix-bindings-util"
version = "0.1.0"
edition = "2021"
license = "LGPL-2.1"
@ -9,5 +9,5 @@ path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-c-raw = { path = "../nix-c-raw" }
nix-bindings-bindgen-raw = { path = "../nix-bindings-bindgen-raw" }
ctor = "0.2"

View file

@ -1,10 +1,10 @@
use anyhow::{bail, Result};
use nix_c_raw as raw;
use nix_bindings_bindgen_raw as raw;
use std::os::raw::c_char;
use std::ptr::null_mut;
use std::ptr::NonNull;
/// A context for error handling, when interacting directly with the generated bindings for the C API in [nix_c_raw].
/// A context for error handling, when interacting directly with the generated bindings for the C API in [nix_bindings_bindgen_raw].
///
/// The `nix-store` and `nix-expr` libraries that consume this type internally store a private context in their `EvalState` and `Store` structs to avoid allocating a new context for each operation. The state of a context is irrelevant when used correctly (e.g. with [check_call!]), so it's safe to reuse, and safe to allocate more contexts in methods such as [Clone::clone].
pub struct Context {

View file

@ -1,5 +1,5 @@
use anyhow::Result;
use nix_c_raw as raw;
use nix_bindings_bindgen_raw as raw;
use std::sync::Mutex;
use crate::{

View file

@ -52,9 +52,9 @@ macro_rules! result_string_init {
#[cfg(test)]
mod tests {
use super::*;
use nix_c_raw as raw;
use nix_bindings_bindgen_raw as raw;
/// Typecheck the function signature against the generated bindings in nix_c_raw.
/// Typecheck the function signature against the generated bindings in nix_bindings_bindgen_raw.
static _CALLBACK_GET_RESULT_STRING: raw::get_string_callback = Some(callback_get_result_string);
#[test]

View file

@ -1,18 +0,0 @@
[package]
name = "nix-expr"
version = "0.1.0"
edition = "2021"
license = "LGPL-2.1"
[lib]
path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-store = { path = "../nix-store" }
nix-util = { path = "../nix-util" }
nix-c-raw = { path = "../nix-c-raw" }
lazy_static = "1.4"
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"

View file

@ -1,17 +0,0 @@
[package]
name = "nix-fetchers"
version = "0.1.0"
edition = "2021"
license = "LGPL-2.1"
[lib]
path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-store = { path = "../nix-store" }
nix-util = { path = "../nix-util" }
nix-c-raw = { path = "../nix-c-raw" }
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"

View file

@ -1,20 +0,0 @@
[package]
name = "nix-flake"
version = "0.1.0"
edition = "2021"
license = "LGPL-2.1"
[lib]
path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
nix-expr = { path = "../nix-expr" }
nix-fetchers = { path = "../nix-fetchers" }
nix-store = { path = "../nix-store" }
nix-util = { path = "../nix-util" }
nix-c-raw = { path = "../nix-c-raw" }
lazy_static = "1.4"
ctor = "0.2"
tempfile = "3.10"
cstr = "0.2"