From ef8a8af0bfa5963a4a19023acb2c94c3bc61f4d6 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 19 Nov 2023 19:50:56 +0200 Subject: refactor(tvix/nix-compat): cleanup parse_{ca,hash} and fmt structs These were used to format to and parse from strings. Move this to the CAHash and NixHash structs directly, and be explicit in the name about which encoding for digests is used. For output path calculation, nix encodes the nixpaths in hex, but for writing out NARInfos, it's using nixbase32. Change-Id: Ia585a76a3811b2609e7ce259fda66a29403b7e07 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10079 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/nix-compat/src/store_path/utils.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'tvix/nix-compat/src/store_path/utils.rs') diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs index a227056edc21..dd32135135db 100644 --- a/tvix/nix-compat/src/store_path/utils.rs +++ b/tvix/nix-compat/src/store_path/utils.rs @@ -93,7 +93,7 @@ pub fn build_ca_path, S: AsRef, I: IntoIterator>( NixHash::Sha256( Sha256::new_with_prefix(format!( "fixed:out:r:{}:", - hash.to_nix_hash_string() + hash.to_nix_hex_string() )) .finalize() .into(), @@ -115,12 +115,9 @@ pub fn build_ca_path, S: AsRef, I: IntoIterator>( "output:out", &{ NixHash::Sha256( - Sha256::new_with_prefix(format!( - "fixed:out:{}:", - hash.to_nix_hash_string() - )) - .finalize() - .into(), + Sha256::new_with_prefix(format!("fixed:out:{}:", hash.to_nix_hex_string())) + .finalize() + .into(), ) }, name, @@ -170,7 +167,7 @@ fn build_store_path_from_fingerprint_parts>( let digest = compress_hash(&{ let mut h = Sha256::new(); - write!(h, "{ty}:{}:{STORE_DIR}:{name}", hash.to_nix_hash_string()).unwrap(); + write!(h, "{ty}:{}:{STORE_DIR}:{name}", hash.to_nix_hex_string()).unwrap(); h.finalize() }); -- cgit 1.4.1