Skip to content

Commit

Permalink
Merge pull request #6431 from commercialhaskell/nixMonoid-prefix
Browse files Browse the repository at this point in the history
Remove nixMonoid prefix from NixOptsMonoid field names
  • Loading branch information
mpilgrem authored Jan 14, 2024
2 parents d27552f + 472d289 commit 92023cb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
21 changes: 11 additions & 10 deletions src/Stack/Config/Nix.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Nix configuration
module Stack.Config.Nix
Expand Down Expand Up @@ -50,17 +51,17 @@ nixOptsFromMonoid nixMonoid os = do
let defaultPure = case os of
OSX -> False
_ -> True
pureShell = fromFirst defaultPure nixMonoid.nixMonoidPureShell
packages = fromFirst [] nixMonoid.nixMonoidPackages
initFile = getFirst nixMonoid.nixMonoidInitFile
pureShell = fromFirst defaultPure nixMonoid.pureShell
packages = fromFirst [] nixMonoid.packages
initFile = getFirst nixMonoid.initFile
shellOptions =
fromFirst [] nixMonoid.nixMonoidShellOptions
++ prefixAll (T.pack "-I") (fromFirst [] nixMonoid.nixMonoidPath)
addGCRoots = fromFirstFalse nixMonoid.nixMonoidAddGCRoots
fromFirst [] nixMonoid.shellOptions
++ prefixAll (T.pack "-I") (fromFirst [] nixMonoid.path)
addGCRoots = fromFirstFalse nixMonoid.addGCRoots

-- Enable Nix-mode by default on NixOS, unless Docker-mode was specified
osIsNixOS <- isNixOS
let nixEnable0 = fromFirst osIsNixOS nixMonoid.nixMonoidEnable
let nixEnable0 = fromFirst osIsNixOS nixMonoid.enable

enable <-
if nixEnable0 && osIsWindows
Expand Down
4 changes: 2 additions & 2 deletions src/Stack/Options/NixParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ nixOptsParser hide0 = overrideActivation <$>
where
hide = hideMods hide0
overrideActivation m =
if fromFirst False m.nixMonoidPureShell
then m { nixMonoidEnable = (First . Just . fromFirst True) m.nixMonoidEnable }
if fromFirst False m.pureShell
then m { enable = (First . Just . fromFirst True) m.enable }
else m
textArgsOption = fmap (map T.pack) . argsOption
49 changes: 25 additions & 24 deletions src/Stack/Types/Nix.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Nix types.
module Stack.Types.Nix
Expand Down Expand Up @@ -42,20 +43,20 @@ data NixOpts = NixOpts
-- | An uninterpreted representation of nix options.
-- Configurations may be "cascaded" using mappend (left-biased).
data NixOptsMonoid = NixOptsMonoid
{ nixMonoidEnable :: !(First Bool)
{ enable :: !(First Bool)
-- ^ Is using nix-shell enabled?
, nixMonoidPureShell :: !(First Bool)
, pureShell :: !(First Bool)
-- ^ Should the nix-shell be pure
, nixMonoidPackages :: !(First [Text])
, packages :: !(First [Text])
-- ^ System packages to use (given to nix-shell)
, nixMonoidInitFile :: !(First FilePath)
, initFile :: !(First FilePath)
-- ^ The path of a file containing preconfiguration of the environment (e.g
-- shell.nix)
, nixMonoidShellOptions :: !(First [Text])
, shellOptions :: !(First [Text])
-- ^ Options to be given to the nix-shell command line
, nixMonoidPath :: !(First [Text])
, path :: !(First [Text])
-- ^ Override parts of NIX_PATH (notably 'nixpkgs')
, nixMonoidAddGCRoots :: !FirstFalse
, addGCRoots :: !FirstFalse
-- ^ Should we register gc roots so running nix-collect-garbage doesn't
-- remove nix dependencies
}
Expand All @@ -64,21 +65,21 @@ data NixOptsMonoid = NixOptsMonoid
-- | Decode uninterpreted nix options from JSON/YAML.
instance FromJSON (WithJSONWarnings NixOptsMonoid) where
parseJSON = withObjectWarnings "NixOptsMonoid" $ \o -> do
nixMonoidEnable <- First <$> o ..:? nixEnableArgName
nixMonoidPureShell <- First <$> o ..:? nixPureShellArgName
nixMonoidPackages <- First <$> o ..:? nixPackagesArgName
nixMonoidInitFile <- First <$> o ..:? nixInitFileArgName
nixMonoidShellOptions <- First <$> o ..:? nixShellOptsArgName
nixMonoidPath <- First <$> o ..:? nixPathArgName
nixMonoidAddGCRoots <- FirstFalse <$> o ..:? nixAddGCRootsArgName
enable <- First <$> o ..:? nixEnableArgName
pureShell <- First <$> o ..:? nixPureShellArgName
packages <- First <$> o ..:? nixPackagesArgName
initFile <- First <$> o ..:? nixInitFileArgName
shellOptions <- First <$> o ..:? nixShellOptsArgName
path <- First <$> o ..:? nixPathArgName
addGCRoots <- FirstFalse <$> o ..:? nixAddGCRootsArgName
pure $ NixOptsMonoid
{ nixMonoidEnable
, nixMonoidPureShell
, nixMonoidPackages
, nixMonoidInitFile
, nixMonoidShellOptions
, nixMonoidPath
, nixMonoidAddGCRoots
{ enable
, pureShell
, packages
, initFile
, shellOptions
, path
, addGCRoots
}

-- | Left-biased combine Nix options
Expand Down

0 comments on commit 92023cb

Please sign in to comment.