Auto-upgrade: List package differences

This commit is contained in:
fruchti 2023-03-27 21:42:08 +02:00
parent 62188455a9
commit 050a28f91f

View file

@ -43,9 +43,11 @@ in
systemd.services.nixos-upgrade.script = mkOverride 50 ( systemd.services.nixos-upgrade.script = mkOverride 50 (
let let
nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild"; nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild";
nix-store = "${pkgs.nix}/bin/nix-store";
date = "${pkgs.coreutils}/bin/date"; date = "${pkgs.coreutils}/bin/date";
readlink = "${pkgs.coreutils}/bin/readlink"; readlink = "${pkgs.coreutils}/bin/readlink";
grep = "${pkgs.gnugrep}/bin/grep"; grep = "${pkgs.gnugrep}/bin/grep";
diff = "${pkgs.diffutils}/bin/diff";
git = "${pkgs.git}/bin/git"; git = "${pkgs.git}/bin/git";
ssh = "${pkgs.openssh}/bin/ssh"; ssh = "${pkgs.openssh}/bin/ssh";
sudo = "${pkgs.sudo}/bin/sudo"; sudo = "${pkgs.sudo}/bin/sudo";
@ -121,6 +123,18 @@ in
email_body="The system upgrade started at $start_time has failed with exit code $exit_code." email_body="The system upgrade started at $start_time has failed with exit code $exit_code."
fi fi
echo " Determining package differences." | tee -a "$output_file"
installed_packages()
{
${nix-store} --query --requisites "$1" | cut -d- -f2- | sort | uniq
}
current_packages="$(installed_packages /run/current-system)"
built_packages="$(installed_packages /nix/var/nix/profiles/system)"
${diff} -y --suppress-common-lines --width=71 \
<(printf "Current generation\n------------------\n%s" "$current_packages") \
<(printf "New generation\n--------------\n%s" "$built_packages") \
| tee -a "$output_file" || true
booted_version="$(${readlink} /run/booted-system/{initrd,kernel,kernel-modules})" booted_version="$(${readlink} /run/booted-system/{initrd,kernel,kernel-modules})"
built_version="$(${readlink} /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})" built_version="$(${readlink} /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"