External flake as a dev dependency

Hi!

I have a Haskell package (let’s call it myDep) available in a remote git repository. This package is not uploaded on hackage, but I made a flake.

Now I develop a Haskell application (let’s call it myApp) which depends on that package myDep. Again, I’d like to package app into a flake.

My approach was to declare an input

inputs.depGit.url = "gitlab:UserName/dep/mainBranch";

provide it in outputs

outputs = { self, nixpkgs, depGit }: # other incantations
...

and then extend haskellPackages:

haskellPackages =
        pkgs.haskell.packages.${ghc}.extend (hself: hsuper: {
          myApp = hself.callCabal2nix "myApp" "${self}/" { };
          myDep= depGit.packages.${system}.myDep;
        });

Unfortunately, this did not work, nix build complained that

Error: Setup: Encountered missing or private dependencies
myDep

I got an advice to forego the “flakiness” of myDep:

inputs.depGit = {url = "gitlab:UserName/dep/mainBranch"; flake = false;};

and then use it as

haskellPackages =
        pkgs.haskell.packages.${ghc}.extend (hself: hsuper: {
          myApp = hself.callCabal2nix "myApp" "${self}/" { };
          myDep = hself.callCabal2nix "myDep" depGit { };
        });

While this approach certainly works, I am not entirely happy with this way of doing things - it feels like I repackaged the same package again. Nothing flake-related was used; I could call a fetchFromGitlab and obtain the same result.

Hence my question - is there a fix for my first approach to make myDep visible? Or is there a yet another approach to the same problem?

Cheers!

Checklist:
flake.nix is committed and pushed;
flake.lock is committed and pushed;
locked mainBranch version is the version that has flake.nix and flake.lock;
Is strange to have a checklist with odd items.

Yes, I did everything in that checklist before asking here.

In that case we can try less ugly approach:

inputs.depGit = {url = "gitlab:UserName/dep/mainBranch";};
haskellPackages =
        pkgs.haskell.packages.${ghc}.extend (hself: hsuper: {
          myApp = hself.callCabal2nix "myApp" "${self}/"  { };
          myDep = hself.callCabal2nix "myDep" "${depGit}" { };
        });

This should work, is only less ugly, but means your flake import is working as expected.
Then your issue isn’t related to flake.

Maybe you have to re-extend the haskellPackages to make it work.

myDepPackages =
        pkgs.haskell.packages.${ghc}.extend (hself: hsuper: {
          myDep = hself.callCabal2nix "myDep" "${depGit}" { };
        });
haskellPackages =
        depGit.packages.${system}.myDepPackages (hself: hsuper: {
          myApp = hself.callCabal2nix "myApp" "${self}/"  { };
        });

While this is even uglier, means the problem is in the way callCabal2nix/haskell.packages.${ghc}.extend works.

At the least, we will know the direction to look.

That’s essentially what I posted as my current solution, I call twice callCabal2nix, once for the dependency and once for the application, both in one extend. Flake or not, it seems bizarre from the novice’s point of view - in the flake definition of the dependency I already invoked callCabal2nix, why do I need to call it once again?