How do you add a Haskell dependency coming from a flake repository?

How do you add a dependency coming from another flake?

I have library’s flake defined as followed:

{
  description = "adhoc-fixtures";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
    yarl.url = "github:blackheaven/yarl";
  };

  outputs = inputs@{ self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};

        haskellPackages = pkgs.haskell.packages.ghc924.override {
          overrides = hself: hsuper: {
            yarl = hself.callCabal2nix "yarl" inputs.yarl { };
          };
        };
      in
      rec
      {
        packages.adhoc-fixtures =
          (haskellPackages.callCabal2nix "adhoc-fixtures" ./. rec {
            # Dependency overrides go here
          });

        defaultPackage = packages.adhoc-fixtures;

        devShell =
          pkgs.mkShell {
            buildInputs = with haskellPackages; [
              haskell-language-server
              ghcid
              cabal-install
              haskell-ci
            ];
            inputsFrom = [
              self.defaultPackage.${system}.env
            ];
          };
      });
}

See the full project.

I’m force to set yarl because it’s not in the snapshot, however it does not seem to work:

error: 'outputs' at /nix/store/3r0cr3cc9swjc02a40qy2cg5z6rq383i-source/flake.nix:10:13 called with unexpected argument 'yarl'

       at «string»:45:21:

           44|
           45|           outputs = flake.outputs (inputs // { self = result; });
             |                     ^
           46|

how can I set it properly?

Thanks in advance.

1 Like

Have you tried:

yarl = inputs.yarl.packages.${system}.yarl;

If you look at yarl’s flake, you’ll see that it outputs an already packaged haskell package: https://github.com/blackheaven/yarl/blob/420fe1ce6de7680d6f7826748d3b3f89883f92f8/flake.nix#L30

I didn’t, but it gives me the same result.

You can solve the problem you’ve shown with a change like this:

diff --git a/flake.nix b/flake.nix
index 68301c2..a0f8437 100644
--- a/flake.nix
+++ b/flake.nix
@@ -7,7 +7,7 @@
     yarl.url = "github:blackheaven/yarl";
   };
 
-  outputs = inputs@{ self, nixpkgs, flake-utils }:
+  outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
     flake-utils.lib.eachDefaultSystem (system:
       let
         pkgs = nixpkgs.legacyPackages.${system};
1 Like

Thank you so much! (even if I feel dumb)

1 Like

Hah, that’s what I get for skimming past the error.