2022-10-11 21:36:27 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit
|
|
|
|
(lib)
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
;
|
|
|
|
|
|
|
|
cfg = config.my.services.photoprism;
|
|
|
|
my = config.my;
|
|
|
|
|
|
|
|
domain = config.networking.domain;
|
|
|
|
hostname = config.networking.hostName;
|
|
|
|
fqdn = "${hostname}.${domain}";
|
|
|
|
in {
|
|
|
|
options.my.services.photoprism = let
|
|
|
|
inherit (lib) types;
|
|
|
|
in {
|
|
|
|
enable = mkEnableOption "Photoprism config";
|
|
|
|
|
|
|
|
home = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/photoprism";
|
|
|
|
example = "/var/lib/photoprism";
|
|
|
|
description = "Home for the photoprism service, where data will be stored";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 2342;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port for Photoprism webapp";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
users.users.photoprism = {
|
|
|
|
isSystemUser = true;
|
|
|
|
home = cfg.home;
|
|
|
|
createHome = true;
|
|
|
|
group = "photoprism";
|
|
|
|
};
|
|
|
|
users.groups.photoprism = {};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts = {
|
|
|
|
"photoprism.${domain}" = {
|
|
|
|
forceSSL = true;
|
|
|
|
useACMEHost = fqdn;
|
|
|
|
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
2022-10-11 22:36:05 +02:00
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_connect_timeout 600;
|
|
|
|
proxy_read_timeout 600;
|
|
|
|
proxy_send_timeout 600;
|
2024-07-03 20:51:17 +02:00
|
|
|
client_max_body_size 500m;
|
2022-10-13 11:13:13 +02:00
|
|
|
access_log syslog:server=unix:/dev/log,tag=photoprism;
|
2022-10-11 22:36:05 +02:00
|
|
|
'';
|
2022-10-11 21:36:27 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
security.acme.certs.${fqdn}.extraDomainNames = ["photoprism.${domain}"];
|
|
|
|
|
|
|
|
my.services.restic-backup = mkIf cfg.enable {
|
|
|
|
paths = [
|
|
|
|
cfg.home
|
|
|
|
];
|
2022-10-12 00:34:07 +02:00
|
|
|
exclude = [
|
|
|
|
"${cfg.home}/storage"
|
|
|
|
];
|
2022-10-11 21:36:27 +02:00
|
|
|
};
|
2022-10-13 11:47:24 +02:00
|
|
|
|
|
|
|
services.fail2ban.jails = {
|
|
|
|
photoprism = ''
|
|
|
|
enabled = true
|
|
|
|
filter = photoprism-failed-login
|
|
|
|
port = http,https
|
|
|
|
maxretry = 3
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc = {
|
|
|
|
"fail2ban/filter.d/photoprism-failed-login.conf".text = ''
|
|
|
|
[Definition]
|
|
|
|
failregex = ^.* photoprism: <HOST> - .*"POST \/api\/v1\/session HTTP[^"]*" 400 .*$
|
|
|
|
ignoreregex =
|
|
|
|
journalmatch = _SYSTEMD_UNIT=nginx.service _TRANSPORT=syslog
|
|
|
|
'';
|
|
|
|
};
|
2022-10-11 21:36:27 +02:00
|
|
|
};
|
|
|
|
}
|