Struct nix_compat::derivation::Derivation
source · pub struct Derivation {
pub arguments: Vec<String>,
pub builder: String,
pub environment: BTreeMap<String, BString>,
pub input_derivations: BTreeMap<StorePath<String>, BTreeSet<String>>,
pub input_sources: BTreeSet<StorePath<String>>,
pub outputs: BTreeMap<String, Output>,
pub system: String,
}
Fields§
§arguments: Vec<String>
§builder: String
§environment: BTreeMap<String, BString>
§input_derivations: BTreeMap<StorePath<String>, BTreeSet<String>>
Map from drv path to output names used from this derivation.
input_sources: BTreeSet<StorePath<String>>
Plain store paths of additional inputs.
outputs: BTreeMap<String, Output>
Maps output names to Output.
system: String
Implementations§
source§impl Derivation
impl Derivation
sourcepub fn validate(
&self,
validate_output_paths: bool
) -> Result<(), DerivationError>
pub fn validate( &self, validate_output_paths: bool ) -> Result<(), DerivationError>
validate ensures a Derivation struct is properly populated, and returns a DerivationError if not.
if validate_output_paths
is set to false, the output paths are
excluded from validation.
This is helpful to validate struct population before invoking Derivation::calculate_output_paths.
source§impl Derivation
impl Derivation
sourcepub fn serialize(&self, writer: &mut impl Write) -> Result<(), Error>
pub fn serialize(&self, writer: &mut impl Write) -> Result<(), Error>
write the Derivation to the given std::io::Write, in ATerm format.
The only errors returns are these when writing to the passed writer.
sourcefn serialize_with_replacements(
&self,
writer: &mut impl Write,
input_derivations: &BTreeMap<impl AtermWriteable, BTreeSet<String>>
) -> Result<(), Error>
fn serialize_with_replacements( &self, writer: &mut impl Write, input_derivations: &BTreeMap<impl AtermWriteable, BTreeSet<String>> ) -> Result<(), Error>
Like serialize
but allow replacing the input_derivations for hash calculations.
sourcepub fn to_aterm_bytes(&self) -> Vec<u8> ⓘ
pub fn to_aterm_bytes(&self) -> Vec<u8> ⓘ
return the ATerm serialization.
sourcefn to_aterm_bytes_with_replacements(
&self,
input_derivations: &BTreeMap<impl AtermWriteable, BTreeSet<String>>
) -> Vec<u8> ⓘ
fn to_aterm_bytes_with_replacements( &self, input_derivations: &BTreeMap<impl AtermWriteable, BTreeSet<String>> ) -> Vec<u8> ⓘ
Like to_aterm_bytes
, but accept a different BTreeMap for input_derivations.
This is used to render the ATerm representation of a Derivation “modulo
fixed-output derivations”.
sourcepub fn from_aterm_bytes(b: &[u8]) -> Result<Derivation, Error<&[u8]>>
pub fn from_aterm_bytes(b: &[u8]) -> Result<Derivation, Error<&[u8]>>
Parse an Derivation in ATerm serialization, and validate it passes our set of validations.
sourcepub fn calculate_derivation_path(
&self,
name: &str
) -> Result<StorePath<String>, DerivationError>
pub fn calculate_derivation_path( &self, name: &str ) -> Result<StorePath<String>, DerivationError>
Returns the drv path of a Derivation struct.
The drv path is calculated by invoking build_text_path, using
the name
with a .drv
suffix as name, all Derivation::input_sources and
keys of Derivation::input_derivations as references, and the ATerm string of
the Derivation as content.
sourcepub fn fod_digest(&self) -> Option<[u8; 32]>
pub fn fod_digest(&self) -> Option<[u8; 32]>
Returns the FOD digest, if the derivation is fixed-output, or None if
it’s not.
TODO: this is kinda the string from build_ca_path with a
CAHash::Flat, what’s fed to build_store_path_from_fingerprint_parts
(except the out_output.path being an empty string)
sourcepub fn hash_derivation_modulo<F>(
&self,
fn_lookup_hash_derivation_modulo: F
) -> [u8; 32]
pub fn hash_derivation_modulo<F>( &self, fn_lookup_hash_derivation_modulo: F ) -> [u8; 32]
Calculates the hash of a derivation modulo fixed-output subderivations.
This is called hashDerivationModulo
in nixcpp.
It returns the sha256 digest of the derivation ATerm representation, except that:
- any input derivation paths have beed replaced “by the result of a recursive call to this function” and that
- for fixed-output derivations the special
fixed:out:${algo}:${digest}:${fodPath}
string is hashed instead of the A-Term.
It’s up to the caller of this function to provide a (infallible) lookup function to query [hash_derivation_modulo] of direct input derivations, by their StorePathRef. It will only be called in case the derivation is not a fixed-output derivation.
sourcepub fn calculate_output_paths(
&mut self,
name: &str,
hash_derivation_modulo: &[u8; 32]
) -> Result<(), DerivationError>
pub fn calculate_output_paths( &mut self, name: &str, hash_derivation_modulo: &[u8; 32] ) -> Result<(), DerivationError>
This calculates all output paths of a Derivation and updates the struct. It requires the struct to be initially without output paths. This means, self.outputs[$outputName].path needs to be an empty string, and self.environment[$outputName] needs to be an empty string.
Output path calculation requires knowledge of the [hash_derivation_modulo], which (in case of non-fixed-output derivations) also requires knowledge of the [hash_derivation_modulo] of input derivations (recursively).
To avoid recursing and doing unnecessary calculation, we simply ask the caller of this function to provide the result of the [hash_derivation_modulo] call of the current Derivation, and leave it up to them to calculate it when needed.
On completion, self.environment[$outputName]
and
self.outputs[$outputName].path
are set to the calculated output path for all
outputs.
Trait Implementations§
source§impl Clone for Derivation
impl Clone for Derivation
source§fn clone(&self) -> Derivation
fn clone(&self) -> Derivation
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Derivation
impl Debug for Derivation
source§impl Default for Derivation
impl Default for Derivation
source§fn default() -> Derivation
fn default() -> Derivation
source§impl<'de> Deserialize<'de> for Derivation
impl<'de> Deserialize<'de> for Derivation
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for Derivation
impl PartialEq for Derivation
source§fn eq(&self, other: &Derivation) -> bool
fn eq(&self, other: &Derivation) -> bool
self
and other
values to be equal, and is used
by ==
.