Skip to content

Emit basic dry run message for garbage collection#15229

Merged
Ericson2314 merged 1 commit intoNixOS:masterfrom
lisanna-dettwyler:fix-gc-dry-run
Feb 13, 2026
Merged

Emit basic dry run message for garbage collection#15229
Ericson2314 merged 1 commit intoNixOS:masterfrom
lisanna-dettwyler:fix-gc-dry-run

Conversation

@lisanna-dettwyler
Copy link
Contributor

nix store gc: prints number of paths that would be freed, but not bytes
nix-collect-garbage: ditto
nix-store --gc: retains current behavior

It would be very non-trivial to also compute the bytes that would be freed, due to hardlinking in the store.

Also adds checking for incompatible mixing of dry-run and max-freed options.

Resolves #5704

Motivation

A very basic output (path count) is better than the current behavior (no output / no-op). The current behavior is kind of dangerous because a user may take the empty output of --dry-run at face value, and assume running without it will not delete anything (or will delete less than it actually will, if combined with --delete-old).

Context

#5704

#5705


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added the new-cli Relating to the "nix" command label Feb 13, 2026
@Ericson2314
Copy link
Member

@lisanna-dettwyler Could you make PrintFreed into a plain function which is called from inside the lambda of a Finally?

nix store gc: prints number of paths that would be freed, but not bytes
nix-collect-garbage: ditto
nix-store --gc: retains current behavior

It would be very non-trivial to also compute the bytes that would be
freed, due to hardlinking in the store.

Also adds checking for incompatible mixing of dry-run and max-freed
options.

Resolves NixOS#5704

Signed-off-by: Lisanna Dettwyler <lisanna.dettwyler@gmail.com>
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks so much!

@Ericson2314 Ericson2314 added this pull request to the merge queue Feb 13, 2026
Merged via the queue into NixOS:master with commit 2913722 Feb 13, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-cli Relating to the "nix" command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"nix store gc --dry-run" doesn't print anything: fix or remove?

2 participants