modules/nixos: separate reboot from auto-upgrade

This commit is contained in:
zowoq 2023-07-19 15:30:03 +10:00
parent 68a4acdadd
commit 92e3a37e12
3 changed files with 21 additions and 19 deletions

View file

@ -1,25 +1,6 @@
{ config, pkgs, ... }:
{
system.autoUpgrade.enable = true;
system.autoUpgrade.flake = "github:nix-community/infra";
system.autoUpgrade.dates = "hourly";
system.autoUpgrade.flags = [ "--option" "accept-flake-config" "true" "--option" "tarball-ttl" "0" ];
# adapted from https://github.com/NixOS/nixpkgs/blob/3428bdf3c93a7608615dddd44dec50c3df89b4be/nixos/modules/tasks/auto-upgrade.nix
systemd.services.reboot-after-update = {
restartIfChanged = false;
unitConfig.X-StopOnRemoval = false;
serviceConfig.Type = "oneshot";
script = ''
booted="$(${pkgs.coreutils}/bin/readlink /run/booted-system/{initrd,kernel,kernel-modules})"
built="$(${pkgs.coreutils}/bin/readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
if [ "''${booted}" != "''${built}" ]; then
${config.systemd.package}/bin/shutdown -r now
fi
'';
startAt = "0/6:00";
};
systemd.timers.reboot-after-update = {
timerConfig.RandomizedDelaySec = "6h";
};
}

View file

@ -3,6 +3,7 @@
imports = [
./auto-upgrade.nix
./nix-daemon.nix
./reboot.nix
./security.nix
./sops-nix.nix
./users.nix

View file

@ -0,0 +1,20 @@
{ config, pkgs, ... }:
{
# adapted from https://github.com/NixOS/nixpkgs/blob/3428bdf3c93a7608615dddd44dec50c3df89b4be/nixos/modules/tasks/auto-upgrade.nix
systemd.services.reboot-after-update = {
restartIfChanged = false;
unitConfig.X-StopOnRemoval = false;
serviceConfig.Type = "oneshot";
script = ''
booted="$(${pkgs.coreutils}/bin/readlink /run/booted-system/{initrd,kernel,kernel-modules})"
built="$(${pkgs.coreutils}/bin/readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
if [ "''${booted}" != "''${built}" ]; then
${config.systemd.package}/bin/shutdown -r now
fi
'';
startAt = "0/6:00";
};
systemd.timers.reboot-after-update = {
timerConfig.RandomizedDelaySec = "6h";
};
}