How to clean system older trash dan 7 days

When I rebuild (switch) my configuration.nix file with the below code to clean the system for older than 7 days it returns in errors.

### clean system
  nix = {
    settings.auto-optimise-store = true;
    gc = {
      automatic = true;
      dates = "weekly";
      options = "--delete-older-than 7d";
    };
  };

What errors does it return? It looks correct to me.

I’d also suggest setting nix.gc.persistent if your computer won’t be running 24/7.

Is it just because there’s a missing semi-colon at the end of the options line?

1 Like
[henry@nixos:~/git/mynixos]$ sudo nixos-rebuild switch
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:352:5:

          351| ### clean system
          352| nix = {
             |     ^
          353|   settings.auto-optimise-store = true;
(use '--show-trace' to show detailed location information)
building Nix...
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:352:5:

          351| ### clean system
          352| nix = {
             |     ^
          353|   settings.auto-optimise-store = true;
(use '--show-trace' to show detailed location information)
building the system configuration...
error: syntax error, unexpected '=', expecting end of file

       at /etc/nixos/configuration.nix:352:5:

          351| ### clean system
          352| nix = {
             |     ^
          353|   settings.auto-optimise-store = true;
(use '--show-trace' to show detailed location information)

Indeed, yet it does not solve all errors.

No, it is not a server, but a desktop. However, sometimes the machine will be on for many days at a time. What would you advise in such situation?

What about:

  system.autoUpgrade.enable = true;
  nix.settings.auto-optimise-store = true;
  nix.gc.automatic = true;
  nix.gc.dates = "daily";
  nix.gc.options = "--delete-older-than 7d";

Stupid me!!!

It was a ‘}’ in the wrong place afterall. OMG

Thanks though guys!

1 Like

I would have persistent on pretty much all the time. It just makes sure that if your computer isn’t on when the timer triggers, it will do the garbage collection when you next turn it on.

I think that’s the least surprising behavior, frankly.

1 Like

Like this right?

### clean system
nix = {
  settings.auto-optimise-store = true;
  gc = {
    automatic = true;
    persistent = true;
    dates = "weekly";
    options = "--delete-older-than 7d";
  };
};
1 Like