Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / by-name / pl / plex-desktop / package.nix
blob50080c0153c96e56e5928489701851c2566dfe1d
1 { alsa-lib
2 , autoPatchelfHook
3 , buildFHSEnv
4 , dbus
5 , elfutils
6 , expat
7 , extraEnv ? { }
8 , fetchFromGitLab
9 , fetchurl
10 , glib
11 , glibc
12 , lib
13 , libGL
14 , libapparmor
15 , libbsd
16 , libedit
17 , libffi_3_3
18 , libgcrypt
19 , libglvnd
20 , makeShellWrapper
21 , sqlite
22 , squashfsTools
23 , stdenv
24 , tcp_wrappers
25 , udev
26 , waylandpp
27 , writeShellScript
28 , xkeyboard_config
29 , xorg
30 , xz
31 , zstd
33 let
34   pname = "plex-desktop";
35   version = "1.96.0";
36   rev = "69";
37   meta = {
38     homepage = "https://plex.tv/";
39     description = "Streaming media player for Plex";
40     longDescription = ''
41       Plex for Linux is your client for playback on the Linux
42       desktop. It features the point and click interface you see in your browser
43       but uses a more powerful playback engine as well as
44       some other advance features.
45     '';
46     maintainers = with lib.maintainers; [ detroyejr ];
47     license = lib.licenses.unfree;
48     platforms = [ "x86_64-linux" ];
49     mainProgram = "plex-desktop";
50   };
52   # The latest unstable version isn't compatible with libraries that ship in the snap.
53   libglvnd-1_4_0 = libglvnd.overrideAttrs {
54     src = fetchFromGitLab {
55       domain = "gitlab.freedesktop.org";
56       owner = "glvnd";
57       repo = "libglvnd";
58       rev = "v1.4.0";
59       sha256 = "sha256-Y6JHRygXcZtnrdnqi1Lzyvh/635gwZWnMeW9aRCpxxs";
60     };
61   };
62   plex-desktop = stdenv.mkDerivation {
63     inherit pname version meta;
65     src = fetchurl {
66       url = "https://api.snapcraft.io/api/v1/snaps/download/qc6MFRM433ZhI1XjVzErdHivhSOhlpf0_${rev}.snap";
67       hash = "sha512-rECc8rK1ENAL5mXdabO8ynudCaSzz0yygOyg4gMbCtddgqwSOanP24/oguzPLr3zdRMC3VSf9B3hr2BGQ54tzg==";
68     };
70     nativeBuildInputs = [ squashfsTools ];
72     buildInputs = [
73       alsa-lib
74       autoPatchelfHook
75       dbus
76       elfutils
77       expat
78       glib
79       glibc
80       libGL
81       libapparmor
82       libbsd
83       libedit
84       libffi_3_3
85       libgcrypt
86       makeShellWrapper
87       sqlite
88       squashfsTools
89       stdenv.cc.cc
90       tcp_wrappers
91       udev
92       waylandpp
93       xorg.libXinerama
94       xz
95       zstd
96     ];
98     unpackPhase = ''
99       runHook preUnpack
100       unsquashfs "$src"
101       cd squashfs-root
102       runHook postUnpack
103     '';
105     dontWrapQtApps = true;
107     installPhase =
108       ''
109         runHook preInstall
111         cp -r . $out
113         ln -s ${libedit}/lib/libedit.so.0 $out/lib/libedit.so.2
114         rm $out/usr/lib/x86_64-linux-gnu/libasound.so.2
115         ln -s ${alsa-lib}/lib/libasound.so.2 $out/usr/lib/x86_64-linux-gnu/libasound.so.2
116         rm $out/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
117         ln -s ${alsa-lib}/lib/libasound.so.2.0.0 $out/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
119         runHook postInstall
120       '';
121   };
123 buildFHSEnv {
124     name = "${pname}-${version}";
125     targetPkgs = pkgs: [ xkeyboard_config ];
127     extraInstallCommands = ''
128       mkdir -p $out/share/applications $out/share/icons/hicolor/scalable/apps
129       install -m 444 -D ${plex-desktop}/meta/gui/plex-desktop.desktop $out/share/applications/plex-desktop.desktop
130       substituteInPlace $out/share/applications/plex-desktop.desktop \
131         --replace-fail \
132         'Icon=''${SNAP}/meta/gui/icon.png' \
133         'Icon=${plex-desktop}/meta/gui/icon.png' \
134         --replace-fail \
135         'Exec=plex-desktop' \
136         'Exec=plex-desktop-${version}'
137     '';
139     runScript = writeShellScript "plex-desktop.sh" ''
140       # Widevine won't download unless this directory exists.
141       mkdir -p $HOME/.cache/plex/
142       PLEX_USR_PATH=${lib.makeSearchPath "usr/lib/x86_64-linux-gnu"  [ plex-desktop ]}
144       set -o allexport
145       LD_LIBRARY_PATH=${lib.makeLibraryPath [ plex-desktop libglvnd-1_4_0 ]}:$PLEX_USR_PATH
146       LIBGL_DRIVERS_PATH=$PLEX_USR_PATH/dri
147       ${lib.toShellVars extraEnv}
148       exec ${plex-desktop}/Plex.sh
149   '';