about summary refs log tree commit diff
path: root/pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix
blob: 1b216ee625a89ead1ce946059863a496d08f7c1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ lib
, backendStdenv
, fetchurl
, autoPatchelfHook
, autoAddOpenGLRunpathHook
}:

pname:
attrs:

let
  arch = "linux-x86_64";
in
backendStdenv.mkDerivation {
  inherit pname;
  inherit (attrs) version;

  src = assert (lib.hasAttr arch attrs); fetchurl {
    url = "https://developer.download.nvidia.com/compute/cuda/redist/${attrs.${arch}.relative_path}";
    inherit (attrs.${arch}) sha256;
  };

  nativeBuildInputs = [
    autoPatchelfHook
    # This hook will make sure libcuda can be found
    # in typically /lib/opengl-driver by adding that
    # directory to the rpath of all ELF binaries.
    # Check e.g. with `patchelf --print-rpath path/to/my/binary
    autoAddOpenGLRunpathHook
  ];

  buildInputs = [
    # autoPatchelfHook will search for a libstdc++ and we're giving it a
    # "compatible" libstdc++ from the same toolchain that NVCC uses.
    #
    # NB: We don't actually know if this is the right thing to do
    backendStdenv.cc.cc.lib
  ];

  dontBuild = true;

  # TODO: choose whether to install static/dynamic libs
  installPhase = ''
    runHook preInstall
    rm LICENSE
    mkdir -p $out
    mv * $out
    runHook postInstall
  '';

  passthru.stdenv = backendStdenv;

  meta = {
    description = attrs.name;
    license = lib.licenses.unfree;
    platforms = lib.optionals (lib.hasAttr arch attrs) [ "x86_64-linux" ];
  };
}