1{ ... }:
2{
3 name = "immich-nixos";
4
5 nodes.machine =
6 { pkgs, ... }:
7 {
8 # These tests need a little more juice
9 virtualisation = {
10 cores = 2;
11 memorySize = 2048;
12 diskSize = 4096;
13 };
14
15 environment.systemPackages = with pkgs; [ immich-cli ];
16
17 services.immich = {
18 enable = true;
19 environment.IMMICH_LOG_LEVEL = "verbose";
20 };
21 };
22
23 testScript = ''
24 import json
25
26 machine.wait_for_unit("immich-server.service")
27
28 machine.wait_for_open_port(2283) # Server
29 machine.wait_for_open_port(3003) # Machine learning
30 machine.succeed("curl --fail http://localhost:2283/")
31
32 machine.succeed("""
33 curl -f --json '{ "email": "test@example.com", "name": "Admin", "password": "admin" }' http://localhost:2283/api/auth/admin-sign-up
34 """)
35 res = machine.succeed("""
36 curl -f --json '{ "email": "test@example.com", "password": "admin" }' http://localhost:2283/api/auth/login
37 """)
38 token = json.loads(res)['accessToken']
39
40 res = machine.succeed("""
41 curl -f -H 'Cookie: immich_access_token=%s' --json '{ "name": "API Key", "permissions": ["all"] }' http://localhost:2283/api/api-keys
42 """ % token)
43 key = json.loads(res)['secret']
44
45 machine.succeed(f"immich login http://localhost:2283/api {key}")
46 res = machine.succeed("immich server-info")
47 print(res)
48
49 machine.succeed("""
50 curl -f -X PUT -H 'Cookie: immich_access_token=%s' --json '{ "command": "start" }' http://localhost:2283/api/jobs/backupDatabase
51 """ % token)
52 res = machine.succeed("""
53 curl -f -H 'Cookie: immich_access_token=%s' http://localhost:2283/api/jobs
54 """ % token)
55 assert sum(json.loads(res)["backupDatabase"]["jobCounts"].values()) >= 1
56 machine.wait_until_succeeds("ls /var/lib/immich/backups/*.sql.gz")
57 '';
58}