forked from aylac.top/nixcfg
this repo has no description
at main 1.5 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: { 7 options.myNixOS.profiles.autoUpgrade = { 8 enable = lib.mkEnableOption "auto-upgrade system"; 9 10 operation = lib.mkOption { 11 type = lib.types.str; 12 default = "boot"; 13 description = "Operation to perform on auto-upgrade. Can be 'boot', 'switch', or 'test'."; 14 }; 15 16 allowReboot = lib.mkOption { 17 type = lib.types.bool; 18 default = true; 19 description = "Allow auto-upgrade to reboot the system."; 20 }; 21 }; 22 23 config = lib.mkIf config.myNixOS.profiles.autoUpgrade.enable { 24 system.autoUpgrade = { 25 inherit (config.myNixOS.profiles.autoUpgrade) operation; 26 27 enable = true; 28 inherit (config.myNixOS.profiles.autoUpgrade) allowReboot; 29 dates = "02:00"; 30 flags = ["--accept-flake-config"]; 31 flake = config.environment.variables.FLAKE or "github:ayla6/nixcfg"; 32 persistent = true; 33 randomizedDelaySec = "120min"; 34 35 rebootWindow = { 36 lower = "02:00"; 37 upper = "06:00"; 38 }; 39 }; 40 41 # Allow nixos-upgrade to restart on failure (e.g. when laptop wakes up before network connection is set) 42 systemd.services.nixos-upgrade = { 43 preStart = "${pkgs.host}/bin/host cloudflare.com"; # Check network connectivity 44 45 serviceConfig = { 46 Restart = "on-failure"; 47 RestartSec = "120"; 48 }; 49 50 unitConfig = { 51 StartLimitIntervalSec = 600; 52 StartLimitBurst = 2; 53 }; 54 }; 55 }; 56}