Packaging an app that is installed via a .run file

Hi all, I’m try to make the following app runnable on Nixos:

Digging around in the repository, it looks possible to compile from source, but I believe certain secrets are used in the Github workflow, which are packed in the installer which you can download from the releases section.
Thus I’ve been trying to work with the installer (.run file) as a way to package the app!

I’ve ran into some issues with this approach though. In the derivation, I’ve gotten the installer to run by using autoPatchelfHook. I’ve verified that it works by passing the --version argument.
But when trying to use the --prefix argument, no output can be found in the path given in the argument.

I’ve tried running the installer on it’s own using steam-run, and it seems to work there. However, running it with manual patching with patchElf doesn’t net the same results. I suspect I might be missing some binaries maybe? But I can’t figure out which that would be from the steps in the documentation.

Would anyone be able to give me some feedback on my current approach?

{ stdenv, lib, fetchurl, autoPatchelfHook }:

let
  name = "xpilot";
  version = "3.0.1";
  xplanePath = "/mnt/games-ssd/Steam/steamapps/common/X-Plane 12";

  src = fetchurl {
    url = "https://github.com/xpilot-project/xpilot/releases/download/v${version}/xPilot-${version}-Linux.run";
    hash = "sha256-BBtsURm6ybKf8fmN+sH3ugO02rKPkhHFcw5OVSB71/c=";
  };

in

stdenv.mkDerivation {
  inherit src name version;

  nativeBuildInputs = [ autoPatchelfHook ];

  buildInputs = [
    stdenv.cc.cc
  ];

  dontUnpack = true;

  installPhase = ''
    mkdir $out
    cp ${src} $out/xpilot-installer.run
    chmod +x $out/xpilot-installer.run
  '';

  postFixup = ''
    $out/xpilot-installer.run --mode unattended --prefix $out/client
  '';
}

There’s an “Artifacts” archive in the releases page containing some binaries, have you tried that?

❯ unzip -v Artifacts-3.0.1.zip 
Archive:  Artifacts-3.0.1.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
       0  Stored        0   0% 05-31-2024 22:51 00000000  Windows/
       0  Stored        0   0% 05-31-2024 22:51 00000000  Windows/plugin/
       0  Stored        0   0% 05-31-2024 22:51 00000000  Windows/plugin/xPilot/
       0  Stored        0   0% 05-31-2024 22:51 00000000  Windows/plugin/xPilot/Resources/
    5352  Defl:N     2562  52% 05-31-2024 22:51 66548d73  Windows/plugin/xPilot/Resources/related.txt
       0  Stored        0   0% 05-31-2024 22:51 00000000  Windows/plugin/xPilot/Resources/CSL/
     713  Defl:N      411  42% 05-31-2024 22:51 fc44409b  Windows/plugin/xPilot/Resources/CSL/PlaceCSLPackagesHere.html
    8581  Defl:N     8496   1% 05-31-2024 22:51 f78a83d8  Windows/plugin/xPilot/Resources/MapIcons.png
    4076  Defl:N      823  80% 05-31-2024 22:51 f235d599  Windows/plugin/xPilot/Resources/Obj8Datarefs.txt
  244506  Defl:N    66391  73% 05-31-2024 22:51 d67572ca  Windows/plugin/xPilot/Resources/Doc8643.txt
       0  Stored        0   0% 05-31-2024 22:51 00000000  Windows/plugin/xPilot/Resources/Contrail/
    3574  Defl:N      726  80% 05-31-2024 22:51 651072e1  Windows/plugin/xPilot/Resources/Contrail/Contrail.pss
     189  Defl:N      149  21% 05-31-2024 22:51 6b8a8a5c  Windows/plugin/xPilot/Resources/Contrail/Contrail.obj
   10084  Defl:N     9250   8% 05-31-2024 22:51 b17aaf63  Windows/plugin/xPilot/Resources/Contrail/Contrail.png
       0  Stored        0   0% 05-31-2024 22:51 00000000  Windows/plugin/xPilot/win_x64/
 2989568  Defl:N  1355264  55% 05-31-2024 22:51 beb83928  Windows/plugin/xPilot/win_x64/xPilot.xpl
 1853440  Defl:N   860291  54% 05-31-2024 22:51 74c76fab  Windows/plugin/xPilot/win_x64/fmod.dll
18075648  Defl:N  4487006  75% 05-31-2024 22:51 550b7306  Windows/plugin/xPilot/win_x64/xPilot.pdb
44931584  Defl:N 20157164  55% 05-31-2024 22:51 7952679c  Windows/xPilot.exe
       0  Stored        0   0% 05-31-2024 22:51 00000000  macOS/
46332900  Stored 46332900   0% 05-31-2024 22:51 360cc7bb  macOS/macOS.zip
       0  Stored        0   0% 05-31-2024 22:51 00000000  Linux/
71026184  Defl:N 26477435  63% 05-31-2024 22:51 ad10496d  Linux/xPilot
       0  Stored        0   0% 05-31-2024 22:51 00000000  Linux/plugin/
       0  Stored        0   0% 05-31-2024 22:51 00000000  Linux/plugin/xPilot/
       0  Stored        0   0% 05-31-2024 22:51 00000000  Linux/plugin/xPilot/Resources/
    5152  Defl:N     2536  51% 05-31-2024 22:51 cf20044e  Linux/plugin/xPilot/Resources/related.txt
       0  Stored        0   0% 05-31-2024 22:51 00000000  Linux/plugin/xPilot/Resources/CSL/
     679  Defl:N      407  40% 05-31-2024 22:51 fd828724  Linux/plugin/xPilot/Resources/CSL/PlaceCSLPackagesHere.html
    8581  Defl:N     8496   1% 05-31-2024 22:51 f78a83d8  Linux/plugin/xPilot/Resources/MapIcons.png
    4024  Defl:N      820  80% 05-31-2024 22:51 627c17d3  Linux/plugin/xPilot/Resources/Obj8Datarefs.txt
  237164  Defl:N    66092  72% 05-31-2024 22:51 41e799df  Linux/plugin/xPilot/Resources/Doc8643.txt
       0  Stored        0   0% 05-31-2024 22:51 00000000  Linux/plugin/xPilot/Resources/Contrail/
    3398  Defl:N      713  79% 05-31-2024 22:51 3df0bf37  Linux/plugin/xPilot/Resources/Contrail/Contrail.pss
     181  Defl:N      144  20% 05-31-2024 22:51 dc5c5511  Linux/plugin/xPilot/Resources/Contrail/Contrail.obj
   10084  Defl:N     9250   8% 05-31-2024 22:51 b17aaf63  Linux/plugin/xPilot/Resources/Contrail/Contrail.png
       0  Stored        0   0% 05-31-2024 22:51 00000000  Linux/plugin/xPilot/lin_x64/
 5810256  Defl:N  2291736  61% 05-31-2024 22:51 a0d63507  Linux/plugin/xPilot/lin_x64/xPilot.xpl
 1659080  Defl:N   344568  79% 05-31-2024 22:51 8a0974c4  Linux/plugin/xPilot/lin_x64/xPilot.debug
 1659120  Defl:N   744050  55% 05-31-2024 22:51 bef94831  Linux/plugin/xPilot/lin_x64/libfmod.so
--------          -------  ---                            -------
194884118         103227680  47%                            40 files

This is as far as I got, it opens, but I can’t tell you whether it works or not.

{
  stdenvNoCC,
  fetchzip,
  autoPatchelfHook,
  fontconfig,
  freetype,
  glib,
  libdrm,
  libglvnd,
  libxkbcommon,
  pulseaudio,
  xcb-util-cursor,
  xcbutilrenderutil,
  xorg,
}:

stdenvNoCC.mkDerivation (finalAttrs: {
  pname = "xpilot";
  version = "3.0.1";

  src = fetchzip {
    url = "https://github.com/xpilot-project/xpilot/releases/download/v${finalAttrs.version}/Artifacts-${finalAttrs.version}.zip";
    hash = "sha256-0blazYguHD53O9MmQpCNWBWj75za77zb+z4WLb1qMow=";
    stripRoot = false;
  };

  nativeBuildInputs = [
    autoPatchelfHook
  ];

  buildInputs = [
    fontconfig
    freetype
    glib
    libdrm
    libglvnd
    libxkbcommon
    pulseaudio
    xcb-util-cursor
    xcbutilrenderutil
    xorg.libICE
    xorg.libSM
    xorg.libX11
    xorg.libxcb
    xorg.xcbutilkeysyms
    xorg.xcbutilwm
  ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin $out/share
    cp -r Linux $out/share/xpilot
    mv $out/share/xpilot/xPilot $out/bin/xpilot
    chmod +x $out/bin/xpilot

    runHook postInstall
  '';
})

Completely missed the artifacts archive, good eye!
It works great for me, thanks for cooking up the derivation for me :+1:

By the way @FedericoSchonborn how did you come to this specific list of build inputs? Is there some steps that I missed, or did you analyze the source for it?

When autoPatchelfHook fails it prints out a list of all the libraries that are missing, you can use that to nix-locate libfoo.so.1 (see nix-index) to find out which packages provide each one of them.