NixOS, Haskell, opengl: problems with building and running openGL programs

I have a problem with GL on NixOS: the problem seems old, but in 2017 there is still no easy solution!

I am trying to create a Haskell program using the Gloss library. I installed Gloss and everything he needs using nix-shell -p mesa and it seems to be properly built and istalled (using cabal install ). However, if I create a program in the same nix-shell , it does not work:

 $ nix-shell -p mesa_glu [nix-shell:]$ ghc --make -O2 SnakePar.hs Linking SnakePar ... [nix-shell:]$ ./SnakePar SnakePar: user error (unknown GLUT entry glutInit) 

While working outside of nix-shell , the binding step is not performed:

 $ ghc --make -O2 SnakePar.hs [1 of 1] Compiling Main ( SnakePar.hs, SnakePar.o ) Linking SnakePar ... /nix/store/<hash>-binutils-2.27/bin/ld: cannot find -lGLU /nix/store/<hash>-binutils-2.27/bin/ld: cannot find -lGL collect2: error: ld returned 1 exit status `cc' failed in phase `Linker'. (Exit code: 1) 

This happens, although I manually installed the glu library through nix-env -iA .

 $ nix-env -q cabal-install-1.24.0.0 ghc-8.0.1 glu-9.0.0 

I tried using freeglut or mesa in the same way, but none of them (or even all together) worked.

What am I missing?

This question matters, but it does not help: nixos + haskell + opengl (prerequisites)

Solution: After switching to the stack, everything works.

+6
source share
1 answer

I just fixed it after three days, well, being another displeased Arch user until the last week: try adding freeglut to the nix-shell environment, i.e. use nix-shell -p mesa freeglut .

For stack users stumbled upon this answer, add this to ~/.stack/stack.yaml :

 nix: enable: true packages: [mesa freeglut] 

The nix-shell solution does not work in this case - the problem, I assume, is that Stack always works inside a clean environment, even if it runs from within the nix-shell . I tried pure: false in the nix stack.yaml section, but that didn't work. This is currently being done.

  • mesa is required to provide C headers for OpenGLRaw and other libraries (and this, in my opinion, is crash binding in your case).
  • freeglut provides GLUT bindings (otherwise you will get an "unknown GLUT record" error), required at runtime.

You may need to change mesa to something else, like mesa_glu .

+4
source

Source: https://habr.com/ru/post/1013865/


All Articles