acr-cli: init at 0.14 (#359508)
[NixPkgs.git] / pkgs / by-name / bl / blackmagic-desktop-video / package.nix
blob8888ba83a8c3dc44e05944dac0addea0e06af02b
1 { stdenv
2 , cacert
3 , curl
4 , runCommandLocal
5 , lib
6 , autoPatchelfHook
7 , libcxx
8 , libGL
9 , gcc
11 stdenv.mkDerivation (finalAttrs: {
12   pname = "blackmagic-desktop-video";
13   version = "14.2a1";
15   buildInputs = [
16     autoPatchelfHook
17     libcxx
18     libGL
19     gcc.cc.lib
20   ];
22   # yes, the below download function is an absolute mess.
23   # blame blackmagicdesign.
24   src =
25     let
26       # from the URL the download page where you click the "only download" button is at
27       REFERID = "b97e55f37a0042fbacd234971d8c93ed";
28       # from the URL that the POST happens to, see browser console
29       DOWNLOADID = "552546307a7c4de29ea6d09a6ca08c90";
30     in
31     runCommandLocal "${finalAttrs.pname}-${lib.versions.majorMinor finalAttrs.version}-src.tar.gz"
32       {
33         outputHashMode = "recursive";
34         outputHashAlgo = "sha256";
35         outputHash = "sha256-rfZDL1YvAuMD5u68MMyiT8cERsIHMc9K25lXt7cqrrk=";
37         impureEnvVars = lib.fetchers.proxyImpureEnvVars;
39         nativeBuildInputs = [ curl ];
41         # ENV VARS
42         SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
44         inherit REFERID;
45         SITEURL = "https://www.blackmagicdesign.com/api/register/us/download/${DOWNLOADID}";
47         USERAGENT = builtins.concatStringsSep " " [
48           "User-Agent: Mozilla/5.0 (X11; Linux ${stdenv.hostPlatform.linuxArch})"
49           "AppleWebKit/537.36 (KHTML, like Gecko)"
50           "Chrome/77.0.3865.75"
51           "Safari/537.36"
52         ];
54         REQJSON = builtins.toJSON {
55           "country" = "nl";
56           "downloadOnly" = true;
57           "platform" = "Linux";
58           "policy" = true;
59         };
61       } ''
62       RESOLVEURL=$(curl \
63         -s \
64         -H "$USERAGENT" \
65         -H 'Content-Type: application/json;charset=UTF-8' \
66         -H "Referer: https://www.blackmagicdesign.com/support/download/$REFERID/Linux" \
67         --data-ascii "$REQJSON" \
68         --compressed \
69         "$SITEURL")
70       curl \
71         --retry 3 --retry-delay 3 \
72         --compressed \
73         "$RESOLVEURL" \
74         > $out
75     '';
77   postUnpack =
78     let
79       arch = stdenv.hostPlatform.uname.processor;
80     in
81     ''
82       tar xf Blackmagic_Desktop_Video_Linux_${lib.head (lib.splitString "a" finalAttrs.version)}/other/${arch}/desktopvideo-${finalAttrs.version}-${arch}.tar.gz
83       unpacked=$NIX_BUILD_TOP/desktopvideo-${finalAttrs.version}-${stdenv.hostPlatform.uname.processor}
84     '';
86   installPhase = ''
87     runHook preInstall
88     mkdir -p $out/{bin,share/doc,lib/systemd/system}
89     cp -r $unpacked/usr/share/doc/desktopvideo $out/share/doc
90     cp $unpacked/usr/lib/*.so $out/lib
91     cp $unpacked/usr/lib/systemd/system/DesktopVideoHelper.service $out/lib/systemd/system
92     cp $unpacked/usr/lib/blackmagic/DesktopVideo/DesktopVideoHelper $out/bin/
93     substituteInPlace $out/lib/systemd/system/DesktopVideoHelper.service \
94       --replace-fail "/usr/lib/blackmagic/DesktopVideo/DesktopVideoHelper" "$out/bin/DesktopVideoHelper"
95     runHook postInstall
96   '';
98   # need to tell the DesktopVideoHelper where to find its own library
99   appendRunpaths = [ "${placeholder "out"}/lib" ];
101   meta = with lib; {
102     homepage = "https://www.blackmagicdesign.com/support/family/capture-and-playback";
103     maintainers = [ maintainers.naxdy ];
104     license = licenses.unfree;
105     description = "Supporting applications for Blackmagic Decklink. Doesn't include the desktop applications, only the helper required to make the driver work";
106     platforms = platforms.linux;
107   };