{ config, pkgs, ... }: let libDir = "/var/lib/calibre-web/library"; in { services = { calibre-web = { enable = true; listen = { ip = "127.0.0.1"; port = 3020; }; options = { calibreLibrary = libDir; enableBookUploading = true; }; }; nginx = { virtualHosts."library.internal" = { locations."/" = { proxyPass = "http://127.0.0.1:3020"; proxyWebsockets = true; }; }; }; }; systemd.services.calibre-web = { preStart = '' if [ ! -f "${libDir}/metadata.db" ]; then mkdir -p "${libDir}" ${pkgs.calibre}/bin/calibredb add --empty \ --with-library "${libDir}" fi ''; }; }