Skip to content

Commit

Permalink
nixos/nvidia: make the nvidia driver variant a mandatory user choice
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiskae committed Aug 25, 2024
1 parent 8b52dae commit fbff9be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2411.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
Processes also now run as a dynamically allocated user by default instead of
root.

- The nvidia driver no longer defaults to the proprietary driver starting with version 560. You will need to manually set `hardware.nvidia.open` to select the proprietary or open driver.

- `singularity-tools` have the `storeDir` argument removed from its override interface and use `builtins.storeDir` instead.

- Two build helpers in `singularity-tools`, i.e., `mkLayer` and `shellScript`, are deprecated, as they are no longer involved in image-building. Maintainers will remove them in future releases.
Expand Down
32 changes: 21 additions & 11 deletions nixos/modules/hardware/video/nvidia.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let
busIDType = lib.types.strMatching "([[:print:]]+[\:\@][0-9]{1,3}\:[0-9]{1,2}\:[0-9])?";
ibtSupport = cfg.open || (nvidia_x11.ibtSupport or false);
settingsFormat = pkgs.formats.keyValue { };
isOpen = cfg.open == true;
in
{
options = {
Expand Down Expand Up @@ -254,10 +255,14 @@ in
'';
};

open = lib.mkEnableOption ''
the open source NVIDIA kernel module
'' // {
defaultText = lib.literalExpression ''lib.versionAtLeast config.hardware.nvidia.package.version "560"'';
open = lib.mkOption {
default = null;
example = true;
description = "Whether to enable the open source NVIDIA kernel module.";
type = lib.types.nullOr lib.types.bool;
defaultText = lib.literalExpression ''
if lib.versionOlder config.hardware.nvidia.package.version "560"' then false else null
'';
};
};
};
Expand Down Expand Up @@ -308,7 +313,7 @@ in
};
environment.systemPackages = [ nvidia_x11.bin ];

hardware.nvidia.open = lib.mkDefault (lib.versionAtLeast nvidia_x11.version "560");
hardware.nvidia.open = lib.mkIf (lib.versionAtLeast nvidia_x11.version "560") (lib.mkDefault false);
})

# X11
Expand Down Expand Up @@ -367,8 +372,13 @@ in
}

{
assertion = cfg.open -> (cfg.package ? open && cfg.package ? firmware);
message = "This version of NVIDIA driver does not provide a corresponding opensource kernel driver";
assertion = isOpen -> (cfg.package ? open && cfg.package ? firmware);
message = "This version of NVIDIA driver does not provide a corresponding opensource kernel driver.";
}

{
assertion = cfg.open != null;
message = "You must specify which variant of the nvidia kernel driver to use.";
}

{
Expand Down Expand Up @@ -555,7 +565,7 @@ in

services.dbus.packages = lib.optional cfg.dynamicBoost.enable nvidia_x11.bin;

hardware.firmware = lib.optional (cfg.open || lib.versionAtLeast nvidia_x11.version "555") nvidia_x11.firmware;
hardware.firmware = lib.optional (isOpen || lib.versionAtLeast nvidia_x11.version "555") nvidia_x11.firmware;

systemd.tmpfiles.rules =
[
Expand All @@ -570,7 +580,7 @@ in
"L+ /run/nvidia-docker/extras/bin/nvidia-persistenced - - - - ${nvidia_x11.persistenced}/origBin/nvidia-persistenced";

boot = {
extraModulePackages = if cfg.open then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
extraModulePackages = if isOpen then [ nvidia_x11.open ] else [ nvidia_x11.bin ];
# nvidia-uvm is required by CUDA applications.
kernelModules =
lib.optionals config.services.xserver.enable [
Expand All @@ -581,14 +591,14 @@ in
# 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 && cfg.open) [ "nvidia_uvm" ];
++ lib.optionals (config.services.xserver.enable && isOpen) [ "nvidia_uvm" ];

# If requested enable modesetting via kernel parameters.
kernelParams =
lib.optional (offloadCfg.enable || cfg.modesetting.enable) "nvidia-drm.modeset=1"
++ lib.optional ((offloadCfg.enable || cfg.modesetting.enable) && lib.versionAtLeast nvidia_x11.version "545") "nvidia-drm.fbdev=1"
++ lib.optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1"
++ lib.optional cfg.open "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1"
++ lib.optional isOpen "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1"
++ lib.optional (config.boot.kernelPackages.kernel.kernelAtLeast "6.2" && !ibtSupport) "ibt=off";

# enable finegrained power management
Expand Down

0 comments on commit fbff9be

Please sign in to comment.