Merge pull request #27903 from volth/issue-27857-libvirt-xml-manipulation

libvirt: 3.5.0 -> 3.6.0
This commit is contained in:
Franz Pletz
2017-08-12 21:45:01 +02:00
committed by GitHub
3 changed files with 32 additions and 27 deletions
+18 -22
View File
@@ -15,7 +15,7 @@ let
'';
qemuConfigFile = pkgs.writeText "qemu.conf" ''
${optionalString cfg.qemuOvmf ''
nvram = ["${pkgs.OVMF.fd}/FV/OVMF_CODE.fd:${pkgs.OVMF.fd}/FV/OVMF_VARS.fd"]
nvram = ["/run/libvirt/nix-ovmf/OVMF_CODE.fd:/run/libvirt/nix-ovmf/OVMF_VARS.fd"]
''}
${cfg.qemuVerbatimConfig}
'';
@@ -102,9 +102,7 @@ in {
config = mkIf cfg.enable {
environment.systemPackages = with pkgs;
[ libvirt netcat-openbsd ]
++ optional cfg.enableKVM qemu_kvm;
environment.systemPackages = with pkgs; [ libvirt netcat-openbsd ];
boot.kernelModules = [ "tun" ];
@@ -129,7 +127,6 @@ in {
dnsmasq
ebtables
]
++ optional cfg.enableKVM qemu_kvm
++ optional vswitch.enable vswitch.package;
preStart = ''
@@ -155,34 +152,31 @@ in {
# Copy generated qemu config to libvirt directory
cp -f ${qemuConfigFile} /var/lib/libvirt/qemu.conf
# 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 /var/lib/libvirt/qemu/*.xml /var/lib/libvirt/lxc/*.xml; do
test -f "$file" || continue
# get (old) emulator path from config file
emulator=$("${pkgs.xmlstarlet}/bin/xmlstarlet" select --template --value-of "/domain/devices/emulator" "$file")
# get a (definitely) working emulator path by re-scanning $PATH
new_emulator=$(PATH=${pkgs.libvirt}/libexec:$PATH command -v $(basename "$emulator"))
# write back
"${pkgs.xmlstarlet}/bin/xmlstarlet" edit --inplace --update "/domain/devices/emulator" -v "$new_emulator" "$file"
# stable (not GC'able as in /nix/store) paths for using in <emulator> section of xml configs
mkdir -p /run/libvirt/nix-emulators
ln -s --force ${pkgs.libvirt}/libexec/libvirt_lxc /run/libvirt/nix-emulators/
${optionalString pkgs.stdenv.isAarch64 "ln -s --force ${pkgs.qemu}/bin/qemu-system-aarch64 /run/libvirt/nix-emulators/"}
${optionalString cfg.enableKVM "ln -s --force ${pkgs.qemu_kvm}/bin/qemu-kvm /run/libvirt/nix-emulators/"}
# Also refresh the OVMF path. Files with no matches are ignored.
"${pkgs.xmlstarlet}/bin/xmlstarlet" edit --inplace --update "/domain/os/loader" -v "${pkgs.OVMF.fd}/FV/OVMF_CODE.fd" "$file"
done
''; # */
${optionalString cfg.qemuOvmf ''
mkdir -p /run/libvirt/nix-ovmf
ln -s --force ${pkgs.OVMF.fd}/FV/OVMF_CODE.fd /run/libvirt/nix-ovmf/
ln -s --force ${pkgs.OVMF.fd}/FV/OVMF_VARS.fd /run/libvirt/nix-ovmf/
''}
'';
serviceConfig = {
Type = "notify";
KillMode = "process"; # when stopping, leave the VMs alone
Restart = "on-failure";
Restart = "no";
};
restartIfChanged = false;
};
systemd.services.libvirt-guests = {
wantedBy = [ "multi-user.target" ];
path = with pkgs; [ coreutils libvirt gawk ];
restartIfChanged = false;
};
systemd.sockets.virtlogd = {
@@ -194,6 +188,7 @@ in {
systemd.services.virtlogd = {
description = "Virtual machine log manager";
serviceConfig.ExecStart = "@${pkgs.libvirt}/sbin/virtlogd virtlogd";
restartIfChanged = false;
};
systemd.sockets.virtlockd = {
@@ -205,6 +200,7 @@ in {
systemd.services.virtlockd = {
description = "Virtual machine lock manager";
serviceConfig.ExecStart = "@${pkgs.libvirt}/sbin/virtlockd virtlockd";
restartIfChanged = false;
};
};
}