nix icon indicating copy to clipboard operation
nix copied to clipboard

nix-collect-garbage: Allow number of generations to be specified rather than age

Open jalseth opened this issue 1 year ago • 5 comments

This is useful for scenarios where you want to ensure N generations are available for roll-back and all others are deleted to free up space.

Motivation

Implements #9455.

Context

See #9455.

Priorities and Process

Add :+1: to pull requests you find important.

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

jalseth avatar Apr 07 '24 19:04 jalseth

  • --delete-older-than +N isn't very intuitive, so it's probably better to have a different flag for this, e.g. --keep N.
  • This functionality should also be exposed by nix profile wipe-history, since we want the new CLI to have feature parity with the old one.
  • There should be a test for this.

edolstra avatar Apr 10 '24 20:04 edolstra

See also https://github.com/NixOS/nix/pull/9894

Ericson2314 avatar May 22 '24 17:05 Ericson2314

Any reason this isn't merged? Having the same option as in nix-env would be helpful.

NomAnor avatar Sep 02 '24 08:09 NomAnor

The manpage mentions this feature should already exist as it says:

This is the equivalent of invoking nix-env --delete-generations <period> on each found profile. See the documentation of that command for additional information about the period argument.

It would be good to get this PR in or change the docs to avoid confusion.

srounce avatar Sep 02 '24 10:09 srounce

I would appreciate it if these specifying age and number of generations were not mutually exclusive. In particular, I'd like to be able to specify "delete all generations older than X days, but make sure at least N generations are kept". This would make more sense with a separate flag, like the aforementioned --keep.

There is a bit of an issue here with ambiguity on what it means to specify both ("both" or "either"), but since "either" can easily be achieved by just running the command twice, I don't think that this is a significant problem.

MithicSpirit avatar Oct 16 '24 00:10 MithicSpirit

There is a bit of an issue here with ambiguity on what it means to specify both ("both" or "either"), but since "either" can easily be achieved by just running the command twice, I don't think that this is a significant problem.

The nix.gc service only runs it once, so having the ability to specify "either" is still important for that.

Rua avatar Jan 02 '25 15:01 Rua