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>2023-03-30T12·01+0200
committerclbot <clbot@tvl.fyi>2023-03-30T14·03+0000
commit5f2c2e79e1778cda877d6122dd24be08740c8720 (patch)
treeb87dba0063a193a39c1bf57a2b1e3513039e144c /tvix/nix-compat/src/derivation/mod.rs
parent4ab180b1ebf411d7d7ebd98ae17c25945b17e2c2 (diff)
refactor(tvix/nix-compat): move build_store_path out of derivation r/6060
This doesn't have anything to do with ATerms, we just happen to be using
the aterm representation of a Derivation as contents.

Moving this into store_path/utils.rs makes these things much cleaner -
Have a build_store_path_from_references function, and a
build_store_path_from_fingerprint helper function that makes use of it.

build_store_path_from_references is invoked from the derivation module
which can be used to calculate the derivation path.

In the derivation module, we also invoke
build_store_path_from_fingerprint during the output path calculation.

Change-Id: Ia8d61a5e8e5d3f396f93593676ed3f5d1a3f1d66
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8367
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/nix-compat/src/derivation/mod.rs')
-rw-r--r--tvix/nix-compat/src/derivation/mod.rs28
1 files changed, 14 insertions, 14 deletions
diff --git a/tvix/nix-compat/src/derivation/mod.rs b/tvix/nix-compat/src/derivation/mod.rs
index 6912b692b2ca..2fa77cd26f49 100644
--- a/tvix/nix-compat/src/derivation/mod.rs
+++ b/tvix/nix-compat/src/derivation/mod.rs
@@ -1,7 +1,8 @@
 use crate::{
     nixhash::HashAlgo,
-    store_path::{self, StorePath},
-    texthash::text_hash_string,
+    store_path::{
+        self, build_store_path_from_fingerprint, build_store_path_from_references, StorePath,
+    },
 };
 use serde::{Deserialize, Serialize};
 use sha2::{Digest, Sha256};
@@ -10,7 +11,6 @@ use std::collections::{BTreeMap, BTreeSet};
 mod errors;
 mod output;
 mod string_escape;
-mod utils;
 mod validate;
 mod write;
 
@@ -21,7 +21,6 @@ mod tests;
 pub use crate::nixhash::{NixHash, NixHashWithMode};
 pub use errors::{DerivationError, OutputError};
 pub use output::Output;
-pub use utils::path_with_references;
 
 #[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
 pub struct Derivation {
@@ -77,12 +76,12 @@ impl Derivation {
         buffer
     }
 
-    /// Returns the drv path of a Derivation struct.
+    /// Returns the drv path of a [Derivation] struct.
     ///
-    /// The drv path is calculated by calculating the [text_hash_string], using
-    /// the `name` with a `.drv` suffix as name, all d.InputDerivations and d.InputSources as references,
-    /// and the ATerm representation of the Derivation as contents.
-    /// The text_hash_string is then passed to the build_store_path function.
+    /// The drv path is calculated by invoking [build_store_path_from_references], using
+    /// the `name` with a `.drv` suffix as name, all [Derivation::input_sources] and
+    /// keys of [Derivation::input_derivations] as references, and the ATerm string of
+    /// the [Derivation] as content.
     pub fn calculate_derivation_path(&self, name: &str) -> Result<StorePath, DerivationError> {
         // append .drv to the name
         let name = &format!("{}.drv", name);
@@ -97,9 +96,8 @@ impl Derivation {
             inputs
         };
 
-        let text_hash_str = &text_hash_string(name, self.to_aterm_string(), references);
-
-        utils::build_store_path(text_hash_str, name)
+        build_store_path_from_references(name, self.to_aterm_string(), references)
+            .map_err(|_e| DerivationError::InvalidOutputName(name.to_string()))
     }
 
     /// Returns the FOD digest, if the derivation is fixed-output, or None if
@@ -249,8 +247,10 @@ impl Derivation {
                 store_path::STORE_DIR,
                 output_path_name,
             ));
-            let abs_store_path =
-                utils::build_store_path(&fp, &output_path_name)?.to_absolute_path();
+
+            let abs_store_path = build_store_path_from_fingerprint(&output_path_name, &fp)
+                .map_err(|_e| DerivationError::InvalidOutputName(output_path_name.to_string()))?
+                .to_absolute_path();
 
             output.path = abs_store_path.clone();
             self.environment