about summary refs log tree commit diff
path: root/tvix/nix-compat/src/derivation/mod.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2024-01-15T18·32+0200
committerflokli <flokli@flokli.de>2024-01-16T08·37+0000
commite2c79e39f00f1b882bde838ecc450d18a1807235 (patch)
tree7e402c0f0cdc7807791a80e5f5eb47e421692994 /tvix/nix-compat/src/derivation/mod.rs
parentc8114810c9f42410e837573e836c32510eb60ba7 (diff)
refactor(nix-compat): use StorePathRef for hash derivation modulo r/7389
Rather than passing strings around, use a StorePathRef.

This makes things a bit more typesafe, and more aligned with what we
want to do in b/264.

Change-Id: Ib7080addf27e7f1a9c8da1d8aaa66744468e3b5a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10633
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/nix-compat/src/derivation/mod.rs')
-rw-r--r--tvix/nix-compat/src/derivation/mod.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs
index b3f3adc55ba2..2f90c54d8f76 100644
--- a/tvix/nix-compat/src/derivation/mod.rs
+++ b/tvix/nix-compat/src/derivation/mod.rs
@@ -1,4 +1,6 @@
-use crate::store_path::{self, build_ca_path, build_output_path, build_text_path, StorePath};
+use crate::store_path::{
+    self, build_ca_path, build_output_path, build_text_path, StorePath, StorePathRef,
+};
 use bstr::BString;
 use serde::{Deserialize, Serialize};
 use sha2::{Digest, Sha256};
@@ -162,7 +164,7 @@ impl Derivation {
     /// drv path).
     pub fn derivation_or_fod_hash<F>(&self, fn_get_derivation_or_fod_hash: F) -> NixHash
     where
-        F: Fn(&str) -> NixHash,
+        F: Fn(&StorePathRef) -> NixHash,
     {
         // Fixed-output derivations return a fixed hash.
         // Non-Fixed-output derivations return a hash of the ATerm notation, but with all
@@ -178,10 +180,13 @@ impl Derivation {
             // derivation_or_fod_hash, and replace the derivation path with it's HEXLOWER
             // digest.
             // This is not the [NixHash::to_nix_hash_string], but without the sha256: prefix).
-            for (drv_path, output_names) in &self.input_derivations {
+            for (drv_path_str, output_names) in &self.input_derivations {
+                // parse drv_path to StorePathRef
+                let drv_path = StorePathRef::from_absolute_path(drv_path_str.as_bytes())
+                    .expect("invalid input derivation path");
                 replaced_input_derivations.insert(
                     data_encoding::HEXLOWER
-                        .encode(fn_get_derivation_or_fod_hash(drv_path).digest_as_bytes()),
+                        .encode(fn_get_derivation_or_fod_hash(&drv_path).digest_as_bytes()),
                     output_names.clone(),
                 );
             }