Skip to content

Commit 9870817

Browse files
committed
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).
1 parent 296e9dc commit 9870817

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

magic-nix-cache/src/gha.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct GhaCache {
2121
worker_result: RwLock<Option<tokio::task::JoinHandle<Result<()>>>>,
2222

2323
channel_tx: UnboundedSender<Request>,
24+
25+
compute_closure: bool,
2426
}
2527

2628
#[derive(Debug)]
@@ -36,6 +38,7 @@ impl GhaCache {
3638
store: Arc<NixStore>,
3739
metrics: Arc<telemetry::TelemetryReport>,
3840
narinfo_negative_cache: Arc<RwLock<HashSet<String>>>,
41+
compute_closure: bool,
3942
) -> Result<GhaCache> {
4043
let mut api = Api::new(credentials)?;
4144

@@ -64,6 +67,7 @@ impl GhaCache {
6467
api,
6568
worker_result: RwLock::new(Some(worker_result)),
6669
channel_tx,
70+
compute_closure,
6771
})
6872
}
6973

@@ -85,18 +89,18 @@ impl GhaCache {
8589
store: Arc<NixStore>,
8690
store_paths: Vec<StorePath>,
8791
) -> Result<()> {
88-
// FIXME: make sending the closure optional. We might want to
89-
// only send the paths that have been built by the user, under
90-
// the assumption that everything else is already in a binary
91-
// cache.
92-
// FIXME: compute_fs_closure_multi doesn't return a
93-
// toposort, though it doesn't really matter for the GHA
94-
// cache.
95-
let closure = store
96-
.compute_fs_closure_multi(store_paths, false, false, false)
97-
.await?;
98-
99-
for p in closure {
92+
let final_paths = if self.compute_closure {
93+
// FIXME: compute_fs_closure_multi doesn't return a
94+
// toposort, though it doesn't really matter for the GHA
95+
// cache.
96+
store
97+
.compute_fs_closure_multi(store_paths, false, false, false)
98+
.await?
99+
} else {
100+
store_paths
101+
};
102+
103+
for p in final_paths {
100104
self.channel_tx
101105
.send(Request::Upload(p))
102106
.map_err(|_| Error::Internal("Cannot send upload message".to_owned()))?;

magic-nix-cache/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ struct Args {
127127
/// Whether or not to diff the store before and after Magic Nix Cache runs
128128
#[arg(long, default_value_t = false)]
129129
diff_store: bool,
130+
131+
/// (GHA only) Don't include the closure of the to-be-cached store paths
132+
#[arg(long, default_value_t = false)]
133+
no_closure: bool,
130134
}
131135

132136
#[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)]
@@ -389,6 +393,7 @@ async fn main_cli() -> Result<()> {
389393
store.clone(),
390394
metrics.clone(),
391395
narinfo_negative_cache.clone(),
396+
!args.no_closure,
392397
)
393398
.with_context(|| "Failed to initialize GitHub Actions Cache API")?;
394399

0 commit comments

Comments
 (0)