nixos下使用kvm和显卡直通等 简要配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{ config, lib, pkgs, ... }:
{

  # <https://github.com/kholia/OSX-KVM>
  # Required by AMD boxes for OSX-KVM
  boot.extraModprobeConfig = ''
    options kvm_amd nested=1
    options bt_coex_active=0 swcrypto=1 11n_disable=8
    options kvm ignore_msrs=1 report_ignored_msrs=0
  '';

  # For Intel:
  /*
  options kvm_intel nested=1
    options kvm_intel emulate_invalid_guest_state=0
    options kvm ignore_msrs=1
  */
virtualisation.libvirtd = {
  enable = true;
  qemu = {
    package = pkgs.qemu_kvm;
    runAsRoot = true;
    swtpm.enable = true;
    ovmf = {
      enable = true;
      #packages = [(pkgs.unstable.OVMF.override {
        packages = [(pkgs.OVMF.override {
        secureBoot = true;
        tpmSupport = true;
      }).fd];
    };
  };
};
    environment.systemPackages = with pkgs; [
    virt-manager
  ];

}

其他一些参考配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

  boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "ehci_pci" "ahci" "nvme" "sr_mod" ];
  boot.kernelParams = [ "radeon.cik_support=0" "amdgpu.cik_support=1" "amd_iommu=on" ];
  boot.initrd.kernelModules = [ "amdgpu" ];
  boot.kernelModules = [ "iwlwifi" "iwlmvm " "kvm-amd" "vfio" "vfio_iommu_type1" "vfio_pci" "vfio_virqfd"]; 
  boot.extraModprobeConfig = ''
    options bt_coex_active=0 swcrypto=1 11n_disable=8
  '';
  #boot.extraModulePackages = [config.boot.kernelPackages.rtw89];
  boot.kernelPackages = pkgs.unstable.linuxPackages_latest; # Use latest kernel.
  boot.supportedFilesystems = [ 
    "ext4"
    "btrfs"
    "xfs"
    #"zfs"
    "ntfs"
    "fat"
    "vfat"
    "exfat"
    ]; 
  hardware.enableAllFirmware = true; 

  boot.loader.systemd-boot.enable = true; # Enable systemd-boot.
  boot.loader.efi.canTouchEfiVariables = true; # Enable EFI variables.

  services.xserver.videoDrivers = [ "amdgpu" ];
  #services.xserver.videoDrivers = [ "amdgpu" "nvidia"];
  # ================= graphics 
  # https://nixos.wiki/wiki/AMD_GPU
  nixpkgs.config.packageOverrides = pkgs: {
   # intel-vaapi-driver = pkgs.intel-vaapi-driver.override { enableHybridCodec = true; };
  };
  hardware.graphics = {
    enable = true;
    #driSupport = true;
    enable32Bit = true;
    extraPackages = with pkgs; [
      rocmPackages.clr.icd
    ];
  };
  hardware.nvidia = {
    modesetting.enable = true;
    powerManagement.enable = false;
    powerManagement.finegrained = false;
    open = false;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.stable;
  };
  environment.sessionVariables = {
    LIBVA_DRIVER_NAME = "iHD";
    #NIXOS_OZONE_WL = "1"; chrome ele
  };
  #services.thermald.enable = true; #防止intel cpu过热
  # =================  auto-cpufreq power-profiles-daemon tlp 三选
  services.power-profiles-daemon.enable = false; #gnome自帶的 關閉
  # tlp
  services.tlp = {
      enable = true;
      settings = {
        CPU_SCALING_GOVERNOR_ON_AC = "performance";
        CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
        CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
        CPU_ENERGY_PERF_POLICY_ON_AC = "performance";
        CPU_MIN_PERF_ON_AC = 0;
        CPU_MAX_PERF_ON_AC = 100;
        CPU_MIN_PERF_ON_BAT = 0;
        CPU_MAX_PERF_ON_BAT = 20;
       #Optional helps save long term battery health
        START_CHARGE_THRESH_BAT0 = 40; # 40 and bellow it starts to charge
        STOP_CHARGE_THRESH_BAT0 = 80; # 80 and above it stops charging
      };
  };
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计