nix-config/modules/timers/flakeUpdate.nix
2025-11-19 22:15:05 +01:00

43 lines
921 B
Nix

{
lib,
config,
pkgs,
...
}: let
inherit (lib) mkEnableOption mkIf;
cfg = config.horseman.timers.flakeUpdate;
in {
options = {
horseman.timers.flakeUpdate = {
enable = mkEnableOption "Updates flake.nix weekly";
};
};
config = mkIf cfg.enable {
systemd.timers."flake-update" = {
wantedBy = ["timers.target"];
timerConfig = {
OnCalendar = "weekly";
Persistent = true;
};
};
systemd.services."flake-update" = let
git = "sudo -u horseman ${pkgs.git}/bin/git";
in {
script = ''
#!/run/current-system/sw/bin/zsh
cd /home/horseman/nix-config
${git} pull
sudo nix flake update
rebuild .#${config.networking.hostName}
${git} commit flake.lock -m "Update flake"
${git} push
'';
serviceConfig = {
Type = "oneshot";
User = "root";
};
};
};
}