about summary refs log tree commit diff
path: root/pkgs/development/libraries/ndi/default.nix
blob: 78a4f808b4c3eb0cfbe440746bf2506b464be95d (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
59
60
61
62
63
64
65
66
67
68
69
{ lib, stdenv, fetchurl, avahi, obs-studio-plugins }:

let
  versionJSON = lib.importJSON ./version.json;
  ndiPlatform =
    if stdenv.hostPlatform.isAarch64 then "aarch64-rpi4-linux-gnueabi"
    else if stdenv.hostPlatform.isAarch32 then "arm-rpi2-linux-gnueabihf"
    else if stdenv.hostPlatform.isx86_64 then "x86_64-linux-gnu"
    else if stdenv.hostPlatform.isi686 then "i686-linux-gnu"
    else throw "unsupported platform for NDI SDK";
in
stdenv.mkDerivation rec {
  pname = "ndi";
  version = versionJSON.version;
  majorVersion = builtins.head (builtins.splitVersion version);
  installerName = "Install_NDI_SDK_v${majorVersion}_Linux";

  src = fetchurl {
    name = "${pname}-${version}.tar.gz";
    url = "https://downloads.ndi.tv/SDK/NDI_SDK_Linux/${installerName}.tar.gz";
    hash = versionJSON.hash;
  };

  buildInputs = [ avahi ];

  unpackPhase = ''
    unpackFile $src
    echo y | ./${installerName}.sh
    sourceRoot="NDI SDK for Linux";
  '';

  installPhase = ''
    mkdir $out
    mv bin/${ndiPlatform} $out/bin
    for i in $out/bin/*; do
      if [ -L "$i" ]; then continue; fi
      patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$i"
    done
    patchelf --set-rpath "${avahi}/lib:${stdenv.cc.libc}/lib" $out/bin/ndi-record
    mv lib/${ndiPlatform} $out/lib
    for i in $out/lib/*; do
      if [ -L "$i" ]; then continue; fi
      patchelf --set-rpath "${avahi}/lib:${stdenv.cc.libc}/lib" "$i"
    done
    rm $out/bin/libndi.so.${majorVersion}
    ln -s $out/lib/libndi.so.${version} $out/bin/libndi.so.${majorVersion}
    mv include examples $out/
    mkdir -p $out/share/doc/${pname}-${version}
    mv licenses $out/share/doc/${pname}-${version}/licenses
    mv documentation/* $out/share/doc/${pname}-${version}/
  '';

  # Stripping breaks ndi-record.
  dontStrip = true;

  passthru.tests = {
    inherit (obs-studio-plugins) obs-ndi;
  };
  passthru.updateScript = ./update.py;

  meta = with lib; {
    homepage = "https://ndi.video/ndi-sdk/";
    description = "NDI Software Developer Kit";
    platforms = ["x86_64-linux" "i686-linux" "aarch64-linux" "armv7l-linux"];
    hydraPlatforms = [];
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    license = licenses.unfree;
  };
}