Add home-manager cleanup cronjob

This commit is contained in:
albert 2025-01-18 00:53:02 +01:00
parent 322b19b3c6
commit 77acbbfe51
Signed by: albert
GPG key ID: 3895DD267CA11BA9
3 changed files with 32 additions and 20 deletions

View file

@ -0,0 +1,26 @@
{ pkgs, ... }: {
systemd.user.services.cleanup-generations = {
Unit = {
Description = "Cleanup old home-manager generations";
};
Service = {
Type = "oneshot";
ExecStart = "${pkgs.writeShellScript "cleanup-generations" ''
home-manager generations | tail -n +6 | awk '{print $5}' | xargs -I {} home-manager remove-generations {}
''}";
};
};
systemd.user.timers.cleanup-generations = {
Unit = {
Description = "Timer for cleaning up old home-manager generations";
};
Timer = {
OnCalendar = "weekly";
Persistent = true;
};
Install = {
WantedBy = [ "timers.target" ];
};
};
}

View file

@ -3,6 +3,9 @@
# Common configs
./common/software/cli
# Services
./common/services/clean-home-manager.nix
# User configs
./users/${username}
@ -25,15 +28,6 @@
homeDirectory = "/home/${username}";
sessionPath = [ "$HOME/.local/bin" ];
};
# Clean up all but the most recent 5 home-manager configs
services.cron = {
enable = true;
crontab = ''
# Cleanup all but last 5 home-manager generations weekly on Sunday at midnight
0 0 * * 0 home-manager generations | tail -n +6 | awk '{print $5}' | xargs -I {} home-manager remove-generations {}
'';
};
nixpkgs = {
overlays = [

View file

@ -1,7 +1,6 @@
{ lib, inputs, hostname, username, desktop, hmStateVersion, ... }: {
imports = [
# Common configs
# ./common/software/cli/bash.nix
./common/software/cli/fish.nix
./common/software/cli/git.nix
./common/software/cli/nixvim/base.nix
@ -13,6 +12,9 @@
./common/software/cli/gpg.nix
./common/software/cli/zoxide.nix
# Services
./common/services/clean-home-manager.nix
# User configs
./users/${username}
@ -35,16 +37,6 @@
homeDirectory = "/home/${username}";
sessionPath = [ "$HOME/.local/bin" ];
};
# Clean up all but the most recent 2 home-manager configs
services.cron = {
enable = true;
crontab = ''
# Cleanup all but last 5 home-manager generations weekly on Sunday at midnight
0 0 * * 0 home-manager generations | tail -n +3 | awk '{print $5}' | xargs -I {} home-manager remove-generations {}
'';
};
nixpkgs = {
overlays = [