Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Conversation

asymmetric
Copy link
Contributor

@asymmetric asymmetric commented Apr 26, 2021

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

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.
@bb2020
Copy link
Member

bb2020 commented Apr 28, 2021

Storage is cheap these days. This change reminds me the dark ages of Windows when winsat kicks in randomly and bogs down the entire system 😃

@asymmetric
Copy link
Contributor Author

asymmetric commented Apr 28, 2021

@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.

@bb2020
Copy link
Member

bb2020 commented Apr 28, 2021

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 /nix onto a larger and slower external drive. I personally don't like the idea of running background tasks by default (Windows flashbacks).

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 cache.nixos.org in the long run.

@SuperSandro2000
Copy link
Member

SuperSandro2000 commented Apr 30, 2021

I only run GC when the drive is out of space, if ever. I am sure most people do the same.

I have a nightly cron otherwise my disk would be full every day and thing stop working.
Also you do not want to sit looking at the command 20 minutes until it cleared the gigabytes out of the way.

But I am also a special power user.

Also, some users mount /nix onto a larger and slower external drive.

This change is not targeted at them. We want to help people who run the a close to default installation.

Constantly removing and re-downloading imperative tools is going to put more stress on your computer

Building is far more stress.

cache.nixos.org in the long run.

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.

@bb2020
Copy link
Member

bb2020 commented Apr 30, 2021

Also, some users mount /nix onto a larger and slower external drive.

This change is not targeted at them. We want to help people who run the a close to default installation.

I mean background GC will slow down their system even more because of external drive being slower.

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.

Exactly my point 👍

@michaelpj
Copy link
Contributor

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!

I assume most users want some kind of [automatic] GC.

Is this true? I don't think it obviously is, maybe we should ask people.

@bb2020
Copy link
Member

bb2020 commented Apr 30, 2021

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.

Imagine building gcc or chromium and then it is garbage collected automatically.

@mohe2015
Copy link
Contributor

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>
Copy link
Member

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

@figsoda
Copy link
Member

figsoda commented Aug 26, 2021

should this be gated behind a config.system.stateVersion?

@bb2020
Copy link
Member

bb2020 commented Aug 26, 2021

I don't think this should be merged.

@mohe2015
Copy link
Contributor

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.

@stale
Copy link

stale bot commented Apr 18, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 18, 2022
@milachew
Copy link

milachew commented Feb 12, 2023

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:

  • rely on the number of days of the working generation
  • start collecting garbage when a certain number of generations is reached (I don't think anyone will object here, but having 20-50 generations to roll back when you hit an unbootable system, for example, hardly solves anything. About 10 , i think, is enough)
  • start collecting garbage when it reaches a certain-occupied space and clean up to a certain free space (say, as soon as_0.5 is occupied by /nix/store, start cleaning up to 0.2).

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 nixos-rebuild switch after the garbage-collector. Otherwise the boot menu will contain items which have been deleted.

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.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 12, 2023
@bb2020
Copy link
Member

bb2020 commented Feb 12, 2023

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.

@SuperSandro2000
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants