From b55d1f97ce8762711ff44f9b5695452cc8083c44 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 14 Mar 2023 17:16:05 +0100 Subject: refactor(tvix/nix-compat): -derivation::Hash, +NixHash This stops using our own custom Hash structure, which was mostly only used because we had to parse the JSON representation somehow. Since cl/8217, there's a `NixHash` struct, which is better suited to hold this data. Converting the format requires a bit of serde labor though, but that only really matters when interacting with JSON representations (which we mostly don't). Change-Id: Idc5ee511e36e6726c71f66face8300a441b0bf4c Reviewed-on: https://cl.tvl.fyi/c/depot/+/8304 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/cli/src/derivation.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'tvix/cli') diff --git a/tvix/cli/src/derivation.rs b/tvix/cli/src/derivation.rs index 61c4489954f1..1508e3e6d935 100644 --- a/tvix/cli/src/derivation.rs +++ b/tvix/cli/src/derivation.rs @@ -1,5 +1,5 @@ //! Implements `builtins.derivation`, the core of what makes Nix build packages. -use nix_compat::derivation::{Derivation, Hash}; +use nix_compat::derivation::Derivation; use nix_compat::{hash_placeholder, nixhash}; use std::cell::RefCell; use std::collections::{btree_map, BTreeSet}; @@ -126,19 +126,18 @@ fn populate_output_configuration( let output_hash = nixhash::from_str(&hash, a).map_err(Error::InvalidOutputHash)?; - // construct the algo string. Depending on hashMode, we prepend a `r:`. - let algo = match hash_mode.as_deref() { - None | Some("flat") => format!("{}", &output_hash.algo), - Some("recursive") => format!("r:{}", &output_hash.algo), + // construct the NixHashWithMode. + out.hash_with_mode = match hash_mode.as_deref() { + None | Some("flat") => Some(nixhash::NixHashWithMode::Flat( + nixhash::NixHash::new(output_hash.algo, output_hash.digest), + )), + Some("recursive") => Some(nixhash::NixHashWithMode::Recursive( + nixhash::NixHash::new(output_hash.algo, output_hash.digest), + )), Some(other) => { return Err(Error::InvalidOutputHashMode(other.to_string()).into()) } - }; - - out.hash = Some(Hash { - algo, - digest: data_encoding::HEXLOWER.encode(&output_hash.digest), - }); + } } } } -- cgit 1.4.1