summaryrefslogtreecommitdiff
path: root/fsmgr.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-07-10 06:29:05 -0400
committerAndrew Cady <d@jerkface.net>2018-07-10 06:29:05 -0400
commit0af33cecec5d0a9a23fb4b1758455cef3840db88 (patch)
treec41069c895929efbbb8512c1680f6b752e6028a1 /fsmgr.hs
parente6d7f0fcc5475b7cbd6b675fc2d4954838410c21 (diff)
separate module ConfigFile
Diffstat (limited to 'fsmgr.hs')
-rw-r--r--fsmgr.hs63
1 files changed, 2 insertions, 61 deletions
diff --git a/fsmgr.hs b/fsmgr.hs
index 626f79f..d5df8ac 100644
--- a/fsmgr.hs
+++ b/fsmgr.hs
@@ -10,72 +10,13 @@
10module Main where 10module Main where
11import Rebase.Prelude hiding (bool, hash, (<.>)) 11import Rebase.Prelude hiding (bool, hash, (<.>))
12 12
13import Data.Yaml.Combinators
14import Development.Shake hiding (getEnv) 13import Development.Shake hiding (getEnv)
15import Development.Shake.Command () 14import Development.Shake.Command ()
16import Development.Shake.FilePath 15import Development.Shake.FilePath
17import qualified Rebase.Data.Set as Set
18import qualified Rebase.Data.Text as Text 16import qualified Rebase.Data.Text as Text
19 ;import Rebase.Data.Text (pack, unpack) 17 ;import Rebase.Data.Text (pack, unpack)
20import Rebase.Data.Text.Encoding 18
21import qualified Rebase.Data.Vector as Vector 19import ConfigFile
22{-
23
24Basic idea is to have a fs.yaml that specifies the build procedure. Analogous to
25stack.yaml, it should specify everything (every source) directly or indirectly.
26
27We want to make new images from CoW copies of old ones. We want to build these
28things incrementally, but still end up with something that will be reproducible
29from scratch.
30
31Anyway, what we'll have is a list of packages, which will be unpacked first.
32Then a list of debconf values, which will be applied. Then we will have the rest
33of the other, slower changes to the image (including dpkg --configure -a). Some
34changes can be assumed to produce the same results out of order. Oh right, and
35the zeroeth step is to generate the empty (or just initial) filesystem image.
36The initial filesystem image, if nonempty, is specified by filename (otherwise,
37by size), while the hash of the configuration determines the output filename.
38
39--
40
41'Parent' param should be a config file, not hash. The hash will only be used to
42determine whether we need to build it.
43
44-}
45
46newtype DebconfConfig = DebconfConfig Text deriving (Show, Read, Eq, Ord)
47newtype Package = Package Text deriving (Show, Read, Eq, Ord)
48data Patch = Patch deriving (Show, Read)
49
50data BaseImageSpecification
51 = EmptyImageOfBytes Int
52 | ParentImageConfigFile FilePath
53 deriving (Show, Read)
54
55data DiskImageConfig = DiskImageConfig {
56 initialImage :: BaseImageSpecification
57, packages :: Set Package
58, debconfConfig :: Maybe FilePath
59, unpackOnly :: Bool
60, binaries :: Vector Text
61, chrootCommands :: Vector Text
62} deriving (Show, Read)
63
64parsePackageName :: Text -> Package
65parsePackageName = Package -- TODO
66
67diskImageConfigParser :: Parser DiskImageConfig
68diskImageConfigParser = object $
69 DiskImageConfig
70 <$> field "parent" ((EmptyImageOfBytes <$> integer) <> (ParentImageConfigFile . unpack <$> string))
71 <*> (Set.fromList . toList . fmap parsePackageName <$> defaultField "packages" Vector.empty (array string))
72 <*> (fmap unpack <$> optField "debconf" string)
73 <*> defaultField "unpack-only" False bool
74 <*> defaultField "binaries" Vector.empty (array string)
75 <*> defaultField "chroot-commands" Vector.empty (array string)
76
77readCfg :: FilePath -> Action DiskImageConfig
78readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml
79 20
80noParent :: BaseImageSpecification -> Bool 21noParent :: BaseImageSpecification -> Bool
81noParent (EmptyImageOfBytes _) = True 22noParent (EmptyImageOfBytes _) = True