How to Run Nvidia Container in NixOS WSL #487
-
I'd like to run some ML projects using docker with Nvidia GPU enabled, but I don't know how to set up nvidia-container-toolkit in NixOS-WSL. My docker-related config is virtualisation.docker = {
enable = true;
rootless = {
enable = true;
setSocketVariable = true;
daemon.settings = {
default-runtime = "nvidia";
runtimes.nvidia.path = "${pkgs.nvidia-docker}/bin/nvidia-container-runtime";
};
};
};
hardware.nvidia-container-toolkit.enable = true; Here's the error message when I try running a simple
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I see the same on my NixOS, my configuration looks like @Fr4nk1inCs's config above. Running on a Dell 5560 with Nvidia dGPU and Intel iGPU and with Prime sync configured. |
Beta Was this translation helpful? Give feedback.
-
Didn't had the time to check, have you tried to enable the CDI feature in the docker daemon settings ? As I saw that it wasn't enabled by default in the docker documentation, wsl provide a Nvidia CDI as far I remember. |
Beta Was this translation helpful? Give feedback.
-
Thanks @shikanime, CDI is the solution: $ sudo docker run --rm --device nvidia.com/gpu=all --security-opt=label=disable ubuntu nvidia-smi -L
GPU 0: NVIDIA GeForce RTX 4070 SUPER (UUID: ...)
$ # rootless
$ docker run --rm --device nvidia.com/gpu=all --security-opt=label=disable ubuntu nvidia-smi -L
GPU 0: NVIDIA GeForce RTX 4070 SUPER (UUID: ...) Configuration: virtualisation.docker = {
enable = true;
rootless = {
enable = true;
setSocketVariable = true;
daemon.settings = {
features.cdi = true;
cdi-spec-dirs = ["/home/${username}/.cdi"];
};
};
daemon.settings = {
features.cdi = true;
};
};
hardware = {
nvidia = {
modesetting.enable = true;
nvidiaSettings = false;
open = false;
};
nvidia-container-toolkit.enable = true;
};
services.xserver.videoDrivers = ["nvidia"]; The After rebuild, we need to run the $ nvidia-ctk cdi generate --output="$HOME/nvidia.yaml"
...
$ sudo nvidia-ctk cdi generate --output="/etc/cdi/nvidia.yaml"
... |
Beta Was this translation helpful? Give feedback.
Thanks @shikanime, CDI is the solution:
Configuration: