From 43c851bc841bccc65ffddab7205783c43f25417f Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 14 Mar 2024 13:50:56 +0200 Subject: refactor(nix-compat/store_path): take [u8;32] for outer fingerprint The outer fingerprint used for store path calculation is always a sha256 digest. This includes both input and output-addressed store paths. We used a NixHash here, which can also represent other hash types, and that had a bunch of annoyances: - Whenever we had the bytes, we had to wrap them in a NixHash::Sha256(). - Things like AtermWriteable had to be implemented on NixHash, even though we then had an assertion it was only called in the NixHash::Sha256 case. Change-Id: Ic895503d9b071800d2e52ae057666f44bd0ab9d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11142 Tested-by: BuildkiteCI Autosubmit: flokli Reviewed-by: John Ericson Reviewed-by: picnoir picnoir --- tvix/nix-compat/src/derivation/write.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'tvix/nix-compat/src/derivation/write.rs') diff --git a/tvix/nix-compat/src/derivation/write.rs b/tvix/nix-compat/src/derivation/write.rs index f20bf4e121d2..735b781574e1 100644 --- a/tvix/nix-compat/src/derivation/write.rs +++ b/tvix/nix-compat/src/derivation/write.rs @@ -8,7 +8,8 @@ use crate::derivation::{ca_kind_prefix, output::Output}; use crate::nixbase32; use crate::store_path::{StorePath, StorePathRef, STORE_DIR_WITH_SLASH}; use bstr::BString; -use std::fmt::Display; +use data_encoding::HEXLOWER; + use std::{ collections::{BTreeMap, BTreeSet}, io, @@ -16,8 +17,6 @@ use std::{ io::Write, }; -use super::NixHash; - pub const DERIVATION_PREFIX: &str = "Derive"; pub const PAREN_OPEN: char = '('; pub const PAREN_CLOSE: char = ')'; @@ -31,7 +30,7 @@ pub const QUOTE: char = '"'; /// Note that we mostly use explicit `write_*` calls /// instead since the serialization of the items depends on /// the context a lot. -pub(crate) trait AtermWriteable: Display { +pub(crate) trait AtermWriteable { fn aterm_write(&self, writer: &mut impl Write) -> std::io::Result<()>; fn aterm_bytes(&self) -> Vec { @@ -67,12 +66,9 @@ impl AtermWriteable for String { } } -impl AtermWriteable for NixHash { +impl AtermWriteable for [u8; 32] { fn aterm_write(&self, writer: &mut impl Write) -> std::io::Result<()> { - // When we serialize the placeholder hashes, - // they need to be SHA256. - debug_assert!(matches!(self, NixHash::Sha256(_))); - write_field(writer, self.to_plain_hex_string(), false) + write_field(writer, HEXLOWER.encode(self), false) } } -- cgit 1.4.1