Nixos + haskell + opengl (prerequisites)

Unfortunately, I am not getting a simple sample program from this open gl tutorial for work.

ghc --make gfx.hs Could not find module 'Graphics.UI.GLUT' [..] 

Then I tried the following:

 cabal install GLUT Warning: The package list for 'hackage.haskell.org' is 44.1 days old. Run 'cabal update' to get the latest list of available packages. Resolving dependencies... Configuring OpenGLRaw-3.2.2.0... Failed to install OpenGLRaw-3.2.2.0 Build log ( /home/m/.cabal/logs/OpenGLRaw-3.2.2.0.log ): Configuring OpenGLRaw-3.2.2.0... setup-Simple-Cabal-1.22.5.0-x86_64-linux-ghc-7.10.3: Missing dependency on a foreign library: * Missing C library: GL This problem can usually be solved by installing the system package that provides this library (you may need the "-dev" version). If the library is already installed but in a non-standard location then you can use the flags --extra-include-dirs= and --extra-lib-dirs= to specify where it is. cabal: Error: some packages failed to install: GLURaw-2.0.0.2 depends on OpenGLRaw-3.2.2.0 which failed to install. GLUT-2.7.0.10 depends on OpenGLRaw-3.2.2.0 which failed to install. OpenGL-3.0.1.0 depends on OpenGLRaw-3.2.2.0 which failed to install. OpenGLRaw-3.2.2.0 failed during the configure step. The exception was: ExitFailure 1 

The missing C library seems to be the problem. I am using nixOS, does anyone know what steps I will need to take to get this done?

+1
source share
3 answers

If you want to use nix-shell :

 $ nix-shell -p 'haskellPackages.ghcWithPackages (p: [ p.GLUT ])' 

will provide you a shell with ghc that knows GLUT

I tried with this code (from the wiki page you mentioned)

 import Graphics.UI.GLUT main :: IO () main = do (_progName, _args) <- getArgsAndInitialize _window <- createWindow "Hello World" displayCallback $= display mainLoop display :: DisplayCallback display = do clear [ ColorBuffer ] flush 

But a more preferable way is to create shell.nix , so you do not need to remember it. To use shell.nix , just call nix-shell with no argument in the directory where it is, or nix-shell /path/to/shell.nix anywhere.

shell.nix , adopted from manual

 { nixpkgs ? import <nixpkgs> {} }: with nixpkgs; let ghc = haskellPackages.ghcWithPackages (ps: with ps; [ GLUT ]); in stdenv.mkDerivation { name = "my-haskell-env"; buildInputs = [ ghc ]; shellHook = "eval $(egrep ^export ${ghc}/bin/ghc)"; } 

For a larger project, you can use cabal or stack , but I think it will be a different story.

+1
source

On Linux (Nix - the Linux distribution), LSB indicates that libGL is part of the desktop profile. This means that at least the X11 client libraries are present. libGL is a bit special, although it is allowed to override the installation of the graphics driver.

What it boils down to: Install graphics drivers for your GPU. If you are using an Intel or AMD GPU, install the Mesa drivers. If your system has an NVidia GPU, I recommend the proprietary NVidia drivers.

-one
source

In nixos, libraries are usually not available in the way where cabal expects them. Try the following:

nix-shell -p mesa mesa_glu cabal install GLUT

-one
source

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


All Articles