diff options
Diffstat (limited to 'tvix/derivation')
-rw-r--r-- | tvix/derivation/src/derivation.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tvix/derivation/src/derivation.rs b/tvix/derivation/src/derivation.rs index a5ea56fbbf89..a9e769543e00 100644 --- a/tvix/derivation/src/derivation.rs +++ b/tvix/derivation/src/derivation.rs @@ -69,6 +69,27 @@ impl Derivation { Ok(()) } + /// Returns the fixed output path and its hash + // (if the Derivation is fixed output), + /// or None if there is no fixed output. + /// This takes some shortcuts in case more than one output exists, as this + /// can't be a valid fixed-output Derivation. + pub fn get_fixed_output(&self) -> Option<(&String, &Hash)> { + if self.outputs.len() != 1 { + return None; + } + + match self.outputs.get("out") { + #[allow(clippy::manual_map)] + Some(out_output) => match &out_output.hash { + Some(out_output_hash) => Some((&out_output.path, out_output_hash)), + // There has to be a hash, otherwise it would not be FOD + None => None, + }, + None => None, + } + } + /// Returns the drv path of a Derivation struct. /// /// The drv path is calculated like this: |