How do I define a variable so that callPackage will see it and pass automatically it as an argument like it does with packages and functions defined in nixpkgs?
For example, if I have a package derivation in a file like this,
error: Function called without required argument "myCustomFetch" at /nix/store/aaaa...-source/pkgs/my-package/default.nix:3
I have looked through the nixpkgs source, and I see that there are multiple callPackage functions for different package scopes, and I read up a bit on nix scopes, but I have only been able to find examples of overriding packages in scopes, but nothing about modifying the scope’s callPackage function itself. I also found callPackageWith, but that appears to be a reimplementation of callPackage, so I could not use that to extend an existing scope.
But depending on the specifics, it might also make sense to add the fetch function to the package set and let its callPackage inject it for you (you will need callPackage from the final package set since the one from prev would not see myCustomFetch defined on the current “level”):
Also, when you have nested overlays like here, you generally want to use the values from a package set through the arguments of the relevant overlay, rather than getting it from an outer overlay (py-final.callPackage instead of final.python3.pkgs.callPackage). Otherwise it will become a tangled mess that is difficult to reason about.