File: Embedding_configuration_files_using_Template_Haskell.mdwn

package info (click to toggle)
propellor 5.12-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,788 kB
  • sloc: haskell: 17,913; makefile: 58; perl: 38; sh: 28
file content (24 lines) | stat: -rw-r--r-- 820 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
I want to replace configuration file contents using Propellor, but some configuration files are long so I want to keep them outside config.hs and without having to use quotation. I came up with this:

```
{-# LANGUAGE TemplateHaskell #-}
module Utility.Embed where

import Language.Haskell.TH
import qualified Data.FileEmbed as FE

sourceFile :: FilePath -> Q Exp
sourceFile path = return . AppE (VarE 'lines) =<< FE.embedStringFile path
```

Which can be used like this:

```
standardSystem :: HostName -> Host
standardSystem hn = host hn
                    & Apt.installed ["heimdal-clients"]
                    & "/etc/krb5.conf" `File.hasContent`
                          $(sourceFile "files/etc/krb5.conf")
```

What do you think, is this the right approach or should I just read source files with the IO monad?