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
impl EvalState
Sourcepub fn eval_from_file(&self, path: impl AsRef<Path>) -> Result<Value<'_>>
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.
Sourcepub fn alloc_value(&self) -> Result<Value<'_>>
pub fn alloc_value(&self) -> Result<Value<'_>>
Sourcepub fn make_float(&self, f: f64) -> Result<Value<'_>>
pub fn make_float(&self, f: f64) -> Result<Value<'_>>
Sourcepub fn make_string(&self, s: &str) -> Result<Value<'_>>
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.
Sourcepub fn make_path(&self, path: impl AsRef<Path>) -> Result<Value<'_>>
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§impl EvalState
impl EvalState
Sourcepub fn make_external<T: NixExternal>(
&self,
data: T,
) -> Result<ExternalValueHandle<'_>>
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.