From 292827b0e0a52312a1abe67bfc8baa44afd04e27 Mon Sep 17 00:00:00 2001 From: Bjørn Forsman Date: Fri, 14 Jul 2017 17:20:58 +0200 Subject: 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.) --- nixos/modules/virtualisation/libvirtd.nix | 4 ++-- 1 file 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:]]*" "$file" | sed 's,^[[:space:]]*\(.*\).*,\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:]]*.*, $new_emulator ," "$file" + "${pkgs.xmlstarlet}/bin/xmlstarlet" edit --inplace --update "/domain/devices/emulator" -v "$new_emulator" "$file" done ''; # */ -- cgit 1.4.1