Jump to content

Immich: Difference between revisions

From NixOS Wiki
Onny (talk | contribs)
Inital page
 
Arnecc (talk | contribs)
added fixes for 25.05 upgrade issue
 
(17 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[https://immich.app Immich] is an open-source software, designed to provide a self-hosted alternative for managing and backing up photos and videos, with a focus on privacy and ease of use.
[https://immich.app Immich] is a self-hosted photo and video management solution.


== Setup ==
== Installation ==
To install Immich, add the following to your NixOS configuration:
{{file|/etc/nixos/configuration.nix|nix|3=services.immich.enable = true;
services.immich.port = 2283;}}
More options are available: {{nixos:option|services.immich.}}


{{Note|The module is not yet part of the latest NixOS stable release and will be available with version 24.11.}}
== Tips and Tricks ==


The following example configuration will enable Immich locally
=== Enabling Hardware Accelerated Video Transcoding ===
Add the Immich user to the <code>render</code> and <code>video</code> groups, override the <code>PrivateDevices</code> service config setting to allow the service to access <code>/dev/dri/</code> and enable [[Accelerated Video Playback]] on your system:{{file|/etc/nixos/configuration.nix|nix|3=# `null` will give access to all devices.
# You may want to restrict this by using something like `[ "/dev/dri/renderD128" ]`
services.immich.accelerationDevices = null;


{{file|/etc/nixos/configuration.nix|nix|3=environment.etc."immich-typsense-api-key".text = "12318551487654187654";
hardware.graphics = {
services.immich = {
# ...
  enable = true;
# See: https://wiki.nixos.org/wiki/Accelerated_Video_Playback
  server.typesense.apiKeyFile = "/etc/immich-typsense-api-key";
};
};


services.typesense = {
users.users.immich.extraGroups = [ "video" "render" ]; }}
   enable = true;
 
   # In a real setup you should generate an api key for immich
=== Using Immich behind Nginx ===
   # and not use the admin key!
 
  apiKeyFile = "/etc/immich-typsense-api-key";
This is a typical [[Nginx]] configuration for Immich:
   settings.server.api-address = "127.0.0.1";
{{file|/etc/nixos/configuration.nix|nix|3=services.nginx.virtualHosts."immich.example.com" = {
   enableACME = true;
   forceSSL = true;
   locations."/" = {
    proxyPass = "http://[::1]:${toString config.services.immich.port}";
    proxyWebsockets = true;
    recommendedProxySettings = true;
    extraConfig = ''
      client_max_body_size 50000M;
      proxy_read_timeout  600s;
      proxy_send_timeout  600s;
      send_timeout        600s;
    '';
   };
};
};
}}
== Troubleshooting ==


services.postgresql = {
=== Fixing postgresql database issue after 25.05 upgrade ===
   enable = true;
 
   identMap = ''
==== Postgresql collation version mismatch ====
    # ArbitraryMapName systemUser DBUser
After upgrading you might run into an issue like this, leading to immich-server continuously failing and restarting: <syntaxhighlight>Jul 01 14:23:12 server2 immich[178592]: Postgres notice: {
    superuser_map      root      postgres
Jul 01 14:23:12 server2 immich[178592]:   severity_local: 'WARNING',
    superuser_map      postgres  postgres
Jul 01 14:23:12 server2 immich[178592]:   severity: 'WARNING',
    # Let other names login as themselves
Jul 01 14:23:12 server2 immich[178592]:   code: '01000',
    superuser_map      /^(.*)$   \1
Jul 01 14:23:12 server2 immich[178592]:   message: 'database "immich" has a collation version mismatch',
   '';
Jul 01 14:23:12 server2 immich[178592]:   detail: 'The database was created using collation version 2.39, but the operating system provides version 2.40.',
   authentication = pkgs.lib.mkOverride 10 ''
Jul 01 14:23:12 server2 immich[178592]:  hint: 'Rebuild all objects in this database that use the default collation and run ALTER DATABASE immich REFRESH COLLATION VERSION,>
    local sameuser all peer map=superuser_map
Jul 01 14:23:12 server2 immich[178592]:   file: 'postinit.c',
   '';
Jul 01 14:23:12 server2 immich[178592]:   line: '477',
   ensureDatabases = [ "immich" ];
Jul 01 14:23:12 server2 immich[178592]:  routine: 'CheckMyDatabase'
  ensureUsers = [
Jul 01 14:23:12 server2 immich[178592]: }</syntaxhighlight>To fix this, run <code>sudo -u immich psql -d immich</code> and execute these to commands:<syntaxhighlight lang="sql" line="1">
    {
ALTER DATABASE immich REFRESH COLLATION VERSION;
      name = "immich";
REINDEX DATABASE immich;
      ensurePermissions = {
</syntaxhighlight>
        "DATABASE immich" = "ALL PRIVILEGES";
 
      };
==== Upgrading pgvecto.rs ====
    }
If you still run into issues after restarting postgresql and immich-server services, some additional postgresql database changes might be necessary to [https://web.archive.org/web/20240910231531/https://docs.pgvecto.rs/admin/upgrading.html#upgrading upgrade pgvecto.rs table]:
  ];
};
}}After applying the configuration you can access the instance via http://localhost:28981 and login with username <code>admin</code> and password <code>admin</code>.


Run <code>sudo -u postgresql psql</code> and execute consecutively:<syntaxhighlight lang="sql" line="1">
CREATE EXTENSION IF NOT EXISTS unaccent;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS vectors;
CREATE EXTENSION IF NOT EXISTS cube;
CREATE EXTENSION IF NOT EXISTS earthdistance;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
ALTER EXTENSION vectors UPDATE;
SELECT pgvectors_upgrade();
</syntaxhighlight>Finally, restart postgresql and immich: <code>systemctl restart postgresql && systemctl restart immich-server</code>
[[Category:Server]]
[[Category:Server]]
[[Category:Web Applications]]
[[Category:Web Applications]]

Latest revision as of 13:15, 1 July 2025

Immich is a self-hosted photo and video management solution.

Installation

To install Immich, add the following to your NixOS configuration:

❄︎ /etc/nixos/configuration.nix
services.immich.enable = true;
services.immich.port = 2283;

More options are available: services.immich.

Tips and Tricks

Enabling Hardware Accelerated Video Transcoding

Add the Immich user to the render and video groups, override the PrivateDevices service config setting to allow the service to access /dev/dri/ and enable Accelerated Video Playback on your system:

❄︎ /etc/nixos/configuration.nix
# `null` will give access to all devices.
# You may want to restrict this by using something like `[ "/dev/dri/renderD128" ]`
services.immich.accelerationDevices = null;

hardware.graphics = { 
 # ...
 # See: https://wiki.nixos.org/wiki/Accelerated_Video_Playback
};

users.users.immich.extraGroups = [ "video" "render" ];

Using Immich behind Nginx

This is a typical Nginx configuration for Immich:

❄︎ /etc/nixos/configuration.nix
services.nginx.virtualHosts."immich.example.com" = {
  enableACME = true;
  forceSSL = true;
  locations."/" = {
    proxyPass = "http://[::1]:${toString config.services.immich.port}";
    proxyWebsockets = true;
    recommendedProxySettings = true;
    extraConfig = ''
      client_max_body_size 50000M;
      proxy_read_timeout   600s;
      proxy_send_timeout   600s;
      send_timeout         600s;
    '';
  };
};

Troubleshooting

Fixing postgresql database issue after 25.05 upgrade

Postgresql collation version mismatch

After upgrading you might run into an issue like this, leading to immich-server continuously failing and restarting:

Jul 01 14:23:12 server2 immich[178592]: Postgres notice: {
Jul 01 14:23:12 server2 immich[178592]:   severity_local: 'WARNING',
Jul 01 14:23:12 server2 immich[178592]:   severity: 'WARNING',
Jul 01 14:23:12 server2 immich[178592]:   code: '01000',
Jul 01 14:23:12 server2 immich[178592]:   message: 'database "immich" has a collation version mismatch',
Jul 01 14:23:12 server2 immich[178592]:   detail: 'The database was created using collation version 2.39, but the operating system provides version 2.40.',
Jul 01 14:23:12 server2 immich[178592]:   hint: 'Rebuild all objects in this database that use the default collation and run ALTER DATABASE immich REFRESH COLLATION VERSION,>
Jul 01 14:23:12 server2 immich[178592]:   file: 'postinit.c',
Jul 01 14:23:12 server2 immich[178592]:   line: '477',
Jul 01 14:23:12 server2 immich[178592]:   routine: 'CheckMyDatabase'
Jul 01 14:23:12 server2 immich[178592]: }

To fix this, run sudo -u immich psql -d immich and execute these to commands:

ALTER DATABASE immich REFRESH COLLATION VERSION;
REINDEX DATABASE immich;

Upgrading pgvecto.rs

If you still run into issues after restarting postgresql and immich-server services, some additional postgresql database changes might be necessary to upgrade pgvecto.rs table:

Run sudo -u postgresql psql and execute consecutively:

CREATE EXTENSION IF NOT EXISTS unaccent; 
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; 
CREATE EXTENSION IF NOT EXISTS vectors; 
CREATE EXTENSION IF NOT EXISTS cube; 
CREATE EXTENSION IF NOT EXISTS earthdistance; 
CREATE EXTENSION IF NOT EXISTS pg_trgm; 
ALTER EXTENSION vectors UPDATE;
SELECT pgvectors_upgrade();

Finally, restart postgresql and immich: systemctl restart postgresql && systemctl restart immich-server