Andrew Wagner
Andrew Wagner

Reputation: 24547

How to enable an optional build dependency using nix-shell?

I would like to use gtk-enabled opencv with python 3 inside of a nix-shell.

I am able to launch a non-gtk enabled python3/opencv environment with:

nix-shell --pure -p python35Packages.opencv3

However, commands that open windows fail:

[nix-shell:~/src/nixpkgs/pkgs/development/libraries/opencv]$ python
Python 3.5.3 (default, Jan 17 2017, 07:57:56) 
[GCC 5.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.namedWindow("foo") 
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvNamedWindow, file /tmp/nix-build-opencv-3.2.0.drv-0/opencv-3.2.0-src/modules/highgui/src/window.cpp, line 565

In the package definition in /nixpkgs/pkgs/development/libraries/opencv/3.x.nix, there are function parameters enableGtk2 and enableGtk3 that switch on the optional dependency in the build.

I read through several nix tutorials and the entire syntax definition for the language.

Switching on an optional dependency is pretty fundamental, so I would expect it to be doable using the command-line tools, i.e. nix-shell. Anyone know how it is done?

Upvotes: 3

Views: 1842

Answers (1)

Zimm i48
Zimm i48

Reputation: 3071

This is the command that you would need to use in this case:

nix-shell -p "python35Packages.opencv3.override { enableGtk2 = true; }"

Another solution would be to override the python35Packages.opencv3 package once and for all as explained in the nixpkgs documentation. Then you would be able to use your command unchanged.

Upvotes: 4

Related Questions