biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / applications / video / davinci-resolve / default.nix
blob686821482e6dd8ef342d3aa91702f70d3a4aa280
1 { stdenv
2 , lib
3 , cacert
4 , curl
5 , runCommandLocal
6 , unzip
7 , appimage-run
8 , addDriverRunpath
9 , dbus
10 , libGLU
11 , xorg
12 , buildFHSEnv
13 , buildFHSEnvChroot
14 , bash
15 , writeText
16 , ocl-icd
17 , xkeyboard_config
18 , glib
19 , libarchive
20 , libxcrypt
21 , python3
22 , aprutil
23 , makeDesktopItem
24 , copyDesktopItems
25 , jq
27 , studioVariant ? false
29 , common-updater-scripts
30 , writeShellApplication
33 let
34   davinci = (
35     stdenv.mkDerivation rec {
36       pname = "davinci-resolve${lib.optionalString studioVariant "-studio"}";
37       version = "19.0.2";
39       nativeBuildInputs = [
40         (appimage-run.override { buildFHSEnv = buildFHSEnvChroot; } )
41         addDriverRunpath
42         copyDesktopItems
43         unzip
44       ];
46       # Pretty sure, there are missing dependencies ...
47       buildInputs = [
48         libGLU
49         xorg.libXxf86vm
50       ];
52       src = runCommandLocal "${pname}-src.zip"
53         rec {
54           outputHashMode = "recursive";
55           outputHashAlgo = "sha256";
56           outputHash =
57             if studioVariant
58             then "sha256-q11stWFWRDUebAUzGH23R3Spd3EdDG85+6yB/srYCJY="
59             else "sha256-dYTrO0wpIN68WhBovmYLK5uWOQ1nubpSyKqPCDMPMiM=";
61           impureEnvVars = lib.fetchers.proxyImpureEnvVars;
63           nativeBuildInputs = [ curl jq ];
65           # ENV VARS
66           SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
68           # Get linux.downloadId from HTTP response on https://www.blackmagicdesign.com/products/davinciresolve
69           REFERID = "263d62f31cbb49e0868005059abcb0c9";
70           DOWNLOADSURL = "https://www.blackmagicdesign.com/api/support/us/downloads.json";
71           SITEURL = "https://www.blackmagicdesign.com/api/register/us/download";
72           PRODUCT = "DaVinci Resolve${lib.optionalString studioVariant " Studio"}";
73           VERSION = version;
75           USERAGENT = builtins.concatStringsSep " " [
76             "User-Agent: Mozilla/5.0 (X11; Linux ${stdenv.hostPlatform.linuxArch})"
77             "AppleWebKit/537.36 (KHTML, like Gecko)"
78             "Chrome/77.0.3865.75"
79             "Safari/537.36"
80           ];
82           REQJSON = builtins.toJSON {
83             "firstname" = "NixOS";
84             "lastname" = "Linux";
85             "email" = "someone@nixos.org";
86             "phone" = "+31 71 452 5670";
87             "country" = "nl";
88             "street" = "-";
89             "state" = "Province of Utrecht";
90             "city" = "Utrecht";
91             "product" = PRODUCT;
92           };
94         } ''
95         DOWNLOADID=$(
96           curl --silent --compressed "$DOWNLOADSURL" \
97             | jq --raw-output '.downloads[] | .urls.Linux?[]? | select(.downloadTitle | test("^'"$PRODUCT $VERSION"'( Update)?$")) | .downloadId'
98         )
99         echo "downloadid is $DOWNLOADID"
100         test -n "$DOWNLOADID"
101         RESOLVEURL=$(curl \
102           --silent \
103           --header 'Host: www.blackmagicdesign.com' \
104           --header 'Accept: application/json, text/plain, */*' \
105           --header 'Origin: https://www.blackmagicdesign.com' \
106           --header "$USERAGENT" \
107           --header 'Content-Type: application/json;charset=UTF-8' \
108           --header "Referer: https://www.blackmagicdesign.com/support/download/$REFERID/Linux" \
109           --header 'Accept-Encoding: gzip, deflate, br' \
110           --header 'Accept-Language: en-US,en;q=0.9' \
111           --header 'Authority: www.blackmagicdesign.com' \
112           --header 'Cookie: _ga=GA1.2.1849503966.1518103294; _gid=GA1.2.953840595.1518103294' \
113           --data-ascii "$REQJSON" \
114           --compressed \
115           "$SITEURL/$DOWNLOADID")
116         echo "resolveurl is $RESOLVEURL"
118         curl \
119           --retry 3 --retry-delay 3 \
120           --header "Upgrade-Insecure-Requests: 1" \
121           --header "$USERAGENT" \
122           --header "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" \
123           --header "Accept-Language: en-US,en;q=0.9" \
124           --compressed \
125           "$RESOLVEURL" \
126           > $out
127       '';
129       # The unpack phase won't generate a directory
130       sourceRoot = ".";
132       installPhase = let
133         appimageName = "DaVinci_Resolve_${lib.optionalString studioVariant "Studio_"}${version}_Linux.run";
134       in ''
135         runHook preInstall
137         export HOME=$PWD/home
138         mkdir -p $HOME
140         mkdir -p $out
141         test -e ${lib.escapeShellArg appimageName}
142         appimage-run ${lib.escapeShellArg appimageName} -i -y -n -C $out
144         mkdir -p $out/{configs,DolbyVision,easyDCP,Fairlight,GPUCache,logs,Media,"Resolve Disk Database",.crashreport,.license,.LUT}
145         runHook postInstall
146       '';
148       dontStrip = true;
150       postFixup = ''
151         for program in $out/bin/*; do
152           isELF "$program" || continue
153           addDriverRunpath "$program"
154         done
156         for program in $out/libs/*; do
157           isELF "$program" || continue
158           if [[ "$program" != *"libcudnn_cnn_infer"* ]];then
159             echo $program
160             addDriverRunpath "$program"
161           fi
162         done
163         ln -s $out/libs/libcrypto.so.1.1 $out/libs/libcrypt.so.1
164       '';
166       desktopItems = [
167         (makeDesktopItem {
168           name = "davinci-resolve${lib.optionalString studioVariant "-studio"}";
169           desktopName = "Davinci Resolve${lib.optionalString studioVariant " Studio"}";
170           genericName = "Video Editor";
171           exec = "davinci-resolve${lib.optionalString studioVariant "-studio"}";
172           icon = "davinci-resolve${lib.optionalString studioVariant "-studio"}";
173           comment = "Professional video editing, color, effects and audio post-processing";
174           categories = [
175             "AudioVideo"
176             "AudioVideoEditing"
177             "Video"
178             "Graphics"
179           ];
180         })
181       ];
182     }
183   );
185 buildFHSEnv {
186   inherit (davinci) pname version;
188   targetPkgs = pkgs: with pkgs; [
189     alsa-lib
190     aprutil
191     bzip2
192     davinci
193     dbus
194     expat
195     fontconfig
196     freetype
197     glib
198     libGL
199     libGLU
200     libarchive
201     libcap
202     librsvg
203     libtool
204     libuuid
205     libxcrypt # provides libcrypt.so.1
206     libxkbcommon
207     nspr
208     ocl-icd
209     opencl-headers
210     python3
211     python3.pkgs.numpy
212     udev
213     xdg-utils # xdg-open needed to open URLs
214     xorg.libICE
215     xorg.libSM
216     xorg.libX11
217     xorg.libXcomposite
218     xorg.libXcursor
219     xorg.libXdamage
220     xorg.libXext
221     xorg.libXfixes
222     xorg.libXi
223     xorg.libXinerama
224     xorg.libXrandr
225     xorg.libXrender
226     xorg.libXt
227     xorg.libXtst
228     xorg.libXxf86vm
229     xorg.libxcb
230     xorg.xcbutil
231     xorg.xcbutilimage
232     xorg.xcbutilkeysyms
233     xorg.xcbutilrenderutil
234     xorg.xcbutilwm
235     xorg.xkeyboardconfig
236     zlib
237   ];
239   extraPreBwrapCmds = lib.optionalString studioVariant ''
240     mkdir -p ~/.local/share/DaVinciResolve/license || exit 1
241   '';
243   extraBwrapArgs = lib.optionals studioVariant [
244     "--bind \"$HOME\"/.local/share/DaVinciResolve/license ${davinci}/.license"
245   ];
247   runScript = "${bash}/bin/bash ${
248     writeText "davinci-wrapper"
249     ''
250     export QT_XKB_CONFIG_ROOT="${xkeyboard_config}/share/X11/xkb"
251     export QT_PLUGIN_PATH="${davinci}/libs/plugins:$QT_PLUGIN_PATH"
252     export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/lib32:${davinci}/libs
253     ${davinci}/bin/resolve
254     ''
255   }";
257   extraInstallCommands = ''
258     mkdir -p $out/share/applications $out/share/icons/hicolor/128x128/apps
259     ln -s ${davinci}/share/applications/*.desktop $out/share/applications/
260     ln -s ${davinci}/graphics/DV_Resolve.png $out/share/icons/hicolor/128x128/apps/davinci-resolve${lib.optionalString studioVariant "-studio"}.png
261   '';
263   passthru = {
264     inherit davinci;
265     updateScript = lib.getExe (writeShellApplication {
266       name = "update-davinci-resolve";
267       runtimeInputs = [ curl jq common-updater-scripts ];
268       text = ''
269         set -o errexit
270         drv=pkgs/applications/video/davinci-resolve/default.nix
271         currentVersion=${lib.escapeShellArg davinci.version}
272         downloadsJSON="$(curl --fail --silent https://www.blackmagicdesign.com/api/support/us/downloads.json)"
274         latestLinuxVersion="$(echo "$downloadsJSON" | jq '[.downloads[] | select(.urls.Linux) | .urls.Linux[] | select(.downloadTitle | test("DaVinci Resolve")) | .downloadTitle]' | grep -oP 'DaVinci Resolve \K\d+\.\d+(\.\d+)?' | sort | tail -n 1)"
275         update-source-version davinci-resolve "$latestLinuxVersion" --source-key=davinci.src
277         # Since the standard and studio both use the same version we need to reset it before updating studio
278         sed -i -e "s/""$latestLinuxVersion""/""$currentVersion""/" "$drv"
280         latestStudioLinuxVersion="$(echo "$downloadsJSON" | jq '[.downloads[] | select(.urls.Linux) | .urls.Linux[] | select(.downloadTitle | test("DaVinci Resolve")) | .downloadTitle]' | grep -oP 'DaVinci Resolve Studio \K\d+\.\d+(\.\d+)?' | sort | tail -n 1)"
281         update-source-version davinci-resolve-studio "$latestStudioLinuxVersion" --source-key=davinci.src
282       '';
283     });
284   };
286   meta = with lib; {
287     description = "Professional video editing, color, effects and audio post-processing";
288     homepage = "https://www.blackmagicdesign.com/products/davinciresolve";
289     license = licenses.unfree;
290     maintainers = with maintainers; [ amarshall jshcmpbll orivej ];
291     platforms = [ "x86_64-linux" ];
292     sourceProvenance = with sourceTypes; [ binaryNativeCode ];
293     mainProgram = "davinci-resolve${lib.optionalString studioVariant "-studio"}";
294   };