Skip to content

Commit

Permalink
modules/nixos/common/update: use grub.extraInstallCommands for boot diff
Browse files Browse the repository at this point in the history
  • Loading branch information
zowoq committed Dec 16, 2024
1 parent de1c033 commit 011cd87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 0 additions & 5 deletions modules/nixos/common/update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions modules/nixos/common/update.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
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";
Expand Down

0 comments on commit 011cd87

Please sign in to comment.