Overriding Python Packages in a Derivation?

I have a derivation with

...
let
  version = "v4.2";
  pypkgs = python-packages: with python-packages; [
    pyserial
    click
    cryptography
    future
    pyparsing
    pyelftools
    setuptools
    pip
  ];
  
  python = pkgs.python3.withPackages pypkgs;
  
in stdenv.mkDerivation rec {
...

I need ‘pyparsing’ to be pinned at a specific version. I put the override for the package in the let-in block

  pythonPackageOverrides = self: super: {
    pyparsingx = super.buildPythonPackage rec {
      pname = "pyparsing";
      version = "2.3.1";
      doCheck = false;
      src = super.fetchPypi {
        inherit pname version;
        sha256 = "0yk6xl885b91dmlhlsap7x78hk2rdr879fln9anbq6k4ca42djb6";
      };
    };
  };

How do I connect ‘pythonPackagesOverrides’ to ‘python’ ?

python = (pkgs.python3.override { packageOverrides = pythonPackagesOverrides; }).withPackages pypkgs;

should work, see NixOS - Nixpkgs 21.05 manual

Also note that you will have pyparsingx in the overridden package set.

1 Like