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/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/core/core.go\x1agithub.com/yunabe/lgo/core\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
main.fromStdin.func3.1(0xc00043a0c0)
	/nix/store/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/cmd/lgo-internal/main.go:149 +0x7d
panic(0x7f0c3f608d80, 0xc000486070)
	/nix/store/v0r93klbpp9fapx0ygla4p2vb38qm9qb-go-1.11/share/go/src/runtime/panic.go:513 +0x1c5
github.com/yunabe/lgo/converter.injectLgoContext(0xc0004920a0, 0xc000492000, 0x0, 0x0)
	/nix/store/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/converter/converter.go:554 +0x2d5
github.com/yunabe/lgo/converter.Convert(0xc000434060, 0xa, 0xc0003c3cc0, 0xc00045c060)
	/nix/store/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/converter/converter.go:805 +0x336
github.com/yunabe/lgo/cmd/runner.(*LgoRunner).Run(0xc0002113e0, 0x7f0c3f80d180, 0xc0004380c0, 0x0, 0x0, 0xc000434060, 0xa, 0xc0003c3db0, 0x20)
	/nix/store/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/cmd/runner/runner.go:165 +0x527
main.fromStdin.func3(0xc00043a0c0, 0xc0002113e0, 0x7f0c3f80d180, 0xc0004380c0, 0xc000434060, 0xa)
	/nix/store/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/cmd/lgo-internal/main.go:152 +0x94
main.fromStdin(0x7f0c3f80d180, 0xc000372700, 0xc0002113e0)
	/nix/store/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/cmd/lgo-internal/main.go:155 +0x1ea
main.main()
	/nix/store/q7zcvgjv0mfrmiayqdf2vv2zzpi3h5sq-github.com-yunabe-lgo-lib/src/github.com/yunabe/lgo/cmd/lgo-internal/main.go:217 +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 https://gist.githubusercontent.com/akavel/6d406ccde40d41920b8f427cf28094e3/raw/4fd9585fc0ddb8c076ed4402f5cbb15c0fbca93d/lgo.nix -o ~/.nixpkgs/overlays/lgo.nix
$ nix-env -iA nixpkgs.lgo
$ export LGOPATH=$HOME/lgo
$ readlink -f `which go`
/nix/store/v0r93klbpp9fapx0ygla4p2vb38qm9qb-go-1.11/share/go/bin/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 libstd.so
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.)