nixos/libvirt: avoid dependency on two qemu packages

Currently libvirt requires two qemu derivations: qemu and qemu_kvm which is just a truncated version of qemu (defined as qemu.override { hostCpuOnly = true; }).

This patch exposes an option virtualisation.libvirtd.qemuPackage which allows to choose which package to use:

 * pkgs.qemu_kvm if all your guests have the same CPU as host, or
 * pkgs.qemu which allows to emulate alien architectures (for example ARMV7L on X86_64), or
 * a custom derivation

virtualisation.libvirtd.enableKVM option is vague and could be deprecate in favor of virtualisation.libvirtd.qemuPackage, anyway it does allow to enable/disable kvm.
This commit is contained in:
volth
2017-12-06 04:33:45 +00:00
committed by Orivej Desh
parent fd91e1441f
commit a52aa6aafb
2 changed files with 16 additions and 9 deletions

View File

@@ -41,7 +41,16 @@ in {
type = types.bool;
default = true;
description = ''
This option enables support for QEMU/KVM in libvirtd.
This option disables support for non-KVM guests in libvirtd (e.g. aarch64 on x86).
KVM is available even if this setting is false.
'';
};
virtualisation.libvirtd.qemuPackage = mkOption {
type = types.package;
default = if cfg.enableKVM then pkgs.qemu_kvm else pkgs.qemu;
description = ''
Qemu package to use with libvirt
'';
};
@@ -102,7 +111,7 @@ in {
config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [ libvirt netcat-openbsd qemu_kvm ];
environment.systemPackages = with pkgs; [ libvirt netcat-openbsd cfg.qemuPackage ];
boot.kernelModules = [ "tun" ];
@@ -154,9 +163,9 @@ in {
# stable (not GC'able as in /nix/store) paths for using in <emulator> section of xml configs
mkdir -p /run/libvirt/nix-emulators
ln -s --force ${pkgs.libvirt}/libexec/libvirt_lxc /run/libvirt/nix-emulators/
${optionalString pkgs.stdenv.isAarch64 "ln -s --force ${pkgs.qemu}/bin/qemu-system-aarch64 /run/libvirt/nix-emulators/"}
${optionalString cfg.enableKVM "ln -s --force ${pkgs.qemu_kvm}/bin/qemu-kvm /run/libvirt/nix-emulators/"}
for emulator in ${pkgs.libvirt}/libexec/libvirt_lxc ${cfg.qemuPackage}/bin/qemu-kvm ${cfg.qemuPackage}/bin/qemu-system-*; do
ln -s --force "$emulator" /run/libvirt/nix-emulators/
done
${optionalString cfg.qemuOvmf ''
mkdir -p /run/libvirt/nix-ovmf