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
|
2022-04-03 11:15:00 +00:00
|
|
|
if [[ "$(${configGit} rev-parse main)" == "$(${configGit} rev-parse origin/main)" ]]; then
|
2021-07-09 11:39:48 +00:00
|
|
|
echo "Git repo up-to-date, not doing anything."
|
|
|
|
exit 0;
|
|
|
|
else
|
2022-12-30 19:07:40 +00:00
|
|
|
${config.home.sessionVariables.TERMINAL} --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
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|