summary refs log tree commit diff
path: root/nixos/modules/virtualisation
diff options
context:
space:
mode:
authorBjørn Forsman <bjorn.forsman@gmail.com>2017-07-14 17:20:58 +0200
committerBjørn Forsman <bjorn.forsman@gmail.com>2017-07-14 22:07:57 +0200
commit292827b0e0a52312a1abe67bfc8baa44afd04e27 (patch)
tree49f04351c4fa77a4e1f1a6190bba5126ecd5e39a /nixos/modules/virtualisation
parent407b56986e1915847f4526ffb9aa9465c73f746f (diff)
downloadnixlib-292827b0e0a52312a1abe67bfc8baa44afd04e27.tar
nixlib-292827b0e0a52312a1abe67bfc8baa44afd04e27.tar.gz
nixlib-292827b0e0a52312a1abe67bfc8baa44afd04e27.tar.bz2
nixlib-292827b0e0a52312a1abe67bfc8baa44afd04e27.tar.lz
nixlib-292827b0e0a52312a1abe67bfc8baa44afd04e27.tar.xz
nixlib-292827b0e0a52312a1abe67bfc8baa44afd04e27.tar.zst
nixlib-292827b0e0a52312a1abe67bfc8baa44afd04e27.zip
nixos/libvirt: modify xml with xmlstarlet
Instead of grep and sed, which is brittle.

(I don't know how to preserve the comment we currently add to say that
this line is auto-updated. But I don't think it adds much value, so I'm
not spending any effort on it.)
Diffstat (limited to 'nixos/modules/virtualisation')
-rw-r--r--nixos/modules/virtualisation/libvirtd.nix4
1 files changed, 2 insertions, 2 deletions
diff --git a/nixos/modules/virtualisation/libvirtd.nix b/nixos/modules/virtualisation/libvirtd.nix
index 10a38b99f871..c8742b27c6d5 100644
--- a/nixos/modules/virtualisation/libvirtd.nix
+++ b/nixos/modules/virtualisation/libvirtd.nix
@@ -162,11 +162,11 @@ in {
         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=$(grep "^[[:space:]]*<emulator>" "$file" | sed 's,^[[:space:]]*<emulator>\(.*\)</emulator>.*,\1,')
+            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
-            sed -i "s,^[[:space:]]*<emulator>.*,    <emulator>$new_emulator</emulator> <!-- WARNING: emulator dirname is auto-updated by the nixos libvirtd module -->," "$file"
+            "${pkgs.xmlstarlet}/bin/xmlstarlet" edit --inplace --update "/domain/devices/emulator" -v "$new_emulator" "$file"
         done
       ''; # */