about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/misc/fx_cast/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/tools/misc/fx_cast/default.nix')
-rw-r--r--nixpkgs/pkgs/tools/misc/fx_cast/default.nix115
1 files changed, 47 insertions, 68 deletions
diff --git a/nixpkgs/pkgs/tools/misc/fx_cast/default.nix b/nixpkgs/pkgs/tools/misc/fx_cast/default.nix
index 4fcb5a655732..e3458ccfe5cf 100644
--- a/nixpkgs/pkgs/tools/misc/fx_cast/default.nix
+++ b/nixpkgs/pkgs/tools/misc/fx_cast/default.nix
@@ -1,85 +1,64 @@
-{ lib, stdenv, fetchurl, dpkg }:
-
+# How to generate a new version:
+#
+# Update version and hash as usual.
+#
+# ```
+# cd fx_cast/app
+# # Add `"name": "fx_cast_bridge", "version": "...",` to package.json and package-lock.json
+# nix run nixpkgs.nodePackages.node2nix -c node2nix -l package-lock.json -d
+# cp -v node-*.nix package*.json ~/p/nixpkgs/pkgs/tools/misc/fx_cast/app
+# ```
+{ pkgs, stdenv, system }: let
+  nodeEnv = import ./node-env.nix {
+    inherit (pkgs) nodejs stdenv lib python2 runCommand writeTextFile;
+    inherit pkgs;
+    libtool = if stdenv.isDarwin then pkgs.darwin.cctools else null;
+  };
+  nodePackages = import ./node-packages.nix {
+    inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
+    inherit nodeEnv;
+    globalBuildInputs = [pkgs.avahi-compat];
+  };
+in
 stdenv.mkDerivation rec {
-  pname = "fx_cast_bridge";
-  version = "0.0.7";
-
-  src = fetchurl {
-     url = "https://github.com/hensm/fx_cast/releases/download/v${version}/${pname}-${version}-x64.deb";
-     sha256 = "0kd58vzsq1qzl7qsh1qv25ylxvr5y37li03gjb48x4vhd85slzz5";
+  name = "fx_cast_bridge-${version}";
+  version = "0.1.2";
+
+  src = pkgs.fetchFromGitHub {
+    owner = "hensm";
+    repo = "fx_cast";
+    rev = "v${version}";
+    hash = "sha256:1prgk9669xgwkdl39clq0l75n0gnkkpn27gp9rbgl4bafrhvmg9a";
   };
 
-  nativeBuildInputs = [ dpkg ];
+  buildInputs = with pkgs; [
+    nodejs
+  ];
 
-  unpackPhase = ''
-    runHook preUnpack
-    dpkg-deb -xv $src ./
-    runHook postUnpack
+  buildPhase = ''
+    ln -vs ${nodePackages.nodeDependencies}/lib/node_modules app/node_modules
+    npm run build:app
   '';
 
-  dontBuild = true;
-  dontPatchELF = true;
-
   installPhase = ''
-    install -DT {opt/fx_cast,$out/bin}/${pname}
-    install -DT {usr,$out}/lib/mozilla/native-messaging-hosts/${pname}.json
-
-    substituteInPlace $out/lib/mozilla/native-messaging-hosts/${pname}.json \
-      --replace {/opt/fx_cast,$out/bin}/${pname}
-  '';
-
-  # See now-cli/default.nix
-  dontStrip = true;
-  preFixup = let
-    libPath = lib.makeLibraryPath [stdenv.cc.cc stdenv.cc.libc];
-    bin = "$out/bin/${pname}";
-  in ''
-
-    orig_size=$(stat --printf=%s ${bin})
-
-    patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" ${bin}
-    patchelf --set-rpath ${libPath} ${bin}
-    chmod +x ${bin}
-
-    new_size=$(stat --printf=%s ${bin})
-
-    ###### zeit-pkg fixing starts here.
-    # we're replacing plaintext js code that looks like
-    # PAYLOAD_POSITION = '1234                  ' | 0
-    # [...]
-    # PRELUDE_POSITION = '1234                  ' | 0
-    # ^-----20-chars-----^^------22-chars------^
-    # ^-- grep points here
-    #
-    # var_* are as described above
-    # shift_by seems to be safe so long as all patchelf adjustments occur
-    # before any locations pointed to by hardcoded offsets
-
-    var_skip=20
-    var_select=22
-    shift_by=$(expr $new_size - $orig_size)
-
-    function fix_offset {
-      # $1 = name of variable to adjust
-      location=$(grep -obUam1 "$1" ${bin} | cut -d: -f1)
-      location=$(expr $location + $var_skip)
-
-      value=$(dd if=${bin} iflag=count_bytes,skip_bytes skip=$location \
-                 bs=1 count=$var_select status=none)
-      value=$(expr $shift_by + $value)
+    mkdir -p $out/bin $out/lib/mozilla/native-messaging-hosts $out/opt
 
-      echo -n $value | dd of=${bin} bs=1 seek=$location conv=notrunc
-    }
+    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
 
-    fix_offset PAYLOAD_POSITION
-    fix_offset PRELUDE_POSITION
+    echo "#! /bin/sh
+      NODE_PATH=${nodePackages.nodeDependencies}/lib/node_modules exec ${pkgs.nodejs}/bin/node $out/opt/fx_cast_bridge/src/main.js --_name fx_cast_bridge \"\$@\"
+    " >$out/bin/fx_cast_bridge
+    chmod +x $out/bin/fx_cast_bridge
 
+    mv dist/app $out/opt/fx_cast_bridge
   '';
 
-  meta = with lib; {
+  meta = with pkgs.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 ];
+    maintainers = with maintainers; [ dtzWill kevincox ];
   };
 }