One main purpose for using cloud services is keeping photos and videos, and other such media backed up in a server that is searchable, and that allows you to create albums to share with friends.
For this purpose, in order to replace Google Photos/iCloud Photos, and to retain our ownership of said photos (both those services have restrictive ToS which gives them rights over your photos), we will use immich, which is a self-hosted free and open-source software photo and video management solution, with many features like duplicate detection and contextual search using machine learning, running locally.
As of writing this, immich is still in early/active development. There may be breaking changes between versions, so be wary and always keep a backup, like an old drive, and store a copy of your photos there, just in case.
specs #
The machine learning models run locally, which might make it more difficult to run on small or old hardware, but you can disable it.
When the machine learning stack is not running, immich takes 285M of RAM on my system.
installation #
Create a immich folder and a default.nix file inside it, at the place where you have the rest of your nixos configuration
$ mkdir immich && touch immich/default.nix(or use the file explorer of your choice)
nix declaration #
Open immich/default.nix in any text editor, and copy the following
{ config, lib, ... }:
{
services = {
# Immich setup
immich = {
enable = true;
host = "127.0.0.1";
port = 3010;
machine-learning.enable = true;
};
nginx = {
virtualHosts."photos.<YOUR-DOMAIN>" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://127.0.0.1:3010";
proxyWebsockets = true;
};
};
};
};
hardware.graphics.enable = lib.mkForce true;
users.users.immich = {
extraGroups = [ "video" "render" ];
};
}Then to enable it, just include it in the server config file:
imports = [
# ... other services
./immich
# ... other services
];and you’re done. Download the app for your phone, and connect through https://photos.<YOUR-DOMAIN>
Let’s break the config file down.
explanation #
- First of all we declare the
immichservice as enabled. - We define the host and port, so that the service only speaks to the outside world via a reverse proxy (via
nginx) - We explcitly enable machine learning functionality, like face and object detection.
- We set up nginx to serve a reverse proxy at
photos.<YOUR-DOMAIN>pointing at the immich service. - We explicitly force the use of graphics drivers
- Finally, we declare some information for the user that will run the
immichservice,immich. (we addimmichto thevideoandrendergroups.)
To disable any machine-learning functionality, simply set
machine-learning.enable = false;
More information can be found at the wiki, but it can be opaque.
More options can be found here.
If you want to declare more settings and/or environment variables for
immich, you can declare them:services = { immich = { settings = { # ... }; environment = { # ... }; }; };
services.immich.settings, declares settings found here and expects JSON syntax You can find these settings and change them from the admin panel in your running instance ofimmich
services.immich.environment, declares envarionment variables found here, and expects
ENV_VAR_NAME = ENV_VAR_VALUE;
Only for env vars taggedserver,api, ormicroservices.
further setup #
Once the service is up and running, go to localhost:3010, or photos.<YOUR-DOMAIN>, or whatever domain you set it to.
You must set up an administrator account. This can either be a completely seperate account to your own, or it could be your own account.
service backups #
By default, all media will be stored somewhere in /var/lib/immich. Automatic database backups are being kept inside /var/lib/immich/backups as ###.sql.gz files, so you can store these alongside your media.
If you want you can simply make a copy of the entire /var/lib/immich folder at regular intervals.