nix-linter icon indicating copy to clipboard operation
nix-linter copied to clipboard

EtaReduce results in failing flake check

Open pinpox opened this issue 3 years ago • 2 comments

The following line in a flake gives me an error:

      overlays.default = final: prev: (import ./overlays inputs) final prev;
Possible η-reduction of argument `prev` at flake.nix:99:33-76
-W EtaReduce

    {
      # When you have a function abstraction, only to immediately apply the
      # argument to a function, this is called an η-abstraction (or eta-abstraction)
      # See also: https://wiki.haskell.org/Eta_conversion
      bad = x: f x;

      # Generally, it nicer to be direct:
      good = f;
    }

I tried simplifying it to:

      overlays.default = (import ./overlays inputs);

But then nix flake check is not happy:

shell ❯ nix flake check                                                                                                                                                                    
error: overlay does not take an argument named 'final'
(use '--show-trace' to show detailed location information)

Is this a bug or am I misunderstanding the help message?

pinpox avatar May 18 '22 11:05 pinpox

No, you are correctly understanding the message. However, flake check doesn't only look at the semantics of the code (which are equal after this transformation), but also at the formatting. nix-linter has no flake-specific code to handle this, so it throws this warning.

As an aside, I think flake check should be a bit less stringent here, because the simplified code is perfectly reasonable.

Synthetica9 avatar May 18 '22 11:05 Synthetica9

So basically I can't use the linter with flakes in their current state with that check? I have found other occurances that seem to have a similar problem. E.g. I'm not using the final: argument in the overlay, but flake check tells me I have to pass it.

pinpox avatar May 18 '22 11:05 pinpox