Option to use 'system' electron
Closed this issue · 5 comments
I'm on a somewhat weird system (NixOS), and the Electron downloaded by go-astilectron doesn't work out of the box.
Electron is, however, packaged in nixpkgs, so there is a 'system-installed' electron that does work.
Would it be possible to (either via code or an environment variable or so) use the system electron instead of downloading one? While I understand it would go against the go-astilectron advantage of having a predictable version of electron, it would be a useful 'escape hatch' in situations such as mine.
Mmmm I don't really know how this system-installed
Electron version works therefore I don't know whether this will work properly.
I think the best is to test it :
- at the top of this function, put :
if name == "Electron" {
return
}
I can confirm that the example doesn't work with the downloaded example, and does work after the above-mentioned changes.
For reference, my attempt with the downloaded attempt was with the following nix configuration:
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
name = "axolotl";
targetPkgs = pkgs: [
pkgs.nodejs
pkgs.gcc
pkgs.go_1_15
pkgs.glib
pkgs.nss
pkgs.nspr
pkgs.atk
pkgs.at-spi2-core
pkgs.at-spi2-atk
pkgs.xlibs.libX11
pkgs.xlibs.libxcb
pkgs.xlibs.libXcomposite
pkgs.xlibs.libXdamage
pkgs.xlibs.libXext
pkgs.xlibs.libXfixes
pkgs.xlibs.libXrandr
pkgs.expat
pkgs.libdrm
pkgs.libxkbcommon
pkgs.libGL_driver
pkgs.alsaLib
pkgs.cups
pkgs.dbus_daemon
pkgs.gdk_pixbuf
pkgs.gtk3-x11
pkgs.gnome2.pango
pkgs.cairo
];
}).env
With this the example fails with:
...
2021/02/17 13:24:00 Starting cmd /home/aengelen/dev/go-astilectron/example/vendor/electron-linux-amd64/electron /home/aengelen/dev/go-astilectron/example/vendor/astilectron/main.js 127.0.0.1:42645 false
2021/02/17 13:24:00 '/home/aengelen/dev/go-astilectron/example/vendor/electron-linux-amd64/electron' exited with code: -1
2021/02/17 13:24:00 App has crashed
And running electron separately also crashes:
$ /home/aengelen/dev/go-astilectron/example/vendor/electron-linux-amd64/electron
Electron 11.1.0 - Build cross platform desktop apps with JavaScript, HTML, and CSS
Usage: electron [options] [path]
A path to an Electron app may be specified. It must be one of the following:
- index.js file.
- Folder containing a package.json file.
- Folder containing an index.js file.
- .html/.htm file.
- http://, https://, or file:// URL.
Options:
-i, --interactive Open a REPL to the main process.
-r, --require Module to preload (option can be repeated).
-v, --version Print the version.
-a, --abi Print the Node ABI version.
Trace/breakpoint trap (core dumped)
$
I'd be happy to help turn this into a PR, but would need some guidance on what you'd like it to look like :).
Can you paste what go env
prints in NixOS
?
sure!
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/aengelen/.cache/go-build"
GOENV="/home/aengelen/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/aengelen/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/aengelen/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/nix/store/wh5b1z3axqgr98rxlmps9m5phlxdxs5z-go-1.15.8/share/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/nix/store/wh5b1z3axqgr98rxlmps9m5phlxdxs5z-go-1.15.8/share/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/aengelen/dev/axolotl/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/run/user/1000/go-build422931867=/tmp/go-build -gno-record-gcc-switches"
mmmm GOARCH="amd64"
and GOOS="linux"
which means there is no way to automatically detect NixOS
. Therefore we'll need to propose this alternative through an option instead of automatically.
Here's the way I see it:
- Add an option
CustomElectronPath string
here (order fields alphabetically) - Put line 63 --> 67 here in a
if o.CustomElectronPath == ""
so that Electron path are only set automatically if this option is empty. In theelse
putp.appExecutable = o.CustomElectronPath
- Before the return here, put an
if paths.ElectronUnzipSrc() == "" { return }
Then to test you'll need to set the CustomElectronPath
option to your Electron system path and confirm this is working properly.