pipewire low latency; boot entry to pass gpu to vm; etc

This commit is contained in:
chayleaf 2023-02-11 23:30:19 +07:00
parent b4ed70706f
commit 43e00a5481
7 changed files with 98 additions and 33 deletions

View file

@ -94,6 +94,13 @@
bat = {
enable = true;
};
bottom = {
enable = true;
settings = {
flags.network_use_bytes = true;
flags.enable_gpu_memory = true;
};
};
lsd = {
enable = true;
settings = {
@ -122,7 +129,8 @@
};
home.packages = with pkgs; [
rclone fuse jq appimage-run python3Full killall
comma
rclone sshfs fuse
jq python3Full killall
appimage-run comma
];
}

View file

@ -78,7 +78,6 @@
# home.file.".Xdefaults".source = /. + "/${config.home.homeDirectory}/.Xresources";
home.file.".Xdefaults".source = config.home.file."${config.home.homeDirectory}/.Xresources".source;
services.gammastep.enable = true;
services.kdeconnect.enable = true;
fonts.fontconfig.enable = true;
gtk = {
enable = true;
@ -130,7 +129,7 @@
qt5ct qgnomeplatform
# various programs i use
keepassxc nheko qbittorrent anki mumble
nextcloud-client gnome.zenity
nextcloud-client gnome.zenity kdeconnect
# cli tools
imagemagick ffmpeg
# fonts

View file

@ -383,10 +383,13 @@ in
export XDG_CURRENT_DESKTOP=sway
'';
};
services.swayidle = {
services.swayidle = let swaylock-start = builtins.toString (with pkgs; writeScript "swaylock-start" ''
#! ${bash}/bin/bash
${procps}/bin/pgrep -fx ${swaylock}/bin/swaylock || ${swaylock}/bin/swaylock
''); in {
enable = true;
events = [
{ event = "before-sleep"; command = "${pkgs.swaylock}/bin/swaylock"; }
{ event = "before-sleep"; command = swaylock-start; }
# after-resume, lock, unlock
];
timeouts = [
@ -394,7 +397,7 @@ in
command = "${pkgs.sway}/bin/swaymsg \"output * dpms off\"";
resumeCommand = "${pkgs.sway}/bin/swaymsg \"output * dpms on\""; }
{ timeout = 600;
command = "${pkgs.swaylock}/bin/swaylock"; }
command = swaylock-start; }
];
};
programs.swaylock.settings = let textColor = "#ebdadd"; bgColor = "#24101ac0"; in {

View file

@ -17,6 +17,17 @@
};
xsession.windowManager.i3.enable = true;
wayland.windowManager.sway.enable = true;
terminals = ["kitty" "urxvt"];
services.mpd = {
enable = true;
network.startWhenNeeded = true;
};
services.mpdris2 = {
enable = true;
};
programs.ncmpcpp = {
enable = true;
};
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"steam-run"
"steam"
@ -24,14 +35,14 @@
"steam-runtime"
"steamcmd"
];
terminals = ["kitty" "urxvt"];
home.packages = with pkgs; [
steam-run steam
easyeffects
wineWowPackages.waylandFull
# wineWowPackages.waylandFull
winetricks
protontricks proton-caller
protontricks # proton-caller
bottles
virtmanager
gimp krita blender
tdesktop
clang rustc rustfmt cargo clippy
@ -53,24 +64,9 @@
xdg.configFile."looking-glass/client.ini".text = ''
[app]
shmFile=/dev/kvmfr0
capture=dxgi
[dxgi]
copyBackend=d3d12
d3d12CopySleep=5
disableDamage=false
[input]
rawMouse=yes
escapeKey=KEY_INSERT
[egl]
vsync=yes
[opengl]
vsync=yes
[win]
jitRender=yes
'';
}

View file

@ -21,7 +21,7 @@
passGpuAtBoot = mkOption {
type = types.bool;
default = false;
description = "Whether to pass the GPU at boot (can be more stable)";
description = "Whether to pass the GPU at boot (can be more stable). If false, a bootloader entry to do it will still be available.";
};
pciIDs = mkOption {
type = with types; listOf str;
@ -70,7 +70,24 @@
gpuIDs = lib.concatStringsSep "," cfg.pciIDs;
enableIvshmem = config.vfio.lookingGlass.enable && (builtins.length config.vfio.lookingGlass.ivshmem) > 0;
in {
specialisation.vfio.configuration = lib.mkIf (!cfg.passGpuAtBoot) {
boot.kernelParams = [ "early_load_vfio" ];
};
boot = {
initrd.postDeviceCommands = lib.mkIf (!cfg.passGpuAtBoot) ''
for o in $(cat /proc/cmdline); do
case $o in
early_load_vfio)
loadVfio=1
;;
esac
done
if [[ -n "$loadVfio" ]]; then
modprobe vfio
modprobe vfio_iommu_type1
modprobe vfio_pci
fi
'';
initrd.kernelModules = [
(if cfg.intelCpu then "kvm-intel" else "kvm-amd")
] ++ (if cfg.passGpuAtBoot then [
@ -79,6 +96,12 @@
"vfio_pci"
"vfio_virqfd"
] else []);
initrd.availableKernelModules = lib.mkIf (!cfg.passGpuAtBoot) [
"vfio"
"vfio_iommu_type1"
"vfio_pci"
"vfio_virqfd"
];
extraModulePackages =
with config.boot.kernelPackages;
lib.mkIf enableIvshmem [ kvmfr ];
@ -118,11 +141,10 @@
qemu = {
ovmf.enable = true;
# Full is needed for TPM and secure boot emulation
ovmf.packages = [ pkgs.OVMFFull ];
ovmf.packages = [ pkgs.OVMFFull.fd ];
# TPM emulation
swtpm.enable = true;
verbatimConfig = ''
nvram = [ "${pkgs.OVMFFull}/FV/OVMF.fd:${pkgs.OVMFFull}/FV/OVMF_VARS.fd" ]
cgroup_device_acl = [
"/dev/kvmfr0",
"/dev/vfio/vfio", "/dev/vfio/11", "/dev/vfio/12",

View file

@ -11,9 +11,13 @@
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-gaming = {
url = "github:fufexan/nix-gaming";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, nixpkgs, utils, nixos-hardware, rust-overlay, impermanence }:
outputs = inputs@{ self, nixpkgs, utils, nixos-hardware, rust-overlay, impermanence, nix-gaming }:
let
hw = nixos-hardware.nixosModules;
# IRL-related stuff I'd rather not put into git
@ -38,6 +42,7 @@
modules = [
./hosts/nixmsi.nix
impermanence.nixosModule
nix-gaming.nixosModules.pipewireLowLatency
hw.common-pc-ssd # enables fstrim
hw.common-cpu-amd # microcode
hw.common-cpu-amd-pstate # amd-pstate

View file

@ -1,9 +1,14 @@
{ config, lib, pkgs, ... }:
let
efiPart = "/dev/disk/by-uuid/D77D-8CE0";
encPart = "/dev/disk/by-uuid/ce6ccdf0-7b6a-43ae-bfdf-10009a55041a";
cryptrootUuid = "f4edc0df-b50b-42f6-94ed-1c8f88d6cdbb";
cryptroot = "/dev/disk/by-uuid/${cryptrootUuid}";
encPart = "/dev/disk/by-uuid/ce6ccdf0-7b6a-43ae-bfdf-10009a55041a";
efiPart = "/dev/disk/by-uuid/D77D-8CE0";
dataPart = "/dev/disk/by-uuid/f1447692-fa7c-4bd6-9cb5-e44c13fddfe3";
datarootUuid = "fa754b1e-ac83-4851-bf16-88efcd40b657";
dataroot = "/dev/disk/by-uuid/${datarootUuid}";
in {
system.stateVersion = "22.11";
@ -24,6 +29,13 @@ in {
bypassWorkqueues = true;
keyFile = "/crypto_keyfile.bin";
};
luks.devices."dataroot" = {
device = dataPart;
preLVM = true;
allowDiscards = true;
bypassWorkqueues = true;
keyFile = "/crypto_keyfile.bin";
};
};
resumeDevice = cryptroot;
kernelParams = [
@ -101,6 +113,9 @@ in {
options = [ discard compress "subvol=@boot" ]; };
"/boot/efi" =
{ device = efiPart; fsType = "vfat"; inherit neededForBoot; };
"/data" =
{ device = dataroot; fsType = "btrfs";
options = [ discard compress ]; };
};
environment.persistence."/persist" = {
@ -147,8 +162,9 @@ in {
i18n.supportedLocales = lib.mkDefault [ "en_US.UTF-8/UTF-8" ];
networking.useDHCP = true;
# networking.firewall.enable = false;
networking.firewall.allowedTCPPorts = [ 27015 25565 7777 ];
# networking.firewall.allowedUDPPorts = [ ... ];
# KDE connect: 1714-1764
networking.firewall.allowedTCPPorts = [ 27015 25565 7777 ] ++ (builtins.genList (x: 1714 + x) (1764 - 1714 + 1));
networking.firewall.allowedUDPPorts = (builtins.genList (x: 1714 + x) (1764 - 1714 + 1));
# networking.hostName = "nixmsi";
networking.wireless.iwd.enable = true;
#networking.networkmanager.enable = true;
@ -170,6 +186,7 @@ in {
vim
wget
git
man-pages man-pages-posix
];
services.dbus.enable = true;
security.polkit.enable = true;
@ -181,6 +198,12 @@ in {
alsa.support32Bit = true;
pulse.enable = true;
jack.enable = true;
# from nix-gaming
lowLatency = {
enable = true;
quantum = 64;
rate = 48000;
};
};
# zsh
environment.pathsToLink = [ "/share/zsh" ];
@ -194,6 +217,7 @@ in {
users.mutableUsers = false;
users.users.user = {
uid = 1000;
isNormalUser = true;
extraGroups = [ "networkmanager" "wheel" ];
# initialHashedPassword = ...set in private.nix;
@ -215,8 +239,16 @@ in {
'';
};
documentation.dev.enable = true;
### RANDOM PATCHES ###
# I've had some weird issues with the entire system breaking after
# suspend because of /dev/shm getting nuked, maybe this'll help
services.logind.extraConfig = ''
RemoveIPC=no
'';
# why is this not part of base NixOS?
systemd.tmpfiles.rules = [ "d /var/lib/systemd/pstore 0755 root root 14d" ];