diff --git a/doc/release-notes/rl-2605.section.md b/doc/release-notes/rl-2605.section.md index 697129906711..9ce8921e827d 100644 --- a/doc/release-notes/rl-2605.section.md +++ b/doc/release-notes/rl-2605.section.md @@ -284,6 +284,10 @@ +- `nvidia-x11` proprietary kernel modules are now provided separately as `nvidia_x11.mod`, while `nvidia_x11.open` remains the open-source kernel module package. + +- `linuxPackages.nvidiaPackages` now follows NVIDIA's official release branches by exposing `production`, `new_feature`, and `beta`. The convenience aliases `latest` (newer of `production` and `new_feature`) and `bleeding_edge` (newer of `latest` and `beta`) are provided; note that `beta` now refers strictly to the beta branch. + - `balatro` now supports the Google Play and Xbox PC versions of the game. Pass the `apk` or `Assets.zip` as `balatro.override { src = "…" }`. - `uptime-kuma` has been updated to v2, which requires an automated migration that can take a few hours. **A backup is highly recommended.** diff --git a/nixos/doc/manual/release-notes/rl-2605.section.md b/nixos/doc/manual/release-notes/rl-2605.section.md index 6d73d66d0d17..b56561170344 100644 --- a/nixos/doc/manual/release-notes/rl-2605.section.md +++ b/nixos/doc/manual/release-notes/rl-2605.section.md @@ -336,6 +336,14 @@ See . +- [`hardware.nvidia.branch`](#opt-hardware.nvidia.branch) was added to select the NVIDIA driver branch; setting [`hardware.nvidia.package`](#opt-hardware.nvidia.package) overrides this. + +- The NixOS NVIDIA module wiring has been updated to match the new `nvidia-x11` output layout. + +- `nixos/nvidia` now uses EGL external platform ICD libraries built from source (`egl-gbm`, `egl-wayland`, `egl-wayland2`, `egl-x11`) instead of relying on vendor-provided binaries for these components. + +- `hardware.nvidia.moduleParams` was added to configure NVIDIA kernel module parameters declaratively. These parameters are now written to `modprobe` configuration instead of being passed through global kernel command-line parameters. + - [hardware.xpadneo](#opt-hardware.xpadneo.enable) now supports configuring kernel module parameters via a freeform [settings](#opt-hardware.xpadneo.settings) option, with convenience options for [rumble attenuation](#opt-hardware.xpadneo.rumbleAttenuation) and [controller quirks](#opt-hardware.xpadneo.quirks). - Wine has been updated to the 11.0 branch. Please check the [upstream announcement](https://gitlab.winehq.org/wine/wine/-/releases/wine-11.0) for more details. diff --git a/nixos/modules/hardware/video/bumblebee.nix b/nixos/modules/hardware/video/bumblebee.nix index fca939797b69..3aebc4a800f5 100644 --- a/nixos/modules/hardware/video/bumblebee.nix +++ b/nixos/modules/hardware/video/bumblebee.nix @@ -93,7 +93,10 @@ in ]; boot.kernelModules = lib.optional useBbswitch "bbswitch"; boot.extraModulePackages = - lib.optional useBbswitch kernel.bbswitch ++ lib.optional useNvidia kernel.nvidia_x11.bin; + lib.optional useBbswitch kernel.bbswitch + ++ lib.optional useNvidia ( + if config.hardware.nvidia.open == true then kernel.nvidia_x11.open else kernel.nvidia_x11.mod + ); environment.systemPackages = [ bumblebee diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index cef902557555..dc3d6cb134f7 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -6,10 +6,12 @@ }: let nvidiaEnabled = lib.elem "nvidia" config.services.xserver.videoDrivers; - nvidia_x11 = if nvidiaEnabled || cfg.datacenter.enable then cfg.package else null; + nvidia_x11 = if cfg.enabled then cfg.package else null; cfg = config.hardware.nvidia; + inherit (config.boot.kernelPackages) nvidiaPackages; + useOpenModules = cfg.open == true; pCfg = cfg.prime; @@ -27,7 +29,7 @@ in enabled = lib.mkOption { readOnly = true; type = lib.types.bool; - default = nvidia_x11 != null; + default = nvidiaEnabled || cfg.datacenter.enable; defaultText = lib.literalMD "`true` if NVIDIA support is enabled"; description = "True if NVIDIA support is enabled"; }; @@ -296,15 +298,63 @@ in It also drastically increases the time the driver needs to clock down after load ''; - package = lib.mkOption { - default = - config.boot.kernelPackages.nvidiaPackages."${if cfg.datacenter.enable then "dc" else "stable"}"; + branch = lib.mkOption { + type = + (lib.types.enum (builtins.attrNames (lib.filterAttrs (_: lib.isDerivation) nvidiaPackages))) + // { + description = "one of the available driver branches in `pkgs/os-specific/linux/nvidia-x11/default.nix`"; + }; + default = if cfg.datacenter.enable then "dc" else "stable"; defaultText = lib.literalExpression '' - config.boot.kernelPackages.nvidiaPackages."\$\{if cfg.datacenter.enable then "dc" else "stable"}" + if config.hardware.nvidia.datacenter.enable then "dc" else "stable" ''; - example = "config.boot.kernelPackages.nvidiaPackages.legacy_470"; + example = "bleeding_edge"; + description = '' + The branch of the NVIDIA driver to use. + + Note: if {option}`hardware.nvidia.package` is set, it overrides this option. + + Commonly interesting branches for end users: + + - production, new_feature, beta: + NVIDIA's official production / new feature / beta release branches. + + - stable: + The default; the highest stable version. + + - latest: + Whichever is newer of `production` and `new_feature`. + + - bleeding_edge: + Whichever is newer of `latest` and `beta`. + + - legacy_580: + The long-lived 580 series (LTSB), for GPUs that newer driver branches + no longer support (often Maxwell through Volta; roughly GeForce GTX 9xx + through 10xx, plus rare Volta cards like TITAN V). + + - vulkan_beta: + The Vulkan developer beta driver, for users interested in testing new + Vulkan features. + ''; + }; + + package = lib.mkOption { + type = lib.types.package; + default = nvidiaPackages.${cfg.branch}; + defaultText = lib.literalExpression "config.boot.kernelPackages.nvidiaPackages.\${config.hardware.nvidia.branch}"; + example = lib.literalExpression "config.boot.kernelPackages.nvidiaPackages.legacy_470"; description = '' The NVIDIA driver package to use. + + Prefer using {option}`hardware.nvidia.branch` when possible. + + If you set this option, it is recommended to pick a package from + `config.boot.kernelPackages.nvidiaPackages` so the driver build matches + your configured kernel. + + For custom versions, you can use `nvidiaPackages.mkDriver`; see + `pkgs/os-specific/linux/nvidia-x11/default.nix` for examples. ''; }; @@ -332,6 +382,20 @@ in videoAcceleration = lib.mkEnableOption "video acceleration (VA-API)" // { default = true; }; + + moduleParams = lib.mkOption { + type = lib.types.attrsOf (lib.types.attrsOf lib.types.raw); + default = { }; + example = '' + { + nvidia = { + NVreg_UsePageAttributeTable = 1; + NVreg_RegistryDwords = "EnableBrightnessControl=1" + }; + } + ''; + description = "Additional parameters to pass to the NVIDIA kernel module."; + }; }; }; @@ -401,10 +465,52 @@ in KERNEL=="nvidia_uvm", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia-uvm c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 0'" KERNEL=="nvidia_uvm", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidia-uvm-tools c $$(grep nvidia-uvm /proc/devices | cut -d \ -f 1) 1'" ''; - hardware.graphics = { - extraPackages = [ nvidia_x11.out ]; - extraPackages32 = [ nvidia_x11.lib32 ]; - }; + hardware.graphics = + let + icd = [ + "egl-wayland" + ] + # GBM support was added in 495. + ++ lib.optionals (lib.versionAtLeast nvidia_x11.version "495") [ + "egl-gbm" + ] + # ICDs below use a new driver interface, which is added in the 560 series drivers. + ++ lib.optionals (lib.versionAtLeast nvidia_x11.version "560") [ + "egl-wayland2" + "egl-x11" + ]; + combineIcdPkgs = + icd: pkgs: + pkgs.symlinkJoin { + name = "nvidia-egl-external-platforms${lib.optionalString pkgs.stdenv.is32bit "-x32"}"; + paths = lib.attrVals icd pkgs; + # Remediate reversed priorities in pre-595 drivers, + # https://github.com/NixOS/nixpkgs/pull/497342#issuecomment-4034876793 + postBuild = lib.optionalString (lib.versionOlder nvidia_x11.version "595") '' + pushd $out/share/egl/egl_external_platform.d + for f in [0-9][0-9]_*; do + num=''${f:0:2} + rest=''${f:2} + new=$(printf "%02d" $((99 - 10#$num))) + mv -- "$f" "tmp-$new$rest" + done + for f in tmp-*; do + mv -- "$f" "''${f#tmp-}" + done + popd + ''; + }; + in + { + extraPackages = [ + nvidia_x11.out + (combineIcdPkgs icd pkgs) + ]; + extraPackages32 = [ + nvidia_x11.lib32 + (combineIcdPkgs icd pkgs.pkgsi686Linux) + ]; + }; environment.systemPackages = [ nvidia_x11.bin ]; } @@ -489,6 +595,17 @@ in -> (useOpenModules && lib.versionAtLeast nvidia_x11.version "595"); message = "NVIDIA driver support for kernel suspend notifiers requires NVIDIA driver version 595 or newer, and the open source kernel modules."; } + + { + assertion = + removeAttrs cfg.moduleParams [ + "nvidia" + "nvidia-drm" + "nvidia-modeset" + "nvidia-uvm" + ] == { }; + message = "You can only use `hardware.nvidia.moduleParams` to set parameters for the kernel modules of NVIDIA drivers."; + } ]; # If Optimus/PRIME is enabled, we: @@ -680,8 +797,25 @@ in lib.optional (nvidia_x11.persistenced != null && config.virtualisation.docker.enableNvidia) "L+ /run/nvidia-docker/extras/bin/nvidia-persistenced - - - - ${nvidia_x11.persistenced}/origBin/nvidia-persistenced"; + hardware.nvidia.moduleParams = lib.mkMerge ( + 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 && cfg.powerManagement.kernelSuspendNotifier) { + nvidia.NVreg_UseKernelSuspendNotifiers = 1; + } + ++ lib.optional cfg.powerManagement.enable { nvidia.NVreg_PreserveVideoMemoryAllocations = 1; } + ++ lib.optional ( + useOpenModules + && lib.versionAtLeast nvidia_x11.version "515.43.04" + && lib.versionOlder nvidia_x11.version "545.23.06" + ) { nvidia.NVreg_OpenRmEnableUnsupportedGpus = 1; } + ++ lib.optional cfg.powerManagement.finegrained { nvidia.NVreg_DynamicPowerManagement = "0x02"; } + ); + boot = { - extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.bin ]; + extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.mod ]; # nvidia-uvm is required by CUDA applications. kernelModules = lib.optionals config.services.xserver.enable [ "nvidia" @@ -689,27 +823,16 @@ in "nvidia_drm" ]; - # 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 && cfg.powerManagement.kernelSuspendNotifier - ) "nvidia.NVreg_UseKernelSuspendNotifiers=1" - ++ lib.optional cfg.powerManagement.enable "nvidia.NVreg_PreserveVideoMemoryAllocations=1" - ++ lib.optional ( - useOpenModules - && lib.versionAtLeast nvidia_x11.version "515.43.04" - && lib.versionOlder nvidia_x11.version "545.23.06" - ) "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1" - ++ lib.optional (config.boot.kernelPackages.kernel.kernelAtLeast "6.2" && !ibtSupport) "ibt=off"; + kernelParams = lib.optional ( + config.boot.kernelPackages.kernel.kernelAtLeast "6.2" && !ibtSupport + ) "ibt=off"; - # enable finegrained power management - extraModprobeConfig = lib.optionalString cfg.powerManagement.finegrained '' - options nvidia "NVreg_DynamicPowerManagement=0x02" - ''; + extraModprobeConfig = + let + mergeParams = lib.concatMapAttrsStringSep " " (k: v: "${k}=${toString v}"); + genModprobeLine = module: params: "options ${module} ${mergeParams params}"; + in + lib.concatMapAttrsStringSep "\n" genModprobeLine cfg.moduleParams; }; services.udev.extraRules = lib.optionalString cfg.powerManagement.finegrained ( lib.optionalString (lib.versionOlder config.boot.kernelPackages.kernel.version "5.5") '' @@ -735,7 +858,7 @@ in }) # Data Center (lib.mkIf (cfg.datacenter.enable) { - boot.extraModulePackages = [ nvidia_x11.bin ]; + boot.extraModulePackages = if useOpenModules then [ nvidia_x11.open ] else [ nvidia_x11.mod ]; systemd = { tmpfiles.rules = diff --git a/pkgs/by-name/eg/egl-gbm/package.nix b/pkgs/by-name/eg/egl-gbm/package.nix new file mode 100644 index 000000000000..bda8f607105a --- /dev/null +++ b/pkgs/by-name/eg/egl-gbm/package.nix @@ -0,0 +1,59 @@ +{ + lib, + stdenv, + fetchFromGitHub, + eglexternalplatform, + pkg-config, + meson, + ninja, + libGL, + libgbm, + libdrm, + nix-update-script, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "egl-gbm"; + version = "1.1.3"; + + src = fetchFromGitHub { + owner = "NVIDIA"; + repo = "egl-gbm"; + tag = finalAttrs.version; + hash = "sha256-OoHgvFbyd6JakSKyN7N97FMJHNYV1spj7zy3f1g/PN0="; + }; + + depsBuildBuild = [ + pkg-config + ]; + + nativeBuildInputs = [ + meson + ninja + pkg-config + ]; + + buildInputs = [ + libGL + libgbm + libdrm + eglexternalplatform + ]; + + absolutizeEglExternalPlatformIcdJson = true; + + strictDeps = true; + __structuredAttrs = true; + + passthru.updateScript = nix-update-script { extraArgs = [ "--use-github-releases" ]; }; + + meta = { + description = "GBM EGL external platform library"; + homepage = "https://github.com/NVIDIA/egl-gbm/"; + license = lib.licenses.mit; + platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ + ccicnce113424 + ]; + }; +}) diff --git a/pkgs/by-name/eg/egl-wayland/package.nix b/pkgs/by-name/eg/egl-wayland/package.nix index acf88b480295..c16988d026a0 100644 --- a/pkgs/by-name/eg/egl-wayland/package.nix +++ b/pkgs/by-name/eg/egl-wayland/package.nix @@ -8,10 +8,10 @@ ninja, wayland-scanner, libGL, - libx11, libdrm, wayland, wayland-protocols, + nix-update-script, }: stdenv.mkDerivation (finalAttrs: { @@ -24,9 +24,9 @@ stdenv.mkDerivation (finalAttrs: { ]; src = fetchFromGitHub { - owner = "Nvidia"; + owner = "NVIDIA"; repo = "egl-wayland"; - rev = finalAttrs.version; + tag = finalAttrs.version; hash = "sha256-a98DzmzCG6DlLJ1HCl/LeD21Q7yyNbTce1poOoAnTjA="; }; @@ -49,7 +49,6 @@ stdenv.mkDerivation (finalAttrs: { buildInputs = [ libGL - libx11 libdrm wayland wayland-protocols @@ -59,11 +58,21 @@ stdenv.mkDerivation (finalAttrs: { eglexternalplatform ]; + absolutizeEglExternalPlatformIcdJson = true; + + strictDeps = true; + __structuredAttrs = true; + + passthru.updateScript = nix-update-script { extraArgs = [ "--use-github-releases" ]; }; + meta = { description = "EGLStream-based Wayland external platform"; homepage = "https://github.com/NVIDIA/egl-wayland/"; license = lib.licenses.mit; platforms = lib.platforms.linux ++ lib.platforms.freebsd; - maintainers = with lib.maintainers; [ hedning ]; + maintainers = with lib.maintainers; [ + hedning + ccicnce113424 + ]; }; }) diff --git a/pkgs/by-name/eg/egl-wayland2/package.nix b/pkgs/by-name/eg/egl-wayland2/package.nix new file mode 100644 index 000000000000..5af0b014e10a --- /dev/null +++ b/pkgs/by-name/eg/egl-wayland2/package.nix @@ -0,0 +1,66 @@ +{ + lib, + stdenv, + fetchFromGitHub, + eglexternalplatform, + pkg-config, + meson, + ninja, + wayland-scanner, + libGL, + libgbm, + libdrm, + wayland, + wayland-protocols, + nix-update-script, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "egl-wayland2"; + version = "1.0.1"; + + src = fetchFromGitHub { + owner = "NVIDIA"; + repo = "egl-wayland2"; + tag = "v${finalAttrs.version}"; + hash = "sha256-Udr+tihx/Si2ynFyM1FW2CIUgTg9SQn7AgrOPpGTxpY="; + }; + + depsBuildBuild = [ + pkg-config + ]; + + nativeBuildInputs = [ + meson + ninja + pkg-config + wayland-scanner + ]; + + buildInputs = [ + libGL + libgbm + libdrm + wayland + wayland-protocols + eglexternalplatform + ]; + + absolutizeEglExternalPlatformIcdJson = true; + + strictDeps = true; + __structuredAttrs = true; + + passthru.updateScript = nix-update-script { extraArgs = [ "--use-github-releases" ]; }; + + meta = { + description = "Dma-buf-based Wayland external platform library"; + homepage = "https://github.com/NVIDIA/egl-wayland2/"; + license = lib.licenses.asl20; + platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ + vancluever + ccicnce113424 + ]; + }; +}) diff --git a/pkgs/by-name/eg/egl-x11/package.nix b/pkgs/by-name/eg/egl-x11/package.nix new file mode 100644 index 000000000000..28b5a8474e56 --- /dev/null +++ b/pkgs/by-name/eg/egl-x11/package.nix @@ -0,0 +1,63 @@ +{ + lib, + stdenv, + fetchFromGitHub, + eglexternalplatform, + pkg-config, + meson, + ninja, + libGL, + libgbm, + libdrm, + libx11, + libxcb, + nix-update-script, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "egl-x11"; + version = "1.0.5"; + + src = fetchFromGitHub { + owner = "NVIDIA"; + repo = "egl-x11"; + tag = "v${finalAttrs.version}"; + hash = "sha256-Sl/qc39H29wXsb5UYKGK7IciwTlbRBqA9omL2sgXpx0="; + }; + + depsBuildBuild = [ + pkg-config + ]; + + nativeBuildInputs = [ + meson + ninja + pkg-config + ]; + + buildInputs = [ + libGL + libgbm + libdrm + libx11 + libxcb + eglexternalplatform + ]; + + absolutizeEglExternalPlatformIcdJson = true; + + strictDeps = true; + __structuredAttrs = true; + + passthru.updateScript = nix-update-script { extraArgs = [ "--use-github-releases" ]; }; + + meta = { + description = "X11/XCB external platform library"; + homepage = "https://github.com/NVIDIA/egl-x11/"; + license = lib.licenses.asl20; + platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ + ccicnce113424 + ]; + }; +}) diff --git a/pkgs/by-name/eg/eglexternalplatform/package.nix b/pkgs/by-name/eg/eglexternalplatform/package.nix index 3208fbcd02eb..c8ac9db06298 100644 --- a/pkgs/by-name/eg/eglexternalplatform/package.nix +++ b/pkgs/by-name/eg/eglexternalplatform/package.nix @@ -4,6 +4,9 @@ fetchFromGitHub, meson, ninja, + buildPackages, + replaceVars, + nix-update-script, }: stdenv.mkDerivation (finalAttrs: { @@ -11,9 +14,9 @@ stdenv.mkDerivation (finalAttrs: { version = "1.2.1"; src = fetchFromGitHub { - owner = "Nvidia"; + owner = "NVIDIA"; repo = "eglexternalplatform"; - rev = finalAttrs.version; + tag = finalAttrs.version; hash = "sha256-tDKh1oSnOSG/XztHHYCwg1tDB7M6olOtJ8te+uan9ko="; }; @@ -22,11 +25,24 @@ stdenv.mkDerivation (finalAttrs: { ninja ]; + setupHook = replaceVars ./setup-hook.sh { + jq = lib.getExe buildPackages.jq; + sponge = lib.getExe' buildPackages.moreutils "sponge"; + }; + + strictDeps = true; + __structuredAttrs = true; + + passthru.updateScript = nix-update-script { extraArgs = [ "--use-github-releases" ]; }; + meta = { description = "EGL External Platform interface"; homepage = "https://github.com/NVIDIA/eglexternalplatform"; license = lib.licenses.mit; platforms = lib.platforms.linux ++ lib.platforms.freebsd; - maintainers = with lib.maintainers; [ hedning ]; + maintainers = with lib.maintainers; [ + hedning + ccicnce113424 + ]; }; }) diff --git a/pkgs/by-name/eg/eglexternalplatform/setup-hook.sh b/pkgs/by-name/eg/eglexternalplatform/setup-hook.sh new file mode 100644 index 000000000000..2beca684e793 --- /dev/null +++ b/pkgs/by-name/eg/eglexternalplatform/setup-hook.sh @@ -0,0 +1,43 @@ +# shellcheck shell=bash + +absolutizeIcdLibraryPath() { + local jsonFile="$1" + local libPath="$2" + + if [[ -z "$jsonFile" || -z "$libPath" ]]; then + nixErrorLog "absolutizeIcdLibraryPath: expected " + return 1 + fi + + if [[ ! -f "$jsonFile" ]]; then + nixErrorLog "absolutizeIcdLibraryPath: JSON file not found: $jsonFile" + return 1 + fi + + @jq@ --arg lib "$libPath" \ + '.ICD.library_path |= $lib + .' \ + "$jsonFile" | @sponge@ "$jsonFile" +} + +fixupEglExternalPlatformIcdJsonHook() { + case "${absolutizeEglExternalPlatformIcdJson-}" in + 1|true|yes) ;; + *) return 0 ;; + esac + + local jsonDir="$prefix/share/egl/egl_external_platform.d" + + if [[ ! -d "$jsonDir" ]]; then + return 0 + fi + + local f + for f in "$jsonDir"/*.json; do + if [[ ! -e "$f" ]]; then + continue + fi + absolutizeIcdLibraryPath "$f" "$prefix/lib/" + done +} + +fixupOutputHooks+=(fixupEglExternalPlatformIcdJsonHook) diff --git a/pkgs/os-specific/linux/nvidia-x11/builder.sh b/pkgs/os-specific/linux/nvidia-x11/builder.sh index 290ee1da2b00..8fa9b8b8fe8b 100755 --- a/pkgs/os-specific/linux/nvidia-x11/builder.sh +++ b/pkgs/os-specific/linux/nvidia-x11/builder.sh @@ -10,23 +10,6 @@ unpackFile() { } -buildPhase() { - runHook preBuild - - if [ -n "$bin" ]; then - # Create the module. - echo "Building linux driver against kernel: $kernel"; - cd kernel - unset src # used by the nv makefile - make $makeFlags -j $NIX_BUILD_CORES module - - cd .. - fi - - runHook postBuild -} - - installPhase() { runHook preInstall @@ -68,6 +51,7 @@ installPhase() { rm -f $i/lib/lib{glx,nvidia-wfb}.so.* # handled separately rm -f $i/lib/libnvidia-gtk* # built from source rm -f $i/lib/libnvidia-wayland-client* # built from source + rm -f $i/lib/libnvidia-egl-* # built from source if [ "$useGLVND" = "1" ]; then # Pre-built libglvnd rm $i/lib/lib{GL,GLX,EGL,GLESv1_CM,GLESv2,OpenGL,GLdispatch}.so.* @@ -96,13 +80,7 @@ installPhase() { else sed -E "s#(libGLX_nvidia)#$i/lib/\\1#" nvidia_icd.json > nvidia_icd.json.fixed fi - - # nvidia currently only supports x86_64 and i686 - if [ "$i" == "$lib32" ]; then - install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia_icd.i686.json - else - install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia_icd.x86_64.json - fi + install -Dm644 nvidia_icd.json.fixed $i/share/vulkan/icd.d/nvidia_icd.json fi if [ -e nvidia_layers.json ]; then @@ -112,17 +90,14 @@ installPhase() { # EGL if [ "$useGLVND" = "1" ]; then - mkdir -p "$i/share/egl/egl_external_platform.d" - for icdname in $(find . -name '*_nvidia*.json') - do - cat "$icdname" | jq ".ICD.library_path |= \"$i/lib/\(.)\"" | tee "$i/share/egl/egl_external_platform.d/$icdname" - done - # glvnd icd mkdir -p "$i/share/glvnd/egl_vendor.d" - mv "$i/share/egl/egl_external_platform.d/10_nvidia.json" "$i/share/glvnd/egl_vendor.d/10_nvidia.json" + for icdname in "10_nvidia.json"; + do + cat "$icdname" | jq ".ICD.library_path |= \"$i/lib/\(.)\"" | tee "$i/share/glvnd/egl_vendor.d/$icdname" + done - if [[ -f "$i/share/egl/egl_external_platform.d/15_nvidia_gbm.json" ]]; then + if [[ -f "15_nvidia_gbm.json" ]]; then mkdir -p $i/lib/gbm ln -s $i/lib/libnvidia-allocator.so $i/lib/gbm/nvidia-drm_gbm.so fi @@ -152,13 +127,6 @@ installPhase() { mkdir -p $bin/lib/xorg/modules/extensions cp -p libglx*.so* $bin/lib/xorg/modules/extensions - # Install the kernel module. - mkdir -p $bin/lib/modules/$kernelVersion/misc - for i in $(find ./kernel -name '*.ko'); do - nuke-refs $i - cp $i $bin/lib/modules/$kernelVersion/misc/ - done - # Install application profiles. if [ "$useProfiles" = "1" ]; then mkdir -p $bin/share/nvidia @@ -167,6 +135,11 @@ installPhase() { fi fi + # Install the proprietary kernel module build files. + if [ -n "$modsrc" ]; then + cp -r kernel $modsrc + fi + if [ -n "$firmware" ]; then # Install the GSP firmware install -Dm644 -t $firmware/lib/firmware/nvidia/$version firmware/gsp*.bin diff --git a/pkgs/os-specific/linux/nvidia-x11/default.nix b/pkgs/os-specific/linux/nvidia-x11/default.nix index 44976a9ceec8..ecdc9fd765d2 100644 --- a/pkgs/os-specific/linux/nvidia-x11/default.nix +++ b/pkgs/os-specific/linux/nvidia-x11/default.nix @@ -6,6 +6,7 @@ fetchpatch, stdenv, pkgsi686Linux, + kernel, }: let @@ -18,20 +19,9 @@ let lib32 = (pkgsi686Linux.callPackage imported { libsOnly = true; - kernel = null; }).out; }; - kernel = - # a hacky way of extracting parameters from callPackage - callPackage ( - { - kernel, - libsOnly ? false, - }: - if libsOnly then { } else kernel - ) { }; - selectHighestVersion = a: b: if lib.versionOlder a.version b.version then b else a; # https://forums.developer.nvidia.com/t/linux-6-7-3-545-29-06-550-40-07-error-modpost-gpl-incompatible-module-nvidia-ko-uses-gpl-only-symbol-rcu-read-lock/280908/19 @@ -76,6 +66,10 @@ rec { # Policy: use the highest stable version as the default (on our master). stable = if stdenv.hostPlatform.system == "i686-linux" then legacy_390 else production; + latest = selectHighestVersion production new_feature; + + bleeding_edge = selectHighestVersion latest beta; + production = generic { version = "595.58.03"; sha256_64bit = "sha256-jA1Plnt5MsSrVxQnKu6BAzkrCnAskq+lVRdtNiBYKfk="; @@ -85,7 +79,7 @@ rec { persistencedSha256 = "sha256-AtjM/ml/ngZil8DMYNH+P111ohuk9mWw5t4z7CHjPWw="; }; - latest = selectHighestVersion production (generic { + new_feature = generic { version = "590.48.01"; sha256_64bit = "sha256-ueL4BpN4FDHMh/TNKRCeEz3Oy1ClDWto1LO/LWlr1ok="; sha256_aarch64 = "sha256-FOz7f6pW1NGM2f74kbP6LbNijxKj5ZtZ08bm0aC+/YA="; @@ -93,16 +87,16 @@ rec { settingsSha256 = "sha256-NWsqUciPa4f1ZX6f0By3yScz3pqKJV1ei9GvOF8qIEE="; persistencedSha256 = "sha256-wsNeuw7IaY6Qc/i/AzT/4N82lPjkwfrhxidKWUtcwW8="; patchesOpen = [ kernel_6_19_patch ]; - }); + }; - beta = selectHighestVersion latest (generic { + beta = generic { version = "595.45.04"; sha256_64bit = "sha256-zUllSSRsuio7dSkcbBTuxF+dN12d6jEPE0WgGvVOj14="; sha256_aarch64 = "sha256-jl6lQWsgF6ya22sAhYPpERJ9r+wjnWzbGnINDpUMzsk="; openSha256 = "sha256-uqNfImwTKhK8gncUdP1TPp0D6Gog4MSeIJMZQiJWDoE="; settingsSha256 = "sha256-Y45pryyM+6ZTJyRaRF3LMKaiIWxB5gF5gGEEcQVr9nA="; persistencedSha256 = "sha256-5FoeUaRRMBIPEWGy4Uo0Aho39KXmjzQsuAD9m/XkNpA="; - }); + }; # Vulkan developer beta driver # See here for more information: https://developer.nvidia.com/vulkan-driver diff --git a/pkgs/os-specific/linux/nvidia-x11/generic.nix b/pkgs/os-specific/linux/nvidia-x11/generic.nix index 4ee461ed8cbf..606a6e715cc1 100644 --- a/pkgs/os-specific/linux/nvidia-x11/generic.nix +++ b/pkgs/os-specific/linux/nvidia-x11/generic.nix @@ -41,16 +41,12 @@ pkgsi686Linux, fetchurl, fetchzip, - kernel ? null, - kernelModuleMakeFlags ? [ ], - perl, - nukeReferences, which, libarchive, jq, - # Whether to build the libraries only (i.e. not the kernel module or - # nvidia-settings). Used to support 32-bit binaries on 64-bit - # Linux. + zstd, + # Whether to build only userspace libraries (without bin/modsrc/firmware + # outputs). Used to support 32-bit binaries on 64-bit Linux. libsOnly ? false, # don't include the bundled 32-bit libraries on 64-bit platforms, # even if it’s in downloaded binary @@ -65,7 +61,6 @@ acceptLicense ? config.nvidia.acceptLicense or false, }: -assert !libsOnly -> kernel != null; assert lib.versionOlder version "391" -> sha256_32bit != null; assert useSettings -> settingsSha256 != null; assert usePersistenced -> persistencedSha256 != null; @@ -96,7 +91,6 @@ let --clean "$patch" > "$out" ''; - nameSuffix = lib.optionalString (!libsOnly) "-${kernel.version}"; pkgSuffix = lib.optionalString (lib.versionOlder version "304") "-pkg0"; i686bundled = lib.versionAtLeast version "391" && !disable32Bit; @@ -143,7 +137,6 @@ let in stdenv.mkDerivation (finalAttrs: { - name = "${finalAttrs.pname}-${finalAttrs.version}${nameSuffix}"; pname = "nvidia-${if useFabricmanager then "dc" else "x11"}"; builder = ./builder.sh; @@ -201,31 +194,13 @@ stdenv.mkDerivation (finalAttrs: { "out" ] ++ lib.optional i686bundled "lib32" - ++ lib.optional (!libsOnly) "bin" + ++ lib.optionals (!libsOnly) [ + "bin" + "modsrc" + ] ++ lib.optional (!libsOnly && firmware) "firmware"; outputDev = if libsOnly then null else "bin"; - kernel = if libsOnly then null else kernel.dev; - kernelVersion = if libsOnly then null else kernel.modDirVersion; - - makeFlags = lib.optionals (!libsOnly) ( - kernelModuleMakeFlags - ++ [ - "IGNORE_PREEMPT_RT_PRESENCE=1" - "NV_BUILD_SUPPORTS_HMM=1" - "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" - "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" - ] - ++ lib.optionals stdenv.cc.isClang [ - "C_INCLUDE_PATH=${lib.getLib stdenv.cc.cc}/lib/clang/${lib.versions.major stdenv.cc.cc.version}/include" - ] - ); - - hardeningDisable = [ - "pic" - "format" - ]; - dontStrip = true; dontPatchELF = true; @@ -233,15 +208,12 @@ stdenv.mkDerivation (finalAttrs: { libPath32 = lib.optionalString i686bundled (libPathFor pkgsi686Linux); nativeBuildInputs = [ - perl - nukeReferences - which libarchive jq ] - ++ lib.optionals (!libsOnly) kernel.moduleBuildDependencies; - - disallowedReferences = lib.optionals (!libsOnly) [ kernel.dev ]; + # NVIDIA has changed the compression format of their driver to zstd since version 530.30.02 + # https://forums.developer.nvidia.com/t/linux-solaris-and-freebsd-driver-530-30-02-beta/244406 + ++ (if (lib.versionAtLeast version "530") then [ zstd ] else [ which ]); passthru = let @@ -274,9 +246,17 @@ stdenv.mkDerivation (finalAttrs: { ); in { + mod = callPackage ./kernel-modules.nix { + open = false; + nvidia_x11 = finalAttrs.finalPackage; + # build files already patched when building the main package, so no need to patch them again + patches = [ ]; + inherit broken; + }; open = lib.mapNullable ( hash: - callPackage ./open.nix { + callPackage ./kernel-modules.nix { + open = true; inherit hash; nvidia_x11 = finalAttrs.finalPackage; patches = @@ -339,11 +319,15 @@ stdenv.mkDerivation (finalAttrs: { ] ++ lib.optionals (sha256_32bit != null) [ "i686-linux" ] ++ lib.optionals (sha256_aarch64 != null) [ "aarch64-linux" ]; + sourceProvenance = with lib.sourceTypes; [ + binaryNativeCode + binaryFirmware + ]; maintainers = with lib.maintainers; [ kiskae edwtjo ]; priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so" - inherit broken; + broken = broken && brokenOpen; }; }) diff --git a/pkgs/os-specific/linux/nvidia-x11/kernel-modules.nix b/pkgs/os-specific/linux/nvidia-x11/kernel-modules.nix new file mode 100644 index 000000000000..9e6998017f87 --- /dev/null +++ b/pkgs/os-specific/linux/nvidia-x11/kernel-modules.nix @@ -0,0 +1,81 @@ +{ + stdenv, + lib, + fetchFromGitHub, + kernel, + kernelModuleMakeFlags, + nvidia_x11, + open, + patches, + broken, + hash ? null, +}: + +assert open -> hash != null; + +stdenv.mkDerivation { + pname = "nvidia-${if open then "open" else "kernel-modules"}"; + version = "${nvidia_x11.version}-${kernel.version}"; + + src = + if open then + fetchFromGitHub { + owner = "NVIDIA"; + repo = "open-gpu-kernel-modules"; + tag = nvidia_x11.version; + inherit hash; + } + else + nvidia_x11.modsrc; + + inherit patches; + + nativeBuildInputs = kernel.moduleBuildDependencies; + + makeFlags = + kernelModuleMakeFlags + ++ [ + "IGNORE_PREEMPT_RT_PRESENCE=1" + "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" + "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + "MODLIB=$(out)/lib/modules/${kernel.modDirVersion}" + "DATE=" + "TARGET_ARCH=${stdenv.hostPlatform.parsed.cpu.name}" + ] + ++ lib.optionals stdenv.cc.isClang [ + "C_INCLUDE_PATH=${lib.getLib stdenv.cc.cc}/lib/clang/${lib.versions.major stdenv.cc.cc.version}/include" + ]; + + buildTargets = [ "modules" ]; + installTargets = [ "modules_install" ]; + enableParallelBuilding = true; + + allowedReferences = [ ]; + + meta = { + description = "NVIDIA Linux ${lib.optionalString open "Open "}GPU Kernel Modules"; + homepage = + if open then "https://github.com/NVIDIA/open-gpu-kernel-modules" else nvidia_x11.meta.homepage; + license = + if open then + with lib.licenses; + [ + gpl2Plus + mit + ] + else + nvidia_x11.meta.license; + platforms = [ + "x86_64-linux" + "aarch64-linux" + ]; + sourceProvenance = + with lib.sourceTypes; + [ + fromSource + ] + ++ lib.optional (!open) binaryNativeCode; + maintainers = with lib.maintainers; [ nickcao ]; + inherit broken; + }; +} diff --git a/pkgs/os-specific/linux/nvidia-x11/open.nix b/pkgs/os-specific/linux/nvidia-x11/open.nix deleted file mode 100644 index 5a897e0dd138..000000000000 --- a/pkgs/os-specific/linux/nvidia-x11/open.nix +++ /dev/null @@ -1,59 +0,0 @@ -{ - stdenv, - lib, - fetchFromGitHub, - kernel, - kernelModuleMakeFlags, - nvidia_x11, - hash, - patches ? [ ], - broken ? false, -}: - -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; - }; - - inherit patches; - - nativeBuildInputs = kernel.moduleBuildDependencies; - - makeFlags = - kernelModuleMakeFlags - ++ [ - "IGNORE_PREEMPT_RT_PRESENCE=1" - "SYSSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" - "SYSOUT=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" - "MODLIB=$(out)/lib/modules/${kernel.modDirVersion}" - "DATE=" - "TARGET_ARCH=${stdenv.hostPlatform.parsed.cpu.name}" - ] - ++ lib.optionals stdenv.cc.isClang [ - "C_INCLUDE_PATH=${lib.getLib stdenv.cc.cc}/lib/clang/${lib.versions.major stdenv.cc.cc.version}/include" - ]; - - installTargets = [ "modules_install" ]; - enableParallelBuilding = true; - - meta = { - description = "NVIDIA Linux Open GPU Kernel Module"; - homepage = "https://github.com/NVIDIA/open-gpu-kernel-modules"; - license = with lib.licenses; [ - gpl2Plus - mit - ]; - platforms = [ - "x86_64-linux" - "aarch64-linux" - ]; - maintainers = with lib.maintainers; [ nickcao ]; - inherit broken; - }; -}