about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/misc/fx-cast-bridge/default.nix
blob: 5f2274101e56d345d0500a7b46203cdb6076ca79 (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
{ lib, buildNpmPackage, fetchFromGitHub, avahi-compat, nodejs, python3 }:

buildNpmPackage rec {
  pname = "fx-cast-bridge";
  version = "0.3.1";

  src = fetchFromGitHub {
    owner = "hensm";
    repo = "fx_cast";
    rev = "v${version}";
    hash = "sha256-hB4NVJW2exHoKsMp0CKzHerYgj8aR77rV+ZsCoWA1Dg=";
  };
  sourceRoot = "${src.name}/app";
  npmDepsHash = "sha256-GLrDRZqKcX1PDGREx+MLZ1TEjr88r9nz4TvZ9nvo40g=";

  nativeBuildInputs = [ python3 ];
  buildInputs = [ avahi-compat ];

  postPatch = ''
    substituteInPlace bin/lib/paths.js \
      --replace "../../../" "../../"
  '';

  dontNpmInstall = true;
  installPhase = ''
    runHook preInstall

    mkdir -p $out/{bin,lib/mozilla/native-messaging-hosts}

    substituteInPlace dist/app/fx_cast_bridge.json \
      --replace "$(realpath dist/app/fx_cast_bridge.sh)" "$out/bin/fx_cast_bridge"
    mv dist/app/fx_cast_bridge.json $out/lib/mozilla/native-messaging-hosts

    rm dist/app/fx_cast_bridge.sh
    mv dist/app $out/lib/fx_cast_bridge
    mv node_modules $out/lib/fx_cast_bridge/node_modules

    echo "#! /bin/sh
    NODE_PATH=\"$out/lib/node_modules\" \\
      exec ${nodejs}/bin/node \\
      $out/lib/fx_cast_bridge/src/main.js \\
      --_name fx_cast_bridge \"\$@\"
    " >$out/bin/fx_cast_bridge
    chmod +x $out/bin/fx_cast_bridge

    runHook postInstall
  '';

  meta = with lib; {
    description = "Implementation of the Chrome Sender API (Chromecast) within Firefox";
    homepage = "https://hensm.github.io/fx_cast/";
    license = licenses.mit;
    maintainers = with maintainers; [ dtzWill pedrohlc ];
  };
}