summaryrefslogtreecommitdiff
path: root/doc/forum/How_to_create_a_property_with_info.mdwn
blob: ea8babe5312b4f1977498d65cb6e8de0fd4085f1 (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
55
56
57
58
59
60
61
62
63
64
65
Hello Joey,

I try to setup a debomatic service on one of my computer.
So I created a data which will store on which host it was installed

    data DebOMaticHostMirror = DebOMaticHostMirror Url
	deriving (Eq, Show, Typeable)

So now I try to create a property which get the hostname and set the info, 
BUT I did not find the right way to do this. Here an attempt

    debomaticHostMirror :: Property (HasInfo + UnixLike)
    debomaticHostMirror = property' desc $ \w -> do
      hostname <- asks hostName
      ensureProperty $ pureInfoProperty desc (InfoVal (DebOMaticHostMirror hostname))
        where
          desc = "setup the Deb-O-Matic host name for other properties"

but I get this error message

    src/propellor-config.hs:935:3: error:
    • Couldn't match expected type ‘Propellor Result’
                  with actual type ‘Property
                                      (Propellor.Types.MetaTypes.MetaTypes inner0)
                                    -> Propellor Result’
    • In a stmt of a 'do' block:
        ensureProperty
        $ pureInfoProperty desc (InfoVal (DebOMaticHostMirror hostname))
      In the expression:
        do { hostname <- asks hostName;
             ensureProperty
             $ pureInfoProperty desc (InfoVal (DebOMaticHostMirror hostname)) }
      In the second argument of ‘($)’, namely
        ‘\ w
           -> do { hostname <- asks hostName;
                   ensureProperty
                   $ pureInfoProperty desc (InfoVal (DebOMaticHostMirror hostname)) }’

    src/propellor-config.hs:935:20: error:
    • Couldn't match expected type ‘OuterMetaTypesWitness outer0’
                  with actual type ‘Property (HasInfo + UnixLike)’
    • In the second argument of ‘($)’, namely
        ‘pureInfoProperty desc (InfoVal (DebOMaticHostMirror hostname))’
      In a stmt of a 'do' block:
        ensureProperty
        $ pureInfoProperty desc (InfoVal (DebOMaticHostMirror hostname))
      In the expression:
        do { hostname <- asks hostName;
             ensureProperty
             $ pureInfoProperty desc (InfoVal (DebOMaticHostMirror hostname)) }

the Idea after is to create a property which will take the DeboMatic Info and generate the
/etc/apt/sourses.list.d/debomatic.list on a bunch of hosts.

Maybe we could have a

    typeclass Mirror a where
       toSourceListDLines :: a -> [Line]

    instance Mirror DebOMaticHostMirror where
       toSourceListDLines (DebOMaticHostMirror hostname) = ...

then the stdSourceListD property should be change to use toSourceListDLines

but this is another story :)