2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
86 lines
2.9 KiB
Nix
86 lines
2.9 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.virtualisation.kvmgt;
|
|
|
|
kernelPackages = config.boot.kernelPackages;
|
|
|
|
vgpuOptions = {
|
|
uuid = mkOption {
|
|
type = with types; listOf str;
|
|
description = "UUID(s) of VGPU device. You can generate one with <package>libossp_uuid</package>.";
|
|
};
|
|
};
|
|
|
|
in {
|
|
options = {
|
|
virtualisation.kvmgt = {
|
|
enable = mkEnableOption ''
|
|
KVMGT (iGVT-g) VGPU support. Allows Qemu/KVM guests to share host's Intel integrated graphics card.
|
|
Currently only one graphical device can be shared. To allow users to access the device without root add them
|
|
to the kvm group: <literal>users.extraUsers.<yourusername>.extraGroups = [ "kvm" ];</literal>
|
|
'';
|
|
# multi GPU support is under the question
|
|
device = mkOption {
|
|
type = types.str;
|
|
default = "0000:00:02.0";
|
|
description = lib.mdDoc "PCI ID of graphics card. You can figure it with {command}`ls /sys/class/mdev_bus`.";
|
|
};
|
|
vgpus = mkOption {
|
|
default = {};
|
|
type = with types; attrsOf (submodule [ { options = vgpuOptions; } ]);
|
|
description = ''
|
|
Virtual GPUs to be used in Qemu. You can find devices via <command>ls /sys/bus/pci/devices/*/mdev_supported_types</command>
|
|
and find info about device via <command>cat /sys/bus/pci/devices/*/mdev_supported_types/i915-GVTg_V5_4/description</command>
|
|
'';
|
|
example = {
|
|
i915-GVTg_V5_8.uuid = [ "a297db4a-f4c2-11e6-90f6-d3b88d6c9525" ];
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = singleton {
|
|
assertion = versionAtLeast kernelPackages.kernel.version "4.16";
|
|
message = "KVMGT is not properly supported for kernels older than 4.16";
|
|
};
|
|
|
|
boot.kernelModules = [ "kvmgt" ];
|
|
boot.kernelParams = [ "i915.enable_gvt=1" ];
|
|
|
|
services.udev.extraRules = ''
|
|
SUBSYSTEM=="vfio", OWNER="root", GROUP="kvm"
|
|
'';
|
|
|
|
systemd = let
|
|
vgpus = listToAttrs (flatten (mapAttrsToList
|
|
(mdev: opt: map (id: nameValuePair "kvmgt-${id}" { inherit mdev; uuid = id; }) opt.uuid)
|
|
cfg.vgpus));
|
|
in {
|
|
paths = mapAttrs (_: opt:
|
|
{
|
|
description = "KVMGT VGPU ${opt.uuid} path";
|
|
wantedBy = [ "multi-user.target" ];
|
|
pathConfig = {
|
|
PathExists = "/sys/bus/pci/devices/${cfg.device}/mdev_supported_types/${opt.mdev}/create";
|
|
};
|
|
}) vgpus;
|
|
|
|
services = mapAttrs (_: opt:
|
|
{
|
|
description = "KVMGT VGPU ${opt.uuid}";
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
ExecStart = "${pkgs.runtimeShell} -c 'echo ${opt.uuid} > /sys/bus/pci/devices/${cfg.device}/mdev_supported_types/${opt.mdev}/create'";
|
|
ExecStop = "${pkgs.runtimeShell} -c 'echo 1 > /sys/bus/pci/devices/${cfg.device}/${opt.uuid}/remove'";
|
|
};
|
|
}) vgpus;
|
|
};
|
|
};
|
|
|
|
meta.maintainers = with maintainers; [ patryk27 ];
|
|
}
|