From a99103dcaaa1651774a6e92820baa1e11347b402 Mon Sep 17 00:00:00 2001 From: Andre Date: Thu, 30 May 2024 10:04:14 -0400 Subject: [PATCH] Reconfigure automatic updates (idea from https://forum.aux.computer/t/how-are-you-handling-automatic-updates/752/4) --- hosts/Haven/default.nix | 28 ++++++++++++++++++++++++++++ modules/base/system.nix | 5 +++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/hosts/Haven/default.nix b/hosts/Haven/default.nix index 70faef8..c52c498 100644 --- a/hosts/Haven/default.nix +++ b/hosts/Haven/default.nix @@ -113,4 +113,32 @@ in # Allow Haven to be a build target for other architectures (mainly ARM64) boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; + + # Automatically update Flake configuration for other hosts to use + systemd.services."nixos-update-flake" = { + serviceConfig = { + Type = "oneshot"; + User = config.users.users.aires.name; + }; + script = '' + set -eu + cd ${config.users.users.aires.home}/Development/nix-configuration + git pull + nix flake update + git add flake.lock + git commit -m "Update flake.lock" + git push + ''; + }; + + systemd.timers."nixos-update-flake-timer" = { + wants = [ "network-online.target" ]; + after = [ "network-online.target" ]; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "daily"; + Persistent = "true"; + Unit = "nixos-update-flake.service"; + }; + }; } diff --git a/modules/base/system.nix b/modules/base/system.nix index c54461c..6927220 100644 --- a/modules/base/system.nix +++ b/modules/base/system.nix @@ -29,11 +29,12 @@ # Configure automatic updates system.autoUpgrade = { enable = true; - flake = "${config.users.users.aires.home}/Development/nix-configuration"; + flake = "git+https://${config.secrets.services.forgejo.url}/aires/nix-configuration"; dates = "daily"; + randomizedDelaySec = "30m"; allowReboot = false; operation = "switch"; - flags = [ "--commit-lock-file" ]; + persistent = true; }; services = {