diff options
author | Florian Klink <flokli@flokli.de> | 2024-03-14T12·32+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-03-14T23·10+0000 |
commit | 905a79308e8b9b66736e6cc62edc62d60f026cb9 (patch) | |
tree | d523841aa9b9f93e75fc7004eb5edcbd146f7342 /tvix/nix-compat/src/derivation/mod.rs | |
parent | 142c72e070e32710cb691c0c3b79babad595cb62 (diff) |
refactor(nix-compat/derivation): emphasize aterm_bytes r/7694
derivation_or_fod_hash constructs ATerm bytes and feeds them to sha256. input_derivations being slightly modified is an implementation detail, so move the BTreeMap construction inline, and have aterm_bytes in a let binding (and feed it to the hash function directly while constructing it). This makes it a bit more understandable what's going on. Change-Id: I2f5cfbd1c964fd39ac731ca39e76cfc168f4c7d7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11147 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: John Ericson <git@johnericson.me>
Diffstat (limited to 'tvix/nix-compat/src/derivation/mod.rs')
-rw-r--r-- | tvix/nix-compat/src/derivation/mod.rs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs index 9a7dd04c11c4..07da127ed038 100644 --- a/tvix/nix-compat/src/derivation/mod.rs +++ b/tvix/nix-compat/src/derivation/mod.rs @@ -97,7 +97,9 @@ impl Derivation { self.to_aterm_bytes_with_replacements(&self.input_derivations) } - /// Like `to_aterm_bytes` but allow input_derivation replacements for hashing. + /// 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". fn to_aterm_bytes_with_replacements( &self, input_derivations: &BTreeMap<impl AtermWriteable, BTreeSet<String>>, @@ -203,19 +205,18 @@ impl Derivation { // For each input_derivation, look up the // derivation_or_fod_hash, and replace the derivation path with // it's HEXLOWER digest. - let input_derivations = BTreeMap::from_iter(self.input_derivations.iter().map( - |(drv_path, output_names)| { - let hash = fn_get_derivation_or_fod_hash(&drv_path.into()); - - (hash, output_names.to_owned()) - }, + let aterm_bytes = self.to_aterm_bytes_with_replacements(&BTreeMap::from_iter( + self.input_derivations + .iter() + .map(|(drv_path, output_names)| { + let hash = fn_get_derivation_or_fod_hash(&drv_path.into()); + + (hash, output_names.to_owned()) + }), )); - // write the ATerm of that to the hash function - let mut hasher = Sha256::new(); - hasher.update(self.to_aterm_bytes_with_replacements(&input_derivations)); - - hasher.finalize().into() + // write the ATerm of that to the hash function and return its digest. + Sha256::new_with_prefix(aterm_bytes).finalize().into() }) } |