{ config, lib, ... }:

with lib;

let
  cfg = config.settings.services.garbage-collection;
in {
  options = {
    settings.services.garbage-collection.enable = lib.mkOption {
      type = lib.types.bool;
      description = ''
        Enable garbage collection of nix store
      '';
    };
  };

  config = mkIf cfg.enable {
    nix.gc = {
      automatic = true;
      dates = "weekly";
      options = "--delete-older-than 1w";
    };

    nix.settings.auto-optimise-store = true;
  };
}
