nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

nixos/hardware/nvidia: eager load nvidia-uvm for open driver

Fixes contingent CUDA issues with open driver:
https://github.com/NixOS/nixpkgs/issues/334180

Co-authored-by: Someone Serge <else@someonex.net>

+16 -12
+16 -12
nixos/modules/hardware/video/nvidia.nix
··· 343 343 ]; 344 344 345 345 # Don't add `nvidia-uvm` to `kernelModules`, because we want 346 - # `nvidia-uvm` be loaded only after `udev` rules for `nvidia` kernel 347 - # module are applied. 346 + # `nvidia-uvm` be loaded only after the GPU device is available, i.e. after `udev` rules 347 + # for `nvidia` kernel module are applied. 348 + # This matters on Azure GPU instances: https://github.com/NixOS/nixpkgs/pull/267335 348 349 # 349 350 # Instead, we use `softdep` to lazily load `nvidia-uvm` kernel module 350 351 # after `nvidia` kernel module is loaded and `udev` rules are applied. 351 352 extraModprobeConfig = '' 352 353 softdep nvidia post: nvidia-uvm 353 354 ''; 355 + 356 + # Exception is the open-source kernel module failing to load nvidia-uvm using softdep 357 + # for unknown reasons. 358 + # It affects CUDA: https://github.com/NixOS/nixpkgs/issues/334180 359 + # Previously nvidia-uvm was explicitly loaded only when xserver was enabled: 360 + # https://github.com/NixOS/nixpkgs/pull/334340/commits/4548c392862115359e50860bcf658cfa8715bde9 361 + # We are now loading the module eagerly for all users of the open driver (including headless). 362 + kernelModules = lib.optionals useOpenModules [ "nvidia_uvm" ]; 354 363 }; 355 364 systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [ 356 365 "L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin" ··· 648 639 boot = { 649 640 extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ]; 650 641 # nvidia-uvm is required by CUDA applications. 651 - kernelModules = 652 - lib.optionals config.services.xserver.enable [ 653 - "nvidia" 654 - "nvidia_modeset" 655 - "nvidia_drm" 656 - ] 657 - # With the open driver, nvidia-uvm does not automatically load as 658 - # a softdep of the nvidia module, so we explicitly load it for now. 659 - # See https://github.com/NixOS/nixpkgs/issues/334180 660 - ++ lib.optionals (config.services.xserver.enable && useOpenModules) [ "nvidia_uvm" ]; 642 + kernelModules = lib.optionals config.services.xserver.enable [ 643 + "nvidia" 644 + "nvidia_modeset" 645 + "nvidia_drm" 646 + ]; 661 647 662 648 # If requested enable modesetting via kernel parameters. 663 649 kernelParams =