Install atari[gym] with mach-nix (i.e. build-time cmake availability)

I’m trying to setup a python 3.8 development environment with the gym[atari] package installed.

Following @jonringer’s Python packaging and development workflow video, I figured out how to do this with venvShellHook:

with import <nixpkgs> {};

mkShell {
  name = "play-dev-env";
  buildInputs = (with python38Packages; [
    venvShellHook
  ]) ++ (with pkgs; [
    cmake
    binutils
    util-linux
    stdenv.cc.cc.lib
    zlib
    autoPatchelfHook
  ]);
  venvDir = "venv38";
}

I’d like to use mach-nix to do this more declaratively. Here’s what I’ve tried:

{ pkgs ? import <nixpkgs> {} }:
let
    mach-nix = import (
        builtins.fetchGit {
            url = "https://github.com/DavHau/mach-nix/";
            ref = "refs/tags/3.3.0";
        }
    ) {};
    custom-python = mach-nix.mkPython {
        python = "python38Full";
        requirements = ''
            gym[atari]
        '';
        # I've tried with and without this line.
        _.gym.buildInputs.add = [ pkgs.cmake ];
    };
in
with pkgs; mkShell {
  buildInputs = [
    custom-python
  ];
}

This produces the following output (excluding lines that begin with copying...

trace: removing dependency python3.8-requests-2.25.1 from gym
these derivations will be built:
  /nix/store/k6cgalfww07a4dfrs75wcdxfljkl4cvg-opencv_python-4.5.2.52-cp38-cp38-manylinux2014_x86_64.whl.drv
  /nix/store/6ad56h7jb3h3gb22kkdg106j3d2f58vb-python3.8-opencv-python-4.5.2.52.drv
  /nix/store/vplghxz66sn4c7dhz6cr5rj12jcvlmwn-python3.8-atari-py-0.2.9.drv
  /nix/store/ng1vln5c8sln2lm7qfp3xgr71izpsmip-python3.8-gym-0.18.3.drv
  /nix/store/0rslwa5gxpkzvj0kk2x63v7bfirwfb05-python3-3.8.9-env.drv
building '/nix/store/vplghxz66sn4c7dhz6cr5rj12jcvlmwn-python3.8-atari-py-0.2.9.drv'...
building '/nix/store/k6cgalfww07a4dfrs75wcdxfljkl4cvg-opencv_python-4.5.2.52-cp38-cp38-manylinux2014_x86_64.whl.drv'...
Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing setuptools-build-hook
Using setuptoolsBuildPhase
Using setuptoolsShellHook
Sourcing pip-install-hook
Using pipInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
unpacking sources
unpacking source archive /nix/store/8faawz8y35hpyg4w2gzk6xzvwhyhyhiy-atari-py-0.2.9.tar.gz
source root is atari-py-0.2.9
setting SOURCE_DATE_EPOCH to timestamp 1621563593 of file atari-py-0.2.9/setup.cfg
patching sources
configuring
no configure script, doing nothing
building
Executing setuptoolsBuildPhase

trying https://files.pythonhosted.org/packages/cp38/o/opencv-python/opencv_python-4.5.2.52-cp38-cp38-manylinux2014_x86_64.whl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/atari_py
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/common
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/controllers
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502/src
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502/src/bspf
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502/src/bspf/src
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/rsynth
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/environment
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/external
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/external/TinyMT
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/games
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/games/supported
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/os_dependent
creating build/lib.linux-x86_64-3.8/atari_py/atari_roms
creating build/lib.linux-x86_64-3.8/atari_py/tests
running build_ext
error: [Errno 2] No such file or directory: 'cmake'
builder for '/nix/store/vplghxz66sn4c7dhz6cr5rj12jcvlmwn-python3.8-atari-py-0.2.9.drv' failed with exit code 1
cannot build derivation '/nix/store/0rslwa5gxpkzvj0kk2x63v7bfirwfb05-python3-3.8.9-env.drv': 1 dependencies couldn't be built
error: build of '/nix/store/0rslwa5gxpkzvj0kk2x63v7bfirwfb05-python3-3.8.9-env.drv' failed

How do I get cmake to be available during the build process?

It looks like there’s an open mach-nix issue discussing this, and I’ve reported substantially the same information there, too.

My nix-info :

  • system: "x86_64-linux"
  • host os: Linux 5.12.10, NixOS, 21.11pre295280.fa0326ce523 (Porcupine)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.12
  • channels(rule): "home-manager, nixos-21.11pre304626.8ecc61c91a5"
  • channels(root): "nixos-21.11pre295280.fa0326ce523"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Thanks!

I managed to create a nix shell with this shell.nix:

{ pkgs ? import <nixpkgs> { } }:
let
  mach-nix = import
    (
      builtins.fetchGit {
        url = "https://github.com/DavHau/mach-nix/";
        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 = ''
      gym[atari]
    '';
    _.atari-py = {
      nativeBuildInputs.add = with pkgs; [ cmake ];
      buildInputs.add = with pkgs; [zlib];
      dontUseCmakeConfigure = true;
    };
  };
in
with pkgs; mkShell {
  buildInputs = [
    custom-python
  ];
}
1 Like

Thanks for your reply, @brogos. Sadly, I’m still getting the same error:

trace: removing dependency python3.8-Pillow-8.2.0 from gym
trace: removing dependency python3.8-pyglet-1.4.2 from gym
trace: removing dependency python3.8-requests-2.25.1 from gym
trace: removing dependency python3.8-scipy-1.6.1 from gym
these derivations will be built:
  /nix/store/1z56116g1vcgq6jxc0j85zdbdq8xbwnh-opencv_python-4.5.3.56-cp38-cp38-manylinux2014_x86_64.whl.drv
  /nix/store/h7hkwxnkda858f52nadixj69g722rkxl-python3.8-opencv-python-4.5.3.56.drv
  /nix/store/nv26bx18z0vdnqhnzscjyz5lydvxxj0x-python3.8-atari-py-0.2.6.drv
  /nix/store/s5hj9b6wnmws1pzl13asncfs8ikb9jg4-python3.8-gym-0.19.0.drv
  /nix/store/v17rg4cinx8a2mfp429716gszxnizd41-python3-3.8.9-env.drv
building '/nix/store/nv26bx18z0vdnqhnzscjyz5lydvxxj0x-python3.8-atari-py-0.2.6.drv'...
building '/nix/store/1z56116g1vcgq6jxc0j85zdbdq8xbwnh-opencv_python-4.5.3.56-cp38-cp38-manylinux2014_x86_64.whl.drv'...
Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing setuptools-build-hook
Using setuptoolsBuildPhase
Using setuptoolsShellHook
Sourcing pip-install-hook
Using pipInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
unpacking sources
unpacking source archive /nix/store/5v8vjrqfs8dm6nixk3isd2sw8n6riak9-atari-py-0.2.6.tar.gz
source root is atari-py-0.2.6
setting SOURCE_DATE_EPOCH to timestamp 1563215339 of file atari-py-0.2.6/setup.cfg
patching sources
configuring
no configure script, doing nothing
building
Executing setuptoolsBuildPhase
running bdist_wheel
running build
running build_py

trying https://files.pythonhosted.org/packages/cp38/o/opencv-python/opencv_python-4.5.3.56-cp38-cp38-manylinux2014_x86_64.whl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/atari_py
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/common
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/controllers
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502/src
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502/src/bspf
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/m6502/src/bspf/src
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/emucore/rsynth
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/environment
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/external
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/external/TinyMT
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/games
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/games/supported
creating build/lib.linux-x86_64-3.8/atari_py/ale_interface/src/os_dependent
creating build/lib.linux-x86_64-3.8/atari_py/atari_roms
creating build/lib.linux-x86_64-3.8/atari_py/tests
running build_ext
Traceback (most recent call last):
  File "setup.py", line 22, in run
    subprocess.check_call(['cmake', '..'], cwd=cwd)
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'cmake'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "nix_run_setup", line 8, in <module>
    exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))
  File "setup.py", line 36, in <module>
    setup(name='atari-py',
  File "/nix/store/9q2apxxlvk5sjj5p7c5hgsvkda1kpcg7-python3.8-setuptools-54.2.0/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/nix/store/yg23r3lgk7ysafb0c52f043hqhbkhrqs-python3.8-wheel-0.36.2/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 299, in run
    self.run_command('build')
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/command/build.py", line 135, in run
    self.run_command(cmd_name)
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/nix/store/qjmp7jvig1xq8sm424nahvi4km9xwwll-python3-3.8.9/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "setup.py", line 28, in run
    sys.stderr.write("Unable to execute '{}'. HINT: are you sure `make` is installed?\n".format(' '.join(cmd)))
NameError: name 'cmd' is not defined
builder for '/nix/store/nv26bx18z0vdnqhnzscjyz5lydvxxj0x-python3.8-atari-py-0.2.6.drv' failed with exit code 1
cannot build derivation '/nix/store/v17rg4cinx8a2mfp429716gszxnizd41-python3-3.8.9-env.drv': 1 dependencies couldn't be built
error: build of '/nix/store/v17rg4cinx8a2mfp429716gszxnizd41-python3-3.8.9-env.drv' failed

usually python builds which make use of cmake are opinionated about where the cmake files go, you should probably add dontUseCmakeConfigure = true; so that a “standard” cmake mkdir build && cd build && cmake .. doesn’t occur (or more likely, is done twice)

1 Like

@jonringer - @brogos put that in his proposed solution under _.atari_py.dontUseCmakeConfigure = true;. Are you suggesting also putting it somewhere else?

FileNotFoundError: [Errno 2] No such file or directory: 'cmake'

I’m not familiar with machnix, but it looks like cmake isn’t being added to PATH

You are using the same shell.nix of my reply?

Maybe the error is because of this typo: it’s atari-py not atari_py.

@brogos - yes, the typo was it! I was just coming back to say that, but you beat me to it.

Having fixed that error, I’m now able to enter the shell. Thanks for your help.

Just to better my own understanding, why is cmake under nativeBuildInputs while zlib is under buildInputs?

I don’t exactly but I think nativeBuildInputs are used to indicate the programs and libs used during the compilation and buildInputs to programs and libs used at runtime.