diff options
author | Bjørn Forsman <bjorn.forsman@gmail.com> | 2017-07-14 17:20:58 +0200 |
---|---|---|
committer | Bjørn Forsman <bjorn.forsman@gmail.com> | 2017-07-14 22:07:57 +0200 |
commit | 292827b0e0a52312a1abe67bfc8baa44afd04e27 (patch) | |
tree | 49f04351c4fa77a4e1f1a6190bba5126ecd5e39a /nixos | |
parent | 407b56986e1915847f4526ffb9aa9465c73f746f (diff) |
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')
-rw-r--r-- | nixos/modules/virtualisation/libvirtd.nix | 4 |
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 ''; # */ |