about summary refs log tree commit diff
path: root/tvix/glue/src
diff options
context:
space:
mode:
authorRyan Lahfa <tvl@lahfa.xyz>2024-03-28T23·43+0100
committerraitobezarius <tvl@lahfa.xyz>2024-04-01T12·30+0000
commit14fe65a50b7bc1e31083c916d254043b0639d5aa (patch)
treefae237c85166d0bc7d07d1cf32f9029ef6aab24a /tvix/glue/src
parentf2ca30774e20afc7134d91f2e24787510cf50e07 (diff)
refactor(tvix/store): generalize `PathInfo` constructors r/7839
Instead of enforcing NAR SHA256 all the time, we generalize the
`PathInfo` constructor to take a `CAHash` argument which can drive
whether we are having a flat, NAR or text scheme.

With this, it is now possible to implement flat schemes in our
evaluation builtins, e.g. `builtins.path`.

Change-Id: I15bfee0ef4f0f428bfbd2f30c57c012cdcf6a976
Signed-off-by: Ryan Lahfa <tvl@lahfa.xyz>
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11286
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/glue/src')
-rw-r--r--tvix/glue/src/builtins/import.rs14
-rw-r--r--tvix/glue/src/tvix_store_io.rs28
2 files changed, 31 insertions, 11 deletions
diff --git a/tvix/glue/src/builtins/import.rs b/tvix/glue/src/builtins/import.rs
index 88e483031f46..8c9efc679171 100644
--- a/tvix/glue/src/builtins/import.rs
+++ b/tvix/glue/src/builtins/import.rs
@@ -119,6 +119,7 @@ mod import_builtins {
 
     use super::*;
 
+    use nix_compat::nixhash::{CAHash, NixHash};
     use tvix_eval::generators::Gen;
     use tvix_eval::{generators::GenCo, ErrorKind, Value};
 
@@ -138,8 +139,19 @@ mod import_builtins {
         Ok(state
             .tokio_handle
             .block_on(async {
+                let (_, nar_sha256) = state
+                    .path_info_service
+                    .as_ref()
+                    .calculate_nar(&root_node)
+                    .await?;
+
                 state
-                    .register_node_in_path_info_service(name, &p, root_node)
+                    .register_node_in_path_info_service(
+                        name,
+                        &p,
+                        CAHash::Nar(NixHash::Sha256(nar_sha256)),
+                        root_node,
+                    )
                     .await
             })
             .map_err(|err| ErrorKind::IO {
diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs
index cbda365c20da..bfdab0846165 100644
--- a/tvix/glue/src/tvix_store_io.rs
+++ b/tvix/glue/src/tvix_store_io.rs
@@ -53,7 +53,8 @@ use crate::tvix_build::derivation_to_build_request;
 pub struct TvixStoreIO {
     blob_service: Arc<dyn BlobService>,
     directory_service: Arc<dyn DirectoryService>,
-    path_info_service: Arc<dyn PathInfoService>,
+    // This is public so builtins can put PathInfos directly.
+    pub(crate) path_info_service: Arc<dyn PathInfoService>,
     std_io: StdIO,
     #[allow(dead_code)]
     build_service: Arc<dyn BuildService>,
@@ -293,9 +294,13 @@ impl TvixStoreIO {
         &self,
         name: &str,
         path: &Path,
+        ca: CAHash,
         root_node: Node,
     ) -> io::Result<(PathInfo, StorePath)> {
         // Ask the PathInfoService for the NAR size and sha256
+        // We always need it no matter what is the actual hash mode
+        // because the path info construct a narinfo which *always*
+        // require a SHA256 of the NAR representation and the NAR size.
         let (nar_size, nar_sha256) = self
             .path_info_service
             .as_ref()
@@ -303,20 +308,22 @@ impl TvixStoreIO {
             .await?;
 
         // Calculate the output path. This might still fail, as some names are illegal.
-        let output_path = nix_compat::store_path::build_nar_based_store_path(&nar_sha256, name)
-            .map_err(|_| {
-                std::io::Error::new(
-                    std::io::ErrorKind::InvalidData,
-                    format!("invalid name: {}", name),
-                )
-            })?;
+        let output_path =
+            nix_compat::store_path::build_ca_path(name, &ca, Vec::<String>::new(), false).map_err(
+                |_| {
+                    std::io::Error::new(
+                        std::io::ErrorKind::InvalidData,
+                        format!("invalid name: {}", name),
+                    )
+                },
+            )?;
 
         // assemble a new root_node with a name that is derived from the nar hash.
         let root_node = root_node.rename(output_path.to_string().into_bytes().into());
         tvix_store::import::log_node(&root_node, path);
 
         let path_info =
-            tvix_store::import::derive_nar_ca_path_info(nar_size, nar_sha256, root_node);
+            tvix_store::import::derive_nar_ca_path_info(nar_size, nar_sha256, Some(ca), root_node);
 
         Ok((path_info, output_path.to_owned()))
     }
@@ -325,9 +332,10 @@ impl TvixStoreIO {
         &self,
         name: &str,
         path: &Path,
+        ca: CAHash,
         root_node: Node,
     ) -> io::Result<StorePath> {
-        let (path_info, output_path) = self.node_to_path_info(name, path, root_node).await?;
+        let (path_info, output_path) = self.node_to_path_info(name, path, ca, root_node).await?;
         let _path_info = self.path_info_service.as_ref().put(path_info).await?;
 
         Ok(output_path)