diff options
author | Andrew Cady <d@jerkface.net> | 2018-07-10 06:29:05 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2018-07-10 06:29:05 -0400 |
commit | 0af33cecec5d0a9a23fb4b1758455cef3840db88 (patch) | |
tree | c41069c895929efbbb8512c1680f6b752e6028a1 /fsmgr.hs | |
parent | e6d7f0fcc5475b7cbd6b675fc2d4954838410c21 (diff) |
separate module ConfigFile
Diffstat (limited to 'fsmgr.hs')
-rw-r--r-- | fsmgr.hs | 63 |
1 files changed, 2 insertions, 61 deletions
@@ -10,72 +10,13 @@ | |||
10 | module Main where | 10 | module Main where |
11 | import Rebase.Prelude hiding (bool, hash, (<.>)) | 11 | import Rebase.Prelude hiding (bool, hash, (<.>)) |
12 | 12 | ||
13 | import Data.Yaml.Combinators | ||
14 | import Development.Shake hiding (getEnv) | 13 | import Development.Shake hiding (getEnv) |
15 | import Development.Shake.Command () | 14 | import Development.Shake.Command () |
16 | import Development.Shake.FilePath | 15 | import Development.Shake.FilePath |
17 | import qualified Rebase.Data.Set as Set | ||
18 | import qualified Rebase.Data.Text as Text | 16 | import qualified Rebase.Data.Text as Text |
19 | ;import Rebase.Data.Text (pack, unpack) | 17 | ;import Rebase.Data.Text (pack, unpack) |
20 | import Rebase.Data.Text.Encoding | 18 | |
21 | import qualified Rebase.Data.Vector as Vector | 19 | import ConfigFile |
22 | {- | ||
23 | |||
24 | Basic idea is to have a fs.yaml that specifies the build procedure. Analogous to | ||
25 | stack.yaml, it should specify everything (every source) directly or indirectly. | ||
26 | |||
27 | We want to make new images from CoW copies of old ones. We want to build these | ||
28 | things incrementally, but still end up with something that will be reproducible | ||
29 | from scratch. | ||
30 | |||
31 | Anyway, what we'll have is a list of packages, which will be unpacked first. | ||
32 | Then a list of debconf values, which will be applied. Then we will have the rest | ||
33 | of the other, slower changes to the image (including dpkg --configure -a). Some | ||
34 | changes can be assumed to produce the same results out of order. Oh right, and | ||
35 | the zeroeth step is to generate the empty (or just initial) filesystem image. | ||
36 | The initial filesystem image, if nonempty, is specified by filename (otherwise, | ||
37 | by 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 | ||
42 | determine whether we need to build it. | ||
43 | |||
44 | -} | ||
45 | |||
46 | newtype DebconfConfig = DebconfConfig Text deriving (Show, Read, Eq, Ord) | ||
47 | newtype Package = Package Text deriving (Show, Read, Eq, Ord) | ||
48 | data Patch = Patch deriving (Show, Read) | ||
49 | |||
50 | data BaseImageSpecification | ||
51 | = EmptyImageOfBytes Int | ||
52 | | ParentImageConfigFile FilePath | ||
53 | deriving (Show, Read) | ||
54 | |||
55 | data 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 | |||
64 | parsePackageName :: Text -> Package | ||
65 | parsePackageName = Package -- TODO | ||
66 | |||
67 | diskImageConfigParser :: Parser DiskImageConfig | ||
68 | diskImageConfigParser = 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 | |||
77 | readCfg :: FilePath -> Action DiskImageConfig | ||
78 | readCfg yaml = either error id . parse diskImageConfigParser . encodeUtf8 . pack <$> readFile' yaml | ||
79 | 20 | ||
80 | noParent :: BaseImageSpecification -> Bool | 21 | noParent :: BaseImageSpecification -> Bool |
81 | noParent (EmptyImageOfBytes _) = True | 22 | noParent (EmptyImageOfBytes _) = True |