From f1142c5a20ef36b8c26be76c52bce4c0c092a757 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Sat, 14 May 2022 19:34:52 +0800 Subject: [PATCH 1/4] nvidia_x11: vulkan_beta: mark as broken on linux 5.17 --- pkgs/os-specific/linux/nvidia-x11/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/os-specific/linux/nvidia-x11/default.nix b/pkgs/os-specific/linux/nvidia-x11/default.nix index 8e7b3cfa6c8..b888afea66d 100644 --- a/pkgs/os-specific/linux/nvidia-x11/default.nix +++ b/pkgs/os-specific/linux/nvidia-x11/default.nix @@ -46,6 +46,7 @@ rec { settingsSha256 = "sha256-fq6RlD6g3uylvvTjE4MmaQwxPJYU0u6IMfpPVzks0tI="; persistencedSha256 = "sha256-eHvauvh8Wd+b8DK6B3ZWNjoWGztupWrR8iog9ok58io="; url = "https://developer.nvidia.com/vulkan-beta-${lib.concatStrings (lib.splitString "." version)}-linux"; + broken = kernel.kernelAtLeast "5.17"; }; # Update note: From 94f5bd2051f59e9e9cdb3f0db1ad88680370117a Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Thu, 12 May 2022 14:09:32 +0800 Subject: [PATCH 2/4] nvidia_x11: init opensource kernel driver --- nixos/modules/hardware/video/nvidia.nix | 5 +++ pkgs/os-specific/linux/nvidia-x11/builder.sh | 5 +++ pkgs/os-specific/linux/nvidia-x11/default.nix | 6 +-- pkgs/os-specific/linux/nvidia-x11/generic.nix | 8 +++- pkgs/os-specific/linux/nvidia-x11/open.nix | 37 +++++++++++++++++++ pkgs/top-level/linux-kernels.nix | 5 +++ 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 pkgs/os-specific/linux/nvidia-x11/open.nix diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index a9b04bcc859..f93fcb814f6 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -231,6 +231,11 @@ in ); message = "Required files for driver based power management don't exist."; } + + { + assertion = cfg.open -> (cfg.package ? open && cfg.package ? firmware); + message = "This version of NVIDIA driver does not provide a corresponding opensource kernel driver"; + } ]; # If Optimus/PRIME is enabled, we: diff --git a/pkgs/os-specific/linux/nvidia-x11/builder.sh b/pkgs/os-specific/linux/nvidia-x11/builder.sh index 75eb5d8757b..da41837cfc2 100755 --- a/pkgs/os-specific/linux/nvidia-x11/builder.sh +++ b/pkgs/os-specific/linux/nvidia-x11/builder.sh @@ -147,6 +147,11 @@ installPhase() { fi fi + if [ -n "$firmware" ]; then + # Install the GSP firmware + install -Dm644 firmware/gsp.bin $firmware/lib/firmware/nvidia/$version/gsp.bin + fi + # All libs except GUI-only are installed now, so fixup them. for libname in $(find "$out/lib/" $(test -n "$lib32" && echo "$lib32/lib/") $(test -n "$bin" && echo "$bin/lib/") -name '*.so.*') do diff --git a/pkgs/os-specific/linux/nvidia-x11/default.nix b/pkgs/os-specific/linux/nvidia-x11/default.nix index b888afea66d..4577a33e1be 100644 --- a/pkgs/os-specific/linux/nvidia-x11/default.nix +++ b/pkgs/os-specific/linux/nvidia-x11/default.nix @@ -3,9 +3,7 @@ let generic = args: let imported = import ./generic.nix args; - in if lib.versionAtLeast args.version "391" - && stdenv.hostPlatform.system != "x86_64-linux" then null - else callPackage imported { + in callPackage imported { lib32 = (pkgsi686Linux.callPackage imported { libsOnly = true; kernel = null; @@ -21,6 +19,7 @@ rec { then generic { version = "515.48.07"; sha256_64bit = "sha256-4odkzFsTwy52NwUT2ur8BcKJt37gURVSRQ8aAOMa4eM="; + openSha256 = "sha256-EGIrdabPr+AhQxXhFb8XXumuPxC+U6XEeIeSYFvA/q4="; settingsSha256 = "sha256-XwdMsAAu5132x2ZHqjtFvcBJk6Dao7I86UksxrOkknU="; persistencedSha256 = "sha256-BTfYNDJKe4tOvV71/1JJSPltJua0Mx/RvDcWT5ccRRY="; } @@ -32,6 +31,7 @@ rec { beta = generic { version = "515.43.04"; sha256_64bit = "sha256-PodaTTUOSyMW8rtdtabIkSLskgzAymQyfToNlwxPPcc="; + openSha256 = "sha256-1bAr5dWZ4jnY3Uo2JaEz/rhw2HuW9LZ5bACmA1VG068="; settingsSha256 = "sha256-j47LtP6FNTPfiXFh9KwXX8vZOQzlytA30ZfW9N5F2PY="; persistencedSha256 = "sha256-hULBy0wnVpLH8I0L6O9/HfgvJURtE2whpXOgN/vb3Wo="; }; diff --git a/pkgs/os-specific/linux/nvidia-x11/generic.nix b/pkgs/os-specific/linux/nvidia-x11/generic.nix index bc867d8b82b..768d4179111 100644 --- a/pkgs/os-specific/linux/nvidia-x11/generic.nix +++ b/pkgs/os-specific/linux/nvidia-x11/generic.nix @@ -2,6 +2,7 @@ , url ? null , sha256_32bit ? null , sha256_64bit +, openSha256 ? null , settingsSha256 , settingsVersion ? version , persistencedSha256 @@ -27,13 +28,14 @@ disable32Bit ? false # 32 bit libs only version of this package , lib32 ? null + # Whether to extract the GSP firmware +, firmware ? openSha256 != null }: with lib; assert !libsOnly -> kernel != null; assert versionOlder version "391" -> sha256_32bit != null; -assert versionAtLeast version "391" -> stdenv.hostPlatform.system == "x86_64-linux"; let nameSuffix = optionalString (!libsOnly) "-${kernel.version}"; @@ -72,7 +74,8 @@ let outputs = [ "out" ] ++ optional i686bundled "lib32" - ++ optional (!libsOnly) "bin"; + ++ optional (!libsOnly) "bin" + ++ optional (!libsOnly && firmware) "firmware"; outputDev = if libsOnly then null else "bin"; kernel = if libsOnly then null else kernel.dev; @@ -100,6 +103,7 @@ let disallowedReferences = optional (!libsOnly) [ kernel.dev ]; passthru = { + open = mapNullable (hash: callPackage (import ./open.nix self hash) { }) openSha256; settings = (if settings32Bit then pkgsi686Linux.callPackage else callPackage) (import ./settings.nix self settingsSha256) { withGtk2 = preferGtk2; withGtk3 = !preferGtk2; diff --git a/pkgs/os-specific/linux/nvidia-x11/open.nix b/pkgs/os-specific/linux/nvidia-x11/open.nix new file mode 100644 index 00000000000..18b699221ef --- /dev/null +++ b/pkgs/os-specific/linux/nvidia-x11/open.nix @@ -0,0 +1,37 @@ +nvidia_x11: hash: +{ stdenv +, lib +, fetchFromGitHub +, kernel +}: + +stdenv.mkDerivation { + pname = "nvidia-open"; + version = "${kernel.version}-${nvidia_x11.version}"; + + src = fetchFromGitHub { + owner = "NVIDIA"; + repo = "open-gpu-kernel-modules"; + rev = nvidia_x11.version; + inherit hash; + }; + + nativeBuildInputs = kernel.moduleBuildDependencies; + + makeFlags = kernel.makeFlags ++ [ + "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" + "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + "MODLIB=$(out)/lib/modules/${kernel.modDirVersion}" + ]; + + installTargets = [ "modules_install" ]; + enableParallelBuilding = true; + + meta = with lib; { + description = "NVIDIA Linux Open GPU Kernel Module"; + homepage = "https://github.com/NVIDIA/open-gpu-kernel-modules"; + license = with licenses; [ gpl2Plus mit ]; + platforms = platforms.linux; + maintainers = with maintainers; [ nickcao ]; + }; +} diff --git a/pkgs/top-level/linux-kernels.nix b/pkgs/top-level/linux-kernels.nix index 2f53fc73874..fc32465fd65 100644 --- a/pkgs/top-level/linux-kernels.nix +++ b/pkgs/top-level/linux-kernels.nix @@ -356,6 +356,11 @@ in { nvidia_x11_vulkan_beta = nvidiaPackages.vulkan_beta; nvidia_x11 = nvidiaPackages.stable; + # this is not a replacement for nvidia_x11 + # only the opensource kernel driver exposed for hydra to build + nvidia_x11_open = nvidiaPackages.stable.open; + nvidia_x11_beta_open = nvidiaPackages.beta.open; + openrazer = callPackage ../os-specific/linux/openrazer/driver.nix { }; ply = callPackage ../os-specific/linux/ply { }; From e84828b973364de21a18a9bab50e9399abdd7e43 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Wed, 1 Jun 2022 10:14:45 +0800 Subject: [PATCH 3/4] nixos/nvidia: add option hardware.nvidia.open for selecting the opensource kernel driver --- .../from_md/release-notes/rl-2211.section.xml | 12 ++++++++++++ nixos/doc/manual/release-notes/rl-2211.section.md | 2 ++ nixos/modules/hardware/video/nvidia.nix | 14 ++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml index b0a84de57e0..b6cda1b0f0b 100644 --- a/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml +++ b/nixos/doc/manual/from_md/release-notes/rl-2211.section.xml @@ -36,6 +36,18 @@ PHP now defaults to PHP 8.1, updated from 8.0. + + + hardware.nvidia has a new option + open that can be used to opt in the + opensource version of NVIDIA kernel driver. Note that the + driver’s support for GeForce and Workstation GPUs is still + alpha quality, see + NVIDIA + Releases Open-Source GPU Kernel Modules for the + official announcement. + +
diff --git a/nixos/doc/manual/release-notes/rl-2211.section.md b/nixos/doc/manual/release-notes/rl-2211.section.md index acad456a4fd..a6abab00f53 100644 --- a/nixos/doc/manual/release-notes/rl-2211.section.md +++ b/nixos/doc/manual/release-notes/rl-2211.section.md @@ -19,6 +19,8 @@ In addition to numerous new and upgraded packages, this release has the followin - PHP now defaults to PHP 8.1, updated from 8.0. +- `hardware.nvidia` has a new option `open` that can be used to opt in the opensource version of NVIDIA kernel driver. Note that the driver's support for GeForce and Workstation GPUs is still alpha quality, see [NVIDIA Releases Open-Source GPU Kernel Modules](https://developer.nvidia.com/blog/nvidia-releases-open-source-gpu-kernel-modules/) for the official announcement. + ## New Services {#sec-release-22.11-new-services} diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index f93fcb814f6..b4717719661 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -183,6 +183,14 @@ in ''; example = literalExpression "config.boot.kernelPackages.nvidiaPackages.legacy_340"; }; + + hardware.nvidia.open = lib.mkOption { + type = lib.types.bool; + default = false; + description = '' + Whether to use the open source kernel module + ''; + }; }; config = let @@ -369,7 +377,8 @@ in ++ optional (nvidia_x11.persistenced != null && config.virtualisation.docker.enableNvidia) "L+ /run/nvidia-docker/extras/bin/nvidia-persistenced - - - - ${nvidia_x11.persistenced}/origBin/nvidia-persistenced"; - boot.extraModulePackages = [ nvidia_x11.bin ]; + boot.extraModulePackages = if cfg.open then [ nvidia_x11.open ] else [ nvidia_x11.bin ]; + hardware.firmware = lib.optional cfg.open nvidia_x11.firmware; # nvidia-uvm is required by CUDA applications. boot.kernelModules = [ "nvidia-uvm" ] ++ @@ -377,7 +386,8 @@ in # If requested enable modesetting via kernel parameter. boot.kernelParams = optional (offloadCfg.enable || cfg.modesetting.enable) "nvidia-drm.modeset=1" - ++ optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1"; + ++ optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1" + ++ optional cfg.open "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1"; services.udev.extraRules = '' From 6959d265b8c9cca53a9f5dafd435afec242d2c62 Mon Sep 17 00:00:00 2001 From: Nick Cao Date: Fri, 3 Jun 2022 12:17:15 +0800 Subject: [PATCH 4/4] linuxPackages.nvidia_x11_open: remove temporarily due to evaluation issues --- pkgs/top-level/linux-kernels.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/top-level/linux-kernels.nix b/pkgs/top-level/linux-kernels.nix index fc32465fd65..5a9098d6db4 100644 --- a/pkgs/top-level/linux-kernels.nix +++ b/pkgs/top-level/linux-kernels.nix @@ -358,7 +358,6 @@ in { # this is not a replacement for nvidia_x11 # only the opensource kernel driver exposed for hydra to build - nvidia_x11_open = nvidiaPackages.stable.open; nvidia_x11_beta_open = nvidiaPackages.beta.open; openrazer = callPackage ../os-specific/linux/openrazer/driver.nix { };