1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
---
title: photos
weight: 150
---
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`](https://immich.app), 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.
{{% hint danger %}}
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.
{{% /hint %}}
## 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
```sh
$ 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
```nix
{ 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:
```nix
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
1) First of all we declare the `immich` service as enabled.
2) We define the host and port, so that the service only speaks to the outside world via a reverse proxy (via `nginx`)
3) We explcitly enable machine learning functionality, like face and object detection.
4) We set up nginx to serve a reverse proxy at `photos.<YOUR-DOMAIN>` pointing at the immich service.
5) We explicitly force the use of graphics drivers
6) Finally, we declare some information for the user that will run the `immich` service, `immich`. (we add `immich` to the `video` and `render` groups.)
{{% hint info %}}
To disable any machine-learning functionality, simply set `machine-learning.enable = false;`
{{% /hint %}}
{{% hint info %}}
More information can be found at the [wiki](https://wiki.nixos.org/wiki/immich), but it can be opaque.
More options can be found [here](https://mynixos.com/nixpkgs/options/services.immich).
{{% /hint %}}
{{% hint info %}}
If you want to declare more settings and/or environment variables for `immich`, you can declare them:
```nix
services = {
immich = {
settings = {
# ...
};
environment = {
# ...
};
};
};
```
- `services.immich.settings`, declares [settings found here](https://immich.app/docs/install/config-file/) and expects JSON syntax
You can find these settings and change them from the admin panel in your running instance of `immich`
- `services.immich.environment`, declares [envarionment variables found here](https://immich.app/docs/install/environment-variables), and expects
`ENV_VAR_NAME = ENV_VAR_VALUE;`
Only for env vars tagged `server`, `api`, or `microservices`.
{{% /hint %}}
### 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.
|