{ pkgs, lib, config, ... }: # TODO: Improve with mariadb database let uid = 458; gid = 458; cfg = config.services.photoprism; in { options.services.photoprism = with lib; { enable = mkEnableOption "Photoprism service"; url = mkOption { type = types.str; description = "Url with http:// prefix"; }; port = mkOption { type = types.int; default = 2342; description = "Port to expose on"; }; rootDir = mkOption { type = types.str; description = "Path to use for photoprism storage"; }; environmentFile = mkOption { type = types.str; description = "Additional environment file. I.e. for specifying PHOTOPRISM_ADMIN_PASSWORD"; }; openFirewall = mkEnableOption "port opening"; }; config = lib.mkIf cfg.enable { # Create the necessary user and group users = { groups.photoprism.gid = gid; users.photoprism = { inherit uid; group = config.users.groups.photoprism.name; isSystemUser = true; }; }; # Open the port in the firewall networking.firewall.allowedTCPPorts = lib.optional cfg.openFirewall cfg.port; virtualisation.oci-containers.containers = { # Configure the main container "photoprism" = { image = "photoprism/photoprism:latest"; ports = ["${builtins.toString cfg.port}:2342"]; environment = { PHOTOPRISM_UPLOAD_NSFW = "true"; PHOTOPRISM_DETECT_NSFW = "true"; PHOTOPRISM_UID = builtins.toString uid; PHOTOPRISM_GID = builtins.toString gid; PHOTOPRISM_SITE_URL = cfg.url; PHOTOPRISM_SITE_TITLE = "PhotoPrism"; PHOTOPRISM_SITE_CAPTION = "All the pictures!"; PHOTOPRISM_SITE_DESCRIPTION = ""; PHOTOPRISM_SITE_AUTHOR = ""; }; environmentFiles = [cfg.environmentFile]; volumes = [ "${cfg.rootDir}/storage:/photoprism/storage" "${cfg.rootDir}/import:/photoprism/import" "${cfg.rootDir}/originals:/photoprism/originals" ]; }; }; }; }