summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorpelle2015-10-06 15:34:08 +0000
committeradmin2015-10-06 15:34:08 +0000
commit111ba8bf7c21bfa7abdbefd7f190772a4350e8a8 (patch)
tree9509ebf8dd7665286f24f5e31c6672310ce96e44 /doc
parent2ba725cc9aaf3d307870547c4615f8d26b199be4 (diff)
Diffstat (limited to 'doc')
-rw-r--r--doc/forum/Embedding_configuration_files_using_Template_Haskell.mdwn24
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/forum/Embedding_configuration_files_using_Template_Haskell.mdwn b/doc/forum/Embedding_configuration_files_using_Template_Haskell.mdwn
new file mode 100644
index 00000000..11abe93b
--- /dev/null
+++ b/doc/forum/Embedding_configuration_files_using_Template_Haskell.mdwn
@@ -0,0 +1,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?