Skip to main content

EvalState

Struct EvalState 

Source
pub struct EvalState { /* private fields */ }
Expand description

Nix evaluation state for evaluating expressions.

This provides the main interface for evaluating Nix expressions and creating values.

Implementations§

Source§

impl EvalState

Source

pub fn eval_from_string(&self, expr: &str, path: &str) -> Result<Value<'_>>

Evaluate a Nix expression from a string.

§Arguments
  • expr - The Nix expression to evaluate
  • path - The path to use for error reporting (e.g., "<eval>")
§Errors

Returns an error if evaluation fails.

Source

pub fn eval_from_file(&self, path: impl AsRef<Path>) -> Result<Value<'_>>

Evaluate a Nix expression from a file.

Reads the file at path as UTF-8, then evaluates its contents using the parent directory as the base path for relative imports. The base path is passed to Nix as a UTF-8 string; non-UTF-8 components are replaced lossily for the error-reporting label only.

§Errors

Returns an error if the file cannot be read as UTF-8 or if evaluation fails.

Source

pub fn alloc_value(&self) -> Result<Value<'_>>

Allocate a new uninitialized value.

§Errors

Returns an error if value allocation fails.

Source

pub fn make_int(&self, i: i64) -> Result<Value<'_>>

Create a Nix integer value.

§Errors

Returns an error if value allocation or initialization fails.

Source

pub fn make_float(&self, f: f64) -> Result<Value<'_>>

Create a Nix float value.

§Errors

Returns an error if value allocation or initialization fails.

Source

pub fn make_bool(&self, b: bool) -> Result<Value<'_>>

Create a Nix boolean value.

§Errors

Returns an error if value allocation or initialization fails.

Source

pub fn make_null(&self) -> Result<Value<'_>>

Create a Nix null value.

§Errors

Returns an error if value allocation or initialization fails.

Source

pub fn make_string(&self, s: &str) -> Result<Value<'_>>

Create a Nix string value.

§Errors

Returns an error if value allocation, string conversion, or initialization fails.

Source

pub fn make_path(&self, path: impl AsRef<Path>) -> Result<Value<'_>>

Create a Nix path value.

§Pure Evaluation

In pure-eval mode (--pure-eval) the Nix evaluator wraps the filesystem in an AllowListSourceAccessor that rejects any unregistered absolute path. When the shim feature is enabled this method automatically registers absolute paths via the shim’s nix_eval_state_allow_path before constructing the value, mirroring what Nix’s own fetch builtins do. Without shim you must arrange for allowPath yourself, or is_pure_eval returns true.

§Errors

Returns an error if value allocation, path conversion, or initialization fails.

Source

pub fn make_list(&self, items: &[&Value<'_>]) -> Result<Value<'_>>

Create a Nix list value from a slice of values.

§Errors

Returns an error if value allocation or list construction fails.

Source

pub fn make_attrs<'s>( &'s self, pairs: &[(&str, &Value<'_>)], ) -> Result<Value<'s>>

Create a Nix attribute set from key-value pairs.

§Errors

Returns an error if value allocation or attribute set construction fails.

Source§

impl EvalState

Source

pub fn make_external<T: NixExternal>( &self, data: T, ) -> Result<ExternalValueHandle<'_>>

Wrap a NixExternal value and return an ExternalValueHandle.

The handle carries the Nix Value and the raw ExternalValue* needed for downcasting via ExternalValueHandle::as_external. The value’s lifetime is managed by the Nix GC.

§Errors

Returns an error if value allocation or external value creation fails.

Trait Implementations§

Source§

impl Drop for EvalState

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for EvalState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.