Skip to main content

Store

Struct Store 

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

Nix store for managing packages and derivations.

The store provides access to Nix packages, derivations, and store paths.

Implementations§

Source§

impl Store

Source

pub fn open(context: &Arc<Context>, uri: Option<&str>) -> Result<Self>

Open a Nix store.

§Arguments
  • context - The Nix context
  • uri - Optional store URI (None for the default local store)
§Errors

Returns an error if the store cannot be opened.

Source

pub fn open_with_params<K, V>( context: &Arc<Context>, uri: Option<&str>, params: &[(K, V)], ) -> Result<Self>
where K: AsRef<str>, V: AsRef<str>,

Open a Nix store with additional store parameters.

Equivalent to passing ?key1=value1&key2=value2 in the URI. Useful for configuring daemon connections, signing keys, or cache options.

§Errors

Returns an error if the store cannot be opened.

Source

pub fn realize(&self, path: &StorePath) -> Result<Vec<(String, StorePath)>>

Realize a store path.

Builds or downloads the store path and all its dependencies, making them available in the local store.

§Returns

A vector of (output_name, store_path) pairs for each realized output.

§Errors

Returns an error if the path cannot be realized.

Source

pub fn store_path(&self, path: &str) -> Result<StorePath>

Parse a store path string into a StorePath.

Convenience wrapper around StorePath::parse.

§Errors

Returns an error if the path cannot be parsed.

§Example
let ctx = Arc::new(Context::new()?);
let store = Store::open(&ctx, None)?;
let path = store.store_path("/nix/store/...")?;
Source

pub fn is_valid_path(&self, path: &StorePath) -> bool

Check whether a store path is present and valid in the store.

Returns true if the path exists in the store’s database.

Source

pub fn real_path(&self, path: &StorePath) -> Result<String>

Resolve the real filesystem path for a store path.

For content-addressed stores (e.g., a binary cache) this may differ from the store path itself.

§Errors

Returns an error if the path cannot be resolved.

Source

pub fn uri(&self) -> Result<String>

Get the URI identifying this store (e.g., "local" or "https://cache.nixos.org").

§Errors

Returns an error if the URI cannot be retrieved.

Source

pub fn store_dir(&self) -> Result<String>

Get the store directory (e.g., "/nix/store").

§Errors

Returns an error if the directory cannot be retrieved.

Source

pub fn version(&self) -> Result<String>

Get the version string of the store daemon.

§Errors

Returns an error if the version cannot be retrieved.

Source

pub fn copy_closure(&self, dst_store: &Store, path: &StorePath) -> Result<()>

Copy the closure of path from self into dst_store.

This copies the store path and all its transitive dependencies.

§Errors

Returns an error if the copy operation fails.

Source

pub fn copy_path( &self, dst_store: &Store, path: &StorePath, options: CopyPathOptions, ) -> Result<()>

Copy a single path from this store into dst_store.

Unlike copy_closure, this copies only the path itself, not its dependencies.

§Errors

Returns an error if the copy operation fails.

Source

pub fn get_fs_closure<F>( &self, path: &StorePath, flip_direction: bool, include_outputs: bool, include_derivers: bool, callback: F, ) -> Result<()>
where F: FnMut(&StorePath),

Enumerate the filesystem closure of a store path.

Calls callback once for each store path in the closure (in no particular order).

§Arguments
  • flip_direction - If false, return paths referenced by paths in the closure (forward). If true, return paths that reference paths in the closure (backward).
  • include_outputs - For derivations, also include their outputs.
  • include_derivers - For outputs, also include the derivation that produced them.
§Errors

Returns an error if the operation fails.

Source

pub fn collect_fs_closure( &self, path: &StorePath, flip_direction: bool, include_outputs: bool, include_derivers: bool, ) -> Result<Vec<StorePath>>

Collect the filesystem closure into a Vec<StorePath>.

Convenience wrapper around get_fs_closure that gathers every visited path into a vector. Use the callback form directly if you want to stream paths without allocating the full closure.

§Errors

Returns an error if the operation fails.

Source

pub fn print_path(&self, path: &StorePath) -> Result<String>

Render a StorePath back to its canonical /nix/store/... string.

Requires the shim feature: the C API does not expose a path-to-string function directly; this calls a C++ shim that delegates to store->printStorePath(path).

§Errors

Returns an error if the rendering fails.

Source

pub fn read_derivation(&self, path: &StorePath) -> Result<Derivation>

Read a derivation from this store by its store path.

Convenience wrapper around Derivation::from_store_path.

§Errors

Returns an error if the derivation cannot be read.

Source

pub fn query_path_from_hash_part(&self, hash: &str) -> Result<Option<StorePath>>

Look up the full store path from a hash part.

§Returns

Some(StorePath) if a matching path exists, None otherwise.

Source

pub fn add_bytes_to_store(&self, name: &str, data: &[u8]) -> Result<StorePath>

Add arbitrary bytes to the Nix store as a flat, content-addressed file.

Equivalent to builtins.toFile, but accepts any byte sequence (including embedded NULs and non-UTF-8 data). The path’s hash is derived from the content, so identical bytes always produce the same store path. The resulting path has no references.

§Arguments
  • name - The filename that will appear in the store path
  • data - The bytes to write
§Errors

Returns an error if the store operation fails.

Source

pub fn add_text_to_store(&self, name: &str, text: &str) -> Result<StorePath>

Add text content to the Nix store.

Thin convenience wrapper over add_bytes_to_store that writes the UTF-8 bytes of text.

§Errors

Returns an error if the store operation fails.

Source

pub fn add_temp_root(&self, path: &StorePath) -> Result<()>

Register a store path as a temporary GC root.

The root lasts until the process exits. On a daemon store it lasts until the daemon connection that carried the request closes.

§Errors

Returns an error if the store rejects the request.

Trait Implementations§

Source§

impl Debug for Store

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Store

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Store

Auto Trait Implementations§

§

impl !Sync for Store

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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.