From cf8aef18aad8e92f699165350ec4e18a0f2ee3f5 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 6 Mar 2017 21:13:03 +0100 Subject: Migrate thermoprint-server to postgresql --- bragi.nix | 48 ++++++-------------------- bragi/thermoprint-server/thermoprint-server.hs | 30 ++++++++++++++++ 2 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 bragi/thermoprint-server/thermoprint-server.hs diff --git a/bragi.nix b/bragi.nix index 28d304f4..a971e6a9 100644 --- a/bragi.nix +++ b/bragi.nix @@ -275,43 +275,9 @@ in rec { home = "/var/lib/thermoprint"; }; - environment.etc."thermoprint-server/thermoprint-server.hs" = { - text = '' - {-# LANGUAGE OverloadedStrings #-} - {-# LANGUAGE ImpredicativeTypes #-} - - module Main (main) where - - import Thermoprint.Server - - import Thermoprint.Server.Printer.Generic - - import Control.Monad.Trans.Resource - import Control.Monad.Logger - import Control.Monad.Reader - - import Database.Persist.Sqlite - - import qualified Network.Wai.Handler.Warp as Warp - - main :: IO () - main = thermoprintServer True (Nat runSqlite) $ (\c -> c { queueManagers = queueManagers, warpSettings = wSettings }) <$> def `withPrinters` printers - where - runSqlite :: ReaderT ConnectionPool (LoggingT IO) a -> IO a - runSqlite = runStderrLoggingT . withSqlitePool "${users.extraUsers."thermoprint".home}/thermoprint.sqlite" 1 . runReaderT - - printers = [ (pure $ genericPrint "/dev/usb/lp0", def :: QMConfig (ResourceT (ReaderT ConnectionPool (LoggingT IO)))) - ] - - queueManagers _ = QMConfig - { manager = union [ limitHistorySize 100 - , limitHistoryAge 3600 - ] - , collapse = standardCollapse - } - - wSettings = Warp.setHost "127.0.0.1" . Warp.setPort 8080 $ Warp.defaultSettings - ''; + environment.etc."thermoprint-server" = { + source = ./bragi/thermoprint-server; + mode = "symlink"; }; systemd.services."thermoprint" = { @@ -319,6 +285,7 @@ in rec { THERMOPRINT_CONFIG = "/etc/thermoprint-server"; THERMOPRINT_CACHE = ''${users.extraUsers."thermoprint".home}/dyre''; }; + requires = [ "postgresql.service" ]; wantedBy = [ "default.target" ]; serviceConfig = { Type = "simple"; @@ -395,6 +362,13 @@ in rec { ''; }; + services.postgresql = { + enable = true; + authorization = lib.mkForce '' + local sameuser all peer + ''; + }; + nix = { daemonIONiceLevel = 3; daemonNiceLevel = 10; diff --git a/bragi/thermoprint-server/thermoprint-server.hs b/bragi/thermoprint-server/thermoprint-server.hs new file mode 100644 index 00000000..4f909f80 --- /dev/null +++ b/bragi/thermoprint-server/thermoprint-server.hs @@ -0,0 +1,30 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE ImpredicativeTypes #-} + +module Main (main) where + +import Thermoprint.Server + +import Thermoprint.Server.Printer.Generic + +import Control.Monad.Trans.Resource +import Control.Monad.Logger +import Control.Monad.Reader + +import Database.Persist.Postgresql + +main :: IO () +main = thermoprintServer True (Nat runDb) $ (\c -> c { queueManagers = queueManagers }) <$> def `withPrinters` printers + where + runDb :: ReaderT ConnectionPool (LoggingT IO) a -> IO a + runDb = runStderrLoggingT . withPostgresqlPool "" 5 . runReaderT + + printers = [ (pure $ genericPrint "/dev/usb/lp0", def) + ] + + queueManagers _ = QMConfig + { manager = union [ limitHistorySize 100 + , limitHistoryAge 3600 + ] + , collapse = standardCollapse + } -- cgit v1.2.3