| 
									
										
										
										
											2025-05-03 20:40:47 +01:00
										 |  |  | { config, lib, ... }: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | with lib; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  |   cfg = homelab.services.${service}; | 
					
						
							|  |  |  |   homelab = config.homelab; | 
					
						
							|  |  |  |   service = "home-assistant"; | 
					
						
							|  |  |  | in | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   options.homelab.services.${service} = { | 
					
						
							|  |  |  |     enable = mkEnableOption "Enable ${service}"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     url = mkOption { | 
					
						
							|  |  |  |       default = "home.${homelab.domain}"; | 
					
						
							|  |  |  |       type = types.str; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     homepage.name = mkOption { | 
					
						
							|  |  |  |       default = "Home Assisant"; | 
					
						
							|  |  |  |       type = types.str; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     homepage.description = mkOption { | 
					
						
							|  |  |  |       default = "Open source home automation that puts local control and privacy first."; | 
					
						
							|  |  |  |       type = types.str; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     homepage.icon = mkOption { | 
					
						
							|  |  |  |       default = "home-assistant"; | 
					
						
							|  |  |  |       type = types.str; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     homepage.category = mkOption { | 
					
						
							|  |  |  |       default = "Services"; | 
					
						
							|  |  |  |       type = types.str; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf cfg.enable { | 
					
						
							|  |  |  |     services = { | 
					
						
							|  |  |  |       home-assistant = { | 
					
						
							|  |  |  |         enable = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         config = { | 
					
						
							|  |  |  |           external_url = "https://home.${homelab.domain}"; | 
					
						
							|  |  |  |           name = "Home"; | 
					
						
							|  |  |  |           time_zone = "Europe/London"; | 
					
						
							|  |  |  |           unit_system = "metric"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           http = { | 
					
						
							|  |  |  |             trusted_proxies = [ | 
					
						
							|  |  |  |               "127.0.0.1" | 
					
						
							|  |  |  |               "::1" | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |             use_x_forwarded_for = true; | 
					
						
							|  |  |  |           }; | 
					
						
							| 
									
										
										
										
											2025-05-04 01:06:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |           mobile_app = { }; | 
					
						
							|  |  |  |           # sia = { }; | 
					
						
							| 
									
										
										
										
											2025-05-03 20:40:47 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         extraComponents = [ | 
					
						
							|  |  |  |           "default_config" | 
					
						
							|  |  |  |           "elgato" | 
					
						
							|  |  |  |           "hive" | 
					
						
							|  |  |  |           "met" | 
					
						
							|  |  |  |           "mobile_app" | 
					
						
							| 
									
										
										
										
											2025-05-04 01:06:50 +01:00
										 |  |  |           # "sia" | 
					
						
							| 
									
										
										
										
											2025-05-05 20:15:05 +01:00
										 |  |  |           "tplink" | 
					
						
							|  |  |  |           "tplink_tapo" | 
					
						
							| 
									
										
										
										
											2025-05-03 20:40:47 +01:00
										 |  |  |           "weather" | 
					
						
							|  |  |  |           "webostv" | 
					
						
							| 
									
										
										
										
											2025-05-04 21:57:28 +01:00
										 |  |  |           "wiz" | 
					
						
							| 
									
										
										
										
											2025-05-03 20:40:47 +01:00
										 |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-04 01:06:50 +01:00
										 |  |  |         extraPackages = | 
					
						
							|  |  |  |           python3Packages: with python3Packages; [ | 
					
						
							|  |  |  |             setuptools | 
					
						
							|  |  |  |           ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-03 20:40:47 +01:00
										 |  |  |         openFirewall = true; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       nginx.virtualHosts."${cfg.url}" = { | 
					
						
							|  |  |  |         forceSSL = true; | 
					
						
							|  |  |  |         useACMEHost = homelab.domain; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         locations."/" = { | 
					
						
							|  |  |  |           proxyPass = "http://localhost:${toString config.services.${service}.config.http.server_port}"; | 
					
						
							|  |  |  |           proxyWebsockets = true; | 
					
						
							|  |  |  |           recommendedProxySettings = true; | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |