nixos/immich: add enableVectors option

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>

Changed files
+99 -15
nixos
doc
manual
release-notes
modules
services
web-apps
tests
pkgs
by-name
im
immich
+1 -1
nixos/doc/manual/release-notes/rl-2511.section.md
···
- `services.ntpd-rs` now performs configuration validation.
-
- Immich now has support for [VectorChord](https://github.com/tensorchord/VectorChord) when using the PostgreSQL configuration provided by `services.immich.database.enable`, which replaces `pgvecto-rs`. VectorChord support can be toggled with the option `services.immich.database.enableVectorChord`.
+
- Immich now has support for [VectorChord](https://github.com/tensorchord/VectorChord) when using the PostgreSQL configuration provided by `services.immich.database.enable`, which replaces `pgvecto-rs`. VectorChord support can be toggled with the option `services.immich.database.enableVectorChord`. Additionally, `pgvecto-rs` support is now disabled from NixOS 25.11 onwards using the option `services.immich.database.enableVectors`. This option will be removed fully in the future once Immich drops support for `pgvecto-rs` fully.
- `services.postsrsd` now automatically integrates with the local Postfix instance, when enabled. This behavior can disabled using the [services.postsrsd.configurePostfix](#opt-services.postsrsd.configurePostfix) option.
+25 -10
nixos/modules/services/web-apps/immich.nix
···
// {
default = true;
};
+
enableVectors =
+
mkEnableOption "pgvecto.rs in the database. You may disable this, if you have migrated to VectorChord and deleted the `vectors` schema."
+
// {
+
default = lib.versionOlder config.system.stateVersion "25.11";
+
defaultText = lib.literalExpression "lib.versionOlder config.system.stateVersion \"25.11\"";
+
};
createDB = mkEnableOption "the automatic creation of the database for immich." // {
default = true;
};
···
}
{
# When removing this assertion, please adjust the nixosTests accordingly.
-
assertion = cfg.database.enable -> lib.versionOlder config.services.postgresql.package.version "17";
-
message = "Immich doesn't support PostgreSQL 17+, yet.";
+
assertion =
+
(cfg.database.enable && cfg.database.enableVectors)
+
-> lib.versionOlder config.services.postgresql.package.version "17";
+
message = "Immich doesn't support PostgreSQL 17+ when using pgvecto.rs. Consider disabling it using services.immich.database.enableVectors if it is not needed anymore.";
+
}
+
{
+
assertion = cfg.database.enable -> (cfg.database.enableVectorChord || cfg.database.enableVectors);
+
message = "At least one of services.immich.database.enableVectorChord and services.immich.database.enableVectors has to be enabled.";
}
];
···
];
extensions =
ps:
-
[ ps.pgvecto-rs ]
+
lib.optionals cfg.database.enableVectors [ ps.pgvecto-rs ]
++ lib.optionals cfg.database.enableVectorChord [
-
ps.vectors
+
ps.pgvector
ps.vectorchord
];
settings = {
-
shared_preload_libraries = [
-
"vectors.so"
-
]
-
++ lib.optionals cfg.database.enableVectorChord [ "vchord.so" ];
+
shared_preload_libraries =
+
lib.optionals cfg.database.enableVectors [
+
"vectors.so"
+
]
+
++ lib.optionals cfg.database.enableVectorChord [ "vchord.so" ];
search_path = "\"$user\", public, vectors";
};
};
···
extensions = [
"unaccent"
"uuid-ossp"
-
"vectors"
"cube"
"earthdistance"
"pg_trgm"
]
+
++ lib.optionals cfg.database.enableVectors [
+
"vectors"
+
]
++ lib.optionals cfg.database.enableVectorChord [
"vector"
"vchord"
···
${lib.concatMapStringsSep "\n" (ext: "CREATE EXTENSION IF NOT EXISTS \"${ext}\";") extensions}
ALTER SCHEMA public OWNER TO ${cfg.database.user};
-
ALTER SCHEMA vectors OWNER TO ${cfg.database.user};
+
${lib.optionalString cfg.database.enableVectors "ALTER SCHEMA vectors OWNER TO ${cfg.database.user};"}
GRANT SELECT ON TABLE pg_vector_index_stat TO ${cfg.database.user};
${lib.concatMapStringsSep "\n" (ext: "ALTER EXTENSION \"${ext}\" UPDATE;") extensions}
+1
nixos/tests/all-tests.nix
···
ifm = runTest ./ifm.nix;
iftop = runTest ./iftop.nix;
immich = runTest ./web-apps/immich.nix;
+
immich-vectorchord-migration = runTest ./web-apps/immich-vectorchord-migration.nix;
immich-public-proxy = runTest ./web-apps/immich-public-proxy.nix;
incron = runTest ./incron.nix;
incus = pkgs.recurseIntoAttrs (
+71
nixos/tests/web-apps/immich-vectorchord-migration.nix
···
+
{ ... }:
+
{
+
name = "immich-vectorchord-migration";
+
+
nodes.machine =
+
{ lib, pkgs, ... }:
+
{
+
# These tests need a little more juice
+
virtualisation = {
+
cores = 2;
+
memorySize = 2048;
+
diskSize = 4096;
+
};
+
+
environment.systemPackages = with pkgs; [ immich-cli ];
+
+
services.immich = {
+
enable = true;
+
environment.IMMICH_LOG_LEVEL = "verbose";
+
# Simulate an existing setup
+
database.enableVectorChord = lib.mkDefault false;
+
database.enableVectors = lib.mkDefault true;
+
};
+
+
# TODO: Remove when PostgreSQL 17 is supported.
+
services.postgresql.package = pkgs.postgresql_16;
+
+
specialisation."immich-vectorchord-enabled".configuration = {
+
services.immich.database.enableVectorChord = true;
+
};
+
+
specialisation."immich-vectorchord-only".configuration = {
+
services.immich.database = {
+
enableVectorChord = true;
+
enableVectors = false;
+
};
+
};
+
};
+
+
testScript =
+
{ nodes, ... }:
+
let
+
specBase = "${nodes.machine.system.build.toplevel}/specialisation";
+
vectorchordEnabled = "${specBase}/immich-vectorchord-enabled";
+
vectorchordOnly = "${specBase}/immich-vectorchord-only";
+
in
+
''
+
def psql(command: str):
+
machine.succeed(f"sudo -u postgres psql -d ${nodes.machine.services.immich.database.name} -c '{command}'")
+
+
def immich_works():
+
machine.wait_for_unit("immich-server.service")
+
+
machine.wait_for_open_port(2283) # Server
+
machine.wait_for_open_port(3003) # Machine learning
+
machine.succeed("curl --fail http://localhost:2283/")
+
+
immich_works()
+
+
machine.succeed("${vectorchordEnabled}/bin/switch-to-configuration test")
+
+
immich_works()
+
+
psql("DROP EXTENSION vectors;")
+
psql("DROP SCHEMA vectors;")
+
+
machine.succeed("${vectorchordOnly}/bin/switch-to-configuration test")
+
+
immich_works()
+
'';
+
}
-3
nixos/tests/web-apps/immich.nix
···
enable = true;
environment.IMMICH_LOG_LEVEL = "verbose";
};
-
-
# TODO: Remove when PostgreSQL 17 is supported.
-
services.postgresql.package = pkgs.postgresql_16;
};
testScript = ''
+1 -1
pkgs/by-name/im/immich/package.nix
···
passthru = {
tests = {
-
inherit (nixosTests) immich;
+
inherit (nixosTests) immich immich-vectorchord-migration;
};
machine-learning = immich-machine-learning;