From 51fabd133e56b98da321cef8ea843b495b89243a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edward=20Tj=C3=B6rnhammar?= Date: Thu, 19 Dec 2024 17:44:51 +0100 Subject: [PATCH] nixos/nvidia: run nixfmt on nvidia related files --- nixos/modules/hardware/video/nvidia.nix | 58 ++-- pkgs/os-specific/linux/nvidia-x11/default.nix | 203 ++++++----- pkgs/os-specific/linux/nvidia-x11/generic.nix | 319 +++++++++++------- pkgs/os-specific/linux/nvidia-x11/open.nix | 93 ++--- .../os-specific/linux/nvidia-x11/settings.nix | 149 ++++---- 5 files changed, 478 insertions(+), 344 deletions(-) diff --git a/nixos/modules/hardware/video/nvidia.nix b/nixos/modules/hardware/video/nvidia.nix index 707b4b324235..0980c4948426 100644 --- a/nixos/modules/hardware/video/nvidia.nix +++ b/nixos/modules/hardware/video/nvidia.nix @@ -92,21 +92,23 @@ in information, see the NVIDIA docs, on Chapter 23. Dynamic Boost on Linux ''; - modesetting.enable = lib.mkEnableOption '' - kernel modesetting when using the NVIDIA proprietary driver. + modesetting.enable = + lib.mkEnableOption '' + kernel modesetting when using the NVIDIA proprietary driver. - Enabling this fixes screen tearing when using Optimus via PRIME (see - {option}`hardware.nvidia.prime.sync.enable`. This is not enabled - by default because it is not officially supported by NVIDIA and would not - work with SLI. + Enabling this fixes screen tearing when using Optimus via PRIME (see + {option}`hardware.nvidia.prime.sync.enable`. This is not enabled + by default because it is not officially supported by NVIDIA and would not + work with SLI. - Enabling this and using version 545 or newer of the proprietary NVIDIA - driver causes it to provide its own framebuffer device, which can cause - Wayland compositors to work when they otherwise wouldn't. - '' // { - default = lib.versionAtLeast cfg.package.version "535"; - defaultText = lib.literalExpression "lib.versionAtLeast cfg.package.version \"535\""; - }; + Enabling this and using version 545 or newer of the proprietary NVIDIA + driver causes it to provide its own framebuffer device, which can cause + Wayland compositors to work when they otherwise wouldn't. + '' + // { + default = lib.versionAtLeast cfg.package.version "535"; + defaultText = lib.literalExpression "lib.versionAtLeast cfg.package.version \"535\""; + }; prime.nvidiaBusId = lib.mkOption { type = busIDType; @@ -266,14 +268,16 @@ in ''; }; - gsp.enable = lib.mkEnableOption '' - the GPU System Processor (GSP) on the video card - '' // { - default = useOpenModules || lib.versionAtLeast nvidia_x11.version "555"; - defaultText = lib.literalExpression '' - config.hardware.nvidia.open == true || lib.versionAtLeast config.hardware.nvidia.package.version "555" - ''; - }; + gsp.enable = + lib.mkEnableOption '' + the GPU System Processor (GSP) on the video card + '' + // { + default = useOpenModules || lib.versionAtLeast nvidia_x11.version "555"; + defaultText = lib.literalExpression '' + config.hardware.nvidia.open == true || lib.versionAtLeast config.hardware.nvidia.package.version "555" + ''; + }; videoAcceleration = (lib.mkEnableOption '' @@ -323,7 +327,9 @@ in softdep nvidia post: nvidia-uvm ''; }; - systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [ "L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin" ]; + systemd.tmpfiles.rules = lib.mkIf config.virtualisation.docker.enableNvidia [ + "L+ /run/nvidia-docker/bin - - - - ${nvidia_x11.bin}/origBin" + ]; services.udev.extraRules = '' # Create /dev/nvidia-uvm when the nvidia-uvm module is loaded. KERNEL=="nvidia", RUN+="${pkgs.runtimeShell} -c 'mknod -m 666 /dev/nvidiactl c 195 255'" @@ -622,7 +628,9 @@ in # 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 ( + (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 useOpenModules "nvidia.NVreg_OpenRmEnableUnsupportedGpus=1" ++ lib.optional (config.boot.kernelPackages.kernel.kernelAtLeast "6.2" && !ibtSupport) "ibt=off"; @@ -683,7 +691,9 @@ in TOPOLOGY_FILE_PATH = "${nvidia_x11.fabricmanager}/share/nvidia-fabricmanager/nvidia/nvswitch"; DATABASE_PATH = "${nvidia_x11.fabricmanager}/share/nvidia-fabricmanager/nvidia/nvswitch"; }; - nv-fab-conf = settingsFormat.generate "fabricmanager.conf" (fabricManagerConfDefaults // cfg.datacenter.settings); + nv-fab-conf = settingsFormat.generate "fabricmanager.conf" ( + fabricManagerConfDefaults // cfg.datacenter.settings + ); in "${lib.getExe nvidia_x11.fabricmanager} -c ${nv-fab-conf}"; LimitCORE = "infinity"; diff --git a/pkgs/os-specific/linux/nvidia-x11/default.nix b/pkgs/os-specific/linux/nvidia-x11/default.nix index bd215cf4183c..1c7f44c4c172 100644 --- a/pkgs/os-specific/linux/nvidia-x11/default.nix +++ b/pkgs/os-specific/linux/nvidia-x11/default.nix @@ -1,21 +1,38 @@ -{ lib, callPackage, fetchFromGitHub, fetchgit, fetchpatch, stdenv, pkgsi686Linux }: +{ + lib, + callPackage, + fetchFromGitHub, + fetchgit, + fetchpatch, + stdenv, + pkgsi686Linux, +}: let - generic = args: let - imported = import ./generic.nix args; - in callPackage imported { - lib32 = (pkgsi686Linux.callPackage imported { - libsOnly = true; - kernel = null; - }).out; - }; + generic = + args: + let + imported = import ./generic.nix args; + in + callPackage imported { + lib32 = + (pkgsi686Linux.callPackage imported { + libsOnly = true; + kernel = null; + }).out; + }; - kernel = callPackage # a hacky way of extracting parameters from callPackage - ({ kernel, libsOnly ? false }: if libsOnly then { } else kernel) { }; + 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; + 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 rcu_patch = fetchpatch { @@ -25,7 +42,7 @@ let # Fixes drm device not working with linux 6.12 # https://github.com/NVIDIA/open-gpu-kernel-modules/issues/712 - drm_fop_flags_linux_612_patch = fetchpatch { + drm_fop_flags_linux_612_patch = fetchpatch { url = "https://github.com/Binary-Eater/open-gpu-kernel-modules/commit/8ac26d3c66ea88b0f80504bdd1e907658b41609d.patch"; hash = "sha256-+SfIu3uYNQCf/KXhv4PWvruTVKQSh4bgU1moePhe57U="; }; @@ -136,85 +153,89 @@ rec { }; # Last one supporting x86 - legacy_390 = let - # Source corresponding to https://aur.archlinux.org/packages/nvidia-390xx-dkms - aurPatches = fetchgit { - url = "https://aur.archlinux.org/nvidia-390xx-utils.git"; - rev = "ebb48c240ce329e89ad3b59e78c8c708f46f27b3"; - hash = "sha256-AGx3/EQ81awBMs6rrXTGWJmyq+UjBCPp6/9z1BQBB9E="; + legacy_390 = + let + # Source corresponding to https://aur.archlinux.org/packages/nvidia-390xx-dkms + aurPatches = fetchgit { + url = "https://aur.archlinux.org/nvidia-390xx-utils.git"; + rev = "ebb48c240ce329e89ad3b59e78c8c708f46f27b3"; + hash = "sha256-AGx3/EQ81awBMs6rrXTGWJmyq+UjBCPp6/9z1BQBB9E="; + }; + patchset = [ + "kernel-4.16+-memory-encryption.patch" + "kernel-6.2.patch" + "kernel-6.3.patch" + "kernel-6.4.patch" + "kernel-6.5.patch" + "kernel-6.6.patch" + "kernel-6.8.patch" + "gcc-14.patch" + "kernel-6.10.patch" + ]; + in + generic { + version = "390.157"; + sha256_32bit = "sha256-VdZeCkU5qct5YgDF8Qgv4mP7CVHeqvlqnP/rioD3B5k="; + sha256_64bit = "sha256-W+u8puj+1da52BBw+541HxjtxTSVJVPL3HHo/QubMoo="; + settingsSha256 = "sha256-uJZO4ak/w/yeTQ9QdXJSiaURDLkevlI81de0q4PpFpw="; + persistencedSha256 = "sha256-NuqUQbVt80gYTXgIcu0crAORfsj9BCRooyH3Gp1y1ns="; + + patches = map (patch: "${aurPatches}/${patch}") patchset; + broken = kernel.kernelAtLeast "6.11 "; + + # fixes the bug described in https://bbs.archlinux.org/viewtopic.php?pid=2083439#p2083439 + # see https://bbs.archlinux.org/viewtopic.php?pid=2083651#p2083651 + # and https://bbs.archlinux.org/viewtopic.php?pid=2083699#p2083699 + postInstall = '' + mv $out/lib/tls/* $out/lib + rmdir $out/lib/tls + ''; }; - patchset = [ - "kernel-4.16+-memory-encryption.patch" - "kernel-6.2.patch" - "kernel-6.3.patch" - "kernel-6.4.patch" - "kernel-6.5.patch" - "kernel-6.6.patch" - "kernel-6.8.patch" - "gcc-14.patch" - "kernel-6.10.patch" - ]; - in generic { - version = "390.157"; - sha256_32bit = "sha256-VdZeCkU5qct5YgDF8Qgv4mP7CVHeqvlqnP/rioD3B5k="; - sha256_64bit = "sha256-W+u8puj+1da52BBw+541HxjtxTSVJVPL3HHo/QubMoo="; - settingsSha256 = "sha256-uJZO4ak/w/yeTQ9QdXJSiaURDLkevlI81de0q4PpFpw="; - persistencedSha256 = "sha256-NuqUQbVt80gYTXgIcu0crAORfsj9BCRooyH3Gp1y1ns="; - patches = map (patch: "${aurPatches}/${patch}") patchset; - broken = kernel.kernelAtLeast "6.11 "; + legacy_340 = + let + # Source corresponding to https://aur.archlinux.org/packages/nvidia-340xx-dkms + aurPatches = fetchFromGitHub { + owner = "archlinux-jerry"; + repo = "nvidia-340xx"; + rev = "7616dfed253aa93ca7d2e05caf6f7f332c439c90"; + hash = "sha256-1qlYc17aEbLD4W8XXn1qKryBk2ltT6cVIv5zAs0jXZo="; + }; + patchset = [ + "0001-kernel-5.7.patch" + "0002-kernel-5.8.patch" + "0003-kernel-5.9.patch" + "0004-kernel-5.10.patch" + "0005-kernel-5.11.patch" + "0006-kernel-5.14.patch" + "0007-kernel-5.15.patch" + "0008-kernel-5.16.patch" + "0009-kernel-5.17.patch" + "0010-kernel-5.18.patch" + "0011-kernel-6.0.patch" + "0012-kernel-6.2.patch" + "0013-kernel-6.3.patch" + "0014-kernel-6.5.patch" + "0015-kernel-6.6.patch" + ]; + in + generic { + version = "340.108"; + sha256_32bit = "1jkwa1phf0x4sgw8pvr9d6krmmr3wkgwyygrxhdazwyr2bbalci0"; + sha256_64bit = "06xp6c0sa7v1b82gf0pq0i5p0vdhmm3v964v0ypw36y0nzqx8wf6"; + settingsSha256 = "0zm29jcf0mp1nykcravnzb5isypm8l8mg2gpsvwxipb7nk1ivy34"; + persistencedSha256 = "1ax4xn3nmxg1y6immq933cqzw6cj04x93saiasdc0kjlv0pvvnkn"; + useGLVND = false; - # fixes the bug described in https://bbs.archlinux.org/viewtopic.php?pid=2083439#p2083439 - # see https://bbs.archlinux.org/viewtopic.php?pid=2083651#p2083651 - # and https://bbs.archlinux.org/viewtopic.php?pid=2083699#p2083699 - postInstall = '' - mv $out/lib/tls/* $out/lib - rmdir $out/lib/tls - ''; - }; + broken = kernel.kernelAtLeast "6.7"; + patches = map (patch: "${aurPatches}/${patch}") patchset; - legacy_340 = let - # Source corresponding to https://aur.archlinux.org/packages/nvidia-340xx-dkms - aurPatches = fetchFromGitHub { - owner = "archlinux-jerry"; - repo = "nvidia-340xx"; - rev = "7616dfed253aa93ca7d2e05caf6f7f332c439c90"; - hash = "sha256-1qlYc17aEbLD4W8XXn1qKryBk2ltT6cVIv5zAs0jXZo="; + # fixes the bug described in https://bbs.archlinux.org/viewtopic.php?pid=2083439#p2083439 + # see https://bbs.archlinux.org/viewtopic.php?pid=2083651#p2083651 + # and https://bbs.archlinux.org/viewtopic.php?pid=2083699#p2083699 + postInstall = '' + mv $out/lib/tls/* $out/lib + rmdir $out/lib/tls + ''; }; - patchset = [ - "0001-kernel-5.7.patch" - "0002-kernel-5.8.patch" - "0003-kernel-5.9.patch" - "0004-kernel-5.10.patch" - "0005-kernel-5.11.patch" - "0006-kernel-5.14.patch" - "0007-kernel-5.15.patch" - "0008-kernel-5.16.patch" - "0009-kernel-5.17.patch" - "0010-kernel-5.18.patch" - "0011-kernel-6.0.patch" - "0012-kernel-6.2.patch" - "0013-kernel-6.3.patch" - "0014-kernel-6.5.patch" - "0015-kernel-6.6.patch" - ]; - in generic { - version = "340.108"; - sha256_32bit = "1jkwa1phf0x4sgw8pvr9d6krmmr3wkgwyygrxhdazwyr2bbalci0"; - sha256_64bit = "06xp6c0sa7v1b82gf0pq0i5p0vdhmm3v964v0ypw36y0nzqx8wf6"; - settingsSha256 = "0zm29jcf0mp1nykcravnzb5isypm8l8mg2gpsvwxipb7nk1ivy34"; - persistencedSha256 = "1ax4xn3nmxg1y6immq933cqzw6cj04x93saiasdc0kjlv0pvvnkn"; - useGLVND = false; - - broken = kernel.kernelAtLeast "6.7"; - patches = map (patch: "${aurPatches}/${patch}") patchset; - - # fixes the bug described in https://bbs.archlinux.org/viewtopic.php?pid=2083439#p2083439 - # see https://bbs.archlinux.org/viewtopic.php?pid=2083651#p2083651 - # and https://bbs.archlinux.org/viewtopic.php?pid=2083699#p2083699 - postInstall = '' - mv $out/lib/tls/* $out/lib - rmdir $out/lib/tls - ''; - }; } diff --git a/pkgs/os-specific/linux/nvidia-x11/generic.nix b/pkgs/os-specific/linux/nvidia-x11/generic.nix index b74af83021d9..db6d89f80bb3 100644 --- a/pkgs/os-specific/linux/nvidia-x11/generic.nix +++ b/pkgs/os-specific/linux/nvidia-x11/generic.nix @@ -1,65 +1,67 @@ -{ version -, url ? null -, sha256_32bit ? null -, sha256_64bit -, sha256_aarch64 ? null -, openSha256 ? null -, settingsSha256 ? null -, settingsVersion ? version -, persistencedSha256 ? null -, persistencedVersion ? version -, fabricmanagerSha256 ? null -, fabricmanagerVersion ? version -, useGLVND ? true -, useProfiles ? true -, preferGtk2 ? false -, settings32Bit ? false -, useSettings ? true -, usePersistenced ? true -, useFabricmanager ? false -, ibtSupport ? false +{ + version, + url ? null, + sha256_32bit ? null, + sha256_64bit, + sha256_aarch64 ? null, + openSha256 ? null, + settingsSha256 ? null, + settingsVersion ? version, + persistencedSha256 ? null, + persistencedVersion ? version, + fabricmanagerSha256 ? null, + fabricmanagerVersion ? version, + useGLVND ? true, + useProfiles ? true, + preferGtk2 ? false, + settings32Bit ? false, + useSettings ? true, + usePersistenced ? true, + useFabricmanager ? false, + ibtSupport ? false, -, prePatch ? null -, postPatch ? null -, patchFlags ? null -, patches ? [ ] -, patchesOpen ? [ ] -, preInstall ? null -, postInstall ? null -, broken ? false -, brokenOpen ? broken + prePatch ? null, + postPatch ? null, + patchFlags ? null, + patches ? [ ], + patchesOpen ? [ ], + preInstall ? null, + postInstall ? null, + broken ? false, + brokenOpen ? broken, }@args: -{ lib -, stdenv -, runCommandLocal -, patchutils -, callPackage -, pkgs -, pkgsi686Linux -, fetchurl -, fetchzip -, kernel ? null -, perl -, nukeReferences -, which -, libarchive -, jq -, # Whether to build the libraries only (i.e. not the kernel module or +{ + lib, + stdenv, + runCommandLocal, + patchutils, + callPackage, + pkgs, + pkgsi686Linux, + fetchurl, + fetchzip, + kernel ? null, + 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. - libsOnly ? false -, # don't include the bundled 32-bit libraries on 64-bit platforms, + libsOnly ? false, + # don't include the bundled 32-bit libraries on 64-bit platforms, # even if it’s in downloaded binary - disable32Bit ? stdenv.hostPlatform.system == "aarch64-linux" + disable32Bit ? stdenv.hostPlatform.system == "aarch64-linux", # 32 bit libs only version of this package -, lib32 ? null + lib32 ? null, # Whether to extract the GSP firmware, datacenter drivers needs to extract the # firmware -, firmware ? openSha256 != null || useFabricmanager + firmware ? openSha256 != null || useFabricmanager, # Whether the user accepts the NVIDIA Software License -, config -, acceptLicense ? config.nvidia.acceptLicense or false + config, + acceptLicense ? config.nvidia.acceptLicense or false, }: assert !libsOnly -> kernel != null; @@ -97,21 +99,26 @@ let pkgSuffix = lib.optionalString (lib.versionOlder version "304") "-pkg0"; i686bundled = lib.versionAtLeast version "391" && !disable32Bit; - libPathFor = pkgs: lib.makeLibraryPath (with pkgs; [ - libdrm - xorg.libXext - xorg.libX11 - xorg.libXv - xorg.libXrandr - xorg.libxcb - zlib - stdenv.cc.cc - wayland - mesa - libGL - openssl - dbus # for nvidia-powerd - ]); + libPathFor = + pkgs: + lib.makeLibraryPath ( + with pkgs; + [ + libdrm + xorg.libXext + xorg.libX11 + xorg.libXv + xorg.libXrandr + xorg.libxcb + zlib + stdenv.cc.cc + wayland + mesa + libGL + openssl + dbus # for nvidia-powerd + ] + ); # maybe silly since we've ignored this previously and just unfree.. throwLicense = throw '' @@ -139,35 +146,46 @@ let builder = ./builder.sh; src = - if !acceptLicense && (openSha256 == null) then throwLicense else - if stdenv.hostPlatform.system == "x86_64-linux" then - fetchurl - { - urls = if args ? url then [ args.url ] else [ - "https://us.download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run" - "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run" - ]; - sha256 = sha256_64bit; - } + if !acceptLicense && (openSha256 == null) then + throwLicense + else if stdenv.hostPlatform.system == "x86_64-linux" then + fetchurl { + urls = + if args ? url then + [ args.url ] + else + [ + "https://us.download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run" + "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run" + ]; + sha256 = sha256_64bit; + } else if stdenv.hostPlatform.system == "i686-linux" then - fetchurl - { - urls = if args ? url then [ args.url ] else [ - "https://us.download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run" - "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run" - ]; - sha256 = sha256_32bit; - } + fetchurl { + urls = + if args ? url then + [ args.url ] + else + [ + "https://us.download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run" + "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run" + ]; + sha256 = sha256_32bit; + } else if stdenv.hostPlatform.system == "aarch64-linux" && sha256_aarch64 != null then - fetchurl - { - urls = if args ? url then [ args.url ] else [ - "https://us.download.nvidia.com/XFree86/aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run" - "https://download.nvidia.com/XFree86/Linux-aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run" - ]; - sha256 = sha256_aarch64; - } - else throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}"; + fetchurl { + urls = + if args ? url then + [ args.url ] + else + [ + "https://us.download.nvidia.com/XFree86/aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run" + "https://download.nvidia.com/XFree86/Linux-aarch64/${version}/NVIDIA-Linux-aarch64-${version}${pkgSuffix}.run" + ]; + sha256 = sha256_aarch64; + } + else + throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}"; patches = if libsOnly then @@ -186,7 +204,8 @@ let inherit (stdenv.hostPlatform) system; inherit i686bundled; - outputs = [ "out" ] + outputs = + [ "out" ] ++ lib.optional i686bundled "lib32" ++ lib.optional (!libsOnly) "bin" ++ lib.optional (!libsOnly && firmware) "firmware"; @@ -195,14 +214,20 @@ let kernel = if libsOnly then null else kernel.dev; kernelVersion = if libsOnly then null else kernel.modDirVersion; - makeFlags = lib.optionals (!libsOnly) (kernel.makeFlags ++ [ - "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" - ]); + makeFlags = lib.optionals (!libsOnly) ( + kernel.makeFlags + ++ [ + "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" + ] + ); - hardeningDisable = [ "pic" "format" ]; + hardeningDisable = [ + "pic" + "format" + ]; dontStrip = true; dontPatchELF = true; @@ -210,31 +235,50 @@ let libPath = libPathFor pkgs; libPath32 = lib.optionalString i686bundled (libPathFor pkgsi686Linux); - nativeBuildInputs = [ perl nukeReferences which libarchive jq ] - ++ lib.optionals (!libsOnly) kernel.moduleBuildDependencies; + nativeBuildInputs = [ + perl + nukeReferences + which + libarchive + jq + ] ++ lib.optionals (!libsOnly) kernel.moduleBuildDependencies; disallowedReferences = lib.optionals (!libsOnly) [ kernel.dev ]; passthru = let - fetchFromGithubOrNvidia = { owner, repo, rev, ... }@args: + fetchFromGithubOrNvidia = + { + owner, + repo, + rev, + ... + }@args: let - args' = builtins.removeAttrs args [ "owner" "repo" "rev" ]; + args' = builtins.removeAttrs args [ + "owner" + "repo" + "rev" + ]; baseUrl = "https://github.com/${owner}/${repo}"; in - fetchzip (args' // { - urls = [ - "${baseUrl}/archive/${rev}.tar.gz" - "https://download.nvidia.com/XFree86/${repo}/${repo}-${rev}.tar.bz2" - ]; - # github and nvidia use different compression algorithms, - # use an invalid file extension to force detection. - extension = "tar.??"; - }); + fetchzip ( + args' + // { + urls = [ + "${baseUrl}/archive/${rev}.tar.gz" + "https://download.nvidia.com/XFree86/${repo}/${repo}-${rev}.tar.bz2" + ]; + # github and nvidia use different compression algorithms, + # use an invalid file extension to force detection. + extension = "tar.??"; + } + ); in { - open = lib.mapNullable - (hash: callPackage ./open.nix { + open = lib.mapNullable ( + hash: + callPackage ./open.nix { inherit hash; nvidia_x11 = self; patches = @@ -244,43 +288,56 @@ let }) patches) ++ patchesOpen; broken = brokenOpen; - }) - openSha256; + } + ) openSha256; settings = if useSettings then - (if settings32Bit then pkgsi686Linux.callPackage else callPackage) (import ./settings.nix self settingsSha256) + (if settings32Bit then pkgsi686Linux.callPackage else callPackage) + (import ./settings.nix self settingsSha256) { withGtk2 = preferGtk2; withGtk3 = !preferGtk2; fetchFromGitHub = fetchFromGithubOrNvidia; - } else { }; + } + else + { }; persistenced = if usePersistenced then - lib.mapNullable - (hash: callPackage (import ./persistenced.nix self hash) { + lib.mapNullable ( + hash: + callPackage (import ./persistenced.nix self hash) { fetchFromGitHub = fetchFromGithubOrNvidia; - }) - persistencedSha256 - else { }; + } + ) persistencedSha256 + else + { }; fabricmanager = if useFabricmanager then lib.mapNullable (hash: callPackage (import ./fabricmanager.nix self hash) { }) fabricmanagerSha256 - else { }; + else + { }; inherit persistencedVersion settingsVersion; compressFirmware = false; ibtSupport = ibtSupport || (lib.versionAtLeast version "530"); - } // lib.optionalAttrs (!i686bundled) { + } + // lib.optionalAttrs (!i686bundled) { inherit lib32; }; meta = with lib; { homepage = "https://www.nvidia.com/object/unix.html"; - description = "${if useFabricmanager then "Data Center" else "X.org"} driver and kernel module for NVIDIA cards"; + description = "${ + if useFabricmanager then "Data Center" else "X.org" + } driver and kernel module for NVIDIA cards"; license = licenses.unfreeRedistributable; - platforms = [ "x86_64-linux" ] + platforms = + [ "x86_64-linux" ] ++ lib.optionals (sha256_32bit != null) [ "i686-linux" ] ++ lib.optionals (sha256_aarch64 != null) [ "aarch64-linux" ]; - maintainers = with maintainers; [ kiskae edwtjo ]; + maintainers = with maintainers; [ + kiskae + edwtjo + ]; priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so" inherit broken; }; diff --git a/pkgs/os-specific/linux/nvidia-x11/open.nix b/pkgs/os-specific/linux/nvidia-x11/open.nix index d9926f9cc3eb..7f60918f3872 100644 --- a/pkgs/os-specific/linux/nvidia-x11/open.nix +++ b/pkgs/os-specific/linux/nvidia-x11/open.nix @@ -1,49 +1,60 @@ -{ stdenv -, lib -, fetchFromGitHub -, kernel -, nvidia_x11 -, hash -, patches ? [ ] -, broken ? false +{ + stdenv, + lib, + fetchFromGitHub, + kernel, + nvidia_x11, + hash, + patches ? [ ], + broken ? false, }: -stdenv.mkDerivation ({ - pname = "nvidia-open"; - version = "${kernel.version}-${nvidia_x11.version}"; +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; - }; + src = fetchFromGitHub { + owner = "NVIDIA"; + repo = "open-gpu-kernel-modules"; + rev = nvidia_x11.version; + inherit hash; + }; - inherit patches; + inherit patches; - nativeBuildInputs = kernel.moduleBuildDependencies; + 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}" - { - aarch64-linux = "TARGET_ARCH=aarch64"; - x86_64-linux = "TARGET_ARCH=x86_64"; - }.${stdenv.hostPlatform.system} - ]; + 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}" + { + aarch64-linux = "TARGET_ARCH=aarch64"; + x86_64-linux = "TARGET_ARCH=x86_64"; + } + .${stdenv.hostPlatform.system} + ]; - installTargets = [ "modules_install" ]; - enableParallelBuilding = true; + 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 = [ "x86_64-linux" "aarch64-linux" ]; - maintainers = with maintainers; [ nickcao ]; - inherit broken; - }; -} // lib.optionalAttrs stdenv.hostPlatform.isAarch64 { - env.NIX_CFLAGS_COMPILE = "-fno-stack-protector"; -}) + 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 = [ + "x86_64-linux" + "aarch64-linux" + ]; + maintainers = with maintainers; [ nickcao ]; + inherit broken; + }; + } + // lib.optionalAttrs stdenv.hostPlatform.isAarch64 { + env.NIX_CFLAGS_COMPILE = "-fno-stack-protector"; + } +) diff --git a/pkgs/os-specific/linux/nvidia-x11/settings.nix b/pkgs/os-specific/linux/nvidia-x11/settings.nix index f1b363f5a696..f67b33368c8b 100644 --- a/pkgs/os-specific/linux/nvidia-x11/settings.nix +++ b/pkgs/os-specific/linux/nvidia-x11/settings.nix @@ -1,27 +1,28 @@ nvidia_x11: sha256: -{ stdenv -, lib -, fetchFromGitHub -, fetchpatch -, pkg-config -, m4 -, jansson -, gtk2 -, dbus -, vulkan-headers -, gtk3 -, libXv -, libXrandr -, libXext -, libXxf86vm -, libvdpau -, librsvg -, libglvnd -, wrapGAppsHook3 -, addDriverRunpath -, withGtk2 ? false -, withGtk3 ? true +{ + stdenv, + lib, + fetchFromGitHub, + fetchpatch, + pkg-config, + m4, + jansson, + gtk2, + dbus, + vulkan-headers, + gtk3, + libXv, + libXrandr, + libXext, + libXxf86vm, + libvdpau, + librsvg, + libglvnd, + wrapGAppsHook3, + addDriverRunpath, + withGtk2 ? false, + withGtk3 ? true, }: let @@ -35,7 +36,10 @@ let meta = with lib; { homepage = "https://www.nvidia.com/object/unix.html"; platforms = nvidia_x11.meta.platforms; - maintainers = with maintainers; [ abbradar aidalgol ]; + maintainers = with maintainers; [ + abbradar + aidalgol + ]; }; libXNVCtrl = stdenv.mkDerivation { @@ -43,7 +47,10 @@ let version = nvidia_x11.settingsVersion; inherit src; - buildInputs = [ libXrandr libXext ]; + buildInputs = [ + libXrandr + libXext + ]; preBuild = '' cd src/libXNVCtrl @@ -57,8 +64,12 @@ let patches = [ # Patch the Makefile to also produce a shared library. - (if lib.versionOlder nvidia_x11.settingsVersion "400" then ./libxnvctrl-build-shared-3xx.patch - else ./libxnvctrl-build-shared.patch) + ( + if lib.versionOlder nvidia_x11.settingsVersion "400" then + ./libxnvctrl-build-shared-3xx.patch + else + ./libxnvctrl-build-shared.patch + ) ]; installPhase = '' @@ -79,7 +90,9 @@ let }; runtimeDependencies = [ - libglvnd libXrandr libXv + libglvnd + libXrandr + libXv ]; runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies; @@ -92,20 +105,22 @@ stdenv.mkDerivation { inherit src; - patches = lib.optional (lib.versionOlder nvidia_x11.settingsVersion "440") - (fetchpatch { + patches = + lib.optional (lib.versionOlder nvidia_x11.settingsVersion "440") (fetchpatch { # fixes "multiple definition of `VDPAUDeviceFunctions'" linking errors url = "https://github.com/NVIDIA/nvidia-settings/commit/a7c1f5fce6303a643fadff7d85d59934bd0cf6b6.patch"; hash = "sha256-ZwF3dRTYt/hO8ELg9weoz1U/XcU93qiJL2d1aq1Jlak="; }) - ++ lib.optional - ((lib.versionAtLeast nvidia_x11.settingsVersion "515.43.04") - && (lib.versionOlder nvidia_x11.settingsVersion "545.29")) - (fetchpatch { - # fix wayland support for compositors that use wl_output version 4 - url = "https://github.com/NVIDIA/nvidia-settings/pull/99/commits/2e0575197e2b3247deafd2a48f45afc038939a06.patch"; - hash = "sha256-wKuO5CUTUuwYvsP46Pz+6fI0yxLNpZv8qlbL0TFkEFE="; - }); + ++ lib.optional + ( + (lib.versionAtLeast nvidia_x11.settingsVersion "515.43.04") + && (lib.versionOlder nvidia_x11.settingsVersion "545.29") + ) + (fetchpatch { + # fix wayland support for compositors that use wl_output version 4 + url = "https://github.com/NVIDIA/nvidia-settings/pull/99/commits/2e0575197e2b3247deafd2a48f45afc038939a06.patch"; + hash = "sha256-wKuO5CUTUuwYvsP46Pz+6fI0yxLNpZv8qlbL0TFkEFE="; + }); postPatch = lib.optionalString nvidia_x11.useProfiles '' sed -i 's,/usr/share/nvidia/,${nvidia_x11.bin}/share/nvidia/,g' src/gtk+-2.x/ctkappprofile.c @@ -122,31 +137,51 @@ stdenv.mkDerivation { fi ''; - nativeBuildInputs = [ pkg-config m4 addDriverRunpath ] - ++ lib.optionals withGtk3 [ wrapGAppsHook3 ]; + nativeBuildInputs = [ + pkg-config + m4 + addDriverRunpath + ] ++ lib.optionals withGtk3 [ wrapGAppsHook3 ]; - buildInputs = [ jansson libXv libXrandr libXext libXxf86vm libvdpau nvidia_x11 dbus vulkan-headers ] + buildInputs = + [ + jansson + libXv + libXrandr + libXext + libXxf86vm + libvdpau + nvidia_x11 + dbus + vulkan-headers + ] ++ lib.optionals (withGtk2 || lib.versionOlder nvidia_x11.settingsVersion "525.53") [ gtk2 ] - ++ lib.optionals withGtk3 [ gtk3 librsvg ]; + ++ lib.optionals withGtk3 [ + gtk3 + librsvg + ]; installFlags = [ "PREFIX=$(out)" ]; - postInstall = lib.optionalString (!withGtk2) '' - rm -f $out/lib/libnvidia-gtk2.so.* - '' + lib.optionalString (!withGtk3) '' - rm -f $out/lib/libnvidia-gtk3.so.* - '' + '' - # Install the desktop file and icon. - # The template has substitution variables intended to be replaced resulting - # in absolute paths. Because absolute paths break after the desktop file is - # copied by a desktop environment, make Exec and Icon be just a name. - sed -i doc/nvidia-settings.desktop \ - -e "s|^Exec=.*$|Exec=nvidia-settings|" \ - -e "s|^Icon=.*$|Icon=nvidia-settings|" \ - -e "s|__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__|Settings|g" - install doc/nvidia-settings.desktop -D -t $out/share/applications/ - install doc/nvidia-settings.png -D -t $out/share/icons/hicolor/128x128/apps/ - ''; + postInstall = + lib.optionalString (!withGtk2) '' + rm -f $out/lib/libnvidia-gtk2.so.* + '' + + lib.optionalString (!withGtk3) '' + rm -f $out/lib/libnvidia-gtk3.so.* + '' + + '' + # Install the desktop file and icon. + # The template has substitution variables intended to be replaced resulting + # in absolute paths. Because absolute paths break after the desktop file is + # copied by a desktop environment, make Exec and Icon be just a name. + sed -i doc/nvidia-settings.desktop \ + -e "s|^Exec=.*$|Exec=nvidia-settings|" \ + -e "s|^Icon=.*$|Icon=nvidia-settings|" \ + -e "s|__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__|Settings|g" + install doc/nvidia-settings.desktop -D -t $out/share/applications/ + install doc/nvidia-settings.png -D -t $out/share/icons/hicolor/128x128/apps/ + ''; binaryName = if withGtk3 then ".nvidia-settings-wrapped" else "nvidia-settings"; postFixup = ''