nixos-config/hosts/miku.nix

262 lines
7.9 KiB
Nix

{ config, pkgs, modulesPath, lib, ... }:
let
unstable = (import ../modules/unstable.nix config);
customPkgs = import ../packages/overlay.nix;
in {
imports = [
./generic.nix
../modules/hardware/generic.nix ../modules/hardware/video.nix
../modules/fonts.nix
../modules/users/alexander.nix
../modules/programs/zsh ../modules/programs/git ../modules/programs/mpv ../modules/programs/tmux ../modules/programs/emacs ../modules/programs/firefox ../modules/programs/gnome-terminal ../modules/programs/gnome ../modules/programs/i18n.nix ../modules/programs/gamemode ../modules/programs/nonvm
../modules/programs/distributed-build/builder.nix
#./modules/programs/music
];
nixpkgs.overlays = [
(import (builtins.fetchGit {
url = "https://github.com/nix-community/emacs-overlay.git";
ref = "master";
rev = "ce0e9482d53d69bedc8416d8a984d00e17607826";
}))
customPkgs
];
nixpkgs.config.packageOverrides = pkgs: {
nur = (import ../modules/nur.nix pkgs);
unstable = unstable;
};
environment = {
systemPackages = with pkgs; [
emacsPgtkGcc
unstable.firmwareLinuxNonfree
gajim
libvirt virt-manager qemu
gamemode # Custom package
key-mapper # Custom package
replaysorcery # Custom package
evdev-proxy # Custom package
scream
steam
linuxPackages_zen.vendor-reset
];
sessionVariables = {
# Prevent us from having to always type it out
#NIXOS_CONFIG = "\${HOME}/Development/Personal/nixos-config/hosts/miku.nix";
};
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]
name = "EvdevProxyTartarus"
vendor = 0x1337
model = 0x1338
class = "Mouse"
[[device.Simple.selector]]
USBIDClass = {vendor=0x1532, model=0x022b, class="Keyboard"}
[[device.Simple.selector]]
EVDEVClass = {phys="\"key-mapper\""}
'';
"libvirt/hooks/qemu" = {
source = pkgs.writeText "qemu" ''
#!/bin/sh
guest=$1
phase=$2
state=$3
what=$4
if [[ "$guest" = "win10" ]]; then
case "$phase" in
"prepare")
sudo -u alexander systemctl --user start evdev-proxy
;;
"start")
sudo -u alexander systemctl --user start scream
;;
"stopped")
sudo -u alexander systemctl --user stop scream
sudo -u alexander systemctl --user stop evdev-proxy
esac
end
'';
mode = "0755";
};
};
};
networking = {
interfaces.enp6s0.useDHCP = false;
hostName = "miku";
# Nix otherwise has a conflict with this option
wireless.enable = lib.mkForce false;
# Allow scream to connect to this host
firewall.allowedUDPPorts = [ 4010 ];
};
boot = {
loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
extraModprobeConfig = ''
options kvm_amd nested=1
options vfio-pci ids=1002:67df,1002:aaf0
'';
initrd = {
availableKernelModules = [ "xhci_pci" "ahci" "usbhid" "sd_mod" "amdgpu" "vendor-reset" ];
kernelModules = [
"amdgpu" # GPU (duh)
"kvm-amd" "vfio_virqfd" "vfio_pci" "vfio_iommu_type1" "vfio" # Virt
"uinput" # key-mapper
"vendor-reset"
];
};
kernelParams = [
"amd_iommu=on"
"iommu=pt"
"sysrq_always_enabled=1"
"kvm.ignore_msrs=1"
"kvm.report_ignored_msrs=N"
"fbcon=rotate:1"
"quiet"
];
kernelModules = [];
extraModulePackages = [ pkgs.linuxPackages_zen.vendor-reset ];
kernelPackages = pkgs.linuxPackages_zen;
#kernelPackages = pkgs.linuxPackages_lqx;
};
services = {
# NOTE: key-mapper has a dbus policy file that we need to include
dbus.packages = [ pkgs.key-mapper ];
emacs.package = pkgs.emacsPgtkGcc;
flatpak.enable = true;
xserver.videoDrivers = [ "amdgpu" ];
udev.extraRules = ''
KERNEL=="uinput", GROUP="input"
# This rule allows the input group to access /dev/uinput device to create virtual input devices
KERNEL=="uinput", SUBSYSTEM=="misc", GROUP="input", MODE="660"
# Create rules for your virtual devices to get persistent names
KERNEL=="event*", SUBSYSTEM=="input", ATTRS{name}=="EvdevProxy*", SYMLINK+="input/by-id/virtual-event-$attr{name}"
'';
sshd.enable = true;
};
virtualisation.libvirtd = {
enable = true;
qemuOvmf = true;
#qemuRunAsRoot = false;
qemuPackage = unstable.qemu;
qemuVerbatimConfig = ''
seccomp_sandbox = 0
cgroup_device_acl = [
"/dev/null", "/dev/full", "/dev/zero",
"/dev/random", "/dev/urandom",
"/dev/ptmx", "/dev/kvm", "/dev/kqemu",
"/dev/rtc","/dev/hpet",
"/dev/input/by-id/usb-Logitech_USB_Receiver-if02-event-mouse",
"/dev/input/by-id/usb-Razer_Razer_Tartarus_V2-event-kbd",
"/dev/input/by-id/virtual-event-EvdevProxyMouse"
]
'';
};
systemd = {
services.NetworkManager-wait-online.enable = false;
user.services = {
scream = {
description = "Audio receiver for the Scream virtual network sound card";
#wantedBy = [ "default.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.scream}/bin/scream -i virbr0 -o pulse";
Restart = "always";
};
};
replaysorcery-kms = {
description = "An open-source, instant-replay solution for Linux; KMS service";
#wantedBy = [ "default.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.replaysorcery}/bin/replay-sorcery kms-service";
Restart = "always";
};
};
key-mapper = {
description = "A tool to change the mapping of your input device buttons";
wantedBy = [ "default.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.key-mapper}/bin/key-mapper-service";
Restart = "always";
};
};
replaysorcery = {
description = "An open-source, instant-replay solution for Linux";
#wantedBy = [ "default.target" ];
requires = [ "replaysorcery-kms.service" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.replaysorcery}/bin/replay-sorcery";
Restart = "always";
};
};
evdev-proxy = {
description = "Creates virtual device to proxy evdev devices events";
#wantedBy = [ "default.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.evdev-proxy}/bin/evdev-proxy";
Restart = "always";
};
};
gamemode = {
description = "A daemon/lib combo for Linux that allows games to request a set of optimisations be temporarily applied to the host OS.";
wantedBy = [ "default.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.gamemode}/bin/gamemoded";
Restart = "always";
};
};
};
};
fileSystems = {
"/" = {
device = "/dev/disk/by-label/root";
fsType = "btrfs";
};
"/boot" = {
device = "/dev/disk/by-label/boot";
fsType = "vfat";
};
"/mnt/Storage" = {
device = "/dev/disk/by-label/storage";
fsType = "ext4";
};
};
swapDevices = [ ];
}