Having trouble overriding python dependencies

I wanted to add a missing Python dependency to an existing package, openstackclient-full. I thought this should work:

  environment.systemPackages = with pkgs; [
    openstackclient-full
  ];

  nixpkgs = {
    overlays = [
      (final: prev: {
        pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ (pyfinal: pyprev: {
          openstackclient-full = pyprev.openstackclient-full.overridePythonAttrs (oldAttrs: {
            dependencies = oldAttrs.dependencies ++ [ pkgs.python311Packages.pysocks ];
          });
        })];
      })
    ];
  };

While this doesn’t throw any error messages, it also doesn’t appear to work as the pysocks package doesn’t get pulled in as a dependency after adding this block of code.

Formally, I’ll probably end up filing an issue against nixpkgs anyway to include this as it probably should be by default, at least as part of the full version of the package. But I thought this would be trivial to add myself on my end for now. That turned out completely wrong!

Hopefully someone has a suggestion on whatever it is I’m missing here.

Thanks!

That overlay is likely not working because openstackclient-full is not a real python package. Try overriding python-openstackclient instead.

Yep, sure enough. I should have known to try something like that when I saw the alias (I’d guess you’d call it) inside nixpkgs/pkgs/top-level/all-packages.nix for openstackclient-full.

This was actually one of the things that was annoying to me about this solution was that I really didn’t want to have to specify potentially the incorrect version of the pysocks package by needing to use the full package name (i.e. python311Packages.pysocks). Within nixpkgs/pkgs/development/python-modules/python-openstackclient/default.nix, none of the included libraries needed to specify the fully qualified package names, including which version of Python was being used ultimately (python311Packages vs python312Packages currently in unstable).

Anyway, glad to know I wasn’t terribly far off. This does work:

  nixpkgs = {
    overlays = [
      (final: prev: {
        pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ (pyfinal: pyprev: {
          python-openstackclient = pyprev.python-openstackclient.overridePythonAttrs (oldAttrs: {
            dependencies = oldAttrs.dependencies ++ [ pkgs.python311Packages.pysocks ];
          });
        })];
      })
    ];
  };

If there is a better way to somehow deduce or imply the correct Python version that matches the overlaid version python-openstackclient is using, that might be nice to document here as I didn’t stumble upon too many working versions of doing this anywhere.

Having said that, I now need to go delve into how to test your PR to include this permanently moving forward! ( package openstackclient-full should include pysocks · Issue #363644 · NixOS/nixpkgs · GitHub ) Thanks for all the help thus far!

You can use pyprev in that code instead of pkgs.python311Packages

Just to close the loop here, your PR worked brilliantly. With a little input from https://astrid.tech/2022/11/03/0/overlay-nixpkgs-pr/ I removed my previous overlay to test the PR and only needed these changes: https://arrakis.bitgnome.net/nipsy/git/nix/commit/?id=a77132be02083c1cbd16ff360d464c4c3657aaad

Thanks again for everything. It takes awhile, but once you wrap your head around it, the composability of NixOS is pretty much unparalleled. It really tickles all of the right parts of my brain!