Skip to content

Commit b024ced

Browse files
authored
nixos/hardware/nvidia: relax conditions eager loading nvidia-uvm (NixOS#398355)
2 parents cb73a81 + 419e4d1 commit b024ced

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

nixos/modules/hardware/video/nvidia.nix

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,23 @@ in
343343
];
344344

345345
# 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
348349
#
349350
# Instead, we use `softdep` to lazily load `nvidia-uvm` kernel module
350351
# after `nvidia` kernel module is loaded and `udev` rules are applied.
351352
extraModprobeConfig = ''
352353
softdep nvidia post: nvidia-uvm
353354
'';
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" ];
354363
};
355364
systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [
356365
"L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin"
@@ -639,16 +648,11 @@ in
639648
boot = {
640649
extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
641650
# nvidia-uvm is required by CUDA applications.
642-
kernelModules =
643-
lib.optionals config.services.xserver.enable [
644-
"nvidia"
645-
"nvidia_modeset"
646-
"nvidia_drm"
647-
]
648-
# With the open driver, nvidia-uvm does not automatically load as
649-
# a softdep of the nvidia module, so we explicitly load it for now.
650-
# See https://github.com/NixOS/nixpkgs/issues/334180
651-
++ lib.optionals (config.services.xserver.enable && useOpenModules) [ "nvidia_uvm" ];
651+
kernelModules = lib.optionals config.services.xserver.enable [
652+
"nvidia"
653+
"nvidia_modeset"
654+
"nvidia_drm"
655+
];
652656

653657
# If requested enable modesetting via kernel parameters.
654658
kernelParams =

0 commit comments

Comments
 (0)