1{
2 autoAddDriverRunpath,
3 backendStdenv,
4 cmake,
5 cudatoolkit,
6 cudaMajorMinorVersion,
7 fetchFromGitHub,
8 fetchpatch,
9 freeimage,
10 glfw3,
11 hash,
12 lib,
13 pkg-config,
14 stdenv,
15}:
16let
17 inherit (lib) lists strings;
18in
19backendStdenv.mkDerivation (finalAttrs: {
20 strictDeps = true;
21
22 pname = "cuda-samples";
23 version = cudaMajorMinorVersion;
24
25 src = fetchFromGitHub {
26 owner = "NVIDIA";
27 repo = "cuda-samples";
28 rev = "v${finalAttrs.version}";
29 inherit hash;
30 };
31
32 nativeBuildInputs =
33 [
34 autoAddDriverRunpath
35 pkg-config
36 ]
37 # CMake has to run as a native, build-time dependency for libNVVM samples.
38 # However, it's not the primary build tool -- that's still make.
39 # As such, we disable CMake's build system.
40 ++ lists.optionals (strings.versionAtLeast finalAttrs.version "12.2") [ cmake ];
41
42 dontUseCmakeConfigure = true;
43
44 buildInputs = [
45 cudatoolkit
46 freeimage
47 glfw3
48 ];
49
50 # See https://github.com/NVIDIA/cuda-samples/issues/75.
51 patches = lib.optionals (finalAttrs.version == "11.3") [
52 (fetchpatch {
53 url = "https://github.com/NVIDIA/cuda-samples/commit/5c3ec60faeb7a3c4ad9372c99114d7bb922fda8d.patch";
54 hash = "sha256-0XxdmNK9MPpHwv8+qECJTvXGlFxc+fIbta4ynYprfpU=";
55 })
56 ];
57
58 enableParallelBuilding = true;
59
60 preConfigure = ''
61 export CUDA_PATH=${cudatoolkit}
62 '';
63
64 installPhase = ''
65 runHook preInstall
66
67 install -Dm755 -t $out/bin bin/${stdenv.hostPlatform.parsed.cpu.name}/${stdenv.hostPlatform.parsed.kernel.name}/release/*
68
69 runHook postInstall
70 '';
71
72 meta = {
73 description = "Samples for CUDA Developers which demonstrates features in CUDA Toolkit";
74 # CUDA itself is proprietary, but these sample apps are not.
75 license = lib.licenses.bsd3;
76 platforms = [ "x86_64-linux" ];
77 maintainers = with lib.maintainers; [ obsidian-systems-maintenance ];
78 teams = [ lib.teams.cuda ];
79 };
80})