module Stack.Types.Nix where
import Control.Applicative
import Data.Aeson.Extended
import Data.Monoid
import Data.Text (Text)
import GHC.Generics (Generic)
import Generics.Deriving.Monoid (mappenddefault, memptydefault)
import Prelude
data NixOpts = NixOpts
{nixEnable :: !Bool
,nixPureShell :: !Bool
,nixPackages :: ![Text]
,nixInitFile :: !(Maybe FilePath)
,nixShellOptions :: ![Text]
,nixAddGCRoots :: !Bool
}
deriving (Show)
data NixOptsMonoid = NixOptsMonoid
{nixMonoidDefaultEnable :: !Any
,nixMonoidEnable :: !(First Bool)
,nixMonoidPureShell :: !(First Bool)
,nixMonoidPackages :: !(First [Text])
,nixMonoidInitFile :: !(First FilePath)
,nixMonoidShellOptions :: !(First [Text])
,nixMonoidPath :: !(First [Text])
,nixMonoidAddGCRoots :: !(First Bool)
}
deriving (Eq, Show, Generic)
instance FromJSON (WithJSONWarnings NixOptsMonoid) where
parseJSON = withObjectWarnings "NixOptsMonoid"
(\o -> do nixMonoidDefaultEnable <- pure (Any False)
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 <- First <$> o ..:? nixAddGCRootsArgName
return NixOptsMonoid{..})
instance Monoid NixOptsMonoid where
mempty = memptydefault
mappend = mappenddefault
nixEnableArgName :: Text
nixEnableArgName = "enable"
nixPureShellArgName :: Text
nixPureShellArgName = "pure"
nixPackagesArgName :: Text
nixPackagesArgName = "packages"
nixInitFileArgName :: Text
nixInitFileArgName = "shell-file"
nixShellOptsArgName :: Text
nixShellOptsArgName = "nix-shell-options"
nixPathArgName :: Text
nixPathArgName = "path"
nixAddGCRootsArgName :: Text
nixAddGCRootsArgName = "add-gc-roots"