···343343 ];
344344345345 # Don't add `nvidia-uvm` to `kernelModules`, because we want
346346- # `nvidia-uvm` be loaded only after `udev` rules for `nvidia` kernel
347347- # module are applied.
346346+ # `nvidia-uvm` be loaded only after the GPU device is available, i.e. after `udev` rules
347347+ # for `nvidia` kernel module are applied.
348348+ # 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 '';
355355+356356+ # Exception is the open-source kernel module failing to load nvidia-uvm using softdep
357357+ # for unknown reasons.
358358+ # It affects CUDA: https://github.com/NixOS/nixpkgs/issues/334180
359359+ # Previously nvidia-uvm was explicitly loaded only when xserver was enabled:
360360+ # https://github.com/NixOS/nixpkgs/pull/334340/commits/4548c392862115359e50860bcf658cfa8715bde9
361361+ # We are now loading the module eagerly for all users of the open driver (including headless).
362362+ 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"
···639648 boot = {
640649 extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
641650 # nvidia-uvm is required by CUDA applications.
642642- kernelModules =
643643- lib.optionals config.services.xserver.enable [
644644- "nvidia"
645645- "nvidia_modeset"
646646- "nvidia_drm"
647647- ]
648648- # With the open driver, nvidia-uvm does not automatically load as
649649- # a softdep of the nvidia module, so we explicitly load it for now.
650650- # See https://github.com/NixOS/nixpkgs/issues/334180
651651- ++ lib.optionals (config.services.xserver.enable && useOpenModules) [ "nvidia_uvm" ];
651651+ kernelModules = lib.optionals config.services.xserver.enable [
652652+ "nvidia"
653653+ "nvidia_modeset"
654654+ "nvidia_drm"
655655+ ];
652656653657 # If requested enable modesetting via kernel parameters.
654658 kernelParams =