New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix.gc.automatic
: default to true
#120759
Conversation
Assuming most users want some kind of GC, turning it on makes it easy for both newcomers and experienced users to get the behaviour they want. Those who want it off know where to look.
Storage is cheap these days. This change reminds me the dark ages of Windows when |
@bb2020 I agree that storage is cheap, but I see it more as a quality of life improvement, especially for first time users/first installs: if we assume that almost everyone will turn this on, then why not turn it on by default? It's probably impossible to know whether the assumption is factually true, but in my anecdotal experience, guiding a few people through NixOS installs, it is. |
I only run GC when the drive is out of space, if ever. I am sure most people do the same. Also, some users mount GC actually shines when you start deleting previous generations. Constantly removing and re-downloading imperative tools is going to put more stress on your computer and |
I have a nightly cron otherwise my disk would be full every day and thing stop working. But I am also a special power user.
This change is not targeted at them. We want to help people who run the a close to default installation.
Building is far more stress.
The bandwidth used is probably a bigger concern than if it stresses amazons servers. The problem is that you don't easily know when gc is running and you might wonder why the system is slow. |
I mean background GC will slow down their system even more because of external drive being slower.
Exactly my point 👍 |
Garbage collecting is not totally consequence-free. Anyone who builds things ad-hoc from time to time has been bitten by garbage collection deleting something that they then want to use again. And having it be done automatically means that this will happen unpredictably, which makes it extra annoying. Moreover, garbage collection is most useful when it's combined with deleting generations, which the auto GC does not do. A clueless user will barely benefit from this unless they also manually delete generations... at which point they might as well also garbage collect!
Is this true? I don't think it obviously is, maybe we should ask people. |
Imagine building |
Maybe instead run something like this in a systemd timer? #!/bin/sh
avail=$(df --block-size=1G /nix | tail -1 | awk '{print $4}') # GB
if [ "$avail" -lt "1" ]; then
notid=$(gdbus call --session --dest=org.freedesktop.Notifications --object-path=/org/freedesktop/Notifications --method=org.freedesktop.Notifications.Notify "NixOS" 0 "nix-snowflake" 'Low on disk space' 'You seem to be low on disk space. NixOS keeps old unused versions of software locally so you may want to delete them. This is called garbage collection. You may also want to delete old versions of you whole system although this prevents you from rolling back.' '["help","Help","run-gc","Only GC","run-gc-d","Also delete old generations"]' '{"urgency": <0>}' 0 | sed -r 's/\(uint32 ([0-9]*),\)/\1/')
echo $notid
gdbus monitor --session --dest=org.freedesktop.Notifications --object-path=/org/freedesktop/Notifications |
while IFS= read -r line
do
echo $line
if echo $line | egrep --color "/org/freedesktop/Notifications: org.freedesktop.Notifications.NotificationClosed \(uint32 $notid, uint32 [0-9]+\)"; then
pkill -SIGINT -P $$
exit 0
fi
if echo $line | grep --color "/org/freedesktop/Notifications: org.freedesktop.Notifications.ActionInvoked (uint32 $notid, 'help')"; then
xdg-open "https://nixos.org/guides/nix-pills/garbage-collector.html"
fi
if echo $line | grep --color "/org/freedesktop/Notifications: org.freedesktop.Notifications.ActionInvoked (uint32 $notid, 'run-gc')"; then
nix-collect-garbage
fi
if echo $line | grep --color "/org/freedesktop/Notifications: org.freedesktop.Notifications.ActionInvoked (uint32 $notid, 'run-gc-d')"; then
nix-collect-garbage -d
fi
done
fi |
@@ -706,6 +706,11 @@ environment.systemPackages = [ | |||
for details. | |||
</para> | |||
</listitem> | |||
<listitem> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should target nixos/doc/manual/release-notes/rl-2111.section.md
and generate with nixos/doc/manual/md-to-db.sh
should this be gated behind a |
I don't think this should be merged. |
I personally would prefer adding a section to the docs instead. Then we could also explain what this does so people are not confused when suddenly derivations disappear. |
I marked this as stale due to inactivity. → More info |
I think the garbage collector itself with default settings, as just a service that runs automatically sometime there, is wrong. There is too much built around it because of the structure of NixOS, from the rollback capability to the temporary, possibly large packages that are once there downloaded via nix-shell. I think it would be much more correct to run the garbage collector according to a certain script. For example:
In any case, automating something like a garbage collector in the most optimal way will really bring NixOS one step closer to a system that "just works" for non-technical or lazy user :) Also, please note that even if you achieve the default garbage-collector, you will need to decide what to do with the default boot items. At the moment you need to manually run the Therefore, after this automatic garbage removal, it will need to clear the boot items as well. And until this is done, I personally don't see the point of an automatic garbage collector for ordinary users. |
I loose my mind when some task starts running at background randomly. On Windows, you just open task manager to see %80 of the CPU is being consumed by some random task. I can't believe people accept this as a norm. |
Closing this because the author went silent for over a year and this needs a more sophisticated solution, maybe something similar to https://github.com/numtide/srvos/blob/main/nixos/roles/nix-remote-builder.nix#L19 |
Motivation for this change
I assume most users want some kind of GC. Novices are the ones who would have a hard time finding out this setting, and would be surprised with their disk filling up without recourse.
Power users, on the other hand, know where to look in case they want to turn GC off..
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)