ivanovs-4 / haskell-flake-utils

Pure Nix flake utility functions for haskell cabal packages
MIT License
6 stars 2 forks source link

nix flake check error: overlay does not take an argument named 'final' #2

Closed jmatsushita closed 2 years ago

jmatsushita commented 2 years ago

When running nix flake check in a simpleCabalProject2flake project, I get:

$ nix flake check --show-trace
error: overlay does not take an argument named 'final'

       … while checking the overlay 'overlays.x86_64-linux'

       at /nix/store/wk1zs2zxcb53qzkil3xjfvbc2lv51qzd-source/default.nix:134:26:

          133|                   then (pushDownSystem system (attrs.hydraJobs or {}) ret.hydraJobs)
          134|                   else { ${system} = ret.${key}; };
             |                          ^
          135|             in attrs //

       … while checking flake output 'overlays'

       at /nix/store/wk1zs2zxcb53qzkil3xjfvbc2lv51qzd-source/default.nix:137:17:

          136|               {
          137|                 ${key} = (attrs.${key} or { })
             |                 ^
          138|                   // (appendSystem key system ret);
jmatsushita commented 2 years ago

I suppose this is related to https://github.com/numtide/flake-utils/issues/50#issuecomment-981126190

Given that outputs are:

outputs = { self, nixpkgs, flake-utils, haskell-flake-utils, ... }@inputs:
  flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-darwin" ] (system:
    inputs.haskell-flake-utils.lib.simpleCabalProject2flake {
      inherit self nixpkgs system;

      name = "rhine";
      packageNames = ["rhine-gloss" "rhine-terminal" "rhine-examples"];
    }
  );

overlays also gets an overlays.${system} attribute. I suppose a way to address this would be to build in the eachSystem call inside simpleCabalProject2flake by passing it a systems array (like in simpleFlake) and use this pattern:

    (flake-utils.lib.eachSystem systems (system: {
        # ... other stuff
      }
    )) // {
      overlay = final: prev: {
        foo = packages.foo;
      };
    };

I'll give it a shot in a PR.

ivanovs-4 commented 2 years ago

Exactly. And actually this was initial design with eachSystem call inside simpleCabalProject2flake. One problem with that is some of the parameters of simpleCabalProject2flake need to know system. And there was a design choice of how to pass it.

Well. For now #4 solves an issue. As to passing system variant with passing it in an optional set seems like good enough.

ivanovs-4 commented 2 years ago

We can not use pattern

haskell-flake-utils.lib.simpleCabalProject2flake systems (system: {
  inherit self nixpkgs;
  name = ...
  config = ...
  haskellFlakes = ...
  preOverlays = ...
  preOverlay = ...
...
});

since at least several of this parameters should not know about system and should not depend on it.

In the same time user might need tools from pkgs.lib while constructing parameters to simpleCabalProject2flake. And this pkgs is

pkgs = import nixpkgs { inherit system }

so maybe something like this will be better:

haskell-flake-utils.lib.simpleCabalProject2flake {
    inherit self nixpkgs;
    name = ...;
    systems = [...];
  }
  (system: {
    config = ...;
    haskellFlakes = ...;
    preOverlays = ...;
    preOverlay = ...;
    hpPreOverrides = ...;
    hpOverrides = ...;
    cabal2nixArgs = ...;
    shell = ...;
    shellExtBuildInputs = ...;
    shellWithHoogle = ...;
    compiler = ...;
    localOverlays = ...;
  });

or even

haskell-flake-utils.lib.simpleCabalProject2flake {
    inherit self nixpkgs;
    name = ...;
    systems = [...];
  }
  (pkgs: {
    ...
  });
jmatsushita commented 2 years ago

Yes! I think:

haskell-flake-utils.lib.simpleCabalProject2flake {
    inherit self nixpkgs;
    name = ...;
    systems = [...];
  }
  (pkgs: {
    ...
  });

Is the approach I prefer! I think in practice pkgs is what we need for instance with shellExtBuildInputs.

ivanovs-4 commented 2 years ago

Tried this option. And now it's clear to me that current version is better. All parameters that might need pkgs as input already have it: preOverlays, preOverlay, cabal2nixArgs, packageCabal2nixArgs, shellExtBuildInputs.

Maybe this should be better illustrated with examples in README. (done)

jmatsushita commented 2 years ago

Ah yes, great it makes sense now with the examples!