From 48fb68c2fd24a0ee2815402bd88a3290f83a290e Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sun, 25 May 2025 14:32:47 +0200 Subject: [PATCH] fix: Separate nfs config --- modules/apps/arr/default.nix | 31 +++----- modules/apps/plex/default.nix | 81 +++++++++------------ modules/fileSystems/default.nix | 5 ++ modules/fileSystems/media/default.nix | 5 ++ modules/fileSystems/media/video/default.nix | 42 +++++++++++ 5 files changed, 100 insertions(+), 64 deletions(-) create mode 100644 modules/fileSystems/default.nix create mode 100644 modules/fileSystems/media/default.nix create mode 100644 modules/fileSystems/media/video/default.nix diff --git a/modules/apps/arr/default.nix b/modules/apps/arr/default.nix index e45b1bf..2687e2a 100644 --- a/modules/apps/arr/default.nix +++ b/modules/apps/arr/default.nix @@ -38,6 +38,11 @@ in { sonarr.enable = true; }; + fileSystems.media.video = { + enable = true; + permissions = [ "read" "write" ]; + }; + virtualisation.containers.enable = lib.mkIf inUse true; }; @@ -139,20 +144,6 @@ in { "_netdev" "nosuid" "tcp" ]; }; - - "/srv/video" = { - device = "192.168.0.11:/mnt/SMALL/MEDIA/VIDEO"; - fsType = "nfs"; - options = [ - "rw" - "auto" - "nfsvers=4.2" - "soft" - "rsize=1048576" "wsize=1048576" - "timeo=600" "retrans=2" - "_netdev" "nosuid" "tcp" - ]; - }; }; # Make sure the Docker network exists. @@ -226,7 +217,9 @@ in { }; }; - virtualisation.oci-containers.containers = { + virtualisation.oci-containers.containers = let + videoHostPath = config.homelab.fileSystems.media.video.hostPath; + in { bazarr = let port = 6767; in lib.mkIf cfg.bazarr.enable { @@ -252,8 +245,8 @@ in { "/srv/bazarr-backup:/config/backup" - "/srv/video/Films:/media/movies" - "/srv/video/Series:/media/series" + "${videoHostPath}/Films:/media/movies" + "${videoHostPath}/Series:/media/series" ]; labels = { "traefik.enable" = "true"; @@ -374,7 +367,7 @@ in { "/srv/radarr-backup:/config/Backups" "/srv/torrent:/media/cache" - "/srv/video/Films:/media/movies" + "${videoHostPath}/Films:/media/movies" ]; labels = { "traefik.enable" = "true"; @@ -407,7 +400,7 @@ in { "/srv/sonarr-backup:/config/Backups" "/srv/torrent:/media/cache" - "/srv/video/Series:/media/series" + "${videoHostPath}/Series:/media/series" ]; labels = { "traefik.enable" = "true"; diff --git a/modules/apps/plex/default.nix b/modules/apps/plex/default.nix index 7e21745..b307b86 100644 --- a/modules/apps/plex/default.nix +++ b/modules/apps/plex/default.nix @@ -11,6 +11,7 @@ in { apps.enable = true; media.enable = true; }; + fileSystems.media.video.enable = true; virtualisation.containers.enable = true; }; @@ -25,53 +26,43 @@ in { shell = null; }; - fileSystems."/srv/video" = { - device = "192.168.0.11:/mnt/SMALL/MEDIA/VIDEO"; - fsType = "nfs"; - options = [ - "ro" - "nfsvers=4.2" - "async" "soft" - "timeo=100" "retry=50" "actimeo=1800" "lookupcache=all" - "nosuid" "tcp" + virtualisation.oci-containers.containers.plex = let + videoHostPath = config.homelab.fileSystems.media.video.hostPath; + in { + hostname = "plex"; + image = "plexinc/pms-docker:1.41.6.9685-d301f511a"; + autoStart = true; + ports = [ + "32400:32400/tcp" # Plex Media Server + "1900:1900/udp" # Plex DLNA Server + "32469:32469/tcp" # Plex DLNA Server + "32410:32410/udp" # GDM network discovery + "32412:32412/udp" # GDM network discovery + "32413:32413/udp" # GDM network discovery + "32414:32414/udp" # GDM network discovery + # "8324:8324/tcp" # Controlling Plex for Roku via Plex Companion ]; - }; + environment = { + #ADVERTISE_AP = "..."; # TODO Configure ip + ALLOWED_NETWORKS = "192.168.0.0/24,172.16.0.0/16"; + CHANGE_CONFIG_DIR_OWNERSHIP = "false"; + HOSTNAME = "Hugo-Plex"; + PLEX_CLAIM = "claim-d5MqsjMeCZrUF6oUvssr"; + PLEX_UID = toString config.users.users.plex.uid; + PLEX_GID = toString config.users.groups.media.gid; + TZ = config.time.timeZone; + }; + volumes = [ + # TODO Backup over NFS + "plex-config:/config" + "plex-transcode:/transcode" - virtualisation.oci-containers.containers = { - plex = { - hostname = "plex"; - image = "plexinc/pms-docker:1.41.0.8992-8463ad060"; - autoStart = true; - ports = [ - "32400:32400/tcp" # Plex Media Server - "1900:1900/udp" # Plex DLNA Server - "32469:32469/tcp" # Plex DLNA Server - "32410:32410/udp" # GDM network discovery - "32412:32412/udp" # GDM network discovery - "32413:32413/udp" # GDM network discovery - "32414:32414/udp" # GDM network discovery - # "8324:8324/tcp" # Controlling Plex for Roku via Plex Companion - ]; - environment = { - #ADVERTISE_AP = "..."; # TODO Configure ip - ALLOWED_NETWORKS = "192.168.0.0/24,172.16.0.0/16"; - CHANGE_CONFIG_DIR_OWNERSHIP = "false"; - HOSTNAME = "PlexServer"; - #PLEX_CLAIM = "..."; # TODO Add token - PLEX_UID = toString config.users.users.plex.uid; - PLEX_GID = toString config.users.groups.media.gid; - TZ = config.time.timeZone; - }; - volumes = [ - "plex-config:/var/lib/plexmediaserver" - "plex-transcode:/transcode" - "/srv/video:/data/video" - ]; - labels = { - "traefik.enable" = "true"; - "traefik.http.routers.plex.rule=" = "Host(`plex.depeuter.dev`)"; - "traefik.http.services.plex.loadbalancer.server.port" = "32400"; - }; + "${videoHostPath}:/data/video:ro" + ]; + labels = { + "traefik.enable" = "true"; + "traefik.http.routers.plex.rule" = "Host(`plex.depeuter.dev`)"; + "traefik.http.services.plex.loadbalancer.server.port" = "32400"; }; }; }; diff --git a/modules/fileSystems/default.nix b/modules/fileSystems/default.nix new file mode 100644 index 0000000..7c25689 --- /dev/null +++ b/modules/fileSystems/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./media + ]; +} diff --git a/modules/fileSystems/media/default.nix b/modules/fileSystems/media/default.nix new file mode 100644 index 0000000..41cb81f --- /dev/null +++ b/modules/fileSystems/media/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./video + ]; +} diff --git a/modules/fileSystems/media/video/default.nix b/modules/fileSystems/media/video/default.nix new file mode 100644 index 0000000..e46193c --- /dev/null +++ b/modules/fileSystems/media/video/default.nix @@ -0,0 +1,42 @@ +{ config, lib, ... }: + +let + cfg = config.homelab.fileSystems.media.video; + + remotePath = "/mnt/SMALL/MEDIA/VIDEO"; + + maxPermissions = permissions: + if builtins.elem "write" permissions then "rw" + else "ro"; + permissionsOption = maxPermissions cfg.permissions; +in { + options.homelab.fileSystems.media.video = { + enable = lib.mkEnableOption "MEDIA/VIDEO dataset"; + hostPath = lib.mkOption { + type = lib.types.path; + default = "/srv/video"; + description = "Mountpath on host"; + }; + permissions = lib.mkOption { + type = lib.types.listOf (lib.types.enum [ "read" "write" ]); + default = [ "read" ]; + description = "Mount options permissions"; + }; + }; + + config = lib.mkIf cfg.enable { + fileSystems."${cfg.hostPath}" = { + device = "192.168.0.11:${remotePath}"; + fsType = "nfs"; + options = [ + permissionsOption + "auto" + "nfsvers=4.2" + "async" "soft" + "rsize=1048576" "wsize=1048576" + "timeo=600" "retry=50" "retrans=2" "actimeo=1800" "lookupcache=all" + "_netdev" "nosuid" "tcp" + ]; + }; + }; +}