about summary refs log tree commit diff
path: root/pkgs/by-name/pl/plex-desktop/package.nix
blob: 50080c0153c96e56e5928489701851c2566dfe1d (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{ alsa-lib
, autoPatchelfHook
, buildFHSEnv
, dbus
, elfutils
, expat
, extraEnv ? { }
, fetchFromGitLab
, fetchurl
, glib
, glibc
, lib
, libGL
, libapparmor
, libbsd
, libedit
, libffi_3_3
, libgcrypt
, libglvnd
, makeShellWrapper
, sqlite
, squashfsTools
, stdenv
, tcp_wrappers
, udev
, waylandpp
, writeShellScript
, xkeyboard_config
, xorg
, xz
, zstd
}:
let
  pname = "plex-desktop";
  version = "1.96.0";
  rev = "69";
  meta = {
    homepage = "https://plex.tv/";
    description = "Streaming media player for Plex";
    longDescription = ''
      Plex for Linux is your client for playback on the Linux
      desktop. It features the point and click interface you see in your browser
      but uses a more powerful playback engine as well as
      some other advance features.
    '';
    maintainers = with lib.maintainers; [ detroyejr ];
    license = lib.licenses.unfree;
    platforms = [ "x86_64-linux" ];
    mainProgram = "plex-desktop";
  };

  # The latest unstable version isn't compatible with libraries that ship in the snap.
  libglvnd-1_4_0 = libglvnd.overrideAttrs {
    src = fetchFromGitLab {
      domain = "gitlab.freedesktop.org";
      owner = "glvnd";
      repo = "libglvnd";
      rev = "v1.4.0";
      sha256 = "sha256-Y6JHRygXcZtnrdnqi1Lzyvh/635gwZWnMeW9aRCpxxs";
    };
  };
  plex-desktop = stdenv.mkDerivation {
    inherit pname version meta;

    src = fetchurl {
      url = "https://api.snapcraft.io/api/v1/snaps/download/qc6MFRM433ZhI1XjVzErdHivhSOhlpf0_${rev}.snap";
      hash = "sha512-rECc8rK1ENAL5mXdabO8ynudCaSzz0yygOyg4gMbCtddgqwSOanP24/oguzPLr3zdRMC3VSf9B3hr2BGQ54tzg==";
    };

    nativeBuildInputs = [ squashfsTools ];

    buildInputs = [
      alsa-lib
      autoPatchelfHook
      dbus
      elfutils
      expat
      glib
      glibc
      libGL
      libapparmor
      libbsd
      libedit
      libffi_3_3
      libgcrypt
      makeShellWrapper
      sqlite
      squashfsTools
      stdenv.cc.cc
      tcp_wrappers
      udev
      waylandpp
      xorg.libXinerama
      xz
      zstd
    ];

    unpackPhase = ''
      runHook preUnpack
      unsquashfs "$src"
      cd squashfs-root
      runHook postUnpack
    '';

    dontWrapQtApps = true;

    installPhase =
      ''
        runHook preInstall

        cp -r . $out

        ln -s ${libedit}/lib/libedit.so.0 $out/lib/libedit.so.2
        rm $out/usr/lib/x86_64-linux-gnu/libasound.so.2
        ln -s ${alsa-lib}/lib/libasound.so.2 $out/usr/lib/x86_64-linux-gnu/libasound.so.2
        rm $out/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0
        ln -s ${alsa-lib}/lib/libasound.so.2.0.0 $out/usr/lib/x86_64-linux-gnu/libasound.so.2.0.0

        runHook postInstall
      '';
  };
in
buildFHSEnv {
    name = "${pname}-${version}";
    targetPkgs = pkgs: [ xkeyboard_config ];

    extraInstallCommands = ''
      mkdir -p $out/share/applications $out/share/icons/hicolor/scalable/apps
      install -m 444 -D ${plex-desktop}/meta/gui/plex-desktop.desktop $out/share/applications/plex-desktop.desktop
      substituteInPlace $out/share/applications/plex-desktop.desktop \
        --replace-fail \
        'Icon=''${SNAP}/meta/gui/icon.png' \
        'Icon=${plex-desktop}/meta/gui/icon.png' \
        --replace-fail \
        'Exec=plex-desktop' \
        'Exec=plex-desktop-${version}'
    '';

    runScript = writeShellScript "plex-desktop.sh" ''
      # Widevine won't download unless this directory exists.
      mkdir -p $HOME/.cache/plex/
      PLEX_USR_PATH=${lib.makeSearchPath "usr/lib/x86_64-linux-gnu"  [ plex-desktop ]}

      set -o allexport
      LD_LIBRARY_PATH=${lib.makeLibraryPath [ plex-desktop libglvnd-1_4_0 ]}:$PLEX_USR_PATH
      LIBGL_DRIVERS_PATH=$PLEX_USR_PATH/dri
      ${lib.toShellVars extraEnv}
      exec ${plex-desktop}/Plex.sh
  '';
}