modules/nixos/common/update: use grub.extraInstallCommands for boot diff

This commit is contained in:
zowoq 2024-12-16 16:45:11 +10:00
parent 9795fb35a0
commit 01137d599d
2 changed files with 10 additions and 6 deletions
modules/nixos/common

View file

@ -12,11 +12,6 @@ nix-env --profile /nix/var/nix/profiles/system --set "$p"
booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules} && cat /run/booted-system/kernel-params)"
built="$(readlink "$p"/{initrd,kernel,kernel-modules} && cat "$p"/kernel-params)"
if [[ $booted != "$built" ]]; then
if [[ -e /run/current-system ]]; then
echo "--- diff to current-system"
nvd diff /run/current-system "$p"
echo "---"
fi
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
# don't use kexec if system is virtualized, reboots are fast enough
if ! systemd-detect-virt -q; then

View file

@ -16,11 +16,20 @@
pkgs.coreutils
pkgs.curl
pkgs.kexec-tools
pkgs.nvd
];
script = builtins.readFile ./update.bash;
};
# https://gist.github.com/Ma27/6650d10f772511931647d3189b3eb1d7
# https://github.com/NuschtOS/nixos-modules/blob/39d26dddae2f117d7f9c33dd1efc866ff684ff94/modules/nix.nix
boot.loader.grub.extraInstallCommands = ''
if [[ "''${NIXOS_ACTION-}" == boot && -e /run/current-system && -e "''${1-}" ]]; then
echo "--- diff to current-system"
${pkgs.nvd}/bin/nvd --nix-bin-dir=${config.nix.package}/bin diff /run/current-system "''${1-}"
echo "---"
fi
'';
systemd.timers.update-host = {
wantedBy = [ "timers.target" ];
timerConfig.OnBootSec = "5m";