From 9870817d875ab7a102fcbbf5df68e21c5d390144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignas=20Vy=C5=A1niauskas?= Date: Thu, 24 Oct 2024 19:38:56 +0300 Subject: [PATCH] Add option for disabling closure computation in GHA cache Allows to only cache the built derivations without their closures. This avoids polluting the GHA cache with many duplicate entries, which happens when a downstream derivation changes (and is rebuilt), but its dependencies don't (but would get pushed to the cache each time regardless). --- magic-nix-cache/src/gha.rs | 28 ++++++++++++++++------------ magic-nix-cache/src/main.rs | 5 +++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/magic-nix-cache/src/gha.rs b/magic-nix-cache/src/gha.rs index cd4df57..ecfc5eb 100644 --- a/magic-nix-cache/src/gha.rs +++ b/magic-nix-cache/src/gha.rs @@ -21,6 +21,8 @@ pub struct GhaCache { worker_result: RwLock>>>, channel_tx: UnboundedSender, + + compute_closure: bool, } #[derive(Debug)] @@ -36,6 +38,7 @@ impl GhaCache { store: Arc, metrics: Arc, narinfo_negative_cache: Arc>>, + compute_closure: bool, ) -> Result { let mut api = Api::new(credentials)?; @@ -64,6 +67,7 @@ impl GhaCache { api, worker_result: RwLock::new(Some(worker_result)), channel_tx, + compute_closure, }) } @@ -85,18 +89,18 @@ impl GhaCache { store: Arc, store_paths: Vec, ) -> Result<()> { - // FIXME: make sending the closure optional. We might want to - // only send the paths that have been built by the user, under - // the assumption that everything else is already in a binary - // cache. - // FIXME: compute_fs_closure_multi doesn't return a - // toposort, though it doesn't really matter for the GHA - // cache. - let closure = store - .compute_fs_closure_multi(store_paths, false, false, false) - .await?; - - for p in closure { + let final_paths = if self.compute_closure { + // FIXME: compute_fs_closure_multi doesn't return a + // toposort, though it doesn't really matter for the GHA + // cache. + store + .compute_fs_closure_multi(store_paths, false, false, false) + .await? + } else { + store_paths + }; + + for p in final_paths { self.channel_tx .send(Request::Upload(p)) .map_err(|_| Error::Internal("Cannot send upload message".to_owned()))?; diff --git a/magic-nix-cache/src/main.rs b/magic-nix-cache/src/main.rs index 9a2b9b2..06bd7de 100644 --- a/magic-nix-cache/src/main.rs +++ b/magic-nix-cache/src/main.rs @@ -127,6 +127,10 @@ struct Args { /// Whether or not to diff the store before and after Magic Nix Cache runs #[arg(long, default_value_t = false)] diff_store: bool, + + /// (GHA only) Don't include the closure of the to-be-cached store paths + #[arg(long, default_value_t = false)] + no_closure: bool, } #[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)] @@ -389,6 +393,7 @@ async fn main_cli() -> Result<()> { store.clone(), metrics.clone(), narinfo_negative_cache.clone(), + !args.no_closure, ) .with_context(|| "Failed to initialize GitHub Actions Cache API")?;