about summary refs log tree commit diff
path: root/tvix/nix-compat/src/derivation/utils.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-30T11·27+0200
committerclbot <clbot@tvl.fyi>2023-03-30T14·03+0000
commit971080c9120725c0bec21ea2e5e14847b0e996e6 (patch)
tree42132ef1f2c39e25e87f416bede5df5985853e6e /tvix/nix-compat/src/derivation/utils.rs
parent14c5781389838f05f3f0063e8c7f04b1eeceaf2e (diff)
refactor(tvix/nix-compat): add text_hash_string function r/6057
Use it to calculate the text_hash_string, which is then used in the
calculate_derivation_path and path_with_references functions.

Relates to b/263.

Change-Id: I7478825e2a23a11224212fea5e3fd06daa97d5e5
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8364
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/derivation/utils.rs')
-rw-r--r--tvix/nix-compat/src/derivation/utils.rs29
1 files changed, 4 insertions, 25 deletions
diff --git a/tvix/nix-compat/src/derivation/utils.rs b/tvix/nix-compat/src/derivation/utils.rs
index cbb5d02a2180..68ab3e23c94b 100644
--- a/tvix/nix-compat/src/derivation/utils.rs
+++ b/tvix/nix-compat/src/derivation/utils.rs
@@ -1,7 +1,7 @@
 use crate::derivation::DerivationError;
 use crate::nixbase32;
-use crate::nixhash::NixHash;
-use crate::store_path::{self, StorePath};
+use crate::store_path::StorePath;
+use crate::texthash::text_hash_string;
 use sha2::{Digest, Sha256};
 
 /// compress_hash takes an arbitrarily long sequence of bytes (usually
@@ -55,27 +55,6 @@ pub fn path_with_references<S: AsRef<str>, I: IntoIterator<Item = S>, C: AsRef<[
     content: C,
     references: I,
 ) -> Result<StorePath, DerivationError> {
-    let mut s = String::from("text");
-
-    for reference in references {
-        s.push(':');
-        s.push_str(reference.as_ref());
-    }
-
-    let content_digest = {
-        let mut hasher = Sha256::new();
-        hasher.update(content);
-        hasher.finalize()
-    };
-
-    let h = NixHash::new(crate::nixhash::HashAlgo::Sha256, content_digest.to_vec());
-
-    s.push_str(&format!(
-        ":{}:{}:{}",
-        h.to_nix_hash_string(),
-        store_path::STORE_DIR,
-        name
-    ));
-
-    build_store_path(false, &s, name)
+    let text_hash_str = text_hash_string(name, content, references);
+    build_store_path(false, &text_hash_str, name)
 }