nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
6.87k stars 1.79k forks source link

Enhance the behavior of the expire-generations option to more closely match nix delete-generations #3325

Open Slime90 opened 2 years ago

Slime90 commented 2 years ago

Currently, the home-manager --expire-generations option which was added in 2018 only supports expiring generations based on a number of days:

expire-generations timestamp
    Remove generations older than timestamp where timestamp is interpreted as in the -d argument of the date(1)
     tool. For example -30 days or 2018-01-01.

nix allows us to delete generations a number of different ways:

Operation --delete-generations
   Synopsis
       nix-env --delete-generations generations

   Description
       This operation deletes the specified generations of the current profile.  The generations can be a list of gener‐
       ation numbers, the special value old to delete all non-current generations, a value such as  30d  to  delete  all
       generations  older  than the specified number of days (except for the generation that was active at that point in
       time), or a value such as +5 to keep the last 5 generations ignoring any newer than current, e.g., if 30  is  the
       current  generation +5 will delete generation 25 and all older generations. Periodically deleting old generations
       is important to make garbage collection effective.

   Examples
       $ nix-env --delete-generations 3 4 8

       $ nix-env --delete-generations +5

       $ nix-env --delete-generations 30d

       $ nix-env -p other_profile --delete-generations old

Some of us have their nix environment configured with scripts to keep a certain number of generations instead of relying on the age of the generations, which is useful for garbage collections and keeping aligned with limiting grub environments to retain. Presently it is not possible to retain the same number of nixos and home-manager generations, instead we are forced to expire home-manager generations based on when they happen to have been created, or not at all. If cleanup and garbage collection has not been run in some time, this results in 1 nixos generation being removed, but potentially all non-current home-manager generations.

I am requesting that the expire-generations option for home-manager be updated to as closely possible follow the behavior of nix delete-generations.

stale[bot] commented 1 year ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

ncfavier commented 1 year ago

@rycee any reason doExpireGenerations doesn't just call nix-env --delete-generations?

stale[bot] commented 1 year ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

ghost commented 1 year ago

this also matters to me!

beeb commented 1 year ago

This would also be of use to me.

stereomato commented 1 year ago

and to me!

tomrut commented 1 week ago

It would be great to have it. I'd like to keep e.g. last three generations. Of course can do it with some script, but its tedious to have it done this way.