system.autoUpgrade: optionally allow rebooting the system on kernel change (#64267)

* autoUpgrade: optionally allow rebooting the system on kernel change

* system.autoUpgrade: Better documentation and readability
wip/yesman
Daniel Frank 5 years ago committed by Danylo Hlynskyi
parent 874f735a6f
commit ed86bbad84
  1. 32
      nixos/modules/tasks/auto-upgrade.nix

@ -53,6 +53,16 @@ let cfg = config.system.autoUpgrade; in
'';
};
allowReboot = mkOption {
default = false;
type = types.bool;
description = ''
Reboot the system into the new generation instead of a switch
if the new generation uses a different kernel, kernel modules
or initrd than the booted system.
'';
};
};
};
@ -78,11 +88,23 @@ let cfg = config.system.autoUpgrade; in
HOME = "/root";
} // config.networking.proxy.envVars;
path = [ pkgs.gnutar pkgs.xz.bin pkgs.gitMinimal config.nix.package.out ];
script = ''
${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch ${toString cfg.flags}
'';
path = [ pkgs.coreutils pkgs.gnutar pkgs.xz.bin pkgs.gitMinimal config.nix.package.out ];
script = let
nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild";
in
if cfg.allowReboot then ''
${nixos-rebuild} boot ${toString cfg.flags}
booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})"
built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
if [ "$booted" = "$built" ]; then
${nixos-rebuild} switch ${toString cfg.flags}
else
/run/current-system/sw/bin/shutdown -r +1
fi
'' else ''
${nixos-rebuild} switch ${toString cfg.flags}
'';
startAt = cfg.dates;
};

Loading…
Cancel
Save