summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bragi.nix48
-rw-r--r--bragi/thermoprint-server/thermoprint-server.hs30
2 files changed, 41 insertions, 37 deletions
diff --git a/bragi.nix b/bragi.nix
index 28d304f4..a971e6a9 100644
--- a/bragi.nix
+++ b/bragi.nix
@@ -275,43 +275,9 @@ in rec {
275 home = "/var/lib/thermoprint"; 275 home = "/var/lib/thermoprint";
276 }; 276 };
277 277
278 environment.etc."thermoprint-server/thermoprint-server.hs" = { 278 environment.etc."thermoprint-server" = {
279 text = '' 279 source = ./bragi/thermoprint-server;
280 {-# LANGUAGE OverloadedStrings #-} 280 mode = "symlink";
281 {-# LANGUAGE ImpredicativeTypes #-}
282
283 module Main (main) where
284
285 import Thermoprint.Server
286
287 import Thermoprint.Server.Printer.Generic
288
289 import Control.Monad.Trans.Resource
290 import Control.Monad.Logger
291 import Control.Monad.Reader
292
293 import Database.Persist.Sqlite
294
295 import qualified Network.Wai.Handler.Warp as Warp
296
297 main :: IO ()
298 main = thermoprintServer True (Nat runSqlite) $ (\c -> c { queueManagers = queueManagers, warpSettings = wSettings }) <$> def `withPrinters` printers
299 where
300 runSqlite :: ReaderT ConnectionPool (LoggingT IO) a -> IO a
301 runSqlite = runStderrLoggingT . withSqlitePool "${users.extraUsers."thermoprint".home}/thermoprint.sqlite" 1 . runReaderT
302
303 printers = [ (pure $ genericPrint "/dev/usb/lp0", def :: QMConfig (ResourceT (ReaderT ConnectionPool (LoggingT IO))))
304 ]
305
306 queueManagers _ = QMConfig
307 { manager = union [ limitHistorySize 100
308 , limitHistoryAge 3600
309 ]
310 , collapse = standardCollapse
311 }
312
313 wSettings = Warp.setHost "127.0.0.1" . Warp.setPort 8080 $ Warp.defaultSettings
314 '';
315 }; 281 };
316 282
317 systemd.services."thermoprint" = { 283 systemd.services."thermoprint" = {
@@ -319,6 +285,7 @@ in rec {
319 THERMOPRINT_CONFIG = "/etc/thermoprint-server"; 285 THERMOPRINT_CONFIG = "/etc/thermoprint-server";
320 THERMOPRINT_CACHE = ''${users.extraUsers."thermoprint".home}/dyre''; 286 THERMOPRINT_CACHE = ''${users.extraUsers."thermoprint".home}/dyre'';
321 }; 287 };
288 requires = [ "postgresql.service" ];
322 wantedBy = [ "default.target" ]; 289 wantedBy = [ "default.target" ];
323 serviceConfig = { 290 serviceConfig = {
324 Type = "simple"; 291 Type = "simple";
@@ -395,6 +362,13 @@ in rec {
395 ''; 362 '';
396 }; 363 };
397 364
365 services.postgresql = {
366 enable = true;
367 authorization = lib.mkForce ''
368 local sameuser all peer
369 '';
370 };
371
398 nix = { 372 nix = {
399 daemonIONiceLevel = 3; 373 daemonIONiceLevel = 3;
400 daemonNiceLevel = 10; 374 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 @@
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE ImpredicativeTypes #-}
3
4module Main (main) where
5
6import Thermoprint.Server
7
8import Thermoprint.Server.Printer.Generic
9
10import Control.Monad.Trans.Resource
11import Control.Monad.Logger
12import Control.Monad.Reader
13
14import Database.Persist.Postgresql
15
16main :: IO ()
17main = thermoprintServer True (Nat runDb) $ (\c -> c { queueManagers = queueManagers }) <$> def `withPrinters` printers
18 where
19 runDb :: ReaderT ConnectionPool (LoggingT IO) a -> IO a
20 runDb = runStderrLoggingT . withPostgresqlPool "" 5 . runReaderT
21
22 printers = [ (pure $ genericPrint "/dev/usb/lp0", def)
23 ]
24
25 queueManagers _ = QMConfig
26 { manager = union [ limitHistorySize 100
27 , limitHistoryAge 3600
28 ]
29 , collapse = standardCollapse
30 }