(This solution is deprecated in favor of my other solution which uses nixGL
)
The issue is that stack
is overriding the LD_LIBRARY_PATH
of your nixos installation. by default it contains something such as /run/opengl-driver/lib:/run/opengl-driver-32/lib
and it is override by stack with the path to the library provided by stack, for me it contains: /nix/store/v1d3fmjjqzd1wh84w8dmy4i3hxzgaybf-libGL-1.0.0/lib:/nix/store/y9s4bbn6j54flhpggccrmjd7cv3nkw60-glu-9.0.0/lib:/nix/store/jx7018a4yvd0x79qwp8ad15h5isy1ny3-freeglut-3.0.0/lib:/nix/store/5z8gx1bjw5s0q96n191k0a8caqr4r580-ghc-8.4.3/lib:/nix/store/yypprmw8hrmvwyhhz23w8z25yjvdhnxb-git-2.18.0/lib:/nix/store/iw94llkj05wgaz268mlzvgx8jkbi1ss0-gcc-wrapper-7.3.0/lib:/nix/store/rxaclc3vhxbzgfllv7601i85z854h48a-gmp-6.1.2/lib
I don't have an easy solution, that's actually painful that stack does not change the rpath
of your binary and instead override LD_LIBRARY_PATH
.
My quick and dirty solution:
- a) Get the
LD_LIBRARY_PATH
from inside stack:
stack exec -- env | grep LD_LIBRARY_PATH
LD_LIBRARY_PATH=/nix/store/v1d3fmjjqzd1wh84w8dmy4i3hxzgaybf-libGL-1.0.0/lib:/nix/store/y9s4bbn6j54flhpggccrmjd7cv3nkw60-glu-9.0.0/lib:/nix/store/jx7018a4yvd0x79qwp8ad15h5isy1ny3-freeglut-3.0.0/lib:/nix/store/5z8gx1bjw5s0q96n191k0a8caqr4r580-ghc-8.4.3/lib:/nix/store/yypprmw8hrmvwyhhz23w8z25yjvdhnxb-git-2.18.0/lib:/nix/store/iw94llkj05wgaz268mlzvgx8jkbi1ss0-gcc-wrapper-7.3.0/lib:/nix/store/rxaclc3vhxbzgfllv7601i85z854h48a-gmp-6.1.2/lib
- b) get your current
LD_LIBRARY_PATH
:
$ echo $LD_LIBRARY_PATH
/run/opengl-driver/lib:/run/opengl-driver-32/lib
- c) get the real path of your executable
$ stack exec --no-nix-pure which rhine-gloss-gears
/tmp/rhine/rhine-gloss/.stack-work/install/x86_64-linux-nix/nightly-2018-09-26/8.4.3/bin/rhine-gloss-gears
here, --no-nix-pure
allows stack
to see which
which should be available in your current environment.
d) concatenate all of that, using:
LD_LIBRARY_PATH=yourLD_LIBRARY_PATH:theOneFromStack the_executable_path
Exemple:
LD_LIBRARY_PATH=/run/opengl-driver/lib:/run/opengl-driver-32/lib:/nix/store/v1d3fmjjqzd1wh84w8dmy4i3hxzgaybf-libGL-1.0.0/lib:/nix/store/y9s4bbn6j54flhpggccrmjd7cv3nkw60-glu-9.0.0/lib:/nix/store/jx7018a4yvd0x79qwp8ad15h5isy1ny3-freeglut-3.0.0/lib:/nix/store/5z8gx1bjw5s0q96n191k0a8caqr4r580-ghc-8.4.3/lib:/nix/store/yypprmw8hrmvwyhhz23w8z25yjvdhnxb-git-2.18.0/lib:/nix/store/iw94llkj05wgaz268mlzvgx8jkbi1ss0-gcc-wrapper-7.3.0/lib:/nix/store/rxaclc3vhxbzgfllv7601i85z854h48a-gmp-6.1.2/lib /tmp/rhine/rhine-gloss/.stack-work/install/x86_64-linux-nix/nightly-2018-09-26/8.4.3/bin/rhine-gloss-gears