summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorBjørn Forsman <bjorn.forsman@gmail.com>2013-11-27 21:31:15 +0100
committerBjørn Forsman <bjorn.forsman@gmail.com>2013-11-27 23:09:57 +0100
commitf52f9bf7cd922b54c874e5500a2c64277e57d417 (patch)
tree2cefe07d91b5e4bee77f6e33fc3ac269870a6e48 /nixos/modules
parent89789e47199b4ff22dfd5d684d70c58bc5d6b20f (diff)
downloadnixpkgs-f52f9bf7cd922b54c874e5500a2c64277e57d417.tar
nixpkgs-f52f9bf7cd922b54c874e5500a2c64277e57d417.tar.gz
nixpkgs-f52f9bf7cd922b54c874e5500a2c64277e57d417.tar.bz2
nixpkgs-f52f9bf7cd922b54c874e5500a2c64277e57d417.tar.lz
nixpkgs-f52f9bf7cd922b54c874e5500a2c64277e57d417.tar.xz
nixpkgs-f52f9bf7cd922b54c874e5500a2c64277e57d417.tar.zst
nixpkgs-f52f9bf7cd922b54c874e5500a2c64277e57d417.zip
nixos/libvirtd-service: fix for garbage collected emulator paths
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. Then this happens:

Error starting domain: Cannot check QEMU binary /nix/store/z5c2xzk9x0pj6x511w0w4gy9xl5wljxy-qemu-1.5.2-x86-only/bin/qemu-kvm: No such file or directory

Fix by updating the emulator path on each service startup to something
valid (re-scan $PATH).
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/virtualisation/libvirtd.nix13
1 files changed, 13 insertions, 0 deletions
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:]]*<emulator>" "$file" | sed 's,^[[:space:]]*<emulator>\(.*\)</emulator>.*,\1,')
+                # get a (definitely) working emulator path by re-scanning $PATH
+                new_emulator=$(command -v $(basename "$emulator"))
+                # write back
+                sed -i "s,^[[:space:]]*<emulator>.*,    <emulator>$new_emulator</emulator> <!-- WARNING: emulator dirname is auto-updated by the nixos libvirtd module -->," "$file"
+            done
           ''; # */
 
         serviceConfig.ExecStart = ''@${pkgs.libvirt}/sbin/libvirtd libvirtd --config "${configFile}" --daemon --verbose'';