about summary refs log tree commit diff
path: root/tvix/nix-compat/src/derivation
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-30T11·31+0200
committerclbot <clbot@tvl.fyi>2023-03-30T14·03+0000
commit6454769eefc6be2bc3f7351f915ca0be37e07541 (patch)
tree380b0ea6dbf54e4cc7b19f415cf22c6736ae9c7e /tvix/nix-compat/src/derivation
parent971080c9120725c0bec21ea2e5e14847b0e996e6 (diff)
refactor(tvix/nix-compat): drop is_derivation in build_store_path r/6058
This only added a suffix to the input argument, if build_store_path was
building the path of a Derivation.

As we need to also add the `.drv` suffix to the name we pass into
text_hash_string inside calculate_derivation_path, we can simply add the
suffix there and drop the parameter from build_store_path.

Change-Id: Icd5343dd1458f112b9296b389e81ce2ebdd16a9f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8365
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/derivation')
-rw-r--r--tvix/nix-compat/src/derivation/mod.rs8
-rw-r--r--tvix/nix-compat/src/derivation/utils.rs11
2 files changed, 7 insertions, 12 deletions
diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs
index 53bdccef6dce..6912b692b2ca 100644
--- a/tvix/nix-compat/src/derivation/mod.rs
+++ b/tvix/nix-compat/src/derivation/mod.rs
@@ -85,7 +85,7 @@ impl Derivation {
     /// The text_hash_string is then passed to the build_store_path function.
     pub fn calculate_derivation_path(&self, name: &str) -> Result<StorePath, DerivationError> {
         // append .drv to the name
-        let name_with_suffix = &format!("{}.drv", name);
+        let name = &format!("{}.drv", name);
 
         // collect the list of paths from input_sources and input_derivations
         // into a (sorted, guaranteed by BTreeSet) list of references
@@ -97,9 +97,9 @@ impl Derivation {
             inputs
         };
 
-        let text_hash_str = &text_hash_string(name_with_suffix, self.to_aterm_string(), references);
+        let text_hash_str = &text_hash_string(name, self.to_aterm_string(), references);
 
-        utils::build_store_path(true, text_hash_str, name)
+        utils::build_store_path(text_hash_str, name)
     }
 
     /// Returns the FOD digest, if the derivation is fixed-output, or None if
@@ -250,7 +250,7 @@ impl Derivation {
                 output_path_name,
             ));
             let abs_store_path =
-                utils::build_store_path(false, &fp, &output_path_name)?.to_absolute_path();
+                utils::build_store_path(&fp, &output_path_name)?.to_absolute_path();
 
             output.path = abs_store_path.clone();
             self.environment
diff --git a/tvix/nix-compat/src/derivation/utils.rs b/tvix/nix-compat/src/derivation/utils.rs
index 68ab3e23c94b..ee7ea26c6ae3 100644
--- a/tvix/nix-compat/src/derivation/utils.rs
+++ b/tvix/nix-compat/src/derivation/utils.rs
@@ -28,7 +28,6 @@ fn compress_hash(input: &[u8], output_size: usize) -> Vec<u8> {
 /// The string is hashed with sha256, its digest is compressed to 20 bytes, and
 /// nixbase32-encoded (32 characters)
 pub(super) fn build_store_path(
-    is_derivation: bool,
     fingerprint: &str,
     name: &str,
 ) -> Result<StorePath, DerivationError> {
@@ -38,12 +37,8 @@ pub(super) fn build_store_path(
         hasher.finalize()
     };
     let compressed = compress_hash(&digest, 20);
-    if is_derivation {
-        StorePath::from_string(format!("{}-{}.drv", nixbase32::encode(&compressed), name).as_str())
-    } else {
-        StorePath::from_string(format!("{}-{}", nixbase32::encode(&compressed), name,).as_str())
-    }
-    .map_err(|_e| DerivationError::InvalidOutputName(name.to_string()))
+    StorePath::from_string(format!("{}-{}", nixbase32::encode(&compressed), name,).as_str())
+        .map_err(|_e| DerivationError::InvalidOutputName(name.to_string()))
     // Constructing the StorePath can only fail if the passed output name was
     // invalid, so map errors to a [DerivationError::InvalidOutputName].
 }
@@ -56,5 +51,5 @@ pub fn path_with_references<S: AsRef<str>, I: IntoIterator<Item = S>, C: AsRef<[
     references: I,
 ) -> Result<StorePath, DerivationError> {
     let text_hash_str = text_hash_string(name, content, references);
-    build_store_path(false, &text_hash_str, name)
+    build_store_path(&text_hash_str, name)
 }