47 lines
1.0 KiB
Nix
47 lines
1.0 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
cfg = config.hm-expire;
|
|
in {
|
|
options.hm-expire = {
|
|
enable = lib.mkEnableOption "Whether to enable hm-expire";
|
|
dates = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "weekly";
|
|
};
|
|
expire = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "-30 days";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
# This creates a user-level systemd service
|
|
systemd.user.services.cleanup-home-manager = {
|
|
Unit = {
|
|
Description = "Cleanup old Home Manager generations";
|
|
};
|
|
Service = {
|
|
Type = "oneshot";
|
|
ExecStart = "${pkgs.bash}/bin/bash -c '${pkgs.home-manager}/bin/home-manager expire-generations \"${cfg.expire}\"'";
|
|
};
|
|
};
|
|
|
|
systemd.user.timers.cleanup-home-manager = {
|
|
Unit = {
|
|
Description = "Weekly cleanup of Home Manager generations";
|
|
};
|
|
Timer = {
|
|
OnCalendar = cfg.dates;
|
|
Persistent = true;
|
|
};
|
|
Install = {
|
|
WantedBy = ["timers.target"];
|
|
};
|
|
};
|
|
};
|
|
}
|