Gc old generations in home-manager declaratively

well all know how we can manipulate the gc in nixos configuration

{lib, ...}: {
  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];

  nix = {
    gc = {
      automatic = true;
      options = lib.mkDefault "--delete-older-than 15d";
    };
    optimise.automatic = true;
  };
  nix.settings.auto-optimise-store = true;
  system = {
    autoUpgrade.enable = true;
    autoUpgrade.dates = lib.mkDefault "weekly";
  };
}

but how can i do the same behaviors like deleting generations older than 15days but for home manager?

NOTE: i’m on home manager standalone

Write a user service that does the same thing?

Just use the nix.gc-Options in your home-manager config. It will run the GC under your user account and clean up the hm-generations.

what is services.home-manager.autoExpire.enable or services.home-manager.autoExpire.store.cleanup what are these options for then?

They serve a similar purpose. Can be used for scenarios such as “expire daily, run GC weekly” (if nix is configured to auto-GC on low disk, it can collect expired generations to free space immediately, but under normal circumstances GC still happens at a predictable time)