From c541fa4e6e2d07dd7a4da538d4e35b4ce09285db Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sat, 24 May 2025 20:04:26 +0200 Subject: [PATCH] feat: Calibre (Desktop + Web) --- modules/apps/calibre/default.nix | 171 +++++++++++++++++++++++++++++-- 1 file changed, 160 insertions(+), 11 deletions(-) diff --git a/modules/apps/calibre/default.nix b/modules/apps/calibre/default.nix index 6fddb81..fc7cd57 100644 --- a/modules/apps/calibre/default.nix +++ b/modules/apps/calibre/default.nix @@ -1,17 +1,166 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: let cfg = config.homelab.apps.calibre; -in { - options.homelab.apps.calibre.enable = lib.mkEnableOption "Calibre"; - config = lib.mkIf cfg.enable { - users.users.calibre = { - uid = lib.mkForce 3010; - isSystemUser = true; - group = config.users.groups.media.name; - home = "/var/empty"; - shell = null; - }; + PUID = toString config.users.users.calibre.uid; + PGID = toString config.users.groups.media.gid; + + networkName = "calibre"; +in { + options.homelab.apps.calibre = { + enable = lib.mkEnableOption "Calibre (Desktop + Web)"; + desktop = lib.mkEnableOption "Calibre Desktop (KasmVNC)"; + web = lib.mkEnableOption "Calibre Web"; }; + + config = lib.mkMerge [ + { + homelab.apps.calibre = lib.mkIf cfg.enable { + desktop = true; + web = true; + }; + } + + # Common + (lib.mkIf (cfg.desktop || cfg.web) { + homelab = { + users.media.enable = true; + virtualisation.containers.enable = true; + }; + + users.users.calibre = { + uid = lib.mkForce 3010; + isSystemUser = true; + group = config.users.groups.media.name; + home = "/var/empty"; + shell = null; + }; + + fileSystems."/srv/books" = { + device = "192.168.0.11:/mnt/SMALL/MEDIA/BOOKS"; + fsType = "nfs"; + options = [ + "rw" + "auto" + "nfsvers=4.2" + "rsize=1048576" "wsize=1048576" + "soft" + "timeo=600" "retrans=2" + "_netdev" "nosuid" "tcp" + ]; + }; + + # Make sure the Docker network exists. + systemd.services."docker-${networkName}-create-network" = { + requiredBy = [ + "docker-calibre.service" + ]; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + script = '' + if ! ${pkgs.docker}/bin/docker network ls | grep -q ${networkName}; then + ${pkgs.docker}/bin/docker network create ${networkName} + fi + ''; + }; + }) + + # Calibre desktop + { + fileSystems."/srv/calibre-config" = { + device = "192.168.0.11:/mnt/SMALL/CONFIG/CALIBRE"; + fsType = "nfs"; + options = [ + "rw" + "auto" + "nfsvers=4.2" + "rsize=1048576" "wsize=1048576" + "soft" + "timeo=600" "retrans=2" + "_netdev" "nosuid" "tcp" + ]; + }; + + virtualisation.oci-containers.containers.calibre = { + hostname = "calibre"; + image = "lscr.io/linuxserver/calibre:latest"; + autoStart = true; + ports = [ + # Open ports if you don't use Traefik + "9480:8080" # Calibre desktop GUI + #"9481:8181" # Calibre desktop GUI HTTPS + #"9581:8081" # Calibre webserver gui + ]; + extraOptions = [ + "--network=${networkName}" + + # syscalls are unkown to Docker + #"--security-opt" "seccomp=unconfined" + ]; + environment = { + inherit PUID PGID; + #UMASK = "022"; + + TZ = config.time.timeZone; + + #PASSWORD = ""; + #CLI_ARGS = ""; + }; + volumes = [ + "/srv/calibre-config:/config" + + "/srv/books:/media/books" + ]; + }; + } + + # Calibre Web + { + fileSystems."/srv/calibre-web-config" = { + device = "192.168.0.11:/mnt/SMALL/CONFIG/CALIBRE-WEB"; + fsType = "nfs"; + options = [ + "rw" + "auto" + "nfsvers=4.2" + "rsize=1048576" "wsize=1048576" + "soft" + "timeo=600" "retrans=2" + "_netdev" "nosuid" "tcp" + ]; + }; + + virtualisation.oci-containers.containers.calibre-web = { + hostname = "calibre-web"; + image = "lscr.io/linuxserver/calibre-web:latest"; + autoStart = true; + ports = [ + # Open ports if you don't use Traefik + "8083:8083" # Web UI + ]; + extraOptions = [ + "--network=${networkName}" + ]; + environment = { + inherit PUID PGID; + #UMASK = "022"; + + TZ = config.time.timeZone; + + # (x86-64 only) Adds the ability to perform ebook conversion + DOCKER_MODS = "linuxserver/mods:universal-calibre"; + # Allow Google Oauth + #OAUTHLIB_RELAX_TOKEN_SCOPE = "1"; + }; + volumes = [ + "/srv/calibre-web-config:/config" + + "/srv/books:/media/books" + ]; + }; + } + ]; }