1 { lib, stdenv, fetchurl, dpkg }:
3 stdenv.mkDerivation rec {
4 pname = "fx_cast_bridge";
8 url = "https://github.com/hensm/fx_cast/releases/download/v${version}/${pname}-${version}-x64.deb";
9 sha256 = "0kd58vzsq1qzl7qsh1qv25ylxvr5y37li03gjb48x4vhd85slzz5";
12 nativeBuildInputs = [ dpkg ];
24 install -DT {opt/fx_cast,$out/bin}/${pname}
25 install -DT {usr,$out}/lib/mozilla/native-messaging-hosts/${pname}.json
27 substituteInPlace $out/lib/mozilla/native-messaging-hosts/${pname}.json \
28 --replace {/opt/fx_cast,$out/bin}/${pname}
31 # See now-cli/default.nix
34 libPath = lib.makeLibraryPath [stdenv.cc.cc stdenv.cc.libc];
35 bin = "$out/bin/${pname}";
38 orig_size=$(stat --printf=%s ${bin})
40 patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" ${bin}
41 patchelf --set-rpath ${libPath} ${bin}
44 new_size=$(stat --printf=%s ${bin})
46 ###### zeit-pkg fixing starts here.
47 # we're replacing plaintext js code that looks like
48 # PAYLOAD_POSITION = '1234 ' | 0
50 # PRELUDE_POSITION = '1234 ' | 0
51 # ^-----20-chars-----^^------22-chars------^
52 # ^-- grep points here
54 # var_* are as described above
55 # shift_by seems to be safe so long as all patchelf adjustments occur
56 # before any locations pointed to by hardcoded offsets
60 shift_by=$(expr $new_size - $orig_size)
63 # $1 = name of variable to adjust
64 location=$(grep -obUam1 "$1" ${bin} | cut -d: -f1)
65 location=$(expr $location + $var_skip)
67 value=$(dd if=${bin} iflag=count_bytes,skip_bytes skip=$location \
68 bs=1 count=$var_select status=none)
69 value=$(expr $shift_by + $value)
71 echo -n $value | dd of=${bin} bs=1 seek=$location conv=notrunc
74 fix_offset PAYLOAD_POSITION
75 fix_offset PRELUDE_POSITION
80 description = "Implementation of the Chrome Sender API (Chromecast) within Firefox";
81 homepage = "https://hensm.github.io/fx_cast/";
82 license = licenses.mit;
83 maintainers = with maintainers; [ dtzWill ];