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.)
This commit is contained in:
parent
407b56986e
commit
292827b0e0
|
@ -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
|
||||
''; # */
|
||||
|
||||
|
|
Loading…
Reference in a new issue