cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Why cabal-install warns about duplicate config files when CABAL_CONFIG is set?

Open phadej opened this issue 5 months ago • 1 comments

Warning: Both /home/phadej/.cabal and /home/phadej/.config/cabal/config exist
- ignoring the former.

even I have $CABAL_CONFIG set. The - ignoring the former makes me think that my $CABAL_CONFIG variables is not respected.

I consider this a bug, it misleads the user. I have no idea what happens.

phadej avatar Jun 25 '25 18:06 phadej

This happens when I use cabal sdist in a project which hadn't been cabal build yet (i.e. no dist-newstyle directory). cabal build doesn't warn.

This non-uniform behavior is definitely a bug.

FWIW, cabal sdist should need to read the config at all, as far as I can tell.

phadej avatar Jun 25 '25 18:06 phadej

this comes from

https://github.com/haskell/cabal/blob/cd7e7a57a7cc678e3938bdc3310ff32892950fec/cabal-install/src/Distribution/Client/Config.hs#L749-L766

#8877 @athas

and currently blocks our update for GHC 9.14 #11174

ulysses4ever avatar Aug 22 '25 13:08 ulysses4ever

My understanding is that the warning is completely insensitive to CABAL_CONFIG, so while the two files it talks about do exist, the message is misleading (none of them are used). I suggest that an easy solution is to modify the logic in loadConfig, where warnOnTwoConfigs is invoked, such that warnOnTwoConfigs is not called when CABAL_CONFIG is set.

athas avatar Aug 22 '25 14:08 athas

Alternatively, the invocation of warnOnTwoConfigs could be moved into getConfigFilePathAndSource and only used in the Default case.

athas avatar Aug 22 '25 14:08 athas

@athas the latter looks a little more plausible to me. But: what about CABAL_DIR? If I set it explicitly, I probably don't want to deal with the warning even if the two configs exist if I explicitly set one of the default locations (like some people do to be on the safe side)? E.g. CABAL_DIR=~/.cabal cabal ....

And then there's an issue with "non-uniform behaviour" as described above?..

ulysses4ever avatar Aug 22 '25 14:08 ulysses4ever

We can just check if CABAL_DIR is set before emitting the warning. It will be very ad hoc, but so is everything about the cabal config anyway.

athas avatar Aug 22 '25 14:08 athas

Ugh, getConfigFilePathAndSource does not have access to the Verbosity.

athas avatar Aug 22 '25 14:08 athas

Could you submit a patch along these lines?

ulysses4ever avatar Aug 22 '25 14:08 ulysses4ever

Yeah, working on it.

athas avatar Aug 22 '25 15:08 athas