]> Git — Sourcephile - sourcephile-nix.git/blob - hosts/mermet/calibre.nix
mermet: calibre: add --disable-use-bonjour
[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 /*
16 port = 17429;
17 libraries = [
18 "${stateDir}/libraries/julm"
19 ];
20 # sudo -u calibre-server calibre-server --userdb /var/lib/calibre/users.sqlite --manage-users
21 auth = {
22 enable = true;
23 mode = "basic";
24 userDb = "${stateDir}/users.sqlite";
25 };
26 */
27 };
28 systemd.services.calibre-server = {
29 unitConfig = {
30 StartLimitBurst = 5;
31 StartLimitIntervalSec = "600s";
32 };
33 serviceConfig = {
34 ExecStart = mkForce "${pkgs.calibre}/bin/calibre-server ${stateDir}/libraries/julm --auth-mode basic --listen-on 127.0.0.1 --port 17429 --userdb ${stateDir}/users.sqlite --enable-auth --disable-use-bonjour";
35 MemoryAccounting = true;
36 MemoryMax = "300M";
37 MemoryHigh = "400M";
38 Restart = mkForce "on-failure";
39 RestartSec = "60s";
40 };
41 };
42 users.users.calibre-server.home = mkForce stateDir;
43 services.nginx = {
44 enable = true;
45 upstreams.${srv} = {
46 servers."127.0.0.1:${toString calibre.port}" = {
47 max_fails = 5;
48 fail_timeout = "60s";
49 };
50 extraConfig = ''
51 '';
52 };
53 virtualHosts."${srv}.${domain}" = {
54 forceSSL = true;
55 useACMEHost = domain;
56 extraConfig = ''
57 access_log /var/log/nginx/${domain}/${srv}/access.log json buffer=32k;
58 error_log /var/log/nginx/${domain}/${srv}/error.log;
59 '';
60 locations."/" = {
61 proxyPass = "http://${srv}";
62 extraConfig = ''
63 client_max_body_size 64m;
64 '';
65 };
66 };
67 };
68 systemd.services.nginx = {
69 serviceConfig = {
70 LogsDirectory = lib.mkForce [ "nginx/${domain}/${srv}" ];
71 };
72 };
73 services.sanoid.datasets."rpool/var/lib/${srv}" = {
74 use_template = [ "snap" ];
75 daily = 31;
76 monthly = 3;
77 recursive = true;
78 };
79 }