nixos/modules/photoprism.nix

70 lines
1.9 KiB
Nix

{
pkgs,
lib,
config,
...
}:
# TODO: Improve with mariadb database
let
port = 2342;
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";
};
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";
};
};
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 = [port];
virtualisation.oci-containers.containers = {
# Configure the main container
"photoprism" = {
image = "photoprism/photoprism:latest";
ports = ["${builtins.toString 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"
];
};
};
};
}