Overriding Python Modules

Sorry, since I know this is a duplicate question, but every source I’ve been able to find has failed me (and a lot of them conflict). I am trying to override python311Packages.django to 4.1.7 (since 4.2+ breaks Seafile), based on a local copy of that version’s derivation. I have tried the below options, and some variations thereon (both python3 and python311 for instance). However, no matter what I try, the latest version of Django is still used.

nixpkgs.overlays = [ (final: prev: {
    python311 = let packageOverrides = (python-self: python-super: {
            django = pkgs.callPackage ../overrides/django-4.1.7.nix {};
        });
        in prev.python311.override { inherit packageOverrides; };
} ) ];
nixpkgs.overlays = [ (final: prev: {
    python311 = prev.python311.override {
        packageOverrides = (python-self: python-super: {
            django = pkgs.callPackage ../overrides/django-4.1.7.nix {};
        });
    };
} ) ];
nixpkgs.overlays = [ (final: prev: {
    python311PackagesExtensions = prev.python311PackagesExtensions ++ [ (pyfinal: pyprev: {
        django = pkgs.callPackage ../overrides/django-4.1.7.nix {
            inherit (prev.python311Packages) aiosmtpd argon2-cffi asgiref backports-zoneinfo bcrypt buildPythonPackage docutils geoip2 jinja2 python-memcached numpy pillow pylibmc pymemcache pythonOlder pytz pywatchman pyyaml redis selenium setuptools sqlparse tblib tzdata;
        };
    }) ];
} ) ];

You need to override django in the python package set that seafile uses.

python = python3.override {
  packageOverrides = prev: final: {
    django = final.django.overridePythonAttrs (oldAttrs: rec {
      version = "4.1.7";
      src = final.fetchPypi {
        pname = "django";
        version = "4.1.7";
        hash = "";
      };
    };
  };
};

Then make sure that seafile uses that python.

I couldn’t find out which seafile component in nixpkgs relies on django, so this is as close as I can describe it.

Thank you for your quick response, but unfortunately it does not work. Using your override, no units are rebuilt and Seafile continues to use Django 4.2.6. Seafile does use python3 (specifically 3.11). The package using Django is seahub.

I think the issue is pkgs in

I usually use what you have as the approach #2 but it should be python-self.callPackage.

1 Like

Your suggestion does indeed work, the old version caused an evaluation error. However, I discovered my more important problem: overriding the package doesn’t seem to change its usage as a dependency. I tried adding environment.systemPackages = [ pkgs.python311Packages.django ] to my config, and suddenly 4.1.7 built immediately. But, Seafile still uses 4.2.6.

The more consistent way to apply overrides is https://github.com/NixOS/nixpkgs/blob/e52b59f96b04a7c87a68596ea36577460574c654/doc/languages-frameworks/python.section.md#how-to-override-a-python-package-for-all-python-versions-using-extensions-how-to-override-a-python-package-for-all-python-versions-using-extensions

That worked like a charm! The final overlay I used was:

nixpkgs.overlays = [ (final: prev: {
	pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ (pyfinal: pyprev: {
		django = pyfinal.callPackage ../overrides/django-4.1.7.nix {};
	}) ];
}) ];

Though unfortunately Seahub still appears to be broken :frowning: back to the drawing board…