nixos/hardware/nvidia: relax conditions eager loading nvidia-uvm (#398355)

This commit is contained in:
Gaétan Lepage 2025-04-18 01:31:41 +02:00 committed by GitHub
commit b024ced1aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -343,14 +343,23 @@ in
]; ];
# Don't add `nvidia-uvm` to `kernelModules`, because we want # Don't add `nvidia-uvm` to `kernelModules`, because we want
# `nvidia-uvm` be loaded only after `udev` rules for `nvidia` kernel # `nvidia-uvm` be loaded only after the GPU device is available, i.e. after `udev` rules
# module are applied. # 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 # Instead, we use `softdep` to lazily load `nvidia-uvm` kernel module
# after `nvidia` kernel module is loaded and `udev` rules are applied. # after `nvidia` kernel module is loaded and `udev` rules are applied.
extraModprobeConfig = '' extraModprobeConfig = ''
softdep nvidia post: nvidia-uvm 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 [ systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [
"L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin" "L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin"
@ -639,16 +648,11 @@ in
boot = { boot = {
extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ]; extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
# nvidia-uvm is required by CUDA applications. # nvidia-uvm is required by CUDA applications.
kernelModules = kernelModules = lib.optionals config.services.xserver.enable [
lib.optionals config.services.xserver.enable [ "nvidia"
"nvidia" "nvidia_modeset"
"nvidia_modeset" "nvidia_drm"
"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" ];
# If requested enable modesetting via kernel parameters. # If requested enable modesetting via kernel parameters.
kernelParams = kernelParams =