From b8979ecffefdf18ce8a3cc3459adda8f6dabbd33 Mon Sep 17 00:00:00 2001 From: "quentin@aristote.fr" Date: Wed, 29 Jan 2025 15:53:56 +0100 Subject: nixos: upgrade: restart if no network --- modules/nixos/personal/nix.nix | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'modules/nixos/personal/nix.nix') diff --git a/modules/nixos/personal/nix.nix b/modules/nixos/personal/nix.nix index e3f7395..94848d9 100644 --- a/modules/nixos/personal/nix.nix +++ b/modules/nixos/personal/nix.nix @@ -57,7 +57,7 @@ in { (lib.mkIf cfg.autoUpgrade.enable { # upgrading flake-update = lib.mkIf (cfg.flake != null && cfg.autoUpgrade.autoUpdateInputs != []) { - preStart = "${pkgs.host}/bin/host 9.9.9.9"; # Check network connectivity + preStart = "${pkgs.host}/bin/host 9.9.9.9 || exit 100"; # Check network connectivity unitConfig = { Description = "Update flake inputs"; StartLimitIntervalSec = 300; @@ -65,7 +65,7 @@ in { }; serviceConfig = { ExecStart = "${config.nix.package}/bin/nix flake update --commit-lock-file --flake ${cfg.flake} " + lib.concatStringsSep " " cfg.autoUpgrade.autoUpdateInputs; - Restart = "on-failure"; + RestartForceExitCode = "100"; RestartSec = "30"; Type = "oneshot"; # Ensure that it finishes before starting nixos-upgrade }; @@ -74,7 +74,15 @@ in { personal.monitor = true; }; nixos-upgrade = { - preStart = "${pkgs.host}/bin/host 9.9.9.9"; # Check network connectivity + preStart = "${pkgs.host}/bin/host 9.9.9.9 || exit 100"; # Check network connectivity + unitConfig = { + StartLimitIntervalSec = 300; + StartLimitBurst = 5; + }; + serviceConfig = { + RestartForceExitCode = "100"; + RestartSec = "30"; + }; after = ["flake-update.service"]; wants = ["flake-update.service"]; personal.monitor = true; -- cgit v1.2.3