diff --git a/extra/media-server.nix b/extra/media-server.nix deleted file mode 100644 index 9f80062..0000000 --- a/extra/media-server.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ config, lib, pkgs, ... }: -{ - services = { - # movie management - radarr = { - enable = true; - openFirewall = true; - }; - # series management - sonarr = { - enable = true; - openFirewall = true; - }; - # subtitle management - bazarr = { - enable = true; - openFirewall = true; - }; - # indexer management - prowlarr = { - enable = true; - openFirewall = true; - }; - # media player - jellyfin = { - enable = true; - openFirewall = true; - }; - }; -} diff --git a/extra/webapps/bazarr.nix b/extra/webapps/bazarr.nix new file mode 100644 index 0000000..a8ea288 --- /dev/null +++ b/extra/webapps/bazarr.nix @@ -0,0 +1,21 @@ +{ config, pkgs, ... }: +{ + services.bazarr = { + enable = true; + openFirewall = true; + }; + + systemd.services.bazarr = { + after = [ "network-online.target" ]; + #unitConfig.RequiresMountsFor = [ "/storage" ]; + }; + + webapps.apps.bazarr = { + dashboard = { + name = "Bazarr"; + category = "manag"; + icon = "closed-captioning"; + link = "http://192.168.178.60:6767"; + }; + }; +} diff --git a/extra/webapps/homer.nix b/extra/webapps/homer.nix new file mode 100644 index 0000000..7363e30 --- /dev/null +++ b/extra/webapps/homer.nix @@ -0,0 +1,57 @@ +{ config, lib, pkgs, ... }: + +let + homer = pkgs.stdenv.mkDerivation rec { + pname = "homer"; + version = "21.09.2"; + + src = pkgs.fetchurl { + urls = [ + "https://github.com/bastienwirtz/${pname}/releases/download/v${version}/${pname}.zip" + ]; + sha256 = "sha256-NHvH3IW05O1YvPp0KOUU0ajZsuh7BMgqUTJvMwbc+qY="; + }; + nativeBuildInputs = [ pkgs.unzip ]; + + dontInstall = true; + sourceRoot = "."; + unpackCmd = "${pkgs.unzip}/bin/unzip -d $out $curSrc"; + }; + + homeConfig = { + title = "Dashboard"; + header = false; + footer = false; + connectivityCheck = true; + colums = "auto"; + services = config.lib.webapps.homerServices; + }; +in +{ + networking.firewall.allowedTCPPorts = [ + 80 + 443 + ]; + services.nginx = { + enable = true; + #virtualHosts."dashboard.rocks" = { + virtualHosts."_" = { + default = true; + locations = { + "/" = { + root = homer; + }; + "=/assets/config.yml" = { + alias = pkgs.writeText "homerConfig.yml" (builtins.toJSON homeConfig); + }; + }; + }; + }; + webapps = { + dashboardCategories = [ + { name = "Applications"; tag = "app"; } + { name = "Media-Management"; tag = "manag"; } + { name = "Infrastructure"; tag = "infra"; } + ]; + }; +} diff --git a/extra/webapps/jellyfin.nix b/extra/webapps/jellyfin.nix new file mode 100644 index 0000000..178d359 --- /dev/null +++ b/extra/webapps/jellyfin.nix @@ -0,0 +1,21 @@ +{ config, pkgs, ... }: +{ + services.jellyfin = { + enable = true; + openFirewall = true; + }; + + systemd.services.jellyfin = { + after = [ "network-online.target" ]; + #unitConfig.RequiresMountsFor = [ "/storage" ]; + }; + + webapps.apps.jellyfin = { + dashboard = { + name = "Jellyfin"; + category = "app"; + icon = "film"; + link = "http://192.168.178.60:8096"; + }; + }; +} diff --git a/extra/webapps/prowlarr.nix b/extra/webapps/prowlarr.nix new file mode 100644 index 0000000..38562aa --- /dev/null +++ b/extra/webapps/prowlarr.nix @@ -0,0 +1,31 @@ +{ config, pkgs, ... }: +{ + services.prowlarr = { + enable = true; + openFirewall = true; + }; + + systemd.services.prowlarr = { + after = [ "network-online.target" ]; + #unitConfig.RequiresMountsFor = [ "/storage" ]; + }; + + webapps.apps.prowlarr = { + dashboard = { + name = "Prowlarr"; + category = "manag"; + icon = "sync-alt"; + link = "http://192.168.178.60:9696"; + }; + }; + # ugly fix for service not having a homedirectory + users.users.prowlarr = { + isSystemUser = true; + home = "/var/lib/prowlarr"; + group = "prowlarr"; + uid = 61654; + }; + users.groups.prowlarr = { + gid = 61654; + }; +} diff --git a/extra/webapps/radarr.nix b/extra/webapps/radarr.nix new file mode 100644 index 0000000..0f18749 --- /dev/null +++ b/extra/webapps/radarr.nix @@ -0,0 +1,21 @@ +{ config, pkgs, ... }: +{ + services.radarr = { + enable = true; + openFirewall = true; + }; + + systemd.services.radarr = { + after = [ "network-online.target" ]; + #unitConfig.RequiresMountsFor = [ "/storage" ]; + }; + + webapps.apps.radarr = { + dashboard = { + name = "Radarr"; + category = "manag"; + icon = "film"; + link = "http://192.168.178.60:7878"; + }; + }; +} diff --git a/extra/webapps/sonarr.nix b/extra/webapps/sonarr.nix new file mode 100644 index 0000000..e172237 --- /dev/null +++ b/extra/webapps/sonarr.nix @@ -0,0 +1,21 @@ +{ config, pkgs, ... }: +{ + services.sonarr = { + enable = true; + openFirewall = true; + }; + + systemd.services.sonarr = { + after = [ "network-online.target" ]; + #unitConfig.RequiresMountsFor = [ "/storage" ]; + }; + + webapps.apps.sonarr = { + dashboard = { + name = "Sonarr"; + category = "manag"; + icon = "tv"; + link = "http://192.168.178.60:8989"; + }; + }; +} diff --git a/modules/webapps/default.nix b/modules/webapps/default.nix new file mode 100644 index 0000000..9813f34 --- /dev/null +++ b/modules/webapps/default.nix @@ -0,0 +1,109 @@ +{ config, lib, pkgs, ... }: + +{ + options.webapps = { + dashboardCategories = lib.mkOption { + type = lib.types.listOf (lib.types.submodule { + options = { + name = lib.mkOption { + type = lib.types.str; + description = '' + Category name. + ''; + example = "Applications"; + }; + tag = lib.mkOption { + type = lib.types.str; + description = '' + Category tag. + ''; + example = "app"; + }; + }; + }); + description = '' + App categories to display on the dashboard. + ''; + example = [ + { + name = "Application"; + tag = "app"; + } + ]; + default = [ ]; + }; + + apps = lib.mkOption { + type = lib.types.attrsOf + (lib.types.submodule { + options = { + dashboard.link = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = '' + Link to webapp + ''; + example = "http://192.168.1.10:1234"; + default = null; + }; + dashboard.name = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = '' + Application name. + ''; + example = "App"; + default = null; + }; + dashboard.category = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = '' + App category tag. + ''; + example = "app"; + default = null; + }; + dashboard.icon = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = '' + Font Awesome application icon. + ''; + example = "rss"; + default = null; + }; + }; + }); + description = '' + Defines a web application. + ''; + default = { }; + }; + }; + + config = + let + cfg = config.webapps; + in { + lib.webapps.homerServices = + let + apps = builtins.filter (a: a.dashboard.name != null) (lib.attrValues cfg.apps); + in + lib.forEach cfg.dashboardCategories (cat: + let + catApps = lib.sort (a: b: a.dashboard.name < b.dashboard.name) ( + builtins.filter + (a: + a.dashboard.category != null && a.dashboard.category == cat.tag || + a.dashboard.category == null && cat.tag == "misc") + apps); + in + { + name = cat.name; + items = lib.forEach catApps (a: { + name = a.dashboard.name; + icon = lib.optionalString (a.dashboard.icon != null) "fas fa-${a.dashboard.icon}"; + url = a.dashboard.link; + target = "_blank"; + }); + } + ); + }; +} diff --git a/serverle.nix b/serverle.nix index 675701e..fabbf7a 100644 --- a/serverle.nix +++ b/serverle.nix @@ -13,10 +13,16 @@ ./extra/development.nix ./extra/docker.nix ./extra/dyndns.nix - ./extra/media-server.nix ./extra/networkdecrypt.nix ./extra/nix.nix ./extra/ssh.nix + ./modules/webapps + ./extra/webapps/bazarr.nix + ./extra/webapps/homer.nix + ./extra/webapps/jellyfin.nix + ./extra/webapps/prowlarr.nix + ./extra/webapps/radarr.nix + ./extra/webapps/sonarr.nix ./hardware/raspberrypi4.nix ]; networking.hostName = "serverle";