cabal2nix icon indicating copy to clipboard operation
cabal2nix copied to clipboard

Non-vanilla `configureFlags`

Open zanculmarktum opened this issue 4 years ago • 3 comments

First of all, I'm not really sure how hackage-packages.nix was generated, but I assume it's using cabal2nix in some way since it has similar result to what is produced by cabal2nix.

So, I'm not really sure if the issue I'm about to make should go in here :), either way:

Recently, I noticed that cabal2nix enables all of the flags from foo.cabal even though by default they're set to false, i.e.

flag with_xft
  description: Use Xft to render text. UTF-8 support included.
  default: False

cabal2nix translates it to

{ configureFlags = [ "-fwith_xft" ]; }

which makes it as if it's

  default: True

in foo.cabal.

I noticed this when I try to build xmobar.

Not saying it's bad, but it's just not vanilla (i.e. the produced binary is different from what you get from upstream aka cabal install xmobar).

I'm using 20.09 if that matters.

zanculmarktum avatar Feb 16 '21 08:02 zanculmarktum

cabal2nix contains a list of hard-coded flag choices that take precedence over the defaults expressed in the Cabal file. You'll find the corresponding code for the case of xmobar here: https://github.com/NixOS/cabal2nix/blob/8d3ef92c5392049cc3c91f582b8a05df0ed8e07c/src/Distribution/Nixpkgs/Haskell/FromCabal/Flags.hs#L57.

So, you are right, those flag choices differ from the defaults expressed in Cabal. There is no deep reasoning behind those choices either, it's typically just that a sufficiently large number of people have complained that they build some Hackage package with cabal2nix and are surprised that certain features won't be enabled, so we always enable them by default. I suppose what constitutesthe "best" default for a packages varies depending on the context in which you build it, and cabal2nix is a tool for building Haskell packages in the context of the Nixpkgs distribution, whereas cabal-install seems to have a more developer-centrist view.

Does that make sense?

peti avatar Feb 16 '21 11:02 peti

Why is it hard-coded in cabal2nix, though? I think it would make more sense to put it somewhere inside <nixpkgs/pkgs/development/haskell-modules/>. I don't really understand the Haskell packaging in Nix, so pardon my ignorance.

There is no deep reasoning behind those choices either, it's typically just that a sufficiently large number of people have complained that they build some Hackage package with cabal2nix and are surprised that certain features won't be enabled, so we always enable them by default.

Wow, I never expected that a lot of people would complain about it. If you want customization you can always compile it manually, at least that's the first thing that I would think whenever I get into this scenario.

I suppose what constitutesthe "best" default for a packages varies depending on the context in which you build it, and cabal2nix is a tool for building Haskell packages in the context of the Nixpkgs distribution, whereas cabal-install seems to have a more developer-centrist view.

I think the default is just when you download the tar.gz file from https://hackage.haskell.org/ and compile it, which is what was the upstream intended. cabal-install is simply doing those steps for you.

zanculmarktum avatar Feb 16 '21 12:02 zanculmarktum

See also #504.

sternenseemann avatar Jun 19 '21 20:06 sternenseemann