From 96f6da104153fcc5700bb156beee2023f7afb025 Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Sun, 22 Oct 2023 19:08:46 +0200 Subject: [PATCH] sombrero: Add `plex` module --- hosts/sombrero/configuration.nix | 20 +----------- hosts/sombrero/modules/plex/default.nix | 42 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 19 deletions(-) create mode 100644 hosts/sombrero/modules/plex/default.nix diff --git a/hosts/sombrero/configuration.nix b/hosts/sombrero/configuration.nix index 42348b7..1f2f85c 100644 --- a/hosts/sombrero/configuration.nix +++ b/hosts/sombrero/configuration.nix @@ -76,7 +76,6 @@ 80 443 1122 # ssh - 32400 # plex 8181 # books-sync 8384 # syncthing 8083 # calibre-web @@ -311,24 +310,6 @@ virtualisation = { oci-containers.containers = { - plex = { - image = "linuxserver/plex"; - autoStart = true; - - environment = { - TZ = "Europe/Stockholm"; - VERSION = "latest"; - }; - - extraOptions = [ "--network=host" ]; - - volumes = [ - "/home/alex/media/plex/db:/config" - "/home/alex/media/Movies:/movies" - "/home/alex/media/TV:/tv" - ]; - }; - koreader-sync = { image = "localhost/koreader-sync"; autoStart = true; @@ -380,6 +361,7 @@ mod = { docker.enable = true; + plex.enable = true; }; # Copy the NixOS configuration file and link it from the resulting system diff --git a/hosts/sombrero/modules/plex/default.nix b/hosts/sombrero/modules/plex/default.nix new file mode 100644 index 0000000..178138d --- /dev/null +++ b/hosts/sombrero/modules/plex/default.nix @@ -0,0 +1,42 @@ +{ lib, config, ... }: +let + enable = config.mod.plex.enable; + dockerEnabled = config.mod.docker.enable; +in +{ + options = { + mod.plex = { + enable = lib.mkEnableOption "enable plex module"; + }; + }; + + config = lib.mkIf (enable && dockerEnabled) { + virtualisation = { + oci-containers.containers = { + plex = { + image = "linuxserver/plex"; + autoStart = true; + + environment = { + TZ = "Europe/Stockholm"; + VERSION = "latest"; + }; + + extraOptions = [ "--network=host" ]; + + volumes = [ + "/home/alex/media/plex/db:/config" + "/home/alex/media/Movies:/movies" + "/home/alex/media/TV:/tv" + ]; + }; + }; + }; + + networking = { + firewall = { + allowedTCPPorts = [ 32400 ]; + }; + }; + }; +}