From ca0604190e4428e1cdf9bb369fbbf73e1679e007 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Wed, 18 Apr 2018 11:29:54 +0900 Subject: [PATCH] qemu-guest-agent: init module Allow out of band communication between qemu VMs and the host. Useful to retrieve IPs of VMs from the host (for instance when libvirt can't analyze DHCP requests because VMs are configured with static addresses or when there is connectivity default). --- nixos/modules/module-list.nix | 1 + .../virtualisation/qemu-guest-agent.nix | 36 +++++++++++++++++++ nixos/modules/virtualisation/qemu-vm.nix | 11 ++++++ 3 files changed, 48 insertions(+) create mode 100644 nixos/modules/virtualisation/qemu-guest-agent.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 8ef76b9d81e..8a81a5fff8d 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -777,6 +777,7 @@ ./virtualisation/hyperv-guest.nix ./virtualisation/openvswitch.nix ./virtualisation/parallels-guest.nix + ./virtualisation/qemu-guest-agent.nix ./virtualisation/rkt.nix ./virtualisation/virtualbox-guest.nix ./virtualisation/virtualbox-host.nix diff --git a/nixos/modules/virtualisation/qemu-guest-agent.nix b/nixos/modules/virtualisation/qemu-guest-agent.nix new file mode 100644 index 00000000000..e0d2b3dc509 --- /dev/null +++ b/nixos/modules/virtualisation/qemu-guest-agent.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.qemuGuest; +in { + + options.services.qemuGuest = { + enable = mkOption { + type = types.bool; + default = false; + description = "Whether to enable the qemu guest agent."; + }; + }; + + config = mkIf cfg.enable ( + mkMerge [ + { + + services.udev.extraRules = '' + SUBSYSTEM=="virtio-ports", ATTR{name}=="org.qemu.guest_agent.0", TAG+="systemd" ENV{SYSTEMD_WANTS}="qemu-guest-agent.service" + ''; + + systemd.services.qemu-guest-agent = { + description = "Run the QEMU Guest Agent"; + serviceConfig = { + ExecStart = "${pkgs.kvm.ga}/bin/qemu-ga"; + Restart = "always"; + RestartSec = 0; + }; + }; + } + ] + ); +} diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix index 2b78276fcde..57e25d808dc 100644 --- a/nixos/modules/virtualisation/qemu-vm.nix +++ b/nixos/modules/virtualisation/qemu-vm.nix @@ -343,6 +343,15 @@ in (virtio or scsi). ''; }; + + guestAgent.enable = + mkOption { + default = true; + type = types.bool; + description = '' + Enable the Qemu guest agent. + ''; + }; }; virtualisation.useBootLoader = @@ -494,6 +503,8 @@ in # Don't run ntpd in the guest. It should get the correct time from KVM. services.timesyncd.enable = false; + services.qemuGuest.enable = cfg.qemu.guestAgent.enable; + system.build.vm = pkgs.runCommand "nixos-vm" { preferLocalBuild = true; } '' mkdir -p $out/bin