Custom subscopes for `haskellPackages`

Hi everyone!

I am trying to have a “scoped” set of packages inside haskellPackages such that my packages wouldn’t mix up with the public ones.

This is the outline of what I currently have:

ps = { package1 = ../code/package1; package2  =  ../code/package2; };
config = {
    packageOverrides = pkgs: {
      haskellPackages = pkgs.haskellPackages.override {
       overrides = self: super: { my-packages = builtins.mapAttrs (name: path: (super.callCabal2nix name (gitignore path) {}) ps; } ;
      };
    };
  };

I want package1 to be able to specify package2 as a dependency even though package2 is not directly in the haskell package set but inside the attribute my-packages. (basically add self.haskellPackages.my-packages to the scope callCabal2nix uses to resolve inputs)

I noticed there’s a overrideScope function in nixpkgs but I didn’t figure out how to use it.

Thanks!