summary refs log tree commit diff
path: root/pkgs/applications/video/webtorrent_desktop/default.nix
blob: 8258f8583090dd9b887a9d31a931847cf8e05dc3 (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
{
  alsaLib, atk, cairo, cups, dbus, dpkg, expat, fetchurl, fontconfig, freetype,
  gdk-pixbuf, glib, gnome2, libX11, libXScrnSaver, libXcomposite, libXcursor,
  libXdamage, libXext, libXfixes, libXi, libXrandr, libXrender, libXtst,
  libxcb, nspr, nss, stdenv, udev
}:

  let
    rpath = stdenv.lib.makeLibraryPath ([
    alsaLib
    atk
    cairo
    cups
    dbus
    expat
    fontconfig
    freetype
    gdk-pixbuf
    glib
    gnome2.GConf
    gnome2.gtk
    gnome2.pango
    libX11
    libXScrnSaver
    libXcomposite
    libXcursor
    libXdamage
    libXext
    libXfixes
    libXi
    libXrandr
    libXrender
    libXtst
    libxcb
    nspr
    nss
    stdenv.cc.cc
    udev
    ]);
  in stdenv.mkDerivation rec {
    pname = "webtorrent-desktop";
    version = "0.20.0";

    src =
      if stdenv.hostPlatform.system == "x86_64-linux" then
        fetchurl {
          url = "https://github.com/webtorrent/webtorrent-desktop/releases/download/v0.20.0/webtorrent-desktop_${version}-1_amd64.deb";
          sha256 = "1kkrnbimiip5pn2nwpln35bbdda9gc3cgrjwphq4fqasbjf2781k";
        }
        else
          throw "Webtorrent is not currently supported on ${stdenv.hostPlatform.system}";
    phases = [ "unpackPhase" "installPhase" ];
    nativeBuildInputs = [ dpkg ];
    unpackPhase = "dpkg-deb -x $src .";
    installPhase = ''
      mkdir -p $out
      cp -R opt $out

      mv ./usr/share $out/share
      mv $out/opt/webtorrent-desktop $out/libexec
      chmod +x $out/libexec/WebTorrent
      rmdir $out/opt

      chmod -R g-w $out

      # Patch WebTorrent
      patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
               --set-rpath ${rpath}:$out/libexec $out/libexec/WebTorrent

      # Symlink to bin
      mkdir -p $out/bin
      ln -s $out/libexec/WebTorrent $out/bin/WebTorrent

      # Fix the desktop link
      substituteInPlace $out/share/applications/webtorrent-desktop.desktop \
        --replace /opt/webtorrent-desktop $out/bin
    '';

    meta = with stdenv.lib; {
      description = "Streaming torrent app for Mac, Windows, and Linux.";
      homepage = https://webtorrent.io/desktop;
      license = licenses.mit;
      maintainers = [ maintainers.flokli ];
      platforms = [
        "x86_64-linux"
      ];
    };
  }