From 975316a114d96fdd13115c181c33f508aff812bf Mon Sep 17 00:00:00 2001 From: niten Date: Tue, 21 May 2024 10:56:23 -0700 Subject: [PATCH] Switch from arion to manual --- immich-ml-container.nix | 53 +++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/immich-ml-container.nix b/immich-ml-container.nix index 7e13c35..75fb3a4 100644 --- a/immich-ml-container.nix +++ b/immich-ml-container.nix @@ -1,7 +1,27 @@ { config, lib, pkgs, ... }: with lib; -let cfg = config.services.immichMlContainer; +let + cfg = config.services.immichMlContainer; + + immichMlConfigYaml = pkgs.writeJSON "immich-ml-compose.yml" { + version = "3.4"; + networks.default.name = "immich-ml"; + volumes = { }; + services.immich-ml = { + image = + "ghcr.io/immich-app/immich-machine-learning:${cfg.immich-version}-cuda"; + deploy.resources.reservations.devices = [{ + driver = "nvidia"; + count = 1; + capabilities = [ "gpu" ]; + }]; + ports = [ "${cfg.port}:3003" ]; + restart = "always"; + volumes = [ "${cfg.state-directory}:/cache" ]; + }; + }; + in { options.services.immichMlContainer = with types; { enable = mkEnableOption "Enable machine learning container."; @@ -31,27 +51,20 @@ in { }; config = mkIf cfg.enable { - systemd.tmpfiles.rules = [ "d ${cfg.state-directory} 0750 root root - -" ]; - - virtualisation.arion.projects.immich-ml.settings = let - image = { ... }: { - project.name = "immich-ml"; - services.immich-ml = { - image.rawConfig.deploy.resources.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" ]; - }; + systemd = { + services.immich-machine-learning = { + after = [ "network-online.target" ]; + before = [ "nginx.service" ]; + path = with pkgs; [ podman-compose ]; + serviceConfig = { + ExecStart = pkgs.writeShellScript "immich-machine-learning" '' + podman-compose -f ${immichMlConfigYaml} + ''; }; }; - in { imports = [ image ]; }; + + tmpfiles.rules = [ "d ${cfg.state-directory} 0750 root root - -" ]; + }; services.nginx = { enable = true;