From 2b5ef6b1457088813473d826e11fcef6e779600a Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 19 Feb 2021 21:21:35 +0100 Subject: [PATCH] jellyfin: setup service --- hosts/poseidon/default.nix | 4 ++++ services/default.nix | 2 ++ services/jellyfin.nix | 32 ++++++++++++++++++++++++++++++++ services/media.nix | 10 ++++++++++ 4 files changed, 48 insertions(+) create mode 100644 services/jellyfin.nix create mode 100644 services/media.nix diff --git a/hosts/poseidon/default.nix b/hosts/poseidon/default.nix index ef8adbf..44e8409 100644 --- a/hosts/poseidon/default.nix +++ b/hosts/poseidon/default.nix @@ -85,6 +85,10 @@ in privatePort = 8082; }; + jellyfin = { + enable = true; + }; + miniflux = { enable = true; adminCredentialsFile = "${../../secrets/miniflux-admin-credentials.secret}"; diff --git a/services/default.nix b/services/default.nix index 5f4c64a..8fd2a9b 100644 --- a/services/default.nix +++ b/services/default.nix @@ -5,7 +5,9 @@ ./bitwarden_rs.nix ./borg-backup.nix ./gitea.nix + ./jellyfin.nix ./matrix.nix + ./media.nix ./miniflux.nix ./monitoring.nix ./nginx.nix diff --git a/services/jellyfin.nix b/services/jellyfin.nix new file mode 100644 index 0000000..491ecfb --- /dev/null +++ b/services/jellyfin.nix @@ -0,0 +1,32 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.my.services.jellyfin; + my = config.my; + + domain = config.networking.domain; + + # hardcoded in NixOS module :( + jellyfinPort = 8096; +in { + options.my.services.jellyfin = { + enable = mkEnableOption "Jellyfin"; + }; + + config = lib.mkIf cfg.enable { + services.jellyfin = { + enable = true; + group = "media"; + }; + + # Proxy to Jellyfin + services.nginx.virtualHosts."jellyfin.${domain}" = { + forceSSL = true; + enableACME = true; + + locations."/".proxyPass = "http://localhost:${toString jellyfinPort}/"; + }; + }; +} diff --git a/services/media.nix b/services/media.nix new file mode 100644 index 0000000..7e1e966 --- /dev/null +++ b/services/media.nix @@ -0,0 +1,10 @@ +{ config, lib, ... }: +let + mediaServices = with config.my.services; [ + jellyfin + ]; + needed = builtins.any (service: service.enable) mediaServices; +in +{ + config.users.groups.media = lib.mkIf needed { }; +}