Overriding not being kept

Hi all, I’ve started to use NixOS just a few days and I’m liking it. Because of plaidml (a Python package) I need to use Keras version 2.2.4. The one in NixOS unstable is 2.3.1. Because of that I’m overriding Keras using overlays with this file:

let
  pythonOverrides = python-self: python-super: {
    Keras = python-super.Keras.overrideAttrs (oldAttrs: rec {
      pname = "Keras";
      version = "2.2.4";
      name = "${pname}-${version}";
      src = python-super.fetchPypi {
        pname = "Keras";
        version = "2.2.4";
        sha256 = "1j8bsqzh49vjdxy6l1k4iwax5vpjzniynyd041xjavdzvfii1dlh";
      };
    });
  };
in
self: super: {
  python = super.python.override { packageOverrides =  pythonOverrides; };
  python3 = super.python3.override { packageOverrides =  pythonOverrides; };
  python37 = super.python37.override { packageOverrides =  pythonOverrides; };
  python38 = super.python38.override { packageOverrides =  pythonOverrides; };
  python39 = super.python39.override { packageOverrides =  pythonOverrides; };
}

To test it I installed it this way:
nix-env -iA nixos.python3Packages.Keras

But it’s installing Keras 2.3.1, not 2.2.4. If I install this way:
nix-env -iA nixos.python38Packages.Keras

It installs Keras 2.2.4. It install 2.2.4 if use python or python37 will also install 2.2.4. There is something wrong with the overlay?

The plaidml/default.nix content is this:

{ lib, pkgs, buildPythonPackage, fetchPypi, unzip, python }:

buildPythonPackage rec {
  pname = "plaidml";
  version = "0.7.0";
  format = "other";

  srcs = [
    (fetchPypi {
      inherit pname version;
      format = "wheel";
      platform = "manylinux1_x86_64";
      sha256 = "1y21sq95c7p1g5n731qc5xsdhxibcs5nzsb33d673g326wysyixq";
    })
    (fetchPypi {
      inherit version;
      pname = "plaidml_keras";
      format = "wheel";
      python = "py2.py3";
      sha256 = "e49cc34d47a6eec6acca8a6bf5ac7af6a8172e333d422ffac8c85846d8521bbc";
    })
  ];

  doCheck = false;
  propagatedBuildInputs = [
    python.pkgs.cffi
    python.pkgs.numpy
    python.pkgs.six
    python.pkgs.pip
    python.pkgs.Theano
    python.pkgs.Keras
  ];

  nativeBuildInputs = [
    unzip
  ];

  unpackPhase = ''
    mkdir ${pname}-${version}
    cd ${pname}-${version}
    unzip -qq ${builtins.elemAt srcs 0}

    cp ${builtins.elemAt srcs 1} ${(builtins.elemAt srcs 1).name}
  '';

  installPhase = ''
    # Installing plaidml
    mkdir -p $out/lib/${python.libPrefix}/site-packages/plaidml
    install -m 644 plaidml/* $out/lib/${python.libPrefix}/site-packages/plaidml/
    cp -r plaidml-${version}.data/data/include -t $out/
    cp -r plaidml-${version}.data/data/lib -t $out/
    cp -r plaidml-${version}.data/data/share -t $out/

    # Installing plaidml-keras and keras
    ${python.pythonForBuild.interpreter} -m pip install --no-build-isolation --no-index --prefix=$out  --ignore-installed --no-dependencies --no-cache --build tmpbuild *.whl
  '';

  shellHook = ''
    export PLAIDML_NATIVE_PATH="$out/lib/libplaidml.so"
    export RUNFILES_DIR="$out/share/plaidml"
  '';


  meta = with lib; {
    homepage = https://github.com/plaidml/plaidml;
    description = "plaidml keras backend";
    license = licenses.apsl20;
  };
}

and plaidml.nix is:

self: super: {
  plaidml = super.callPackage ./pkgs/plaidml {
    buildPythonPackage = super.python3.pkgs.buildPythonPackage;
    fetchPypi = super.python3.pkgs.fetchPypi;
    python = super.python3;
  };
}

It seems that is not possible to have more than one overlay calling python3.override. Based on this solution, I fixed this problem this way:

1- I created a file to keep all python overlays called python_overlays.nix with this content:

python-self: python-super:
{

  nibabel = python-super.nibabel.overrideAttrs (oldAttrs: {
    doInstallCheck = false;
    propagatedBuildInputs = oldAttrs.propagatedBuildInputs
    ++ [python-super.packaging];
  });

  Keras = python-super.Keras.overrideAttrs (oldAttrs: rec {
    pname = "Keras";
    version = "2.2.4";
    src = python-super.fetchPypi {
      pname = "Keras";
      version = "2.2.4";
      sha256 = "1j8bsqzh49vjdxy6l1k4iwax5vpjzniynyd041xjavdzvfii1dlh";
    };
  });

  plaidml = python-super.callPackage ./pkgs/plaidml {
  };
}

2 - I create a file to override the python packages from the python_overlays.nix:

self: super: {
  python3 = super.python3.override {
    packageOverrides = import ./python_overlays.nix;
  };

  python37 = super.python37.override {
    packageOverrides = import ./python_overlays.nix;
  };

  python38 = super.python38.override {
    packageOverrides = import ./python_overlays.nix;
  };
}