summaryrefslogtreecommitdiff
path: root/src/Propellor/Types/Chroot.hs
blob: b27203e57c4cb5b216570c0a12978c1f6617fff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{-# LANGUAGE DeriveDataTypeable #-}

module Propellor.Types.Chroot where

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

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

data ChrootInfo = ChrootInfo
	{ _chroots :: M.Map FilePath Host
	, _chrootCfg :: ChrootCfg
	}
	deriving (Show, Typeable)

instance IsInfo ChrootInfo where
	propagateInfo _ = PropagateInfo False

instance Sem.Semigroup ChrootInfo where
	old <> new = ChrootInfo
		{ _chroots = M.union (_chroots old) (_chroots new)
		, _chrootCfg = _chrootCfg old <> _chrootCfg new
		}

instance Monoid ChrootInfo where
	mempty = ChrootInfo mempty mempty
	mappend = (<>)

instance Empty ChrootInfo where
	isEmpty i = and
		[ isEmpty (_chroots i)
		, isEmpty (_chrootCfg i)
		]

data ChrootCfg
	= NoChrootCfg
	| SystemdNspawnCfg [(String, Bool)]
	deriving (Show, Eq)

instance Sem.Semigroup ChrootCfg where
	v <> NoChrootCfg = v
	NoChrootCfg <> v = v
	SystemdNspawnCfg l1 <> SystemdNspawnCfg l2 =
		SystemdNspawnCfg (l1 <> l2)

instance Monoid ChrootCfg where
	mempty = NoChrootCfg
	mappend = (<>)

instance Empty ChrootCfg where
	isEmpty c= c == NoChrootCfg