about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-16T23·11+0100
committerclbot <clbot@tvl.fyi>2023-03-19T20·57+0000
commit49cb2a2b1f964e07d2b6919c36ef0c4fbcd34443 (patch)
tree83e4c2b28b899fb01c17821b9c1eefa51398ebdb
parent80aaadfc199c4038b69c89f3493528f09c28efc2 (diff)
feat(tvix/store/bin): print store path r/6028
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 <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
-rw-r--r--tvix/store/src/bin/tvix-store.rs38
1 files changed, 38 insertions, 0 deletions
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<dyn std::error::Error>> {
             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<dyn std::error::Error>> {
                     &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!(