{ config, pkgs, ... }:
let
  domain = "photos.danielk.me";
  bind = "127.0.0.1";
  port = 2283;
  data = "/var/lib/data/immich";
in
{
  services.immich = {
    enable = true;
    mediaLocation = data;
    host = bind;
    port = port;
    machine-learning.environment.MACHINE_LEARNING_REQUEST_THREADS = "2";
  };


  services.caddy.virtualHosts."${domain}" = {
    extraConfig = ''
      reverse_proxy ${bind}:${toString port}
    '';
  };

  fileSystems."/var/lib/data/immich/thumbs" = {
    device = "/var/lib/immich-thumbnails";
    options = [ "bind" ];
  };

  systemd.tmpfiles.rules = [
    "d ${data} 0750 immich immich -"
    "d /var/lib/immich-thumbnails 0750 immich immich -"
  ];
}
