Add home-manager cleanup cronjob
This commit is contained in:
parent
322b19b3c6
commit
77acbbfe51
3 changed files with 32 additions and 20 deletions
home-manager
26
home-manager/common/services/clean-home-manager.nix
Normal file
26
home-manager/common/services/clean-home-manager.nix
Normal 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" ];
|
||||
};
|
||||
};
|
||||
}
|
|
@ -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 = [
|
||||
|
|
|
@ -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 = [
|
||||
|
|
Loading…
Add table
Reference in a new issue