2024-05-20 17:35:25 -07:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
2024-05-20 19:05:15 -07:00
|
|
|
with lib;
|
2024-05-21 10:56:23 -07:00
|
|
|
let
|
|
|
|
cfg = config.services.immichMlContainer;
|
|
|
|
|
2024-05-21 11:03:52 -07:00
|
|
|
immichMlConfigYaml = pkgs.writeText "immich-ml-compose.yml" (builtins.toJSON {
|
2024-05-22 13:51:26 -07:00
|
|
|
version = "3.8";
|
2024-05-22 10:34:19 -07:00
|
|
|
name = "immich-machine-learning";
|
2024-05-21 10:56:23 -07:00
|
|
|
networks.default.name = "immich-ml";
|
2024-05-22 10:34:19 -07:00
|
|
|
|
2024-05-21 10:56:23 -07:00
|
|
|
volumes = { };
|
|
|
|
services.immich-ml = {
|
|
|
|
image =
|
|
|
|
"ghcr.io/immich-app/immich-machine-learning:${cfg.immich-version}-cuda";
|
2024-05-22 10:44:02 -07:00
|
|
|
deploy.resources.reservations.devices =
|
|
|
|
[{ capabilities = [ "nvidia-gpu" "nvidia-compute" "nvidia-video" ]; }];
|
2024-05-21 11:06:24 -07:00
|
|
|
ports = [ "${toString cfg.port}:3003" ];
|
2024-05-21 10:56:23 -07:00
|
|
|
restart = "always";
|
|
|
|
volumes = [ "${cfg.state-directory}:/cache" ];
|
2024-05-22 11:16:02 -07:00
|
|
|
environment = { IMMICH_LOG_LEVEL = "debug"; };
|
2024-05-21 10:56:23 -07:00
|
|
|
};
|
2024-05-21 10:59:13 -07:00
|
|
|
});
|
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
|
|
|
};
|
|
|
|
|
|
|
|
state-directory = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Path on which to store service state.";
|
|
|
|
};
|
|
|
|
|
|
|
|
immich-version = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "";
|
|
|
|
};
|
|
|
|
|
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-21 10:56:23 -07:00
|
|
|
systemd = {
|
|
|
|
services.immich-machine-learning = {
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
before = [ "nginx.service" ];
|
2024-05-22 10:34:19 -07:00
|
|
|
path = with pkgs; [ docker-compose nvidia-podman coreutils ];
|
2024-05-21 10:56:23 -07:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = pkgs.writeShellScript "immich-machine-learning" ''
|
2024-05-22 10:34:19 -07:00
|
|
|
docker-compose -f ${immichMlConfigYaml} up
|
2024-05-21 10:56:23 -07:00
|
|
|
'';
|
2024-05-20 17:35:25 -07:00
|
|
|
};
|
|
|
|
};
|
2024-05-21 10:56:23 -07:00
|
|
|
|
|
|
|
tmpfiles.rules = [ "d ${cfg.state-directory} 0750 root root - -" ];
|
|
|
|
};
|
2024-05-20 17:35:25 -07:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts = genAttrs cfg.hostnames (hostname: {
|
|
|
|
enableACME = false;
|
|
|
|
forceSSL = false;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString cfg.port}";
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|