    {-# LANGUAGE DeriveDataTypeable #-}

    module Propellor.Types.Chroot where

    import Propellor.Types
    import Propellor.Types.Empty
    import Propellor.Types.Info

    import qualified Data.Semigroup as Sem
    import qualified Data.Map as M
    import Data.Monoid
    import Prelude

    data ChrootInfo = ChrootInfo
    	{ ChrootInfo -> Map FilePath Host
    _chroots :: M.Map FilePath Host
    	, ChrootInfo -> ChrootCfg
    _chrootCfg :: ChrootCfg
    	}
    	deriving (Int -> ChrootInfo -> ShowS
    [ChrootInfo] -> ShowS
    ChrootInfo -> FilePath
    (Int -> ChrootInfo -> ShowS)
    -> (ChrootInfo -> FilePath)
    -> ([ChrootInfo] -> ShowS)
    -> Show ChrootInfo
    forall a.
    (Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ChrootInfo -> ShowS
    showsPrec :: Int -> ChrootInfo -> ShowS
    $cshow :: ChrootInfo -> FilePath
    show :: ChrootInfo -> FilePath
    $cshowList :: [ChrootInfo] -> ShowS
    showList :: [ChrootInfo] -> ShowS
    Show, Typeable)

    instance IsInfo ChrootInfo where
    	propagateInfo :: ChrootInfo -> PropagateInfo
    propagateInfo ChrootInfo
    _ = Bool -> PropagateInfo
    PropagateInfo Bool
    False

    instance Sem.Semigroup ChrootInfo where
    	ChrootInfo
    old <> :: ChrootInfo -> ChrootInfo -> ChrootInfo
    <> ChrootInfo
    new = ChrootInfo
    		{ _chroots :: Map FilePath Host
    _chroots = Map FilePath Host -> Map FilePath Host -> Map FilePath Host
    forall k a. Ord k => Map k a -> Map k a -> Map k a
    M.union (ChrootInfo -> Map FilePath Host
    _chroots ChrootInfo
    old) (ChrootInfo -> Map FilePath Host
    _chroots ChrootInfo
    new)
    		, _chrootCfg :: ChrootCfg
    _chrootCfg = ChrootInfo -> ChrootCfg
    _chrootCfg ChrootInfo
    old ChrootCfg -> ChrootCfg -> ChrootCfg
    forall a. Semigroup a => a -> a -> a
    <> ChrootInfo -> ChrootCfg
    _chrootCfg ChrootInfo
    new
    		}

    instance Monoid ChrootInfo where
    	mempty :: ChrootInfo
    mempty = Map FilePath Host -> ChrootCfg -> ChrootInfo
    ChrootInfo Map FilePath Host
    forall a. Monoid a => a
    mempty ChrootCfg
    forall a. Monoid a => a
    mempty
    	mappend :: ChrootInfo -> ChrootInfo -> ChrootInfo
    mappend = ChrootInfo -> ChrootInfo -> ChrootInfo
    forall a. Semigroup a => a -> a -> a
    (Sem.<>)

    instance Empty ChrootInfo where
    	isEmpty :: ChrootInfo -> Bool
    isEmpty ChrootInfo
    i = [Bool] -> Bool
    forall (t :: * -> *). Foldable t => t Bool -> Bool
    and
    		[ Map FilePath Host -> Bool
    forall t. Empty t => t -> Bool
    isEmpty (ChrootInfo -> Map FilePath Host
    _chroots ChrootInfo
    i)
    		, ChrootCfg -> Bool
    forall t. Empty t => t -> Bool
    isEmpty (ChrootInfo -> ChrootCfg
    _chrootCfg ChrootInfo
    i)
    		]

    data ChrootCfg
    	= NoChrootCfg
    	| SystemdNspawnCfg [(String, Bool)]
    	deriving (Int -> ChrootCfg -> ShowS
    [ChrootCfg] -> ShowS
    ChrootCfg -> FilePath
    (Int -> ChrootCfg -> ShowS)
    -> (ChrootCfg -> FilePath)
    -> ([ChrootCfg] -> ShowS)
    -> Show ChrootCfg
    forall a.
    (Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> ChrootCfg -> ShowS
    showsPrec :: Int -> ChrootCfg -> ShowS
    $cshow :: ChrootCfg -> FilePath
    show :: ChrootCfg -> FilePath
    $cshowList :: [ChrootCfg] -> ShowS
    showList :: [ChrootCfg] -> ShowS
    Show, ChrootCfg -> ChrootCfg -> Bool
    (ChrootCfg -> ChrootCfg -> Bool)
    -> (ChrootCfg -> ChrootCfg -> Bool) -> Eq ChrootCfg
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: ChrootCfg -> ChrootCfg -> Bool
    == :: ChrootCfg -> ChrootCfg -> Bool
    $c/= :: ChrootCfg -> ChrootCfg -> Bool
    /= :: ChrootCfg -> ChrootCfg -> Bool
    Eq)

    instance Sem.Semigroup ChrootCfg where
    	ChrootCfg
    v <> :: ChrootCfg -> ChrootCfg -> ChrootCfg
    <> ChrootCfg
    NoChrootCfg = ChrootCfg
    v
    	ChrootCfg
    NoChrootCfg <> ChrootCfg
    v = ChrootCfg
    v
    	SystemdNspawnCfg [(FilePath, Bool)]
    l1 <> SystemdNspawnCfg [(FilePath, Bool)]
    l2 =
    		[(FilePath, Bool)] -> ChrootCfg
    SystemdNspawnCfg ([(FilePath, Bool)]
    l1 [(FilePath, Bool)] -> [(FilePath, Bool)] -> [(FilePath, Bool)]
    forall a. Semigroup a => a -> a -> a
    <> [(FilePath, Bool)]
    l2)

    instance Monoid ChrootCfg where
    	mempty :: ChrootCfg
    mempty = ChrootCfg
    NoChrootCfg
    	mappend :: ChrootCfg -> ChrootCfg -> ChrootCfg
    mappend = ChrootCfg -> ChrootCfg -> ChrootCfg
    forall a. Semigroup a => a -> a -> a
    (Sem.<>)

    instance Empty ChrootCfg where
    	isEmpty :: ChrootCfg -> Bool
    isEmpty ChrootCfg
    c= ChrootCfg
    c ChrootCfg -> ChrootCfg -> Bool
    forall a. Eq a => a -> a -> Bool
    == ChrootCfg
    NoChrootCfg