diff --git a/nixos/modules/virtualisation/libvirtd.nix b/nixos/modules/virtualisation/libvirtd.nix index 552441f6a62..d8668eb1607 100644 --- a/nixos/modules/virtualisation/libvirtd.nix +++ b/nixos/modules/virtualisation/libvirtd.nix @@ -101,6 +101,19 @@ in mkdir -p /etc/$(dirname $i) -m 755 cp -fpd ${pkgs.libvirt}/etc/$i /etc/$i done + + # libvirtd puts the full path of the emulator binary in the machine + # config file. But this path can unfortunately be garbage collected + # while still being used by the virtual machine. So update the + # emulator path on each startup to something valid (re-scan $PATH). + for file in /etc/libvirt/qemu/*.xml; do + # get (old) emulator path from config file + emulator=$(grep "^[[:space:]]*" "$file" | sed 's,^[[:space:]]*\(.*\).*,\1,') + # get a (definitely) working emulator path by re-scanning $PATH + new_emulator=$(command -v $(basename "$emulator")) + # write back + sed -i "s,^[[:space:]]*.*, $new_emulator ," "$file" + done ''; # */ serviceConfig.ExecStart = ''@${pkgs.libvirt}/sbin/libvirtd libvirtd --config "${configFile}" --daemon --verbose'';