From 5069440f1b566cc15d1229c48c8f7f875fd32d87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Fern=C3=A1ndez=20L=C3=B3pez?= Date: Mon, 20 May 2024 17:21:42 +0200 Subject: [PATCH] fix: set wsl.useWindowsDriver when the nvidia-ctk is enabled This improves the user experience as whenever the user enables the `config.hardware.nvidia-container-toolkit.enable` option, they cannot use their Nvidia GPU's within the Docker containers because of missing libraries. This gets fixed by setting `wsl.useWindowsDriver` explicitly when the user requests to enable GPU support on Docker containers. Issue and fix provided by @qwqawawow Related: https://github.com/nix-community/NixOS-WSL/issues/433 Related: https://github.com/NVIDIA/nvidia-container-toolkit/issues/452 --- modules/default.nix | 1 + modules/nvidia.nix | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 modules/nvidia.nix diff --git a/modules/default.nix b/modules/default.nix index dde28965..18521b17 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,6 +3,7 @@ ./build-tarball.nix ./docker-desktop.nix ./interop.nix + ./nvidia.nix ./recovery.nix ./systemd ./usbip.nix diff --git a/modules/nvidia.nix b/modules/nvidia.nix new file mode 100644 index 00000000..41900810 --- /dev/null +++ b/modules/nvidia.nix @@ -0,0 +1,24 @@ +{ config, lib, ... }: +{ + + config = + lib.mkIf + ( + config.wsl.enable && + (config.wsl.docker-desktop.enable || + config.virtualisation.podman.enable || + (config.virtualisation.docker.enable && + (lib.versionAtLeast config.virtualisation.docker.package.version "25"))) + ) + { + + # Related issues: + # - https://github.com/nix-community/NixOS-WSL/issues/433 + # - https://github.com/NVIDIA/nvidia-container-toolkit/issues/452 + # + # By setting `useWindowsDriver` to true, the Nvidia libraries are properly + # mounted on the container from the host. + wsl.useWindowsDriver = lib.mkIf config.hardware.nvidia-container-toolkit.enable true; + + }; +}