about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-13T22·45+0300
committertazjin <tazjin@tvl.su>2023-01-17T10·31+0000
commit79e54f46ce1b532a115d3b53482216a4b22f9881 (patch)
tree2e868d5c5dbf8bab7111f019d945c7a68ac833cc
parent499e72c1cba8f7aa0415d3d8b93c57ca98457635 (diff)
feat(tvix/cli): add replacement strings tracking to KnownPaths r/5673
Replacement strings are some weird internal feature of Nix that is
required for calculating derivation hashes. We need to track these
like other paths, as they need to be re-used on builds with
dependencies on values from previous builds.

Change-Id: Ie955b3fb5ae3685cfadfbe4d06ea6b5e219590c7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7828
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
-rw-r--r--tvix/cli/src/known_paths.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/tvix/cli/src/known_paths.rs b/tvix/cli/src/known_paths.rs
index 569fb41ba318..a5e95f5b5972 100644
--- a/tvix/cli/src/known_paths.rs
+++ b/tvix/cli/src/known_paths.rs
@@ -33,6 +33,12 @@ pub enum PathType {
 pub struct KnownPaths {
     /// All known paths, and their associated [`PathType`].
     paths: HashMap<String, PathType>,
+
+    /// All known replacement strings for derivations.
+    ///
+    /// Keys are derivation paths, values are the opaque replacement
+    /// strings.
+    replacements: HashMap<String, String>,
 }
 
 impl Index<&str> for KnownPaths {
@@ -112,4 +118,27 @@ impl KnownPaths {
         let candidates = self.paths.keys().map(Clone::clone).collect();
         ReferenceScanner::new(candidates)
     }
+
+    /// Fetch the opaque "replacement string" for a given derivation path.
+    pub fn get_replacement_string(&self, drv: &str) -> String {
+        // TODO: we rely on an invariant that things *should* have
+        // been calculated if we get this far.
+        self.replacements[drv].clone()
+    }
+
+    pub fn add_replacement_string<D: ToString>(&mut self, drv: D, replacement_str: &str) {
+        let old = self
+            .replacements
+            .insert(drv.to_string(), replacement_str.to_owned());
+
+        #[cfg(debug_assertions)]
+        {
+            if let Some(old) = old {
+                debug_assert!(
+                    old == replacement_str,
+                    "replacement string for a given derivation should always match"
+                );
+            }
+        }
+    }
 }