From 04bf03348486d1362841a60bb560413a16c2ad4d Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Wed, 9 Nov 2022 22:15:47 +0100 Subject: [PATCH] homer: split config and update to new version --- modules/services/homer/config.nix | 120 +++++++++++++++++++++++ modules/services/homer/default.nix | 148 +++++++++-------------------- pkgs/homer/default.nix | 4 +- 3 files changed, 168 insertions(+), 104 deletions(-) create mode 100644 modules/services/homer/config.nix diff --git a/modules/services/homer/config.nix b/modules/services/homer/config.nix new file mode 100644 index 0000000..c59ceba --- /dev/null +++ b/modules/services/homer/config.nix @@ -0,0 +1,120 @@ +{ 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; + }; + dashboard.type = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = '' + application type. + ''; + example = "Ping"; + default = "Ping"; + }; + }; + }); + 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"; + type = a.dashboard.type; + method = "head"; + }); + } + ); + }; +} diff --git a/modules/services/homer/default.nix b/modules/services/homer/default.nix index e04b382..6bc22a3 100644 --- a/modules/services/homer/default.nix +++ b/modules/services/homer/default.nix @@ -1,110 +1,54 @@ +# Dashboard site { config, lib, pkgs, ... }: +let + cfg = config.my.services.homer; + domain = config.networking.domain; + homeConfig = { + title = "Dashboard"; + header = false; + footer = false; + connectivityCheck = true; + colums = "auto"; + services = config.lib.webapps.homerServices; + }; +in { - 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 = [ ]; - }; + imports = [ + ./config.nix + ]; - 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 = { }; - }; + options.my.services.homer = with lib; { + enable = mkEnableOption "Homer Dashboard"; }; - 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"; - type = "Ping"; - }); - } - ); + config = lib.mkIf cfg.enable { + services.nginx.virtualHosts = { + # This is not a subdomain, cannot use my nginx wrapper module + ${domain} = { + forceSSL = true; + useACMEHost = domain; + root = pkgs.homer; + locations."=/assets/config.yml" = { + alias = pkgs.writeText "homerConfig.yml" (builtins.toJSON homeConfig); + }; }; + # redirect any other attempt to the main site + "${domain}-redirect" = { + forceSSL = true; + useACMEHost = domain; + default = true; + globalRedirect = "${domain}"; + }; + }; + + webapps = { + dashboardCategories = [ + { name = "Applications"; tag = "app"; } + { name = "Media"; tag = "media"; } + { name = "Infrastructure"; tag = "infra"; } + { name = "Other"; tag = "other"; } + ]; + }; + }; } diff --git a/pkgs/homer/default.nix b/pkgs/homer/default.nix index 76ee371..20eb637 100644 --- a/pkgs/homer/default.nix +++ b/pkgs/homer/default.nix @@ -1,13 +1,13 @@ { stdenv, fetchzip }: stdenv.mkDerivation rec { pname = "homer"; - version = "22.07.2"; + version = "22.11.1"; src = fetchzip { urls = [ "https://github.com/bastienwirtz/homer/releases/download/v${version}/homer.zip" ]; - sha256 = "sha256-rmCqjWn7bbTESmOHTO5H7YVyZzny617pI0VdSlsqYGI="; + sha256 = "sha256-5W+bnPxXAv+svg3zrsiNTjZWrUuR39qKCnGGYY6pBjg="; stripRoot = false; };