Mach-nix/python with opengl

Hello, I am trying to get openai gym working. Inspired by Install atari[gym] with mach-nix (i.e. build-time cmake availability) I have the following in a shell.nix file:

{ pkgs ? import <nixpkgs> { } }:

  mach-nix = import
      builtins.fetchGit {
        url = "";
        ref = "refs/tags/3.3.0";
      inherit pkgs;
      pypiDataRev = "9699653ccac8681ce92004b210b73f5d929d6e41"; # 2021-08-30T20:17:04Z
      pypiDataSha256 = "0zayz2flj46gf6gc3h9ip9i2fkpff50qiyjnrrpcgxjyxnq4rndz";
  custom-python = mach-nix.mkPython {
    python = "python38Full";
    requirements = ''
with pkgs; mkShell {
  buildInputs = [

Many of the things in the file are probably not needed, but it was a starting point.
I want this to be able to run

import gym
import numpy as np
import matplotlib.pyplot as plt
env = gym.make('MountainCar-v0')
a = env.reset()

Entering a nix-shell and running the file.

> nix-shell shell.nix
Traceback (most recent call last):
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/gym/envs/classic_control/", line 27, in <module>
    from import *
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/pyglet/gl/", line 95, in <module>
    from import *
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/pyglet/gl/", line 45, in <module>
    from import link_GL as _link_function
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/pyglet/gl/", line 149, in <module>
    from import link_GL, link_GLU, link_GLX
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/pyglet/gl/", line 45, in <module>
    gl_lib = pyglet.lib.load_library('GL')
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/pyglet/", line 164, in load_library
    raise ImportError('Library "%s" not found.' % names[0])
ImportError: Library "GL" not found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 7, in <module>
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/gym/", line 254, in render
    return self.env.render(mode, **kwargs)
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/gym/envs/classic_control/", line 118, in render
    from gym.envs.classic_control import rendering
  File "/nix/store/hmc86a13mcq3csfhgiffcg8dm97j6h4s-python3-3.8.12-env/lib/python3.8/site-packages/gym/envs/classic_control/", line 29, in <module>
    raise ImportError(
    Error occurred while running `from import *`
    HINT: make sure you have OpenGL installed. On Ubuntu, you can run 'apt-get install python-opengl'.
    If you're running on a server, you may need a virtual frame buffer; something like this should work:
    'xvfb-run -s "-screen 0 1400x900x24" python <>'

So it’s complaining about opengl/pyopengl. I tried to add them to the requirements in the shell.nix-file (as you can see - PyOpenGl.
I also tried to add python39Packages.pyopengl to buildInputs, and finally I tried to add hardware.opengl.enable= true; to configuration.nix. Neither of these worked. Is there something else I can try?

22.05pre333986.73369f8d086 (Quokka)
1 Like