From 10c0e429540e1d1f795c9945236c1e4ac32751ee Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 8 Sep 2024 22:34:29 -0400 Subject: [PATCH] Services: parse domain from service URL (there's probably a better way to do this) --- hosts/Dimaga/default.nix | 4 ---- hosts/Hevana/default.nix | 5 ----- modules/services/airsonic.nix | 15 ++++++++------- modules/services/deluge.nix | 16 ++++++++-------- modules/services/forgejo.nix | 24 ++++++++++++++++-------- modules/services/home-assistant.nix | 22 +++++++++------------- modules/services/jellyfin.nix | 15 ++++++++------- modules/services/netdata.nix | 15 ++++++++------- 8 files changed, 57 insertions(+), 59 deletions(-) diff --git a/hosts/Dimaga/default.nix b/hosts/Dimaga/default.nix index 6f7e97f..d949a35 100644 --- a/hosts/Dimaga/default.nix +++ b/hosts/Dimaga/default.nix @@ -137,7 +137,6 @@ in deluge = { enable = true; home = "${services-root}/deluge"; - domain = config.secrets.networking.domains.primary; url = config.secrets.services.deluge.url; }; duplicacy-web = { @@ -147,7 +146,6 @@ in forgejo = { enable = true; home = "${services-root}/forgejo"; - domain = config.secrets.networking.domains.primary; url = config.secrets.services.forgejo.url; actions = { enable = true; @@ -157,13 +155,11 @@ in jellyfin = { enable = true; home = "${services-root}/jellyfin"; - domain = config.secrets.networking.domains.primary; url = config.secrets.services.jellyfin.url; }; msmtp.enable = true; netdata = { enable = true; - domain = config.secrets.networking.domains.primary; type = "parent"; url = config.secrets.services.netdata.url; auth = { diff --git a/hosts/Hevana/default.nix b/hosts/Hevana/default.nix index d464cb3..2b4c9af 100644 --- a/hosts/Hevana/default.nix +++ b/hosts/Hevana/default.nix @@ -124,7 +124,6 @@ in deluge = { enable = true; home = "${services-root}/deluge"; - domain = config.secrets.networking.domains.primary; url = config.secrets.services.deluge.url; }; duplicacy-web = { @@ -134,7 +133,6 @@ in forgejo = { enable = true; home = "${services-root}/forgejo"; - domain = config.secrets.networking.domains.primary; url = config.secrets.services.forgejo.url; actions = { enable = true; @@ -144,19 +142,16 @@ in home-assistant = { enable = false; home = "${services-root}/home-assistant"; - domain = config.secrets.networking.domains.primary; url = config.secrets.services.home-assistant.url; }; jellyfin = { enable = true; home = "${services-root}/jellyfin"; - domain = config.secrets.networking.domains.primary; url = config.secrets.services.jellyfin.url; }; msmtp.enable = true; netdata = { enable = true; - domain = config.secrets.networking.domains.primary; type = "parent"; url = config.secrets.services.netdata.url; auth = { diff --git a/modules/services/airsonic.nix b/modules/services/airsonic.nix index 4c5ae8a..fd45802 100644 --- a/modules/services/airsonic.nix +++ b/modules/services/airsonic.nix @@ -16,12 +16,6 @@ in type = lib.types.str; description = "Where to store Airsonic's files"; }; - domain = lib.mkOption { - default = ""; - type = lib.types.str; - description = "The root domain that Airsonic will be hosted on."; - example = "example.com"; - }; url = lib.mkOption { default = ""; type = lib.types.str; @@ -37,7 +31,14 @@ in services = { nginx.virtualHosts."${cfg.url}" = { - useACMEHost = cfg.domain; + useACMEHost = + let + parsedURL = (lib.strings.splitString "." cfg.url); + in + builtins.concatStringsSep "." [ + (builtins.elemAt parsedURL 1) + (builtins.elemAt parsedURL 2) + ]; forceSSL = true; locations."/" = { proxyPass = "http://127.0.0.1:4040"; diff --git a/modules/services/deluge.nix b/modules/services/deluge.nix index cdc876a..26555b8 100644 --- a/modules/services/deluge.nix +++ b/modules/services/deluge.nix @@ -1,4 +1,3 @@ -# This is an example of a blank module. { config, lib, ... }: let @@ -13,12 +12,6 @@ in type = lib.types.str; description = "Where to store Deluge's files"; }; - domain = lib.mkOption { - default = ""; - type = lib.types.str; - description = "The root domain that Deluge will be hosted on."; - example = "example.com"; - }; url = lib.mkOption { default = ""; type = lib.types.str; @@ -32,7 +25,14 @@ in config = lib.mkIf cfg.enable { services = { nginx.virtualHosts."${cfg.url}" = { - useACMEHost = cfg.domain; + useACMEHost = + let + parsedURL = (lib.strings.splitString "." cfg.url); + in + builtins.concatStringsSep "." [ + (builtins.elemAt parsedURL 1) + (builtins.elemAt parsedURL 2) + ]; forceSSL = true; locations."/" = { proxyPass = "http://127.0.0.1:8112"; diff --git a/modules/services/forgejo.nix b/modules/services/forgejo.nix index 5ac4d37..03b2cb5 100644 --- a/modules/services/forgejo.nix +++ b/modules/services/forgejo.nix @@ -25,12 +25,6 @@ in options = { aux.system.services.forgejo = { enable = lib.mkEnableOption "Enables Forgejo Git hosting service."; - domain = lib.mkOption { - default = "/var/lib/forgejo"; - type = lib.types.str; - description = "The root domain that Forgejo will be hosted on."; - example = "example.com"; - }; home = lib.mkOption { default = ""; type = lib.types.str; @@ -63,7 +57,14 @@ in forgejo = { enable = true; settings.server = { - DOMAIN = cfg.domain; + DOMAIN = + let + parsedURL = (lib.strings.splitString "." cfg.url); + in + builtins.concatStringsSep "." [ + (builtins.elemAt parsedURL 1) + (builtins.elemAt parsedURL 2) + ]; ROOT_URL = cfg.url; HTTP_PORT = 3000; }; @@ -71,7 +72,14 @@ in } // lib.optionalAttrs (cfg.home != null) { stateDir = cfg.home; }; nginx.virtualHosts."${cfg.url}" = { - useACMEHost = cfg.domain; + useACMEHost = + let + parsedURL = (lib.strings.splitString "." cfg.url); + in + builtins.concatStringsSep "." [ + (builtins.elemAt parsedURL 1) + (builtins.elemAt parsedURL 2) + ]; forceSSL = true; locations."/" = { proxyPass = "http://127.0.0.1:3000"; diff --git a/modules/services/home-assistant.nix b/modules/services/home-assistant.nix index 64ca162..86ade25 100644 --- a/modules/services/home-assistant.nix +++ b/modules/services/home-assistant.nix @@ -1,9 +1,4 @@ -{ - config, - lib, - pkgs, - ... -}: +{ config, lib, ... }: let cfg = config.aux.system.services.home-assistant; @@ -12,12 +7,6 @@ in options = { aux.system.services.home-assistant = { enable = lib.mkEnableOption "Enables Home Assistant."; - domain = lib.mkOption { - default = ""; - type = lib.types.str; - description = "The root domain that Home Assistant will be hosted on."; - example = "example.com"; - }; home = lib.mkOption { default = "/etc/home-assistant"; type = lib.types.str; @@ -60,7 +49,14 @@ in }; }; nginx.virtualHosts."${cfg.url}" = { - useACMEHost = cfg.domain; + useACMEHost = + let + parsedURL = (lib.strings.splitString "." cfg.url); + in + builtins.concatStringsSep "." [ + (builtins.elemAt parsedURL 1) + (builtins.elemAt parsedURL 2) + ]; forceSSL = true; locations."/" = { proxyPass = "http://[::1]:8123"; diff --git a/modules/services/jellyfin.nix b/modules/services/jellyfin.nix index 1c32477..672ca4f 100644 --- a/modules/services/jellyfin.nix +++ b/modules/services/jellyfin.nix @@ -20,12 +20,6 @@ in type = lib.types.str; description = "Where to store Jellyfin's files"; }; - domain = lib.mkOption { - default = ""; - type = lib.types.str; - description = "The root domain that Jellyfin will be hosted on."; - example = "example.com"; - }; url = lib.mkOption { default = ""; type = lib.types.str; @@ -40,7 +34,14 @@ in services = { nginx.virtualHosts."${cfg.url}" = { - useACMEHost = cfg.domain; + useACMEHost = + let + parsedURL = (lib.strings.splitString "." cfg.url); + in + builtins.concatStringsSep "." [ + (builtins.elemAt parsedURL 1) + (builtins.elemAt parsedURL 2) + ]; forceSSL = true; locations."/" = { proxyPass = "http://127.0.0.1:8096"; diff --git a/modules/services/netdata.nix b/modules/services/netdata.nix index 4f16ddf..9d1997c 100644 --- a/modules/services/netdata.nix +++ b/modules/services/netdata.nix @@ -28,12 +28,6 @@ in description = "API key for streaming data from a child to a parent."; }; }; - domain = lib.mkOption { - default = ""; - type = lib.types.str; - description = "The root domain that Netdata will be hosted on."; - example = "example.com"; - }; type = lib.mkOption { default = "parent"; type = lib.types.enum [ @@ -56,7 +50,14 @@ in (lib.mkIf (cfg.enable && cfg.type == "parent") { services = { nginx.virtualHosts."${cfg.url}" = { - useACMEHost = cfg.domain; + useACMEHost = + let + parsedURL = (lib.strings.splitString "." cfg.url); + in + builtins.concatStringsSep "." [ + (builtins.elemAt parsedURL 1) + (builtins.elemAt parsedURL 2) + ]; forceSSL = true; basicAuth = { "${cfg.auth.user}" = cfg.auth.password;