Failing to set up Immich according to the wiki

Hey y’all, I’m having an error setting up Immich on both of my computers. I’m trying to import a (as of yet) very minimal file to set up Immich on a computer I’m converting to a server:

{
  config,
  pkgs,
  ...
}: {
  services.immich = {
    enable = true;
    machine-learning = {
      enable = true;
    };
  };
}

… but I get an error saying The option 'services.immich' does not exist. Likewise, my log returned an error after running this code on my main computer:

  services.immich = {
    enable = true;
  };

Looking this up, I see long configs, and I’m assuming they either enable features I’m not looking for right now, or are from before Immich was merged into nixpkgs as a service.
The wiki has a minimal config for it (albeit with a line of code for machine learning that seems to be deprecated): https://wiki.nixos.org/wiki/Immich


TLDR; I just want to use Immich to let me and others view and upload images and videos on my home server. What do I do to get it running?

if it’s saying services.immich does not exist, you should make sure that your nixpkgs is on 24.11, as thar was the version where the service was introduced. if it’s running a version previous, then that won’t work(and is what I assume your issue is in this case)

4 Likes

This solved the error on my server, but now I’m getting the same error as on my main computer. The main thing I’m eyeballing in both cases is the following units failed bit. On both computers, postgresql.service failed. Here’s the bit in the log I posted:

× postgresql.service - PostgreSQL Server
     Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Sun 2024-12-08 00:13:18 CST; 1min 30s ago
   Duration: 4d 10h 43min 42.672s
 Invocation: 41c4c7636a584fa18199e21d3e33a560
    Process: 661952 ExecStartPre=/nix/store/8i4ryvqpr4bpyhdz76w01689ilijcsg4-unit-script-postgresql-pre-start/bin/postgresql-pre-start (code=exited, status=0/SUCCESS)
    Process: 661966 ExecStart=/nix/store/ryfs0dskyvj2lhfsl89c7iffykwv9y31-postgresql-and-plugins-15.9/bin/postgres (code=exited, status=0/SUCCESS)
    Process: 662052 ExecStartPost=/nix/store/y7v3j7ipv8bz7ddgrgjj3fqxhwbrd838-unit-script-postgresql-post-start/bin/postgresql-post-start (code=exited, status=1/FAILURE)
   Main PID: 661966 (code=exited, status=0/SUCCESS)
         IP: 0B in, 0B out
         IO: 3.8M read, 36K written
   Mem peak: 28.1M
        CPU: 171ms

If you upgraded NixOS 24.05 to 24.11 you also upgraded postgres 15 to 16, you have to manually upgrade your database, or your could stick to the postgresql_15 package.

You can look at the logs to verify this: journalctl -u postgresql.service

I downgraded PostgreSQL to 15 and rebuild still fails. (error: Failed build of NixOS with Immich, after PostgreSQL downgrade. · GitHub)
I’m completely new to SQL so I’m assuming I’m doing something wrong. I’m using this bit in my main config to make it work:

services.postgresql = {
  enable = true;
  package = pkgs.postgresql_15;
};

Before downgrading to 15, I also tried to upgrade my database using the Wiki page you linked me to. Following the instructions, I couldn’t get SQL running using sudo systemctl start postgresql.service, and I tried running the following command:

sudo -u postgres pg_upgrade -b "$(nix build --no-link --print-out-paths nixpkgs#postgresql_15.out)/bin" -B /run/current-system/sw/bin -d /var/lib/postgresql/15 -D /var/lib/postgresql/16

but got the following error:

could not read permissions of directory "/var/lib/postgresql/16": No such file or directory

After failing to start PostgreSQL 16, I looked at systemctl status postgresql.status and this was the output:

× postgresql.service - PostgreSQL Server
     Loaded: loaded (/etc/systemd/system/postgresql.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Fri 2024-12-13 15:14:39 CST; 5s ago
   Duration: 5min 951ms
 Invocation: 7b64df6a698940289ed9f287267eca68
    Process: 9820 ExecStartPre=/nix/store/hd8hxdfwgnsd5vgdq94lw84jpv3rpyv3-unit-script-postgresql-pre-start/bin/postgresql-pre-start (code=exited, status=0/SUCCESS)
    Process: 9822 ExecStart=/nix/store/j54b9h6pja78b13cfs480x75fricvpx4-postgresql-and-plugins-15.9/bin/postgres (code=exited, status=0/SUCCESS)
    Process: 9833 ExecStartPost=/nix/store/2w769zxy9abapj7mhak5amnd773j993q-unit-script-postgresql-post-start/bin/postgresql-post-start (code=exited, status=1/FAILURE)
   Main PID: 9822 (code=exited, status=0/SUCCESS)
         IP: 0B in, 0B out
         IO: 0B read, 32K written
   Mem peak: 23.7M
        CPU: 181ms

Dec 13 15:14:39 nixos systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
Dec 13 15:14:39 nixos postgres[9822]: [9822] LOG:  received fast shutdown request
Dec 13 15:14:39 nixos postgres[9822]: [9822] LOG:  aborting any active transactions
Dec 13 15:14:39 nixos postgres[9822]: [9822] LOG:  background worker "logical replication launcher" (PID 9832) exited with exit code 1
Dec 13 15:14:39 nixos postgres[9824]: [9824] LOG:  shutting down
Dec 13 15:14:39 nixos postgres[9824]: [9824] LOG:  checkpoint starting: shutdown immediate
Dec 13 15:14:39 nixos postgres[9824]: [9824] LOG:  checkpoint complete: wrote 3 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.034 s, sync=0.028 s, total=0.221 s; sync files=2, longest=0.0>
Dec 13 15:14:39 nixos postgres[9822]: [9822] LOG:  database system is shut down
Dec 13 15:14:39 nixos systemd[1]: postgresql.service: Failed with result 'exit-code'.
Dec 13 15:14:39 nixos systemd[1]: Failed to start PostgreSQL Server.

I got PostgreSQL 15 to start, however.

You have to look into the journal to get more logs.

journalctl -b -0 -u postgresql, at minimum, with -x for explanatory text if you wish.

1 Like

If you have no data yet in the database, an easy solution would be to reset it entirely:

# !! Be very careful, this will erase all your postgres databases
sudo rm -r /var/lib/postgresql
reboot

I ran the command and it’s telling me I have databases I need to upgrade: Detailed postgres journalctl · GitHub

Namely, it’s listing Atuin, which I do use. I’m using Atuin for Bash history and I haven’t been using my other computer as much up until now, so it’s small but I’d still like to keep it. But I don’t know how to upgrade the databases.

Please log into a postgres user shell(with the following: sudo -u postgres psql), then run:

ALTER DATABASE atuin REFRESH COLLATION VERSION;

then \q to quit the shell, and restart postgres.