Skip to content

Latest commit

 

History

History
106 lines (74 loc) · 3.97 KB

01-nixos-nvidia-setup.org

File metadata and controls

106 lines (74 loc) · 3.97 KB

01. Setup NixOS to use Nvidia drivers with CUDA support

As NixOS already has good support for using Nvidia drivers, this is going to be one of the easiest steps. Make a note of the CUDA version installed, as it’ll be important for the steps later.

Start using Nvidia drivers

As mentioned in the official NixOS wiki, installation of the driver is a simple switch of configuration. https://nixos.wiki/wiki/Nvidia

This setup is used for a RTX 30 series card, and using the stable driver on 23.11 channel. (Driver Version: 545.29.02 on Jan 19th 2024). Please check the wiki link above to see if you’re using a relatively old card and might need legacy drivers.

Having the GPU configuration in a separate file makes it easy to include in the main configuration.

nvidia_gpu.nix

{ config, lib, pkgs, ... }:


{
  services.xserver.videoDrivers = [ "nvidia" ];

  # If you have GPUs from multiple providers (such as Intel)
  # services.xserver.videoDrivers = [ "intel" "nvidia" ];

  # Also enable OpenGL
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

}

Include the gpu config in the main configuration

configuration.nix

{ config, lib, pkgs, ... }:

{
  imports = [
    ./hardware-configuration.nix

    .
    .

    # gpu
    ./nvidia_gpu.nix

    .
    .

  ];

.
.
.

Rebuild nixos and wait for the driver to be successfully installed. Reboot and continue.

Pay attention to the driver version and CUDA version

At this point, you should have a functioning Nvidia GPU on your NixOS host. Check the wiki and forums again for any issues.

Check the general information about your GPU. Make a note of the CUDA driver version.

> nvidia-smi
Fri Jan 19 00:56:50 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 545.29.02              Driver Version: 545.29.02    CUDA Version: 12.3     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3090        Off | 00000000:01:00.0 Off |                  N/A |
|  0%   35C    P8              23W / 370W |     60MiB / 24576MiB |      0%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

+---------------------------------------------------------------------------------------+
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|=======================================================================================|
|    0   N/A  N/A      1421      G   ...d7i554q9hl-xorg-server-21.1.9/bin/X       52MiB |
+---------------------------------------------------------------------------------------+

Install some useful tools (and benchmarks) on the NixOS host

The instruction below are for running them without permanent installation. Install them as needed.

nix-shell -p nvtop --run nvtop
nix-shell -p glxinfo --run glxgears
nix-shell -p unigine-valley --run valley

Optionally, for i3 window manager, i3status-rust supports Nvidia GPU blocks

https://greshake.github.io/i3status-rust/i3status_rs/blocks/nvidia_gpu/index.html