about summary refs log tree commit diff
path: root/pkgs/applications/video/mpv/scripts/webtorrent-mpv-hook.nix
blob: 811b49e8714bc8f3d5bb3860713c081e2decba84 (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
{ lib , buildNpmPackage , fetchFromGitHub, nodejs }:

buildNpmPackage rec {
  pname = "webtorrent-mpv-hook";
  version = "1.3.3";

  src = fetchFromGitHub {
    owner = "mrxdst";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-AFKX31kriacXygZy0Mw+QwO+SwFEu13687mJ/WeAoKY=";
  };

  postPatch = ''
    substituteInPlace src/webtorrent.ts --replace "node_path: 'node'" "node_path: '${nodejs}/bin/node'"
    # This executable is just for telling non-Nix users how to install
    substituteInPlace package.json --replace '"bin": "build/bin.js",' ""
    rm -rf src/bin.ts
  '';

  npmDepsHash = "sha256-GpNUJ5ZCgMjSYLqsIE/RwkTSFT3uAhxrHPe7XvGDRHE=";
  makeCacheWritable = true;

  postInstall = ''
    mkdir -p $out/share/mpv/scripts/
    ln -s $out/lib/node_modules/webtorrent-mpv-hook/build/webtorrent.js $out/share/mpv/scripts/
  '';
  passthru.scriptName = "webtorrent.js";

  meta = {
    description = "Adds a hook that allows mpv to stream torrents";
    homepage = "https://github.com/mrxdst/webtorrent-mpv-hook";
    maintainers = [ lib.maintainers.chuangzhu ];
    license = lib.licenses.isc;
  };
}