| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  | # The Free Software Media System | 
					
						
							| 
									
										
										
										
											2024-07-28 21:08:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |   config, | 
					
						
							|  |  |  |   lib, | 
					
						
							|  |  |  |   pkgs, | 
					
						
							|  |  |  |   ... | 
					
						
							|  |  |  | }: | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  | let | 
					
						
							|  |  |  |   cfg = config.my.services.jellyfin; | 
					
						
							| 
									
										
										
										
											2023-11-07 23:13:51 +01:00
										 |  |  |   inherit (config.networking) domain; | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  |   port = 8096; | 
					
						
							| 
									
										
										
										
											2023-06-03 22:42:21 +02:00
										 |  |  |   # enable monitoring | 
					
						
							|  |  |  |   jellyfin-with-metrics = pkgs.jellyfin.overrideAttrs (attrs: { | 
					
						
							| 
									
										
										
										
											2024-06-10 22:48:19 +02:00
										 |  |  |     patches = | 
					
						
							|  |  |  |       let | 
					
						
							| 
									
										
										
										
											2024-07-28 21:08:02 +02:00
										 |  |  |         existingPatches = if attrs ? patches && builtins.isList attrs.patches then attrs.patches else [ ]; | 
					
						
							| 
									
										
										
										
											2024-06-10 22:48:19 +02:00
										 |  |  |       in | 
					
						
							|  |  |  |       # with this patch the default setting for metrics is changed | 
					
						
							|  |  |  |       existingPatches ++ [ ./enable-metrics.patch ]; | 
					
						
							| 
									
										
										
										
											2023-06-03 22:42:21 +02:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  | in | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   options.my.services.jellyfin = with lib; { | 
					
						
							|  |  |  |     enable = mkEnableOption "Jellyfin Media Server"; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = lib.mkIf cfg.enable { | 
					
						
							|  |  |  |     services.jellyfin = { | 
					
						
							|  |  |  |       enable = true; | 
					
						
							| 
									
										
										
										
											2023-06-03 22:42:21 +02:00
										 |  |  |       package = jellyfin-with-metrics; | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-03 22:42:21 +02:00
										 |  |  |     services.prometheus = { | 
					
						
							|  |  |  |       scrapeConfigs = [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           job_name = "jellyfin"; | 
					
						
							|  |  |  |           static_configs = [ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               targets = [ "127.0.0.1:${toString cfg.port}" ]; | 
					
						
							|  |  |  |               labels = { | 
					
						
							|  |  |  |                 instance = config.networking.hostName; | 
					
						
							|  |  |  |               }; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           ]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       ]; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     # sadly the metrics do not contain application specific metrics, only c# -> no dashboard | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  |     my.services.nginx.virtualHosts = [ | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2023-04-02 15:54:01 +02:00
										 |  |  |         subdomain = "media"; | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  |         inherit port; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     webapps.apps.jellyfin = { | 
					
						
							|  |  |  |       dashboard = { | 
					
						
							| 
									
										
										
										
											2023-04-02 15:54:01 +02:00
										 |  |  |         name = "Media"; | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  |         category = "media"; | 
					
						
							| 
									
										
										
										
											2023-06-04 14:30:30 +02:00
										 |  |  |         icon = "eye"; | 
					
						
							| 
									
										
										
										
											2023-11-12 20:39:44 +01:00
										 |  |  |         url = "https://media.${domain}"; | 
					
						
							| 
									
										
										
										
											2022-11-29 18:47:27 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } |