home-manager
home-manager copied to clipboard
bug: home manager as a NixOS module makes its own GC roots which are not deleted even when specifying --delete-generations
Are you following the right branch?
- [X] My Nixpkgs and Home Manager versions are in sync
Is there an existing issue for this?
- [X] I have searched the existing issues
Issue description
I noticed that my disk usage was too high so i printed all gc roots and saw the gc roots from home-manager, this is not documented anywhere and is quite unexpected, i assumed that specifying delete generations would remove everything from those generations on my system.
what happens if i need to rollback my system configuration and i've deleted the corresponding home-manager generation?
how can i delete these gc roots besides by using rm on them manually?
Maintainer CC
No response
System information
- system: `"x86_64-linux"`
- host os: `Linux 6.1.62, NixOS, 23.11 (Tapir), 23.11.20231117.c757e9b`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.18.1`
- nixpkgs: `/nix/store/0y446mjvwzrhv723jh0lpkaz9gw8jzbq-source`
I noticed that my disk usage was too high so i printed all gc roots and saw the gc roots from home-manager, this is not documented anywhere and is quite unexpected, i assumed that specifying delete generations would remove everything from those generations on my system.
Yes, this is a long-standing issue that should be resolved at some point. Until then, any PR updating the documentation to match the current behavior would be very welcome.
what happens if i need to rollback my system configuration and i've deleted the corresponding home-manager generation?
A new HM generation should be generated matching the rollback target's configuration.
how can i delete these gc roots besides by using rm on them manually?
I would suggest using nix-collect-garbage since it should handle all profiles, whether NixOS, Home Manager, or other.
Excuse me, but is this issue about having many home-manager-paths in /nix/store?
I use home-manager as an input to my flake definition and thus also a module, and I am currently left with many home-manager-paths in /nix/store which even survive nix-collect-garbage -d:
$ sudo nix-collect-garbage -d
removing old generations of profile /nix/var/nix/profiles/per-user/nixos/profile
removing old generations of profile /nix/var/nix/profiles/per-user/root/channels
removing old generations of profile /nix/var/nix/profiles/system
removing old generations of profile /nix/var/nix/profiles/per-user/root/channels
finding garbage collector roots...
deleting garbage...
deleting unused links...
note: currently hard linking saves -0.00 MiB
0 store paths deleted, 0.00 MiB freed
$ ls /nix/store | grep 'home-manager-path$' | wc -l
20
I have also seen home manager related paths in gc roots, which point back to my own profiles:
$ ls -l /nix/var/nix/gcroots/auto | grep home-manager | wc -l
21
$ ls -l /nix/var/nix/gcroots/auto/lhpnhpy8r432v8j5mwg348s6pc2w0cv5
lrwxrwxrwx 1 root root 56 Dec 13 14:19 /nix/var/nix/gcroots/auto/lhpnhpy8r432v8j5mwg348s6pc2w0cv5 -> /home/xug/.local/state/nix/profiles/home-manager-11-link
Now, I do not have home-manager the command as I am using home manager as a flake module. Do I manually delete the unwanted symlinks in my profiles and then do nix-collect-garbage -d to clean up the old generations? Thanks.
Update: I temporarily solved my issue with the following command template:
nix-env --profile ~/.local/state/nix/profiles/home-manager --delete-generations <generations-list...>
where generations-list is a list of numbers.
I have a user service and timer to expire old HM GC roots, which are then cleaned up on the next run of nix-collect-garbage: https://git.sr.ht/~r-vdp/nixos-config/tree/c4335ada77879f254a5a58850edf5e9bbd0f7d77/item/home-modules/default.nix#L164
I think that this behaviour changed in a recent version of nix when the user profiles moved to a different location, but I didn't look into the details. It's been on my list to submit a PR to add such a service to expire generations to HM so that it can be enabled with an option.
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.
wow i hate the stale bot, anyways i think the solution would be to automatically delete the home-manager profile if the corresponding system profile is deleted any directions on this?
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.