Trying to override pythonPackages.opencv with gtk

Hello, I’m currently using GitHub - lopsided98/nix-ros-overlay: ROS overlay for the Nix package manager and I need to use opencv+gtk for development. However, even after adding an overlay to compile opencv with gtk in my flake.nix, I was still unable to run opencv with gtk.

After looking through the derivation tree, I realized that ros-env was depending on different versions of opencv:

$ nix-store --query --references /nix/store/5q0w0m94nba8hvv16iq7l9ymp950fyz1-ros-env.drv
/nix/store/6lpwvnrsi6qln936lhg9p2jylhnnrwnz-opencv-4.9.0.drv
/nix/store/7dzqrvdkdyx5bidqzp9j4g5pwaldyqlb-ros-jazzy-sensor-msgs-5.3.5-r1.drv
/nix/store/cszbjmpmmz47jc023kdc4pfk272dqjg4-opencv-4.9.0.drv
$ nix-store --query --referrers /nix/store/6lpwvnrsi6qln936lhg9p2jylhnnrwnz-opencv-4.9.0.drv
/nix/store/0xw0jif4aw3qhp6kw2fz32xhdh8bmzbd-ros-jazzy-cv-bridge-4.1.0-r1.drv
/nix/store/5q0w0m94nba8hvv16iq7l9ymp950fyz1-ros-env.drv

$ nix-store --query --referrers /nix/store/cszbjmpmmz47jc023kdc4pfk272dqjg4-opencv-4.9.0.drv
/nix/store/0xw0jif4aw3qhp6kw2fz32xhdh8bmzbd-ros-jazzy-cv-bridge-4.1.0-r1.drv
/nix/store/2vvyb9y8p1mn0g98vg493sm6rs98byrm-brisk-2.0.8.drv
/nix/store/5q0w0m94nba8hvv16iq7l9ymp950fyz1-ros-env.drv

Seemed really odd to me that ros-jazzy-cv-bridge would need two different versions of opencv, so I took a look at the original package definition:

So it depends on opencv and python3Packages.opencv4, which… are somehow built separately?

I also confirmed this by inspecting the derivation of ros-jazzy-cv-bridge, which referred to two different paths for opencv:

$ nix derivation show /nix/store/0xw0jif4aw3qhp6kw2fz32xhdh8bmzbd-ros-jazzy-cv-bridge-4.1.0-r1.drv
...
      "propagatedBuildInputs": "... /nix/store/373xh6ms054n8scfi4f7y33g3asb994y-opencv-4.9.0 /nix/store/y2i44k9g4srjj4pamldxln0b1q00n98z-opencv-4.9.0-cxxdev /nix/store/f6n37s0wrqbiykxklxnm7bs82kap1f5p-python3.12-numpy-1.26.4 /nix/store/f0csr6f8q3vlvzjwpxsdsjifsgx8lq1n-opencv-4.9.0  ...",
...

However, I’m not quite sure where to go on from here. Where is the problem here exactly? Should there be a change in:

  1. how I’m applying the overlay?
  2. how the inputs are declared for ros-jazzy-cv-bridge?
  3. how ros-env is built?

Any help would be appreciated, I’ve been stuck on this for 2 days at this point :')

Woops, apparently I was just looking into this way too hard that I missed the incredibly simple solution…