1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.qemuGuest;
7in {
8
9 options.services.qemuGuest = {
10 enable = mkOption {
11 type = types.bool;
12 default = false;
13 description = "Whether to enable the qemu guest agent.";
14 };
15 package = mkPackageOption pkgs [ "qemu_kvm" "ga" ] { };
16 };
17
18 config = mkIf cfg.enable (
19 mkMerge [
20 {
21
22 services.udev.extraRules = ''
23 SUBSYSTEM=="virtio-ports", ATTR{name}=="org.qemu.guest_agent.0", TAG+="systemd" ENV{SYSTEMD_WANTS}="qemu-guest-agent.service"
24 '';
25
26 systemd.services.qemu-guest-agent = {
27 description = "Run the QEMU Guest Agent";
28 serviceConfig = {
29 ExecStart = "${cfg.package}/bin/qemu-ga --statedir /run/qemu-ga";
30 Restart = "always";
31 RestartSec = 0;
32 # Runtime directory and mode
33 RuntimeDirectory = "qemu-ga";
34 RuntimeDirectoryMode = "0755";
35 };
36 };
37 }
38 ]
39 );
40}