From 56149c0fed834e567e1be767e58d4331e268fd0b Mon Sep 17 00:00:00 2001 From: Diogo Correia Date: Thu, 30 Jul 2026 11:12:16 +0100 Subject: [PATCH 1/2] nixos/immich: do not create postgresql-setup if not using local db The Immich module is unconditionally creating the postgresql-setup unit, even if it never runs. This commit adds a guard that prevents the unit from being created if the module is not managing a local db. --- nixos/modules/services/web-apps/immich.nix | 70 +++++++++++----------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/nixos/modules/services/web-apps/immich.nix b/nixos/modules/services/web-apps/immich.nix index 57d6c3eb8b64..4334bcf760d4 100644 --- a/nixos/modules/services/web-apps/immich.nix +++ b/nixos/modules/services/web-apps/immich.nix @@ -325,41 +325,43 @@ in search_path = "\"$user\", public, vectors"; }; }; - systemd.services.postgresql-setup.serviceConfig.ExecStartPost = - let - extensions = [ - "unaccent" - "uuid-ossp" - "cube" - "earthdistance" - "pg_trgm" - "vector" - "vchord" + systemd.services.postgresql-setup = mkIf cfg.database.enable { + serviceConfig.ExecStartPost = + let + extensions = [ + "unaccent" + "uuid-ossp" + "cube" + "earthdistance" + "pg_trgm" + "vector" + "vchord" + ]; + sqlFile = pkgs.writeText "immich-pgvectors-setup.sql" '' + -- save previous version of vectorchord to trigger reindex on update + SELECT COALESCE(installed_version, ''') AS vchord_version_before FROM pg_available_extensions WHERE name = 'vchord' \gset + + ${lib.concatMapStringsSep "\n" (ext: "CREATE EXTENSION IF NOT EXISTS \"${ext}\";") extensions} + ${lib.concatMapStringsSep "\n" (ext: "ALTER EXTENSION \"${ext}\" UPDATE;") extensions} + ALTER SCHEMA public OWNER TO ${cfg.database.user}; + + -- trigger reindex if vectorchord updates + -- https://docs.immich.app/administration/postgres-standalone/#updating-vectorchord + SELECT COALESCE(installed_version, ''') AS vchord_version_after FROM pg_available_extensions WHERE name = 'vchord' \gset + + SELECT (:'vchord_version_before' != ''' AND :'vchord_version_before' != :'vchord_version_after') AS has_vchord_updated \gset + \if :has_vchord_updated + REINDEX INDEX face_index; + REINDEX INDEX clip_index; + \endif + ''; + in + [ + '' + ${lib.getExe' cfg.database.package "psql"} -d "${cfg.database.name}" -f "${sqlFile}" + '' ]; - sqlFile = pkgs.writeText "immich-pgvectors-setup.sql" '' - -- save previous version of vectorchord to trigger reindex on update - SELECT COALESCE(installed_version, ''') AS vchord_version_before FROM pg_available_extensions WHERE name = 'vchord' \gset - - ${lib.concatMapStringsSep "\n" (ext: "CREATE EXTENSION IF NOT EXISTS \"${ext}\";") extensions} - ${lib.concatMapStringsSep "\n" (ext: "ALTER EXTENSION \"${ext}\" UPDATE;") extensions} - ALTER SCHEMA public OWNER TO ${cfg.database.user}; - - -- trigger reindex if vectorchord updates - -- https://docs.immich.app/administration/postgres-standalone/#updating-vectorchord - SELECT COALESCE(installed_version, ''') AS vchord_version_after FROM pg_available_extensions WHERE name = 'vchord' \gset - - SELECT (:'vchord_version_before' != ''' AND :'vchord_version_before' != :'vchord_version_after') AS has_vchord_updated \gset - \if :has_vchord_updated - REINDEX INDEX face_index; - REINDEX INDEX clip_index; - \endif - ''; - in - [ - '' - ${lib.getExe' cfg.database.package "psql"} -d "${cfg.database.name}" -f "${sqlFile}" - '' - ]; + }; services.redis.servers = mkIf cfg.redis.enable { immich = { From f493e86f6998c38fdfdcddbec4a5a4e9f55e9826 Mon Sep 17 00:00:00 2001 From: Diogo Correia Date: Thu, 30 Jul 2026 12:01:05 +0100 Subject: [PATCH 2/2] nixos/immich: fix punctuation for services.immich.database.createDB mkEnableOption already adds a dot at the end of the description, so this resulted in double dot. --- nixos/modules/services/web-apps/immich.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/web-apps/immich.nix b/nixos/modules/services/web-apps/immich.nix index 4334bcf760d4..fc80faf73504 100644 --- a/nixos/modules/services/web-apps/immich.nix +++ b/nixos/modules/services/web-apps/immich.nix @@ -232,7 +232,7 @@ in // { default = true; }; - createDB = mkEnableOption "the automatic creation of the database for immich." // { + createDB = mkEnableOption "the automatic creation of the database for immich" // { default = true; }; name = mkOption {