]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/mermet/calibre.nix
mermet: set memory limits
[sourcephile-nix.git] / hosts / mermet / calibre.nix
1 { pkgs, lib, config, ... }:
2 with lib;
3 let
4 domain = "sourcephile.fr";
5 srv = "calibre";
6 calibre = config.services.calibre-server;
7 stateDir = "/var/lib/calibre";
8 in
9 {
10 # Beware, calibre pulls a lot of dependencies..
11 # TODO: The calibre server also supports systemd socket activation
12 services.calibre-server = {
13 enable = true;
14 host = "127.0.0.1";
15 port = 17429;
16 libraries = [
17 "${stateDir}/libraries/julm"
18 ];
19 # sudo -u calibre-server calibre-server --userdb /var/lib/calibre/users.sqlite --manage-users
20 auth = {
21 enable = true;
22 mode = "basic";
23 userDb = "${stateDir}/users.sqlite";
24 };
25 };
26 systemd.services.calibre-server = {
27 unitConfig = {
28 StartLimitBurst = 5;
29 StartLimitIntervalSec = "600s";
30 };
31 serviceConfig = {
32 MemoryAccounting = true;
33 MemoryMax = "300M";
34 MemoryHigh = "400M";
35 Restart = mkForce "on-failure";
36 RestartSec = "60s";
37 };
38 };
39 users.users.calibre-server.home = mkForce stateDir;
40 services.nginx = {
41 enable = true;
42 upstreams.${srv} = {
43 servers."127.0.0.1:${toString calibre.port}" = {
44 max_fails = 5;
45 fail_timeout = "60s";
46 };
47 extraConfig = ''
48 '';
49 };
50 virtualHosts."${srv}.${domain}" = {
51 forceSSL = true;
52 useACMEHost = domain;
53 extraConfig = ''
54 access_log /var/log/nginx/${domain}/${srv}/access.log json buffer=32k;
55 error_log /var/log/nginx/${domain}/${srv}/error.log;
56 '';
57 locations."/" = {
58 proxyPass = "http://${srv}";
59 extraConfig = ''
60 client_max_body_size 64m;
61 '';
62 };
63 };
64 };
65 systemd.services.nginx = {
66 serviceConfig = {
67 LogsDirectory = lib.mkForce [ "nginx/${domain}/${srv}" ];
68 };
69 };
70 services.sanoid.datasets."rpool/var/lib/${srv}" = {
71 use_template = [ "snap" ];
72 daily = 31;
73 monthly = 3;
74 recursive = true;
75 };
76 }