Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nix config option #8522

Merged
merged 5 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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