Skip to content

fix: set wsl.useWindowsDriver when the nvidia-ctk is enabled - #478

Open
ereslibre wants to merge 1 commit into
nix-community:mainfrom
ereslibre:use-windows-driver
Open

fix: set wsl.useWindowsDriver when the nvidia-ctk is enabled#478
ereslibre wants to merge 1 commit into
nix-community:mainfrom
ereslibre:use-windows-driver

Conversation

@ereslibre

Copy link
Copy Markdown

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: #433
Related: NVIDIA/nvidia-container-toolkit#452


Note: unsure if this is the right approach for this project. I am the maintainer of the CDI-generation for NixOS, and we got a couple of reports that users could not use their GPU's inside Docker containers.

I cannot test it since I don't use NixOS-WSL, but I thought it would be good to improve the user experience here a bit if possible.

Thanks :)

@loicreynier

Copy link
Copy Markdown

I just tested this following NixOS/nixpkgs#312253 and can confirm it works fine with config.hardware.nvidia-container-toolkit.enable.

However, I don't think this should be limited only to wsl.docker-desktop.enable, since Podman users, for example, may want this feature by default without having to install Docker on their system.

@ereslibre
ereslibre force-pushed the use-windows-driver branch from 97fa52c to 179a541 Compare May 20, 2024 18:02
@ereslibre

Copy link
Copy Markdown
Author

Thanks a lot for checking @loicreynier! Good point, I have updated the PR to take into account config.virtualisation.podman.enable and config.virtualisation.docker.enable if the docker package supports CDI (Docker >= 25).

Comment thread modules/default.nix Outdated
Comment thread modules/nvidia-container-toolkit.nix Outdated
Comment thread modules/nvidia-container-toolkit.nix Outdated
Comment thread modules/nvidia-container-toolkit.nix Outdated
@loicreynier

Copy link
Copy Markdown

Looks good to me! Tested on a Podman setup and works as expected.

@ereslibre
ereslibre force-pushed the use-windows-driver branch from 179a541 to db74ebe Compare May 20, 2024 18:58
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: nix-community#433
Related: NVIDIA/nvidia-container-toolkit#452
@ereslibre
ereslibre force-pushed the use-windows-driver branch from db74ebe to 5069440 Compare May 20, 2024 18:59
@ereslibre
ereslibre requested a review from SuperSandro2000 May 20, 2024 19:00
573 added a commit to 573/nix-config-1 that referenced this pull request May 24, 2024
- Update neovim-nightly-flake
- Update docker used in Nixos-WSL to use v25 and
  nvidia-container-toolkit (nix-community/NixOS-WSL#478)
- reorganize emacs-novelist (still WIP) as scaffold to analyse
  extraPackages further
@573

573 commented Jul 3, 2024

Copy link
Copy Markdown
Contributor

Can this be force-pushed ?

@eihqnh

eihqnh commented Jul 4, 2024

Copy link
Copy Markdown

Excuse me, should the file nvidia-container-toolkit.json partly depend on NixOS's nvidia driver?
nvidia-x11-555.58-6.6.36

Here is

      {
        "containerPath": "/usr/bin/nvidia-smi",
        "hostPath": "**/nix/store/5s8mapl88avcqrggazg5kvm1y6b36a5p-nvidia-x11-555.58-6.6.36-bin/bin/nvidia-smi**",
        "options": [
          "ro",
          "nosuid",
          "nodev",
          "bind"
        ]
      },
      {
        "containerPath": "/usr/local/nvidia/lib",
        "hostPath": "/**nix/store/qb18b5vz3rd6jch2klqfkr9zv9pxnj06-nvidia-x11-555.58-6.6.36/lib**",
        "options": [
          "ro",
          "nosuid",
          "nodev",
          "bind"
        ]
      },
      {
        "containerPath": "/usr/local/nvidia/lib64",
        "hostPath": "/nix/store/qb18b5vz3rd6jch2klqfkr9zv9pxnj06-nvidia-x11-555.58-6.6.36/lib",
        "options": [
          "ro",
          "nosuid",
          "nodev",
          "bind"
        ]
      }        

@ereslibre

Copy link
Copy Markdown
Author

Excuse me, should the file nvidia-container-toolkit.json partly depend on NixOS's nvidia driver?

Yes. This is expected.

@nzbr
nzbr force-pushed the main branch 12 times, most recently from 0fa96ff to d34d941 Compare July 11, 2025 02:04
@nzbr
nzbr force-pushed the main branch 3 times, most recently from cc18cce to fd04040 Compare August 13, 2025 23:30
@nzbr nzbr added the GPU Related to GPU passthrough label Dec 15, 2025
@mdaniels5757 mdaniels5757 added the bug Something isn't working label Jun 5, 2026
Comment thread modules/nvidia.nix
#
# 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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wsl.useWindowsDriver = lib.mkIf config.hardware.nvidia-container-toolkit.enable true;
wsl.useWindowsDriver = lib.mkDefault config.hardware.nvidia-container-toolkit.enable;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also turn it off per default. This is an often pattern that is undesired, not sure what the correct variant is here.

@nzbr nzbr Jun 13, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe mkIf ... (mkDefault ...) then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working GPU Related to GPU passthrough

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants