From 79e54f46ce1b532a115d3b53482216a4b22f9881 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 14 Jan 2023 01:45:57 +0300 Subject: feat(tvix/cli): add replacement strings tracking to KnownPaths 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 Tested-by: BuildkiteCI --- tvix/cli/src/known_paths.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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, + + /// All known replacement strings for derivations. + /// + /// Keys are derivation paths, values are the opaque replacement + /// strings. + replacements: HashMap, } 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(&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" + ); + } + } + } } -- cgit 1.4.1