Problems setting up the new Immich module

I’m trying to set up the new Immich module but so far my config doesn’t work.

{
  containers.immich = {
    autoStart = true;
    bindMounts = {
      "/var/lib/immich" = {
        hostPath = "/mnt/sdb1/photos";
        isReadOnly = false;
      };
    };

    config =
      { pkgs, ... }:
      {
        services = {
          immich = {
            enable = true;
            host = "immich.***.ts.net";
          };

          tailscale = {
            enable = true;
            useRoutingFeatures = "server";
            interfaceName = "userspace-networking";
          };
        };

        system.stateVersion = "24.05";
      };
  };
}

As you can see, I have it in a container and I use Tailscale.

I ran tailscale serve --bg 3001. I was wondering why this module uses port 3001 instead of 2283 like the official implementation?

I also ran journalctl -xeu postgresql:

Oct 11 16:32:43 immich systemd[1]: Starting PostgreSQL Server...
░░ Subject: A start job for unit postgresql.service has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit postgresql.service has begun execution.
░░
░░ The job identifier is 93.
Oct 11 16:32:43 immich postgres[260]: [260] LOG:  starting PostgreSQL 15.8 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 13.3.0, 64-bit
Oct 11 16:32:43 immich postgres[260]: [260] LOG:  could not bind IPv6 address "::1": Address already in use
Oct 11 16:32:43 immich postgres[260]: [260] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
Oct 11 16:32:43 immich postgres[260]: [260] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
Oct 11 16:32:43 immich postgres[260]: [260] HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
Oct 11 16:32:43 immich postgres[260]: [260] WARNING:  could not create listen socket for "localhost"
Oct 11 16:32:43 immich postgres[260]: [260] FATAL:  could not create any TCP/IP sockets
Oct 11 16:32:43 immich postgres[260]: [260] LOG:  database system is shut down
Oct 11 16:32:43 immich systemd[1]: postgresql.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ An ExecStart= process belonging to unit postgresql.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 1.
Oct 11 16:32:43 immich systemd[1]: postgresql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit postgresql.service has entered the 'failed' state with result 'exit-code'.
Oct 11 16:32:43 immich systemd[1]: Failed to start PostgreSQL Server.
░░ Subject: A start job for unit postgresql.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit postgresql.service has finished with a failure.
░░
░░ The job identifier is 93 and the job result is failed.

Aren’t my containers separated from each other? What do I need to do to fix this?

You might need to set privateNetwork to true

If this option is not set, then the container shares the network interfaces of the host, and can bind to any port on any interface.

How do I gain access to the internet afterwards?

Another solution: change services.postgresql.settings.port on the container. It isn’t open on the firewall by default and immich connects by unix socket by default so it shouldn’t break

You probably need NAT for that, see Container networking.

This didn’t work:

Oct 12 16:30:22 immich postgres[281]: [138B blob data]
Oct 12 16:30:22 immich postgres[281]: [1B blob data]
Oct 12 16:30:22 immich postgres[281]: [2B blob data]
Oct 12 16:30:22 immich postgres[281]: [138B blob data]
Oct 12 16:30:22 immich postgres[253]: [253] LOG:  database system is ready to accept connections
Oct 12 16:30:22 immich postgresql-post-start[313]: ALTER ROLE
Oct 12 16:30:22 immich postgresql-post-start[315]: ALTER DATABASE
Oct 12 16:30:22 immich psql[318]: psql: error: connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Oct 12 16:30:22 immich psql[318]:         Is the server running locally and accepting connections on that socket?
Oct 12 16:30:22 immich systemd[1]: postgresql.service: Control process exited, code=exited, status=2/INVALIDARGUMENT
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ An ExecStartPost= process belonging to unit postgresql.service has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 2.
Oct 12 16:30:22 immich postgres[253]: [253] LOG:  received fast shutdown request
Oct 12 16:30:22 immich postgres[253]: [253] LOG:  aborting any active transactions
Oct 12 16:30:22 immich postgres[253]: [253] LOG:  background worker "logical replication launcher" (PID 296) exited with exit code 1
Oct 12 16:30:22 immich postgres[278]: [278] LOG:  shutting down
Oct 12 16:30:22 immich postgres[278]: [278] LOG:  checkpoint starting: shutdown immediate
Oct 12 16:30:22 immich postgres[278]: [278] LOG:  checkpoint complete: wrote 4 buffers (0.0%); 0 WAL file(s) added, 0 removed, 0 recycled; writ>
Oct 12 16:30:22 immich postgres[253]: [253] LOG:  database system is shut down
Oct 12 16:30:22 immich systemd[1]: postgresql.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ The unit postgresql.service has entered the 'failed' state with result 'exit-code'.
Oct 12 16:30:22 immich systemd[1]: Failed to start PostgreSQL Server.
░░ Subject: A start job for unit postgresql.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit postgresql.service has finished with a failure.
░░
░░ The job identifier is 92 and the job result is failed.

Hmm, maybe change the db port in immich settings too

Did that. Also 5432 is the default port and I changed both settings to 5435.