nix.dev icon indicating copy to clipboard operation
nix.dev copied to clipboard

Guide on packaging stuff that doesn't fit into Nix model (steam, electron)

Open domenkozar opened this issue 5 years ago • 4 comments

domenkozar avatar Aug 31 '20 13:08 domenkozar

Here's an example of packaging Sabaki, an Electron app for Go (the game). This runs 100% inside of an fhsUserEnv.

https://github.com/savannidgerinel/nix-shell/blob/sol/sabaki/default.nix

It has one mysterious bug in that disk access causes the app to crash if I launch the app from dmenu. No problems at all if I launch the app from the command line.

Electron has a lot of explicit requirements, and one implicit requirement on udev and libudev. Generally it will crash with a sigtrap if either is missing.

savannidgerinel avatar Aug 31 '20 13:08 savannidgerinel

@savannidgerinel how do you then run it inside fhsUserEnv?

domenkozar avatar Sep 01 '20 10:09 domenkozar

oof you're right, this isn't an fhsUserEnv :(. I'm sorry, I mis-remembered how I bundled Sabaki. It is an Electron app, but patchElf is sufficient to make it work.

Apparently I only use fhsUserEnv when I'm running development shell environments where I have to all Electron directly. For that I posted a question and answer to the Discourse a while back: https://discourse.nixos.org/t/unexpected-sigtrap-when-running-electron/7864 . As such, my comments may not be applicable to this in particular.

savannidgerinel avatar Sep 01 '20 18:09 savannidgerinel

I am trying to figure out a derivation that wraps, for instance, a copy of electron that I downloaded manually, or a copy of electron that gets installed with npm. It looks like this, but actually running it gives me a SIGTRAP and a core dump with no backtrace information:

        let rpath = pkgs.stdenv.lib.makeLibraryPath [ ... lots of libraries ... ]

            script = pkgs.writeScript "electron" ''
                #!${pkgs.bash}/bin/bash
                export LD_LIBRARY_PATH=$PWD:${rpath}
                ${pkgs.stdenv.cc.bintools.dynamicLinker} $NODE_PATH/electron/dist/electron
                '';

        in pkgs.stdenv.mkDerivation {
            name = "electron_wrapper";
            src = script;

            dontUnpack = true;
            dontBuild = true;

            installPhase = ''
                mkdir -p $out/bin
                cp $src $out/bin/electron
            '';
        };

savannidgerinel avatar Sep 01 '20 19:09 savannidgerinel