Instructions came from this video, which also links to this repo.
NixOS documentation is also available at https://nixos.wiki/wiki/Nvidia
- First enable openGL
hardware.graphics = { enable = true; enable32Bit = true; };
- Follow the instructions for the graphics card
Add the following to the config:
services.xserver.videoDrivers = [ "nvidia" ];
If the host is a laptop and has two graphics cards, like an Intel, which consumes less energy, and the NVidia, which has more power, add the following:
# This is not the only way to configure the driver. Please check more options in nixos documentation
hardware.nvidia = {
open = true;
prime = {
offload = {
enable = true;
# Will enable nvidia-offload command
enableOffloadCmd = true;
};
# Bus ids retrieved with command:
# nix shell nixpkgs#pciutils -c lspci
# And confirmed with
# sudo nix run nixpkgs#lshw -- -c display
# integrated
intelBusId = "PCI:0:2:0";
# amdgpuBusId = "PCI:6:0:0"
# dedicated
nvidiaBusId = "PCI:1:0:0";
};
};
Also note that the intelBusId
and nvidiaBusId
will have to be changed, as they vary by hardware.
To get the Bus IDs, you need to use either the command nix shell nixpkgs#pciutils -c lspci | grep ' VGA '"
(you may need to omit the grep
part) or the command sudo lshw -c display
. I used both to ensure I got the correct value. Also, the values will need to be in decimal, while the commands could output them in hexadecimal. For more details, read the documentation.
To use the graphics card, use nvidia-offload %command%
. This will instruct the OS to use the GPU for the spawned process.
I haven't installed with AMD graphics cards right now, but it's possible that the instructions on the video/repo will still work.