commit 792b11846cb392f188f5dd79e48894f175917607 Author: niten Date: Wed Feb 7 14:09:35 2024 -0800 Initial checkin diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..08e7115 --- /dev/null +++ b/flake.nix @@ -0,0 +1,17 @@ +{ + description = "Immich running in a container"; + + inputs = { + nixpkgs.url = "nixpkgs/nixos-23.11"; + arion.url = "github:hercules-ci/arion"; + }; + + outputs = { self, nixpkgs, arion, ... }: { + nixosModules = rec { + default = immichContainer; + immichContainer = { ... }: { + imports = [ arion.nixosModules.arion ./immich-container.nix ]; + }; + }; + }; +} diff --git a/immich-container.nix b/immich-container.nix new file mode 100644 index 0000000..f878ef7 --- /dev/null +++ b/immich-container.nix @@ -0,0 +1,99 @@ +{ config, lib, pkgs, ... }: + +with lib; +let cfg = config.services.immichContainer; +in { + options.services.immichContainer = with types; { + enable = + mkEnableOption "Enable Immich photo server running in a container."; + + state-directory = mkOption { + type = str; + description = "Path at which to store server state."; + }; + + store-directory = mkOption { + type = str; + description = "Path at which to store bulk server data."; + }; + + images = { + immich = mkOption { + type = str; + description = "Immich server docker image to use."; + }; + immich-ml = mkOption { + type = str; + description = "Immich Machine Learning docker image to use."; + }; + redis = mkOption { + type = str; + description = "Redis server docker image to use."; + }; + postgresql = mkOption { + type = str; + description = "Postgresql server docker image to use."; + }; + }; + }; + + config = { + virtualisation.arion.projects.nextcloud.settings = let + image = { ... }: { + project.name = "immich"; + services = { + immich = { + service = { + image = cfg.images.immich; + restart = "always"; + ports = [ "${cfg.port}:3001" ]; + command = [ "start.sh" "immich" ]; + depends_on = [ "redis" "database" ]; + volumes = [ + "${cfg.store-directory}:/usr/src/app/upload" + "/etc/localtime:/etc/localtime:ro" + ]; + }; + }; + + immich-microservices = { + service = { + image = cfg.images.immich; + restart = "always"; + command = [ "start.sh" "microservices" ]; + depends_on = [ "redis" "database" ]; + volumes = [ + "${cfg.store-directory}:/usr/src/app/upload" + "/etc/localtime:/etc/localtime:ro" + ]; + }; + }; + + immich-ml = { + service = { + image = cfg.images.immich-ml; + restart = "always"; + volumes = [ "${cfg.state-directory}/model-cache:/cache" ]; + }; + }; + + redis.service = { + image = cfg.images.redis; + restart = "always"; + volumes = [ "${cfg.state-directory}/redis:/var/lib/redis" ]; + }; + + database = { + service = { + image = cfg.images.postgresql; + restart = "always"; + depends_on = [ "redis" "database" ]; + volumes = + [ "${cfg.state-directory}/database:/var/lib/postgresql/data" ]; + }; + }; + }; + }; + in imports [ image ]; + }; +}