how to configure nixos in wsl2 to use nvidia drivers for cuda
- User
how to configure nixos in wsl2 to use nvidia drivers for cuda
- Assistant
how to configure nixos in wsl2 to use nvidia drivers for cuda
Configuring NixOS in WSL2 to use NVIDIA drivers for CUDA involves several steps. It’s important to note that NVIDIA support within WSL2 has been evolving, and the necessary drivers and features may require specific versions of Windows, WSL2, and NVIDIA drivers.
Here's a general guide to get you started. Make sure you have a modern Windows 10/11 build and the latest WSL2 distribution.
Ensure you have WSL2 installed and updated.
wsl --install
wsl --update
Install NVIDIA Driver for CUDA on Windows.
Verify CUDA on WSL2:
nvidia-smi works within WSL2, which requires having NVIDIA GPU drivers along with support for WSL2 CUDA.nvidia-smi
Install NixOS in WSL2 if not already installed.
Configure NixOS with CUDA and NVIDIA dependencies.
configuration.nix to include the necessary NVIDIA packages.Here is an example configuration snippet to add NVIDIA and CUDA support:
{ config, pkgs, ... }:
{
# Enable the X11 windowing system (comment if not needed, as WSL2 typically does not use a windowing system)
services.xserver.enable = true;
# Enable CUDA support
hardware.nvidia = {
modesetting.enable = true;
nvidiaPersistenced.enable = true;
nvidiaSettings.enable = true;
};
# Add CUDA
environment.systemPackages = with pkgs; [
cuda
cudatoolkit
nvidia-x11
];
# Ensure the correct kernel modules are loaded
boot.extraModulePackages = [
pkgs.linuxPackages.nvidia_x11
];
# Ensure drivers are loaded at boot time
boot.kernelModules = [ "nvidia" "nvidia_uvm" "nvidia_drm" "nvidia_modeset" ];
# Set up the OpenCL configuration
hardware.opengl.extraPackages = with pkgs; [
opencl-headers
opencl-nvidia
];
}
Rebuild your NixOS configuration within WSL2.
sudo nixos-rebuild switch
Verify NVIDIA and CUDA setup within NixOS on WSL2.
nvidia-smi
nvcc --version
By following the guidelines above, you should have a basic NixOS setup in WSL2 that is capable of leveraging NVIDIA drivers for CUDA. Always refer to the latest documentation and community forums for up-to-date practices and troubleshooting.
Not yet included in a published release.