2022-08-06 16:07:29 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
2022-08-06 17:00:45 +02:00
|
|
|
dataDir = "/var/lib/immich";
|
2023-04-11 19:30:32 +02:00
|
|
|
typesenseDataDir = "/var/lib/typesense/data";
|
2022-08-06 17:00:45 +02:00
|
|
|
uploadDir = "${dataDir}/upload";
|
2022-08-06 16:07:29 +02:00
|
|
|
dbuser = "immich";
|
|
|
|
dbname = "immich";
|
2022-08-06 17:00:45 +02:00
|
|
|
dbPasswordFile = config.age.secrets.immich-db-password.path;
|
2022-08-06 16:07:29 +02:00
|
|
|
ociBackend = config.virtualisation.oci-containers.backend;
|
2022-08-06 17:00:45 +02:00
|
|
|
containersHost = "localhost";
|
2022-08-06 16:07:29 +02:00
|
|
|
domain = "photos.felschr.com";
|
|
|
|
|
2022-08-06 17:00:45 +02:00
|
|
|
pgSuperUser = config.services.postgresql.superUser;
|
|
|
|
|
2022-08-07 12:17:29 +02:00
|
|
|
immichBase = {
|
2022-08-06 16:07:29 +02:00
|
|
|
environment = {
|
|
|
|
NODE_ENV = "production";
|
|
|
|
DB_HOSTNAME = containersHost;
|
|
|
|
DB_PORT = toString config.services.postgresql.port;
|
|
|
|
DB_USERNAME = dbuser;
|
|
|
|
DB_DATABASE_NAME = dbname;
|
|
|
|
REDIS_HOSTNAME = containersHost;
|
|
|
|
REDIS_PORT = toString config.services.redis.servers.immich.port;
|
|
|
|
};
|
2022-08-06 17:00:45 +02:00
|
|
|
# only secrets need to be included, e.g. DB_PASSWORD, JWT_SECRET, MAPBOX_KEY
|
2023-04-11 19:30:32 +02:00
|
|
|
environmentFiles = [
|
|
|
|
config.age.secrets.immich-env.path
|
|
|
|
config.age.secrets.immich-typesense-env.path
|
|
|
|
];
|
2022-08-07 12:17:29 +02:00
|
|
|
extraOptions = [
|
|
|
|
"--network=host"
|
|
|
|
"--add-host=immich-server:127.0.0.1"
|
|
|
|
"--add-host=immich-microservices:127.0.0.1"
|
|
|
|
"--add-host=immich-machine-learning:127.0.0.1"
|
|
|
|
"--add-host=immich-web:127.0.0.1"
|
2023-04-11 19:30:32 +02:00
|
|
|
"--add-host=typesense:127.0.0.1"
|
2022-08-07 12:17:29 +02:00
|
|
|
];
|
2022-08-06 16:07:29 +02:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
age.secrets.immich-env.file = ../secrets/immich/.env.age;
|
2022-08-06 17:00:45 +02:00
|
|
|
age.secrets.immich-db-password.file = ../secrets/immich/db-password.age;
|
2023-04-11 19:30:32 +02:00
|
|
|
age.secrets.immich-typesense-env.file = ../secrets/immich/typesense/.env.age;
|
2022-08-06 16:07:29 +02:00
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2022-08-06 17:00:45 +02:00
|
|
|
enableTCPIP = true;
|
2022-08-06 16:07:29 +02:00
|
|
|
ensureDatabases = [ dbname ];
|
|
|
|
ensureUsers = [{
|
|
|
|
name = dbuser;
|
|
|
|
ensurePermissions."DATABASE ${dbname}" = "ALL PRIVILEGES";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
2022-08-06 17:00:45 +02:00
|
|
|
services.redis.servers.immich = {
|
|
|
|
enable = true;
|
|
|
|
port = 31640;
|
|
|
|
};
|
2022-08-06 16:07:29 +02:00
|
|
|
|
2022-08-06 17:00:45 +02:00
|
|
|
systemd.services.immich-init = {
|
2022-08-06 16:07:29 +02:00
|
|
|
enable = true;
|
2022-08-06 17:00:45 +02:00
|
|
|
description = "Set up paths & database access";
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
2022-08-06 16:07:29 +02:00
|
|
|
before = [
|
|
|
|
"${ociBackend}-immich-server.service"
|
|
|
|
"${ociBackend}-immich-microservices.service"
|
|
|
|
"${ociBackend}-immich-machine-learning.service"
|
|
|
|
"${ociBackend}-immich-web.service"
|
2023-04-11 19:30:32 +02:00
|
|
|
"${ociBackend}-typesense.service"
|
2022-08-06 16:07:29 +02:00
|
|
|
];
|
2022-08-06 17:00:45 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
LoadCredential = [ "db_password:${dbPasswordFile}" ];
|
|
|
|
};
|
|
|
|
script = ''
|
2023-04-11 19:30:32 +02:00
|
|
|
mkdir -p ${dataDir} ${uploadDir} ${typesenseDataDir}
|
2022-08-06 17:00:45 +02:00
|
|
|
echo "Set immich postgres user password"
|
|
|
|
db_password="$(<"$CREDENTIALS_DIRECTORY/db_password")"
|
|
|
|
${pkgs.sudo}/bin/sudo -u ${pgSuperUser} ${pkgs.postgresql}/bin/psql postgres \
|
|
|
|
-c "alter user ${dbuser} with password '$db_password'"
|
|
|
|
'';
|
2022-08-06 16:07:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation.oci-containers.containers = {
|
2022-08-07 12:17:29 +02:00
|
|
|
immich-server = immichBase // {
|
2023-04-11 19:30:32 +02:00
|
|
|
image = "ghcr.io/immich-app/immich-server:release";
|
2022-08-06 17:00:45 +02:00
|
|
|
ports = [ "3001:3001" ];
|
2022-08-06 16:07:29 +02:00
|
|
|
entrypoint = "/bin/sh";
|
|
|
|
cmd = [ "./start-server.sh" ];
|
|
|
|
volumes = [ "${uploadDir}:/usr/src/app/upload" ];
|
2023-04-11 19:30:32 +02:00
|
|
|
dependsOn = [ "typesense" ];
|
2022-08-06 16:07:29 +02:00
|
|
|
};
|
|
|
|
|
2022-08-07 12:17:29 +02:00
|
|
|
immich-microservices = immichBase // {
|
2023-04-11 19:30:32 +02:00
|
|
|
image = "ghcr.io/immich-app/immich-server:release";
|
2022-08-06 16:07:29 +02:00
|
|
|
entrypoint = "/bin/sh";
|
|
|
|
cmd = [ "./start-microservices.sh" ];
|
|
|
|
volumes = [ "${uploadDir}:/usr/src/app/upload" ];
|
2023-04-11 19:30:32 +02:00
|
|
|
dependsOn = [ "typesense" ];
|
2022-08-06 16:07:29 +02:00
|
|
|
};
|
|
|
|
|
2023-04-11 19:30:32 +02:00
|
|
|
immich-machine-learning = immichBase // {
|
|
|
|
image = "ghcr.io/immich-app/immich-machine-learning:release";
|
|
|
|
volumes = [ "${uploadDir}:/usr/src/app/upload" ];
|
|
|
|
};
|
2022-08-06 16:07:29 +02:00
|
|
|
|
2022-08-07 12:17:29 +02:00
|
|
|
immich-web = immichBase // {
|
2023-04-11 19:30:32 +02:00
|
|
|
image = "ghcr.io/immich-app/immich-web:release";
|
2022-08-06 17:00:45 +02:00
|
|
|
ports = [ "3000:3000" ];
|
2022-08-06 16:07:29 +02:00
|
|
|
entrypoint = "/bin/sh";
|
|
|
|
cmd = [ "./entrypoint.sh" ];
|
|
|
|
};
|
2023-04-11 19:30:32 +02:00
|
|
|
|
|
|
|
typesense = {
|
2023-09-28 21:01:30 +02:00
|
|
|
image = "docker.io/typesense/typesense:0.24.0";
|
2023-04-11 19:30:32 +02:00
|
|
|
environment.TYPESENSE_DATA_DIR = "/data";
|
|
|
|
environmentFiles = [ config.age.secrets.immich-typesense-env.path ];
|
|
|
|
volumes = [ "${typesenseDataDir}:/data" ];
|
|
|
|
extraOptions = [ "--network=host" ];
|
|
|
|
};
|
2022-08-06 16:07:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services = {
|
|
|
|
"${ociBackend}-immich-server" = {
|
|
|
|
requires = [ "postgresql.service" "redis-immich.service" ];
|
|
|
|
after = [ "postgresql.service" "redis-immich.service" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
"${ociBackend}-immich-microservices" = {
|
|
|
|
requires = [ "postgresql.service" "redis-immich.service" ];
|
|
|
|
after = [ "postgresql.service" "redis-immich.service" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
"${ociBackend}-immich-machine-learning" = {
|
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts.${domain} = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/api" = {
|
|
|
|
proxyPass = "http://localhost:3001";
|
|
|
|
extraConfig = ''
|
|
|
|
rewrite /api/(.*) /$1 break;
|
|
|
|
client_max_body_size 50000M;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://localhost:3000";
|
|
|
|
extraConfig = ''
|
|
|
|
client_max_body_size 50000M;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|