cabal icon indicating copy to clipboard operation
cabal copied to clipboard

"nix: True" in .cabal/config causes parsing error

Open mhwombat opened this issue 3 years ago • 11 comments

Describe the bug

Nix integration not working as expected in cabal 3.8.1.0.

To Reproduce

~/.cabal 
❯ cabal user-config init
Writing default configuration to /home/amy/.cabal/config

~/.cabal 
❯ cabal v2-update
Downloading the latest package list from hackage.haskell.org
Package list of hackage.haskell.org is up to date.
The index-state is set to 2022-09-04T17:19:43Z.

Now edit ~/.cabal/config, changing line 24 to:

nix: True

This used to work (e.g. in Cabal library and cabal-install version: 3.4.0.0), and it's what the documentation says to do.

~/.cabal 
✦ ❯ cabal v2-update
Error: cabal: Error parsing config file /home/amy/.cabal/config:24:
True

Please use version-prefixed commands (e.g. v2-build or v1-build) to avoid ambiguity.

Expected behavior

cabal v2-update should handle this setting, or if something has changed and this is no longer correct, the docs should be updated and cabal should warn me.

System information

❯ uname -a
Linux wombat11k 5.15.63 #1-NixOS SMP Thu Aug 25 09:40:49 UTC 2022 x86_64 GNU/Linux

❯ cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library 

❯ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.0.2

Additional context

I'm running NixOS.

✦ ❯ cat ~/.cabal/config
-- This is the configuration file for the 'cabal' command line tool.
--
-- The available configuration options are listed below.
-- Some of them have default values listed.
--
-- Lines (like this one) beginning with '--' are comments.
-- Be careful with spaces and indentation because they are
-- used to indicate layout for nested sections.
--
-- This config file was generated using the following versions
-- of Cabal and cabal-install:
-- Cabal library version: 3.8.1.0
-- cabal-install version: 3.8.1.0


repository hackage.haskell.org
  url: http://hackage.haskell.org/
  -- secure: True
  -- root-keys:
  -- key-threshold: 3

-- ignore-expiry: False
-- http-transport:
nix: True
-- store-dir:
-- active-repositories:
-- local-no-index-repo:
remote-repo-cache: /home/amy/.cabal/packages
-- logs-dir: /home/amy/.cabal/logs
-- default-user-config:
-- verbose: 1
-- compiler: ghc
-- cabal-file:
-- with-compiler:
-- with-hc-pkg:
-- program-prefix:
-- program-suffix:
-- library-vanilla: True
-- library-profiling:
-- shared:
-- static:
-- executable-dynamic: False
-- executable-static: False
-- profiling:
-- executable-profiling:
-- profiling-detail:
-- library-profiling-detail:
-- optimization: True
-- debug-info: False
-- build-info:
-- library-for-ghci:
-- split-sections: False
-- split-objs: False
-- executable-stripping:
-- library-stripping:
-- configure-option:
-- user-install: True
-- package-db:
-- flags:
-- extra-include-dirs:
-- deterministic:
-- cid:
-- extra-lib-dirs:
-- extra-lib-dirs-static:
-- extra-framework-dirs:
extra-prog-path: /home/amy/.cabal/bin
-- instantiate-with:
-- tests: False
-- coverage: False
-- library-coverage:
-- exact-configuration: False
-- benchmarks: False
-- relocatable: False
-- response-files:
-- allow-depending-on-private-libs:
-- cabal-lib-version:
-- append:
-- backup:
-- constraint:
-- preference:
-- solver: modular
-- allow-older: False
-- allow-newer: False
-- write-ghc-environment-files:
-- documentation: False
-- doc-index-file: $datadir/doc/$arch-$os-$compiler/index.html
-- only-download: False
-- target-package-db:
-- max-backjumps: 4000
-- reorder-goals: False
-- count-conflicts: True
-- fine-grained-conflicts: True
-- minimize-conflict-set: False
-- independent-goals: False
-- shadow-installed-packages: False
-- strong-flags: False
-- allow-boot-library-installs: False
-- reject-unconstrained-dependencies: none
-- reinstall: False
-- avoid-reinstalls: False
-- force-reinstalls: False
-- upgrade-dependencies: False
-- index-state:
-- root-cmd:
-- symlink-bindir:
build-summary: /home/amy/.cabal/logs/build.log
-- build-log:
remote-build-reporting: none
-- report-planning-failure: False
-- per-component: True
-- run-tests:
jobs: $ncpus
-- keep-going: False
-- offline: False
-- lib: False
-- package-env:
-- overwrite-policy:
-- install-method:
installdir: /home/amy/.cabal/bin
-- username:
-- password:
-- password-command:
-- builddir:

haddock
  -- keep-temp-files: False
  -- hoogle: False
  -- html: False
  -- html-location:
  -- executables: False
  -- tests: False
  -- benchmarks: False
  -- foreign-libraries: False
  -- all:
  -- internal: False
  -- css:
  -- hyperlink-source: False
  -- quickjump: False
  -- hscolour-css:
  -- contents-location:

init
  -- interactive: False
  -- cabal-version: 3.0
  -- license:
  -- extra-doc-file:
  -- tests:
  -- test-dir:
  -- language: Haskell2010
  -- application-dir: app
  -- source-dir: src

install-dirs user
  -- prefix: /home/amy/.cabal
  -- bindir: $prefix/bin
  -- libdir: $prefix/lib
  -- libsubdir: $abi/$libname
  -- dynlibdir: $libdir/$abi
  -- libexecdir: $prefix/libexec
  -- libexecsubdir: $abi/$pkgid
  -- datadir: $prefix/share
  -- datasubdir: $abi/$pkgid
  -- docdir: $datadir/doc/$abi/$pkgid
  -- htmldir: $docdir/html
  -- haddockdir: $htmldir
  -- sysconfdir: $prefix/etc

install-dirs global
  -- prefix: /usr/local
  -- bindir: $prefix/bin
  -- libdir: $prefix/lib
  -- libsubdir: $abi/$libname
  -- dynlibdir: $libdir/$abi
  -- libexecdir: $prefix/libexec
  -- libexecsubdir: $abi/$pkgid
  -- datadir: $prefix/share
  -- datasubdir: $abi/$pkgid
  -- docdir: $datadir/doc/$abi/$pkgid
  -- htmldir: $docdir/html
  -- haddockdir: $htmldir
  -- sysconfdir: $prefix/etc

program-locations
  -- alex-location:
  -- ar-location:
  -- c2hs-location:
  -- cpphs-location:
  -- doctest-location:
  -- gcc-location:
  -- ghc-location:
  -- ghc-pkg-location:
  -- ghcjs-location:
  -- ghcjs-pkg-location:
  -- greencard-location:
  -- haddock-location:
  -- happy-location:
  -- haskell-suite-location:
  -- haskell-suite-pkg-location:
  -- hmake-location:
  -- hpc-location:
  -- hsc2hs-location:
  -- hscolour-location:
  -- jhc-location:
  -- ld-location:
  -- pkg-config-location:
  -- runghc-location:
  -- strip-location:
  -- tar-location:
  -- uhc-location:

program-default-options
  -- alex-options:
  -- ar-options:
  -- c2hs-options:
  -- cpphs-options:
  -- doctest-options:
  -- gcc-options:
  -- ghc-options:
  -- ghc-pkg-options:
  -- ghcjs-options:
  -- ghcjs-pkg-options:
  -- greencard-options:
  -- haddock-options:
  -- happy-options:
  -- haskell-suite-options:
  -- haskell-suite-pkg-options:
  -- hmake-options:
  -- hpc-options:
  -- hsc2hs-options:
  -- hscolour-options:
  -- jhc-options:
  -- ld-options:
  -- pkg-config-options:
  -- runghc-options:
  -- strip-options:
  -- tar-options:
  -- uhc-options:

mhwombat avatar Sep 04 '22 17:09 mhwombat

Thanks for the report! V2-commands don't support this option anyway (#4646), so these are (probably) not the droids you're looking for, but we certainly shouldn't fail with a parse error!

ulysses4ever avatar Sep 04 '22 19:09 ulysses4ever

I get the same error if I do cabal update [no v2], which is what I normally do. That used to work. Should I no longer put nix: True in my cabal configuration?

mhwombat avatar Sep 04 '22 20:09 mhwombat

Since cabal 3.x (for some x... I wanna say 4), cabal update is cabal v2-update. To get to a v1 command, you have to spell it, e.g. cabal v1-update.

I'm not trying to say that v1 won't fall for it. I'm trying to say that you probably don't need nix: True at all. Just enter the shell. This is the whole point of nix-shell: the tools you're running don't have to know about it. So, this flag is imo a mis-feature.

If you don't want to manually enter the shell every time, you could look into (nix-)direnv, lorri, etc. Again, I'm not saying this is better (I guess, having nix: True working would be nice, that's why #4646 is still open), but I'm saying: workarounds are available. Not for the parse error, but for the feature you're trying to use.

ulysses4ever avatar Sep 04 '22 20:09 ulysses4ever

It would seem like a bug to me that -- nix: is in the default configuration if this is not supported.

denizdogan avatar Sep 26 '22 01:09 denizdogan

It would seem like a bug to me that -- nix: is in the default configuration if this is not supported.

I think you may not be wrong. An issue and/or PR are welcome (and we're going to double-check removing this is a good idea in the discussion for the PR).

Mikolaj avatar Sep 30 '22 16:09 Mikolaj

Was a change to the "nix" config option intentional or accidental? The only thing mentioned in the change log is: "Make enable/disable nix flags easier to read"

chris-martin avatar Oct 04 '22 20:10 chris-martin

I didn't realized it's a 3.8 regression. I'd be very surprised if #8054 is the reason (thanks Chris for pointing to it!) -- it looks completely innocent, but otoh it's the most likely... Would be good is someone confirmed.

ulysses4ever avatar Oct 04 '22 21:10 ulysses4ever

I checked that #8054 is indeed the culprit.

ulysses4ever avatar Oct 05 '22 00:10 ulysses4ever

I tried to make sense of it but cabal flag combinators are simply above my head. I'm paging in @cbclemmer, the author of #8054, in case they want to work on fixing this regression.

Simply rolling back the change is easy, but would be more interesting to retain the improved documentation and have the parser recognize the "nix" flag in config as before… Maybe rolling back for now and researching more in due course would be the right way to go.

ulysses4ever avatar Oct 08 '22 16:10 ulysses4ever

@ulysses4ever Yeah, I can look into it

cbclemmer avatar Oct 08 '22 16:10 cbclemmer

PR is up #8522 it fixes the issue and adds tests for the config file.

cbclemmer avatar Oct 10 '22 17:10 cbclemmer