Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 205 lines 5.1 kB view raw
1nvidia_x11: sha256: 2 3{ 4 stdenv, 5 lib, 6 fetchFromGitHub, 7 fetchpatch, 8 pkg-config, 9 m4, 10 jansson, 11 gtk2, 12 dbus, 13 vulkan-headers, 14 gtk3, 15 libXv, 16 libXrandr, 17 libXext, 18 libXxf86vm, 19 libvdpau, 20 librsvg, 21 libglvnd, 22 wrapGAppsHook3, 23 addDriverRunpath, 24 withGtk2 ? false, 25 withGtk3 ? true, 26}: 27 28let 29 src = fetchFromGitHub { 30 owner = "NVIDIA"; 31 repo = "nvidia-settings"; 32 rev = nvidia_x11.settingsVersion; 33 inherit sha256; 34 }; 35 36 meta = with lib; { 37 homepage = "https://www.nvidia.com/object/unix.html"; 38 platforms = nvidia_x11.meta.platforms; 39 maintainers = with maintainers; [ 40 abbradar 41 aidalgol 42 ]; 43 }; 44 45 libXNVCtrl = stdenv.mkDerivation { 46 pname = "libXNVCtrl"; 47 version = nvidia_x11.settingsVersion; 48 inherit src; 49 50 buildInputs = [ 51 libXrandr 52 libXext 53 ]; 54 55 preBuild = '' 56 cd src/libXNVCtrl 57 ''; 58 59 makeFlags = [ 60 "OUTPUTDIR=." # src/libXNVCtrl 61 "libXNVCtrl.a" 62 "libXNVCtrl.so" 63 ]; 64 65 patches = [ 66 # Patch the Makefile to also produce a shared library. 67 ( 68 if lib.versionOlder nvidia_x11.settingsVersion "400" then 69 ./libxnvctrl-build-shared-3xx.patch 70 else 71 ./libxnvctrl-build-shared.patch 72 ) 73 ]; 74 75 installPhase = '' 76 mkdir -p $out/lib 77 mkdir -p $out/include/NVCtrl 78 79 cp libXNVCtrl.a $out/lib 80 cp NVCtrl.h $out/include/NVCtrl 81 cp NVCtrlLib.h $out/include/NVCtrl 82 cp -P libXNVCtrl.so* $out/lib 83 ''; 84 85 meta = meta // { 86 description = "NVIDIA NV-CONTROL X extension"; 87 # https://github.com/NVIDIA/nvidia-settings/commit/edcf9edad9f52f9b10e63d4480bbe88b22dde884 88 license = lib.licenses.mit; 89 }; 90 }; 91 92 runtimeDependencies = [ 93 libglvnd 94 libXrandr 95 libXv 96 ]; 97 98 runtimeLibraryPath = lib.makeLibraryPath runtimeDependencies; 99 100in 101 102stdenv.mkDerivation { 103 pname = "nvidia-settings"; 104 version = nvidia_x11.settingsVersion; 105 106 inherit src; 107 108 patches = 109 lib.optional (lib.versionOlder nvidia_x11.settingsVersion "440") (fetchpatch { 110 # fixes "multiple definition of `VDPAUDeviceFunctions'" linking errors 111 url = "https://github.com/NVIDIA/nvidia-settings/commit/a7c1f5fce6303a643fadff7d85d59934bd0cf6b6.patch"; 112 hash = "sha256-ZwF3dRTYt/hO8ELg9weoz1U/XcU93qiJL2d1aq1Jlak="; 113 }) 114 ++ 115 lib.optional 116 ( 117 (lib.versionAtLeast nvidia_x11.settingsVersion "515.43.04") 118 && (lib.versionOlder nvidia_x11.settingsVersion "545.29") 119 ) 120 (fetchpatch { 121 # fix wayland support for compositors that use wl_output version 4 122 url = "https://github.com/NVIDIA/nvidia-settings/pull/99/commits/2e0575197e2b3247deafd2a48f45afc038939a06.patch"; 123 hash = "sha256-wKuO5CUTUuwYvsP46Pz+6fI0yxLNpZv8qlbL0TFkEFE="; 124 }); 125 126 postPatch = lib.optionalString nvidia_x11.useProfiles '' 127 sed -i 's,/usr/share/nvidia/,${nvidia_x11.bin}/share/nvidia/,g' src/gtk+-2.x/ctkappprofile.c 128 ''; 129 130 enableParallelBuilding = true; 131 makeFlags = [ "NV_USE_BUNDLED_LIBJANSSON=0" ]; 132 133 preBuild = '' 134 if [ -e src/libXNVCtrl/libXNVCtrl.a ]; then 135 ( cd src/libXNVCtrl 136 make $makeFlags 137 ) 138 fi 139 ''; 140 141 nativeBuildInputs = [ 142 pkg-config 143 m4 144 addDriverRunpath 145 ] 146 ++ lib.optionals withGtk3 [ wrapGAppsHook3 ]; 147 148 buildInputs = [ 149 jansson 150 libXv 151 libXrandr 152 libXext 153 libXxf86vm 154 libvdpau 155 nvidia_x11 156 dbus 157 vulkan-headers 158 ] 159 ++ lib.optionals (withGtk2 || lib.versionOlder nvidia_x11.settingsVersion "525.53") [ gtk2 ] 160 ++ lib.optionals withGtk3 [ 161 gtk3 162 librsvg 163 ]; 164 165 installFlags = [ "PREFIX=$(out)" ]; 166 167 postInstall = 168 lib.optionalString (!withGtk2) '' 169 rm -f $out/lib/libnvidia-gtk2.so.* 170 '' 171 + lib.optionalString (!withGtk3) '' 172 rm -f $out/lib/libnvidia-gtk3.so.* 173 '' 174 + '' 175 # Install the desktop file and icon. 176 # The template has substitution variables intended to be replaced resulting 177 # in absolute paths. Because absolute paths break after the desktop file is 178 # copied by a desktop environment, make Exec and Icon be just a name. 179 sed -i doc/nvidia-settings.desktop \ 180 -e "s|^Exec=.*$|Exec=nvidia-settings|" \ 181 -e "s|^Icon=.*$|Icon=nvidia-settings|" \ 182 -e "s|__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__|Settings|g" 183 install doc/nvidia-settings.desktop -D -t $out/share/applications/ 184 install doc/nvidia-settings.png -D -t $out/share/icons/hicolor/128x128/apps/ 185 ''; 186 187 binaryName = if withGtk3 then ".nvidia-settings-wrapped" else "nvidia-settings"; 188 postFixup = '' 189 patchelf --set-rpath "$(patchelf --print-rpath $out/bin/$binaryName):$out/lib:${runtimeLibraryPath}" \ 190 $out/bin/$binaryName 191 192 addDriverRunpath $out/bin/$binaryName 193 ''; 194 195 passthru = { 196 inherit libXNVCtrl; 197 }; 198 199 meta = meta // { 200 description = "Settings application for NVIDIA graphics cards"; 201 # nvml.h is licensed as part of the cuda developer license. 202 license = lib.licenses.unfreeRedistributable; 203 mainProgram = "nvidia-settings"; 204 }; 205}