···343 ];
344345 # 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.
0348 #
349 # Instead, we use `softdep` to lazily load `nvidia-uvm` kernel module
350 # after `nvidia` kernel module is loaded and `udev` rules are applied.
351 extraModprobeConfig = ''
352 softdep nvidia post: nvidia-uvm
353 '';
00000000354 };
355 systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [
356 "L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin"
···639 boot = {
640 extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
641 # 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" ];
652653 # If requested enable modesetting via kernel parameters.
654 kernelParams =
···343 ];
344345 # Don't add `nvidia-uvm` to `kernelModules`, because we want
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
349 #
350 # Instead, we use `softdep` to lazily load `nvidia-uvm` kernel module
351 # after `nvidia` kernel module is loaded and `udev` rules are applied.
352 extraModprobeConfig = ''
353 softdep nvidia post: nvidia-uvm
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" ];
363 };
364 systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [
365 "L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin"
···648 boot = {
649 extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
650 # nvidia-uvm is required by CUDA applications.
651+ kernelModules = lib.optionals config.services.xserver.enable [
652+ "nvidia"
653+ "nvidia_modeset"
654+ "nvidia_drm"
655+ ];
00000656657 # If requested enable modesetting via kernel parameters.
658 kernelParams =