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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
{
lib,
...
}:
let
apiKeyFile = "/tmp/immich-api.key";
customInterval = 5;
user = "alice";
in
{
name = "immichframe";
meta.maintainers = with lib.maintainers; [
numinit
jfly
];
enableOCR = true;
nodes.machine =
{
config,
pkgs,
lib,
...
}:
{
imports = [
../common/user-account.nix
../common/x11.nix
];
# When setting memory to 2500 I got "Kernel panic - not syncing: Out of
# memory: compulsory panic_on_oom is enabled".
# Setting cores to 1 (the default) also makes immich take a long time to start up.
# If this breaks, keep synced with the immich test.
virtualisation = {
memorySize = 4096;
cores = 2;
};
hardware.graphics.enable = true;
environment.variables.XAUTHORITY = "/home/${user}/.Xauthority";
test-support.displayManager.auto.user = user;
environment.systemPackages = with pkgs; [
imagemagick
immich-cli
firefox
xdotool
];
fonts.packages = [ pkgs.liberation_ttf ];
services.immich = {
enable = true;
port = 2283;
openFirewall = true;
# Disable a bunch of features that aren't needed for this test.
machine-learning.enable = false;
settings = {
backup.database.enabled = false;
machineLearning.enabled = false;
map.enabled = false;
reverseGeocoding.enabled = false;
metadata.faces.import = false;
newVersionCheck.enabled = false;
notifications.smtp.enabled = false;
};
};
services.immichframe = {
enable = true;
port = 8002;
settings = {
General.Interval = customInterval;
Accounts = [
{
ImmichServerUrl = "http://localhost:${toString config.services.immich.port}";
ApiKeyFile = apiKeyFile;
}
];
};
};
};
testScript = /* python */ ''
import json
import tempfile
from shlex import quote
custom_interval = ${toString customInterval}
machine.wait_for_x()
machine.wait_for_unit("immich-server.service")
machine.wait_for_open_port(2283)
# Log in to Immich and create an access key.
machine.succeed("""
curl --no-progress-meter -f --json '{ "email": "test@example.com", "name": "Admin", "password": "admin" }' http://localhost:2283/api/auth/admin-sign-up
""")
res = machine.succeed("""
curl --no-progress-meter -f --json '{ "email": "test@example.com", "password": "admin" }' http://localhost:2283/api/auth/login
""")
token = json.loads(res)['accessToken']
res = machine.succeed("""
curl --no-progress-meter -f -H 'Cookie: immich_access_token=%s' --json '{ "name": "API Key", "permissions": ["all"] }' http://localhost:2283/api/api-keys
""" % token)
key = json.loads(res)['secret']
machine.succeed(f"immich login http://localhost:2283/api {key}")
res = machine.succeed("immich server-info")
print(res)
# Create the API key so ImmichFrame can start.
with tempfile.NamedTemporaryFile("w", delete_on_close=False) as f:
f.write(key)
f.close()
machine.copy_from_host(f.name, ${builtins.toJSON apiKeyFile})
# We finally have an api key! Make sure ImmichFrame starts up.
machine.wait_for_unit("immichframe.service")
machine.wait_for_open_port(8002)
# Check ImmichFrame's configuration.
res = machine.succeed("curl --no-progress-meter -f http://localhost:8002/api/Config")
frame_config = json.loads(res)
assert frame_config['interval'] == custom_interval, frame_config
# At this point, ImmichFrame should not find any images to serve.
res = machine.succeed("curl -f http://localhost:8002/api/Asset")
assets = json.loads(res)
assert len(assets) == 0, assets
# Repeat to make it easier for OCR to pick up given overlays
image_text = '\\n'.join(['reproduce this moment', 'with NixOS tests <3'] * 6)
# These settings make it display fine given potential cropping.
common_args = f"-gravity center -font Liberation-Mono -pointsize 50 -annotate 0 {quote(image_text)}"
# Upload some images to a new album.
album_title = '✨ Reproducible Moments ✨'
machine.succeed(f"magick -size 1920x1080 canvas:white -fill black {common_args} /tmp/white.png")
machine.succeed(f"immich upload -A {quote(album_title)} /tmp/white.png")
machine.succeed(f"magick -size 1920x1080 canvas:black -fill white {common_args} /tmp/black.png")
machine.succeed(f"immich upload -A {quote(album_title)} /tmp/black.png")
res = machine.succeed("immich server-info")
print(res)
# ImmichFrame should now find some assets.
# Note: we restart ImmichFrame because it has some caching that prevents it
# from immediately seeing the newly uploaded photos.
machine.succeed("systemctl restart immichframe.service")
machine.wait_for_open_port(8002)
res = machine.succeed("curl --no-progress-meter -f http://localhost:8002/api/Asset")
assets = json.loads(res)
assert len(assets) == 2, assets
# Wait for a photo to be displayed.
machine.execute("su - ${user} -c 'firefox --kiosk http://localhost:8002' >&2 & disown")
machine.wait_for_text('reproduce this moment')
machine.wait_for_text('with NixOS tests')
machine.screenshot("screen")
'';
}
|