From a20dc996f5a169fd052bc04c510e47d0909cc28d Mon Sep 17 00:00:00 2001 From: Daniel Frank Date: Fri, 5 Jul 2019 19:58:09 +0200 Subject: [PATCH] nixos: test new auto-upgrade module --- auto-upgrade.nix | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/auto-upgrade.nix b/auto-upgrade.nix index 20e74fa..18753ae 100644 --- a/auto-upgrade.nix +++ b/auto-upgrade.nix @@ -57,9 +57,9 @@ let cfg = config.system.autoUpgrade; in default = false; type = types.bool; description = '' - Shall the system be rebooted if the new configuration - uses a different kernel, kernel modules or initrd - than the booted system? + 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. ''; }; @@ -88,29 +88,25 @@ let cfg = config.system.autoUpgrade; in HOME = "/root"; } // 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 = '' - ${lib.optionalString cfg.allowReboot '' - set -euo pipefail - T=$(mktemp -d) - cd "$T" - ${config.system.build.nixos-rebuild}/bin/nixos-rebuild build ${toString cfg.flags} - booted="$(${pkgs.coreutils}/bin/readlink /run/booted-system/{initrd,kernel,kernel-modules})" - built="$(${pkgs.coreutils}/bin/readlink result/{initrd,kernel,kernel-modules})" - cd /tmp - rm -rf "$T" - if [ "$booted" = "$built" ]; then - ${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch ${toString cfg.flags} - else - ${config.system.build.nixos-rebuild}/bin/nixos-rebuild boot ${toString cfg.flags} - /run/current-system/sw/bin/shutdown -r +1 - fi - ''} - ${lib.optionalString (!cfg.allowReboot) "${config.system.build.nixos-rebuild}/bin/nixos-rebuild switch ${toString cfg.flags}"} + 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 = optional cfg.enable cfg.dates; + startAt = cfg.dates; }; };