diff options
-rw-r--r-- | services/tazblog/blog/Main.hs | 39 | ||||
-rw-r--r-- | services/tazblog/default.nix | 7 |
2 files changed, 24 insertions, 22 deletions
diff --git a/services/tazblog/blog/Main.hs b/services/tazblog/blog/Main.hs index 246f1325e7fc..2842d1ee1b72 100644 --- a/services/tazblog/blog/Main.hs +++ b/services/tazblog/blog/Main.hs @@ -1,28 +1,25 @@ -- | Main module for the blog's web server module Main where -import Control.Applicative (pure, (<*>)) -import Control.Exception (bracket) -import Data.Word (Word16) -import Locales (version) -import Network (HostName, PortID (..)) -import Options -import Server +import Control.Applicative ((<$>), (<*>)) +import Locales (version) +import Server (runBlog) +import System.Environment (getEnv) -data MainOptions = MainOptions { - blogPort :: Int, - resourceDir :: String -} +data MainOptions + = MainOptions + { blogPort :: Int, + resourceDir :: String + } -instance Options MainOptions where - defineOptions = pure MainOptions - <*> simpleOption "blogPort" 8000 - "Port to serve the blog on. Default is 8000." - <*> simpleOption "resourceDir" "/opt/tazblog/static" - "Resources folder location." +readOpts :: IO MainOptions +readOpts = + MainOptions + <$> (fmap read $ getEnv "PORT") + <*> getEnv "RESOURCE_DIR" -main :: IO() +main :: IO () main = do - putStrLn ("TazBlog " ++ version ++ " in Haskell starting") - runCommand $ \opts _ -> - runBlog (blogPort opts) (resourceDir opts) + putStrLn ("TazBlog " ++ version ++ " in Haskell starting") + opts <- readOpts + runBlog (blogPort opts) (resourceDir opts) diff --git a/services/tazblog/default.nix b/services/tazblog/default.nix index 3999f2b278cd..b1a1f95587bc 100644 --- a/services/tazblog/default.nix +++ b/services/tazblog/default.nix @@ -4,4 +4,9 @@ { pkgs ? import <nixpkgs> {} }: -pkgs.haskell.packages.ghc865.callPackage ./tazblog.nix {} +let tazblog = pkgs.haskell.packages.ghc865.callPackage ./tazblog.nix {}; +in pkgs.writeShellScriptBin "tazblog" '' + export PORT=8000 + export RESOURCE_DIR=${./static} + exec ${tazblog}/bin/tazblog +'' |