1
0
Fork 0
nixos-config/home-manager/roles/hourly-maintenance.nix

34 lines
873 B
Nix
Raw Normal View History

2022-03-08 01:42:46 +00:00
{
pkgs,
config,
...
}: let
2021-07-09 11:39:48 +00:00
configPath = "${config.home.homeDirectory}/git/config";
configGit = "${pkgs.git}/bin/git -C ${configPath}";
script = pkgs.writeShellScript "hourly-maintenance" ''
set -e
${configGit} fetch
if [[ "$(${configGit} rev-parse master)" == "$(${configGit} rev-parse origin/master)" ]]; then
echo "Git repo up-to-date, not doing anything."
exit 0;
else
2022-03-07 18:40:12 +00:00
${pkgs.foot}/bin/foot --hold ${config.home.profileDirectory}/bin/maintenance
2021-07-09 11:39:48 +00:00
fi
'';
2022-03-08 01:42:46 +00:00
in {
2021-07-08 22:27:52 +00:00
systemd.user = {
services.maintenance = {
Unit.Description = "Routine maintenance";
Service = {
Type = "oneshot";
2021-07-09 11:39:48 +00:00
ExecStart = toString script;
2021-07-08 22:27:52 +00:00
};
};
timers.maintenance = {
Unit.Description = "Hourly maintenance";
Timer.OnCalendar = "hourly";
2022-03-08 01:42:46 +00:00
Install.WantedBy = ["timers.target"];
2021-07-08 22:27:52 +00:00
};
};
}