From f196f546b8de6bc9fc1982ba7e1156f24bad841e Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 2 Oct 2022 17:40:10 +0000 Subject: [PATCH] add jellyfin, switch caddy to one listener --- hosts/oracle/default.nix | 2 ++ modules/services/caddy.nix | 14 +++++++++----- modules/services/calibre.nix | 17 +++++++---------- modules/services/jellyfin.nix | 23 +++++++++++++++++++++++ 4 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 modules/services/jellyfin.nix diff --git a/hosts/oracle/default.nix b/hosts/oracle/default.nix index e8dd31f..62cf364 100644 --- a/hosts/oracle/default.nix +++ b/hosts/oracle/default.nix @@ -10,6 +10,7 @@ nixpkgs.lib.nixosSystem { { networking.hostName = "oracle"; bookServer = "books.masu.rs"; + streamServer = "stream.masu.rs"; gui.enable = false; colorscheme = (import ../../modules/colorscheme/gruvbox); passwordHash = null; @@ -23,5 +24,6 @@ nixpkgs.lib.nixosSystem { ../../modules/services/oracle.nix ../../modules/services/sshd.nix ../../modules/services/calibre.nix + ../../modules/services/jellyfin.nix ]; } diff --git a/modules/services/caddy.nix b/modules/services/caddy.nix index d788fc1..eec26cc 100644 --- a/modules/services/caddy.nix +++ b/modules/services/caddy.nix @@ -5,9 +5,9 @@ let in { options = { - caddyServers = lib.mkOption { - type = lib.types.attrs; - description = "Caddy JSON configs for http servers"; + caddyRoutes = lib.mkOption { + type = lib.types.listOf lib.types.attrs; + description = "Caddy JSON routes for http servers"; }; }; @@ -16,8 +16,12 @@ in { services.caddy = { enable = true; adapter = "''"; # Required to enable JSON - configFile = pkgs.writeText "Caddyfile" - (builtins.toJSON { apps.http.servers = config.caddyServers; }); + configFile = pkgs.writeText "Caddyfile" (builtins.toJSON { + apps.http.servers.main = { + listen = [ ":443" ]; + routes = config.caddyRoutes; + }; + }); }; diff --git a/modules/services/calibre.nix b/modules/services/calibre.nix index 83b4725..38b794c 100644 --- a/modules/services/calibre.nix +++ b/modules/services/calibre.nix @@ -28,17 +28,14 @@ in { }; }; - caddyServers.calibre = { - listen = [ ":443" ]; - routes = [{ - match = [{ host = [ config.bookServer ]; }]; - handle = [{ - handler = "reverse_proxy"; - upstreams = [{ dial = "localhost:8083"; }]; - headers.request.add."X-Script-Name" = [ "/calibre-web" ]; - }]; + caddyRoutes = [{ + match = [{ host = [ config.bookServer ]; }]; + handle = [{ + handler = "reverse_proxy"; + upstreams = [{ dial = "localhost:8083"; }]; + headers.request.add."X-Script-Name" = [ "/calibre-web" ]; }]; - }; + }]; networking.firewall.interfaces.calibre = { allowedTCPPorts = [ 80 443 ]; }; diff --git a/modules/services/jellyfin.nix b/modules/services/jellyfin.nix new file mode 100644 index 0000000..c866cc0 --- /dev/null +++ b/modules/services/jellyfin.nix @@ -0,0 +1,23 @@ +{ config, lib, ... }: { + + options = { + streamServer = lib.mkOption { + type = lib.types.str; + description = "Hostname for Jellyfin library"; + }; + }; + + config = { + + services.jellyfin.enable = true; + + caddyRoutes = [{ + match = [{ host = [ config.streamServer ]; }]; + handle = [{ + handler = "reverse_proxy"; + upstreams = [{ dial = "localhost:8096"; }]; + }]; + }]; + }; + +}