{
  lib,
  config,
  inputs,
  ...
}: let
  cfg = config.myConfig.autoUpdate;
in {
  options.myConfig.autoUpdate = {
    enable = lib.mkEnableOption "extra binary caches";
  };

  config = lib.mkIf cfg.enable {
    system.autoUpgrade = {
      enable = true;
      flake = inputs.self.outPath;
      flags = [
        "--recreate-lock-file"
        "--commit-lock-file"
        "-L"
      ];
      dates = "9:00";
      randomizedDelaySec = "45min";
    };

    nix.gc = {
      automatic = true;
      dates = "10:00";
      randomizedDelaySec = "45min";
      options = "--delete-older-than 14d";
    };
  };
}
