diff options
Diffstat (limited to 'modules/auto-update.nix')
| -rw-r--r-- | modules/auto-update.nix | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/auto-update.nix b/modules/auto-update.nix new file mode 100644 index 0000000..b370390 --- /dev/null +++ b/modules/auto-update.nix @@ -0,0 +1,26 @@ +{ pkgs, ... }: + +{ + system.autoUpgrade = { + enable = true; + dates = "minutely"; + allowReboot = true; + upgrade = false; + }; + + systemd.services.nixos-upgrade = { + path = [ pkgs.git ]; + serviceConfig = { + WorkingDirectory = "/etc/nixos"; + StateDirectory = "nixos-repo-update"; + ExecCondition = pkgs.writeShellScript "check-nixos-repo" '' + set -euo pipefail + git fetch || exit 255 + test "$(cat "$STATE_DIRECTORY/applied" 2>/dev/null || true)" != "$(git rev-parse '@{upstream}')" + ''; + }; + + preStart = "git pull --ff-only"; + postStart = ''git rev-parse HEAD > "$STATE_DIRECTORY/applied"''; + }; +} |
