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>
This commit is contained in:
Gaetan Lepage 2025-04-13 15:06:30 +02:00
parent 9fb5d292ba
commit 419e4d1822

View file

@ -343,14 +343,23 @@ in
];
# Don't add `nvidia-uvm` to `kernelModules`, because we want
# `nvidia-uvm` be loaded only after `udev` rules for `nvidia` kernel
# module are applied.
# `nvidia-uvm` be loaded only after the GPU device is available, i.e. after `udev` rules
# for `nvidia` kernel module are applied.
# This matters on Azure GPU instances: https://github.com/NixOS/nixpkgs/pull/267335
#
# Instead, we use `softdep` to lazily load `nvidia-uvm` kernel module
# after `nvidia` kernel module is loaded and `udev` rules are applied.
extraModprobeConfig = ''
softdep nvidia post: nvidia-uvm
'';
# Exception is the open-source kernel module failing to load nvidia-uvm using softdep
# for unknown reasons.
# It affects CUDA: https://github.com/NixOS/nixpkgs/issues/334180
# Previously nvidia-uvm was explicitly loaded only when xserver was enabled:
# https://github.com/NixOS/nixpkgs/pull/334340/commits/4548c392862115359e50860bcf658cfa8715bde9
# We are now loading the module eagerly for all users of the open driver (including headless).
kernelModules = lib.optionals useOpenModules [ "nvidia_uvm" ];
};
systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [
"L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin"
@ -639,16 +648,11 @@ in
boot = {
extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
# nvidia-uvm is required by CUDA applications.
kernelModules =
lib.optionals config.services.xserver.enable [
"nvidia"
"nvidia_modeset"
"nvidia_drm"
]
# With the open driver, nvidia-uvm does not automatically load as
# a softdep of the nvidia module, so we explicitly load it for now.
# See https://github.com/NixOS/nixpkgs/issues/334180
++ lib.optionals (config.services.xserver.enable && useOpenModules) [ "nvidia_uvm" ];
kernelModules = lib.optionals config.services.xserver.enable [
"nvidia"
"nvidia_modeset"
"nvidia_drm"
];
# If requested enable modesetting via kernel parameters.
kernelParams =