From 49cb2a2b1f964e07d2b6919c36ef0c4fbcd34443 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 17 Mar 2023 00:11:43 +0100 Subject: feat(tvix/store/bin): print store path After ingestion of the contents into the store, this will use the NonCachingNARCalculationService to create a NAR stream or the contents of the path, and use our Derivation output path calculation machinery to determine the output path (using recursive hashing strategy). In a real-world scenario, we obviously want to cache these calculations, but this should be sufficient to tinker around with it. Change-Id: I9b2e69384414f0be1bdcb5a99a4bfd46e8db9932 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8317 Autosubmit: flokli Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/store/src/bin/tvix-store.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tvix/store/src') diff --git a/tvix/store/src/bin/tvix-store.rs b/tvix/store/src/bin/tvix-store.rs index 1cbe2f1e8dbc..72814fa530e7 100644 --- a/tvix/store/src/bin/tvix-store.rs +++ b/tvix/store/src/bin/tvix-store.rs @@ -1,11 +1,17 @@ use clap::Subcommand; use data_encoding::BASE64; +use nix_compat::derivation::Derivation; +use nix_compat::derivation::Output; +use nix_compat::nixhash::HashAlgo; +use nix_compat::nixhash::NixHash; +use nix_compat::nixhash::NixHashWithMode; use std::path::PathBuf; use tracing_subscriber::prelude::*; use tvix_store::blobservice::SledBlobService; use tvix_store::chunkservice::SledChunkService; use tvix_store::directoryservice::SledDirectoryService; use tvix_store::import::import_path; +use tvix_store::nar::NARCalculationService; use tvix_store::nar::NonCachingNARCalculationService; use tvix_store::pathinfoservice::SledPathInfoService; use tvix_store::proto::blob_service_server::BlobServiceServer; @@ -127,6 +133,12 @@ async fn main() -> Result<(), Box> { router.serve(listen_address).await?; } Commands::Import { paths } => { + let nar_calculation_service = NonCachingNARCalculationService::new( + blob_service.clone(), + chunk_service.clone(), + directory_service.clone(), + ); + for path in paths { let root_node = import_path( &mut blob_service, @@ -135,6 +147,32 @@ async fn main() -> Result<(), Box> { &path, )?; + let nar_hash = NixHashWithMode::Recursive(NixHash::new( + HashAlgo::Sha256, + nar_calculation_service + .calculate_nar(&root_node)? + .nar_sha256, + )); + + let mut drv = Derivation::default(); + drv.outputs.insert( + "out".to_string(), + Output { + path: "".to_string(), + hash_with_mode: Some(nar_hash), + }, + ); + drv.calculate_output_paths( + path.file_name() + .expect("path must not be ..") + .to_str() + .expect("path must be valid unicode"), + // Note the derivation_or_fod_hash argument is *unused* for FODs, so it doesn't matter what we pass here. + &NixHash::new(HashAlgo::Sha256, vec![]), + )?; + + println!("{}", drv.outputs.get("out").unwrap().path); + match root_node { tvix_store::proto::node::Node::Directory(directory_node) => { info!( -- cgit 1.4.1