portage-stable: Add nvidia-drivers ebuilds

From Gentoo commit 9fbc01bc73344c66498d3a3ccbf4fff5be10219b
This commit is contained in:
Daniel Zatovic 2025-02-18 11:28:48 +01:00
parent ab90a85304
commit be2cbc7bd4
34 changed files with 6826 additions and 0 deletions

View File

@ -0,0 +1,14 @@
: ${MODULES_ROOT:=$(echo ${SYSROOT}/lib/modules/*)}
KERNEL_DIR="${MODULES_ROOT}/build"
# This addresses an issue with the kernel version compatibility check
# when installing zfs-kmod to /build/<arch> (e.g. via build_packages)
# from its binpkg (i.e. not recompiling it).
SKIP_KERNEL_BINPKG_ENV_RESET=1
# Necessary to prevent KV_FULL & KV_OUT_DIR from being unset
# when building Kernel modules for sysext. See also eclass/linux-info.eclass.
cros_pre_pkg_setup_kernel_version() {
LINUX_INFO_BINARY_RESET=1
get_version
}

View File

@ -0,0 +1,55 @@
DIST NVIDIA-Linux-aarch64-535.247.01.run 269861217 BLAKE2B c72eb28472c6a5ee5344618b343efc3f8edac94a5d2c994b86d113f7258c0df228076462d3fb84791f8f1c666554d20116ebb6a7444b680128556a4b9e8b2b29 SHA512 a0bd487238d41fd907c7e87d8ce10b4e19a367c8faafafc914fe6d741b348619e7427a5ff22dd2a475e4dd5cf3148965934b746bcc34b3f572bc01e8a6429bda
DIST NVIDIA-Linux-aarch64-550.163.01.run 236409124 BLAKE2B 21c79346f6b739f44d7ed2d4955129613f51e1329ff15948ef50a9a06b82975ad890d6142e5dfb163e7b0da19bf5c26029cf507d120037f8a76abc177a286403 SHA512 0ef4ab4aae308ec0cfb5458cef34a1503ac1a85f0e1d0c9f061d8e28f939b15784e3862d96d83e93123d9eb56807a6804318ce230ee68917fb75e363011f8304
DIST NVIDIA-Linux-aarch64-570.133.07.run 289675662 BLAKE2B 376c03e28a4b441ba8d661759efda3fc83928f950f7c7eac7a4a6f6fd79ac63e1b40c9cad2833e52f48f09f21318d88a40d6089597fe930f1e0e93603b07defc SHA512 3b117e27230198d7305d629257680f1ca7106ad4e84856ce9092c88955416a2c475e6c4f3f0d9ecbc1a2c8e5509b5a902759ead4ba32fdc0d0273ffd84024e4a
DIST NVIDIA-Linux-aarch64-570.144.run 289812160 BLAKE2B 45b7fd81be03b5ee96c51081ed2eb498b3ab45ff3d31459f4d220dc022c790ba5186dff37bc9cfcc49d0874fb9c49fedbe9edb9268d4c5577bafad0c85c7667b SHA512 554e3ae25643502562017c2c6d5224ef8d6065ac81602d9d561576390f8e402f4ab365d5fc46e2139abf47073b4af7e98b60c602035bbc3f1450947bcc00b432
DIST NVIDIA-Linux-aarch64-575.51.02.run 304442848 BLAKE2B f773b79a63e1140919d0d4c6411c601f4aea31a8a40d996fe0b6f9471905e587ae5b1618e4fcb9b3ef2d7970df3440ddbf612c13461f99bbb19ad58a1bd37dac SHA512 94ce8f0c19dd7077810b040f9f4d08e158cf28b112d9a269fd848c3a0bffa57c8bee9bba481a6c1e8d5f70f2ffaf750e2f3fa395c99479159770b284ae35be99
DIST NVIDIA-Linux-x86-390.157.run 49417041 BLAKE2B 435b5e0e60468cc74b41cc5d9b5bb0105d29c11a2d408457835212a96519c9334ecf19278b36749d3ff7f498f5b0ae45a2efae2d428703dac21245c62f1efebe SHA512 dae9ac2c12f9ad90f7441e00e01a984147c577892421911d7f67f6a31e616ac1cb7d434bc9c7f58fbd9b8ae909521b5bece607a63c79588c0bb9d99c6bad5fb0
DIST NVIDIA-Linux-x86_64-390.157.run 85835541 BLAKE2B 44b855cd11f3b2f231f9fb90492ae2e67a67ea3ea83c413e7c90956d38c9730a8bd0321281ae03c6afce633d102f5b499aed25622b9bfd31bdd2c98f0717e95b SHA512 4780503a4cff0180b1b1f37d20a6ba3438dd78b51fa7f69b98d35521835e5d61099129746929d51d63afa2d47b672b3e145e1e1897584dc3799e7f822c5b3a0a
DIST NVIDIA-Linux-x86_64-470.256.02.run 272850014 BLAKE2B 0fdc867f92b82b2a60810c3b43751cad7ac2c39928c92c6c343c0c6044f4d7d923d93b8599db3f7c999c0ee7d16940e65d991a61cbb30e1d9e49c5639ac6bdc8 SHA512 a837946dd24d7945c1962a695f1f31965f3ceb6927f52cd08fd51b8db138b7a888bbeab69243f5c8468a7bd7ccd47f5dbdb48a1ca81264866c1ebb7d88628f88
DIST NVIDIA-Linux-x86_64-535.247.01.run 341853459 BLAKE2B ef91097a36add821a623c8d1f19eca8ca9571fe4a08b8e25eb70f09923899bcb3bd2c0f408dd6ff045ffdccb192be3a46cec4fd7b7d8d7bc17449c436cc2cbde SHA512 f8e04e5f7cf8b7fdae9135cb5f0f2740d5eae0ef9a44a41dbf78996d3c2d4139bdbec99be14f73aa2d275d78658b4a91a274f20545e4325cef787548e3d073a6
DIST NVIDIA-Linux-x86_64-550.163.01.run 307143336 BLAKE2B 256106bcd3bace402289e60aca4cd3b447d0fd8ec3dabd50e2bb303c5e866f8da5c28f9b578d95775bf69158f100d68a91d20d9a91426285a8e799817f21db6b SHA512 676b1de35d21e80091528a49080c114e0870ea90b3f3721265ae8071abbc2183c851e6f11ba96a332c743fedfaf4ec9a014ad6ceed586fdbb03d94d33405e356
DIST NVIDIA-Linux-x86_64-570.123.07.run 375974099 BLAKE2B b1cacbdcda8e335cd57db21a379ba4506341d10f26f7485f3d776f3f2896ad12ea5eac2d350e1e9149405d916fd088f5d19341cb15b52077b7e595793c0b1f5e SHA512 7745bb228f80015c9f1ba09c731cea47a148ab38e39a723d4a5d5a89611e705811da7f290cb73617b29607f16b8add94b0b146e17d13bdf00dbfc04be74f8db5
DIST NVIDIA-Linux-x86_64-570.133.07.run 375774798 BLAKE2B ddfd8e8e58453f8cbd2bec55af4a9f9030510f5b1685f3daf8c446d32fd96b6c71587d98f1f7cf049c4a0dbd74a27b2dcf2b532d4f5faa05793c779076c2b122 SHA512 f7c2de3b4242a50a5fc5cb7c6eed6677bbf28e3b157dd22ced385822d8a42df351c7ead039d37cc5b18251971a8496539f4448e2cd8d297303f4e89db16feb13
DIST NVIDIA-Linux-x86_64-570.144.run 375742470 BLAKE2B 8611e5d7a5043c18d1ef122c62d2a4efed6dcdec343c7a519778c603f2ddc5186b479af1b09277b47c92af9e6021dedca33e02fb3c7f3096d4dea18acfb2c9d1 SHA512 f0d6a8377cbcb38a4a0491a654d3ed86082ac5609129a247daaa455bd7cffbad0be579db2ba9448a9f0ebc7cf36459d640f03ecbe1f25e8e47f3990f78989c97
DIST NVIDIA-Linux-x86_64-575.51.02.run 386859216 BLAKE2B c6c47095226b1a9535b0f005bd8dddff772516738c168ff2bb577c75769ef1e216cde5f83a5979dfcc9ce6876d2e112afbe86f52d02721ec0a230eff9aaffeb2 SHA512 0354f4d46a2de8be670a3fa58ec255b8673c40c51fea9ca594aa3ddab936b50efb91cecbb93f14ac4a8ed87e7c3e101b4d643721602d22135f9259dad94a5c12
DIST NVIDIA-kernel-module-source-535.247.01.tar.xz 12517152 BLAKE2B b12497621ba32da4ca80ca6736d559bc98ba45974e06bbb63c08695c3b24c45752b3fd3dc2854ed64950e89e99b38d1006ce672096e35daced0ebe0a9dda77f6 SHA512 ed8e10d5245447fcdf348509ad62e9ac3d56a052d254b764e3a574a711cfa5c8831a759d425f42795c2db752f3d91d60b6097f6901c88654f242c94768faddb6
DIST NVIDIA-kernel-module-source-550.163.01.tar.xz 13552400 BLAKE2B e1fd753127d10097c5f1d3c90d95c7eb0934c0d5e1df0a371aed2a0d7669960b67c46eed20eec3c42ca41c0f34bf6d7d3d2a77a94308c9f86d4f5d831da19363 SHA512 c9f4ce2890db3fdc66dd080da4d6802a8bc3b18feba96be5d33641b02cca637b1bcd2a3748f36f93a32f26ba57eb352156314f139688b0d3a102efdfde6c32ba
DIST NVIDIA-kernel-module-source-570.133.07.tar.xz 17934788 BLAKE2B b78e9e8bd6f5dbfe4bf7121be502922454446f4ebb2201d40d3f0b1d5a0819b3eea255a49ab661d75e10b0ee296940db1b2ff2b3156aa0f98ec810a472d93290 SHA512 84d9798cfbe7b125ce48935b651d51f15c876a0dbc57d2da10994f291942755f5df05b265d16eed924f83dea1732bc2a5c05efc520e00a5fc05afbb4a7198742
DIST NVIDIA-kernel-module-source-570.144.tar.xz 17900228 BLAKE2B 9003530642f17f8ee61599716d7981fa8326c6b3c38aa84c4a9056894f3e1f06da211eb1383b84c9871a612e8e4081af8112584b185820b6c1aa446d2b5a7935 SHA512 761561fbc7433815fae79644c2996b8894edbc8158fd53ab81a143e869b0ae832a965bd7dcfe5f54db0f1b8e06ae1a02a921b7657d4fbd76a4fb252f39cef427
DIST NVIDIA-kernel-module-source-575.51.02.tar.xz 18222252 BLAKE2B 861a00236dfe26123e441a311ad0e28cb555329ef79257be24fadcbdfb9409e8aca94086c18988c2e5a24e2146d80647aa0ae5aa13301ad76cd51bec7bb26926 SHA512 c25f449b739168b2e1a7113e3c437455f646f37a95274605e1b06ea36e83fe6f74325fbb09df975092c8bbd492e089b80686162412720c0b1ea14e7551ef441e
DIST nvidia-installer-390.157.tar.bz2 150323 BLAKE2B 8058ca87a6dea956d564af9f7eab9b1fc82b1f2382bd5cb2f6d97cbe2e19292533522d5f8f2eacbeb16520372715fcb72f8f9b0998962af5d4e75522c8d74524 SHA512 93a7ece648602157496c8e27a88864ede341a100f5328a4c1a25faf8f0b94d252060e5e2f71d0c302fd0566c10773c30b76b3b5f431d8039b71c90a7969f7d7e
DIST nvidia-installer-470.256.02.tar.bz2 146269 BLAKE2B 4402e725c8fd0157eb84d4ec140a33f97e873014577487ef1e32fb8921cabe79c60ff46532e5bfaabb2b6ac894f7c80086dbab19e61906e2e27346fb85f98829 SHA512 c962dc17d9696256d1ebedcaeb3010994f2ce3895aedc47987599ebfec132a9b9a249d2ece6502b15bd4a93f9b0106aa13487a7da5f64199c274ce11eba27cfd
DIST nvidia-installer-535.247.01.tar.bz2 148887 BLAKE2B 3455f064d3a5745971e8ca6574bfe16258544e669f05fa6e1f31cc88a7224f76cbf5d1ea26a62e70e908b7261c3264664e090209221a6e64030c6f486b9452b3 SHA512 be97915091e60c56b442dcec45f76380ab316e95b7417d99133419a7883e1cf547ac0c03d7e763574613dfe5bc27dbc6c887ed9870e528ae056b2400175044e4
DIST nvidia-installer-550.163.01.tar.bz2 155861 BLAKE2B 662064b3ceb4aadebde419057d85c6b4e28b91944bd5bab241bcba9b3c9a105e507afc7651b17fff01e1cccb78d66fdc6789597ce059f882a6f322b08f28e832 SHA512 f8df7a0eccdecb7d4d4f47d96050cdbefff91289b29550b061358614845648451d4b161d9bdbfbf5a9a87ce650d272cb3b795e6d2ed4d0274844a56db097bd15
DIST nvidia-installer-570.133.07.tar.bz2 169618 BLAKE2B b56a892a68be77c0b1b9f8d348907557a4f09e68a9aab22de27bd211a539a2beba4c1bbe7f34820f3c70cc93832cd58439d9c2a5b09e0263e203260d22ef3573 SHA512 4603b9661cf7844eca0c49777e50f992b22933a6f28c810d238f3e4da5d755da19d1593beeaefdb671ac397c6c506716c9de40bbfdb2c20fb1c6c2ad83881b87
DIST nvidia-installer-570.144.tar.bz2 169317 BLAKE2B 8238feeebd61c1ae37bad82ae6801aaedddc2b861ca4c2eccde7c5576f82baf14969b8acaf4b0e922ebae218201d47190b6e9b3ff1ce264857ae58586b2df7b0 SHA512 2201cf95bb2f69067e3a2f555877b46ded5cd46e8f91e0adb100adaed03df1de7eae15bf593a8834516d62a029f81793c5d5406a314551039115f601bda1a465
DIST nvidia-installer-575.51.02.tar.bz2 169435 BLAKE2B d19432f65d94da9929c3aee2e3aa734b1c542f6d0e5c23a97b8387409e552dbbfef1a4570bea5ad0116d2ccf1c3cc0d8805e89b561caf16c1e78de976732e007 SHA512 097f5692ea7a2fc8e5a60f68589c00cc29de0ff947284b23765c4dcb1892e502d2922d2ee259d7af5b5c6a5f0fbf38f89a085f5a47f5115c8623afa4893c3dcd
DIST nvidia-modprobe-390.157.tar.bz2 35306 BLAKE2B 80d202b39c2f95ec0f909712c2e101483af50124092c32efb33bd98ff58ddfb97b737ff07f1ddc941f688c1b4c26a15f392566d522e18506771f10422fcd571c SHA512 109bbe24a3758b568ea65fe1e9d78f69fae6108ec0497b796c885a3912825fe04ffd7389a3e22987f1a10a2926bf6eaa384faabc59478aa3ee244dd3ac91c6d3
DIST nvidia-modprobe-470.256.02.tar.bz2 38769 BLAKE2B 0db444b09b0b6d24c04877fae95249e781d82b3141f90eb05d869b64d2b6e65ad00bf44c4e427c64dbd4765fa99a8699f80a1d95b00c66137a54dc878d7ea298 SHA512 c1cbfa6c8e188e5a5eb5d390b9a903406cbff103d212fc30e611e4023be3fde896ad84e8bb45b030beb5d1bcd8155c9e55a8f9636c45ce1e2a5c03f672989a31
DIST nvidia-modprobe-535.247.01.tar.bz2 40736 BLAKE2B 31172b50777fb0bcc7696af660fd4f8ddc42bb126ff42edcee12097fe37748727c6357ef46b65a96004345fdc501487f8b5ad89eccef991eeb3c83e958f41a09 SHA512 f28340f935804e3cb07d394ad103b296a5e4fbfadeef7905266b85afd7cd145de033d603a4bd7947348add23a866548605264c814b48f4f6a5a1f4254f82cdc1
DIST nvidia-modprobe-550.163.01.tar.bz2 41448 BLAKE2B 23e567d612e669ec6ae9f389651c9e1cebe7ba59ee95bb5961e5071952697860df77f02026040e29135338eb7cf96bba0015b3d94548297235fb5214f35bec48 SHA512 0f5b59468a6e5e95dcdef1d938ea78f4ce09a0c9784e3c70d83f1c3b1bd52e8055b6b332147316445c3be714abab3629320d6117878d50aa7a2d7d2d9b9b6485
DIST nvidia-modprobe-570.133.07.tar.bz2 41633 BLAKE2B 49e541fdf2c7f89689da298cdef3dfcc510bd7bfe5b53b19c1e49e526f5e5018f24271d5991e5dd6d6d4c27e2645df7908376ffefca56c73ce9e5935560e6d18 SHA512 c447ea50df0e8ab8a765378007a96a5a1897f20c3c8ad5c9a3d4271a859177ae39bc82bd041182dbe7f5a752ab4bd3bee459905a27e37d136faa7cd6c00a7100
DIST nvidia-modprobe-570.144.tar.bz2 41634 BLAKE2B 212578e8a49aa482524cb9da7a60249b88e9a151e19eb64b2e8195883f26476db3bb2859b2df3307a5281311311c22f24fdf2ae7019e9a2a07363b1ebef22b7c SHA512 56c7d8d0b8419d61676f4a9f9ab8b0592bb8f341b54bded42949bcdd1face39a264253a9f391e8f69b3c07631aca457a5c98ccf6b66eb8a9de3df4335f6c34bc
DIST nvidia-modprobe-575.51.02.tar.bz2 41686 BLAKE2B e70363c8ef8b4c30105a77cc66a70108d709458644cce2fbde08fe735156d1b10b48797a24022f4133c65307e10c108b0df2a0abfc6b36bfe591efea8dd0ff5c SHA512 89b53aae61e0d92d5b7821afa391dbdf1e769d0be4bebc8df01e593a6100496cecac71c34205737aae1cd09cec6fadb3655dd1f495a364feea0f45100aa1d4b4
DIST nvidia-persistenced-390.157.tar.bz2 48654 BLAKE2B 2cf6c92da90acff55e8c180a06b0c6a29d48be9fd8ca3c541202fd14f0697220fba6b66452942aa7ae7cc8821f5c5eb9fa8f7a31d2248624e5f9141d83a176b8 SHA512 70f0707ed6f2b877e69ef90cf782f66cbc9d2071db53ca09ceb7b89427b0fe176708517340621fa251539b7d481b238adeeb60261674eed74de1f62db6dbb72e
DIST nvidia-persistenced-470.256.02.tar.bz2 46567 BLAKE2B 8f837322a3b88412fd2f6acf38721b49a6cb444fbd842d652519e5596f2e545d8f06bbdf017f46a22301ce87455f96147fab2829ca5fbf26131ec3e4a772e282 SHA512 4fd19258649b7d39945fb5c8578bf11ab118617dd14f3d11cdf15cb3fe77daf7b4719e4ae57af59031b1b809d02f4e8e8afed0ec60b9d0aed4d2488bd3013cd9
DIST nvidia-persistenced-535.247.01.tar.bz2 48589 BLAKE2B 1b641fb85fb74e5314c0f525361cba23ac08d5f6570bcd9a6d89b376497bd0aa1cbbb52fe391a8f7bf41734e49d46d464440573b0298b5c0fd5db7fcf3100d58 SHA512 be23e7790d582a340e14c7df16f9ed09447ef8efb352d8b8e53e5be91b624953d8237c988ce0b0b0c90e1b15077af7efd6c6a0e628345f2188b6dbe09122373b
DIST nvidia-persistenced-550.163.01.tar.bz2 61450 BLAKE2B 1a11cb89981b88f8d14558227d9493f1f8a81ccb5502002c436e9311a38c9c8fe0402c65eac1517a2893985eec07699b2e7bc7a81aa14dc0d52198ac85a2cd1b SHA512 f17dbcafa917b5b450f7665f98fd24f06ad99e6bcd1fcf42ef95aa9337b55561b7b16eaad8fa408110d08ee7e6d812444792cccbb9c92865099891832da779ce
DIST nvidia-persistenced-570.133.07.tar.bz2 61946 BLAKE2B 4e4082b1ddb095132579366f9cc7585ee9d33f972f7a1176475622e0b2e7334aa87cc7cfdc6ff6c7e18d2da28d89e36ab3fb84d734d2b33826c7902e0c41cfdb SHA512 6274287a9dbd23e9b9fbf39b1a30d3830a0088e204ba65fd4d37db33027c8a58b4b7edd817190031736711e33978c15f2a0949ecf190a72d62fc846860dde1c8
DIST nvidia-persistenced-570.144.tar.bz2 61930 BLAKE2B 5839812070626045f492803238fbb9989be2f43d0c8e98bf79716d7fc6f0561142578682c850aa423d707ee6f9922f1bb3673826573a9d037616173324adf4f9 SHA512 c08a261fd0158a0b2fd77de3c2b32ee99034dd1ad064b0693a07545c7b7f9cbedab21de80c03488f1762323bb4e4644e6c5c3b838cf2b3d977c1244563af829b
DIST nvidia-persistenced-575.51.02.tar.bz2 61975 BLAKE2B 51c345184fd79a16db3fa29d897ea511ab20b24c9d1587128d232d03f66555c6b3ba029319f9c9f740a8f401ebff4d878d7695c4de445def42601b529195e4ba SHA512 467b1180c894e20019a975de828db6d39088be6e98fb80e367a8285b2e13eb3ceda70a2c4deba238567794631e5ceb54f2daad617d75effe66d225f04f3bf33d
DIST nvidia-settings-390.157.tar.bz2 1108938 BLAKE2B d9ec1ab5d7f157d74627272adf752a671dd17e2ede02069437b6180b927fe315b15cc6416d584ab2f038b76fe01e5b64514a834f24d88ac16676e55205fdecdd SHA512 b16699009bf56a1ff3b623a528c58061c4f5a2c5c4a373756a07bcd667743a1df7c733a572d2d0baa835a904ac2fda8a5c85890dcc00c3a0f223e0467aea902d
DIST nvidia-settings-470.256.02.tar.bz2 1062273 BLAKE2B 8e66201e7861469b12932595ef8f9fd29d4cfd570c2576ae7fbb7383f61c55ac71fe721cc431e79d6d69f86d998b5b4c3cafe531b573f439e6b499b0fc047a19 SHA512 626e66118ae2e62eacfdf44e37529c409b945a6f33637b9690d74abd87a2afb581aaca5f90328d280da99ceb659959d0e5dc5c22ef8013b2205b2b1c72e08007
DIST nvidia-settings-535.247.01.tar.bz2 1094617 BLAKE2B 26a12ea76be9ab930553fcdd0f19db1de8e8fd41a5f180a09f418bdbec38aab6f05c019a85249de3fe523df4aba6ffd339ccce4758e739fe092ecaaf25fb5008 SHA512 9651cc907fa78139f4774764132f5a46c1feee016aae021905a463100f102e6321b79c2c4f5b1fe149cde481a5baac17017770244ad35c6d7f14e7975f23a7c9
DIST nvidia-settings-550.163.01.tar.bz2 1099317 BLAKE2B 25419c1796deeea238b3e44fd8d648a8627272565be40cb0745132cef1c16e0c422242a1e6369745d577e674a68bf9dfc3c009e281a84ba58db5429d97ac9cff SHA512 5306ab05f284ba06852d7c96ff62ded7b8b615d3a002009cd5d781fdad716db37f53d1c8a43337ada60d524b4f7d183d98ad2673f40a5ca1ca4c5112bb913e74
DIST nvidia-settings-570.133.07.tar.bz2 1123730 BLAKE2B 1b64f8fb19ce68bbda3a14a0ad440b305c4772bd385f792d83e8d2f4928b6dca9184b6dc1412862ce604002a6db939aea48ff7a0e115b07b7e20e051086dc2b9 SHA512 cd715cfc26c42bdb52e4a33f2e868068a0495d25db3e29180e6b21afb2bcfb319961f5ba3c486e085791825c1107028d3ff0cc334c82ae3f6bc9fb1e8f84d727
DIST nvidia-settings-570.144.tar.bz2 1123525 BLAKE2B 02cd0624b3b34ed05c72f6aa5fd0eec8ee75759297324d47dfb17ad0c935c5ce25835720405f65096dee88cd633501346d1dc1b5958ae65b8573e3f5c59111dc SHA512 71caea01dee3fab5b2f28ff27bbc886688b40f6a2298c73367d1819441ac52e47fb93caa27917962f9a6a2d97b5f7967a6db27834e1fec3acb4f80cc00d14baf
DIST nvidia-settings-575.51.02.tar.bz2 1127839 BLAKE2B c88bcf089a68f6a33ad230107f018bb3ab7ab6c526685d6a1ddf0902b354c2f443d8e96a9f2549005ea276633654916d0bab8fb89c3ca83818177c8da2b46f8d SHA512 d10c548637ff38e6cfc4dd577cea19bc1c4dba3b3d475dc0affdfa211a50d0e80f75d060230c56a003dc3741b9fee6d70ef7d91d9be36d2e53b47ab7be9d1fe4
DIST nvidia-xconfig-390.157.tar.bz2 107399 BLAKE2B 0cbb3b1ba508ddc3ba4a161c290b31bf7a67f67880bdbd01171a962c5fa97ca945b1ef17932403f8589309380743f1da632c728d8accb6d4e56dbd895e7486bb SHA512 50b390811c9bf091b14add41f886925b17496b41006b7d3981d2398caa65cf5db8a579c8cebed78278384bf3acc629befb07b54339c61abcc75852c0dcb8b8ca
DIST nvidia-xconfig-470.256.02.tar.bz2 108698 BLAKE2B e468574e4bc57e7279d4120e2b08a201671b50d408be0c530eabe5da7d45daaf21cbf5c7fa31410d0d732fe8ea1551cbfb21d1ae193c1b3f5b5c50c764c9e236 SHA512 9dcec1e0c2b56b4d38a5f2c76086302f8bc0860cc15012cce29c3a5062f801a48b6a2bb78344361b07a2717b58502783441a2daf402d9973a17526175b1f15ca
DIST nvidia-xconfig-535.247.01.tar.bz2 110621 BLAKE2B 3d567d30e19dfc449e23c80e6fe25536f02e2450bb82c4cdc2b508493cad6d6b4f58467d302fd64a8b37e8a129be4c04b365ec3e4e9f18966d25cd23c6adc91c SHA512 2748aa9997e84e0f39b52bc6f49e2b53ffa7181aaf0ce5b9d06d8e6e010ecd589ee77388807d922c3be4a847b8a4e9e1eeba42c905a32ebb5d3f9b93d6f30511
DIST nvidia-xconfig-550.163.01.tar.bz2 111149 BLAKE2B d19ef0427e3432798e674dc66447090e8fb8fcb549ebe27aaee19aa38294cf178e175a067b2da5313342c93ea2aebef35861d05cc4cc0ee2c3eae955b3ddbbb3 SHA512 35f95d85928c82bc5de8e462ca5e90a6d8fe03e5b5367b9cdaadddc1e956f0d26b6dc42e716ae7c88512afdfb98cc841fe9b22846f6d6acc578c5dba4d0a16e1
DIST nvidia-xconfig-570.133.07.tar.bz2 111288 BLAKE2B 2dca752e735440c989826ca42a1c13a73084c6589ecbed1bb24bd139ddb2d11f1ce3c8f6523f8902464ebd80a3805435f694678c5a9c70f0027cd1ab8096249f SHA512 5f5ff4da84b76707e051d24b252f809f8d5feadea442156aa9c52c2be61c818144f245bfc1fc5b31c9051ee7a9164cf922e86a01e3ffb1d129c45e790aca705f
DIST nvidia-xconfig-570.144.tar.bz2 111243 BLAKE2B f7c9cd692665ef563238fb8cd1d2294b4b9acab6b082c8541ed24f6cdbb3f5466a1fa0b7be06d51ba1c87648cc8d0fecc1137d898844c80a0ba0fba8dfe43bad SHA512 9d38abf935dbce8d50d7d758a543e2ac4ba278a527a4dd6d167551a2ed11bbe17c3290a51f59f6a0e3611cd8e3d695efd09e9dab4aab748bdb70320c8c9d2f0c
DIST nvidia-xconfig-575.51.02.tar.bz2 111328 BLAKE2B 5df501db6e5fd669e7dbfdfed1c18cd85122fcb587256a0f4cd46c58fab10e13553769f4178775bbbf3d347bc522476b59c9b7d7973098b274494727eeef2c1f SHA512 8135924a0e1ce8c7444fcfa0f52fe666c55b4b1c92c8fb7ecc67de803b8e23b854b2b367942f8c13216503774ed86e2b287ad7251473b91e4d2e4ee91d184d74
DIST open-gpu-kernel-modules-570.123.07.tar.gz 18658818 BLAKE2B 5228a09fa88d17ed2881838b5904eab8be1bdee6b37f01a4aef92e33ddf7f06040f3addbce5b70d2b4901f8b24ee4dbc349dd88ced6f248c90f840be2c217f27 SHA512 5c17574aa90b7a6be9ca4412400ff12b1f671258bee9176e078fe1a66f323381fa47ccb113387bd9eda118e36de0a806ae69ae06991329c31347488268b48d33

View File

@ -0,0 +1,2 @@
#!/bin/sh
/usr/bin/nvidia-settings --load-config-only

View File

@ -0,0 +1,21 @@
# NVIDIA drivers options
# See /usr/share/doc/nvidia-drivers-*/README.txt* for more information.
# nvidia-drivers and nouveau cannot be used at same time.
# Comment out the following line if you wish to allow nouveau.
blacklist nouveau
# !!! Security Warning !!!
# Do not change the DeviceFile options unless you know what you are doing.
# Only add trusted users to the 'video' group, these users may be able to
# crash, compromise, or irreparably damage the machine.
options nvidia \
NVreg_DeviceFileGID=@VIDEOGID@ \
NVreg_DeviceFileMode=432 \
NVreg_DeviceFileUID=0 \
NVreg_ModifyDeviceFiles=1
# Should be no need to touch anything below.
alias char-major-195 nvidia
alias /dev/nvidiactl char-major-195
remove nvidia modprobe -r --ignore-remove nvidia-drm nvidia-modeset nvidia-uvm nvidia

View File

@ -0,0 +1,33 @@
# NVIDIA drivers options
# See /usr/share/doc/nvidia-drivers-*/README.txt* for more information.
# nvidia-drivers and nouveau cannot be used at same time.
# Comment out the following line if you wish to allow nouveau.
blacklist nouveau
# Kernel Mode Setting (needed for wayland but is hardly usable with legacy 470)
# Enabling may possibly cause issues with SLI and Reverse PRIME.
#options nvidia-drm modeset=1
# Suspend options. Note that Allocations=1 requires suspend hooks currently
# only used when either systemd or elogind is used to suspend. If using
# neither or have issues, try Allocations=0 (revert if it does not help
# as =0 is not recommended).
options nvidia \
NVreg_PreserveVideoMemoryAllocations=1 \
NVreg_TemporaryFilePath=/var/tmp
# !!! Security Warning !!!
# Do not change the DeviceFile options unless you know what you are doing.
# Only add trusted users to the 'video' group, these users may be able to
# crash, compromise, or irreparably damage the machine.
options nvidia \
NVreg_DeviceFileGID=@VIDEOGID@ \
NVreg_DeviceFileMode=432 \
NVreg_DeviceFileUID=0 \
NVreg_ModifyDeviceFiles=1
# Should be no need to touch anything below.
alias char-major-195 nvidia
alias /dev/nvidiactl char-major-195
remove nvidia modprobe -r --ignore-remove nvidia-drm nvidia-modeset nvidia-uvm nvidia

View File

@ -0,0 +1,38 @@
# NVIDIA drivers options
# See /usr/share/doc/nvidia-drivers-*/README.txt* for more information.
# nvidia-drivers and nouveau cannot be used at same time.
# Comment out the following line if you wish to allow nouveau.
blacklist nouveau
# Kernel Mode Setting (notably needed for fbdev and wayland).
# Enabling may possibly cause issues with SLI and Reverse PRIME.
#options nvidia-drm modeset=1
# Enable experimental framebuffer console support (requires modeset=1 above).
# Replaces efifb, simpledrm, or similar once loaded (emphasis on being
# experimental, "may" cause issues X mode switching, sleep, or more).
#options nvidia-drm fbdev=1
# Suspend options. Note that Allocations=1 requires suspend hooks currently
# only used when either systemd or elogind is used to suspend. If using
# neither or have issues, try Allocations=0 (revert if it does not help
# as =0 is not recommended).
options nvidia \
NVreg_PreserveVideoMemoryAllocations=1 \
NVreg_TemporaryFilePath=/var/tmp
# !!! Security Warning !!!
# Do not change the DeviceFile options unless you know what you are doing.
# Only add trusted users to the 'video' group, these users may be able to
# crash, compromise, or irreparably damage the machine.
options nvidia \
NVreg_DeviceFileGID=@VIDEOGID@ \
NVreg_DeviceFileMode=432 \
NVreg_DeviceFileUID=0 \
NVreg_ModifyDeviceFiles=1
# Should be no need to touch anything below.
alias char-major-195 nvidia
alias /dev/nvidiactl char-major-195
remove nvidia modprobe -r --ignore-remove nvidia-drm nvidia-modeset nvidia-uvm nvidia

View File

@ -0,0 +1,47 @@
# NVIDIA drivers options
# See /usr/share/doc/nvidia-drivers-*/README.txt* for more information.
# nvidia-drivers and nouveau cannot be used at same time.
# Comment out the following line if you wish to allow nouveau.
blacklist nouveau
# Kernel Mode Setting (notably needed for fbdev and wayland).
# Enabling may possibly cause issues with SLI and Reverse PRIME.
#options nvidia-drm modeset=1
# If modeset=1 ^, NVIDIA will handle the console/tty display and
# allow overriding DRM devices such as simpledrm. This is a default
# since 570.x drivers but has been known to cause a variety of
# problems. Given efifb is more typically used on Gentoo at the moment,
# it is not *required* here and is safer to be disabled for now.
# Comment out the line if you need it. https://bugs.gentoo.org/949097
options nvidia-drm fbdev=0
# Disable use of the GSP firmware which has newly been enabled by default
# for GPUs that support it (Turing/Ampere+ GPUs, aka GTX 1650+). Not
# recommended unless experience regressions for which disabling helps.
# Cannot be disabled if using USE="kernel-open".
#options nvidia NVreg_EnableGpuFirmware=0
# Suspend options. Note that Allocations=1 requires suspend hooks currently
# only used when either systemd or elogind is used to suspend. If using
# neither or have issues, try Allocations=0 (revert if it does not help
# as =0 is not recommended).
options nvidia \
NVreg_PreserveVideoMemoryAllocations=1 \
NVreg_TemporaryFilePath=/var/tmp
# !!! Security Warning !!!
# Do not change the DeviceFile options unless you know what you are doing.
# Only add trusted users to the 'video' group, these users may be able to
# crash, compromise, or irreparably damage the machine.
options nvidia \
NVreg_DeviceFileGID=@VIDEOGID@ \
NVreg_DeviceFileMode=432 \
NVreg_DeviceFileUID=0 \
NVreg_ModifyDeviceFiles=1
# Should be no need to touch anything below.
alias char-major-195 nvidia
alias /dev/nvidiactl char-major-195
remove nvidia modprobe -r --ignore-remove nvidia-drm nvidia-modeset nvidia-uvm nvidia

View File

@ -0,0 +1,29 @@
Kernel's makefiles pass -Werror=strict-prototypes which
can trigger errors depending on compiler defaults.
https://bugs.gentoo.org/870238
https://github.com/NVIDIA/open-gpu-kernel-modules/issues/377
--- a/kernel/nvidia/nvlink_linux.c
+++ b/kernel/nvidia/nvlink_linux.c
@@ -639 +639 @@
-void * NVLINK_API_CALL nvlink_allocLock()
+void * NVLINK_API_CALL nvlink_allocLock(void)
--- a/kernel/nvidia/os-interface.c
+++ b/kernel/nvidia/os-interface.c
@@ -879 +879 @@
-NV_STATUS NV_API_CALL os_flush_cpu_cache()
+NV_STATUS NV_API_CALL os_flush_cpu_cache(void)
@@ -886 +886 @@
-NV_STATUS NV_API_CALL os_flush_cpu_cache_all()
+NV_STATUS NV_API_CALL os_flush_cpu_cache_all(void)
@@ -944 +944 @@
-void NV_API_CALL os_flush_cpu_write_combine_buffer()
+void NV_API_CALL os_flush_cpu_write_combine_buffer(void)
@@ -1073 +1073 @@
-NvU32 NV_API_CALL os_get_cpu_number()
+NvU32 NV_API_CALL os_get_cpu_number(void)
@@ -1080 +1080 @@
-NvU32 NV_API_CALL os_get_cpu_count()
+NvU32 NV_API_CALL os_get_cpu_count(void)
@@ -1155 +1155 @@
-void NV_API_CALL os_dump_stack()
+void NV_API_CALL os_dump_stack(void)

View File

@ -0,0 +1,84 @@
Kernel's makefiles pass -Werror=strict-prototypes which
can trigger errors depending on compiler defaults.
https://bugs.gentoo.org/870238
https://github.com/NVIDIA/open-gpu-kernel-modules/issues/377
--- a/kernel/nvidia/nvlink_linux.c
+++ b/kernel/nvidia/nvlink_linux.c
@@ -639 +639 @@
-void * NVLINK_API_CALL nvlink_allocLock()
+void * NVLINK_API_CALL nvlink_allocLock(void)
--- a/kernel/nvidia/os-interface.c
+++ b/kernel/nvidia/os-interface.c
@@ -879 +879 @@
-NV_STATUS NV_API_CALL os_flush_cpu_cache()
+NV_STATUS NV_API_CALL os_flush_cpu_cache(void)
@@ -886 +886 @@
-NV_STATUS NV_API_CALL os_flush_cpu_cache_all()
+NV_STATUS NV_API_CALL os_flush_cpu_cache_all(void)
@@ -944 +944 @@
-void NV_API_CALL os_flush_cpu_write_combine_buffer()
+void NV_API_CALL os_flush_cpu_write_combine_buffer(void)
@@ -1073 +1073 @@
-NvU32 NV_API_CALL os_get_cpu_number()
+NvU32 NV_API_CALL os_get_cpu_number(void)
@@ -1080 +1080 @@
-NvU32 NV_API_CALL os_get_cpu_count()
+NvU32 NV_API_CALL os_get_cpu_count(void)
@@ -1155 +1155 @@
-void NV_API_CALL os_dump_stack()
+void NV_API_CALL os_dump_stack(void)
--- a/kernel/nvidia-uvm/uvm8_lock.c
+++ b/kernel/nvidia-uvm/uvm8_lock.c
@@ -312 +312 @@
-bool __uvm_thread_check_all_unlocked()
+bool __uvm_thread_check_all_unlocked(void)
--- a/kernel/nvidia-uvm/uvm8_perf_heuristics.c
+++ b/kernel/nvidia-uvm/uvm8_perf_heuristics.c
@@ -29 +29 @@
-NV_STATUS uvm_perf_heuristics_init()
+NV_STATUS uvm_perf_heuristics_init(void)
@@ -44 +44 @@
-void uvm_perf_heuristics_exit()
+void uvm_perf_heuristics_exit(void)
--- a/kernel/nvidia-uvm/uvm8_perf_prefetch.c
+++ b/kernel/nvidia-uvm/uvm8_perf_prefetch.c
@@ -462 +462 @@
-NV_STATUS uvm_perf_prefetch_init()
+NV_STATUS uvm_perf_prefetch_init(void)
@@ -500 +500 @@
-void uvm_perf_prefetch_exit()
+void uvm_perf_prefetch_exit(void)
--- a/kernel/nvidia-uvm/uvm8_perf_thrashing.c
+++ b/kernel/nvidia-uvm/uvm8_perf_thrashing.c
@@ -1324 +1324 @@
-NV_STATUS uvm_perf_thrashing_init()
+NV_STATUS uvm_perf_thrashing_init(void)
@@ -1401 +1401 @@
-void uvm_perf_thrashing_exit()
+void uvm_perf_thrashing_exit(void)
--- a/kernel/nvidia-uvm/uvm8_procfs.c
+++ b/kernel/nvidia-uvm/uvm8_procfs.c
@@ -61 +61 @@
-NV_STATUS uvm_procfs_init()
+NV_STATUS uvm_procfs_init(void)
@@ -77 +77 @@
-void uvm_procfs_exit()
+void uvm_procfs_exit(void)
@@ -106 +106 @@
-struct proc_dir_entry *uvm_procfs_get_gpu_base_dir()
+struct proc_dir_entry *uvm_procfs_get_gpu_base_dir(void)
--- a/kernel/nvidia-uvm/uvm8_push.c
+++ b/kernel/nvidia-uvm/uvm8_push.c
@@ -103 +103 @@
-bool uvm_push_info_is_tracking_descriptions()
+bool uvm_push_info_is_tracking_descriptions(void)
--- a/kernel/nvidia-uvm/uvm8_tools.c
+++ b/kernel/nvidia-uvm/uvm8_tools.c
@@ -2041 +2041 @@
-void uvm_tools_flush_events()
+void uvm_tools_flush_events(void)
--- a/kernel/nvidia-uvm/uvm_common.c
+++ b/kernel/nvidia-uvm/uvm_common.c
@@ -63 +63 @@
-bool uvm_debug_prints_enabled()
+bool uvm_debug_prints_enabled(void)

View File

@ -0,0 +1,110 @@
Kernel's makefiles pass -Werror=strict-prototypes which
can trigger errors depending on compiler defaults.
https://bugs.gentoo.org/870238
https://github.com/NVIDIA/open-gpu-kernel-modules/issues/377
--- a/kernel/nvidia/nvlink_linux.c
+++ b/kernel/nvidia/nvlink_linux.c
@@ -571 +571 @@
-void * nvlink_allocLock()
+void * nvlink_allocLock(void)
--- a/kernel/nvidia/os-interface.c
+++ b/kernel/nvidia/os-interface.c
@@ -1076 +1076 @@
-NvU32 NV_API_CALL os_get_cpu_number()
+NvU32 NV_API_CALL os_get_cpu_number(void)
@@ -1083 +1083 @@
-NvU32 NV_API_CALL os_get_cpu_count()
+NvU32 NV_API_CALL os_get_cpu_count(void)
@@ -1136 +1136 @@
-void NV_API_CALL os_dump_stack()
+void NV_API_CALL os_dump_stack(void)
--- a/kernel/nvidia-uvm/uvm_common.c
+++ b/kernel/nvidia-uvm/uvm_common.c
@@ -37 +37 @@
-bool uvm_debug_prints_enabled()
+bool uvm_debug_prints_enabled(void)
--- a/kernel/nvidia-uvm/uvm_gpu_access_counters.c
+++ b/kernel/nvidia-uvm/uvm_gpu_access_counters.c
@@ -1527 +1527 @@
-NV_STATUS uvm_perf_access_counters_init()
+NV_STATUS uvm_perf_access_counters_init(void)
@@ -1538 +1538 @@
-void uvm_perf_access_counters_exit()
+void uvm_perf_access_counters_exit(void)
--- a/kernel/nvidia-uvm/uvm_lock.c
+++ b/kernel/nvidia-uvm/uvm_lock.c
@@ -337 +337 @@
-bool __uvm_thread_check_all_unlocked()
+bool __uvm_thread_check_all_unlocked(void)
--- a/kernel/nvidia-uvm/uvm_migrate.c
+++ b/kernel/nvidia-uvm/uvm_migrate.c
@@ -795 +795 @@
-NV_STATUS uvm_migrate_init()
+NV_STATUS uvm_migrate_init(void)
@@ -821 +821 @@
-void uvm_migrate_exit()
+void uvm_migrate_exit(void)
--- a/kernel/nvidia-uvm/uvm_migrate_pageable.c
+++ b/kernel/nvidia-uvm/uvm_migrate_pageable.c
@@ -979 +979 @@
-NV_STATUS uvm_migrate_pageable_init()
+NV_STATUS uvm_migrate_pageable_init(void)
@@ -988 +988 @@
-void uvm_migrate_pageable_exit()
+void uvm_migrate_pageable_exit(void)
--- a/kernel/nvidia-uvm/uvm_perf_heuristics.c
+++ b/kernel/nvidia-uvm/uvm_perf_heuristics.c
@@ -31 +31 @@
-NV_STATUS uvm_perf_heuristics_init()
+NV_STATUS uvm_perf_heuristics_init(void)
@@ -50 +50 @@
-void uvm_perf_heuristics_exit()
+void uvm_perf_heuristics_exit(void)
--- a/kernel/nvidia-uvm/uvm_perf_prefetch.c
+++ b/kernel/nvidia-uvm/uvm_perf_prefetch.c
@@ -463 +463 @@
-NV_STATUS uvm_perf_prefetch_init()
+NV_STATUS uvm_perf_prefetch_init(void)
@@ -501 +501 @@
-void uvm_perf_prefetch_exit()
+void uvm_perf_prefetch_exit(void)
--- a/kernel/nvidia-uvm/uvm_perf_thrashing.c
+++ b/kernel/nvidia-uvm/uvm_perf_thrashing.c
@@ -1955 +1955 @@
-NV_STATUS uvm_perf_thrashing_init()
+NV_STATUS uvm_perf_thrashing_init(void)
@@ -2014 +2014 @@
-void uvm_perf_thrashing_exit()
+void uvm_perf_thrashing_exit(void)
--- a/kernel/nvidia-uvm/uvm_procfs.c
+++ b/kernel/nvidia-uvm/uvm_procfs.c
@@ -49 +49 @@
-NV_STATUS uvm_procfs_init()
+NV_STATUS uvm_procfs_init(void)
@@ -69 +69 @@
-void uvm_procfs_exit()
+void uvm_procfs_exit(void)
@@ -98 +98 @@
-struct proc_dir_entry *uvm_procfs_get_gpu_base_dir()
+struct proc_dir_entry *uvm_procfs_get_gpu_base_dir(void)
@@ -103 +103 @@
-struct proc_dir_entry *uvm_procfs_get_cpu_base_dir()
+struct proc_dir_entry *uvm_procfs_get_cpu_base_dir(void)
--- a/kernel/nvidia-uvm/uvm_push.c
+++ b/kernel/nvidia-uvm/uvm_push.c
@@ -245 +245 @@
-bool uvm_push_info_is_tracking_descriptions()
+bool uvm_push_info_is_tracking_descriptions(void)
@@ -250 +250 @@
-bool uvm_push_info_is_tracking_acquires()
+bool uvm_push_info_is_tracking_acquires(void)
--- a/kernel/nvidia-uvm/uvm_thread_context.c
+++ b/kernel/nvidia-uvm/uvm_thread_context.c
@@ -104 +104 @@
-bool uvm_thread_context_wrapper_is_used()
+bool uvm_thread_context_wrapper_is_used(void)
--- a/kernel/nvidia-uvm/uvm_tools.c
+++ b/kernel/nvidia-uvm/uvm_tools.c
@@ -2144 +2144 @@
-void uvm_tools_flush_events()
+void uvm_tools_flush_events(void)

View File

@ -0,0 +1,7 @@
Section "OutputClass"
Identifier "nvidia"
MatchDriver "nvidia-drm"
Driver "nvidia"
Option "AllowEmptyInitialConfiguration"
ModulePath "@LIBDIR@/extensions/nvidia"
EndSection

View File

@ -0,0 +1,13 @@
Need to pass ABI flags if LD is ld.lld for USE=kernel-open
ld.lld: error: target emulation unknown: -m or at least one .o file required
https://bugs.gentoo.org/885483
https://github.com/NVIDIA/open-gpu-kernel-modules/issues/405
https://github.com/NVIDIA/open-gpu-kernel-modules/issues/214
--- a/kernel-module-source/utils.mk
+++ b/kernel-module-source/utils.mk
@@ -556,3 +556,3 @@
$(at_if_quiet)cd $$(dir $(1)); \
- $$(call quiet_cmd_no_at,LD) -r -z noexecstack --format=binary \
+ $$(call quiet_cmd_no_at,LD) $$(RAW_LDFLAGS) -r -z noexecstack --format=binary \
$$(notdir $(1)) -o $$(OUTPUTDIR_ABSOLUTE)/$$(notdir $$@)

View File

@ -0,0 +1,12 @@
Create /dev/nvidia-uvm* by respecting nvidia.conf's permissions.
--- a/nvidia-modprobe/modprobe-utils/nvidia-modprobe-utils.c
+++ b/nvidia-modprobe/modprobe-utils/nvidia-modprobe-utils.c
@@ -742,6 +742,6 @@
}
- return mknod_helper(major, base_minor, NV_UVM_DEVICE_NAME, NULL) &&
- mknod_helper(major, base_minor + 1, NV_UVM_TOOLS_DEVICE_NAME, NULL);
+ return mknod_helper(major, base_minor, NV_UVM_DEVICE_NAME, NV_PROC_REGISTRY_PATH) &&
+ mknod_helper(major, base_minor + 1, NV_UVM_TOOLS_DEVICE_NAME, NV_PROC_REGISTRY_PATH);
}

View File

@ -0,0 +1,7 @@
# configuration file for /etc/init.d/nvidia-persistenced
# NVPD_USER: user to run as, needs access to /dev/nvidia* (video group)
NVPD_USER="nvpd"
# ARGS: additional arguments, see nvidia-persistenced(1)
ARGS=""

View File

@ -0,0 +1,11 @@
#!/sbin/openrc-run
# SPDX-License-Identifier: MIT
description="Maintain persistent software state in the NVIDIA driver"
command="nvidia-persistenced"
command_args="${NVPD_USER:+--user ${NVPD_USER}} ${ARGS}"
pidfile="/var/run/nvidia-persistenced/nvidia-persistenced.pid"
stop_post() {
rmdir "${pidfile%/*}" 2>/dev/null || true
}

View File

@ -0,0 +1,11 @@
#!/sbin/openrc-run
# SPDX-License-Identifier: MIT
description="Support for NVIDIA Dynamic Boost (only for use with specific laptops)"
command="nvidia-powerd"
command_background=true
pidfile="/var/run/nvidia-powerd.pid"
depend() {
need dbus
}

View File

@ -0,0 +1,16 @@
Fix compilation with -fno-common or gcc10
https://bugs.gentoo.org/706742
--- a/nvidia-settings/src/gtk+-2.x/ctkvdpau.c
+++ b/nvidia-settings/src/gtk+-2.x/ctkvdpau.c
@@ -105,2 +105,4 @@
+struct VDPAUDeviceImpl VDPAUDeviceFunctions;
+
static int queryOutputSurface(CtkVDPAU *ctk_vdpau, VdpDevice device,
--- a/nvidia-settings/src/gtk+-2.x/ctkvdpau.h
+++ b/nvidia-settings/src/gtk+-2.x/ctkvdpau.h
@@ -48,3 +48,3 @@
-struct VDPAUDeviceImpl {
+extern struct VDPAUDeviceImpl {

View File

@ -0,0 +1,12 @@
For icon: https://github.com/NVIDIA/nvidia-settings/pull/56
--- a/nvidia-settings/doc/nvidia-settings.desktop
+++ b/nvidia-settings/doc/nvidia-settings.desktop
@@ -5,5 +5,5 @@
Comment=Configure NVIDIA X Server Settings
-Exec=__UTILS_PATH__/nvidia-settings
-Icon=__PIXMAP_PATH__/nvidia-settings.png
-Categories=__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__
+Exec=nvidia-settings
+Icon=nvidia-settings
+Categories=System;HardwareSettings;

View File

@ -0,0 +1,11 @@
--- a/nvidia-settings/src/Makefile
+++ b/nvidia-settings/src/Makefile
@@ -132,3 +132,2 @@
GTK2LIB_DIR = $(OUTPUTDIR)/gtk2
-GTK2LIB = $(OUTPUTDIR)/$(GTK2LIB_NAME)
GTK2LIB_SONAME = $(GTK2LIB_NAME).$(NVIDIA_SETTINGS_VERSION)
@@ -276,4 +275,2 @@
$(MKDIR) $(LIBDIR)
- $(INSTALL) $(INSTALL_LIB_ARGS) $(GTK2LIB) \
- $(LIBDIR)/$(GTK2LIB_SONAME)
ifdef BUILD_GTK3LIB

View File

@ -0,0 +1,9 @@
Currently need to pass ABI flags if LD is ld.lld for USE=tools
ld.lld: error: target emulation unknown: -m or at least one .o file required
--- a/nvidia-settings/utils.mk
+++ b/nvidia-settings/utils.mk
@@ -477,3 +477,3 @@
$(at_if_quiet)cd $$(dir $(1)); \
- $$(call quiet_cmd_no_at,LD) -r -z noexecstack --format=binary \
+ $$(call quiet_cmd_no_at,LD) $$(RAW_LDFLAGS) -r -z noexecstack --format=binary \
$$(notdir $(1)) -o $$(OUTPUTDIR_ABSOLUTE)/$$(notdir $$@)

View File

@ -0,0 +1,11 @@
These __PLACEHOLDER__ are replaced by nvidia-installer which we don't use.
--- a/nvidia-settings/doc/nvidia-settings.desktop
+++ b/nvidia-settings/doc/nvidia-settings.desktop
@@ -5,5 +5,5 @@
Comment=Configure NVIDIA X Server Settings
-Exec=__UTILS_PATH__/nvidia-settings
+Exec=nvidia-settings
Icon=nvidia-settings
-Categories=__NVIDIA_SETTINGS_DESKTOP_CATEGORIES__
+Categories=System;HardwareSettings;

View File

@ -0,0 +1,7 @@
#!/bin/sh
case ${1-} in
pre) nvidia-sleep.sh suspend;;
# run in background given resume is flaky if elogind did not finish
post) nvidia-sleep.sh resume &;;
*) exit 1;;
esac

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>ionen@gentoo.org</email>
<name>Ionen Wolkens</name>
</maintainer>
<maintainer type="person">
<email>soap@gentoo.org</email>
<name>David Seifert</name>
</maintainer>
<use>
<flag name="kernel-open">
Use the open source variant of the drivers
(Turing/Ampere+ GPUs only, aka GTX 1650+ --
recommended with >=560.xx drivers if usable and
it may be required for 50xx Blackwell+ GPUs)
</flag>
<flag name="persistenced">Install the persistence daemon for keeping devices state when unused (e.g. for headless)</flag>
<flag name="powerd">Install the NVIDIA dynamic boost support daemon (only useful with specific laptops, ignore if unsure)</flag>
<flag name="static-libs">Install the XNVCtrl static library for accessing sensors and other features</flag>
<flag name="tools">Install additional tools such as nvidia-settings</flag>
</use>
<upstream>
<remote-id type="cpe">cpe:/a:nvidia:gpu_driver</remote-id>
<remote-id type="github">NVIDIA/nvidia-installer</remote-id>
<remote-id type="github">NVIDIA/nvidia-modprobe</remote-id>
<remote-id type="github">NVIDIA/nvidia-persistenced</remote-id>
<remote-id type="github">NVIDIA/nvidia-settings</remote-id>
<remote-id type="github">NVIDIA/nvidia-xconfig</remote-id>
<remote-id type="github">NVIDIA/open-gpu-kernel-modules</remote-id>
</upstream>
</pkgmetadata>

View File

@ -0,0 +1,450 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus flag-o-matic linux-mod-r1 multilib
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.1
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
x86? ( ${NV_URI}Linux-x86/${PV}/NVIDIA-Linux-x86-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 x86"
IUSE="+X abi_x86_32 abi_x86_64 persistenced +static-libs +tools"
COMMON_DEPEND="
acct-group/video
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="usr/bin/* usr/lib*"
PATCHES=(
# note: no plans to add patches for newer kernels here, when the last
# working 6.1.x LTS is EOL then 390 will simply be removed from the tree
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-390.141-fno-common.patch
"${FILESDIR}"/nvidia-settings-390.144-desktop.patch
"${FILESDIR}"/nvidia-settings-390.144-no-gtk2.patch
"${FILESDIR}"/nvidia-settings-390.144-raw-ldflags.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~SYSVIPC
~!AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT
~!LOCKDEP
~!X86_KERNEL_IBT
!DEBUG_MUTEXES
"
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and optional nvidia-drm.modeset=1.
With 390.xx drivers, also used by a GLX workaround needed for OpenGL.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_AMDGPU=m or
DRM_I915=y, DRM_NOUVEAU=m also acceptable if a module and not built-in."
local ERROR_X86_KERNEL_IBT="CONFIG_X86_KERNEL_IBT: is set and, if the CPU supports the feature,
this will likely lead to modules load failure with ENDBR errors.
Please ignore if not having issues, but otherwise try to unset or
pass ibt=off to the kernel's command line." #911142
kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
eapply "${FILESDIR}"/nvidia-drivers-390.154-clang15$(usev {,-}x86).patch
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
sed "s/__NV_VK_ICD__/lib$(usex X GLX EGL)_nvidia.so.0/" \
nvidia_icd.json.template > nvidia_icd.json || die
# 390 has legacy glx needing a modified .conf (bug #713546)
# directory is not quite right, but kept for any existing custom xorg.conf
sed "s|@LIBDIR@|${EPREFIX}/usr/$(get_libdir)|" \
"${FILESDIR}"/nvidia-drm-outputclass-390.conf > nvidia-drm-outputclass.conf || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local -x RAW_LDFLAGS="$(get_abi_LDFLAGS) $(raw-ldflags)" # raw-ldflags.patch
# dead branch that will never be fixed and due for eventual removal,
# so keeping lazy "fixes" (bug #921370)
local kcflags=(
-std=gnu17
-Wno-error=implicit-function-declaration
-Wno-error=incompatible-pointer-types
)
# not *FLAGS to ensure it's used everywhere including conftest.sh
CC+=" $(test-flags-CC "${kcflags[@]}")"
use modules && KERNEL_CC+=" $(CC=${KERNEL_CC} test-flags-CC "${kcflags[@]}")"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
)
local modlist=( nvidia{,-drm,-modeset}=video:kernel )
use x86 || modlist+=( nvidia-uvm=video:kernel )
local modargs=(
CC="${KERNEL_CC}" # for the above kcflags workarounds
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
)
# temporary workaround for bug #914468
use modules && addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
if use persistenced; then
# 390.xx persistenced does not auto-detect libtirpc
LIBS=$(${PKG_CONFIG} --libs libtirpc || die) \
common_cflags=$(${PKG_CONFIG} --cflags libtirpc || die) \
emake "${NV_ARGS[@]}" -C nvidia-persistenced
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
emake "${NV_ARGS[@]}" -C nvidia-settings/src build-xnvctrl
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[VULKAN_ICD_JSON]=/usr/share/vulkan/icd.d
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/extensions/nvidia
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
[XMODULE_SYMLINK]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglx libnvidia-ifr")
libGLX_indirect # non-glvnd unused fallback
libnvidia-gtk nvidia-{settings,xconfig} # built from source
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP # handled separately
XMODULE_NEWSYM # use xorg's libwfb.so, nvidia also keeps it if it exists
.\*_SRC DKMS_CONF LIBGL_LA OPENGL_HEADER # unused
)
local DOCS=(
README.txt NVIDIA_Changelog
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")\
$(usev X "
390.xx libglvnd support is partial and requires different Xorg modules
for working OpenGL/GLX. If using the default Xorg configuration these
should be used automatically, otherwise manually add the ModulePath
from: '${EPREFIX}/${paths[XORG_OUTPUTCLASS_CONFIG]#/}/nvidia-drm-outputclass.conf'")\
$(usev x86 "
Note that NVIDIA is no longer offering support for the unified memory
module (nvidia-uvm) on x86 (32bit), as such the module is missing.
This means OpenCL/CUDA (and related, like nvenc) cannot be used.
Other functions, like OpenGL, will continue to work.")
Support from NVIDIA for 390.xx will end in December 2022, how long
Gentoo will be able to reasonably support it beyond that is unknown.
If wish to continue using this hardware, should consider switching
to the Nouveau open source driver.
https://nvidia.custhelp.com/app/answers/detail/a_id/3142/
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
newins "${FILESDIR}"/nvidia-390.conf nvidia.conf
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/libXNVCtrl/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GLX_MODULE_SYMLINK|XMODULE_NEWSYM)
# messy symlinks for non-glvnd xorg modules overrides put
# in a different directory to avoid collisions (390-only)
m[4]=../../xorg/modules/${m[3]#/}${m[4]}
m[3]=/
;;
TLS_LIB) [[ ${m[4]} == CLASSIC ]] && continue;; # segfaults (bug #785289)
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
VULKAN_ICD_JSON) m[0]=${m[0]%.template};;
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$|_NEWSYM$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
dolib.so libnvidia-cfg.so.${PV}
dosym libnvidia-cfg.so.${PV} /usr/${libdir}/libnvidia-cfg.so.1
dosym libnvidia-cfg.so.${PV} /usr/${libdir}/libnvidia-cfg.so
dobin nvidia-bug-report.sh
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# sandbox issues with /dev/nvidiactl are widespread and sometime
# affect revdeps of packages built with USE=opencl/cuda making it
# hard to manage in ebuilds (minimal set, ebuilds should handle
# manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
ewarn
ewarn "Be warned/reminded that the 390.xx branch reached end-of-life and"
ewarn "NVIDIA is no longer fixing issues (including security). Free to keep"
ewarn "using (for now) but it is recommended to either switch to nouveau or"
ewarn "replace hardware. Will be kept in-tree while possible, but expect it"
ewarn "to be removed likely in late 2027 or earlier if major issues arise."
ewarn
ewarn "Note that there is no plans to patch in support for kernels branches"
ewarn "newer than 6.1.x which will be supported upstream until December 2026."
}

View File

@ -0,0 +1,488 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus flag-o-matic linux-mod-r1 multilib
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.6
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64"
IUSE="+X abi_x86_32 abi_x86_64 persistenced +static-libs +tools"
COMMON_DEPEND="
acct-group/video
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-drivers-470.141.03-clang15.patch
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-390.144-desktop.patch
"${FILESDIR}"/nvidia-settings-390.144-no-gtk2.patch
"${FILESDIR}"/nvidia-settings-390.144-raw-ldflags.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~SYSVIPC
~!AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT
~!LOCKDEP
~!SLUB_DEBUG_ON
~!X86_KERNEL_IBT
!DEBUG_MUTEXES
"
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for nvidia-drm.modeset=1 if used.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_AMDGPU=m or
DRM_I915=y, DRM_NOUVEAU=m also acceptable if a module and not built-in."
local ERROR_X86_KERNEL_IBT="CONFIG_X86_KERNEL_IBT: is set and, if the CPU supports the feature,
this *could* lead to modules load failure with ENDBR errors, or to
broken CUDA/NVENC. Please ignore if not having issues, but otherwise
try to unset or pass ibt=off to the kernel's command line." #911142
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local -x RAW_LDFLAGS="$(get_abi_LDFLAGS) $(raw-ldflags)" # raw-ldflags.patch
# dead branch that will never be fixed and due for eventual removal,
# so keeping lazy "fixes" (bug #921370)
local kcflags=(
-std=gnu17
-Wno-error=implicit-function-declaration
-Wno-error=incompatible-pointer-types
)
# not *FLAGS to ensure it's used everywhere including conftest.sh
CC+=" $(test-flags-CC "${kcflags[@]}")"
use modules && KERNEL_CC+=" $(CC=${KERNEL_CC} test-flags-CC "${kcflags[@]}")"
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
XNVCTRL_CFLAGS="${xnvflags}"
)
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=video:kernel )
local modargs=(
CC="${KERNEL_CC}" # for the above kcflags workarounds
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
)
# temporary workaround for bug #914468
use modules && addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
emake "${NV_ARGS[@]}" -C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia libnvidia-ifr")
libGLX_indirect # non-glvnd unused fallback
libnvidia-gtk nvidia-{settings,xconfig} # built from source
# skip wayland-related files, largely broken with 470 at this point
libnvidia-egl-wayland 10_nvidia_wayland libnvidia-vulkan-producer
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
newins "${FILESDIR}"/nvidia-470.conf nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
[[ ${m[0]} =~ ^libnvidia-ngx.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1 # soname not in .manifest
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend}.service
dobin nvidia-bug-report.sh
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl (and /dev/char wrt bug #904292)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
ewarn
ewarn "Be warned/reminded that the 470.xx branch reached end-of-life and"
ewarn "NVIDIA is no longer fixing issues (including security). Free to keep"
ewarn "using (for now) but it is recommended to either switch to nouveau or"
ewarn "replace hardware. Will be kept in-tree while possible, but expect it"
ewarn "to be removed likely in late 2027 or earlier if major issues arise."
ewarn
ewarn "Note that there is no plans to patch in support for kernels branches"
ewarn "newer than 6.6.x which will be supported upstream until December 2026."
}

View File

@ -0,0 +1,574 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus flag-o-matic linux-mod-r1 multilib
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.13
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 ~arm64"
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
gui-libs/egl-gbm
>=gui-libs/egl-wayland-1.1.10
media-libs/libglvnd
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-kernel-module-source-515.86.01-raw-ldflags.patch
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-390.144-raw-ldflags.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_AMDGPU=m or
DRM_I915=y, DRM_NOUVEAU=m also acceptable if a module and not built-in."
local ERROR_X86_KERNEL_IBT="CONFIG_X86_KERNEL_IBT: is set and, if the CPU supports the feature,
this *could* lead to modules load failure with ENDBR errors, or to
broken CUDA/NVENC. Please ignore if not having issues, but otherwise
try to unset or pass ibt=off to the kernel's command line." #911142
use kernel-open || CONFIG_CHECK+=" ~!X86_KERNEL_IBT"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-470.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
# temporary option, nvidia will remove in the future
use !kernel-open ||
sed -i '/blacklist/a\
\
# Enable using kernel-open with workstation GPUs (experimental)\
options nvidia NVreg_OpenRmEnableUnsupportedGpus=1' "${T}"/nvidia.conf || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local -x RAW_LDFLAGS="$(get_abi_LDFLAGS) $(raw-ldflags)" # raw-ldflags.patch
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
$(usev !wayland libnvidia-vulkan-producer)
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
[[ ${m[0]} =~ ^libnvidia-ngx.so|^libnvidia-egl-gbm.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1 # soname not in .manifest
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend}.service
dobin nvidia-bug-report.sh
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl (and /dev/char wrt bug #904292)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open; then
ewarn
ewarn "Open source variant of ${PN} was selected, be warned it is experimental"
ewarn "and only for modern GPUs (e.g. GTX 1650+). Try to disable if run into issues."
ewarn "Please also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
}

View File

@ -0,0 +1,574 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus flag-o-matic linux-mod-r1 multilib
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.14
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 ~arm64"
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
gui-libs/egl-gbm
>=gui-libs/egl-wayland-1.1.10
media-libs/libglvnd
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-kernel-module-source-515.86.01-raw-ldflags.patch
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-390.144-raw-ldflags.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_AMDGPU=m or
DRM_I915=y, DRM_NOUVEAU=m also acceptable if a module and not built-in."
local ERROR_X86_KERNEL_IBT="CONFIG_X86_KERNEL_IBT: is set and, if the CPU supports the feature,
this *could* lead to modules load failure with ENDBR errors, or to
broken CUDA/NVENC. Please ignore if not having issues, but otherwise
try to unset or pass ibt=off to the kernel's command line." #911142
use kernel-open || CONFIG_CHECK+=" ~!X86_KERNEL_IBT"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-470.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
# temporary option, nvidia will remove in the future
use !kernel-open ||
sed -i '/blacklist/a\
\
# Enable using kernel-open with workstation GPUs (experimental)\
options nvidia NVreg_OpenRmEnableUnsupportedGpus=1' "${T}"/nvidia.conf || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local -x RAW_LDFLAGS="$(get_abi_LDFLAGS) $(raw-ldflags)" # raw-ldflags.patch
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
$(usev !wayland libnvidia-vulkan-producer)
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
[[ ${m[0]} =~ ^libnvidia-ngx.so|^libnvidia-egl-gbm.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1 # soname not in .manifest
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend}.service
dobin nvidia-bug-report.sh
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl (and /dev/char wrt bug #904292)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open; then
ewarn
ewarn "Open source variant of ${PN} was selected, be warned it is experimental"
ewarn "and only for modern GPUs (e.g. GTX 1650+). Try to disable if run into issues."
ewarn "Please also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
}

View File

@ -0,0 +1,568 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus flag-o-matic linux-mod-r1 readme.gentoo-r1
inherit systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.13
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 ~arm64"
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
gui-libs/egl-gbm
>=gui-libs/egl-wayland-1.1.10
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
# do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
get_version
require_configured_kernel
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
CONFIG_CHECK+=" DRM_TTM_HELPER"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
DRM_AMDGPU=m (among others, consult the kernel config's help), can
also use DRM_NOUVEAU=m as long as built as module *not* built-in."
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
${drm_helper_msg}"
local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
${drm_helper_msg}"
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-545.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
[[ ${m[0]} =~ ^libnvidia-ngx.so|^libnvidia-egl-gbm.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1 # soname not in .manifest
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend}.service
dobin nvidia-bug-report.sh
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
ewarn
ewarn "Open source variant of ${PN} was selected, be warned it is experimental"
ewarn "and only for modern GPUs (e.g. GTX 1650+). Try to disable if run into issues."
ewarn "Please also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
}

View File

@ -0,0 +1,568 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus flag-o-matic linux-mod-r1 readme.gentoo-r1
inherit systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.14
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 ~arm64"
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
gui-libs/egl-gbm
>=gui-libs/egl-wayland-1.1.10
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
# do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
get_version
require_configured_kernel
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
CONFIG_CHECK+=" DRM_TTM_HELPER"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
DRM_AMDGPU=m (among others, consult the kernel config's help), can
also use DRM_NOUVEAU=m as long as built as module *not* built-in."
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
${drm_helper_msg}"
local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
${drm_helper_msg}"
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-545.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
[[ ${m[0]} =~ ^libnvidia-ngx.so|^libnvidia-egl-gbm.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1 # soname not in .manifest
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend}.service
dobin nvidia-bug-report.sh
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
ewarn
ewarn "Open source variant of ${PN} was selected, be warned it is experimental"
ewarn "and only for modern GPUs (e.g. GTX 1650+). Try to disable if run into issues."
ewarn "Please also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
}

View File

@ -0,0 +1,602 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus eapi9-ver flag-o-matic linux-mod-r1
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.14
NV_PIN=570.133.07
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://developer.nvidia.com/vulkan-driver"
SRC_URI="
https://developer.nvidia.com/downloads/vulkan-beta-${PV//.}-linux
-> NVIDIA-Linux-x86_64-${PV}.run
$(printf "https://download.nvidia.com/XFree86/%s/%s-${NV_PIN}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
https://github.com/NVIDIA/open-gpu-kernel-modules/archive/refs/tags/${PV}.tar.gz
-> open-gpu-kernel-modules-${PV}.tar.gz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/vulkan"
KEYWORDS="-* ~amd64"
# note: kernel-open is an upstream default in >=560 if all GPUs on the system
# support it but, since no automagic here, keeping it off for the wider support
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
>=gui-libs/egl-gbm-1.1.1-r2[abi_x86_32(-)?]
>=gui-libs/egl-wayland-1.1.13.1[abi_x86_32(-)?]
X? ( gui-libs/egl-x11[abi_x86_32(-)?] )
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
dev-util/vulkan-headers
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
# do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
get_version
require_configured_kernel
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~DRM_FBDEV_EMULATION
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
CONFIG_CHECK+=" DRM_TTM_HELPER"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
DRM_AMDGPU=m (among others, consult the kernel config's help), can
also use DRM_NOUVEAU=m as long as built as module *not* built-in."
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
${drm_helper_msg}"
local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
${drm_helper_msg}"
local ERROR_DRM_FBDEV_EMULATION="CONFIG_DRM_FBDEV_EMULATION: is not set but is needed for
nvidia-drm.fbdev=1 support, currently off-by-default and it could
be ignored, but note that is due to change in the future."
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${NV_PIN},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${NV_PIN},} || die
rm nvidia-settings && mv nvidia-settings{-${NV_PIN},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${NV_PIN},} || die
mv open-gpu-kernel-modules-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-570.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
LDFLAGS=$(raw-ldflags)
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKANSC_ICD_JSON]=/usr/share/vulkansc
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-egl-xcb 20_nvidia_xcb.json # gui-libs/egl-x11
libnvidia-egl-xlib 20_nvidia_xlib.json # gui-libs/egl-x11
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
Be warned that USE=kernel-open may need to be either enabled or
disabled for certain cards to function:
- GTX 50xx (blackwell) and higher are known to require it to be enabled
- GTX 1650 and higher (pre-blackwell) should work either way
- Older cards require it to be disabled
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
# avoid portage warning due to missing soname links in manifest
[[ ${m[0]} =~ ^libnvidia-ngx.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend,suspend-then-hibernate}.service
dobin nvidia-bug-report.sh
insinto /usr/share/nvidia/files.d
doins sandboxutils-filelist.json
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-suspend-then-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
# TODO?: automatically check "kernelopen" bit for USE=kernel-open compat
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
ewarn
ewarn "Open source variant of ${PN} was selected, note that it requires"
ewarn "Turing/Ampere+ GPUs (aka GTX 1650+). Try disabling if run into issues."
ewarn "Also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
if use !kernel-open && ver_replacing -lt 555; then
elog
elog "If using a Turing/Ampere+ GPU (aka GTX 1650+), note that >=nvidia-drivers-555"
elog "enables the use of the GSP firmware by default. *If* experience regressions,"
elog "please see '${EROOT}/etc/modprobe.d/nvidia.conf' to optionally disable."
fi
}

View File

@ -0,0 +1,601 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus eapi9-ver flag-o-matic linux-mod-r1
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.14
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 ~arm64"
# note: kernel-open is an upstream default in >=560 if all GPUs on the system
# support it but, since no automagic here, keeping it off for the wider support
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
>=gui-libs/egl-gbm-1.1.1-r2[abi_x86_32(-)?]
>=gui-libs/egl-wayland-1.1.13.1[abi_x86_32(-)?]
X? ( gui-libs/egl-x11[abi_x86_32(-)?] )
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
dev-util/vulkan-headers
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
# do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
get_version
require_configured_kernel
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~DRM_FBDEV_EMULATION
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
CONFIG_CHECK+=" DRM_TTM_HELPER"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
DRM_AMDGPU=m (among others, consult the kernel config's help), can
also use DRM_NOUVEAU=m as long as built as module *not* built-in."
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
${drm_helper_msg}"
local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
${drm_helper_msg}"
local ERROR_DRM_FBDEV_EMULATION="CONFIG_DRM_FBDEV_EMULATION: is not set but is needed for
nvidia-drm.fbdev=1 support, currently off-by-default and it could
be ignored, but note that is due to change in the future."
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-570.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
LDFLAGS=$(raw-ldflags)
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKANSC_ICD_JSON]=/usr/share/vulkansc
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-egl-xcb 20_nvidia_xcb.json # gui-libs/egl-x11
libnvidia-egl-xlib 20_nvidia_xlib.json # gui-libs/egl-x11
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
Be warned that USE=kernel-open may need to be either enabled or
disabled for certain cards to function:
- GTX 50xx (blackwell) and higher are known to require it to be enabled
- GTX 1650 and higher (pre-blackwell) should work either way
- Older cards require it to be disabled
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
# avoid portage warning due to missing soname links in manifest
[[ ${m[0]} =~ ^libnvidia-ngx.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend,suspend-then-hibernate}.service
dobin nvidia-bug-report.sh
insinto /usr/share/nvidia/files.d
doins sandboxutils-filelist.json
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-suspend-then-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
# TODO?: automatically check "kernelopen" bit for USE=kernel-open compat
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
ewarn
ewarn "Open source variant of ${PN} was selected, note that it requires"
ewarn "Turing/Ampere+ GPUs (aka GTX 1650+). Try disabling if run into issues."
ewarn "Also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
if use !kernel-open && ver_replacing -lt 555; then
elog
elog "If using a Turing/Ampere+ GPU (aka GTX 1650+), note that >=nvidia-drivers-555"
elog "enables the use of the GSP firmware by default. *If* experience regressions,"
elog "please see '${EROOT}/etc/modprobe.d/nvidia.conf' to optionally disable."
fi
}

View File

@ -0,0 +1,601 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus eapi9-ver flag-o-matic linux-mod-r1
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.14
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 ~arm64"
# note: kernel-open is an upstream default in >=560 if all GPUs on the system
# support it but, since no automagic here, keeping it off for the wider support
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
>=gui-libs/egl-gbm-1.1.1-r2[abi_x86_32(-)?]
>=gui-libs/egl-wayland-1.1.13.1[abi_x86_32(-)?]
X? ( gui-libs/egl-x11[abi_x86_32(-)?] )
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
dev-util/vulkan-headers
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
# do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
get_version
require_configured_kernel
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~DRM_FBDEV_EMULATION
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
CONFIG_CHECK+=" DRM_TTM_HELPER"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
DRM_AMDGPU=m (among others, consult the kernel config's help), can
also use DRM_NOUVEAU=m as long as built as module *not* built-in."
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
${drm_helper_msg}"
local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
${drm_helper_msg}"
local ERROR_DRM_FBDEV_EMULATION="CONFIG_DRM_FBDEV_EMULATION: is not set but is needed for
nvidia-drm.fbdev=1 support, currently off-by-default and it could
be ignored, but note that is due to change in the future."
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-570.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
LDFLAGS=$(raw-ldflags)
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKANSC_ICD_JSON]=/usr/share/vulkansc
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-egl-xcb 20_nvidia_xcb.json # gui-libs/egl-x11
libnvidia-egl-xlib 20_nvidia_xlib.json # gui-libs/egl-x11
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
Be warned that USE=kernel-open may need to be either enabled or
disabled for certain cards to function:
- GTX 50xx (blackwell) and higher are known to require it to be enabled
- GTX 1650 and higher (pre-blackwell) should work either way
- Older cards require it to be disabled
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
# avoid portage warning due to missing soname links in manifest
[[ ${m[0]} =~ ^libnvidia-ngx.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend,suspend-then-hibernate}.service
dobin nvidia-bug-report.sh
insinto /usr/share/nvidia/files.d
doins sandboxutils-filelist.json
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-suspend-then-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
# TODO?: automatically check "kernelopen" bit for USE=kernel-open compat
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
ewarn
ewarn "Open source variant of ${PN} was selected, note that it requires"
ewarn "Turing/Ampere+ GPUs (aka GTX 1650+). Try disabling if run into issues."
ewarn "Also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
if use !kernel-open && ver_replacing -lt 555; then
elog
elog "If using a Turing/Ampere+ GPU (aka GTX 1650+), note that >=nvidia-drivers-555"
elog "enables the use of the GSP firmware by default. *If* experience regressions,"
elog "please see '${EROOT}/etc/modprobe.d/nvidia.conf' to optionally disable."
fi
}

View File

@ -0,0 +1,601 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus eapi9-ver flag-o-matic linux-mod-r1
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.14
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="NVIDIA-r2 Apache-2.0 BSD BSD-2 GPL-2 MIT ZLIB curl openssl"
SLOT="0/${PV%%.*}"
KEYWORDS="-* amd64 ~arm64"
# note: kernel-open is an upstream default in >=560 if all GPUs on the system
# support it but, since no automagic here, keeping it off for the wider support
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
>=gui-libs/egl-gbm-1.1.1-r2[abi_x86_32(-)?]
>=gui-libs/egl-wayland-1.1.13.1[abi_x86_32(-)?]
X? ( gui-libs/egl-x11[abi_x86_32(-)?] )
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
dev-util/vulkan-headers
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
# do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
get_version
require_configured_kernel
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~DRM_FBDEV_EMULATION
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
CONFIG_CHECK+=" DRM_TTM_HELPER"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
DRM_AMDGPU=m (among others, consult the kernel config's help), can
also use DRM_NOUVEAU=m as long as built as module *not* built-in."
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
${drm_helper_msg}"
local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
${drm_helper_msg}"
local ERROR_DRM_FBDEV_EMULATION="CONFIG_DRM_FBDEV_EMULATION: is not set but is needed for
nvidia-drm.fbdev=1 support, currently off-by-default and it could
be ignored, but note that is due to change in the future."
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-570.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
LDFLAGS=$(raw-ldflags)
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKANSC_ICD_JSON]=/usr/share/vulkansc
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-egl-xcb 20_nvidia_xcb.json # gui-libs/egl-x11
libnvidia-egl-xlib 20_nvidia_xlib.json # gui-libs/egl-x11
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd powerd)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
Be warned that USE=kernel-open may need to be either enabled or
disabled for certain cards to function:
- GTX 50xx (blackwell) and higher are known to require it to be enabled
- GTX 1650 and higher (pre-blackwell) should work either way
- Older cards require it to be disabled
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
# avoid portage warning due to missing soname links in manifest
[[ ${m[0]} =~ ^libnvidia-ngx.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend,suspend-then-hibernate}.service
dobin nvidia-bug-report.sh
insinto /usr/share/nvidia/files.d
doins sandboxutils-filelist.json
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-suspend-then-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
# TODO?: automatically check "kernelopen" bit for USE=kernel-open compat
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
ewarn
ewarn "Open source variant of ${PN} was selected, note that it requires"
ewarn "Turing/Ampere+ GPUs (aka GTX 1650+). Try disabling if run into issues."
ewarn "Also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
if use !kernel-open && ver_replacing -lt 555; then
elog
elog "If using a Turing/Ampere+ GPU (aka GTX 1650+), note that >=nvidia-drivers-555"
elog "enables the use of the GSP firmware by default. *If* experience regressions,"
elog "please see '${EROOT}/etc/modprobe.d/nvidia.conf' to optionally disable."
fi
}

View File

@ -0,0 +1,606 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
MODULES_OPTIONAL_IUSE=+modules
inherit desktop eapi9-pipestatus eapi9-ver flag-o-matic linux-mod-r1
inherit readme.gentoo-r1 systemd toolchain-funcs unpacker user-info
MODULES_KERNEL_MAX=6.14
NV_URI="https://download.nvidia.com/XFree86/"
DESCRIPTION="NVIDIA Accelerated Graphics Driver"
HOMEPAGE="https://www.nvidia.com/"
SRC_URI="
amd64? ( ${NV_URI}Linux-x86_64/${PV}/NVIDIA-Linux-x86_64-${PV}.run )
arm64? ( ${NV_URI}Linux-aarch64/${PV}/NVIDIA-Linux-aarch64-${PV}.run )
$(printf "${NV_URI}%s/%s-${PV}.tar.bz2 " \
nvidia-{installer,modprobe,persistenced,settings,xconfig}{,})
${NV_URI}NVIDIA-kernel-module-source/NVIDIA-kernel-module-source-${PV}.tar.xz
"
# nvidia-installer is unused but here for GPL-2's "distribute sources"
S=${WORKDIR}
LICENSE="
NVIDIA-r2 Apache-2.0 Boost-1.0 BSD BSD-2 GPL-2 MIT ZLIB
curl openssl public-domain
"
SLOT="0/${PV%%.*}"
# unkeyworded due to being a beta, feel free to opt-in
#KEYWORDS="-* ~amd64 ~arm64"
# note: kernel-open is an upstream default in >=560 if all GPUs on the system
# support it but, since no automagic here, keeping it off for the wider support
IUSE="+X abi_x86_32 abi_x86_64 kernel-open persistenced powerd +static-libs +tools wayland"
REQUIRED_USE="kernel-open? ( modules )"
COMMON_DEPEND="
acct-group/video
X? ( x11-libs/libpciaccess )
persistenced? (
acct-user/nvpd
net-libs/libtirpc:=
)
tools? (
>=app-accessibility/at-spi2-core-2.46:2
dev-libs/glib:2
dev-libs/jansson:=
media-libs/harfbuzz:=
x11-libs/cairo
x11-libs/gdk-pixbuf:2
x11-libs/gtk+:3[X]
x11-libs/libX11
x11-libs/libXext
x11-libs/libXxf86vm
x11-libs/pango
)
"
RDEPEND="
${COMMON_DEPEND}
dev-libs/openssl:0/3
sys-libs/glibc
X? (
media-libs/libglvnd[X,abi_x86_32(-)?]
x11-libs/libX11[abi_x86_32(-)?]
x11-libs/libXext[abi_x86_32(-)?]
)
powerd? ( sys-apps/dbus[abi_x86_32(-)?] )
wayland? (
>=gui-libs/egl-gbm-1.1.1-r2[abi_x86_32(-)?]
>=gui-libs/egl-wayland-1.1.13.1[abi_x86_32(-)?]
X? ( gui-libs/egl-x11[abi_x86_32(-)?] )
)
"
DEPEND="
${COMMON_DEPEND}
static-libs? (
x11-base/xorg-proto
x11-libs/libX11
x11-libs/libXext
)
tools? (
dev-util/vulkan-headers
media-libs/libglvnd
sys-apps/dbus
x11-base/xorg-proto
x11-libs/libXrandr
x11-libs/libXv
x11-libs/libvdpau
)
"
BDEPEND="
app-alternatives/awk
sys-devel/m4
virtual/pkgconfig
"
# there is some non-prebuilt exceptions but rather not maintain a list
QA_PREBUILT="lib/firmware/* usr/bin/* usr/lib*"
PATCHES=(
"${FILESDIR}"/nvidia-modprobe-390.141-uvm-perms.patch
"${FILESDIR}"/nvidia-settings-530.30.02-desktop.patch
)
pkg_setup() {
use modules && [[ ${MERGE_TYPE} != binary ]] || return
# do early before linux-mod-r1 so can use chkconfig to setup CONFIG_CHECK
get_version
require_configured_kernel
local CONFIG_CHECK="
PROC_FS
~DRM_KMS_HELPER
~DRM_FBDEV_EMULATION
~SYSVIPC
~!LOCKDEP
~!PREEMPT_RT
~!SLUB_DEBUG_ON
!DEBUG_MUTEXES
$(usev powerd '~CPU_FREQ')
"
kernel_is -ge 6 11 && linux_chkconfig_present DRM_FBDEV_EMULATION &&
CONFIG_CHECK+=" DRM_TTM_HELPER"
use amd64 && kernel_is -ge 5 8 && CONFIG_CHECK+=" X86_PAT" #817764
use kernel-open && CONFIG_CHECK+=" MMU_NOTIFIER" #843827
local drm_helper_msg="Cannot be directly selected in the kernel's config menus, and may need
selection of a DRM device even if unused, e.g. CONFIG_DRM_QXL=m or
DRM_AMDGPU=m (among others, consult the kernel config's help), can
also use DRM_NOUVEAU=m as long as built as module *not* built-in."
local ERROR_DRM_KMS_HELPER="CONFIG_DRM_KMS_HELPER: is not set but needed for Xorg auto-detection
of drivers (no custom config), and for wayland / nvidia-drm.modeset=1.
${drm_helper_msg}"
local ERROR_DRM_TTM_HELPER="CONFIG_DRM_TTM_HELPER: is not set but is needed to compile when using
kernel version 6.11.x or newer while DRM_FBDEV_EMULATION is set.
${drm_helper_msg}"
local ERROR_DRM_FBDEV_EMULATION="CONFIG_DRM_FBDEV_EMULATION: is not set but is needed for
nvidia-drm.fbdev=1 support, currently off-by-default and it could
be ignored, but note that is due to change in the future."
local ERROR_MMU_NOTIFIER="CONFIG_MMU_NOTIFIER: is not set but needed to build with USE=kernel-open.
Cannot be directly selected in the kernel's menuconfig, and may need
selection of another option that requires it such as CONFIG_KVM."
local ERROR_PREEMPT_RT="CONFIG_PREEMPT_RT: is set but is unsupported by NVIDIA upstream and
will fail to build unless the env var IGNORE_PREEMPT_RT_PRESENCE=1 is
set. Please do not report issues if run into e.g. kernel panics while
ignoring this."
linux-mod-r1_pkg_setup
}
src_prepare() {
# make patches usable across versions
rm nvidia-modprobe && mv nvidia-modprobe{-${PV},} || die
rm nvidia-persistenced && mv nvidia-persistenced{-${PV},} || die
rm nvidia-settings && mv nvidia-settings{-${PV},} || die
rm nvidia-xconfig && mv nvidia-xconfig{-${PV},} || die
mv NVIDIA-kernel-module-source-${PV} kernel-module-source || die
default
# prevent detection of incomplete kernel DRM support (bug #603818)
sed 's/defined(CONFIG_DRM/defined(CONFIG_DRM_KMS_HELPER/g' \
-i kernel{,-module-source/kernel-open}/conftest.sh || die
sed 's/__USER__/nvpd/' \
nvidia-persistenced/init/systemd/nvidia-persistenced.service.template \
> "${T}"/nvidia-persistenced.service || die
# use alternative vulkan icd option if USE=-X (bug #909181)
use X || sed -i 's/"libGLX/"libEGL/' nvidia_{layers,icd}.json || die
# enable nvidia-drm.modeset=1 by default with USE=wayland
cp "${FILESDIR}"/nvidia-570.conf "${T}"/nvidia.conf || die
use !wayland || sed -i '/^#.*modeset=1$/s/^#//' "${T}"/nvidia.conf || die
# makefile attempts to install wayland library even if not built
use wayland || sed -i 's/ WAYLAND_LIB_install$//' \
nvidia-settings/src/Makefile || die
}
src_compile() {
tc-export AR CC CXX LD OBJCOPY OBJDUMP PKG_CONFIG
local xnvflags=-fPIC #840389
# lto static libraries tend to cause problems without fat objects
tc-is-lto && xnvflags+=" $(test-flags-CC -ffat-lto-objects)"
NV_ARGS=(
PREFIX="${EPREFIX}"/usr
HOST_CC="$(tc-getBUILD_CC)"
HOST_LD="$(tc-getBUILD_LD)"
BUILD_GTK2LIB=
NV_USE_BUNDLED_LIBJANSSON=0
NV_VERBOSE=1 DO_STRIP= MANPAGE_GZIP= OUTPUTDIR=out
WAYLAND_AVAILABLE=$(usex wayland 1 0)
XNVCTRL_CFLAGS="${xnvflags}"
)
if use modules; then
local o_cflags=${CFLAGS} o_cxxflags=${CXXFLAGS} o_ldflags=${LDFLAGS}
# conftest.sh is broken with c23 due to func() changing meaning,
# and then fails later due to ealier misdetections
# TODO: try without now and then + drop modargs' CC= (bug #944092)
KERNEL_CC+=" -std=gnu17"
local modlistargs=video:kernel
if use kernel-open; then
modlistargs+=-module-source:kernel-module-source/kernel-open
# environment flags are normally unused for modules, but nvidia
# uses it for building the "blob" and it is a bit fragile
filter-flags -fno-plt #912949
filter-lto
CC=${KERNEL_CC} CXX=${KERNEL_CXX} strip-unsupported-flags
LDFLAGS=$(raw-ldflags)
fi
local modlist=( nvidia{,-drm,-modeset,-peermem,-uvm}=${modlistargs} )
local modargs=(
CC="${KERNEL_CC}" # needed for above gnu17 workaround
IGNORE_CC_MISMATCH=yes NV_VERBOSE=1
SYSOUT="${KV_OUT_DIR}" SYSSRC="${KV_DIR}"
# kernel takes "x86" and "x86_64" as meaning the same, but nvidia
# makes the distinction (since 550.135) and is not happy with "x86"
# TODO?: it should be ok/better for tc-arch-kernel to do x86_64
$(usev amd64 ARCH=x86_64)
)
# temporary workaround for bug #914468
addpredict "${KV_OUT_DIR}"
linux-mod-r1_src_compile
CFLAGS=${o_cflags} CXXFLAGS=${o_cxxflags} LDFLAGS=${o_ldflags}
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe
use persistenced && emake "${NV_ARGS[@]}" -C nvidia-persistenced
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig
if use tools; then
# avoid noisy *very* noisy logs with deprecation warnings
CFLAGS="-Wno-deprecated-declarations ${CFLAGS}" \
emake "${NV_ARGS[@]}" -C nvidia-settings
elif use static-libs; then
# pretend GTK+3 is available, not actually used (bug #880879)
emake "${NV_ARGS[@]}" BUILD_GTK3LIB=1 \
-C nvidia-settings/src out/libXNVCtrl.a
fi
}
src_install() {
local libdir=$(get_libdir) libdir32=$(ABI=x86 get_libdir)
NV_ARGS+=( DESTDIR="${D}" LIBDIR="${ED}"/usr/${libdir} )
local -A paths=(
[APPLICATION_PROFILE]=/usr/share/nvidia
[CUDA_ICD]=/etc/OpenCL/vendors
[EGL_EXTERNAL_PLATFORM_JSON]=/usr/share/egl/egl_external_platform.d
[FIRMWARE]=/lib/firmware/nvidia/${PV}
[GBM_BACKEND_LIB_SYMLINK]=/usr/${libdir}/gbm
[GLVND_EGL_ICD_JSON]=/usr/share/glvnd/egl_vendor.d
[OPENGL_DATA]=/usr/share/nvidia
[VULKANSC_ICD_JSON]=/usr/share/vulkansc
[VULKAN_ICD_JSON]=/usr/share/vulkan
[WINE_LIB]=/usr/${libdir}/nvidia/wine
[XORG_OUTPUTCLASS_CONFIG]=/usr/share/X11/xorg.conf.d
[GLX_MODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules/extensions
[GLX_MODULE_SYMLINK]=/usr/${libdir}/xorg/modules
[XMODULE_SHARED_LIB]=/usr/${libdir}/xorg/modules
)
local skip_files=(
$(usev !X "libGLX_nvidia libglxserver_nvidia")
libGLX_indirect # non-glvnd unused fallback
libnvidia-{gtk,wayland-client} nvidia-{settings,xconfig} # from source
libnvidia-egl-gbm 15_nvidia_gbm # gui-libs/egl-gbm
libnvidia-egl-wayland 10_nvidia_wayland # gui-libs/egl-wayland
libnvidia-egl-xcb 20_nvidia_xcb.json # gui-libs/egl-x11
libnvidia-egl-xlib 20_nvidia_xlib.json # gui-libs/egl-x11
libnvidia-pkcs11.so # using the openssl3 version instead
)
local skip_modules=(
$(usev !X "nvfbc vdpau xdriver")
$(usev !modules gsp)
$(usev !powerd nvtopps)
installer nvpd # handled separately / built from source
)
local skip_types=(
GLVND_LIB GLVND_SYMLINK EGL_CLIENT.\* GLX_CLIENT.\* # media-libs/libglvnd
OPENCL_WRAPPER.\* # virtual/opencl
DOCUMENTATION DOT_DESKTOP .\*_SRC DKMS_CONF SYSTEMD_UNIT # handled separately / unused
)
local DOCS=(
README.txt NVIDIA_Changelog supported-gpus/supported-gpus.json
nvidia-settings/doc/{FRAMELOCK,NV-CONTROL-API}.txt
)
local HTML_DOCS=( html/. )
einstalldocs
local DISABLE_AUTOFORMATTING=yes
local DOC_CONTENTS="\
Trusted users should be in the 'video' group to use NVIDIA devices.
You can add yourself by using: gpasswd -a my-user video\
$(usev modules "
Like all out-of-tree kernel modules, it is necessary to rebuild
${PN} after upgrading or rebuilding the Linux kernel
by for example running \`emerge @module-rebuild\`. Alternatively,
if using a distribution kernel (sys-kernel/gentoo-kernel{,-bin}),
this can be automated by setting USE=dist-kernel globally.
Loaded kernel modules also must not mismatch with the installed
${PN} version (excluding -r revision), meaning should
ensure \`eselect kernel list\` points to the kernel that will be
booted before building and preferably reboot after upgrading
${PN} (the ebuild will emit a warning if mismatching).
See '${EPREFIX}/etc/modprobe.d/nvidia.conf' for modules options.")\
$(use amd64 && usev !abi_x86_32 "
Note that without USE=abi_x86_32 on ${PN}, 32bit applications
(typically using wine / steam) will not be able to use GPU acceleration.")
Be warned that USE=kernel-open may need to be either enabled or
disabled for certain cards to function:
- GTX 50xx (blackwell) and higher are known to require it to be enabled
- GTX 1650 and higher (pre-blackwell) should work either way
- Older cards require it to be disabled
For additional information or for troubleshooting issues, please see
https://wiki.gentoo.org/wiki/NVIDIA/nvidia-drivers and NVIDIA's own
documentation that is installed alongside this README."
readme.gentoo_create_doc
if use modules; then
linux-mod-r1_src_install
insinto /etc/modprobe.d
doins "${T}"/nvidia.conf
# used for gpu verification with binpkgs (not kept, see pkg_preinst)
insinto /usr/share/nvidia
doins supported-gpus/supported-gpus.json
fi
emake "${NV_ARGS[@]}" -C nvidia-modprobe install
fowners :video /usr/bin/nvidia-modprobe #505092
fperms 4710 /usr/bin/nvidia-modprobe
if use persistenced; then
emake "${NV_ARGS[@]}" -C nvidia-persistenced install
newconfd "${FILESDIR}"/nvidia-persistenced.confd nvidia-persistenced
newinitd "${FILESDIR}"/nvidia-persistenced.initd nvidia-persistenced
systemd_dounit "${T}"/nvidia-persistenced.service
fi
if use tools; then
emake "${NV_ARGS[@]}" -C nvidia-settings install
doicon nvidia-settings/doc/nvidia-settings.png
domenu nvidia-settings/doc/nvidia-settings.desktop
exeinto /etc/X11/xinit/xinitrc.d
newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
fi
if use static-libs; then
dolib.a nvidia-settings/src/out/libXNVCtrl.a
insinto /usr/include/NVCtrl
doins nvidia-settings/src/libXNVCtrl/NVCtrl{Lib,}.h
fi
use X && emake "${NV_ARGS[@]}" -C nvidia-xconfig install
# mimic nvidia-installer by reading .manifest to install files
# 0:file 1:perms 2:type 3+:subtype/arguments -:module
local m into
while IFS=' ' read -ra m; do
! [[ ${#m[@]} -ge 2 && ${m[-1]} =~ MODULE: ]] ||
[[ " ${m[0]##*/}" =~ ^(\ ${skip_files[*]/%/.*|\\} )$ ]] ||
[[ " ${m[2]}" =~ ^(\ ${skip_types[*]/%/|\\} )$ ]] ||
has ${m[-1]#MODULE:} "${skip_modules[@]}" && continue
case ${m[2]} in
MANPAGE)
gzip -dc ${m[0]} | newman - ${m[0]%.gz}
pipestatus || die
continue
;;
GBM_BACKEND_LIB_SYMLINK) m[4]=../${m[4]};; # missing ../
VDPAU_SYMLINK) m[4]=vdpau/; m[5]=${m[5]#vdpau/};; # .so to vdpau/
esac
if [[ -v 'paths[${m[2]}]' ]]; then
into=${paths[${m[2]}]}
elif [[ ${m[2]} == EXPLICIT_PATH ]]; then
into=${m[3]}
elif [[ ${m[2]} == *_BINARY ]]; then
into=/usr/bin
elif [[ ${m[3]} == COMPAT32 ]]; then
use abi_x86_32 || continue
into=/usr/${libdir32}
elif [[ ${m[2]} == *_@(LIB|SYMLINK) ]]; then
into=/usr/${libdir}
else
die "No known installation path for ${m[0]}"
fi
[[ ${m[3]: -2} == ?/ ]] && into+=/${m[3]%/}
[[ ${m[4]: -2} == ?/ ]] && into+=/${m[4]%/}
if [[ ${m[2]} =~ _SYMLINK$ ]]; then
[[ ${m[4]: -1} == / ]] && m[4]=${m[5]}
dosym ${m[4]} ${into}/${m[0]}
continue
fi
# avoid portage warning due to missing soname links in manifest
[[ ${m[0]} =~ ^libnvidia-ngx.so ]] &&
dosym ${m[0]} ${into}/${m[0]%.so*}.so.1
printf -v m[1] %o $((m[1] | 0200)) # 444->644
insopts -m${m[1]}
insinto ${into}
doins ${m[0]}
done < .manifest || die
insopts -m0644 # reset
# MODULE:installer non-skipped extras
: "$(systemd_get_sleepdir)"
exeinto "${_#"${EPREFIX}"}"
doexe systemd/system-sleep/nvidia
dobin systemd/nvidia-sleep.sh
systemd_dounit systemd/system/nvidia-{hibernate,resume,suspend,suspend-then-hibernate}.service
dobin nvidia-bug-report.sh
insinto /usr/share/nvidia/files.d
doins sandboxutils-filelist.json
# MODULE:powerd extras
if use powerd; then
newinitd "${FILESDIR}"/nvidia-powerd.initd nvidia-powerd #923117
systemd_dounit systemd/system/nvidia-powerd.service
insinto /usr/share/dbus-1/system.d
doins nvidia-dbus.conf
fi
# enabling is needed for sleep to work properly and little reason not to do
# it unconditionally for a better user experience
: "$(systemd_get_systemunitdir)"
local unitdir=${_#"${EPREFIX}"}
# not using relative symlinks to match systemd's own links
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-hibernate.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-suspend.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend.service.wants}/nvidia-resume.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-suspend-then-hibernate.service
dosym {"${unitdir}",/etc/systemd/system/systemd-suspend-then-hibernate.service.wants}/nvidia-resume.service
# also add a custom elogind hook to do the equivalent of the above
exeinto /usr/lib/elogind/system-sleep
newexe "${FILESDIR}"/system-sleep.elogind nvidia
# <elogind-255.5 used a different path (bug #939216), keep a compat symlink
# TODO: cleanup after 255.5 been stable for a few months
dosym {/usr/lib,/"${libdir}"}/elogind/system-sleep/nvidia
# needed with >=systemd-256 or may fail to resume with some setups
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1072722
insinto "${unitdir}"/systemd-homed.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_HOME_LOCK_FREEZE_SESSION=false
EOF
insinto "${unitdir}"/systemd-suspend.service.d
newins - 10-nvidia.conf <<-EOF
[Service]
Environment=SYSTEMD_SLEEP_FREEZE_USER_SESSIONS=false
EOF
dosym -r "${unitdir}"/systemd-{suspend,hibernate}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,hybrid-sleep}.service.d/10-nvidia.conf
dosym -r "${unitdir}"/systemd-{suspend,suspend-then-hibernate}.service.d/10-nvidia.conf
# symlink non-versioned so nvidia-settings can use it even if misdetected
dosym nvidia-application-profiles-${PV}-key-documentation \
${paths[APPLICATION_PROFILE]}/nvidia-application-profiles-key-documentation
# don't attempt to strip firmware files (silences errors)
dostrip -x ${paths[FIRMWARE]}
# sandbox issues with /dev/nvidiactl and others (bug #904292,#921578)
# are widespread and sometime affect revdeps of packages built with
# USE=opencl/cuda making it hard to manage in ebuilds (minimal set,
# ebuilds should handle manually if need others or addwrite)
insinto /etc/sandbox.d
newins - 20nvidia <<<'SANDBOX_PREDICT="/dev/nvidiactl:/dev/nvidia-caps:/dev/char"'
# dracut does not use /etc/modprobe.d if hostonly=no, but want to make sure
# our settings are used for bug 932781#c8 and nouveau blacklist if either
# modules are included (however, just best-effort without initramfs regen)
if use modules; then
echo "install_items+=\" ${EPREFIX}/etc/modprobe.d/nvidia.conf \"" >> \
"${ED}"/usr/lib/dracut/dracut.conf.d/10-${PN}.conf || die
fi
}
pkg_preinst() {
has_version "${CATEGORY}/${PN}[kernel-open]" && NV_HAD_KERNEL_OPEN=
has_version "${CATEGORY}/${PN}[wayland]" && NV_HAD_WAYLAND=
use modules || return
# set video group id based on live system (bug #491414)
local g=$(egetent group video | cut -d: -f3)
[[ ${g} =~ ^[0-9]+$ ]] || die "Failed to determine video group id (got '${g}')"
sed -i "s/@VIDEOGID@/${g}/" "${ED}"/etc/modprobe.d/nvidia.conf || die
# try to find driver mismatches using temporary supported-gpus.json
# TODO?: automatically check "kernelopen" bit for USE=kernel-open compat
for g in $(grep -l 0x10de /sys/bus/pci/devices/*/vendor 2>/dev/null); do
g=$(grep -io "\"devid\":\"$(<${g%vendor}device)\"[^}]*branch\":\"[0-9]*" \
"${ED}"/usr/share/nvidia/supported-gpus.json 2>/dev/null)
if [[ ${g} ]]; then
g=$((${g##*\"}+1))
if ver_test -ge ${g}; then
NV_LEGACY_MASK=">=${CATEGORY}/${PN}-${g}"
break
fi
fi
done
rm "${ED}"/usr/share/nvidia/supported-gpus.json || die
}
pkg_postinst() {
linux-mod-r1_pkg_postinst
readme.gentoo_print_elog
if [[ -r /proc/driver/nvidia/version &&
$(</proc/driver/nvidia/version) != *" ${PV} "* ]]; then
ewarn "Currently loaded NVIDIA modules do not match the newly installed"
ewarn "libraries and may prevent launching GPU-accelerated applications."
if use modules; then
ewarn "Easiest way to fix this is normally to reboot. If still run into issues"
ewarn "(e.g. API mismatch messages in the \`dmesg\` output), please verify"
ewarn "that the running kernel is ${KV_FULL} and that (if used) the"
ewarn "initramfs does not include NVIDIA modules (or at least, not old ones)."
fi
fi
if [[ $(</proc/cmdline) == *slub_debug=[!-]* ]]; then
ewarn "Detected that the current kernel command line is using 'slub_debug=',"
ewarn "this may lead to system instability/freezes with this version of"
ewarn "${PN}. Bug: https://bugs.gentoo.org/796329"
fi
if [[ -v NV_LEGACY_MASK ]]; then
ewarn
ewarn "***WARNING***"
ewarn
ewarn "You are installing a version of ${PN} known not to work"
ewarn "with a GPU of the current system. If unwanted, add the mask:"
if [[ -d ${EROOT}/etc/portage/package.mask ]]; then
ewarn " echo '${NV_LEGACY_MASK}' > ${EROOT}/etc/portage/package.mask/${PN}"
else
ewarn " echo '${NV_LEGACY_MASK}' >> ${EROOT}/etc/portage/package.mask"
fi
ewarn "...then downgrade to a legacy[1] branch if possible (not all old versions"
ewarn "are available or fully functional, may need to consider nouveau[2])."
ewarn "[1] https://www.nvidia.com/object/IO_32667.html"
ewarn "[2] https://wiki.gentoo.org/wiki/Nouveau"
fi
if use kernel-open && [[ ! -v NV_HAD_KERNEL_OPEN ]]; then
ewarn
ewarn "Open source variant of ${PN} was selected, note that it requires"
ewarn "Turing/Ampere+ GPUs (aka GTX 1650+). Try disabling if run into issues."
ewarn "Also see: ${EROOT}/usr/share/doc/${PF}/html/kernel_open.html"
fi
if use wayland && use modules && [[ ! -v NV_HAD_WAYLAND ]]; then
elog
elog "With USE=wayland, this version of ${PN} sets nvidia-drm.modeset=1"
elog "in '${EROOT}/etc/modprobe.d/nvidia.conf'. This feature is considered"
elog "experimental but is required for wayland."
elog
elog "If you experience issues, either disable wayland or edit nvidia.conf."
elog "Of note, may possibly cause issues with SLI and Reverse PRIME."
fi
if use !kernel-open && ver_replacing -lt 555; then
elog
elog "If using a Turing/Ampere+ GPU (aka GTX 1650+), note that >=nvidia-drivers-555"
elog "enables the use of the GSP firmware by default. *If* experience regressions,"
elog "please see '${EROOT}/etc/modprobe.d/nvidia.conf' to optionally disable."
fi
}