How to globally override a pythonPackage in nix

Viewed 599

I'm trying to override a python package (uvloop) globally, in nix, such that black sees the override.

uvloop (python package) tests fail for me because I'm working behind a firewall. I can build things that use uvloop by editing the nixpkgs derivation directly (ugh) to set doCheck = false.

I'm trying to encode this in an overlay, but without success - the overlay is read (e.g., syntax errors cause failure), but nothing I do in the overlay actually stop the tests from running.

I've tried following tips from https://nixos.wiki/wiki/Overlays, https://nixos.org/manual/nixpkgs/stable/#how-to-override-a-python-package-using-overlays and How to use custom python with existing packages - nix derivation? (overlaying python using packageOverrides; with pythonOverrides; and with and without using overridePythonAttrs); both for python3 and python39; but with no success.

E.g.,

self: super: {
  python3 = super.python3.override {
    packageOverrides = pyself: pysuper: {
      uvloop = pysuper.uvloop.overrideAttrs (_: {
        doCheck = false;
      });
    };
  };
}
    

For bonus points, I'd like to achieve this for all instances of python package uvloop - not just the one in 3.9 - but I'll take any help I can get.

Thanks,

1 Answers

The following worked for me. It applies a patch to twitch-chat-downloader (Python app) and a patch to twitch-python (Python library used by twitch-chat-downloader). nix-env -iA nixpkgs.twitch-chat-downloader installed a patch copy of twitch-chat-downloader which uses a patched copy of twitch-python.

{
  packageOverrides = pkgs: {
    python3 = pkgs.python3.override {
      packageOverrides = python-self: python-super: {
        twitch-python = python-super.twitch-python.overrideAttrs (attrs: {
          patches = (attrs.patches or []) ++ [
            ./twitch-allow-no-token.patch
          ];
        });
      };
    };

    twitch-chat-downloader = pkgs.twitch-chat-downloader.overrideAttrs (attrs: {
      patches = (attrs.patches or []) ++ [
        ./twitch-chat-downloader-no-oauth.patch
      ];
    });
  };
}
Related