pub struct Derivation {
    pub arguments: Vec<String>,
    pub builder: String,
    pub environment: BTreeMap<String, BString>,
    pub input_derivations: BTreeMap<StorePath, BTreeSet<String>>,
    pub input_sources: BTreeSet<StorePath>,
    pub outputs: BTreeMap<String, Output>,
    pub system: String,
}

Fields§

§arguments: Vec<String>§builder: String§environment: BTreeMap<String, BString>§input_derivations: BTreeMap<StorePath, BTreeSet<String>>

Map from drv path to output names used from this derivation.

§input_sources: BTreeSet<StorePath>

Plain store paths of additional inputs.

§outputs: BTreeMap<String, Output>

Maps output names to Output.

§system: String

Implementations§

source§

impl Derivation

source

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

source

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.

source

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.

source

pub fn to_aterm_bytes(&self) -> Vec<u8>

return the ATerm serialization.

source

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”.

source

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.

source

pub fn calculate_derivation_path( &self, name: &str ) -> Result<StorePath, 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.

source

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)

source

pub fn hash_derivation_modulo<F>( &self, fn_lookup_hash_derivation_modulo: F ) -> [u8; 32]
where F: Fn(&StorePathRef<'_>) -> [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.

source

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

source§

fn clone(&self) -> Derivation

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Derivation

source§

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

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

impl Default for Derivation

source§

fn default() -> Derivation

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Derivation

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for Derivation

source§

fn eq(&self, other: &Derivation) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Derivation

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Derivation

source§

impl StructuralPartialEq for Derivation

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> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,