nixos: test new auto-upgrade module

This commit is contained in:
Daniel Frank 2019-07-05 19:58:09 +02:00
parent 40e7f12b33
commit a20dc996f5
Signed by: tokudan
GPG key ID: 063CCCAD04182D32

View file

@ -57,9 +57,9 @@ let cfg = config.system.autoUpgrade; in
default = false; default = false;
type = types.bool; type = types.bool;
description = '' description = ''
Shall the system be rebooted if the new configuration Reboot the system into the new generation instead of a switch
uses a different kernel, kernel modules or initrd if the new generation uses a different kernel, kernel modules
than the booted system? or initrd than the booted system.
''; '';
}; };
@ -88,29 +88,25 @@ let cfg = config.system.autoUpgrade; in
HOME = "/root"; HOME = "/root";
} // config.networking.proxy.envVars; } // config.networking.proxy.envVars;
path = [ pkgs.gnutar pkgs.xz.bin pkgs.gitMinimal config.nix.package.out ]; path = [ pkgs.coreutils pkgs.gnutar pkgs.xz.bin pkgs.gitMinimal config.nix.package.out ];
script = '' script = let
${lib.optionalString cfg.allowReboot '' nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild";
set -euo pipefail in
T=$(mktemp -d) if cfg.allowReboot then ''
cd "$T" ${nixos-rebuild} boot ${toString cfg.flags}
${config.system.build.nixos-rebuild}/bin/nixos-rebuild build ${toString cfg.flags} booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})"
booted="$(${pkgs.coreutils}/bin/readlink /run/booted-system/{initrd,kernel,kernel-modules})" built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
built="$(${pkgs.coreutils}/bin/readlink result/{initrd,kernel,kernel-modules})"
cd /tmp
rm -rf "$T"
if [ "$booted" = "$built" ]; then if [ "$booted" = "$built" ]; then
${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch ${toString cfg.flags} ${nixos-rebuild} switch ${toString cfg.flags}
else else
${config.system.build.nixos-rebuild}/bin/nixos-rebuild boot ${toString cfg.flags}
/run/current-system/sw/bin/shutdown -r +1 /run/current-system/sw/bin/shutdown -r +1
fi fi
''} '' else ''
${lib.optionalString (!cfg.allowReboot) "${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch ${toString cfg.flags}"} ${nixos-rebuild} switch ${toString cfg.flags}
''; '';
startAt = optional cfg.enable cfg.dates; startAt = cfg.dates;
}; };
}; };