treewide: Group media services in modules/services/media

This commit is contained in:
Felix Buehler 2025-12-27 15:56:21 +01:00
parent e9951968c7
commit b494b01a9c
11 changed files with 15 additions and 9 deletions

View file

@ -0,0 +1,62 @@
# manages and downloads subtitles
{ config, lib, ... }:
let
cfg = config.my.services.bazarr;
inherit (config.networking) domain;
port = config.services.bazarr.listenPort;
in
{
options.my.services.bazarr = {
enable = lib.mkEnableOption "Bazarr for subtitle management";
apiKeyFile = lib.mkOption {
type = lib.types.path;
description = ''
File containing the api-key.
'';
};
};
config = lib.mkIf cfg.enable {
services = {
bazarr = {
enable = true;
};
prometheus.exporters.exportarr-bazarr = {
inherit (config.services.prometheus) enable;
port = port + 1;
url = "http://localhost:${toString port}";
inherit (cfg) apiKeyFile;
};
prometheus.scrapeConfigs = [
{
job_name = "bazarr";
static_configs = [
{
targets = [ "localhost:${toString port + 1}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
};
my.services.webserver.virtualHosts = [
{
subdomain = "subtitles";
inherit port;
}
];
webapps.apps.bazarr = {
dashboard = {
name = "Subtitles";
category = "app";
icon = "closed-captioning";
url = "https://subtitles.${domain}";
};
};
};
}

View file

@ -0,0 +1,13 @@
{ ... }:
{
imports = [
./bazarr
./jellyfin
./jellyseerr
./navidrome
./photos
./prowlarr
./radarr
./sonarr
];
}

View file

@ -0,0 +1,66 @@
# The Free Software Media System
{
config,
lib,
pkgs,
...
}:
let
cfg = config.my.services.jellyfin;
inherit (config.networking) domain;
# enable monitoring
jellyfin-with-metrics = pkgs.jellyfin.overrideAttrs (attrs: {
patches =
let
existingPatches = if attrs ? patches && builtins.isList attrs.patches then attrs.patches else [ ];
in
# with this patch the default setting for metrics is changed
existingPatches ++ [ ./enable-metrics.patch ];
});
in
{
options.my.services.jellyfin = {
enable = lib.mkEnableOption "Jellyfin Media Server";
};
config = lib.mkIf cfg.enable {
services.jellyfin = {
enable = true;
package = jellyfin-with-metrics;
};
services.prometheus = {
scrapeConfigs = [
{
job_name = "jellyfin";
static_configs = [
{
targets = [ "localhost:${toString cfg.port}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
};
# sadly the metrics do not contain application specific metrics, only c# -> no dashboard
my.services.webserver.virtualHosts = [
{
subdomain = "media";
# jellyfin does not allow modification
port = 8096;
}
];
webapps.apps.jellyfin = {
dashboard = {
name = "Media";
category = "media";
icon = "eye";
url = "https://media.${domain}";
};
};
};
}

View file

@ -0,0 +1,13 @@
diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
index 52f7e53b81..b149e3251a 100644
--- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs
+++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs
@@ -67,7 +67,7 @@ public class ServerConfiguration : BaseApplicationConfiguration
/// <summary>
/// Gets or sets a value indicating whether to enable prometheus metrics exporting.
/// </summary>
- public bool EnableMetrics { get; set; } = false;
+ public bool EnableMetrics { get; set; } = true;
public bool EnableNormalizedItemByNameIds { get; set; } = true;

View file

@ -0,0 +1,33 @@
# manages and downloads films
{ config, lib, ... }:
let
cfg = config.my.services.jellyseerr;
inherit (config.networking) domain;
in
{
options.my.services.jellyseerr = {
enable = lib.mkEnableOption "Sonarr for films management";
};
config = lib.mkIf cfg.enable {
services.jellyseerr = {
enable = true;
};
my.services.webserver.virtualHosts = [
{
subdomain = "view";
inherit (config.services.jellyseerr) port;
}
];
webapps.apps.jellyseerr = {
dashboard = {
name = "View";
category = "media";
icon = "users-viewfinder";
url = "https://view.${domain}";
};
};
};
}

View file

@ -0,0 +1,101 @@
# A FLOSS self-hosted, subsonic compatible music server
{
config,
lib,
pkgs,
...
}:
let
cfg = config.my.services.navidrome;
inherit (config.networking) domain;
in
{
options.my.services.navidrome = {
enable = lib.mkEnableOption "Navidrome Music Server";
settings = lib.mkOption {
inherit (pkgs.formats.json { }) type;
default = {
EnableSharing = true;
};
example = {
"LastFM.ApiKey" = "MYKEY";
"LastFM.Secret" = "MYSECRET";
"Spotify.ID" = "MYKEY";
"Spotify.Secret" = "MYSECRET";
};
description = ''
Additional settings.
'';
};
musicFolder = lib.mkOption {
type = lib.types.str;
example = "/mnt/music/";
description = "Music folder";
};
};
config = lib.mkIf cfg.enable {
services = {
navidrome = {
enable = true;
settings = cfg.settings // {
MusicFolder = cfg.musicFolder;
LogLevel = "info";
Prometheus.Enabled = config.services.prometheus.enable;
};
};
prometheus = {
scrapeConfigs = [
{
job_name = "navidrome";
static_configs = [
{
targets = [ "localhost:${toString config.services.navidrome.settings.Port}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
};
grafana.provision = {
dashboards.settings.providers = [
{
name = "Navidrome";
options.path = pkgs.grafana-dashboards.navidrome;
disableDeletion = true;
}
];
};
};
my.services.prometheus.rules = {
navidrome_not_enough_albums = {
condition = ''http_navidrome_album_count != 1'';
description = "navidrome: not enough albums as expected: {{$value}}";
};
};
my.services.webserver.virtualHosts = [
{
subdomain = "music";
port = config.services.navidrome.settings.Port;
}
];
webapps.apps.navidrome = {
dashboard = {
name = "Music";
category = "media";
icon = "music";
url = "https://music.${domain}";
method = "get";
};
};
};
}

View file

@ -0,0 +1,96 @@
# self-hosted photo gallery
{ config, lib, ... }:
let
cfg = config.my.services.photos;
inherit (config.networking) domain;
inherit (config.services.immich) port;
in
{
options.my.services.photos = {
enable = lib.mkEnableOption "Photos gallery";
secretsFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
pass secrets
'';
};
settings = lib.mkOption {
type = lib.types.anything;
default = { };
description = ''
see <https://immich.app/docs/install/config-file/>.
'';
};
path = lib.mkOption {
type = lib.types.path;
default = null;
example = "/data/photos";
description = ''
Storage path of your original media files (photos and videos)
'';
};
};
config = lib.mkIf cfg.enable {
services.immich = {
enable = true;
# mediaLocation = path;
inherit (cfg) secretsFile;
settings = {
ffmpeg.transcode = "disabled";
server.externalDomain = "https://photos.${domain}";
}
// cfg.settings;
environment = {
IMMICH_TELEMETRY_INCLUDE = "all";
IMMICH_API_METRICS_PORT = toString (port + 1);
IMMICH_MICROSERVICES_METRICS_PORT = toString (port + 2);
};
};
services.prometheus = {
scrapeConfigs = [
{
job_name = "immich";
static_configs = [
{
targets = [ "localhost:${toString (port + 1)}" ];
labels = {
instance = config.networking.hostName;
service = "api";
};
}
{
targets = [ "localhost:${toString (port + 2)}" ];
labels = {
instance = config.networking.hostName;
service = "server";
};
}
];
}
];
};
my.services.webserver.virtualHosts = [
{
subdomain = "photos";
inherit port;
}
];
webapps.apps.photos = {
dashboard = {
name = "Photos";
category = "media";
icon = "image";
url = "https://photos.${domain}";
method = "get";
};
};
};
}

View file

@ -0,0 +1,64 @@
# manages indexes
{ config, lib, ... }:
let
cfg = config.my.services.prowlarr;
inherit (config.networking) domain;
port = 9696;
in
{
options.my.services.prowlarr = {
enable = lib.mkEnableOption "Prowlarr for indexing";
apiKeyFile = lib.mkOption {
type = lib.types.path;
description = ''
File containing the api-key.
'';
};
};
config = lib.mkIf cfg.enable {
services = {
prowlarr = {
enable = true;
settings.server.port = port;
};
prometheus.exporters.exportarr-prowlarr = {
inherit (config.services.prometheus) enable;
port = port + 1;
url = "http://localhost:${toString port}";
inherit (cfg) apiKeyFile;
};
prometheus.scrapeConfigs = [
{
job_name = "prowlarr";
static_configs = [
{
targets = [ "localhost:${toString port + 1}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
};
my.services.webserver.virtualHosts = [
{
subdomain = "indexer";
inherit port;
}
];
webapps.apps.prowlarr = {
dashboard = {
name = "Indexer";
category = "app";
icon = "sync-alt";
url = "https://indexer.${domain}";
method = "get";
};
};
};
}

View file

@ -0,0 +1,64 @@
# manages and downloads films
{ config, lib, ... }:
let
cfg = config.my.services.radarr;
inherit (config.networking) domain;
port = 7878;
in
{
options.my.services.radarr = {
enable = lib.mkEnableOption "Radarr for film management";
apiKeyFile = lib.mkOption {
type = lib.types.path;
description = ''
File containing the api-key.
'';
};
};
config = lib.mkIf cfg.enable {
services = {
radarr = {
enable = true;
settings.server.port = port;
};
prometheus.exporters.exportarr-radarr = {
inherit (config.services.prometheus) enable;
port = port + 1;
url = "http://localhost:${toString port}";
inherit (cfg) apiKeyFile;
};
prometheus.scrapeConfigs = [
{
job_name = "radarr";
static_configs = [
{
targets = [ "localhost:${toString port + 1}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
};
my.services.webserver.virtualHosts = [
{
subdomain = "movies";
inherit port;
}
];
webapps.apps.radarr = {
dashboard = {
name = "Movies";
category = "media";
icon = "film";
url = "https://movies.${domain}";
method = "get";
};
};
};
}

View file

@ -0,0 +1,70 @@
# manages and downloads series
{ config, lib, ... }:
let
cfg = config.my.services.sonarr;
inherit (config.networking) domain;
port = 8989;
in
{
options.my.services.sonarr = {
enable = lib.mkEnableOption "Sonarr for series management";
apiKeyFile = lib.mkOption {
type = lib.types.path;
description = ''
File containing the api-key.
'';
};
};
config = lib.mkIf cfg.enable {
# TODO: remove when sonarr is updated to 5.x
nixpkgs.config.permittedInsecurePackages = [
"dotnet-sdk-6.0.428"
"aspnetcore-runtime-6.0.36"
];
services = {
sonarr = {
enable = true;
settings.server.port = port;
};
prometheus.exporters.exportarr-sonarr = {
inherit (config.services.prometheus) enable;
port = port + 1;
url = "http://localhost:${toString port}";
inherit (cfg) apiKeyFile;
};
prometheus.scrapeConfigs = [
{
job_name = "sonarr";
static_configs = [
{
targets = [ "localhost:${toString port + 1}" ];
labels = {
instance = config.networking.hostName;
};
}
];
}
];
};
my.services.webserver.virtualHosts = [
{
subdomain = "series";
inherit port;
}
];
webapps.apps.sonarr = {
dashboard = {
name = "Series";
category = "media";
icon = "tv";
url = "https://series.${domain}";
method = "get";
};
};
};
}