summaryrefslogtreecommitdiffstats
path: root/hosts/poweredge/immich.nix
blob: ff0275c4f1975707de9a60edfd6356593efc556e (plain)
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
{ pkgs, ... }: let
	onnxruntimeCuda = pkgs.onnxruntime.override { cudaSupport = true; };
in {
	containers.immich = {
		autoStart = true;
		privateNetwork = true;
		hostBridge = "br-lan0";
		localMacAddress = "02:00:00:00:00:01";

		# Host path
		bindMounts = {
			"/var/lib/immich" = {
				hostPath = "/media/ingens/immich";
				isReadOnly = false;
			};
		};

		# GPU
		allowedDevices = [
			{ node = "/dev/nvidia0";           modifier = "rw"; }
			{ node = "/dev/nvidiactl";         modifier = "rw"; }
			{ node = "/dev/nvidia-uvm";        modifier = "rw"; }
			{ node = "/dev/nvidia-uvm-tools";  modifier = "rw"; }
			{ node = "/dev/nvidia-modeset";    modifier = "rw"; }
		];

		bindMounts = {
			# NVENC/NVDEC - video transcoding
			"/dev/nvidia0"           = { hostPath = "/dev/nvidia0";           isReadOnly = false; };
			"/dev/nvidiactl"         = { hostPath = "/dev/nvidiactl";         isReadOnly = false; };
			# CUDA - required for ML inference
			"/dev/nvidia-uvm"        = { hostPath = "/dev/nvidia-uvm";        isReadOnly = false; };
			"/dev/nvidia-uvm-tools"  = { hostPath = "/dev/nvidia-uvm-tools";  isReadOnly = false; };
			# Modeset - needed by some driver paths
			"/dev/nvidia-modeset"    = { hostPath = "/dev/nvidia-modeset";    isReadOnly = false; };
		};

		config = { lib, config, ... }: {
			imports = [ ./nvidia.nix ];

			# Network
			networking.interfaces.eth0.useDHCP = true;
			networking.firewall.allowedTCPPorts = [ 80 2283 ];  # Caddy + immich

			# Immich
			services.immich = {
				enable = true;
				host = "0.0.0.0";
				package = pkgs.unstable.immich;
				accelerationDevices = [
					"/dev/nvidia0"
					"/dev/nvidiactl"
					"/dev/nvidia-uvm"
					"/dev/nvidia-uvm-tools"
					"/dev/nvidia-modeset"
				];

				# Tell immich-server to use NVENC for transcoding
				environment = {
					NVIDIA_VISIBLE_DEVICES = "all";
					NVIDIA_DRIVER_CAPABILITIES = "compute,video,utility";
				};

				# Enable the ML microservice with CUDA
				# FIXME Disabled since the ML service w/ CUDA uses almost all the vram on my gpu
				machine-learning.enable = false;
			};
			environment.systemPackages = with pkgs.unstable; [ immich immich-cli ];

			# TODO IPP is missing a lot of features right now. Check back later
			## Immich public proxy
			#services.immich-public-proxy = {
			#	enable = true;
			#	immichUrl = "http://localhost:2283";
			#	package = pkgs.unstable.immich-public-proxy;
			#};

			# Reverse proxy
			services.caddy = {
				enable = true;
				virtualHosts.":80".extraConfig = ''
					reverse_proxy localhost:2283
				'';
			};

			system.stateVersion = "25.11";
		};
	};
}