libvirtd service: Move mutable configs to /var

Modifies libvirt package to search for configs in /var/lib and changes
libvirtd service to copy the default configs to the new location.

This enables the user to change e.g. the networking configuration with
virsh or virt-manager and keep those settings.

+7 -11
+5 -9
nixos/modules/virtualisation/libvirtd.nix
··· 122 chmod 755 /var/lib/libvirt 123 chmod 755 /var/lib/libvirt/dnsmasq 124 125 - # Libvirt unfortunately writes mutable state (such as 126 - # runtime changes to VM, network or filter configurations) 127 - # to /etc. So we can't use environment.etc to make the 128 - # default network and filter definitions available, since 129 - # libvirt will then modify the originals in the Nix store. 130 - # So here we copy them instead. Ugly. 131 - for i in $(cd ${pkgs.libvirt}/etc && echo \ 132 libvirt/qemu/networks/*.xml libvirt/qemu/networks/autostart/*.xml \ 133 libvirt/nwfilter/*.xml ); 134 do 135 - mkdir -p /etc/$(dirname $i) -m 755 136 - cp -fpd ${pkgs.libvirt}/etc/$i /etc/$i 137 done 138 139 # libvirtd puts the full path of the emulator binary in the machine
··· 122 chmod 755 /var/lib/libvirt 123 chmod 755 /var/lib/libvirt/dnsmasq 124 125 + # Copy default libvirt network config .xml files to /var/lib 126 + # Files modified by the user will not be overwritten 127 + for i in $(cd ${pkgs.libvirt}/var/lib && echo \ 128 libvirt/qemu/networks/*.xml libvirt/qemu/networks/autostart/*.xml \ 129 libvirt/nwfilter/*.xml ); 130 do 131 + mkdir -p /var/lib/$(dirname $i) -m 755 132 + cp -npd ${pkgs.libvirt}/var/lib/$i /var/lib/$i 133 done 134 135 # libvirtd puts the full path of the emulator binary in the machine
+2 -2
pkgs/development/libraries/libvirt/default.nix
··· 40 41 configureFlags = [ 42 "--localstatedir=/var" 43 - "--sysconfdir=/etc" 44 "--with-libpcap" 45 "--with-vmware" 46 "--with-vbox" ··· 58 59 installFlags = [ 60 "localstatedir=$(TMPDIR)/var" 61 - "sysconfdir=$(out)/etc" 62 ]; 63 64 postInstall = ''
··· 40 41 configureFlags = [ 42 "--localstatedir=/var" 43 + "--sysconfdir=/var/lib" 44 "--with-libpcap" 45 "--with-vmware" 46 "--with-vbox" ··· 58 59 installFlags = [ 60 "localstatedir=$(TMPDIR)/var" 61 + "sysconfdir=$(out)/var/lib" 62 ]; 63 64 postInstall = ''