Use garbage collector declaratively

I need to automate garbage collection process on my server, so I need to run nix-collect-garbage -d declaratively. I can create systemd service that does that, but I wanted to clarify, if there’s any native methods of declarative management available?

There is the nix.gc.* configuration option, which should be exactly what you want. You may also be interested in nix.optimise and nix.autoOptimiseStore.

1 Like

What’s the difference between autoOptimiseStore and optimise.*.

Do they refer to different kinds of optimisations?
The option comments are not clear on this.

nix.autoOptimise does optimise on each operation to the store.

The nix.optimise.* configure a scheduled service that basically runs nix optimise-store occasionally.

3 Likes