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
impl Store
Sourcepub fn open_with_params<K, V>(
context: &Arc<Context>,
uri: Option<&str>,
params: &[(K, V)],
) -> Result<Self>
pub fn open_with_params<K, V>( context: &Arc<Context>, uri: Option<&str>, params: &[(K, V)], ) -> Result<Self>
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.
Sourcepub fn store_path(&self, path: &str) -> Result<StorePath>
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/...")?;Sourcepub fn is_valid_path(&self, path: &StorePath) -> bool
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.
Sourcepub fn real_path(&self, path: &StorePath) -> Result<String>
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.
Sourcepub fn uri(&self) -> Result<String>
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.
Sourcepub fn store_dir(&self) -> Result<String>
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.
Sourcepub fn version(&self) -> Result<String>
pub fn version(&self) -> Result<String>
Get the version string of the store daemon.
§Errors
Returns an error if the version cannot be retrieved.
Sourcepub fn copy_closure(&self, dst_store: &Store, path: &StorePath) -> Result<()>
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.
Sourcepub fn copy_path(
&self,
dst_store: &Store,
path: &StorePath,
options: CopyPathOptions,
) -> Result<()>
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.
Sourcepub fn get_fs_closure<F>(
&self,
path: &StorePath,
flip_direction: bool,
include_outputs: bool,
include_derivers: bool,
callback: F,
) -> Result<()>
pub fn get_fs_closure<F>( &self, path: &StorePath, flip_direction: bool, include_outputs: bool, include_derivers: bool, callback: F, ) -> Result<()>
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.
Sourcepub fn collect_fs_closure(
&self,
path: &StorePath,
flip_direction: bool,
include_outputs: bool,
include_derivers: bool,
) -> Result<Vec<StorePath>>
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.
Sourcepub fn print_path(&self, path: &StorePath) -> Result<String>
pub fn print_path(&self, path: &StorePath) -> Result<String>
Sourcepub fn read_derivation(&self, path: &StorePath) -> Result<Derivation>
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.
Sourcepub fn query_path_from_hash_part(&self, hash: &str) -> Result<Option<StorePath>>
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.
Sourcepub fn add_bytes_to_store(&self, name: &str, data: &[u8]) -> Result<StorePath>
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 pathdata- The bytes to write
§Errors
Returns an error if the store operation fails.
Sourcepub fn add_text_to_store(&self, name: &str, text: &str) -> Result<StorePath>
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.