immich-ml-container/immich-ml-container.nix

97 lines
2.7 KiB
Nix
Raw Normal View History

2024-05-20 17:35:25 -07:00
{ config, lib, pkgs, ... }:
2024-05-20 19:05:15 -07:00
with lib;
2024-05-22 18:17:58 -07:00
let cfg = config.services.immichMlContainer;
2024-05-21 10:56:23 -07:00
2024-05-20 17:35:25 -07:00
in {
options.services.immichMlContainer = with types; {
enable = mkEnableOption "Enable machine learning container.";
hostnames = mkOption {
type = listOf str;
description = "List of hostnames at which this container can be reached.";
};
port = mkOption {
type = port;
description = "Port on which to listen for connections.";
2024-05-20 18:28:03 -07:00
default = 3003;
2024-05-20 17:35:25 -07:00
};
2024-05-24 09:35:57 -07:00
metrics-port = mkOption {
type = port;
description = "Port on which to supply metrics.";
default = 9090;
};
2024-05-20 17:35:25 -07:00
state-directory = mkOption {
type = str;
description = "Path on which to store service state.";
};
2024-05-24 15:55:54 -07:00
workers = mkOption {
type = int;
description = "Number of workers to run.";
default = 3;
};
threads = mkOption {
type = int;
description = "Number of request threads to run.";
default = 12;
};
immich-version = mkOption { type = str; };
2024-05-20 17:35:25 -07:00
2024-05-21 11:51:33 -07:00
debug = mkEnableOption "Enable debugging logs.";
2024-05-20 17:35:25 -07:00
# TODO: maybe have different types?
};
2024-05-20 19:41:53 -07:00
config = mkIf cfg.enable {
2024-05-22 18:17:58 -07:00
systemd.tmpfiles.rules = [ "d ${cfg.state-directory} 0750 root root - -" ];
2024-05-22 18:21:17 -07:00
virtualisation.oci-containers.containers = {
2024-05-22 18:17:58 -07:00
immich-machine-learning = {
autoStart = true;
image =
"ghcr.io/immich-app/immich-machine-learning:${cfg.immich-version}-cuda";
volumes = [ "${cfg.state-directory}:/cache" ];
2024-05-24 09:35:57 -07:00
ports =
[ "${toString cfg.port}:3003" "${toString cfg.metrics-port}:9090" ];
2024-05-22 18:17:58 -07:00
extraOptions = [ "--gpus=all" ];
2024-05-24 15:55:54 -07:00
environment = {
IMMICH_METRICS = "true";
2024-05-24 16:04:42 -07:00
MACHINE_LEARNING_WORKERS = toString cfg.workers;
MACHINE_LEARNING_REQUEST_THREADS = toString cfg.threads;
2024-05-24 15:55:54 -07:00
};
2024-05-20 17:35:25 -07:00
};
2024-05-21 10:56:23 -07:00
};
2024-05-20 17:35:25 -07:00
services.nginx = {
enable = true;
2024-05-23 11:48:03 -07:00
clientMaxBodySize = "1024M";
2024-05-24 10:39:44 -07:00
commonHttpConfig = ''
log_format with_response_time '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$request_time" "$upstream_response_time"';
access_log /var/log/nginx/access.log with_response_time;
'';
2024-05-20 17:35:25 -07:00
virtualHosts = genAttrs cfg.hostnames (hostname: {
enableACME = false;
forceSSL = false;
2024-05-24 09:37:12 -07:00
locations."/metrics" = {
proxyPass = "http://127.0.0.1:${toString cfg.metrics-port}";
recommendedProxySettings = true;
};
2024-05-20 17:35:25 -07:00
locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.port}";
recommendedProxySettings = true;
2024-05-22 22:14:22 -07:00
proxyWebsockets = true;
2024-05-20 17:35:25 -07:00
};
});
};
};
}