Deleting old generations
Is there a way to manually delete old generations?
for me running nix-collect-garbage -d doesn't seem to delete old generations.
after having run it, when I run darwin-rebuild --list-generations I still get a list of all the generations.
Whereas for home-manager for example it deletes old generations.
I'm using fish shell.
I'm on the master channel for nix-darwin darwin https://github.com/LnL7/nix-darwin/archive/master.tar.gz, and I have updated nix-darwin to the latest.
Let me know if you need any more informations.
Same issue.
I assume this is happening with an installation that uses the nix-daemon.
On a multi user installation permissions of profiles is split between root and per user profiles. In this case the root profile manages the version of nix that's installed. Only per user profiles are owned by each user respectively so packages can be installed without privileges. The nix-darwin system profile also falls under root since it takes a similar place as the initial root profile.
The darwin-rebuild command automatically uses sudo in the appropriate places when switching to a new system, but nix-collect-garbage doesn't and thus won't have permissions to touch the system generations unless executed with sudo explicitly.
As you assumed, I am using nix-daemon.
After running sudo nix-collect-garbage -d, the old generations is cleaned up.
Same here. And of course, it worked with sudo. Should the documentation of this go in the wiki? I don't mind making a PR, I just don't know how to contribute to the wiki.
The wiki on github is a separate repo linked at in the right banner https://github.com/LnL7/nix-darwin.wiki.git. I'm a bit surprised that contributing isn't exposed in the webui however.
Is that repo public? That repo's address yields a 404 to me. Do you think it could be a problem with the repo's name? I've always open a PR from the github UI (to contribute from a fork). I don't know of any other way to do that.
It should be, but that's git only. Seems there's no way to contribute to github wikis without access to the repo which is disappointing.
Given this I would propose you make an issue (or comment here) with the content you would like to add.
Actually I just found an option to limit access to collaborators, perhaps it's accessible now?
Perhaps I'm not a collaborator, because I still get a 404.
I quite like what you wrote actually, I think it's a perfect explanation.
So as a contribution, I would add a page named Deleting old generations with the following.
Deleting old generations
TLDR: sudo nix-collect-garbage -d
On a multi user installation permissions of profiles is split between root and per user profiles. In this case the root profile manages the version of nix that's installed. Only per user profiles are owned by each user respectively so packages can be installed without privileges. The nix-darwin system profile also falls under root since it takes a similar place as the initial root profile.
The darwin-rebuild command automatically uses sudo in the appropriate places when switching to a new system, but nix-collect-garbage doesn't and thus won't have permissions to touch the system generations unless executed with sudo explicitly.
@happysalada I have permission for that, so I added it. https://github.com/LnL7/nix-darwin/wiki/Deleting-old-generations Feel free to edit if you want.
For the pureness of wiki, I will not mention you at wiki. Thanks for your summary. ;)
@c4710n awesome thanks! No need for the mention.
This appears to have changed behavior recently
when running sudo nix-collect-garbage -d the following warning now appears
warning: $HOME ('/Users/raphael') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
and it doesn't delete old darwin generations anymore. (without sudo doesn't work either).
for anyone else ending up here, here is what worked for me. you have to use the nix-collect-garbage produced by nix-darwin, so this will be
sudo ./result/sw/bin/nix-collect-garbage -d
Hitting the same thing as https://github.com/LnL7/nix-darwin/issues/237#issuecomment-1526952371
Can a maintainer please reopen this until nix-collect-garbage -d is fixed to once again delete old generations?
for anyone else ending up here, here is what worked for me. you have to use the nix-collect-garbage produced by nix-darwin
This didn't work for me:
nix-darwin on master
❯ ./result-2/sw/bin/nix-collect-garbage -d
removing old generations of profile /Users/jab/.local/state/nix/profiles/channels
removing old generations of profile /nix/var/nix/profiles/per-user/jab/profile
removing old generations of profile /nix/var/nix/profiles/per-user/jab/channels
removing old generations of profile /nix/var/nix/profiles/per-user/jab/profile
removing old generations of profile /nix/var/nix/profiles/per-user/jab/channels
finding garbage collector roots...
deleting garbage...
deleting '/nix/store/l2hbrnxdskw4zafnsdyk2b18nbdikdp1-stdenv-darwin'
...
deleting unused links...
note: currently hard linking saves 6215.80 MiB
17 store paths deleted, 8.93 MiB freed
nix-darwin on master took 5s
❯ darwin-rebuild --list-generations | wc -l # did not remove old generations
59
Using nix-darwin via a flake, the following worked for me:
-
without sudo,
nix-collect-garbage -d; this seemed to remove old profiles' garbage collector roots -
sudo ./result/sw/bin/nix-collect-garbage -dwas then able to clean things up
Thanks @StephenWithPH! That worked for me too. Great to have a workaround while a fix for this is still pending.
@StephenWithPH 's solution is working great - is there a way to tell nix-collect-garbage to only consider up to a certain generation in this case? I'd ideally like to keep the last one or two generations around in case a new generation is broken.
You can use nix-collect-garbage --delete-older-than 30d to only delete configurations older than 30 days
I've tried sudo nix-collect-garbage -d and still had nix store paths I can't remove cause they're in old home manager generations. I used home-manager expire-generations "-1 days" to get rid of them. Then the garbage collect went to town on them.
Ah yeah, if you're using standalone home-manager then you'll need to use the home-manager command (I'm using the nix-darwin module)