How to package old Electron apps?

Hi,

I’ve been trying for a while to get synochat packaged without any luck and pretty much gave up on it. Howver today I thought I’d try again with an different app EasyEda in this case which didn’t work out either:

final: prev: {
  easyeda = let
    lib = final.lib;
  in
    final.stdenv.mkDerivation (finalAttrs: rec {
      name = "easyeda";
      version = "6.5.46";
      src = final.fetchzip {
        url = "https://image.easyeda.com/files/easyeda-linux-x64-${finalAttrs.version}.zip";
        sha256 = "sha256-0aMh8dD3z4A4IA1hlAwz9VeERlRWHe9HV54u7+OyKFM=";
        stripRoot = false;
      };
      propagatedBuildInputs = with final; [electron];
      buildInputs = with final; [
        stdenv.cc.cc
        stdenv.cc.cc.lib
        alsa-lib
        nss
        libdrm
        mesa
        vulkan-loader
        glib
        nspr
        atk
        cups
        dbus
        gtk3
        pango
        cairo
        gdk-pixbuf
        xorg.libX11
        xorg.libXcomposite
        xorg.libXdamage
        xorg.libXext
        xorg.libXfixes
        xorg.libXrandr
        xorg.libxcb
        expat
        libxkbcommon
        gnome.gvfs
        harfbuzzFull
      ];
      nativeBuildInputs = with final; [makeWrapper wrapGAppsHook patchelf autoPatchelfHook];
      binaryName = "easyeda";
      installPhase = ''
               runHook preInstall
               mkdir -p $out/bin $out/opt $out/share/applications/
               cp -r $src/easyeda-linux-x64/ $out/opt/easyeda
               chmod 755 $out/opt/easyeda/${binaryName}
        patchelf --set-interpreter ${final.stdenv.cc.bintools.dynamicLinker} \
               	$out/opt/${binaryName}/${binaryName}
               cp $out/opt/easyeda/EASYEDA.dkt $out/share/applications/EASYEDA.desktop
               substituteInPlace $out/share/applications/EASYEDA.desktop \
                   --replace 'Exec=/opt/easyeda/easyeda %f' "Exec=easyeda %f"
               runHook postInstall
      '';
      postFixup = ''
              makeWrapper $out/opt/easyeda/easyeda $out/bin/easyeda \
        "''${gappsWrapperArgs[@]}" \
              --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform=wayland --enable-features=WaylandWindowDecorations}}" \
               --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath finalAttrs.buildInputs}:$out/opt/easyeda \
               --prefix PATH : ${lib.makeBinPath finalAttrs.buildInputs}
      '';
    });
  easyeda-fhs = final.buildFHSUserEnv {
    name = "easyeda";
    targetPkgs = pkgs: pkgs.easyeda.buildInputs ++ [pkgs.easyeda];
  };
}

Both synochat and easyeda fail with the similar error message:

[3288378:0100/000000.527210:ERROR:zygote_linux.cc(611)] Zygote could not fork: process_type gpu-process numfds 3 child_pid -1
[3288378:0100/000000.527296:ERROR:zygote_linux.cc(643)] write: Broken pipe (32)

Has anybody here any idea on how to tackle this problem ? Maybe somebody with an deeper understanding about the inner workings of electron?

Looks decently alright to me but I’m a bit confused why you wrap the patchelf’d binary in an FHSEnv? Patchelf already packages it in a nix-compatible manner; you usually only do one or the other.

You’re probably going to need to strace it or get some sort of debug output to figure out what’s going on.

GPU stuff might also be drivers related?

Have you tried running this without forcing the ozone platform to wayland? Old Electron versions are unlikely to have had good Wayland support that is compatible with modern compositors.

That was an attempt to replicate what steam-run does since the synochat derivation works in conjunction with steam-run, my fhs attempt does not not however.

It works in steam-run?

Then remove its FHSEnv packages from it until it stops working to figure out what you need (ideally in a bisecting manner for O(log(n)) time complexity).

The app might dlopen something at runtime without declaring it as NEEDED, so you may have to add it to the rpath of some binary manually. You can do so in a second postFixup step and have everything else injected by autopatchelf.