{ 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"; }; }; }; }