diff --git a/hosts/chernobog/modules/boot.nix b/hosts/chernobog/modules/boot.nix index ebbeb1e..4608d45 100644 --- a/hosts/chernobog/modules/boot.nix +++ b/hosts/chernobog/modules/boot.nix @@ -6,4 +6,8 @@ consoleMode = "max"; }; boot.loader.efi.canTouchEfiVariables = true; + + boot.kernelParams = [ + "clearcpuid=514" + ]; } diff --git a/hosts/chernobog/modules/cpuid-fault.nix b/hosts/chernobog/modules/cpuid-fault.nix new file mode 100644 index 0000000..fb0fa20 --- /dev/null +++ b/hosts/chernobog/modules/cpuid-fault.nix @@ -0,0 +1,87 @@ +{ + config, + pkgs, + lib, + ... +}: +let + kernel = config.boot.kernelPackages.kernel; + cpuidFaultEmulation = config.boot.kernelPackages.callPackage ( + { + stdenv, + fetchFromGitHub, + kernel, + }: + stdenv.mkDerivation { + pname = "cpuid_fault_emulation"; + version = "git-d54eb17"; + src = fetchFromGitHub { + owner = "dnmodder"; + repo = "cpuid-fault-emulation"; + rev = "d54eb176ddca3f22830f02d338904cc19ff1fc4a"; + hash = "sha256-ZpYY5EC1GPyTFyuYq3uY3a6OXlMeHrj/N8rdkPaDFyQ="; + }; + nativeBuildInputs = kernel.moduleBuildDependencies; + hardeningDisable = [ + "pic" + "format" + ]; + makeFlags = [ "KERNEL=${kernel.modDirVersion}" ]; + postPatch = '' + substituteInPlace Makefile \ + --replace-fail "/lib/modules/" "${kernel.dev}/lib/modules/" + ''; + installPhase = '' + install -D cpuid_fault_emulation.ko \ + $out/lib/modules/${kernel.modDirVersion}/extra/cpuid_fault_emulation.ko + ''; + meta.platforms = [ "x86_64-linux" ]; + } + ) { }; +in +{ + boot.extraModulePackages = [ cpuidFaultEmulation ]; + + systemd.services.cpuid-fault-emulation = { + description = "CPUID Fault Emulation Service"; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStart = pkgs.writeShellScript "cpuid-fault-emulation-start" '' + export PATH=${lib.makeBinPath (with pkgs; [ kmod gnugrep ])}:$PATH + if lsmod | grep -q "^kvm_amd"; then + modprobe -r kvm_amd + elif lsmod | grep -q "^kvm_intel"; then + modprobe -r kvm_intel + fi + modprobe -r kvm || true + modprobe cpuid_fault_emulation + ''; + ExecStop = pkgs.writeShellScript "cpuid-fault-emulation-stop" '' + export PATH=${lib.makeBinPath (with pkgs; [ kmod gnugrep ])}:$PATH + modprobe -r cpuid_fault_emulation + modprobe kvm || true + if grep -q "AuthenticAMD" /proc/cpuinfo; then + modprobe kvm_amd || true + elif grep -q "GenuineIntel" /proc/cpuinfo; then + modprobe kvm_intel || true + fi + ''; + }; + }; + + security.polkit.extraConfig = '' + // Allow users in wheel group to manage cpuid-fault-emulation.service without authentication + polkit.addRule(function(action, subject) { + if (action.id == "org.freedesktop.systemd1.manage-units" && + action.lookup("unit") == "cpuid-fault-emulation.service") { + var verb = action.lookup("verb"); + if (verb == "start" || verb == "stop" || verb == "restart") { + if (subject.isInGroup("wheel")) { + return polkit.Result.YES; + } + } + } + }); + ''; +} diff --git a/users/mayer/default.nix b/users/mayer/default.nix index 998f964..04bbd9f 100644 --- a/users/mayer/default.nix +++ b/users/mayer/default.nix @@ -175,6 +175,7 @@ in home = { homeDirectory = nixosConfig.users.users.mayer.home; packages = (with pkgs; [ + icu.dev # Font stuff noto-fonts-cjk-sans font-awesome