summaryrefslogtreecommitdiff
path: root/custom/tinc/generate_hostfile.hs
blob: 70be98dced8ce87e5a2f5e656db53eebfe463cd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#! /usr/bin/env nix-shell
#! nix-shell -i runghc shell.nix

import System.Directory.Tree
import Data.List

main :: IO ()
main = readDirectory "." >>= putStrLn . genHostFile

genHostFile :: AnchoredDirTree String -> String
genHostFile (_ :/ (Dir _ contents)) = "{\n" ++ entries ++ "\n}\n"
  where
    entries = concat $ [genEntry name content | (File name content) <- contents, name `notElem` hidden]
    genEntry fileName fileContent = unlines . indent $ [ "\"" ++ fileName ++ "\" = ''" ] ++ indent (lines fileContent) ++ [ "'';" ]
    hidden = [ "hosts.nix"
             ]

indent :: [String] -> [String]
indent = map ("  " ++)