diff --git a/machines/solis/modules.nix b/machines/solis/modules.nix index 0c9e32e..8e84ee7 100644 --- a/machines/solis/modules.nix +++ b/machines/solis/modules.nix @@ -33,6 +33,7 @@ timers = { backup.enable = true; rooms.enable = true; + flakeUpdate.enable = true; }; }; } diff --git a/modules/timers/default.nix b/modules/timers/default.nix index 330ca6a..05da776 100644 --- a/modules/timers/default.nix +++ b/modules/timers/default.nix @@ -3,5 +3,6 @@ ./wol.nix ./backup.nix ./rooms.nix + ./flakeUpdate.nix ]; } diff --git a/modules/timers/flakeUpdate.nix b/modules/timers/flakeUpdate.nix new file mode 100644 index 0000000..1bca345 --- /dev/null +++ b/modules/timers/flakeUpdate.nix @@ -0,0 +1,39 @@ +{ + lib, + config, + ... +}: 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" = { + script = '' + cd /home/horseman/nix-config + git pull + nix flake update + rebuild .#${config.networking.hostName} + git commit flake.lock -m "Update flake" + git push + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + }; + }; +}