diff --git a/nixide/Cargo.toml b/nixide/Cargo.toml index 6a64ced..b9a6405 100644 --- a/nixide/Cargo.toml +++ b/nixide/Cargo.toml @@ -15,8 +15,8 @@ path = "src/lib.rs" [features] default = [] store = ["nixide-sys/nix-store-c"] -exprs = ["store", "nixide-sys/nix-expr-c"] -flakes = ["store", "nixide-sys/nix-flake-c", "nixide-sys/nix-fetchers-c"] +expr = ["store", "nixide-sys/nix-expr-c"] +flake = ["store", "nixide-sys/nix-flake-c", "nixide-sys/nix-fetchers-c"] [dependencies] libc = "0.2.183" diff --git a/nixide/src/expr/evalstatebuilder.rs b/nixide/src/expr/evalstatebuilder.rs index 1c6d34c..6163ee5 100644 --- a/nixide/src/expr/evalstatebuilder.rs +++ b/nixide/src/expr/evalstatebuilder.rs @@ -3,8 +3,6 @@ use std::ptr::{self, NonNull}; use std::sync::Arc; use super::EvalState; -#[cfg(feature = "flakes")] -use crate::FlakeSettings; use crate::Store; use crate::errors::{ErrorContext, NixideResult}; use crate::sys; @@ -67,6 +65,11 @@ impl EvalStateBuilder { /// /// Returns an error if the evaluation state cannot be built. pub fn build(self) -> NixideResult { + // Load configuration first + wrap::nix_fn!(|ctx: &ErrorContext| unsafe { + sys::nix_eval_state_builder_load(ctx.as_ptr(), self.as_ptr()) + })?; + // Build the state let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe { sys::nix_eval_state_build(ctx.as_ptr(), self.as_ptr()) @@ -76,39 +79,19 @@ impl EvalStateBuilder { } // XXX: TODO - #[cfg(feature = "flakes")] - fn set_flake_settings(self, settings: FlakeSettings) -> NixideResult { - wrap::nix_fn!(|ctx: &ErrorContext| unsafe { - sys::nix_flake_settings_add_to_eval_state_builder( - ctx.as_ptr(), - settings.as_ptr(), - self.as_ptr(), - ); - })?; - - Ok(self) - } - - fn load_ambient_settings(self) -> NixideResult { - wrap::nix_fn!(|ctx: &ErrorContext| unsafe { - sys::nix_eval_state_builder_load(ctx.as_ptr(), self.as_ptr()); - })?; - - Ok(self) - } + // fn set_flake_settings(FlakeSettings) { } fn set_lookup_path>(self, paths: Vec

) -> NixideResult { let paths_len = paths.len(); let paths_capacity = paths.capacity(); - // XXX: TODO: use the `AsCArray` trait instead let mut ptrs: Vec<*const c_char> = paths .into_iter() .map(|p| { CString::new(p.as_ref()) .unwrap_or_else(|err| { panic_issue_call_failed!( - "given string {} contains a NUL byte ({})", + "Given string {} contains a NUL byte ({})", p.as_ref(), err ) @@ -128,7 +111,6 @@ impl EvalStateBuilder { }) .map(|()| self); - // ensure all allocated memory is dropped unsafe { Vec::from_raw_parts(ptr, paths_len, paths_capacity) .into_iter() diff --git a/nixide/src/flake/flake_settings.rs b/nixide/src/flake/flake_settings.rs index 3ef46da..a16d68b 100644 --- a/nixide/src/flake/flake_settings.rs +++ b/nixide/src/flake/flake_settings.rs @@ -1,6 +1,6 @@ use std::ptr::NonNull; -use crate::errors::{ErrorContext, new_nixide_error}; +use crate::errors::{new_nixide_error, ErrorContext}; use crate::sys; use crate::util::wrappers::AsInnerPtr; use crate::{EvalStateBuilder, NixideError}; diff --git a/nixide/src/flake/mod.rs b/nixide/src/flake/mod.rs index 9ae171f..51ae925 100644 --- a/nixide/src/flake/mod.rs +++ b/nixide/src/flake/mod.rs @@ -1,3 +1,4 @@ +mod eval_state_builder_ext; mod fetchers_settings; mod flake_lock_flags; mod flake_reference; @@ -5,9 +6,10 @@ mod flake_reference_parse_flags; mod flake_settings; mod locked_flake; +pub(self) use eval_state_builder_ext::EvalStateBuilderExt; pub(self) use fetchers_settings::FetchersSettings; pub(self) use flake_lock_flags::{FlakeLockFlags, FlakeLockMode}; pub(self) use flake_reference::FlakeReference; pub(self) use flake_reference_parse_flags::FlakeReferenceParseFlags; -pub use flake_settings::FlakeSettings; -pub use locked_flake::LockedFlake; +pub(self) use flake_settings::FlakeSettings; +pub(self) use locked_flake::LockedFlake; diff --git a/nixide/src/lib.rs b/nixide/src/lib.rs index c4b7be6..ccbccf1 100644 --- a/nixide/src/lib.rs +++ b/nixide/src/lib.rs @@ -12,9 +12,9 @@ pub(crate) mod util; mod verbosity; mod version; -#[cfg(feature = "exprs")] +#[cfg(feature = "expr")] mod expr; -#[cfg(feature = "flakes")] +#[cfg(feature = "flake")] mod flake; #[cfg(feature = "store")] mod store; @@ -23,10 +23,8 @@ pub use errors::{NixError, NixideError, NixideResult}; pub use verbosity::{NixVerbosity, set_verbosity}; pub use version::NixVersion; -#[cfg(feature = "exprs")] +#[cfg(feature = "expr")] pub use expr::{EvalState, EvalStateBuilder, Value}; -#[cfg(feature = "flakes")] -pub use flake::{FlakeSettings, LockedFlake}; #[cfg(feature = "store")] pub use store::{Store, StorePath}; @@ -36,7 +34,7 @@ use util::wrappers::AsInnerPtr as _; pub(crate) static mut INIT_LIBUTIL_STATUS: Option> = None; #[cfg(feature = "store")] pub(crate) static mut INIT_LIBSTORE_STATUS: Option> = None; -#[cfg(feature = "exprs")] +#[cfg(feature = "expr")] pub(crate) static mut INIT_LIBEXPR_STATUS: Option> = None; /// # Warning @@ -55,6 +53,9 @@ fn init_libutil() { } } +/// # TODO +/// **Only run this if the "store" feature flag was enabled** +/// /// # Warning /// /// > Rust's philosophy is that nothing happens before or after main and [ctor](https://github.com/mmastrac/rust-ctor) @@ -73,6 +74,9 @@ fn init_libstore() { } } +/// # TODO +/// **Only run this if the "expr" feature flag was enabled** +// /// # Warning /// /// > Rust's philosophy is that nothing happens before or after main and [ctor](https://github.com/mmastrac/rust-ctor)