Skip to content

Commit

Permalink
Fix nix config option (haskell#8522)
Browse files Browse the repository at this point in the history
* Fix nix config option

* Add changelog file

* Fix whitespace

* Reduce string to bool flag fn

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and alexbiehl committed Dec 15, 2022
1 parent dee990f commit b49be74
Show file tree
Hide file tree
Showing 6 changed files with 710 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ globalCommand commands = CommandUI {
,multiOption "nix"
globalNix (\v flags -> flags { globalNix = v })
[
optArg' "(True or False)" (maybeToFlag . (readMaybe =<<)) (\case
Flag True -> [Just "enable"]
Flag False -> [Just "disable"]
NoFlag -> [Just "disable"]) "" ["nix"]
"Nix integration: run commands through nix-shell if a 'shell.nix' file exists (default is False)",
noArg (Flag True) [] ["enable-nix"]
"Enable Nix integration: run commands through nix-shell if a 'shell.nix' file exists",
noArg (Flag False) [] ["disable-nix"]
Expand Down Expand Up @@ -413,7 +418,6 @@ globalCommand commands = CommandUI {
"Set a location for a cabal.config file for projects without their own cabal.config freeze file."
globalConstraintsFile (\v flags -> flags {globalConstraintsFile = v})
(reqArgFlag "FILE")

]

-- ------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import Distribution.PackageDescription
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import Distribution.Simple.Setup (toFlag, HaddockFlags(..), defaultHaddockFlags)
import Distribution.Client.Setup (globalCommand)
import Distribution.Client.Config (loadConfig, SavedConfig(savedGlobalFlags))
import Distribution.Simple.Compiler
import Distribution.Simple.Command
import qualified Distribution.Simple.Flag as Flag
Expand Down Expand Up @@ -1954,6 +1955,15 @@ testNixFlags = do
Just True @=? (fromFlag . globalNix . fromJust $ nixEnabledFlags)
Just False @=? (fromFlag . globalNix . fromJust $ nixDisabledFlags)
Nothing @=? (fromFlag . globalNix . fromJust $ nixDefaultFlags)

-- Config file options
defaultConfig <- loadConfig verbosity (Flag (basedir </> "nix-config/default-config"))
trueConfig <- loadConfig verbosity (Flag (basedir </> "nix-config/nix-true"))
falseConfig <- loadConfig verbosity (Flag (basedir </> "nix-config/nix-false"))

Nothing @=? (fromFlag . globalNix . savedGlobalFlags $ defaultConfig)
Just True @=? (fromFlag . globalNix . savedGlobalFlags $ trueConfig)
Just False @=? (fromFlag . globalNix . savedGlobalFlags $ falseConfig)
where
fromFlag :: Flag Bool -> Maybe Bool
fromFlag (Flag x) = Just x
Expand Down
229 changes: 229 additions & 0 deletions cabal-install/tests/IntegrationTests2/nix-config/default-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
-- 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.6.2.0
-- cabal-install version: 3.6.2.0


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

-- default-user-config:
-- ignore-expiry: False
-- http-transport:
-- nix: False
-- local-no-index-repo:

--debug-info: 1
-- store-dir:
-- active-repositories:
-- 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
-- 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-framework-dirs:
-- 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:
-- 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-log:
remote-build-reporting: none
-- report-planning-failure: False
-- per-component: True
-- one-shot: False
-- run-tests:
jobs: $ncpus
-- keep-going: False
-- offline: False
-- lib: False
-- package-env:
-- overwrite-policy:
-- install-method:
-- 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: 2.4
-- license:
-- tests:
-- test-dir:
-- language: Haskell2010
-- application-dir: app
-- source-dir: src

install-dirs user
-- 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:
Loading

0 comments on commit b49be74

Please sign in to comment.