summaryrefslogtreecommitdiff
path: root/bragi.nix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-06 21:13:03 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-06 21:13:03 +0100
commitcf8aef18aad8e92f699165350ec4e18a0f2ee3f5 (patch)
treea860ca4c37602d646a5b9a90a7fa37e8701e5405 /bragi.nix
parent523df0e6643c63a6927bac7f4de8be42f1484b8d (diff)
downloadnixos-cf8aef18aad8e92f699165350ec4e18a0f2ee3f5.tar
nixos-cf8aef18aad8e92f699165350ec4e18a0f2ee3f5.tar.gz
nixos-cf8aef18aad8e92f699165350ec4e18a0f2ee3f5.tar.bz2
nixos-cf8aef18aad8e92f699165350ec4e18a0f2ee3f5.tar.xz
nixos-cf8aef18aad8e92f699165350ec4e18a0f2ee3f5.zip
Migrate thermoprint-server to postgresql
Diffstat (limited to 'bragi.nix')
-rw-r--r--bragi.nix48
1 files changed, 11 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;