Problem importing Go shared libraries: "panic: [...] cannot import, [...] unknown export format version -1 [...]"

I’ve written a Nix expression for a recent Go language REPL project. However, when I’m trying to use the REPL, I’m getting a weird error message:

$ lgo run
>>> x := 1 + 2
panic: Failed to import core: cannot import, possibly version skew (unknown export format version -1 ("i\x00\xb3\x10\xe1\x1el/nix/store/\\x00\aContext\acontext\aDisplay\rDataDisplayer")) - reinstall package

goroutine 1 [running]:
runtime/debug.Stack(0xc0003c3600, 0x7f0c3f608d80, 0xc000486070)
	/nix/store/v0r93klbpp9fapx0ygla4p2vb38qm9qb-go-1.11/share/go/src/runtime/debug/stack.go:24 +0xa9
	/nix/store/ +0x7d
panic(0x7f0c3f608d80, 0xc000486070)
	/nix/store/v0r93klbpp9fapx0ygla4p2vb38qm9qb-go-1.11/share/go/src/runtime/panic.go:513 +0x1c5, 0xc000492000, 0x0, 0x0)
	/nix/store/ +0x2d5, 0xa, 0xc0003c3cc0, 0xc00045c060)
	/nix/store/ +0x336*LgoRunner).Run(0xc0002113e0, 0x7f0c3f80d180, 0xc0004380c0, 0x0, 0x0, 0xc000434060, 0xa, 0xc0003c3db0, 0x20)
	/nix/store/ +0x527
main.fromStdin.func3(0xc00043a0c0, 0xc0002113e0, 0x7f0c3f80d180, 0xc0004380c0, 0xc000434060, 0xa)
	/nix/store/ +0x94
main.fromStdin(0x7f0c3f80d180, 0xc000372700, 0xc0002113e0)
	/nix/store/ +0x1ea
	/nix/store/ +0x5f0

Just noticed, that the same message gets printed if I even press “Enter” on an empty line with the “>>>” prompt.

I’ve compiled the lgo with a “from scratch” infrastructure for Go packages, as with buildGoPackage I wasn’t able to construct a GOPATH based on the build dependencies, which was required in wrapProgram on lgo binary. The sequence of commands to get the error above based on the provided Nix expression goes like this:

$ curl -o ~/.nixpkgs/overlays/lgo.nix
$ nix-env -iA nixpkgs.lgo
$ export LGOPATH=$HOME/lgo
$ readlink -f `which go`
$ lgo install      # will build some stuff into $LGOPATH
2018/10/10 09:28:34 Install lgo to /home/akavel/lgo
2018/10/10 09:28:34 Building
2018/10/10 09:28:38 Building lgo core package
2018/10/10 09:28:41 Building third-party packages in $GOPATH
2018/10/10 09:28:41 Installing lgo-internal
2018/10/10 09:28:44 lgo was installed in /home/akavel/lgo successfully
$ lgo run
>>> x := 1+2    # type the expression and press Enter

Any hints/ideas?

Try adding the following attributes to your derivation:

  allowGoReference = true;

References to the go compiler are removed by default to reduce programs closure size.

@zimbatm But allowGoReference cannot have any impact if I’m not using buildGoPackage, no?

(As I wrote above, I’m not using it because I needed to build GOPATH for wrapProgram on the final lgo binary, and I couldn’t extract it from buildGoPackage.)