nixos/libvirtd: add package option
At the moment, it's not possible to override the libvirtd package used without supplying a nixpkgs overlay. Adding a package option makes libvirtd more consistent and allows enabling e.g. ceph and iSCSI support more easily.
This commit is contained in:
parent
40be12c695
commit
1ce6b05ea1
|
@ -46,6 +46,15 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.libvirt;
|
||||||
|
defaultText = "pkgs.libvirt";
|
||||||
|
description = ''
|
||||||
|
libvirt package to use.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
qemuPackage = mkOption {
|
qemuPackage = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
default = pkgs.qemu;
|
default = pkgs.qemu;
|
||||||
|
@ -149,7 +158,7 @@ in {
|
||||||
# this file is expected in /etc/qemu and not sysconfdir (/var/lib)
|
# this file is expected in /etc/qemu and not sysconfdir (/var/lib)
|
||||||
etc."qemu/bridge.conf".text = lib.concatMapStringsSep "\n" (e:
|
etc."qemu/bridge.conf".text = lib.concatMapStringsSep "\n" (e:
|
||||||
"allow ${e}") cfg.allowedBridges;
|
"allow ${e}") cfg.allowedBridges;
|
||||||
systemPackages = with pkgs; [ libvirt libressl.nc iptables cfg.qemuPackage ];
|
systemPackages = with pkgs; [ libressl.nc iptables cfg.package cfg.qemuPackage ];
|
||||||
etc.ethertypes.source = "${pkgs.iptables}/etc/ethertypes";
|
etc.ethertypes.source = "${pkgs.iptables}/etc/ethertypes";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -169,26 +178,26 @@ in {
|
||||||
source = "/run/${dirName}/nix-helpers/qemu-bridge-helper";
|
source = "/run/${dirName}/nix-helpers/qemu-bridge-helper";
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.packages = [ pkgs.libvirt ];
|
systemd.packages = [ cfg.package ];
|
||||||
|
|
||||||
systemd.services.libvirtd-config = {
|
systemd.services.libvirtd-config = {
|
||||||
description = "Libvirt Virtual Machine Management Daemon - configuration";
|
description = "Libvirt Virtual Machine Management Daemon - configuration";
|
||||||
script = ''
|
script = ''
|
||||||
# Copy default libvirt network config .xml files to /var/lib
|
# Copy default libvirt network config .xml files to /var/lib
|
||||||
# Files modified by the user will not be overwritten
|
# Files modified by the user will not be overwritten
|
||||||
for i in $(cd ${pkgs.libvirt}/var/lib && echo \
|
for i in $(cd ${cfg.package}/var/lib && echo \
|
||||||
libvirt/qemu/networks/*.xml libvirt/qemu/networks/autostart/*.xml \
|
libvirt/qemu/networks/*.xml libvirt/qemu/networks/autostart/*.xml \
|
||||||
libvirt/nwfilter/*.xml );
|
libvirt/nwfilter/*.xml );
|
||||||
do
|
do
|
||||||
mkdir -p /var/lib/$(dirname $i) -m 755
|
mkdir -p /var/lib/$(dirname $i) -m 755
|
||||||
cp -npd ${pkgs.libvirt}/var/lib/$i /var/lib/$i
|
cp -npd ${cfg.package}/var/lib/$i /var/lib/$i
|
||||||
done
|
done
|
||||||
|
|
||||||
# Copy generated qemu config to libvirt directory
|
# Copy generated qemu config to libvirt directory
|
||||||
cp -f ${qemuConfigFile} /var/lib/${dirName}/qemu.conf
|
cp -f ${qemuConfigFile} /var/lib/${dirName}/qemu.conf
|
||||||
|
|
||||||
# stable (not GC'able as in /nix/store) paths for using in <emulator> section of xml configs
|
# stable (not GC'able as in /nix/store) paths for using in <emulator> section of xml configs
|
||||||
for emulator in ${pkgs.libvirt}/libexec/libvirt_lxc ${cfg.qemuPackage}/bin/qemu-kvm ${cfg.qemuPackage}/bin/qemu-system-*; do
|
for emulator in ${cfg.package}/libexec/libvirt_lxc ${cfg.qemuPackage}/bin/qemu-kvm ${cfg.qemuPackage}/bin/qemu-system-*; do
|
||||||
ln -s --force "$emulator" /run/${dirName}/nix-emulators/
|
ln -s --force "$emulator" /run/${dirName}/nix-emulators/
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -234,7 +243,7 @@ in {
|
||||||
|
|
||||||
systemd.services.libvirt-guests = {
|
systemd.services.libvirt-guests = {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
path = with pkgs; [ coreutils libvirt gawk ];
|
path = with pkgs; [ coreutils gawk cfg.package ];
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
|
|
||||||
environment.ON_BOOT = "${cfg.onBoot}";
|
environment.ON_BOOT = "${cfg.onBoot}";
|
||||||
|
@ -249,7 +258,7 @@ in {
|
||||||
|
|
||||||
systemd.services.virtlogd = {
|
systemd.services.virtlogd = {
|
||||||
description = "Virtual machine log manager";
|
description = "Virtual machine log manager";
|
||||||
serviceConfig.ExecStart = "@${pkgs.libvirt}/sbin/virtlogd virtlogd";
|
serviceConfig.ExecStart = "@${cfg.package}/sbin/virtlogd virtlogd";
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -261,7 +270,7 @@ in {
|
||||||
|
|
||||||
systemd.services.virtlockd = {
|
systemd.services.virtlockd = {
|
||||||
description = "Virtual machine lock manager";
|
description = "Virtual machine lock manager";
|
||||||
serviceConfig.ExecStart = "@${pkgs.libvirt}/sbin/virtlockd virtlockd";
|
serviceConfig.ExecStart = "@${cfg.package}/sbin/virtlockd virtlockd";
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue