From a94414e7ffc5c21874fa0ea6e92aa63fcc55cb7d Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 16 Oct 2024 02:41:05 +0300 Subject: [PATCH] refactor(nix-compat/store_path): drop build_nar_based_store_path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the only (remaining) occurence of it, and not really more code than just calling store_path::build_ca_path with `CAHash::Nar(NixHash::Sha256(…))`, especially considering we need the CAHash in the PathInfo struct later anyways - so let's remove this function. Change-Id: Ia82212086062c366e0280ca0823d9e68a3f91d3a Reviewed-on: https://cl.tvl.fyi/c/depot/+/12632 Reviewed-by: edef Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/nix-compat/src/store_path/utils.rs | 14 -------------- tvix/store/src/import.rs | 8 +++++--- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/tvix/nix-compat/src/store_path/utils.rs b/tvix/nix-compat/src/store_path/utils.rs index 543a2e7e8..a0dc21160 100644 --- a/tvix/nix-compat/src/store_path/utils.rs +++ b/tvix/nix-compat/src/store_path/utils.rs @@ -119,20 +119,6 @@ where .map_err(BuildStorePathError::InvalidStorePath) } -/// For given NAR sha256 digest and name, return the new [StorePath] this would -/// have, or an error, in case the name is invalid. -pub fn build_nar_based_store_path<'a, SP>( - nar_sha256_digest: &[u8; 32], - name: &'a str, -) -> Result, BuildStorePathError> -where - SP: std::cmp::Eq + std::ops::Deref + std::convert::From<&'a str>, -{ - let nar_hash_with_mode = CAHash::Nar(NixHash::Sha256(nar_sha256_digest.to_owned())); - - build_ca_path(name, &nar_hash_with_mode, Vec::::new(), false) -} - /// This builds an input-addressed store path. /// /// Input-addresed store paths are always derivation outputs, the "input" in question is the diff --git a/tvix/store/src/import.rs b/tvix/store/src/import.rs index 8101b6635..4c1bd51ee 100644 --- a/tvix/store/src/import.rs +++ b/tvix/store/src/import.rs @@ -99,11 +99,13 @@ where // Ask for the NAR size and sha256 let (nar_size, nar_sha256) = nar_calculation_service.calculate_nar(&root_node).await?; + let ca = CAHash::Nar(NixHash::Sha256(nar_sha256)); + // Calculate the output path. This might still fail, as some names are illegal. // FUTUREWORK: express the `name` at the type level to be valid and move the conversion // at the caller level. - let output_path: StorePath = store_path::build_nar_based_store_path(&nar_sha256, name) - .map_err(|_| { + let output_path: StorePath = + store_path::build_ca_path(name, &ca, std::iter::empty::<&str>(), false).map_err(|_| { std::io::Error::new( std::io::ErrorKind::InvalidData, format!("invalid name: {}", name), @@ -122,7 +124,7 @@ where nar_sha256, signatures: vec![], deriver: None, - ca: Some(CAHash::Nar(NixHash::Sha256(nar_sha256))), + ca: Some(ca), }) .await?) }