nixos-config/modules/virtualisation/gaming.nix

99 lines
3.3 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
let
cfg = config.ptw.virtualisation.gaming;
in {
options.ptw.virtualisation.gaming = {
enable = lib.mkEnableOption "Configure virtualisation for gaming purposes";
};
config = lib.mkIf cfg.enable {
environment.etc = {
"evdev-proxy/config.toml".source = pkgs.writeText "config.toml" ''
log_level = "INFO"
[[device]]
[device.Simple]
name = "EvdevProxyMouse"
vendor = 0x1337
model = 0x1337
class = "Mouse"
[[device.Simple.selector]]
USBIDClass = {vendor=0x046d, model=0xc531, class="Mouse"}
[[device.Simple.selector]]
USBIDClass = {vendor=0x046d, model=0xc07c, class="Mouse"}
[[device]]
[device.Simple]
2022-02-14 17:34:04 +00:00
name = "EvdevProxyKeyboard"
vendor = 0x1337
model = 0x1338
class = "Keyboard"
# This is to give a deterministic /dev/input/by-id/ path to
# the mapped version of the Tartarus evdev node.
# (Useful for qemu)
[[device.Simple.selector]]
2022-02-14 17:34:04 +00:00
EVDEVClass = {phys="\"input-remapper\""}
[[device.Simple.selector]]
USBIDClass = {vendor=0x1532, model=0x011a, class="Keyboard"}
'';
2023-04-08 15:30:39 +00:00
# "libvirt/hooks/qemu".source = let
# vfio-isolate-state = "/tmp/vfio-isolate-state";
# in pkgs.writeScript "qemu" ''
# #!${pkgs.stdenv.shell}
# guest=$1
# action=$2
# phase=$3
# extra=$4
2023-04-08 15:30:39 +00:00
# echo "called with $1 $2 $3 $4" > /dev/stderr
# if [[ "$guest" = "win10-gaming" ]]; then
# case "$action" in
# prepare)
# # Only do this while in preparation
# [[ ! "$phase" = "prepare" ]] && exit 0
2023-04-08 15:30:39 +00:00
# GUEST_CORES="C1-3,5-7"
# ${pkgs.vfio-isolate}/bin/vfio-isolate \
# -u ${vfio-isolate-state} \
# cpu-governor performance "$GUEST_CORES" \
# cpuset-create --cpus "$GUEST_CORES" /guest.slice \
# cpuset-create --cpus C0,4 /host.slice \
# move-tasks / /host.slice \
# irq-affinity mask "$GUEST_CORES"
# ;;
# stopped)
# # Only run when the VM is fully stopped
# [[ ! "$phase" = "end" ]] && exit 0
# ${pkgs.vfio-isolate}/bin/vfio-isolate \
# restore ${vfio-isolate-state}
# esac
# fi
# '';
};
# NOTE: Workaround for libvirt's SYSCONFDIR being set to /var/lib
# (See https://github.com/NixOS/nixpkgs/issues/51152#issuecomment-899374407)
system.activationScripts.libvirt-hooks.text = ''
2022-02-02 11:08:03 +00:00
ln -Tfs /etc/libvirt/hooks /var/lib/libvirt/hooks
'';
2022-02-02 11:08:03 +00:00
services.udev.packages = with pkgs; [ evdev-proxy ];
systemd = {
2022-02-11 13:01:52 +00:00
services = {
2023-04-08 15:30:39 +00:00
libvirtd.path = with pkgs; [ /*vfio-isolate*/ systemd bash ];
2022-02-11 13:01:52 +00:00
};
2022-02-02 11:08:03 +00:00
user.services.evdev-proxy = {
description = "Creates virtual device to proxy evdev devices events";
2022-02-11 13:01:52 +00:00
wantedBy = [ "default.target" ];
2022-02-02 11:08:03 +00:00
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.evdev-proxy}/bin/evdev-proxy";
Restart = "always";
};
};
};
};
}