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

69 lines
1.8 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-20 17:35:25 -07:00
let cfg = config.services.immichMlContainer;
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 = "";
};
# TODO: maybe have different types?
};
config = {
systemd.tmpfiles.rules = [ "d ${cfg.state-directory} 0750 root root - -" ];
virtualisation.arion.projects.immich.settings = let
image = { ... }: {
project.name = "immich-ml";
services.immich-ml = {
image.rawConfig.deploy.resoruces.reservations.devices = [{
driver = "nvidia";
count = 1;
capabilities = [ "gpu" ];
}];
service = {
image =
"ghcr.io/immich-app/immich-machine-learning:${cfg.immich-version}-cuda";
restart = "always";
ports = [ "${toString cfg.port}:3003" ];
volumes = [ "${cfg.state-directory}:/cache" ];
};
};
};
in { imports = [ image ]; };
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;
};
});
};
};
}