NixOS NVIDIA PRIME 配置笔记


NixOS logo NixOS logo

我的硬件是 Lenovo Legion Y9000P,Intel Iris Xe 核显和 NVIDIA RTX 3060 独显。

Offload 模式

configuration.nix 中添加:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{ config, pkgs, ... }:
let
nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
export __NV_PRIME_RENDER_OFFLOAD=1
export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
export __GLX_VENDOR_LIBRARY_NAME=nvidia
export __VK_LAYER_NV_optimus=NVIDIA_only
exec "$@"
'';
in
{

#无关内容省略

nixpkgs.config.allowUnfree = true;
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia.prime = {
offload.enable = true;
intelBusId = "PCI:0:2:0"; # 此处的 BusId 需要通过命令 lspci | grep VGA 来查看
nvidiaBusId = "PCI:1:0:0"; # 同上
};
}

完成!